tab.h revision dc0f95d653279beabeb9817299e2902918ba123e
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/scoped_ptr.h" 12#include "chrome/browser/ui/views/tabs/base_tab.h" 13#include "ui/gfx/point.h" 14 15namespace ui { 16class MultiAnimation; 17class 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/////////////////////////////////////////////////////////////////////////////// 27class 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. 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; 61 virtual const gfx::Rect& GetIconBounds() const; 62 virtual void DataChanged(const TabRendererData& old); 63 64 private: 65 // Overridden from views::View: 66 virtual void OnPaint(gfx::Canvas* canvas); 67 virtual void Layout(); 68 virtual void OnThemeChanged(); 69 virtual std::string GetClassName() const; 70 virtual bool HasHitTestMask() const; 71 virtual void GetHitTestMask(gfx::Path* path) const; 72 virtual bool GetTooltipTextOrigin(const gfx::Point& p, gfx::Point* origin); 73 virtual void OnMouseMoved(const views::MouseEvent& event); 74 75 // Paint various portions of the Tab 76 void PaintTabBackground(gfx::Canvas* canvas); 77 void PaintInactiveTabBackgroundWithTitleChange(gfx::Canvas* canvas); 78 void PaintInactiveTabBackground(gfx::Canvas* canvas); 79 void PaintActiveTabBackground(gfx::Canvas* canvas); 80 SkBitmap DrawHoverGlowBitmap(int width, int height); 81 82 // Returns the number of favicon-size elements that can fit in the tab's 83 // current size. 84 int IconCapacity() const; 85 86 // Returns whether the Tab should display a favicon. 87 bool ShouldShowIcon() const; 88 89 // Returns whether the Tab should display a close button. 90 bool ShouldShowCloseBox() const; 91 92 // Gets the throb value for the tab. When a tab is not selected the 93 // active background is drawn at |GetThrobValue()|%. This is used for hover, 94 // mini tab title change and pulsing. 95 double GetThrobValue(); 96 97 // Performs a one-time initialization of static resources such as tab images. 98 static void InitTabResources(); 99 100 // Loads the images to be used for the tab background. 101 static void LoadTabImages(); 102 103 // The bounds of various sections of the display. 104 gfx::Rect favicon_bounds_; 105 gfx::Rect title_bounds_; 106 107 // The offset used to paint the inactive background image. 108 gfx::Point background_offset_; 109 110 // The center point for the radial hover glow. 111 gfx::Point hover_point_; 112 113 // Animation used when the title of an inactive mini tab changes. 114 scoped_ptr<ui::MultiAnimation> mini_title_animation_; 115 116 struct TabImage { 117 SkBitmap* image_l; 118 SkBitmap* image_c; 119 SkBitmap* image_r; 120 int l_width; 121 int r_width; 122 int y_offset; 123 }; 124 static TabImage tab_active_; 125 static TabImage tab_inactive_; 126 static TabImage tab_alpha_; 127 128 // Whether we're showing the icon. It is cached so that we can detect when it 129 // changes and layout appropriately. 130 bool showing_icon_; 131 132 // Whether we are showing the close button. It is cached so that we can 133 // detect when it changes and layout appropriately. 134 bool showing_close_button_; 135 136 // The current color of the close button. 137 SkColor close_button_color_; 138 139 static bool initialized_; 140 141 DISALLOW_COPY_AND_ASSIGN(Tab); 142}; 143 144#endif // CHROME_BROWSER_UI_VIEWS_TABS_TAB_H_ 145