1 /* 2 * Copyright (C) 1999 Lars Knoll (knoll (at) kde.org) 3 * (C) 1999 Antti Koivisto (koivisto (at) kde.org) 4 * (C) 2000 Dirk Mueller (mueller (at) 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 "HTMLFormControlElement.h" 28 29 namespace WebCore { 30 31 class BeforeTextInsertedEvent; 32 class VisibleSelection; 33 34 class HTMLTextAreaElement : public HTMLTextFormControlElement { 35 public: 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 bool valueMissing(const String& value) const { return isRequiredFormControl() && !disabled() && !readOnly() && value.isEmpty(); } 51 bool tooLong(const String&, NeedsToCheckDirtyFlag) const; 52 bool isValidValue(const String&) const; 53 54 void rendererWillBeDestroyed(); 55 56 void setCols(int); 57 void setRows(int); 58 59 bool lastChangeWasUserEdit() const; 60 61 void cacheSelection(int s, int e) { m_cachedSelectionStart = s; m_cachedSelectionEnd = e; }; 62 63 private: 64 HTMLTextAreaElement(const QualifiedName&, Document*, HTMLFormElement*); 65 66 enum WrapMethod { NoWrap, SoftWrap, HardWrap }; 67 68 void handleBeforeTextInsertedEvent(BeforeTextInsertedEvent*) const; 69 static String sanitizeUserInputValue(const String&, unsigned maxLength); 70 void updateValue() const; 71 void setNonDirtyValue(const String&); 72 void setValueCommon(const String&); 73 74 virtual bool supportsPlaceholder() const { return true; } 75 virtual bool isEmptyValue() const { return value().isEmpty(); } 76 virtual int cachedSelectionStart() const { return m_cachedSelectionStart; } 77 virtual int cachedSelectionEnd() const { return m_cachedSelectionEnd; } 78 79 virtual bool isOptionalFormControl() const { return !isRequiredFormControl(); } 80 virtual bool isRequiredFormControl() const { return required(); } 81 82 virtual void defaultEventHandler(Event*); 83 84 virtual bool isEnumeratable() const { return true; } 85 86 virtual const AtomicString& formControlType() const; 87 88 virtual bool saveFormControlState(String& value) const; 89 virtual void restoreFormControlState(const String&); 90 91 virtual bool isTextFormControl() const { return true; } 92 93 virtual void childrenChanged(bool changedByParser = false, Node* beforeChange = 0, Node* afterChange = 0, int childCountDelta = 0); 94 virtual void parseMappedAttribute(Attribute*); 95 virtual RenderObject* createRenderer(RenderArena*, RenderStyle*); 96 virtual bool appendFormData(FormDataList&, bool); 97 virtual void reset(); 98 virtual bool isMouseFocusable() const; 99 virtual bool isKeyboardFocusable(KeyboardEvent*) const; 100 virtual void updateFocusAppearance(bool restorePreviousSelection); 101 102 virtual void accessKeyAction(bool sendToAnyElement); 103 104 virtual bool shouldUseInputMethod() const; 105 106 int m_rows; 107 int m_cols; 108 WrapMethod m_wrap; 109 mutable String m_value; 110 int m_cachedSelectionStart; 111 int m_cachedSelectionEnd; 112 mutable bool m_isDirty; 113 }; 114 115 } //namespace 116 117 #endif 118