Commit d42019b1 authored by Peter Kasting's avatar Peter Kasting Committed by Commit Bot

Initial work on MD Refresh new tab button position.

Does not implement padding in spec.

BUG=822063
TEST=none

Change-Id: Ifcbcb1f7b6e4385a6c0318624d95e6201b5d5a4a
Reviewed-on: https://chromium-review.googlesource.com/1024666Reviewed-by: default avatarAllen Bauer <kylixrd@chromium.org>
Commit-Queue: Peter Kasting <pkasting@chromium.org>
Cr-Commit-Position: refs/heads/master@{#553234}
parent 7f7c86d8
This diff is collapsed.
...@@ -172,11 +172,12 @@ class TabStrip : public views::View, ...@@ -172,11 +172,12 @@ class TabStrip : public views::View,
void SetTabNeedsAttention(int model_index, bool attention); void SetTabNeedsAttention(int model_index, bool attention);
// Retrieves the ideal bounds for the Tab at the specified index. // Retrieves the ideal bounds for the Tab at the specified index.
const gfx::Rect& ideal_bounds(int tab_data_index) { const gfx::Rect& ideal_bounds(int tab_data_index) const {
return tabs_.ideal_bounds(tab_data_index); return tabs_.ideal_bounds(tab_data_index);
} }
// Returns the Tab at |index|. // Returns the Tab at |index|.
// TODO(pkasting): Make const correct
Tab* tab_at(int index) const { return tabs_.view_at(index); } Tab* tab_at(int index) const { return tabs_.view_at(index); }
// Returns the NewTabButton. // Returns the NewTabButton.
...@@ -387,6 +388,13 @@ class TabStrip : public views::View, ...@@ -387,6 +388,13 @@ class TabStrip : public views::View,
void CalculateBoundsForDraggedTabs(const Tabs& tabs, void CalculateBoundsForDraggedTabs(const Tabs& tabs,
std::vector<gfx::Rect>* bounds); std::vector<gfx::Rect>* bounds);
// Returns the X coordinate the first tab should start at.
int TabStartX() const;
// Returns the X coordinate the new tab button should be placed at. Requires
// |tabs_| to have correct ideal bounds.
int NewTabButtonX() const;
// Returns the size needed for the specified tabs. This is invoked during drag // Returns the size needed for the specified tabs. This is invoked during drag
// and drop to calculate offsets and positioning. // and drop to calculate offsets and positioning.
int GetSizeNeededForTabs(const Tabs& tabs); int GetSizeNeededForTabs(const Tabs& tabs);
......
...@@ -52,27 +52,29 @@ void CalculateNormalTabWidths(const TabSizeInfo& tab_size_info, ...@@ -52,27 +52,29 @@ void CalculateNormalTabWidths(const TabSizeInfo& tab_size_info,
} // namespace } // namespace
void CalculateBoundsForPinnedTabs(const TabSizeInfo& tab_size_info, int CalculateBoundsForPinnedTabs(const TabSizeInfo& tab_size_info,
int num_pinned_tabs, int num_pinned_tabs,
int num_tabs, int num_tabs,
std::vector<gfx::Rect>* tabs_bounds) { int start_x,
std::vector<gfx::Rect>* tabs_bounds) {
DCHECK_EQ(static_cast<size_t>(num_tabs), tabs_bounds->size()); DCHECK_EQ(static_cast<size_t>(num_tabs), tabs_bounds->size());
int index = 0; int index = 0;
int next_x = 0; int next_x = start_x;
for (; index < num_pinned_tabs; ++index) { for (; index < num_pinned_tabs; ++index) {
(*tabs_bounds)[index].SetRect(next_x, 0, tab_size_info.pinned_tab_width, (*tabs_bounds)[index].SetRect(next_x, 0, tab_size_info.pinned_tab_width,
tab_size_info.max_size.height()); tab_size_info.max_size.height());
next_x += tab_size_info.pinned_tab_width - tab_size_info.tab_overlap; next_x += tab_size_info.pinned_tab_width - tab_size_info.tab_overlap;
} }
if (index > 0 && index < num_tabs) { if (num_pinned_tabs)
(*tabs_bounds)[index].set_x(next_x + tab_size_info.pinned_to_normal_offset); next_x += tab_size_info.pinned_to_normal_offset;
} return next_x;
} }
std::vector<gfx::Rect> CalculateBounds(const TabSizeInfo& tab_size_info, std::vector<gfx::Rect> CalculateBounds(const TabSizeInfo& tab_size_info,
int num_pinned_tabs, int num_pinned_tabs,
int num_tabs, int num_tabs,
int active_index, int active_index,
int start_x,
int width, int width,
int* active_width, int* active_width,
int* inactive_width) { int* inactive_width) {
...@@ -82,18 +84,11 @@ std::vector<gfx::Rect> CalculateBounds(const TabSizeInfo& tab_size_info, ...@@ -82,18 +84,11 @@ std::vector<gfx::Rect> CalculateBounds(const TabSizeInfo& tab_size_info,
*active_width = *inactive_width = tab_size_info.max_size.width(); *active_width = *inactive_width = tab_size_info.max_size.width();
int next_x = 0; int next_x = CalculateBoundsForPinnedTabs(tab_size_info, num_pinned_tabs,
if (num_pinned_tabs) { num_tabs, start_x, &tabs_bounds);
CalculateBoundsForPinnedTabs(tab_size_info, num_pinned_tabs, num_tabs, if (num_pinned_tabs == num_tabs)
&tabs_bounds); return tabs_bounds;
if (num_pinned_tabs == num_tabs) width -= next_x - start_x;
return tabs_bounds;
// CalculateBoundsForPinnedTabs() sets the x location of the first normal
// tab.
width -= tabs_bounds[num_pinned_tabs].x();
next_x = tabs_bounds[num_pinned_tabs].x();
}
const bool is_active_tab_normal = active_index >= num_pinned_tabs; const bool is_active_tab_normal = active_index >= num_pinned_tabs;
const int num_normal_tabs = num_tabs - num_pinned_tabs; const int num_normal_tabs = num_tabs - num_pinned_tabs;
......
...@@ -35,13 +35,13 @@ struct TabSizeInfo { ...@@ -35,13 +35,13 @@ struct TabSizeInfo {
}; };
// Calculates the bounds of the pinned tabs. This assumes |tabs_bounds| is the // Calculates the bounds of the pinned tabs. This assumes |tabs_bounds| is the
// same size as |num_tabs|. In addition to setting the bounds of the pinned // same size as |num_tabs|. Returns the x-coordinate to use for the first
// tabs this sets the x-coordinate of the first normal tab (as long as there is // non-pinned tab, if any.
// a normal tab). int CalculateBoundsForPinnedTabs(const TabSizeInfo& tab_size_info,
void CalculateBoundsForPinnedTabs(const TabSizeInfo& tab_size_info, int num_pinned_tabs,
int num_pinned_tabs, int num_tabs,
int num_tabs, int start_x,
std::vector<gfx::Rect>* tabs_bounds); std::vector<gfx::Rect>* tabs_bounds);
// Calculates and returns the bounds of the tabs. |width| is the available // Calculates and returns the bounds of the tabs. |width| is the available
// width to use for tab layout. This never sizes the tabs smaller then the // width to use for tab layout. This never sizes the tabs smaller then the
...@@ -51,6 +51,7 @@ std::vector<gfx::Rect> CalculateBounds(const TabSizeInfo& tab_size_info, ...@@ -51,6 +51,7 @@ std::vector<gfx::Rect> CalculateBounds(const TabSizeInfo& tab_size_info,
int num_pinned_tabs, int num_pinned_tabs,
int num_tabs, int num_tabs,
int active_index, int active_index,
int start_x,
int width, int width,
int* active_width, int* active_width,
int* inactive_width); int* inactive_width);
......
...@@ -41,65 +41,69 @@ TEST(TabStripLayoutTest, Tests) { ...@@ -41,65 +41,69 @@ TEST(TabStripLayoutTest, Tests) {
int num_pinned_tabs; int num_pinned_tabs;
int num_tabs; int num_tabs;
int active_index; int active_index;
int start_x;
int width; int width;
const char* expected_sizes; const char* expected_sizes;
int expected_active_width; int expected_active_width;
int expected_inactive_width; int expected_inactive_width;
} test_cases[] = { } test_cases[] = {
// Ample space, all normal tabs. // Ample space, all normal tabs.
{0, 3, 0, 1000, "0 100, 96 100, 192 100", 100, 100}, {0, 3, 0, 0, 1000, "0 100, 96 100, 192 100", 100, 100},
// Ample space, all normal tabs, starting at a nonzero value.
{0, 3, 0, 100, 1000, "100 100, 196 100, 292 100", 100, 100},
// Ample space, all pinned. // Ample space, all pinned.
{3, 3, 0, 1000, "0 10, 6 10, 12 10", 100, 100}, {3, 3, 0, 0, 1000, "0 10, 6 10, 12 10", 100, 100},
// Ample space, one pinned and two normal tabs. // Ample space, one pinned and two normal tabs.
{1, 3, 0, 1000, "0 10, 12 100, 108 100", 100, 100}, {1, 3, 0, 0, 1000, "0 10, 12 100, 108 100", 100, 100},
// Resize between min and max, no pinned and no rounding. // Resize between min and max, no pinned and no rounding.
{0, 4, 0, 100, "0 28, 24 28, 48 28, 72 28", 28, 28}, {0, 4, 0, 0, 100, "0 28, 24 28, 48 28, 72 28", 28, 28},
// Resize between min and max, pinned and no rounding. // Resize between min and max, pinned and no rounding.
{1, 3, 0, 100, "0 10, 12 46, 54 46", 46, 46}, {1, 3, 0, 0, 100, "0 10, 12 46, 54 46", 46, 46},
// Resize between min and max, no pinned, rounding. // Resize between min and max, no pinned, rounding.
{0, 4, 0, 102, "0 29, 25 29, 50 28, 74 28", 28, 28}, {0, 4, 0, 0, 102, "0 29, 25 29, 50 28, 74 28", 28, 28},
// Resize between min and max, pinned and rounding. // Resize between min and max, pinned and rounding.
{1, 3, 0, 101, "0 10, 12 47, 55 46", 46, 46}, {1, 3, 0, 0, 101, "0 10, 12 47, 55 46", 46, 46},
// Resize between active/inactive width, only one tab. // Resize between active/inactive width, only one tab.
{0, 1, 0, 15, "0 20", 20, 15}, {0, 1, 0, 0, 15, "0 20", 20, 15},
// Resize between active/inactive width and no rounding. // Resize between active/inactive width and no rounding.
{0, 6, 0, 90, "0 20, 16 18, 30 18, 44 18, 58 18, 72 18", 20, 18}, {0, 6, 0, 0, 90, "0 20, 16 18, 30 18, 44 18, 58 18, 72 18", 20, 18},
// Resize between active/inactive width, rounding. // Resize between active/inactive width, rounding.
{0, 6, 0, 93, "0 20, 16 19, 31 19, 46 19, 61 18, 75 18", 20, 18}, {0, 6, 0, 0, 93, "0 20, 16 19, 31 19, 46 19, 61 18, 75 18", 20, 18},
// Resize between active/inactive width, one pinned and active, no // Resize between active/inactive width, one pinned and active, no
// rounding. // rounding.
{1, 6, 0, 91, "0 10, 12 19, 27 19, 42 19, 57 19, 72 19", 20, 19}, {1, 6, 0, 0, 91, "0 10, 12 19, 27 19, 42 19, 57 19, 72 19", 20, 19},
// Resize between active/inactive width, one pinned and active, rounding. // Resize between active/inactive width, one pinned and active, rounding.
{1, 6, 0, 92, "0 10, 12 20, 28 19, 43 19, 58 19, 73 19", 20, 19}, {1, 6, 0, 0, 92, "0 10, 12 20, 28 19, 43 19, 58 19, 73 19", 20, 19},
// Not enough space, all pinned. // Not enough space, all pinned.
{3, 3, 0, 10, "0 10, 6 10, 12 10", 100, 100}, {3, 3, 0, 0, 10, "0 10, 6 10, 12 10", 100, 100},
// Not enough space (for minimum widths), all normal. // Not enough space (for minimum widths), all normal.
{0, 3, 0, 10, "0 20, 16 14, 26 14", 20, 14}, {0, 3, 0, 0, 10, "0 20, 16 14, 26 14", 20, 14},
// Not enough space (for minimum widths), one pinned and two normal. // Not enough space (for minimum widths), one pinned and two normal.
{1, 3, 0, 10, "0 10, 12 14, 22 14", 20, 14}, {1, 3, 0, 0, 10, "0 10, 12 14, 22 14", 20, 14},
}; };
for (size_t i = 0; i < arraysize(test_cases); ++i) { for (size_t i = 0; i < arraysize(test_cases); ++i) {
int active_width; int active_width;
int inactive_width; int inactive_width;
std::vector<gfx::Rect> tabs_bounds = std::vector<gfx::Rect> tabs_bounds = CalculateBounds(
CalculateBounds(tab_size_info, test_cases[i].num_pinned_tabs, tab_size_info, test_cases[i].num_pinned_tabs, test_cases[i].num_tabs,
test_cases[i].num_tabs, test_cases[i].active_index, test_cases[i].active_index, test_cases[i].start_x, test_cases[i].width,
test_cases[i].width, &active_width, &inactive_width); &active_width, &inactive_width);
EXPECT_EQ(test_cases[i].expected_sizes, TabsBoundsToString(tabs_bounds)) EXPECT_EQ(test_cases[i].expected_sizes, TabsBoundsToString(tabs_bounds))
<< i; << i;
EXPECT_EQ(test_cases[i].expected_active_width, active_width) << i; EXPECT_EQ(test_cases[i].expected_active_width, active_width) << i;
......
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