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.
31 #ifndef WebInputElement_h
32 #define WebInputElement_h
34 #include "WebFormControlElement.h"
36 #if BLINK_IMPLEMENTATION
37 namespace WebCore { class HTMLInputElement; }
42 class WebElementCollection;
44 // Provides readonly access to some properties of a DOM input element node.
45 class WebInputElement : public WebFormControlElement {
47 enum SpeechInputState {
53 WebInputElement() : WebFormControlElement() { }
54 WebInputElement(const WebInputElement& element) : WebFormControlElement(element) { }
56 WebInputElement& operator=(const WebInputElement& element)
58 WebFormControlElement::assign(element);
61 void assign(const WebInputElement& element) { WebFormControlElement::assign(element); }
63 // This returns true for all of textfield-looking types such as text,
64 // password, search, email, url, and number.
65 BLINK_EXPORT bool isTextField() const;
66 // This returns true only for type=text.
67 BLINK_EXPORT bool isText() const;
68 BLINK_EXPORT bool isPasswordField() const;
69 BLINK_EXPORT bool isImageButton() const;
70 BLINK_EXPORT bool isRadioButton() const;
71 BLINK_EXPORT bool isCheckbox() const;
72 BLINK_EXPORT bool autoComplete() const;
73 BLINK_EXPORT int maxLength() const;
74 BLINK_EXPORT bool isActivatedSubmit() const;
75 BLINK_EXPORT void setActivatedSubmit(bool);
76 BLINK_EXPORT int size() const;
77 BLINK_EXPORT void setValue(const WebString&, bool sendChangeEvent = false);
78 BLINK_EXPORT void setChecked(bool, bool sendChangeEvent = false);
79 BLINK_EXPORT WebString value() const;
80 // This returns the non-sanitized, exact value inside the text field.
81 BLINK_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 BLINK_EXPORT void setEditingValue(const WebString&);
86 BLINK_EXPORT void setSuggestedValue(const WebString&);
87 BLINK_EXPORT WebString suggestedValue() const;
88 BLINK_EXPORT void setSelectionRange(int, int);
89 BLINK_EXPORT int selectionStart() const;
90 BLINK_EXPORT int selectionEnd() const;
91 BLINK_EXPORT bool isValidValue(const WebString&) const;
92 BLINK_EXPORT bool isChecked() const;
93 BLINK_EXPORT bool isMultiple() const;
95 BLINK_EXPORT WebElementCollection dataListOptions() const;
97 // Return the localized value for this input type.
98 BLINK_EXPORT WebString localizeValue(const WebString&) const;
100 BLINK_EXPORT bool isSpeechInputEnabled() const;
101 BLINK_EXPORT SpeechInputState getSpeechInputState() const;
102 BLINK_EXPORT void startSpeechInput();
103 BLINK_EXPORT void stopSpeechInput();
105 // Exposes the default value of the maxLength attribute.
106 BLINK_EXPORT static int defaultMaxLength();
108 // Returns the direction of the text in this element.
109 BLINK_EXPORT WebString directionForFormData() const;
111 BLINK_EXPORT WebElement decorationElementFor(void*);
112 BLINK_EXPORT WebElement passwordGeneratorButtonElement() const;
114 // If true, forces the text of the element to be visible.
115 BLINK_EXPORT void setShouldRevealPassword(bool value);
117 #if BLINK_IMPLEMENTATION
118 WebInputElement(const WTF::PassRefPtr<WebCore::HTMLInputElement>&);
119 WebInputElement& operator=(const WTF::PassRefPtr<WebCore::HTMLInputElement>&);
120 operator WTF::PassRefPtr<WebCore::HTMLInputElement>() const;
124 BLINK_EXPORT WebInputElement* toWebInputElement(WebElement*);
126 inline const WebInputElement* toWebInputElement(const WebElement* element)
128 return toWebInputElement(const_cast<WebElement*>(element));