2 * Copyright (C) 2009 Google Inc. All rights reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are
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
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.
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.
32 #include "WebInputElement.h"
34 #include "HTMLNames.h"
35 #include "RuntimeEnabledFeatures.h"
36 #include "WebElementCollection.h"
37 #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"
41 #include "core/html/shadow/ShadowElementNames.h"
42 #include "core/html/shadow/TextControlInnerElements.h"
43 #include "public/platform/WebString.h"
44 #include "wtf/PassRefPtr.h"
46 using namespace WebCore;
50 bool WebInputElement::isTextField() const
52 return constUnwrap<HTMLInputElement>()->isTextField();
55 bool WebInputElement::isText() const
57 return constUnwrap<HTMLInputElement>()->isText();
60 bool WebInputElement::isPasswordField() const
62 return constUnwrap<HTMLInputElement>()->isPasswordField();
65 bool WebInputElement::isImageButton() const
67 return constUnwrap<HTMLInputElement>()->isImageButton();
70 bool WebInputElement::isRadioButton() const
72 return constUnwrap<HTMLInputElement>()->isRadioButton();
75 bool WebInputElement::isCheckbox() const
77 return constUnwrap<HTMLInputElement>()->isCheckbox();
80 bool WebInputElement::autoComplete() const
82 return constUnwrap<HTMLInputElement>()->shouldAutocomplete();
85 int WebInputElement::maxLength() const
87 return constUnwrap<HTMLInputElement>()->maxLength();
90 bool WebInputElement::isActivatedSubmit() const
92 return constUnwrap<HTMLInputElement>()->isActivatedSubmit();
95 void WebInputElement::setActivatedSubmit(bool activated)
97 unwrap<HTMLInputElement>()->setActivatedSubmit(activated);
100 int WebInputElement::size() const
102 return constUnwrap<HTMLInputElement>()->size();
105 void WebInputElement::setValue(const WebString& value, bool sendChangeEvent)
107 unwrap<HTMLInputElement>()->setValue(value, sendChangeEvent ? DispatchChangeEvent : DispatchNoEvent);
110 WebString WebInputElement::value() const
112 return constUnwrap<HTMLInputElement>()->value();
115 WebString WebInputElement::editingValue() const
117 return constUnwrap<HTMLInputElement>()->innerTextValue();
120 void WebInputElement::setEditingValue(const WebString& value)
122 unwrap<HTMLInputElement>()->setEditingValue(value);
125 void WebInputElement::setSuggestedValue(const WebString& value)
127 unwrap<HTMLInputElement>()->setSuggestedValue(value);
130 WebString WebInputElement::suggestedValue() const
132 return constUnwrap<HTMLInputElement>()->suggestedValue();
135 void WebInputElement::setSelectionRange(int start, int end)
137 unwrap<HTMLInputElement>()->setSelectionRange(start, end);
140 int WebInputElement::selectionStart() const
142 return constUnwrap<HTMLInputElement>()->selectionStart();
145 int WebInputElement::selectionEnd() const
147 return constUnwrap<HTMLInputElement>()->selectionEnd();
150 bool WebInputElement::isValidValue(const WebString& value) const
152 return constUnwrap<HTMLInputElement>()->isValidValue(value);
155 void WebInputElement::setChecked(bool nowChecked, bool sendChangeEvent)
157 unwrap<HTMLInputElement>()->setChecked(nowChecked, sendChangeEvent ? DispatchChangeEvent : DispatchNoEvent);
160 bool WebInputElement::isChecked() const
162 return constUnwrap<HTMLInputElement>()->checked();
165 bool WebInputElement::isMultiple() const
167 return constUnwrap<HTMLInputElement>()->multiple();
170 WebElementCollection WebInputElement::dataListOptions() const
172 if (HTMLDataListElement* dataList = toHTMLDataListElement(constUnwrap<HTMLInputElement>()->list()))
173 return WebElementCollection(dataList->options());
174 return WebElementCollection();
177 WebString WebInputElement::localizeValue(const WebString& proposedValue) const
179 return constUnwrap<HTMLInputElement>()->localizeValue(proposedValue);
182 bool WebInputElement::isSpeechInputEnabled() const
184 #if ENABLE(INPUT_SPEECH)
185 return constUnwrap<HTMLInputElement>()->isSpeechEnabled();
191 #if ENABLE(INPUT_SPEECH)
192 static inline InputFieldSpeechButtonElement* speechButtonElement(const WebInputElement* webInput)
194 return toInputFieldSpeechButtonElement(webInput->constUnwrap<HTMLInputElement>()->userAgentShadowRoot()->getElementById(ShadowElementNames::speechButton()));
198 WebInputElement::SpeechInputState WebInputElement::getSpeechInputState() const
200 #if ENABLE(INPUT_SPEECH)
201 if (InputFieldSpeechButtonElement* speechButton = speechButtonElement(this))
202 return static_cast<WebInputElement::SpeechInputState>(speechButton->state());
208 void WebInputElement::startSpeechInput()
210 #if ENABLE(INPUT_SPEECH)
211 if (InputFieldSpeechButtonElement* speechButton = speechButtonElement(this))
212 speechButton->startSpeechInput();
216 void WebInputElement::stopSpeechInput()
218 #if ENABLE(INPUT_SPEECH)
219 if (InputFieldSpeechButtonElement* speechButton = speechButtonElement(this))
220 speechButton->stopSpeechInput();
224 int WebInputElement::defaultMaxLength()
226 return HTMLInputElement::maximumLength;
229 WebString WebInputElement::directionForFormData() const
231 return constUnwrap<HTMLInputElement>()->directionForFormData();
234 // FIXME: Remove this once password_generation_manager.h stops using it.
235 WebElement WebInputElement::decorationElementFor(void*)
237 return passwordGeneratorButtonElement();
240 WebElement WebInputElement::passwordGeneratorButtonElement() const
242 return WebElement(constUnwrap<HTMLInputElement>()->passwordGeneratorButtonElement());
245 void WebInputElement::setShouldRevealPassword(bool value)
247 unwrap<HTMLInputElement>()->setShouldRevealPassword(value);
250 WebInputElement::WebInputElement(const PassRefPtr<HTMLInputElement>& elem)
251 : WebFormControlElement(elem)
255 WebInputElement& WebInputElement::operator=(const PassRefPtr<HTMLInputElement>& elem)
261 WebInputElement::operator PassRefPtr<HTMLInputElement>() const
263 return toHTMLInputElement(m_private.get());
266 WebInputElement* toWebInputElement(WebElement* webElement)
268 if (!webElement->unwrap<Element>()->hasTagName(HTMLNames::inputTag))
271 return static_cast<WebInputElement*>(webElement);