Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1088)

Unified Diff: Source/core/html/HTMLLabelElement.cpp

Issue 556813002: Fix behavior of label associated with control element (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Rebased Created 6 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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);

Powered by Google App Engine
This is Rietveld 408576698