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; 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; 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 HTMLElement* innerTextElement() const; 57 58 void rendererWillBeDestroyed(); 59 60 void setCols(int); 61 void setRows(int); 62 63private: 64 HTMLTextAreaElement(const QualifiedName&, Document*, HTMLFormElement*); 65 66 enum WrapMethod { NoWrap, SoftWrap, HardWrap }; 67 68 virtual void didAddUserAgentShadowRoot(ShadowRoot*) OVERRIDE; 69 virtual bool areAuthorShadowsAllowed() const OVERRIDE { return false; } 70 71 void handleBeforeTextInsertedEvent(BeforeTextInsertedEvent*) const; 72 static String sanitizeUserInputValue(const String&, unsigned maxLength); 73 void updateValue() const; 74 void setNonDirtyValue(const String&); 75 void setValueCommon(const String&); 76 77 virtual bool supportsPlaceholder() const { return true; } 78 virtual HTMLElement* placeholderElement() const; 79 virtual void updatePlaceholderText(); 80 virtual bool isEmptyValue() const { return value().isEmpty(); } 81 82 virtual bool isOptionalFormControl() const { return !isRequiredFormControl(); } 83 virtual bool isRequiredFormControl() const { return isRequired(); } 84 85 virtual void defaultEventHandler(Event*); 86 87 virtual void subtreeHasChanged(); 88 89 virtual bool isEnumeratable() const { return true; } 90 virtual bool supportLabels() const OVERRIDE { return true; } 91 92 virtual const AtomicString& formControlType() const; 93 94 virtual FormControlState saveFormControlState() const OVERRIDE; 95 virtual void restoreFormControlState(const FormControlState&) OVERRIDE; 96 97 virtual bool isTextFormControl() const { return true; } 98 99 virtual void childrenChanged(bool changedByParser = false, Node* beforeChange = 0, Node* afterChange = 0, int childCountDelta = 0); 100 virtual void parseAttribute(const QualifiedName&, const AtomicString&) OVERRIDE; 101 virtual bool isPresentationAttribute(const QualifiedName&) const OVERRIDE; 102 virtual void collectStyleForPresentationAttribute(const QualifiedName&, const AtomicString&, MutableStylePropertySet*) OVERRIDE; 103 virtual RenderObject* createRenderer(RenderArena*, RenderStyle*); 104 virtual bool appendFormData(FormDataList&, bool); 105 virtual void reset(); 106 virtual bool hasCustomFocusLogic() const OVERRIDE; 107 virtual bool isMouseFocusable() const OVERRIDE; 108 virtual bool isKeyboardFocusable(KeyboardEvent*) const OVERRIDE; 109 virtual void updateFocusAppearance(bool restorePreviousSelection); 110 111 virtual void accessKeyAction(bool sendMouseEvents); 112 113 virtual bool shouldUseInputMethod() OVERRIDE; 114 virtual void attach(const AttachContext& = AttachContext()) 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 130inline bool isHTMLTextAreaElement(Node* node) 131{ 132 return node->hasTagName(HTMLNames::textareaTag); 133} 134 135} //namespace 136 137#endif 138