Commit 578e97f1 authored by Collin Baker's avatar Collin Baker Committed by Commit Bot

Open WebUI tab strip by default

When a new window is opened in touch mode, or any windows switch to
touch mode, the tab strip starts open.

Fixed: 1028384
Change-Id: Ie50c4df7725ebe4841d29ba84382638418df2f2d
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1941057
Commit-Queue: Collin Baker <collinbaker@chromium.org>
Commit-Queue: Peter Boström <pbos@chromium.org>
Reviewed-by: default avatarPeter Boström <pbos@chromium.org>
Cr-Commit-Position: refs/heads/master@{#721074}
parent e8f4ee13
......@@ -34,6 +34,7 @@
#include "chrome/grit/generated_resources.h"
#include "ui/aura/window.h"
#include "ui/base/l10n/l10n_util.h"
#include "ui/gfx/animation/tween.h"
#include "ui/gfx/color_palette.h"
#include "ui/gfx/paint_vector_icon.h"
#include "ui/views/background.h"
......@@ -111,13 +112,16 @@ WebUITabStripContainerView::WebUITabStripContainerView(
DCHECK(UseTouchableTabStrip());
animation_.SetTweenType(gfx::Tween::Type::FAST_OUT_SLOW_IN);
SetVisible(false);
// TODO(crbug.com/1010589) WebContents are initially assumed to be visible by
// default unless explicitly hidden. The WebContents need to be set to hidden
// so that the visibility state of the document in JavaScript is correctly
// initially set to 'hidden', and the 'visibilitychange' events correctly get
// fired.
web_view_->GetWebContents()->WasHidden();
// Our observed Widget's NativeView may be destroyed before us. We
// have no reasonable way of un-registering our pre-target handler
// from the NativeView while the Widget is destroying. This disables
// EventHandler's check that it has been removed from all
// EventTargets.
auto_closer_->DisableCheckTargets();
SetVisible(true);
animation_.Reset(1.0);
auto_closer_->set_enabled(true);
web_view_->set_allow_accelerators(true);
......@@ -137,13 +141,6 @@ WebUITabStripContainerView::WebUITabStripContainerView(
TabStripUI* const tab_strip_ui = static_cast<TabStripUI*>(
web_view_->GetWebContents()->GetWebUI()->GetController());
tab_strip_ui->Initialize(browser_, this);
// Our observed Widget's NativeView may be destroyed before us. We
// have no reasonable way of un-registering our pre-target handler
// from the NativeView while the Widget is destroying. This disables
// EventHandler's check that it has been removed from all
// EventTargets.
auto_closer_->DisableCheckTargets();
}
WebUITabStripContainerView::~WebUITabStripContainerView() {
......@@ -280,6 +277,7 @@ void WebUITabStripContainerView::CloseForEventOutsideTabStrip() {
void WebUITabStripContainerView::AnimationEnded(
const gfx::Animation* animation) {
DCHECK_EQ(&animation_, animation);
PreferredSizeChanged();
if (animation_.GetCurrentValue() == 0.0)
SetVisible(false);
}
......@@ -319,7 +317,13 @@ void WebUITabStripContainerView::RemovedFromWidget() {
}
int WebUITabStripContainerView::GetHeightForWidth(int w) const {
return desired_height_ * animation_.GetCurrentValue();
if (!GetVisible())
return 0;
if (!animation_.is_animating())
return desired_height_;
return gfx::Tween::LinearIntValueBetween(animation_.GetCurrentValue(), 0,
desired_height_);
}
void WebUITabStripContainerView::ButtonPressed(views::Button* sender,
......
// Copyright 2019 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "chrome/browser/ui/views/frame/webui_tab_strip_container_view.h"
#include "base/command_line.h"
#include "chrome/browser/ui/views/frame/browser_view.h"
#include "chrome/browser/ui/views/frame/test_with_browser_view.h"
#include "chrome/common/chrome_switches.h"
#include "ui/base/test/material_design_controller_test_api.h"
#include "ui/base/ui_base_switches.h"
class WebUITabStripContainerViewTest : public TestWithBrowserView {
public:
WebUITabStripContainerViewTest() : touch_mode_(true) {
// Both the switch and |touch_mode_| are necessary since
// MaterialDesignController::Initialize() gets called at different
// times on different platforms.
base::CommandLine::ForCurrentProcess()->AppendSwitchASCII(
switches::kTopChromeTouchUi, switches::kTopChromeTouchUiEnabled);
base::CommandLine::ForCurrentProcess()->AppendSwitch(
switches::kWebUITabStrip);
}
~WebUITabStripContainerViewTest() override = default;
private:
ui::test::MaterialDesignControllerTestAPI touch_mode_;
};
TEST_F(WebUITabStripContainerViewTest, TabStripStartsOpen) {
EXPECT_TRUE(WebUITabStripContainerView::UseTouchableTabStrip());
ASSERT_NE(nullptr, browser_view()->webui_tab_strip());
EXPECT_TRUE(browser_view()->webui_tab_strip()->GetVisible());
}
TEST_F(WebUITabStripContainerViewTest, TouchModeTransition) {
EXPECT_TRUE(WebUITabStripContainerView::UseTouchableTabStrip());
EXPECT_NE(nullptr, browser_view()->webui_tab_strip());
EXPECT_FALSE(browser_view()->IsTabStripVisible());
ui::test::MaterialDesignControllerTestAPI disable_touch_mode(false);
browser_view()->Layout();
EXPECT_FALSE(WebUITabStripContainerView::UseTouchableTabStrip());
EXPECT_TRUE(browser_view()->IsTabStripVisible());
ui::test::MaterialDesignControllerTestAPI reenable_touch_mode(true);
browser_view()->Layout();
EXPECT_TRUE(WebUITabStripContainerView::UseTouchableTabStrip());
EXPECT_FALSE(browser_view()->IsTabStripVisible());
WebUITabStripContainerView* const container =
browser_view()->webui_tab_strip();
ASSERT_NE(nullptr, container);
EXPECT_TRUE(container->GetVisible());
}
......@@ -3,7 +3,6 @@
// found in the LICENSE file.
#include "base/strings/utf_string_conversions.h"
#include "base/test/scoped_feature_list.h"
#include "chrome/browser/ui/ui_features.h"
#include "chrome/browser/ui/view_ids.h"
#include "chrome/browser/ui/views/frame/browser_view.h"
......@@ -14,6 +13,7 @@
#include "chrome/common/chrome_switches.h"
#include "chrome/test/base/in_process_browser_test.h"
#include "chrome/test/base/interactive_test_utils.h"
#include "ui/base/test/material_design_controller_test_api.h"
#include "ui/base/ui_base_switches.h"
#include "ui/views/controls/webview/webview.h"
......@@ -26,8 +26,7 @@ class WebUITabStripInteractiveTest : public InProcessBrowserTest {
switches::kWebUITabStrip);
}
private:
base::test::ScopedFeatureList feature_override_;
~WebUITabStripInteractiveTest() override = default;
};
// Regression test for crbug.com/1027375.
......@@ -36,21 +35,24 @@ IN_PROC_BROWSER_TEST_F(WebUITabStripInteractiveTest,
BrowserView* const browser_view =
BrowserView::GetBrowserViewForBrowser(browser());
WebUITabStripContainerView* const container = browser_view->webui_tab_strip();
// Open the tab strip.
container->SetVisibleForTesting(true);
ASSERT_NE(nullptr, container);
container->SetVisibleForTesting(false);
browser_view->Layout();
// Make sure the tab strip's contents are fully loaded.
views::WebView* const container_web_view = container->web_view_for_testing();
ASSERT_TRUE(WaitForLoadStop(container_web_view->GetWebContents()));
ui_test_utils::FocusView(browser(), VIEW_ID_OMNIBOX);
EXPECT_TRUE(ui_test_utils::IsViewFocused(browser(), VIEW_ID_OMNIBOX));
OmniboxViewViews* const omnibox =
browser_view->toolbar()->location_bar()->omnibox_view();
omnibox->SetUserText(base::ASCIIToUTF16(""));
container->SetVisibleForTesting(true);
browser_view->Layout();
// Make sure the tab strip's contents are fully loaded.
views::WebView* const container_web_view = container->web_view_for_testing();
ASSERT_TRUE(WaitForLoadStop(container_web_view->GetWebContents()));
// Click in tab strip, then close it.
base::RunLoop click_loop;
ui_test_utils::MoveMouseToCenterAndPress(
......
......@@ -5227,6 +5227,7 @@ test("unit_tests") {
if (enable_webui_tab_strip) {
sources += [
"../browser/ui/views/frame/webui_tab_strip_container_view_unittest.cc",
"../browser/ui/webui/tab_strip/tab_strip_ui_layout_unittest.cc",
"../browser/ui/webui/tab_strip/thumbnail_tracker_unittest.cc",
]
......
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