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 "public/web/WebInputElement.h"
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"
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 int WebInputElement::maxLength() const
82 return constUnwrap<HTMLInputElement>()->maxLength();
85 void WebInputElement::setActivatedSubmit(bool activated)
87 unwrap<HTMLInputElement>()->setActivatedSubmit(activated);
90 int WebInputElement::size() const
92 return constUnwrap<HTMLInputElement>()->size();
95 void WebInputElement::setEditingValue(const WebString& value)
97 unwrap<HTMLInputElement>()->setEditingValue(value);
100 bool WebInputElement::isValidValue(const WebString& value) const
102 return constUnwrap<HTMLInputElement>()->isValidValue(value);
105 void WebInputElement::setChecked(bool nowChecked, bool sendEvents)
107 unwrap<HTMLInputElement>()->setChecked(nowChecked, sendEvents ? DispatchInputAndChangeEvent : DispatchNoEvent);
110 bool WebInputElement::isChecked() const
112 return constUnwrap<HTMLInputElement>()->checked();
115 bool WebInputElement::isMultiple() const
117 return constUnwrap<HTMLInputElement>()->multiple();
120 WebElementCollection WebInputElement::dataListOptions() const
122 if (HTMLDataListElement* dataList = toHTMLDataListElement(constUnwrap<HTMLInputElement>()->list()))
123 return WebElementCollection(dataList->options());
124 return WebElementCollection();
127 WebString WebInputElement::localizeValue(const WebString& proposedValue) const
129 return constUnwrap<HTMLInputElement>()->localizeValue(proposedValue);
132 int WebInputElement::defaultMaxLength()
134 return HTMLInputElement::maximumLength;
137 // FIXME: Remove this once password_generation_manager.h stops using it.
138 WebElement WebInputElement::decorationElementFor(void*)
140 return passwordGeneratorButtonElement();
143 WebElement WebInputElement::passwordGeneratorButtonElement() const
145 return WebElement(constUnwrap<HTMLInputElement>()->passwordGeneratorButtonElement());
148 void WebInputElement::setShouldRevealPassword(bool value)
150 unwrap<HTMLInputElement>()->setShouldRevealPassword(value);
153 WebInputElement::WebInputElement(const PassRefPtrWillBeRawPtr<HTMLInputElement>& elem)
154 : WebFormControlElement(elem)
158 WebInputElement& WebInputElement::operator=(const PassRefPtrWillBeRawPtr<HTMLInputElement>& elem)
164 WebInputElement::operator PassRefPtrWillBeRawPtr<HTMLInputElement>() const
166 return toHTMLInputElement(m_private.get());
169 WebInputElement* toWebInputElement(WebElement* webElement)
171 if (!isHTMLInputElement(*webElement->unwrap<Element>()))
174 return static_cast<WebInputElement*>(webElement);