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

Side by Side Diff: third_party/WebKit/Source/web/WebInputEventConversion.cpp

Issue 1829743003: Fix missing fields in GestureScrollBegin/Update/End event conversions. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix tdresser's comments in patch set 1 Created 4 years, 9 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 /* 1 /*
2 * Copyright (C) 2009 Google Inc. All rights reserved. 2 * Copyright (C) 2009 Google Inc. All rights reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are 5 * modification, are permitted provided that the following conditions are
6 * met: 6 * met:
7 * 7 *
8 * * Redistributions of source code must retain the above copyright 8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer. 9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above 10 * * Redistributions in binary form must reproduce the above
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
42 #include "core/frame/VisualViewport.h" 42 #include "core/frame/VisualViewport.h"
43 #include "core/layout/LayoutObject.h" 43 #include "core/layout/LayoutObject.h"
44 #include "core/page/ChromeClient.h" 44 #include "core/page/ChromeClient.h"
45 #include "core/page/Page.h" 45 #include "core/page/Page.h"
46 #include "platform/KeyboardCodes.h" 46 #include "platform/KeyboardCodes.h"
47 #include "platform/Widget.h" 47 #include "platform/Widget.h"
48 #include "public/platform/Platform.h" 48 #include "public/platform/Platform.h"
49 49
50 namespace blink { 50 namespace blink {
51 51
52 static float scaleDeltaToWindow(const Widget* widget, float delta) 52 namespace {
53 float scaleDeltaToWindow(const Widget* widget, float delta)
53 { 54 {
54 float scale = 1; 55 float scale = 1;
55 if (widget) { 56 if (widget) {
56 FrameView* rootView = toFrameView(widget->root()); 57 FrameView* rootView = toFrameView(widget->root());
57 if (rootView) 58 if (rootView)
58 scale = rootView->inputEventsScaleFactor(); 59 scale = rootView->inputEventsScaleFactor();
59 } 60 }
60 return delta / scale; 61 return delta / scale;
61 } 62 }
62 63
63 static FloatSize scaleSizeToWindow(const Widget* widget, FloatSize size) 64 FloatSize scaleSizeToWindow(const Widget* widget, FloatSize size)
64 { 65 {
65 return FloatSize(scaleDeltaToWindow(widget, size.width()), scaleDeltaToWindo w(widget, size.height())); 66 return FloatSize(scaleDeltaToWindow(widget, size.width()), scaleDeltaToWindo w(widget, size.height()));
66 } 67 }
67 68
68 // This method converts from the renderer's coordinate space into Blink's root f rame coordinate space. 69 // This method converts from the renderer's coordinate space into Blink's root f rame coordinate space.
69 // It's somewhat unique in that it takes into account DevTools emulation, which applies a scale and offset 70 // It's somewhat unique in that it takes into account DevTools emulation, which applies a scale and offset
70 // in the root layer (see updateRootLayerTransform in WebViewImpl) as well as th e overscroll effect on OSX. 71 // in the root layer (see updateRootLayerTransform in WebViewImpl) as well as th e overscroll effect on OSX.
71 // This is in addition to the visual viewport "pinch-zoom" transformation and is one of the few cases where 72 // This is in addition to the visual viewport "pinch-zoom" transformation and is one of the few cases where
72 // the visual viewport is not equal to the renderer's coordinate-space. 73 // the visual viewport is not equal to the renderer's coordinate-space.
73 static FloatPoint convertHitPointToRootFrame(const Widget* widget, FloatPoint po intInRendererViewport) 74 FloatPoint convertHitPointToRootFrame(const Widget* widget, FloatPoint pointInRe ndererViewport)
74 { 75 {
75 float scale = 1; 76 float scale = 1;
76 IntSize offset; 77 IntSize offset;
77 IntPoint visualViewport; 78 IntPoint visualViewport;
78 FloatSize overscrollOffset; 79 FloatSize overscrollOffset;
79 if (widget) { 80 if (widget) {
80 FrameView* rootView = toFrameView(widget->root()); 81 FrameView* rootView = toFrameView(widget->root());
81 if (rootView) { 82 if (rootView) {
82 scale = rootView->inputEventsScaleFactor(); 83 scale = rootView->inputEventsScaleFactor();
83 offset = rootView->inputEventsOffsetForEmulation(); 84 offset = rootView->inputEventsOffsetForEmulation();
84 visualViewport = flooredIntPoint(rootView->page()->frameHost().visua lViewport().visibleRect().location()); 85 visualViewport = flooredIntPoint(rootView->page()->frameHost().visua lViewport().visibleRect().location());
85 overscrollOffset = rootView->page()->frameHost().chromeClient().elas ticOverscroll(); 86 overscrollOffset = rootView->page()->frameHost().chromeClient().elas ticOverscroll();
86 } 87 }
87 } 88 }
88 return FloatPoint( 89 return FloatPoint(
89 (pointInRendererViewport.x() - offset.width()) / scale + visualViewport. x() + overscrollOffset.width(), 90 (pointInRendererViewport.x() - offset.width()) / scale + visualViewport. x() + overscrollOffset.width(),
90 (pointInRendererViewport.y() - offset.height()) / scale + visualViewport .y() + overscrollOffset.height()); 91 (pointInRendererViewport.y() - offset.height()) / scale + visualViewport .y() + overscrollOffset.height());
91 } 92 }
92 93
93 static unsigned toPlatformModifierFrom(WebMouseEvent::Button button) 94 unsigned toPlatformModifierFrom(WebMouseEvent::Button button)
94 { 95 {
95 if (button == WebMouseEvent::ButtonNone) 96 if (button == WebMouseEvent::ButtonNone)
96 return 0; 97 return 0;
97 98
98 unsigned webMouseButtonToPlatformModifier[] = { 99 unsigned webMouseButtonToPlatformModifier[] = {
99 PlatformEvent::LeftButtonDown, 100 PlatformEvent::LeftButtonDown,
100 PlatformEvent::MiddleButtonDown, 101 PlatformEvent::MiddleButtonDown,
101 PlatformEvent::RightButtonDown 102 PlatformEvent::RightButtonDown
102 }; 103 };
103 104
104 return webMouseButtonToPlatformModifier[button]; 105 return webMouseButtonToPlatformModifier[button];
105 } 106 }
106 107
108 ScrollGranularity toPlatformScrollGranularity(WebGestureEvent::ScrollUnits units )
109 {
110 switch (units) {
111 case WebGestureEvent::ScrollUnits::PrecisePixels:
112 return ScrollGranularity::ScrollByPrecisePixel;
113 case WebGestureEvent::ScrollUnits::Pixels:
114 return ScrollGranularity::ScrollByPixel;
115 case WebGestureEvent::ScrollUnits::Page:
116 return ScrollGranularity::ScrollByPage;
117 default:
118 ASSERT_NOT_REACHED();
119 return ScrollGranularity::ScrollByPrecisePixel;
120 }
121 }
122
123 WebGestureEvent::ScrollUnits toWebGestureScrollUnits(ScrollGranularity granulari ty)
124 {
125 switch (granularity) {
126 case ScrollGranularity::ScrollByPrecisePixel:
127 return WebGestureEvent::ScrollUnits::PrecisePixels;
128 case ScrollGranularity::ScrollByPixel:
129 return WebGestureEvent::ScrollUnits::Pixels;
130 case ScrollGranularity::ScrollByPage:
131 return WebGestureEvent::ScrollUnits::Page;
132 default:
133 ASSERT_NOT_REACHED();
134 return WebGestureEvent::ScrollUnits::PrecisePixels;
135 }
136 }
137
138 } // namespace
139
107 // MakePlatformMouseEvent ----------------------------------------------------- 140 // MakePlatformMouseEvent -----------------------------------------------------
108 141
109 // TODO(mustaq): Add tests for this. 142 // TODO(mustaq): Add tests for this.
110 PlatformMouseEventBuilder::PlatformMouseEventBuilder(Widget* widget, const WebMo useEvent& e) 143 PlatformMouseEventBuilder::PlatformMouseEventBuilder(Widget* widget, const WebMo useEvent& e)
111 { 144 {
112 // FIXME: Widget is always toplevel, unless it's a popup. We may be able 145 // FIXME: Widget is always toplevel, unless it's a popup. We may be able
113 // to get rid of this once we abstract popups into a WebKit API. 146 // to get rid of this once we abstract popups into a WebKit API.
114 m_position = widget->convertFromRootFrame(flooredIntPoint(convertHitPointToR ootFrame(widget, IntPoint(e.x, e.y)))); 147 m_position = widget->convertFromRootFrame(flooredIntPoint(convertHitPointToR ootFrame(widget, IntPoint(e.x, e.y))));
115 m_globalPosition = IntPoint(e.globalX, e.globalY); 148 m_globalPosition = IntPoint(e.globalX, e.globalY);
116 m_movementDelta = IntPoint(scaleDeltaToWindow(widget, e.movementX), scaleDel taToWindow(widget, e.movementY)); 149 m_movementDelta = IntPoint(scaleDeltaToWindow(widget, e.movementX), scaleDel taToWindow(widget, e.movementY));
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
178 } 211 }
179 212
180 // PlatformGestureEventBuilder ------------------------------------------------- - 213 // PlatformGestureEventBuilder ------------------------------------------------- -
181 214
182 PlatformGestureEventBuilder::PlatformGestureEventBuilder(Widget* widget, const W ebGestureEvent& e) 215 PlatformGestureEventBuilder::PlatformGestureEventBuilder(Widget* widget, const W ebGestureEvent& e)
183 { 216 {
184 switch (e.type) { 217 switch (e.type) {
185 case WebInputEvent::GestureScrollBegin: 218 case WebInputEvent::GestureScrollBegin:
186 m_type = PlatformEvent::GestureScrollBegin; 219 m_type = PlatformEvent::GestureScrollBegin;
187 m_data.m_scroll.m_resendingPluginId = e.resendingPluginId; 220 m_data.m_scroll.m_resendingPluginId = e.resendingPluginId;
221 m_data.m_scroll.m_deltaX = e.data.scrollBegin.deltaXHint;
222 m_data.m_scroll.m_deltaY = e.data.scrollBegin.deltaYHint;
223 m_data.m_scroll.m_deltaUnits = toPlatformScrollGranularity(e.data.scroll Begin.deltaHintUnits);
224 m_data.m_scroll.m_inertial = e.data.scrollBegin.inertial;
225 m_data.m_scroll.m_synthetic = e.data.scrollBegin.synthetic;
188 break; 226 break;
189 case WebInputEvent::GestureScrollEnd: 227 case WebInputEvent::GestureScrollEnd:
190 m_type = PlatformEvent::GestureScrollEnd; 228 m_type = PlatformEvent::GestureScrollEnd;
191 m_data.m_scroll.m_resendingPluginId = e.resendingPluginId; 229 m_data.m_scroll.m_resendingPluginId = e.resendingPluginId;
230 m_data.m_scroll.m_deltaUnits = toPlatformScrollGranularity(e.data.scroll End.deltaUnits);
231 m_data.m_scroll.m_inertial = e.data.scrollEnd.inertial;
232 m_data.m_scroll.m_synthetic = e.data.scrollEnd.synthetic;
192 break; 233 break;
193 case WebInputEvent::GestureFlingStart: 234 case WebInputEvent::GestureFlingStart:
194 m_type = PlatformEvent::GestureFlingStart; 235 m_type = PlatformEvent::GestureFlingStart;
195 m_data.m_scroll.m_velocityX = e.data.flingStart.velocityX; 236 m_data.m_scroll.m_velocityX = e.data.flingStart.velocityX;
196 m_data.m_scroll.m_velocityY = e.data.flingStart.velocityY; 237 m_data.m_scroll.m_velocityY = e.data.flingStart.velocityY;
197 break; 238 break;
198 case WebInputEvent::GestureScrollUpdate: 239 case WebInputEvent::GestureScrollUpdate:
199 m_type = PlatformEvent::GestureScrollUpdate; 240 m_type = PlatformEvent::GestureScrollUpdate;
200 m_data.m_scroll.m_resendingPluginId = e.resendingPluginId; 241 m_data.m_scroll.m_resendingPluginId = e.resendingPluginId;
201 m_data.m_scroll.m_deltaX = scaleDeltaToWindow(widget, e.data.scrollUpdat e.deltaX); 242 m_data.m_scroll.m_deltaX = scaleDeltaToWindow(widget, e.data.scrollUpdat e.deltaX);
202 m_data.m_scroll.m_deltaY = scaleDeltaToWindow(widget, e.data.scrollUpdat e.deltaY); 243 m_data.m_scroll.m_deltaY = scaleDeltaToWindow(widget, e.data.scrollUpdat e.deltaY);
203 m_data.m_scroll.m_velocityX = e.data.scrollUpdate.velocityX; 244 m_data.m_scroll.m_velocityX = e.data.scrollUpdate.velocityX;
204 m_data.m_scroll.m_velocityY = e.data.scrollUpdate.velocityY; 245 m_data.m_scroll.m_velocityY = e.data.scrollUpdate.velocityY;
205 m_data.m_scroll.m_preventPropagation = e.data.scrollUpdate.preventPropag ation; 246 m_data.m_scroll.m_preventPropagation = e.data.scrollUpdate.preventPropag ation;
206 m_data.m_scroll.m_inertial = e.data.scrollUpdate.inertial; 247 m_data.m_scroll.m_inertial = e.data.scrollUpdate.inertial;
207 switch (e.data.scrollUpdate.deltaUnits) { 248 m_data.m_scroll.m_deltaUnits = toPlatformScrollGranularity(e.data.scroll Update.deltaUnits);
208 case WebGestureEvent::ScrollUnits::PrecisePixels:
209 m_data.m_scroll.m_deltaUnits = ScrollGranularity::ScrollByPrecisePix el;
210 break;
211 case WebGestureEvent::ScrollUnits::Pixels:
212 m_data.m_scroll.m_deltaUnits = ScrollGranularity::ScrollByPixel;
213 break;
214 case WebGestureEvent::ScrollUnits::Page:
215 m_data.m_scroll.m_deltaUnits = ScrollGranularity::ScrollByPage;
216 break;
217 default:
218 ASSERT_NOT_REACHED();
219 }
220 break; 249 break;
221 case WebInputEvent::GestureTap: 250 case WebInputEvent::GestureTap:
222 m_type = PlatformEvent::GestureTap; 251 m_type = PlatformEvent::GestureTap;
223 m_area = expandedIntSize(scaleSizeToWindow(widget, FloatSize(e.data.tap. width, e.data.tap.height))); 252 m_area = expandedIntSize(scaleSizeToWindow(widget, FloatSize(e.data.tap. width, e.data.tap.height)));
224 m_data.m_tap.m_tapCount = e.data.tap.tapCount; 253 m_data.m_tap.m_tapCount = e.data.tap.tapCount;
225 break; 254 break;
226 case WebInputEvent::GestureTapUnconfirmed: 255 case WebInputEvent::GestureTapUnconfirmed:
227 m_type = PlatformEvent::GestureTapUnconfirmed; 256 m_type = PlatformEvent::GestureTapUnconfirmed;
228 m_area = expandedIntSize(scaleSizeToWindow(widget, FloatSize(e.data.tap. width, e.data.tap.height))); 257 m_area = expandedIntSize(scaleSizeToWindow(widget, FloatSize(e.data.tap. width, e.data.tap.height)));
229 break; 258 break;
(...skipping 475 matching lines...) Expand 10 before | Expand all | Expand 10 after
705 { 734 {
706 if (event.type() == EventTypeNames::gestureshowpress) { 735 if (event.type() == EventTypeNames::gestureshowpress) {
707 type = GestureShowPress; 736 type = GestureShowPress;
708 } else if (event.type() == EventTypeNames::gesturelongpress) { 737 } else if (event.type() == EventTypeNames::gesturelongpress) {
709 type = GestureLongPress; 738 type = GestureLongPress;
710 } else if (event.type() == EventTypeNames::gesturetapdown) { 739 } else if (event.type() == EventTypeNames::gesturetapdown) {
711 type = GestureTapDown; 740 type = GestureTapDown;
712 } else if (event.type() == EventTypeNames::gesturescrollstart) { 741 } else if (event.type() == EventTypeNames::gesturescrollstart) {
713 type = GestureScrollBegin; 742 type = GestureScrollBegin;
714 resendingPluginId = event.resendingPluginId(); 743 resendingPluginId = event.resendingPluginId();
744 data.scrollBegin.deltaXHint = event.deltaX();
745 data.scrollBegin.deltaYHint = event.deltaY();
746 data.scrollBegin.deltaHintUnits = toWebGestureScrollUnits(event.deltaUni ts());
747 data.scrollBegin.inertial = event.inertial();
748 data.scrollBegin.synthetic = event.synthetic();
715 } else if (event.type() == EventTypeNames::gesturescrollend) { 749 } else if (event.type() == EventTypeNames::gesturescrollend) {
716 type = GestureScrollEnd; 750 type = GestureScrollEnd;
717 resendingPluginId = event.resendingPluginId(); 751 resendingPluginId = event.resendingPluginId();
752 data.scrollEnd.deltaUnits = toWebGestureScrollUnits(event.deltaUnits());
753 data.scrollEnd.inertial = event.inertial();
754 data.scrollEnd.synthetic = event.synthetic();
718 } else if (event.type() == EventTypeNames::gesturescrollupdate) { 755 } else if (event.type() == EventTypeNames::gesturescrollupdate) {
719 type = GestureScrollUpdate; 756 type = GestureScrollUpdate;
757 data.scrollUpdate.deltaUnits = toWebGestureScrollUnits(event.deltaUnits( ));
720 data.scrollUpdate.deltaX = event.deltaX(); 758 data.scrollUpdate.deltaX = event.deltaX();
721 data.scrollUpdate.deltaY = event.deltaY(); 759 data.scrollUpdate.deltaY = event.deltaY();
722 data.scrollUpdate.inertial = event.inertial(); 760 data.scrollUpdate.inertial = event.inertial();
723 resendingPluginId = event.resendingPluginId(); 761 resendingPluginId = event.resendingPluginId();
724 } else if (event.type() == EventTypeNames::gestureflingstart) { 762 } else if (event.type() == EventTypeNames::gestureflingstart) {
725 type = GestureFlingStart; 763 type = GestureFlingStart;
726 data.flingStart.velocityX = event.velocityX(); 764 data.flingStart.velocityX = event.velocityX();
727 data.flingStart.velocityY = event.velocityY(); 765 data.flingStart.velocityY = event.velocityY();
728 } else if (event.type() == EventTypeNames::gesturetap) { 766 } else if (event.type() == EventTypeNames::gesturetap) {
729 type = GestureTap; 767 type = GestureTap;
(...skipping 15 matching lines...) Expand all
745 break; 783 break;
746 case GestureSourceTouchscreen: 784 case GestureSourceTouchscreen:
747 sourceDevice = WebGestureDeviceTouchscreen; 785 sourceDevice = WebGestureDeviceTouchscreen;
748 break; 786 break;
749 case GestureSourceUninitialized: 787 case GestureSourceUninitialized:
750 ASSERT_NOT_REACHED(); 788 ASSERT_NOT_REACHED();
751 } 789 }
752 } 790 }
753 791
754 } // namespace blink 792 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698