diff options
Diffstat (limited to 'Source/WebCore/html/HTMLButtonElement.cpp')
-rw-r--r-- | Source/WebCore/html/HTMLButtonElement.cpp | 76 |
1 files changed, 42 insertions, 34 deletions
diff --git a/Source/WebCore/html/HTMLButtonElement.cpp b/Source/WebCore/html/HTMLButtonElement.cpp index bceeef5e9..c7913e113 100644 --- a/Source/WebCore/html/HTMLButtonElement.cpp +++ b/Source/WebCore/html/HTMLButtonElement.cpp @@ -2,7 +2,7 @@ * Copyright (C) 1999 Lars Knoll (knoll@kde.org) * (C) 1999 Antti Koivisto (koivisto@kde.org) * (C) 2001 Dirk Mueller (mueller@kde.org) - * Copyright (C) 2004, 2005, 2006, 2007, 2010 Apple Inc. All rights reserved. + * Copyright (C) 2004, 2005, 2006, 2007, 2010, 2016 Apple Inc. All rights reserved. * (C) 2006 Alexey Proskuryakov (ap@nypop.com) * Copyright (C) 2007 Samuel Weinig (sam@webkit.org) * @@ -26,7 +26,6 @@ #include "config.h" #include "HTMLButtonElement.h" -#include "Attribute.h" #include "EventNames.h" #include "FormDataList.h" #include "HTMLFormElement.h" @@ -47,34 +46,34 @@ inline HTMLButtonElement::HTMLButtonElement(const QualifiedName& tagName, Docume ASSERT(hasTagName(buttonTag)); } -PassRefPtr<HTMLButtonElement> HTMLButtonElement::create(const QualifiedName& tagName, Document& document, HTMLFormElement* form) +Ref<HTMLButtonElement> HTMLButtonElement::create(const QualifiedName& tagName, Document& document, HTMLFormElement* form) { - return adoptRef(new HTMLButtonElement(tagName, document, form)); + return adoptRef(*new HTMLButtonElement(tagName, document, form)); } void HTMLButtonElement::setType(const AtomicString& type) { - setAttribute(typeAttr, type); + setAttributeWithoutSynchronization(typeAttr, type); } -RenderPtr<RenderElement> HTMLButtonElement::createElementRenderer(PassRef<RenderStyle> style) +RenderPtr<RenderElement> HTMLButtonElement::createElementRenderer(RenderStyle&& style, const RenderTreePosition&) { - return createRenderer<RenderButton>(*this, std::move(style)); + return createRenderer<RenderButton>(*this, WTFMove(style)); } const AtomicString& HTMLButtonElement::formControlType() const { switch (m_type) { case SUBMIT: { - DEFINE_STATIC_LOCAL(const AtomicString, submit, ("submit", AtomicString::ConstructFromLiteral)); + static NeverDestroyed<const AtomicString> submit("submit", AtomicString::ConstructFromLiteral); return submit; } case BUTTON: { - DEFINE_STATIC_LOCAL(const AtomicString, button, ("button", AtomicString::ConstructFromLiteral)); + static NeverDestroyed<const AtomicString> button("button", AtomicString::ConstructFromLiteral); return button; } case RESET: { - DEFINE_STATIC_LOCAL(const AtomicString, reset, ("reset", AtomicString::ConstructFromLiteral)); + static NeverDestroyed<const AtomicString> reset("reset", AtomicString::ConstructFromLiteral); return reset; } } @@ -97,54 +96,60 @@ bool HTMLButtonElement::isPresentationAttribute(const QualifiedName& name) const void HTMLButtonElement::parseAttribute(const QualifiedName& name, const AtomicString& value) { if (name == typeAttr) { - if (equalIgnoringCase(value, "reset")) + Type oldType = m_type; + if (equalLettersIgnoringASCIICase(value, "reset")) m_type = RESET; - else if (equalIgnoringCase(value, "button")) + else if (equalLettersIgnoringASCIICase(value, "button")) m_type = BUTTON; else m_type = SUBMIT; - setNeedsWillValidateCheck(); + if (oldType != m_type) { + setNeedsWillValidateCheck(); + if (form() && (oldType == SUBMIT || m_type == SUBMIT)) + form()->resetDefaultButton(); + } } else HTMLFormControlElement::parseAttribute(name, value); } -void HTMLButtonElement::defaultEventHandler(Event* event) +void HTMLButtonElement::defaultEventHandler(Event& event) { - if (event->type() == eventNames().DOMActivateEvent && !isDisabledFormControl()) { + if (event.type() == eventNames().DOMActivateEvent && !isDisabledFormControl()) { if (form() && m_type == SUBMIT) { m_isActivatedSubmit = true; form()->prepareForSubmission(event); - event->setDefaultHandled(); + event.setDefaultHandled(); m_isActivatedSubmit = false; // Do this in case submission was canceled. } if (form() && m_type == RESET) { form()->reset(); - event->setDefaultHandled(); + event.setDefaultHandled(); } } - if (event->isKeyboardEvent()) { - if (event->type() == eventNames().keydownEvent && static_cast<KeyboardEvent*>(event)->keyIdentifier() == "U+0020") { + if (is<KeyboardEvent>(event)) { + KeyboardEvent& keyboardEvent = downcast<KeyboardEvent>(event); + if (keyboardEvent.type() == eventNames().keydownEvent && keyboardEvent.keyIdentifier() == "U+0020") { setActive(true, true); // No setDefaultHandled() - IE dispatches a keypress in this case. return; } - if (event->type() == eventNames().keypressEvent) { - switch (static_cast<KeyboardEvent*>(event)->charCode()) { + if (keyboardEvent.type() == eventNames().keypressEvent) { + switch (keyboardEvent.charCode()) { case '\r': - dispatchSimulatedClick(event); - event->setDefaultHandled(); + dispatchSimulatedClick(&keyboardEvent); + keyboardEvent.setDefaultHandled(); return; case ' ': // Prevent scrolling down the page. - event->setDefaultHandled(); + keyboardEvent.setDefaultHandled(); return; } } - if (event->type() == eventNames().keyupEvent && static_cast<KeyboardEvent*>(event)->keyIdentifier() == "U+0020") { + if (keyboardEvent.type() == eventNames().keyupEvent && keyboardEvent.keyIdentifier() == "U+0020") { if (active()) - dispatchSimulatedClick(event); - event->setDefaultHandled(); + dispatchSimulatedClick(&keyboardEvent); + keyboardEvent.setDefaultHandled(); return; } } @@ -154,9 +159,7 @@ void HTMLButtonElement::defaultEventHandler(Event* event) bool HTMLButtonElement::willRespondToMouseClickEvents() { - if (!isDisabledFormControl() && form() && (m_type == SUBMIT || m_type == RESET)) - return true; - return HTMLFormControlElement::willRespondToMouseClickEvents(); + return !isDisabledFormControl(); } bool HTMLButtonElement::isSuccessfulSubmitButton() const @@ -166,6 +169,11 @@ bool HTMLButtonElement::isSuccessfulSubmitButton() const return m_type == SUBMIT && !isDisabledFormControl(); } +bool HTMLButtonElement::matchesDefaultPseudoClass() const +{ + return isSuccessfulSubmitButton() && form() && form()->defaultButton() == this; +} + bool HTMLButtonElement::isActivatedSubmit() const { return m_isActivatedSubmit; @@ -196,14 +204,14 @@ bool HTMLButtonElement::isURLAttribute(const Attribute& attribute) const return attribute.name() == formactionAttr || HTMLFormControlElement::isURLAttribute(attribute); } -String HTMLButtonElement::value() const +const AtomicString& HTMLButtonElement::value() const { - return getAttribute(valueAttr); + return attributeWithoutSynchronization(valueAttr); } -bool HTMLButtonElement::recalcWillValidate() const +bool HTMLButtonElement::computeWillValidate() const { - return m_type == SUBMIT && HTMLFormControlElement::recalcWillValidate(); + return m_type == SUBMIT && HTMLFormControlElement::computeWillValidate(); } } // namespace |