2 * Copyright (C) 2010 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.
32 #include "public/web/WebFormControlElement.h"
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"
40 #include "wtf/PassRefPtr.h"
42 using namespace WebCore;
46 bool WebFormControlElement::isEnabled() const
48 return !constUnwrap<HTMLFormControlElement>()->isDisabledFormControl();
51 bool WebFormControlElement::isReadOnly() const
53 return constUnwrap<HTMLFormControlElement>()->isReadOnly();
56 WebString WebFormControlElement::formControlName() const
58 return constUnwrap<HTMLFormControlElement>()->name();
61 WebString WebFormControlElement::formControlType() const
63 return constUnwrap<HTMLFormControlElement>()->type();
66 void WebFormControlElement::dispatchFormControlChangeEvent()
68 unwrap<HTMLFormControlElement>()->dispatchFormControlChangeEvent();
71 bool WebFormControlElement::isAutofilled() const
73 return constUnwrap<HTMLFormControlElement>()->isAutofilled();
76 void WebFormControlElement::setAutofilled(bool autofilled)
78 unwrap<HTMLFormControlElement>()->setAutofilled(autofilled);
81 WebString WebFormControlElement::nameForAutofill() const
83 return constUnwrap<HTMLFormControlElement>()->nameForAutofill();
86 bool WebFormControlElement::autoComplete() const
88 if (isHTMLInputElement(*m_private))
89 return constUnwrap<HTMLInputElement>()->shouldAutocomplete();
90 if (isHTMLTextAreaElement(*m_private))
91 return constUnwrap<HTMLTextAreaElement>()->shouldAutocomplete();
95 void WebFormControlElement::setValue(const WebString& value, bool sendEvents)
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);
105 WebString WebFormControlElement::value() const
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();
116 void WebFormControlElement::setSuggestedValue(const WebString& value)
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);
126 WebString WebFormControlElement::suggestedValue() const
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();
137 WebString WebFormControlElement::editingValue() const
139 if (isHTMLInputElement(*m_private))
140 return constUnwrap<HTMLInputElement>()->innerTextValue();
141 if (isHTMLTextAreaElement(*m_private))
142 return constUnwrap<HTMLTextAreaElement>()->innerTextValue();
146 void WebFormControlElement::setSelectionRange(int start, int end)
148 if (isHTMLInputElement(*m_private))
149 unwrap<HTMLInputElement>()->setSelectionRange(start, end);
150 else if (isHTMLTextAreaElement(*m_private))
151 unwrap<HTMLTextAreaElement>()->setSelectionRange(start, end);
154 int WebFormControlElement::selectionStart() const
156 if (isHTMLInputElement(*m_private))
157 return constUnwrap<HTMLInputElement>()->selectionStart();
158 if (isHTMLTextAreaElement(*m_private))
159 return constUnwrap<HTMLTextAreaElement>()->selectionStart();
163 int WebFormControlElement::selectionEnd() const
165 if (isHTMLInputElement(*m_private))
166 return constUnwrap<HTMLInputElement>()->selectionEnd();
167 if (isHTMLTextAreaElement(*m_private))
168 return constUnwrap<HTMLTextAreaElement>()->selectionEnd();
172 WebString WebFormControlElement::directionForFormData() const
174 if (isHTMLInputElement(*m_private))
175 return constUnwrap<HTMLInputElement>()->directionForFormData();
176 if (isHTMLTextAreaElement(*m_private))
177 return constUnwrap<HTMLTextAreaElement>()->directionForFormData();
181 bool WebFormControlElement::isActivatedSubmit() const
183 return constUnwrap<HTMLFormControlElement>()->isActivatedSubmit();
186 WebFormElement WebFormControlElement::form() const
188 return WebFormElement(constUnwrap<HTMLFormControlElement>()->form());
191 WebFormControlElement::WebFormControlElement(const PassRefPtrWillBeRawPtr<HTMLFormControlElement>& elem)
196 WebFormControlElement& WebFormControlElement::operator=(const PassRefPtrWillBeRawPtr<HTMLFormControlElement>& elem)
202 WebFormControlElement::operator PassRefPtrWillBeRawPtr<HTMLFormControlElement>() const
204 return toHTMLFormControlElement(m_private.get());