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/dom/NodeRenderStyle.h"
35 #include "core/html/HTMLFormControlElement.h"
36 #include "core/html/HTMLFormElement.h"
37 #include "core/html/HTMLInputElement.h"
38 #include "core/html/HTMLSelectElement.h"
39 #include "core/html/HTMLTextAreaElement.h"
41 #include "wtf/PassRefPtr.h"
43 using namespace blink;
47 bool WebFormControlElement::isEnabled() const
49 return !constUnwrap<HTMLFormControlElement>()->isDisabledFormControl();
52 bool WebFormControlElement::isReadOnly() const
54 return constUnwrap<HTMLFormControlElement>()->isReadOnly();
57 WebString WebFormControlElement::formControlName() const
59 return constUnwrap<HTMLFormControlElement>()->name();
62 WebString WebFormControlElement::formControlType() const
64 return constUnwrap<HTMLFormControlElement>()->type();
67 void WebFormControlElement::dispatchFormControlChangeEvent()
69 unwrap<HTMLFormControlElement>()->dispatchFormControlChangeEvent();
72 bool WebFormControlElement::isAutofilled() const
74 return constUnwrap<HTMLFormControlElement>()->isAutofilled();
77 void WebFormControlElement::setAutofilled(bool autofilled)
79 unwrap<HTMLFormControlElement>()->setAutofilled(autofilled);
82 WebString WebFormControlElement::nameForAutofill() const
84 return constUnwrap<HTMLFormControlElement>()->nameForAutofill();
87 bool WebFormControlElement::autoComplete() const
89 if (isHTMLInputElement(*m_private))
90 return constUnwrap<HTMLInputElement>()->shouldAutocomplete();
91 if (isHTMLTextAreaElement(*m_private))
92 return constUnwrap<HTMLTextAreaElement>()->shouldAutocomplete();
96 void WebFormControlElement::setValue(const WebString& value, bool sendEvents)
98 if (isHTMLInputElement(*m_private))
99 unwrap<HTMLInputElement>()->setValue(value, sendEvents ? DispatchInputAndChangeEvent : DispatchNoEvent);
100 else if (isHTMLTextAreaElement(*m_private))
101 unwrap<HTMLTextAreaElement>()->setValue(value, sendEvents ? DispatchInputAndChangeEvent : DispatchNoEvent);
102 else if (isHTMLSelectElement(*m_private))
103 unwrap<HTMLSelectElement>()->setValue(value, sendEvents);
106 WebString WebFormControlElement::value() const
108 if (isHTMLInputElement(*m_private))
109 return constUnwrap<HTMLInputElement>()->value();
110 if (isHTMLTextAreaElement(*m_private))
111 return constUnwrap<HTMLTextAreaElement>()->value();
112 if (isHTMLSelectElement(*m_private))
113 return constUnwrap<HTMLSelectElement>()->value();
117 void WebFormControlElement::setSuggestedValue(const WebString& value)
119 if (isHTMLInputElement(*m_private))
120 unwrap<HTMLInputElement>()->setSuggestedValue(value);
121 else if (isHTMLTextAreaElement(*m_private))
122 unwrap<HTMLTextAreaElement>()->setSuggestedValue(value);
123 else if (isHTMLSelectElement(*m_private))
124 unwrap<HTMLSelectElement>()->setSuggestedValue(value);
127 WebString WebFormControlElement::suggestedValue() const
129 if (isHTMLInputElement(*m_private))
130 return constUnwrap<HTMLInputElement>()->suggestedValue();
131 if (isHTMLTextAreaElement(*m_private))
132 return constUnwrap<HTMLTextAreaElement>()->suggestedValue();
133 if (isHTMLSelectElement(*m_private))
134 return constUnwrap<HTMLSelectElement>()->suggestedValue();
138 WebString WebFormControlElement::editingValue() const
140 if (isHTMLInputElement(*m_private))
141 return constUnwrap<HTMLInputElement>()->innerEditorValue();
142 if (isHTMLTextAreaElement(*m_private))
143 return constUnwrap<HTMLTextAreaElement>()->innerEditorValue();
147 void WebFormControlElement::setSelectionRange(int start, int end)
149 if (isHTMLInputElement(*m_private))
150 unwrap<HTMLInputElement>()->setSelectionRange(start, end);
151 else if (isHTMLTextAreaElement(*m_private))
152 unwrap<HTMLTextAreaElement>()->setSelectionRange(start, end);
155 int WebFormControlElement::selectionStart() const
157 if (isHTMLInputElement(*m_private))
158 return constUnwrap<HTMLInputElement>()->selectionStart();
159 if (isHTMLTextAreaElement(*m_private))
160 return constUnwrap<HTMLTextAreaElement>()->selectionStart();
164 int WebFormControlElement::selectionEnd() const
166 if (isHTMLInputElement(*m_private))
167 return constUnwrap<HTMLInputElement>()->selectionEnd();
168 if (isHTMLTextAreaElement(*m_private))
169 return constUnwrap<HTMLTextAreaElement>()->selectionEnd();
173 WebString WebFormControlElement::directionForFormData() const
175 if (RenderStyle* style = constUnwrap<HTMLFormControlElement>()->renderStyle())
176 return style->isLeftToRightDirection() ? WebString::fromUTF8("ltr") : WebString::fromUTF8("rtl");
177 return WebString::fromUTF8("ltr");
180 bool WebFormControlElement::isActivatedSubmit() const
182 return constUnwrap<HTMLFormControlElement>()->isActivatedSubmit();
185 WebFormElement WebFormControlElement::form() const
187 return WebFormElement(constUnwrap<HTMLFormControlElement>()->form());
190 WebFormControlElement::WebFormControlElement(const PassRefPtrWillBeRawPtr<HTMLFormControlElement>& elem)
195 WebFormControlElement& WebFormControlElement::operator=(const PassRefPtrWillBeRawPtr<HTMLFormControlElement>& elem)
201 WebFormControlElement::operator PassRefPtrWillBeRawPtr<HTMLFormControlElement>() const
203 return toHTMLFormControlElement(m_private.get());