Commit 82848abb authored by Peter Boström's avatar Peter Boström Committed by Commit Bot

Decrease extension button size + add spacing

This makes ToolbarActionView the same size as other toolbar buttons
instead of increasing its internal size with 4dp to accomodate for
padding between items.

This reduces the BrowserActionsContainer height by 4dp (matching its
current visual height) so it should no longer be able to push the
toolbar height. It also fixes some polish where the spacing left and
right of the browser actions were inadvertedly 10dp instead of 8dp.

Bug: chromium:831393, chromium:916241, chromium:916462
Change-Id: I63e5413ce187f173a5e35b40a3ec8f02a68fa09c
Reviewed-on: https://chromium-review.googlesource.com/c/1394870Reviewed-by: default avatarElly Fong-Jones <ellyjones@chromium.org>
Commit-Queue: Peter Boström <pbos@chromium.org>
Cr-Commit-Position: refs/heads/master@{#619999}
parent df014e7c
...@@ -99,7 +99,7 @@ gfx::Insets GetLayoutInsets(LayoutInset inset) { ...@@ -99,7 +99,7 @@ gfx::Insets GetLayoutInsets(LayoutInset inset) {
case TOOLBAR_ACTION_VIEW: { case TOOLBAR_ACTION_VIEW: {
// TODO(afakhry): Unify all toolbar button sizes on all platforms. // TODO(afakhry): Unify all toolbar button sizes on all platforms.
// https://crbug.com/822967. // https://crbug.com/822967.
return gfx::Insets(touch_ui ? 10 : 2); return gfx::Insets(touch_ui ? 10 : 0);
} }
} }
NOTREACHED(); NOTREACHED();
......
...@@ -166,7 +166,7 @@ gfx::Size ToolbarActionsBar::GetFullSize() const { ...@@ -166,7 +166,7 @@ gfx::Size ToolbarActionsBar::GetFullSize() const {
num_rows += (std::max(0, icon_count - 1) / num_icons); num_rows += (std::max(0, icon_count - 1) / num_icons);
} }
return gfx::ScaleToFlooredSize(GetViewSize(), num_icons, num_rows); return gfx::Size(IconCountToWidth(num_icons), IconCountToWidth(num_rows));
} }
int ToolbarActionsBar::GetMinimumWidth() const { int ToolbarActionsBar::GetMinimumWidth() const {
...@@ -178,12 +178,17 @@ int ToolbarActionsBar::GetMaximumWidth() const { ...@@ -178,12 +178,17 @@ int ToolbarActionsBar::GetMaximumWidth() const {
} }
int ToolbarActionsBar::IconCountToWidth(size_t icons) const { int ToolbarActionsBar::IconCountToWidth(size_t icons) const {
return icons * GetViewSize().width(); if (icons == 0)
return 0;
return icons * GetViewSize().width() +
(icons - 1) * GetLayoutConstant(TOOLBAR_ELEMENT_PADDING);
} }
size_t ToolbarActionsBar::WidthToIconCount(int pixels) const { size_t ToolbarActionsBar::WidthToIconCount(int pixels) const {
return base::ClampToRange(pixels / GetViewSize().width(), 0, const int element_padding = GetLayoutConstant(TOOLBAR_ELEMENT_PADDING);
static_cast<int>(toolbar_actions_.size())); return base::ClampToRange(
(pixels + element_padding) / (GetViewSize().width() + element_padding), 0,
static_cast<int>(toolbar_actions_.size()));
} }
size_t ToolbarActionsBar::GetIconCount() const { size_t ToolbarActionsBar::GetIconCount() const {
...@@ -274,8 +279,10 @@ gfx::Rect ToolbarActionsBar::GetFrameForIndex( ...@@ -274,8 +279,10 @@ gfx::Rect ToolbarActionsBar::GetFrameForIndex(
: relative_index; : relative_index;
const auto size = GetViewSize(); const auto size = GetViewSize();
return gfx::Rect( const int element_padding = GetLayoutConstant(TOOLBAR_ELEMENT_PADDING);
gfx::Point(index_in_row * size.width(), row_index * size.height()), size); return gfx::Rect(gfx::Point(index_in_row * (size.width() + element_padding),
row_index * (size.height() + element_padding)),
size);
} }
std::vector<ToolbarActionViewController*> std::vector<ToolbarActionViewController*>
...@@ -372,7 +379,7 @@ bool ToolbarActionsBar::ShowToolbarActionPopup(const std::string& action_id, ...@@ -372,7 +379,7 @@ bool ToolbarActionsBar::ShowToolbarActionPopup(const std::string& action_id,
void ToolbarActionsBar::SetOverflowRowWidth(int width) { void ToolbarActionsBar::SetOverflowRowWidth(int width) {
DCHECK(in_overflow_mode()); DCHECK(in_overflow_mode());
platform_settings_.icons_per_overflow_menu_row = platform_settings_.icons_per_overflow_menu_row =
std::max(width / GetViewSize().width(), 1); std::max(WidthToIconCount(width), static_cast<size_t>(1));
} }
void ToolbarActionsBar::OnResizeComplete(int width) { void ToolbarActionsBar::OnResizeComplete(int width) {
......
...@@ -255,7 +255,8 @@ TEST_P(ToolbarActionsBarUnitTest, BasicToolbarActionsBarTest) { ...@@ -255,7 +255,8 @@ TEST_P(ToolbarActionsBarUnitTest, BasicToolbarActionsBarTest) {
EXPECT_EQ(3u, toolbar_actions_bar()->GetIconCount()); EXPECT_EQ(3u, toolbar_actions_bar()->GetIconCount());
const gfx::Size view_size = toolbar_actions_bar()->GetViewSize(); const gfx::Size view_size = toolbar_actions_bar()->GetViewSize();
// Check the widths. // Check the widths.
int expected_width = 3 * view_size.width(); int expected_width =
3 * view_size.width() + 2 * GetLayoutConstant(TOOLBAR_ELEMENT_PADDING);
EXPECT_EQ(expected_width, toolbar_actions_bar()->GetFullSize().width()); EXPECT_EQ(expected_width, toolbar_actions_bar()->GetFullSize().width());
// Since all icons are showing, the current width should be the max width. // Since all icons are showing, the current width should be the max width.
int maximum_width = expected_width; int maximum_width = expected_width;
...@@ -271,7 +272,8 @@ TEST_P(ToolbarActionsBarUnitTest, BasicToolbarActionsBarTest) { ...@@ -271,7 +272,8 @@ TEST_P(ToolbarActionsBarUnitTest, BasicToolbarActionsBarTest) {
EXPECT_EQ(2u, toolbar_actions_bar()->GetIconCount()); EXPECT_EQ(2u, toolbar_actions_bar()->GetIconCount());
// The current width should now be enough for two icons. // The current width should now be enough for two icons.
expected_width = 2 * view_size.width(); expected_width =
2 * view_size.width() + GetLayoutConstant(TOOLBAR_ELEMENT_PADDING);
EXPECT_EQ(expected_width, toolbar_actions_bar()->GetFullSize().width()); EXPECT_EQ(expected_width, toolbar_actions_bar()->GetFullSize().width());
// The maximum and minimum widths should have remained constant (since we have // The maximum and minimum widths should have remained constant (since we have
// the same number of actions). // the same number of actions).
...@@ -328,7 +330,7 @@ TEST_P(ToolbarActionsBarUnitTest, BasicToolbarActionsBarTest) { ...@@ -328,7 +330,7 @@ TEST_P(ToolbarActionsBarUnitTest, BasicToolbarActionsBarTest) {
// If we resize by enough to include a new icon, width and icon count should // If we resize by enough to include a new icon, width and icon count should
// both increase. // both increase.
width += view_size.width(); width += view_size.width() + GetLayoutConstant(TOOLBAR_ELEMENT_PADDING);
toolbar_actions_bar()->OnResizeComplete(width); toolbar_actions_bar()->OnResizeComplete(width);
EXPECT_EQ(width, toolbar_actions_bar()->GetFullSize().width()); EXPECT_EQ(width, toolbar_actions_bar()->GetFullSize().width());
EXPECT_EQ(2u, toolbar_actions_bar()->GetIconCount()); EXPECT_EQ(2u, toolbar_actions_bar()->GetIconCount());
...@@ -336,7 +338,7 @@ TEST_P(ToolbarActionsBarUnitTest, BasicToolbarActionsBarTest) { ...@@ -336,7 +338,7 @@ TEST_P(ToolbarActionsBarUnitTest, BasicToolbarActionsBarTest) {
// If we shrink the bar so that a full icon can't fit, it should resize to // If we shrink the bar so that a full icon can't fit, it should resize to
// hide that icon. // hide that icon.
toolbar_actions_bar()->OnResizeComplete(width - 1); toolbar_actions_bar()->OnResizeComplete(width - 1);
width -= view_size.width(); width -= view_size.width() + GetLayoutConstant(TOOLBAR_ELEMENT_PADDING);
EXPECT_EQ(width, toolbar_actions_bar()->GetFullSize().width()); EXPECT_EQ(width, toolbar_actions_bar()->GetFullSize().width());
EXPECT_EQ(1u, toolbar_actions_bar()->GetIconCount()); EXPECT_EQ(1u, toolbar_actions_bar()->GetIconCount());
} }
...@@ -442,8 +444,11 @@ TEST_P(ToolbarActionsBarUnitTest, TestHighlightMode) { ...@@ -442,8 +444,11 @@ TEST_P(ToolbarActionsBarUnitTest, TestHighlightMode) {
// Test the bounds calculation for different indices. // Test the bounds calculation for different indices.
TEST_P(ToolbarActionsBarUnitTest, TestActionFrameBounds) { TEST_P(ToolbarActionsBarUnitTest, TestActionFrameBounds) {
const auto size = toolbar_actions_bar()->GetViewSize(); const auto size = toolbar_actions_bar()->GetViewSize();
const auto icon_rect = [size](int x, int y) { const int element_padding = GetLayoutConstant(TOOLBAR_ELEMENT_PADDING);
return gfx::Rect(gfx::Point(x * size.width(), y * size.height()), size); const auto icon_rect = [size, element_padding](int x, int y) {
return gfx::Rect(gfx::Point(x * (element_padding + size.width()),
y * (element_padding + size.height())),
size);
}; };
constexpr int kIconsPerOverflowRow = 3; constexpr int kIconsPerOverflowRow = 3;
...@@ -456,8 +461,11 @@ TEST_P(ToolbarActionsBarUnitTest, TestActionFrameBounds) { ...@@ -456,8 +461,11 @@ TEST_P(ToolbarActionsBarUnitTest, TestActionFrameBounds) {
ActionType::BROWSER_ACTION); ActionType::BROWSER_ACTION);
} }
toolbar_model()->SetVisibleIconCount(kNumExtensions); toolbar_model()->SetVisibleIconCount(kNumExtensions);
const int icon_width = toolbar_actions_bar()->GetViewSize().width(); const int overflow_width =
overflow_bar()->SetOverflowRowWidth(icon_width * kIconsPerOverflowRow); kIconsPerOverflowRow *
(toolbar_actions_bar()->GetViewSize().width() + element_padding) -
element_padding;
overflow_bar()->SetOverflowRowWidth(overflow_width);
EXPECT_EQ(kIconsPerOverflowRow, EXPECT_EQ(kIconsPerOverflowRow,
overflow_bar()->platform_settings().icons_per_overflow_menu_row); overflow_bar()->platform_settings().icons_per_overflow_menu_row);
......
...@@ -519,20 +519,18 @@ int BrowserActionsContainer::OnDragUpdated( ...@@ -519,20 +519,18 @@ int BrowserActionsContainer::OnDragUpdated(
const auto size = toolbar_actions_bar_->GetViewSize(); const auto size = toolbar_actions_bar_->GetViewSize();
const int offset_into_icon_area = GetMirroredXInView(event.x()) - const int offset_into_icon_area = GetMirroredXInView(event.x()) -
GetResizeAreaWidth() + (size.width() / 2); GetResizeAreaWidth() + (size.width() / 2);
const int before_icon_unclamped = offset_into_icon_area / size.width(); const int before_icon_unclamped =
toolbar_actions_bar_->WidthToIconCount(offset_into_icon_area);
// Next, figure out what row we're on. This only matters for overflow mode,
// but the calculation is the same for both.
row_index = event.y() / size.height();
// Sanity check - we should never be on a different row in the main
// container.
DCHECK(ShownInsideMenu() || row_index == 0);
// We need to figure out how many icons are visible on the relevant row. // We need to figure out how many icons are visible on the relevant row.
// In the main container, this will just be the visible actions. // In the main container, this will just be the visible actions.
int visible_icons_on_row = VisibleBrowserActionsAfterAnimation(); int visible_icons_on_row = VisibleBrowserActionsAfterAnimation();
if (ShownInsideMenu()) { if (ShownInsideMenu()) {
// Next, figure out what row we're on.
const int element_padding = GetLayoutConstant(TOOLBAR_ELEMENT_PADDING);
row_index =
(event.y() + element_padding) / (size.height() + element_padding);
const int icons_per_row = platform_settings().icons_per_overflow_menu_row; const int icons_per_row = platform_settings().icons_per_overflow_menu_row;
// If this is the final row of the overflow, then this is the remainder of // If this is the final row of the overflow, then this is the remainder of
// visible icons. Otherwise, it's a full row (kIconsPerRow). // visible icons. Otherwise, it's a full row (kIconsPerRow).
...@@ -575,11 +573,8 @@ int BrowserActionsContainer::OnPerformDrop( ...@@ -575,11 +573,8 @@ int BrowserActionsContainer::OnPerformDrop(
// Make sure we have the same view as we started with. // Make sure we have the same view as we started with.
DCHECK_EQ(GetIdAt(data.index()), data.id()); DCHECK_EQ(GetIdAt(data.index()), data.id());
size_t i = drop_position_->row * size_t i = GetDropPositionIndex();
platform_settings().icons_per_overflow_menu_row +
drop_position_->icon_in_row;
if (ShownInsideMenu())
i += main_container_->VisibleBrowserActionsAfterAnimation();
// |i| now points to the item to the right of the drop indicator*, which is // |i| now points to the item to the right of the drop indicator*, which is
// correct when dragging an icon to the left. When dragging to the right, // correct when dragging an icon to the left. When dragging to the right,
// however, we want the icon being dragged to get the index of the item to // however, we want the icon being dragged to get the index of the item to
...@@ -712,23 +707,18 @@ void BrowserActionsContainer::OnPaint(gfx::Canvas* canvas) { ...@@ -712,23 +707,18 @@ void BrowserActionsContainer::OnPaint(gfx::Canvas* canvas) {
// The two-pixel width drop indicator. // The two-pixel width drop indicator.
constexpr int kDropIndicatorWidth = 2; constexpr int kDropIndicatorWidth = 2;
// Convert back to a pixel offset into the container. First find the X const size_t i = GetDropPositionIndex();
// coordinate of the drop icon. const gfx::Rect frame = toolbar_actions_bar_->GetFrameForIndex(i);
const auto size = toolbar_actions_bar_->GetViewSize(); gfx::Rect indicator_bounds = GetMirroredRect(
// TODO(pbos): The drag/drop separator and view placement should share code gfx::Rect(GetResizeAreaWidth() + frame.x() -
// after ToolbarActionsBar and BrowserActionsContainer merge. GetLayoutConstant(TOOLBAR_ELEMENT_PADDING) / 2 -
const int drop_icon_x = GetResizeAreaWidth() + kDropIndicatorWidth / 2,
drop_position_->icon_in_row * size.width() - frame.y(), kDropIndicatorWidth, frame.height()));
(kDropIndicatorWidth / 2); // Clamp the indicator to the view bounds so that heading / trailing markers
// don't paint outside the controller. It's OK if they paint over the resize
// Next, clamp so the indicator doesn't touch the adjoining toolbar items. // area or separator (but the in-menu container has neither).
const int drop_indicator_x = indicator_bounds.set_x(base::ClampToRange(
base::ClampToRange(drop_icon_x, 1, width() - kDropIndicatorWidth - 1); indicator_bounds.x(), 0, width() - indicator_bounds.width()));
const int row_height = size.height();
const int drop_indicator_y = row_height * drop_position_->row;
gfx::Rect indicator_bounds = GetMirroredRect(gfx::Rect(
drop_indicator_x, drop_indicator_y, kDropIndicatorWidth, row_height));
// Color of the drop indicator. // Color of the drop indicator.
// Always get the theme provider of the browser widget, since if this view // Always get the theme provider of the browser widget, since if this view
...@@ -787,7 +777,7 @@ int BrowserActionsContainer::GetWidthForIconCount(size_t num_icons) const { ...@@ -787,7 +777,7 @@ int BrowserActionsContainer::GetWidthForIconCount(size_t num_icons) const {
if (num_icons == 0) if (num_icons == 0)
return 0; return 0;
return GetResizeAreaWidth() + GetSeparatorAreaWidth() + return GetResizeAreaWidth() + GetSeparatorAreaWidth() +
num_icons * toolbar_actions_bar_->GetViewSize().width(); toolbar_actions_bar_->IconCountToWidth(num_icons);
} }
int BrowserActionsContainer::GetWidthWithAllActionsVisible() const { int BrowserActionsContainer::GetWidthWithAllActionsVisible() const {
...@@ -795,6 +785,15 @@ int BrowserActionsContainer::GetWidthWithAllActionsVisible() const { ...@@ -795,6 +785,15 @@ int BrowserActionsContainer::GetWidthWithAllActionsVisible() const {
toolbar_actions_bar_->toolbar_actions_unordered().size()); toolbar_actions_bar_->toolbar_actions_unordered().size());
} }
size_t BrowserActionsContainer::GetDropPositionIndex() const {
size_t i =
drop_position_->row * platform_settings().icons_per_overflow_menu_row +
drop_position_->icon_in_row;
if (ShownInsideMenu())
i += main_container_->VisibleBrowserActionsAfterAnimation();
return i;
}
int BrowserActionsContainer::GetResizeAreaWidth() const { int BrowserActionsContainer::GetResizeAreaWidth() const {
if (!resize_area_) if (!resize_area_)
return 0; return 0;
......
...@@ -267,6 +267,9 @@ class BrowserActionsContainer : public views::View, ...@@ -267,6 +267,9 @@ class BrowserActionsContainer : public views::View,
int GetWidthForIconCount(size_t num_icons) const; int GetWidthForIconCount(size_t num_icons) const;
int GetWidthWithAllActionsVisible() const; int GetWidthWithAllActionsVisible() const;
// Get index of the drag-drop position.
size_t GetDropPositionIndex() const;
// Returns the preferred width given the limit of |max_width|. (Unlike most // Returns the preferred width given the limit of |max_width|. (Unlike most
// views, since we don't want to show part of an icon or a large space after // views, since we don't want to show part of an icon or a large space after
// the omnibox, this is probably *not* |max_width|). // the omnibox, this is probably *not* |max_width|).
......
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