1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style license that can be 3 // found in the LICENSE file. 4 5 #ifndef CHROME_BROWSER_UI_VIEWS_TABS_TAB_H_ 6 #define CHROME_BROWSER_UI_VIEWS_TABS_TAB_H_ 7 #pragma once 8 9 #include <string> 10 11 #include "base/memory/scoped_ptr.h" 12 #include "chrome/browser/ui/views/tabs/base_tab.h" 13 #include "ui/gfx/point.h" 14 15 namespace ui { 16 class MultiAnimation; 17 class SlideAnimation; 18 } 19 20 /////////////////////////////////////////////////////////////////////////////// 21 // 22 // TabRenderer 23 // 24 // A View that renders a Tab, either in a TabStrip or in a DraggedTabView. 25 // 26 /////////////////////////////////////////////////////////////////////////////// 27 class Tab : public BaseTab { 28 public: 29 // The menu button's class name. 30 static const char kViewClassName[]; 31 32 explicit Tab(TabController* controller); 33 virtual ~Tab(); 34 35 // Start/stop the mini-tab title animation. 36 void StartMiniTabTitleAnimation(); 37 void StopMiniTabTitleAnimation(); 38 39 // Set the background offset used to match the image in the inactive tab 40 // to the frame image. set_background_offset(const gfx::Point & offset)41 void set_background_offset(const gfx::Point& offset) { 42 background_offset_ = offset; 43 } 44 45 // Returns the minimum possible size of a single unselected Tab. 46 static gfx::Size GetMinimumUnselectedSize(); 47 // Returns the minimum possible size of a selected Tab. Selected tabs must 48 // always show a close button and have a larger minimum size than unselected 49 // tabs. 50 static gfx::Size GetMinimumSelectedSize(); 51 // Returns the preferred size of a single Tab, assuming space is 52 // available. 53 static gfx::Size GetStandardSize(); 54 55 // Returns the width for mini-tabs. Mini-tabs always have this width. 56 static int GetMiniWidth(); 57 58 protected: 59 // BaseTab overrides: 60 virtual const gfx::Rect& GetTitleBounds() const OVERRIDE; 61 virtual const gfx::Rect& GetIconBounds() const OVERRIDE; 62 virtual void DataChanged(const TabRendererData& old) OVERRIDE; 63 64 private: 65 // Overridden from views::View: 66 virtual void OnPaint(gfx::Canvas* canvas) OVERRIDE; 67 virtual void Layout() OVERRIDE; 68 virtual void OnThemeChanged() OVERRIDE; 69 virtual std::string GetClassName() const OVERRIDE; 70 virtual bool HasHitTestMask() const OVERRIDE; 71 virtual void GetHitTestMask(gfx::Path* path) const OVERRIDE; 72 virtual bool GetTooltipTextOrigin(const gfx::Point& p, 73 gfx::Point* origin) OVERRIDE; 74 virtual void OnMouseMoved(const views::MouseEvent& event) OVERRIDE; 75 76 // Paint various portions of the Tab 77 void PaintTabBackground(gfx::Canvas* canvas); 78 void PaintInactiveTabBackgroundWithTitleChange(gfx::Canvas* canvas); 79 void PaintInactiveTabBackground(gfx::Canvas* canvas); 80 void PaintActiveTabBackground(gfx::Canvas* canvas); 81 SkBitmap DrawHoverGlowBitmap(int width, int height); 82 83 // Returns the number of favicon-size elements that can fit in the tab's 84 // current size. 85 int IconCapacity() const; 86 87 // Returns whether the Tab should display a favicon. 88 bool ShouldShowIcon() const; 89 90 // Returns whether the Tab should display a close button. 91 bool ShouldShowCloseBox() const; 92 93 // Gets the throb value for the tab. When a tab is not selected the 94 // active background is drawn at |GetThrobValue()|%. This is used for hover, 95 // mini tab title change and pulsing. 96 double GetThrobValue(); 97 98 // Performs a one-time initialization of static resources such as tab images. 99 static void InitTabResources(); 100 101 // Loads the images to be used for the tab background. 102 static void LoadTabImages(); 103 104 // The bounds of various sections of the display. 105 gfx::Rect favicon_bounds_; 106 gfx::Rect title_bounds_; 107 108 // The offset used to paint the inactive background image. 109 gfx::Point background_offset_; 110 111 // The center point for the radial hover glow. 112 gfx::Point hover_point_; 113 114 // Animation used when the title of an inactive mini tab changes. 115 scoped_ptr<ui::MultiAnimation> mini_title_animation_; 116 117 struct TabImage { 118 SkBitmap* image_l; 119 SkBitmap* image_c; 120 SkBitmap* image_r; 121 int l_width; 122 int r_width; 123 int y_offset; 124 }; 125 static TabImage tab_active_; 126 static TabImage tab_inactive_; 127 static TabImage tab_alpha_; 128 129 // Whether we're showing the icon. It is cached so that we can detect when it 130 // changes and layout appropriately. 131 bool showing_icon_; 132 133 // Whether we are showing the close button. It is cached so that we can 134 // detect when it changes and layout appropriately. 135 bool showing_close_button_; 136 137 // The current color of the close button. 138 SkColor close_button_color_; 139 140 static bool initialized_; 141 142 DISALLOW_COPY_AND_ASSIGN(Tab); 143 }; 144 145 #endif // CHROME_BROWSER_UI_VIEWS_TABS_TAB_H_ 146