Commit 2fefe1b8 authored by Malay Keshav's avatar Malay Keshav Committed by Commit Bot

Adds touch optimization to ink drop animations in bookmarkbar buttons

This patch adds the layout constants for the rounded corners in
bookmark button ink drop highligh and ripple. It also adds the colors
the ink drop animation.

Bug: 810902
Change-Id: I96853d3c66eeca45881901a6d8b2053d2838c16e
Component: Bookmarkbar, theme colors
Reviewed-on: https://chromium-review.googlesource.com/954546
Commit-Queue: Malay Keshav <malaykeshav@chromium.org>
Reviewed-by: default avatarPeter Kasting <pkasting@chromium.org>
Cr-Commit-Position: refs/heads/master@{#542684}
parent d344b787
...@@ -48,6 +48,7 @@ ...@@ -48,6 +48,7 @@
#include "chrome/browser/ui/views/frame/browser_view.h" #include "chrome/browser/ui/views/frame/browser_view.h"
#include "chrome/browser/ui/views/harmony/chrome_layout_provider.h" #include "chrome/browser/ui/views/harmony/chrome_layout_provider.h"
#include "chrome/browser/ui/views/location_bar/location_bar_view.h" #include "chrome/browser/ui/views/location_bar/location_bar_view.h"
#include "chrome/browser/ui/views/toolbar/toolbar_ink_drop_util.h"
#include "chrome/common/chrome_switches.h" #include "chrome/common/chrome_switches.h"
#include "chrome/common/extensions/extension_constants.h" #include "chrome/common/extensions/extension_constants.h"
#include "chrome/common/extensions/extension_metrics.h" #include "chrome/common/extensions/extension_metrics.h"
...@@ -124,9 +125,6 @@ static const int kNewTabHorizontalPadding = 2; ...@@ -124,9 +125,6 @@ static const int kNewTabHorizontalPadding = 2;
// Maximum size of buttons on the bookmark bar. // Maximum size of buttons on the bookmark bar.
static const int kMaxButtonWidth = 150; static const int kMaxButtonWidth = 150;
// Corner radius for masking the ink drop effects on buttons.
static const int kInkDropCornerRadius = 2;
// Number of pixels the attached bookmark bar overlaps with the toolbar. // Number of pixels the attached bookmark bar overlaps with the toolbar.
static const int kToolbarAttachedBookmarkBarOverlap = 3; static const int kToolbarAttachedBookmarkBarOverlap = 3;
...@@ -167,13 +165,62 @@ gfx::ImageSkia* GetImageSkiaNamed(int id) { ...@@ -167,13 +165,62 @@ gfx::ImageSkia* GetImageSkiaNamed(int id) {
return ui::ResourceBundle::GetSharedInstance().GetImageSkiaNamed(id); return ui::ResourceBundle::GetSharedInstance().GetImageSkiaNamed(id);
} }
constexpr int kInkDropVerticalInsetPx = 1; bool IsTouchOptimized() {
return ui::MaterialDesignController::IsTouchOptimizedUiEnabled();
}
int GetInkDropCornerRadius() {
return IsTouchOptimized() ? 4 : 2;
}
gfx::Insets GetInkDropInsets() {
// Ink drop ripple/highlight for bookmark buttons should be inset 1px
// vertically so that they do not touch the bookmark bar borders.
// TODO(estade): currently this is used as DIP rather than pixels. This
// should be fixed: see https://crbug.com/706228
return IsTouchOptimized() ? gfx::Insets(3, 3) : gfx::Insets(1, 0);
}
SkColor GetBookmarkButtonInkDropBaseColor(const ui::ThemeProvider* tp) {
if (IsTouchOptimized()) {
return color_utils::BlendTowardOppositeLuma(
tp->GetColor(ThemeProperties::COLOR_TOOLBAR), SK_AlphaOPAQUE);
}
return tp->GetColor(ThemeProperties::COLOR_TOOLBAR_BUTTON_ICON);
}
std::unique_ptr<views::InkDrop> CreateBookmarkButtonInkDrop(
std::unique_ptr<views::InkDropImpl> ink_drop) {
ink_drop->SetShowHighlightOnFocus(true);
return std::move(ink_drop);
}
std::unique_ptr<views::InkDropRipple> CreateBookmarkButtonInkDropRipple(
const views::InkDropHostView* host_view,
const gfx::Point& center_point) {
return std::make_unique<views::FloodFillInkDropRipple>(
host_view->size(), GetInkDropInsets(), center_point,
GetBookmarkButtonInkDropBaseColor(host_view->GetThemeProvider()),
host_view->ink_drop_visible_opacity());
}
std::unique_ptr<views::InkDropMask> CreateBookmarkButtonInkDropMask(
const views::InkDropHostView* host_view) {
return std::make_unique<views::RoundRectInkDropMask>(
host_view->size(), GetInkDropInsets(), GetInkDropCornerRadius());
}
// Ink drop ripple/highlight for bookmark buttons should be inset 1px vertically std::unique_ptr<views::InkDropHighlight> CreateBookmarkButtonInkDropHighlight(
// so that they do not touch the bookmark bar borders. const views::InkDropHostView* host_view) {
// TODO(estade): currently this is used as DIP rather than pixels. This should std::unique_ptr<views::InkDropHighlight> highlight(
// be fixed: see crbug.com/706228 new views::InkDropHighlight(
constexpr gfx::Insets kInkDropInsets(kInkDropVerticalInsetPx, 0); host_view->size(), GetInkDropCornerRadius(),
gfx::RectF(gfx::Rect(host_view->size())).CenterPoint(),
GetBookmarkButtonInkDropBaseColor(host_view->GetThemeProvider())));
if (IsTouchOptimized())
highlight->set_visible_opacity(kTouchToolbarHighlightVisibleOpacity);
return highlight;
}
// BookmarkButtonBase ----------------------------------------------- // BookmarkButtonBase -----------------------------------------------
...@@ -189,6 +236,8 @@ class BookmarkButtonBase : public views::LabelButton { ...@@ -189,6 +236,8 @@ class BookmarkButtonBase : public views::LabelButton {
SetElideBehavior(kElideBehavior); SetElideBehavior(kElideBehavior);
SetInkDropMode(InkDropMode::ON); SetInkDropMode(InkDropMode::ON);
set_has_ink_drop_action_on_click(true); set_has_ink_drop_action_on_click(true);
if (IsTouchOptimized())
set_ink_drop_visible_opacity(kTouchToolbarInkDropVisibleOpacity);
SetFocusPainter(nullptr); SetFocusPainter(nullptr);
show_animation_.reset(new gfx::SlideAnimation(this)); show_animation_.reset(new gfx::SlideAnimation(this));
if (!animations_enabled) { if (!animations_enabled) {
...@@ -213,37 +262,21 @@ class BookmarkButtonBase : public views::LabelButton { ...@@ -213,37 +262,21 @@ class BookmarkButtonBase : public views::LabelButton {
// LabelButton: // LabelButton:
std::unique_ptr<views::InkDrop> CreateInkDrop() override { std::unique_ptr<views::InkDrop> CreateInkDrop() override {
std::unique_ptr<views::InkDropImpl> ink_drop = return CreateBookmarkButtonInkDrop(CreateDefaultFloodFillInkDropImpl());
CreateDefaultFloodFillInkDropImpl();
ink_drop->SetShowHighlightOnFocus(true);
return std::move(ink_drop);
} }
std::unique_ptr<views::InkDropRipple> CreateInkDropRipple() const override { std::unique_ptr<views::InkDropRipple> CreateInkDropRipple() const override {
return std::make_unique<views::FloodFillInkDropRipple>( return CreateBookmarkButtonInkDropRipple(
size(), kInkDropInsets, GetInkDropCenterBasedOnLastEvent(), this, GetInkDropCenterBasedOnLastEvent());
GetInkDropBaseColor(), ink_drop_visible_opacity());
} }
std::unique_ptr<views::InkDropHighlight> CreateInkDropHighlight() std::unique_ptr<views::InkDropHighlight> CreateInkDropHighlight()
const override { const override {
gfx::RectF bounds((gfx::Rect(size()))); return CreateBookmarkButtonInkDropHighlight(this);
bounds.Inset(gfx::InsetsF(
kInkDropVerticalInsetPx /
GetWidget()->GetLayer()->GetCompositor()->device_scale_factor(),
0));
return std::make_unique<views::InkDropHighlight>(
bounds.size(), 0, bounds.CenterPoint(), GetInkDropBaseColor());
} }
std::unique_ptr<views::InkDropMask> CreateInkDropMask() const override { std::unique_ptr<views::InkDropMask> CreateInkDropMask() const override {
return std::make_unique<views::RoundRectInkDropMask>(size(), kInkDropInsets, return CreateBookmarkButtonInkDropMask(this);
kInkDropCornerRadius);
}
SkColor GetInkDropBaseColor() const override {
return GetThemeProvider()->GetColor(
ThemeProperties::COLOR_TOOLBAR_BUTTON_ICON);
} }
private: private:
...@@ -340,42 +373,28 @@ class BookmarkMenuButtonBase : public views::MenuButton { ...@@ -340,42 +373,28 @@ class BookmarkMenuButtonBase : public views::MenuButton {
SetImageLabelSpacing(ChromeLayoutProvider::Get()->GetDistanceMetric( SetImageLabelSpacing(ChromeLayoutProvider::Get()->GetDistanceMetric(
DISTANCE_RELATED_LABEL_HORIZONTAL_LIST)); DISTANCE_RELATED_LABEL_HORIZONTAL_LIST));
SetInkDropMode(InkDropMode::ON); SetInkDropMode(InkDropMode::ON);
if (IsTouchOptimized())
set_ink_drop_visible_opacity(kTouchToolbarInkDropVisibleOpacity);
SetFocusPainter(nullptr); SetFocusPainter(nullptr);
} }
// MenuButton: // MenuButton:
std::unique_ptr<views::InkDrop> CreateInkDrop() override { std::unique_ptr<views::InkDrop> CreateInkDrop() override {
std::unique_ptr<views::InkDropImpl> ink_drop = return CreateBookmarkButtonInkDrop(CreateDefaultFloodFillInkDropImpl());
CreateDefaultFloodFillInkDropImpl();
ink_drop->SetShowHighlightOnFocus(true);
return std::move(ink_drop);
} }
std::unique_ptr<views::InkDropRipple> CreateInkDropRipple() const override { std::unique_ptr<views::InkDropRipple> CreateInkDropRipple() const override {
return std::make_unique<views::FloodFillInkDropRipple>( return CreateBookmarkButtonInkDropRipple(
size(), kInkDropInsets, GetInkDropCenterBasedOnLastEvent(), this, GetInkDropCenterBasedOnLastEvent());
GetInkDropBaseColor(), ink_drop_visible_opacity());
} }
std::unique_ptr<views::InkDropHighlight> CreateInkDropHighlight() std::unique_ptr<views::InkDropHighlight> CreateInkDropHighlight()
const override { const override {
gfx::RectF bounds((gfx::Rect(size()))); return CreateBookmarkButtonInkDropHighlight(this);
bounds.Inset(gfx::InsetsF(
kInkDropVerticalInsetPx /
GetWidget()->GetLayer()->GetCompositor()->device_scale_factor(),
0));
return std::make_unique<views::InkDropHighlight>(
bounds.size(), 0, bounds.CenterPoint(), GetInkDropBaseColor());
} }
std::unique_ptr<views::InkDropMask> CreateInkDropMask() const override { std::unique_ptr<views::InkDropMask> CreateInkDropMask() const override {
return std::make_unique<views::RoundRectInkDropMask>(size(), kInkDropInsets, return CreateBookmarkButtonInkDropMask(this);
kInkDropCornerRadius);
}
SkColor GetInkDropBaseColor() const override {
return GetThemeProvider()->GetColor(
ThemeProperties::COLOR_TOOLBAR_BUTTON_ICON);
} }
private: private:
...@@ -1720,8 +1739,7 @@ void BookmarkBarView::ConfigureButton(const BookmarkNode* node, ...@@ -1720,8 +1739,7 @@ void BookmarkBarView::ConfigureButton(const BookmarkNode* node,
bool themify_icon = node->url().SchemeIs(content::kChromeUIScheme); bool themify_icon = node->url().SchemeIs(content::kChromeUIScheme);
gfx::ImageSkia favicon = model_->GetFavicon(node).AsImageSkia(); gfx::ImageSkia favicon = model_->GetFavicon(node).AsImageSkia();
if (favicon.isNull()) { if (favicon.isNull()) {
if (ui::MaterialDesignController::IsTouchOptimizedUiEnabled() && if (IsTouchOptimized() && GetThemeProvider()) {
GetThemeProvider()) {
// This favicon currently does not match the default favicon icon used // This favicon currently does not match the default favicon icon used
// elsewhere in the codebase. // elsewhere in the codebase.
// See https://crbug/814447 // See https://crbug/814447
...@@ -2047,11 +2065,9 @@ void BookmarkBarView::UpdateAppearanceForTheme() { ...@@ -2047,11 +2065,9 @@ void BookmarkBarView::UpdateAppearanceForTheme() {
const SkColor overflow_color = const SkColor overflow_color =
theme_provider->GetColor(ThemeProperties::COLOR_TOOLBAR_BUTTON_ICON); theme_provider->GetColor(ThemeProperties::COLOR_TOOLBAR_BUTTON_ICON);
const bool is_touch_optimized =
ui::MaterialDesignController::IsTouchOptimizedUiEnabled();
overflow_button_->SetImage( overflow_button_->SetImage(
views::Button::STATE_NORMAL, views::Button::STATE_NORMAL,
gfx::CreateVectorIcon(is_touch_optimized ? kBookmarkbarTouchOverflowIcon gfx::CreateVectorIcon(IsTouchOptimized() ? kBookmarkbarTouchOverflowIcon
: kOverflowChevronIcon, : kOverflowChevronIcon,
overflow_color)); overflow_color));
......
...@@ -29,6 +29,7 @@ constexpr gfx::Insets kTouchInkDropInsets{6}; ...@@ -29,6 +29,7 @@ constexpr gfx::Insets kTouchInkDropInsets{6};
} // namespace } // namespace
constexpr float kTouchToolbarInkDropVisibleOpacity = 0.06f; constexpr float kTouchToolbarInkDropVisibleOpacity = 0.06f;
constexpr float kTouchToolbarHighlightVisibleOpacity = 0.08f;
// The below utility functions are templated since we have two different types // The below utility functions are templated since we have two different types
// of buttons on the toolbar (ToolbarButton and AppMenuButton) which don't share // of buttons on the toolbar (ToolbarButton and AppMenuButton) which don't share
...@@ -87,7 +88,7 @@ std::unique_ptr<views::InkDropHighlight> CreateToolbarInkDropHighlight( ...@@ -87,7 +88,7 @@ std::unique_ptr<views::InkDropHighlight> CreateToolbarInkDropHighlight(
auto highlight = std::make_unique<views::InkDropHighlight>( auto highlight = std::make_unique<views::InkDropHighlight>(
kTouchInkDropHighlightSize, kTouchInkDropCornerRadius, kTouchInkDropHighlightSize, kTouchInkDropCornerRadius,
gfx::PointF(center_point), host_view->GetInkDropBaseColor()); gfx::PointF(center_point), host_view->GetInkDropBaseColor());
highlight->set_visible_opacity(0.08f); highlight->set_visible_opacity(kTouchToolbarHighlightVisibleOpacity);
return highlight; return highlight;
} }
......
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