blob: 58648d3836decf1592f4362479cdeb024266be24 [file] [log] [blame]
Ben Murdoche69819b2013-07-17 14:56:49 +01001/*
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 "HTMLNames.h"
35#include "RuntimeEnabledFeatures.h"
Torne (Richard Coles)09380292014-02-21 12:17:33 +000036#include "WebElementCollection.h"
Ben Murdoche69819b2013-07-17 14:56:49 +010037#include "core/dom/shadow/ElementShadow.h"
38#include "core/dom/shadow/ShadowRoot.h"
39#include "core/html/HTMLDataListElement.h"
40#include "core/html/HTMLInputElement.h"
Torne (Richard Coles)e1f1df52013-08-23 16:39:30 +010041#include "core/html/shadow/ShadowElementNames.h"
Ben Murdoche69819b2013-07-17 14:56:49 +010042#include "core/html/shadow/TextControlInnerElements.h"
43#include "public/platform/WebString.h"
44#include "wtf/PassRefPtr.h"
45
46using namespace WebCore;
47
Torne (Richard Coles)51b29062013-11-28 11:56:03 +000048namespace blink {
Ben Murdoche69819b2013-07-17 14:56:49 +010049
50bool WebInputElement::isTextField() const
51{
52 return constUnwrap<HTMLInputElement>()->isTextField();
53}
54
55bool WebInputElement::isText() const
56{
57 return constUnwrap<HTMLInputElement>()->isText();
58}
59
60bool WebInputElement::isPasswordField() const
61{
62 return constUnwrap<HTMLInputElement>()->isPasswordField();
63}
64
65bool WebInputElement::isImageButton() const
66{
67 return constUnwrap<HTMLInputElement>()->isImageButton();
68}
69
70bool WebInputElement::isRadioButton() const
71{
72 return constUnwrap<HTMLInputElement>()->isRadioButton();
73}
74
75bool WebInputElement::isCheckbox() const
76{
77 return constUnwrap<HTMLInputElement>()->isCheckbox();
78}
79
Ben Murdoche69819b2013-07-17 14:56:49 +010080int WebInputElement::maxLength() const
81{
82 return constUnwrap<HTMLInputElement>()->maxLength();
83}
84
85bool WebInputElement::isActivatedSubmit() const
86{
87 return constUnwrap<HTMLInputElement>()->isActivatedSubmit();
88}
89
90void WebInputElement::setActivatedSubmit(bool activated)
91{
92 unwrap<HTMLInputElement>()->setActivatedSubmit(activated);
93}
94
95int WebInputElement::size() const
96{
97 return constUnwrap<HTMLInputElement>()->size();
98}
99
Ben Murdoche69819b2013-07-17 14:56:49 +0100100void WebInputElement::setEditingValue(const WebString& value)
101{
102 unwrap<HTMLInputElement>()->setEditingValue(value);
103}
104
Ben Murdoche69819b2013-07-17 14:56:49 +0100105bool WebInputElement::isValidValue(const WebString& value) const
106{
107 return constUnwrap<HTMLInputElement>()->isValidValue(value);
108}
109
Ben Murdoch07a852d2014-03-31 11:51:52 +0100110void WebInputElement::setChecked(bool nowChecked, bool sendEvents)
Ben Murdoche69819b2013-07-17 14:56:49 +0100111{
Ben Murdoch07a852d2014-03-31 11:51:52 +0100112 unwrap<HTMLInputElement>()->setChecked(nowChecked, sendEvents ? DispatchInputAndChangeEvent : DispatchNoEvent);
Ben Murdoche69819b2013-07-17 14:56:49 +0100113}
114
115bool WebInputElement::isChecked() const
116{
117 return constUnwrap<HTMLInputElement>()->checked();
118}
119
120bool WebInputElement::isMultiple() const
121{
122 return constUnwrap<HTMLInputElement>()->multiple();
123}
124
Torne (Richard Coles)09380292014-02-21 12:17:33 +0000125WebElementCollection WebInputElement::dataListOptions() const
Ben Murdoche69819b2013-07-17 14:56:49 +0100126{
Torne (Richard Coles)09380292014-02-21 12:17:33 +0000127 if (HTMLDataListElement* dataList = toHTMLDataListElement(constUnwrap<HTMLInputElement>()->list()))
128 return WebElementCollection(dataList->options());
129 return WebElementCollection();
Ben Murdoche69819b2013-07-17 14:56:49 +0100130}
131
132WebString WebInputElement::localizeValue(const WebString& proposedValue) const
133{
134 return constUnwrap<HTMLInputElement>()->localizeValue(proposedValue);
135}
136
137bool WebInputElement::isSpeechInputEnabled() const
138{
139#if ENABLE(INPUT_SPEECH)
140 return constUnwrap<HTMLInputElement>()->isSpeechEnabled();
141#else
142 return false;
143#endif
144}
145
Torne (Richard Coles)e1f1df52013-08-23 16:39:30 +0100146#if ENABLE(INPUT_SPEECH)
147static inline InputFieldSpeechButtonElement* speechButtonElement(const WebInputElement* webInput)
148{
149 return toInputFieldSpeechButtonElement(webInput->constUnwrap<HTMLInputElement>()->userAgentShadowRoot()->getElementById(ShadowElementNames::speechButton()));
150}
151#endif
152
Ben Murdoche69819b2013-07-17 14:56:49 +0100153WebInputElement::SpeechInputState WebInputElement::getSpeechInputState() const
154{
155#if ENABLE(INPUT_SPEECH)
Torne (Richard Coles)e1f1df52013-08-23 16:39:30 +0100156 if (InputFieldSpeechButtonElement* speechButton = speechButtonElement(this))
Ben Murdoche69819b2013-07-17 14:56:49 +0100157 return static_cast<WebInputElement::SpeechInputState>(speechButton->state());
158#endif
159
160 return Idle;
161}
162
163void WebInputElement::startSpeechInput()
164{
165#if ENABLE(INPUT_SPEECH)
Torne (Richard Coles)e1f1df52013-08-23 16:39:30 +0100166 if (InputFieldSpeechButtonElement* speechButton = speechButtonElement(this))
Ben Murdoche69819b2013-07-17 14:56:49 +0100167 speechButton->startSpeechInput();
168#endif
169}
170
171void WebInputElement::stopSpeechInput()
172{
173#if ENABLE(INPUT_SPEECH)
Torne (Richard Coles)e1f1df52013-08-23 16:39:30 +0100174 if (InputFieldSpeechButtonElement* speechButton = speechButtonElement(this))
Ben Murdoche69819b2013-07-17 14:56:49 +0100175 speechButton->stopSpeechInput();
176#endif
177}
178
179int WebInputElement::defaultMaxLength()
180{
181 return HTMLInputElement::maximumLength;
182}
183
Ben Murdoche69819b2013-07-17 14:56:49 +0100184// FIXME: Remove this once password_generation_manager.h stops using it.
185WebElement WebInputElement::decorationElementFor(void*)
186{
187 return passwordGeneratorButtonElement();
188}
189
190WebElement WebInputElement::passwordGeneratorButtonElement() const
191{
192 return WebElement(constUnwrap<HTMLInputElement>()->passwordGeneratorButtonElement());
193}
194
Torne (Richard Coles)09380292014-02-21 12:17:33 +0000195void WebInputElement::setShouldRevealPassword(bool value)
196{
197 unwrap<HTMLInputElement>()->setShouldRevealPassword(value);
198}
199
Ben Murdoche69819b2013-07-17 14:56:49 +0100200WebInputElement::WebInputElement(const PassRefPtr<HTMLInputElement>& elem)
201 : WebFormControlElement(elem)
202{
203}
204
205WebInputElement& WebInputElement::operator=(const PassRefPtr<HTMLInputElement>& elem)
206{
207 m_private = elem;
208 return *this;
209}
210
211WebInputElement::operator PassRefPtr<HTMLInputElement>() const
212{
213 return toHTMLInputElement(m_private.get());
214}
215
216WebInputElement* toWebInputElement(WebElement* webElement)
217{
Torne (Richard Coles)d5428f32014-03-18 10:21:16 +0000218 if (!isHTMLInputElement(*webElement->unwrap<Element>()))
Ben Murdoche69819b2013-07-17 14:56:49 +0100219 return 0;
220
221 return static_cast<WebInputElement*>(webElement);
222}
Torne (Richard Coles)51b29062013-11-28 11:56:03 +0000223} // namespace blink