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

Don't rely on creating VisualProperties to change autoresize in tests

Stop relying on the RenderWidget holding all the VisualProperties
state and constructing a VisualProperties in order for web tests to
toggle auto resize on the widget/view.

R=avi@chromium.org

Bug: 419087
Change-Id: I1a20c1ead527489ed0075907a45b70812b63f84f
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1811430Reviewed-by: default avatarAvi Drissman <avi@chromium.org>
Commit-Queue: danakj <danakj@chromium.org>
Cr-Commit-Position: refs/heads/master@{#697755}
parent 0438c40d
...@@ -798,25 +798,10 @@ void RenderWidget::OnSynchronizeVisualProperties( ...@@ -798,25 +798,10 @@ void RenderWidget::OnSynchronizeVisualProperties(
delegate()->ApplyNewDisplayModeForWidget(visual_properties.display_mode); delegate()->ApplyNewDisplayModeForWidget(visual_properties.display_mode);
} }
bool auto_resize_mode_changed = SetAutoResizeMode(visual_properties.auto_resize_enabled,
auto_resize_mode_ != visual_properties.auto_resize_enabled; visual_properties.min_size_for_auto_resize,
auto_resize_mode_ = visual_properties.auto_resize_enabled; visual_properties.max_size_for_auto_resize,
min_size_for_auto_resize_ = visual_properties.min_size_for_auto_resize; visual_properties.screen_info.device_scale_factor);
max_size_for_auto_resize_ = visual_properties.max_size_for_auto_resize;
if (auto_resize_mode_) {
gfx::Size min_auto_size = min_size_for_auto_resize_;
gfx::Size max_auto_size = max_size_for_auto_resize_;
if (compositor_deps_->IsUseZoomForDSFEnabled()) {
min_auto_size = gfx::ScaleToCeiledSize(
min_auto_size, visual_properties.screen_info.device_scale_factor);
max_auto_size = gfx::ScaleToCeiledSize(
max_auto_size, visual_properties.screen_info.device_scale_factor);
}
delegate()->ApplyAutoResizeLimitsForWidget(min_auto_size, max_auto_size);
} else if (auto_resize_mode_changed) {
delegate()->DisableAutoResizeForWidget();
}
browser_controls_shrink_blink_size_ = browser_controls_shrink_blink_size_ =
visual_properties.browser_controls_shrink_blink_size; visual_properties.browser_controls_shrink_blink_size;
...@@ -886,7 +871,7 @@ void RenderWidget::OnSynchronizeVisualProperties( ...@@ -886,7 +871,7 @@ void RenderWidget::OnSynchronizeVisualProperties(
visual_properties.bottom_controls_height, visual_properties.bottom_controls_height,
visual_properties.browser_controls_shrink_blink_size); visual_properties.browser_controls_shrink_blink_size);
if (!visual_properties.auto_resize_enabled) { if (!auto_resize_mode_) {
if (visual_properties.is_fullscreen_granted != is_fullscreen_granted_) { if (visual_properties.is_fullscreen_granted != is_fullscreen_granted_) {
is_fullscreen_granted_ = visual_properties.is_fullscreen_granted; is_fullscreen_granted_ = visual_properties.is_fullscreen_granted;
if (is_fullscreen_granted_) if (is_fullscreen_granted_)
...@@ -993,6 +978,31 @@ void RenderWidget::OnEnableDeviceEmulation( ...@@ -993,6 +978,31 @@ void RenderWidget::OnEnableDeviceEmulation(
} }
} }
void RenderWidget::SetAutoResizeMode(bool auto_resize,
const gfx::Size& min_size_before_dsf,
const gfx::Size& max_size_before_dsf,
float device_scale_factor) {
bool was_changed = auto_resize_mode_ != auto_resize;
auto_resize_mode_ = auto_resize;
min_size_for_auto_resize_ = min_size_before_dsf;
max_size_for_auto_resize_ = max_size_before_dsf;
if (auto_resize) {
gfx::Size min_auto_size = min_size_for_auto_resize_;
gfx::Size max_auto_size = max_size_for_auto_resize_;
if (compositor_deps_->IsUseZoomForDSFEnabled()) {
min_auto_size =
gfx::ScaleToCeiledSize(min_auto_size, device_scale_factor);
max_auto_size =
gfx::ScaleToCeiledSize(max_auto_size, device_scale_factor);
}
delegate()->ApplyAutoResizeLimitsForWidget(min_auto_size, max_auto_size);
} else if (was_changed) {
delegate()->DisableAutoResizeForWidget();
}
}
void RenderWidget::OnDisableDeviceEmulation() { void RenderWidget::OnDisableDeviceEmulation() {
screen_metrics_emulator_.reset(); screen_metrics_emulator_.reset();
} }
...@@ -1710,7 +1720,7 @@ void RenderWidget::SynchronizeVisualProperties( ...@@ -1710,7 +1720,7 @@ void RenderWidget::SynchronizeVisualProperties(
// but not others. // but not others.
gfx::Rect new_compositor_viewport_pixel_rect = gfx::Rect new_compositor_viewport_pixel_rect =
visual_properties.auto_resize_enabled auto_resize_mode_
? gfx::Rect(gfx::ScaleToCeiledSize( ? gfx::Rect(gfx::ScaleToCeiledSize(
size_, visual_properties.screen_info.device_scale_factor)) size_, visual_properties.screen_info.device_scale_factor))
: visual_properties.compositor_viewport_pixel_rect; : visual_properties.compositor_viewport_pixel_rect;
...@@ -1740,7 +1750,7 @@ void RenderWidget::SynchronizeVisualProperties( ...@@ -1740,7 +1750,7 @@ void RenderWidget::SynchronizeVisualProperties(
} }
} }
if (!visual_properties.auto_resize_enabled) { if (!auto_resize_mode_) {
visible_viewport_size_ = visual_properties.visible_viewport_size; visible_viewport_size_ = visual_properties.visible_viewport_size;
display_mode_ = visual_properties.display_mode; display_mode_ = visual_properties.display_mode;
size_ = visual_properties.new_size; size_ = visual_properties.new_size;
...@@ -3836,43 +3846,23 @@ void RenderWidget::SetWindowRectSynchronouslyForTesting( ...@@ -3836,43 +3846,23 @@ void RenderWidget::SetWindowRectSynchronouslyForTesting(
void RenderWidget::EnableAutoResizeForTesting(const gfx::Size& min_size, void RenderWidget::EnableAutoResizeForTesting(const gfx::Size& min_size,
const gfx::Size& max_size) { const gfx::Size& max_size) {
VisualProperties visual_properties; SetAutoResizeMode(true, min_size, max_size,
visual_properties.auto_resize_enabled = true; page_properties_->GetDeviceScaleFactor());
visual_properties.min_size_for_auto_resize = min_size;
visual_properties.max_size_for_auto_resize = max_size;
visual_properties.local_surface_id_allocation =
base::Optional<viz::LocalSurfaceIdAllocation>(
viz::LocalSurfaceIdAllocation(
viz::LocalSurfaceId(1, 1, base::UnguessableToken::Create()),
base::TimeTicks::Now()));
OnSynchronizeVisualProperties(visual_properties);
} }
void RenderWidget::DisableAutoResizeForTesting(const gfx::Size& new_size) { void RenderWidget::DisableAutoResizeForTesting(const gfx::Size& new_size) {
if (!auto_resize_mode_) if (!auto_resize_mode_)
return; return;
VisualProperties visual_properties; SetAutoResizeMode(false, gfx::Size(), gfx::Size(),
visual_properties.auto_resize_enabled = false; page_properties_->GetDeviceScaleFactor());
visual_properties.screen_info = page_properties_->GetScreenInfo();
visual_properties.new_size = new_size;
visual_properties.compositor_viewport_pixel_rect = CompositorViewportRect();
visual_properties.browser_controls_shrink_blink_size =
browser_controls_shrink_blink_size_;
visual_properties.top_controls_height = top_controls_height_;
visual_properties.visible_viewport_size = visible_viewport_size_;
visual_properties.is_fullscreen_granted = is_fullscreen_granted_;
visual_properties.display_mode = display_mode_;
if (new_size.IsEmpty()) { // The |new_size| is empty when resetting auto resize in between tests. In
// The |new_size| is empty when resetting auto resize in between tests. In // this case the current size should just be preserved.
// this case the current size should just be preserved. if (!new_size.IsEmpty()) {
visual_properties.new_size = size_; size_ = new_size;
} else { ResizeWebWidget();
visual_properties.new_size = new_size;
} }
OnSynchronizeVisualProperties(visual_properties);
} }
blink::WebLocalFrame* RenderWidget::GetFocusedWebLocalFrameInWidget() const { blink::WebLocalFrame* RenderWidget::GetFocusedWebLocalFrameInWidget() const {
......
...@@ -752,6 +752,13 @@ class CONTENT_EXPORT RenderWidget ...@@ -752,6 +752,13 @@ class CONTENT_EXPORT RenderWidget
gfx::Size GetSizeForWebWidget() const; gfx::Size GetSizeForWebWidget() const;
void ResizeWebWidget(); void ResizeWebWidget();
// Enable or disable auto-resize. This is part of
// OnSynchronizeVisualProperties though tests may call to it more directly.
void SetAutoResizeMode(bool auto_resize,
const gfx::Size& min_size_before_dsf,
const gfx::Size& max_size_before_dsf,
float device_scale_factor);
// Helper method to get the device_viewport_rect() from the compositor, which // Helper method to get the device_viewport_rect() from the compositor, which
// is always in physical pixels. // is always in physical pixels.
gfx::Rect CompositorViewportRect() const; gfx::Rect CompositorViewportRect() const;
......
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