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

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

Powered by Google App Engine
This is Rietveld 408576698