Commit f26cfd8f authored by danakj's avatar danakj Committed by Commit Bot

Separate RenderWidgetScreenMetricsEmulator and SynchronizeVisualProperties

Change RenderWidgetScreenMetricsEmulator API back into RenderWidget to be
specific to the properties being changed. Then it won't need to take as
input the whole VisualProperties in the future. And now it doesn't need
to construct a VisualProperties object.

Also make turning off the emulator explicit rather than having to destroy
it and having the destructor call back into the RenderWidget. We will
continue to remove RenderWidget re-entrancy with the emulator in future
changes.

R=avi@chromium.org

Bug: 1006052
Change-Id: Ie751a57117aa52205216b78190fec96777088e9c
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1825318
Commit-Queue: danakj <danakj@chromium.org>
Reviewed-by: default avatarAvi Drissman <avi@chromium.org>
Cr-Commit-Position: refs/heads/master@{#700411}
parent de88f517
......@@ -336,9 +336,11 @@ blink::WebDeviceEmulationParams EmulationHandler::GetDeviceEmulationParams() {
void EmulationHandler::SetDeviceEmulationParams(
const blink::WebDeviceEmulationParams& params) {
bool enabled = params != blink::WebDeviceEmulationParams();
device_emulation_enabled_ = enabled;
device_emulation_params_ = params;
UpdateDeviceEmulationState();
if (params != device_emulation_params_) {
device_emulation_enabled_ = enabled;
device_emulation_params_ = params;
UpdateDeviceEmulationState();
}
}
WebContentsImpl* EmulationHandler::GetWebContents() {
......
This diff is collapsed.
......@@ -390,11 +390,12 @@ class CONTENT_EXPORT RenderWidget
bool WillHandleMouseEvent(const blink::WebMouseEvent& event) override;
// RenderWidgetScreenMetricsEmulatorDelegate
void SynchronizeVisualProperties(
const VisualProperties& visual_properties) override;
void SetScreenMetricsEmulationParameters(
bool enabled,
const blink::WebDeviceEmulationParams& params) override;
void SetScreenInfoAndSize(const ScreenInfo& screen_info,
const gfx::Size& widget_size,
const gfx::Size& visible_viewport_size) override;
void SetScreenRects(const gfx::Rect& widget_screen_rect,
const gfx::Rect& window_screen_rect) override;
......@@ -689,6 +690,9 @@ class CONTENT_EXPORT RenderWidget
// [routing IPC from browser].
virtual void SynchronizeVisualPropertiesFromRenderView(
const VisualProperties& visual_properties);
// TODO(danakj): A sub-step of SynchronizeVisualPropertiesFromRenderView that
// should be merged together.
void SynchronizeVisualProperties(const VisualProperties& visual_properties);
bool in_synchronous_composite_for_testing() const {
return in_synchronous_composite_for_testing_;
......@@ -748,7 +752,8 @@ class CONTENT_EXPORT RenderWidget
// browser.
static void DoDeferredClose(int widget_routing_id);
gfx::Size GetSizeForWebWidget() const;
// Must be called to pass updated values to blink when the widget size, the
// visual viewport size, or the device scale factor change.
void ResizeWebWidget();
// Enable or disable auto-resize. This is part of
......
......@@ -12,22 +12,26 @@ namespace content {
RenderWidgetScreenMetricsEmulator::RenderWidgetScreenMetricsEmulator(
RenderWidgetScreenMetricsEmulatorDelegate* delegate,
const blink::WebDeviceEmulationParams& params,
const VisualProperties& visual_properties,
const gfx::Rect& view_screen_rect,
const gfx::Rect& window_screen_rect)
: delegate_(delegate),
emulation_params_(params),
scale_(1.f),
original_visual_properties_(visual_properties),
original_view_screen_rect_(view_screen_rect),
original_window_screen_rect_(window_screen_rect) {}
RenderWidgetScreenMetricsEmulator::~RenderWidgetScreenMetricsEmulator() {
delegate_->SynchronizeVisualProperties(original_visual_properties_);
RenderWidgetScreenMetricsEmulator::~RenderWidgetScreenMetricsEmulator() =
default;
void RenderWidgetScreenMetricsEmulator::DisableAndApply() {
delegate_->SetScreenMetricsEmulationParameters(false, emulation_params_);
delegate_->SetScreenRects(original_view_screen_rect_,
original_window_screen_rect_);
delegate_->SetScreenInfoAndSize(
original_visual_properties_.screen_info,
/*widget_size=*/original_visual_properties_.new_size,
/*visible_viewport_size=*/
original_visual_properties_.visible_viewport_size);
}
void RenderWidgetScreenMetricsEmulator::ChangeEmulationParams(
......@@ -37,7 +41,8 @@ void RenderWidgetScreenMetricsEmulator::ChangeEmulationParams(
}
void RenderWidgetScreenMetricsEmulator::Apply() {
VisualProperties modified_visual_properties = original_visual_properties_;
ScreenInfo screen_info = original_visual_properties_.screen_info;
applied_widget_rect_.set_size(gfx::Size(emulation_params_.view_size));
if (!applied_widget_rect_.width())
......@@ -56,9 +61,8 @@ void RenderWidgetScreenMetricsEmulator::Apply() {
gfx::Rect window_screen_rect;
if (emulation_params_.screen_position ==
blink::WebDeviceEmulationParams::kDesktop) {
modified_visual_properties.screen_info.rect = original_screen_info().rect;
modified_visual_properties.screen_info.available_rect =
original_screen_info().available_rect;
screen_info.rect = original_screen_info().rect;
screen_info.available_rect = original_screen_info().available_rect;
window_screen_rect = original_window_screen_rect_;
if (emulation_params_.view_position) {
applied_widget_rect_.set_origin(*emulation_params_.view_position);
......@@ -69,20 +73,19 @@ void RenderWidgetScreenMetricsEmulator::Apply() {
} else {
applied_widget_rect_.set_origin(
emulation_params_.view_position.value_or(blink::WebPoint()));
modified_visual_properties.screen_info.rect = applied_widget_rect_;
modified_visual_properties.screen_info.available_rect =
applied_widget_rect_;
screen_info.rect = applied_widget_rect_;
screen_info.available_rect = applied_widget_rect_;
window_screen_rect = applied_widget_rect_;
}
if (!emulation_params_.screen_size.IsEmpty()) {
gfx::Rect screen_rect = gfx::Rect(0, 0, emulation_params_.screen_size.width,
emulation_params_.screen_size.height);
modified_visual_properties.screen_info.rect = screen_rect;
modified_visual_properties.screen_info.available_rect = screen_rect;
screen_info.rect = screen_rect;
screen_info.available_rect = screen_rect;
}
modified_visual_properties.screen_info.device_scale_factor =
screen_info.device_scale_factor =
emulation_params_.device_scale_factor
? emulation_params_.device_scale_factor
: original_screen_info().device_scale_factor;
......@@ -91,28 +94,26 @@ void RenderWidgetScreenMetricsEmulator::Apply() {
blink::kWebScreenOrientationUndefined) {
switch (emulation_params_.screen_orientation_type) {
case blink::kWebScreenOrientationPortraitPrimary:
modified_visual_properties.screen_info.orientation_type =
screen_info.orientation_type =
SCREEN_ORIENTATION_VALUES_PORTRAIT_PRIMARY;
break;
case blink::kWebScreenOrientationPortraitSecondary:
modified_visual_properties.screen_info.orientation_type =
screen_info.orientation_type =
SCREEN_ORIENTATION_VALUES_PORTRAIT_SECONDARY;
break;
case blink::kWebScreenOrientationLandscapePrimary:
modified_visual_properties.screen_info.orientation_type =
screen_info.orientation_type =
SCREEN_ORIENTATION_VALUES_LANDSCAPE_PRIMARY;
break;
case blink::kWebScreenOrientationLandscapeSecondary:
modified_visual_properties.screen_info.orientation_type =
screen_info.orientation_type =
SCREEN_ORIENTATION_VALUES_LANDSCAPE_SECONDARY;
break;
default:
modified_visual_properties.screen_info.orientation_type =
SCREEN_ORIENTATION_VALUES_DEFAULT;
screen_info.orientation_type = SCREEN_ORIENTATION_VALUES_DEFAULT;
break;
}
modified_visual_properties.screen_info.orientation_angle =
emulation_params_.screen_orientation_angle;
screen_info.orientation_angle = emulation_params_.screen_orientation_angle;
}
// Pass three emulation parameters to the blink side:
......@@ -129,10 +130,9 @@ void RenderWidgetScreenMetricsEmulator::Apply() {
delegate_->SetScreenRects(applied_widget_rect_, window_screen_rect);
modified_visual_properties.new_size = applied_widget_rect_.size();
modified_visual_properties.visible_viewport_size =
applied_widget_rect_.size();
delegate_->SynchronizeVisualProperties(modified_visual_properties);
delegate_->SetScreenInfoAndSize(
screen_info, /*widget_size=*/applied_widget_rect_.size(),
/*visible_viewport_size=*/applied_widget_rect_.size());
}
void RenderWidgetScreenMetricsEmulator::OnSynchronizeVisualProperties(
......
......@@ -7,6 +7,7 @@
#include <memory>
#include "content/common/content_export.h"
#include "content/common/visual_properties.h"
#include "third_party/blink/public/web/web_device_emulation_params.h"
......@@ -15,7 +16,6 @@ class Rect;
}
namespace content {
class RenderWidgetScreenMetricsEmulatorDelegate;
struct ContextMenuParams;
......@@ -27,11 +27,10 @@ class CONTENT_EXPORT RenderWidgetScreenMetricsEmulator {
public:
RenderWidgetScreenMetricsEmulator(
RenderWidgetScreenMetricsEmulatorDelegate* delegate,
const blink::WebDeviceEmulationParams& params,
const VisualProperties& visual_properties,
const gfx::Rect& view_screen_rect,
const gfx::Rect& window_screen_rect);
virtual ~RenderWidgetScreenMetricsEmulator();
~RenderWidgetScreenMetricsEmulator();
// Scale and offset used to convert between host coordinates
// and webwidget coordinates.
......@@ -48,6 +47,11 @@ class CONTENT_EXPORT RenderWidgetScreenMetricsEmulator {
return original_view_screen_rect_;
}
// Disables emulation and applies non-emulated values to the RenderWidget.
// Call this before destroying the RenderWidgetScreenMetricsEmulator.
void DisableAndApply();
// Sets new parameters and applies them to the RenderWidget.
void ChangeEmulationParams(const blink::WebDeviceEmulationParams& params);
// The following methods alter handlers' behavior for messages related to
......@@ -57,17 +61,17 @@ class CONTENT_EXPORT RenderWidgetScreenMetricsEmulator {
const gfx::Rect& window_screen_rect);
void OnShowContextMenu(ContextMenuParams* params);
// Apply parameters to the render widget.
void Apply();
private:
RenderWidgetScreenMetricsEmulatorDelegate* const delegate_;
// Applies emulated values to the RenderWidget.
void Apply();
// Parameters as passed by RenderWidget::EnableScreenMetricsEmulation.
blink::WebDeviceEmulationParams emulation_params_;
// The computed scale and offset used to fit widget into browser window.
float scale_;
float scale_ = 1;
// Widget rect as passed to webwidget.
gfx::Rect applied_widget_rect_;
......
......@@ -13,21 +13,20 @@ struct WebDeviceEmulationParams;
namespace content {
struct VisualProperties;
// Consumers of RenderWidgetScreenMetricsEmulatorDelegate implement this
// delegate in order to transport emulation information across processes.
class CONTENT_EXPORT RenderWidgetScreenMetricsEmulatorDelegate {
public:
// Synchronize visual properties with the widget.
virtual void SynchronizeVisualProperties(
const VisualProperties& visual_properties) = 0;
// Passes device emulation parameters to the delegate.
virtual void SetScreenMetricsEmulationParameters(
bool enabled,
const blink::WebDeviceEmulationParams& params) = 0;
// Passes an updated ScreenInfo and sizes to the delegate.
virtual void SetScreenInfoAndSize(const ScreenInfo& screen_info,
const gfx::Size& widget_size,
const gfx::Size& visible_viewport_size) = 0;
// Passes new view bounds and window bounds in screen coordinates to the
// delegate.
virtual void SetScreenRects(const gfx::Rect& view_screen_rect,
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment