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/views/tabs/tab_renderer_data.h" | 13 #include "chrome/browser/ui/views/tabs/tab_renderer_data.h" |
14 #include "ui/base/layout.h" | 14 #include "ui/base/layout.h" |
15 #include "ui/gfx/animation/animation_delegate.h" | 15 #include "ui/gfx/animation/animation_delegate.h" |
16 #include "ui/gfx/point.h" | 16 #include "ui/gfx/point.h" |
17 #include "ui/views/context_menu_controller.h" | 17 #include "ui/views/context_menu_controller.h" |
18 #include "ui/views/controls/button/button.h" | 18 #include "ui/views/controls/button/button.h" |
19 #include "ui/views/controls/glow_hover_controller.h" | 19 #include "ui/views/controls/glow_hover_controller.h" |
20 #include "ui/views/masked_targeter_delegate.h" | 20 #include "ui/views/masked_targeter_delegate.h" |
21 #include "ui/views/view.h" | 21 #include "ui/views/view.h" |
22 | 22 |
| 23 class MediaIndicatorButton; |
23 class TabController; | 24 class TabController; |
24 | 25 |
25 namespace gfx { | 26 namespace gfx { |
26 class Animation; | 27 class Animation; |
27 class AnimationContainer; | 28 class AnimationContainer; |
28 class LinearAnimation; | 29 class LinearAnimation; |
29 class MultiAnimation; | 30 class MultiAnimation; |
30 class ThrobAnimation; | 31 class ThrobAnimation; |
31 } | 32 } |
32 namespace views { | 33 namespace views { |
33 class ImageButton; | 34 class ImageButton; |
34 class Label; | 35 class Label; |
35 } | 36 } |
36 | 37 |
37 /////////////////////////////////////////////////////////////////////////////// | 38 /////////////////////////////////////////////////////////////////////////////// |
38 // | 39 // |
39 // A View that renders a Tab in a TabStrip. | 40 // A View that renders a Tab in a TabStrip. |
40 // | 41 // |
41 /////////////////////////////////////////////////////////////////////////////// | 42 /////////////////////////////////////////////////////////////////////////////// |
42 class Tab : public gfx::AnimationDelegate, | 43 class Tab : public gfx::AnimationDelegate, |
43 public views::ButtonListener, | 44 public views::ButtonListener, |
44 public views::ContextMenuController, | 45 public views::ContextMenuController, |
45 public views::MaskedTargeterDelegate, | 46 public views::MaskedTargeterDelegate, |
46 public views::View { | 47 public views::View { |
47 public: | 48 public: |
48 // The menu button's class name. | 49 // The Tab's class name. |
49 static const char kViewClassName[]; | 50 static const char kViewClassName[]; |
50 | 51 |
51 explicit Tab(TabController* controller); | 52 explicit Tab(TabController* controller); |
52 virtual ~Tab(); | 53 virtual ~Tab(); |
53 | 54 |
| 55 TabController* controller() const { return controller_; } |
| 56 |
54 // Used to set/check whether this Tab is being animated closed. | 57 // Used to set/check whether this Tab is being animated closed. |
55 void set_closing(bool closing) { closing_ = closing; } | 58 void set_closing(bool closing) { closing_ = closing; } |
56 bool closing() const { return closing_; } | 59 bool closing() const { return closing_; } |
57 | 60 |
58 // See description above field. | 61 // See description above field. |
59 void set_dragging(bool dragging) { dragging_ = dragging; } | 62 void set_dragging(bool dragging) { dragging_ = dragging; } |
60 bool dragging() const { return dragging_; } | 63 bool dragging() const { return dragging_; } |
61 | 64 |
62 // Used to mark the tab as having been detached. Once this has happened, the | 65 // Used to mark the tab as having been detached. Once this has happened, the |
63 // tab should be invisibly closed. This is irreversible. | 66 // tab should be invisibly closed. This is irreversible. |
(...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
218 void PaintImmersiveTab(gfx::Canvas* canvas); | 221 void PaintImmersiveTab(gfx::Canvas* canvas); |
219 | 222 |
220 // Paint various portions of the Tab | 223 // Paint various portions of the Tab |
221 void PaintTabBackground(gfx::Canvas* canvas); | 224 void PaintTabBackground(gfx::Canvas* canvas); |
222 void PaintInactiveTabBackgroundWithTitleChange(gfx::Canvas* canvas); | 225 void PaintInactiveTabBackgroundWithTitleChange(gfx::Canvas* canvas); |
223 void PaintInactiveTabBackground(gfx::Canvas* canvas); | 226 void PaintInactiveTabBackground(gfx::Canvas* canvas); |
224 void PaintInactiveTabBackgroundUsingResourceId(gfx::Canvas* canvas, | 227 void PaintInactiveTabBackgroundUsingResourceId(gfx::Canvas* canvas, |
225 int tab_id); | 228 int tab_id); |
226 void PaintActiveTabBackground(gfx::Canvas* canvas); | 229 void PaintActiveTabBackground(gfx::Canvas* canvas); |
227 | 230 |
228 // Paints the favicon and media indicator icon, mirrored for RTL if needed. | 231 // Paints the favicon, mirrored for RTL if needed. |
229 void PaintIcon(gfx::Canvas* canvas); | 232 void PaintIcon(gfx::Canvas* canvas); |
230 void PaintMediaIndicator(gfx::Canvas* canvas); | |
231 | 233 |
232 // Invoked if data_.network_state changes, or the network_state is not none. | 234 // Invoked if data_.network_state changes, or the network_state is not none. |
233 void AdvanceLoadingAnimation(TabRendererData::NetworkState old_state, | 235 void AdvanceLoadingAnimation(TabRendererData::NetworkState old_state, |
234 TabRendererData::NetworkState state); | 236 TabRendererData::NetworkState state); |
235 | 237 |
236 // Returns the number of favicon-size elements that can fit in the tab's | 238 // Returns the number of favicon-size elements that can fit in the tab's |
237 // current size. | 239 // current size. |
238 int IconCapacity() const; | 240 int IconCapacity() const; |
239 | 241 |
240 // Returns whether the Tab should display a favicon. | 242 // Returns whether the Tab should display a favicon. |
(...skipping 16 matching lines...) Expand all Loading... |
257 | 259 |
258 void DisplayCrashedFavicon(); | 260 void DisplayCrashedFavicon(); |
259 void ResetCrashedFavicon(); | 261 void ResetCrashedFavicon(); |
260 | 262 |
261 void StopCrashAnimation(); | 263 void StopCrashAnimation(); |
262 void StartCrashAnimation(); | 264 void StartCrashAnimation(); |
263 | 265 |
264 // Returns true if the crash animation is currently running. | 266 // Returns true if the crash animation is currently running. |
265 bool IsPerformingCrashAnimation() const; | 267 bool IsPerformingCrashAnimation() const; |
266 | 268 |
267 // Starts the media indicator fade-in/out animation. There's no stop method | |
268 // because this is not a continuous animation. | |
269 void StartMediaIndicatorAnimation(); | |
270 | |
271 // Schedules repaint task for icon. | 269 // Schedules repaint task for icon. |
272 void ScheduleIconPaint(); | 270 void ScheduleIconPaint(); |
273 | 271 |
274 // Returns the rectangle for the light bar in immersive mode. | 272 // Returns the rectangle for the light bar in immersive mode. |
275 gfx::Rect GetImmersiveBarRect() const; | 273 gfx::Rect GetImmersiveBarRect() const; |
276 | 274 |
277 // Gets the tab id and frame id. | 275 // Gets the tab id and frame id. |
278 void GetTabIdAndFrameId(views::Widget* widget, | 276 void GetTabIdAndFrameId(views::Widget* widget, |
279 int* tab_id, | 277 int* tab_id, |
280 int* frame_id) const; | 278 int* frame_id) const; |
281 | 279 |
| 280 // Returns |media_indicator_button_|, creating it on-demand. |
| 281 MediaIndicatorButton* GetMediaIndicatorButton(); |
| 282 |
282 // Performs a one-time initialization of static resources such as tab images. | 283 // Performs a one-time initialization of static resources such as tab images. |
283 static void InitTabResources(); | 284 static void InitTabResources(); |
284 | 285 |
285 // Returns the minimum possible size of a single unselected Tab, not | 286 // Returns the minimum possible size of a single unselected Tab, not |
286 // including considering touch mode. | 287 // including considering touch mode. |
287 static gfx::Size GetBasicMinimumUnselectedSize(); | 288 static gfx::Size GetBasicMinimumUnselectedSize(); |
288 | 289 |
289 // Loads the images to be used for the tab background. | 290 // Loads the images to be used for the tab background. |
290 static void LoadTabImages(); | 291 static void LoadTabImages(); |
291 | 292 |
292 // Returns the cached image for the specified arguments, or an empty image if | 293 // Returns the cached image for the specified arguments, or an empty image if |
293 // there isn't one cached. | 294 // there isn't one cached. |
294 static gfx::ImageSkia GetCachedImage(int resource_id, | 295 static gfx::ImageSkia GetCachedImage(int resource_id, |
295 const gfx::Size& size, | 296 const gfx::Size& size, |
296 ui::ScaleFactor scale_factor); | 297 ui::ScaleFactor scale_factor); |
297 | 298 |
298 // Caches the specified image. | 299 // Caches the specified image. |
299 static void SetCachedImage(int resource_id, | 300 static void SetCachedImage(int resource_id, |
300 ui::ScaleFactor scale_factor, | 301 ui::ScaleFactor scale_factor, |
301 const gfx::ImageSkia& image); | 302 const gfx::ImageSkia& image); |
302 | 303 |
303 // The controller, never NULL. | 304 // The controller, never NULL. |
304 TabController* controller_; | 305 TabController* const controller_; |
305 | 306 |
306 TabRendererData data_; | 307 TabRendererData data_; |
307 | 308 |
308 // True if the tab is being animated closed. | 309 // True if the tab is being animated closed. |
309 bool closing_; | 310 bool closing_; |
310 | 311 |
311 // True if the tab is being dragged. | 312 // True if the tab is being dragged. |
312 bool dragging_; | 313 bool dragging_; |
313 | 314 |
314 // True if the tab has been detached. | 315 // True if the tab has been detached. |
(...skipping 13 matching lines...) Expand all Loading... |
328 bool should_display_crashed_favicon_; | 329 bool should_display_crashed_favicon_; |
329 | 330 |
330 // Whole-tab throbbing "pulse" animation. | 331 // Whole-tab throbbing "pulse" animation. |
331 scoped_ptr<gfx::ThrobAnimation> pulse_animation_; | 332 scoped_ptr<gfx::ThrobAnimation> pulse_animation_; |
332 | 333 |
333 scoped_ptr<gfx::MultiAnimation> mini_title_change_animation_; | 334 scoped_ptr<gfx::MultiAnimation> mini_title_change_animation_; |
334 | 335 |
335 // Crash icon animation (in place of favicon). | 336 // Crash icon animation (in place of favicon). |
336 scoped_ptr<gfx::LinearAnimation> crash_icon_animation_; | 337 scoped_ptr<gfx::LinearAnimation> crash_icon_animation_; |
337 | 338 |
338 // Media indicator fade-in/out animation (i.e., only on show/hide, not a | |
339 // continuous animation). | |
340 scoped_ptr<gfx::Animation> media_indicator_animation_; | |
341 TabMediaState animating_media_state_; | |
342 | |
343 scoped_refptr<gfx::AnimationContainer> animation_container_; | 339 scoped_refptr<gfx::AnimationContainer> animation_container_; |
344 | 340 |
345 views::ImageButton* close_button_; | 341 views::ImageButton* close_button_; |
| 342 MediaIndicatorButton* media_indicator_button_; // NULL until first use. |
346 views::Label* title_; | 343 views::Label* title_; |
347 | 344 |
348 bool tab_activated_with_last_tap_down_; | 345 bool tab_activated_with_last_tap_down_; |
349 | 346 |
350 views::GlowHoverController hover_controller_; | 347 views::GlowHoverController hover_controller_; |
351 | 348 |
352 // The bounds of various sections of the display. | 349 // The bounds of various sections of the display. |
353 gfx::Rect favicon_bounds_; | 350 gfx::Rect favicon_bounds_; |
354 gfx::Rect media_indicator_bounds_; | |
355 | 351 |
356 // The offset used to paint the inactive background image. | 352 // The offset used to paint the inactive background image. |
357 gfx::Point background_offset_; | 353 gfx::Point background_offset_; |
358 | 354 |
359 struct TabImage { | 355 struct TabImage { |
360 gfx::ImageSkia* image_l; | 356 gfx::ImageSkia* image_l; |
361 gfx::ImageSkia* image_c; | 357 gfx::ImageSkia* image_c; |
362 gfx::ImageSkia* image_r; | 358 gfx::ImageSkia* image_r; |
363 int l_width; | 359 int l_width; |
364 int r_width; | 360 int r_width; |
(...skipping 18 matching lines...) Expand all Loading... |
383 SkColor close_button_color_; | 379 SkColor close_button_color_; |
384 | 380 |
385 // As the majority of the tabs are inactive, and painting tabs is slowish, | 381 // As the majority of the tabs are inactive, and painting tabs is slowish, |
386 // we cache a handful of the inactive tab backgrounds here. | 382 // we cache a handful of the inactive tab backgrounds here. |
387 static ImageCache* image_cache_; | 383 static ImageCache* image_cache_; |
388 | 384 |
389 DISALLOW_COPY_AND_ASSIGN(Tab); | 385 DISALLOW_COPY_AND_ASSIGN(Tab); |
390 }; | 386 }; |
391 | 387 |
392 #endif // CHROME_BROWSER_UI_VIEWS_TABS_TAB_H_ | 388 #endif // CHROME_BROWSER_UI_VIEWS_TABS_TAB_H_ |
OLD | NEW |