Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1055)

Unified Diff: chrome/browser/ui/views/tabs/tab_strip.cc

Issue 10115029: Set toolbar padding to something appropriate for Metro icons. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: scale -> layout Created 8 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/browser/ui/views/tabs/tab_strip.cc
diff --git a/chrome/browser/ui/views/tabs/tab_strip.cc b/chrome/browser/ui/views/tabs/tab_strip.cc
index 0377d6af1b292721aae728ac05fb3e25b8cbcd36..709b4b38fdf7833d9c18f03aec6b1ba03d3d42b5 100644
--- a/chrome/browser/ui/views/tabs/tab_strip.cc
+++ b/chrome/browser/ui/views/tabs/tab_strip.cc
@@ -31,6 +31,7 @@
#include "ui/base/animation/throb_animation.h"
#include "ui/base/dragdrop/drag_drop_types.h"
#include "ui/base/l10n/l10n_util.h"
+#include "ui/base/layout.h"
#include "ui/base/resource/resource_bundle.h"
#include "ui/base/touch/touch_mode_support.h"
#include "ui/gfx/canvas.h"
@@ -53,21 +54,8 @@
using views::DropTargetEvent;
-// Offset for the new tab button to bring it closer to the rightmost tab.
-#if defined(USE_ASH)
-static const int kNewTabButtonHOffset = -11;
-static const int kNewTabButtonVOffset = 7;
-#else
-static const int kNewTabButtonHOffset = -5;
-static const int kNewTabButtonVOffset = 5;
-#endif
-// Amount the left edge of a tab is offset from the rectangle of the tab's
-// favicon/title/close box. Related to the width of IDR_TAB_ACTIVE_LEFT.
-#if defined(USE_ASH)
-static const int kTabHOffset = -27;
-#else
-static const int kTabHOffset = -16;
-#endif
+namespace {
+
static const int kTabStripAnimationVSlop = 40;
// Inactive tabs in a native frame are slightly transparent.
static const int kNativeFrameInactiveTabAlpha = 200;
@@ -92,7 +80,62 @@ static inline int Round(double x) {
// Max width reserved for stacked tabs along a particular edge.
static const double kMaxEdgeStackWidth = 24;
-namespace {
+// Horizontal offset for the new tab button to bring it closer to the
+// rightmost tab.
+const int GetNewTabButtonHOffset() {
+ static int value = -1;
+ if (value == -1) {
+ switch (ui::GetDisplayLayout()) {
+ case ui::LAYOUT_ASH:
+ value = -11;
+ break;
+ case ui::LAYOUT_METRO:
+ value = -6;
+ break;
+ default:
+ value = -5;
+ }
+ }
+ return value;
+}
+
+// Vertical offset for the new tab button to bring it closer to the
+// rightmost tab.
+const int GetNewTabButtonVOffset() {
+ static int value = -1;
+ if (value == -1) {
+ switch (ui::GetDisplayLayout()) {
+ case ui::LAYOUT_ASH:
+ value = 7;
+ break;
+ case ui::LAYOUT_METRO:
+ value = 10;
+ break;
+ default:
+ value = 5;
+ }
+ }
+ return value;
+}
+
+// Amount the left edge of a tab is offset from the rectangle of the tab's
+// favicon/title/close box. Related to the width of IDR_TAB_ACTIVE_LEFT.
+const int GetTabHOffset() {
+ static int value = -1;
+ if (value == -1) {
+ switch (ui::GetDisplayLayout()) {
+ case ui::LAYOUT_ASH:
+ value = -27;
+ break;
+ case ui::LAYOUT_METRO:
+ value = -16;
+ break;
+ default:
+ value = -16;
+ }
+ }
+ return value;
+}
// Animation delegate used when a dragged tab is released. When done sets the
// dragging state to false.
@@ -252,7 +295,7 @@ SkBitmap NewTabButton::GetBackgroundBitmap(
int offset_y = GetThemeProvider()->HasCustomImage(background_id) ?
0 : background_offset_.y();
canvas.TileImageInt(*background, GetMirroredX() + background_offset_.x(),
- kNewTabButtonVOffset + offset_y, 0, 0, width, height);
+ GetNewTabButtonVOffset() + offset_y, 0, 0, width, height);
if (alpha != 255) {
SkPaint paint;
@@ -496,7 +539,7 @@ void TabStrip::PrepareForCloseAt(int model_index) {
Tab* last_tab = tab_at(model_count - 1);
Tab* tab_being_removed = tab_at(model_index);
available_width_for_tabs_ = last_tab->x() + last_tab->width() -
- tab_being_removed->width() - kTabHOffset;
+ tab_being_removed->width() - GetTabHOffset();
if (model_index == 0 && tab_being_removed->data().mini &&
!tab_at(1)->data().mini) {
available_width_for_tabs_ -= kMiniToNonMiniGap;
@@ -921,7 +964,7 @@ gfx::Size TabStrip::GetPreferredSize() {
// it's undesirable to have the minimum window size change when a new tab is
// opened.
int needed_width = Tab::GetMinimumSelectedSize().width();
- needed_width += kNewTabButtonHOffset - kTabHOffset;
+ needed_width += GetNewTabButtonHOffset() - GetTabHOffset();
needed_width += newtab_button_bounds_.width();
return gfx::Size(needed_width, Tab::GetMinimumUnselectedSize().height());
}
@@ -1098,7 +1141,7 @@ void TabStrip::StartInsertTabAnimation(int model_index) {
ideal_bounds(model_index).height());
} else {
BaseTab* last_tab = tab_at(model_index - 1);
- tab->SetBounds(last_tab->bounds().right() + kTabHOffset,
+ tab->SetBounds(last_tab->bounds().right() + GetTabHOffset(),
ideal_bounds(model_index).y(), 0,
ideal_bounds(model_index).height());
}
@@ -1183,7 +1226,7 @@ void TabStrip::DoLayout() {
if (newtab_button_) {
if (SizeTabButtonToTopOfTabStrip()) {
newtab_button_bounds_.set_height(
- kNewTabButtonHeight + kNewTabButtonVOffset);
+ kNewTabButtonHeight + GetNewTabButtonVOffset());
newtab_button_->SetImageAlignment(views::ImageButton::ALIGN_LEFT,
views::ImageButton::ALIGN_BOTTOM);
} else {
@@ -1248,7 +1291,7 @@ void TabStrip::CalculateBoundsForDraggedTabs(const std::vector<BaseTab*>& tabs,
gfx::Rect new_bounds = tab->bounds();
new_bounds.set_origin(gfx::Point(x, 0));
bounds->push_back(new_bounds);
- x += tab->width() + kTabHOffset;
+ x += tab->width() + GetTabHOffset();
}
}
@@ -1261,7 +1304,7 @@ int TabStrip::GetSizeNeededForTabs(const std::vector<BaseTab*>& tabs) {
width += kMiniToNonMiniGap;
}
if (tabs.size() > 0)
- width += kTabHOffset * static_cast<int>(tabs.size() - 1);
+ width += GetTabHOffset() * static_cast<int>(tabs.size() - 1);
return width;
}
@@ -1400,7 +1443,7 @@ int TabStrip::NumNonClosingTabs(int index1, int index2) const {
void TabStrip::UpdateNumVisibleTabs(int non_closing_tab_count,
int width,
double tab_size) {
- num_visible_tabs_ = (width + kTabHOffset) / (tab_size + kTabHOffset);
+ num_visible_tabs_ = (width + GetTabHOffset()) / (tab_size + GetTabHOffset());
num_visible_tabs_ = std::max(1, num_visible_tabs_);
// Make sure the first_visible_tab_index_ is valid.
// TODO: this isn't quite right, it doesn't take into account closing tabs.
@@ -1448,7 +1491,8 @@ void TabStrip::GetDesiredTabWidths(int tab_count,
int available_width;
if (available_width_for_tabs_ < 0) {
available_width = width();
- available_width -= (kNewTabButtonHOffset + newtab_button_bounds_.width());
+ available_width -=
+ (GetNewTabButtonHOffset() + newtab_button_bounds_.width());
} else {
// Interesting corner case: if |available_width_for_tabs_| > the result
// of the calculation in the conditional arm above, the strip is in
@@ -1463,7 +1507,7 @@ void TabStrip::GetDesiredTabWidths(int tab_count,
}
if (mini_tab_count > 0) {
- available_width -= mini_tab_count * (Tab::GetMiniWidth() + kTabHOffset);
+ available_width -= mini_tab_count * (Tab::GetMiniWidth() + GetTabHOffset());
tab_count -= mini_tab_count;
if (tab_count == 0) {
*selected_width = *unselected_width = Tab::GetStandardSize().width();
@@ -1476,7 +1520,7 @@ void TabStrip::GetDesiredTabWidths(int tab_count,
// Calculate the desired tab widths by dividing the available space into equal
// portions. Don't let tabs get larger than the "standard width" or smaller
// than the minimum width for each type, respectively.
- const int total_offset = kTabHOffset * (tab_count - 1);
+ const int total_offset = GetTabHOffset() * (tab_count - 1);
const double desired_tab_width = std::min((static_cast<double>(
available_width - total_offset) / static_cast<double>(tab_count)),
static_cast<double>(Tab::GetStandardSize().width()));
@@ -1569,12 +1613,12 @@ gfx::Rect TabStrip::GetDropBounds(int drop_index,
if (drop_index < tab_count()) {
Tab* tab = tab_at(drop_index);
if (drop_before)
- center_x = tab->x() - (kTabHOffset / 2);
+ center_x = tab->x() - (GetTabHOffset() / 2);
else
center_x = tab->x() + (tab->width() / 2);
} else {
Tab* last_tab = tab_at(drop_index - 1);
- center_x = last_tab->x() + last_tab->width() + (kTabHOffset / 2);
+ center_x = last_tab->x() + last_tab->width() + (GetTabHOffset() / 2);
}
// Mirror the center point if necessary.
@@ -1760,14 +1804,14 @@ void TabStrip::GenerateIdealBounds() {
set_ideal_bounds(i,
gfx::Rect(rounded_tab_x, 0, Round(end_of_tab) - rounded_tab_x,
tab_height));
- tab_x = end_of_tab + kTabHOffset;
+ tab_x = end_of_tab + GetTabHOffset();
last_was_mini = tab->data().mini;
}
}
// If we're in stacking mode, update the positions now that we have
// appropriate widths.
- if (stacking_ && tab_x - kTabHOffset >
+ if (stacking_ && tab_x - GetTabHOffset() >
width() - newtab_button_bounds_.width()) {
tab_x = GenerateIdealBoundsWithStacking(
mini_tab_count, non_closing_tab_count, tab_x, selected);
@@ -1775,7 +1819,7 @@ void TabStrip::GenerateIdealBounds() {
// Update bounds of new tab button.
int new_tab_x;
- int new_tab_y = SizeTabButtonToTopOfTabStrip() ? 0 : kNewTabButtonVOffset;
+ int new_tab_y = SizeTabButtonToTopOfTabStrip() ? 0 : GetNewTabButtonVOffset();
if (abs(Round(unselected) - Tab::GetStandardSize().width()) > 1 &&
!in_tab_close_) {
// We're shrinking tabs, so we need to anchor the New Tab button to the
@@ -1783,7 +1827,7 @@ void TabStrip::GenerateIdealBounds() {
// right-most Tab, otherwise it'll bounce when animating.
new_tab_x = width() - newtab_button_bounds_.width();
} else {
- new_tab_x = Round(tab_x - kTabHOffset) + kNewTabButtonHOffset;
+ new_tab_x = Round(tab_x - GetTabHOffset()) + GetNewTabButtonHOffset();
}
newtab_button_bounds_.set_origin(gfx::Point(new_tab_x, new_tab_y));
}
@@ -1813,7 +1857,7 @@ double TabStrip::GenerateIdealBoundsWithStacking(int mini_tab_count,
// Always reserve kMaxEdgeStackWidth on each side for stacking. We don't
// later try to adjust as it can lead to tabs bouncing around.
int available_width = width() -
- (kNewTabButtonHOffset + newtab_button_bounds_.width()) - next_x -
+ (GetNewTabButtonHOffset() + newtab_button_bounds_.width()) - next_x -
2 * kMaxEdgeStackWidth;
if (available_width <= 0)
return new_tab_x;
@@ -1852,7 +1896,7 @@ double TabStrip::GenerateIdealBoundsWithStacking(int mini_tab_count,
// it to the last stacked tab on the left.
next_x += available_width + kMaxEdgeStackWidth -
(num_visible_tabs_ * selected_size +
- std::max(num_visible_tabs_ - 1, 0) * kTabHOffset);
+ std::max(num_visible_tabs_ - 1, 0) * GetTabHOffset());
}
// Totally visible tabs.
@@ -1863,7 +1907,7 @@ double TabStrip::GenerateIdealBoundsWithStacking(int mini_tab_count,
continue;
gfx::Rect bounds = ideal_bounds(tab_index);
bounds.set_x(next_x);
- next_x = bounds.right() + kTabHOffset;
+ next_x = bounds.right() + GetTabHOffset();
set_ideal_bounds(tab_index, bounds);
visible_count++;
}
@@ -1874,7 +1918,8 @@ double TabStrip::GenerateIdealBoundsWithStacking(int mini_tab_count,
double stacked_offset =
kMaxEdgeStackWidth / static_cast<double>(stacked_trailing_count);
- next_x = width() - (kNewTabButtonHOffset + newtab_button_bounds_.width()) -
+ next_x = width() -
+ (GetNewTabButtonHOffset() + newtab_button_bounds_.width()) -
(stacked_trailing_count - 1) * stacked_offset - selected_size;
for (; tab_index < tab_count(); ++tab_index) {
if (tab_at(tab_index)->closing())
@@ -1885,7 +1930,7 @@ double TabStrip::GenerateIdealBoundsWithStacking(int mini_tab_count,
next_x += stacked_offset;
}
- return next_x + kTabHOffset;
+ return next_x + GetTabHOffset();
}
void TabStrip::StartResizeLayoutAnimation() {
@@ -1908,7 +1953,7 @@ void TabStrip::StartMouseInitiatedRemoveTabAnimation(int model_index) {
// The user initiated the close. We want to persist the bounds of all the
// existing tabs, so we manually shift ideal_bounds then animate.
BaseTab* tab_closing = tab_at(model_index);
- int delta = tab_closing->width() + kTabHOffset;
+ int delta = tab_closing->width() + GetTabHOffset();
// If the tab being closed is a mini-tab next to a non-mini-tab, be sure to
// add the extra padding.
DCHECK_NE(model_index + 1, tab_count());

Powered by Google App Engine
This is Rietveld 408576698