Skip to content

Commit ed63ea8

Browse files
committed
Fix touchable insets for Avatar/Cast toolbar icons
An earlier refactoring set zero-insets for touchable AvatarToolbarButton instead of insets for TOOLBAR_BUTTON. This API was confusing to use so SetLayoutInsets was changed and renamed to SetLayoutInsetDelta to make it easier to use. Callers no longer need to include the call to GetLayoutInsets(TOOLBAR_BUTTON). CastToolbarButton having incorrect ink-drops was not a regression but has always used a 16dp icon in both touchable and non-touchable modes. This change also calls SetInsetDelta to make up for the missing 8dp. Bug: chromium:895519 Change-Id: I30595913dfb8a19358d198d9f4e0dbcb37993117 Reviewed-on: https://chromium-review.googlesource.com/c/1281903 Reviewed-by: Bret Sepulveda <[email protected]> Commit-Queue: Peter Boström <[email protected]> Cr-Original-Commit-Position: refs/heads/master@{#599765}(cherry picked from commit 019423b) Reviewed-on: https://chromium-review.googlesource.com/c/1285321 Reviewed-by: Peter Boström <[email protected]> Cr-Commit-Position: refs/branch-heads/3578@{#74} Cr-Branched-From: 4226ddf-refs/heads/master@{#599034}
1 parent dd66965 commit ed63ea8

File tree

4 files changed

+21
-16
lines changed

4 files changed

+21
-16
lines changed

chrome/browser/ui/views/media_router/cast_toolbar_button.cc

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,12 @@
99
#include "chrome/browser/media/router/media_router_factory.h"
1010
#include "chrome/browser/media/router/media_router_metrics.h"
1111
#include "chrome/browser/ui/browser.h"
12+
#include "chrome/browser/ui/layout_constants.h"
1213
#include "chrome/browser/ui/media_router/media_router_ui_service.h"
1314
#include "chrome/grit/generated_resources.h"
1415
#include "components/vector_icons/vector_icons.h"
1516
#include "ui/base/l10n/l10n_util.h"
17+
#include "ui/base/material_design/material_design_controller.h"
1618
#include "ui/base/models/menu_model.h"
1719
#include "ui/gfx/color_palette.h"
1820
#include "ui/gfx/paint_vector_icon.h"
@@ -83,6 +85,10 @@ void CastToolbarButton::UpdateIcon() {
8385
const gfx::VectorIcon& icon = GetCurrentIcon();
8486
SetImage(views::Button::STATE_NORMAL,
8587
gfx::CreateVectorIcon(icon, GetIconColor(&icon)));
88+
// This icon is smaller than the touchable-UI expected 24dp, so we need to pad
89+
// the insets to match.
90+
SetLayoutInsetDelta(gfx::Insets(
91+
ui::MaterialDesignController::IsTouchOptimizedUiEnabled() ? 4 : 0));
8692
}
8793

8894
const gfx::VectorIcon& CastToolbarButton::GetCurrentIcon() const {

chrome/browser/ui/views/profiles/avatar_toolbar_button.cc

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -340,9 +340,7 @@ AvatarToolbarButton::SyncState AvatarToolbarButton::GetSyncState() const {
340340

341341
void AvatarToolbarButton::SetInsets() {
342342
// In non-touch mode we use a larger-than-normal icon size for avatars as 16dp
343-
// is hard to read for user avatars. This constant is correspondingly smaller
344-
// than GetLayoutInsets(TOOLBAR_BUTTON).
345-
SetLayoutInsets(ui::MaterialDesignController::IsTouchOptimizedUiEnabled()
346-
? gfx::Insets()
347-
: GetLayoutInsets(TOOLBAR_BUTTON) - gfx::Insets(2));
343+
// is hard to read for user avatars, so we need to set corresponding insets.
344+
SetLayoutInsetDelta(gfx::Insets(
345+
ui::MaterialDesignController::IsTouchOptimizedUiEnabled() ? 0 : -2));
348346
}

chrome/browser/ui/views/toolbar/toolbar_button.cc

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -88,17 +88,18 @@ void ToolbarButton::UpdateHighlightBackgroundAndInsets() {
8888
SetEnabledTextColors(*highlight_color_);
8989
}
9090

91-
gfx::Insets insets = (layout_insets_ ? layout_insets_.value()
92-
: GetLayoutInsets(TOOLBAR_BUTTON)) +
91+
gfx::Insets insets = GetLayoutInsets(TOOLBAR_BUTTON) + layout_inset_delta_ +
9392
gfx::Insets(0, leading_margin_, 0, 0);
9493
if (highlight_color_)
9594
insets += gfx::Insets(0, highlight_radius / 2, 0, 0);
9695

9796
SetBorder(views::CreateEmptyBorder(insets));
9897
}
9998

100-
void ToolbarButton::SetLayoutInsets(const gfx::Insets& insets) {
101-
layout_insets_ = insets;
99+
void ToolbarButton::SetLayoutInsetDelta(const gfx::Insets& inset_delta) {
100+
if (layout_inset_delta_ == inset_delta)
101+
return;
102+
layout_inset_delta_ = inset_delta;
102103
UpdateHighlightBackgroundAndInsets();
103104
}
104105

chrome/browser/ui/views/toolbar/toolbar_button.h

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -97,8 +97,8 @@ class ToolbarButton : public views::LabelButton,
9797
// Function to show the dropdown menu.
9898
virtual void ShowDropDownMenu(ui::MenuSourceType source_type);
9999

100-
// Sets |layout_insets_|, see comment there.
101-
void SetLayoutInsets(const gfx::Insets& insets);
100+
// Sets |layout_inset_delta_|, see comment there.
101+
void SetLayoutInsetDelta(const gfx::Insets& insets);
102102

103103
private:
104104
friend test::ToolbarButtonTestApi;
@@ -136,11 +136,11 @@ class ToolbarButton : public views::LabelButton,
136136
// to extend to the full window width.
137137
int leading_margin_ = 0;
138138

139-
// Base layout insets that are used for the button. This is overridable as
140-
// AvatarToolbarButton uses smaller insets to accommodate for a larger avatar
141-
// avatar icon. |leading_margin_| and |ink_drop_large_corner_radius()| are
142-
// also used to calculate final insets.
143-
base::Optional<gfx::Insets> layout_insets_;
139+
// Delta from regular toolbar-button insets. This is necessary for buttons
140+
// that use smaller or larger icons than regular ToolbarButton instances.
141+
// AvatarToolbarButton for instance uses smaller insets to accommodate for a
142+
// larger-than-16dp avatar avatar icon outside of touchable mode.
143+
gfx::Insets layout_inset_delta_;
144144

145145
// A highlight color is used to signal error states. When set this color is
146146
// used as a base for background, text and ink drops. When not set, uses the

0 commit comments

Comments
 (0)