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 "public/web/WebInputElement.h"
33
34 #include "core/HTMLNames.h"
35 #include "core/dom/shadow/ElementShadow.h"
36 #include "core/dom/shadow/ShadowRoot.h"
37 #include "core/html/HTMLDataListElement.h"
38 #include "core/html/HTMLInputElement.h"
39 #include "core/html/shadow/ShadowElementNames.h"
40 #include "core/html/shadow/TextControlInnerElements.h"
41 #include "platform/RuntimeEnabledFeatures.h"
42 #include "public/platform/WebString.h"
43 #include "public/web/WebElementCollection.h"
44 #include "wtf/PassRefPtr.h"
45
46 using namespace WebCore;
47
48 namespace blink {
49
isTextField() const50 bool WebInputElement::isTextField() const
51 {
52 return constUnwrap<HTMLInputElement>()->isTextField();
53 }
54
isText() const55 bool WebInputElement::isText() const
56 {
57 return constUnwrap<HTMLInputElement>()->isText();
58 }
59
isPasswordField() const60 bool WebInputElement::isPasswordField() const
61 {
62 return constUnwrap<HTMLInputElement>()->isPasswordField();
63 }
64
isImageButton() const65 bool WebInputElement::isImageButton() const
66 {
67 return constUnwrap<HTMLInputElement>()->isImageButton();
68 }
69
isRadioButton() const70 bool WebInputElement::isRadioButton() const
71 {
72 return constUnwrap<HTMLInputElement>()->isRadioButton();
73 }
74
isCheckbox() const75 bool WebInputElement::isCheckbox() const
76 {
77 return constUnwrap<HTMLInputElement>()->isCheckbox();
78 }
79
maxLength() const80 int WebInputElement::maxLength() const
81 {
82 return constUnwrap<HTMLInputElement>()->maxLength();
83 }
84
setActivatedSubmit(bool activated)85 void WebInputElement::setActivatedSubmit(bool activated)
86 {
87 unwrap<HTMLInputElement>()->setActivatedSubmit(activated);
88 }
89
size() const90 int WebInputElement::size() const
91 {
92 return constUnwrap<HTMLInputElement>()->size();
93 }
94
setEditingValue(const WebString & value)95 void WebInputElement::setEditingValue(const WebString& value)
96 {
97 unwrap<HTMLInputElement>()->setEditingValue(value);
98 }
99
isValidValue(const WebString & value) const100 bool WebInputElement::isValidValue(const WebString& value) const
101 {
102 return constUnwrap<HTMLInputElement>()->isValidValue(value);
103 }
104
setChecked(bool nowChecked,bool sendEvents)105 void WebInputElement::setChecked(bool nowChecked, bool sendEvents)
106 {
107 unwrap<HTMLInputElement>()->setChecked(nowChecked, sendEvents ? DispatchInputAndChangeEvent : DispatchNoEvent);
108 }
109
isChecked() const110 bool WebInputElement::isChecked() const
111 {
112 return constUnwrap<HTMLInputElement>()->checked();
113 }
114
isMultiple() const115 bool WebInputElement::isMultiple() const
116 {
117 return constUnwrap<HTMLInputElement>()->multiple();
118 }
119
dataListOptions() const120 WebElementCollection WebInputElement::dataListOptions() const
121 {
122 if (HTMLDataListElement* dataList = toHTMLDataListElement(constUnwrap<HTMLInputElement>()->list()))
123 return WebElementCollection(dataList->options());
124 return WebElementCollection();
125 }
126
localizeValue(const WebString & proposedValue) const127 WebString WebInputElement::localizeValue(const WebString& proposedValue) const
128 {
129 return constUnwrap<HTMLInputElement>()->localizeValue(proposedValue);
130 }
131
defaultMaxLength()132 int WebInputElement::defaultMaxLength()
133 {
134 return HTMLInputElement::maximumLength;
135 }
136
setShouldRevealPassword(bool value)137 void WebInputElement::setShouldRevealPassword(bool value)
138 {
139 unwrap<HTMLInputElement>()->setShouldRevealPassword(value);
140 }
141
WebInputElement(const PassRefPtrWillBeRawPtr<HTMLInputElement> & elem)142 WebInputElement::WebInputElement(const PassRefPtrWillBeRawPtr<HTMLInputElement>& elem)
143 : WebFormControlElement(elem)
144 {
145 }
146
operator =(const PassRefPtrWillBeRawPtr<HTMLInputElement> & elem)147 WebInputElement& WebInputElement::operator=(const PassRefPtrWillBeRawPtr<HTMLInputElement>& elem)
148 {
149 m_private = elem;
150 return *this;
151 }
152
operator PassRefPtrWillBeRawPtr<HTMLInputElement>() const153 WebInputElement::operator PassRefPtrWillBeRawPtr<HTMLInputElement>() const
154 {
155 return toHTMLInputElement(m_private.get());
156 }
157
toWebInputElement(WebElement * webElement)158 WebInputElement* toWebInputElement(WebElement* webElement)
159 {
160 if (!isHTMLInputElement(*webElement->unwrap<Element>()))
161 return 0;
162
163 return static_cast<WebInputElement*>(webElement);
164 }
165 } // namespace blink
166