Commit faa32d27 authored by Ahmed Fakhry's avatar Ahmed Fakhry Committed by Commit Bot

top-chrome slide: set shown ratio for main frame widget only

Opening a drop-down menu in a webpage will create a new
RenderWidget with a new LayerTreeHostImpl, whose value
of the top_controls_shown_ratio_ (initialized to 0) will
be pushed to the browser when a new compositor frame is
generated. This will cause top-chrome to hide briefly
on opening the menu which will result in closing the
menu immediately.

This CL fixes the issue by allowing only the main frame
widget to set the shown ratio.

BUG=891471
TEST=Manual, added a new browser test.

Change-Id: I8ead7f903d56e68523a7654abc21aa6e5ca7b690
Reviewed-on: https://chromium-review.googlesource.com/c/1258348Reviewed-by: default avatarDavid Bokan <bokan@chromium.org>
Reviewed-by: default avatarScott Violet <sky@chromium.org>
Commit-Queue: Ahmed Fakhry <afakhry@chromium.org>
Cr-Commit-Position: refs/heads/master@{#597146}
parent b9795a6f
......@@ -34,6 +34,7 @@
#include "services/service_manager/public/cpp/connector.h"
#include "ui/aura/window.h"
#include "ui/aura/window_tree_host.h"
#include "ui/base/ui_base_features.h"
#include "ui/display/display.h"
#include "ui/events/test/event_generator.h"
#include "ui/gfx/geometry/rect.h"
......@@ -836,6 +837,56 @@ class PageStateUpdateWaiter : content::WebContentsObserver {
DISALLOW_COPY_AND_ASSIGN(PageStateUpdateWaiter);
};
// Verifies that we ignore the shown ratios sent from widgets other than that of
// the main frame (such as widgets of the drop-down menus in web pages).
// https://crbug.com/891471.
IN_PROC_BROWSER_TEST_F(TopControlsSlideControllerTest, TestDropDowns) {
browser_view()->frame()->Maximize();
ToggleTabletMode();
ASSERT_TRUE(GetTabletModeEnabled());
EXPECT_TRUE(top_controls_slide_controller()->IsEnabled());
EXPECT_FLOAT_EQ(top_controls_slide_controller()->GetShownRatio(), 1.f);
OpenUrlAtIndex(embedded_test_server()->GetURL("/top_controls_scroll.html"),
0);
// On mash, use nullptr root windows to route events over mojo to ash.
aura::Window* browser_window = browser()->window()->GetNativeWindow();
ui::test::EventGenerator event_generator(
features::IsUsingWindowService() ? nullptr
: browser_window->GetRootWindow());
// Send a mouse click event that should open the popup drop-down menu of the
// <select> html element on the page.
// Note that if a non-main-frame widget is created, its LayerTreeHostImpl's
// `top_controls_shown_ratio_` (which is initialized to 0.f) will be sent to
// the browser when a new compositor frame gets generated. If this shown ratio
// value is not ignored, top-chrome will immediately hide, which will result
// in a BrowserView's Layout() and the immediate closure of the drop-down
// menu.
// We verify below that this doesn't happen, the menu remains open, and it's
// possible to select another option in the drop-down menu.
content::WebContents* contents =
browser()->tab_strip_model()->GetActiveWebContents();
PageStateUpdateWaiter page_state_update_waiter(contents);
event_generator.MoveMouseTo(54, 173);
event_generator.ClickLeftButton();
page_state_update_waiter.Wait();
// Verify that the element has been focused.
EXPECT_EQ(true, content::EvalJs(contents, "selectFocused;"));
// Now send a mouse click event that should select the forth option in the
// drop-down menu.
event_generator.MoveMouseTo(54, 300);
event_generator.ClickLeftButton();
// Verify that the selected option has changed and the forth option is
// selected.
EXPECT_EQ(true, content::EvalJs(contents, "selectChanged;"));
EXPECT_EQ("4", content::EvalJs(contents, "getSelectedValue();"));
}
IN_PROC_BROWSER_TEST_F(TopControlsSlideControllerTest,
TestScrollingMaximizedPageBeforeGoingToTabletMode) {
// If the page exists in a maximized browser window before going to tablet
......
......@@ -10,9 +10,19 @@
background: linear-gradient(cyan, cyan 50%, blue 50%, blue);
background-size: 100% 200px;
}
select {
width: 100%;
height: 100px;
}
</style>
</head>
<body>
<select id="select">
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
</select>
<h1>Browser Top Controls Scrolls Test Page</h1>
<p>
This page is used to test the browser top controls scroll behavior with page
......@@ -20,5 +30,28 @@
</p>
<input id="editable-element" type="text">
<div></div>
<script>
let selectFocused = false;
let selectChanged = false;
let selectElement = document.getElementById('select');
selectElement.onfocus = function() {
selectFocused = true;
};
selectElement.onblur = function() {
selectFocused = false;
};
selectElement.onchange = function() {
selectChanged = true;
};
function getSelectedValue() {
return selectElement.options[selectElement.selectedIndex].value;
}
</script>
</body>
</html>
......@@ -58,7 +58,9 @@ class CONTENT_EXPORT RenderWidgetHostDelegate {
public:
// Functions for controlling the browser top controls slide behavior with page
// gesture scrolling.
virtual void SetTopControlsShownRatio(float ratio) {}
virtual void SetTopControlsShownRatio(
RenderWidgetHostImpl* render_widget_host,
float ratio) {}
virtual bool DoBrowserControlsShrinkRendererSize() const;
virtual int GetTopControlsHeight() const;
virtual void SetTopControlsGestureScrollInProgress(bool in_progress) {}
......
......@@ -2116,7 +2116,7 @@ void RenderWidgetHostViewAura::OnDidUpdateVisualPropertiesComplete(
if (host()->delegate()) {
host()->delegate()->SetTopControlsShownRatio(
metadata.top_controls_shown_ratio);
host(), metadata.top_controls_shown_ratio);
}
SynchronizeVisualProperties(cc::DeadlinePolicy::UseDefaultDeadline(),
......
......@@ -2143,9 +2143,17 @@ ukm::SourceId WebContentsImpl::GetUkmSourceIdForLastCommittedSource() const {
return last_committed_source_id_;
}
void WebContentsImpl::SetTopControlsShownRatio(float ratio) {
if (delegate_)
delegate_->SetTopControlsShownRatio(this, ratio);
void WebContentsImpl::SetTopControlsShownRatio(
RenderWidgetHostImpl* render_widget_host,
float ratio) {
if (!delegate_)
return;
RenderFrameHostImpl* rfh = GetMainFrame();
if (!rfh || render_widget_host != rfh->GetRenderWidgetHost())
return;
delegate_->SetTopControlsShownRatio(this, ratio);
}
bool WebContentsImpl::DoBrowserControlsShrinkRendererSize() const {
......
......@@ -691,7 +691,8 @@ class CONTENT_EXPORT WebContentsImpl : public WebContents,
// RenderWidgetHostDelegate --------------------------------------------------
ukm::SourceId GetUkmSourceIdForLastCommittedSource() const override;
void SetTopControlsShownRatio(float ratio) override;
void SetTopControlsShownRatio(RenderWidgetHostImpl* render_widget_host,
float ratio) override;
bool DoBrowserControlsShrinkRendererSize() const override;
int GetTopControlsHeight() const override;
void SetTopControlsGestureScrollInProgress(bool in_progress) override;
......
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