| 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 497269ffebb6bf558023ef711cec80fd0bee82d9..1c398270d580335fba93d224bd7bb676041b039f 100644
|
| --- a/chrome/browser/ui/views/tabs/tab_strip.cc
|
| +++ b/chrome/browser/ui/views/tabs/tab_strip.cc
|
| @@ -32,6 +32,7 @@
|
| #include "ui/base/dragdrop/drag_drop_types.h"
|
| #include "ui/base/l10n/l10n_util.h"
|
| #include "ui/base/resource/resource_bundle.h"
|
| +#include "ui/base/scale.h"
|
| #include "ui/base/touch/touch_mode_support.h"
|
| #include "ui/gfx/canvas.h"
|
| #include "ui/gfx/path.h"
|
| @@ -52,21 +53,55 @@
|
|
|
| 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
|
| +namespace {
|
| +
|
| +// Offsets for the new tab button to bring it closer to the rightmost tab.
|
| +
|
| +const int GetNewTabButtonHOffset() {
|
| + switch (ui::GetDisplayScale()) {
|
| + case ui::DS_ASH:
|
| + return -11;
|
| + case ui::DS_METRO_100:
|
| + case ui::DS_METRO_140:
|
| + case ui::DS_METRO_180:
|
| + // TODO(joi): Metro scales other than 100%.
|
| + return -6;
|
| + default:
|
| + return -5;
|
| + }
|
| +}
|
| +
|
| +const int GetNewTabButtonVOffset() {
|
| + switch (ui::GetDisplayScale()) {
|
| + case ui::DS_ASH:
|
| + return 7;
|
| + case ui::DS_METRO_100:
|
| + case ui::DS_METRO_140:
|
| + case ui::DS_METRO_180:
|
| + // TODO(joi): Metro scales other than 100%.
|
| + return 10;
|
| + default:
|
| + return 5;
|
| + }
|
| +}
|
| +
|
| // 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
|
| +
|
| +const int GetTabHOffset() {
|
| + switch (ui::GetDisplayScale()) {
|
| + case ui::DS_ASH:
|
| + return -27;
|
| + case ui::DS_METRO_100:
|
| + case ui::DS_METRO_140:
|
| + case ui::DS_METRO_180:
|
| + // TODO(joi): Metro scales other than 100%.
|
| + return -16;
|
| + default:
|
| + return -16;
|
| + }
|
| +}
|
| +
|
| static const int kTabStripAnimationVSlop = 40;
|
| // Inactive tabs in a native frame are slightly transparent.
|
| static const int kNativeFrameInactiveTabAlpha = 200;
|
| @@ -91,8 +126,6 @@ static inline int Round(double x) {
|
| // Max width reserved for stacked tabs along a particular edge.
|
| static const double kMaxEdgeStackWidth = 24;
|
|
|
| -namespace {
|
| -
|
| // Animation delegate used when a dragged tab is released. When done sets the
|
| // dragging state to false.
|
| class ResetDraggingStateDelegate
|
| @@ -251,7 +284,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;
|
| @@ -501,7 +534,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;
|
| @@ -926,7 +959,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());
|
| }
|
| @@ -1103,7 +1136,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());
|
| }
|
| @@ -1188,7 +1221,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 {
|
| @@ -1253,7 +1286,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();
|
| }
|
| }
|
|
|
| @@ -1266,7 +1299,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;
|
| }
|
|
|
| @@ -1405,7 +1438,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.
|
| @@ -1453,7 +1486,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
|
| @@ -1468,7 +1502,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();
|
| @@ -1481,7 +1515,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()));
|
| @@ -1574,12 +1608,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.
|
| @@ -1765,14 +1799,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);
|
| @@ -1780,7 +1814,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
|
| @@ -1788,7 +1822,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));
|
| }
|
| @@ -1818,7 +1852,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;
|
| @@ -1857,7 +1891,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.
|
| @@ -1868,7 +1902,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++;
|
| }
|
| @@ -1879,7 +1913,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())
|
| @@ -1890,7 +1925,7 @@ double TabStrip::GenerateIdealBoundsWithStacking(int mini_tab_count,
|
| next_x += stacked_offset;
|
| }
|
|
|
| - return next_x + kTabHOffset;
|
| + return next_x + GetTabHOffset();
|
| }
|
|
|
| void TabStrip::StartResizeLayoutAnimation() {
|
| @@ -1913,7 +1948,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());
|
|
|