Torne (Richard Coles) | 5c87bf8 | 2012-11-14 11:46:17 +0000 | [diff] [blame] | 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 "WebFormControlElement.h" |
| 33 | |
Torne (Richard Coles) | 53e740f | 2013-05-09 18:38:43 +0100 | [diff] [blame] | 34 | #include "core/html/HTMLFormControlElement.h" |
| 35 | #include "core/html/HTMLFormElement.h" |
Torne (Richard Coles) | d5428f3 | 2014-03-18 10:21:16 +0000 | [diff] [blame] | 36 | #include "core/html/HTMLInputElement.h" |
| 37 | #include "core/html/HTMLSelectElement.h" |
| 38 | #include "core/html/HTMLTextAreaElement.h" |
| 39 | |
Ben Murdoch | 591b958 | 2013-07-10 11:41:44 +0100 | [diff] [blame] | 40 | #include "wtf/PassRefPtr.h" |
Torne (Richard Coles) | 5c87bf8 | 2012-11-14 11:46:17 +0000 | [diff] [blame] | 41 | |
| 42 | using namespace WebCore; |
| 43 | |
Torne (Richard Coles) | 51b2906 | 2013-11-28 11:56:03 +0000 | [diff] [blame] | 44 | namespace blink { |
Torne (Richard Coles) | 5c87bf8 | 2012-11-14 11:46:17 +0000 | [diff] [blame] | 45 | |
| 46 | bool WebFormControlElement::isEnabled() const |
| 47 | { |
Torne (Richard Coles) | 53e740f | 2013-05-09 18:38:43 +0100 | [diff] [blame] | 48 | return !constUnwrap<HTMLFormControlElement>()->isDisabledFormControl(); |
Torne (Richard Coles) | 5c87bf8 | 2012-11-14 11:46:17 +0000 | [diff] [blame] | 49 | } |
| 50 | |
| 51 | bool WebFormControlElement::isReadOnly() const |
| 52 | { |
Torne (Richard Coles) | 53e740f | 2013-05-09 18:38:43 +0100 | [diff] [blame] | 53 | return constUnwrap<HTMLFormControlElement>()->isReadOnly(); |
Torne (Richard Coles) | 5c87bf8 | 2012-11-14 11:46:17 +0000 | [diff] [blame] | 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 | |
Torne (Richard Coles) | 1e20218 | 2013-10-18 15:46:42 +0100 | [diff] [blame] | 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 | |
Torne (Richard Coles) | 5c87bf8 | 2012-11-14 11:46:17 +0000 | [diff] [blame] | 81 | WebString WebFormControlElement::nameForAutofill() const |
| 82 | { |
Torne (Richard Coles) | a854de0 | 2013-12-18 16:25:25 +0000 | [diff] [blame] | 83 | return constUnwrap<HTMLFormControlElement>()->nameForAutofill(); |
Torne (Richard Coles) | 5c87bf8 | 2012-11-14 11:46:17 +0000 | [diff] [blame] | 84 | } |
| 85 | |
Torne (Richard Coles) | d5428f3 | 2014-03-18 10:21:16 +0000 | [diff] [blame] | 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 | |
Ben Murdoch | 07a852d | 2014-03-31 11:51:52 +0100 | [diff] [blame] | 95 | void WebFormControlElement::setValue(const WebString& value, bool sendEvents) |
Torne (Richard Coles) | d5428f3 | 2014-03-18 10:21:16 +0000 | [diff] [blame] | 96 | { |
| 97 | if (isHTMLInputElement(*m_private)) |
Ben Murdoch | 07a852d | 2014-03-31 11:51:52 +0100 | [diff] [blame] | 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); |
Torne (Richard Coles) | d5428f3 | 2014-03-18 10:21:16 +0000 | [diff] [blame] | 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); |
Ben Murdoch | 07a852d | 2014-03-31 11:51:52 +0100 | [diff] [blame] | 120 | else if (isHTMLTextAreaElement(*m_private)) |
Torne (Richard Coles) | d5428f3 | 2014-03-18 10:21:16 +0000 | [diff] [blame] | 121 | unwrap<HTMLTextAreaElement>()->setSuggestedValue(value); |
Ben Murdoch | 07a852d | 2014-03-31 11:51:52 +0100 | [diff] [blame] | 122 | else if (isHTMLSelectElement(*m_private)) |
Torne (Richard Coles) | 43e7502 | 2014-03-21 14:26:12 +0000 | [diff] [blame] | 123 | unwrap<HTMLSelectElement>()->setSuggestedValue(value); |
Torne (Richard Coles) | d5428f3 | 2014-03-18 10:21:16 +0000 | [diff] [blame] | 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(); |
Torne (Richard Coles) | 43e7502 | 2014-03-21 14:26:12 +0000 | [diff] [blame] | 132 | if (isHTMLSelectElement(*m_private)) |
| 133 | return constUnwrap<HTMLSelectElement>()->suggestedValue(); |
Torne (Richard Coles) | d5428f3 | 2014-03-18 10:21:16 +0000 | [diff] [blame] | 134 | return WebString(); |
| 135 | } |
| 136 | |
| 137 | WebString WebFormControlElement::editingValue() const |
| 138 | { |
| 139 | if (isHTMLInputElement(*m_private)) |
| 140 | return constUnwrap<HTMLInputElement>()->innerTextValue(); |
| 141 | if (isHTMLTextAreaElement(*m_private)) |
| 142 | return constUnwrap<HTMLTextAreaElement>()->innerTextValue(); |
| 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); |
Ben Murdoch | 07a852d | 2014-03-31 11:51:52 +0100 | [diff] [blame] | 150 | else if (isHTMLTextAreaElement(*m_private)) |
Torne (Richard Coles) | d5428f3 | 2014-03-18 10:21:16 +0000 | [diff] [blame] | 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 | |
Torne (Richard Coles) | 5c87bf8 | 2012-11-14 11:46:17 +0000 | [diff] [blame] | 181 | WebFormElement WebFormControlElement::form() const |
| 182 | { |
| 183 | return WebFormElement(constUnwrap<HTMLFormControlElement>()->form()); |
| 184 | } |
| 185 | |
| 186 | WebFormControlElement::WebFormControlElement(const PassRefPtr<HTMLFormControlElement>& elem) |
| 187 | : WebElement(elem) |
| 188 | { |
| 189 | } |
| 190 | |
| 191 | WebFormControlElement& WebFormControlElement::operator=(const PassRefPtr<HTMLFormControlElement>& elem) |
| 192 | { |
| 193 | m_private = elem; |
| 194 | return *this; |
| 195 | } |
| 196 | |
| 197 | WebFormControlElement::operator PassRefPtr<HTMLFormControlElement>() const |
| 198 | { |
Ben Murdoch | 591b958 | 2013-07-10 11:41:44 +0100 | [diff] [blame] | 199 | return toHTMLFormControlElement(m_private.get()); |
Torne (Richard Coles) | 5c87bf8 | 2012-11-14 11:46:17 +0000 | [diff] [blame] | 200 | } |
| 201 | |
Torne (Richard Coles) | 51b2906 | 2013-11-28 11:56:03 +0000 | [diff] [blame] | 202 | } // namespace blink |