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

Unified 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 side-by-side diff with in-line comments
Download patch
Index: content/renderer/render_widget.h
===================================================================
--- content/renderer/render_widget.h (revision 221161)
+++ content/renderer/render_widget.h (working copy)
@@ -22,6 +22,7 @@
#include "content/renderer/paint_aggregator.h"
#include "ipc/ipc_listener.h"
#include "ipc/ipc_sender.h"
+#include "skia/ext/platform_canvas.h"
#include "third_party/WebKit/public/platform/WebRect.h"
#include "third_party/WebKit/public/web/WebCompositionUnderline.h"
#include "third_party/WebKit/public/web/WebPopupType.h"
@@ -54,6 +55,7 @@
class WebKeyboardEvent;
class WebMouseEvent;
class WebTouchEvent;
+class WebTouchPoint;
struct WebPoint;
struct WebRenderingStatsImpl;
}
@@ -65,9 +67,11 @@
}
namespace content {
+class DeviceEmulationEventRewriter;
class PepperPluginInstanceImpl;
class RenderWidgetCompositor;
class RenderWidgetTest;
+struct ContextMenuParams;
struct GpuRenderingStats;
struct WebPluginGeometry;
@@ -282,6 +286,16 @@
bool is_fullscreen,
ResizeAck resize_ack);
+ // Emulates device and widget metrics. Supplied values override everything
+ // coming from host.
+ void EmulateDevice(bool enabled,
+ const gfx::Size& device_size,
+ const gfx::Rect& widget_rect,
+ float device_scale_factor,
+ bool fit_to_view);
+ // This sets a tranformation on root compositor layer.
+ virtual void SetDeviceEmulationScale(float scale);
+
// RenderWidget IPC message handlers
void OnHandleInputEvent(const WebKit::WebInputEvent* event,
const ui::LatencyInfo& latency_info,
@@ -296,6 +310,7 @@
virtual void OnWasHidden();
virtual void OnWasShown(bool needs_repainting);
virtual void OnWasSwappedOut();
+ void OnEmulateDeviceAck(bool enabled);
void OnUpdateRectAck();
void OnCreateVideoAck(int32 video_id);
void OnUpdateVideoAck(int32 video_id);
@@ -738,6 +753,77 @@
int outstanding_ime_acks_;
#endif
+ // Helper class which is managing device emulation. This includes resizing,
+ // placing view on the screen at desired position, changing device scale
+ // factor, and scaling down the whole widget if required to fit into the
+ // browser window.
+ class DeviceEmulationHelper {
+ public:
+ DeviceEmulationHelper(const gfx::Size& device_size,
+ const gfx::Rect& widget_rect,
+ float device_scale_factor,
+ bool fit_to_view);
+ virtual ~DeviceEmulationHelper();
+
+ void BeginEmulation(RenderWidget* widget);
+ void ChangeEmulationParams(RenderWidget* widget,
+ DeviceEmulationHelper* params);
+ void EndEmulation(RenderWidget* widget);
+
+ // The following methods alter handlers' behavior for messages related to
+ // widget size and position.
+ void OnResizeMessage(RenderWidget* widget,
+ const ViewMsg_Resize_Params& params);
+ void OnUpdateScreenRectsMessage(RenderWidget* widget,
+ const gfx::Rect view_screen_rect,
+ const gfx::Rect window_screen_rect);
+ void OnShowContextMenu(RenderWidget* widget, ContextMenuParams* params);
+
+ WebKit::WebInputEvent* ConvertInputEventToEmulated(
+ RenderWidget* widget, const WebKit::WebInputEvent* event);
+
+ // Created popups need to be repositioned.
+ void PopupCreated(RenderWidget* widget, RenderWidget* popup);
+ WebKit::WebRect ConvertPopupScreenRectFromEmulated(
+ RenderWidget* popup, const WebKit::WebRect& rect);
+
+ private:
+ void Apply(RenderWidget* widget, float overdraw_bottom_height,
+ gfx::Rect resizer_rect, bool is_fullscreen);
+
+ // Parameters as passed by WebViewClient::EmulateDevice.
+ gfx::Size device_size_;
+ gfx::Rect widget_rect_;
+ float device_scale_factor_;
+ bool fit_to_view_;
+
+ // The computed scaled used to fit widget into browser window.
+ float scale_;
+
+ // Original values to restore back after emulation ends.
+ gfx::Size original_size_;
+ gfx::Size original_physical_backing_size_;
+ WebKit::WebScreenInfo original_screen_info_;
+ gfx::Rect original_view_screen_rect_;
+ gfx::Rect original_window_screen_rect_;
+
+ // This handles the rewriting of input events incoming to the widget and
+ // the compositor.
+ scoped_ptr<DeviceEmulationEventRewriter> input_event_rewriter_;
+
+ base::WeakPtrFactory<DeviceEmulationHelper> weak_ptr_factory_;
+ };
+
+ scoped_ptr<DeviceEmulationHelper> device_emulation_helper_;
+
+ // Popup has a weak ptr to the device emulation helper of creator.
+ base::WeakPtr<DeviceEmulationHelper> popup_device_emulation_helper_;
+
+ // While we send ViewMsg_EmulateDevice to the host, these store the requested
+ // emulation parameters.
+ scoped_ptr<DeviceEmulationHelper> pending_device_emulation_helper_;
+ bool pending_device_emulation_enabled_;
+
base::WeakPtrFactory<RenderWidget> weak_ptr_factory_;
DISALLOW_COPY_AND_ASSIGN(RenderWidget);

Powered by Google App Engine
This is Rietveld 408576698