Commit 6d048fe5 authored by Ahmed Fakhry's avatar Ahmed Fakhry Committed by Commit Bot

Touchable Chrome: Toolbar (1/2)

This CL implements the needed changes for the toolbar buttons,
and the app menu button. The browser actions container will be
done in a follow-up CL.

BUG=818034

Change-Id: I0d8ec316aa98e553e77bef34d4ca120dd9c2f09f
Reviewed-on: https://chromium-review.googlesource.com/947385Reviewed-by: default avatarEvan Stade <estade@chromium.org>
Reviewed-by: default avatarMichael Wasserman <msw@chromium.org>
Reviewed-by: default avatarPeter Kasting <pkasting@chromium.org>
Commit-Queue: Ahmed Fakhry <afakhry@chromium.org>
Cr-Commit-Position: refs/heads/master@{#542242}
parent 35377892
......@@ -34,8 +34,11 @@ aggregate_vector_icons("chrome_vector_icons") {
# Alternative squarer content_paste icon optimised for display at 18x18dip.
# Currently only used in the Page Info bubble.
"page_info_content_paste.icon",
"back_arrow_touch.icon",
"bookmarkbar_touch_overflow.icon",
"browser_tools_error_touch.icon",
"browser_tools_touch.icon",
"browser_tools_update_touch.icon",
"content_paste.icon",
"cookie.icon",
"crashed_tab.icon",
......@@ -51,6 +54,7 @@ aggregate_vector_icons("chrome_vector_icons") {
"folder.icon",
"folder_supervised.1x.icon",
"folder_supervised.icon",
"forward_arrow_touch.icon",
"globe.icon",
"google_g_logo.icon",
"google_pay_logo_with_vertical_separator.icon",
......@@ -65,16 +69,20 @@ aggregate_vector_icons("chrome_vector_icons") {
"my_location.icon",
"navigate_home.1x.icon",
"navigate_home.icon",
"navigate_home_touch.icon",
"navigate_stop.1x.icon",
"navigate_stop.icon",
"navigate_stop_touch.icon",
"new_tab_button_incognito.icon",
"new_tab_button_plus.icon",
"overflow_chevron.1x.icon",
"overflow_chevron.icon",
"page_info_content_paste.icon",
"paintbrush.icon",
"photo.icon",
"photo_camera.icon",
"profile_switcher_outline.icon",
"reload_touch.icon",
"remove.icon",
"remove_box.icon",
"sad_tab.icon",
......@@ -93,10 +101,10 @@ aggregate_vector_icons("chrome_vector_icons") {
"tab.icon",
"tab_audio.1x.icon",
"tab_audio.icon",
"tab_audio_rounded.icon",
"tab_audio_muting.1x.icon",
"tab_audio_muting.icon",
"tab_audio_muting_rounded.icon",
"tab_audio_rounded.icon",
"tab_bluetooth_connected.icon",
"tab_close_button_touch.icon",
"tab_close_button_touch_incognito.icon",
......
// Copyright 2018 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.
CANVAS_DIMENSIONS, 24,
MOVE_TO, 12.91f, 18.59f,
R_LINE_TO, 0.09f, -0.09f,
LINE_TO, 7.49f, 13,
H_LINE_TO, 19,
R_ARC_TO, 1, 1, 0, 0, 0, 0, -2,
H_LINE_TO, 7.49f,
LINE_TO, 13, 5.49f,
R_LINE_TO, -0.09f, -0.09f,
R_ARC_TO, 1, 1, 0, 0, 0, -1.32f, -1.32f,
R_H_LINE_TO, 0,
LINE_TO, 11.51f, 4,
LINE_TO, 4, 11.51f,
R_LINE_TO, 0.09f, 0.09f,
R_ARC_TO, 1, 1, 0, 0, 0, 0, 0.82f,
LINE_TO, 4, 12.5f,
LINE_TO, 11.51f, 20,
R_LINE_TO, 0.09f, -0.09f,
R_ARC_TO, 1, 1, 0, 0, 0, 1.32f, -1.32f,
R_V_LINE_TO, 0,
CLOSE,
END
\ No newline at end of file
// Copyright 2018 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.
CANVAS_DIMENSIONS, 24,
MOVE_TO, 12, 22,
R_CUBIC_TO, 5.52f, 0, 10, -4.48f, 10, -10,
CUBIC_TO_SHORTHAND, 17.52f, 2, 12, 2,
CUBIC_TO_SHORTHAND, 2, 6.48f, 2, 12,
R_CUBIC_TO, 0, 5.52f, 4.48f, 10, 10, 10,
CLOSE,
R_MOVE_TO, 1, -9,
R_H_LINE_TO, -2,
V_LINE_TO, 7,
R_H_LINE_TO, 2,
R_V_LINE_TO, 6,
CLOSE,
R_MOVE_TO, 0, 4,
R_H_LINE_TO, -2,
R_V_LINE_TO, -2,
R_H_LINE_TO, 2,
R_V_LINE_TO, 2,
CLOSE,
MOVE_TO, 0, 0,
R_H_LINE_TO, 24,
R_V_LINE_TO, 24,
H_LINE_TO, 0,
CLOSE,
END
\ No newline at end of file
// Copyright 2018 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.
CANVAS_DIMENSIONS, 24,
MOVE_TO, 12, 8,
R_ARC_TO, 2, 2, 0, 1, 0, 0, -4,
R_ARC_TO, 2, 2, 0, 0, 0, 0, 4,
CLOSE,
R_MOVE_TO, 0, 2,
R_ARC_TO, 2, 2, 0, 1, 0, 0, 4,
R_ARC_TO, 2, 2, 0, 0, 0, 0, -4,
CLOSE,
R_MOVE_TO, 0, 6,
R_ARC_TO, 2, 2, 0, 1, 0, 0, 4,
R_ARC_TO, 2, 2, 0, 0, 0, 0, -4,
CLOSE,
END
\ No newline at end of file
// Copyright 2018 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.
CANVAS_DIMENSIONS, 24,
MOVE_TO, 12, 22,
CUBIC_TO, 6.48f, 22, 2, 17.52f, 2, 12,
CUBIC_TO_SHORTHAND, 6.48f, 2, 12, 2,
R_CUBIC_TO, 5.52f, 0, 10, 4.48f, 10, 10,
R_CUBIC_TO, 0, 5.52f, -4.48f, 10, -10, 10,
CLOSE,
R_MOVE_TO, -2, -5,
R_H_LINE_TO, 4,
R_V_LINE_TO, -4,
R_H_LINE_TO, 3.5f,
LINE_TO, 12, 6.5f,
LINE_TO, 6.5f, 13,
H_LINE_TO, 10,
R_V_LINE_TO, 4,
CLOSE,
MOVE_TO, 0, 0,
R_H_LINE_TO, 24,
R_V_LINE_TO, 24,
H_LINE_TO, 0,
CLOSE,
END
\ No newline at end of file
// Copyright 2018 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.
CANVAS_DIMENSIONS, 24,
MOVE_TO, 11.09f, 18.59f,
LINE_TO, 11, 18.51f,
LINE_TO, 16.51f, 13,
H_LINE_TO, 5,
R_ARC_TO, 1, 1, 0, 0, 1, 0, -2,
R_H_LINE_TO, 11.51f,
LINE_TO, 11, 5.49f,
R_LINE_TO, 0.09f, -0.09f,
R_ARC_TO, 1, 1, 0, 0, 1, 1.32f, -1.32f,
R_H_LINE_TO, 0,
LINE_TO, 12.49f, 4,
LINE_TO, 20, 11.51f,
R_LINE_TO, -0.09f, 0.09f,
R_ARC_TO, 1, 1, 0, 0, 1, 0, 0.82f,
R_LINE_TO, 0.09f, 0.09f,
LINE_TO, 12.49f, 20,
R_LINE_TO, -0.09f, -0.09f,
R_ARC_TO, 1, 1, 0, 0, 1, -1.32f, -1.32f,
R_V_LINE_TO, 0,
CLOSE,
END
\ No newline at end of file
// 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.
CANVAS_DIMENSIONS, 24,
MOVE_TO, 12.87f, 3.54f,
CUBIC_TO, 12.67f, 3.33f, 12.33f, 3, 12, 3,
R_CUBIC_TO, -0.33f, 0, -0.67f, 0.33f, -0.87f, 0.54f,
R_LINE_TO, -7.89f, 7.84f,
ARC_TO, 0.98f, 0.98f, 0, 0, 0, 3, 12,
R_ARC_TO, 1, 1, 0, 0, 0, 1, 1,
R_CUBIC_TO, 0.24f, 0, 0.45f, -0.09f, 0.62f, -0.24f,
R_LINE_TO, 0.38f, -0.35f,
V_LINE_TO, 19,
R_ARC_TO, 2, 2, 0, 0, 0, 2, 2,
R_H_LINE_TO, 10,
R_ARC_TO, 2, 2, 0, 0, 0, 2, -2,
R_V_LINE_TO, -6.59f,
R_LINE_TO, 0.38f, 0.35f,
ARC_TO, 0.98f, 0.98f, 0, 0, 0, 20, 13,
R_ARC_TO, 1, 1, 0, 0, 0, 1, -1,
R_ARC_TO, 0.98f, 0.98f, 0, 0, 0, -0.24f, -0.62f,
R_CUBIC_TO, 0, 0, -5.91f, -5.88f, -7.89f, -7.84f,
CLOSE,
MOVE_TO, 7, 19,
R_V_LINE_TO, -8.85f,
LINE_TO, 12, 5,
R_LINE_TO, 5, 5.15f,
V_LINE_TO, 19,
H_LINE_TO, 7,
CLOSE,
END
\ No newline at end of file
// Copyright 2018 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.
CANVAS_DIMENSIONS, 24,
MOVE_TO, 17.51f, 5,
R_LINE_TO, 0.09f, 0.09f,
R_ARC_TO, 1, 1, 0, 0, 1, 1.32f, 1.32f,
R_LINE_TO, 0.09f, 0.09f,
LINE_TO, 14.49f, 11,
R_LINE_TO, -0.99f, 1,
R_LINE_TO, 0.99f, 1,
LINE_TO, 19, 17.51f,
R_LINE_TO, -0.09f, 0.09f,
R_ARC_TO, 1, 1, 0, 0, 1, -1.32f, 1.32f,
R_LINE_TO, -0.09f, 0.09f,
LINE_TO, 12, 13.5f,
LINE_TO, 6.49f, 19,
R_LINE_TO, -0.09f, -0.09f,
R_ARC_TO, 1, 1, 0, 0, 1, -1.32f, -1.32f,
LINE_TO, 5, 17.51f,
LINE_TO, 9.51f, 13,
R_LINE_TO, 0.99f, -1,
R_LINE_TO, -0.99f, -1,
LINE_TO, 5, 6.49f,
R_LINE_TO, 0.09f, -0.09f,
R_ARC_TO, 1, 1, 0, 0, 1, 1.32f, -1.32f,
LINE_TO, 6.5f, 5,
LINE_TO, 12, 10.51f,
LINE_TO, 17.51f, 5,
CLOSE,
END
\ No newline at end of file
// Copyright 2018 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.
CANVAS_DIMENSIONS, 24,
MOVE_TO, 17.68f, 6.32f,
LINE_TO, 20, 4,
R_V_LINE_TO, 7,
R_H_LINE_TO, -7,
R_LINE_TO, 3.27f, -3.27f,
ARC_TO, 6.01f, 6.01f, 0, 0, 0, 12.04f, 6,
R_CUBIC_TO, -3.33f, 0, -6.03f, 2.69f, -6.03f, 6,
R_CUBIC_TO, 0, 3.31f, 2.7f, 6, 6.03f, 6,
R_CUBIC_TO, 2.62f, 0, 4.71f, -1.62f, 5.47f, -3.89f,
R_LINE_TO, 0.11f, -0.01f,
R_ARC_TO, 1, 1, 0, 0, 1, 0.89f, -0.6f,
R_CUBIC_TO, 0.44f, 0, 1, 0.32f, 1, 1,
R_ARC_TO, 1, 1, 0, 0, 1, -0.09f, 0.41f,
R_LINE_TO, 0.05f, 0,
CUBIC_TO, 18.26f, 17.84f, 15.41f, 20, 12.04f, 20,
CUBIC_TO, 7.6f, 20, 4, 16.42f, 4, 12,
R_CUBIC_TO, 0, -4.42f, 3.6f, -8, 8.04f, -8,
R_CUBIC_TO, 2.2f, 0, 4.2f, 0.88f, 5.65f, 2.32f,
CLOSE,
END
\ No newline at end of file
......@@ -174,38 +174,33 @@ base::Optional<SkColor> MaybeGetDefaultColorForTouchOptimizedUi(
return base::nullopt;
switch (id) {
// Properties stored in theme pack.
case ThemeProperties::COLOR_FRAME:
// Active frame colors.
return incognito ? gfx::kGoogleGrey900 : kDefaultTouchUiColorActiveFrame;
case ThemeProperties::COLOR_FRAME_INACTIVE:
// Inactive frame colors.
return incognito ? kDefaultTouchUiColorInactiveFrameIncognito
: kDefaultTouchUiColorInactiveFrame;
case ThemeProperties::COLOR_TOOLBAR:
return incognito ? kDefaultTouchUiColorInactiveFrameIncognito
: kDefaultTouchUiColorToolbar;
case ThemeProperties::COLOR_TAB_TEXT:
case ThemeProperties::COLOR_BOOKMARK_TEXT:
case ThemeProperties::COLOR_TAB_CLOSE_BUTTON_BACKGROUND_ACTIVE:
case ThemeProperties::COLOR_TOOLBAR_BUTTON_ICON:
return incognito ? gfx::kGoogleGrey100 : gfx::kGoogleGrey800;
case ThemeProperties::COLOR_BACKGROUND_TAB_TEXT:
case ThemeProperties::COLOR_TAB_CLOSE_BUTTON_BACKGROUND_INACTIVE:
case ThemeProperties::COLOR_TAB_ALERT_AUDIO:
return incognito ? gfx::kGoogleGrey400 : gfx::kGoogleGrey700;
// Properties not stored in theme pack.
case ThemeProperties::COLOR_BACKGROUND_TAB:
return incognito ? kDefaultTouchUiColorTabBackgroundInactiveIncognito
: kDefaultTouchUiColorTabBackgroundInactive;
case ThemeProperties::COLOR_TAB_CLOSE_BUTTON_BACKGROUND_ACTIVE:
return incognito ? gfx::kGoogleGrey100 : gfx::kGoogleGrey800;
case ThemeProperties::COLOR_TAB_CLOSE_BUTTON_BACKGROUND_INACTIVE:
return incognito ? gfx::kGoogleGrey400 : gfx::kGoogleGrey700;
case ThemeProperties::COLOR_TAB_CLOSE_BUTTON_BACKGROUND_HOVER:
return incognito ? gfx::kGoogleRedDark600 : gfx::kGoogleRed600;
case ThemeProperties::COLOR_TAB_CLOSE_BUTTON_BACKGROUND_PRESSED:
return incognito ? gfx::kGoogleRedDark800 : gfx::kGoogleRed800;
case ThemeProperties::COLOR_TAB_ALERT_AUDIO:
return incognito ? gfx::kGoogleGrey400 : gfx::kGoogleGrey700;
case ThemeProperties::COLOR_TAB_ALERT_RECORDING:
return incognito ? gfx::kGoogleGrey400 : gfx::kGoogleRed600;
case ThemeProperties::COLOR_TAB_ALERT_CAPTURING:
......
......@@ -424,8 +424,17 @@ SkColor ThemeService::GetDefaultColor(int id, bool incognito) const {
const int kNtpText = ThemeProperties::COLOR_NTP_TEXT;
const int kLabelBackground =
ThemeProperties::COLOR_SUPERVISED_USER_LABEL_BACKGROUND;
const bool is_touch =
ui::MaterialDesignController::IsTouchOptimizedUiEnabled();
switch (id) {
case ThemeProperties::COLOR_TOOLBAR_BUTTON_ICON:
// Touch-optimized UI uses different colors than gfx::kChromeIconGrey.
// They are two specific colors in normal and incognito modes which we
// can't get one from the other by HSLShift().
// TODO: This will break custom themes. https://crbug.com/820495.
if (is_touch)
break;
return color_utils::HSLShift(
gfx::kChromeIconGrey,
GetTint(ThemeProperties::TINT_BUTTONS, incognito));
......@@ -433,7 +442,7 @@ SkColor ThemeService::GetDefaultColor(int id, bool incognito) const {
// The active color is overridden in GtkUi.
return SkColorSetA(
GetColor(ThemeProperties::COLOR_TOOLBAR_BUTTON_ICON, incognito),
0x33);
is_touch ? 0x6E : 0x33);
case ThemeProperties::COLOR_LOCATION_BAR_BORDER:
return SkColorSetA(SK_ColorBLACK, 0x4D);
case ThemeProperties::COLOR_TOOLBAR_TOP_SEPARATOR:
......@@ -460,8 +469,8 @@ SkColor ThemeService::GetDefaultColor(int id, bool incognito) const {
case ThemeProperties::COLOR_BACKGROUND_TAB: {
// Touch optimized color design uses different tab background colors.
// TODO(malaykeshav) - This will break custom themes on touch optimized
// UI. Use tint shift instead.
if (ui::MaterialDesignController::IsTouchOptimizedUiEnabled())
// UI. Use tint shift instead. https://crbug.com/820495.
if (is_touch)
break;
// The tints here serve a different purpose than TINT_BACKGROUND_TAB.
......
......@@ -3231,6 +3231,7 @@ split_static_library("ui") {
"views/toolbar/toolbar_action_view_delegate_views.h",
"views/toolbar/toolbar_button.cc",
"views/toolbar/toolbar_button.h",
"views/toolbar/toolbar_ink_drop_util.h",
"views/toolbar/toolbar_view.cc",
"views/toolbar/toolbar_view.h",
"views/touch_uma/touch_uma.h",
......
......@@ -45,12 +45,14 @@ int GetLayoutConstant(LayoutConstant constant) {
return hybrid ? 3 : 1;
case LOCATION_BAR_PADDING:
return hybrid ? 3 : 1;
case LOCATION_BAR_HEIGHT:
return hybrid ? 32 : 28;
case LOCATION_BAR_HEIGHT: {
constexpr int kHeights[] = {28, 32, 36};
return kHeights[mode];
}
case LOCATION_BAR_ICON_SIZE:
return 16;
case LOCATION_BAR_ICON_INTERIOR_PADDING:
return 4;
return touch_optimized_material ? 8 : 4;
case TABSTRIP_NEW_TAB_BUTTON_SPACING: {
// In non-touch optimized UI, we make the new tab button overlap with the
// last tab in the tabstrip (i.e negative spacing). However, in
......@@ -81,8 +83,10 @@ int GetLayoutConstant(LayoutConstant constant) {
return touch_optimized_material ? 245 : 193;
case TOOLBAR_ELEMENT_PADDING:
return hybrid ? 8 : 0;
case TOOLBAR_STANDARD_SPACING:
return hybrid ? 8 : 4;
case TOOLBAR_STANDARD_SPACING: {
constexpr int kSpacings[] = {4, 8, 12};
return kSpacings[mode];
}
}
NOTREACHED();
return 0;
......@@ -90,10 +94,14 @@ int GetLayoutConstant(LayoutConstant constant) {
gfx::Insets GetLayoutInsets(LayoutInset inset) {
switch (inset) {
case TAB:
case TAB: {
constexpr int kTabHorizontalInset[] = {16, 18, 24};
return gfx::Insets(
1, kTabHorizontalInset[ui::MaterialDesignController::GetMode()]);
}
case TOOLBAR_BUTTON:
return gfx::Insets(
ui::MaterialDesignController::IsTouchOptimizedUiEnabled() ? 12 : 6);
}
NOTREACHED();
return gfx::Insets();
......
......@@ -112,6 +112,9 @@ enum LayoutConstant {
enum LayoutInset {
// The padding inside the tab bounds that defines the tab contents region.
TAB,
// The padding inside the border of a toolbar button (around the image).
TOOLBAR_BUTTON,
};
enum LayoutSize {
......
......@@ -24,10 +24,12 @@
#include "chrome/browser/ui/views/extensions/browser_action_drag_data.h"
#include "chrome/browser/ui/views/toolbar/app_menu.h"
#include "chrome/browser/ui/views/toolbar/toolbar_button.h"
#include "chrome/browser/ui/views/toolbar/toolbar_ink_drop_util.h"
#include "chrome/browser/ui/views/toolbar/toolbar_view.h"
#include "chrome/common/chrome_features.h"
#include "chrome/grit/chromium_strings.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/theme_provider.h"
#include "ui/gfx/canvas.h"
......@@ -41,10 +43,13 @@
namespace {
constexpr float kIconSize = 16;
constexpr base::TimeDelta kDelayTime = base::TimeDelta::FromMilliseconds(1500);
// Returns true if the touch-optimized UI is enabled.
bool IsTouchOptimized() {
return ui::MaterialDesignController::IsTouchOptimizedUiEnabled();
}
} // namespace
// static
......@@ -61,6 +66,7 @@ AppMenuButton::AppMenuButton(ToolbarView* toolbar_view)
false) {
SetInkDropMode(InkDropMode::ON);
SetFocusPainter(nullptr);
SetHorizontalAlignment(gfx::ALIGN_CENTER);
if (base::FeatureList::IsEnabled(features::kAnimatedAppMenuIcon)) {
toolbar_view_->browser()->tab_strip_model()->AddObserver(this);
......@@ -68,6 +74,9 @@ AppMenuButton::AppMenuButton(ToolbarView* toolbar_view)
should_delay_animation_ = base::GetFieldTrialParamByFeatureAsBool(
features::kAnimatedAppMenuIcon, "HasDelay", false);
}
if (IsTouchOptimized())
set_ink_drop_visible_opacity(kTouchToolbarInkDropVisibleOpacity);
}
AppMenuButton::~AppMenuButton() {}
......@@ -151,8 +160,10 @@ void AppMenuButton::RemoveMenuListener(views::MenuListener* listener) {
}
gfx::Size AppMenuButton::CalculatePreferredSize() const {
gfx::Rect rect(gfx::Size(kIconSize, kIconSize));
rect.Inset(gfx::Insets(-ToolbarButton::kInteriorPadding));
const int icon_size = IsTouchOptimized() ? 24 : 16;
gfx::Rect rect(gfx::Size(icon_size, icon_size));
rect.Inset(-GetLayoutInsets(TOOLBAR_BUTTON));
return rect.size();
}
......@@ -224,18 +235,21 @@ void AppMenuButton::UpdateIcon(bool should_animate) {
return;
}
const bool is_touch = IsTouchOptimized();
const gfx::VectorIcon* icon_id = nullptr;
switch (type_) {
case AppMenuIconController::IconType::NONE:
icon_id = &kBrowserToolsIcon;
icon_id = is_touch ? &kBrowserToolsTouchIcon : &kBrowserToolsIcon;
DCHECK_EQ(AppMenuIconController::Severity::NONE, severity_);
break;
case AppMenuIconController::IconType::UPGRADE_NOTIFICATION:
icon_id = &kBrowserToolsUpdateIcon;
icon_id =
is_touch ? &kBrowserToolsUpdateTouchIcon : &kBrowserToolsUpdateIcon;
break;
case AppMenuIconController::IconType::GLOBAL_ERROR:
case AppMenuIconController::IconType::INCOMPATIBILITY_WARNING:
icon_id = &kBrowserToolsErrorIcon;
icon_id =
is_touch ? &kBrowserToolsErrorTouchIcon : &kBrowserToolsErrorIcon;
break;
}
......@@ -329,3 +343,25 @@ void AppMenuButton::OnDragExited() {
int AppMenuButton::OnPerformDrop(const ui::DropTargetEvent& event) {
return ui::DragDropTypes::DRAG_MOVE;
}
std::unique_ptr<views::InkDrop> AppMenuButton::CreateInkDrop() {
return CreateToolbarInkDrop<MenuButton>(this);
}
std::unique_ptr<views::InkDropRipple> AppMenuButton::CreateInkDropRipple()
const {
// FIXME: GetInkDropCenterBasedOnLastEvent() will always return the center
// of this view. https://crbug.com/819878.
return CreateToolbarInkDropRipple<MenuButton>(
this, GetInkDropCenterBasedOnLastEvent());
}
std::unique_ptr<views::InkDropHighlight> AppMenuButton::CreateInkDropHighlight()
const {
return CreateToolbarInkDropHighlight<MenuButton>(
this, GetMirroredRect(GetContentsBounds()).CenterPoint());
}
std::unique_ptr<views::InkDropMask> AppMenuButton::CreateInkDropMask() const {
return CreateToolbarInkDropMask<MenuButton>(this);
}
......@@ -31,6 +31,8 @@ class ToolbarView;
// The app menu button lives in the top right of the main browser window. It
// shows three dots and animates to a hamburger-ish icon when there's a need to
// alert the user. Clicking displays the app menu.
// TODO: Consider making ToolbarButton and AppMenuButton share a common base
// class https://crbug.com/819854.
class AppMenuButton : public views::MenuButton, public TabStripModelObserver {
public:
explicit AppMenuButton(ToolbarView* toolbar_view);
......@@ -108,6 +110,11 @@ class AppMenuButton : public views::MenuButton, public TabStripModelObserver {
int OnDragUpdated(const ui::DropTargetEvent& event) override;
void OnDragExited() override;
int OnPerformDrop(const ui::DropTargetEvent& event) override;
std::unique_ptr<views::InkDrop> CreateInkDrop() override;
std::unique_ptr<views::InkDropRipple> CreateInkDropRipple() const override;
std::unique_ptr<views::InkDropHighlight> CreateInkDropHighlight()
const override;
std::unique_ptr<views::InkDropMask> CreateInkDropMask() const override;
AppMenuIconController::Severity severity_ =
AppMenuIconController::Severity::NONE;
......
......@@ -15,6 +15,7 @@
#include "chrome/grit/generated_resources.h"
#include "components/vector_icons/vector_icons.h"
#include "ui/base/l10n/l10n_util.h"
#include "ui/base/material_design/material_design_controller.h"
#include "ui/base/models/simple_menu_model.h"
#include "ui/base/theme_provider.h"
#include "ui/base/window_open_disposition.h"
......@@ -31,6 +32,18 @@ const int kReloadMenuItems[] = {
IDS_RELOAD_MENU_EMPTY_AND_HARD_RELOAD_ITEM,
};
// Returns true if the touch-optimized UI is enabled.
bool IsTouchOptimized() {
return ui::MaterialDesignController::IsTouchOptimizedUiEnabled();
}
const gfx::VectorIcon& GetIconForMode(bool is_reload) {
if (IsTouchOptimized())
return is_reload ? kReloadTouchIcon : kNavigateStopTouchIcon;
return is_reload ? vector_icons::kReloadIcon : kNavigateStopIcon;
}
} // namespace
// ReloadButton ---------------------------------------------------------------
......@@ -224,8 +237,7 @@ void ReloadButton::ChangeModeInternal(Mode mode) {
const ui::ThemeProvider* tp = GetThemeProvider();
// |tp| can be NULL in unit tests.
if (tp) {
const gfx::VectorIcon& icon =
(mode == Mode::kReload) ? vector_icons::kReloadIcon : kNavigateStopIcon;
const gfx::VectorIcon& icon = GetIconForMode(mode == Mode::kReload);
const SkColor normal_color =
tp->GetColor(ThemeProperties::COLOR_TOOLBAR_BUTTON_ICON);
const SkColor disabled_color =
......
......@@ -12,18 +12,28 @@
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/themes/theme_service.h"
#include "chrome/browser/themes/theme_service_factory.h"
#include "chrome/browser/ui/layout_constants.h"
#include "chrome/browser/ui/views/toolbar/toolbar_ink_drop_util.h"
#include "ui/accessibility/ax_node_data.h"
#include "ui/base/material_design/material_design_controller.h"
#include "ui/base/models/menu_model.h"
#include "ui/display/display.h"
#include "ui/display/screen.h"
#include "ui/views/animation/ink_drop_highlight.h"
#include "ui/views/animation/ink_drop_ripple.h"
#include "ui/views/controls/button/label_button_border.h"
#include "ui/views/controls/menu/menu_item_view.h"
#include "ui/views/controls/menu/menu_model_adapter.h"
#include "ui/views/controls/menu/menu_runner.h"
#include "ui/views/widget/widget.h"
namespace {
// Returns true if the touch-optimized UI is enabled.
bool IsTouchOptimized() {
return ui::MaterialDesignController::IsTouchOptimizedUiEnabled();
}
} // namespace
ToolbarButton::ToolbarButton(Profile* profile,
views::ButtonListener* listener,
std::unique_ptr<ui::MenuModel> model)
......@@ -36,6 +46,9 @@ ToolbarButton::ToolbarButton(Profile* profile,
SetInkDropMode(InkDropMode::ON);
SetFocusPainter(nullptr);
SetLeadingMargin(0);
if (IsTouchOptimized())
set_ink_drop_visible_opacity(kTouchToolbarInkDropVisibleOpacity);
}
ToolbarButton::~ToolbarButton() {}
......@@ -45,8 +58,9 @@ void ToolbarButton::Init() {
}
void ToolbarButton::SetLeadingMargin(int margin) {
SetBorder(views::CreateEmptyBorder(gfx::Insets(kInteriorPadding) +
gfx::Insets(0, margin, 0, 0)));
const gfx::Insets insets =
GetLayoutInsets(TOOLBAR_BUTTON) + gfx::Insets(0, margin, 0, 0);
SetBorder(views::CreateEmptyBorder(insets));
}
void ToolbarButton::ClearPendingMenu() {
......@@ -133,6 +147,26 @@ void ToolbarButton::GetAccessibleNodeData(ui::AXNodeData* node_data) {
node_data->SetDefaultActionVerb(ax::mojom::DefaultActionVerb::kPress);
}
std::unique_ptr<views::InkDrop> ToolbarButton::CreateInkDrop() {
return CreateToolbarInkDrop<ImageButton>(this);
}
std::unique_ptr<views::InkDropRipple> ToolbarButton::CreateInkDropRipple()
const {
return CreateToolbarInkDropRipple<ImageButton>(
this, GetInkDropCenterBasedOnLastEvent());
}
std::unique_ptr<views::InkDropHighlight> ToolbarButton::CreateInkDropHighlight()
const {
return CreateToolbarInkDropHighlight<ImageButton>(
this, GetMirroredRect(GetContentsBounds()).CenterPoint());
}
std::unique_ptr<views::InkDropMask> ToolbarButton::CreateInkDropMask() const {
return CreateToolbarInkDropMask<ImageButton>(this);
}
void ToolbarButton::ShowContextMenuForView(View* source,
const gfx::Point& point,
ui::MenuSourceType source_type) {
......
......@@ -30,12 +30,11 @@ class MenuRunner;
// This class provides basic drawing and mouse-over behavior for buttons
// appearing in the toolbar.
// TODO: Consider making ToolbarButton and AppMenuButton share a common base
// class https://crbug.com/819854.
class ToolbarButton : public views::ImageButton,
public views::ContextMenuController {
public:
// Padding inside the border (around the image).
static constexpr int kInteriorPadding = 6;
// The profile and listener pointers must outlive this class. The model can
// be null if no menu is to be shown.
ToolbarButton(Profile* profile,
......@@ -64,6 +63,11 @@ class ToolbarButton : public views::ImageButton,
void OnMouseExited(const ui::MouseEvent& event) override;
void OnGestureEvent(ui::GestureEvent* event) override;
void GetAccessibleNodeData(ui::AXNodeData* node_data) override;
std::unique_ptr<views::InkDrop> CreateInkDrop() override;
std::unique_ptr<views::InkDropRipple> CreateInkDropRipple() const override;
std::unique_ptr<views::InkDropHighlight> CreateInkDropHighlight()
const override;
std::unique_ptr<views::InkDropMask> CreateInkDropMask() const override;
// views::ContextMenuController:
void ShowContextMenuForView(View* source,
......
// Copyright 2018 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 CHROME_BROWSER_UI_VIEWS_TOOLBAR_TOOLBAR_INK_DROP_UTIL_H_
#define CHROME_BROWSER_UI_VIEWS_TOOLBAR_TOOLBAR_INK_DROP_UTIL_H_
#include <memory>
#include "ui/base/material_design/material_design_controller.h"
#include "ui/gfx/geometry/insets.h"
#include "ui/gfx/geometry/point.h"
#include "ui/gfx/geometry/size.h"
#include "ui/views/animation/flood_fill_ink_drop_ripple.h"
#include "ui/views/animation/ink_drop_highlight.h"
#include "ui/views/animation/ink_drop_impl.h"
#include "ui/views/animation/ink_drop_mask.h"
#include "ui/views/animation/ink_drop_ripple.h"
namespace {
// Dimentions specific to the ink drop on the Browser's toolbar buttons when
// the Touch-optimized UI is being used.
constexpr int kTouchInkDropCornerRadius = 18;
constexpr gfx::Size kTouchInkDropHighlightSize{2 * kTouchInkDropCornerRadius,
2 * kTouchInkDropCornerRadius};
constexpr gfx::Insets kTouchInkDropInsets{6};
} // namespace
constexpr float kTouchToolbarInkDropVisibleOpacity = 0.06f;
// The below utility functions are templated since we have two different types
// of buttons on the toolbar (ToolbarButton and AppMenuButton) which don't share
// the same base classes (ImageButton and MenuButton respectively), and these
// functions need to call into the base classes' default implementations when
// needed.
// TODO: Consider making ToolbarButton and AppMenuButton share a common base
// class https://crbug.com/819854.
// Creates the appropriate ink drop for the calling button. When the touch-
// optimized UI is not enabled, it uses the default implementation of the
// calling button's base class (the template argument BaseInkDropHostView).
// Otherwise, it uses an ink drop that shows a highlight on hover that is kept
// and combined with the ripple when the ripple is shown.
template <class BaseInkDropHostView>
std::unique_ptr<views::InkDrop> CreateToolbarInkDrop(
BaseInkDropHostView* host_view) {
if (!ui::MaterialDesignController::IsTouchOptimizedUiEnabled())
return host_view->BaseInkDropHostView::CreateInkDrop();
auto ink_drop =
std::make_unique<views::InkDropImpl>(host_view, host_view->size());
ink_drop->SetAutoHighlightMode(
views::InkDropImpl::AutoHighlightMode::SHOW_ON_RIPPLE);
ink_drop->SetShowHighlightOnHover(true);
return ink_drop;
}
// Creates the appropriate ink drop ripple for the calling button. When the
// touch-optimized UI is not enabled, it uses the default implementation of the
// calling button's base class (the template argument BaseInkDropHostView).
// Otherwise, it uses a |FloodFillInkDropRipple|.
template <class BaseInkDropHostView>
std::unique_ptr<views::InkDropRipple> CreateToolbarInkDropRipple(
const BaseInkDropHostView* host_view,
const gfx::Point& center_point) {
if (!ui::MaterialDesignController::IsTouchOptimizedUiEnabled())
return host_view->BaseInkDropHostView::CreateInkDropRipple();
return std::make_unique<views::FloodFillInkDropRipple>(
host_view->size(), kTouchInkDropInsets, center_point,
host_view->GetInkDropBaseColor(), host_view->ink_drop_visible_opacity());
}
// Creates the appropriate ink drop highlight for the calling button. When the
// touch-optimized UI is not enabled, it uses the default implementation of the
// calling button's base class (the template argument BaseInkDropHostView).
// Otherwise, it uses a kTouchInkDropHighlightSize circular highlight.
template <class BaseInkDropHostView>
std::unique_ptr<views::InkDropHighlight> CreateToolbarInkDropHighlight(
const BaseInkDropHostView* host_view,
const gfx::Point& center_point) {
if (!ui::MaterialDesignController::IsTouchOptimizedUiEnabled())
return host_view->BaseInkDropHostView::CreateInkDropHighlight();
auto highlight = std::make_unique<views::InkDropHighlight>(
kTouchInkDropHighlightSize, kTouchInkDropCornerRadius,
gfx::PointF(center_point), host_view->GetInkDropBaseColor());
highlight->set_visible_opacity(0.08f);
return highlight;
}
// Creates the appropriate ink drop mask for the calling button. When the
// touch-optimized UI is not enabled, it uses the default implementation of the
// calling button's base class (the template argument BaseInkDropHostView).
// Otherwise, it uses a circular mask that has the same size as that of the
// highlight, which is needed to make the flood
// fill ripple fill a circle rather than a default square shape.
template <class BaseInkDropHostView>
std::unique_ptr<views::InkDropMask> CreateToolbarInkDropMask(
const BaseInkDropHostView* host_view) {
if (!ui::MaterialDesignController::IsTouchOptimizedUiEnabled())
return host_view->BaseInkDropHostView::CreateInkDropMask();
return std::make_unique<views::RoundRectInkDropMask>(
host_view->size(), kTouchInkDropInsets, kTouchInkDropCornerRadius);
}
#endif // CHROME_BROWSER_UI_VIEWS_TOOLBAR_TOOLBAR_INK_DROP_UTIL_H_
......@@ -89,8 +89,17 @@ using content::WebContents;
namespace {
int GetToolbarHorizontalPadding() {
// In the touch-optimized UI, we don't use any horizontal paddings; the back
// button starts from the beginning of the view, and the app menu button ends
// at the end of the view.
using Md = ui::MaterialDesignController;
return Md::GetMode() == Md::MATERIAL_HYBRID ? 8 : 4;
constexpr int kPaddings[] = {4, 8, 0};
return kPaddings[Md::GetMode()];
}
// Returns true if the touch-optimized UI is enabled.
bool IsTouchOptimized() {
return ui::MaterialDesignController::IsTouchOptimizedUiEnabled();
}
} // namespace
......@@ -333,13 +342,6 @@ bool ToolbarView::SetPaneFocus(views::View* initial_focus) {
return true;
}
////////////////////////////////////////////////////////////////////////////////
// ToolbarView, Menu::Delegate overrides:
bool ToolbarView::GetAcceleratorInfo(int id, ui::Accelerator* accel) {
return GetWidget()->GetAccelerator(id, accel);
}
////////////////////////////////////////////////////////////////////////////////
// ToolbarView, views::MenuButtonListener implementation:
......@@ -538,7 +540,6 @@ void ToolbarView::Layout() {
const int location_height = location_bar_->GetPreferredSize().height();
const int location_y = (height() - location_height) / 2;
location_bar_->SetBounds(next_element_x, location_y,
location_bar_width, location_height);
......@@ -567,6 +568,7 @@ void ToolbarView::Layout() {
// we extend the back button to the left edge.
if (maximized)
app_menu_width += end_padding;
app_menu_button_->SetBounds(next_element_x, toolbar_button_y, app_menu_width,
toolbar_button_height);
app_menu_button_->SetTrailingMargin(maximized ? end_padding : 0);
......@@ -698,8 +700,10 @@ gfx::Size ToolbarView::SizeForContentSize(gfx::Size size) const {
// and constant padding values.
int content_height = std::max(back_->GetPreferredSize().height(),
location_bar_->GetPreferredSize().height());
const int kExtraVerticalSpace = 9;
size.SetToMax(gfx::Size(0, content_height + kExtraVerticalSpace));
// In the touch-optimized UI, the toolbar buttons are big and occupy the
// entire view's height, we don't need to add any extra vertical space.
const int extra_vertical_space = IsTouchOptimized() ? 0 : 9;
size.SetToMax(gfx::Size(0, content_height + extra_vertical_space));
}
return size;
}
......@@ -712,26 +716,33 @@ void ToolbarView::LoadImages() {
const SkColor disabled_color =
tp->GetColor(ThemeProperties::COLOR_TOOLBAR_BUTTON_ICON_INACTIVE);
back_->SetImage(
views::Button::STATE_NORMAL,
gfx::CreateVectorIcon(vector_icons::kBackArrowIcon, normal_color));
back_->SetImage(
views::Button::STATE_DISABLED,
gfx::CreateVectorIcon(vector_icons::kBackArrowIcon, disabled_color));
forward_->SetImage(
views::Button::STATE_NORMAL,
gfx::CreateVectorIcon(vector_icons::kForwardArrowIcon, normal_color));
forward_->SetImage(
views::Button::STATE_DISABLED,
gfx::CreateVectorIcon(vector_icons::kForwardArrowIcon, disabled_color));
const bool is_touch = IsTouchOptimized();
const gfx::VectorIcon& back_image =
is_touch ? kBackArrowTouchIcon : vector_icons::kBackArrowIcon;
back_->SetImage(views::Button::STATE_NORMAL,
gfx::CreateVectorIcon(back_image, normal_color));
back_->SetImage(views::Button::STATE_DISABLED,
gfx::CreateVectorIcon(back_image, disabled_color));
const gfx::VectorIcon& forward_image =
is_touch ? kForwardArrowTouchIcon : vector_icons::kForwardArrowIcon;
forward_->SetImage(views::Button::STATE_NORMAL,
gfx::CreateVectorIcon(forward_image, normal_color));
forward_->SetImage(views::Button::STATE_DISABLED,
gfx::CreateVectorIcon(forward_image, disabled_color));
const gfx::VectorIcon& home_image =
is_touch ? kNavigateHomeTouchIcon : kNavigateHomeIcon;
home_->SetImage(views::Button::STATE_NORMAL,
gfx::CreateVectorIcon(kNavigateHomeIcon, normal_color));
gfx::CreateVectorIcon(home_image, normal_color));
app_menu_button_->UpdateIcon(false);
back_->set_ink_drop_base_color(normal_color);
forward_->set_ink_drop_base_color(normal_color);
home_->set_ink_drop_base_color(normal_color);
app_menu_button_->set_ink_drop_base_color(normal_color);
const SkColor ink_drop_color = color_utils::BlendTowardOppositeLuma(
tp->GetColor(ThemeProperties::COLOR_TOOLBAR), SK_AlphaOPAQUE);
back_->set_ink_drop_base_color(ink_drop_color);
forward_->set_ink_drop_base_color(ink_drop_color);
home_->set_ink_drop_base_color(ink_drop_color);
app_menu_button_->set_ink_drop_base_color(ink_drop_color);
reload_->LoadImages();
}
......
......@@ -81,8 +81,6 @@ class ToolbarView : public views::AccessiblePaneView,
// Returns true if the app menu is focused.
bool IsAppMenuFocused();
virtual bool GetAcceleratorInfo(int id, ui::Accelerator* accel);
#if defined(OS_CHROMEOS)
void ShowIntentPickerBubble(
const std::vector<IntentPickerBubbleView::AppInfo>& app_info,
......
......@@ -168,6 +168,10 @@ std::unique_ptr<InkDropHighlight> InkDropHostView::CreateInkDropHighlight()
gfx::RectF(GetMirroredRect(GetContentsBounds())).CenterPoint());
}
std::unique_ptr<views::InkDropMask> InkDropHostView::CreateInkDropMask() const {
return nullptr;
}
std::unique_ptr<InkDropRipple> InkDropHostView::CreateDefaultInkDropRipple(
const gfx::Point& center_point,
const gfx::Size& size) const {
......@@ -278,10 +282,6 @@ SkColor InkDropHostView::GetInkDropBaseColor() const {
return gfx::kPlaceholderColor;
}
std::unique_ptr<views::InkDropMask> InkDropHostView::CreateInkDropMask() const {
return nullptr;
}
bool InkDropHostView::HasInkDrop() const {
return !!ink_drop_;
}
......
......@@ -45,6 +45,12 @@ class VIEWS_EXPORT InkDropHostView : public View, public InkDropHost {
std::unique_ptr<InkDropRipple> CreateInkDropRipple() const override;
std::unique_ptr<InkDropHighlight> CreateInkDropHighlight() const override;
// Subclasses can override to return a mask for the ink drop. By default,
// returns nullptr (i.e no mask).
// TODO(bruthig): InkDropMasks do not currently work on Windows. See
// https://crbug.com/713359.
virtual std::unique_ptr<views::InkDropMask> CreateInkDropMask() const;
// Toggle to enable/disable an InkDrop on this View. Descendants can override
// CreateInkDropHighlight() and CreateInkDropRipple() to change the look/feel
// of the InkDrop.
......@@ -107,12 +113,6 @@ class VIEWS_EXPORT InkDropHostView : public View, public InkDropHost {
// ink drop.
virtual SkColor GetInkDropBaseColor() const;
// Subclasses can override to return a mask for the ink drop. By default,
// returns nullptr (i.e no mask).
// TODO(bruthig): InkDropMasks do not currently work on Windows. See
// crbug.com/713359.
virtual std::unique_ptr<views::InkDropMask> CreateInkDropMask() const;
// Called after a new InkDrop instance is created.
virtual void OnInkDropCreated() {}
......
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