diff options
author | ben@chromium.org <ben@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-07-09 19:45:55 +0000 |
---|---|---|
committer | ben@chromium.org <ben@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-07-09 19:45:55 +0000 |
commit | 6ae2b6adde38614230f62edaf6774157c680de58 (patch) | |
tree | f842197ccf18642c39c6ce25ab2c4cc69cd396a9 /chrome/browser/views/tabs/tab_2.h | |
parent | 851da074d1c73438f30f4671ac45d25ee589573d (diff) | |
download | chromium_src-6ae2b6adde38614230f62edaf6774157c680de58.zip chromium_src-6ae2b6adde38614230f62edaf6774157c680de58.tar.gz chromium_src-6ae2b6adde38614230f62edaf6774157c680de58.tar.bz2 |
Bring over most of the old TabRenderer into Tab2. No real logic changes here. Split out a few large functions into sub functions (Layout -> LayoutIcon, LayoutTitle, etc; Paint -> PaintIcon, PaintTitle etc).
BUG=none
TEST=none
Review URL: http://codereview.chromium.org/149380
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@20301 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/views/tabs/tab_2.h')
-rw-r--r-- | chrome/browser/views/tabs/tab_2.h | 164 |
1 files changed, 149 insertions, 15 deletions
diff --git a/chrome/browser/views/tabs/tab_2.h b/chrome/browser/views/tabs/tab_2.h index f5ae969..4af97ec 100644 --- a/chrome/browser/views/tabs/tab_2.h +++ b/chrome/browser/views/tabs/tab_2.h @@ -5,20 +5,24 @@ #ifndef CHROME_BROWSER_VIEWS_TABS_TAB_2_H_ #define CHROME_BROWSER_VIEWS_TABS_TAB_2_H_ +#include "app/animation.h" #include "base/string16.h" +#include "views/controls/button/button.h" #include "views/view.h" -class Tab2; - namespace gfx { class Canvas; class Path; }; - +class SkBitmap; +class SlideAnimation; +class Tab2; +class ThrobAnimation; namespace views { class AnimationContext; class Animator; class AnimatorDelegate; +class ImageButton; } // An interface implemented by an object that provides data to the Tab2. @@ -27,19 +31,27 @@ class Tab2Model { public: virtual ~Tab2Model() {} - // Tab2 presentation state. + // Tab presentation state. virtual string16 GetTitle(Tab2* tab) const = 0; + virtual SkBitmap GetIcon(Tab2* tab) const = 0; virtual bool IsSelected(Tab2* tab) const = 0; + virtual bool ShouldShowIcon(Tab2* tab) const = 0; + virtual bool IsLoading(Tab2* tab) const = 0; + virtual bool IsCrashed(Tab2* tab) const = 0; + virtual bool IsIncognito(Tab2* tab) const = 0; - // The Tab2 has been clicked and should become selected. + // The tab has been clicked and should become selected. virtual void SelectTab(Tab2* tab) = 0; - // The mouse has been pressed down on the Tab2, pertinent information for any + // The tab should be closed. + virtual void CloseTab(Tab2* tab) = 0; + + // The mouse has been pressed down on the tab, pertinent information for any // drag that might occur should be captured at this time. virtual void CaptureDragInfo(Tab2* tab, const views::MouseEvent& drag_event) = 0; - // The mouse has been dragged after a press on the Tab2. + // The mouse has been dragged after a press on the tab. virtual bool DragTab(Tab2* tab, const views::MouseEvent& drag_event) = 0; // The current drag operation has ended. @@ -50,7 +62,9 @@ class Tab2Model { }; // A view that represents a Tab in a TabStrip2. -class Tab2 : public views::View { +class Tab2 : public views::View, + public views::ButtonListener, + public AnimationDelegate { public: explicit Tab2(Tab2Model* model); virtual ~Tab2(); @@ -72,25 +86,97 @@ class Tab2 : public views::View { // TODO(beng): consider moving to views::View. views::Animator* GetAnimator(); - // Returns the ideal size of the Tab2. - static gfx::Size GetStandardSize(); + // Set the background offset used to match the image in the inactive tab + // to the frame image. + void set_background_offset(gfx::Point offset) { + background_offset_ = offset; + } + + // Set the theme provider - because we get detached, we are frequently + // outside of a hierarchy with a theme provider at the top. This should be + // called whenever we're detached or attached to a hierarchy. + void set_theme_provider(ThemeProvider* provider) { + theme_provider_ = provider; + } // Adds the shape of the tab to the specified path. Used to create a clipped // window during detached window dragging operations. void AddTabShapeToPath(gfx::Path* path) const; + // Returns the minimum possible size of a single unselected Tab. + static gfx::Size GetMinimumUnselectedSize(); + + // Returns the minimum possible size of a selected Tab. Selected tabs must + // always show a close button and have a larger minimum size than unselected + // tabs. + static gfx::Size GetMinimumSelectedSize(); + + // Returns the preferred size of a single Tab, assuming space is + // available. + static gfx::Size GetStandardSize(); + + // Loads the themable resources associated with this View. + static void LoadTabImages(); + + private: + // Possible animation states. + enum AnimationState { + ANIMATION_NONE, + ANIMATION_WAITING, + ANIMATION_LOADING + }; + + // views::ButtonListener overrides: + virtual void ButtonPressed(views::Button* sender); + // Overridden from views::View: - virtual gfx::Size GetPreferredSize(); virtual void Layout(); virtual void Paint(gfx::Canvas* canvas); + virtual void OnMouseEntered(const views::MouseEvent& event); + virtual void OnMouseExited(const views::MouseEvent& event); virtual bool OnMousePressed(const views::MouseEvent& event); virtual bool OnMouseDragged(const views::MouseEvent& event); virtual void OnMouseReleased(const views::MouseEvent& event, bool canceled); - virtual void DidChangeBounds(const gfx::Rect& previous, - const gfx::Rect& current); - - private: + virtual void ThemeChanged(); + virtual void ViewHierarchyChanged(bool is_add, + views::View* parent, + views::View* child); + virtual ThemeProvider* GetThemeProvider(); + + // Overridden from AnimationDelegate: + virtual void AnimationProgressed(const Animation* animation); + virtual void AnimationCanceled(const Animation* animation); + virtual void AnimationEnded(const Animation* animation); + + // Layout various portions of the tab. For each of the below, |content_height| + // is the actual height of the content based on the font, icon size etc. + // |content_rect| is the rectangle within which the content is laid out, and + // may be larger. + void LayoutIcon(int content_height, const gfx::Rect& content_rect); + void LayoutCloseButton(int content_height, const gfx::Rect& content_rect); + void LayoutTitle(int content_height, const gfx::Rect& content_rect); + + // Paint various portions of the tab. + void PaintIcon(gfx::Canvas* canvas); + void PaintTitle(gfx::Canvas* canvas); + void PaintTabBackground(gfx::Canvas* canvas); + void PaintInactiveTabBackground(gfx::Canvas* canvas); + void PaintActiveTabBackground(gfx::Canvas* canvas); + void PaintHoverTabBackground(gfx::Canvas* canvas, double opacity); + void PaintLoadingAnimation(gfx::Canvas* canvas); + + // Returns the number of icon-size elements that can fit in the tab's + // current size. + int IconCapacity() const; + + // Returns whether the Tab should display a icon. + bool ShouldShowIcon() const; + + // Returns whether the Tab should display a close button. + bool ShouldShowCloseBox() const; + + // The object that provides state for this tab. Tab2Model* model_; // True if the Tab2 is being dragged currently. @@ -108,6 +194,54 @@ class Tab2 : public views::View { // animated out of existence). scoped_ptr<Tab2Model> removing_model_; + // The bounds of various sections of the display. + gfx::Rect icon_bounds_; + gfx::Rect title_bounds_; + + // The offset used to paint the inactive background image. + gfx::Point background_offset_; + + // Current state of the animation. + AnimationState animation_state_; + + // The current index into the Animation image strip. + int animation_frame_; + + // Close Button. + views::ImageButton* close_button_; + + // Hover animation. + scoped_ptr<SlideAnimation> hover_animation_; + + // Pulse animation. + scoped_ptr<ThrobAnimation> pulse_animation_; + + // Whether we're showing the icon. It is cached so that we can detect when it + // changes and layout appropriately. + bool showing_icon_; + + // Whether we are showing the close button. It is cached so that we can + // detect when it changes and layout appropriately. + bool showing_close_button_; + + // The offset used to animate the icon location. + int icon_hiding_offset_; + + // The theme provider to source tab images from. + ThemeProvider* theme_provider_; + + // Resources used in the tab display. + struct TabImage { + SkBitmap* image_l; + SkBitmap* image_c; + SkBitmap* image_r; + int l_width; + int r_width; + }; + static TabImage tab_active_; + static TabImage tab_inactive_; + static TabImage tab_alpha_; + DISALLOW_COPY_AND_ASSIGN(Tab2); }; |