1 /*
2 * Copyright (C) 2009 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 "WebFormElement.h"
33
34 #include "HTMLNames.h"
35 #include "WebFormControlElement.h"
36 #include "WebInputElement.h"
37 #include "core/html/HTMLFormControlElement.h"
38 #include "core/html/HTMLFormElement.h"
39 #include "core/html/HTMLInputElement.h"
40 #include "core/loader/FormState.h"
41 #include "public/platform/WebString.h"
42 #include "public/platform/WebURL.h"
43 #include "wtf/PassRefPtr.h"
44
45 using namespace WebCore;
46
47 namespace blink {
48
autoComplete() const49 bool WebFormElement::autoComplete() const
50 {
51 return constUnwrap<HTMLFormElement>()->shouldAutocomplete();
52 }
53
action() const54 WebString WebFormElement::action() const
55 {
56 return constUnwrap<HTMLFormElement>()->action();
57 }
58
name() const59 WebString WebFormElement::name() const
60 {
61 return constUnwrap<HTMLFormElement>()->name();
62 }
63
method() const64 WebString WebFormElement::method() const
65 {
66 return constUnwrap<HTMLFormElement>()->method();
67 }
68
wasUserSubmitted() const69 bool WebFormElement::wasUserSubmitted() const
70 {
71 return constUnwrap<HTMLFormElement>()->wasUserSubmitted();
72 }
73
submit()74 void WebFormElement::submit()
75 {
76 unwrap<HTMLFormElement>()->submit();
77 }
78
getNamedElements(const WebString & name,WebVector<WebNode> & result)79 void WebFormElement::getNamedElements(const WebString& name,
80 WebVector<WebNode>& result)
81 {
82 Vector<RefPtr<Node> > tempVector;
83 unwrap<HTMLFormElement>()->getNamedElements(name, tempVector);
84 result.assign(tempVector);
85 }
86
getFormControlElements(WebVector<WebFormControlElement> & result) const87 void WebFormElement::getFormControlElements(WebVector<WebFormControlElement>& result) const
88 {
89 const HTMLFormElement* form = constUnwrap<HTMLFormElement>();
90 Vector<RefPtr<HTMLFormControlElement> > formControlElements;
91
92 const Vector<FormAssociatedElement*>& associatedElements = form->associatedElements();
93 for (Vector<FormAssociatedElement*>::const_iterator it = associatedElements.begin(); it != associatedElements.end(); ++it) {
94 if ((*it)->isFormControlElement())
95 formControlElements.append(toHTMLFormControlElement(*it));
96 }
97 result.assign(formControlElements);
98 }
99
checkValidityWithoutDispatchingEvents()100 bool WebFormElement::checkValidityWithoutDispatchingEvents()
101 {
102 return unwrap<HTMLFormElement>()->checkValidityWithoutDispatchingEvents();
103 }
104
finishRequestAutocomplete(WebFormElement::AutocompleteResult result)105 void WebFormElement::finishRequestAutocomplete(WebFormElement::AutocompleteResult result)
106 {
107 unwrap<HTMLFormElement>()->finishRequestAutocomplete(static_cast<HTMLFormElement::AutocompleteResult>(result));
108 }
109
WebFormElement(const PassRefPtr<HTMLFormElement> & e)110 WebFormElement::WebFormElement(const PassRefPtr<HTMLFormElement>& e)
111 : WebElement(e)
112 {
113 }
114
operator =(const PassRefPtr<HTMLFormElement> & e)115 WebFormElement& WebFormElement::operator=(const PassRefPtr<HTMLFormElement>& e)
116 {
117 m_private = e;
118 return *this;
119 }
120
operator PassRefPtr<HTMLFormElement>() const121 WebFormElement::operator PassRefPtr<HTMLFormElement>() const
122 {
123 return toHTMLFormElement(m_private.get());
124 }
125
126 } // namespace blink
127