1 /* 2 * Copyright (C) 2010 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 THIRD_PARTY_BLINK_PUBLIC_WEB_WEB_FORM_CONTROL_ELEMENT_H_ 32 #define THIRD_PARTY_BLINK_PUBLIC_WEB_WEB_FORM_CONTROL_ELEMENT_H_ 33 34 #include "third_party/blink/public/platform/web_string.h" 35 #include "third_party/blink/public/web/web_autofill_state.h" 36 #include "third_party/blink/public/web/web_element.h" 37 #include "third_party/blink/public/web/web_form_element.h" 38 39 namespace blink { 40 41 class HTMLFormControlElement; 42 43 // Provides readonly access to some properties of a DOM form control element 44 // node. 45 class BLINK_EXPORT WebFormControlElement : public WebElement { 46 public: WebFormControlElement()47 WebFormControlElement() : WebElement() {} 48 WebFormControlElement(const WebFormControlElement& e) = default; 49 50 WebFormControlElement& operator=(const WebFormControlElement& e) { 51 WebElement::Assign(e); 52 return *this; 53 } Assign(const WebFormControlElement & e)54 void Assign(const WebFormControlElement& e) { WebElement::Assign(e); } 55 56 bool IsEnabled() const; 57 bool IsReadOnly() const; 58 WebString FormControlName() const; 59 WebString FormControlType() const; 60 61 // Same as FormControlType() but returns the type "password" for text fields 62 // that have been a password in the past. 63 WebString FormControlTypeForAutofill() const; 64 65 enum WebAutofillState GetAutofillState() const; 66 bool IsAutofilled() const; 67 void SetAutofillState(enum WebAutofillState); 68 bool UserHasEditedTheField() const; 69 // This is only used for simulating the user's action in tests. 70 void SetUserHasEditedTheFieldForTest(); 71 72 // The autofill section to which this element belongs (e.g. billing address, 73 // shipping address, .. .) 74 WebString AutofillSection() const; 75 void SetAutofillSection(const WebString&); 76 77 // Returns true if autocomplete attribute of the element is not set as "off". 78 bool AutoComplete() const; 79 80 // Sets value for input element, textarea element and select element. For 81 // select element it finds the option with value matches the given parameter 82 // and make the option as the current selection. 83 void SetValue(const WebString&, bool send_events = false); 84 // Sets the autofilled value for input element, textarea element and select 85 // element and sends a sequence of events to the element. 86 void SetAutofillValue(const WebString&); 87 // Triggers the emission of a focus event. 88 void DispatchFocusEvent(); 89 // Triggers the emission of a blur event. 90 void DispatchBlurEvent(); 91 // Returns value of element. For select element, it returns the value of 92 // the selected option if present. If no selected option, an empty string 93 // is returned. If element doesn't fall into input element, textarea element 94 // and select element categories, a null string is returned. 95 WebString Value() const; 96 // Sets suggested value for element. For select element it finds the option 97 // with value matches the given parameter and make the option as the suggested 98 // selection. The goal of introducing suggested value is to not leak any 99 // information to JavaScript. 100 void SetSuggestedValue(const WebString&); 101 // Returns suggested value of element. If element doesn't fall into input 102 // element, textarea element and select element categories, a null string is 103 // returned. 104 WebString SuggestedValue() const; 105 106 // Returns the non-sanitized, exact value inside the text input field 107 // or insisde the textarea. If neither input element nor textarea element, 108 // a null string is returned. 109 WebString EditingValue() const; 110 111 // Sets character selection range. 112 void SetSelectionRange(int start, int end); 113 // Returned value represents a cursor/caret position at the current 114 // selection's start for text input field or textarea. If neither input 115 // element nor textarea element, 0 is returned. 116 int SelectionStart() const; 117 // Returned value represents a cursor/caret position at the current 118 // selection's end for text input field or textarea. If neither input 119 // element nor textarea element, 0 is returned. 120 int SelectionEnd() const; 121 122 // Returns text-align(only left and right are supported. see crbug.com/482339) 123 // of text of element. 124 WebString AlignmentForFormData() const; 125 126 // Returns direction of text of element. 127 WebString DirectionForFormData() const; 128 129 // Returns the name that should be used for the specified |element| when 130 // storing autofill data. This is either the field name or its id, an empty 131 // string if it has no name and no id. 132 WebString NameForAutofill() const; 133 134 WebFormElement Form() const; 135 136 // Returns the identifier which is unique among all form control elements in 137 // the current renderer process. In the current implementation ids are 138 // consecutive numbers so their uniqueness might be broken in case of 139 // overflow. 140 unsigned UniqueRendererFormControlId() const; 141 142 // Returns the ax node id of the form control element in the accessibility 143 // tree. The ax node id is consistent across renderer and browser processes. 144 int32_t GetAxId() const; 145 146 #if INSIDE_BLINK 147 WebFormControlElement(HTMLFormControlElement*); 148 WebFormControlElement& operator=(HTMLFormControlElement*); 149 operator HTMLFormControlElement*() const; 150 #endif 151 }; 152 153 DECLARE_WEB_NODE_TYPE_CASTS(WebFormControlElement); 154 155 } // namespace blink 156 157 #endif // THIRD_PARTY_BLINK_PUBLIC_WEB_WEB_FORM_CONTROL_ELEMENT_H_ 158