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

Unified Diff: third_party/WebKit/Source/core/input/MouseEventManager.cpp

Issue 2255323004: Create MouseEventManager and EventHandlingUtil (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebasing Created 4 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: third_party/WebKit/Source/core/input/MouseEventManager.cpp
diff --git a/third_party/WebKit/Source/core/input/MouseEventManager.cpp b/third_party/WebKit/Source/core/input/MouseEventManager.cpp
new file mode 100644
index 0000000000000000000000000000000000000000..20929e3412e9aee8200f4672de952deaea4df703
--- /dev/null
+++ b/third_party/WebKit/Source/core/input/MouseEventManager.cpp
@@ -0,0 +1,134 @@
+// Copyright 2016 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "core/input/MouseEventManager.h"
+
+#include "core/dom/ElementTraversal.h"
+#include "core/events/MouseEvent.h"
+#include "core/html/HTMLCanvasElement.h"
+#include "core/input/EventHandlingUtil.h"
+
+namespace blink {
+
+namespace {
+
+PlatformMouseEvent mouseEventWithRegion(Node* node, const PlatformMouseEvent& mouseEvent)
+{
+ if (!node->isElementNode())
+ return mouseEvent;
+
+ Element* element = toElement(node);
+ if (!element->isInCanvasSubtree())
+ return mouseEvent;
+
+ HTMLCanvasElement* canvas = Traversal<HTMLCanvasElement>::firstAncestorOrSelf(*element);
+ // In this case, the event target is canvas and mouse rerouting doesn't happen.
+ if (canvas == element)
+ return mouseEvent;
+ String region = canvas->getIdFromControl(element);
+ PlatformMouseEvent newMouseEvent = mouseEvent;
+ newMouseEvent.setRegion(region);
+ return newMouseEvent;
+}
+
+} // namespace
+
+MouseEventManager::MouseEventBoundaryEventDispatcher::MouseEventBoundaryEventDispatcher(
+ MouseEventManager* mouseEventManager,
+ const PlatformMouseEvent* platformMouseEvent,
+ EventTarget* exitedTarget)
+ : m_mouseEventManager(mouseEventManager)
+ , m_platformMouseEvent(platformMouseEvent)
+ , m_exitedTarget(exitedTarget)
+{
+}
+
+void MouseEventManager::MouseEventBoundaryEventDispatcher::dispatchOut(
+ EventTarget* target, EventTarget* relatedTarget)
+{
+ dispatch(target, relatedTarget, EventTypeNames::mouseout, mouseEventWithRegion(m_exitedTarget->toNode(), *m_platformMouseEvent), false);
+}
+
+void MouseEventManager::MouseEventBoundaryEventDispatcher::dispatchOver(
+ EventTarget* target, EventTarget* relatedTarget)
+{
+ dispatch(target, relatedTarget, EventTypeNames::mouseover, *m_platformMouseEvent, false);
+}
+
+void MouseEventManager::MouseEventBoundaryEventDispatcher::dispatchLeave(
+ EventTarget* target, EventTarget* relatedTarget, bool checkForListener)
+{
+ dispatch(target, relatedTarget, EventTypeNames::mouseleave, mouseEventWithRegion(m_exitedTarget->toNode(), *m_platformMouseEvent), checkForListener);
+}
+
+void MouseEventManager::MouseEventBoundaryEventDispatcher::dispatchEnter(
+ EventTarget* target, EventTarget* relatedTarget, bool checkForListener)
+{
+ dispatch(target, relatedTarget, EventTypeNames::mouseenter, *m_platformMouseEvent, checkForListener);
+}
+
+AtomicString MouseEventManager::MouseEventBoundaryEventDispatcher::getLeaveEvent()
+{
+ return EventTypeNames::mouseleave;
+}
+
+AtomicString MouseEventManager::MouseEventBoundaryEventDispatcher::getEnterEvent()
+{
+ return EventTypeNames::mouseenter;
+}
+
+void MouseEventManager::MouseEventBoundaryEventDispatcher::dispatch(
+ EventTarget* target, EventTarget* relatedTarget, const AtomicString& type,
+ const PlatformMouseEvent& platformMouseEvent, bool checkForListener)
+{
+ m_mouseEventManager->dispatchMouseEvent(target, type, platformMouseEvent,
+ relatedTarget, 0, checkForListener);
+}
+
+void MouseEventManager::sendBoundaryEvents(
+ EventTarget* exitedTarget,
+ EventTarget* enteredTarget,
+ const PlatformMouseEvent& mousePlatformEvent)
+{
+ MouseEventBoundaryEventDispatcher boundaryEventDispatcher(this, &mousePlatformEvent, exitedTarget);
+ boundaryEventDispatcher.sendBoundaryEvents(exitedTarget, enteredTarget);
+}
+
+WebInputEventResult MouseEventManager::dispatchMouseEvent(
+ EventTarget* target,
+ const AtomicString& mouseEventType,
+ const PlatformMouseEvent& mouseEvent,
+ EventTarget* relatedTarget,
+ int detail,
+ bool checkForListener)
+{
+ if (target && target->toNode()
+ && (!checkForListener || target->hasEventListeners(mouseEventType))) {
+ Node* targetNode = target->toNode();
+ MouseEvent* event = MouseEvent::create(mouseEventType,
+ targetNode->document().domWindow(), mouseEvent, detail,
+ relatedTarget ? relatedTarget->toNode() : nullptr);
+ DispatchEventResult dispatchResult = target->dispatchEvent(event);
+ return EventHandlingUtil::toWebInputEventResult(dispatchResult);
+ }
+ return WebInputEventResult::NotHandled;
+}
+
+MouseEventManager::MouseEventManager(LocalFrame* frame)
+ : m_frame(frame)
+{
+ clear();
+}
+
+void MouseEventManager::clear()
+{
+}
+
+DEFINE_TRACE(MouseEventManager)
+{
+ visitor->trace(m_frame);
+ visitor->trace(m_nodeUnderMouse);
+}
+
+} // namespace blink
« no previous file with comments | « third_party/WebKit/Source/core/input/MouseEventManager.h ('k') | third_party/WebKit/Source/core/input/PointerEventManager.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698