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 "core/HTMLNames.h"
35 #include "core/InputTypeNames.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/HTMLDataListOptionsCollection.h"
40 #include "core/html/HTMLInputElement.h"
41 #include "core/html/shadow/ShadowElementNames.h"
42 #include "core/html/shadow/TextControlInnerElements.h"
43 #include "platform/RuntimeEnabledFeatures.h"
44 #include "public/platform/WebString.h"
45 #include "public/web/WebElementCollection.h"
46 #include "wtf/PassRefPtr.h"
50 bool WebInputElement::isTextField() const
52 return constUnwrap
<HTMLInputElement
>()->isTextField();
55 bool WebInputElement::isText() const
57 return constUnwrap
<HTMLInputElement
>()->isTextField() && constUnwrap
<HTMLInputElement
>()->type() != InputTypeNames::number
;
60 bool WebInputElement::isEmailField() const
62 return constUnwrap
<HTMLInputElement
>()->type() == InputTypeNames::email
;
65 bool WebInputElement::isPasswordField() const
67 return constUnwrap
<HTMLInputElement
>()->type() == InputTypeNames::password
;
70 bool WebInputElement::isImageButton() const
72 return constUnwrap
<HTMLInputElement
>()->type() == InputTypeNames::image
;
75 bool WebInputElement::isRadioButton() const
77 return constUnwrap
<HTMLInputElement
>()->type() == InputTypeNames::radio
;
80 bool WebInputElement::isCheckbox() const
82 return constUnwrap
<HTMLInputElement
>()->type() == InputTypeNames::checkbox
;
85 int WebInputElement::maxLength() const
87 return constUnwrap
<HTMLInputElement
>()->maxLength();
90 void WebInputElement::setActivatedSubmit(bool activated
)
92 unwrap
<HTMLInputElement
>()->setActivatedSubmit(activated
);
95 int WebInputElement::size() const
97 return constUnwrap
<HTMLInputElement
>()->size();
100 void WebInputElement::setEditingValue(const WebString
& value
)
102 unwrap
<HTMLInputElement
>()->setEditingValue(value
);
105 bool WebInputElement::isValidValue(const WebString
& value
) const
107 return constUnwrap
<HTMLInputElement
>()->isValidValue(value
);
110 void WebInputElement::setChecked(bool nowChecked
, bool sendEvents
)
112 unwrap
<HTMLInputElement
>()->setChecked(nowChecked
, sendEvents
? DispatchInputAndChangeEvent
: DispatchNoEvent
);
115 bool WebInputElement::isChecked() const
117 return constUnwrap
<HTMLInputElement
>()->checked();
120 bool WebInputElement::isMultiple() const
122 return constUnwrap
<HTMLInputElement
>()->multiple();
125 WebElementCollection
WebInputElement::dataListOptions() const
127 if (HTMLDataListElement
* dataList
= toHTMLDataListElement(constUnwrap
<HTMLInputElement
>()->list()))
128 return WebElementCollection(dataList
->options());
129 return WebElementCollection();
132 WebString
WebInputElement::localizeValue(const WebString
& proposedValue
) const
134 return constUnwrap
<HTMLInputElement
>()->localizeValue(proposedValue
);
137 int WebInputElement::defaultMaxLength()
139 return HTMLInputElement::maximumLength
;
142 void WebInputElement::setShouldRevealPassword(bool value
)
144 unwrap
<HTMLInputElement
>()->setShouldRevealPassword(value
);
147 WebInputElement::WebInputElement(const PassRefPtrWillBeRawPtr
<HTMLInputElement
>& elem
)
148 : WebFormControlElement(elem
)
152 WebInputElement
& WebInputElement::operator=(const PassRefPtrWillBeRawPtr
<HTMLInputElement
>& elem
)
158 WebInputElement::operator PassRefPtrWillBeRawPtr
<HTMLInputElement
>() const
160 return toHTMLInputElement(m_private
.get());
163 WebInputElement
* toWebInputElement(WebElement
* webElement
)
165 if (!isHTMLInputElement(*webElement
->unwrap
<Element
>()))
168 return static_cast<WebInputElement
*>(webElement
);