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 #ifndef WebInputElement_h
     32 #define WebInputElement_h
     33 
     34 #include "WebFormControlElement.h"
     35 
     36 #if WEBKIT_IMPLEMENTATION
     37 namespace WebCore { class HTMLInputElement; }
     38 #endif
     39 
     40 namespace WebKit {
     41 
     42     class WebNodeCollection;
     43 
     44     // Provides readonly access to some properties of a DOM input element node.
     45     class WebInputElement : public WebFormControlElement {
     46     public:
     47         enum SpeechInputState {
     48             Idle,
     49             Recording,
     50             Recognizing,
     51         };
     52 
     53         WebInputElement() : WebFormControlElement() { }
     54         WebInputElement(const WebInputElement& element) : WebFormControlElement(element) { }
     55 
     56         WebInputElement& operator=(const WebInputElement& element)
     57         {
     58             WebFormControlElement::assign(element);
     59             return *this;
     60         }
     61         void assign(const WebInputElement& element) { WebFormControlElement::assign(element); }
     62 
     63         // This returns true for all of textfield-looking types such as text,
     64         // password, search, email, url, and number.
     65         WEBKIT_EXPORT bool isTextField() const;
     66         // This returns true only for type=text.
     67         WEBKIT_EXPORT bool isText() const;
     68         WEBKIT_EXPORT bool isPasswordField() const;
     69         WEBKIT_EXPORT bool isImageButton() const;
     70         WEBKIT_EXPORT bool isRadioButton() const;
     71         WEBKIT_EXPORT bool isCheckbox() const;
     72         WEBKIT_EXPORT bool autoComplete() const;
     73         WEBKIT_EXPORT int maxLength() const;
     74         WEBKIT_EXPORT bool isActivatedSubmit() const;
     75         WEBKIT_EXPORT void setActivatedSubmit(bool);
     76         WEBKIT_EXPORT int size() const;
     77         WEBKIT_EXPORT void setValue(const WebString&, bool sendChangeEvent = false);
     78         WEBKIT_EXPORT void setChecked(bool, bool sendChangeEvent = false);
     79         WEBKIT_EXPORT WebString value() const;
     80         // This returns the non-sanitized, exact value inside the text field.
     81         WEBKIT_EXPORT WebString editingValue() const;
     82         // Sets the value inside the text field without being sanitized.
     83         // Can't be used if a renderer doesn't exist or on a non text field type.
     84         // Caret will be moved to the end.
     85         WEBKIT_EXPORT void setEditingValue(const WebString&);
     86         WEBKIT_EXPORT void setSuggestedValue(const WebString&);
     87         WEBKIT_EXPORT WebString suggestedValue() const;
     88         WEBKIT_EXPORT void setPlaceholder(const WebString&);
     89         WEBKIT_EXPORT WebString placeholder() const;
     90         WEBKIT_EXPORT bool isAutofilled() const;
     91         WEBKIT_EXPORT void setAutofilled(bool);
     92         WEBKIT_EXPORT void setSelectionRange(int, int);
     93         WEBKIT_EXPORT int selectionStart() const;
     94         WEBKIT_EXPORT int selectionEnd() const;
     95         WEBKIT_EXPORT bool isValidValue(const WebString&) const;
     96         WEBKIT_EXPORT bool isChecked() const;
     97         WEBKIT_EXPORT bool isMultiple() const;
     98 
     99         WEBKIT_EXPORT WebNodeCollection dataListOptions() const;
    100 
    101         // Return the localized value for this input type.
    102         WEBKIT_EXPORT WebString localizeValue(const WebString&) const;
    103 
    104         WEBKIT_EXPORT bool isSpeechInputEnabled() const;
    105         WEBKIT_EXPORT SpeechInputState getSpeechInputState() const;
    106         WEBKIT_EXPORT void startSpeechInput();
    107         WEBKIT_EXPORT void stopSpeechInput();
    108 
    109         // Exposes the default value of the maxLength attribute.
    110         WEBKIT_EXPORT static int defaultMaxLength();
    111 
    112         // Returns the direction of the text in this element.
    113         WEBKIT_EXPORT WebString directionForFormData() const;
    114 
    115         WEBKIT_EXPORT WebElement decorationElementFor(void*);
    116         WEBKIT_EXPORT WebElement passwordGeneratorButtonElement() const;
    117 
    118 #if WEBKIT_IMPLEMENTATION
    119         WebInputElement(const WTF::PassRefPtr<WebCore::HTMLInputElement>&);
    120         WebInputElement& operator=(const WTF::PassRefPtr<WebCore::HTMLInputElement>&);
    121         operator WTF::PassRefPtr<WebCore::HTMLInputElement>() const;
    122 #endif
    123     };
    124 
    125     WEBKIT_EXPORT WebInputElement* toWebInputElement(WebElement*);
    126 
    127     inline const WebInputElement* toWebInputElement(const WebElement* element)
    128     {
    129         return toWebInputElement(const_cast<WebElement*>(element));
    130     }
    131 
    132 } // namespace WebKit
    133 
    134 #endif
    135