2 * Copyright (C) 2008 Torch Mobile Inc. All rights reserved. (http://www.torchmobile.com/)
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.
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.
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.
21 #ifndef InputElement_h
22 #define InputElement_h
24 #include "AtomicString.h"
25 #include "PlatformString.h"
32 class InputElementData
;
33 class MappedAttribute
;
37 virtual ~InputElement() { }
39 virtual bool isPasswordField() const = 0;
40 virtual bool isSearchField() const = 0;
41 virtual bool isTextField() const = 0;
43 virtual bool placeholderShouldBeVisible() const = 0;
44 virtual bool searchEventsShouldBeDispatched() const = 0;
46 virtual int size() const = 0;
47 virtual String
value() const = 0;
48 virtual void setValue(const String
&) = 0;
49 virtual String
placeholderValue() const = 0;
51 virtual String
constrainValue(const String
&) const = 0;
52 virtual void setValueFromRenderer(const String
&) = 0;
54 virtual void cacheSelection(int start
, int end
) = 0;
55 virtual void select() = 0;
57 static const int s_maximumLength
;
58 static const int s_defaultSize
;
63 static void dispatchFocusEvent(InputElementData
&, Document
*);
64 static void dispatchBlurEvent(InputElementData
&, Document
*);
65 static void updatePlaceholderVisibility(InputElementData
&, Document
*, bool placeholderValueChanged
= false);
66 static void updateFocusAppearance(InputElementData
&, Document
*, bool restorePreviousSelection
);
67 static void updateSelectionRange(InputElementData
&, int start
, int end
);
68 static void aboutToUnload(InputElementData
&, Document
*);
69 static void setValueFromRenderer(InputElementData
&, Document
*, const String
&);
70 static String
constrainValue(const InputElementData
&, const String
& proposedValue
, int maxLength
);
71 static void handleBeforeTextInsertedEvent(InputElementData
&, Document
*, Event
*);
72 static void parseSizeAttribute(InputElementData
&, MappedAttribute
*);
73 static void parseMaxLengthAttribute(InputElementData
&, MappedAttribute
*);
74 static void updateValueIfNeeded(InputElementData
&);
75 static void notifyFormStateChanged(InputElementData
&, Document
*);
78 // HTML/WMLInputElement hold this struct as member variable
79 // and pass it to the static helper functions in InputElement
80 class InputElementData
{
82 InputElementData(InputElement
*, Element
*);
85 InputElement
* inputElement() const { return m_inputElement
; }
86 Element
* element() const { return m_element
; }
88 bool placeholderShouldBeVisible() const { return m_placeholderShouldBeVisible
; }
89 void setPlaceholderShouldBeVisible(bool visible
) { m_placeholderShouldBeVisible
= visible
; }
91 const AtomicString
& name() const;
92 void setName(const AtomicString
& value
) { m_name
= value
; }
94 String
value() const { return m_value
; }
95 void setValue(const String
& value
) { m_value
= value
; }
97 int size() const { return m_size
; }
98 void setSize(int value
) { m_size
= value
; }
100 int maxLength() const { return m_maxLength
; }
101 void setMaxLength(int value
) { m_maxLength
= value
; }
103 int cachedSelectionStart() const { return m_cachedSelectionStart
; }
104 void setCachedSelectionStart(int value
) { m_cachedSelectionStart
= value
; }
106 int cachedSelectionEnd() const { return m_cachedSelectionEnd
; }
107 void setCachedSelectionEnd(int value
) { m_cachedSelectionEnd
= value
; }
110 InputElement
* m_inputElement
;
112 bool m_placeholderShouldBeVisible
;
117 int m_cachedSelectionStart
;
118 int m_cachedSelectionEnd
;
121 InputElement
* toInputElement(Element
*);