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

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

Issue 23364004: Implementation of device metrics emulation in render view. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Moved helper class to cc Created 7 years, 3 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 | Annotate | Revision Log
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.h" 5 #include "content/renderer/render_widget.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/command_line.h" 8 #include "base/command_line.h"
9 #include "base/debug/trace_event.h" 9 #include "base/debug/trace_event.h"
10 #include "base/logging.h" 10 #include "base/logging.h"
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
46 #include "third_party/WebKit/public/platform/WebString.h" 46 #include "third_party/WebKit/public/platform/WebString.h"
47 #include "third_party/WebKit/public/web/WebCursorInfo.h" 47 #include "third_party/WebKit/public/web/WebCursorInfo.h"
48 #include "third_party/WebKit/public/web/WebHelperPlugin.h" 48 #include "third_party/WebKit/public/web/WebHelperPlugin.h"
49 #include "third_party/WebKit/public/web/WebPagePopup.h" 49 #include "third_party/WebKit/public/web/WebPagePopup.h"
50 #include "third_party/WebKit/public/web/WebPopupMenu.h" 50 #include "third_party/WebKit/public/web/WebPopupMenu.h"
51 #include "third_party/WebKit/public/web/WebPopupMenuInfo.h" 51 #include "third_party/WebKit/public/web/WebPopupMenuInfo.h"
52 #include "third_party/WebKit/public/web/WebRange.h" 52 #include "third_party/WebKit/public/web/WebRange.h"
53 #include "third_party/WebKit/public/web/WebScreenInfo.h" 53 #include "third_party/WebKit/public/web/WebScreenInfo.h"
54 #include "third_party/skia/include/core/SkShader.h" 54 #include "third_party/skia/include/core/SkShader.h"
55 #include "ui/base/ui_base_switches.h" 55 #include "ui/base/ui_base_switches.h"
56 #include "ui/gfx/point.h" 56 #include "ui/gfx/point_conversions.h"
57 #include "ui/gfx/rect_conversions.h" 57 #include "ui/gfx/rect_conversions.h"
58 #include "ui/gfx/size_conversions.h" 58 #include "ui/gfx/size_conversions.h"
59 #include "ui/gfx/skia_util.h" 59 #include "ui/gfx/skia_util.h"
60 #include "ui/gl/gl_switches.h" 60 #include "ui/gl/gl_switches.h"
61 #include "ui/surface/transport_dib.h" 61 #include "ui/surface/transport_dib.h"
62 #include "webkit/renderer/compositor_bindings/web_rendering_stats_impl.h" 62 #include "webkit/renderer/compositor_bindings/web_rendering_stats_impl.h"
63 63
64 #if defined(OS_ANDROID) 64 #if defined(OS_ANDROID)
65 #include "content/renderer/android/synchronous_compositor_factory.h" 65 #include "content/renderer/android/synchronous_compositor_factory.h"
66 #endif 66 #endif
67 67
68 #if defined(OS_POSIX) 68 #if defined(OS_POSIX)
69 #include "ipc/ipc_channel_posix.h" 69 #include "ipc/ipc_channel_posix.h"
70 #include "third_party/skia/include/core/SkMallocPixelRef.h" 70 #include "third_party/skia/include/core/SkMallocPixelRef.h"
71 #include "third_party/skia/include/core/SkPixelRef.h" 71 #include "third_party/skia/include/core/SkPixelRef.h"
72 #endif // defined(OS_POSIX) 72 #endif // defined(OS_POSIX)
73 73
74 #include "third_party/WebKit/public/web/WebWidget.h" 74 #include "third_party/WebKit/public/web/WebWidget.h"
75 75
76 using WebKit::WebCompositionUnderline; 76 using WebKit::WebCompositionUnderline;
77 using WebKit::WebCursorInfo; 77 using WebKit::WebCursorInfo;
78 using WebKit::WebGestureEvent; 78 using WebKit::WebGestureEvent;
79 using WebKit::WebInputEvent; 79 using WebKit::WebInputEvent;
80 using WebKit::WebKeyboardEvent; 80 using WebKit::WebKeyboardEvent;
81 using WebKit::WebMouseEvent; 81 using WebKit::WebMouseEvent;
82 using WebKit::WebMouseWheelEvent;
82 using WebKit::WebNavigationPolicy; 83 using WebKit::WebNavigationPolicy;
83 using WebKit::WebPagePopup; 84 using WebKit::WebPagePopup;
84 using WebKit::WebPoint; 85 using WebKit::WebPoint;
85 using WebKit::WebPopupMenu; 86 using WebKit::WebPopupMenu;
86 using WebKit::WebPopupMenuInfo; 87 using WebKit::WebPopupMenuInfo;
87 using WebKit::WebPopupType; 88 using WebKit::WebPopupType;
88 using WebKit::WebRange; 89 using WebKit::WebRange;
89 using WebKit::WebRect; 90 using WebKit::WebRect;
90 using WebKit::WebScreenInfo; 91 using WebKit::WebScreenInfo;
91 using WebKit::WebSize; 92 using WebKit::WebSize;
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
179 TextInputModeMap::iterator it = singleton->Map().find(input_mode.utf8()); 180 TextInputModeMap::iterator it = singleton->Map().find(input_mode.utf8());
180 if (it == singleton->Map().end()) 181 if (it == singleton->Map().end())
181 return ui::TEXT_INPUT_MODE_DEFAULT; 182 return ui::TEXT_INPUT_MODE_DEFAULT;
182 return it->second; 183 return it->second;
183 } 184 }
184 185
185 } // namespace 186 } // namespace
186 187
187 namespace content { 188 namespace content {
188 189
190 // RenderWidget::DeviceEmulator ------------------------------------------------
191
192 class RenderWidget::DeviceEmulator {
aelias_OOO_until_Jul13 2013/09/20 07:10:14 I suggest renaming this to ScreenMetricsEmulator.
dgozman 2013/09/27 19:02:03 Done. I've left "device" in Blink API though, as "
193 public:
194 DeviceEmulator(const gfx::Size& device_size,
195 const gfx::Rect& widget_rect,
pfeldman 2013/09/19 17:27:16 Poor indent.
dgozman 2013/09/27 19:02:03 Done.
196 float device_scale_factor,
197 bool fit_to_view);
198 virtual ~DeviceEmulator();
199
200 base::WeakPtr<DeviceEmulator> AsWeakPtr();
201
202 void BeginEmulation(RenderWidget* widget);
aelias_OOO_until_Jul13 2013/09/20 07:10:14 If it's always the same RenderWidget, can we just
dgozman 2013/09/27 19:02:03 Done.
203 void ChangeEmulationParams(RenderWidget* widget,
204 DeviceEmulator* params);
205 void EndEmulation(RenderWidget* widget);
206
207 // The following methods alter handlers' behavior for messages related to
208 // widget size and position.
209 void OnResizeMessage(RenderWidget* widget,
210 const ViewMsg_Resize_Params& params);
211 void OnUpdateScreenRectsMessage(RenderWidget* widget,
212 const gfx::Rect view_screen_rect,
213 const gfx::Rect window_screen_rect);
214 void OnShowContextMenu(RenderWidget* widget, ContextMenuParams* params);
215
216 WebKit::WebInputEvent* ConvertInputEventToEmulated(
217 RenderWidget* widget, const WebKit::WebInputEvent* event);
218
219 // Created popups need to be repositioned.
220 WebKit::WebRect ConvertPopupScreenRectFromEmulated(
221 RenderWidget* popup, const WebKit::WebRect& rect);
222
223 private:
224 void Apply(RenderWidget* widget, float overdraw_bottom_height,
225 gfx::Rect resizer_rect, bool is_fullscreen);
226 void ConvertMouseEventToEmulated(WebKit::WebMouseEvent* event);
227 void ConvertTouchPointToEmulated(WebKit::WebTouchPoint* point);
228
229 // Parameters as passed by WebViewClient::EmulateDevice.
230 gfx::Size device_size_;
231 gfx::Rect widget_rect_;
232 float device_scale_factor_;
233 bool fit_to_view_;
234
235 // The computed scaled used to fit widget into browser window.
236 float scale_;
237
238 // Original values to restore back after emulation ends.
239 gfx::Size original_size_;
240 gfx::Size original_physical_backing_size_;
241 WebKit::WebScreenInfo original_screen_info_;
242 gfx::Rect original_view_screen_rect_;
243 gfx::Rect original_window_screen_rect_;
244
245 base::WeakPtrFactory<DeviceEmulator> weak_ptr_factory_;
246 };
247
248 RenderWidget::DeviceEmulator::DeviceEmulator(
249 const gfx::Size& device_size,
250 const gfx::Rect& widget_rect,
251 float device_scale_factor,
252 bool fit_to_view)
pfeldman 2013/09/19 17:27:16 scale_ is not initialized.
dgozman 2013/09/27 19:02:03 Done.
253 : device_size_(device_size),
254 widget_rect_(widget_rect),
255 device_scale_factor_(device_scale_factor),
256 fit_to_view_(fit_to_view),
257 weak_ptr_factory_(this) {
258 }
259
260 RenderWidget::DeviceEmulator::~DeviceEmulator() {
261 }
262
263 void RenderWidget::DeviceEmulator::BeginEmulation(RenderWidget* widget) {
264 original_size_ = widget->size_;
265 original_physical_backing_size_ = widget->physical_backing_size_;
266 original_screen_info_ = widget->screen_info_;
267 original_view_screen_rect_ = widget->view_screen_rect_;
268 original_window_screen_rect_ = widget->window_screen_rect_;
269 Apply(widget, widget->overdraw_bottom_height_,
270 widget->resizer_rect_, widget->is_fullscreen_);
271 }
272
273 void RenderWidget::DeviceEmulator::ChangeEmulationParams(
274 RenderWidget* widget, DeviceEmulator* params) {
275 device_size_ = params->device_size_;
276 widget_rect_ = params->widget_rect_;
277 device_scale_factor_ = params->device_scale_factor_;
278 fit_to_view_ = params->fit_to_view_;
279 Apply(widget, widget->overdraw_bottom_height_,
280 widget->resizer_rect_, widget->is_fullscreen_);
281 }
282
283 void RenderWidget::DeviceEmulator::EndEmulation(RenderWidget* widget) {
284 widget->screen_info_ = original_screen_info_;
285
286 widget->Send(new ViewHostMsg_SetExpectedSize(widget->routing_id(),
287 gfx::Size()));
288
289 widget->SetDeviceScaleFactor(original_screen_info_.deviceScaleFactor);
290 widget->SetDeviceEmulationParameters(false /* enabled */, 1.f, 1.f);
291 widget->view_screen_rect_ = original_view_screen_rect_;
292 widget->window_screen_rect_ = original_window_screen_rect_;
293 widget->Resize(original_size_, original_physical_backing_size_,
294 widget->overdraw_bottom_height_, widget->resizer_rect_,
295 widget->is_fullscreen_, NO_RESIZE_ACK);
296 }
297
298 void RenderWidget::DeviceEmulator::Apply(RenderWidget* widget,
299 float overdraw_bottom_height, gfx::Rect resizer_rect, bool is_fullscreen) {
300 if (fit_to_view_) {
301 float width_ratio = !original_size_.width() ? 1.f :
302 static_cast<float>(widget_rect_.width()) / original_size_.width();
303 float height_ratio = !original_size_.height() ? 1.f :
304 static_cast<float>(widget_rect_.height()) / original_size_.height();
305 float ratio = std::max(1.0f, std::max(width_ratio, height_ratio));
306 scale_ = 1.f / ratio;
307 } else {
308 scale_ = 1.f;
309 }
310
311 widget->screen_info_.rect = gfx::Rect(device_size_);
312 widget->screen_info_.availableRect = gfx::Rect(device_size_);
313 widget->screen_info_.deviceScaleFactor = device_scale_factor_;
314
315 // Pass two emulation parameters to the blink side:
316 // - we keep the real device scale factor in compositor to produce sharp image
317 // even when emulating different scale factor;
318 // - in order to fit into view, WebView applies scaling transform to the
319 // root layer.
320 widget->SetDeviceEmulationParameters(true /* enabled */,
321 original_screen_info_.deviceScaleFactor, scale_);
322
323 widget->SetDeviceScaleFactor(device_scale_factor_);
324 widget->view_screen_rect_ = widget_rect_;
325 widget->window_screen_rect_ = widget->screen_info_.availableRect;
326
327 // Make host accept an image of different size.
328 widget->Send(new ViewHostMsg_SetExpectedSize(widget->routing_id(),
329 gfx::ToCeiledSize(gfx::ScaleSize(widget_rect_.size(), scale_))));
330
331 gfx::Size physical_backing_size = gfx::ToCeiledSize(gfx::ScaleSize(
332 widget_rect_.size(), original_screen_info_.deviceScaleFactor * scale_));
333 widget->Resize(widget_rect_.size(), physical_backing_size,
334 overdraw_bottom_height, resizer_rect, is_fullscreen, NO_RESIZE_ACK);
335 }
336
337 void RenderWidget::DeviceEmulator::OnResizeMessage(
338 RenderWidget* widget, const ViewMsg_Resize_Params& params) {
339 bool need_ack = params.new_size != original_size_;
340 original_size_ = params.new_size;
341 original_physical_backing_size_ = params.physical_backing_size;
342 original_screen_info_ = params.screen_info;
343 Apply(widget, params.overdraw_bottom_height, params.resizer_rect,
344 params.is_fullscreen);
345
346 if (need_ack) {
347 widget->set_next_paint_is_resize_ack();
348 if (widget->is_accelerated_compositing_active_ && widget->compositor_)
349 widget->compositor_->SetNeedsRedrawRect(gfx::Rect(widget->size_));
350 else
351 widget->didInvalidateRect(gfx::Rect(widget->size_));
aelias_OOO_until_Jul13 2013/09/20 07:10:14 I thought accelerated compositing was mandatory fo
dgozman 2013/09/27 19:02:03 You are right. Removed.
352 }
353 }
354
355 void RenderWidget::DeviceEmulator::OnUpdateScreenRectsMessage(
356 RenderWidget* widget,
357 const gfx::Rect view_screen_rect,
358 const gfx::Rect window_screen_rect) {
359 original_view_screen_rect_ = view_screen_rect;
360 original_window_screen_rect_ = window_screen_rect;
361 widget->Send(new ViewHostMsg_UpdateScreenRects_ACK(widget->routing_id()));
362 }
363
364 void RenderWidget::DeviceEmulator::OnShowContextMenu(
365 RenderWidget* widget, ContextMenuParams* params) {
366 params->x *= scale_;
367 params->y *= scale_;
368 }
369
370 WebInputEvent* RenderWidget::DeviceEmulator::ConvertInputEventToEmulated(
aelias_OOO_until_Jul13 2013/09/20 07:10:14 It's the job of Source/web/WebInputEventConversion
dgozman 2013/09/27 19:02:03 Done. Please see https://codereview.chromium.org/2
371 RenderWidget* widget, const WebInputEvent* event) {
372 if (!event)
373 return NULL;
374
375 if (WebInputEvent::isKeyboardEventType(event->type)) {
376 const WebKeyboardEvent& keyboard_event =
377 *static_cast<const WebKeyboardEvent*>(event);
378 WebKeyboardEvent* result = new WebKeyboardEvent(keyboard_event);
pfeldman 2013/09/19 17:27:16 return new ...
dgozman 2013/09/27 19:02:03 Done.
379 return result;
380 }
381
382 if (WebInputEvent::isMouseEventType(event->type)) {
383 const WebMouseEvent& mouse_event =
384 *static_cast<const WebMouseEvent*>(event);
385 WebMouseEvent* result = new WebMouseEvent(mouse_event);
386 ConvertMouseEventToEmulated(result);
387 return result;
388 }
389
390 if (WebInputEvent::MouseWheel == event->type) {
391 const WebMouseWheelEvent& mouse_wheel_event =
392 *static_cast<const WebMouseWheelEvent*>(event);
393 WebMouseWheelEvent* result = new WebMouseWheelEvent(mouse_wheel_event);
394 ConvertMouseEventToEmulated(result);
395 return result;
396 }
397
398 if (WebInputEvent::isGestureEventType(event->type)) {
399 const WebGestureEvent& gesture_event =
400 *static_cast<const WebGestureEvent*>(event);
401 WebGestureEvent* result = new WebGestureEvent(gesture_event);
402 result->x = 1.f / scale_ * result->x;
403 result->y = 1.f / scale_ * result->y;
404 result->globalX = widget_rect_.x() + result->x;
405 result->globalY = widget_rect_.y() + result->y;
406 return result;
407 }
408
409 if (WebInputEvent::isTouchEventType(event->type)) {
410 const WebTouchEvent& touch_event =
411 *static_cast<const WebTouchEvent*>(event);
412 WebTouchEvent* result = new WebTouchEvent(touch_event);
413 for (size_t index = 0; index < result->touchesLength; ++index) {
pfeldman 2013/09/19 17:27:16 One line blocks don't need {}
dgozman 2013/09/27 19:02:03 Done.
414 ConvertTouchPointToEmulated(&result->touches[index]);
415 }
416 for (size_t index = 0; index < result->changedTouchesLength; ++index) {
417 ConvertTouchPointToEmulated(&result->changedTouches[index]);
418 }
419 for (size_t index = 0; index < result->targetTouchesLength; ++index) {
420 ConvertTouchPointToEmulated(&result->targetTouches[index]);
421 }
422 return result;
423 }
424
425 return NULL;
426 }
427
428 void RenderWidget::DeviceEmulator::ConvertMouseEventToEmulated(
429 WebKit::WebMouseEvent* event) {
430 event->x = 1.f / scale_ * event->x;
431 event->y = 1.f / scale_ * event->y;
432 event->movementX = 1.f / scale_ * event->movementX;
433 event->movementY = 1.f / scale_ * event->movementY;
434 event->windowX = widget_rect_.x() + event->x;
435 event->windowY = widget_rect_.y() + event->y;
436 event->globalX = event->windowX;
437 event->globalY = event->windowY;
438 }
439
440 void RenderWidget::DeviceEmulator::ConvertTouchPointToEmulated(
441 WebKit::WebTouchPoint* point) {
442 point->position.x = 1.f / scale_ * point->position.x;
443 point->position.y = 1.f / scale_ * point->position.y;
444 point->screenPosition.x = widget_rect_.x() + point->position.x;
445 point->screenPosition.y = widget_rect_.y() + point->position.y;
446 }
447
448 base::WeakPtr<RenderWidget::DeviceEmulator> RenderWidget::DeviceEmulator::AsWeak Ptr() {
pfeldman 2013/09/19 17:27:16 80 chars limit please. base::WeakPtr<RenderWidget
dgozman 2013/09/27 19:02:03 Done.
449 return weak_ptr_factory_.GetWeakPtr();
450 }
451
452 WebKit::WebRect RenderWidget::DeviceEmulator::ConvertPopupScreenRectFromEmulated (
pfeldman 2013/09/19 17:27:16 ditto
dgozman 2013/09/27 19:02:03 Done.
453 RenderWidget* popup, const WebKit::WebRect& rect) {
454 WebKit::WebRect result = rect;
455 result.x = original_view_screen_rect_.x() +
456 (result.x - widget_rect_.x()) * scale_;
457 result.y = original_view_screen_rect_.y() +
458 (result.y - widget_rect_.y()) * scale_;
459 return result;
460 }
461
462 // RenderWidget ----------------------------------------------------------------
463
189 RenderWidget::RenderWidget(WebKit::WebPopupType popup_type, 464 RenderWidget::RenderWidget(WebKit::WebPopupType popup_type,
190 const WebKit::WebScreenInfo& screen_info, 465 const WebKit::WebScreenInfo& screen_info,
191 bool swapped_out, 466 bool swapped_out,
192 bool hidden) 467 bool hidden)
193 : routing_id_(MSG_ROUTING_NONE), 468 : routing_id_(MSG_ROUTING_NONE),
194 surface_id_(0), 469 surface_id_(0),
195 webwidget_(NULL), 470 webwidget_(NULL),
196 opener_id_(MSG_ROUTING_NONE), 471 opener_id_(MSG_ROUTING_NONE),
197 init_complete_(false), 472 init_complete_(false),
198 current_paint_buf_(NULL), 473 current_paint_buf_(NULL),
(...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after
361 } 636 }
362 637
363 bool RenderWidget::UsingSynchronousRendererCompositor() const { 638 bool RenderWidget::UsingSynchronousRendererCompositor() const {
364 #if defined(OS_ANDROID) 639 #if defined(OS_ANDROID)
365 return SynchronousCompositorFactory::GetInstance() != NULL; 640 return SynchronousCompositorFactory::GetInstance() != NULL;
366 #else 641 #else
367 return false; 642 return false;
368 #endif 643 #endif
369 } 644 }
370 645
646 void RenderWidget::EmulateDevice(
647 bool enabled,
648 const gfx::Size& device_size,
649 const gfx::Rect& widget_rect,
650 float device_scale_factor,
651 bool fit_to_view) {
652 if (enabled) {
653 DeviceEmulator* helper = new DeviceEmulator(device_size, widget_rect,
654 device_scale_factor, fit_to_view);
655
656 if (!device_emulator_) {
657 device_emulator_.reset(helper);
658 device_emulator_->BeginEmulation(this);
pfeldman 2013/09/19 17:27:16 I prefer StartEmulation / UpdateEmulation / StopEm
dgozman 2013/09/27 19:02:03 BeginEmulation/EndEmulation are removed. I'd keep
659 } else {
660 device_emulator_->ChangeEmulationParams(this, helper);
aelias_OOO_until_Jul13 2013/09/20 07:10:14 You're leaking the "helper" object" in this codepa
dgozman 2013/09/27 19:02:03 Done.
661 }
662 } else {
663 if (device_emulator_)
664 device_emulator_->EndEmulation(this);
aelias_OOO_until_Jul13 2013/09/20 07:10:14 Doesn't look like keeping BeginEmulation/EndEmulat
dgozman 2013/09/27 19:02:03 Done.
665 device_emulator_.reset();
666 }
667 }
668
669 void RenderWidget::SetDeviceEmulationParameters(
670 bool enabled, float device_scale_factor, float root_layer_scale) {
671 // This is only supported in RenderView.
672 NOTREACHED();
673 }
674
675 void RenderWidget::OnShowHostContextMenu(ContextMenuParams* params) {
676 if (device_emulator_)
677 device_emulator_->OnShowContextMenu(this, params);
678 }
679
680 void RenderWidget::set_popup_device_emulator(
681 RenderWidget::DeviceEmulator *emulator) {
682 popup_device_emulator_ = emulator->AsWeakPtr();
683 }
684
371 bool RenderWidget::OnMessageReceived(const IPC::Message& message) { 685 bool RenderWidget::OnMessageReceived(const IPC::Message& message) {
372 bool handled = true; 686 bool handled = true;
373 IPC_BEGIN_MESSAGE_MAP(RenderWidget, message) 687 IPC_BEGIN_MESSAGE_MAP(RenderWidget, message)
374 IPC_MESSAGE_HANDLER(InputMsg_HandleInputEvent, OnHandleInputEvent) 688 IPC_MESSAGE_HANDLER(InputMsg_HandleInputEvent, OnHandleInputEvent)
375 IPC_MESSAGE_HANDLER(InputMsg_CursorVisibilityChange, 689 IPC_MESSAGE_HANDLER(InputMsg_CursorVisibilityChange,
376 OnCursorVisibilityChange) 690 OnCursorVisibilityChange)
377 IPC_MESSAGE_HANDLER(InputMsg_MouseCaptureLost, OnMouseCaptureLost) 691 IPC_MESSAGE_HANDLER(InputMsg_MouseCaptureLost, OnMouseCaptureLost)
378 IPC_MESSAGE_HANDLER(InputMsg_SetFocus, OnSetFocus) 692 IPC_MESSAGE_HANDLER(InputMsg_SetFocus, OnSetFocus)
379 IPC_MESSAGE_HANDLER(ViewMsg_Close, OnClose) 693 IPC_MESSAGE_HANDLER(ViewMsg_Close, OnClose)
380 IPC_MESSAGE_HANDLER(ViewMsg_CreatingNew_ACK, OnCreatingNewAck) 694 IPC_MESSAGE_HANDLER(ViewMsg_CreatingNew_ACK, OnCreatingNewAck)
(...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after
524 838
525 // Got a response from the browser after the renderer decided to create a new 839 // Got a response from the browser after the renderer decided to create a new
526 // view. 840 // view.
527 void RenderWidget::OnCreatingNewAck() { 841 void RenderWidget::OnCreatingNewAck() {
528 DCHECK(routing_id_ != MSG_ROUTING_NONE); 842 DCHECK(routing_id_ != MSG_ROUTING_NONE);
529 843
530 CompleteInit(); 844 CompleteInit();
531 } 845 }
532 846
533 void RenderWidget::OnResize(const ViewMsg_Resize_Params& params) { 847 void RenderWidget::OnResize(const ViewMsg_Resize_Params& params) {
848 if (device_emulator_) {
849 device_emulator_->OnResizeMessage(this, params);
850 return;
851 }
852
534 screen_info_ = params.screen_info; 853 screen_info_ = params.screen_info;
535 SetDeviceScaleFactor(screen_info_.deviceScaleFactor); 854 SetDeviceScaleFactor(screen_info_.deviceScaleFactor);
536 Resize(params.new_size, params.physical_backing_size, 855 Resize(params.new_size, params.physical_backing_size,
537 params.overdraw_bottom_height, params.resizer_rect, 856 params.overdraw_bottom_height, params.resizer_rect,
538 params.is_fullscreen, SEND_RESIZE_ACK); 857 params.is_fullscreen, SEND_RESIZE_ACK);
539 } 858 }
540 859
541 void RenderWidget::OnChangeResizeRect(const gfx::Rect& resizer_rect) { 860 void RenderWidget::OnChangeResizeRect(const gfx::Rect& resizer_rect) {
542 if (resizer_rect_ != resizer_rect) { 861 if (resizer_rect_ != resizer_rect) {
543 gfx::Rect view_rect(size_); 862 gfx::Rect view_rect(size_);
(...skipping 262 matching lines...) Expand 10 before | Expand all | Expand 10 after
806 } 1125 }
807 1126
808 // Continue painting if necessary... 1127 // Continue painting if necessary...
809 DoDeferredUpdateAndSendInputAck(); 1128 DoDeferredUpdateAndSendInputAck();
810 } 1129 }
811 1130
812 void RenderWidget::OnHandleInputEvent(const WebKit::WebInputEvent* input_event, 1131 void RenderWidget::OnHandleInputEvent(const WebKit::WebInputEvent* input_event,
813 const ui::LatencyInfo& latency_info, 1132 const ui::LatencyInfo& latency_info,
814 bool is_keyboard_shortcut) { 1133 bool is_keyboard_shortcut) {
815 handling_input_event_ = true; 1134 handling_input_event_ = true;
1135
1136 scoped_ptr<const WebKit::WebInputEvent> owner;
1137 if (device_emulator_) {
1138 input_event = device_emulator_->ConvertInputEventToEmulated(
1139 this, input_event);
1140 if (input_event)
1141 owner.reset(input_event);
pfeldman 2013/09/19 17:27:16 You can reset unconditionally.
dgozman 2013/09/27 19:02:03 Removed.
1142 }
1143
816 if (!input_event) { 1144 if (!input_event) {
817 handling_input_event_ = false; 1145 handling_input_event_ = false;
818 return; 1146 return;
819 } 1147 }
820 1148
821 const char* const event_name = GetEventName(input_event->type); 1149 const char* const event_name = GetEventName(input_event->type);
822 TRACE_EVENT1("renderer", "RenderWidget::OnHandleInputEvent", 1150 TRACE_EVENT1("renderer", "RenderWidget::OnHandleInputEvent",
823 "event", event_name); 1151 "event", event_name);
824 1152
825 if (compositor_) 1153 if (compositor_)
(...skipping 943 matching lines...) Expand 10 before | Expand all | Expand 10 after
1769 return pending_window_rect_; 2097 return pending_window_rect_;
1770 2098
1771 return view_screen_rect_; 2099 return view_screen_rect_;
1772 } 2100 }
1773 2101
1774 void RenderWidget::setToolTipText(const WebKit::WebString& text, 2102 void RenderWidget::setToolTipText(const WebKit::WebString& text,
1775 WebTextDirection hint) { 2103 WebTextDirection hint) {
1776 Send(new ViewHostMsg_SetTooltipText(routing_id_, text, hint)); 2104 Send(new ViewHostMsg_SetTooltipText(routing_id_, text, hint));
1777 } 2105 }
1778 2106
1779 void RenderWidget::setWindowRect(const WebRect& pos) { 2107 void RenderWidget::setWindowRect(const WebRect& rect) {
2108 WebRect pos = rect;
2109 if (popup_device_emulator_) {
2110 pos = popup_device_emulator_->ConvertPopupScreenRectFromEmulated(
2111 this, rect);
2112 }
2113
1780 if (did_show_) { 2114 if (did_show_) {
1781 if (!RenderThreadImpl::current()->layout_test_mode()) { 2115 if (!RenderThreadImpl::current()->layout_test_mode()) {
1782 Send(new ViewHostMsg_RequestMove(routing_id_, pos)); 2116 Send(new ViewHostMsg_RequestMove(routing_id_, pos));
1783 SetPendingWindowRect(pos); 2117 SetPendingWindowRect(pos);
1784 } else { 2118 } else {
1785 WebSize new_size(pos.width, pos.height); 2119 WebSize new_size(pos.width, pos.height);
1786 Resize(new_size, new_size, overdraw_bottom_height_, 2120 Resize(new_size, new_size, overdraw_bottom_height_,
1787 WebRect(), is_fullscreen_, NO_RESIZE_ACK); 2121 WebRect(), is_fullscreen_, NO_RESIZE_ACK);
1788 view_screen_rect_ = pos; 2122 view_screen_rect_ = pos;
1789 window_screen_rect_ = pos; 2123 window_screen_rect_ = pos;
(...skipping 220 matching lines...) Expand 10 before | Expand all | Expand 10 after
2010 } 2344 }
2011 2345
2012 void RenderWidget::OnSetTextDirection(WebTextDirection direction) { 2346 void RenderWidget::OnSetTextDirection(WebTextDirection direction) {
2013 if (!webwidget_) 2347 if (!webwidget_)
2014 return; 2348 return;
2015 webwidget_->setTextDirection(direction); 2349 webwidget_->setTextDirection(direction);
2016 } 2350 }
2017 2351
2018 void RenderWidget::OnUpdateScreenRects(const gfx::Rect& view_screen_rect, 2352 void RenderWidget::OnUpdateScreenRects(const gfx::Rect& view_screen_rect,
2019 const gfx::Rect& window_screen_rect) { 2353 const gfx::Rect& window_screen_rect) {
2354 if (device_emulator_) {
2355 device_emulator_->OnUpdateScreenRectsMessage(
2356 this, view_screen_rect, window_screen_rect);
2357 return;
2358 }
2020 view_screen_rect_ = view_screen_rect; 2359 view_screen_rect_ = view_screen_rect;
2021 window_screen_rect_ = window_screen_rect; 2360 window_screen_rect_ = window_screen_rect;
2022 Send(new ViewHostMsg_UpdateScreenRects_ACK(routing_id())); 2361 Send(new ViewHostMsg_UpdateScreenRects_ACK(routing_id()));
2023 } 2362 }
2024 2363
2025 #if defined(OS_ANDROID) 2364 #if defined(OS_ANDROID)
2026 void RenderWidget::OnImeBatchStateChanged(bool is_begin) { 2365 void RenderWidget::OnImeBatchStateChanged(bool is_begin) {
2027 Send(new ViewHostMsg_ImeBatchStateChanged_ACK(routing_id(), is_begin)); 2366 Send(new ViewHostMsg_ImeBatchStateChanged_ACK(routing_id(), is_begin));
2028 } 2367 }
2029 2368
(...skipping 495 matching lines...) Expand 10 before | Expand all | Expand 10 after
2525 2864
2526 if (!context->InitializeWithDefaultBufferSizes( 2865 if (!context->InitializeWithDefaultBufferSizes(
2527 attributes, 2866 attributes,
2528 false /* bind generates resources */, 2867 false /* bind generates resources */,
2529 CAUSE_FOR_GPU_LAUNCH_WEBGRAPHICSCONTEXT3DCOMMANDBUFFERIMPL_INITIALIZE) ) 2868 CAUSE_FOR_GPU_LAUNCH_WEBGRAPHICSCONTEXT3DCOMMANDBUFFERIMPL_INITIALIZE) )
2530 return scoped_ptr<WebGraphicsContext3DCommandBufferImpl>(); 2869 return scoped_ptr<WebGraphicsContext3DCommandBufferImpl>();
2531 return context.Pass(); 2870 return context.Pass();
2532 } 2871 }
2533 2872
2534 } // namespace content 2873 } // namespace content
OLDNEW
« content/renderer/render_view_impl.cc ('K') | « content/renderer/render_widget.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698