Commit 9b8af72a authored by Thomas Lukaszewicz's avatar Thomas Lukaszewicz Committed by Commit Bot

Fixed web frame views not triggering Layout in fullscreen on Mac

WebAppFrameToolbarView now invalidates its layout when in fullscreen
on Mac, necessary since the frame needs to layout toolbar buttons and
remains visible in Mac's fullscreen mode.

Fixed a related FindBar bug incorrectly anchoring to the web app
frame when the frame was not visible.

Bug: 1063304
Change-Id: Ic6ae3ffbeaa32bd548bcf010f3218455073d7afc
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2176603
Commit-Queue: Thomas Lukaszewicz <tluk@chromium.org>
Reviewed-by: default avatarPeter Kasting <pkasting@chromium.org>
Cr-Commit-Position: refs/heads/master@{#798181}
parent 94be7a81
......@@ -214,8 +214,13 @@ void BrowserNonClientFrameViewMac::UpdateFullscreenTopUI() {
browser_view()->browser()->FullscreenTopUIStateChanged();
// Re-layout if toolbar style changes in fullscreen mode.
if (frame()->IsFullscreen())
if (frame()->IsFullscreen()) {
browser_view()->Layout();
// The web frame toolbar is visible in fullscreen mode on Mac and thus
// requires a re-layout when in fullscreen.
if (web_app_frame_toolbar())
InvalidateLayout();
}
}
bool BrowserNonClientFrameViewMac::ShouldHideTopUIForFullscreen() const {
......
......@@ -9,16 +9,20 @@
#include "chrome/browser/ui/browser_commands.h"
#include "chrome/browser/ui/tabs/tab_strip_model.h"
#include "chrome/browser/ui/view_ids.h"
#include "chrome/browser/ui/views/frame/browser_non_client_frame_view.h"
#include "chrome/browser/ui/views/frame/browser_view.h"
#include "chrome/browser/ui/web_applications/web_app_controller_browsertest.h"
#include "chrome/browser/web_applications/test/web_app_test.h"
#include "chrome/common/pref_names.h"
#include "chrome/test/base/ui_test_utils.h"
#include "components/prefs/pref_service.h"
#include "content/public/test/browser_test.h"
#include "content/public/test/browser_test_utils.h"
#include "net/test/embedded_test_server/embedded_test_server.h"
#include "ui/base/test/scoped_fake_nswindow_fullscreen.h"
#include "ui/views/controls/label.h"
#include "ui/views/view.h"
#include "ui/views/view_test_api.h"
#include "ui/views/widget/widget.h"
#include "ui/views/window/non_client_view.h"
#include "url/gurl.h"
......@@ -114,6 +118,43 @@ IN_PROC_BROWSER_TEST_P(BrowserNonClientFrameViewMacBrowserTest, TitleUpdates) {
}
}
// Test to make sure the WebAppToolbarFrame triggers an InvalidateLayout() when
// toggled in fullscreen mode.
IN_PROC_BROWSER_TEST_P(BrowserNonClientFrameViewMacBrowserTest,
ToolbarLayoutFullscreenTransition) {
ui::test::ScopedFakeNSWindowFullscreen fake_fullscreen;
const GURL app_url = GetInstallableAppURL();
const web_app::AppId app_id = InstallPWA(app_url);
Browser* const browser = LaunchWebAppBrowser(app_id);
BrowserView* browser_view = BrowserView::GetBrowserViewForBrowser(browser);
BrowserNonClientFrameView* const frame_view =
static_cast<BrowserNonClientFrameView*>(
browser_view->GetWidget()->non_client_view()->frame_view());
// Trigger a layout on the view tree to address any invalid layouts waiting
// for a re-layout.
views::ViewTestApi frame_view_test_api(frame_view);
browser_view->GetWidget()->LayoutRootViewIfNecessary();
// Assert that the layout of the frame view is in a valid state.
EXPECT_FALSE(frame_view_test_api.needs_layout());
PrefService* prefs = browser->profile()->GetPrefs();
prefs->SetBoolean(prefs::kShowFullscreenToolbar, false);
chrome::ToggleFullscreenMode(browser);
fake_fullscreen.FinishTransition();
EXPECT_FALSE(frame_view_test_api.needs_layout());
prefs->SetBoolean(prefs::kShowFullscreenToolbar, true);
// Showing the toolbar in fullscreen mode should trigger a layout
// invalidation.
EXPECT_TRUE(frame_view_test_api.needs_layout());
}
INSTANTIATE_TEST_SUITE_P(All,
BrowserNonClientFrameViewMacBrowserTest,
::testing::Values(ProviderType::kBookmarkApps,
......
......@@ -797,6 +797,8 @@ WebAppFrameToolbarView::WebAppFrameToolbarView(views::Widget* widget,
SetID(VIEW_ID_WEB_APP_FRAME_TOOLBAR);
{
// TODO(tluk) fix the need for both LayoutInContainer() and a layout
// manager for frame layout.
views::FlexLayout* layout =
SetLayoutManager(std::make_unique<views::FlexLayout>());
layout->SetOrientation(views::LayoutOrientation::kHorizontal);
......@@ -876,6 +878,8 @@ std::pair<int, int> WebAppFrameToolbarView::LayoutInContainer(
int trailing_x,
int y,
int available_height) {
SetVisible(available_height > 0);
if (available_height == 0) {
SetSize(gfx::Size());
return std::pair<int, int>(0, 0);
......
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