Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "core/input/MouseEventManager.h" | 5 #include "core/input/MouseEventManager.h" |
| 6 | 6 |
| 7 #include "core/clipboard/DataObject.h" | |
| 8 #include "core/clipboard/DataTransfer.h" | |
| 9 #include "core/dom/Element.h" | |
| 7 #include "core/dom/ElementTraversal.h" | 10 #include "core/dom/ElementTraversal.h" |
| 11 #include "core/editing/FrameSelection.h" | |
| 12 #include "core/editing/SelectionController.h" | |
| 13 #include "core/events/DragEvent.h" | |
| 8 #include "core/events/MouseEvent.h" | 14 #include "core/events/MouseEvent.h" |
| 15 #include "core/frame/FrameView.h" | |
| 16 #include "core/frame/LocalFrame.h" | |
| 17 #include "core/frame/Settings.h" | |
| 9 #include "core/html/HTMLCanvasElement.h" | 18 #include "core/html/HTMLCanvasElement.h" |
| 19 #include "core/input/EventHandler.h" | |
| 10 #include "core/input/EventHandlingUtil.h" | 20 #include "core/input/EventHandlingUtil.h" |
| 21 #include "core/input/InputDeviceCapabilities.h" | |
| 22 #include "core/input/KeyboardEventManager.h" | |
| 23 #include "core/layout/HitTestResult.h" | |
| 24 #include "core/layout/api/LayoutViewItem.h" | |
| 25 #include "core/page/AutoscrollController.h" | |
| 26 #include "core/page/DragController.h" | |
| 27 #include "core/page/DragState.h" | |
| 28 #include "core/page/FocusController.h" | |
| 29 #include "core/svg/SVGDocumentExtensions.h" | |
| 30 #include "platform/geometry/FloatQuad.h" | |
| 31 | |
| 11 | 32 |
| 12 namespace blink { | 33 namespace blink { |
| 13 | 34 |
| 14 namespace { | 35 namespace { |
| 15 | 36 |
| 16 PlatformMouseEvent mouseEventWithRegion(Node* node, const PlatformMouseEvent& mo useEvent) | 37 PlatformMouseEvent mouseEventWithRegion(Node* node, const PlatformMouseEvent& mo useEvent) |
| 17 { | 38 { |
| 18 if (!node->isElementNode()) | 39 if (!node->isElementNode()) |
| 19 return mouseEvent; | 40 return mouseEvent; |
| 20 | 41 |
| 21 Element* element = toElement(node); | 42 Element* element = toElement(node); |
| 22 if (!element->isInCanvasSubtree()) | 43 if (!element->isInCanvasSubtree()) |
| 23 return mouseEvent; | 44 return mouseEvent; |
| 24 | 45 |
| 25 HTMLCanvasElement* canvas = Traversal<HTMLCanvasElement>::firstAncestorOrSel f(*element); | 46 HTMLCanvasElement* canvas = Traversal<HTMLCanvasElement>::firstAncestorOrSel f(*element); |
| 26 // In this case, the event target is canvas and mouse rerouting doesn't happ en. | 47 // In this case, the event target is canvas and mouse rerouting doesn't happ en. |
| 27 if (canvas == element) | 48 if (canvas == element) |
| 28 return mouseEvent; | 49 return mouseEvent; |
| 29 String region = canvas->getIdFromControl(element); | 50 String region = canvas->getIdFromControl(element); |
| 30 PlatformMouseEvent newMouseEvent = mouseEvent; | 51 PlatformMouseEvent newMouseEvent = mouseEvent; |
| 31 newMouseEvent.setRegion(region); | 52 newMouseEvent.setRegion(region); |
| 32 return newMouseEvent; | 53 return newMouseEvent; |
| 33 } | 54 } |
| 34 | 55 |
| 35 } // namespace | 56 } // namespace |
| 36 | 57 |
| 58 // The amount of time to wait before sending a fake mouse event triggered | |
| 59 // during a scroll. | |
| 60 static const double fakeMouseMoveInterval = 0.1; | |
|
dtapuska
2016/09/21 17:07:44
Shouldn't these be in an anonymous namespace and f
Navid Zolghadr
2016/09/21 17:17:30
I don't know. I was copying it from EventHandler a
mustaq
2016/09/21 17:51:16
Let's use the kName style for all constants here.
Navid Zolghadr
2016/09/23 11:11:16
Done.
| |
| 61 | |
| 62 #if OS(MACOSX) | |
| 63 static const double TextDragDelay = 0.15; | |
| 64 #else | |
| 65 static const double TextDragDelay = 0.0; | |
| 66 #endif | |
| 67 | |
| 68 // The link drag hysteresis is much larger than the others because there | |
| 69 // needs to be enough space to cancel the link press without starting a link dra g, | |
| 70 // and because dragging links is rare. | |
| 71 static const int LinkDragHysteresis = 40; | |
| 72 static const int ImageDragHysteresis = 5; | |
| 73 static const int TextDragHysteresis = 3; | |
| 74 static const int GeneralDragHysteresis = 3; | |
| 75 | |
| 76 enum class DragInitiator { Mouse, Touch }; | |
| 77 | |
| 37 MouseEventManager::MouseEventBoundaryEventDispatcher::MouseEventBoundaryEventDis patcher( | 78 MouseEventManager::MouseEventBoundaryEventDispatcher::MouseEventBoundaryEventDis patcher( |
| 38 MouseEventManager* mouseEventManager, | 79 MouseEventManager* mouseEventManager, |
| 39 const PlatformMouseEvent* platformMouseEvent, | 80 const PlatformMouseEvent* platformMouseEvent, |
| 40 EventTarget* exitedTarget) | 81 EventTarget* exitedTarget) |
| 41 : m_mouseEventManager(mouseEventManager) | 82 : m_mouseEventManager(mouseEventManager) |
| 42 , m_platformMouseEvent(platformMouseEvent) | 83 , m_platformMouseEvent(platformMouseEvent) |
| 43 , m_exitedTarget(exitedTarget) | 84 , m_exitedTarget(exitedTarget) |
| 44 { | 85 { |
| 45 } | 86 } |
| 46 | 87 |
| (...skipping 29 matching lines...) Expand all Loading... | |
| 76 AtomicString MouseEventManager::MouseEventBoundaryEventDispatcher::getEnterEvent () | 117 AtomicString MouseEventManager::MouseEventBoundaryEventDispatcher::getEnterEvent () |
| 77 { | 118 { |
| 78 return EventTypeNames::mouseenter; | 119 return EventTypeNames::mouseenter; |
| 79 } | 120 } |
| 80 | 121 |
| 81 void MouseEventManager::MouseEventBoundaryEventDispatcher::dispatch( | 122 void MouseEventManager::MouseEventBoundaryEventDispatcher::dispatch( |
| 82 EventTarget* target, EventTarget* relatedTarget, const AtomicString& type, | 123 EventTarget* target, EventTarget* relatedTarget, const AtomicString& type, |
| 83 const PlatformMouseEvent& platformMouseEvent, bool checkForListener) | 124 const PlatformMouseEvent& platformMouseEvent, bool checkForListener) |
| 84 { | 125 { |
| 85 m_mouseEventManager->dispatchMouseEvent(target, type, platformMouseEvent, | 126 m_mouseEventManager->dispatchMouseEvent(target, type, platformMouseEvent, |
| 86 relatedTarget, 0, checkForListener); | 127 relatedTarget, checkForListener); |
| 87 } | 128 } |
| 88 | 129 |
| 89 void MouseEventManager::sendBoundaryEvents( | 130 void MouseEventManager::sendBoundaryEvents( |
| 90 EventTarget* exitedTarget, | 131 EventTarget* exitedTarget, |
| 91 EventTarget* enteredTarget, | 132 EventTarget* enteredTarget, |
| 92 const PlatformMouseEvent& mousePlatformEvent) | 133 const PlatformMouseEvent& mousePlatformEvent) |
| 93 { | 134 { |
| 94 MouseEventBoundaryEventDispatcher boundaryEventDispatcher(this, &mousePlatfo rmEvent, exitedTarget); | 135 MouseEventBoundaryEventDispatcher boundaryEventDispatcher(this, &mousePlatfo rmEvent, exitedTarget); |
| 95 boundaryEventDispatcher.sendBoundaryEvents(exitedTarget, enteredTarget); | 136 boundaryEventDispatcher.sendBoundaryEvents(exitedTarget, enteredTarget); |
| 96 } | 137 } |
| 97 | 138 |
| 98 WebInputEventResult MouseEventManager::dispatchMouseEvent( | 139 WebInputEventResult MouseEventManager::dispatchMouseEvent( |
| 99 EventTarget* target, | 140 EventTarget* target, |
| 100 const AtomicString& mouseEventType, | 141 const AtomicString& mouseEventType, |
| 101 const PlatformMouseEvent& mouseEvent, | 142 const PlatformMouseEvent& mouseEvent, |
| 102 EventTarget* relatedTarget, | 143 EventTarget* relatedTarget, |
| 103 int detail, | |
| 104 bool checkForListener) | 144 bool checkForListener) |
| 105 { | 145 { |
| 106 if (target && target->toNode() | 146 if (target && target->toNode() |
| 107 && (!checkForListener || target->hasEventListeners(mouseEventType))) { | 147 && (!checkForListener || target->hasEventListeners(mouseEventType))) { |
| 108 Node* targetNode = target->toNode(); | 148 Node* targetNode = target->toNode(); |
| 149 int clickCount = 0; | |
| 150 if (mouseEventType == EventTypeNames::mouseup | |
| 151 || mouseEventType == EventTypeNames::mousedown | |
| 152 || mouseEventType == EventTypeNames::click | |
| 153 || mouseEventType == EventTypeNames::auxclick | |
| 154 || mouseEventType == EventTypeNames::dblclick | |
| 155 || mouseEventType == EventTypeNames::mousedown) { | |
| 156 clickCount = m_clickCount; | |
| 157 } | |
| 109 MouseEvent* event = MouseEvent::create(mouseEventType, | 158 MouseEvent* event = MouseEvent::create(mouseEventType, |
| 110 targetNode->document().domWindow(), mouseEvent, detail, | 159 targetNode->document().domWindow(), mouseEvent, clickCount, |
| 111 relatedTarget ? relatedTarget->toNode() : nullptr); | 160 relatedTarget ? relatedTarget->toNode() : nullptr); |
| 112 DispatchEventResult dispatchResult = target->dispatchEvent(event); | 161 DispatchEventResult dispatchResult = target->dispatchEvent(event); |
| 113 return EventHandlingUtil::toWebInputEventResult(dispatchResult); | 162 return EventHandlingUtil::toWebInputEventResult(dispatchResult); |
| 114 } | 163 } |
| 115 return WebInputEventResult::NotHandled; | 164 return WebInputEventResult::NotHandled; |
| 116 } | 165 } |
| 117 | 166 |
| 118 MouseEventManager::MouseEventManager(LocalFrame* frame) | 167 WebInputEventResult MouseEventManager::dispatchMouseEvent( |
|
mustaq
2016/09/21 17:28:14
This method is very similar to the one above (both
Navid Zolghadr
2016/09/22 12:24:29
You mean like directDispatchMouseEvent?
Navid Zolghadr
2016/09/23 11:11:16
I changed the second function name to setMousePosi
| |
| 168 Node* targetNode, const AtomicString& eventType, | |
| 169 const PlatformMouseEvent& platformMouseEvent) | |
| 170 { | |
| 171 // If the target node is a text node, dispatch on the parent node. | |
| 172 if (targetNode && targetNode->isTextNode()) | |
| 173 targetNode = FlatTreeTraversal::parent(*targetNode); | |
| 174 | |
| 175 setNodeUnderMouse(targetNode, platformMouseEvent); | |
| 176 | |
| 177 return dispatchMouseEvent(m_nodeUnderMouse, eventType, platformMouseEvent, | |
| 178 nullptr); | |
| 179 } | |
| 180 | |
| 181 | |
| 182 WebInputEventResult MouseEventManager::dispatchMouseClickIfNeeded( | |
| 183 const MouseEventWithHitTestResults& mev) | |
| 184 { | |
| 185 // We only prevent click event when the click may cause contextmenu to popup . | |
| 186 // However, we always send auxclick. | |
| 187 bool contextMenuEvent = !RuntimeEnabledFeatures::auxclickEnabled() | |
| 188 && mev.event().pointerProperties().button == WebPointerProperties::Butto n::Right; | |
| 189 #if OS(MACOSX) | |
| 190 // FIXME: The Mac port achieves the same behavior by checking whether the co ntext menu is currently open in WebPage::mouseEvent(). Consider merging the impl ementations. | |
| 191 if (mev.event().pointerProperties().button == WebPointerProperties::Button:: Left | |
| 192 && mev.event().getModifiers() & PlatformEvent::CtrlKey) | |
| 193 contextMenuEvent = true; | |
| 194 #endif | |
| 195 | |
| 196 WebInputEventResult clickEventResult = WebInputEventResult::NotHandled; | |
| 197 const bool shouldDispatchClickEvent = m_clickCount > 0 | |
| 198 && !contextMenuEvent | |
| 199 && mev.innerNode() && m_clickNode | |
| 200 && mev.innerNode()->canParticipateInFlatTree() && m_clickNode->canPartic ipateInFlatTree() | |
| 201 && !(m_frame->eventHandler().selectionController().hasExtendedSelection( ) && isLinkSelection(mev)); | |
| 202 if (shouldDispatchClickEvent) { | |
| 203 Node* clickTargetNode = nullptr; | |
| 204 // Updates distribution because a 'mouseup' event listener can make the | |
| 205 // tree dirty at dispatchMouseEvent() invocation above. | |
| 206 // Unless distribution is updated, commonAncestor would hit ASSERT. | |
| 207 if (m_clickNode == mev.innerNode()) { | |
| 208 clickTargetNode = m_clickNode; | |
| 209 clickTargetNode->updateDistribution(); | |
| 210 } else if (m_clickNode->document() == mev.innerNode()->document()) { | |
| 211 m_clickNode->updateDistribution(); | |
| 212 mev.innerNode()->updateDistribution(); | |
| 213 clickTargetNode = mev.innerNode()->commonAncestor( | |
| 214 *m_clickNode, EventHandlingUtil::parentForClickEvent); | |
| 215 } | |
| 216 if (clickTargetNode) { | |
| 217 clickEventResult = dispatchMouseEvent(clickTargetNode, | |
| 218 !RuntimeEnabledFeatures::auxclickEnabled() | |
| 219 || (mev.event().pointerProperties().button == WebPointerProperti es::Button::Left) | |
| 220 ? EventTypeNames::click | |
| 221 : EventTypeNames::auxclick, mev.event(), nullptr); | |
| 222 } | |
| 223 } | |
| 224 return clickEventResult; | |
| 225 } | |
| 226 | |
| 227 | |
| 228 void MouseEventManager::fakeMouseMoveEventTimerFired(TimerBase* timer) | |
| 229 { | |
| 230 TRACE_EVENT0("input", "MouseEventManager::fakeMouseMoveEventTimerFired"); | |
| 231 DCHECK(timer, timer == &m_fakeMouseMoveEventTimer); | |
| 232 DCHECK(!m_mousePressed); | |
| 233 | |
| 234 Settings* settings = m_frame->settings(); | |
| 235 if (settings && !settings->deviceSupportsMouse()) | |
| 236 return; | |
| 237 | |
| 238 FrameView* view = m_frame->view(); | |
| 239 if (!view) | |
| 240 return; | |
| 241 | |
| 242 if (!m_frame->page() || !m_frame->page()->focusController().isActive()) | |
| 243 return; | |
| 244 | |
| 245 // Don't dispatch a synthetic mouse move event if the mouse cursor is not vi sible to the user. | |
| 246 if (!m_frame->page()->isCursorVisible()) | |
| 247 return; | |
| 248 | |
| 249 PlatformMouseEvent fakeMouseMoveEvent(m_lastKnownMousePosition, m_lastKnownM ouseGlobalPosition, WebPointerProperties::Button::NoButton, PlatformEvent::Mouse Moved, 0, static_cast<PlatformEvent::Modifiers>(KeyboardEventManager::getCurrent ModifierState()), PlatformMouseEvent::RealOrIndistinguishable, monotonicallyIncr easingTime(), WebPointerProperties::PointerType::Mouse); | |
| 250 m_frame->eventHandler().handleMouseMoveEvent(fakeMouseMoveEvent); | |
| 251 } | |
| 252 | |
| 253 void MouseEventManager::cancelFakeMouseMoveEvent() | |
| 254 { | |
| 255 m_fakeMouseMoveEventTimer.stop(); | |
| 256 } | |
| 257 | |
| 258 void MouseEventManager::setNodeUnderMouse( | |
| 259 Node* target, const PlatformMouseEvent &platformMouseEvent) | |
| 260 { | |
| 261 Node* lastNodeUnderMouse = m_nodeUnderMouse; | |
| 262 m_nodeUnderMouse = target; | |
| 263 | |
| 264 PaintLayer* layerForLastNode = EventHandlingUtil::layerForNode(lastNodeUnder Mouse); | |
| 265 PaintLayer* layerForNodeUnderMouse = EventHandlingUtil::layerForNode(m_nodeU nderMouse.get()); | |
| 266 Page* page = m_frame->page(); | |
| 267 | |
| 268 if (lastNodeUnderMouse && (!m_nodeUnderMouse || m_nodeUnderMouse->document() != m_frame->document())) { | |
| 269 // The mouse has moved between frames. | |
| 270 if (LocalFrame* frame = lastNodeUnderMouse->document().frame()) { | |
| 271 if (FrameView* frameView = frame->view()) | |
| 272 frameView->mouseExitedContentArea(); | |
| 273 } | |
| 274 } else if (page && (layerForLastNode && (!layerForNodeUnderMouse || layerFor NodeUnderMouse != layerForLastNode))) { | |
| 275 // The mouse has moved between layers. | |
| 276 if (ScrollableArea* scrollableAreaForLastNode = EventHandlingUtil::assoc iatedScrollableArea(layerForLastNode)) | |
| 277 scrollableAreaForLastNode->mouseExitedContentArea(); | |
| 278 } | |
| 279 | |
| 280 if (m_nodeUnderMouse && (!lastNodeUnderMouse || lastNodeUnderMouse->document () != m_frame->document())) { | |
| 281 // The mouse has moved between frames. | |
| 282 if (LocalFrame* frame = m_nodeUnderMouse->document().frame()) { | |
| 283 if (FrameView* frameView = frame->view()) | |
| 284 frameView->mouseEnteredContentArea(); | |
| 285 } | |
| 286 } else if (page && (layerForNodeUnderMouse && (!layerForLastNode || layerFor NodeUnderMouse != layerForLastNode))) { | |
| 287 // The mouse has moved between layers. | |
| 288 if (ScrollableArea* scrollableAreaForNodeUnderMouse = EventHandlingUtil: :associatedScrollableArea(layerForNodeUnderMouse)) | |
| 289 scrollableAreaForNodeUnderMouse->mouseEnteredContentArea(); | |
| 290 } | |
| 291 | |
| 292 if (lastNodeUnderMouse && lastNodeUnderMouse->document() != m_frame->documen t()) { | |
| 293 lastNodeUnderMouse = nullptr; | |
| 294 } | |
| 295 | |
| 296 sendBoundaryEvents(lastNodeUnderMouse, m_nodeUnderMouse, platformMouseEvent) ; | |
| 297 } | |
| 298 | |
| 299 void MouseEventManager::nodeWillBeRemoved(Node& nodeToBeRemoved) | |
| 300 { | |
| 301 if (nodeToBeRemoved.isShadowIncludingInclusiveAncestorOf(m_clickNode.get())) { | |
| 302 // We don't dispatch click events if the mousedown node is removed | |
| 303 // before a mouseup event. It is compatible with IE and Firefox. | |
| 304 m_clickNode = nullptr; | |
| 305 } | |
| 306 } | |
| 307 | |
| 308 Node* MouseEventManager::getNodeUnderMouse() | |
| 309 { | |
| 310 return m_nodeUnderMouse; | |
| 311 } | |
| 312 | |
| 313 WebInputEventResult MouseEventManager::handleMouseFocus(const HitTestResult& hit TestResult, InputDeviceCapabilities* sourceCapabilities) | |
| 314 { | |
| 315 // If clicking on a frame scrollbar, do not mess up with content focus. | |
| 316 if (hitTestResult.scrollbar() && !m_frame->contentLayoutItem().isNull()) { | |
| 317 if (hitTestResult.scrollbar()->getScrollableArea() == m_frame->contentLa youtItem().getScrollableArea()) | |
| 318 return WebInputEventResult::NotHandled; | |
| 319 } | |
| 320 | |
| 321 // The layout needs to be up to date to determine if an element is focusable . | |
| 322 m_frame->document()->updateStyleAndLayoutIgnorePendingStylesheets(); | |
| 323 | |
| 324 Element* element = nullptr; | |
| 325 if (m_nodeUnderMouse) | |
| 326 element = m_nodeUnderMouse->isElementNode() ? toElement(m_nodeUnderMouse ) : m_nodeUnderMouse->parentOrShadowHostElement(); | |
| 327 for (; element; element = element->parentOrShadowHostElement()) { | |
| 328 if (element->isFocusable() && element->isFocusedElementInDocument()) | |
| 329 return WebInputEventResult::NotHandled; | |
| 330 if (element->isMouseFocusable()) | |
| 331 break; | |
| 332 } | |
| 333 DCHECK(!element || element->isMouseFocusable()); | |
| 334 | |
| 335 // To fix <rdar://problem/4895428> Can't drag selected ToDo, we don't focus | |
| 336 // a node on mouse down if it's selected and inside a focused node. It will | |
| 337 // be focused if the user does a mouseup over it, however, because the | |
| 338 // mouseup will set a selection inside it, which will call | |
| 339 // FrameSelection::setFocusedNodeIfNeeded. | |
| 340 if (element && m_frame->selection().isRange()) { | |
| 341 // TODO(yosin) We should not create |Range| object for calling | |
| 342 // |isNodeFullyContained()|. | |
| 343 if (createRange(m_frame->selection().selection().toNormalizedEphemeralRa nge())->isNodeFullyContained(*element) | |
| 344 && element->isDescendantOf(m_frame->document()->focusedElement())) | |
| 345 return WebInputEventResult::NotHandled; | |
| 346 } | |
| 347 | |
| 348 | |
| 349 // Only change the focus when clicking scrollbars if it can transfered to a | |
| 350 // mouse focusable node. | |
| 351 if (!element && hitTestResult.scrollbar()) | |
| 352 return WebInputEventResult::HandledSystem; | |
| 353 | |
| 354 if (Page* page = m_frame->page()) { | |
| 355 // If focus shift is blocked, we eat the event. Note we should never | |
| 356 // clear swallowEvent if the page already set it (e.g., by canceling | |
| 357 // default behavior). | |
| 358 if (element) { | |
| 359 if (slideFocusOnShadowHostIfNecessary(*element)) | |
| 360 return WebInputEventResult::HandledSystem; | |
| 361 if (!page->focusController().setFocusedElement(element, m_frame, Foc usParams(SelectionBehaviorOnFocus::None, WebFocusTypeMouse, sourceCapabilities)) ) | |
| 362 return WebInputEventResult::HandledSystem; | |
| 363 } else { | |
| 364 // We call setFocusedElement even with !element in order to blur | |
| 365 // current focus element when a link is clicked; this is expected by | |
| 366 // some sites that rely on onChange handlers running from form | |
| 367 // fields before the button click is processed. | |
| 368 if (!page->focusController().setFocusedElement(nullptr, m_frame, Foc usParams(SelectionBehaviorOnFocus::None, WebFocusTypeNone, sourceCapabilities))) | |
| 369 return WebInputEventResult::HandledSystem; | |
| 370 } | |
| 371 } | |
| 372 | |
| 373 return WebInputEventResult::NotHandled; | |
| 374 } | |
| 375 | |
| 376 bool MouseEventManager::slideFocusOnShadowHostIfNecessary(const Element& element ) | |
| 377 { | |
| 378 if (element.authorShadowRoot() && element.authorShadowRoot()->delegatesFocus ()) { | |
| 379 Document* doc = m_frame->document(); | |
| 380 if (element.isShadowIncludingInclusiveAncestorOf(doc->focusedElement())) { | |
| 381 // If the inner element is already focused, do nothing. | |
| 382 return true; | |
| 383 } | |
| 384 | |
| 385 // If the host has a focusable inner element, focus it. Otherwise, the h ost takes focus. | |
| 386 Page* page = m_frame->page(); | |
| 387 DCHECK(page); | |
| 388 Element* found = page->focusController().findFocusableElementInShadowHos t(element); | |
| 389 if (found && element.isShadowIncludingInclusiveAncestorOf(found)) { | |
| 390 // Use WebFocusTypeForward instead of WebFocusTypeMouse here to mean the focus has slided. | |
| 391 found->focus(FocusParams(SelectionBehaviorOnFocus::Reset, WebFocusTy peForward, nullptr)); | |
| 392 return true; | |
| 393 } | |
| 394 } | |
| 395 return false; | |
| 396 } | |
| 397 | |
| 398 void MouseEventManager::handleMousePressEventUpdateStates( | |
| 399 const PlatformMouseEvent& mouseEvent) { | |
| 400 cancelFakeMouseMoveEvent(); | |
| 401 m_mousePressed = true; | |
| 402 m_capturesDragging = true; | |
| 403 setLastKnownMousePosition(mouseEvent); | |
| 404 m_mouseDownMayStartDrag = false; | |
| 405 m_mouseDownMayStartAutoscroll = false; | |
| 406 m_mouseDownTimestamp = mouseEvent.timestamp(); | |
| 407 | |
| 408 if (FrameView* view = m_frame->view()) { | |
| 409 m_mouseDownPos = view->rootFrameToContents(mouseEvent.position()); | |
| 410 } else { | |
| 411 invalidateClick(); | |
| 412 } | |
| 413 } | |
| 414 | |
| 415 bool MouseEventManager::isMousePositionUnknown() | |
| 416 { | |
| 417 return m_isMousePositionUnknown; | |
| 418 } | |
| 419 | |
| 420 IntPoint MouseEventManager::lastKnownMousePosition() | |
| 421 { | |
| 422 return m_lastKnownMousePosition; | |
| 423 } | |
| 424 | |
| 425 void MouseEventManager::setLastKnownMousePosition(const PlatformMouseEvent& even t) | |
| 426 { | |
| 427 m_isMousePositionUnknown = false; | |
| 428 m_lastKnownMousePosition = event.position(); | |
| 429 m_lastKnownMouseGlobalPosition = event.globalPosition(); | |
| 430 } | |
| 431 | |
| 432 void MouseEventManager::dispatchFakeMouseMoveEventSoon() | |
|
dtapuska
2016/09/21 17:07:44
I wonder if these things should be at a Frame leve
Navid Zolghadr
2016/09/21 17:17:30
Should it be? Wouldn't it happen for every frame?
| |
| 433 { | |
| 434 if (m_mousePressed) | |
| 435 return; | |
| 436 | |
| 437 if (m_isMousePositionUnknown) | |
| 438 return; | |
| 439 | |
| 440 Settings* settings = m_frame->settings(); | |
| 441 if (settings && !settings->deviceSupportsMouse()) | |
| 442 return; | |
| 443 | |
| 444 // Reschedule the timer, to prevent dispatching mouse move events | |
| 445 // during a scroll. This avoids a potential source of scroll jank. | |
| 446 if (m_fakeMouseMoveEventTimer.isActive()) | |
| 447 m_fakeMouseMoveEventTimer.stop(); | |
| 448 m_fakeMouseMoveEventTimer.startOneShot(fakeMouseMoveInterval, BLINK_FROM_HER E); | |
| 449 } | |
| 450 | |
| 451 void MouseEventManager::dispatchFakeMouseMoveEventSoonInQuad(const FloatQuad& qu ad) | |
| 452 { | |
| 453 FrameView* view = m_frame->view(); | |
| 454 if (!view) | |
| 455 return; | |
| 456 | |
| 457 if (!quad.containsPoint(view->rootFrameToContents(m_lastKnownMousePosition)) ) | |
| 458 return; | |
| 459 | |
| 460 dispatchFakeMouseMoveEventSoon(); | |
| 461 } | |
| 462 | |
| 463 WebInputEventResult MouseEventManager::handleMousePressEvent(const MouseEventWit hHitTestResults& event) | |
| 464 { | |
| 465 TRACE_EVENT0("blink", "MouseEventManager::handleMousePressEvent"); | |
| 466 | |
| 467 // Reset drag state. | |
| 468 dragState().m_dragSrc = nullptr; | |
| 469 | |
| 470 cancelFakeMouseMoveEvent(); | |
| 471 | |
| 472 m_frame->document()->updateStyleAndLayoutIgnorePendingStylesheets(); | |
| 473 | |
| 474 if (FrameView* frameView = m_frame->view()) { | |
| 475 if (frameView->isPointInScrollbarCorner(event.event().position())) | |
| 476 return WebInputEventResult::NotHandled; | |
| 477 } | |
| 478 | |
| 479 bool singleClick = event.event().clickCount() <= 1; | |
| 480 | |
| 481 m_mouseDownMayStartDrag = singleClick && !isLinkSelection(event) && !isExten dingSelection(event); | |
| 482 | |
| 483 m_frame->eventHandler().selectionController().handleMousePressEvent(event); | |
| 484 | |
| 485 m_mouseDown = event.event(); | |
| 486 | |
| 487 if (m_frame->document()->isSVGDocument() && m_frame->document()->accessSVGEx tensions().zoomAndPanEnabled()) { | |
| 488 if (event.event().shiftKey() && singleClick) { | |
| 489 m_svgPan = true; | |
| 490 m_frame->document()->accessSVGExtensions().startPan(m_frame->view()- >rootFrameToContents(event.event().position())); | |
| 491 return WebInputEventResult::HandledSystem; | |
| 492 } | |
| 493 } | |
| 494 | |
| 495 // We don't do this at the start of mouse down handling, | |
| 496 // because we don't want to do it until we know we didn't hit a widget. | |
| 497 if (singleClick) | |
| 498 focusDocumentView(); | |
| 499 | |
| 500 Node* innerNode = event.innerNode(); | |
| 501 | |
| 502 m_mousePressNode = innerNode; | |
| 503 m_frame->document()->setSequentialFocusNavigationStartingPoint(innerNode); | |
| 504 m_dragStartPos = event.event().position(); | |
| 505 | |
| 506 bool swallowEvent = false; | |
| 507 m_mousePressed = true; | |
| 508 | |
| 509 if (event.event().clickCount() == 2) | |
| 510 swallowEvent = m_frame->eventHandler().selectionController().handleMouse PressEventDoubleClick(event); | |
| 511 else if (event.event().clickCount() >= 3) | |
| 512 swallowEvent = m_frame->eventHandler().selectionController().handleMouse PressEventTripleClick(event); | |
| 513 else | |
| 514 swallowEvent = m_frame->eventHandler().selectionController().handleMouse PressEventSingleClick(event); | |
| 515 | |
| 516 m_mouseDownMayStartAutoscroll = m_frame->eventHandler().selectionController( ).mouseDownMayStartSelect() | |
| 517 || (m_mousePressNode && m_mousePressNode->layoutBox() && m_mousePressNod e->layoutBox()->canBeProgramaticallyScrolled()); | |
| 518 | |
| 519 return swallowEvent ? WebInputEventResult::HandledSystem : WebInputEventResu lt::NotHandled; | |
| 520 } | |
| 521 | |
| 522 WebInputEventResult MouseEventManager::handleMouseReleaseEvent(const MouseEventW ithHitTestResults& event) | |
| 523 { | |
| 524 AutoscrollController* controller = m_scrollManager->autoscrollController(); | |
| 525 if (controller && controller->autoscrollInProgress()) | |
| 526 m_scrollManager->stopAutoscroll(); | |
| 527 | |
| 528 return m_frame->eventHandler().selectionController().handleMouseReleaseEvent (event, m_dragStartPos) ? WebInputEventResult::HandledSystem : WebInputEventResu lt::NotHandled; | |
| 529 } | |
| 530 | |
| 531 void MouseEventManager::updateSelectionForMouseDrag() | |
| 532 { | |
| 533 m_frame->eventHandler().selectionController().updateSelectionForMouseDrag(m_ mousePressNode, m_dragStartPos, m_lastKnownMousePosition); | |
| 534 } | |
| 535 | |
| 536 bool MouseEventManager::handleDragDropIfPossible(const GestureEventWithHitTestRe sults& targetedEvent) | |
| 537 { | |
| 538 if (m_frame->settings() && m_frame->settings()->touchDragDropEnabled() && m_ frame->view()) { | |
| 539 const PlatformGestureEvent& gestureEvent = targetedEvent.event(); | |
| 540 IntPoint adjustedPoint = gestureEvent.position(); | |
| 541 unsigned modifiers = gestureEvent.getModifiers(); | |
| 542 | |
| 543 // TODO(mustaq): Suppressing long-tap MouseEvents could break | |
| 544 // drag-drop. Will do separately because of the risk. crbug.com/606938. | |
| 545 PlatformMouseEvent mouseDownEvent(adjustedPoint, gestureEvent.globalPosi tion(), WebPointerProperties::Button::Left, PlatformEvent::MousePressed, 1, | |
| 546 static_cast<PlatformEvent::Modifiers>(modifiers | PlatformEvent::Lef tButtonDown), | |
| 547 PlatformMouseEvent::FromTouch, WTF::monotonicallyIncreasingTime(), W ebPointerProperties::PointerType::Mouse); | |
| 548 m_mouseDown = mouseDownEvent; | |
| 549 | |
| 550 PlatformMouseEvent mouseDragEvent(adjustedPoint, gestureEvent.globalPosi tion(), WebPointerProperties::Button::Left, PlatformEvent::MouseMoved, 1, | |
| 551 static_cast<PlatformEvent::Modifiers>(modifiers | PlatformEvent::Lef tButtonDown), | |
| 552 PlatformMouseEvent::FromTouch, WTF::monotonicallyIncreasingTime(), W ebPointerProperties::PointerType::Mouse); | |
| 553 HitTestRequest request(HitTestRequest::ReadOnly); | |
| 554 MouseEventWithHitTestResults mev = EventHandlingUtil::prepareMouseEvent( m_frame, request, mouseDragEvent); | |
| 555 m_mouseDownMayStartDrag = true; | |
| 556 dragState().m_dragSrc = nullptr; | |
| 557 m_mouseDownPos = m_frame->view()->rootFrameToContents(mouseDragEvent.pos ition()); | |
| 558 return handleDrag(mev, DragInitiator::Touch); | |
| 559 } | |
| 560 return false; | |
| 561 } | |
| 562 | |
| 563 void MouseEventManager::focusDocumentView() | |
| 564 { | |
| 565 Page* page = m_frame->page(); | |
| 566 if (!page) | |
| 567 return; | |
| 568 page->focusController().focusDocumentView(m_frame); | |
| 569 } | |
| 570 | |
| 571 WebInputEventResult MouseEventManager::handleMouseDraggedEvent(const MouseEventW ithHitTestResults& event) | |
| 572 { | |
| 573 TRACE_EVENT0("blink", "MouseEventManager::handleMouseDraggedEvent"); | |
| 574 | |
| 575 // While resetting m_mousePressed here may seem out of place, it turns out | |
| 576 // to be needed to handle some bugs^Wfeatures in Blink mouse event handling: | |
| 577 // 1. Certain elements, such as <embed>, capture mouse events. They do not | |
| 578 // bubble back up. One way for a <embed> to start capturing mouse events | |
| 579 // is on a mouse press. The problem is the <embed> node only starts | |
| 580 // capturing mouse events *after* m_mousePressed for the containing frame | |
| 581 // has already been set to true. As a result, the frame's EventHandler | |
| 582 // never sees the mouse release event, which is supposed to reset | |
| 583 // m_mousePressed... so m_mousePressed ends up remaining true until the | |
| 584 // event handler finally gets another mouse released event. Oops. | |
| 585 // 2. Dragging doesn't start until after a mouse press event, but a drag | |
| 586 // that ends as a result of a mouse release does not send a mouse release | |
| 587 // event. As a result, m_mousePressed also ends up remaining true until | |
| 588 // the next mouse release event seen by the EventHandler. | |
| 589 if (event.event().pointerProperties().button != WebPointerProperties::Button ::Left) | |
| 590 m_mousePressed = false; | |
| 591 | |
| 592 if (!m_mousePressed) | |
| 593 return WebInputEventResult::NotHandled; | |
| 594 | |
| 595 if (handleDrag(event, DragInitiator::Mouse)) | |
| 596 return WebInputEventResult::HandledSystem; | |
| 597 | |
| 598 Node* targetNode = event.innerNode(); | |
| 599 if (!targetNode) | |
| 600 return WebInputEventResult::NotHandled; | |
| 601 | |
| 602 LayoutObject* layoutObject = targetNode->layoutObject(); | |
| 603 if (!layoutObject) { | |
| 604 Node* parent = FlatTreeTraversal::parent(*targetNode); | |
| 605 if (!parent) | |
| 606 return WebInputEventResult::NotHandled; | |
| 607 | |
| 608 layoutObject = parent->layoutObject(); | |
| 609 if (!layoutObject || !layoutObject->isListBox()) | |
| 610 return WebInputEventResult::NotHandled; | |
| 611 } | |
| 612 | |
| 613 m_mouseDownMayStartDrag = false; | |
| 614 | |
| 615 if (m_mouseDownMayStartAutoscroll && !m_scrollManager->middleClickAutoscroll InProgress()) { | |
| 616 if (AutoscrollController* controller = m_scrollManager->autoscrollContro ller()) { | |
| 617 controller->startAutoscrollForSelection(layoutObject); | |
| 618 m_mouseDownMayStartAutoscroll = false; | |
| 619 } | |
| 620 } | |
| 621 | |
| 622 m_frame->eventHandler().selectionController().handleMouseDraggedEvent(event, m_mouseDownPos, m_dragStartPos, m_mousePressNode.get(), m_lastKnownMousePositio n); | |
| 623 return WebInputEventResult::HandledSystem; | |
| 624 } | |
| 625 | |
| 626 | |
| 627 bool MouseEventManager::handleDrag(const MouseEventWithHitTestResults& event, Dr agInitiator initiator) | |
| 628 { | |
| 629 DCHECK(event.event().type() == PlatformEvent::MouseMoved); | |
| 630 // Callers must protect the reference to FrameView, since this function may dispatch DOM | |
| 631 // events, causing page/FrameView to go away. | |
| 632 DCHECK(m_frame); | |
| 633 DCHECK(m_frame->view()); | |
| 634 if (!m_frame->page()) | |
| 635 return false; | |
| 636 | |
| 637 if (m_mouseDownMayStartDrag) { | |
| 638 HitTestRequest request(HitTestRequest::ReadOnly); | |
| 639 HitTestResult result(request, m_mouseDownPos); | |
| 640 m_frame->contentLayoutItem().hitTest(result); | |
| 641 Node* node = result.innerNode(); | |
| 642 if (node) { | |
| 643 DragController::SelectionDragPolicy selectionDragPolicy = event.even t().timestamp() - m_mouseDownTimestamp < TextDragDelay | |
| 644 ? DragController::DelayedSelectionDragResolution | |
| 645 : DragController::ImmediateSelectionDragResolution; | |
| 646 dragState().m_dragSrc = m_frame->page()->dragController().draggableN ode(m_frame, node, m_mouseDownPos, selectionDragPolicy, dragState().m_dragType); | |
| 647 } else { | |
| 648 dragState().m_dragSrc = nullptr; | |
| 649 } | |
| 650 | |
| 651 if (!dragState().m_dragSrc) | |
| 652 m_mouseDownMayStartDrag = false; // no element is draggable | |
| 653 } | |
| 654 | |
| 655 if (!m_mouseDownMayStartDrag) | |
| 656 return initiator == DragInitiator::Mouse && !m_frame->eventHandler().sel ectionController().mouseDownMayStartSelect() && !m_mouseDownMayStartAutoscroll; | |
| 657 | |
| 658 // We are starting a text/image/url drag, so the cursor should be an arrow | |
| 659 // FIXME <rdar://7577595>: Custom cursors aren't supported during drag and d rop (default to pointer). | |
| 660 m_frame->view()->setCursor(pointerCursor()); | |
| 661 | |
| 662 if (initiator == DragInitiator::Mouse && !dragHysteresisExceeded(event.event ().position())) | |
| 663 return true; | |
| 664 | |
| 665 // Once we're past the hysteresis point, we don't want to treat this gesture as a click | |
| 666 invalidateClick(); | |
| 667 | |
| 668 if (!tryStartDrag(event)) { | |
| 669 // Something failed to start the drag, clean up. | |
| 670 clearDragDataTransfer(); | |
| 671 dragState().m_dragSrc = nullptr; | |
| 672 } | |
| 673 | |
| 674 m_mouseDownMayStartDrag = false; | |
| 675 // Whether or not the drag actually started, no more default handling (like selection). | |
| 676 return true; | |
| 677 } | |
| 678 | |
| 679 DataTransfer* MouseEventManager::createDraggingDataTransfer() const | |
| 680 { | |
| 681 return DataTransfer::create(DataTransfer::DragAndDrop, DataTransferWritable, DataObject::create()); | |
| 682 } | |
| 683 | |
| 684 bool MouseEventManager::tryStartDrag(const MouseEventWithHitTestResults& event) | |
| 685 { | |
| 686 // The DataTransfer would only be non-empty if we missed a dragEnd. | |
| 687 // Clear it anyway, just to make sure it gets numbified. | |
| 688 clearDragDataTransfer(); | |
| 689 | |
| 690 dragState().m_dragDataTransfer = createDraggingDataTransfer(); | |
| 691 | |
| 692 // Check to see if this a DOM based drag, if it is get the DOM specified dra g | |
| 693 // image and offset | |
| 694 if (dragState().m_dragType == DragSourceActionDHTML) { | |
| 695 if (LayoutObject* layoutObject = dragState().m_dragSrc->layoutObject()) { | |
| 696 IntRect boundingIncludingDescendants = layoutObject->absoluteBoundin gBoxRectIncludingDescendants(); | |
| 697 IntSize delta = m_mouseDownPos - boundingIncludingDescendants.locati on(); | |
| 698 dragState().m_dragDataTransfer->setDragImageElement(dragState().m_dr agSrc.get(), IntPoint(delta)); | |
| 699 } else { | |
| 700 // The layoutObject has disappeared, this can happen if the onStartD rag handler has hidden | |
| 701 // the element in some way. In this case we just kill the drag. | |
| 702 return false; | |
| 703 } | |
| 704 } | |
| 705 | |
| 706 DragController& dragController = m_frame->page()->dragController(); | |
| 707 if (!dragController.populateDragDataTransfer(m_frame, dragState(), m_mouseDo wnPos)) | |
| 708 return false; | |
| 709 | |
| 710 // If dispatching dragstart brings about another mouse down -- one way | |
| 711 // this will happen is if a DevTools user breaks within a dragstart | |
| 712 // handler and then clicks on the suspended page -- the drag state is | |
| 713 // reset. Hence, need to check if this particular drag operation can | |
| 714 // continue even if dispatchEvent() indicates no (direct) cancellation. | |
| 715 // Do that by checking if m_dragSrc is still set. | |
| 716 m_mouseDownMayStartDrag = dispatchDragSrcEvent(EventTypeNames::dragstart, m_ mouseDown) == WebInputEventResult::NotHandled | |
| 717 && !m_frame->selection().isInPasswordField() && dragState().m_dragSrc; | |
| 718 | |
| 719 // Invalidate clipboard here against anymore pasteboard writing for security . The drag | |
| 720 // image can still be changed as we drag, but not the pasteboard data. | |
| 721 dragState().m_dragDataTransfer->setAccessPolicy(DataTransferImageWritable); | |
| 722 | |
| 723 if (m_mouseDownMayStartDrag) { | |
| 724 // Dispatching the event could cause Page to go away. Make sure it's sti ll valid before trying to use DragController. | |
| 725 if (m_frame->page() && dragController.startDrag(m_frame, dragState(), ev ent.event(), m_mouseDownPos)) | |
| 726 return true; | |
| 727 // Drag was canned at the last minute - we owe m_dragSrc a DRAGEND event | |
| 728 dispatchDragSrcEvent(EventTypeNames::dragend, event.event()); | |
| 729 } | |
| 730 | |
| 731 return false; | |
| 732 } | |
| 733 | |
| 734 // returns if we should continue "default processing", i.e., whether eventhandle r canceled | |
| 735 WebInputEventResult MouseEventManager::dispatchDragSrcEvent(const AtomicString& eventType, const PlatformMouseEvent& event) | |
| 736 { | |
| 737 return dispatchDragEvent(eventType, dragState().m_dragSrc.get(), event, drag State().m_dragDataTransfer.get()); | |
| 738 } | |
| 739 | |
| 740 WebInputEventResult MouseEventManager::dispatchDragEvent(const AtomicString& eve ntType, Node* dragTarget, const PlatformMouseEvent& event, DataTransfer* dataTra nsfer) | |
| 741 { | |
| 742 FrameView* view = m_frame->view(); | |
| 743 | |
| 744 // FIXME: We might want to dispatch a dragleave even if the view is gone. | |
| 745 if (!view) | |
| 746 return WebInputEventResult::NotHandled; | |
| 747 | |
| 748 DragEvent* me = DragEvent::create(eventType, | |
| 749 true, true, m_frame->document()->domWindow(), | |
| 750 0, event.globalPosition().x(), event.globalPosition().y(), event.positio n().x(), event.position().y(), | |
| 751 event.movementDelta().x(), event.movementDelta().y(), | |
| 752 event.getModifiers(), | |
| 753 0, MouseEvent::platformModifiersToButtons(event.getModifiers()), nullptr , event.timestamp(), dataTransfer, event.getSyntheticEventType()); | |
| 754 | |
| 755 return EventHandlingUtil::toWebInputEventResult(dragTarget->dispatchEvent(me )); | |
| 756 } | |
| 757 | |
| 758 void MouseEventManager::clearDragDataTransfer() | |
| 759 { | |
| 760 if (dragState().m_dragDataTransfer) { | |
| 761 dragState().m_dragDataTransfer->clearDragImage(); | |
| 762 dragState().m_dragDataTransfer->setAccessPolicy(DataTransferNumb); | |
| 763 } | |
| 764 } | |
| 765 | |
| 766 void MouseEventManager::dragSourceEndedAt(const PlatformMouseEvent& event, DragO peration operation) | |
| 767 { | |
| 768 // Send a hit test request so that Layer gets a chance to update the :hover and :active pseudoclasses. | |
| 769 HitTestRequest request(HitTestRequest::Release); | |
| 770 EventHandlingUtil::prepareMouseEvent(m_frame, request, event); | |
| 771 | |
| 772 if (dragState().m_dragSrc) { | |
| 773 dragState().m_dragDataTransfer->setDestinationOperation(operation); | |
| 774 // for now we don't care if event handler cancels default behavior, sinc e there is none | |
| 775 dispatchDragSrcEvent(EventTypeNames::dragend, event); | |
| 776 } | |
| 777 clearDragDataTransfer(); | |
| 778 dragState().m_dragSrc = nullptr; | |
| 779 // In case the drag was ended due to an escape key press we need to ensure | |
| 780 // that consecutive mousemove events don't reinitiate the drag and drop. | |
| 781 m_mouseDownMayStartDrag = false; | |
| 782 } | |
| 783 | |
| 784 DragState& MouseEventManager::dragState() | |
| 785 { | |
| 786 DEFINE_STATIC_LOCAL(DragState, state, (new DragState)); | |
| 787 return state; | |
| 788 } | |
| 789 | |
| 790 bool MouseEventManager::dragHysteresisExceeded(const IntPoint& dragLocationInRoo tFrame) const | |
| 791 { | |
| 792 FrameView* view = m_frame->view(); | |
| 793 if (!view) | |
| 794 return false; | |
| 795 IntPoint dragLocation = view->rootFrameToContents(dragLocationInRootFrame); | |
| 796 IntSize delta = dragLocation - m_mouseDownPos; | |
| 797 | |
| 798 int threshold = GeneralDragHysteresis; | |
| 799 switch (dragState().m_dragType) { | |
| 800 case DragSourceActionSelection: | |
| 801 threshold = TextDragHysteresis; | |
| 802 break; | |
| 803 case DragSourceActionImage: | |
| 804 threshold = ImageDragHysteresis; | |
| 805 break; | |
| 806 case DragSourceActionLink: | |
| 807 threshold = LinkDragHysteresis; | |
| 808 break; | |
| 809 case DragSourceActionDHTML: | |
| 810 break; | |
| 811 case DragSourceActionNone: | |
| 812 NOTREACHED(); | |
| 813 } | |
| 814 | |
| 815 return abs(delta.width()) >= threshold || abs(delta.height()) >= threshold; | |
| 816 } | |
| 817 | |
| 818 void MouseEventManager::clearDragHeuristicState() | |
| 819 { | |
| 820 // Used to prevent mouseMoveEvent from initiating a drag before | |
| 821 // the mouse is pressed again. | |
| 822 m_mousePressed = false; | |
| 823 m_capturesDragging = false; | |
| 824 m_mouseDownMayStartDrag = false; | |
| 825 m_mouseDownMayStartAutoscroll = false; | |
| 826 } | |
| 827 | |
| 828 bool MouseEventManager::handleSvgPanIfNeeded(bool isReleaseEvent) | |
| 829 { | |
| 830 if (!m_svgPan) | |
| 831 return false; | |
| 832 m_svgPan = !isReleaseEvent; | |
| 833 m_frame->document()->accessSVGExtensions().updatePan(m_frame->view()->rootFr ameToContents(m_lastKnownMousePosition)); | |
| 834 return true; | |
| 835 } | |
| 836 | |
| 837 void MouseEventManager::invalidateClick() | |
| 838 { | |
| 839 m_clickCount = 0; | |
| 840 m_clickNode = nullptr; | |
| 841 } | |
| 842 | |
| 843 bool MouseEventManager::mousePressed() | |
| 844 { | |
| 845 return m_mousePressed; | |
| 846 } | |
| 847 | |
| 848 void MouseEventManager::setMousePressed(bool mousePressed) | |
| 849 { | |
| 850 m_mousePressed = mousePressed; | |
| 851 } | |
| 852 | |
| 853 bool MouseEventManager::capturesDragging() const | |
| 854 { | |
| 855 return m_capturesDragging; | |
| 856 } | |
| 857 | |
| 858 void MouseEventManager::setCapturesDragging(bool capturesDragging) | |
| 859 { | |
| 860 m_capturesDragging = capturesDragging; | |
| 861 } | |
| 862 | |
| 863 Node* MouseEventManager::mousePressNode() | |
| 864 { | |
| 865 return m_mousePressNode; | |
| 866 } | |
| 867 | |
| 868 void MouseEventManager::setMousePressNode(Node* node) | |
| 869 { | |
| 870 m_mousePressNode = node; | |
| 871 } | |
| 872 | |
| 873 void MouseEventManager::setClickNode(Node* node) | |
| 874 { | |
| 875 m_clickNode = node; | |
| 876 } | |
| 877 | |
| 878 void MouseEventManager::setClickCount(int clickCount) | |
| 879 { | |
| 880 m_clickCount = clickCount; | |
| 881 } | |
| 882 | |
| 883 bool MouseEventManager::mouseDownMayStartDrag() | |
| 884 { | |
| 885 return m_mouseDownMayStartDrag; | |
| 886 } | |
| 887 | |
| 888 MouseEventManager::MouseEventManager(LocalFrame* frame, | |
| 889 ScrollManager* scrollManager) | |
| 119 : m_frame(frame) | 890 : m_frame(frame) |
| 891 , m_scrollManager(scrollManager) | |
| 892 , m_fakeMouseMoveEventTimer(this, &MouseEventManager::fakeMouseMoveEventTime rFired) | |
| 120 { | 893 { |
| 121 clear(); | 894 clear(); |
| 122 } | 895 } |
| 123 | 896 |
| 897 MouseEventManager::~MouseEventManager() | |
| 898 { | |
| 899 DCHECK(!m_fakeMouseMoveEventTimer.isActive()); | |
| 900 } | |
| 901 | |
| 124 void MouseEventManager::clear() | 902 void MouseEventManager::clear() |
| 125 { | 903 { |
| 904 m_nodeUnderMouse = nullptr; | |
| 905 m_mousePressNode = nullptr; | |
| 906 m_mouseDownMayStartAutoscroll = false; | |
| 907 m_mouseDownMayStartDrag = false; | |
| 908 m_capturesDragging = false; | |
| 909 m_isMousePositionUnknown = true; | |
| 910 m_lastKnownMousePosition = IntPoint(); | |
| 911 m_lastKnownMouseGlobalPosition = IntPoint(); | |
| 912 m_mousePressed = false; | |
| 913 m_clickCount = 0; | |
| 914 m_clickNode = nullptr; | |
| 915 m_mouseDownPos = IntPoint(); | |
| 916 m_mouseDownTimestamp = 0; | |
| 917 m_mouseDown = PlatformMouseEvent(); | |
| 918 m_svgPan = false; | |
| 919 m_dragStartPos = LayoutPoint(); | |
| 920 m_fakeMouseMoveEventTimer.stop(); | |
| 126 } | 921 } |
| 127 | 922 |
| 128 DEFINE_TRACE(MouseEventManager) | 923 DEFINE_TRACE(MouseEventManager) |
| 129 { | 924 { |
| 130 visitor->trace(m_frame); | 925 visitor->trace(m_frame); |
| 926 visitor->trace(m_scrollManager); | |
| 131 visitor->trace(m_nodeUnderMouse); | 927 visitor->trace(m_nodeUnderMouse); |
| 928 visitor->trace(m_mousePressNode); | |
| 929 visitor->trace(m_clickNode); | |
| 132 } | 930 } |
| 133 | 931 |
| 134 } // namespace blink | 932 } // namespace blink |
| OLD | NEW |