| Index: chrome/browser/ui/views/sidebar/sidebar_base_tab_strip.cc
|
| ===================================================================
|
| --- chrome/browser/ui/views/sidebar/sidebar_base_tab_strip.cc (revision 0)
|
| +++ chrome/browser/ui/views/sidebar/sidebar_base_tab_strip.cc (revision 0)
|
| @@ -0,0 +1,198 @@
|
| +// Copyright (c) 2010 The Chromium Authors. All rights reserved.
|
| +// Use of this source code is governed by a BSD-style license that can be
|
| +// found in the LICENSE file.
|
| +
|
| +#include "chrome/browser/ui/views/sidebar/sidebar_base_tab_strip.h"
|
| +
|
| +#include "chrome/browser/ui/view_ids.h"
|
| +#include "chrome/browser/ui/views/sidebar/sidebar_base_tab.h"
|
| +#include "chrome/browser/ui/views/sidebar/sidebar_tab_strip_controller.h"
|
| +#include "views/window/window.h"
|
| +
|
| +SidebarBaseTabStrip::SidebarBaseTabStrip(SidebarTabStripController* controller)
|
| + : controller_(controller),
|
| + ALLOW_THIS_IN_INITIALIZER_LIST(bounds_animator_(this)) {
|
| + DCHECK(controller_.get());
|
| + bounds_animator_.set_observer(this);
|
| + SetID(VIEW_ID_SIDEBAR_TAB_STRIP);
|
| +}
|
| +
|
| +SidebarBaseTabStrip::~SidebarBaseTabStrip() {
|
| +}
|
| +
|
| +void SidebarBaseTabStrip::OnBoundsChanged() {
|
| + View::OnBoundsChanged();
|
| + controller_->TabStripBoundsChanged(IsAnimating());
|
| +}
|
| +
|
| +void SidebarBaseTabStrip::SelectTab(SidebarBaseTab* tab) {
|
| + int model_index = GetModelIndexOfBaseTab(tab);
|
| + controller_->SelectTab(model_index);
|
| +}
|
| +
|
| +bool SidebarBaseTabStrip::IsTabSelected(const SidebarBaseTab* tab) {
|
| + if (tab->closing())
|
| + return false;
|
| + int model_index = GetModelIndexOfBaseTab(tab);
|
| + return controller_->IsTabSelected(model_index);
|
| +}
|
| +
|
| +bool SidebarBaseTabStrip::IsSidebarExpanded() {
|
| + return controller_->IsSidebarExpanded();
|
| +}
|
| +
|
| +bool SidebarBaseTabStrip::IsAnimating() const {
|
| + return bounds_animator_.IsAnimating();
|
| +}
|
| +
|
| +void SidebarBaseTabStrip::AddTabAt(int model_index,
|
| + bool animate,
|
| + const SidebarTabRendererData& data) {
|
| + SidebarBaseTab* tab = CreateTab();
|
| + tab->SetData(data);
|
| +
|
| + TabData d = { tab, gfx::Rect() };
|
| + tab_data_.insert(tab_data_.begin() + ModelIndexToTabIndex(model_index), d);
|
| +
|
| + AddChildView(tab);
|
| +
|
| + tab->Layout();
|
| +
|
| + if (animate) {
|
| + // 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 && GetWindow() && GetWindow()->IsVisible())
|
| + StartInsertTabAnimation(model_index);
|
| + else
|
| + SetToIdealBounds();
|
| + }
|
| +}
|
| +
|
| +void SidebarBaseTabStrip::RemoveTabAt(int model_index, bool animate) {
|
| + if (animate) {
|
| + if (tab_count() > 1) {
|
| + // Have to do it before calling set_closing(), otherwise model_index
|
| + // to tab_data_index mapping will miss this tab.
|
| + StartRemoveTabAnimation(model_index);
|
| + } else {
|
| + // Do not animate the last tab removal, do it right away.
|
| + GetBaseTabAtModelIndex(model_index)->set_closing(true);
|
| + SetToIdealBounds();
|
| + }
|
| + } else {
|
| + GetBaseTabAtModelIndex(model_index)->set_closing(true);
|
| + }
|
| +}
|
| +
|
| +void SidebarBaseTabStrip::SelectTabAt(int new_model_index) {
|
| + SchedulePaint();
|
| +}
|
| +
|
| +void SidebarBaseTabStrip::SetTabData(int model_index,
|
| + const SidebarTabRendererData& data) {
|
| + SidebarBaseTab* tab = GetBaseTabAtModelIndex(model_index);
|
| + tab->SetData(data);
|
| + tab->SchedulePaint();
|
| +}
|
| +
|
| +SidebarBaseTab* SidebarBaseTabStrip::GetBaseTabAtModelIndex(
|
| + int model_index) const {
|
| + return base_tab_at_tab_index(ModelIndexToTabIndex(model_index));
|
| +}
|
| +
|
| +int SidebarBaseTabStrip::GetModelIndexOfBaseTab(
|
| + const SidebarBaseTab* tab) const {
|
| + for (int i = 0, model_index = 0; i < tab_count(); ++i) {
|
| + SidebarBaseTab* current_tab = base_tab_at_tab_index(i);
|
| + if (!current_tab->closing()) {
|
| + if (current_tab == tab)
|
| + return model_index;
|
| + ++model_index;
|
| + }
|
| + }
|
| + return -1;
|
| +}
|
| +
|
| +int SidebarBaseTabStrip::ModelIndexToTabIndex(int model_index) const {
|
| + int current_model_index = 0;
|
| + for (int i = 0; i < tab_count(); ++i) {
|
| + if (!base_tab_at_tab_index(i)->closing()) {
|
| + if (current_model_index == model_index)
|
| + return i;
|
| + ++current_model_index;
|
| + }
|
| + }
|
| + return static_cast<int>(tab_data_.size());
|
| +}
|
| +
|
| +void SidebarBaseTabStrip::SetToIdealBounds() {
|
| + StopAnimating();
|
| +
|
| + RemoveClosingTabs();
|
| +
|
| + GenerateIdealBounds();
|
| +
|
| + // Move all tabs to their planned positions.
|
| + for (int i = 0; i < tab_count(); ++i)
|
| + base_tab_at_tab_index(i)->SetBoundsRect(ideal_bounds(i));
|
| +
|
| + UpdateViewBounds();
|
| +
|
| + SchedulePaint();
|
| +}
|
| +
|
| +void SidebarBaseTabStrip::AnimateToIdealBounds() {
|
| + for (int i = 0; i < tab_count(); ++i) {
|
| + SidebarBaseTab* tab = base_tab_at_tab_index(i);
|
| + if (tab->bounds() != ideal_bounds(i))
|
| + bounds_animator_.AnimateViewTo(tab, ideal_bounds(i));
|
| + }
|
| +}
|
| +
|
| +void SidebarBaseTabStrip::StopAnimating() {
|
| + if (!IsAnimating())
|
| + return;
|
| +
|
| + bounds_animator_.Cancel();
|
| +
|
| + DCHECK(!IsAnimating());
|
| +}
|
| +
|
| +void SidebarBaseTabStrip::UpdateViewBounds() {
|
| + int width = 0;
|
| + int height = 0;
|
| + for (int i = 0; i < tab_count(); ++i) {
|
| + const gfx::Rect& bounds = base_tab_at_tab_index(i)->bounds();
|
| + width = std::max(width, bounds.x() + bounds.width());
|
| + height = std::max(height, bounds.y() + bounds.height());
|
| + }
|
| + SetBounds(x(), y(), width, height);
|
| +}
|
| +
|
| +void SidebarBaseTabStrip::OnBoundsAnimatorProgressed(
|
| + views::BoundsAnimator* animator) {
|
| + UpdateViewBounds();
|
| +}
|
| +
|
| +void SidebarBaseTabStrip::OnBoundsAnimatorDone(
|
| + views::BoundsAnimator* animator) {
|
| + RemoveClosingTabs();
|
| +}
|
| +
|
| +void SidebarBaseTabStrip::RemoveAndDeleteTab(int tab_data_index) {
|
| + SidebarBaseTab* tab = base_tab_at_tab_index(tab_data_index);
|
| +
|
| + // Remove the tab from the SidebarTabStrip's list.
|
| + tab_data_.erase(tab_data_.begin() + tab_data_index);
|
| +
|
| + delete tab;
|
| +}
|
| +
|
| +void SidebarBaseTabStrip::RemoveClosingTabs() {
|
| + for (int i = tab_count() - 1; i >= 0; --i) {
|
| + SidebarBaseTab* tab = base_tab_at_tab_index(i);
|
| + if (tab->closing())
|
| + RemoveAndDeleteTab(i);
|
| + }
|
| +}
|
| +
|
|
|
| Property changes on: chrome\browser\ui\views\sidebar\sidebar_base_tab_strip.cc
|
| ___________________________________________________________________
|
| Added: svn:eol-style
|
| + LF
|
|
|
|
|