Index: Source/core/html/HTMLLabelElement.cpp |
diff --git a/Source/core/html/HTMLLabelElement.cpp b/Source/core/html/HTMLLabelElement.cpp |
index 354514026d3d51c1dd607049a2a51fe6a5a756e5..bca898a9bb303e42de99fcd41aecb5a0b3fdb374 100644 |
--- a/Source/core/html/HTMLLabelElement.cpp |
+++ b/Source/core/html/HTMLLabelElement.cpp |
@@ -123,20 +123,30 @@ bool HTMLLabelElement::isInInteractiveContent(Node* node) const |
void HTMLLabelElement::defaultEventHandler(Event* evt) |
{ |
static bool processingClick = false; |
+ static bool isDragged = false; |
if (evt->type() == EventTypeNames::click && !processingClick) { |
+ // If click event is generated after selecting the text in label |
+ // by dragging over it, then do not pass the click event to control |
+ // element. |
+ if (isDragged) { |
+ isDragged = false; |
esprehn
2014/09/09 20:32:45
Static vars like this seem pretty sketchy.
|
+ return; |
+ } |
+ |
// If the click is not simulated and the text of label element is |
- // selected, do not pass the event to control element. |
+ // selected, by continous clicking, then save the selection |
+ // and pass the click event to control element. |
// Note: a click event may be not a mouse event if created by |
// document.createEvent(). |
+ VisibleSelection savedSelection; |
if (evt->isMouseEvent() && !toMouseEvent(evt)->isSimulated()) { |
if (LocalFrame* frame = document().frame()) { |
- if (frame->selection().selection().isRange()) |
- return; |
+ if (frame->selection().isRange()) |
+ savedSelection = frame->selection().selection(); |
} |
} |
- |
RefPtrWillBeRawPtr<HTMLElement> element = control(); |
// If we can't find a control or if the control received the click |
@@ -156,9 +166,22 @@ void HTMLLabelElement::defaultEventHandler(Event* evt) |
// Click the corresponding control. |
element->dispatchSimulatedClick(evt); |
+ // Restore the saved selection. |
+ if (savedSelection.isRange()) { |
+ if (LocalFrame* frame = document().frame()) |
+ frame->selection().setSelection(savedSelection); |
+ } |
+ |
processingClick = false; |
evt->setDefaultHandled(); |
+ } else if (evt->type() == EventTypeNames::mousemove && evt->isMouseEvent()) { |
+ MouseEvent* mouseEvent = toMouseEvent(evt); |
+ if (mouseEvent->button() != LeftButton || !mouseEvent->buttonDown()) |
+ return; |
+ // Mark isDragged: true, as selection is started, |
+ // by dragging the mouse over label text. |
+ isDragged = true; |
esprehn
2014/09/09 20:32:45
This doesn't seem like the right way to detect dra
|
} |
HTMLElement::defaultEventHandler(evt); |