2 * Copyright (C) 2009 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 "WebFormElement.h"
34 #include "FormState.h"
35 #include "HTMLFormControlElement.h"
36 #include "HTMLFormElement.h"
37 #include "HTMLInputElement.h"
38 #include "HTMLNames.h"
39 #include "WebFormControlElement.h"
40 #include "WebInputElement.h"
41 #include "WebString.h"
43 #include <wtf/PassRefPtr.h>
45 using namespace WebCore;
49 bool WebFormElement::autoComplete() const
51 return constUnwrap<HTMLFormElement>()->shouldAutocomplete();
54 WebString WebFormElement::action() const
56 return constUnwrap<HTMLFormElement>()->action();
59 WebString WebFormElement::name() const
61 return constUnwrap<HTMLFormElement>()->name();
64 WebString WebFormElement::method() const
66 return constUnwrap<HTMLFormElement>()->method();
69 bool WebFormElement::wasUserSubmitted() const
71 return constUnwrap<HTMLFormElement>()->wasUserSubmitted();
74 void WebFormElement::submit()
76 unwrap<HTMLFormElement>()->submit();
79 void WebFormElement::getNamedElements(const WebString& name,
80 WebVector<WebNode>& result)
82 Vector<RefPtr<Node> > tempVector;
83 unwrap<HTMLFormElement>()->getNamedElements(name, tempVector);
84 result.assign(tempVector);
87 void WebFormElement::getFormControlElements(WebVector<WebFormControlElement>& result) const
89 const HTMLFormElement* form = constUnwrap<HTMLFormElement>();
90 Vector<RefPtr<HTMLFormControlElement> > tempVector;
91 // FIXME: We should move the for-loop condition into a variable instead of
92 // re-evaluating size each time. Also, consider refactoring this code so that
93 // we don't call form->associatedElements() multiple times.
94 for (size_t i = 0; i < form->associatedElements().size(); i++) {
95 if (!form->associatedElements()[i]->isFormControlElement())
97 HTMLFormControlElement* element = static_cast<HTMLFormControlElement*>(form->associatedElements()[i]);
98 if (element->hasLocalName(HTMLNames::inputTag)
99 || element->hasLocalName(HTMLNames::selectTag))
100 tempVector.append(element);
102 result.assign(tempVector);
105 WebFormElement::WebFormElement(const PassRefPtr<HTMLFormElement>& e)
110 WebFormElement& WebFormElement::operator=(const PassRefPtr<HTMLFormElement>& e)
116 WebFormElement::operator PassRefPtr<HTMLFormElement>() const
118 return static_cast<HTMLFormElement*>(m_private.get());
121 } // namespace WebKit