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 THIRD_PARTY_BLINK_RENDERER_CORE_HTML_FORMS_HTML_TEXT_AREA_ELEMENT_H_ 25 #define THIRD_PARTY_BLINK_RENDERER_CORE_HTML_FORMS_HTML_TEXT_AREA_ELEMENT_H_ 26 27 #include "base/gtest_prod_util.h" 28 #include "third_party/blink/renderer/core/core_export.h" 29 #include "third_party/blink/renderer/core/html/forms/text_control_element.h" 30 31 namespace blink { 32 33 class BeforeTextInsertedEvent; 34 35 class CORE_EXPORT HTMLTextAreaElement final : public TextControlElement { 36 DEFINE_WRAPPERTYPEINFO(); 37 38 public: 39 explicit HTMLTextAreaElement(Document&); 40 cols()41 unsigned cols() const { return cols_; } rows()42 unsigned rows() const { return rows_; } 43 ShouldWrapText()44 bool ShouldWrapText() const { return wrap_ != kNoWrap; } 45 46 String value() const override; 47 void setValue( 48 const String&, 49 TextFieldEventBehavior = TextFieldEventBehavior::kDispatchNoEvent, 50 TextControlSetValueSelection = 51 TextControlSetValueSelection::kSetSelectionToEnd) override; 52 String defaultValue() const; 53 void setDefaultValue(const String&); textLength()54 int textLength() const { return value().length(); } 55 56 void SetSuggestedValue(const String& value) override; 57 58 // For ValidityState 59 String validationMessage() const override; 60 bool ValueMissing() const override; 61 bool TooLong() const override; 62 bool TooShort() const override; 63 bool IsValidValue(const String&) const; 64 65 void setCols(unsigned); 66 void setRows(unsigned); 67 68 private: 69 FRIEND_TEST_ALL_PREFIXES(HTMLTextAreaElementTest, SanitizeUserInputValue); 70 71 enum WrapMethod { kNoWrap, kSoftWrap, kHardWrap }; 72 73 void DidAddUserAgentShadowRoot(ShadowRoot&) override; 74 // FIXME: Author shadows should be allowed 75 // https://bugs.webkit.org/show_bug.cgi?id=92608 AreAuthorShadowsAllowed()76 bool AreAuthorShadowsAllowed() const override { return false; } 77 78 void HandleBeforeTextInsertedEvent(BeforeTextInsertedEvent*) const; 79 static String SanitizeUserInputValue(const String&, unsigned max_length); 80 void UpdateValue(); 81 void SetNonDirtyValue(const String&, TextControlSetValueSelection); 82 void SetValueCommon(const String&, 83 TextFieldEventBehavior, 84 TextControlSetValueSelection); 85 IsPlaceholderVisible()86 bool IsPlaceholderVisible() const override { return is_placeholder_visible_; } 87 void SetPlaceholderVisibility(bool) override; SupportsPlaceholder()88 bool SupportsPlaceholder() const override { return true; } 89 String GetPlaceholderValue() const final; 90 void UpdatePlaceholderText() override; IsEmptyValue()91 bool IsEmptyValue() const override { return value().IsEmpty(); } 92 IsOptionalFormControl()93 bool IsOptionalFormControl() const override { 94 return !IsRequiredFormControl(); 95 } IsRequiredFormControl()96 bool IsRequiredFormControl() const override { return IsRequired(); } 97 98 void DefaultEventHandler(Event&) override; 99 100 void SubtreeHasChanged() override; 101 IsEnumeratable()102 bool IsEnumeratable() const override { return true; } 103 bool IsInteractiveContent() const override; IsLabelable()104 bool IsLabelable() const override { return true; } 105 106 const AtomicString& FormControlType() const override; 107 108 FormControlState SaveFormControlState() const override; 109 void RestoreFormControlState(const FormControlState&) override; 110 IsTextControl()111 bool IsTextControl() const override { return true; } 112 113 void ChildrenChanged(const ChildrenChange&) override; 114 void ParseAttribute(const AttributeModificationParams&) override; 115 bool IsPresentationAttribute(const QualifiedName&) const override; 116 void CollectStyleForPresentationAttribute( 117 const QualifiedName&, 118 const AtomicString&, 119 MutableCSSPropertyValueSet*) override; TypeShouldForceLegacyLayout()120 bool TypeShouldForceLegacyLayout() const override { return true; } 121 LayoutObject* CreateLayoutObject(const ComputedStyle&, LegacyLayout) override; 122 void AppendToFormData(FormData&) override; 123 void ResetImpl() override; 124 bool HasCustomFocusLogic() const override; 125 bool MayTriggerVirtualKeyboard() const override; 126 bool IsKeyboardFocusable() const override; 127 void UpdateFocusAppearanceWithOptions(SelectionBehaviorOnFocus, 128 const FocusOptions*) override; 129 130 void AccessKeyAction(bool send_mouse_events) override; 131 132 bool MatchesReadOnlyPseudoClass() const override; 133 bool MatchesReadWritePseudoClass() const override; 134 void CloneNonAttributePropertiesFrom(const Element&, CloneChildrenFlag) final; 135 136 // If the String* argument is 0, apply value(). 137 bool ValueMissing(const String*) const; 138 bool TooLong(const String*, NeedsToCheckDirtyFlag) const; 139 bool TooShort(const String*, NeedsToCheckDirtyFlag) const; 140 141 unsigned rows_; 142 unsigned cols_; 143 WrapMethod wrap_; 144 mutable String value_; 145 mutable bool is_dirty_; 146 unsigned is_placeholder_visible_ : 1; 147 }; 148 149 } // namespace blink 150 151 #endif // THIRD_PARTY_BLINK_RENDERER_CORE_HTML_FORMS_HTML_TEXT_AREA_ELEMENT_H_ 152