| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef CHROME_BROWSER_UI_VIEWS_TABS_TAB_H_ | 5 #ifndef CHROME_BROWSER_UI_VIEWS_TABS_TAB_H_ |
| 6 #define CHROME_BROWSER_UI_VIEWS_TABS_TAB_H_ | 6 #define CHROME_BROWSER_UI_VIEWS_TABS_TAB_H_ |
| 7 | 7 |
| 8 #include <list> | 8 #include <list> |
| 9 #include <string> | 9 #include <string> |
| 10 | 10 |
| 11 #include "base/memory/ref_counted.h" | 11 #include "base/memory/ref_counted.h" |
| 12 #include "base/memory/scoped_ptr.h" | 12 #include "base/memory/scoped_ptr.h" |
| 13 #include "chrome/browser/ui/tabs/tab_audio_indicator.h" | |
| 14 #include "chrome/browser/ui/views/tabs/tab_renderer_data.h" | 13 #include "chrome/browser/ui/views/tabs/tab_renderer_data.h" |
| 15 #include "ui/base/layout.h" | 14 #include "ui/base/layout.h" |
| 16 #include "ui/gfx/animation/animation_delegate.h" | 15 #include "ui/gfx/animation/animation_delegate.h" |
| 17 #include "ui/gfx/point.h" | 16 #include "ui/gfx/point.h" |
| 18 #include "ui/views/context_menu_controller.h" | 17 #include "ui/views/context_menu_controller.h" |
| 19 #include "ui/views/controls/button/button.h" | 18 #include "ui/views/controls/button/button.h" |
| 20 #include "ui/views/controls/glow_hover_controller.h" | 19 #include "ui/views/controls/glow_hover_controller.h" |
| 21 #include "ui/views/view.h" | 20 #include "ui/views/view.h" |
| 22 | 21 |
| 23 class TabController; | 22 class TabController; |
| 24 | 23 |
| 25 namespace gfx { | 24 namespace gfx { |
| 26 class Animation; | 25 class Animation; |
| 27 class AnimationContainer; | 26 class AnimationContainer; |
| 28 class Font; | 27 class Font; |
| 29 class LinearAnimation; | 28 class LinearAnimation; |
| 30 class MultiAnimation; | 29 class MultiAnimation; |
| 31 } | 30 } |
| 32 namespace views { | 31 namespace views { |
| 33 class ImageButton; | 32 class ImageButton; |
| 34 } | 33 } |
| 35 | 34 |
| 36 /////////////////////////////////////////////////////////////////////////////// | 35 /////////////////////////////////////////////////////////////////////////////// |
| 37 // | 36 // |
| 38 // A View that renders a Tab, either in a TabStrip or in a DraggedTabView. | 37 // A View that renders a Tab, either in a TabStrip or in a DraggedTabView. |
| 39 // | 38 // |
| 40 /////////////////////////////////////////////////////////////////////////////// | 39 /////////////////////////////////////////////////////////////////////////////// |
| 41 class Tab : public TabAudioIndicator::Delegate, | 40 class Tab : public gfx::AnimationDelegate, |
| 42 public gfx::AnimationDelegate, | |
| 43 public views::ButtonListener, | 41 public views::ButtonListener, |
| 44 public views::ContextMenuController, | 42 public views::ContextMenuController, |
| 45 public views::View { | 43 public views::View { |
| 46 public: | 44 public: |
| 47 // The menu button's class name. | 45 // The menu button's class name. |
| 48 static const char kViewClassName[]; | 46 static const char kViewClassName[]; |
| 49 | 47 |
| 50 explicit Tab(TabController* controller); | 48 explicit Tab(TabController* controller); |
| 51 virtual ~Tab(); | 49 virtual ~Tab(); |
| 52 | 50 |
| (...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 146 | 144 |
| 147 // Scale factor we're drawing it. | 145 // Scale factor we're drawing it. |
| 148 ui::ScaleFactor scale_factor; | 146 ui::ScaleFactor scale_factor; |
| 149 | 147 |
| 150 // The image. | 148 // The image. |
| 151 gfx::ImageSkia image; | 149 gfx::ImageSkia image; |
| 152 }; | 150 }; |
| 153 | 151 |
| 154 typedef std::list<ImageCacheEntry> ImageCache; | 152 typedef std::list<ImageCacheEntry> ImageCache; |
| 155 | 153 |
| 156 // Overridden from TabAudioIndicator::Delegate: | |
| 157 virtual void ScheduleAudioIndicatorPaint() OVERRIDE; | |
| 158 | |
| 159 // Overridden from gfx::AnimationDelegate: | 154 // Overridden from gfx::AnimationDelegate: |
| 160 virtual void AnimationProgressed(const gfx::Animation* animation) OVERRIDE; | 155 virtual void AnimationProgressed(const gfx::Animation* animation) OVERRIDE; |
| 161 virtual void AnimationCanceled(const gfx::Animation* animation) OVERRIDE; | 156 virtual void AnimationCanceled(const gfx::Animation* animation) OVERRIDE; |
| 162 virtual void AnimationEnded(const gfx::Animation* animation) OVERRIDE; | 157 virtual void AnimationEnded(const gfx::Animation* animation) OVERRIDE; |
| 163 | 158 |
| 164 // Overridden from views::ButtonListener: | 159 // Overridden from views::ButtonListener: |
| 165 virtual void ButtonPressed(views::Button* sender, | 160 virtual void ButtonPressed(views::Button* sender, |
| 166 const ui::Event& event) OVERRIDE; | 161 const ui::Event& event) OVERRIDE; |
| 167 | 162 |
| 168 // Overridden from views::ContextMenuController: | 163 // Overridden from views::ContextMenuController: |
| (...skipping 22 matching lines...) Expand all Loading... |
| 191 virtual void OnMouseExited(const ui::MouseEvent& event) OVERRIDE; | 186 virtual void OnMouseExited(const ui::MouseEvent& event) OVERRIDE; |
| 192 virtual void GetAccessibleState(ui::AccessibleViewState* state) OVERRIDE; | 187 virtual void GetAccessibleState(ui::AccessibleViewState* state) OVERRIDE; |
| 193 | 188 |
| 194 // Overridden from ui::EventHandler: | 189 // Overridden from ui::EventHandler: |
| 195 virtual void OnGestureEvent(ui::GestureEvent* event) OVERRIDE; | 190 virtual void OnGestureEvent(ui::GestureEvent* event) OVERRIDE; |
| 196 | 191 |
| 197 // Returns the bounds of the title and icon. | 192 // Returns the bounds of the title and icon. |
| 198 const gfx::Rect& GetTitleBounds() const; | 193 const gfx::Rect& GetTitleBounds() const; |
| 199 const gfx::Rect& GetIconBounds() const; | 194 const gfx::Rect& GetIconBounds() const; |
| 200 | 195 |
| 196 // Invoked from Layout to adjust the position of the favicon or audio |
| 197 // indicator for mini tabs. |
| 198 void MaybeAdjustLeftForMiniTab(gfx::Rect* bounds) const; |
| 199 |
| 201 // Invoked from SetData after |data_| has been updated to the new data. | 200 // Invoked from SetData after |data_| has been updated to the new data. |
| 202 void DataChanged(const TabRendererData& old); | 201 void DataChanged(const TabRendererData& old); |
| 203 | 202 |
| 204 // Paint with the normal tab style. | 203 // Paint with the normal tab style. |
| 205 void PaintTab(gfx::Canvas* canvas); | 204 void PaintTab(gfx::Canvas* canvas); |
| 206 | 205 |
| 207 // Paint with the "immersive mode" light-bar style. | 206 // Paint with the "immersive mode" light-bar style. |
| 208 void PaintImmersiveTab(gfx::Canvas* canvas); | 207 void PaintImmersiveTab(gfx::Canvas* canvas); |
| 209 | 208 |
| 210 // Paint various portions of the Tab | 209 // Paint various portions of the Tab |
| 211 void PaintTabBackground(gfx::Canvas* canvas); | 210 void PaintTabBackground(gfx::Canvas* canvas); |
| 212 void PaintInactiveTabBackgroundWithTitleChange( | 211 void PaintInactiveTabBackgroundWithTitleChange( |
| 213 gfx::Canvas* canvas, | 212 gfx::Canvas* canvas, |
| 214 gfx::MultiAnimation* animation); | 213 gfx::MultiAnimation* animation); |
| 215 void PaintInactiveTabBackground(gfx::Canvas* canvas); | 214 void PaintInactiveTabBackground(gfx::Canvas* canvas); |
| 216 void PaintInactiveTabBackgroundUsingResourceId(gfx::Canvas* canvas, | 215 void PaintInactiveTabBackgroundUsingResourceId(gfx::Canvas* canvas, |
| 217 int tab_id); | 216 int tab_id); |
| 218 void PaintActiveTabBackground(gfx::Canvas* canvas); | 217 void PaintActiveTabBackground(gfx::Canvas* canvas); |
| 219 | 218 |
| 220 // Paints the icon at the specified coordinates, mirrored for RTL if needed. | 219 // Paints the icon, audio indicator icon, etc., mirrored for RTL if needed. |
| 221 void PaintIcon(gfx::Canvas* canvas); | 220 void PaintIcon(gfx::Canvas* canvas); |
| 222 void PaintCaptureState(gfx::Canvas* canvas, gfx::Rect bounds); | 221 void PaintCaptureState(gfx::Canvas* canvas, gfx::Rect bounds); |
| 222 void PaintAudioIndicator(gfx::Canvas* canvas); |
| 223 void PaintTitle(gfx::Canvas* canvas, SkColor title_color); | 223 void PaintTitle(gfx::Canvas* canvas, SkColor title_color); |
| 224 | 224 |
| 225 // Invoked if data_.network_state changes, or the network_state is not none. | 225 // Invoked if data_.network_state changes, or the network_state is not none. |
| 226 void AdvanceLoadingAnimation(TabRendererData::NetworkState old_state, | 226 void AdvanceLoadingAnimation(TabRendererData::NetworkState old_state, |
| 227 TabRendererData::NetworkState state); | 227 TabRendererData::NetworkState state); |
| 228 | 228 |
| 229 // Returns the number of favicon-size elements that can fit in the tab's | 229 // Returns the number of favicon-size elements that can fit in the tab's |
| 230 // current size. | 230 // current size. |
| 231 int IconCapacity() const; | 231 int IconCapacity() const; |
| 232 | 232 |
| 233 // Returns whether the Tab should display a favicon. | 233 // Returns whether the Tab should display a favicon. |
| 234 bool ShouldShowIcon() const; | 234 bool ShouldShowIcon() const; |
| 235 | 235 |
| 236 // Returns whether the Tab should display the audio indicator. |
| 237 bool ShouldShowAudioIndicator() const; |
| 238 |
| 236 // Returns whether the Tab should display a close button. | 239 // Returns whether the Tab should display a close button. |
| 237 bool ShouldShowCloseBox() const; | 240 bool ShouldShowCloseBox() const; |
| 238 | 241 |
| 239 // Gets the throb value for the tab. When a tab is not selected the | 242 // Gets the throb value for the tab. When a tab is not selected the |
| 240 // active background is drawn at |GetThrobValue()|%. This is used for hover, | 243 // active background is drawn at |GetThrobValue()|%. This is used for hover, |
| 241 // mini tab title change and pulsing. | 244 // mini tab title change and pulsing. |
| 242 double GetThrobValue(); | 245 double GetThrobValue(); |
| 243 | 246 |
| 244 // Set the temporary offset for the favicon. This is used during the crash | 247 // Set the temporary offset for the favicon. This is used during the crash |
| 245 // animation. | 248 // animation. |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 314 | 317 |
| 315 // The tab and the icon can both be animating. The tab 'throbs' by changing | 318 // The tab and the icon can both be animating. The tab 'throbs' by changing |
| 316 // color. The icon can have one of several of animations like crashing, | 319 // color. The icon can have one of several of animations like crashing, |
| 317 // recording, projecting, etc. Note that the icon animation related to network | 320 // recording, projecting, etc. Note that the icon animation related to network |
| 318 // state does not have an animation associated with it. | 321 // state does not have an animation associated with it. |
| 319 scoped_ptr<gfx::Animation> tab_animation_; | 322 scoped_ptr<gfx::Animation> tab_animation_; |
| 320 scoped_ptr<gfx::LinearAnimation> icon_animation_; | 323 scoped_ptr<gfx::LinearAnimation> icon_animation_; |
| 321 | 324 |
| 322 scoped_refptr<gfx::AnimationContainer> animation_container_; | 325 scoped_refptr<gfx::AnimationContainer> animation_container_; |
| 323 | 326 |
| 324 scoped_ptr<TabAudioIndicator> tab_audio_indicator_; | |
| 325 | |
| 326 views::ImageButton* close_button_; | 327 views::ImageButton* close_button_; |
| 327 | 328 |
| 328 ui::ThemeProvider* theme_provider_; | 329 ui::ThemeProvider* theme_provider_; |
| 329 | 330 |
| 330 bool tab_activated_with_last_gesture_begin_; | 331 bool tab_activated_with_last_gesture_begin_; |
| 331 | 332 |
| 332 views::GlowHoverController hover_controller_; | 333 views::GlowHoverController hover_controller_; |
| 333 | 334 |
| 334 // The bounds of various sections of the display. | 335 // The bounds of various sections of the display. |
| 335 gfx::Rect favicon_bounds_; | 336 gfx::Rect favicon_bounds_; |
| 336 gfx::Rect title_bounds_; | 337 gfx::Rect title_bounds_; |
| 338 gfx::Rect audio_indicator_bounds_; |
| 337 | 339 |
| 338 // The offset used to paint the inactive background image. | 340 // The offset used to paint the inactive background image. |
| 339 gfx::Point background_offset_; | 341 gfx::Point background_offset_; |
| 340 | 342 |
| 341 struct TabImage { | 343 struct TabImage { |
| 342 gfx::ImageSkia* image_l; | 344 gfx::ImageSkia* image_l; |
| 343 gfx::ImageSkia* image_c; | 345 gfx::ImageSkia* image_c; |
| 344 gfx::ImageSkia* image_r; | 346 gfx::ImageSkia* image_r; |
| 345 int l_width; | 347 int l_width; |
| 346 int r_width; | 348 int r_width; |
| 347 }; | 349 }; |
| 348 static TabImage tab_active_; | 350 static TabImage tab_active_; |
| 349 static TabImage tab_inactive_; | 351 static TabImage tab_inactive_; |
| 350 static TabImage tab_alpha_; | 352 static TabImage tab_alpha_; |
| 351 | 353 |
| 352 // Whether we're showing the icon. It is cached so that we can detect when it | 354 // Whether we're showing the icon. It is cached so that we can detect when it |
| 353 // changes and layout appropriately. | 355 // changes and layout appropriately. |
| 354 bool showing_icon_; | 356 bool showing_icon_; |
| 355 | 357 |
| 358 // Whether we're showing the audio indicator. It is cached so that we can |
| 359 // detect when it changes and layout appropriately. |
| 360 bool showing_audio_indicator_; |
| 361 |
| 356 // Whether we are showing the close button. It is cached so that we can | 362 // Whether we are showing the close button. It is cached so that we can |
| 357 // detect when it changes and layout appropriately. | 363 // detect when it changes and layout appropriately. |
| 358 bool showing_close_button_; | 364 bool showing_close_button_; |
| 359 | 365 |
| 360 // The current color of the close button. | 366 // The current color of the close button. |
| 361 SkColor close_button_color_; | 367 SkColor close_button_color_; |
| 362 | 368 |
| 363 static gfx::Font* font_; | 369 static gfx::Font* font_; |
| 364 static int font_height_; | 370 static int font_height_; |
| 365 | 371 |
| 366 // As the majority of the tabs are inactive, and painting tabs is slowish, | 372 // As the majority of the tabs are inactive, and painting tabs is slowish, |
| 367 // we cache a handful of the inactive tab backgrounds here. | 373 // we cache a handful of the inactive tab backgrounds here. |
| 368 static ImageCache* image_cache_; | 374 static ImageCache* image_cache_; |
| 369 | 375 |
| 370 DISALLOW_COPY_AND_ASSIGN(Tab); | 376 DISALLOW_COPY_AND_ASSIGN(Tab); |
| 371 }; | 377 }; |
| 372 | 378 |
| 373 #endif // CHROME_BROWSER_UI_VIEWS_TABS_TAB_H_ | 379 #endif // CHROME_BROWSER_UI_VIEWS_TABS_TAB_H_ |
| OLD | NEW |