Index: Source/core/html/HTMLLabelElement.cpp |
diff --git a/Source/core/html/HTMLLabelElement.cpp b/Source/core/html/HTMLLabelElement.cpp |
index 354514026d3d51c1dd607049a2a51fe6a5a756e5..e5efef9c4f749a6af798ac96cdfaca7cdff323c8 100644 |
--- a/Source/core/html/HTMLLabelElement.cpp |
+++ b/Source/core/html/HTMLLabelElement.cpp |
@@ -32,6 +32,7 @@ |
#include "core/events/MouseEvent.h" |
#include "core/frame/LocalFrame.h" |
#include "core/html/FormAssociatedElement.h" |
+#include "core/page/EventHandler.h" |
namespace blink { |
@@ -125,18 +126,6 @@ void HTMLLabelElement::defaultEventHandler(Event* evt) |
static bool processingClick = false; |
if (evt->type() == EventTypeNames::click && !processingClick) { |
- // If the click is not simulated and the text of label element is |
tkent
2014/09/16 01:53:37
Why do you move the code?
deepak.sa
2014/09/16 10:31:16
All the checks should happen once it is clear that
|
- // 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 |
@@ -147,11 +136,32 @@ void HTMLLabelElement::defaultEventHandler(Event* evt) |
if (evt->target() && isInInteractiveContent(evt->target()->toNode())) |
return; |
+ bool isLabelTextSelected = false; |
+ |
+ // If the click is not simulated and the text of the label element |
+ // is selected by dragging over it, then return without passing the |
+ // click 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().isRange() && !frame->eventHandler().isMouseDownWasSingleClickInSelection()) |
+ isLabelTextSelected = true; |
+ // If selection is there and is single click i.e. text is selected |
tkent
2014/09/16 01:53:38
nit: I recommend to wrap code comments in 80 colum
deepak.sa
2014/09/16 10:31:16
Added additional comments.
|
+ // by dragging over label text, then return. |
+ if (isLabelTextSelected && frame->eventHandler().clickCount() == 1) |
tkent
2014/09/16 01:53:38
Need a comment why clickCount>=2 should not skip t
deepak.sa
2014/09/16 10:31:16
Added more comments.
|
+ return; |
+ } |
+ } |
+ |
processingClick = true; |
document().updateLayoutIgnorePendingStylesheets(); |
- if (element->isMouseFocusable()) |
- element->focus(true, FocusTypeMouse); |
+ if (element->isMouseFocusable()) { |
+ // If there is selection, do not focus the control element. |
tkent
2014/09/16 01:53:38
This comment is helpless. It just says what the co
deepak.sa
2014/09/16 10:31:16
Replaced this comment.
|
+ if (!isLabelTextSelected) |
+ element->focus(true, FocusTypeMouse); |
+ } |
// Click the corresponding control. |
element->dispatchSimulatedClick(evt); |