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 #include "config.h" 32 #include "public/web/WebFormControlElement.h" 33 34 #include "core/html/HTMLFormControlElement.h" 35 #include "core/html/HTMLFormElement.h" 36 #include "core/html/HTMLInputElement.h" 37 #include "core/html/HTMLSelectElement.h" 38 #include "core/html/HTMLTextAreaElement.h" 39 40 #include "wtf/PassRefPtr.h" 41 42 using namespace WebCore; 43 44 namespace blink { 45 46 bool WebFormControlElement::isEnabled() const 47 { 48 return !constUnwrap<HTMLFormControlElement>()->isDisabledFormControl(); 49 } 50 51 bool WebFormControlElement::isReadOnly() const 52 { 53 return constUnwrap<HTMLFormControlElement>()->isReadOnly(); 54 } 55 56 WebString WebFormControlElement::formControlName() const 57 { 58 return constUnwrap<HTMLFormControlElement>()->name(); 59 } 60 61 WebString WebFormControlElement::formControlType() const 62 { 63 return constUnwrap<HTMLFormControlElement>()->type(); 64 } 65 66 void WebFormControlElement::dispatchFormControlChangeEvent() 67 { 68 unwrap<HTMLFormControlElement>()->dispatchFormControlChangeEvent(); 69 } 70 71 bool WebFormControlElement::isAutofilled() const 72 { 73 return constUnwrap<HTMLFormControlElement>()->isAutofilled(); 74 } 75 76 void WebFormControlElement::setAutofilled(bool autofilled) 77 { 78 unwrap<HTMLFormControlElement>()->setAutofilled(autofilled); 79 } 80 81 WebString WebFormControlElement::nameForAutofill() const 82 { 83 return constUnwrap<HTMLFormControlElement>()->nameForAutofill(); 84 } 85 86 bool WebFormControlElement::autoComplete() const 87 { 88 if (isHTMLInputElement(*m_private)) 89 return constUnwrap<HTMLInputElement>()->shouldAutocomplete(); 90 if (isHTMLTextAreaElement(*m_private)) 91 return constUnwrap<HTMLTextAreaElement>()->shouldAutocomplete(); 92 return false; 93 } 94 95 void WebFormControlElement::setValue(const WebString& value, bool sendEvents) 96 { 97 if (isHTMLInputElement(*m_private)) 98 unwrap<HTMLInputElement>()->setValue(value, sendEvents ? DispatchInputAndChangeEvent : DispatchNoEvent); 99 else if (isHTMLTextAreaElement(*m_private)) 100 unwrap<HTMLTextAreaElement>()->setValue(value, sendEvents ? DispatchInputAndChangeEvent : DispatchNoEvent); 101 else if (isHTMLSelectElement(*m_private)) 102 unwrap<HTMLSelectElement>()->setValue(value, sendEvents); 103 } 104 105 WebString WebFormControlElement::value() const 106 { 107 if (isHTMLInputElement(*m_private)) 108 return constUnwrap<HTMLInputElement>()->value(); 109 if (isHTMLTextAreaElement(*m_private)) 110 return constUnwrap<HTMLTextAreaElement>()->value(); 111 if (isHTMLSelectElement(*m_private)) 112 return constUnwrap<HTMLSelectElement>()->value(); 113 return WebString(); 114 } 115 116 void WebFormControlElement::setSuggestedValue(const WebString& value) 117 { 118 if (isHTMLInputElement(*m_private)) 119 unwrap<HTMLInputElement>()->setSuggestedValue(value); 120 else if (isHTMLTextAreaElement(*m_private)) 121 unwrap<HTMLTextAreaElement>()->setSuggestedValue(value); 122 else if (isHTMLSelectElement(*m_private)) 123 unwrap<HTMLSelectElement>()->setSuggestedValue(value); 124 } 125 126 WebString WebFormControlElement::suggestedValue() const 127 { 128 if (isHTMLInputElement(*m_private)) 129 return constUnwrap<HTMLInputElement>()->suggestedValue(); 130 if (isHTMLTextAreaElement(*m_private)) 131 return constUnwrap<HTMLTextAreaElement>()->suggestedValue(); 132 if (isHTMLSelectElement(*m_private)) 133 return constUnwrap<HTMLSelectElement>()->suggestedValue(); 134 return WebString(); 135 } 136 137 WebString WebFormControlElement::editingValue() const 138 { 139 if (isHTMLInputElement(*m_private)) 140 return constUnwrap<HTMLInputElement>()->innerEditorValue(); 141 if (isHTMLTextAreaElement(*m_private)) 142 return constUnwrap<HTMLTextAreaElement>()->innerEditorValue(); 143 return WebString(); 144 } 145 146 void WebFormControlElement::setSelectionRange(int start, int end) 147 { 148 if (isHTMLInputElement(*m_private)) 149 unwrap<HTMLInputElement>()->setSelectionRange(start, end); 150 else if (isHTMLTextAreaElement(*m_private)) 151 unwrap<HTMLTextAreaElement>()->setSelectionRange(start, end); 152 } 153 154 int WebFormControlElement::selectionStart() const 155 { 156 if (isHTMLInputElement(*m_private)) 157 return constUnwrap<HTMLInputElement>()->selectionStart(); 158 if (isHTMLTextAreaElement(*m_private)) 159 return constUnwrap<HTMLTextAreaElement>()->selectionStart(); 160 return 0; 161 } 162 163 int WebFormControlElement::selectionEnd() const 164 { 165 if (isHTMLInputElement(*m_private)) 166 return constUnwrap<HTMLInputElement>()->selectionEnd(); 167 if (isHTMLTextAreaElement(*m_private)) 168 return constUnwrap<HTMLTextAreaElement>()->selectionEnd(); 169 return 0; 170 } 171 172 WebString WebFormControlElement::directionForFormData() const 173 { 174 if (isHTMLInputElement(*m_private)) 175 return constUnwrap<HTMLInputElement>()->directionForFormData(); 176 if (isHTMLTextAreaElement(*m_private)) 177 return constUnwrap<HTMLTextAreaElement>()->directionForFormData(); 178 return WebString(); 179 } 180 181 bool WebFormControlElement::isActivatedSubmit() const 182 { 183 return constUnwrap<HTMLFormControlElement>()->isActivatedSubmit(); 184 } 185 186 WebFormElement WebFormControlElement::form() const 187 { 188 return WebFormElement(constUnwrap<HTMLFormControlElement>()->form()); 189 } 190 191 WebFormControlElement::WebFormControlElement(const PassRefPtrWillBeRawPtr<HTMLFormControlElement>& elem) 192 : WebElement(elem) 193 { 194 } 195 196 WebFormControlElement& WebFormControlElement::operator=(const PassRefPtrWillBeRawPtr<HTMLFormControlElement>& elem) 197 { 198 m_private = elem; 199 return *this; 200 } 201 202 WebFormControlElement::operator PassRefPtrWillBeRawPtr<HTMLFormControlElement>() const 203 { 204 return toHTMLFormControlElement(m_private.get()); 205 } 206 207 } // namespace blink 208