diff options
21 files changed, 337 insertions, 198 deletions
diff --git a/chrome/browser/views/frame/browser_frame.h b/chrome/browser/views/frame/browser_frame.h index 4e09619..ca8ae7c 100644 --- a/chrome/browser/views/frame/browser_frame.h +++ b/chrome/browser/views/frame/browser_frame.h @@ -10,7 +10,7 @@ class BrowserView; class Profile; -class TabStrip; +class TabStripWrapper; class ThemeProvider; namespace gfx { @@ -40,7 +40,7 @@ class BrowserFrame { // Notification that the tab strip has been created. This should let the // BrowserRootView know about it so it can enable drag and drop. - virtual void TabStripCreated(TabStrip* tabstrip) = 0; + virtual void TabStripCreated(TabStripWrapper* tabstrip) = 0; // Determine the distance of the left edge of the minimize button from the // left edge of the window. Used in our Non-Client View's Layout. @@ -48,7 +48,7 @@ class BrowserFrame { // Retrieves the bounds, in non-client view coordinates for the specified // TabStrip. - virtual gfx::Rect GetBoundsForTabStrip(TabStrip* tabstrip) const = 0; + virtual gfx::Rect GetBoundsForTabStrip(TabStripWrapper* tabstrip) const = 0; // Tells the frame to update the throbber. virtual void UpdateThrobber(bool running) = 0; diff --git a/chrome/browser/views/frame/browser_frame_gtk.cc b/chrome/browser/views/frame/browser_frame_gtk.cc index c3686b2..00486d7 100644 --- a/chrome/browser/views/frame/browser_frame_gtk.cc +++ b/chrome/browser/views/frame/browser_frame_gtk.cc @@ -42,7 +42,7 @@ views::Window* BrowserFrameGtk::GetWindow() { return this; } -void BrowserFrameGtk::TabStripCreated(TabStrip* tabstrip) { +void BrowserFrameGtk::TabStripCreated(TabStripWrapper* tabstrip) { root_view_->set_tabstrip(tabstrip); } @@ -51,7 +51,7 @@ int BrowserFrameGtk::GetMinimizeButtonOffset() const { return 0; } -gfx::Rect BrowserFrameGtk::GetBoundsForTabStrip(TabStrip* tabstrip) const { +gfx::Rect BrowserFrameGtk::GetBoundsForTabStrip(TabStripWrapper* tabstrip) const { return browser_frame_view_->GetBoundsForTabStrip(tabstrip); } diff --git a/chrome/browser/views/frame/browser_frame_gtk.h b/chrome/browser/views/frame/browser_frame_gtk.h index 4d0f068..78e9d53 100644 --- a/chrome/browser/views/frame/browser_frame_gtk.h +++ b/chrome/browser/views/frame/browser_frame_gtk.h @@ -26,9 +26,9 @@ class BrowserFrameGtk : public BrowserFrame, // BrowserFrame implementation. virtual views::Window* GetWindow(); - virtual void TabStripCreated(TabStrip* tabstrip); + virtual void TabStripCreated(TabStripWrapper* tabstrip); virtual int GetMinimizeButtonOffset() const; - virtual gfx::Rect GetBoundsForTabStrip(TabStrip* tabstrip) const; + virtual gfx::Rect GetBoundsForTabStrip(TabStripWrapper* tabstrip) const; virtual void UpdateThrobber(bool running); virtual void ContinueDraggingDetachedTab(); virtual ThemeProvider* GetThemeProviderForFrame() const; diff --git a/chrome/browser/views/frame/browser_frame_win.cc b/chrome/browser/views/frame/browser_frame_win.cc index 2f00e20..7543f87 100644 --- a/chrome/browser/views/frame/browser_frame_win.cc +++ b/chrome/browser/views/frame/browser_frame_win.cc @@ -64,7 +64,7 @@ views::Window* BrowserFrameWin::GetWindow() { return this; } -void BrowserFrameWin::TabStripCreated(TabStrip* tabstrip) { +void BrowserFrameWin::TabStripCreated(TabStripWrapper* tabstrip) { root_view_->set_tabstrip(tabstrip); } @@ -80,7 +80,7 @@ int BrowserFrameWin::GetMinimizeButtonOffset() const { return minimize_button_corner.x; } -gfx::Rect BrowserFrameWin::GetBoundsForTabStrip(TabStrip* tabstrip) const { +gfx::Rect BrowserFrameWin::GetBoundsForTabStrip(TabStripWrapper* tabstrip) const { return browser_frame_view_->GetBoundsForTabStrip(tabstrip); } @@ -139,12 +139,12 @@ void BrowserFrameWin::OnExitSizeMove() { detached_drag_mode_ = false; if (drop_tabstrip_) { gfx::Point screen_point = views::Screen::GetCursorScreenPoint(); - BrowserTabStrip* tabstrip = browser_view_->bts(); + BrowserTabStrip* tabstrip = browser_view_->tabstrip()->AsBrowserTabStrip(); gfx::Rect tsb = tabstrip->GetDraggedTabScreenBounds(screen_point); drop_tabstrip_->AttachTab(tabstrip->DetachTab(0), screen_point, tsb); } else { UpdateWindowAlphaForTabDragging(detached_drag_mode_); - browser_view_->bts()->SendDraggedTabHome(); + browser_view_->tabstrip()->AsBrowserTabStrip()->SendDraggedTabHome(); } } } @@ -278,8 +278,9 @@ void BrowserFrameWin::OnWindowPosChanged(WINDOWPOS* window_pos) { HWND local_window = DockInfo::GetLocalProcessWindowAtPoint(screen_point, ignore_windows); if (local_window) { - drop_tabstrip_ = - BrowserView::GetBrowserViewForNativeWindow(local_window)->bts(); + BrowserView* browser_view = + BrowserView::GetBrowserViewForNativeWindow(local_window); + drop_tabstrip_ = browser_view->tabstrip()->AsBrowserTabStrip(); if (TabStrip2::IsDragRearrange(drop_tabstrip_, screen_point)) { ReleaseCapture(); return; diff --git a/chrome/browser/views/frame/browser_frame_win.h b/chrome/browser/views/frame/browser_frame_win.h index a355019..5ad12a4 100644 --- a/chrome/browser/views/frame/browser_frame_win.h +++ b/chrome/browser/views/frame/browser_frame_win.h @@ -16,7 +16,6 @@ class BrowserTabStrip; class BrowserView; class NonClientFrameView; class Profile; -class TabStrip; /////////////////////////////////////////////////////////////////////////////// // BrowserFrameWin @@ -37,9 +36,9 @@ class BrowserFrameWin : public BrowserFrame, public views::WindowWin { // BrowserFrame implementation. virtual views::Window* GetWindow(); - virtual void TabStripCreated(TabStrip* tabstrip); + virtual void TabStripCreated(TabStripWrapper* tabstrip); virtual int GetMinimizeButtonOffset() const; - virtual gfx::Rect GetBoundsForTabStrip(TabStrip* tabstrip) const; + virtual gfx::Rect GetBoundsForTabStrip(TabStripWrapper* tabstrip) const; virtual void UpdateThrobber(bool running); virtual void ContinueDraggingDetachedTab(); virtual ThemeProvider* GetThemeProviderForFrame() const; diff --git a/chrome/browser/views/frame/browser_non_client_frame_view.h b/chrome/browser/views/frame/browser_non_client_frame_view.h index 5b87d9e..04a9bf4 100644 --- a/chrome/browser/views/frame/browser_non_client_frame_view.h +++ b/chrome/browser/views/frame/browser_non_client_frame_view.h @@ -7,7 +7,7 @@ #include "views/window/non_client_view.h" -class TabStrip; +class TabStripWrapper; // A specialization of the NonClientFrameView object that provides additional // Browser-specific methods. @@ -17,7 +17,7 @@ class BrowserNonClientFrameView : public views::NonClientFrameView { virtual ~BrowserNonClientFrameView() {} // Returns the bounds within which the TabStrip should be laid out. - virtual gfx::Rect GetBoundsForTabStrip(TabStrip* tabstrip) const = 0; + virtual gfx::Rect GetBoundsForTabStrip(TabStripWrapper* tabstrip) const = 0; // Updates the throbber. virtual void UpdateThrobber(bool running) = 0; diff --git a/chrome/browser/views/frame/browser_root_view.cc b/chrome/browser/views/frame/browser_root_view.cc index 86c919c..5e471c6 100644 --- a/chrome/browser/views/frame/browser_root_view.cc +++ b/chrome/browser/views/frame/browser_root_view.cc @@ -8,7 +8,7 @@ #include "app/os_exchange_data.h" #include "chrome/browser/views/frame/browser_view.h" #include "chrome/browser/views/frame/browser_frame.h" -#include "chrome/browser/views/tabs/tab_strip.h" +#include "chrome/browser/views/tabs/tab_strip_wrapper.h" BrowserRootView::BrowserRootView(views::Widget* widget) : views::RootView(widget), @@ -18,7 +18,7 @@ BrowserRootView::BrowserRootView(views::Widget* widget) } bool BrowserRootView::CanDrop(const OSExchangeData& data) { - can_drop_ = (tabstrip_ && tabstrip_->IsVisible() && + can_drop_ = (tabstrip_ && tabstrip_->GetView()->IsVisible() && !tabstrip_->IsAnimating() && data.HasURL()); return can_drop_; } @@ -27,7 +27,7 @@ void BrowserRootView::OnDragEntered(const views::DropTargetEvent& event) { if (can_drop_ && ShouldForwardToTabStrip(event)) { forwarding_to_tab_strip_ = true; scoped_ptr<views::DropTargetEvent> mapped_event(MapEventToTabStrip(event)); - tabstrip_->OnDragEntered(*mapped_event.get()); + tabstrip_->GetView()->OnDragEntered(*mapped_event.get()); } } @@ -37,13 +37,13 @@ int BrowserRootView::OnDragUpdated(const views::DropTargetEvent& event) { scoped_ptr<views::DropTargetEvent> mapped_event( MapEventToTabStrip(event)); if (!forwarding_to_tab_strip_) { - tabstrip_->OnDragEntered(*mapped_event.get()); + tabstrip_->GetView()->OnDragEntered(*mapped_event.get()); forwarding_to_tab_strip_ = true; } - return tabstrip_->OnDragUpdated(*mapped_event.get()); + return tabstrip_->GetView()->OnDragUpdated(*mapped_event.get()); } else if (forwarding_to_tab_strip_) { forwarding_to_tab_strip_ = false; - tabstrip_->OnDragExited(); + tabstrip_->GetView()->OnDragExited(); } } return DragDropTypes::DRAG_NONE; @@ -52,7 +52,7 @@ int BrowserRootView::OnDragUpdated(const views::DropTargetEvent& event) { void BrowserRootView::OnDragExited() { if (forwarding_to_tab_strip_) { forwarding_to_tab_strip_ = false; - tabstrip_->OnDragExited(); + tabstrip_->GetView()->OnDragExited(); } } @@ -61,27 +61,27 @@ int BrowserRootView::OnPerformDrop(const views::DropTargetEvent& event) { forwarding_to_tab_strip_ = false; scoped_ptr<views::DropTargetEvent> mapped_event( MapEventToTabStrip(event)); - return tabstrip_->OnPerformDrop(*mapped_event.get()); + return tabstrip_->GetView()->OnPerformDrop(*mapped_event.get()); } return DragDropTypes::DRAG_NONE; } bool BrowserRootView::ShouldForwardToTabStrip( const views::DropTargetEvent& event) { - if (!tabstrip_->IsVisible()) + if (!tabstrip_->GetView()->IsVisible()) return false; // Allow the drop as long as the mouse is over the tabstrip or vertically // before it. gfx::Point tab_loc_in_host; - ConvertPointToView(tabstrip_, this, &tab_loc_in_host); - return event.y() < tab_loc_in_host.y() + tabstrip_->height(); + ConvertPointToView(tabstrip_->GetView(), this, &tab_loc_in_host); + return event.y() < tab_loc_in_host.y() + tabstrip_->GetView()->height(); } views::DropTargetEvent* BrowserRootView::MapEventToTabStrip( const views::DropTargetEvent& event) { gfx::Point tab_strip_loc(event.location()); - ConvertPointToView(this, tabstrip_, &tab_strip_loc); + ConvertPointToView(this, tabstrip_->GetView(), &tab_strip_loc); return new views::DropTargetEvent(event.GetData(), tab_strip_loc.x(), tab_strip_loc.y(), event.GetSourceOperations()); diff --git a/chrome/browser/views/frame/browser_root_view.h b/chrome/browser/views/frame/browser_root_view.h index a5a2e39f..370ef5f 100644 --- a/chrome/browser/views/frame/browser_root_view.h +++ b/chrome/browser/views/frame/browser_root_view.h @@ -8,7 +8,7 @@ #include "views/widget/root_view.h" class OSExchangeData; -class TabStrip; +class TabStripWrapper; // RootView implementation used by BrowserFrame. This forwards drop events to // the TabStrip. Visually the tabstrip extends to the top of the frame, but in @@ -23,7 +23,7 @@ class BrowserRootView : public views::RootView { // Sets the tabstrip associated with this window. This is used to forward // drag and drop operations to, so no drops will be accepted if there is no // tabstrip set. - void set_tabstrip(TabStrip* tabstrip) { tabstrip_ = tabstrip; } + void set_tabstrip(TabStripWrapper* tabstrip) { tabstrip_ = tabstrip; } virtual bool CanDrop(const OSExchangeData& data); virtual void OnDragEntered(const views::DropTargetEvent& event); @@ -41,7 +41,7 @@ class BrowserRootView : public views::RootView { const views::DropTargetEvent& event); // The TabStrip. - TabStrip* tabstrip_; + TabStripWrapper* tabstrip_; // Is a drop allowed? This is set by CanDrop. bool can_drop_; diff --git a/chrome/browser/views/frame/browser_view.cc b/chrome/browser/views/frame/browser_view.cc index 90b4f23..becc26a 100644 --- a/chrome/browser/views/frame/browser_view.cc +++ b/chrome/browser/views/frame/browser_view.cc @@ -431,10 +431,8 @@ int BrowserView::GetTabStripHeight() const { // We want to return tabstrip_->height(), but we might be called in the midst // of layout, when that hasn't yet been updated to reflect the current state. // So return what the tabstrip height _ought_ to be right now. - views::View* tabstrip = - TabStrip2::Enabled() ? static_cast<views::View*>(bts_) - : static_cast<views::View*>(tabstrip_); - return IsTabStripVisible() ? tabstrip->GetPreferredSize().height() : 0; + return IsTabStripVisible() ? tabstrip_->GetView()->GetPreferredSize().height() + : 0; } gfx::Rect BrowserView::GetTabStripBounds() const { @@ -945,8 +943,7 @@ void BrowserView::ShowHTMLDialog(HtmlDialogUIDelegate* delegate, } void BrowserView::ContinueDraggingDetachedTab(const gfx::Rect& tab_bounds) { - DCHECK(TabStrip2::Enabled()); - bts_->SetDraggedTabBounds(0, tab_bounds); + tabstrip_->SetDraggedTabBounds(0, tab_bounds); frame_->ContinueDraggingDetachedTab(); } @@ -1228,7 +1225,7 @@ views::ClientView* BrowserView::CreateClientView(views::Window* window) { bool BrowserView::CanClose() const { // You cannot close a frame for which there is an active originating drag // session. - if (!TabStrip2::Enabled() && tabstrip_->IsDragSessionActive()) + if (tabstrip_->IsDragSessionActive()) return false; // Give beforeunload handlers the chance to cancel the close before we hide @@ -1286,21 +1283,21 @@ int BrowserView::NonClientHitTest(const gfx::Point& point) { View::ConvertPointToView(GetParent(), this, &point_in_view_coords); // See if the mouse pointer is within the bounds of the TabStrip. - if (!TabStrip2::Enabled()) { - gfx::Point point_in_tabstrip_coords(point); - View::ConvertPointToView(GetParent(), tabstrip_, &point_in_tabstrip_coords); - if (tabstrip_->HitTest(point_in_tabstrip_coords)) { - if (tabstrip_->PointIsWithinWindowCaption(point_in_tabstrip_coords)) - return HTCAPTION; - return HTCLIENT; - } + gfx::Point point_in_tabstrip_coords(point); + View::ConvertPointToView(GetParent(), tabstrip_->GetView(), + &point_in_tabstrip_coords); + if (tabstrip_->GetView()->HitTest(point_in_tabstrip_coords)) { + if (tabstrip_->PointIsWithinWindowCaption(point_in_tabstrip_coords)) + return HTCAPTION; + return HTCLIENT; } // The top few pixels of the TabStrip are a drop-shadow - as we're pretty // starved of dragable area, let's give it to window dragging (this also // makes sense visually). - if (!TabStrip2::Enabled() && !IsMaximized() && - (point_in_view_coords.y() < tabstrip_->y() + kTabShadowSize)) { + if (!IsMaximized() && + (point_in_view_coords.y() < + (tabstrip_->GetView()->y() + kTabShadowSize))) { // We return HTNOWHERE as this is a signal to our containing // NonClientView that it should figure out what the correct hit-test // code is given the mouse position... @@ -1312,13 +1309,8 @@ int BrowserView::NonClientHitTest(const gfx::Point& point) { // within the bounds of this view, the point is considered to be within the // client area. gfx::Rect bv_bounds = bounds(); - if (TabStrip2::Enabled()) { - bv_bounds.Offset(0, bts_->y()); - bv_bounds.set_height(bv_bounds.height() - bts_->y()); - } else { - bv_bounds.Offset(0, toolbar_->y()); - bv_bounds.set_height(bv_bounds.height() - toolbar_->y()); - } + bv_bounds.Offset(0, toolbar_->y()); + bv_bounds.set_height(bv_bounds.height() - toolbar_->y()); if (bv_bounds.Contains(point)) return HTCLIENT; @@ -1342,14 +1334,11 @@ int BrowserView::NonClientHitTest(const gfx::Point& point) { } gfx::Size BrowserView::GetMinimumSize() { - views::View* tabstrip = - TabStrip2::Enabled() ? static_cast<views::View*>(bts_) - : static_cast<views::View*>(tabstrip_); // TODO(noname): In theory the tabstrip width should probably be // (OTR + tabstrip + caption buttons) width. gfx::Size tabstrip_size( browser_->SupportsWindowFeature(Browser::FEATURE_TABSTRIP) ? - tabstrip->GetMinimumSize() : gfx::Size()); + tabstrip_->GetView()->GetMinimumSize() : gfx::Size()); gfx::Size toolbar_size( (browser_->SupportsWindowFeature(Browser::FEATURE_TOOLBAR) || browser_->SupportsWindowFeature(Browser::FEATURE_LOCATIONBAR)) ? @@ -1438,16 +1427,10 @@ void BrowserView::Init() { LoadAccelerators(); SetAccessibleName(l10n_util::GetString(IDS_PRODUCT_NAME)); - if (TabStrip2::Enabled()) { - bts_ = new BrowserTabStrip(browser_->tabstrip_model()); - AddChildView(bts_); - } else { - tabstrip_ = new TabStrip(browser_->tabstrip_model()); - tabstrip_->SetAccessibleName(l10n_util::GetString(IDS_ACCNAME_TABSTRIP)); - AddChildView(tabstrip_); - tabstrip_->InitTabStripButtons(); - frame_->TabStripCreated(tabstrip_); - } + tabstrip_ = TabStripWrapper::CreateTabStrip(browser_->tabstrip_model()); + tabstrip_->GetView()->SetAccessibleName(l10n_util::GetString(IDS_ACCNAME_TABSTRIP)); + AddChildView(tabstrip_->GetView()); + frame_->TabStripCreated(tabstrip_); toolbar_ = new ToolbarView(browser_.get()); AddChildView(toolbar_); @@ -1496,14 +1479,9 @@ void BrowserView::InitSystemMenu() { int BrowserView::LayoutTabStrip() { gfx::Rect tabstrip_bounds; - if (TabStrip2::Enabled()) { - tabstrip_bounds = gfx::Rect(0, 0, width(), - bts_->GetPreferredSize().height()); - } else { - tabstrip_bounds = frame_->GetBoundsForTabStrip(tabstrip_); - tabstrip_->SetBackgroundOffset( - gfx::Point(tabstrip_bounds.x(), tabstrip_bounds.y())); - } + tabstrip_bounds = frame_->GetBoundsForTabStrip(tabstrip_); + tabstrip_->SetBackgroundOffset( + gfx::Point(tabstrip_bounds.x(), tabstrip_bounds.y())); gfx::Point tabstrip_origin = tabstrip_bounds.origin(); ConvertPointToView(GetParent(), this, &tabstrip_origin); tabstrip_bounds.set_origin(tabstrip_origin); @@ -1511,13 +1489,9 @@ int BrowserView::LayoutTabStrip() { int y = visible ? tabstrip_bounds.y() : 0; int height = visible ? tabstrip_bounds.height() : 0; int bottom = y + height; - if (TabStrip2::Enabled()) { - gfx::Size btsps = bts_->GetPreferredSize(); - bts_->SetBounds(tabstrip_bounds.x(), y, width(), btsps.height()); - } else { - tabstrip_->SetVisible(visible); - tabstrip_->SetBounds(tabstrip_bounds.x(), y, tabstrip_bounds.width(), height); - } + tabstrip_->GetView()->SetVisible(visible); + tabstrip_->GetView()->SetBounds(tabstrip_bounds.x(), y, + tabstrip_bounds.width(), height); return bottom; } @@ -1834,8 +1808,7 @@ void BrowserView::LoadingAnimationCallback() { // will return false for fullscreen windows, but we still need to update // their animations (so that when they come out of fullscreen mode they'll // be correct). - if (!TabStrip2::Enabled()) - tabstrip_->UpdateLoadingAnimations(); + tabstrip_->UpdateLoadingAnimations(); } else if (ShouldShowWindowIcon()) { // ... or in the window icon area for popups and app windows. TabContents* tab_contents = browser_->GetSelectedTabContents(); diff --git a/chrome/browser/views/frame/browser_view.h b/chrome/browser/views/frame/browser_view.h index c3b48a9..3aaf547 100644 --- a/chrome/browser/views/frame/browser_view.h +++ b/chrome/browser/views/frame/browser_view.h @@ -31,7 +31,6 @@ class BookmarkBarView; class Browser; class BrowserBubble; -class BrowserTabStrip; class DownloadShelfView; class EncodingMenuModel; class ExtensionShelf; @@ -41,7 +40,7 @@ class InfoBarContainer; class LocationBarView; class StatusBubbleViews; class TabContentsContainer; -class TabStrip; +class TabStripWrapper; class ToolbarView; class ZoomMenuModel; @@ -121,8 +120,7 @@ class BrowserView : public BrowserWindow, gfx::Rect GetTabStripBounds() const; // Accessor for the TabStrip. - TabStrip* tabstrip() const { return tabstrip_; } - BrowserTabStrip* bts() const { return bts_; } + TabStripWrapper* tabstrip() const { return tabstrip_; } // Accessor for the ExtensionShelf. ExtensionShelf* extension_shelf() const { return extension_shelf_; } @@ -396,10 +394,7 @@ class BrowserView : public BrowserWindow, views::View* active_bookmark_bar_; // The TabStrip. - TabStrip* tabstrip_; - - // The BrowserTabStrip. - BrowserTabStrip* bts_; + TabStripWrapper* tabstrip_; // The Toolbar containing the navigation buttons, menus and the address bar. ToolbarView* toolbar_; diff --git a/chrome/browser/views/frame/glass_browser_frame_view.cc b/chrome/browser/views/frame/glass_browser_frame_view.cc index 48c1695..d7c8139 100644 --- a/chrome/browser/views/frame/glass_browser_frame_view.cc +++ b/chrome/browser/views/frame/glass_browser_frame_view.cc @@ -9,7 +9,7 @@ #include "app/theme_provider.h" #include "chrome/browser/browser_theme_provider.h" #include "chrome/browser/views/frame/browser_view.h" -#include "chrome/browser/views/tabs/tab_strip.h" +#include "chrome/browser/views/tabs/tab_strip_wrapper.h" #include "grit/app_resources.h" #include "grit/theme_resources.h" #include "views/window/client_view.h" @@ -79,7 +79,7 @@ GlassBrowserFrameView::~GlassBrowserFrameView() { // GlassBrowserFrameView, BrowserNonClientFrameView implementation: gfx::Rect GlassBrowserFrameView::GetBoundsForTabStrip( - TabStrip* tabstrip) const { + TabStripWrapper* tabstrip) const { int minimize_button_offset = frame_->GetMinimizeButtonOffset(); int tabstrip_x = browser_view_->ShouldShowOffTheRecordAvatar() ? (otr_avatar_bounds_.right() + kOTRSideSpacing) : @@ -95,7 +95,8 @@ gfx::Rect GlassBrowserFrameView::GetBoundsForTabStrip( if (UILayoutIsRightToLeft()) tabstrip_width += tabstrip_x; return gfx::Rect(tabstrip_x, NonClientTopBorderHeight(), - std::max(0, tabstrip_width), tabstrip->GetPreferredHeight()); + std::max(0, tabstrip_width), + tabstrip->GetPreferredHeight()); } void GlassBrowserFrameView::UpdateThrobber(bool running) { diff --git a/chrome/browser/views/frame/glass_browser_frame_view.h b/chrome/browser/views/frame/glass_browser_frame_view.h index 3700ff1..81e5000 100644 --- a/chrome/browser/views/frame/glass_browser_frame_view.h +++ b/chrome/browser/views/frame/glass_browser_frame_view.h @@ -20,7 +20,7 @@ class GlassBrowserFrameView : public BrowserNonClientFrameView { virtual ~GlassBrowserFrameView(); // Overridden from BrowserNonClientFrameView: - virtual gfx::Rect GetBoundsForTabStrip(TabStrip* tabstrip) const; + virtual gfx::Rect GetBoundsForTabStrip(TabStripWrapper* tabstrip) const; virtual void UpdateThrobber(bool running); // Overridden from views::NonClientFrameView: diff --git a/chrome/browser/views/frame/opaque_browser_frame_view.cc b/chrome/browser/views/frame/opaque_browser_frame_view.cc index 5c941bd..2d74f05 100644 --- a/chrome/browser/views/frame/opaque_browser_frame_view.cc +++ b/chrome/browser/views/frame/opaque_browser_frame_view.cc @@ -14,7 +14,7 @@ #include "chrome/browser/tab_contents/tab_contents.h" #include "chrome/browser/views/frame/browser_frame.h" #include "chrome/browser/views/frame/browser_view.h" -#include "chrome/browser/views/tabs/tab_strip.h" +#include "chrome/browser/views/tabs/tab_strip_wrapper.h" #include "grit/app_resources.h" #include "grit/chromium_strings.h" #include "grit/generated_resources.h" @@ -200,7 +200,7 @@ OpaqueBrowserFrameView::~OpaqueBrowserFrameView() { // OpaqueBrowserFrameView, BrowserNonClientFrameView implementation: gfx::Rect OpaqueBrowserFrameView::GetBoundsForTabStrip( - TabStrip* tabstrip) const { + TabStripWrapper* tabstrip) const { int tabstrip_x = browser_view_->ShouldShowOffTheRecordAvatar() ? (otr_avatar_bounds_.right() + kOTRSideSpacing) : NonClientBorderThickness(); @@ -208,7 +208,8 @@ gfx::Rect OpaqueBrowserFrameView::GetBoundsForTabStrip( (frame_->GetWindow()->IsMaximized() ? kNewTabCaptionMaximizedSpacing : kNewTabCaptionRestoredSpacing); return gfx::Rect(tabstrip_x, NonClientTopBorderHeight(), - std::max(0, tabstrip_width), tabstrip->GetPreferredHeight()); + std::max(0, tabstrip_width), + tabstrip->GetPreferredHeight()); } void OpaqueBrowserFrameView::UpdateThrobber(bool running) { @@ -366,14 +367,14 @@ bool OpaqueBrowserFrameView::HitTest(const gfx::Point& l) const { return in_nonclient; // Otherwise claim it only if it's in a non-tab portion of the tabstrip. - if (l.y() > browser_view_->tabstrip()->bounds().bottom()) + if (l.y() > browser_view_->tabstrip()->GetView()->bounds().bottom()) return false; // We convert from our parent's coordinates since we assume we fill its bounds // completely. We need to do this since we're not a parent of the tabstrip, // meaning ConvertPointToView would otherwise return something bogus. gfx::Point tabstrip_point(l); - View::ConvertPointToView(GetParent(), browser_view_->tabstrip(), + View::ConvertPointToView(GetParent(), browser_view_->tabstrip()->GetView(), &tabstrip_point); return browser_view_->tabstrip()->PointIsWithinWindowCaption(tabstrip_point); } diff --git a/chrome/browser/views/frame/opaque_browser_frame_view.h b/chrome/browser/views/frame/opaque_browser_frame_view.h index 4345d8c..3f71560 100644 --- a/chrome/browser/views/frame/opaque_browser_frame_view.h +++ b/chrome/browser/views/frame/opaque_browser_frame_view.h @@ -32,7 +32,7 @@ class OpaqueBrowserFrameView : public BrowserNonClientFrameView, virtual ~OpaqueBrowserFrameView(); // Overridden from BrowserNonClientFrameView: - virtual gfx::Rect GetBoundsForTabStrip(TabStrip* tabstrip) const; + virtual gfx::Rect GetBoundsForTabStrip(TabStripWrapper* tabstrip) const; virtual void UpdateThrobber(bool running); virtual gfx::Size GetMinimumSize(); diff --git a/chrome/browser/views/tabs/browser_tab_strip.cc b/chrome/browser/views/tabs/browser_tab_strip.cc index 489b97a..b256e5c 100644 --- a/chrome/browser/views/tabs/browser_tab_strip.cc +++ b/chrome/browser/views/tabs/browser_tab_strip.cc @@ -6,6 +6,7 @@ #include "base/compiler_specific.h" #include "chrome/browser/tab_contents/tab_contents.h" +#include "chrome/browser/views/tabs/tab_strip.h" // for CreateTabStrip only. namespace { @@ -147,3 +148,60 @@ void BrowserTabStrip::DetachTabAt(int index, const gfx::Rect& window_bounds, model_->delegate()->ContinueDraggingDetachedTab(contents, window_bounds, tab_bounds); } + +//////////////////////////////////////////////////////////////////////////////// +// BrowserTabStrip, TabStripWrapper implementation: + +int BrowserTabStrip::GetPreferredHeight() { + return GetPreferredSize().height(); +} + +bool BrowserTabStrip::IsAnimating() const { + return false; +} + +void BrowserTabStrip::SetBackgroundOffset(gfx::Point offset) { +} + +bool BrowserTabStrip::PointIsWithinWindowCaption( + const gfx::Point& point) { + return false; +} + +bool BrowserTabStrip::IsDragSessionActive() const { + return false; +} + +bool BrowserTabStrip::IsCompatibleWith(TabStripWrapper* other) const { + return false; +} + +void BrowserTabStrip::SetDraggedTabBounds(int tab_index, + const gfx::Rect& tab_bounds) { + TabStrip2::SetDraggedTabBounds(tab_index, tab_bounds); +} + +void BrowserTabStrip::UpdateLoadingAnimations() { +} + +views::View* BrowserTabStrip::GetView() { + return this; +} + +BrowserTabStrip* BrowserTabStrip::AsBrowserTabStrip() { + return this; +} + +TabStrip* BrowserTabStrip::AsTabStrip() { + return NULL; +} + +//////////////////////////////////////////////////////////////////////////////// +// TabStripWrapper, public: + +// static +TabStripWrapper* TabStripWrapper::CreateTabStrip(TabStripModel* model) { + if (TabStrip2::Enabled()) + return new BrowserTabStrip(model); + return new TabStrip(model); +} diff --git a/chrome/browser/views/tabs/browser_tab_strip.h b/chrome/browser/views/tabs/browser_tab_strip.h index f88de2d..c1343c864 100644 --- a/chrome/browser/views/tabs/browser_tab_strip.h +++ b/chrome/browser/views/tabs/browser_tab_strip.h @@ -14,7 +14,8 @@ // one. class BrowserTabStrip : public TabStrip2, public TabStrip2Model, - public TabStripModelObserver { + public TabStripModelObserver, + public TabStripWrapper { public: explicit BrowserTabStrip(TabStripModel* model); virtual ~BrowserTabStrip(); @@ -49,6 +50,20 @@ class BrowserTabStrip : public TabStrip2, const gfx::Rect& window_bounds, const gfx::Rect& tab_bounds); + // Overridden from TabStripWrapper: + virtual int GetPreferredHeight(); + virtual bool IsAnimating() const; + virtual void SetBackgroundOffset(gfx::Point offset); + virtual bool PointIsWithinWindowCaption(const gfx::Point& point); + virtual bool IsDragSessionActive() const; + virtual bool IsCompatibleWith(TabStripWrapper* other) const; + virtual void SetDraggedTabBounds(int tab_index, + const gfx::Rect& tab_bounds); + virtual void UpdateLoadingAnimations(); + virtual views::View* GetView(); + virtual BrowserTabStrip* AsBrowserTabStrip(); + virtual TabStrip* AsTabStrip(); + private: TabStripModel* model_; diff --git a/chrome/browser/views/tabs/dragged_tab_controller.cc b/chrome/browser/views/tabs/dragged_tab_controller.cc index 0052971..9a55152 100644 --- a/chrome/browser/views/tabs/dragged_tab_controller.cc +++ b/chrome/browser/views/tabs/dragged_tab_controller.cc @@ -689,10 +689,10 @@ TabStrip* DraggedTabController::GetTabStripForPoint( if (!browser || !browser->IsBrowserTypeNormal()) return NULL; - TabStrip* other_tabstrip = browser->tabstrip(); + TabStripWrapper* other_tabstrip = browser->tabstrip(); if (!other_tabstrip->IsCompatibleWith(source_tabstrip_)) return NULL; - return GetTabStripIfItContains(other_tabstrip, screen_point); + return GetTabStripIfItContains(other_tabstrip->AsTabStrip(), screen_point); } TabStrip* DraggedTabController::GetTabStripIfItContains( diff --git a/chrome/browser/views/tabs/tab_strip.cc b/chrome/browser/views/tabs/tab_strip.cc index 4c72983..37fdaec 100644 --- a/chrome/browser/views/tabs/tab_strip.cc +++ b/chrome/browser/views/tabs/tab_strip.cc @@ -499,46 +499,10 @@ TabStrip::~TabStrip() { RemoveMessageLoopObserver(); } -int TabStrip::GetPreferredHeight() { - return GetPreferredSize().height(); -} - bool TabStrip::CanProcessInputEvents() const { return !IsAnimating(); } -bool TabStrip::PointIsWithinWindowCaption(const gfx::Point& point) { - views::View* v = GetViewForPoint(point); - - // If there is no control at this location, claim the hit was in the title - // bar to get a move action. - if (v == this) - return true; - - // Check to see if the point is within the non-button parts of the new tab - // button. The button has a non-rectangular shape, so if it's not in the - // visual portions of the button we treat it as a click to the caption. - gfx::Point point_in_newtab_coords(point); - View::ConvertPointToView(this, newtab_button_, &point_in_newtab_coords); - if (newtab_button_->bounds().Contains(point) && - !newtab_button_->HitTest(point_in_newtab_coords)) { - return true; - } - - // All other regions, including the new Tab button, should be considered part - // of the containing Window's client area so that regular events can be - // processed for them. - return false; -} - -bool TabStrip::IsCompatibleWith(TabStrip* other) { - return model_->profile() == other->model()->profile(); -} - -bool TabStrip::IsAnimating() const { - return active_animation_.get() != NULL; -} - void TabStrip::DestroyDragController() { if (IsDragSessionActive()) drag_controller_.reset(NULL); @@ -573,30 +537,6 @@ gfx::Rect TabStrip::GetIdealBounds(int index) { return tab_data_.at(index).ideal_bounds; } -void TabStrip::UpdateLoadingAnimations() { - for (int i = 0, index = 0; i < GetTabCount(); ++i, ++index) { - Tab* current_tab = GetTabAt(i); - if (current_tab->closing()) { - --index; - } else { - TabContents* contents = model_->GetTabContentsAt(index); - if (!contents || !contents->is_loading()) { - current_tab->ValidateLoadingAnimation(Tab::ANIMATION_NONE); - } else if (contents->waiting_for_response()) { - current_tab->ValidateLoadingAnimation(Tab::ANIMATION_WAITING); - } else { - current_tab->ValidateLoadingAnimation(Tab::ANIMATION_LOADING); - } - } - } -} - -void TabStrip::SetBackgroundOffset(gfx::Point offset) { - int tab_count = GetTabCount(); - for (int i = 0; i < tab_count; ++i) - GetTabAt(i)->SetBackgroundOffset(offset); -} - void TabStrip::InitTabStripButtons() { newtab_button_ = new NewTabButton(this); LoadNewTabButtonImage(); @@ -781,6 +721,14 @@ void TabStrip::ThemeChanged() { LoadNewTabButtonImage(); } +void TabStrip::ViewHierarchyChanged(bool is_add, + views::View* parent, + views::View* child) { + if (is_add && child == this) + InitTabStripButtons(); +} + + /////////////////////////////////////////////////////////////////////////////// // TabStrip, TabStripModelObserver implementation: @@ -1083,6 +1031,88 @@ void TabStrip::DidProcessEvent(GdkEvent* event) { } #endif +//////////////////////////////////////////////////////////////////////////////// +// TabStrip, TabStripWrapper implementation: + +int TabStrip::GetPreferredHeight() { + return GetPreferredSize().height(); +} + +bool TabStrip::IsAnimating() const { + return active_animation_.get() != NULL; +} + +void TabStrip::SetBackgroundOffset(gfx::Point offset) { + int tab_count = GetTabCount(); + for (int i = 0; i < tab_count; ++i) + GetTabAt(i)->SetBackgroundOffset(offset); +} + +bool TabStrip::PointIsWithinWindowCaption(const gfx::Point& point) { + views::View* v = GetViewForPoint(point); + + // If there is no control at this location, claim the hit was in the title + // bar to get a move action. + if (v == this) + return true; + + // Check to see if the point is within the non-button parts of the new tab + // button. The button has a non-rectangular shape, so if it's not in the + // visual portions of the button we treat it as a click to the caption. + gfx::Point point_in_newtab_coords(point); + View::ConvertPointToView(this, newtab_button_, &point_in_newtab_coords); + if (newtab_button_->bounds().Contains(point) && + !newtab_button_->HitTest(point_in_newtab_coords)) { + return true; + } + + // All other regions, including the new Tab button, should be considered part + // of the containing Window's client area so that regular events can be + // processed for them. + return false; +} + +bool TabStrip::IsDragSessionActive() const { + return drag_controller_.get() != NULL; +} + +bool TabStrip::IsCompatibleWith(TabStripWrapper* other) const { + return model_->profile() == other->AsTabStrip()->model()->profile(); +} + +void TabStrip::SetDraggedTabBounds(int tab_index, const gfx::Rect& tab_bounds) { +} + +void TabStrip::UpdateLoadingAnimations() { + for (int i = 0, index = 0; i < GetTabCount(); ++i, ++index) { + Tab* current_tab = GetTabAt(i); + if (current_tab->closing()) { + --index; + } else { + TabContents* contents = model_->GetTabContentsAt(index); + if (!contents || !contents->is_loading()) { + current_tab->ValidateLoadingAnimation(Tab::ANIMATION_NONE); + } else if (contents->waiting_for_response()) { + current_tab->ValidateLoadingAnimation(Tab::ANIMATION_WAITING); + } else { + current_tab->ValidateLoadingAnimation(Tab::ANIMATION_LOADING); + } + } + } +} + +views::View* TabStrip::GetView() { + return this; +} + +BrowserTabStrip* TabStrip::AsBrowserTabStrip() { + return NULL; +} + +TabStrip* TabStrip::AsTabStrip() { + return this; +} + /////////////////////////////////////////////////////////////////////////////// // TabStrip, private: diff --git a/chrome/browser/views/tabs/tab_strip.h b/chrome/browser/views/tabs/tab_strip.h index 649e250..0e25248 100644 --- a/chrome/browser/views/tabs/tab_strip.h +++ b/chrome/browser/views/tabs/tab_strip.h @@ -9,6 +9,7 @@ #include "base/message_loop.h" #include "chrome/browser/tabs/tab_strip_model.h" #include "chrome/browser/views/tabs/tab.h" +#include "chrome/browser/views/tabs/tab_strip_wrapper.h" #include "views/controls/button/image_button.h" #include "views/view.h" #if defined(OS_WIN) @@ -40,40 +41,20 @@ class TabStrip : public views::View, public TabStripModelObserver, public Tab::TabDelegate, public views::ButtonListener, - public MessageLoopForUI::Observer { + public MessageLoopForUI::Observer, + public TabStripWrapper { public: TabStrip(TabStripModel* model); virtual ~TabStrip(); - // Returns the preferred height of this TabStrip. This is based on the - // typical height of its constituent tabs. - int GetPreferredHeight(); - // Returns true if the TabStrip can accept input events. This returns false // when the TabStrip is animating to a new state and as such the user should // not be allowed to interact with the TabStrip. bool CanProcessInputEvents() const; - // Returns true if the specified point (in TabStrip coordinates) is within a - // portion of the TabStrip that should be treated as the containing Window's - // titlebar for dragging purposes. - // TODO(beng): (Cleanup) should be const, but GetViewForPoint isn't, so fie! - bool PointIsWithinWindowCaption(const gfx::Point& point); - - // Return true if this tab strip is compatible with the provided tab strip. - // Compatible tab strips can transfer tabs during drag and drop. - bool IsCompatibleWith(TabStrip* other); - - // Returns true if Tabs in this TabStrip are currently changing size or - // position. - bool IsAnimating() const; - // Accessors for the model and individual Tabs. TabStripModel* model() { return model_; } - // Returns true if there is an active drag session. - bool IsDragSessionActive() const { return drag_controller_.get() != NULL; } - // Destroys the active drag controller. void DestroyDragController(); @@ -83,12 +64,6 @@ class TabStrip : public views::View, // Retrieve the ideal bounds for the Tab at the specified index. gfx::Rect GetIdealBounds(int index); - // Updates loading animations for the TabStrip. - void UpdateLoadingAnimations(); - - // Set the background offset used by inactive tabs to match the frame image. - void SetBackgroundOffset(gfx::Point offset); - // Create the new tab button. void InitTabStripButtons(); @@ -108,8 +83,11 @@ class TabStrip : public views::View, virtual void SetAccessibleName(const std::wstring& name); virtual views::View* GetViewForPoint(const gfx::Point& point); virtual void ThemeChanged(); - protected: + virtual void ViewHierarchyChanged(bool is_add, + views::View* parent, + views::View* child); + // TabStripModelObserver implementation: virtual void TabInsertedAt(TabContents* contents, int index, @@ -153,6 +131,20 @@ class TabStrip : public views::View, virtual void DidProcessEvent(GdkEvent* event); #endif + // TabStripWrapper implementation: + virtual int GetPreferredHeight(); + virtual bool IsAnimating() const; + virtual void SetBackgroundOffset(gfx::Point offset); + virtual bool PointIsWithinWindowCaption(const gfx::Point& point); + virtual bool IsDragSessionActive() const; + virtual bool IsCompatibleWith(TabStripWrapper* other) const; + virtual void SetDraggedTabBounds(int tab_index, + const gfx::Rect& tab_bounds); + virtual void UpdateLoadingAnimations(); + virtual views::View* GetView(); + virtual BrowserTabStrip* AsBrowserTabStrip(); + virtual TabStrip* AsTabStrip(); + private: class InsertTabAnimation; class MoveTabAnimation; diff --git a/chrome/browser/views/tabs/tab_strip_2.h b/chrome/browser/views/tabs/tab_strip_2.h index 7bbce90..3096b08 100644 --- a/chrome/browser/views/tabs/tab_strip_2.h +++ b/chrome/browser/views/tabs/tab_strip_2.h @@ -9,6 +9,7 @@ #include "base/task.h" #include "chrome/browser/views/tabs/tab_2.h" +#include "chrome/browser/views/tabs/tab_strip_wrapper.h" #include "views/animator.h" #include "views/view.h" diff --git a/chrome/browser/views/tabs/tab_strip_wrapper.h b/chrome/browser/views/tabs/tab_strip_wrapper.h new file mode 100644 index 0000000..7e94825 --- /dev/null +++ b/chrome/browser/views/tabs/tab_strip_wrapper.h @@ -0,0 +1,73 @@ +// Copyright (c) 2009 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. + +#ifndef CHROME_BROWSER_VIEWS_TABS_TAB_STRIP_WRAPPER_H_ +#define CHROME_BROWSER_VIEWS_TABS_TAB_STRIP_WRAPPER_H_ + +class BrowserTabStrip; +namespace gfx { +class Point; +class Rect; +} +class TabStrip; +class TabStripModel; +namespace views { +class View; +} + +// A temporary interface to abstract the TabStrip implementation (which can be +// either TabStrip or TabStrip2) from the rest of the Browser frontend code +// while the new TabStrip is brought up. +class TabStripWrapper { + public: + // Returns the preferred height of this TabStrip. This is based on the + // typical height of its constituent tabs. + virtual int GetPreferredHeight() = 0; + + // Returns true if Tabs in this TabStrip are currently changing size or + // position. + virtual bool IsAnimating() const = 0; + + // Set the background offset used by inactive tabs to match the frame image. + virtual void SetBackgroundOffset(gfx::Point offset) = 0; + + // Returns true if the specified point(TabStrip coordinates) should be + // considered to be within the window caption area of the browser window. + virtual bool PointIsWithinWindowCaption(const gfx::Point& point) = 0; + + // Returns true if a drag session is currently active. + virtual bool IsDragSessionActive() const = 0; + + // Return true if this tab strip is compatible with the provided tab strip. + // Compatible tab strips can transfer tabs during drag and drop. + virtual bool IsCompatibleWith(TabStripWrapper* other) const = 0; + + // Sets the bounds of the tab at the specified |tab_index|. |tab_bounds| are + // in TabStrip coordinates. + virtual void SetDraggedTabBounds(int tab_index, + const gfx::Rect& tab_bounds) = 0; + + // Updates the loading animations displayed by tabs in the tabstrip to the + // next frame. + virtual void UpdateLoadingAnimations() = 0; + + // Returns the views::View of the wrapped tabstrip, for layout and sizing. + virtual views::View* GetView() = 0; + + // Shim to provide access to the BrowserTabStrip implementation for code only + // called from within TabStrip2::Enabled() == true blocks. Returns NULL when + // old TabStrip is in effect. + virtual BrowserTabStrip* AsBrowserTabStrip() = 0; + + // Shim to provide access to the TabStrip implementation for code only called + // from within TabStrip2::Enabled() == false blocks. Returns NULL when the new + // TabStrip is in effect. + virtual TabStrip* AsTabStrip() = 0; + + // Creates a TabStrip - either the old or new one depending on command line + // flags. + static TabStripWrapper* CreateTabStrip(TabStripModel* model); +}; + +#endif // CHROME_BROWSER_VIEWS_TABS_TAB_STRIP_WRAPPER_H_ |