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 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
116 if (node->isHTMLElement() && toHTMLElement(node)->isInteractiveContent() ) | 116 if (node->isHTMLElement() && toHTMLElement(node)->isInteractiveContent() ) |
117 return true; | 117 return true; |
118 node = node->parentOrShadowHostNode(); | 118 node = node->parentOrShadowHostNode(); |
119 } | 119 } |
120 return false; | 120 return false; |
121 } | 121 } |
122 | 122 |
123 void HTMLLabelElement::defaultEventHandler(Event* evt) | 123 void HTMLLabelElement::defaultEventHandler(Event* evt) |
124 { | 124 { |
125 static bool processingClick = false; | 125 static bool processingClick = false; |
126 static bool isDragged = false; | |
126 | 127 |
127 if (evt->type() == EventTypeNames::click && !processingClick) { | 128 if (evt->type() == EventTypeNames::click && !processingClick) { |
129 // If click event is generated after selecting the text in label | |
130 // by dragging over it, then do not pass the click event to control | |
131 // element. | |
132 if (isDragged) { | |
133 isDragged = false; | |
esprehn
2014/09/09 20:32:45
Static vars like this seem pretty sketchy.
| |
134 return; | |
135 } | |
136 | |
128 // If the click is not simulated and the text of label element is | 137 // If the click is not simulated and the text of label element is |
129 // selected, do not pass the event to control element. | 138 // selected, by continous clicking, then save the selection |
139 // and pass the click event to control element. | |
130 // Note: a click event may be not a mouse event if created by | 140 // Note: a click event may be not a mouse event if created by |
131 // document.createEvent(). | 141 // document.createEvent(). |
142 VisibleSelection savedSelection; | |
132 if (evt->isMouseEvent() && !toMouseEvent(evt)->isSimulated()) { | 143 if (evt->isMouseEvent() && !toMouseEvent(evt)->isSimulated()) { |
133 if (LocalFrame* frame = document().frame()) { | 144 if (LocalFrame* frame = document().frame()) { |
134 if (frame->selection().selection().isRange()) | 145 if (frame->selection().isRange()) |
135 return; | 146 savedSelection = frame->selection().selection(); |
136 } | 147 } |
137 } | 148 } |
138 | 149 |
139 | |
140 RefPtrWillBeRawPtr<HTMLElement> element = control(); | 150 RefPtrWillBeRawPtr<HTMLElement> element = control(); |
141 | 151 |
142 // If we can't find a control or if the control received the click | 152 // 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. | 153 // event, then there's no need for us to do anything. |
144 if (!element || (evt->target() && element->containsIncludingShadowDOM(ev t->target()->toNode()))) | 154 if (!element || (evt->target() && element->containsIncludingShadowDOM(ev t->target()->toNode()))) |
145 return; | 155 return; |
146 | 156 |
147 if (evt->target() && isInInteractiveContent(evt->target()->toNode())) | 157 if (evt->target() && isInInteractiveContent(evt->target()->toNode())) |
148 return; | 158 return; |
149 | 159 |
150 processingClick = true; | 160 processingClick = true; |
151 | 161 |
152 document().updateLayoutIgnorePendingStylesheets(); | 162 document().updateLayoutIgnorePendingStylesheets(); |
153 if (element->isMouseFocusable()) | 163 if (element->isMouseFocusable()) |
154 element->focus(true, FocusTypeMouse); | 164 element->focus(true, FocusTypeMouse); |
155 | 165 |
156 // Click the corresponding control. | 166 // Click the corresponding control. |
157 element->dispatchSimulatedClick(evt); | 167 element->dispatchSimulatedClick(evt); |
158 | 168 |
169 // Restore the saved selection. | |
170 if (savedSelection.isRange()) { | |
171 if (LocalFrame* frame = document().frame()) | |
172 frame->selection().setSelection(savedSelection); | |
173 } | |
174 | |
159 processingClick = false; | 175 processingClick = false; |
160 | 176 |
161 evt->setDefaultHandled(); | 177 evt->setDefaultHandled(); |
178 } else if (evt->type() == EventTypeNames::mousemove && evt->isMouseEvent()) { | |
179 MouseEvent* mouseEvent = toMouseEvent(evt); | |
180 if (mouseEvent->button() != LeftButton || !mouseEvent->buttonDown()) | |
181 return; | |
182 // Mark isDragged: true, as selection is started, | |
183 // by dragging the mouse over label text. | |
184 isDragged = true; | |
esprehn
2014/09/09 20:32:45
This doesn't seem like the right way to detect dra
| |
162 } | 185 } |
163 | 186 |
164 HTMLElement::defaultEventHandler(evt); | 187 HTMLElement::defaultEventHandler(evt); |
165 } | 188 } |
166 | 189 |
167 bool HTMLLabelElement::willRespondToMouseClickEvents() | 190 bool HTMLLabelElement::willRespondToMouseClickEvents() |
168 { | 191 { |
169 if (control() && control()->willRespondToMouseClickEvents()) | 192 if (control() && control()->willRespondToMouseClickEvents()) |
170 return true; | 193 return true; |
171 | 194 |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
228 { | 251 { |
229 if (insertionPoint->isInTreeScope() && treeScope() == document()) { | 252 if (insertionPoint->isInTreeScope() && treeScope() == document()) { |
230 TreeScope& treeScope = insertionPoint->treeScope(); | 253 TreeScope& treeScope = insertionPoint->treeScope(); |
231 if (treeScope.shouldCacheLabelsByForAttribute()) | 254 if (treeScope.shouldCacheLabelsByForAttribute()) |
232 updateLabel(treeScope, fastGetAttribute(forAttr), nullAtom); | 255 updateLabel(treeScope, fastGetAttribute(forAttr), nullAtom); |
233 } | 256 } |
234 HTMLElement::removedFrom(insertionPoint); | 257 HTMLElement::removedFrom(insertionPoint); |
235 } | 258 } |
236 | 259 |
237 } // namespace | 260 } // namespace |
OLD | NEW |