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

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

Issue 2406263003: Make PointerEvent coordinates fractional for touch (Closed)
Patch Set: Rebased. 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 unified diff | Download patch
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2001 Peter Kelly (pmk@post.com) 2 * Copyright (C) 2001 Peter Kelly (pmk@post.com)
3 * Copyright (C) 2001 Tobias Anton (anton@stud.fbi.fh-darmstadt.de) 3 * Copyright (C) 2001 Tobias Anton (anton@stud.fbi.fh-darmstadt.de)
4 * Copyright (C) 2006 Samuel Weinig (sam.weinig@gmail.com) 4 * Copyright (C) 2006 Samuel Weinig (sam.weinig@gmail.com)
5 * Copyright (C) 2003, 2005, 2006, 2008 Apple Inc. All rights reserved. 5 * Copyright (C) 2003, 2005, 2006, 2008 Apple Inc. All rights reserved.
6 * 6 *
7 * This library is free software; you can redistribute it and/or 7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Library General Public 8 * modify it under the terms of the GNU Library General Public
9 * License as published by the Free Software Foundation; either 9 * License as published by the Free Software Foundation; either
10 * version 2 of the License, or (at your option) any later version. 10 * version 2 of the License, or (at your option) any later version.
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
67 canBubble, 67 canBubble,
68 cancelable, 68 cancelable,
69 abstractView, 69 abstractView,
70 detail, 70 detail,
71 modifiers, 71 modifiers,
72 platformTimeStamp, 72 platformTimeStamp,
73 sourceCapabilities), 73 sourceCapabilities),
74 m_screenLocation(screenLocation), 74 m_screenLocation(screenLocation),
75 m_movementDelta(movementDelta), 75 m_movementDelta(movementDelta),
76 m_positionType(positionType) { 76 m_positionType(positionType) {
77 LayoutPoint adjustedPageLocation; 77 DoublePoint adjustedPageLocation;
78 LayoutSize scrollOffset; 78 DoubleSize scrollOffset;
79 79
80 LocalFrame* frame = view() && view()->isLocalDOMWindow() 80 LocalFrame* frame = view() && view()->isLocalDOMWindow()
81 ? toLocalDOMWindow(view())->frame() 81 ? toLocalDOMWindow(view())->frame()
82 : nullptr; 82 : nullptr;
83 if (frame && hasPosition()) { 83 if (frame && hasPosition()) {
84 if (FrameView* frameView = frame->view()) { 84 if (FrameView* frameView = frame->view()) {
85 scrollOffset = LayoutSize(frameView->scrollOffsetInt());
86 adjustedPageLocation = frameView->rootFrameToContents(rootFrameLocation); 85 adjustedPageLocation = frameView->rootFrameToContents(rootFrameLocation);
86 scrollOffset = frameView->scrollOffsetInt();
87 float scaleFactor = 1 / frame->pageZoomFactor(); 87 float scaleFactor = 1 / frame->pageZoomFactor();
88 if (scaleFactor != 1.0f) { 88 if (scaleFactor != 1.0f) {
89 adjustedPageLocation.scale(scaleFactor, scaleFactor); 89 adjustedPageLocation.scale(scaleFactor, scaleFactor);
90 scrollOffset.scale(scaleFactor, scaleFactor); 90 scrollOffset.scale(scaleFactor, scaleFactor);
91 } 91 }
92 } 92 }
93 } 93 }
94 94
95 m_clientLocation = adjustedPageLocation - scrollOffset; 95 m_clientLocation = adjustedPageLocation - scrollOffset;
96 m_pageLocation = adjustedPageLocation; 96 m_pageLocation = adjustedPageLocation;
97 97
98 // Set up initial values for coordinates. 98 // Set up initial values for coordinates.
99 // Correct values are computed lazily, see computeRelativePosition. 99 // Correct values are computed lazily, see computeRelativePosition.
100 m_layerLocation = m_pageLocation; 100 m_layerLocation = m_pageLocation;
101 m_offsetLocation = m_pageLocation; 101 m_offsetLocation = m_pageLocation;
102 102
103 computePageLocation(); 103 computePageLocation();
104 m_hasCachedRelativePosition = false; 104 m_hasCachedRelativePosition = false;
105 } 105 }
106 106
107 MouseRelatedEvent::MouseRelatedEvent(const AtomicString& eventType, 107 MouseRelatedEvent::MouseRelatedEvent(const AtomicString& eventType,
108 const MouseEventInit& initializer) 108 const MouseEventInit& initializer)
109 : UIEventWithKeyState(eventType, initializer), 109 : UIEventWithKeyState(eventType, initializer),
110 m_screenLocation(IntPoint(initializer.screenX(), initializer.screenY())), 110 m_screenLocation(
111 DoublePoint(initializer.screenX(), initializer.screenY())),
111 m_movementDelta( 112 m_movementDelta(
112 IntPoint(initializer.movementX(), initializer.movementY())), 113 IntPoint(initializer.movementX(), initializer.movementY())),
113 m_positionType(PositionType::Position) { 114 m_positionType(PositionType::Position) {
114 initCoordinates(IntPoint(initializer.clientX(), initializer.clientY())); 115 initCoordinates(initializer.clientX(), initializer.clientY());
115 } 116 }
116 117
117 void MouseRelatedEvent::initCoordinates(const LayoutPoint& clientLocation) { 118 void MouseRelatedEvent::initCoordinates(const double clientX,
119 const double clientY) {
118 // Set up initial values for coordinates. 120 // Set up initial values for coordinates.
119 // Correct values are computed lazily, see computeRelativePosition. 121 // Correct values are computed lazily, see computeRelativePosition.
120 m_clientLocation = clientLocation; 122 m_clientLocation = DoublePoint(clientX, clientY);
121 m_pageLocation = clientLocation + contentsScrollOffset(view()); 123 m_pageLocation = m_clientLocation + DoubleSize(contentsScrollOffset(view()));
122 124
123 m_layerLocation = m_pageLocation; 125 m_layerLocation = m_pageLocation;
124 m_offsetLocation = m_pageLocation; 126 m_offsetLocation = m_pageLocation;
125 127
126 computePageLocation(); 128 computePageLocation();
127 m_hasCachedRelativePosition = false; 129 m_hasCachedRelativePosition = false;
128 } 130 }
129 131
130 static float pageZoomFactor(const UIEvent* event) { 132 static float pageZoomFactor(const UIEvent* event) {
131 if (!event->view() || !event->view()->isLocalDOMWindow()) 133 if (!event->view() || !event->view()->isLocalDOMWindow())
132 return 1; 134 return 1;
133 LocalFrame* frame = toLocalDOMWindow(event->view())->frame(); 135 LocalFrame* frame = toLocalDOMWindow(event->view())->frame();
134 if (!frame) 136 if (!frame)
135 return 1; 137 return 1;
136 return frame->pageZoomFactor(); 138 return frame->pageZoomFactor();
137 } 139 }
138 140
139 void MouseRelatedEvent::computePageLocation() { 141 void MouseRelatedEvent::computePageLocation() {
140 float scaleFactor = pageZoomFactor(this); 142 float scaleFactor = pageZoomFactor(this);
141 setAbsoluteLocation( 143 m_absoluteLocation = m_pageLocation.scaledBy(scaleFactor);
142 LayoutPoint(FloatPoint(pageX() * scaleFactor, pageY() * scaleFactor)));
143 } 144 }
144 145
145 void MouseRelatedEvent::receivedTarget() { 146 void MouseRelatedEvent::receivedTarget() {
146 m_hasCachedRelativePosition = false; 147 m_hasCachedRelativePosition = false;
147 } 148 }
148 149
149 static const LayoutObject* findTargetLayoutObject(Node*& targetNode) { 150 static const LayoutObject* findTargetLayoutObject(Node*& targetNode) {
150 LayoutObject* layoutObject = targetNode->layoutObject(); 151 LayoutObject* layoutObject = targetNode->layoutObject();
151 if (!layoutObject || !layoutObject->isSVG()) 152 if (!layoutObject || !layoutObject->isSVG())
152 return layoutObject; 153 return layoutObject;
(...skipping 27 matching lines...) Expand all
180 181
181 // Adding this here to address crbug.com/570666. Basically we'd like to 182 // Adding this here to address crbug.com/570666. Basically we'd like to
182 // find the local coordinates relative to the padding box not the border 183 // find the local coordinates relative to the padding box not the border
183 // box. 184 // box.
184 if (layoutObject->isBoxModelObject()) { 185 if (layoutObject->isBoxModelObject()) {
185 const LayoutBoxModelObject* layoutBox = 186 const LayoutBoxModelObject* layoutBox =
186 toLayoutBoxModelObject(layoutObject); 187 toLayoutBoxModelObject(layoutObject);
187 localPos.move(-layoutBox->borderLeft(), -layoutBox->borderTop()); 188 localPos.move(-layoutBox->borderLeft(), -layoutBox->borderTop());
188 } 189 }
189 190
190 m_offsetLocation = LayoutPoint(localPos); 191 m_offsetLocation = DoublePoint(localPos);
191 float scaleFactor = 1 / pageZoomFactor(this); 192 float scaleFactor = 1 / pageZoomFactor(this);
192 if (scaleFactor != 1.0f) 193 if (scaleFactor != 1.0f)
193 m_offsetLocation.scale(scaleFactor, scaleFactor); 194 m_offsetLocation.scale(scaleFactor, scaleFactor);
194 } 195 }
195 196
196 // Adjust layerLocation to be relative to the layer. 197 // Adjust layerLocation to be relative to the layer.
197 // FIXME: event.layerX and event.layerY are poorly defined, 198 // FIXME: event.layerX and event.layerY are poorly defined,
198 // and probably don't always correspond to PaintLayer offsets. 199 // and probably don't always correspond to PaintLayer offsets.
199 // https://bugs.webkit.org/show_bug.cgi?id=21868 200 // https://bugs.webkit.org/show_bug.cgi?id=21868
200 Node* n = targetNode; 201 Node* n = targetNode;
201 while (n && !n->layoutObject()) 202 while (n && !n->layoutObject())
202 n = n->parentNode(); 203 n = n->parentNode();
203 204
204 if (n) { 205 if (n) {
205 // FIXME: This logic is a wrong implementation of convertToLayerCoords. 206 // FIXME: This logic is a wrong implementation of convertToLayerCoords.
206 for (PaintLayer* layer = n->layoutObject()->enclosingLayer(); layer; 207 for (PaintLayer* layer = n->layoutObject()->enclosingLayer(); layer;
207 layer = layer->parent()) 208 layer = layer->parent()) {
208 m_layerLocation -= toLayoutSize(layer->location()); 209 m_layerLocation -= DoubleSize(layer->location().x().toDouble(),
210 layer->location().y().toDouble());
211 }
209 } 212 }
210 213
211 m_hasCachedRelativePosition = true; 214 m_hasCachedRelativePosition = true;
212 } 215 }
213 216
214 int MouseRelatedEvent::layerX() { 217 int MouseRelatedEvent::layerX() {
215 if (!m_hasCachedRelativePosition) 218 if (!m_hasCachedRelativePosition)
216 computeRelativePosition(); 219 computeRelativePosition();
217 return m_layerLocation.x().toInt(); 220
221 // TODO(mustaq): Remove the PointerEvent specific code when mouse has
222 // fractional coordinates. See crbug.com/655786.
223 return isPointerEvent() ? m_layerLocation.x()
224 : static_cast<int>(m_layerLocation.x());
218 } 225 }
219 226
220 int MouseRelatedEvent::layerY() { 227 int MouseRelatedEvent::layerY() {
221 if (!m_hasCachedRelativePosition) 228 if (!m_hasCachedRelativePosition)
222 computeRelativePosition(); 229 computeRelativePosition();
223 return m_layerLocation.y().toInt(); 230
231 // TODO(mustaq): Remove the PointerEvent specific code when mouse has
232 // fractional coordinates. See crbug.com/655786.
233 return isPointerEvent() ? m_layerLocation.y()
234 : static_cast<int>(m_layerLocation.y());
224 } 235 }
225 236
226 int MouseRelatedEvent::offsetX() { 237 int MouseRelatedEvent::offsetX() {
227 if (!hasPosition()) 238 if (!hasPosition())
228 return 0; 239 return 0;
229 if (!m_hasCachedRelativePosition) 240 if (!m_hasCachedRelativePosition)
230 computeRelativePosition(); 241 computeRelativePosition();
231 return roundToInt(m_offsetLocation.x()); 242 return std::round(m_offsetLocation.x());
232 } 243 }
233 244
234 int MouseRelatedEvent::offsetY() { 245 int MouseRelatedEvent::offsetY() {
235 if (!hasPosition()) 246 if (!hasPosition())
236 return 0; 247 return 0;
237 if (!m_hasCachedRelativePosition) 248 if (!m_hasCachedRelativePosition)
238 computeRelativePosition(); 249 computeRelativePosition();
239 return roundToInt(m_offsetLocation.y()); 250 return std::round(m_offsetLocation.y());
240 }
241
242 int MouseRelatedEvent::pageX() const {
243 return m_pageLocation.x().toInt();
244 }
245
246 int MouseRelatedEvent::pageY() const {
247 return m_pageLocation.y().toInt();
248 }
249
250 int MouseRelatedEvent::x() const {
251 // FIXME: This is not correct.
252 // See Microsoft documentation and
253 // <http://www.quirksmode.org/dom/w3c_events.html>.
254 return m_clientLocation.x().toInt();
255 }
256
257 int MouseRelatedEvent::y() const {
258 // FIXME: This is not correct.
259 // See Microsoft documentation and
260 // <http://www.quirksmode.org/dom/w3c_events.html>.
261 return m_clientLocation.y().toInt();
262 } 251 }
263 252
264 DEFINE_TRACE(MouseRelatedEvent) { 253 DEFINE_TRACE(MouseRelatedEvent) {
265 UIEventWithKeyState::trace(visitor); 254 UIEventWithKeyState::trace(visitor);
266 } 255 }
267 256
268 } // namespace blink 257 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698