• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 PassRefPtr<HTMLTextAreaElement> create(Document&, HTMLFormElement*);
38 
cols()39     int cols() const { return m_cols; }
rows()40     int rows() const { return m_rows; }
41 
shouldWrapText()42     bool shouldWrapText() const { return m_wrap != NoWrap; }
43 
44     virtual String value() const;
45     void setValue(const String&);
46     String defaultValue() const;
47     void setDefaultValue(const String&);
textLength()48     int textLength() const { return value().length(); }
49     virtual int maxLength() const;
50     void setMaxLength(int, ExceptionState&);
51     // For ValidityState
52     virtual String validationMessage() const OVERRIDE;
53     virtual bool valueMissing() const OVERRIDE;
54     virtual bool tooLong() const OVERRIDE;
55     bool isValidValue(const String&) const;
56 
57     void rendererWillBeDestroyed();
58 
59     void setCols(int);
60     void setRows(int);
61 
62 private:
63     HTMLTextAreaElement(Document&, HTMLFormElement*);
64 
65     enum WrapMethod { NoWrap, SoftWrap, HardWrap };
66 
67     virtual void didAddUserAgentShadowRoot(ShadowRoot&) OVERRIDE;
68     // FIXME: Author shadows should be allowed
69     // https://bugs.webkit.org/show_bug.cgi?id=92608
areAuthorShadowsAllowed()70     virtual bool areAuthorShadowsAllowed() const OVERRIDE { return false; }
71 
72     void handleBeforeTextInsertedEvent(BeforeTextInsertedEvent*) const;
73     static String sanitizeUserInputValue(const String&, unsigned maxLength);
74     void updateValue() const;
75     void setNonDirtyValue(const String&);
76     void setValueCommon(const String&);
77 
supportsPlaceholder()78     virtual bool supportsPlaceholder() const { return true; }
79     virtual void updatePlaceholderText();
isEmptyValue()80     virtual bool isEmptyValue() const { return value().isEmpty(); }
81 
isOptionalFormControl()82     virtual bool isOptionalFormControl() const { return !isRequiredFormControl(); }
isRequiredFormControl()83     virtual bool isRequiredFormControl() const { return isRequired(); }
84 
85     virtual void defaultEventHandler(Event*);
86     virtual void handleFocusEvent(Element* oldFocusedNode, FocusDirection) OVERRIDE;
87 
88     virtual void subtreeHasChanged();
89 
isEnumeratable()90     virtual bool isEnumeratable() const { return true; }
91     virtual bool isInteractiveContent() const OVERRIDE;
supportLabels()92     virtual bool supportLabels() const OVERRIDE { return true; }
93 
94     virtual const AtomicString& formControlType() const;
95 
96     virtual FormControlState saveFormControlState() const OVERRIDE;
97     virtual void restoreFormControlState(const FormControlState&) OVERRIDE;
98 
isTextFormControl()99     virtual bool isTextFormControl() const { return true; }
100 
101     virtual void childrenChanged(bool changedByParser = false, Node* beforeChange = 0, Node* afterChange = 0, int childCountDelta = 0);
102     virtual void parseAttribute(const QualifiedName&, const AtomicString&) OVERRIDE;
103     virtual bool isPresentationAttribute(const QualifiedName&) const OVERRIDE;
104     virtual void collectStyleForPresentationAttribute(const QualifiedName&, const AtomicString&, MutableStylePropertySet*) OVERRIDE;
105     virtual RenderObject* createRenderer(RenderStyle*);
106     virtual bool appendFormData(FormDataList&, bool);
107     virtual void resetImpl() OVERRIDE;
108     virtual bool hasCustomFocusLogic() const OVERRIDE;
109     virtual bool shouldShowFocusRingOnMouseFocus() const OVERRIDE;
110     virtual bool isKeyboardFocusable() const OVERRIDE;
111     virtual void updateFocusAppearance(bool restorePreviousSelection);
112 
113     virtual void accessKeyAction(bool sendMouseEvents);
114 
115     virtual bool shouldUseInputMethod();
116     virtual bool matchesReadOnlyPseudoClass() const OVERRIDE;
117     virtual bool matchesReadWritePseudoClass() const OVERRIDE;
118 
valueMissing(const String & value)119     bool valueMissing(const String& value) const { return isRequiredFormControl() && !isDisabledOrReadOnly() && value.isEmpty(); }
120     bool tooLong(const String&, NeedsToCheckDirtyFlag) const;
121 
122     int m_rows;
123     int m_cols;
124     WrapMethod m_wrap;
125     mutable String m_value;
126     mutable bool m_isDirty;
127 };
128 
isHTMLTextAreaElement(const Node * node)129 inline bool isHTMLTextAreaElement(const Node* node)
130 {
131     return node->hasTagName(HTMLNames::textareaTag);
132 }
133 
isHTMLTextAreaElement(const Element * element)134 inline bool isHTMLTextAreaElement(const Element* element)
135 {
136     return element->hasTagName(HTMLNames::textareaTag);
137 }
138 
139 DEFINE_NODE_TYPE_CASTS(HTMLTextAreaElement, hasTagName(HTMLNames::textareaTag));
140 
141 } //namespace
142 
143 #endif
144