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

Unified Diff: third_party/WebKit/Source/core/dom/Node.cpp

Issue 2517603002: Fired PointerEvent from Node::dispatchMouseEvent() to fix a bug. (Closed)
Patch Set: Created 4 years, 1 month 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
« no previous file with comments | « third_party/WebKit/Source/core/dom/Node.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: third_party/WebKit/Source/core/dom/Node.cpp
diff --git a/third_party/WebKit/Source/core/dom/Node.cpp b/third_party/WebKit/Source/core/dom/Node.cpp
index 9047ea695c62fed8bd1903e49392d63febe25cb2..aaa07c6c6bac677e814d5ff84fdf83a6a13cb6d1 100644
--- a/third_party/WebKit/Source/core/dom/Node.cpp
+++ b/third_party/WebKit/Source/core/dom/Node.cpp
@@ -77,11 +77,13 @@
#include "core/events/MouseEvent.h"
#include "core/events/MutationEvent.h"
#include "core/events/PointerEvent.h"
+#include "core/events/PointerEventFactory.h"
#include "core/events/TextEvent.h"
#include "core/events/TouchEvent.h"
#include "core/events/UIEvent.h"
#include "core/events/WheelEvent.h"
#include "core/frame/EventHandlerRegistry.h"
+#include "core/frame/FrameView.h"
#include "core/frame/LocalDOMWindow.h"
#include "core/frame/LocalFrame.h"
#include "core/html/HTMLDialogElement.h"
@@ -2083,14 +2085,74 @@ DispatchEventResult Node::dispatchDOMActivateEvent(int detail,
return EventTarget::dispatchEventResult(*event);
}
-DispatchEventResult Node::dispatchMouseEvent(
- const PlatformMouseEvent& nativeEvent,
- const AtomicString& eventType,
- int detail,
- Node* relatedTarget) {
- MouseEvent* event = MouseEvent::create(eventType, document().domWindow(),
- nativeEvent, detail, relatedTarget);
- return dispatchEvent(event);
+void Node::createAndDispatchPointerEvent(const AtomicString& mouseEventName,
+ const PlatformMouseEvent& mouseEvent,
+ LocalDOMWindow* view) {
+ AtomicString pointerEventName;
+ if (mouseEventName == EventTypeNames::mousemove)
+ pointerEventName = EventTypeNames::pointermove;
+ else if (mouseEventName == EventTypeNames::mousedown)
+ pointerEventName = EventTypeNames::pointerdown;
+ else if (mouseEventName == EventTypeNames::mouseup)
+ pointerEventName = EventTypeNames::pointerup;
+ else
+ return;
+
+ PointerEventInit pointerEventInit;
+
+ pointerEventInit.setPointerId(PointerEventFactory::s_mouseId);
+ pointerEventInit.setPointerType("mouse");
+ pointerEventInit.setIsPrimary(true);
+ pointerEventInit.setButtons(
+ MouseEvent::platformModifiersToButtons(mouseEvent.getModifiers()));
+
+ pointerEventInit.setBubbles(true);
+ pointerEventInit.setCancelable(true);
+ pointerEventInit.setComposed(true);
+ pointerEventInit.setDetail(0);
+
+ pointerEventInit.setScreenX(mouseEvent.globalPosition().x());
+ pointerEventInit.setScreenY(mouseEvent.globalPosition().y());
+
+ IntPoint locationInFrameZoomed;
+ if (view && view->frame() && view->frame()->view()) {
+ LocalFrame* frame = view->frame();
+ FrameView* frameView = frame->view();
+ IntPoint locationInContents =
+ frameView->rootFrameToContents(mouseEvent.position());
+ locationInFrameZoomed = frameView->contentsToFrame(locationInContents);
+ float scaleFactor = 1 / frame->pageZoomFactor();
+ locationInFrameZoomed.scale(scaleFactor, scaleFactor);
+ }
+
+ // Set up initial values for coordinates.
+ pointerEventInit.setClientX(locationInFrameZoomed.x());
+ pointerEventInit.setClientY(locationInFrameZoomed.y());
+
+ if (pointerEventName == EventTypeNames::pointerdown ||
+ pointerEventName == EventTypeNames::pointerup) {
+ pointerEventInit.setButton(
+ static_cast<int>(mouseEvent.pointerProperties().button));
+ } else {
+ pointerEventInit.setButton(
+ static_cast<int>(WebPointerProperties::Button::NoButton));
+ }
+
+ UIEventWithKeyState::setFromPlatformModifiers(pointerEventInit,
+ mouseEvent.getModifiers());
+ pointerEventInit.setView(view);
+
+ dispatchEvent(PointerEvent::create(pointerEventName, pointerEventInit));
+}
+
+void Node::dispatchMouseEvent(const PlatformMouseEvent& nativeEvent,
+ const AtomicString& mouseEventType,
+ int detail,
+ Node* relatedTarget) {
+ createAndDispatchPointerEvent(mouseEventType, nativeEvent,
+ document().domWindow());
+ dispatchEvent(MouseEvent::create(mouseEventType, document().domWindow(),
+ nativeEvent, detail, relatedTarget));
}
void Node::dispatchSimulatedClick(Event* underlyingEvent,
« no previous file with comments | « third_party/WebKit/Source/core/dom/Node.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698