diff options
Diffstat (limited to 'chromium/third_party/WebKit/Source/core/html/HTMLLabelElement.cpp')
-rw-r--r-- | chromium/third_party/WebKit/Source/core/html/HTMLLabelElement.cpp | 54 |
1 files changed, 32 insertions, 22 deletions
diff --git a/chromium/third_party/WebKit/Source/core/html/HTMLLabelElement.cpp b/chromium/third_party/WebKit/Source/core/html/HTMLLabelElement.cpp index 6e8fa3d5ea0..ffaa6316873 100644 --- a/chromium/third_party/WebKit/Source/core/html/HTMLLabelElement.cpp +++ b/chromium/third_party/WebKit/Source/core/html/HTMLLabelElement.cpp @@ -25,23 +25,25 @@ #include "config.h" #include "core/html/HTMLLabelElement.h" -#include "HTMLNames.h" +#include "core/HTMLNames.h" +#include "core/dom/Document.h" #include "core/dom/ElementTraversal.h" -#include "core/events/Event.h" -#include "core/events/ThreadLocalEventNames.h" +#include "core/editing/FrameSelection.h" +#include "core/events/MouseEvent.h" +#include "core/frame/LocalFrame.h" #include "core/html/FormAssociatedElement.h" namespace WebCore { using namespace HTMLNames; -static bool supportsLabels(Element* element) +static bool supportsLabels(const Element& element) { - if (!element || !element->isHTMLElement()) + if (!element.isHTMLElement()) return false; - if (!toHTMLElement(element)->isLabelable()) + if (!toHTMLElement(element).isLabelable()) return false; - return toLabelableElement(element)->supportLabels(); + return toLabelableElement(element).supportLabels(); } inline HTMLLabelElement::HTMLLabelElement(Document& document) @@ -50,10 +52,7 @@ inline HTMLLabelElement::HTMLLabelElement(Document& document) ScriptWrappable::init(this); } -PassRefPtr<HTMLLabelElement> HTMLLabelElement::create(Document& document) -{ - return adoptRef(new HTMLLabelElement(document)); -} +DEFINE_NODE_FACTORY(HTMLLabelElement) bool HTMLLabelElement::rendererIsFocusable() const { @@ -61,16 +60,15 @@ bool HTMLLabelElement::rendererIsFocusable() const return that->isContentEditable(); } -LabelableElement* HTMLLabelElement::control() +LabelableElement* HTMLLabelElement::control() const { const AtomicString& controlId = getAttribute(forAttr); if (controlId.isNull()) { // Search the children and descendants of the label element for a form element. // per http://dev.w3.org/html5/spec/Overview.html#the-label-element // the form element must be "labelable form-associated element". - Element* element = this; - while ((element = ElementTraversal::next(*element, this))) { - if (!supportsLabels(element)) + for (Element* element = ElementTraversal::next(*this, this); element; element = ElementTraversal::next(*element, this)) { + if (!supportsLabels(*element)) continue; return toLabelableElement(element); } @@ -78,7 +76,7 @@ LabelableElement* HTMLLabelElement::control() } if (Element* element = treeScope().getElementById(controlId)) { - if (supportsLabels(element)) + if (supportsLabels(*element)) return toLabelableElement(element); } @@ -87,7 +85,7 @@ LabelableElement* HTMLLabelElement::control() HTMLFormElement* HTMLLabelElement::formOwner() const { - return FormAssociatedElement::findAssociatedForm(this, 0); + return FormAssociatedElement::findAssociatedForm(this); } void HTMLLabelElement::setActive(bool down) @@ -138,7 +136,19 @@ void HTMLLabelElement::defaultEventHandler(Event* evt) static bool processingClick = false; if (evt->type() == EventTypeNames::click && !processingClick) { - RefPtr<HTMLElement> element = control(); + // If the click is not simulated and the text of label element is + // selected, do not pass the event to control element. + // Note: a click event may be not a mouse event if created by + // document.createEvent(). + if (evt->isMouseEvent() && !toMouseEvent(evt)->isSimulated()) { + if (LocalFrame* frame = document().frame()) { + if (frame->selection().selection().isRange()) + return; + } + } + + + RefPtrWillBeRawPtr<HTMLElement> element = control(); // If we can't find a control or if the control received the click // event, then there's no need for us to do anything. @@ -152,7 +162,7 @@ void HTMLLabelElement::defaultEventHandler(Event* evt) document().updateLayoutIgnorePendingStylesheets(); if (element->isMouseFocusable()) - element->focus(true, FocusDirectionMouse); + element->focus(true, FocusTypeMouse); // Click the corresponding control. element->dispatchSimulatedClick(evt); @@ -173,13 +183,13 @@ bool HTMLLabelElement::willRespondToMouseClickEvents() return HTMLElement::willRespondToMouseClickEvents(); } -void HTMLLabelElement::focus(bool, FocusDirection direction) +void HTMLLabelElement::focus(bool, FocusType type) { // to match other browsers, always restore previous selection if (HTMLElement* element = control()) - element->focus(true, direction); + element->focus(true, type); if (isFocusable()) - HTMLElement::focus(true, direction); + HTMLElement::focus(true, type); } void HTMLLabelElement::accessKeyAction(bool sendMouseEvents) |