summaryrefslogtreecommitdiffstats
path: root/content/renderer/devtools/render_widget_screen_metrics_emulator.h
diff options
context:
space:
mode:
authormfomitchev <mfomitchev@chromium.org>2016-02-11 14:20:52 -0800
committerCommit bot <commit-bot@chromium.org>2016-02-11 22:22:23 +0000
commit39a061b3187ea3816ecdd38597057f95c19cfcfb (patch)
tree5e0aa0cb6decdd7cfe8b4d9b158eec5acef8dfaa /content/renderer/devtools/render_widget_screen_metrics_emulator.h
parenta429a07842244fdb70a17352da186fc0d65985fb (diff)
downloadchromium_src-39a061b3187ea3816ecdd38597057f95c19cfcfb.zip
chromium_src-39a061b3187ea3816ecdd38597057f95c19cfcfb.tar.gz
chromium_src-39a061b3187ea3816ecdd38597057f95c19cfcfb.tar.bz2
Decouple ScreenMetricsEmulator From RenderWidget
This is part of the ongoing effort to thin down RenderWidget to be just IPC transport. Started in http://crrev.com/1599583002 BUG=577321 Review URL: https://codereview.chromium.org/1675783002 Cr-Commit-Position: refs/heads/master@{#375020}
Diffstat (limited to 'content/renderer/devtools/render_widget_screen_metrics_emulator.h')
-rw-r--r--content/renderer/devtools/render_widget_screen_metrics_emulator.h88
1 files changed, 88 insertions, 0 deletions
diff --git a/content/renderer/devtools/render_widget_screen_metrics_emulator.h b/content/renderer/devtools/render_widget_screen_metrics_emulator.h
new file mode 100644
index 0000000..8288dfa
--- /dev/null
+++ b/content/renderer/devtools/render_widget_screen_metrics_emulator.h
@@ -0,0 +1,88 @@
+// Copyright 2016 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef CONTENT_RENDERER_DEVTOOLS_RENDER_WIDGET_SCREEN_METRICS_EMULATOR_H_
+#define CONTENT_RENDERER_DEVTOOLS_RENDER_WIDGET_SCREEN_METRICS_EMULATOR_H_
+
+#include "base/memory/scoped_ptr.h"
+#include "content/common/resize_params.h"
+#include "third_party/WebKit/public/web/WebDeviceEmulationParams.h"
+
+namespace gfx {
+class PointF;
+class Rect;
+}
+
+namespace content {
+
+class RenderWidgetScreenMetricsEmulatorDelegate;
+struct ContextMenuParams;
+
+// RenderWidgetScreenMetricsEmulator class manages screen emulation inside a
+// RenderWidget. 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 RenderWidgetScreenMetricsEmulator {
+ public:
+ RenderWidgetScreenMetricsEmulator(
+ RenderWidgetScreenMetricsEmulatorDelegate* delegate,
+ const blink::WebDeviceEmulationParams& params,
+ const ResizeParams& resize_params,
+ const gfx::Rect& view_screen_rect,
+ const gfx::Rect& window_screen_rect);
+ virtual ~RenderWidgetScreenMetricsEmulator();
+
+ // Scale and offset used to convert between host coordinates
+ // and webwidget coordinates.
+ const gfx::Size& original_size() const {
+ return original_resize_params_.new_size;
+ }
+
+ float scale() const { return scale_; }
+ const gfx::PointF& offset() const { return offset_; }
+ const gfx::Rect& applied_widget_rect() const { return applied_widget_rect_; }
+ const blink::WebScreenInfo& original_screen_info() const {
+ return original_resize_params_.screen_info;
+ }
+ const gfx::Rect& original_screen_rect() const {
+ return original_view_screen_rect_;
+ }
+
+ void ChangeEmulationParams(const blink::WebDeviceEmulationParams& params);
+
+ // The following methods alter handlers' behavior for messages related to
+ // widget size and position.
+ void OnResize(const ResizeParams& params);
+ void OnUpdateScreenRects(const gfx::Rect& view_screen_rect,
+ const gfx::Rect& window_screen_rect);
+ void OnShowContextMenu(ContextMenuParams* params);
+ gfx::Rect AdjustValidationMessageAnchor(const gfx::Rect& anchor);
+
+ private:
+ // Apply original_resize_params_
+ void Apply();
+
+ RenderWidgetScreenMetricsEmulatorDelegate* const delegate_;
+
+ // Parameters as passed by RenderWidget::EnableScreenMetricsEmulation.
+ blink::WebDeviceEmulationParams emulation_params_;
+
+ // The computed scale and offset used to fit widget into browser window.
+ float scale_;
+ gfx::PointF offset_;
+
+ // Widget rect as passed to webwidget.
+ gfx::Rect applied_widget_rect_;
+
+ // Original values to restore back after emulation ends.
+ ResizeParams original_resize_params_;
+ gfx::Rect original_view_screen_rect_;
+ gfx::Rect original_window_screen_rect_;
+
+ DISALLOW_COPY_AND_ASSIGN(RenderWidgetScreenMetricsEmulator);
+};
+
+} // namespace content
+
+#endif // CONTENT_RENDERER_DEVTOOLS_RENDER_WIDGET_SCREEN_METRICS_EMULATOR_H_