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/view.h" | 20 #include "ui/views/view.h" |
21 | 21 |
22 class TabController; | 22 class TabController; |
23 | 23 |
24 namespace gfx { | 24 namespace gfx { |
25 class Animation; | 25 class Animation; |
26 class AnimationContainer; | 26 class AnimationContainer; |
27 class Font; | |
28 class LinearAnimation; | 27 class LinearAnimation; |
29 class MultiAnimation; | 28 class MultiAnimation; |
30 } | 29 } |
31 namespace views { | 30 namespace views { |
32 class ImageButton; | 31 class ImageButton; |
| 32 class Label; |
33 } | 33 } |
34 | 34 |
35 /////////////////////////////////////////////////////////////////////////////// | 35 /////////////////////////////////////////////////////////////////////////////// |
36 // | 36 // |
37 // A View that renders a Tab in a TabStrip. | 37 // A View that renders a Tab in a TabStrip. |
38 // | 38 // |
39 /////////////////////////////////////////////////////////////////////////////// | 39 /////////////////////////////////////////////////////////////////////////////// |
40 class Tab : public gfx::AnimationDelegate, | 40 class Tab : public gfx::AnimationDelegate, |
41 public views::ButtonListener, | 41 public views::ButtonListener, |
42 public views::ContextMenuController, | 42 public views::ContextMenuController, |
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
178 virtual void OnMouseReleased(const ui::MouseEvent& event) OVERRIDE; | 178 virtual void OnMouseReleased(const ui::MouseEvent& event) OVERRIDE; |
179 virtual void OnMouseCaptureLost() OVERRIDE; | 179 virtual void OnMouseCaptureLost() OVERRIDE; |
180 virtual void OnMouseEntered(const ui::MouseEvent& event) OVERRIDE; | 180 virtual void OnMouseEntered(const ui::MouseEvent& event) OVERRIDE; |
181 virtual void OnMouseMoved(const ui::MouseEvent& event) OVERRIDE; | 181 virtual void OnMouseMoved(const ui::MouseEvent& event) OVERRIDE; |
182 virtual void OnMouseExited(const ui::MouseEvent& event) OVERRIDE; | 182 virtual void OnMouseExited(const ui::MouseEvent& event) OVERRIDE; |
183 virtual void GetAccessibleState(ui::AXViewState* state) OVERRIDE; | 183 virtual void GetAccessibleState(ui::AXViewState* state) OVERRIDE; |
184 | 184 |
185 // Overridden from ui::EventHandler: | 185 // Overridden from ui::EventHandler: |
186 virtual void OnGestureEvent(ui::GestureEvent* event) OVERRIDE; | 186 virtual void OnGestureEvent(ui::GestureEvent* event) OVERRIDE; |
187 | 187 |
188 // Returns the bounds of the title and icon. | |
189 const gfx::Rect& GetTitleBounds() const; | |
190 const gfx::Rect& GetIconBounds() const; | |
191 | |
192 // Invoked from Layout to adjust the position of the favicon or media | 188 // Invoked from Layout to adjust the position of the favicon or media |
193 // indicator for mini tabs. | 189 // indicator for mini tabs. |
194 void MaybeAdjustLeftForMiniTab(gfx::Rect* bounds) const; | 190 void MaybeAdjustLeftForMiniTab(gfx::Rect* bounds) const; |
195 | 191 |
196 // Invoked from SetData after |data_| has been updated to the new data. | 192 // Invoked from SetData after |data_| has been updated to the new data. |
197 void DataChanged(const TabRendererData& old); | 193 void DataChanged(const TabRendererData& old); |
198 | 194 |
199 // Paint with the normal tab style. | 195 // Paint with the normal tab style. |
200 void PaintTab(gfx::Canvas* canvas); | 196 void PaintTab(gfx::Canvas* canvas); |
201 | 197 |
202 // Paint with the "immersive mode" light-bar style. | 198 // Paint with the "immersive mode" light-bar style. |
203 void PaintImmersiveTab(gfx::Canvas* canvas); | 199 void PaintImmersiveTab(gfx::Canvas* canvas); |
204 | 200 |
205 // Paint various portions of the Tab | 201 // Paint various portions of the Tab |
206 void PaintTabBackground(gfx::Canvas* canvas); | 202 void PaintTabBackground(gfx::Canvas* canvas); |
207 void PaintInactiveTabBackgroundWithTitleChange( | 203 void PaintInactiveTabBackgroundWithTitleChange( |
208 gfx::Canvas* canvas, | 204 gfx::Canvas* canvas, |
209 gfx::MultiAnimation* animation); | 205 gfx::MultiAnimation* animation); |
210 void PaintInactiveTabBackground(gfx::Canvas* canvas); | 206 void PaintInactiveTabBackground(gfx::Canvas* canvas); |
211 void PaintInactiveTabBackgroundUsingResourceId(gfx::Canvas* canvas, | 207 void PaintInactiveTabBackgroundUsingResourceId(gfx::Canvas* canvas, |
212 int tab_id); | 208 int tab_id); |
213 void PaintActiveTabBackground(gfx::Canvas* canvas); | 209 void PaintActiveTabBackground(gfx::Canvas* canvas); |
214 | 210 |
215 // Paints the favicon, media indicator icon, etc., mirrored for RTL if needed. | 211 // Paints the favicon and media indicator icon, mirrored for RTL if needed. |
216 void PaintIcon(gfx::Canvas* canvas); | 212 void PaintIcon(gfx::Canvas* canvas); |
217 void PaintMediaIndicator(gfx::Canvas* canvas); | 213 void PaintMediaIndicator(gfx::Canvas* canvas); |
218 void PaintTitle(gfx::Canvas* canvas, SkColor title_color); | |
219 | 214 |
220 // Invoked if data_.network_state changes, or the network_state is not none. | 215 // Invoked if data_.network_state changes, or the network_state is not none. |
221 void AdvanceLoadingAnimation(TabRendererData::NetworkState old_state, | 216 void AdvanceLoadingAnimation(TabRendererData::NetworkState old_state, |
222 TabRendererData::NetworkState state); | 217 TabRendererData::NetworkState state); |
223 | 218 |
224 // Returns the number of favicon-size elements that can fit in the tab's | 219 // Returns the number of favicon-size elements that can fit in the tab's |
225 // current size. | 220 // current size. |
226 int IconCapacity() const; | 221 int IconCapacity() const; |
227 | 222 |
228 // Returns whether the Tab should display a favicon. | 223 // Returns whether the Tab should display a favicon. |
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
319 scoped_ptr<gfx::LinearAnimation> crash_icon_animation_; | 314 scoped_ptr<gfx::LinearAnimation> crash_icon_animation_; |
320 | 315 |
321 // Media indicator fade-in/out animation (i.e., only on show/hide, not a | 316 // Media indicator fade-in/out animation (i.e., only on show/hide, not a |
322 // continuous animation). | 317 // continuous animation). |
323 scoped_ptr<gfx::Animation> media_indicator_animation_; | 318 scoped_ptr<gfx::Animation> media_indicator_animation_; |
324 TabMediaState animating_media_state_; | 319 TabMediaState animating_media_state_; |
325 | 320 |
326 scoped_refptr<gfx::AnimationContainer> animation_container_; | 321 scoped_refptr<gfx::AnimationContainer> animation_container_; |
327 | 322 |
328 views::ImageButton* close_button_; | 323 views::ImageButton* close_button_; |
| 324 views::Label* title_; |
329 | 325 |
330 bool tab_activated_with_last_gesture_begin_; | 326 bool tab_activated_with_last_gesture_begin_; |
331 | 327 |
332 views::GlowHoverController hover_controller_; | 328 views::GlowHoverController hover_controller_; |
333 | 329 |
334 // The bounds of various sections of the display. | 330 // The bounds of various sections of the display. |
335 gfx::Rect favicon_bounds_; | 331 gfx::Rect favicon_bounds_; |
336 gfx::Rect title_bounds_; | |
337 gfx::Rect media_indicator_bounds_; | 332 gfx::Rect media_indicator_bounds_; |
338 | 333 |
339 // The offset used to paint the inactive background image. | 334 // The offset used to paint the inactive background image. |
340 gfx::Point background_offset_; | 335 gfx::Point background_offset_; |
341 | 336 |
342 struct TabImage { | 337 struct TabImage { |
343 gfx::ImageSkia* image_l; | 338 gfx::ImageSkia* image_l; |
344 gfx::ImageSkia* image_c; | 339 gfx::ImageSkia* image_c; |
345 gfx::ImageSkia* image_r; | 340 gfx::ImageSkia* image_r; |
346 int l_width; | 341 int l_width; |
(...skipping 11 matching lines...) Expand all Loading... |
358 // detect when it changes and layout appropriately. | 353 // detect when it changes and layout appropriately. |
359 bool showing_media_indicator_; | 354 bool showing_media_indicator_; |
360 | 355 |
361 // Whether we are showing the close button. It is cached so that we can | 356 // Whether we are showing the close button. It is cached so that we can |
362 // detect when it changes and layout appropriately. | 357 // detect when it changes and layout appropriately. |
363 bool showing_close_button_; | 358 bool showing_close_button_; |
364 | 359 |
365 // The current color of the close button. | 360 // The current color of the close button. |
366 SkColor close_button_color_; | 361 SkColor close_button_color_; |
367 | 362 |
368 static gfx::Font* font_; | |
369 static int font_height_; | |
370 | |
371 // As the majority of the tabs are inactive, and painting tabs is slowish, | 363 // As the majority of the tabs are inactive, and painting tabs is slowish, |
372 // we cache a handful of the inactive tab backgrounds here. | 364 // we cache a handful of the inactive tab backgrounds here. |
373 static ImageCache* image_cache_; | 365 static ImageCache* image_cache_; |
374 | 366 |
375 DISALLOW_COPY_AND_ASSIGN(Tab); | 367 DISALLOW_COPY_AND_ASSIGN(Tab); |
376 }; | 368 }; |
377 | 369 |
378 #endif // CHROME_BROWSER_UI_VIEWS_TABS_TAB_H_ | 370 #endif // CHROME_BROWSER_UI_VIEWS_TABS_TAB_H_ |
OLD | NEW |