1 /*
2 * Copyright (C) 2009 Google Inc. All rights reserved.
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are
6 * met:
7 *
8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above
11 * copyright notice, this list of conditions and the following disclaimer
12 * in the documentation and/or other materials provided with the
13 * distribution.
14 * * Neither the name of Google Inc. nor the names of its
15 * contributors may be used to endorse or promote products derived from
16 * this software without specific prior written permission.
17 *
18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 */
30
31 #include "config.h"
32 #include "WebInputElement.h"
33
34 #include "HTMLInputElement.h"
35 #include "HTMLNames.h"
36 #include "WebString.h"
37 #include <wtf/PassRefPtr.h>
38
39 using namespace WebCore;
40
41 namespace WebKit {
42
isTextField() const43 bool WebInputElement::isTextField() const
44 {
45 return constUnwrap<HTMLInputElement>()->isTextField();
46 }
47
isText() const48 bool WebInputElement::isText() const
49 {
50 return constUnwrap<HTMLInputElement>()->isText();
51 }
52
isPasswordField() const53 bool WebInputElement::isPasswordField() const
54 {
55 return constUnwrap<HTMLInputElement>()->isPasswordField();
56 }
57
isImageButton() const58 bool WebInputElement::isImageButton() const
59 {
60 return constUnwrap<HTMLInputElement>()->isImageButton();
61 }
62
autoComplete() const63 bool WebInputElement::autoComplete() const
64 {
65 return constUnwrap<HTMLInputElement>()->autoComplete();
66 }
67
maxLength() const68 int WebInputElement::maxLength() const
69 {
70 return constUnwrap<HTMLInputElement>()->maxLength();
71 }
72
isActivatedSubmit() const73 bool WebInputElement::isActivatedSubmit() const
74 {
75 return constUnwrap<HTMLInputElement>()->isActivatedSubmit();
76 }
77
setActivatedSubmit(bool activated)78 void WebInputElement::setActivatedSubmit(bool activated)
79 {
80 unwrap<HTMLInputElement>()->setActivatedSubmit(activated);
81 }
82
size() const83 int WebInputElement::size() const
84 {
85 return constUnwrap<HTMLInputElement>()->size();
86 }
87
setValue(const WebString & value,bool sendChangeEvent)88 void WebInputElement::setValue(const WebString& value, bool sendChangeEvent)
89 {
90 unwrap<HTMLInputElement>()->setValue(value, sendChangeEvent);
91 }
92
value() const93 WebString WebInputElement::value() const
94 {
95 return constUnwrap<HTMLInputElement>()->value();
96 }
97
setSuggestedValue(const WebString & value)98 void WebInputElement::setSuggestedValue(const WebString& value)
99 {
100 unwrap<HTMLInputElement>()->setSuggestedValue(value);
101 }
102
suggestedValue() const103 WebString WebInputElement::suggestedValue() const
104 {
105 return constUnwrap<HTMLInputElement>()->suggestedValue();
106 }
107
setPlaceholder(const WebString & value)108 void WebInputElement::setPlaceholder(const WebString& value)
109 {
110 unwrap<HTMLInputElement>()->setPlaceholder(value);
111 }
112
placeholder() const113 WebString WebInputElement::placeholder() const
114 {
115 return constUnwrap<HTMLInputElement>()->placeholder();
116 }
117
isAutofilled() const118 bool WebInputElement::isAutofilled() const
119 {
120 return constUnwrap<HTMLInputElement>()->isAutofilled();
121 }
122
setAutofilled(bool autoFilled)123 void WebInputElement::setAutofilled(bool autoFilled)
124 {
125 unwrap<HTMLInputElement>()->setAutofilled(autoFilled);
126 }
127
setSelectionRange(int start,int end)128 void WebInputElement::setSelectionRange(int start, int end)
129 {
130 unwrap<HTMLInputElement>()->setSelectionRange(start, end);
131 }
132
selectionStart() const133 int WebInputElement::selectionStart() const
134 {
135 return constUnwrap<HTMLInputElement>()->selectionStart();
136 }
137
selectionEnd() const138 int WebInputElement::selectionEnd() const
139 {
140 return constUnwrap<HTMLInputElement>()->selectionEnd();
141 }
142
isValidValue(const WebString & value) const143 bool WebInputElement::isValidValue(const WebString& value) const
144 {
145 return constUnwrap<HTMLInputElement>()->isValidValue(value);
146 }
147
isChecked() const148 bool WebInputElement::isChecked() const
149 {
150 return constUnwrap<HTMLInputElement>()->checked();
151 }
152
defaultMaxLength()153 int WebInputElement::defaultMaxLength()
154 {
155 return HTMLInputElement::s_maximumLength;
156 }
157
WebInputElement(const PassRefPtr<HTMLInputElement> & elem)158 WebInputElement::WebInputElement(const PassRefPtr<HTMLInputElement>& elem)
159 : WebFormControlElement(elem)
160 {
161 }
162
operator =(const PassRefPtr<HTMLInputElement> & elem)163 WebInputElement& WebInputElement::operator=(const PassRefPtr<HTMLInputElement>& elem)
164 {
165 m_private = elem;
166 return *this;
167 }
168
operator PassRefPtr<HTMLInputElement>() const169 WebInputElement::operator PassRefPtr<HTMLInputElement>() const
170 {
171 return static_cast<HTMLInputElement*>(m_private.get());
172 }
173
toWebInputElement(WebElement * webElement)174 WebInputElement* toWebInputElement(WebElement* webElement)
175 {
176 InputElement* inputElement = webElement->unwrap<Element>()->toInputElement();
177 if (!inputElement)
178 return 0;
179
180 ASSERT(webElement->unwrap<Element>()->isHTMLElement());
181
182 return static_cast<WebInputElement*>(webElement);
183 }
184
185 } // namespace WebKit
186