Home | History | Annotate | Download | only in html
      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 "core/html/HTMLTextFormControlElement.h"
     28 
     29 namespace WebCore {
     30 
     31 class BeforeTextInsertedEvent;
     32 class ExceptionState;
     33 class VisibleSelection;
     34 
     35 class HTMLTextAreaElement FINAL : public HTMLTextFormControlElement {
     36 public:
     37     static PassRefPtr<HTMLTextAreaElement> create(const QualifiedName&, Document*, HTMLFormElement*);
     38 
     39     int cols() const { return m_cols; }
     40     int rows() const { return m_rows; }
     41 
     42     bool shouldWrapText() const { return m_wrap != NoWrap; }
     43 
     44     virtual String value() const;
     45     void setValue(const String&);
     46     String defaultValue() const;
     47     void setDefaultValue(const String&);
     48     int textLength() const { return value().length(); }
     49     virtual int maxLength() const;
     50     void setMaxLength(int, ExceptionState&);
     51     // For ValidityState
     52     virtual String validationMessage() const OVERRIDE;
     53     virtual bool valueMissing() const OVERRIDE;
     54     virtual bool tooLong() const OVERRIDE;
     55     bool isValidValue(const String&) const;
     56 
     57     virtual HTMLElement* innerTextElement() const;
     58 
     59     void rendererWillBeDestroyed();
     60 
     61     void setCols(int);
     62     void setRows(int);
     63 
     64 private:
     65     HTMLTextAreaElement(const QualifiedName&, Document*, HTMLFormElement*);
     66 
     67     enum WrapMethod { NoWrap, SoftWrap, HardWrap };
     68 
     69     virtual void didAddUserAgentShadowRoot(ShadowRoot*) OVERRIDE;
     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(RenderStyle*);
    104     virtual bool appendFormData(FormDataList&, bool);
    105     virtual void reset();
    106     virtual bool hasCustomFocusLogic() const OVERRIDE;
    107     virtual bool shouldShowFocusRingOnMouseFocus() const OVERRIDE;
    108     virtual bool isKeyboardFocusable() const OVERRIDE;
    109     virtual void updateFocusAppearance(bool restorePreviousSelection);
    110 
    111     virtual void accessKeyAction(bool sendMouseEvents);
    112 
    113     virtual bool shouldUseInputMethod();
    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 
    130 inline bool isHTMLTextAreaElement(const Node* node)
    131 {
    132     return node->hasTagName(HTMLNames::textareaTag);
    133 }
    134 
    135 inline bool isHTMLTextAreaElement(const Element* element)
    136 {
    137     return element->hasTagName(HTMLNames::textareaTag);
    138 }
    139 
    140 inline HTMLTextAreaElement* toHTMLTextAreaElement(Node* node)
    141 {
    142     ASSERT_WITH_SECURITY_IMPLICATION(!node || isHTMLTextAreaElement(node));
    143     return static_cast<HTMLTextAreaElement*>(node);
    144 }
    145 
    146 } //namespace
    147 
    148 #endif
    149