Commit 53445e10 authored by Dave Tapuska's avatar Dave Tapuska Committed by Commit Bot

Move the AutoResize handling from WebViewFrameWidget into base.

Along with moving SetAutoResizeMode and DidAutoResize into base, move a
few things that are necessary to move auto resize handling into
base, the size and synchronous resize mode setting.

BUG=1097816

Change-Id: I41890ab7586cfdbc9df04d4b08b1d3701e98f1ca
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2540846
Commit-Queue: Dave Tapuska <dtapuska@chromium.org>
Reviewed-by: default avatardanakj <danakj@chromium.org>
Cr-Commit-Position: refs/heads/master@{#828603}
parent 94737673
......@@ -535,6 +535,10 @@ float WebFrameWidgetBase::DIPsToBlinkSpace(float scalar) {
return widget_base_->DIPsToBlinkSpace(scalar);
}
gfx::Size WebFrameWidgetBase::DIPsToCeiledBlinkSpace(const gfx::Size& size) {
return widget_base_->DIPsToCeiledBlinkSpace(size);
}
void WebFrameWidgetBase::SetActive(bool active) {
View()->SetIsActive(active);
}
......@@ -1094,10 +1098,12 @@ void WebFrameWidgetBase::UpdateVisualProperties(
// https://developer.mozilla.org/en-US/docs/Web/CSS/@media/display-mode
SetDisplayMode(visual_properties.display_mode);
SetAutoResizeMode(visual_properties.auto_resize_enabled,
visual_properties.min_size_for_auto_resize,
visual_properties.max_size_for_auto_resize,
visual_properties.screen_info.device_scale_factor);
if (ForMainFrame()) {
SetAutoResizeMode(visual_properties.auto_resize_enabled,
visual_properties.min_size_for_auto_resize,
visual_properties.max_size_for_auto_resize,
visual_properties.screen_info.device_scale_factor);
}
bool capture_sequence_number_changed =
visual_properties.capture_sequence_number !=
......@@ -1282,6 +1288,10 @@ void WebFrameWidgetBase::SynchronouslyCompositeForTesting(
widget_base_->LayerTreeHost()->CompositeForTest(frame_time, false);
}
void WebFrameWidgetBase::UseSynchronousResizeModeForTesting(bool enable) {
main_data().synchronous_resize_mode_for_testing = enable;
}
// TODO(665924): Remove direct dispatches of mouse events from
// PointerLockController, instead passing them through EventHandler.
void WebFrameWidgetBase::PointerLockMouseEvent(
......@@ -1416,6 +1426,44 @@ void WebFrameWidgetBase::SetZoomLevel(double zoom_level) {
zoom_level));
}
void WebFrameWidgetBase::SetAutoResizeMode(bool auto_resize,
const gfx::Size& min_window_size,
const gfx::Size& max_window_size,
float device_scale_factor) {
// Auto resize only applies to main frames.
DCHECK(ForMainFrame());
if (auto_resize) {
if (!Platform::Current()->IsUseZoomForDSFEnabled())
device_scale_factor = 1.f;
View()->EnableAutoResizeMode(
gfx::ScaleToCeiledSize(min_window_size, device_scale_factor),
gfx::ScaleToCeiledSize(max_window_size, device_scale_factor));
} else if (AutoResizeMode()) {
View()->DisableAutoResizeMode();
}
}
void WebFrameWidgetBase::DidAutoResize(const gfx::Size& size) {
DCHECK(ForMainFrame());
gfx::Size size_in_dips = widget_base_->BlinkSpaceToFlooredDIPs(size);
size_ = size;
if (main_data().synchronous_resize_mode_for_testing) {
gfx::Rect new_pos(widget_base_->WindowRect());
new_pos.set_size(size_in_dips);
SetScreenRects(new_pos, new_pos);
}
// TODO(ccameron): Note that this destroys any information differentiating
// |size| from the compositor's viewport size.
gfx::Rect size_with_dsf = gfx::Rect(gfx::ScaleToCeiledSize(
gfx::Rect(size_in_dips).size(),
widget_base_->GetScreenInfo().device_scale_factor));
widget_base_->LayerTreeHost()->RequestNewLocalSurfaceId();
widget_base_->UpdateCompositorViewportRect(size_with_dsf);
}
LocalFrame* WebFrameWidgetBase::FocusedLocalFrameInWidget() const {
if (!local_root_) {
// WebFrameWidget is created in the call to CreateFrame. The corresponding
......@@ -3248,6 +3296,10 @@ HitTestResult WebFrameWidgetBase::HitTestResultForRootFramePos(
return result;
}
bool WebFrameWidgetBase::SynchronousResizeModeForTestingEnabled() {
return main_data().synchronous_resize_mode_for_testing;
}
KURL WebFrameWidgetBase::GetURLForDebugTrace() {
WebFrame* main_frame = View()->MainFrame();
if (main_frame->IsWebLocalFrame())
......
......@@ -501,10 +501,13 @@ class CORE_EXPORT WebFrameWidgetBase
// Enable or disable auto-resize. This is part of
// UpdateVisualProperties though tests may call to it more directly.
virtual void SetAutoResizeMode(bool auto_resize,
const gfx::Size& min_size_before_dsf,
const gfx::Size& max_size_before_dsf,
float device_scale_factor) = 0;
void SetAutoResizeMode(bool auto_resize,
const gfx::Size& min_size_before_dsf,
const gfx::Size& max_size_before_dsf,
float device_scale_factor);
// Called when the View has auto resized.
void DidAutoResize(const gfx::Size& size);
// This method returns the focused frame belonging to this WebWidget, that
// is, a focused frame with the same local root as the one corresponding
......@@ -571,6 +574,15 @@ class CORE_EXPORT WebFrameWidgetBase
// BeginMainFrame, and update the document lifecycle.
void SynchronouslyCompositeForTesting(base::TimeTicks frame_time);
// Adjust the synchronous resize mode for testing. Normally resizes are
// asynchronous with sending the resize to the browser, however some tests
// still need the resize to happen in a synchronous fashion.
void UseSynchronousResizeModeForTesting(bool enable);
// Converts from DIPs to Blink coordinate space (ie. Viewport/Physical
// pixels).
gfx::Size DIPsToCeiledBlinkSpace(const gfx::Size& size);
void SetToolTipText(const String& tooltip_text, TextDirection dir);
void ShowVirtualKeyboardOnElementFocus();
......@@ -711,6 +723,9 @@ class CORE_EXPORT WebFrameWidgetBase
HitTestResult HitTestResultForRootFramePos(
const FloatPoint& pos_in_root_frame);
// Returns the current state of synchronous resize mode for testing.
bool SynchronousResizeModeForTestingEnabled();
// A copy of the web drop data object we received from the browser.
Member<DataObject> current_drag_data_;
......@@ -744,6 +759,10 @@ class CORE_EXPORT WebFrameWidgetBase
// base class.
Member<HTMLPlugInElement> mouse_capture_element_;
// The size of the widget in viewport coordinates. This is slightly different
// than the WebViewImpl::size_ since isn't set in auto resize mode.
base::Optional<gfx::Size> size_;
private:
// PageWidgetEventHandler methods:
WebInputEventResult HandleKeyEvent(const WebKeyboardEvent&) override;
......@@ -879,6 +898,20 @@ class CORE_EXPORT WebFrameWidgetBase
// contents") like a <webview> or <portal> widget. If false, the widget is
// the top level widget.
bool is_for_nested_main_frame = false;
// In web tests, synchronous resizing mode may be used. Normally each
// widget's size is controlled by IPC from the browser. In synchronous
// resize mode the renderer controls the size directly, and IPCs from the
// browser must be ignored. This was deprecated but then later undeprecated,
// so it is now called unfortunate instead. See https://crbug.com/309760.
// When this is enabled the various size properties will be controlled
// directly when SetWindowRect() is called instead of needing a round trip
// through the browser. Note that SetWindowRectSynchronouslyForTesting()
// provides a secondary way to control the size of the FrameWidget
// independently from the renderer process, without the use of this mode,
// however it would be overridden by the browser if they disagree.
bool synchronous_resize_mode_for_testing = false;
} main_frame_data_;
MainFrameData& main_data() {
......
......@@ -486,13 +486,6 @@ void WebFrameWidgetImpl::SetRootLayer(scoped_refptr<cc::Layer> layer) {
widget_base_->LayerTreeHost()->SetRootLayer(layer);
}
void WebFrameWidgetImpl::SetAutoResizeMode(bool auto_resize,
const gfx::Size& min_size_before_dsf,
const gfx::Size& max_size_before_dsf,
float device_scale_factor) {
// Auto resize mode only exists on the top level widget.
}
void WebFrameWidgetImpl::DidCreateLocalRootView() {
// If this WebWidget still hasn't received its size from the embedder, block
// the parser. This is necessary, because the parser can cause layout to
......
......@@ -101,10 +101,6 @@ class WebFrameWidgetImpl final : public WebFrameWidgetBase {
// WebFrameWidgetBase overrides:
void DidCreateLocalRootView() override;
void SetAutoResizeMode(bool auto_resize,
const gfx::Size& min_size_before_dsf,
const gfx::Size& max_size_before_dsf,
float device_scale_factor) override;
void ApplyVisualPropertiesSizing(
const VisualProperties& visual_properties) override;
......@@ -133,8 +129,6 @@ class WebFrameWidgetImpl final : public WebFrameWidgetBase {
PhysicalRect& rect_to_scroll,
mojom::blink::ScrollIntoViewParamsPtr& params);
base::Optional<gfx::Size> size_;
bool did_suspend_parsing_ = false;
SelfKeepAlive<WebFrameWidgetImpl> self_keep_alive_;
......
......@@ -106,7 +106,7 @@ bool WebViewFrameWidget::ShouldHandleImeEvents() {
}
void WebViewFrameWidget::SetWindowRect(const gfx::Rect& window_rect) {
if (synchronous_resize_mode_for_testing_) {
if (SynchronousResizeModeForTestingEnabled()) {
// This is a web-test-only path. At one point, it was planned to be
// removed. See https://crbug.com/309760.
SetWindowRectSynchronously(window_rect);
......@@ -319,21 +319,6 @@ WebInputEventResult WebViewFrameWidget::HandleGestureEvent(
return event_result;
}
void WebViewFrameWidget::SetAutoResizeMode(bool auto_resize,
const gfx::Size& min_window_size,
const gfx::Size& max_window_size,
float device_scale_factor) {
if (auto_resize) {
if (!Platform::Current()->IsUseZoomForDSFEnabled())
device_scale_factor = 1.f;
web_view_->EnableAutoResizeMode(
gfx::ScaleToCeiledSize(min_window_size, device_scale_factor),
gfx::ScaleToCeiledSize(max_window_size, device_scale_factor));
} else if (web_view_->AutoResizeMode()) {
web_view_->DisableAutoResizeMode();
}
}
void WebViewFrameWidget::SetPageScaleStateAndLimits(
float page_scale_factor,
bool is_pinch_gesture_active,
......@@ -352,25 +337,6 @@ void WebViewFrameWidget::SetPageScaleStateAndLimits(
NotifyPageScaleFactorChanged(page_scale_factor, is_pinch_gesture_active);
}
void WebViewFrameWidget::DidAutoResize(const gfx::Size& size) {
gfx::Size size_in_dips = widget_base_->BlinkSpaceToFlooredDIPs(size);
size_ = size;
if (synchronous_resize_mode_for_testing_) {
gfx::Rect new_pos(widget_base_->WindowRect());
new_pos.set_size(size_in_dips);
SetScreenRects(new_pos, new_pos);
}
// TODO(ccameron): Note that this destroys any information differentiating
// |size| from the compositor's viewport size.
gfx::Rect size_with_dsf = gfx::Rect(gfx::ScaleToCeiledSize(
gfx::Rect(size_in_dips).size(),
widget_base_->GetScreenInfo().device_scale_factor));
widget_base_->LayerTreeHost()->RequestNewLocalSurfaceId();
widget_base_->UpdateCompositorViewportRect(size_with_dsf);
}
void WebViewFrameWidget::SetDeviceColorSpaceForTesting(
const gfx::ColorSpace& color_space) {
// We are changing the device color space from the renderer, so allocate a
......@@ -412,14 +378,6 @@ void WebViewFrameWidget::SetWindowRectSynchronously(
widget_base_->SetScreenRects(new_window_rect, new_window_rect);
}
void WebViewFrameWidget::UseSynchronousResizeModeForTesting(bool enable) {
synchronous_resize_mode_for_testing_ = enable;
}
gfx::Size WebViewFrameWidget::DIPsToCeiledBlinkSpace(const gfx::Size& size) {
return widget_base_->DIPsToCeiledBlinkSpace(size);
}
void WebViewFrameWidget::ApplyVisualPropertiesSizing(
const VisualProperties& visual_properties) {
if (size_ !=
......@@ -438,7 +396,7 @@ void WebViewFrameWidget::ApplyVisualPropertiesSizing(
// We can ignore browser-initialized resizing during synchronous
// (renderer-controlled) mode, unless it is switching us to/from
// fullsreen mode or changing the device scale factor.
bool ignore_resize = synchronous_resize_mode_for_testing_;
bool ignore_resize = SynchronousResizeModeForTestingEnabled();
if (ignore_resize) {
// TODO(danakj): Does the browser actually change DSF inside a web test??
// TODO(danakj): Isn't the display mode check redundant with the
......@@ -460,7 +418,7 @@ void WebViewFrameWidget::ApplyVisualPropertiesSizing(
visual_properties.compositor_viewport_pixel_rect;
if (AutoResizeMode()) {
new_compositor_viewport_pixel_rect = gfx::Rect(gfx::ScaleToCeiledSize(
widget_base_->BlinkSpaceToFlooredDIPs(size_),
widget_base_->BlinkSpaceToFlooredDIPs(size_.value_or(gfx::Size())),
visual_properties.screen_info.device_scale_factor));
}
......@@ -478,7 +436,7 @@ void WebViewFrameWidget::ApplyVisualPropertiesSizing(
size_ = widget_base_->DIPsToCeiledBlinkSpace(visual_properties.new_size);
View()->ResizeWithBrowserControls(
size_,
size_.value(),
widget_base_->DIPsToCeiledBlinkSpace(
widget_base_->VisibleViewportSizeInDIPs()),
visual_properties.browser_controls_params);
......
......@@ -70,10 +70,6 @@ class CORE_EXPORT WebViewFrameWidget : public WebFrameWidgetBase {
bool ScrollFocusedEditableElementIntoView() override;
// WebFrameWidgetBase overrides:
void SetAutoResizeMode(bool auto_resize,
const gfx::Size& min_size_before_dsf,
const gfx::Size& max_size_before_dsf,
float device_scale_factor) override;
void SetPageScaleStateAndLimits(float page_scale_factor,
bool is_pinch_gesture_active,
float minimum,
......@@ -88,15 +84,9 @@ class CORE_EXPORT WebViewFrameWidget : public WebFrameWidgetBase {
// WidgetBaseClient overrides:
void FocusChanged(bool enabled) override;
void DidAutoResize(const gfx::Size& size);
void SetDeviceColorSpaceForTesting(const gfx::ColorSpace& color_space);
void SetWindowRect(const gfx::Rect& window_rect);
void SetWindowRectSynchronouslyForTesting(const gfx::Rect& new_window_rect);
void UseSynchronousResizeModeForTesting(bool enable);
// Converts from DIPs to Blink coordinate space (ie. Viewport/Physical
// pixels).
gfx::Size DIPsToCeiledBlinkSpace(const gfx::Size& size);
private:
// PageWidgetEventHandler overrides:
......@@ -107,24 +97,6 @@ class CORE_EXPORT WebViewFrameWidget : public WebFrameWidgetBase {
scoped_refptr<WebViewImpl> web_view_;
// In web tests, synchronous resizing mode may be used. Normally each widget's
// size is controlled by IPC from the browser. In synchronous resize mode the
// renderer controls the size directly, and IPCs from the browser must be
// ignored. This was deprecated but then later undeprecated, so it is now
// called unfortunate instead. See https://crbug.com/309760. When this is
// enabled the various size properties will be controlled directly when
// SetWindowRect() is called instead of needing a round trip through the
// browser.
// Note that SetWindowRectSynchronouslyForTesting() provides a secondary way
// to control the size of the FrameWidget independently from the renderer
// process, without the use of this mode, however it would be overridden by
// the browser if they disagree.
bool synchronous_resize_mode_for_testing_ = false;
// The size of the widget in viewport coordinates. This is slightly different
// than the WebViewImpl::size_ since isn't set in auto resize mode.
gfx::Size size_;
// This stores the last hidden page popup. If a GestureTap attempts to open
// the popup that is closed by its previous GestureTapDown, the popup remains
// closed.
......
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