Upstream version 7.36.149.0
[platform/framework/web/crosswalk.git] / src / third_party / WebKit / Source / web / WebInputElement.cpp
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 "HTMLNames.h"
35 #include "RuntimeEnabledFeatures.h"
36 #include "core/dom/shadow/ElementShadow.h"
37 #include "core/dom/shadow/ShadowRoot.h"
38 #include "core/html/HTMLDataListElement.h"
39 #include "core/html/HTMLInputElement.h"
40 #include "core/html/shadow/ShadowElementNames.h"
41 #include "core/html/shadow/TextControlInnerElements.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
50 bool WebInputElement::isTextField() const
51 {
52     return constUnwrap<HTMLInputElement>()->isTextField();
53 }
54
55 bool WebInputElement::isText() const
56 {
57     return constUnwrap<HTMLInputElement>()->isText();
58 }
59
60 bool WebInputElement::isPasswordField() const
61 {
62     return constUnwrap<HTMLInputElement>()->isPasswordField();
63 }
64
65 bool WebInputElement::isImageButton() const
66 {
67     return constUnwrap<HTMLInputElement>()->isImageButton();
68 }
69
70 bool WebInputElement::isRadioButton() const
71 {
72     return constUnwrap<HTMLInputElement>()->isRadioButton();
73 }
74
75 bool WebInputElement::isCheckbox() const
76 {
77     return constUnwrap<HTMLInputElement>()->isCheckbox();
78 }
79
80 int WebInputElement::maxLength() const
81 {
82     return constUnwrap<HTMLInputElement>()->maxLength();
83 }
84
85 void WebInputElement::setActivatedSubmit(bool activated)
86 {
87     unwrap<HTMLInputElement>()->setActivatedSubmit(activated);
88 }
89
90 int WebInputElement::size() const
91 {
92     return constUnwrap<HTMLInputElement>()->size();
93 }
94
95 void WebInputElement::setEditingValue(const WebString& value)
96 {
97     unwrap<HTMLInputElement>()->setEditingValue(value);
98 }
99
100 bool WebInputElement::isValidValue(const WebString& value) const
101 {
102     return constUnwrap<HTMLInputElement>()->isValidValue(value);
103 }
104
105 void WebInputElement::setChecked(bool nowChecked, bool sendEvents)
106 {
107     unwrap<HTMLInputElement>()->setChecked(nowChecked, sendEvents ? DispatchInputAndChangeEvent : DispatchNoEvent);
108 }
109
110 bool WebInputElement::isChecked() const
111 {
112     return constUnwrap<HTMLInputElement>()->checked();
113 }
114
115 bool WebInputElement::isMultiple() const
116 {
117     return constUnwrap<HTMLInputElement>()->multiple();
118 }
119
120 WebElementCollection WebInputElement::dataListOptions() const
121 {
122     if (HTMLDataListElement* dataList = toHTMLDataListElement(constUnwrap<HTMLInputElement>()->list()))
123         return WebElementCollection(dataList->options());
124     return WebElementCollection();
125 }
126
127 WebString WebInputElement::localizeValue(const WebString& proposedValue) const
128 {
129     return constUnwrap<HTMLInputElement>()->localizeValue(proposedValue);
130 }
131
132 int WebInputElement::defaultMaxLength()
133 {
134     return HTMLInputElement::maximumLength;
135 }
136
137 // FIXME: Remove this once password_generation_manager.h stops using it.
138 WebElement WebInputElement::decorationElementFor(void*)
139 {
140     return passwordGeneratorButtonElement();
141 }
142
143 WebElement WebInputElement::passwordGeneratorButtonElement() const
144 {
145     return WebElement(constUnwrap<HTMLInputElement>()->passwordGeneratorButtonElement());
146 }
147
148 void WebInputElement::setShouldRevealPassword(bool value)
149 {
150     unwrap<HTMLInputElement>()->setShouldRevealPassword(value);
151 }
152
153 WebInputElement::WebInputElement(const PassRefPtrWillBeRawPtr<HTMLInputElement>& elem)
154     : WebFormControlElement(elem)
155 {
156 }
157
158 WebInputElement& WebInputElement::operator=(const PassRefPtrWillBeRawPtr<HTMLInputElement>& elem)
159 {
160     m_private = elem;
161     return *this;
162 }
163
164 WebInputElement::operator PassRefPtrWillBeRawPtr<HTMLInputElement>() const
165 {
166     return toHTMLInputElement(m_private.get());
167 }
168
169 WebInputElement* toWebInputElement(WebElement* webElement)
170 {
171     if (!isHTMLInputElement(*webElement->unwrap<Element>()))
172         return 0;
173
174     return static_cast<WebInputElement*>(webElement);
175 }
176 } // namespace blink