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

Side by Side Diff: content/renderer/render_widget_fullscreen_pepper.cc

Issue 2573073003: Collapse the API surface on WebInputEvent via accessor functions. (Closed)
Patch Set: Fix nits Created 3 years, 11 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
« no previous file with comments | « content/renderer/render_widget.cc ('k') | content/renderer/render_widget_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 "content/renderer/render_widget_fullscreen_pepper.h" 5 #include "content/renderer/render_widget_fullscreen_pepper.h"
6 6
7 #include <vector> 7 #include <vector>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/command_line.h" 10 #include "base/command_line.h"
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
65 }; 65 };
66 66
67 WebMouseEvent WebMouseEventFromGestureEvent(const WebGestureEvent& gesture) { 67 WebMouseEvent WebMouseEventFromGestureEvent(const WebGestureEvent& gesture) {
68 68
69 // Only convert touch screen gesture events, do not convert 69 // Only convert touch screen gesture events, do not convert
70 // touchpad/mouse wheel gesture events. (crbug.com/620974) 70 // touchpad/mouse wheel gesture events. (crbug.com/620974)
71 if (gesture.sourceDevice != blink::WebGestureDeviceTouchscreen) 71 if (gesture.sourceDevice != blink::WebGestureDeviceTouchscreen)
72 return WebMouseEvent(); 72 return WebMouseEvent();
73 73
74 WebInputEvent::Type type = WebInputEvent::Undefined; 74 WebInputEvent::Type type = WebInputEvent::Undefined;
75 switch (gesture.type) { 75 switch (gesture.type()) {
76 case WebInputEvent::GestureScrollBegin: 76 case WebInputEvent::GestureScrollBegin:
77 type = WebInputEvent::MouseDown; 77 type = WebInputEvent::MouseDown;
78 break; 78 break;
79 case WebInputEvent::GestureScrollUpdate: 79 case WebInputEvent::GestureScrollUpdate:
80 type = WebInputEvent::MouseMove; 80 type = WebInputEvent::MouseMove;
81 break; 81 break;
82 case WebInputEvent::GestureFlingStart: 82 case WebInputEvent::GestureFlingStart:
83 // A scroll gesture on the touchscreen may end with a GestureScrollEnd 83 // A scroll gesture on the touchscreen may end with a GestureScrollEnd
84 // when there is no velocity, or a GestureFlingStart when it has a 84 // when there is no velocity, or a GestureFlingStart when it has a
85 // velocity. In both cases, it should end the drag that was initiated by 85 // velocity. In both cases, it should end the drag that was initiated by
86 // the GestureScrollBegin (and subsequent GestureScrollUpdate) events. 86 // the GestureScrollBegin (and subsequent GestureScrollUpdate) events.
87 type = WebInputEvent::MouseUp; 87 type = WebInputEvent::MouseUp;
88 break; 88 break;
89 case WebInputEvent::GestureScrollEnd: 89 case WebInputEvent::GestureScrollEnd:
90 type = WebInputEvent::MouseUp; 90 type = WebInputEvent::MouseUp;
91 break; 91 break;
92 default: 92 default:
93 return WebMouseEvent(); 93 return WebMouseEvent();
94 } 94 }
95 95
96 WebMouseEvent mouse(type, gesture.modifiers | WebInputEvent::LeftButtonDown, 96 WebMouseEvent mouse(type, gesture.modifiers() | WebInputEvent::LeftButtonDown,
97 gesture.timeStampSeconds); 97 gesture.timeStampSeconds());
98 mouse.button = WebMouseEvent::Button::Left; 98 mouse.button = WebMouseEvent::Button::Left;
99 mouse.clickCount = (mouse.type == WebInputEvent::MouseDown || 99 mouse.clickCount = (mouse.type() == WebInputEvent::MouseDown ||
100 mouse.type == WebInputEvent::MouseUp); 100 mouse.type() == WebInputEvent::MouseUp);
101 101
102 mouse.x = gesture.x; 102 mouse.x = gesture.x;
103 mouse.y = gesture.y; 103 mouse.y = gesture.y;
104 mouse.windowX = gesture.x; 104 mouse.windowX = gesture.x;
105 mouse.windowY = gesture.y; 105 mouse.windowY = gesture.y;
106 mouse.globalX = gesture.globalX; 106 mouse.globalX = gesture.globalX;
107 mouse.globalY = gesture.globalY; 107 mouse.globalY = gesture.globalY;
108 108
109 return mouse; 109 return mouse;
110 } 110 }
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
158 if (!widget_->plugin()) 158 if (!widget_->plugin())
159 return WebInputEventResult::NotHandled; 159 return WebInputEventResult::NotHandled;
160 160
161 // This cursor info is ignored, we always set the cursor directly from 161 // This cursor info is ignored, we always set the cursor directly from
162 // RenderWidgetFullscreenPepper::DidChangeCursor. 162 // RenderWidgetFullscreenPepper::DidChangeCursor.
163 WebCursorInfo cursor; 163 WebCursorInfo cursor;
164 164
165 // Pepper plugins do not accept gesture events. So do not send the gesture 165 // Pepper plugins do not accept gesture events. So do not send the gesture
166 // events directly to the plugin. Instead, try to convert them to equivalent 166 // events directly to the plugin. Instead, try to convert them to equivalent
167 // mouse events, and then send to the plugin. 167 // mouse events, and then send to the plugin.
168 if (WebInputEvent::isGestureEventType(event.type)) { 168 if (WebInputEvent::isGestureEventType(event.type())) {
169 bool result = false; 169 bool result = false;
170 const WebGestureEvent* gesture_event = 170 const WebGestureEvent* gesture_event =
171 static_cast<const WebGestureEvent*>(&event); 171 static_cast<const WebGestureEvent*>(&event);
172 switch (event.type) { 172 switch (event.type()) {
173 case WebInputEvent::GestureTap: { 173 case WebInputEvent::GestureTap: {
174 WebMouseEvent mouse(WebInputEvent::MouseMove, 174 WebMouseEvent mouse(WebInputEvent::MouseMove,
175 gesture_event->modifiers, 175 gesture_event->modifiers(),
176 gesture_event->timeStampSeconds); 176 gesture_event->timeStampSeconds());
177 mouse.x = gesture_event->x; 177 mouse.x = gesture_event->x;
178 mouse.y = gesture_event->y; 178 mouse.y = gesture_event->y;
179 mouse.windowX = gesture_event->x; 179 mouse.windowX = gesture_event->x;
180 mouse.windowY = gesture_event->y; 180 mouse.windowY = gesture_event->y;
181 mouse.globalX = gesture_event->globalX; 181 mouse.globalX = gesture_event->globalX;
182 mouse.globalY = gesture_event->globalY; 182 mouse.globalY = gesture_event->globalY;
183 mouse.movementX = 0; 183 mouse.movementX = 0;
184 mouse.movementY = 0; 184 mouse.movementY = 0;
185 result |= widget_->plugin()->HandleInputEvent(mouse, &cursor); 185 result |= widget_->plugin()->HandleInputEvent(mouse, &cursor);
186 186
187 mouse.setType(WebInputEvent::MouseDown); 187 mouse.setType(WebInputEvent::MouseDown);
188 mouse.button = WebMouseEvent::Button::Left; 188 mouse.button = WebMouseEvent::Button::Left;
189 mouse.clickCount = gesture_event->data.tap.tapCount; 189 mouse.clickCount = gesture_event->data.tap.tapCount;
190 result |= widget_->plugin()->HandleInputEvent(mouse, &cursor); 190 result |= widget_->plugin()->HandleInputEvent(mouse, &cursor);
191 191
192 mouse.setType(WebInputEvent::MouseUp); 192 mouse.setType(WebInputEvent::MouseUp);
193 result |= widget_->plugin()->HandleInputEvent(mouse, &cursor); 193 result |= widget_->plugin()->HandleInputEvent(mouse, &cursor);
194 break; 194 break;
195 } 195 }
196 196
197 default: { 197 default: {
198 WebMouseEvent mouse = WebMouseEventFromGestureEvent(*gesture_event); 198 WebMouseEvent mouse = WebMouseEventFromGestureEvent(*gesture_event);
199 if (mouse.type != WebInputEvent::Undefined) 199 if (mouse.type() != WebInputEvent::Undefined)
200 result |= widget_->plugin()->HandleInputEvent(mouse, &cursor); 200 result |= widget_->plugin()->HandleInputEvent(mouse, &cursor);
201 break; 201 break;
202 } 202 }
203 } 203 }
204 return result ? WebInputEventResult::HandledApplication 204 return result ? WebInputEventResult::HandledApplication
205 : WebInputEventResult::NotHandled; 205 : WebInputEventResult::NotHandled;
206 } 206 }
207 207
208 bool result = widget_->plugin()->HandleInputEvent(event, &cursor); 208 bool result = widget_->plugin()->HandleInputEvent(event, &cursor);
209 209
210 // For normal web pages, WebViewImpl does input event translations and 210 // For normal web pages, WebViewImpl does input event translations and
211 // generates context menu events. Since we don't have a WebView, we need to 211 // generates context menu events. Since we don't have a WebView, we need to
212 // do the necessary translation ourselves. 212 // do the necessary translation ourselves.
213 if (WebInputEvent::isMouseEventType(event.type)) { 213 if (WebInputEvent::isMouseEventType(event.type())) {
214 const WebMouseEvent& mouse_event = 214 const WebMouseEvent& mouse_event =
215 reinterpret_cast<const WebMouseEvent&>(event); 215 reinterpret_cast<const WebMouseEvent&>(event);
216 bool send_context_menu_event = false; 216 bool send_context_menu_event = false;
217 // On Mac/Linux, we handle it on mouse down. 217 // On Mac/Linux, we handle it on mouse down.
218 // On Windows, we handle it on mouse up. 218 // On Windows, we handle it on mouse up.
219 #if defined(OS_WIN) 219 #if defined(OS_WIN)
220 send_context_menu_event = 220 send_context_menu_event =
221 mouse_event.type == WebInputEvent::MouseUp && 221 mouse_event.type() == WebInputEvent::MouseUp &&
222 mouse_event.button == WebMouseEvent::Button::Right; 222 mouse_event.button == WebMouseEvent::Button::Right;
223 #elif defined(OS_MACOSX) 223 #elif defined(OS_MACOSX)
224 send_context_menu_event = 224 send_context_menu_event =
225 mouse_event.type == WebInputEvent::MouseDown && 225 mouse_event.type() == WebInputEvent::MouseDown &&
226 (mouse_event.button == WebMouseEvent::Button::Right || 226 (mouse_event.button == WebMouseEvent::Button::Right ||
227 (mouse_event.button == WebMouseEvent::Button::Left && 227 (mouse_event.button == WebMouseEvent::Button::Left &&
228 mouse_event.modifiers & WebMouseEvent::ControlKey)); 228 mouse_event.modifiers() & WebMouseEvent::ControlKey));
229 #else 229 #else
230 send_context_menu_event = 230 send_context_menu_event =
231 mouse_event.type == WebInputEvent::MouseDown && 231 mouse_event.type() == WebInputEvent::MouseDown &&
232 mouse_event.button == WebMouseEvent::Button::Right; 232 mouse_event.button == WebMouseEvent::Button::Right;
233 #endif 233 #endif
234 if (send_context_menu_event) { 234 if (send_context_menu_event) {
235 WebMouseEvent context_menu_event(mouse_event); 235 WebMouseEvent context_menu_event(mouse_event);
236 context_menu_event.type = WebInputEvent::ContextMenu; 236 context_menu_event.setType(WebInputEvent::ContextMenu);
237 widget_->plugin()->HandleInputEvent(context_menu_event, &cursor); 237 widget_->plugin()->HandleInputEvent(context_menu_event, &cursor);
238 } 238 }
239 } 239 }
240 return result ? WebInputEventResult::HandledApplication 240 return result ? WebInputEventResult::HandledApplication
241 : WebInputEventResult::NotHandled; 241 : WebInputEventResult::NotHandled;
242 } 242 }
243 243
244 private: 244 private:
245 RenderWidgetFullscreenPepper* widget_; 245 RenderWidgetFullscreenPepper* widget_;
246 WebSize size_; 246 WebSize size_;
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after
376 GURL RenderWidgetFullscreenPepper::GetURLForGraphicsContext3D() { 376 GURL RenderWidgetFullscreenPepper::GetURLForGraphicsContext3D() {
377 return active_url_; 377 return active_url_;
378 } 378 }
379 379
380 void RenderWidgetFullscreenPepper::OnDeviceScaleFactorChanged() { 380 void RenderWidgetFullscreenPepper::OnDeviceScaleFactorChanged() {
381 if (compositor_) 381 if (compositor_)
382 compositor_->setDeviceScaleFactor(device_scale_factor_); 382 compositor_->setDeviceScaleFactor(device_scale_factor_);
383 } 383 }
384 384
385 } // namespace content 385 } // namespace content
OLDNEW
« no previous file with comments | « content/renderer/render_widget.cc ('k') | content/renderer/render_widget_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698