OLD | NEW |
---|---|
1 /* | 1 /* |
2 * Copyright (C) 1999 Lars Knoll (knoll@kde.org) | 2 * Copyright (C) 1999 Lars Knoll (knoll@kde.org) |
3 * (C) 1999 Antti Koivisto (koivisto@kde.org) | 3 * (C) 1999 Antti Koivisto (koivisto@kde.org) |
4 * (C) 2001 Dirk Mueller (mueller@kde.org) | 4 * (C) 2001 Dirk Mueller (mueller@kde.org) |
5 * Copyright (C) 2004, 2005, 2006, 2007, 2010 Apple Inc. All rights reserved. | 5 * Copyright (C) 2004, 2005, 2006, 2007, 2010 Apple Inc. All rights reserved. |
6 * (C) 2006 Alexey Proskuryakov (ap@nypop.com) | 6 * (C) 2006 Alexey Proskuryakov (ap@nypop.com) |
7 * | 7 * |
8 * This library is free software; you can redistribute it and/or | 8 * This library is free software; you can redistribute it and/or |
9 * modify it under the terms of the GNU Library General Public | 9 * modify it under the terms of the GNU Library General Public |
10 * License as published by the Free Software Foundation; either | 10 * License as published by the Free Software Foundation; either |
(...skipping 14 matching lines...) Expand all Loading... | |
25 #include "config.h" | 25 #include "config.h" |
26 #include "core/html/HTMLLabelElement.h" | 26 #include "core/html/HTMLLabelElement.h" |
27 | 27 |
28 #include "core/HTMLNames.h" | 28 #include "core/HTMLNames.h" |
29 #include "core/dom/Document.h" | 29 #include "core/dom/Document.h" |
30 #include "core/dom/ElementTraversal.h" | 30 #include "core/dom/ElementTraversal.h" |
31 #include "core/editing/FrameSelection.h" | 31 #include "core/editing/FrameSelection.h" |
32 #include "core/events/MouseEvent.h" | 32 #include "core/events/MouseEvent.h" |
33 #include "core/frame/LocalFrame.h" | 33 #include "core/frame/LocalFrame.h" |
34 #include "core/html/FormAssociatedElement.h" | 34 #include "core/html/FormAssociatedElement.h" |
35 #include "core/page/EventHandler.h" | |
35 | 36 |
36 namespace blink { | 37 namespace blink { |
37 | 38 |
38 using namespace HTMLNames; | 39 using namespace HTMLNames; |
39 | 40 |
40 inline HTMLLabelElement::HTMLLabelElement(Document& document) | 41 inline HTMLLabelElement::HTMLLabelElement(Document& document) |
41 : HTMLElement(labelTag, document) | 42 : HTMLElement(labelTag, document) |
42 { | 43 { |
43 } | 44 } |
44 | 45 |
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
118 node = node->parentOrShadowHostNode(); | 119 node = node->parentOrShadowHostNode(); |
119 } | 120 } |
120 return false; | 121 return false; |
121 } | 122 } |
122 | 123 |
123 void HTMLLabelElement::defaultEventHandler(Event* evt) | 124 void HTMLLabelElement::defaultEventHandler(Event* evt) |
124 { | 125 { |
125 static bool processingClick = false; | 126 static bool processingClick = false; |
126 | 127 |
127 if (evt->type() == EventTypeNames::click && !processingClick) { | 128 if (evt->type() == EventTypeNames::click && !processingClick) { |
128 // 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
| |
129 // selected, do not pass the event to control element. | |
130 // Note: a click event may be not a mouse event if created by | |
131 // document.createEvent(). | |
132 if (evt->isMouseEvent() && !toMouseEvent(evt)->isSimulated()) { | |
133 if (LocalFrame* frame = document().frame()) { | |
134 if (frame->selection().selection().isRange()) | |
135 return; | |
136 } | |
137 } | |
138 | |
139 | |
140 RefPtrWillBeRawPtr<HTMLElement> element = control(); | 129 RefPtrWillBeRawPtr<HTMLElement> element = control(); |
141 | 130 |
142 // If we can't find a control or if the control received the click | 131 // If we can't find a control or if the control received the click |
143 // event, then there's no need for us to do anything. | 132 // event, then there's no need for us to do anything. |
144 if (!element || (evt->target() && element->containsIncludingShadowDOM(ev t->target()->toNode()))) | 133 if (!element || (evt->target() && element->containsIncludingShadowDOM(ev t->target()->toNode()))) |
145 return; | 134 return; |
146 | 135 |
147 if (evt->target() && isInInteractiveContent(evt->target()->toNode())) | 136 if (evt->target() && isInInteractiveContent(evt->target()->toNode())) |
148 return; | 137 return; |
149 | 138 |
139 bool isLabelTextSelected = false; | |
140 | |
141 // If the click is not simulated and the text of the label element | |
142 // is selected by dragging over it, then return without passing the | |
143 // click event to control element. | |
144 // Note: a click event may be not a mouse event if created by | |
145 // document.createEvent(). | |
146 if (evt->isMouseEvent() && !toMouseEvent(evt)->isSimulated()) { | |
147 if (LocalFrame* frame = document().frame()) { | |
148 if (frame->selection().isRange() && !frame->eventHandler().isMou seDownWasSingleClickInSelection()) | |
149 isLabelTextSelected = true; | |
150 // If selection is there and is single click i.e. text is select ed | |
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.
| |
151 // by dragging over label text, then return. | |
152 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.
| |
153 return; | |
154 } | |
155 } | |
156 | |
150 processingClick = true; | 157 processingClick = true; |
151 | 158 |
152 document().updateLayoutIgnorePendingStylesheets(); | 159 document().updateLayoutIgnorePendingStylesheets(); |
153 if (element->isMouseFocusable()) | 160 if (element->isMouseFocusable()) { |
154 element->focus(true, FocusTypeMouse); | 161 // 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.
| |
162 if (!isLabelTextSelected) | |
163 element->focus(true, FocusTypeMouse); | |
164 } | |
155 | 165 |
156 // Click the corresponding control. | 166 // Click the corresponding control. |
157 element->dispatchSimulatedClick(evt); | 167 element->dispatchSimulatedClick(evt); |
158 | 168 |
159 processingClick = false; | 169 processingClick = false; |
160 | 170 |
161 evt->setDefaultHandled(); | 171 evt->setDefaultHandled(); |
162 } | 172 } |
163 | 173 |
164 HTMLElement::defaultEventHandler(evt); | 174 HTMLElement::defaultEventHandler(evt); |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
228 { | 238 { |
229 if (insertionPoint->isInTreeScope() && treeScope() == document()) { | 239 if (insertionPoint->isInTreeScope() && treeScope() == document()) { |
230 TreeScope& treeScope = insertionPoint->treeScope(); | 240 TreeScope& treeScope = insertionPoint->treeScope(); |
231 if (treeScope.shouldCacheLabelsByForAttribute()) | 241 if (treeScope.shouldCacheLabelsByForAttribute()) |
232 updateLabel(treeScope, fastGetAttribute(forAttr), nullAtom); | 242 updateLabel(treeScope, fastGetAttribute(forAttr), nullAtom); |
233 } | 243 } |
234 HTMLElement::removedFrom(insertionPoint); | 244 HTMLElement::removedFrom(insertionPoint); |
235 } | 245 } |
236 | 246 |
237 } // namespace | 247 } // namespace |
OLD | NEW |