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/NodeComputedStyle.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"
45 bool WebFormControlElement::isEnabled() const
47 return !constUnwrap
<HTMLFormControlElement
>()->isDisabledFormControl();
50 bool WebFormControlElement::isReadOnly() const
52 return constUnwrap
<HTMLFormControlElement
>()->isReadOnly();
55 WebString
WebFormControlElement::formControlName() const
57 return constUnwrap
<HTMLFormControlElement
>()->name();
60 WebString
WebFormControlElement::formControlType() const
62 return constUnwrap
<HTMLFormControlElement
>()->type();
65 bool WebFormControlElement::isAutofilled() const
67 return constUnwrap
<HTMLFormControlElement
>()->isAutofilled();
70 void WebFormControlElement::setAutofilled(bool autofilled
)
72 unwrap
<HTMLFormControlElement
>()->setAutofilled(autofilled
);
75 WebString
WebFormControlElement::nameForAutofill() const
77 return constUnwrap
<HTMLFormControlElement
>()->nameForAutofill();
80 bool WebFormControlElement::autoComplete() const
82 if (isHTMLInputElement(*m_private
))
83 return constUnwrap
<HTMLInputElement
>()->shouldAutocomplete();
84 if (isHTMLTextAreaElement(*m_private
))
85 return constUnwrap
<HTMLTextAreaElement
>()->shouldAutocomplete();
89 void WebFormControlElement::setValue(const WebString
& value
, bool sendEvents
)
91 if (isHTMLInputElement(*m_private
))
92 unwrap
<HTMLInputElement
>()->setValue(value
, sendEvents
? DispatchInputAndChangeEvent
: DispatchNoEvent
);
93 else if (isHTMLTextAreaElement(*m_private
))
94 unwrap
<HTMLTextAreaElement
>()->setValue(value
, sendEvents
? DispatchInputAndChangeEvent
: DispatchNoEvent
);
95 else if (isHTMLSelectElement(*m_private
))
96 unwrap
<HTMLSelectElement
>()->setValue(value
, sendEvents
);
99 WebString
WebFormControlElement::value() const
101 if (isHTMLInputElement(*m_private
))
102 return constUnwrap
<HTMLInputElement
>()->value();
103 if (isHTMLTextAreaElement(*m_private
))
104 return constUnwrap
<HTMLTextAreaElement
>()->value();
105 if (isHTMLSelectElement(*m_private
))
106 return constUnwrap
<HTMLSelectElement
>()->value();
110 void WebFormControlElement::setSuggestedValue(const WebString
& value
)
112 if (isHTMLInputElement(*m_private
))
113 unwrap
<HTMLInputElement
>()->setSuggestedValue(value
);
114 else if (isHTMLTextAreaElement(*m_private
))
115 unwrap
<HTMLTextAreaElement
>()->setSuggestedValue(value
);
116 else if (isHTMLSelectElement(*m_private
))
117 unwrap
<HTMLSelectElement
>()->setSuggestedValue(value
);
120 WebString
WebFormControlElement::suggestedValue() const
122 if (isHTMLInputElement(*m_private
))
123 return constUnwrap
<HTMLInputElement
>()->suggestedValue();
124 if (isHTMLTextAreaElement(*m_private
))
125 return constUnwrap
<HTMLTextAreaElement
>()->suggestedValue();
126 if (isHTMLSelectElement(*m_private
))
127 return constUnwrap
<HTMLSelectElement
>()->suggestedValue();
131 WebString
WebFormControlElement::editingValue() const
133 if (isHTMLInputElement(*m_private
))
134 return constUnwrap
<HTMLInputElement
>()->innerEditorValue();
135 if (isHTMLTextAreaElement(*m_private
))
136 return constUnwrap
<HTMLTextAreaElement
>()->innerEditorValue();
140 void WebFormControlElement::setSelectionRange(int start
, int end
)
142 if (isHTMLInputElement(*m_private
))
143 unwrap
<HTMLInputElement
>()->setSelectionRange(start
, end
, SelectionHasNoDirection
, NotDispatchSelectEvent
);
144 else if (isHTMLTextAreaElement(*m_private
))
145 unwrap
<HTMLTextAreaElement
>()->setSelectionRange(start
, end
, SelectionHasNoDirection
, NotDispatchSelectEvent
);
148 int WebFormControlElement::selectionStart() const
150 if (isHTMLInputElement(*m_private
))
151 return constUnwrap
<HTMLInputElement
>()->selectionStart();
152 if (isHTMLTextAreaElement(*m_private
))
153 return constUnwrap
<HTMLTextAreaElement
>()->selectionStart();
157 int WebFormControlElement::selectionEnd() const
159 if (isHTMLInputElement(*m_private
))
160 return constUnwrap
<HTMLInputElement
>()->selectionEnd();
161 if (isHTMLTextAreaElement(*m_private
))
162 return constUnwrap
<HTMLTextAreaElement
>()->selectionEnd();
166 WebString
WebFormControlElement::directionForFormData() const
168 if (const ComputedStyle
* style
= constUnwrap
<HTMLFormControlElement
>()->computedStyle())
169 return style
->isLeftToRightDirection() ? WebString::fromUTF8("ltr") : WebString::fromUTF8("rtl");
170 return WebString::fromUTF8("ltr");
173 WebFormElement
WebFormControlElement::form() const
175 return WebFormElement(constUnwrap
<HTMLFormControlElement
>()->form());
178 WebFormControlElement::WebFormControlElement(const PassRefPtrWillBeRawPtr
<HTMLFormControlElement
>& elem
)
183 WebFormControlElement
& WebFormControlElement::operator=(const PassRefPtrWillBeRawPtr
<HTMLFormControlElement
>& elem
)
189 WebFormControlElement::operator PassRefPtrWillBeRawPtr
<HTMLFormControlElement
>() const
191 return toHTMLFormControlElement(m_private
.get());