15c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)/*
25c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * Copyright (C) 2010 Google Inc. All rights reserved.
35c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * Copyright (C) 2011 Apple Inc. All rights reserved.
45c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) *
55c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * Redistribution and use in source and binary forms, with or without
65c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * modification, are permitted provided that the following conditions are
75c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * met:
85c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) *
95c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) *     * Redistributions of source code must retain the above copyright
105c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * notice, this list of conditions and the following disclaimer.
115c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) *     * Redistributions in binary form must reproduce the above
125c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * copyright notice, this list of conditions and the following disclaimer
135c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * in the documentation and/or other materials provided with the
145c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * distribution.
155c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) *     * Neither the name of Google Inc. nor the names of its
165c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * contributors may be used to endorse or promote products derived from
175c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * this software without specific prior written permission.
185c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) *
195c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
205c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
215c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
225c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
235c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
245c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
255c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
265c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
275c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
285c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
295c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
305c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) */
315c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
325c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)#include "config.h"
3306f816c7c76bc45a15e452ade8a34e8af077693eTorne (Richard Coles)#include "core/html/forms/SubmitInputType.h"
345c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
355d92fedcae5e801a8b224de090094f2d9df0b54aTorne (Richard Coles)#include "core/InputTypeNames.h"
3606f816c7c76bc45a15e452ade8a34e8af077693eTorne (Richard Coles)#include "core/events/Event.h"
37bfe3590b1806e3ff18f46ee3af5d4b83078f305aTorne (Richard Coles)#include "core/html/FormDataList.h"
3853e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles)#include "core/html/HTMLFormElement.h"
3953e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles)#include "core/html/HTMLInputElement.h"
401e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)#include "platform/text/PlatformLocale.h"
41e69819bd8e388ea4ad1636a19aa6b2eed4952191Ben Murdoch#include "wtf/PassOwnPtr.h"
425c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
43c1847b1379d12d0e05df27436bf19a9b1bf12deaTorne (Richard Coles)namespace blink {
445c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
45323480423219ecd77329f8326dc5e0e3b50926d4Torne (Richard Coles)PassRefPtrWillBeRawPtr<InputType> SubmitInputType::create(HTMLInputElement& element)
465c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles){
47323480423219ecd77329f8326dc5e0e3b50926d4Torne (Richard Coles)    return adoptRefWillBeNoop(new SubmitInputType(element));
485c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)}
495c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
505c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)const AtomicString& SubmitInputType::formControlType() const
515c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles){
5251b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)    return InputTypeNames::submit;
535c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)}
545c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
555c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)bool SubmitInputType::appendFormData(FormDataList& encoding, bool) const
565c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles){
57bfe3590b1806e3ff18f46ee3af5d4b83078f305aTorne (Richard Coles)    if (!element().isActivatedSubmit())
585c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)        return false;
59bfe3590b1806e3ff18f46ee3af5d4b83078f305aTorne (Richard Coles)    encoding.appendData(element().name(), element().valueWithDefault());
605c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    return true;
615c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)}
625c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
635c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)bool SubmitInputType::supportsRequired() const
645c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles){
655c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    return false;
665c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)}
675c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
685c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)void SubmitInputType::handleDOMActivateEvent(Event* event)
695c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles){
70d6cdb82654e8f3343a693ca752d5c4cee0324e17Torne (Richard Coles)    RefPtrWillBeRawPtr<HTMLInputElement> element(this->element());
7153e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles)    if (element->isDisabledFormControl() || !element->form())
725c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)        return;
735c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    element->setActivatedSubmit(true);
745c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    element->form()->prepareForSubmission(event); // Event handlers can run.
755c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    element->setActivatedSubmit(false);
765c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    event->setDefaultHandled();
775c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)}
785c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
795c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)bool SubmitInputType::canBeSuccessfulSubmitButton()
805c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles){
815c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    return true;
825c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)}
835c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
845c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)String SubmitInputType::defaultValue() const
855c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles){
8651b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)    return locale().queryString(blink::WebLocalizedString::SubmitButtonDefaultLabel);
875c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)}
885c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
895c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)bool SubmitInputType::isTextButton() const
905c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles){
915c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    return true;
925c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)}
935c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
94c1847b1379d12d0e05df27436bf19a9b1bf12deaTorne (Richard Coles)} // namespace blink
95