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.
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.
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.
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.
24 #ifndef HTMLTextAreaElement_h
25 #define HTMLTextAreaElement_h
27 #include "core/html/HTMLTextFormControlElement.h"
31 class BeforeTextInsertedEvent;
34 class HTMLTextAreaElement final : public HTMLTextFormControlElement {
35 DEFINE_WRAPPERTYPEINFO();
37 static PassRefPtrWillBeRawPtr<HTMLTextAreaElement> create(Document&, HTMLFormElement*);
39 int cols() const { return m_cols; }
40 int rows() const { return m_rows; }
42 bool shouldWrapText() const { return m_wrap != NoWrap; }
44 virtual String value() const override;
45 void setValue(const String&, TextFieldEventBehavior = DispatchNoEvent);
46 String defaultValue() const;
47 void setDefaultValue(const String&);
48 int textLength() const { return value().length(); }
49 int maxLength() const;
50 int minLength() const;
51 void setMaxLength(int, ExceptionState&);
52 void setMinLength(int, ExceptionState&);
54 String suggestedValue() const;
55 void setSuggestedValue(const String&);
58 virtual String validationMessage() const override;
59 virtual bool valueMissing() const override;
60 virtual bool tooLong() const override;
61 virtual bool tooShort() const override;
62 bool isValidValue(const String&) const;
68 HTMLTextAreaElement(Document&, HTMLFormElement*);
70 enum WrapMethod { NoWrap, SoftWrap, HardWrap };
71 enum SetValueCommonOption {
76 virtual void didAddUserAgentShadowRoot(ShadowRoot&) override;
77 // FIXME: Author shadows should be allowed
78 // https://bugs.webkit.org/show_bug.cgi?id=92608
79 virtual bool areAuthorShadowsAllowed() const override { return false; }
81 void handleBeforeTextInsertedEvent(BeforeTextInsertedEvent*) const;
82 static String sanitizeUserInputValue(const String&, unsigned maxLength);
83 void updateValue() const;
84 virtual void setInnerEditorValue(const String&) override;
85 void setNonDirtyValue(const String&);
86 void setValueCommon(const String&, TextFieldEventBehavior, SetValueCommonOption = NotSetSelection);
88 virtual bool supportsPlaceholder() const override { return true; }
89 virtual void updatePlaceholderText() override;
90 virtual bool isEmptyValue() const override { return value().isEmpty(); }
91 virtual bool isEmptySuggestedValue() const override final { return suggestedValue().isEmpty(); }
93 virtual bool isOptionalFormControl() const override { return !isRequiredFormControl(); }
94 virtual bool isRequiredFormControl() const override { return isRequired(); }
96 virtual void defaultEventHandler(Event*) override;
97 virtual void handleFocusEvent(Element* oldFocusedNode, FocusType) override;
99 virtual void subtreeHasChanged() override;
101 virtual bool isEnumeratable() const override { return true; }
102 virtual bool isInteractiveContent() const override;
103 virtual bool supportsAutofocus() const override;
104 virtual bool supportLabels() const override { return true; }
106 virtual const AtomicString& formControlType() const override;
108 virtual FormControlState saveFormControlState() const override;
109 virtual void restoreFormControlState(const FormControlState&) override;
111 virtual bool isTextFormControl() const override { return true; }
113 virtual void childrenChanged(const ChildrenChange&) override;
114 virtual void parseAttribute(const QualifiedName&, const AtomicString&) override;
115 virtual bool isPresentationAttribute(const QualifiedName&) const override;
116 virtual void collectStyleForPresentationAttribute(const QualifiedName&, const AtomicString&, MutableStylePropertySet*) override;
117 virtual RenderObject* createRenderer(RenderStyle*) override;
118 virtual bool appendFormData(FormDataList&, bool) override;
119 virtual void resetImpl() override;
120 virtual bool hasCustomFocusLogic() const override;
121 virtual bool shouldShowFocusRingOnMouseFocus() const override;
122 virtual bool isKeyboardFocusable() const override;
123 virtual void updateFocusAppearance(bool restorePreviousSelection) override;
125 virtual void accessKeyAction(bool sendMouseEvents) override;
127 virtual bool matchesReadOnlyPseudoClass() const override;
128 virtual bool matchesReadWritePseudoClass() const override;
130 // If the String* argument is 0, apply this->value().
131 bool valueMissing(const String*) const;
132 bool tooLong(const String*, NeedsToCheckDirtyFlag) const;
133 bool tooShort(const String*, NeedsToCheckDirtyFlag) const;
138 mutable String m_value;
139 mutable bool m_isDirty;
140 bool m_valueIsUpToDate;
141 String m_suggestedValue;
146 #endif // HTMLTextAreaElement_h