summaryrefslogtreecommitdiffstats
path: root/content/renderer/devtools/render_widget_screen_metrics_emulator.h
blob: 5650d0a3ed7944b4b5b7fab7b89fcb345b818692 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
// 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 OnUpdateWindowScreenRect(const gfx::Rect& window_screen_rect);
  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);

  // Apply parameters to the render widget.
  void Apply();

 private:
  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_