• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2008 Torch Mobile Inc. All rights reserved. (http://www.torchmobile.com/)
3  *
4  * This library is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Library General Public
6  * License as published by the Free Software Foundation; either
7  * version 2 of the License, or (at your option) any later version.
8  *
9  * This library is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12  * Library General Public License for more details.
13  *
14  * You should have received a copy of the GNU Library General Public License
15  * along with this library; see the file COPYING.LIB.  If not, write to
16  * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17  * Boston, MA 02110-1301, USA.
18  *
19  */
20 
21 #ifndef InputElement_h
22 #define InputElement_h
23 
24 #include "AtomicString.h"
25 #include "PlatformString.h"
26 
27 namespace WebCore {
28 
29 class Document;
30 class Element;
31 class Event;
32 class InputElementData;
33 class MappedAttribute;
34 
35 class InputElement {
36 public:
~InputElement()37     virtual ~InputElement() { }
38 
39     virtual bool isAutofilled() const = 0;
40     virtual bool isChecked() const = 0;
41     virtual bool isIndeterminate() const = 0;
42     virtual bool isInputTypeHidden() const = 0;
43     virtual bool isPasswordField() const = 0;
44     virtual bool isSearchField() const = 0;
45     virtual bool isTextField() const = 0;
46 
47     virtual bool searchEventsShouldBeDispatched() const = 0;
48 
49     virtual int size() const = 0;
50     virtual const String& suggestedValue() const = 0;
51     virtual String value() const = 0;
52     virtual void setValue(const String&, bool sendChangeEvent = false) = 0;
53     virtual void setValueForUser(const String&) = 0;
54 
55     virtual String sanitizeValue(const String&) const = 0;
56     virtual void setValueFromRenderer(const String&) = 0;
57 
58     virtual void cacheSelection(int start, int end) = 0;
59     virtual void select() = 0;
60 
61     static const int s_maximumLength;
62     static const int s_defaultSize;
63 
64 protected:
65     static void dispatchFocusEvent(InputElement*, Element*);
66     static void dispatchBlurEvent(InputElement*, Element*);
67     static void updateFocusAppearance(InputElementData&, InputElement*, Element*, bool restorePreviousSelection);
68     static void updateSelectionRange(InputElement*, Element*, int start, int end);
69     static void aboutToUnload(InputElement*, Element*);
70     static void setValueFromRenderer(InputElementData&, InputElement*, Element*, const String&);
71     // Replaces CRs and LFs, shrinks the value for s_maximumLength.
72     // This should be applied to values from the HTML value attribute and the DOM value property.
73     static String sanitizeValue(const InputElement*, const String&);
74     // Replaces CRs and LFs, shrinks the value for the specified maximum length.
75     // This should be applied to values specified by users.
76     static String sanitizeUserInputValue(const InputElement*, const String&, int);
77     static void handleBeforeTextInsertedEvent(InputElementData&, InputElement*, Element*, Event*);
78     static void parseSizeAttribute(InputElementData&, Element*, MappedAttribute*);
79     static void parseMaxLengthAttribute(InputElementData&, InputElement*, Element*, MappedAttribute*);
80     static void updateValueIfNeeded(InputElementData&, InputElement*);
81     static void notifyFormStateChanged(Element*);
82 };
83 
84 // HTML/WMLInputElement hold this struct as member variable
85 // and pass it to the static helper functions in InputElement
86 class InputElementData {
87 public:
88     InputElementData();
89 
90     const AtomicString& name() const;
setName(const AtomicString & value)91     void setName(const AtomicString& value) { m_name = value; }
92 
value()93     String value() const { return m_value; }
setValue(const String & value)94     void setValue(const String& value) { m_value = value; }
95 
suggestedValue()96     const String& suggestedValue() const { return m_suggestedValue; }
setSuggestedValue(const String & value)97     void setSuggestedValue(const String& value) { m_suggestedValue = value; }
98 
size()99     int size() const { return m_size; }
setSize(int value)100     void setSize(int value) { m_size = value; }
101 
maxLength()102     int maxLength() const { return m_maxLength; }
setMaxLength(int value)103     void setMaxLength(int value) { m_maxLength = value; }
104 
cachedSelectionStart()105     int cachedSelectionStart() const { return m_cachedSelectionStart; }
setCachedSelectionStart(int value)106     void setCachedSelectionStart(int value) { m_cachedSelectionStart = value; }
107 
cachedSelectionEnd()108     int cachedSelectionEnd() const { return m_cachedSelectionEnd; }
setCachedSelectionEnd(int value)109     void setCachedSelectionEnd(int value) { m_cachedSelectionEnd = value; }
110 
111 private:
112     AtomicString m_name;
113     String m_value;
114     String m_suggestedValue;
115     int m_size;
116     int m_maxLength;
117     int m_cachedSelectionStart;
118     int m_cachedSelectionEnd;
119 };
120 
121 InputElement* toInputElement(Element*);
122 
123 }
124 
125 #endif
126