Update To 11.40.268.0
[platform/framework/web/crosswalk.git] / src / third_party / WebKit / Source / core / html / HTMLTextAreaElement.h
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
29 namespace blink {
30
31 class BeforeTextInsertedEvent;
32 class ExceptionState;
33
34 class HTMLTextAreaElement final : public HTMLTextFormControlElement {
35     DEFINE_WRAPPERTYPEINFO();
36 public:
37     static PassRefPtrWillBeRawPtr<HTMLTextAreaElement> create(Document&, HTMLFormElement*);
38
39     int cols() const { return m_cols; }
40     int rows() const { return m_rows; }
41
42     bool shouldWrapText() const { return m_wrap != NoWrap; }
43
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&);
53
54     String suggestedValue() const;
55     void setSuggestedValue(const String&);
56
57     // For ValidityState
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;
63
64     void setCols(int);
65     void setRows(int);
66
67 private:
68     HTMLTextAreaElement(Document&, HTMLFormElement*);
69
70     enum WrapMethod { NoWrap, SoftWrap, HardWrap };
71     enum SetValueCommonOption {
72         NotSetSelection,
73         SetSeletion
74     };
75
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; }
80
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);
87
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(); }
92
93     virtual bool isOptionalFormControl() const override { return !isRequiredFormControl(); }
94     virtual bool isRequiredFormControl() const override { return isRequired(); }
95
96     virtual void defaultEventHandler(Event*) override;
97     virtual void handleFocusEvent(Element* oldFocusedNode, FocusType) override;
98
99     virtual void subtreeHasChanged() override;
100
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; }
105
106     virtual const AtomicString& formControlType() const override;
107
108     virtual FormControlState saveFormControlState() const override;
109     virtual void restoreFormControlState(const FormControlState&) override;
110
111     virtual bool isTextFormControl() const override { return true; }
112
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;
124
125     virtual void accessKeyAction(bool sendMouseEvents) override;
126
127     virtual bool matchesReadOnlyPseudoClass() const override;
128     virtual bool matchesReadWritePseudoClass() const override;
129
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;
134
135     int m_rows;
136     int m_cols;
137     WrapMethod m_wrap;
138     mutable String m_value;
139     mutable bool m_isDirty;
140     bool m_valueIsUpToDate;
141     String m_suggestedValue;
142 };
143
144 } // namespace blink
145
146 #endif // HTMLTextAreaElement_h