Home | History | Annotate | Download | only in src
      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 "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"
     42 #include "WebURL.h"
     43 #include <wtf/PassRefPtr.h>
     44 
     45 using namespace WebCore;
     46 
     47 namespace WebKit {
     48 
     49 bool WebFormElement::autoComplete() const
     50 {
     51     return constUnwrap<HTMLFormElement>()->autoComplete();
     52 }
     53 
     54 WebString WebFormElement::action() const
     55 {
     56     return constUnwrap<HTMLFormElement>()->action();
     57 }
     58 
     59 WebString WebFormElement::name() const
     60 {
     61     return constUnwrap<HTMLFormElement>()->name();
     62 }
     63 
     64 WebString WebFormElement::method() const
     65 {
     66     return constUnwrap<HTMLFormElement>()->method();
     67 }
     68 
     69 bool WebFormElement::wasUserSubmitted() const
     70 {
     71     return constUnwrap<HTMLFormElement>()->wasUserSubmitted();
     72 }
     73 
     74 void WebFormElement::submit()
     75 {
     76     unwrap<HTMLFormElement>()->submit();
     77 }
     78 
     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 
     87 void WebFormElement::getFormControlElements(WebVector<WebFormControlElement>& result) const
     88 {
     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())
     96             continue;
     97         HTMLFormControlElement* element = static_cast<HTMLFormControlElement*>(form->associatedElements()[i]);
     98         if (element->hasLocalName(HTMLNames::inputTag)
     99             || element->hasLocalName(HTMLNames::selectTag))
    100             tempVector.append(element);
    101     }
    102     result.assign(tempVector);
    103 }
    104 
    105 WebFormElement::WebFormElement(const PassRefPtr<HTMLFormElement>& e)
    106     : WebElement(e)
    107 {
    108 }
    109 
    110 WebFormElement& WebFormElement::operator=(const PassRefPtr<HTMLFormElement>& e)
    111 {
    112     m_private = e;
    113     return *this;
    114 }
    115 
    116 WebFormElement::operator PassRefPtr<HTMLFormElement>() const
    117 {
    118     return static_cast<HTMLFormElement*>(m_private.get());
    119 }
    120 
    121 } // namespace WebKit
    122