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 "HTMLTextFormControlElement.h"
28
29namespace WebCore {
30
31class BeforeTextInsertedEvent;
32class VisibleSelection;
33
34class HTMLTextAreaElement final : public HTMLTextFormControlElement {
35public:
36    static PassRefPtr<HTMLTextAreaElement> create(const QualifiedName&, Document&, HTMLFormElement*);
37
38    int cols() const { return m_cols; }
39    int rows() const { return m_rows; }
40
41    bool shouldWrapText() const { return m_wrap != NoWrap; }
42
43    virtual String value() const override;
44    void setValue(const String&);
45    String defaultValue() const;
46    void setDefaultValue(const String&);
47    int textLength() const { return value().length(); }
48    virtual int maxLength() const override;
49    void setMaxLength(int, ExceptionCode&);
50    // For ValidityState
51    virtual String validationMessage() const override;
52    virtual bool valueMissing() const override;
53    virtual bool tooLong() const override;
54    bool isValidValue(const String&) const;
55
56    virtual TextControlInnerTextElement* innerTextElement() const override;
57
58    void rendererWillBeDestroyed();
59
60    void setCols(int);
61    void setRows(int);
62
63    virtual bool willRespondToMouseClickEvents() override;
64
65private:
66    HTMLTextAreaElement(const QualifiedName&, Document&, HTMLFormElement*);
67
68    enum WrapMethod { NoWrap, SoftWrap, HardWrap };
69
70    virtual void didAddUserAgentShadowRoot(ShadowRoot*) override;
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
78    virtual bool supportsPlaceholder() const override { return true; }
79    virtual HTMLElement* placeholderElement() const override;
80    virtual void updatePlaceholderText() override;
81    virtual bool isEmptyValue() const override { return value().isEmpty(); }
82
83    virtual bool isOptionalFormControl() const override { return !isRequiredFormControl(); }
84    virtual bool isRequiredFormControl() const override { return isRequired(); }
85
86    virtual void defaultEventHandler(Event*) override;
87
88    virtual void subtreeHasChanged() override;
89
90    virtual bool isEnumeratable() const override { return true; }
91    virtual bool supportLabels() const override { return true; }
92
93    virtual const AtomicString& formControlType() const override;
94
95    virtual FormControlState saveFormControlState() const override;
96    virtual void restoreFormControlState(const FormControlState&) override;
97
98    virtual bool isTextFormControl() const override { return true; }
99
100    virtual void childrenChanged(const ChildChange&) override;
101    virtual void parseAttribute(const QualifiedName&, const AtomicString&) override;
102    virtual bool isPresentationAttribute(const QualifiedName&) const override;
103    virtual void collectStyleForPresentationAttribute(const QualifiedName&, const AtomicString&, MutableStyleProperties&) override;
104    virtual RenderPtr<RenderElement> createElementRenderer(PassRef<RenderStyle>) override;
105    virtual bool appendFormData(FormDataList&, bool) override;
106    virtual void reset() override;
107    virtual bool hasCustomFocusLogic() const override;
108    virtual bool isMouseFocusable() const override;
109    virtual bool isKeyboardFocusable(KeyboardEvent*) const override;
110    virtual void updateFocusAppearance(bool restorePreviousSelection) override;
111
112    virtual void accessKeyAction(bool sendMouseEvents) override;
113
114    virtual bool shouldUseInputMethod() override;
115    virtual bool matchesReadOnlyPseudoClass() const override;
116    virtual bool matchesReadWritePseudoClass() const override;
117
118    bool valueMissing(const String& value) const { return isRequiredFormControl() && !isDisabledOrReadOnly() && value.isEmpty(); }
119    bool tooLong(const String&, NeedsToCheckDirtyFlag) const;
120
121    int m_rows;
122    int m_cols;
123    WrapMethod m_wrap;
124    HTMLElement* m_placeholder;
125    mutable String m_value;
126    mutable bool m_isDirty;
127    mutable bool m_wasModifiedByUser;
128};
129
130NODE_TYPE_CASTS(HTMLTextAreaElement)
131
132} //namespace
133
134#endif
135