blob: 1a1fb4ec468edc55fed7d1b21c378443983f18ef [file] [log] [blame]
Torne (Richard Coles)5c87bf82012-11-14 11:46:17 +00001/*
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)53e740f2013-05-09 18:38:43 +010034#include "core/html/HTMLFormControlElement.h"
35#include "core/html/HTMLFormElement.h"
Torne (Richard Coles)d5428f32014-03-18 10:21:16 +000036#include "core/html/HTMLInputElement.h"
37#include "core/html/HTMLSelectElement.h"
38#include "core/html/HTMLTextAreaElement.h"
39
Ben Murdoch591b9582013-07-10 11:41:44 +010040#include "wtf/PassRefPtr.h"
Torne (Richard Coles)5c87bf82012-11-14 11:46:17 +000041
42using namespace WebCore;
43
Torne (Richard Coles)51b29062013-11-28 11:56:03 +000044namespace blink {
Torne (Richard Coles)5c87bf82012-11-14 11:46:17 +000045
46bool WebFormControlElement::isEnabled() const
47{
Torne (Richard Coles)53e740f2013-05-09 18:38:43 +010048 return !constUnwrap<HTMLFormControlElement>()->isDisabledFormControl();
Torne (Richard Coles)5c87bf82012-11-14 11:46:17 +000049}
50
51bool WebFormControlElement::isReadOnly() const
52{
Torne (Richard Coles)53e740f2013-05-09 18:38:43 +010053 return constUnwrap<HTMLFormControlElement>()->isReadOnly();
Torne (Richard Coles)5c87bf82012-11-14 11:46:17 +000054}
55
56WebString WebFormControlElement::formControlName() const
57{
58 return constUnwrap<HTMLFormControlElement>()->name();
59}
60
61WebString WebFormControlElement::formControlType() const
62{
63 return constUnwrap<HTMLFormControlElement>()->type();
64}
65
66void WebFormControlElement::dispatchFormControlChangeEvent()
67{
68 unwrap<HTMLFormControlElement>()->dispatchFormControlChangeEvent();
69}
70
Torne (Richard Coles)1e202182013-10-18 15:46:42 +010071bool WebFormControlElement::isAutofilled() const
72{
73 return constUnwrap<HTMLFormControlElement>()->isAutofilled();
74}
75
76void WebFormControlElement::setAutofilled(bool autofilled)
77{
78 unwrap<HTMLFormControlElement>()->setAutofilled(autofilled);
79}
80
Torne (Richard Coles)5c87bf82012-11-14 11:46:17 +000081WebString WebFormControlElement::nameForAutofill() const
82{
Torne (Richard Coles)a854de02013-12-18 16:25:25 +000083 return constUnwrap<HTMLFormControlElement>()->nameForAutofill();
Torne (Richard Coles)5c87bf82012-11-14 11:46:17 +000084}
85
Torne (Richard Coles)d5428f32014-03-18 10:21:16 +000086bool 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 Murdoch07a852d2014-03-31 11:51:52 +010095void WebFormControlElement::setValue(const WebString& value, bool sendEvents)
Torne (Richard Coles)d5428f32014-03-18 10:21:16 +000096{
97 if (isHTMLInputElement(*m_private))
Ben Murdoch07a852d2014-03-31 11:51:52 +010098 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)d5428f32014-03-18 10:21:16 +0000103}
104
105WebString 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
116void WebFormControlElement::setSuggestedValue(const WebString& value)
117{
118 if (isHTMLInputElement(*m_private))
119 unwrap<HTMLInputElement>()->setSuggestedValue(value);
Ben Murdoch07a852d2014-03-31 11:51:52 +0100120 else if (isHTMLTextAreaElement(*m_private))
Torne (Richard Coles)d5428f32014-03-18 10:21:16 +0000121 unwrap<HTMLTextAreaElement>()->setSuggestedValue(value);
Ben Murdoch07a852d2014-03-31 11:51:52 +0100122 else if (isHTMLSelectElement(*m_private))
Torne (Richard Coles)43e75022014-03-21 14:26:12 +0000123 unwrap<HTMLSelectElement>()->setSuggestedValue(value);
Torne (Richard Coles)d5428f32014-03-18 10:21:16 +0000124}
125
126WebString 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)43e75022014-03-21 14:26:12 +0000132 if (isHTMLSelectElement(*m_private))
133 return constUnwrap<HTMLSelectElement>()->suggestedValue();
Torne (Richard Coles)d5428f32014-03-18 10:21:16 +0000134 return WebString();
135}
136
137WebString 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
146void WebFormControlElement::setSelectionRange(int start, int end)
147{
148 if (isHTMLInputElement(*m_private))
149 unwrap<HTMLInputElement>()->setSelectionRange(start, end);
Ben Murdoch07a852d2014-03-31 11:51:52 +0100150 else if (isHTMLTextAreaElement(*m_private))
Torne (Richard Coles)d5428f32014-03-18 10:21:16 +0000151 unwrap<HTMLTextAreaElement>()->setSelectionRange(start, end);
152}
153
154int 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
163int 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
172WebString 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)5c87bf82012-11-14 11:46:17 +0000181WebFormElement WebFormControlElement::form() const
182{
183 return WebFormElement(constUnwrap<HTMLFormControlElement>()->form());
184}
185
186WebFormControlElement::WebFormControlElement(const PassRefPtr<HTMLFormControlElement>& elem)
187 : WebElement(elem)
188{
189}
190
191WebFormControlElement& WebFormControlElement::operator=(const PassRefPtr<HTMLFormControlElement>& elem)
192{
193 m_private = elem;
194 return *this;
195}
196
197WebFormControlElement::operator PassRefPtr<HTMLFormControlElement>() const
198{
Ben Murdoch591b9582013-07-10 11:41:44 +0100199 return toHTMLFormControlElement(m_private.get());
Torne (Richard Coles)5c87bf82012-11-14 11:46:17 +0000200}
201
Torne (Richard Coles)51b29062013-11-28 11:56:03 +0000202} // namespace blink