diff options
author | ben@chromium.org <ben@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-07-08 23:12:36 +0000 |
---|---|---|
committer | ben@chromium.org <ben@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-07-08 23:12:36 +0000 |
commit | e1fbf5bb7ff932edf51c328aaf9c3c8a8a2b7eb7 (patch) | |
tree | 7853a5989372ae9acc42b3b6453886acbf28d9a5 /chrome/browser/views/tabs | |
parent | 57c959f989ccc8f6a9e47190294ee2b9e22c2fb2 (diff) | |
download | chromium_src-e1fbf5bb7ff932edf51c328aaf9c3c8a8a2b7eb7.zip chromium_src-e1fbf5bb7ff932edf51c328aaf9c3c8a8a2b7eb7.tar.gz chromium_src-e1fbf5bb7ff932edf51c328aaf9c3c8a8a2b7eb7.tar.bz2 |
Add temporary TabStripWrapper interface that is implemented by both TabStrip and BrowserTabStrip... this makes dealing with the multiple implementations more manageable in shared code like BrowserView, etc. This interface will die once the new work is completed and a conversion is finished. The interface contains all the methods that BrowserView expect to find on TabStrip.
BUG=none
TEST=none
Review URL: http://codereview.chromium.org/155242
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@20204 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/views/tabs')
-rw-r--r-- | chrome/browser/views/tabs/browser_tab_strip.cc | 58 | ||||
-rw-r--r-- | chrome/browser/views/tabs/browser_tab_strip.h | 17 | ||||
-rw-r--r-- | chrome/browser/views/tabs/dragged_tab_controller.cc | 4 | ||||
-rw-r--r-- | chrome/browser/views/tabs/tab_strip.cc | 150 | ||||
-rw-r--r-- | chrome/browser/views/tabs/tab_strip.h | 50 | ||||
-rw-r--r-- | chrome/browser/views/tabs/tab_strip_2.h | 1 | ||||
-rw-r--r-- | chrome/browser/views/tabs/tab_strip_wrapper.h | 73 |
7 files changed, 261 insertions, 92 deletions
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_ |