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