Home | History | Annotate | Download | only in web
      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 "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"
     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>()->isTextField() && constUnwrap<HTMLInputElement>()->type() != InputTypeNames::number;
     58 }
     59 
     60 bool WebInputElement::isEmailField() const
     61 {
     62     return constUnwrap<HTMLInputElement>()->type() == InputTypeNames::email;
     63 }
     64 
     65 bool WebInputElement::isPasswordField() const
     66 {
     67     return constUnwrap<HTMLInputElement>()->type() == InputTypeNames::password;
     68 }
     69 
     70 bool WebInputElement::isImageButton() const
     71 {
     72     return constUnwrap<HTMLInputElement>()->type() == InputTypeNames::image;
     73 }
     74 
     75 bool WebInputElement::isRadioButton() const
     76 {
     77     return constUnwrap<HTMLInputElement>()->type() == InputTypeNames::radio;
     78 }
     79 
     80 bool WebInputElement::isCheckbox() const
     81 {
     82     return constUnwrap<HTMLInputElement>()->type() == InputTypeNames::checkbox;
     83 }
     84 
     85 int WebInputElement::maxLength() const
     86 {
     87     return constUnwrap<HTMLInputElement>()->maxLength();
     88 }
     89 
     90 void WebInputElement::setActivatedSubmit(bool activated)
     91 {
     92     unwrap<HTMLInputElement>()->setActivatedSubmit(activated);
     93 }
     94 
     95 int WebInputElement::size() const
     96 {
     97     return constUnwrap<HTMLInputElement>()->size();
     98 }
     99 
    100 void WebInputElement::setEditingValue(const WebString& value)
    101 {
    102     unwrap<HTMLInputElement>()->setEditingValue(value);
    103 }
    104 
    105 bool WebInputElement::isValidValue(const WebString& value) const
    106 {
    107     return constUnwrap<HTMLInputElement>()->isValidValue(value);
    108 }
    109 
    110 void WebInputElement::setChecked(bool nowChecked, bool sendEvents)
    111 {
    112     unwrap<HTMLInputElement>()->setChecked(nowChecked, sendEvents ? DispatchInputAndChangeEvent : DispatchNoEvent);
    113 }
    114 
    115 bool WebInputElement::isChecked() const
    116 {
    117     return constUnwrap<HTMLInputElement>()->checked();
    118 }
    119 
    120 bool WebInputElement::isMultiple() const
    121 {
    122     return constUnwrap<HTMLInputElement>()->multiple();
    123 }
    124 
    125 WebElementCollection WebInputElement::dataListOptions() const
    126 {
    127     if (HTMLDataListElement* dataList = toHTMLDataListElement(constUnwrap<HTMLInputElement>()->list()))
    128         return WebElementCollection(dataList->options());
    129     return WebElementCollection();
    130 }
    131 
    132 WebString WebInputElement::localizeValue(const WebString& proposedValue) const
    133 {
    134     return constUnwrap<HTMLInputElement>()->localizeValue(proposedValue);
    135 }
    136 
    137 int WebInputElement::defaultMaxLength()
    138 {
    139     return HTMLInputElement::maximumLength;
    140 }
    141 
    142 void WebInputElement::setShouldRevealPassword(bool value)
    143 {
    144     unwrap<HTMLInputElement>()->setShouldRevealPassword(value);
    145 }
    146 
    147 WebInputElement::WebInputElement(const PassRefPtrWillBeRawPtr<HTMLInputElement>& elem)
    148     : WebFormControlElement(elem)
    149 {
    150 }
    151 
    152 WebInputElement& WebInputElement::operator=(const PassRefPtrWillBeRawPtr<HTMLInputElement>& elem)
    153 {
    154     m_private = elem;
    155     return *this;
    156 }
    157 
    158 WebInputElement::operator PassRefPtrWillBeRawPtr<HTMLInputElement>() const
    159 {
    160     return toHTMLInputElement(m_private.get());
    161 }
    162 
    163 WebInputElement* toWebInputElement(WebElement* webElement)
    164 {
    165     if (!isHTMLInputElement(*webElement->unwrap<Element>()))
    166         return 0;
    167 
    168     return static_cast<WebInputElement*>(webElement);
    169 }
    170 } // namespace blink
    171