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

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

Issue 23364004: Implementation of device metrics emulation in render view. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Style 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 #ifndef CONTENT_RENDERER_RENDER_WIDGET_H_ 5 #ifndef CONTENT_RENDERER_RENDER_WIDGET_H_
6 #define CONTENT_RENDERER_RENDER_WIDGET_H_ 6 #define CONTENT_RENDERER_RENDER_WIDGET_H_
7 7
8 #include <deque> 8 #include <deque>
9 #include <map> 9 #include <map>
10 10
11 #include "base/basictypes.h" 11 #include "base/basictypes.h"
12 #include "base/compiler_specific.h" 12 #include "base/compiler_specific.h"
13 #include "base/memory/ref_counted.h" 13 #include "base/memory/ref_counted.h"
14 #include "base/memory/scoped_ptr.h" 14 #include "base/memory/scoped_ptr.h"
15 #include "base/memory/weak_ptr.h" 15 #include "base/memory/weak_ptr.h"
16 #include "base/time/time.h" 16 #include "base/time/time.h"
17 #include "base/timer/timer.h" 17 #include "base/timer/timer.h"
18 #include "cc/debug/rendering_stats_instrumentation.h" 18 #include "cc/debug/rendering_stats_instrumentation.h"
19 #include "content/common/browser_rendering_stats.h" 19 #include "content/common/browser_rendering_stats.h"
20 #include "content/common/content_export.h" 20 #include "content/common/content_export.h"
21 #include "content/common/gpu/client/webgraphicscontext3d_command_buffer_impl.h" 21 #include "content/common/gpu/client/webgraphicscontext3d_command_buffer_impl.h"
22 #include "content/renderer/paint_aggregator.h" 22 #include "content/renderer/paint_aggregator.h"
23 #include "ipc/ipc_listener.h" 23 #include "ipc/ipc_listener.h"
24 #include "ipc/ipc_sender.h" 24 #include "ipc/ipc_sender.h"
25 #include "skia/ext/platform_canvas.h"
25 #include "third_party/WebKit/public/platform/WebRect.h" 26 #include "third_party/WebKit/public/platform/WebRect.h"
26 #include "third_party/WebKit/public/web/WebCompositionUnderline.h" 27 #include "third_party/WebKit/public/web/WebCompositionUnderline.h"
27 #include "third_party/WebKit/public/web/WebPopupType.h" 28 #include "third_party/WebKit/public/web/WebPopupType.h"
28 #include "third_party/WebKit/public/web/WebTextDirection.h" 29 #include "third_party/WebKit/public/web/WebTextDirection.h"
29 #include "third_party/WebKit/public/web/WebTextInputInfo.h" 30 #include "third_party/WebKit/public/web/WebTextInputInfo.h"
30 #include "third_party/WebKit/public/web/WebWidget.h" 31 #include "third_party/WebKit/public/web/WebWidget.h"
31 #include "third_party/WebKit/public/web/WebWidgetClient.h" 32 #include "third_party/WebKit/public/web/WebWidgetClient.h"
32 #include "third_party/skia/include/core/SkBitmap.h" 33 #include "third_party/skia/include/core/SkBitmap.h"
33 #include "ui/base/ime/text_input_mode.h" 34 #include "ui/base/ime/text_input_mode.h"
34 #include "ui/base/ime/text_input_type.h" 35 #include "ui/base/ime/text_input_type.h"
(...skipping 12 matching lines...) Expand all
47 namespace IPC { 48 namespace IPC {
48 class SyncMessage; 49 class SyncMessage;
49 } 50 }
50 51
51 namespace WebKit { 52 namespace WebKit {
52 class WebGestureEvent; 53 class WebGestureEvent;
53 class WebInputEvent; 54 class WebInputEvent;
54 class WebKeyboardEvent; 55 class WebKeyboardEvent;
55 class WebMouseEvent; 56 class WebMouseEvent;
56 class WebTouchEvent; 57 class WebTouchEvent;
58 class WebTouchPoint;
57 struct WebPoint; 59 struct WebPoint;
58 struct WebRenderingStatsImpl; 60 struct WebRenderingStatsImpl;
59 } 61 }
60 62
61 namespace cc { class OutputSurface; } 63 namespace cc { class OutputSurface; }
62 64
63 namespace ui { 65 namespace ui {
64 class Range; 66 class Range;
65 } 67 }
66 68
67 namespace content { 69 namespace content {
70 class DeviceEmulationEventRewriter;
68 class PepperPluginInstanceImpl; 71 class PepperPluginInstanceImpl;
69 class RenderWidgetCompositor; 72 class RenderWidgetCompositor;
70 class RenderWidgetTest; 73 class RenderWidgetTest;
74 struct ContextMenuParams;
71 struct GpuRenderingStats; 75 struct GpuRenderingStats;
72 struct WebPluginGeometry; 76 struct WebPluginGeometry;
73 77
74 // RenderWidget provides a communication bridge between a WebWidget and 78 // RenderWidget provides a communication bridge between a WebWidget and
75 // a RenderWidgetHost, the latter of which lives in a different process. 79 // a RenderWidgetHost, the latter of which lives in a different process.
76 class CONTENT_EXPORT RenderWidget 80 class CONTENT_EXPORT RenderWidget
77 : public IPC::Listener, 81 : public IPC::Listener,
78 public IPC::Sender, 82 public IPC::Sender,
79 NON_EXPORTED_BASE(virtual public WebKit::WebWidgetClient), 83 NON_EXPORTED_BASE(virtual public WebKit::WebWidgetClient),
80 NON_EXPORTED_BASE(public WebGraphicsContext3DSwapBuffersClient), 84 NON_EXPORTED_BASE(public WebGraphicsContext3DSwapBuffersClient),
(...skipping 194 matching lines...) Expand 10 before | Expand all | Expand 10 after
275 virtual void SetBackground(const SkBitmap& bitmap); 279 virtual void SetBackground(const SkBitmap& bitmap);
276 280
277 // Resizes the render widget. 281 // Resizes the render widget.
278 void Resize(const gfx::Size& new_size, 282 void Resize(const gfx::Size& new_size,
279 const gfx::Size& physical_backing_size, 283 const gfx::Size& physical_backing_size,
280 float overdraw_bottom_height, 284 float overdraw_bottom_height,
281 const gfx::Rect& resizer_rect, 285 const gfx::Rect& resizer_rect,
282 bool is_fullscreen, 286 bool is_fullscreen,
283 ResizeAck resize_ack); 287 ResizeAck resize_ack);
284 288
289 // Emulates device and widget metrics. Supplied values override everything
290 // coming from host.
291 void EmulateDevice(bool enabled,
292 const gfx::Size& device_size,
293 const gfx::Rect& widget_rect,
294 float device_scale_factor,
295 bool fit_to_view);
296 // This sets a tranformation on root compositor layer.
297 virtual void SetDeviceEmulationScale(float scale);
298
285 // RenderWidget IPC message handlers 299 // RenderWidget IPC message handlers
286 void OnHandleInputEvent(const WebKit::WebInputEvent* event, 300 void OnHandleInputEvent(const WebKit::WebInputEvent* event,
287 const ui::LatencyInfo& latency_info, 301 const ui::LatencyInfo& latency_info,
288 bool keyboard_shortcut); 302 bool keyboard_shortcut);
289 void OnCursorVisibilityChange(bool is_visible); 303 void OnCursorVisibilityChange(bool is_visible);
290 void OnMouseCaptureLost(); 304 void OnMouseCaptureLost();
291 virtual void OnSetFocus(bool enable); 305 virtual void OnSetFocus(bool enable);
292 void OnClose(); 306 void OnClose();
293 void OnCreatingNewAck(); 307 void OnCreatingNewAck();
294 virtual void OnResize(const ViewMsg_Resize_Params& params); 308 virtual void OnResize(const ViewMsg_Resize_Params& params);
295 void OnChangeResizeRect(const gfx::Rect& resizer_rect); 309 void OnChangeResizeRect(const gfx::Rect& resizer_rect);
296 virtual void OnWasHidden(); 310 virtual void OnWasHidden();
297 virtual void OnWasShown(bool needs_repainting); 311 virtual void OnWasShown(bool needs_repainting);
298 virtual void OnWasSwappedOut(); 312 virtual void OnWasSwappedOut();
313 void OnEmulateDeviceAck(bool enabled);
299 void OnUpdateRectAck(); 314 void OnUpdateRectAck();
300 void OnCreateVideoAck(int32 video_id); 315 void OnCreateVideoAck(int32 video_id);
301 void OnUpdateVideoAck(int32 video_id); 316 void OnUpdateVideoAck(int32 video_id);
302 void OnRequestMoveAck(); 317 void OnRequestMoveAck();
303 void OnSetInputMethodActive(bool is_active); 318 void OnSetInputMethodActive(bool is_active);
304 virtual void OnImeSetComposition( 319 virtual void OnImeSetComposition(
305 const string16& text, 320 const string16& text,
306 const std::vector<WebKit::WebCompositionUnderline>& underlines, 321 const std::vector<WebKit::WebCompositionUnderline>& underlines,
307 int selection_start, 322 int selection_start,
308 int selection_end); 323 int selection_end);
(...skipping 422 matching lines...) Expand 10 before | Expand all | Expand 10 after
731 746
732 uint32 next_output_surface_id_; 747 uint32 next_output_surface_id_;
733 748
734 #if defined(OS_ANDROID) 749 #if defined(OS_ANDROID)
735 // A counter for number of outstanding messages from the renderer to the 750 // A counter for number of outstanding messages from the renderer to the
736 // browser regarding IME-type events that have not been acknowledged by the 751 // browser regarding IME-type events that have not been acknowledged by the
737 // browser. If this value is not 0 IME events will be dropped. 752 // browser. If this value is not 0 IME events will be dropped.
738 int outstanding_ime_acks_; 753 int outstanding_ime_acks_;
739 #endif 754 #endif
740 755
756 // Helper class which is managing device emulation. This includes resizing,
757 // placing view on the screen at desired position, changing device scale
758 // factor, and scaling down the whole widget if required to fit into the
759 // browser window.
760 class DeviceEmulationHelper {
761 public:
762 DeviceEmulationHelper(const gfx::Size& device_size,
763 const gfx::Rect& widget_rect,
764 float device_scale_factor,
765 bool fit_to_view);
766 virtual ~DeviceEmulationHelper();
767
768 void BeginEmulation(RenderWidget* widget);
769 void ChangeEmulationParams(RenderWidget* widget,
770 DeviceEmulationHelper* params);
771 void EndEmulation(RenderWidget* widget);
772
773 // The following methods alter handlers' behavior for messages related to
774 // widget size and position.
775 void OnResizeMessage(RenderWidget* widget,
776 const ViewMsg_Resize_Params& params);
777 void OnUpdateScreenRectsMessage(RenderWidget* widget,
778 const gfx::Rect view_screen_rect,
779 const gfx::Rect window_screen_rect);
780 void OnShowContextMenu(RenderWidget* widget, ContextMenuParams* params);
781
782 WebKit::WebInputEvent* ConvertInputEventToEmulated(
783 RenderWidget* widget, const WebKit::WebInputEvent* event);
784
785 // Created popups need to be repositioned.
786 void PopupCreated(RenderWidget* widget, RenderWidget* popup);
787 WebKit::WebRect ConvertPopupScreenRectFromEmulated(
788 RenderWidget* popup, const WebKit::WebRect& rect);
789
790 private:
791 void Apply(RenderWidget* widget, float overdraw_bottom_height,
792 gfx::Rect resizer_rect, bool is_fullscreen);
793
794 // Parameters as passed by WebViewClient::EmulateDevice.
795 gfx::Size device_size_;
796 gfx::Rect widget_rect_;
797 float device_scale_factor_;
798 bool fit_to_view_;
799
800 // The computed scaled used to fit widget into browser window.
801 float scale_;
802
803 // Original values to restore back after emulation ends.
804 gfx::Size original_size_;
805 gfx::Size original_physical_backing_size_;
806 WebKit::WebScreenInfo original_screen_info_;
807 gfx::Rect original_view_screen_rect_;
808 gfx::Rect original_window_screen_rect_;
809
810 // This handles the rewriting of input events incoming to the widget and
811 // the compositor.
812 scoped_ptr<DeviceEmulationEventRewriter> input_event_rewriter_;
813
814 base::WeakPtrFactory<DeviceEmulationHelper> weak_ptr_factory_;
815 };
816
817 scoped_ptr<DeviceEmulationHelper> device_emulation_helper_;
818
819 // Popup has a weak ptr to the device emulation helper of creator.
820 base::WeakPtr<DeviceEmulationHelper> popup_device_emulation_helper_;
821
822 // While we send ViewMsg_EmulateDevice to the host, these store the requested
823 // emulation parameters.
824 scoped_ptr<DeviceEmulationHelper> pending_device_emulation_helper_;
825 bool pending_device_emulation_enabled_;
826
741 base::WeakPtrFactory<RenderWidget> weak_ptr_factory_; 827 base::WeakPtrFactory<RenderWidget> weak_ptr_factory_;
742 828
743 DISALLOW_COPY_AND_ASSIGN(RenderWidget); 829 DISALLOW_COPY_AND_ASSIGN(RenderWidget);
744 }; 830 };
745 831
746 } // namespace content 832 } // namespace content
747 833
748 #endif // CONTENT_RENDERER_RENDER_WIDGET_H_ 834 #endif // CONTENT_RENDERER_RENDER_WIDGET_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698