Commit 57803468 authored by Matthew Mourgos's avatar Matthew Mourgos Committed by Commit Bot

Use ShelfConstants functions within overflow_bubble_view.

- This change will ensure proper spacing with shelf constants that have been
  changed for the new dense shelf ui.

Bug: 973483
Change-Id: I4790a9e602ee592c15637f4a7cd300bb52dda3a2
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1708011Reviewed-by: default avatarXiyuan Xia <xiyuan@chromium.org>
Commit-Queue: Matthew Mourgos <mmourgos@chromium.org>
Cr-Commit-Position: refs/heads/master@{#680603}
parent 33be8e5d
...@@ -33,17 +33,23 @@ namespace { ...@@ -33,17 +33,23 @@ namespace {
// Padding between the end of the shelf in overflow mode and the arrow button // Padding between the end of the shelf in overflow mode and the arrow button
// (if any). // (if any).
constexpr int kDistanceToArrowButton = kShelfButtonSpacing; int GetDistanceToArrowButton() {
return ShelfConstants::button_spacing();
}
// Distance between overflow bubble and the main shelf. // Distance between overflow bubble and the main shelf.
constexpr int kDistanceToMainShelf = 4; constexpr int kDistanceToMainShelf = 4;
// Sum of the shelf button size and the gap between shelf buttons. // Sum of the shelf button size and the gap between shelf buttons.
constexpr int kUnit = kShelfButtonSize + kShelfButtonSpacing; int GetUnit() {
return ShelfConstants::button_size() + ShelfConstants::button_spacing();
}
// Decides whether the current first visible shelf icon of the overflow shelf // Decides whether the current first visible shelf icon of the overflow shelf
// should be hidden or fully shown when gesture scroll ends. // should be hidden or fully shown when gesture scroll ends.
constexpr int kGestureDragThreshold = kShelfButtonSize / 2; int GetGestureDragTheshold() {
return ShelfConstants::button_size() / 2;
}
} // namespace } // namespace
...@@ -101,7 +107,7 @@ void OverflowBubbleView::ScrollArrowView::PaintButtonContents( ...@@ -101,7 +107,7 @@ void OverflowBubbleView::ScrollArrowView::PaintButtonContents(
canvas->DrawImageInt(img, center_point.x() - img.width() / 2, canvas->DrawImageInt(img, center_point.x() - img.width() / 2,
center_point.y() - img.height() / 2); center_point.y() - img.height() / 2);
float ring_radius_dp = OverflowBubbleView::kArrowButtonSize / 2; float ring_radius_dp = GetArrowButtonSize() / 2;
{ {
gfx::PointF circle_center(center_point); gfx::PointF circle_center(center_point);
gfx::ScopedCanvas scoped_canvas(canvas); gfx::ScopedCanvas scoped_canvas(canvas);
...@@ -130,14 +136,15 @@ OverflowBubbleView::ScrollArrowView::CreateInkDrop() { ...@@ -130,14 +136,15 @@ OverflowBubbleView::ScrollArrowView::CreateInkDrop() {
std::unique_ptr<views::InkDropMask> std::unique_ptr<views::InkDropMask>
OverflowBubbleView::ScrollArrowView::CreateInkDropMask() const { OverflowBubbleView::ScrollArrowView::CreateInkDropMask() const {
gfx::Point center_point = gfx::Rect(size()).CenterPoint(); gfx::Point center_point = gfx::Rect(size()).CenterPoint();
return std::make_unique<views::CircleInkDropMask>(size(), center_point, 20); return std::make_unique<views::CircleInkDropMask>(size(), center_point,
GetArrowButtonSize() / 2);
} }
std::unique_ptr<views::InkDropRipple> std::unique_ptr<views::InkDropRipple>
OverflowBubbleView::ScrollArrowView::CreateInkDropRipple() const { OverflowBubbleView::ScrollArrowView::CreateInkDropRipple() const {
const int button_radius = 20; const int button_size = GetArrowButtonSize();
gfx::Rect bounds = gfx::Rect(size()); gfx::Rect bounds = gfx::Rect(size());
bounds.ClampToCenteredSize(gfx::Size(2 * button_radius, 2 * button_radius)); bounds.ClampToCenteredSize(gfx::Size(button_size, button_size));
return std::make_unique<views::FloodFillInkDropRipple>( return std::make_unique<views::FloodFillInkDropRipple>(
size(), GetLocalBounds().InsetsFrom(bounds), size(), GetLocalBounds().InsetsFrom(bounds),
GetInkDropCenterBasedOnLastEvent(), kShelfInkDropBaseColor, GetInkDropCenterBasedOnLastEvent(), kShelfInkDropBaseColor,
...@@ -214,8 +221,6 @@ void OverflowBubbleView::OverflowShelfContainerView::TranslateShelfView( ...@@ -214,8 +221,6 @@ void OverflowBubbleView::OverflowShelfContainerView::TranslateShelfView(
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
// OverflowBubbleView // OverflowBubbleView
const int OverflowBubbleView::kArrowButtonSize = kShelfControlSize;
OverflowBubbleView::OverflowBubbleView(ShelfView* shelf_view, OverflowBubbleView::OverflowBubbleView(ShelfView* shelf_view,
views::View* anchor, views::View* anchor,
SkColor background_color) SkColor background_color)
...@@ -270,14 +275,15 @@ bool OverflowBubbleView::ProcessGestureEvent(const ui::GestureEvent& event) { ...@@ -270,14 +275,15 @@ bool OverflowBubbleView::ProcessGestureEvent(const ui::GestureEvent& event) {
int current_scroll_distance = shelf_->IsHorizontalAlignment() int current_scroll_distance = shelf_->IsHorizontalAlignment()
? scroll_offset_.x() ? scroll_offset_.x()
: scroll_offset_.y(); : scroll_offset_.y();
const int residue = current_scroll_distance % kUnit; const int residue = current_scroll_distance % GetUnit();
// if it does not need to adjust the location of the shelf view, // if it does not need to adjust the location of the shelf view,
// return early. // return early.
if (current_scroll_distance == CalculateScrollUpperBound() || residue == 0) if (current_scroll_distance == CalculateScrollUpperBound() || residue == 0)
return true; return true;
int offset = residue > kGestureDragThreshold ? kUnit - residue : -residue; int offset =
residue > GetGestureDragTheshold() ? GetUnit() - residue : -residue;
if (shelf_->IsHorizontalAlignment()) if (shelf_->IsHorizontalAlignment())
ScrollByXOffset(offset, /*animate=*/true); ScrollByXOffset(offset, /*animate=*/true);
else else
...@@ -361,7 +367,7 @@ void OverflowBubbleView::AdjustToEnsureIconsFullyVisible( ...@@ -361,7 +367,7 @@ void OverflowBubbleView::AdjustToEnsureIconsFullyVisible(
int width = shelf_->IsHorizontalAlignment() ? bubble_bounds->width() int width = shelf_->IsHorizontalAlignment() ? bubble_bounds->width()
: bubble_bounds->height(); : bubble_bounds->height();
const int rd = width % kUnit; const int rd = width % GetUnit();
width -= rd; width -= rd;
// Offset to ensure that the bubble view is shown at the center of the screen. // Offset to ensure that the bubble view is shown at the center of the screen.
...@@ -433,8 +439,9 @@ gfx::Size OverflowBubbleView::CalculatePreferredSize() const { ...@@ -433,8 +439,9 @@ gfx::Size OverflowBubbleView::CalculatePreferredSize() const {
} }
void OverflowBubbleView::Layout() { void OverflowBubbleView::Layout() {
constexpr gfx::Size shelf_button_size(kShelfButtonSize, kShelfButtonSize); const gfx::Size shelf_button_size(ShelfConstants::button_size(),
constexpr gfx::Size arrow_button_size(kArrowButtonSize, kArrowButtonSize); ShelfConstants::button_size());
const gfx::Size arrow_button_size(GetArrowButtonSize(), GetArrowButtonSize());
bool is_horizontal = shelf_->IsHorizontalAlignment(); bool is_horizontal = shelf_->IsHorizontalAlignment();
gfx::Rect shelf_container_bounds = bounds(); gfx::Rect shelf_container_bounds = bounds();
...@@ -452,17 +459,17 @@ void OverflowBubbleView::Layout() { ...@@ -452,17 +459,17 @@ void OverflowBubbleView::Layout() {
layout_strategy_ == SHOW_BUTTONS) { layout_strategy_ == SHOW_BUTTONS) {
left_arrow_bounds = gfx::Rect(shelf_button_size); left_arrow_bounds = gfx::Rect(shelf_button_size);
left_arrow_bounds.ClampToCenteredSize(arrow_button_size); left_arrow_bounds.ClampToCenteredSize(arrow_button_size);
shelf_container_bounds.Inset(kShelfButtonSize + kDistanceToArrowButton, 0, shelf_container_bounds.Inset(
0, 0); ShelfConstants::button_size() + GetDistanceToArrowButton(), 0, 0, 0);
} }
if (layout_strategy_ == SHOW_RIGHT_ARROW_BUTTON || if (layout_strategy_ == SHOW_RIGHT_ARROW_BUTTON ||
layout_strategy_ == SHOW_BUTTONS) { layout_strategy_ == SHOW_BUTTONS) {
shelf_container_bounds.Inset(0, 0, kShelfButtonSize, 0); shelf_container_bounds.Inset(0, 0, ShelfConstants::button_size(), 0);
right_arrow_bounds = right_arrow_bounds =
gfx::Rect(shelf_container_bounds.top_right(), shelf_button_size); gfx::Rect(shelf_container_bounds.top_right(), shelf_button_size);
right_arrow_bounds.ClampToCenteredSize(arrow_button_size); right_arrow_bounds.ClampToCenteredSize(arrow_button_size);
shelf_container_bounds.Inset(0, 0, kDistanceToArrowButton, 0); shelf_container_bounds.Inset(0, 0, GetDistanceToArrowButton(), 0);
} }
shelf_container_bounds.Inset(kEndPadding, 0, kEndPadding, 0); shelf_container_bounds.Inset(kEndPadding, 0, kEndPadding, 0);
...@@ -539,7 +546,7 @@ void OverflowBubbleView::ButtonPressed(views::Button* sender, ...@@ -539,7 +546,7 @@ void OverflowBubbleView::ButtonPressed(views::Button* sender,
// bubble view. The key is to calculate the suitable scroll distance. // bubble view. The key is to calculate the suitable scroll distance.
int offset = int offset =
(shelf_->IsHorizontalAlignment() ? bounds().width() : bounds().height()) - (shelf_->IsHorizontalAlignment() ? bounds().width() : bounds().height()) -
2 * kUnit; 2 * GetUnit();
DCHECK_GT(offset, 0); DCHECK_GT(offset, 0);
// If |forward| is true, scroll the overflow bubble view rightward. // If |forward| is true, scroll the overflow bubble view rightward.
...@@ -623,4 +630,9 @@ bool OverflowBubbleView::ShouldCloseOnMouseExit() { ...@@ -623,4 +630,9 @@ bool OverflowBubbleView::ShouldCloseOnMouseExit() {
return false; return false;
} }
int OverflowBubbleView::GetArrowButtonSize() {
static int kArrowButtonSize = ShelfConstants::control_size();
return kArrowButtonSize;
}
} // namespace ash } // namespace ash
...@@ -66,15 +66,14 @@ class ASH_EXPORT OverflowBubbleView : public ShelfBubble, ...@@ -66,15 +66,14 @@ class ASH_EXPORT OverflowBubbleView : public ShelfBubble,
bool ShouldCloseOnPressDown() override; bool ShouldCloseOnPressDown() override;
bool ShouldCloseOnMouseExit() override; bool ShouldCloseOnMouseExit() override;
static int GetArrowButtonSize();
// Padding at the two ends of the shelf in overflow mode. // Padding at the two ends of the shelf in overflow mode.
static constexpr int kEndPadding = 4; static constexpr int kEndPadding = 4;
// Minimum margin around the bubble so that it doesn't hug the screen edges. // Minimum margin around the bubble so that it doesn't hug the screen edges.
static constexpr int kMinimumMargin = 8; static constexpr int kMinimumMargin = 8;
// Size of the arrow button.
static const int kArrowButtonSize;
private: private:
friend class OverflowBubbleViewTestAPI; friend class OverflowBubbleViewTestAPI;
......
...@@ -1777,11 +1777,12 @@ TEST_F(ShelfViewTest, CheckOverflowBubbleViewArrowButton) { ...@@ -1777,11 +1777,12 @@ TEST_F(ShelfViewTest, CheckOverflowBubbleViewArrowButton) {
ASSERT_TRUE(shelf_view_->IsShowingOverflowBubble()); ASSERT_TRUE(shelf_view_->IsShowingOverflowBubble());
OverflowBubbleView* bubble_view = test_api_->overflow_bubble()->bubble_view(); OverflowBubbleView* bubble_view = test_api_->overflow_bubble()->bubble_view();
const gfx::Size shelf_icon_size(kShelfButtonSize, kShelfButtonSize); const int button_size = ShelfConstants::button_size();
const int arrow_button_size = OverflowBubbleView::kArrowButtonSize; const gfx::Size shelf_icon_size(button_size, button_size);
const int arrow_button_size = OverflowBubbleView::GetArrowButtonSize();
const int bubble_view_min_margin = OverflowBubbleView::kMinimumMargin; const int bubble_view_min_margin = OverflowBubbleView::kMinimumMargin;
const int end_padding = OverflowBubbleView::kEndPadding; const int end_padding = OverflowBubbleView::kEndPadding;
const int unit = kShelfButtonSize + kShelfButtonSpacing; const int unit = button_size + ShelfConstants::button_spacing();
// Add sufficient app icons to ensure that it needs to press the right arrow // Add sufficient app icons to ensure that it needs to press the right arrow
// buttons twice to reach the end. // buttons twice to reach the end.
...@@ -1791,7 +1792,7 @@ TEST_F(ShelfViewTest, CheckOverflowBubbleViewArrowButton) { ...@@ -1791,7 +1792,7 @@ TEST_F(ShelfViewTest, CheckOverflowBubbleViewArrowButton) {
GetPrimaryDisplay().work_area().width() - 2 * bubble_view_min_margin - GetPrimaryDisplay().work_area().width() - 2 * bubble_view_min_margin -
2 * end_padding; 2 * end_padding;
const int max_accommodated_shelf_num = const int max_accommodated_shelf_num =
std::ceil(available_width_for_shortcuts / unit); (available_width_for_shortcuts - arrow_button_size) / unit + 1;
int additional_item_num = int additional_item_num =
2 * max_accommodated_shelf_num - 1 - current_item_count; 2 * max_accommodated_shelf_num - 1 - current_item_count;
while (additional_item_num) { while (additional_item_num) {
...@@ -1847,8 +1848,8 @@ TEST_F(ShelfViewTest, CheckOverflowBubbleViewArrowButton) { ...@@ -1847,8 +1848,8 @@ TEST_F(ShelfViewTest, CheckOverflowBubbleViewArrowButton) {
// Verifies that the right button shows in the expected bounds. // Verifies that the right button shows in the expected bounds.
EXPECT_TRUE(right_arrow_button->GetVisible()); EXPECT_TRUE(right_arrow_button->GetVisible());
gfx::Rect expected_right_arrow_bounds = gfx::Rect expected_right_arrow_bounds =
gfx::Rect(overflow_bubble_bounds.width() - kShelfButtonSize, 0, gfx::Rect(overflow_bubble_bounds.width() - button_size, 0, button_size,
kShelfButtonSize, kShelfButtonSize); button_size);
expected_right_arrow_bounds.ClampToCenteredSize( expected_right_arrow_bounds.ClampToCenteredSize(
gfx::Size(arrow_button_size, arrow_button_size)); gfx::Size(arrow_button_size, arrow_button_size));
EXPECT_EQ(expected_right_arrow_bounds, right_arrow_button->bounds()); EXPECT_EQ(expected_right_arrow_bounds, right_arrow_button->bounds());
...@@ -1856,7 +1857,7 @@ TEST_F(ShelfViewTest, CheckOverflowBubbleViewArrowButton) { ...@@ -1856,7 +1857,7 @@ TEST_F(ShelfViewTest, CheckOverflowBubbleViewArrowButton) {
// Verifies that the left button shows in the expected bounds. // Verifies that the left button shows in the expected bounds.
EXPECT_TRUE(left_arrow_button->GetVisible()); EXPECT_TRUE(left_arrow_button->GetVisible());
gfx::Rect expected_left_arrow_bounds = gfx::Rect expected_left_arrow_bounds =
gfx::Rect(0, 0, kShelfButtonSize, kShelfButtonSize); gfx::Rect(0, 0, button_size, button_size);
expected_left_arrow_bounds.ClampToCenteredSize( expected_left_arrow_bounds.ClampToCenteredSize(
gfx::Size(arrow_button_size, arrow_button_size)); gfx::Size(arrow_button_size, arrow_button_size));
EXPECT_EQ(expected_left_arrow_bounds, left_arrow_button->bounds()); EXPECT_EQ(expected_left_arrow_bounds, left_arrow_button->bounds());
...@@ -1878,7 +1879,7 @@ TEST_F(ShelfViewTest, CheckOverflowBubbleViewArrowButton) { ...@@ -1878,7 +1879,7 @@ TEST_F(ShelfViewTest, CheckOverflowBubbleViewArrowButton) {
EXPECT_TRUE(left_arrow_button->GetVisible()); EXPECT_TRUE(left_arrow_button->GetVisible());
gfx::Rect expected_last_icon_bounds(overflow_bubble_bounds.top_right(), gfx::Rect expected_last_icon_bounds(overflow_bubble_bounds.top_right(),
shelf_icon_size); shelf_icon_size);
expected_last_icon_bounds.Offset(-kShelfButtonSize - end_padding, 0); expected_last_icon_bounds.Offset(-button_size - end_padding, 0);
EXPECT_EQ(expected_last_icon_bounds, EXPECT_EQ(expected_last_icon_bounds,
test_for_overflow_view test_for_overflow_view
.GetButton(bubble_view->shelf_view()->last_visible_index()) .GetButton(bubble_view->shelf_view()->last_visible_index())
...@@ -1910,7 +1911,8 @@ TEST_F(ShelfViewTest, CheckGestureDraggingOverflowBubbleView) { ...@@ -1910,7 +1911,8 @@ TEST_F(ShelfViewTest, CheckGestureDraggingOverflowBubbleView) {
const int bubble_view_min_margin = OverflowBubbleView::kMinimumMargin; const int bubble_view_min_margin = OverflowBubbleView::kMinimumMargin;
const int end_padding = OverflowBubbleView::kEndPadding; const int end_padding = OverflowBubbleView::kEndPadding;
const int unit = kShelfButtonSize + kShelfButtonSpacing; const int unit =
ShelfConstants::button_size() + ShelfConstants::button_spacing();
// Calculates the start point of the gesture drag event. Ensures that the // Calculates the start point of the gesture drag event. Ensures that the
// start point is not within the bounds of any shelf icon. // start point is not within the bounds of any shelf icon.
...@@ -1927,7 +1929,7 @@ TEST_F(ShelfViewTest, CheckGestureDraggingOverflowBubbleView) { ...@@ -1927,7 +1929,7 @@ TEST_F(ShelfViewTest, CheckGestureDraggingOverflowBubbleView) {
ASSERT_EQ(OverflowBubbleView::NOT_SHOW_ARROW_BUTTON, ASSERT_EQ(OverflowBubbleView::NOT_SHOW_ARROW_BUTTON,
bubble_view->layout_strategy()); bubble_view->layout_strategy());
gfx::Point gesture_end_point = gesture_drag_point; gfx::Point gesture_end_point = gesture_drag_point;
gesture_end_point.Offset(-kShelfButtonSize, 0); gesture_end_point.Offset(-ShelfConstants::button_size(), 0);
GetEventGenerator()->GestureScrollSequence( GetEventGenerator()->GestureScrollSequence(
gesture_drag_point, gesture_end_point, gesture_drag_point, gesture_end_point,
base::TimeDelta::FromMilliseconds(100), 5); base::TimeDelta::FromMilliseconds(100), 5);
...@@ -1937,8 +1939,10 @@ TEST_F(ShelfViewTest, CheckGestureDraggingOverflowBubbleView) { ...@@ -1937,8 +1939,10 @@ TEST_F(ShelfViewTest, CheckGestureDraggingOverflowBubbleView) {
const int available_width_for_shortcuts = const int available_width_for_shortcuts =
GetPrimaryDisplay().bounds().width() - 2 * bubble_view_min_margin - GetPrimaryDisplay().bounds().width() - 2 * bubble_view_min_margin -
2 * end_padding; 2 * end_padding;
int max_accommodated_shelf_num = int max_accommodated_shelf_num = (available_width_for_shortcuts -
std::ceil(available_width_for_shortcuts / unit); OverflowBubbleView::GetArrowButtonSize()) /
unit +
1;
while (max_accommodated_shelf_num) { while (max_accommodated_shelf_num) {
AddAppShortcut(); AddAppShortcut();
max_accommodated_shelf_num--; max_accommodated_shelf_num--;
...@@ -1957,7 +1961,7 @@ TEST_F(ShelfViewTest, CheckGestureDraggingOverflowBubbleView) { ...@@ -1957,7 +1961,7 @@ TEST_F(ShelfViewTest, CheckGestureDraggingOverflowBubbleView) {
// Verifies that the large gesture offset will scroll the overflow bubble. The // Verifies that the large gesture offset will scroll the overflow bubble. The
// scroll offset is adjusted to fully show all of shelf icons. // scroll offset is adjusted to fully show all of shelf icons.
gesture_end_point = gesture_drag_point; gesture_end_point = gesture_drag_point;
gesture_end_point.Offset(-kShelfButtonSize, 0); gesture_end_point.Offset(-ShelfConstants::button_size(), 0);
GetEventGenerator()->GestureScrollSequence( GetEventGenerator()->GestureScrollSequence(
gesture_drag_point, gesture_end_point, gesture_drag_point, gesture_end_point,
base::TimeDelta::FromMilliseconds(100), 1); base::TimeDelta::FromMilliseconds(100), 1);
......
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