Upstream version 7.36.149.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 WebCore {
30
31 class BeforeTextInsertedEvent;
32 class ExceptionState;
33 class VisibleSelection;
34
35 class HTMLTextAreaElement FINAL : public HTMLTextFormControlElement {
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     void setMaxLength(int, ExceptionState&);
51
52     String suggestedValue() const;
53     void setSuggestedValue(const String&);
54
55     // For ValidityState
56     virtual String validationMessage() const OVERRIDE;
57     virtual bool valueMissing() const OVERRIDE;
58     virtual bool tooLong() const OVERRIDE;
59     bool isValidValue(const String&) const;
60
61     void setCols(int);
62     void setRows(int);
63
64 private:
65     HTMLTextAreaElement(Document&, HTMLFormElement*);
66
67     enum WrapMethod { NoWrap, SoftWrap, HardWrap };
68
69     virtual void didAddUserAgentShadowRoot(ShadowRoot&) OVERRIDE;
70     // FIXME: Author shadows should be allowed
71     // https://bugs.webkit.org/show_bug.cgi?id=92608
72     virtual bool areAuthorShadowsAllowed() const OVERRIDE { return false; }
73
74     void handleBeforeTextInsertedEvent(BeforeTextInsertedEvent*) const;
75     static String sanitizeUserInputValue(const String&, unsigned maxLength);
76     void updateValue() const;
77     virtual void setInnerTextValue(const String&) OVERRIDE;
78     void setNonDirtyValue(const String&);
79     void setValueCommon(const String&, TextFieldEventBehavior);
80
81     virtual bool supportsPlaceholder() const OVERRIDE { return true; }
82     virtual void updatePlaceholderText() OVERRIDE;
83     virtual bool isEmptyValue() const OVERRIDE { return value().isEmpty(); }
84     virtual bool isEmptySuggestedValue() const OVERRIDE FINAL { return suggestedValue().isEmpty(); }
85
86     virtual bool isOptionalFormControl() const OVERRIDE { return !isRequiredFormControl(); }
87     virtual bool isRequiredFormControl() const OVERRIDE { return isRequired(); }
88
89     virtual void defaultEventHandler(Event*) OVERRIDE;
90     virtual void handleFocusEvent(Element* oldFocusedNode, FocusType) OVERRIDE;
91
92     virtual void subtreeHasChanged() OVERRIDE;
93
94     virtual bool isEnumeratable() const OVERRIDE { return true; }
95     virtual bool isInteractiveContent() const OVERRIDE;
96     virtual bool supportsAutofocus() const OVERRIDE;
97     virtual bool supportLabels() const OVERRIDE { return true; }
98
99     virtual const AtomicString& formControlType() const OVERRIDE;
100
101     virtual FormControlState saveFormControlState() const OVERRIDE;
102     virtual void restoreFormControlState(const FormControlState&) OVERRIDE;
103
104     virtual bool isTextFormControl() const OVERRIDE { return true; }
105
106     virtual void childrenChanged(bool changedByParser = false, Node* beforeChange = 0, Node* afterChange = 0, int childCountDelta = 0) OVERRIDE;
107     virtual void parseAttribute(const QualifiedName&, const AtomicString&) OVERRIDE;
108     virtual bool isPresentationAttribute(const QualifiedName&) const OVERRIDE;
109     virtual void collectStyleForPresentationAttribute(const QualifiedName&, const AtomicString&, MutableStylePropertySet*) OVERRIDE;
110     virtual RenderObject* createRenderer(RenderStyle*) OVERRIDE;
111     virtual bool appendFormData(FormDataList&, bool) OVERRIDE;
112     virtual void resetImpl() OVERRIDE;
113     virtual bool hasCustomFocusLogic() const OVERRIDE;
114     virtual bool shouldShowFocusRingOnMouseFocus() const OVERRIDE;
115     virtual bool isKeyboardFocusable() const OVERRIDE;
116     virtual void updateFocusAppearance(bool restorePreviousSelection) OVERRIDE;
117
118     virtual void accessKeyAction(bool sendMouseEvents) OVERRIDE;
119
120     virtual bool shouldUseInputMethod() OVERRIDE;
121     virtual bool matchesReadOnlyPseudoClass() const OVERRIDE;
122     virtual bool matchesReadWritePseudoClass() const OVERRIDE;
123
124     bool valueMissing(const String& value) const { return isRequiredFormControl() && !isDisabledOrReadOnly() && value.isEmpty(); }
125     bool tooLong(const String&, NeedsToCheckDirtyFlag) const;
126
127     int m_rows;
128     int m_cols;
129     WrapMethod m_wrap;
130     mutable String m_value;
131     mutable bool m_isDirty;
132     bool m_valueIsUpToDate;
133     String m_suggestedValue;
134 };
135
136 } //namespace
137
138 #endif