Commit 99fcf927 authored by Dave Tapuska's avatar Dave Tapuska Committed by Commit Bot

Move Zoom, Device Scale overrides into WebFrameWidgetBase.

Move these testing APIs into the base implementation.

BUG=1097816

Change-Id: I4e476c9d150cc204692bedf82d577c5e4909051c
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2536980
Commit-Queue: Dave Tapuska <dtapuska@chromium.org>
Commit-Queue: danakj <danakj@chromium.org>
Reviewed-by: default avatardanakj <danakj@chromium.org>
Cr-Commit-Position: refs/heads/master@{#827552}
parent acf1f557
...@@ -1311,6 +1311,10 @@ WebFrameWidgetBase::GetAndResetContextMenuLocation() { ...@@ -1311,6 +1311,10 @@ WebFrameWidgetBase::GetAndResetContextMenuLocation() {
} }
void WebFrameWidgetBase::SetZoomLevel(double zoom_level) { void WebFrameWidgetBase::SetZoomLevel(double zoom_level) {
// Override the zoom level with the testing one if necessary.
if (zoom_level_for_testing_ != -INFINITY)
zoom_level = zoom_level_for_testing_;
View()->SetZoomLevel(zoom_level); View()->SetZoomLevel(zoom_level);
// Part of the UpdateVisualProperties dance we send the zoom level to // Part of the UpdateVisualProperties dance we send the zoom level to
...@@ -3059,6 +3063,10 @@ KURL WebFrameWidgetBase::GetURLForDebugTrace() { ...@@ -3059,6 +3063,10 @@ KURL WebFrameWidgetBase::GetURLForDebugTrace() {
return {}; return {};
} }
float WebFrameWidgetBase::GetTestingDeviceScaleFactorOverride() {
return device_scale_factor_for_testing_;
}
void WebFrameWidgetBase::ReleaseMouseLockAndPointerCaptureForTesting() { void WebFrameWidgetBase::ReleaseMouseLockAndPointerCaptureForTesting() {
GetPage()->GetPointerLockController().ExitPointerLock(); GetPage()->GetPointerLockController().ExitPointerLock();
MouseCaptureLost(); MouseCaptureLost();
...@@ -3075,6 +3083,49 @@ WebHitTestResult WebFrameWidgetBase::HitTestResultAt(const gfx::PointF& point) { ...@@ -3075,6 +3083,49 @@ WebHitTestResult WebFrameWidgetBase::HitTestResultAt(const gfx::PointF& point) {
return CoreHitTestResultAt(point); return CoreHitTestResultAt(point);
} }
void WebFrameWidgetBase::SetZoomLevelForTesting(double zoom_level) {
DCHECK(ForMainFrame());
DCHECK_NE(zoom_level, -INFINITY);
zoom_level_for_testing_ = zoom_level;
SetZoomLevel(zoom_level);
}
void WebFrameWidgetBase::ResetZoomLevelForTesting() {
DCHECK(ForMainFrame());
zoom_level_for_testing_ = -INFINITY;
SetZoomLevel(0);
}
void WebFrameWidgetBase::SetDeviceScaleFactorForTesting(float factor) {
DCHECK(ForMainFrame());
DCHECK_GE(factor, 0.f);
// Stash the window size before we adjust the scale factor, as subsequent
// calls to convert will use the new scale factor.
gfx::Size size_in_dips = widget_base_->BlinkSpaceToFlooredDIPs(Size());
device_scale_factor_for_testing_ = factor;
// Receiving a 0 is used to reset between tests, it removes the override in
// order to listen to the browser for the next test.
if (!factor)
return;
// We are changing the device scale factor from the renderer, so allocate a
// new viz::LocalSurfaceId to avoid surface invariants violations in tests.
widget_base_->LayerTreeHost()->RequestNewLocalSurfaceId();
ScreenInfo info = widget_base_->GetScreenInfo();
info.device_scale_factor = factor;
gfx::Size size_with_dsf = gfx::ScaleToCeiledSize(size_in_dips, factor);
widget_base_->UpdateCompositorViewportAndScreenInfo(gfx::Rect(size_with_dsf),
info);
if (!AutoResizeMode()) {
// This picks up the new device scale factor as
// `UpdateCompositorViewportAndScreenInfo()` has applied a new value.
Resize(widget_base_->DIPsToCeiledBlinkSpace(size_in_dips));
}
}
WebPlugin* WebFrameWidgetBase::GetFocusedPluginContainer() { WebPlugin* WebFrameWidgetBase::GetFocusedPluginContainer() {
LocalFrame* focused_frame = FocusedLocalFrameInWidget(); LocalFrame* focused_frame = FocusedLocalFrameInWidget();
if (!focused_frame) if (!focused_frame)
......
...@@ -300,6 +300,9 @@ class CORE_EXPORT WebFrameWidgetBase ...@@ -300,6 +300,9 @@ class CORE_EXPORT WebFrameWidgetBase
void ReleaseMouseLockAndPointerCaptureForTesting() override; void ReleaseMouseLockAndPointerCaptureForTesting() override;
const viz::FrameSinkId& GetFrameSinkId() override; const viz::FrameSinkId& GetFrameSinkId() override;
WebHitTestResult HitTestResultAt(const gfx::PointF&) override; WebHitTestResult HitTestResultAt(const gfx::PointF&) override;
void SetZoomLevelForTesting(double zoom_level) override;
void ResetZoomLevelForTesting() override;
void SetDeviceScaleFactorForTesting(float factor) override;
// Called when a drag-n-drop operation should begin. // Called when a drag-n-drop operation should begin.
void StartDragging(const WebDragData&, void StartDragging(const WebDragData&,
...@@ -404,6 +407,7 @@ class CORE_EXPORT WebFrameWidgetBase ...@@ -404,6 +407,7 @@ class CORE_EXPORT WebFrameWidgetBase
void WasHidden() override; void WasHidden() override;
void WasShown(bool was_evicted) override; void WasShown(bool was_evicted) override;
KURL GetURLForDebugTrace() override; KURL GetURLForDebugTrace() override;
float GetTestingDeviceScaleFactorOverride() override;
// mojom::blink::FrameWidget methods. // mojom::blink::FrameWidget methods.
void DragTargetDragEnter(const WebDragData&, void DragTargetDragEnter(const WebDragData&,
...@@ -477,7 +481,7 @@ class CORE_EXPORT WebFrameWidgetBase ...@@ -477,7 +481,7 @@ class CORE_EXPORT WebFrameWidgetBase
// Called when the FrameView for this Widget's local root is created. // Called when the FrameView for this Widget's local root is created.
virtual void DidCreateLocalRootView() {} virtual void DidCreateLocalRootView() {}
virtual void SetZoomLevel(double zoom_level); void SetZoomLevel(double zoom_level);
// Enable or disable auto-resize. This is part of // Enable or disable auto-resize. This is part of
// UpdateVisualProperties though tests may call to it more directly. // UpdateVisualProperties though tests may call to it more directly.
...@@ -835,6 +839,20 @@ class CORE_EXPORT WebFrameWidgetBase ...@@ -835,6 +839,20 @@ class CORE_EXPORT WebFrameWidgetBase
return child_local_root_data_; return child_local_root_data_;
} }
// Web tests override the zoom factor in the renderer with this. We store it
// to keep the override if the browser passes along VisualProperties with the
// real device scale factor. A value of -INFINITY means this is ignored.
// It is always valid to read this variable but it can only be set for main
// frame widgets.
double zoom_level_for_testing_ = -INFINITY;
// Web tests override the device scale factor in the renderer with this. We
// store it to keep the override if the browser passes along VisualProperties
// with the real device scale factor. A value of 0.f means this is ignored.
// It is always valid to read this variable but it can only be set for main
// frame widgets.
float device_scale_factor_for_testing_ = 0;
friend class WebViewImpl; friend class WebViewImpl;
friend class ReportTimeSwapPromise; friend class ReportTimeSwapPromise;
}; };
......
...@@ -345,20 +345,6 @@ bool WebFrameWidgetImpl::ScrollFocusedEditableElementIntoView() { ...@@ -345,20 +345,6 @@ bool WebFrameWidgetImpl::ScrollFocusedEditableElementIntoView() {
return true; return true;
} }
void WebFrameWidgetImpl::SetZoomLevelForTesting(double zoom_level) {
// Zoom level is only controlled for testing on the main frame.
NOTREACHED();
}
void WebFrameWidgetImpl::ResetZoomLevelForTesting() {
// Zoom level is only controlled for testing on the main frame.
NOTREACHED();
}
void WebFrameWidgetImpl::SetDeviceScaleFactorForTesting(float factor) {
NOTREACHED();
}
void WebFrameWidgetImpl::IntrinsicSizingInfoChanged( void WebFrameWidgetImpl::IntrinsicSizingInfoChanged(
mojom::blink::IntrinsicSizingInfoPtr sizing_info) { mojom::blink::IntrinsicSizingInfoPtr sizing_info) {
GetAssociatedFrameWidgetHost()->IntrinsicSizingInfoChanged( GetAssociatedFrameWidgetHost()->IntrinsicSizingInfoChanged(
......
...@@ -102,9 +102,6 @@ class WebFrameWidgetImpl final : public WebFrameWidgetBase { ...@@ -102,9 +102,6 @@ class WebFrameWidgetImpl final : public WebFrameWidgetBase {
// WebFrameWidget implementation. // WebFrameWidget implementation.
bool ScrollFocusedEditableElementIntoView() override; bool ScrollFocusedEditableElementIntoView() override;
void SetZoomLevelForTesting(double zoom_level) override;
void ResetZoomLevelForTesting() override;
void SetDeviceScaleFactorForTesting(float factor) override;
PaintLayerCompositor* Compositor() const; PaintLayerCompositor* Compositor() const;
......
...@@ -115,10 +115,6 @@ void WebViewFrameWidget::FocusChanged(bool enable) { ...@@ -115,10 +115,6 @@ void WebViewFrameWidget::FocusChanged(bool enable) {
web_view_->SetFocus(enable); web_view_->SetFocus(enable);
} }
float WebViewFrameWidget::GetDeviceScaleFactorForTesting() {
return device_scale_factor_for_testing_;
}
bool WebViewFrameWidget::ShouldHandleImeEvents() { bool WebViewFrameWidget::ShouldHandleImeEvents() {
return HasFocus(); return HasFocus();
} }
...@@ -373,53 +369,6 @@ LocalFrameView* WebViewFrameWidget::GetLocalFrameViewForAnimationScrolling() { ...@@ -373,53 +369,6 @@ LocalFrameView* WebViewFrameWidget::GetLocalFrameViewForAnimationScrolling() {
return nullptr; return nullptr;
} }
void WebViewFrameWidget::SetZoomLevelForTesting(double zoom_level) {
DCHECK_NE(zoom_level, -INFINITY);
zoom_level_for_testing_ = zoom_level;
SetZoomLevel(zoom_level);
}
void WebViewFrameWidget::ResetZoomLevelForTesting() {
zoom_level_for_testing_ = -INFINITY;
SetZoomLevel(0);
}
void WebViewFrameWidget::SetDeviceScaleFactorForTesting(float factor) {
DCHECK_GE(factor, 0.f);
// Stash the window size before we adjust the scale factor, as subsequent
// calls to convert will use the new scale factor.
gfx::Size size_in_dips = widget_base_->BlinkSpaceToFlooredDIPs(size_);
device_scale_factor_for_testing_ = factor;
// Receiving a 0 is used to reset between tests, it removes the override in
// order to listen to the browser for the next test.
if (!factor)
return;
// We are changing the device scale factor from the renderer, so allocate a
// new viz::LocalSurfaceId to avoid surface invariants violations in tests.
widget_base_->LayerTreeHost()->RequestNewLocalSurfaceId();
ScreenInfo info = widget_base_->GetScreenInfo();
info.device_scale_factor = factor;
gfx::Size size_with_dsf = gfx::ScaleToCeiledSize(size_in_dips, factor);
widget_base_->UpdateCompositorViewportAndScreenInfo(gfx::Rect(size_with_dsf),
info);
if (!AutoResizeMode()) {
// This picks up the new device scale factor as
// UpdateCompositorViewportAndScreenInfo has applied a new value.
Resize(widget_base_->DIPsToCeiledBlinkSpace(size_in_dips));
}
}
void WebViewFrameWidget::SetZoomLevel(double zoom_level) {
// Override the zoom level with the testing one if necessary
if (zoom_level_for_testing_ != -INFINITY)
zoom_level = zoom_level_for_testing_;
WebFrameWidgetBase::SetZoomLevel(zoom_level);
}
void WebViewFrameWidget::SetAutoResizeMode(bool auto_resize, void WebViewFrameWidget::SetAutoResizeMode(bool auto_resize,
const gfx::Size& min_window_size, const gfx::Size& min_window_size,
const gfx::Size& max_window_size, const gfx::Size& max_window_size,
......
...@@ -68,19 +68,13 @@ class CORE_EXPORT WebViewFrameWidget : public WebFrameWidgetBase { ...@@ -68,19 +68,13 @@ class CORE_EXPORT WebViewFrameWidget : public WebFrameWidgetBase {
DocumentUpdateReason reason) override; DocumentUpdateReason reason) override;
void MouseCaptureLost() override; void MouseCaptureLost() override;
// blink::mojom::FrameWidget
// WebFrameWidget overrides: // WebFrameWidget overrides:
bool ScrollFocusedEditableElementIntoView() override; bool ScrollFocusedEditableElementIntoView() override;
void SetZoomLevelForTesting(double zoom_level) override;
void ResetZoomLevelForTesting() override;
void SetDeviceScaleFactorForTesting(float factor) override;
// WebFrameWidgetBase overrides: // WebFrameWidgetBase overrides:
bool ForSubframe() const override { return false; } bool ForSubframe() const override { return false; }
bool ForTopLevelFrame() const override { return !is_for_nested_main_frame_; } bool ForTopLevelFrame() const override { return !is_for_nested_main_frame_; }
void ZoomToFindInPageRect(const WebRect& rect_in_root_frame) override; void ZoomToFindInPageRect(const WebRect& rect_in_root_frame) override;
void SetZoomLevel(double zoom_level) override;
void SetAutoResizeMode(bool auto_resize, void SetAutoResizeMode(bool auto_resize,
const gfx::Size& min_size_before_dsf, const gfx::Size& min_size_before_dsf,
const gfx::Size& max_size_before_dsf, const gfx::Size& max_size_before_dsf,
...@@ -101,7 +95,6 @@ class CORE_EXPORT WebViewFrameWidget : public WebFrameWidgetBase { ...@@ -101,7 +95,6 @@ class CORE_EXPORT WebViewFrameWidget : public WebFrameWidgetBase {
void ApplyViewportChanges(const cc::ApplyViewportChangesArgs& args) override; void ApplyViewportChanges(const cc::ApplyViewportChangesArgs& args) override;
void RecordManipulationTypeCounts(cc::ManipulationInfo info) override; void RecordManipulationTypeCounts(cc::ManipulationInfo info) override;
void FocusChanged(bool enabled) override; void FocusChanged(bool enabled) override;
float GetDeviceScaleFactorForTesting() override;
void RunPaintBenchmark(int repeat_count, void RunPaintBenchmark(int repeat_count,
cc::PaintBenchmarkResult& result) override; cc::PaintBenchmarkResult& result) override;
...@@ -126,16 +119,6 @@ class CORE_EXPORT WebViewFrameWidget : public WebFrameWidgetBase { ...@@ -126,16 +119,6 @@ class CORE_EXPORT WebViewFrameWidget : public WebFrameWidgetBase {
scoped_refptr<WebViewImpl> web_view_; scoped_refptr<WebViewImpl> web_view_;
// Web tests override the zoom factor in the renderer with this. We store it
// to keep the override if the browser passes along VisualProperties with the
// real device scale factor. A value of -INFINITY means this is ignored.
double zoom_level_for_testing_ = -INFINITY;
// Web tests override the device scale factor in the renderer with this. We
// store it to keep the override if the browser passes along VisualProperties
// with the real device scale factor. A value of 0.f means this is ignored.
float device_scale_factor_for_testing_ = 0;
// This bit is used to tell if this is a nested widget (an "inner web // This bit is used to tell if this is a nested widget (an "inner web
// contents") like a <webview> or <portal> widget. If false, the widget is the // contents") like a <webview> or <portal> widget. If false, the widget is the
// top level widget. // top level widget.
......
...@@ -353,7 +353,7 @@ void WidgetBase::UpdateVisualProperties( ...@@ -353,7 +353,7 @@ void WidgetBase::UpdateVisualProperties(
blink::VisualProperties visual_properties = visual_properties_from_browser; blink::VisualProperties visual_properties = visual_properties_from_browser;
// Web tests can override the device scale factor in the renderer. // Web tests can override the device scale factor in the renderer.
if (auto scale_factor = client_->GetDeviceScaleFactorForTesting()) { if (auto scale_factor = client_->GetTestingDeviceScaleFactorOverride()) {
visual_properties.screen_info.device_scale_factor = scale_factor; visual_properties.screen_info.device_scale_factor = scale_factor;
visual_properties.compositor_viewport_pixel_rect = visual_properties.compositor_viewport_pixel_rect =
gfx::Rect(gfx::ScaleToCeiledSize( gfx::Rect(gfx::ScaleToCeiledSize(
......
...@@ -182,7 +182,7 @@ class WidgetBaseClient { ...@@ -182,7 +182,7 @@ class WidgetBaseClient {
} }
// Return the overridden device scale factor for testing. // Return the overridden device scale factor for testing.
virtual float GetDeviceScaleFactorForTesting() { return 0.f; } virtual float GetTestingDeviceScaleFactorOverride() { return 0.f; }
// Test-specific methods below this point. // Test-specific methods below this point.
virtual void ScheduleAnimationForWebTests() {} virtual void ScheduleAnimationForWebTests() {}
......
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