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

Side by Side Diff: third_party/WebKit/Source/core/events/PointerEventFactory.cpp

Issue 1960233002: Fix mouse pointer event clientX/Y (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 7 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 unified diff | Download patch
OLDNEW
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/events/PointerEventFactory.h" 5 #include "core/events/PointerEventFactory.h"
6 6
7 #include "core/frame/FrameView.h"
7 #include "platform/geometry/FloatSize.h" 8 #include "platform/geometry/FloatSize.h"
8 9
9 namespace blink { 10 namespace blink {
10 11
11 namespace { 12 namespace {
12 13
13 inline int toInt(WebPointerProperties::PointerType t) { return static_cast<int>( t); } 14 inline int toInt(WebPointerProperties::PointerType t) { return static_cast<int>( t); }
14 15
15 const char* pointerTypeNameForWebPointPointerType(WebPointerProperties::PointerT ype type) 16 const char* pointerTypeNameForWebPointPointerType(WebPointerProperties::PointerT ype type)
16 { 17 {
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
82 { 83 {
83 pointerEventInit.setBubbles(type != EventTypeNames::pointerenter 84 pointerEventInit.setBubbles(type != EventTypeNames::pointerenter
84 && type != EventTypeNames::pointerleave); 85 && type != EventTypeNames::pointerleave);
85 pointerEventInit.setCancelable(type != EventTypeNames::pointerenter 86 pointerEventInit.setCancelable(type != EventTypeNames::pointerenter
86 && type != EventTypeNames::pointerleave && type != EventTypeNames::point ercancel); 87 && type != EventTypeNames::pointerleave && type != EventTypeNames::point ercancel);
87 } 88 }
88 89
89 PointerEvent* PointerEventFactory::create( 90 PointerEvent* PointerEventFactory::create(
90 const AtomicString& mouseEventName, const PlatformMouseEvent& mouseEvent, 91 const AtomicString& mouseEventName, const PlatformMouseEvent& mouseEvent,
91 EventTarget* relatedTarget, 92 EventTarget* relatedTarget,
92 AbstractView* view) 93 LocalDOMWindow* view)
93 { 94 {
94 AtomicString pointerEventName = pointerEventNameForMouseEventName(mouseEvent Name); 95 AtomicString pointerEventName = pointerEventNameForMouseEventName(mouseEvent Name);
95 unsigned buttons = MouseEvent::platformModifiersToButtons(mouseEvent.getModi fiers()); 96 unsigned buttons = MouseEvent::platformModifiersToButtons(mouseEvent.getModi fiers());
96 PointerEventInit pointerEventInit; 97 PointerEventInit pointerEventInit;
97 98
98 setIdTypeButtons(pointerEventInit, mouseEvent.pointerProperties(), buttons); 99 setIdTypeButtons(pointerEventInit, mouseEvent.pointerProperties(), buttons);
99 setBubblesAndCancelable(pointerEventInit, pointerEventName); 100 setBubblesAndCancelable(pointerEventInit, pointerEventName);
100 101
101 pointerEventInit.setScreenX(mouseEvent.globalPosition().x()); 102 pointerEventInit.setScreenX(mouseEvent.globalPosition().x());
102 pointerEventInit.setScreenY(mouseEvent.globalPosition().y()); 103 pointerEventInit.setScreenY(mouseEvent.globalPosition().y());
103 pointerEventInit.setClientX(mouseEvent.position().x()); 104
104 pointerEventInit.setClientY(mouseEvent.position().y()); 105 LayoutPoint scrollPosition;
106 LayoutPoint adjustedPageLocation;
107 LocalFrame* frame = view->frame();
108 if (frame) {
mustaq 2016/05/09 18:22:51 The original code in MouseRelatedEvent() seems to
109 if (FrameView* frameView = frame->view()) {
110 scrollPosition = frameView->scrollPosition();
111 adjustedPageLocation = frameView->rootFrameToContents(mouseEvent.pos ition());
112 float scaleFactor = 1 / frame->pageZoomFactor();
113 if (scaleFactor != 1.0f) {
114 adjustedPageLocation.scale(scaleFactor, scaleFactor);
115 scrollPosition.scale(scaleFactor, scaleFactor);
116 }
117 }
118 }
119 LayoutPoint clientPoint = adjustedPageLocation - toLayoutSize(scrollPosition );
120
121 // Set up initial values for coordinates.
122 // Set up initial values for coordinates.
123 pointerEventInit.setClientX(clientPoint.x().toInt());
124 pointerEventInit.setClientY(clientPoint.y().toInt());
105 125
106 if (pointerEventName == EventTypeNames::pointerdown 126 if (pointerEventName == EventTypeNames::pointerdown
107 || pointerEventName == EventTypeNames::pointerup) { 127 || pointerEventName == EventTypeNames::pointerup) {
108 pointerEventInit.setButton(mouseEvent.button()); 128 pointerEventInit.setButton(mouseEvent.button());
109 } else { 129 } else {
110 // TODO(crbug.com/587955): We are setting NoButton for transition 130 // TODO(crbug.com/587955): We are setting NoButton for transition
111 // pointerevents should be resolved as part of this bug 131 // pointerevents should be resolved as part of this bug
112 pointerEventInit.setButton(NoButton); 132 pointerEventInit.setButton(NoButton);
113 } 133 }
114 pointerEventInit.setPressure(getPointerEventPressure( 134 pointerEventInit.setPressure(getPointerEventPressure(
(...skipping 248 matching lines...) Expand 10 before | Expand all | Expand 10 after
363 if (properties.pointerType 383 if (properties.pointerType
364 == WebPointerProperties::PointerType::Mouse) 384 == WebPointerProperties::PointerType::Mouse)
365 return PointerEventFactory::s_mouseId; 385 return PointerEventFactory::s_mouseId;
366 IncomingId id(properties.pointerType, properties.id); 386 IncomingId id(properties.pointerType, properties.id);
367 if (m_pointerIncomingIdMapping.contains(id)) 387 if (m_pointerIncomingIdMapping.contains(id))
368 return m_pointerIncomingIdMapping.get(id); 388 return m_pointerIncomingIdMapping.get(id);
369 return PointerEventFactory::s_invalidId; 389 return PointerEventFactory::s_invalidId;
370 } 390 }
371 391
372 } // namespace blink 392 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/core/events/PointerEventFactory.h ('k') | third_party/WebKit/Source/core/input/EventHandler.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698