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 29namespace WebCore { 30 31class BeforeTextInsertedEvent; 32class VisibleSelection; 33 34class HTMLTextAreaElement : public HTMLTextFormControlElement { 35public: 36 HTMLTextAreaElement(const QualifiedName&, Document*, HTMLFormElement* = 0); 37 38 virtual bool checkDTD(const Node* newChild) { return newChild->isTextNode(); } 39 40 int cols() const { return m_cols; } 41 int rows() const { return m_rows; } 42 43 bool shouldWrapText() const { return m_wrap != NoWrap; } 44 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 52 bool readOnly() const { return isReadOnlyFormControl(); } 53 54 virtual bool isTextFormControl() const { return true; } 55 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&); 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 87 void cacheSelection(int s, int e) { m_cachedSelectionStart = s; m_cachedSelectionEnd = e; }; 88 89 virtual bool shouldUseInputMethod() const; 90 91private: 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 99 virtual bool supportsPlaceholder() const { return true; } 100 virtual bool isEmptyValue() const { return value().isEmpty(); } 101 virtual int cachedSelectionStart() const { return m_cachedSelectionStart; } 102 virtual int cachedSelectionEnd() const { return m_cachedSelectionEnd; } 103 104 virtual bool isOptionalFormControl() const { return !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