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 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 "HTMLFormControlElement.h" 28 29 namespace WebCore { 30 31 class BeforeTextInsertedEvent; 32 class VisibleSelection; 33 34 class HTMLTextAreaElement : public HTMLTextFormControlElement { 35 public: 36 HTMLTextAreaElement(const QualifiedName&, Document*, HTMLFormElement* = 0); 37 checkDTD(const Node * newChild)38 virtual bool checkDTD(const Node* newChild) { return newChild->isTextNode(); } 39 cols()40 int cols() const { return m_cols; } rows()41 int rows() const { return m_rows; } 42 shouldWrapText()43 bool shouldWrapText() const { return m_wrap != NoWrap; } 44 isEnumeratable()45 virtual bool isEnumeratable() const { return true; } 46 47 virtual const AtomicString& formControlType() const; 48 49 virtual bool saveFormControlState(String& value) const; 50 virtual void restoreFormControlState(const String&); 51 readOnly()52 bool readOnly() const { return isReadOnlyFormControl(); } 53 isTextFormControl()54 virtual bool isTextFormControl() const { return true; } 55 valueMissing()56 virtual bool valueMissing() const { return isRequiredFormControl() && !disabled() && !readOnly() && value().isEmpty(); } 57 58 virtual void childrenChanged(bool changedByParser = false, Node* beforeChange = 0, Node* afterChange = 0, int childCountDelta = 0); 59 virtual void parseMappedAttribute(MappedAttribute*); 60 virtual RenderObject* createRenderer(RenderArena*, RenderStyle*); 61 virtual bool appendFormData(FormDataList&, bool); 62 virtual void reset(); 63 virtual void defaultEventHandler(Event*); 64 virtual bool isMouseFocusable() const; 65 virtual bool isKeyboardFocusable(KeyboardEvent*) const; 66 virtual void updateFocusAppearance(bool restorePreviousSelection); 67 68 String value() const; 69 void setValue(const String&); 70 String defaultValue() const; 71 void setDefaultValue(const String&); textLength()72 int textLength() const { return value().length(); } 73 int maxLength() const; 74 void setMaxLength(int, ExceptionCode&); 75 virtual bool tooLong() const; 76 77 void rendererWillBeDestroyed(); 78 79 virtual void accessKeyAction(bool sendToAnyElement); 80 81 const AtomicString& accessKey() const; 82 void setAccessKey(const String&); 83 84 void setCols(int); 85 void setRows(int); 86 cacheSelection(int s,int e)87 void cacheSelection(int s, int e) { m_cachedSelectionStart = s; m_cachedSelectionEnd = e; }; 88 89 virtual bool shouldUseInputMethod() const; 90 91 private: 92 enum WrapMethod { NoWrap, SoftWrap, HardWrap }; 93 94 void handleBeforeTextInsertedEvent(BeforeTextInsertedEvent*) const; 95 static String sanitizeUserInputValue(const String&, unsigned maxLength); 96 void updateValue() const; 97 void setNonDirtyValue(const String&); 98 supportsPlaceholder()99 virtual bool supportsPlaceholder() const { return true; } isEmptyValue()100 virtual bool isEmptyValue() const { return value().isEmpty(); } cachedSelectionStart()101 virtual int cachedSelectionStart() const { return m_cachedSelectionStart; } cachedSelectionEnd()102 virtual int cachedSelectionEnd() const { return m_cachedSelectionEnd; } 103 isOptionalFormControl()104 virtual bool isOptionalFormControl() const { return !isRequiredFormControl(); } isRequiredFormControl()105 virtual bool isRequiredFormControl() const { return required(); } 106 107 int m_rows; 108 int m_cols; 109 WrapMethod m_wrap; 110 mutable String m_value; 111 int m_cachedSelectionStart; 112 int m_cachedSelectionEnd; 113 mutable bool m_isDirty; 114 }; 115 116 } //namespace 117 118 #endif 119