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#pragma once
25
26#include "HTMLTextFormControlElement.h"
27
28namespace WebCore {
29
30class BeforeTextInsertedEvent;
31class RenderTextControlMultiLine;
32class VisibleSelection;
33
34class HTMLTextAreaElement final : public HTMLTextFormControlElement {
35 WTF_MAKE_ISO_ALLOCATED(HTMLTextAreaElement);
36public:
37 static Ref<HTMLTextAreaElement> create(const QualifiedName&, Document&, HTMLFormElement*);
38
39 unsigned cols() const { return m_cols; }
40 unsigned rows() const { return m_rows; }
41
42 bool shouldWrapText() const { return m_wrap != NoWrap; }
43
44 WEBCORE_EXPORT String value() const final;
45 WEBCORE_EXPORT void setValue(const String&);
46 WEBCORE_EXPORT String defaultValue() const;
47 WEBCORE_EXPORT void setDefaultValue(const String&);
48 int textLength() const { return value().length(); }
49 int effectiveMaxLength() const { return maxLength(); }
50 // For ValidityState
51 String validationMessage() const final;
52 bool valueMissing() const final;
53 bool tooShort() const final;
54 bool tooLong() const final;
55 bool isValidValue(const String&) const;
56
57 RefPtr<TextControlInnerTextElement> innerTextElement() const final;
58 RenderStyle createInnerTextStyle(const RenderStyle&) final;
59 void copyNonAttributePropertiesFromElement(const Element&) final;
60
61 void rendererWillBeDestroyed();
62
63 WEBCORE_EXPORT void setCols(unsigned);
64 WEBCORE_EXPORT void setRows(unsigned);
65
66 bool willRespondToMouseClickEvents() final;
67
68 RenderTextControlMultiLine* renderer() const;
69
70private:
71 HTMLTextAreaElement(const QualifiedName&, Document&, HTMLFormElement*);
72
73 enum WrapMethod { NoWrap, SoftWrap, HardWrap };
74
75 void didAddUserAgentShadowRoot(ShadowRoot&) final;
76
77 void maxLengthAttributeChanged(const AtomString& newValue);
78 void minLengthAttributeChanged(const AtomString& newValue);
79
80 void handleBeforeTextInsertedEvent(BeforeTextInsertedEvent&) const;
81 static String sanitizeUserInputValue(const String&, unsigned maxLength);
82 void updateValue() const;
83 void setNonDirtyValue(const String&);
84 void setValueCommon(const String&);
85
86 bool supportsPlaceholder() const final { return true; }
87 HTMLElement* placeholderElement() const final;
88 void updatePlaceholderText() final;
89 bool isEmptyValue() const final { return value().isEmpty(); }
90
91 bool isOptionalFormControl() const final { return !isRequiredFormControl(); }
92 bool isRequiredFormControl() const final { return isRequired(); }
93
94 void defaultEventHandler(Event&) final;
95
96 void subtreeHasChanged() final;
97
98 bool isEnumeratable() const final { return true; }
99 bool supportLabels() const final { return true; }
100
101 const AtomString& formControlType() const final;
102
103 FormControlState saveFormControlState() const final;
104 void restoreFormControlState(const FormControlState&) final;
105
106 bool isTextField() const final { return true; }
107
108 void childrenChanged(const ChildChange&) final;
109 void parseAttribute(const QualifiedName&, const AtomString&) final;
110 bool isPresentationAttribute(const QualifiedName&) const final;
111 void collectStyleForPresentationAttribute(const QualifiedName&, const AtomString&, MutableStyleProperties&) final;
112 RenderPtr<RenderElement> createElementRenderer(RenderStyle&&, const RenderTreePosition&) final;
113 bool appendFormData(DOMFormData&, bool) final;
114 void reset() final;
115 bool hasCustomFocusLogic() const final;
116 bool isMouseFocusable() const final;
117 bool isKeyboardFocusable(KeyboardEvent*) const final;
118 void updateFocusAppearance(SelectionRestorationMode, SelectionRevealMode) final;
119
120 void accessKeyAction(bool sendMouseEvents) final;
121
122 bool shouldUseInputMethod() final;
123 bool matchesReadWritePseudoClass() const final;
124
125 bool valueMissing(const String& value) const { return isRequiredFormControl() && !isDisabledOrReadOnly() && value.isEmpty(); }
126 bool tooShort(StringView, NeedsToCheckDirtyFlag) const;
127 bool tooLong(StringView, NeedsToCheckDirtyFlag) const;
128
129 unsigned m_rows;
130 unsigned m_cols;
131 WrapMethod m_wrap { SoftWrap };
132 RefPtr<HTMLElement> m_placeholder;
133 mutable String m_value;
134 mutable bool m_isDirty { false };
135 mutable bool m_wasModifiedByUser { false };
136};
137
138} //namespace
139