0

Convert MaterialDesignController to a true singleton.

This involves
* Moving non-MD-related code out of Initialize into LinearAnimation
* Moving other Initialize() code into the constructor
* Removing all Initialize() calls
* Replacing other static methods with instance methods
* Adding GetInstance() calls to callers to get the instance
* Converting the TestAPI class to a scoping object
* Other assorted #include removal etc. in the process

Bug: 940773
Change-Id: Ieb8d44eabae63b014a90ff452010eb4c067e5e90
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2090877
Commit-Queue: Peter Kasting <pkasting@chromium.org>
Reviewed-by: Scott Violet <sky@chromium.org>
Cr-Commit-Position: refs/heads/master@{#748895}
This commit is contained in:
Peter Kasting
2020-03-10 21:21:08 +00:00
committed by Commit Bot
parent 78256e6a6f
commit c6fd7f2db7
81 changed files with 252 additions and 484 deletions
ash
chrome
components/omnibox/browser
content
docs/testing
ui
weblayer/browser

@ -25,7 +25,6 @@
#include "ui/aura/window_tree_host.h"
#include "ui/base/layout.h"
#include "ui/base/ui_base_features.h"
#include "ui/base/ui_base_switches_util.h"
#include "ui/display/display_layout.h"
#include "ui/display/display_transform.h"
#include "ui/display/manager/display_layout_store.h"

@ -42,7 +42,6 @@
#include "ui/base/ime/init/input_method_factory.h"
#include "ui/base/l10n/l10n_util.h"
#include "ui/base/ui_base_features.h"
#include "ui/base/ui_base_switches_util.h"
#include "ui/compositor/compositor.h"
#include "ui/compositor/compositor_switches.h"
#include "ui/display/display.h"

@ -51,8 +51,6 @@
#include "ui/aura/test/test_windows.h"
#include "ui/aura/window.h"
#include "ui/base/ime/init/input_method_initializer.h"
#include "ui/base/material_design/material_design_controller.h"
#include "ui/base/ui_base_switches_util.h"
#include "ui/compositor/scoped_animation_duration_scale_mode.h"
#include "ui/compositor/test/test_context_factories.h"
#include "ui/display/display.h"
@ -145,8 +143,6 @@ void AshTestHelper::SetUp(const InitParams& init_params,
// last cursor visibility state, etc.
::wm::CursorManager::ResetCursorVisibilityStateForTest();
ui::MaterialDesignController::Initialize();
CreateShell(std::move(shell_init_params), init_params.local_state);
// Reset aura::Env to eliminate test dependency (https://crbug.com/586514).

@ -65,7 +65,6 @@
#include "printing/buildflags/buildflags.h"
#include "services/service_manager/embedder/switches.h"
#include "services/tracing/public/cpp/stack_sampling/tracing_sampler_profiler.h"
#include "ui/base/material_design/material_design_controller.h"
#include "ui/base/resource/resource_bundle.h"
#include "ui/base/ui_base_switches.h"
@ -1022,7 +1021,6 @@ void ChromeMainDelegate::PreSandboxStartup() {
base::i18n::SetICUDefaultLocale(locale);
const std::string loaded_locale = locale;
#else
ui::MaterialDesignController::Initialize();
const std::string loaded_locale =
ui::ResourceBundle::InitSharedInstanceWithLocale(
locale, NULL, ui::ResourceBundle::LOAD_COMMON_RESOURCES);

@ -13,7 +13,6 @@
#include "testing/gtest/include/gtest/gtest.h"
#include "ui/base/l10n/l10n_util.h"
#include "ui/base/material_design/material_design_controller.h"
#include "ui/base/resource/resource_bundle.h"
#include "ui/base/ui_base_paths.h"
@ -21,7 +20,6 @@ class ResourcesTest : public ::testing::Test {
protected:
ResourcesTest() {
ui::RegisterPathProvider();
ui::MaterialDesignController::Initialize();
ui::ResourceBundle::InitSharedInstanceWithLocale(
"en-US", nullptr, ui::ResourceBundle::LOAD_COMMON_RESOURCES);
}

@ -11,7 +11,6 @@
#include "base/test/task_environment.h"
#include "build/build_config.h"
#include "mojo/core/embedder/embedder.h"
#include "ui/base/material_design/material_design_controller.h"
#include "ui/base/resource/resource_bundle.h"
#include "ui/base/ui_base_paths.h"
@ -34,7 +33,6 @@ void ArTestSuite::Initialize() {
base::PathService::Get(ui::DIR_RESOURCE_PAKS_ANDROID, &pak_path);
ui::ResourceBundle::InitSharedInstanceWithPakPath(
pak_path.AppendASCII("vr_test.pak"));
ui::MaterialDesignController::Initialize();
}
void ArTestSuite::Shutdown() {

@ -32,7 +32,7 @@ TabletModePageBehavior::~TabletModePageBehavior() {
void TabletModePageBehavior::OnTabletModeToggled(bool enabled) {
SetMobileLikeBehaviorEnabled(enabled);
ui::MaterialDesignController::OnTabletModeToggled(enabled);
ui::MaterialDesignController::GetInstance()->OnTabletModeToggled(enabled);
}
void TabletModePageBehavior::OnTabletModeStarting() {

@ -331,7 +331,7 @@ gfx::ImageSkia GetBookmarkFolderIcon(SkColor text_color) {
.GetNativeImageNamed(resource_id)
.ToImageSkia();
#else
folder = GetFolderIcon(ui::MaterialDesignController::touch_ui()
folder = GetFolderIcon(ui::MaterialDesignController::GetInstance()->touch_ui()
? vector_icons::kFolderTouchIcon
: vector_icons::kFolderIcon,
text_color);
@ -352,7 +352,7 @@ gfx::ImageSkia GetBookmarkManagedFolderIcon(SkColor text_color) {
.GetNativeImageNamed(resource_id)
.ToImageSkia();
#else
folder = GetFolderIcon(ui::MaterialDesignController::touch_ui()
folder = GetFolderIcon(ui::MaterialDesignController::GetInstance()->touch_ui()
? vector_icons::kFolderManagedTouchIcon
: vector_icons::kFolderManagedIcon,
text_color);

@ -461,7 +461,7 @@ bool ContentSettingBlockedImageModel::UpdateAndGetVisibility(
const gfx::VectorIcon* icon = &image_details->icon;
// Touch mode uses a different tab audio icon.
if (image_details->content_type == ContentSettingsType::SOUND &&
ui::MaterialDesignController::touch_ui()) {
ui::MaterialDesignController::GetInstance()->touch_ui()) {
icon = &kTabAudioRoundedIcon;
}
set_icon(*icon, *badge_id);

@ -27,7 +27,7 @@ int GetCocoaLayoutConstant(LayoutConstant constant) {
#endif
int GetLayoutConstant(LayoutConstant constant) {
const bool touch_ui = ui::MaterialDesignController::touch_ui();
const bool touch_ui = ui::MaterialDesignController::GetInstance()->touch_ui();
switch (constant) {
case BOOKMARK_BAR_HEIGHT:
// The fixed margin ensures the bookmark buttons appear centered relative
@ -85,7 +85,7 @@ int GetLayoutConstant(LayoutConstant constant) {
}
gfx::Insets GetLayoutInsets(LayoutInset inset) {
const bool touch_ui = ui::MaterialDesignController::touch_ui();
const bool touch_ui = ui::MaterialDesignController::GetInstance()->touch_ui();
switch (inset) {
case LOCATION_BAR_ICON_INTERIOR_PADDING:
return touch_ui ? gfx::Insets(5, 10) : gfx::Insets(4, 8);

@ -15,7 +15,7 @@ constexpr int kSeparatorThickness = 1;
// Returns the height of the separator between tabs.
int GetSeparatorHeight() {
return ui::MaterialDesignController::touch_ui() ? 24 : 20;
return ui::MaterialDesignController::GetInstance()->touch_ui() ? 24 : 20;
}
} // namespace

@ -33,7 +33,6 @@
#include "extensions/browser/test_extension_registry_observer.h"
#include "extensions/common/extension.h"
#include "extensions/test/test_extension_dir.h"
#include "ui/base/test/material_design_controller_test_api.h"
namespace {
@ -143,7 +142,7 @@ class ToolbarActionErrorTestObserver
} // namespace
ToolbarActionsBarUnitTest::ToolbarActionsBarUnitTest()
: toolbar_model_(nullptr) {
: touch_ui_scoper_(GetParam()) {
// The ToolbarActionsBar is not used when kExtensionsToolbarMenu is enabled.
feature_list_.InitAndDisableFeature(features::kExtensionsToolbarMenu);
}
@ -151,10 +150,6 @@ ToolbarActionsBarUnitTest::ToolbarActionsBarUnitTest()
ToolbarActionsBarUnitTest::~ToolbarActionsBarUnitTest() {}
void ToolbarActionsBarUnitTest::SetUp() {
// Overriding MD state needs to be done before setting up the test window to
// maintain consistency throughout its lifetime.
material_design_state_ =
std::make_unique<ui::test::MaterialDesignControllerTestAPI>(GetParam());
BrowserWithTestWindowTest::SetUp();
extensions::LoadErrorReporter::Init(false);
@ -186,7 +181,6 @@ void ToolbarActionsBarUnitTest::TearDown() {
overflow_browser_action_test_util_.reset();
ToolbarActionsBar::disable_animations_for_testing_ = false;
BrowserWithTestWindowTest::TearDown();
material_design_state_.reset();
}
void ToolbarActionsBarUnitTest::ActivateTab(int index) {

@ -14,6 +14,7 @@
#include "chrome/browser/ui/extensions/extension_action_test_helper.h"
#include "chrome/test/base/browser_with_test_window_test.h"
#include "extensions/common/extension_builder.h"
#include "ui/base/material_design/material_design_controller.h"
class ScopedTestingLocalState;
class ToolbarActionsBar;
@ -23,12 +24,6 @@ namespace extensions {
class Extension;
}
namespace ui {
namespace test {
class MaterialDesignControllerTestAPI;
}
} // namespace ui
// A cross-platform unit test for the ToolbarActionsBar that uses the
// TestToolbarActionsBarHelper to create the platform-specific containers.
// TODO(devlin): Since this *does* use the real platform containers, in theory,
@ -86,7 +81,7 @@ class ToolbarActionsBarUnitTest : public BrowserWithTestWindowTest,
base::test::ScopedFeatureList feature_list_;
// The associated ToolbarActionsModel (owned by the keyed service setup).
ToolbarActionsModel* toolbar_model_;
ToolbarActionsModel* toolbar_model_ = nullptr;
// A ExtensionActionTestHelper object constructed with the associated
// ToolbarActionsBar.
@ -95,8 +90,7 @@ class ToolbarActionsBarUnitTest : public BrowserWithTestWindowTest,
// The overflow container's ExtensionActionTestHelper.
std::unique_ptr<ExtensionActionTestHelper> overflow_browser_action_test_util_;
std::unique_ptr<ui::test::MaterialDesignControllerTestAPI>
material_design_state_;
ui::MaterialDesignController::TouchUiScoperForTesting touch_ui_scoper_;
// Local state for the browser process.
std::unique_ptr<ScopedTestingLocalState> local_state_;

@ -1548,7 +1548,8 @@ void BookmarkBarView::ConfigureButton(const BookmarkNode* node,
bool themify_icon = node->url().SchemeIs(content::kChromeUIScheme);
gfx::ImageSkia favicon = model_->GetFavicon(node).AsImageSkia();
if (favicon.isNull()) {
if (ui::MaterialDesignController::touch_ui() && GetThemeProvider()) {
if (ui::MaterialDesignController::GetInstance()->touch_ui() &&
GetThemeProvider()) {
// This favicon currently does not match the default favicon icon used
// elsewhere in the codebase.
// See https://crbug/814447
@ -1896,12 +1897,12 @@ void BookmarkBarView::UpdateAppearanceForTheme() {
const SkColor overflow_color =
theme_provider->GetColor(ThemeProperties::COLOR_TOOLBAR_BUTTON_ICON);
const bool touch_ui = ui::MaterialDesignController::GetInstance()->touch_ui();
overflow_button_->SetImage(
views::Button::STATE_NORMAL,
gfx::CreateVectorIcon(ui::MaterialDesignController::touch_ui()
? kBookmarkbarTouchOverflowIcon
: kOverflowChevronIcon,
overflow_color));
gfx::CreateVectorIcon(
touch_ui ? kBookmarkbarTouchOverflowIcon : kOverflowChevronIcon,
overflow_color));
// Redraw the background.
SchedulePaint();

@ -21,7 +21,6 @@
#include "components/ui_devtools/views/devtools_server_util.h"
#include "content/public/browser/tracing_service.h"
#include "services/service_manager/sandbox/switches.h"
#include "ui/base/material_design/material_design_controller.h"
#if defined(USE_AURA)
#include "base/run_loop.h"
@ -72,11 +71,6 @@ void ChromeBrowserMainExtraPartsViews::ToolkitInitialized() {
SetConstrainedWindowViewsClient(CreateChromeConstrainedWindowViewsClient());
// The MaterialDesignController needs to look at command line flags, which
// are not available until this point. Now that they are, proceed with
// initializing the MaterialDesignController.
ui::MaterialDesignController::Initialize();
#if defined(USE_AURA)
wm_state_ = std::make_unique<wm::WMState>();
#endif

@ -51,7 +51,7 @@ ChromeLayoutProvider::CreateLayoutProvider() {
gfx::Insets ChromeLayoutProvider::GetInsetsMetric(int metric) const {
DCHECK_LT(metric, views::VIEWS_INSETS_MAX);
const bool touch_ui = ui::MaterialDesignController::touch_ui();
const bool touch_ui = ui::MaterialDesignController::GetInstance()->touch_ui();
switch (metric) {
case views::INSETS_DIALOG:
case views::INSETS_DIALOG_SUBSECTION:

@ -57,7 +57,8 @@ void ApplyCommonFontStyles(int context,
gfx::Font::Weight* weight) {
switch (context) {
case CONTEXT_TOOLBAR_BUTTON: {
int height = ui::MaterialDesignController::touch_ui() ? 22 : 17;
int height =
ui::MaterialDesignController::GetInstance()->touch_ui() ? 22 : 17;
// We only want the font size to be constrained by available height, and
// don't actually have a target font size, so we just need to supply any
// sufficiently-large value for the second argument here. |height| will
@ -72,10 +73,11 @@ void ApplyCommonFontStyles(int context,
}
case CONTEXT_OMNIBOX_PRIMARY:
case CONTEXT_OMNIBOX_DEEMPHASIZED: {
using MD = ui::MaterialDesignController;
const int omnibox_primary_delta =
GetFontSizeDeltaBoundedByAvailableHeight(
LocationBarView::GetAvailableTextHeight(),
ui::MaterialDesignController::touch_ui() ? 15 : 14);
MD::GetInstance()->touch_ui() ? 15 : 14);
*size_delta = omnibox_primary_delta;
if (context == CONTEXT_OMNIBOX_DEEMPHASIZED) {
(*size_delta)--;

@ -86,7 +86,7 @@ void ExtensionsToolbarButton::ButtonPressed(views::Button* sender,
}
int ExtensionsToolbarButton::GetIconSize() const {
return ui::MaterialDesignController::touch_ui() && !browser_->app_controller()
? kDefaultTouchableIconSize
: kDefaultIconSize;
const bool touch_ui = ui::MaterialDesignController::GetInstance()->touch_ui();
return (touch_ui && !browser_->app_controller()) ? kDefaultTouchableIconSize
: kDefaultIconSize;
}

@ -88,7 +88,7 @@
#include "ui/aura/test/env_test_helper.h"
#include "ui/base/class_property.h"
#include "ui/base/hit_test.h"
#include "ui/base/test/material_design_controller_test_api.h"
#include "ui/base/material_design/material_design_controller.h"
#include "ui/compositor/scoped_animation_duration_scale_mode.h"
#include "ui/events/base_event_utils.h"
#include "ui/events/event.h"
@ -155,11 +155,11 @@ template <class BaseTest>
class TopChromeMdParamTest : public BaseTest,
public ::testing::WithParamInterface<bool> {
public:
TopChromeMdParamTest() : test_api_(GetParam()) {}
TopChromeMdParamTest() : touch_ui_scoper_(GetParam()) {}
~TopChromeMdParamTest() override = default;
private:
ui::test::MaterialDesignControllerTestAPI test_api_;
ui::MaterialDesignController::TouchUiScoperForTesting touch_ui_scoper_;
};
// Template to be used when a test does not work with the webUI tabstrip.

@ -290,7 +290,7 @@ WebUITabStripContainerView::~WebUITabStripContainerView() {
// static
bool WebUITabStripContainerView::UseTouchableTabStrip() {
return base::FeatureList::IsEnabled(features::kWebUITabStrip) &&
ui::MaterialDesignController::touch_ui();
ui::MaterialDesignController::GetInstance()->touch_ui();
}
// static

@ -5,7 +5,6 @@
#include "chrome/browser/ui/views/frame/webui_tab_strip_container_view.h"
#include <utility>
#include "base/command_line.h"
#include "base/test/scoped_feature_list.h"
#include "chrome/browser/extensions/extension_tab_util.h"
#include "chrome/browser/ui/ui_features.h"
@ -13,22 +12,15 @@
#include "chrome/browser/ui/views/frame/test_with_browser_view.h"
#include "chrome/browser/ui/views/toolbar/toolbar_view.h"
#include "chrome/browser/ui/webui/tab_strip/tab_strip_ui.h"
#include "chrome/common/chrome_switches.h"
#include "chrome/test/base/test_browser_window.h"
#include "content/public/common/drop_data.h"
#include "ui/base/test/material_design_controller_test_api.h"
#include "ui/base/ui_base_switches.h"
#include "ui/base/material_design/material_design_controller.h"
class WebUITabStripContainerViewTest : public TestWithBrowserView {
public:
template <typename... Args>
explicit WebUITabStripContainerViewTest(Args... args)
: TestWithBrowserView(args...), 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);
: TestWithBrowserView(args...) {
feature_override_.InitAndEnableFeature(features::kWebUITabStrip);
}
@ -36,7 +28,7 @@ class WebUITabStripContainerViewTest : public TestWithBrowserView {
private:
base::test::ScopedFeatureList feature_override_;
ui::test::MaterialDesignControllerTestAPI touch_mode_;
ui::MaterialDesignController::TouchUiScoperForTesting touch_ui_scoper_{true};
};
TEST_F(WebUITabStripContainerViewTest, TabStripStartsClosed) {
@ -50,12 +42,14 @@ TEST_F(WebUITabStripContainerViewTest, TouchModeTransition) {
EXPECT_NE(nullptr, browser_view()->webui_tab_strip());
EXPECT_FALSE(browser_view()->IsTabStripVisible());
ui::test::MaterialDesignControllerTestAPI disable_touch_mode(false);
ui::MaterialDesignController::TouchUiScoperForTesting disable_touch_mode(
false);
browser_view()->Layout();
EXPECT_FALSE(WebUITabStripContainerView::UseTouchableTabStrip());
EXPECT_TRUE(browser_view()->IsTabStripVisible());
ui::test::MaterialDesignControllerTestAPI reenable_touch_mode(true);
ui::MaterialDesignController::TouchUiScoperForTesting reenable_touch_mode(
true);
browser_view()->Layout();
EXPECT_TRUE(WebUITabStripContainerView::UseTouchableTabStrip());
EXPECT_FALSE(browser_view()->IsTabStripVisible());
@ -147,7 +141,9 @@ class WebUITabStripDevToolsTest : public WebUITabStripContainerViewTest {
TEST_F(WebUITabStripDevToolsTest, DevToolsWindowHasNoTabStrip) {
EXPECT_EQ(nullptr, browser_view()->webui_tab_strip());
ui::test::MaterialDesignControllerTestAPI disable_touch_mode(false);
ui::test::MaterialDesignControllerTestAPI reenable_touch_mode(true);
ui::MaterialDesignController::TouchUiScoperForTesting disable_touch_mode(
false);
ui::MaterialDesignController::TouchUiScoperForTesting reenable_touch_mode(
true);
EXPECT_EQ(nullptr, browser_view()->webui_tab_strip());
}

@ -11,18 +11,14 @@
#include "chrome/browser/ui/views/location_bar/location_bar_view.h"
#include "chrome/browser/ui/views/omnibox/omnibox_view_views.h"
#include "chrome/browser/ui/views/toolbar/toolbar_view.h"
#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/base/material_design/material_design_controller.h"
#include "ui/views/controls/webview/webview.h"
class WebUITabStripInteractiveTest : public InProcessBrowserTest {
public:
WebUITabStripInteractiveTest() {
base::CommandLine::ForCurrentProcess()->AppendSwitchASCII(
switches::kTopChromeTouchUi, switches::kTopChromeTouchUiEnabled);
feature_override_.InitAndEnableFeature(features::kWebUITabStrip);
}
@ -30,6 +26,7 @@ class WebUITabStripInteractiveTest : public InProcessBrowserTest {
private:
base::test::ScopedFeatureList feature_override_;
ui::MaterialDesignController::TouchUiScoperForTesting touch_ui_scoper_{true};
};
// Regression test for crbug.com/1027375.

@ -139,9 +139,9 @@ void MediaToolbarButtonView::UpdateIcon() {
if (!GetWidget())
return;
const gfx::VectorIcon& icon = ui::MaterialDesignController::touch_ui()
? kMediaToolbarButtonTouchIcon
: kMediaToolbarButtonIcon;
const bool touch_ui = ui::MaterialDesignController::GetInstance()->touch_ui();
const gfx::VectorIcon& icon =
touch_ui ? kMediaToolbarButtonTouchIcon : kMediaToolbarButtonIcon;
UpdateIconsWithStandardColors(icon);
}

@ -426,7 +426,7 @@ gfx::Size IconLabelBubbleView::GetSizeForLabelWidth(int label_width) const {
int IconLabelBubbleView::GetInternalSpacing() const {
if (image()->GetPreferredSize().IsEmpty())
return 0;
return (MD::touch_ui() ? 10 : 8) + GetExtraInternalSpacing();
return (MD::GetInstance()->touch_ui() ? 10 : 8) + GetExtraInternalSpacing();
}
int IconLabelBubbleView::GetExtraInternalSpacing() const {

@ -828,9 +828,9 @@ void LocationBarView::ButtonPressed(views::Button* sender,
}
void LocationBarView::RefreshClearAllButtonIcon() {
const gfx::VectorIcon& icon = ui::MaterialDesignController::touch_ui()
? omnibox::kClearIcon
: kTabCloseNormalIcon;
const bool touch_ui = ui::MaterialDesignController::GetInstance()->touch_ui();
const gfx::VectorIcon& icon =
touch_ui ? omnibox::kClearIcon : kTabCloseNormalIcon;
SetImageFromVectorIcon(clear_all_button_, icon,
GetColor(OmniboxPart::LOCATION_BAR_CLEAR_ALL));
clear_all_button_->SetBorder(views::CreateEmptyBorder(

@ -36,7 +36,7 @@
#include "services/network/public/cpp/features.h"
#include "services/network/public/mojom/url_response_head.mojom.h"
#include "third_party/blink/public/common/page/page_zoom.h"
#include "ui/base/test/material_design_controller_test_api.h"
#include "ui/base/material_design/material_design_controller.h"
class LocationBarViewBrowserTest : public InProcessBrowserTest {
public:
@ -128,11 +128,10 @@ IN_PROC_BROWSER_TEST_F(LocationBarViewBrowserTest, BubblesCloseOnHide) {
class TouchLocationBarViewBrowserTest : public LocationBarViewBrowserTest {
public:
TouchLocationBarViewBrowserTest() : test_api_(true) {}
TouchLocationBarViewBrowserTest() = default;
private:
ui::test::MaterialDesignControllerTestAPI test_api_;
DISALLOW_COPY_AND_ASSIGN(TouchLocationBarViewBrowserTest);
ui::MaterialDesignController::TouchUiScoperForTesting touch_ui_scoper_{true};
};
// Test the corners of the OmniboxViewViews do not get drawn on top of the

@ -191,8 +191,8 @@ void CastToolbarButton::UpdateIcon() {
GetIconColor(views::Button::STATE_DISABLED, &icon));
// This icon is smaller than the touchable-UI expected 24dp, so we need to pad
// the insets to match.
SetLayoutInsetDelta(
gfx::Insets(ui::MaterialDesignController::touch_ui() ? 4 : 0));
SetLayoutInsetDelta(gfx::Insets(
ui::MaterialDesignController::GetInstance()->touch_ui() ? 4 : 0));
}
MediaRouterActionController* CastToolbarButton::GetActionController() const {

@ -155,7 +155,7 @@ OmniboxMatchCellView::~OmniboxMatchCellView() = default;
// static
int OmniboxMatchCellView::GetTextIndent() {
return ui::MaterialDesignController::touch_ui() ? 51 : 47;
return ui::MaterialDesignController::GetInstance()->touch_ui() ? 51 : 47;
}
void OmniboxMatchCellView::OnMatchUpdate(const OmniboxResultView* result_view,

@ -204,8 +204,9 @@ int RoundedOmniboxResultsFrame::GetNonResultSectionHeight() {
// static
gfx::Insets RoundedOmniboxResultsFrame::GetLocationBarAlignmentInsets() {
return ui::MaterialDesignController::touch_ui() ? gfx::Insets(6, 1, 5, 1)
: gfx::Insets(4, 6);
return ui::MaterialDesignController::GetInstance()->touch_ui()
? gfx::Insets(6, 1, 5, 1)
: gfx::Insets(4, 6);
}
// static

@ -244,7 +244,7 @@ base::string16 AvatarToolbarButton::GetAvatarTooltipText() const {
gfx::ImageSkia AvatarToolbarButton::GetAvatarIcon(
ButtonState state,
const gfx::Image& gaia_account_image) const {
const int icon_size = ui::MaterialDesignController::touch_ui()
const int icon_size = ui::MaterialDesignController::GetInstance()->touch_ui()
? kDefaultTouchableIconSize
: kIconSizeForNonTouchUi;
SkColor icon_color = GetForegroundColor(state);
@ -274,9 +274,8 @@ gfx::ImageSkia AvatarToolbarButton::GetAvatarIcon(
void AvatarToolbarButton::SetInsets() {
// In non-touch mode we use a larger-than-normal icon size for avatars so we
// need to compensate it by smaller insets.
gfx::Insets layout_insets(ui::MaterialDesignController::touch_ui()
? 0
: (kDefaultIconSize - kIconSizeForNonTouchUi) /
2);
const bool touch_ui = ui::MaterialDesignController::GetInstance()->touch_ui();
gfx::Insets layout_insets(
touch_ui ? 0 : (kDefaultIconSize - kIconSizeForNonTouchUi) / 2);
SetLayoutInsetDelta(layout_insets);
}

@ -81,7 +81,7 @@ gfx::Image GetTabAlertIndicatorImage(TabAlertState alert_state,
SkColor button_color) {
const gfx::VectorIcon* icon = nullptr;
int image_width = GetLayoutConstant(TAB_ALERT_INDICATOR_ICON_WIDTH);
const bool touch_ui = ui::MaterialDesignController::touch_ui();
const bool touch_ui = ui::MaterialDesignController::GetInstance()->touch_ui();
switch (alert_state) {
case TabAlertState::AUDIO_PLAYING:
icon = touch_ui ? &kTabAudioRoundedIcon : &kTabAudioIcon;

@ -282,7 +282,8 @@ void NewTabButton::PaintPlusIcon(gfx::Canvas* canvas) const {
constexpr int kStrokeWidth = 2;
flags.setStrokeWidth(kStrokeWidth);
const int radius = ui::MaterialDesignController::touch_ui() ? 7 : 6;
const int radius =
ui::MaterialDesignController::GetInstance()->touch_ui() ? 7 : 6;
const int offset = GetCornerRadius() - radius;
// The cap will be added outside the end of the stroke; inset to compensate.
constexpr int kCapRadius = kStrokeWidth / 2;

@ -362,7 +362,7 @@ void Tab::Layout() {
if (showing_close_button_) {
right = close_x;
if (extra_alert_indicator_padding_)
right -= MD::touch_ui() ? 8 : 6;
right -= MD::GetInstance()->touch_ui() ? 8 : 6;
}
const gfx::Size image_size = alert_indicator_->GetPreferredSize();
gfx::Rect bounds(
@ -948,7 +948,7 @@ void Tab::UpdateIconVisibility() {
int available_width = GetContentsBounds().width();
const bool touch_ui = MD::touch_ui();
const bool touch_ui = MD::GetInstance()->touch_ui();
const int favicon_width = gfx::kFaviconSize;
const int alert_icon_width = alert_indicator_->GetPreferredSize().width();
// In case of touch optimized UI, the close button has an extra padding on the

@ -82,8 +82,9 @@ TabCloseButton::~TabCloseButton() {}
// static
int TabCloseButton::GetWidth() {
return ui::MaterialDesignController::touch_ui() ? kTouchGlyphWidth
: kGlyphWidth;
return ui::MaterialDesignController::GetInstance()->touch_ui()
? kTouchGlyphWidth
: kGlyphWidth;
}
void TabCloseButton::SetIconColors(SkColor foreground_color,

@ -267,7 +267,8 @@ TabDragController::EventSource EventSourceFromEvent(
}
int GetStackableTabWidth() {
return TabStyle::GetTabOverlap() + (MD::touch_ui() ? 136 : 102);
return TabStyle::GetTabOverlap() +
(MD::GetInstance()->touch_ui() ? 136 : 102);
}
} // namespace

@ -30,7 +30,6 @@
#include "components/tab_groups/tab_group_id.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "ui/base/material_design/material_design_controller.h"
#include "ui/base/test/material_design_controller_test_api.h"
#include "ui/events/base_event_utils.h"
#include "ui/gfx/animation/animation_test_api.h"
#include "ui/gfx/canvas.h"
@ -128,7 +127,7 @@ class TabStripTest : public ChromeViewsTestBase,
public testing::WithParamInterface<bool> {
public:
TabStripTest()
: test_api_(GetParam()),
: touch_ui_scoper_(GetParam()),
animation_mode_reset_(gfx::AnimationTestApi::SetRichAnimationRenderMode(
gfx::Animation::RichAnimationRenderMode::FORCE_ENABLED)) {}
@ -268,7 +267,7 @@ class TabStripTest : public ChromeViewsTestBase,
0);
private:
ui::test::MaterialDesignControllerTestAPI test_api_;
ui::MaterialDesignController::TouchUiScoperForTesting touch_ui_scoper_;
std::unique_ptr<base::AutoReset<gfx::Animation::RichAnimationRenderMode>>
animation_mode_reset_;
@ -525,7 +524,7 @@ TEST_P(TabStripTest, TabForEventWhenStacked) {
// the tabstrip is in stacked tab mode.
TEST_P(TabStripTest, TabCloseButtonVisibilityWhenStacked) {
// Touch-optimized UI requires a larger width for tabs to show close buttons.
const bool touch_ui = ui::MaterialDesignController::touch_ui();
const bool touch_ui = ui::MaterialDesignController::GetInstance()->touch_ui();
tab_strip_->SetBounds(0, 0, touch_ui ? 442 : 346, 20);
controller_->AddTab(0, false);
controller_->AddTab(1, true);
@ -597,7 +596,7 @@ TEST_P(TabStripTest, TabCloseButtonVisibilityWhenNotStacked) {
// Set the tab strip width to be wide enough for three tabs to show all
// three icons, but not enough for five tabs to show all three icons.
// Touch-optimized UI requires a larger width for tabs to show close buttons.
const bool touch_ui = ui::MaterialDesignController::touch_ui();
const bool touch_ui = ui::MaterialDesignController::GetInstance()->touch_ui();
tab_strip_->SetBounds(0, 0, touch_ui ? 442 : 346, 20);
controller_->AddTab(0, false);
controller_->AddTab(1, true);
@ -1292,7 +1291,8 @@ TEST_P(TabStripTest, ChangingLayoutTypeResizesTabs) {
Tab* tab = tab_strip_->tab_at(0);
const int initial_height = tab->height();
ui::test::MaterialDesignControllerTestAPI other_layout(!GetParam());
ui::MaterialDesignController::TouchUiScoperForTesting other_layout(
!GetParam());
CompleteAnimationAndLayout();
if (GetParam()) {

@ -259,7 +259,7 @@ void BrowserAppMenuButton::OnThemeChanged() {
}
void BrowserAppMenuButton::UpdateIcon() {
bool touch_ui = ui::MaterialDesignController::touch_ui();
bool touch_ui = ui::MaterialDesignController::GetInstance()->touch_ui();
if (base::FeatureList::IsEnabled(features::kUseTextForUpdateButton)) {
const gfx::VectorIcon& icon =
touch_ui ? kBrowserToolsTouchIcon : kBrowserToolsIcon;

@ -37,10 +37,12 @@ const int kReloadMenuItems[] = {
const gfx::VectorIcon& GetIconForMode(ReloadButton::IconStyle icon_style,
bool is_reload) {
const bool touch_ui = ui::MaterialDesignController::GetInstance()->touch_ui();
#if defined(OS_WIN)
if (icon_style == ReloadButton::IconStyle::kMinimalUi &&
UseWindowsIconsForMinimalUI()) {
if (ui::MaterialDesignController::touch_ui()) {
if (touch_ui) {
return is_reload ? kReloadWindowsTouchIcon
: kNavigateStopWindowsTouchIcon;
}
@ -49,7 +51,7 @@ const gfx::VectorIcon& GetIconForMode(ReloadButton::IconStyle icon_style,
}
#endif
if (ui::MaterialDesignController::touch_ui())
if (touch_ui)
return is_reload ? kReloadTouchIcon : kNavigateStopTouchIcon;
return is_reload ? vector_icons::kReloadIcon : kNavigateStopIcon;

@ -921,7 +921,7 @@ void ToolbarView::LoadImages() {
ThemeProperties::COLOR_TOOLBAR_VERTICAL_SEPARATOR));
}
const bool touch_ui = ui::MaterialDesignController::touch_ui();
const bool touch_ui = ui::MaterialDesignController::GetInstance()->touch_ui();
const gfx::VectorIcon& back_image =
touch_ui ? kBackArrowTouchIcon : vector_icons::kBackArrowIcon;

@ -272,7 +272,8 @@ class WebAppFrameToolbarView::NavigationButtonContainer
const SkColor disabled_color =
SkColorSetA(icon_color_, gfx::kDisabledControlAlpha);
const bool touch_ui = ui::MaterialDesignController::touch_ui();
const bool touch_ui =
ui::MaterialDesignController::GetInstance()->touch_ui();
const gfx::VectorIcon& back_image = GetBackImage(touch_ui);
back_button_->SetImage(views::Button::STATE_NORMAL,
gfx::CreateVectorIcon(back_image, icon_color_));

@ -11,7 +11,6 @@
#include "build/build_config.h"
#include "content/public/test/browser_task_environment.h"
#include "mojo/core/embedder/embedder.h"
#include "ui/base/material_design/material_design_controller.h"
#include "ui/base/resource/resource_bundle.h"
#include "ui/base/ui_base_paths.h"
@ -37,7 +36,6 @@ void VrTestSuite::Initialize() {
#endif
ui::ResourceBundle::InitSharedInstanceWithPakPath(
pak_path.AppendASCII("vr_test.pak"));
ui::MaterialDesignController::Initialize();
}
void VrTestSuite::Shutdown() {

@ -18,7 +18,6 @@
#include "chrome/browser/vr/testapp/gl_renderer.h"
#include "chrome/browser/vr/testapp/vr_test_context.h"
#include "third_party/skia/include/core/SkBitmap.h"
#include "ui/base/material_design/material_design_controller.h"
#include "ui/display/types/display_snapshot.h"
#include "ui/display/types/native_display_delegate.h"
#include "ui/display/types/native_display_observer.h"
@ -296,7 +295,6 @@ int main(int argc, char** argv) {
ui::OzonePlatform::InitializeForUI(params);
ui::KeyboardLayoutEngineManager::GetKeyboardLayoutEngine()
->SetCurrentLayoutByName("us");
ui::MaterialDesignController::Initialize();
base::RunLoop run_loop;

@ -53,7 +53,6 @@
#include "net/url_request/url_fetcher.h"
#include "services/network/public/cpp/network_switches.h"
#include "ui/base/l10n/l10n_util.h"
#include "ui/base/material_design/material_design_controller.h"
#include "ui/base/resource/resource_bundle.h"
#include "ui/base/ui_base_switches.h"
@ -222,7 +221,6 @@ bool ServiceProcess::Initialize(base::OnceClosure quit_closure,
if (locale.empty())
locale = kDefaultServiceProcessLocale;
}
ui::MaterialDesignController::Initialize();
ui::ResourceBundle::InitSharedInstanceWithLocale(
locale, NULL, ui::ResourceBundle::LOAD_COMMON_RESOURCES);

@ -608,7 +608,7 @@ OmniboxFieldTrial::GetEmphasizeTitlesConditionForInput(
}
// Touch-optimized UI always swaps title and URL.
if (ui::MaterialDesignController::touch_ui())
if (ui::MaterialDesignController::GetInstance()->touch_ui())
return EMPHASIZE_WHEN_NONEMPTY;
// Look up the parameter named kEmphasizeTitlesRule + "_" + input.type(),

@ -25,7 +25,6 @@
#include "gpu/ipc/common/gpu_messages.h"
#include "third_party/blink/public/common/input/web_input_event.h"
#include "third_party/blink/public/mojom/frame/intrinsic_sizing_info.mojom.h"
#include "ui/base/ui_base_switches_util.h"
#include "ui/gfx/geometry/dip_util.h"
namespace content {

@ -228,7 +228,6 @@
#include "third_party/skia/include/core/SkBitmap.h"
#include "ui/accessibility/accessibility_switches.h"
#include "ui/base/ui_base_switches.h"
#include "ui/base/ui_base_switches_util.h"
#include "ui/display/display_switches.h"
#include "ui/gl/gl_switches.h"
#include "ui/native_theme/native_theme_features.h"

@ -75,7 +75,6 @@
#include "ui/base/ime/input_method.h"
#include "ui/base/mojom/cursor_type.mojom-shared.h"
#include "ui/base/ui_base_switches.h"
#include "ui/base/ui_base_switches_util.h"
#include "ui/base/ui_base_types.h"
#include "ui/compositor/dip_util.h"
#include "ui/display/screen.h"

@ -72,7 +72,6 @@
#include "ui/base/dragdrop/os_exchange_data.h"
#include "ui/base/dragdrop/os_exchange_data_provider_factory.h"
#include "ui/base/hit_test.h"
#include "ui/base/ui_base_switches_util.h"
#include "ui/compositor/layer.h"
#include "ui/display/screen.h"
#include "ui/events/blink/web_input_event.h"

@ -19,7 +19,6 @@
#include "content/renderer/in_process_renderer_thread.h"
#include "content/utility/in_process_utility_thread.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "ui/base/material_design/material_design_controller.h"
#include "ui/base/ui_base_paths.h"
#if defined(V8_USE_EXTERNAL_STARTUP_DATA)
@ -70,8 +69,6 @@ void ContentTestSuiteBase::Initialize() {
#if defined(V8_USE_EXTERNAL_STARTUP_DATA)
gin::V8Initializer::LoadV8Snapshot(kSnapshotType);
#endif
ui::MaterialDesignController::Initialize();
}
void ContentTestSuiteBase::RegisterContentSchemes(

@ -37,7 +37,6 @@
#include "content/test/test_render_widget_host_factory.h"
#include "content/test/test_web_contents.h"
#include "net/base/mock_network_change_notifier.h"
#include "ui/base/material_design/material_design_controller.h"
#if defined(OS_ANDROID)
#include "ui/android/dummy_screen_android.h"
@ -234,8 +233,6 @@ void RenderViewHostTestHarness::NavigateAndCommit(
}
void RenderViewHostTestHarness::SetUp() {
ui::MaterialDesignController::Initialize();
rvh_test_enabler_.reset(new RenderViewHostTestEnabler);
if (factory_)
rvh_test_enabler_->rvh_factory_->set_render_process_host_factory(factory_);

@ -30,7 +30,6 @@
#include "net/base/net_module.h"
#include "net/grit/net_resources.h"
#include "services/service_manager/embedder/result_codes.h"
#include "ui/base/material_design/material_design_controller.h"
#include "ui/base/resource/resource_bundle.h"
#include "url/gurl.h"
@ -139,7 +138,6 @@ void ShellBrowserMainParts::InitializeBrowserContexts() {
}
void ShellBrowserMainParts::InitializeMessageLoopContext() {
ui::MaterialDesignController::Initialize();
Shell::CreateNewWindow(browser_context_.get(), GetStartupURL(), nullptr,
gfx::Size());
}

@ -175,9 +175,8 @@ Even discovering the full set of UI present for each platform in Chrome is
* An alternative is to maintain a working end-to-end build target executable
to do this, but this has additional costs (and is hard).
* E.g. setup/teardown of low-level functions (
`InitializeGLOneOffPlatform()`,
`MaterialDesignController::Initialize()`, etc.).
* E.g. setup/teardown of low-level functions
(`InitializeGLOneOffPlatform()`, etc.).
* Why not chrome.exe?
* E.g. a scrappy chrome:// page with links to invoke UI would be great!

@ -11,10 +11,8 @@
#include "ui/aura/test/test_windows.h"
#include "ui/aura/window.h"
#include "ui/base/ime/init/input_method_initializer.h"
#include "ui/base/material_design/material_design_controller.h"
#include "ui/base/ui_base_features.h"
#include "ui/base/ui_base_switches.h"
#include "ui/base/ui_base_switches_util.h"
#include "ui/compositor/test/test_context_factories.h"
#include "ui/events/event_dispatcher.h"
#include "ui/events/event_sink.h"
@ -36,7 +34,6 @@ AuraTestBase::~AuraTestBase() {
void AuraTestBase::SetUp() {
setup_called_ = true;
testing::Test::SetUp();
ui::MaterialDesignController::Initialize();
ui::GestureConfiguration* gesture_config =
ui::GestureConfiguration::GetInstance();
// Changing the parameters for gesture recognition shouldn't cause

@ -37,7 +37,6 @@
#include "ui/aura/window_tree_host.h"
#include "ui/base/class_property.h"
#include "ui/base/hit_test.h"
#include "ui/base/ui_base_switches_util.h"
#include "ui/compositor/layer.h"
#include "ui/compositor/layer_animation_observer.h"
#include "ui/compositor/layer_animator.h"

@ -689,8 +689,6 @@ jumbo_static_library("test_support") {
sources = [
"resource/mock_resource_bundle_delegate.cc",
"resource/mock_resource_bundle_delegate.h",
"test/material_design_controller_test_api.cc",
"test/material_design_controller_test_api.h",
]
if (is_mac) {

@ -8,18 +8,14 @@
#include "base/bind.h"
#include "base/command_line.h"
#include "base/feature_list.h"
#include "base/logging.h"
#include "base/message_loop/message_loop_current.h"
#include "base/no_destructor.h"
#include "base/observer_list.h"
#include "base/strings/string_number_conversions.h"
#include "build/buildflag.h"
#include "ui/base/buildflags.h"
#include "ui/base/material_design/material_design_controller_observer.h"
#include "ui/base/ui_base_features.h"
#include "ui/base/ui_base_switches.h"
#include "ui/gfx/animation/linear_animation.h"
#if defined(OS_WIN)
#include "base/win/win_util.h"
@ -39,74 +35,59 @@ bool IsTabletMode() {
gfx::SingletonHwnd::GetInstance()->hwnd());
}
void TabletModeWatcherWinProc(HWND hwnd,
UINT message,
WPARAM wparam,
LPARAM lparam) {
if (message == WM_SETTINGCHANGE)
MaterialDesignController::OnTabletModeToggled(IsTabletMode());
}
} // namespace
#endif // defined(OS_WIN)
bool MaterialDesignController::touch_ui_ = false;
bool MaterialDesignController::automatic_touch_ui_ = false;
MaterialDesignController::TouchUiScoperForTesting::TouchUiScoperForTesting(
bool enabled,
MaterialDesignController* controller)
: controller_(controller),
old_state_(controller_->SetTouchUiState(
enabled ? TouchUiState::kEnabled : TouchUiState::kDisabled)) {}
// static
void MaterialDesignController::Initialize() {
base::CommandLine* command_line = base::CommandLine::ForCurrentProcess();
const std::string switch_value =
command_line->GetSwitchValueASCII(switches::kTopChromeTouchUi);
bool touch = switch_value == switches::kTopChromeTouchUiEnabled;
automatic_touch_ui_ = switch_value == switches::kTopChromeTouchUiAuto;
// When the mode is not explicitly forced, platforms vary as to the default
// behavior.
if (!touch && (switch_value != switches::kTopChromeTouchUiDisabled) &&
features::IsAutomaticUiAdjustmentsForTouchEnabled()) {
#if defined(OS_CHROMEOS)
// TabletModePageBehavior's default state is in non-tablet mode.
automatic_touch_ui_ = true;
#elif defined(OS_WIN)
if (base::win::GetVersion() >= base::win::Version::WIN10) {
// Win 10+ uses dynamic mode by default and checks the current tablet mode
// state to determine whether to start in touch mode.
automatic_touch_ui_ = true;
if (base::MessageLoopCurrentForUI::IsSet() &&
!GetInstance()->singleton_hwnd_observer_) {
GetInstance()->singleton_hwnd_observer_ =
std::make_unique<gfx::SingletonHwndObserver>(
base::BindRepeating(TabletModeWatcherWinProc));
touch = IsTabletMode();
}
}
#endif
}
SetTouchUi(touch);
// TODO(crbug.com/864544): Ideally, there would be a more general, "initialize
// random stuff here" function into which this sort of thing can be placed.
double animation_duration_scale;
if (base::StringToDouble(
command_line->GetSwitchValueASCII(switches::kAnimationDurationScale),
&animation_duration_scale)) {
gfx::LinearAnimation::SetDurationScale(animation_duration_scale);
}
}
// static
void MaterialDesignController::OnTabletModeToggled(bool enabled) {
if (automatic_touch_ui_)
SetTouchUi(enabled);
MaterialDesignController::TouchUiScoperForTesting::~TouchUiScoperForTesting() {
controller_->SetTouchUiState(old_state_);
}
// static
MaterialDesignController* MaterialDesignController::GetInstance() {
static base::NoDestructor<MaterialDesignController> instance;
static base::NoDestructor<MaterialDesignController> instance([] {
const std::string switch_value =
base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII(
switches::kTopChromeTouchUi);
if (switch_value == switches::kTopChromeTouchUiDisabled)
return TouchUiState::kDisabled;
const bool enabled = switch_value == switches::kTopChromeTouchUiEnabled;
return enabled ? TouchUiState::kEnabled : TouchUiState::kAuto;
}());
return instance.get();
}
MaterialDesignController::MaterialDesignController(TouchUiState touch_ui_state)
: touch_ui_state_(touch_ui_state) {
#if defined(OS_WIN)
if (base::MessageLoopCurrentForUI::IsSet() &&
(base::win::GetVersion() >= base::win::Version::WIN10)) {
singleton_hwnd_observer_ =
std::make_unique<gfx::SingletonHwndObserver>(base::BindRepeating(
[](HWND hwnd, UINT message, WPARAM wparam, LPARAM lparam) {
if (message == WM_SETTINGCHANGE)
GetInstance()->OnTabletModeToggled(IsTabletMode());
}));
tablet_mode_ = IsTabletMode();
}
#endif
}
MaterialDesignController::~MaterialDesignController() = default;
void MaterialDesignController::OnTabletModeToggled(bool enabled) {
const bool was_touch_ui = touch_ui();
tablet_mode_ = enabled;
if (touch_ui() != was_touch_ui)
NotifyObservers();
}
void MaterialDesignController::AddObserver(
MaterialDesignControllerObserver* observer) {
observers_.AddObserver(observer);
@ -117,15 +98,18 @@ void MaterialDesignController::RemoveObserver(
observers_.RemoveObserver(observer);
}
MaterialDesignController::MaterialDesignController() = default;
MaterialDesignController::TouchUiState
MaterialDesignController::SetTouchUiState(TouchUiState touch_ui_state) {
const bool was_touch_ui = touch_ui();
const TouchUiState old_state = std::exchange(touch_ui_state_, touch_ui_state);
if (touch_ui() != was_touch_ui)
NotifyObservers();
return old_state;
}
// static
void MaterialDesignController::SetTouchUi(bool touch_ui) {
if (touch_ui_ != touch_ui) {
touch_ui_ = touch_ui;
for (auto& observer : GetInstance()->observers_)
observer.OnTouchUiChanged();
}
void MaterialDesignController::NotifyObservers() const {
for (auto& observer : observers_)
observer.OnTouchUiChanged();
}
} // namespace ui

@ -5,67 +5,76 @@
#ifndef UI_BASE_MATERIAL_DESIGN_MATERIAL_DESIGN_CONTROLLER_H_
#define UI_BASE_MATERIAL_DESIGN_MATERIAL_DESIGN_CONTROLLER_H_
#include "base/macros.h"
#include <string>
#include "base/observer_list.h"
#include "base/optional.h"
#include "build/build_config.h"
#include "ui/base/ui_base_export.h"
namespace base {
template <typename T>
class NoDestructor;
}
#if defined(OS_WIN)
namespace gfx {
class SingletonHwndObserver;
}
#endif
namespace ui {
class MaterialDesignControllerObserver;
namespace test {
class MaterialDesignControllerTestAPI;
} // namespace test
// Central controller to handle material design modes.
class UI_BASE_EXPORT MaterialDesignController {
public:
// Initializes touch UI state based on command-line flags.
static void Initialize();
enum class TouchUiState {
kDisabled,
kAuto,
kEnabled,
};
static bool touch_ui() { return touch_ui_; }
class UI_BASE_EXPORT TouchUiScoperForTesting {
public:
explicit TouchUiScoperForTesting(
bool enabled,
MaterialDesignController* controller = GetInstance());
TouchUiScoperForTesting(const TouchUiScoperForTesting&) = delete;
TouchUiScoperForTesting& operator=(const TouchUiScoperForTesting&) = delete;
~TouchUiScoperForTesting();
// Exposed for TabletModePageBehavior on ChromeOS + ash.
static void OnTabletModeToggled(bool enabled);
private:
MaterialDesignController* const controller_;
const TouchUiState old_state_;
};
static MaterialDesignController* GetInstance();
explicit MaterialDesignController(
TouchUiState touch_ui_state = TouchUiState::kAuto);
MaterialDesignController(const MaterialDesignController&) = delete;
MaterialDesignController& operator=(const MaterialDesignController&) = delete;
~MaterialDesignController();
bool touch_ui() const {
return (touch_ui_state_ == TouchUiState::kEnabled) ||
((touch_ui_state_ == TouchUiState::kAuto) && tablet_mode_);
}
void OnTabletModeToggled(bool enabled);
void AddObserver(MaterialDesignControllerObserver* observer);
void RemoveObserver(MaterialDesignControllerObserver* observer);
private:
friend class base::NoDestructor<MaterialDesignController>;
friend class test::MaterialDesignControllerTestAPI;
TouchUiState SetTouchUiState(TouchUiState touch_ui_state);
void NotifyObservers() const;
MaterialDesignController();
~MaterialDesignController() = delete;
// Sets the touch UI state and notifies observers of the state change.
static void SetTouchUi(bool touch_ui);
// Whether the UI layout should be touch-optimized.
static bool touch_ui_;
// Whether |touch_ui_| should toggle on and off depending on the tablet state.
static bool automatic_touch_ui_;
bool tablet_mode_ = false;
TouchUiState touch_ui_state_;
#if defined(OS_WIN)
std::unique_ptr<gfx::SingletonHwndObserver> singleton_hwnd_observer_;
#endif
base::ObserverList<MaterialDesignControllerObserver> observers_;
DISALLOW_COPY_AND_ASSIGN(MaterialDesignController);
};
} // namespace ui

@ -4,155 +4,92 @@
#include <string>
#include "base/command_line.h"
#include "base/macros.h"
#include "base/scoped_observer.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "ui/base/material_design/material_design_controller.h"
#include "ui/base/material_design/material_design_controller_observer.h"
#include "ui/base/ui_base_switches.h"
namespace ui {
using MD = MaterialDesignController;
using MDObserver = MaterialDesignControllerObserver;
namespace {
class TestObserver : public MDObserver {
class TestObserver : public MaterialDesignControllerObserver {
public:
TestObserver() = default;
explicit TestObserver(MaterialDesignController* controller) {
observer_.Add(controller);
}
~TestObserver() override = default;
int touch_ui_changes() const { return touch_ui_changes_; }
private:
// MDObserver:
// MaterialDesignControllerObserver:
void OnTouchUiChanged() override { ++touch_ui_changes_; }
int touch_ui_changes_ = 0;
DISALLOW_COPY_AND_ASSIGN(TestObserver);
};
// Test fixture for the MaterialDesignController class.
class MaterialDesignControllerTest : public testing::Test {
public:
MaterialDesignControllerTest() = default;
~MaterialDesignControllerTest() override = default;
protected:
// testing::Test:
void SetUp() override {
testing::Test::SetUp();
MD::Initialize();
}
void TearDown() override {
testing::Test::TearDown();
}
void SetCommandLineSwitch(const std::string& value_string) {
base::CommandLine::ForCurrentProcess()->AppendSwitchASCII(
switches::kTopChromeTouchUi, value_string);
}
private:
DISALLOW_COPY_AND_ASSIGN(MaterialDesignControllerTest);
};
class MaterialDesignControllerTestCommandLineTouchUiDisabled
: public MaterialDesignControllerTest {
public:
MaterialDesignControllerTestCommandLineTouchUiDisabled() {
SetCommandLineSwitch(switches::kTopChromeTouchUiDisabled);
}
private:
DISALLOW_COPY_AND_ASSIGN(
MaterialDesignControllerTestCommandLineTouchUiDisabled);
};
class MaterialDesignControllerTestCommandLineTouchUiEnabled
: public MaterialDesignControllerTest {
public:
MaterialDesignControllerTestCommandLineTouchUiEnabled() {
SetCommandLineSwitch(switches::kTopChromeTouchUiEnabled);
}
private:
DISALLOW_COPY_AND_ASSIGN(
MaterialDesignControllerTestCommandLineTouchUiEnabled);
};
class MaterialDesignControllerTestCommandLineTouchUiAuto
: public MaterialDesignControllerTest {
public:
MaterialDesignControllerTestCommandLineTouchUiAuto() {
SetCommandLineSwitch(switches::kTopChromeTouchUiAuto);
}
private:
DISALLOW_COPY_AND_ASSIGN(MaterialDesignControllerTestCommandLineTouchUiAuto);
ScopedObserver<MaterialDesignController, MaterialDesignControllerObserver>
observer_{this};
};
} // namespace
// Verifies that non-touch is the default.
TEST_F(MaterialDesignControllerTest, NoCommandLineFlagIsNonTouch) {
ASSERT_FALSE(base::CommandLine::ForCurrentProcess()->HasSwitch(
switches::kTopChromeTouchUi));
EXPECT_FALSE(MD::touch_ui());
TEST(MaterialDesignControllerTest, DefaultIsNonTouch) {
MaterialDesignController controller;
EXPECT_FALSE(controller.touch_ui());
}
// Verifies that switches::kTopChromeTouchUiDisabled maps to non-touch (the
// default).
TEST_F(MaterialDesignControllerTestCommandLineTouchUiDisabled,
CheckApiReturns) {
EXPECT_FALSE(MD::touch_ui());
// Verifies that kDisabled maps to non-touch.
TEST(MaterialDesignControllerTest, DisabledIsNonTouch) {
MaterialDesignController controller(
MaterialDesignController::TouchUiState::kDisabled);
EXPECT_FALSE(controller.touch_ui());
}
// Verifies that switches::kTopChromeTouchUiEnabled maps to touch.
TEST_F(MaterialDesignControllerTestCommandLineTouchUiEnabled, CheckApiReturns) {
EXPECT_TRUE(MD::touch_ui());
// Verifies that kAuto maps to non-touch (the default).
TEST(MaterialDesignControllerTest, AutoIsNonTouch) {
MaterialDesignController controller(
MaterialDesignController::TouchUiState::kAuto);
EXPECT_FALSE(controller.touch_ui());
}
// Verifies that switches::kTopChromeTouchUiAuto maps to non-touch.
TEST_F(MaterialDesignControllerTestCommandLineTouchUiAuto, CheckApiReturns) {
EXPECT_FALSE(MD::touch_ui());
// Verifies that kEnabled maps to touch.
TEST(MaterialDesignControllerTest, EnabledIsNonTouch) {
MaterialDesignController controller(
MaterialDesignController::TouchUiState::kEnabled);
EXPECT_TRUE(controller.touch_ui());
}
// Verifies that when the mode is set to non-touch and the tablet mode toggles,
// the touch UI state does not change.
TEST_F(MaterialDesignControllerTestCommandLineTouchUiDisabled,
TabletOnTouchUiChanged) {
TestObserver observer;
ScopedObserver<MD, MDObserver> scoped_observer(&observer);
scoped_observer.Add(MD::GetInstance());
TEST(MaterialDesignControllerTest, TabletToggledOnTouchUiDisabled) {
MaterialDesignController controller(
MaterialDesignController::TouchUiState::kDisabled);
TestObserver observer(&controller);
MD::OnTabletModeToggled(true);
EXPECT_FALSE(MD::touch_ui());
controller.OnTabletModeToggled(true);
EXPECT_FALSE(controller.touch_ui());
EXPECT_EQ(0, observer.touch_ui_changes());
MD::OnTabletModeToggled(false);
EXPECT_FALSE(MD::touch_ui());
controller.OnTabletModeToggled(false);
EXPECT_FALSE(controller.touch_ui());
EXPECT_EQ(0, observer.touch_ui_changes());
}
// Verifies that when the mode is set to auto and the tablet mode toggles, the
// touch UI state changes and the observer gets called back.
TEST_F(MaterialDesignControllerTestCommandLineTouchUiAuto,
TabletOnTouchUiChanged) {
TestObserver observer;
ScopedObserver<MD, MDObserver> scoped_observer(&observer);
scoped_observer.Add(MD::GetInstance());
TEST(MaterialDesignControllerTest, TabletToggledOnTouchUiAuto) {
MaterialDesignController controller(
MaterialDesignController::TouchUiState::kAuto);
TestObserver observer(&controller);
MD::OnTabletModeToggled(true);
EXPECT_TRUE(MD::touch_ui());
controller.OnTabletModeToggled(true);
EXPECT_TRUE(controller.touch_ui());
EXPECT_EQ(1, observer.touch_ui_changes());
MD::OnTabletModeToggled(false);
EXPECT_FALSE(MD::touch_ui());
controller.OnTabletModeToggled(false);
EXPECT_FALSE(controller.touch_ui());
EXPECT_EQ(2, observer.touch_ui_changes());
}

@ -1,20 +0,0 @@
// Copyright 2015 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 "ui/base/test/material_design_controller_test_api.h"
namespace ui {
namespace test {
MaterialDesignControllerTestAPI::MaterialDesignControllerTestAPI(bool touch_ui)
: previous_touch_ui_(MaterialDesignController::touch_ui_) {
MaterialDesignController::SetTouchUi(touch_ui);
}
MaterialDesignControllerTestAPI::~MaterialDesignControllerTestAPI() {
MaterialDesignController::touch_ui_ = previous_touch_ui_;
}
} // namespace test
} // namespace ui

@ -1,31 +0,0 @@
// Copyright 2015 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.
#ifndef UI_BASE_TEST_MATERIAL_DESIGN_CONTROLLER_TEST_API_H_
#define UI_BASE_TEST_MATERIAL_DESIGN_CONTROLLER_TEST_API_H_
#include "base/macros.h"
#include "ui/base/material_design/material_design_controller.h"
namespace ui {
namespace test {
// Test API to access the internal state of the MaterialDesignController class.
// Creating an instance of this class and then destroying it preserves global
// state in MaterialDesignController class.
class MaterialDesignControllerTestAPI {
public:
explicit MaterialDesignControllerTestAPI(bool touch_ui);
~MaterialDesignControllerTestAPI();
private:
const bool previous_touch_ui_;
DISALLOW_COPY_AND_ASSIGN(MaterialDesignControllerTestAPI);
};
} // namespace test
} // namespace ui
#endif // UI_BASE_TEST_MATERIAL_DESIGN_CONTROLLER_TEST_API_H_

@ -112,11 +112,6 @@ const base::Feature kPrecisionTouchpadLogging{
"PrecisionTouchpadLogging", base::FEATURE_DISABLED_BY_DEFAULT};
#endif // defined(OS_WIN)
#if defined(OS_WIN) || defined(OS_CHROMEOS)
const base::Feature kEnableAutomaticUiAdjustmentsForTouch{
"EnableAutomaticUiAdjustmentsForTouch", base::FEATURE_ENABLED_BY_DEFAULT};
#endif // defined(OS_WIN) || defined(OS_CHROMEOS)
#if defined(OS_WIN) || defined(OS_MACOSX) || defined(OS_LINUX)
// Enables stylus appearing as touch when in contact with digitizer.
const base::Feature kDirectManipulationStylus = {
@ -152,15 +147,6 @@ bool IsFormControlsRefreshEnabled() {
return form_controls_refresh_enabled;
}
bool IsAutomaticUiAdjustmentsForTouchEnabled() {
#if defined(OS_WIN) || defined(OS_CHROMEOS)
return base::FeatureList::IsEnabled(
features::kEnableAutomaticUiAdjustmentsForTouch);
#else
return false;
#endif
}
const base::Feature kEnableOzoneDrmMojo = {"OzoneDrmMojo",
base::FEATURE_ENABLED_BY_DEFAULT};

@ -58,11 +58,6 @@ COMPONENT_EXPORT(UI_BASE_FEATURES) extern const base::Feature kTSFImeSupport;
COMPONENT_EXPORT(UI_BASE_FEATURES) bool IsUsingWMPointerForTouch();
#endif // defined(OS_WIN)
#if defined(OS_WIN) || defined(OS_CHROMEOS)
COMPONENT_EXPORT(UI_BASE_FEATURES)
extern const base::Feature kEnableAutomaticUiAdjustmentsForTouch;
#endif // defined(OS_WIN) || defined(OS_CHROMEOS)
#if defined(OS_WIN) || defined(OS_MACOSX) || defined(OS_LINUX)
COMPONENT_EXPORT(UI_BASE_FEATURES)
extern const base::Feature kDirectManipulationStylus;
@ -73,10 +68,6 @@ COMPONENT_EXPORT(UI_BASE_FEATURES)
extern const base::Feature kFormControlsRefresh;
COMPONENT_EXPORT(UI_BASE_FEATURES) bool IsFormControlsRefreshEnabled();
// Whether the UI may accommodate touch input in response to hardware changes.
COMPONENT_EXPORT(UI_BASE_FEATURES)
bool IsAutomaticUiAdjustmentsForTouchEnabled();
// Use mojo communication in the drm platform instead of paramtraits. Remove
// this switch (and associated code) when the drm platform always uses mojo
// communication.

@ -25,10 +25,6 @@ const char kDisableRemoteCoreAnimation[] = "disable-remote-core-animation";
const char kShowMacOverlayBorders[] = "show-mac-overlay-borders";
#endif
// Scale factor to apply to every animation duration. Must be >= 0.0. This will
// only apply to LinearAnimation and its subclasses.
const char kAnimationDurationScale[] = "animation-duration-scale";
// Disables layer-edge anti-aliasing in the compositor.
const char kDisableCompositedAntialiasing[] = "disable-composited-antialiasing";

@ -20,7 +20,6 @@ UI_BASE_EXPORT extern const char kDisableRemoteCoreAnimation[];
UI_BASE_EXPORT extern const char kShowMacOverlayBorders[];
#endif
UI_BASE_EXPORT extern const char kAnimationDurationScale[];
UI_BASE_EXPORT extern const char kDisableCompositedAntialiasing[];
UI_BASE_EXPORT extern const char kDisableDwmComposition[];
UI_BASE_EXPORT extern const char kDisableTouchAdjustment[];

@ -11,12 +11,11 @@
namespace switches {
bool IsTouchDragDropEnabled() {
const auto* const command_line = base::CommandLine::ForCurrentProcess();
#if defined(OS_CHROMEOS) || defined(OS_ANDROID)
return !base::CommandLine::ForCurrentProcess()->HasSwitch(
kDisableTouchDragDrop);
return !command_line->HasSwitch(kDisableTouchDragDrop);
#else
return base::CommandLine::ForCurrentProcess()->HasSwitch(
kEnableTouchDragDrop);
return command_line->HasSwitch(kEnableTouchDragDrop);
#endif
}

@ -9,15 +9,12 @@
#include <algorithm>
#include "base/command_line.h"
#include "base/numerics/ranges.h"
#include "base/strings/string_number_conversions.h"
#include "ui/gfx/animation/animation_container.h"
#include "ui/gfx/animation/animation_delegate.h"
namespace {
double g_duration_scale_factor = 1.0;
} // namespace
#include "ui/gfx/switches.h"
namespace gfx {
@ -65,19 +62,23 @@ void LinearAnimation::End() {
}
void LinearAnimation::SetDuration(base::TimeDelta duration) {
duration_ = duration * g_duration_scale_factor;
static const double duration_scale_factor = []() {
base::CommandLine* command_line = base::CommandLine::ForCurrentProcess();
double animation_duration_scale;
return (base::StringToDouble(command_line->GetSwitchValueASCII(
switches::kAnimationDurationScale),
&animation_duration_scale) &&
(animation_duration_scale >= 0.0))
? animation_duration_scale
: 1.0;
}();
duration_ = duration * duration_scale_factor;
if (duration_ < timer_interval())
duration_ = timer_interval();
if (is_animating())
SetStartTime(container()->last_tick_time());
}
// static
void LinearAnimation::SetDurationScale(const double scale_factor) {
if (scale_factor >= 0.0)
g_duration_scale_factor = scale_factor;
}
void LinearAnimation::Step(base::TimeTicks time_now) {
base::TimeDelta elapsed_time = time_now - start_time();
state_ = static_cast<double>(elapsed_time.InMicroseconds()) /

@ -50,11 +50,6 @@ class ANIMATION_EXPORT LinearAnimation : public Animation {
// the currently set scale factor.
void SetDuration(base::TimeDelta duration);
// Sets the duration scale factor. This scale factor will be applied to all
// animation durations globally. This value must be >= 0. The default value
// is 1.0.
static void SetDurationScale(double scale_factor);
protected:
// Called when the animation progresses. Subclasses override this to
// efficiently update their state.

@ -7,11 +7,18 @@
namespace switches {
// Scale factor to apply to every animation duration. Must be >= 0.0. This will
// only apply to LinearAnimation and its subclasses.
const char kAnimationDurationScale[] = "animation-duration-scale";
// Force disables font subpixel positioning. This affects the character glyph
// sharpness, kerning, hinting and layout.
const char kDisableFontSubpixelPositioning[] =
"disable-font-subpixel-positioning";
// Enable native CPU-mappable GPU memory buffer support on Linux.
const char kEnableNativeGpuMemoryBuffers[] = "enable-native-gpu-memory-buffers";
// Forces whether the user desires reduced motion, regardless of system
// settings.
const char kForcePrefersReducedMotion[] = "force-prefers-reduced-motion";
@ -19,7 +26,4 @@ const char kForcePrefersReducedMotion[] = "force-prefers-reduced-motion";
// Run in headless mode, i.e., without a UI or display server dependencies.
const char kHeadless[] = "headless";
// Enable native CPU-mappable GPU memory buffer support on Linux.
const char kEnableNativeGpuMemoryBuffers[] = "enable-native-gpu-memory-buffers";
} // namespace switches

@ -10,13 +10,11 @@
namespace switches {
GFX_SWITCHES_EXPORT extern const char kAnimationDurationScale[];
GFX_SWITCHES_EXPORT extern const char kDisableFontSubpixelPositioning[];
GFX_SWITCHES_EXPORT extern const char kForcePrefersReducedMotion[];
GFX_SWITCHES_EXPORT extern const char kHeadless[];
GFX_SWITCHES_EXPORT extern const char kEnableNativeGpuMemoryBuffers[];
GFX_SWITCHES_EXPORT extern const char kForcePrefersReducedMotion[];
GFX_SWITCHES_EXPORT extern const char kHeadless[];
} // namespace switches

@ -9,7 +9,6 @@
#include "base/test/test_suite.h"
#include "build/build_config.h"
#include "mojo/core/embedder/embedder.h"
#include "ui/base/material_design/material_design_controller.h"
#include "ui/base/resource/resource_bundle.h"
#include "ui/base/ui_base_paths.h"
@ -43,7 +42,6 @@ void ShellDialogsTestSuite::Initialize() {
#endif
// Setup resource bundle.
ui::MaterialDesignController::Initialize();
ui::RegisterPathProvider();
base::FilePath ui_test_pak_path;

@ -9,7 +9,6 @@
#include "base/threading/thread_task_runner_handle.h"
#include "base/timer/timer.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "ui/base/test/material_design_controller_test_api.h"
#include "ui/compositor/scoped_animation_duration_scale_mode.h"
#include "ui/views/animation/ink_drop.h"
#include "ui/views/animation/ink_drop_host_view.h"

@ -24,7 +24,6 @@
#import "testing/gtest_mac.h"
#import "ui/base/cocoa/window_size_constants.h"
#include "ui/base/ime/input_method.h"
#include "ui/base/material_design/material_design_controller.h"
#import "ui/base/test/cocoa_helper.h"
#include "ui/events/test/cocoa_test_event_utils.h"
#import "ui/gfx/mac/coordinate_conversion.h"
@ -375,8 +374,6 @@ class BridgedNativeWidgetTestBase : public ui::CocoaTest {
void SetUp() override {
ui::CocoaTest::SetUp();
ui::MaterialDesignController::Initialize();
Widget::InitParams init_params;
init_params.native_widget = native_widget_mac_;
init_params.type = type_;

@ -11,8 +11,6 @@
#include "build/build_config.h"
#include "third_party/skia/include/core/SkBitmap.h"
#include "ui/accessibility/ax_node_data.h"
#include "ui/base/material_design/material_design_controller.h"
#include "ui/base/test/material_design_controller_test_api.h"
#include "ui/base/ui_base_switches.h"
#include "ui/events/test/event_generator.h"
#include "ui/gfx/canvas.h"

@ -23,7 +23,6 @@
#include "components/viz/service/frame_sinks/frame_sink_manager_impl.h"
#include "mojo/core/embedder/embedder.h"
#include "ui/base/ime/init/input_method_initializer.h"
#include "ui/base/material_design/material_design_controller.h"
#include "ui/base/resource/resource_bundle.h"
#include "ui/base/ui_base_paths.h"
#include "ui/compositor/test/in_process_context_factory.h"
@ -130,7 +129,6 @@ int main(int argc, char** argv) {
aura::Env::GetInstance()->set_context_factory(context_factory.get());
#endif
ui::InitializeInputMethodForTesting();
ui::MaterialDesignController::Initialize();
{
views::DesktopTestViewsDelegate views_delegate;

@ -64,13 +64,7 @@ bool InitializeVisuals() {
} // namespace
ViewsTestBase::ViewsTestBase(
ViewsTestBase::SubclassManagesTaskEnvironment /* tag */)
: task_environment_(base::nullopt) {
// MaterialDesignController is initialized here instead of in SetUp because
// a subclass might construct a MaterialDesignControllerTestAPI as a member to
// override the value, and this must happen first.
ui::MaterialDesignController::Initialize();
}
ViewsTestBase::SubclassManagesTaskEnvironment tag) {}
ViewsTestBase::~ViewsTestBase() {
CHECK(setup_called_)

@ -14,7 +14,6 @@
#include "build/build_config.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "testing/platform_test.h"
#include "ui/base/material_design/material_design_controller.h"
#include "ui/base/ui_base_features.h"
#include "ui/views/test/scoped_views_test_helper.h"
#include "ui/views/test/test_views_delegate.h"
@ -50,10 +49,6 @@ class ViewsTestBase : public PlatformTest {
: task_environment_(base::in_place,
base::test::TaskEnvironment::MainThreadType::UI,
std::forward<TaskEnvironmentTraits>(traits)...) {
// MaterialDesignController is initialized here instead of in SetUp because
// a subclass might construct a MaterialDesignControllerTestAPI as a member
// to override the value, and this must happen first.
ui::MaterialDesignController::Initialize();
}
// Alternatively a subclass may pass this tag to ask this ViewsTestBase not to

@ -4,7 +4,6 @@
#include "ui/views/views_touch_selection_controller_factory.h"
#include "ui/base/ui_base_switches_util.h"
#include "ui/views/touchui/touch_selection_controller_impl.h"
namespace views {

@ -17,7 +17,8 @@ gfx::Size GetCaptionButtonLayoutSize(CaptionButtonLayoutSize size) {
// |kBrowserMaximizedCaptionButtonHeight| should be kept in sync with those
// for TAB_HEIGHT in // chrome/browser/ui/layout_constants.cc.
// TODO: Ideally these values should be obtained from a common location.
int height = ui::MaterialDesignController::touch_ui() ? 41 : 34;
int height =
ui::MaterialDesignController::GetInstance()->touch_ui() ? 41 : 34;
if (size == CaptionButtonLayoutSize::kBrowserCaptionRestored)
height += 8; // Restored window titlebars are 8 DIP taller than maximized.
return gfx::Size(kCaptionButtonWidth, height);

@ -11,7 +11,6 @@
#include "content/public/browser/context_factory.h"
#include "content/shell/browser/shell_browser_context.h"
#include "ui/base/ime/init/input_method_initializer.h"
#include "ui/base/material_design/material_design_controller.h"
#include "ui/views/test/desktop_test_views_delegate.h"
#include "ui/views_content_client/views_content_client.h"
@ -31,7 +30,6 @@ void ViewsContentClientMainParts::PreCreateMainMessageLoop() {}
#endif
void ViewsContentClientMainParts::PreMainMessageLoopRun() {
ui::MaterialDesignController::Initialize();
ui::InitializeInputMethodForTesting();
browser_context_ = std::make_unique<content::ShellBrowserContext>(false);

@ -6,7 +6,6 @@ include_rules = [
"+ui/base/hit_test.h",
"+ui/base/ime",
"+ui/base/resource",
"+ui/base/ui_base_switches_util.h",
"+ui/base/ui_base_paths.h",
"+ui/base/ui_base_types.h",
"+ui/compositor",

@ -20,7 +20,6 @@
#include "content/public/common/main_function_params.h"
#include "content/public/common/url_constants.h"
#include "services/service_manager/embedder/result_codes.h"
#include "ui/base/material_design/material_design_controller.h"
#include "ui/base/resource/resource_bundle.h"
#include "weblayer/browser/browser_process.h"
#include "weblayer/browser/host_content_settings_map_factory.h"
@ -129,7 +128,6 @@ int BrowserMainPartsImpl::PreEarlyInitialization() {
}
void BrowserMainPartsImpl::PreMainMessageLoopRun() {
ui::MaterialDesignController::Initialize();
// It's necessary to have a complete dependency graph of
// BrowserContextKeyedServices before calling out to the delegate (which
// will potentially create a profile), so that a profile creation message is