| 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 42835490b6401cedfaf0876b52a6c1977048510f..59ba6267fb0410d6cbbbf55e12f31d7f595d66cd 100644
|
| --- a/chrome/browser/ui/views/tabs/tab_strip.cc
|
| +++ b/chrome/browser/ui/views/tabs/tab_strip.cc
|
| @@ -604,7 +604,7 @@ void TabStrip::StartHighlight(int model_index) {
|
| }
|
|
|
| void TabStrip::StopAllHighlighting() {
|
| - for (int i = 0; i < tab_count(); ++i)
|
| + for (int i = 0; i < GetTabCount(); ++i)
|
| tab_at(i)->StopPulse();
|
| }
|
|
|
| @@ -637,7 +637,7 @@ void TabStrip::AddTabAt(int model_index,
|
|
|
| // Don't animate the first tab, it looks weird, and don't animate anything
|
| // if the containing window isn't visible yet.
|
| - if (tab_count() > 1 && GetWidget() && GetWidget()->IsVisible())
|
| + if (GetTabCount() > 1 && GetWidget() && GetWidget()->IsVisible())
|
| StartInsertTabAnimation(model_index);
|
| else
|
| DoLayout();
|
| @@ -856,10 +856,6 @@ void TabStrip::TabTitleChangedNotLoading(int model_index) {
|
| tab->StartMiniTabTitleAnimation();
|
| }
|
|
|
| -int TabStrip::GetModelIndexOfTab(const Tab* tab) const {
|
| - return tabs_.GetIndexOfView(tab);
|
| -}
|
| -
|
| int TabStrip::GetModelCount() const {
|
| return controller_->GetCount();
|
| }
|
| @@ -873,7 +869,7 @@ bool TabStrip::IsDragSessionActive() const {
|
| }
|
|
|
| bool TabStrip::IsActiveDropTarget() const {
|
| - for (int i = 0; i < tab_count(); ++i) {
|
| + for (int i = 0; i < GetTabCount(); ++i) {
|
| Tab* tab = tab_at(i);
|
| if (tab->dragging())
|
| return true;
|
| @@ -923,7 +919,7 @@ bool TabStrip::IsRectInWindowCaption(const gfx::Rect& rect) {
|
| }
|
|
|
| void TabStrip::SetBackgroundOffset(const gfx::Point& offset) {
|
| - for (int i = 0; i < tab_count(); ++i)
|
| + for (int i = 0; i < GetTabCount(); ++i)
|
| tab_at(i)->set_background_offset(offset);
|
| newtab_button_->set_background_offset(offset);
|
| }
|
| @@ -1056,7 +1052,7 @@ void TabStrip::MaybeStartDrag(
|
| int y = event.y();
|
| // Build the set of selected tabs to drag and calculate the offset from the
|
| // first selected tab.
|
| - for (int i = 0; i < tab_count(); ++i) {
|
| + for (int i = 0; i < GetTabCount(); ++i) {
|
| Tab* other_tab = tab_at(i);
|
| if (IsTabSelected(other_tab)) {
|
| tabs.push_back(other_tab);
|
| @@ -1148,7 +1144,7 @@ bool TabStrip::ShouldPaintTab(const Tab* tab, gfx::Rect* clip) {
|
|
|
| int active_index = IsStackingDraggedTabs() ?
|
| controller_->GetActiveIndex() : touch_layout_->active_index();
|
| - if (active_index == tab_count())
|
| + if (active_index == GetTabCount())
|
| active_index--;
|
|
|
| if (index < active_index) {
|
| @@ -1225,9 +1221,9 @@ void TabStrip::PaintChildren(gfx::Canvas* canvas,
|
| if (inactive_tab_alpha < 255)
|
| canvas->SaveLayerAlpha(inactive_tab_alpha);
|
|
|
| - PaintClosingTabs(canvas, tab_count(), cull_set);
|
| + PaintClosingTabs(canvas, GetTabCount(), cull_set);
|
|
|
| - for (int i = tab_count() - 1; i >= 0; --i) {
|
| + for (int i = GetTabCount() - 1; i >= 0; --i) {
|
| Tab* tab = tab_at(i);
|
| if (tab->IsSelected())
|
| selected_tab_count++;
|
| @@ -1260,7 +1256,7 @@ void TabStrip::PaintChildren(gfx::Canvas* canvas,
|
| tab->Paint(canvas, cull_set);
|
| }
|
|
|
| - for (int i = tab_count() - 1; i > active_tab_index; --i) {
|
| + for (int i = GetTabCount() - 1; i > active_tab_index; --i) {
|
| Tab* tab = tab_at(i);
|
| tab->Paint(canvas, cull_set);
|
| }
|
| @@ -1323,15 +1319,15 @@ gfx::Size TabStrip::GetPreferredSize() const {
|
| // Otherwise the minimum width is based on the actual number of tabs.
|
| const int mini_tab_count = GetMiniTabCount();
|
| needed_tab_width = mini_tab_count * Tab::GetMiniWidth();
|
| - const int remaining_tab_count = tab_count() - mini_tab_count;
|
| + const int remaining_tab_count = GetTabCount() - mini_tab_count;
|
| const int min_selected_width = Tab::GetMinimumSelectedSize().width();
|
| const int min_unselected_width = Tab::GetMinimumUnselectedSize().width();
|
| if (remaining_tab_count > 0) {
|
| needed_tab_width += kMiniToNonMiniGap + min_selected_width +
|
| ((remaining_tab_count - 1) * min_unselected_width);
|
| }
|
| - if (tab_count() > 1)
|
| - needed_tab_width += (tab_count() - 1) * kTabHorizontalOffset;
|
| + if (GetTabCount() > 1)
|
| + needed_tab_width += (GetTabCount() - 1) * kTabHorizontalOffset;
|
|
|
| // Don't let the tabstrip shrink smaller than is necessary to show one tab,
|
| // and don't force it to be larger than is necessary to show 20 tabs.
|
| @@ -1469,6 +1465,14 @@ views::View* TabStrip::GetTooltipHandlerForPoint(const gfx::Point& point) {
|
| return this;
|
| }
|
|
|
| +int TabStrip::GetModelIndexOfTab(const Tab* tab) const {
|
| + return tabs_.GetIndexOfView(tab);
|
| +}
|
| +
|
| +int TabStrip::GetTabCount() const {
|
| + return tabs_.view_size();
|
| +}
|
| +
|
| // static
|
| int TabStrip::GetImmersiveHeight() {
|
| return Tab::GetImmersiveHeight();
|
| @@ -1575,7 +1579,7 @@ void TabStrip::ScheduleRemoveTabAnimation(Tab* tab) {
|
| }
|
|
|
| void TabStrip::AnimateToIdealBounds() {
|
| - for (int i = 0; i < tab_count(); ++i) {
|
| + for (int i = 0; i < GetTabCount(); ++i) {
|
| Tab* tab = tab_at(i);
|
| if (!tab->dragging()) {
|
| bounds_animator_.AnimateViewTo(tab, ideal_bounds(i));
|
| @@ -1620,7 +1624,7 @@ void TabStrip::SetTabVisibility() {
|
| // we could e.g. binary-search for the changeover point. But since we have to
|
| // iterate through all the tabs to call SetVisible() anyway, it doesn't seem
|
| // worth it.
|
| - for (int i = 0; i < tab_count(); ++i) {
|
| + for (int i = 0; i < GetTabCount(); ++i) {
|
| Tab* tab = tab_at(i);
|
| tab->SetVisible(ShouldTabBeVisible(tab));
|
| }
|
| @@ -1635,7 +1639,7 @@ void TabStrip::SetTabVisibility() {
|
|
|
| void TabStrip::DragActiveTab(const std::vector<int>& initial_positions,
|
| int delta) {
|
| - DCHECK_EQ(tab_count(), static_cast<int>(initial_positions.size()));
|
| + DCHECK_EQ(GetTabCount(), static_cast<int>(initial_positions.size()));
|
| if (!touch_layout_) {
|
| StackDraggedTabs(delta);
|
| return;
|
| @@ -1646,10 +1650,10 @@ void TabStrip::DragActiveTab(const std::vector<int>& initial_positions,
|
| }
|
|
|
| void TabStrip::SetIdealBoundsFromPositions(const std::vector<int>& positions) {
|
| - if (static_cast<size_t>(tab_count()) != positions.size())
|
| + if (static_cast<size_t>(GetTabCount()) != positions.size())
|
| return;
|
|
|
| - for (int i = 0; i < tab_count(); ++i) {
|
| + for (int i = 0; i < GetTabCount(); ++i) {
|
| gfx::Rect bounds(ideal_bounds(i));
|
| bounds.set_x(positions[i]);
|
| tabs_.set_ideal_bounds(i, bounds);
|
| @@ -1675,7 +1679,7 @@ void TabStrip::StackDraggedTabs(int delta) {
|
| }
|
| const bool is_active_mini = tab_at(active_index)->data().mini;
|
| const int active_width = ideal_bounds(active_index).width();
|
| - for (int i = active_index + 1; i < tab_count(); ++i) {
|
| + for (int i = active_index + 1; i < GetTabCount(); ++i) {
|
| const int max_x = ideal_bounds(active_index).x() +
|
| (kStackedPadding * std::min(i - active_index, kMaxStackedCount));
|
| gfx::Rect new_bounds(ideal_bounds(i));
|
| @@ -1688,21 +1692,21 @@ void TabStrip::StackDraggedTabs(int delta) {
|
| }
|
| } else {
|
| // Drag the tabs to the right, stacking tabs after the active tab.
|
| - const int last_tab_width = ideal_bounds(tab_count() - 1).width();
|
| + const int last_tab_width = ideal_bounds(GetTabCount() - 1).width();
|
| const int last_tab_x = tab_area_width() - last_tab_width;
|
| - if (active_index == tab_count() - 1 &&
|
| - ideal_bounds(tab_count() - 1).x() == last_tab_x)
|
| + if (active_index == GetTabCount() - 1 &&
|
| + ideal_bounds(GetTabCount() - 1).x() == last_tab_x)
|
| return;
|
| - const int adjusted_delta =
|
| - std::min(last_tab_x -
|
| - kStackedPadding * std::min(tab_count() - active_index - 1,
|
| - kMaxStackedCount) -
|
| - ideal_bounds(active_index).x(),
|
| - delta);
|
| - for (int last_index = tab_count() - 1, i = last_index; i >= active_index;
|
| + const int adjusted_delta = std::min(
|
| + last_tab_x -
|
| + kStackedPadding *
|
| + std::min(GetTabCount() - active_index - 1, kMaxStackedCount) -
|
| + ideal_bounds(active_index).x(),
|
| + delta);
|
| + for (int last_index = GetTabCount() - 1, i = last_index; i >= active_index;
|
| --i) {
|
| const int max_x = last_tab_x -
|
| - std::min(tab_count() - i - 1, kMaxStackedCount) * kStackedPadding;
|
| + std::min(GetTabCount() - i - 1, kMaxStackedCount) * kStackedPadding;
|
| gfx::Rect new_bounds(ideal_bounds(i));
|
| int new_x = std::min(max_x, new_bounds.x() + adjusted_delta);
|
| // Because of rounding not all tabs are the same width. Adjust the
|
| @@ -1720,7 +1724,7 @@ void TabStrip::StackDraggedTabs(int delta) {
|
| new_bounds.set_x(std::min(min_x, new_bounds.x() + delta));
|
| tabs_.set_ideal_bounds(i, new_bounds);
|
| }
|
| - if (ideal_bounds(tab_count() - 1).right() >= newtab_button_->x())
|
| + if (ideal_bounds(GetTabCount() - 1).right() >= newtab_button_->x())
|
| newtab_button_->SetVisible(false);
|
| }
|
| views::ViewModelUtils::SetViewBoundsToIdealBounds(tabs_);
|
| @@ -1796,13 +1800,13 @@ int TabStrip::GetSizeNeededForTabs(const Tabs& tabs) {
|
|
|
| int TabStrip::GetMiniTabCount() const {
|
| int mini_count = 0;
|
| - while (mini_count < tab_count() && tab_at(mini_count)->data().mini)
|
| + while (mini_count < GetTabCount() && tab_at(mini_count)->data().mini)
|
| mini_count++;
|
| return mini_count;
|
| }
|
|
|
| const Tab* TabStrip::GetLastVisibleTab() const {
|
| - for (int i = tab_count() - 1; i >= 0; --i) {
|
| + for (int i = GetTabCount() - 1; i >= 0; --i) {
|
| const Tab* tab = tab_at(i);
|
| if (tab->visible())
|
| return tab;
|
| @@ -1863,7 +1867,7 @@ void TabStrip::StartedDraggingTabs(const Tabs& tabs) {
|
| PrepareForAnimation();
|
|
|
| // Reset dragging state of existing tabs.
|
| - for (int i = 0; i < tab_count(); ++i)
|
| + for (int i = 0; i < GetTabCount(); ++i)
|
| tab_at(i)->set_dragging(false);
|
|
|
| for (size_t i = 0; i < tabs.size(); ++i) {
|
| @@ -2126,7 +2130,7 @@ void TabStrip::ResizeLayoutTabs() {
|
| // We've been called back after the TabStrip has been emptied out (probably
|
| // just prior to the window being destroyed). We need to do nothing here or
|
| // else GetTabAt below will crash.
|
| - if (tab_count() == 0)
|
| + if (GetTabCount() == 0)
|
| return;
|
|
|
| // It is critically important that this is unhooked here, otherwise we will
|
| @@ -2136,7 +2140,7 @@ void TabStrip::ResizeLayoutTabs() {
|
| in_tab_close_ = false;
|
| available_width_for_tabs_ = -1;
|
| int mini_tab_count = GetMiniTabCount();
|
| - if (mini_tab_count == tab_count()) {
|
| + if (mini_tab_count == GetTabCount()) {
|
| // Only mini-tabs, we know the tab widths won't have changed (all
|
| // mini-tabs have the same width), so there is nothing to do.
|
| return;
|
| @@ -2165,8 +2169,8 @@ void TabStrip::StartResizeLayoutTabsFromTouchTimer() {
|
|
|
| void TabStrip::SetTabBoundsForDrag(const std::vector<gfx::Rect>& tab_bounds) {
|
| StopAnimating(false);
|
| - DCHECK_EQ(tab_count(), static_cast<int>(tab_bounds.size()));
|
| - for (int i = 0; i < tab_count(); ++i)
|
| + DCHECK_EQ(GetTabCount(), static_cast<int>(tab_bounds.size()));
|
| + for (int i = 0; i < GetTabCount(); ++i)
|
| tab_at(i)->SetBoundsRect(tab_bounds[i]);
|
| // Reset the layout size as we've effectively layed out a different size.
|
| // This ensures a layout happens after the drag is done.
|
| @@ -2193,7 +2197,7 @@ gfx::Rect TabStrip::GetDropBounds(int drop_index,
|
| bool* is_beneath) {
|
| DCHECK_NE(drop_index, -1);
|
| int center_x;
|
| - if (drop_index < tab_count()) {
|
| + if (drop_index < GetTabCount()) {
|
| Tab* tab = tab_at(drop_index);
|
| if (drop_before)
|
| center_x = tab->x() - (kTabHorizontalOffset / 2);
|
| @@ -2230,7 +2234,7 @@ void TabStrip::UpdateDropIndex(const DropTargetEvent& event) {
|
| // original (and therefore non-mirrored) positions of the tabs.
|
| const int x = GetMirroredXInView(event.x());
|
| // We don't allow replacing the urls of mini-tabs.
|
| - for (int i = GetMiniTabCount(); i < tab_count(); ++i) {
|
| + for (int i = GetMiniTabCount(); i < GetTabCount(); ++i) {
|
| Tab* tab = tab_at(i);
|
| const int tab_max_x = tab->x() + tab->width();
|
| const int hot_width = tab->width() / kTabEdgeRatioInverse;
|
| @@ -2246,7 +2250,7 @@ void TabStrip::UpdateDropIndex(const DropTargetEvent& event) {
|
| }
|
|
|
| // The drop isn't over a tab, add it to the end.
|
| - SetDropIndex(tab_count(), true);
|
| + SetDropIndex(GetTabCount(), true);
|
| }
|
|
|
| void TabStrip::SetDropIndex(int tab_data_index, bool drop_before) {
|
| @@ -2335,7 +2339,7 @@ TabStrip::DropInfo::~DropInfo() {
|
|
|
| void TabStrip::PrepareForAnimation() {
|
| if (!IsDragSessionActive() && !TabDragController::IsAttachedTo(this)) {
|
| - for (int i = 0; i < tab_count(); ++i)
|
| + for (int i = 0; i < GetTabCount(); ++i)
|
| tab_at(i)->set_dragging(false);
|
| }
|
| }
|
| @@ -2353,7 +2357,7 @@ void TabStrip::GenerateIdealBounds() {
|
| return;
|
| }
|
|
|
| - GetDesiredTabWidths(tab_count(), GetMiniTabCount(),
|
| + GetDesiredTabWidths(GetTabCount(), GetMiniTabCount(),
|
| ¤t_unselected_width_, ¤t_selected_width_);
|
|
|
| // NOTE: This currently assumes a tab's height doesn't differ based on
|
| @@ -2361,7 +2365,7 @@ void TabStrip::GenerateIdealBounds() {
|
| int tab_height = Tab::GetStandardSize().height();
|
| int first_non_mini_index = 0;
|
| double tab_x = GenerateIdealBoundsForMiniTabs(&first_non_mini_index);
|
| - for (int i = first_non_mini_index; i < tab_count(); ++i) {
|
| + for (int i = first_non_mini_index; i < GetTabCount(); ++i) {
|
| Tab* tab = tab_at(i);
|
| DCHECK(!tab->data().mini);
|
| double tab_width =
|
| @@ -2395,11 +2399,11 @@ int TabStrip::GenerateIdealBoundsForMiniTabs(int* first_non_mini_index) {
|
| int mini_width = Tab::GetMiniWidth();
|
| int tab_height = Tab::GetStandardSize().height();
|
| int index = 0;
|
| - for (; index < tab_count() && tab_at(index)->data().mini; ++index) {
|
| + for (; index < GetTabCount() && tab_at(index)->data().mini; ++index) {
|
| tabs_.set_ideal_bounds(index, gfx::Rect(next_x, 0, mini_width, tab_height));
|
| next_x += mini_width + kTabHorizontalOffset;
|
| }
|
| - if (index > 0 && index < tab_count())
|
| + if (index > 0 && index < GetTabCount())
|
| next_x += kMiniToNonMiniGap;
|
| if (first_non_mini_index)
|
| *first_non_mini_index = index;
|
| @@ -2429,11 +2433,11 @@ void TabStrip::StartMouseInitiatedRemoveTabAnimation(int model_index) {
|
| int delta = tab_closing->width() + kTabHorizontalOffset;
|
| // If the tab being closed is a mini-tab next to a non-mini-tab, be sure to
|
| // add the extra padding.
|
| - DCHECK_LT(model_index, tab_count() - 1);
|
| + DCHECK_LT(model_index, GetTabCount() - 1);
|
| if (tab_closing->data().mini && !tab_at(model_index + 1)->data().mini)
|
| delta += kMiniToNonMiniGap;
|
|
|
| - for (int i = model_index + 1; i < tab_count(); ++i) {
|
| + for (int i = model_index + 1; i < GetTabCount(); ++i) {
|
| gfx::Rect bounds = ideal_bounds(i);
|
| bounds.set_x(bounds.x() - delta);
|
| tabs_.set_ideal_bounds(i, bounds);
|
| @@ -2444,7 +2448,7 @@ void TabStrip::StartMouseInitiatedRemoveTabAnimation(int model_index) {
|
| // the new tab button should stay where it is.
|
| newtab_button_bounds_.set_x(std::min(
|
| width() - newtab_button_bounds_.width(),
|
| - ideal_bounds(tab_count() - 1).right() + kNewTabButtonHorizontalOffset));
|
| + ideal_bounds(GetTabCount() - 1).right() + kNewTabButtonHorizontalOffset));
|
|
|
| PrepareForAnimation();
|
|
|
| @@ -2492,10 +2496,10 @@ Tab* TabStrip::FindTabForEvent(const gfx::Point& point) {
|
| tab = FindTabForEventFrom(point, active_tab_index + 1, 1);
|
| return tab;
|
| }
|
| - if (tab_count())
|
| + if (GetTabCount())
|
| return FindTabForEventFrom(point, 0, 1);
|
| } else {
|
| - for (int i = 0; i < tab_count(); ++i) {
|
| + for (int i = 0; i < GetTabCount(); ++i) {
|
| if (IsPointInTab(tab_at(i), point))
|
| return tab_at(i);
|
| }
|
| @@ -2506,10 +2510,10 @@ Tab* TabStrip::FindTabForEvent(const gfx::Point& point) {
|
| Tab* TabStrip::FindTabForEventFrom(const gfx::Point& point,
|
| int start,
|
| int delta) {
|
| - // |start| equals tab_count() when there are only pinned tabs.
|
| - if (start == tab_count())
|
| + // |start| equals GetTabCount() when there are only pinned tabs.
|
| + if (start == GetTabCount())
|
| start += delta;
|
| - for (int i = start; i >= 0 && i < tab_count(); i += delta) {
|
| + for (int i = start; i >= 0 && i < GetTabCount(); i += delta) {
|
| if (IsPointInTab(tab_at(i), point))
|
| return tab_at(i);
|
| }
|
| @@ -2521,8 +2525,8 @@ views::View* TabStrip::FindTabHitByPoint(const gfx::Point& point) {
|
| // walk the display list hit-testing Tabs. Since the active tab always
|
| // renders on top of adjacent tabs, it needs to be hit-tested before any
|
| // left-adjacent Tab, so we look ahead for it as we walk.
|
| - for (int i = 0; i < tab_count(); ++i) {
|
| - Tab* next_tab = i < (tab_count() - 1) ? tab_at(i + 1) : NULL;
|
| + for (int i = 0; i < GetTabCount(); ++i) {
|
| + Tab* next_tab = i < (GetTabCount() - 1) ? tab_at(i + 1) : NULL;
|
| if (next_tab && next_tab->IsActive() && IsPointInTab(next_tab, point))
|
| return next_tab;
|
| if (IsPointInTab(tab_at(i), point))
|
| @@ -2534,7 +2538,7 @@ views::View* TabStrip::FindTabHitByPoint(const gfx::Point& point) {
|
|
|
| std::vector<int> TabStrip::GetTabXCoordinates() {
|
| std::vector<int> results;
|
| - for (int i = 0; i < tab_count(); ++i)
|
| + for (int i = 0; i < GetTabCount(); ++i)
|
| results.push_back(ideal_bounds(i).x());
|
| return results;
|
| }
|
| @@ -2576,7 +2580,7 @@ bool TabStrip::NeedsTouchLayout() const {
|
| return false;
|
|
|
| int mini_tab_count = GetMiniTabCount();
|
| - int normal_count = tab_count() - mini_tab_count;
|
| + int normal_count = GetTabCount() - mini_tab_count;
|
| if (normal_count <= 1 || normal_count == mini_tab_count)
|
| return false;
|
| int x = GetStartXForNormalTabs();
|
| @@ -2626,12 +2630,12 @@ void TabStrip::ButtonPressed(views::Button* sender, const ui::Event& event) {
|
|
|
| // Overridden to support automation. See automation_proxy_uitest.cc.
|
| const views::View* TabStrip::GetViewByID(int view_id) const {
|
| - if (tab_count() > 0) {
|
| + if (GetTabCount() > 0) {
|
| if (view_id == VIEW_ID_TAB_LAST)
|
| - return tab_at(tab_count() - 1);
|
| + return tab_at(GetTabCount() - 1);
|
| if ((view_id >= VIEW_ID_TAB_0) && (view_id < VIEW_ID_TAB_LAST)) {
|
| int index = view_id - VIEW_ID_TAB_0;
|
| - return (index >= 0 && index < tab_count()) ? tab_at(index) : NULL;
|
| + return (index >= 0 && index < GetTabCount()) ? tab_at(index) : NULL;
|
| }
|
| }
|
|
|
|
|