Home | History | Annotate | Download | only in public
      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     // Provides readonly access to some properties of a DOM input element node.
     43     class WebInputElement : public WebFormControlElement {
     44     public:
     45         WebInputElement() : WebFormControlElement() { }
     46         WebInputElement(const WebInputElement& element) : WebFormControlElement(element) { }
     47 
     48         WebInputElement& operator=(const WebInputElement& element)
     49         {
     50             WebFormControlElement::assign(element);
     51             return *this;
     52         }
     53         void assign(const WebInputElement& element) { WebFormControlElement::assign(element); }
     54 
     55         // This returns true for all of textfield-looking types such as text,
     56         // password, search, email, url, and number.
     57         WEBKIT_API bool isTextField() const;
     58         // This returns true only for type=text.
     59         WEBKIT_API bool isText() const;
     60         WEBKIT_API bool isPasswordField() const;
     61         WEBKIT_API bool isImageButton() const;
     62         WEBKIT_API bool autoComplete() const;
     63         WEBKIT_API int maxLength() const;
     64         WEBKIT_API bool isActivatedSubmit() const;
     65         WEBKIT_API void setActivatedSubmit(bool);
     66         WEBKIT_API int size() const;
     67         WEBKIT_API void setValue(const WebString&, bool sendChangeEvent = false);
     68         WEBKIT_API WebString value() const;
     69         WEBKIT_API void setSuggestedValue(const WebString&);
     70         WEBKIT_API WebString suggestedValue() const;
     71         WEBKIT_API void setPlaceholder(const WebString&);
     72         WEBKIT_API WebString placeholder() const;
     73         WEBKIT_API bool isAutofilled() const;
     74         WEBKIT_API void setAutofilled(bool);
     75         WEBKIT_API void setSelectionRange(int, int);
     76         WEBKIT_API int selectionStart() const;
     77         WEBKIT_API int selectionEnd() const;
     78         WEBKIT_API bool isValidValue(const WebString&) const;
     79         WEBKIT_API bool isChecked() const;
     80 
     81         // Exposes the default value of the maxLength attribute.
     82         WEBKIT_API static int defaultMaxLength();
     83 
     84 #if WEBKIT_IMPLEMENTATION
     85         WebInputElement(const WTF::PassRefPtr<WebCore::HTMLInputElement>&);
     86         WebInputElement& operator=(const WTF::PassRefPtr<WebCore::HTMLInputElement>&);
     87         operator WTF::PassRefPtr<WebCore::HTMLInputElement>() const;
     88 #endif
     89     };
     90 
     91     WEBKIT_API WebInputElement* toWebInputElement(WebElement*);
     92 
     93     inline const WebInputElement* toWebInputElement(const WebElement* element)
     94     {
     95         return toWebInputElement(const_cast<WebElement*>(element));
     96     }
     97 
     98 } // namespace WebKit
     99 
    100 #endif
    101