1/* 2 * Copyright (C) 1999 Lars Knoll (knoll@kde.org) 3 * (C) 1999 Antti Koivisto (koivisto@kde.org) 4 * (C) 2000 Dirk Mueller (mueller@kde.org) 5 * Copyright (C) 2004, 2005, 2006, 2007, 2010 Apple Inc. All rights reserved. 6 * 7 * This library is free software; you can redistribute it and/or 8 * modify it under the terms of the GNU Library General Public 9 * License as published by the Free Software Foundation; either 10 * version 2 of the License, or (at your option) any later version. 11 * 12 * This library is distributed in the hope that it will be useful, 13 * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 15 * Library General Public License for more details. 16 * 17 * You should have received a copy of the GNU Library General Public License 18 * along with this library; see the file COPYING.LIB. If not, write to 19 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 20 * Boston, MA 02110-1301, USA. 21 * 22 */ 23 24#ifndef HTMLTextAreaElement_h 25#define HTMLTextAreaElement_h 26 27#include "core/html/HTMLTextFormControlElement.h" 28 29namespace blink { 30 31class BeforeTextInsertedEvent; 32class ExceptionState; 33class VisibleSelection; 34 35class HTMLTextAreaElement FINAL : public HTMLTextFormControlElement { 36 DEFINE_WRAPPERTYPEINFO(); 37public: 38 static PassRefPtrWillBeRawPtr<HTMLTextAreaElement> create(Document&, HTMLFormElement*); 39 40 int cols() const { return m_cols; } 41 int rows() const { return m_rows; } 42 43 bool shouldWrapText() const { return m_wrap != NoWrap; } 44 45 virtual String value() const OVERRIDE; 46 void setValue(const String&, TextFieldEventBehavior = DispatchNoEvent); 47 String defaultValue() const; 48 void setDefaultValue(const String&); 49 int textLength() const { return value().length(); } 50 int maxLength() const; 51 void setMaxLength(int, ExceptionState&); 52 53 String suggestedValue() const; 54 void setSuggestedValue(const String&); 55 56 // For ValidityState 57 virtual String validationMessage() const OVERRIDE; 58 virtual bool valueMissing() const OVERRIDE; 59 virtual bool tooLong() const OVERRIDE; 60 bool isValidValue(const String&) const; 61 62 void setCols(int); 63 void setRows(int); 64 65private: 66 HTMLTextAreaElement(Document&, HTMLFormElement*); 67 68 enum WrapMethod { NoWrap, SoftWrap, HardWrap }; 69 enum SetValueCommonOption { 70 NotSetSelection, 71 SetSeletion 72 }; 73 74 virtual void didAddUserAgentShadowRoot(ShadowRoot&) OVERRIDE; 75 // FIXME: Author shadows should be allowed 76 // https://bugs.webkit.org/show_bug.cgi?id=92608 77 virtual bool areAuthorShadowsAllowed() const OVERRIDE { return false; } 78 79 void handleBeforeTextInsertedEvent(BeforeTextInsertedEvent*) const; 80 static String sanitizeUserInputValue(const String&, unsigned maxLength); 81 void updateValue() const; 82 virtual void setInnerEditorValue(const String&) OVERRIDE; 83 void setNonDirtyValue(const String&); 84 void setValueCommon(const String&, TextFieldEventBehavior, SetValueCommonOption = NotSetSelection); 85 86 virtual bool supportsPlaceholder() const OVERRIDE { return true; } 87 virtual void updatePlaceholderText() OVERRIDE; 88 virtual bool isEmptyValue() const OVERRIDE { return value().isEmpty(); } 89 virtual bool isEmptySuggestedValue() const OVERRIDE FINAL { return suggestedValue().isEmpty(); } 90 91 virtual bool isOptionalFormControl() const OVERRIDE { return !isRequiredFormControl(); } 92 virtual bool isRequiredFormControl() const OVERRIDE { return isRequired(); } 93 94 virtual void defaultEventHandler(Event*) OVERRIDE; 95 virtual void handleFocusEvent(Element* oldFocusedNode, FocusType) OVERRIDE; 96 97 virtual void subtreeHasChanged() OVERRIDE; 98 99 virtual bool isEnumeratable() const OVERRIDE { return true; } 100 virtual bool isInteractiveContent() const OVERRIDE; 101 virtual bool supportsAutofocus() const OVERRIDE; 102 virtual bool supportLabels() const OVERRIDE { return true; } 103 104 virtual const AtomicString& formControlType() const OVERRIDE; 105 106 virtual FormControlState saveFormControlState() const OVERRIDE; 107 virtual void restoreFormControlState(const FormControlState&) OVERRIDE; 108 109 virtual bool isTextFormControl() const OVERRIDE { return true; } 110 111 virtual void childrenChanged(const ChildrenChange&) OVERRIDE; 112 virtual void parseAttribute(const QualifiedName&, const AtomicString&) OVERRIDE; 113 virtual bool isPresentationAttribute(const QualifiedName&) const OVERRIDE; 114 virtual void collectStyleForPresentationAttribute(const QualifiedName&, const AtomicString&, MutableStylePropertySet*) OVERRIDE; 115 virtual RenderObject* createRenderer(RenderStyle*) OVERRIDE; 116 virtual bool appendFormData(FormDataList&, bool) OVERRIDE; 117 virtual void resetImpl() OVERRIDE; 118 virtual bool hasCustomFocusLogic() const OVERRIDE; 119 virtual bool shouldShowFocusRingOnMouseFocus() const OVERRIDE; 120 virtual bool isKeyboardFocusable() const OVERRIDE; 121 virtual void updateFocusAppearance(bool restorePreviousSelection) OVERRIDE; 122 123 virtual void accessKeyAction(bool sendMouseEvents) OVERRIDE; 124 125 virtual bool matchesReadOnlyPseudoClass() const OVERRIDE; 126 virtual bool matchesReadWritePseudoClass() const OVERRIDE; 127 128 // If the String* argument is 0, apply this->value(). 129 bool valueMissing(const String*) const; 130 bool tooLong(const String*, NeedsToCheckDirtyFlag) const; 131 132 int m_rows; 133 int m_cols; 134 WrapMethod m_wrap; 135 mutable String m_value; 136 mutable bool m_isDirty; 137 bool m_valueIsUpToDate; 138 String m_suggestedValue; 139}; 140 141} // namespace blink 142 143#endif // HTMLTextAreaElement_h 144