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/gtest_prod_util.h" | 11 #include "base/gtest_prod_util.h" |
12 #include "base/macros.h" | 12 #include "base/macros.h" |
13 #include "base/memory/ref_counted.h" | 13 #include "base/memory/ref_counted.h" |
14 #include "base/memory/scoped_ptr.h" | 14 #include "base/memory/scoped_ptr.h" |
15 #include "chrome/browser/ui/views/tabs/tab_renderer_data.h" | 15 #include "chrome/browser/ui/views/tabs/tab_renderer_data.h" |
16 #include "ui/base/layout.h" | 16 #include "ui/base/layout.h" |
17 #include "ui/gfx/animation/animation_delegate.h" | 17 #include "ui/gfx/animation/animation_delegate.h" |
18 #include "ui/gfx/geometry/point.h" | 18 #include "ui/gfx/geometry/point.h" |
19 #include "ui/gfx/paint_throbber.h" | 19 #include "ui/gfx/paint_throbber.h" |
20 #include "ui/views/context_menu_controller.h" | 20 #include "ui/views/context_menu_controller.h" |
21 #include "ui/views/controls/button/button.h" | 21 #include "ui/views/controls/button/button.h" |
22 #include "ui/views/controls/glow_hover_controller.h" | 22 #include "ui/views/controls/glow_hover_controller.h" |
23 #include "ui/views/masked_targeter_delegate.h" | 23 #include "ui/views/masked_targeter_delegate.h" |
24 #include "ui/views/view.h" | 24 #include "ui/views/view.h" |
25 | 25 |
26 class MediaIndicatorButton; | 26 class AlertIndicatorButton; |
27 class TabController; | 27 class TabController; |
28 | 28 |
29 namespace gfx { | 29 namespace gfx { |
30 class Animation; | 30 class Animation; |
31 class AnimationContainer; | 31 class AnimationContainer; |
32 class LinearAnimation; | 32 class LinearAnimation; |
33 class MultiAnimation; | 33 class MultiAnimation; |
34 class ThrobAnimation; | 34 class ThrobAnimation; |
35 } | 35 } |
36 namespace views { | 36 namespace views { |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
68 // Used to mark the tab as having been detached. Once this has happened, the | 68 // Used to mark the tab as having been detached. Once this has happened, the |
69 // tab should be invisibly closed. This is irreversible. | 69 // tab should be invisibly closed. This is irreversible. |
70 void set_detached() { detached_ = true; } | 70 void set_detached() { detached_ = true; } |
71 bool detached() const { return detached_; } | 71 bool detached() const { return detached_; } |
72 | 72 |
73 SkColor button_color() const { return button_color_; } | 73 SkColor button_color() const { return button_color_; } |
74 | 74 |
75 // Returns true if this tab is the active tab. | 75 // Returns true if this tab is the active tab. |
76 bool IsActive() const; | 76 bool IsActive() const; |
77 | 77 |
78 // Notifies the MediaIndicatorButton that the active state of this tab has | 78 // Notifies the AlertIndicatorButton that the active state of this tab has |
79 // changed. | 79 // changed. |
80 void ActiveStateChanged(); | 80 void ActiveStateChanged(); |
81 | 81 |
82 // Called when the media indicator has changed states. | 82 // Called when the alert indicator has changed states. |
83 void MediaStateChanged(); | 83 void AlertStateChanged(); |
84 | 84 |
85 // Returns true if the tab is selected. | 85 // Returns true if the tab is selected. |
86 bool IsSelected() const; | 86 bool IsSelected() const; |
87 | 87 |
88 // Sets the data this tabs displays. Invokes DataChanged. Should only be | 88 // Sets the data this tabs displays. Invokes DataChanged. Should only be |
89 // called after Tab is added to widget hierarchy. | 89 // called after Tab is added to widget hierarchy. |
90 void SetData(const TabRendererData& data); | 90 void SetData(const TabRendererData& data); |
91 const TabRendererData& data() const { return data_; } | 91 const TabRendererData& data() const { return data_; } |
92 | 92 |
93 // Sets the network state. | 93 // Sets the network state. |
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
166 // Returns the inverse of the slope of the diagonal portion of the tab outer | 166 // Returns the inverse of the slope of the diagonal portion of the tab outer |
167 // border. (This is a positive value, so it's specifically for the slope of | 167 // border. (This is a positive value, so it's specifically for the slope of |
168 // the leading edge.) | 168 // the leading edge.) |
169 // | 169 // |
170 // This returns the inverse (dx/dy instead of dy/dx) because we use exact | 170 // This returns the inverse (dx/dy instead of dy/dx) because we use exact |
171 // values for the vertical distances between points and then compute the | 171 // values for the vertical distances between points and then compute the |
172 // horizontal deltas from those. | 172 // horizontal deltas from those. |
173 static float GetInverseDiagonalSlope(); | 173 static float GetInverseDiagonalSlope(); |
174 | 174 |
175 private: | 175 private: |
176 friend class MediaIndicatorButtonTest; | 176 friend class AlertIndicatorButtonTest; |
177 friend class TabTest; | 177 friend class TabTest; |
178 friend class TabStripTest; | 178 friend class TabStripTest; |
179 FRIEND_TEST_ALL_PREFIXES(TabStripTest, TabHitTestMaskWhenStacked); | 179 FRIEND_TEST_ALL_PREFIXES(TabStripTest, TabHitTestMaskWhenStacked); |
180 FRIEND_TEST_ALL_PREFIXES(TabStripTest, TabCloseButtonVisibilityWhenStacked); | 180 FRIEND_TEST_ALL_PREFIXES(TabStripTest, TabCloseButtonVisibilityWhenStacked); |
181 | 181 |
182 // The animation object used to swap the favicon with the sad tab icon. | 182 // The animation object used to swap the favicon with the sad tab icon. |
183 class FaviconCrashAnimation; | 183 class FaviconCrashAnimation; |
184 | 184 |
185 class TabCloseButton; | 185 class TabCloseButton; |
186 class ThrobberView; | 186 class ThrobberView; |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
224 void OnMouseReleased(const ui::MouseEvent& event) override; | 224 void OnMouseReleased(const ui::MouseEvent& event) override; |
225 void OnMouseCaptureLost() override; | 225 void OnMouseCaptureLost() override; |
226 void OnMouseEntered(const ui::MouseEvent& event) override; | 226 void OnMouseEntered(const ui::MouseEvent& event) override; |
227 void OnMouseMoved(const ui::MouseEvent& event) override; | 227 void OnMouseMoved(const ui::MouseEvent& event) override; |
228 void OnMouseExited(const ui::MouseEvent& event) override; | 228 void OnMouseExited(const ui::MouseEvent& event) override; |
229 void GetAccessibleState(ui::AXViewState* state) override; | 229 void GetAccessibleState(ui::AXViewState* state) override; |
230 | 230 |
231 // ui::EventHandler: | 231 // ui::EventHandler: |
232 void OnGestureEvent(ui::GestureEvent* event) override; | 232 void OnGestureEvent(ui::GestureEvent* event) override; |
233 | 233 |
234 // Invoked from Layout to adjust the position of the favicon or media | 234 // Invoked from Layout to adjust the position of the favicon or alert |
235 // indicator for pinned tabs. | 235 // indicator for pinned tabs. |
236 void MaybeAdjustLeftForPinnedTab(gfx::Rect* bounds) const; | 236 void MaybeAdjustLeftForPinnedTab(gfx::Rect* bounds) const; |
237 | 237 |
238 // Invoked from SetData after |data_| has been updated to the new data. | 238 // Invoked from SetData after |data_| has been updated to the new data. |
239 void DataChanged(const TabRendererData& old); | 239 void DataChanged(const TabRendererData& old); |
240 | 240 |
241 // Paint with the normal tab style. | 241 // Paint with the normal tab style. |
242 void PaintTab(gfx::Canvas* canvas); | 242 void PaintTab(gfx::Canvas* canvas); |
243 | 243 |
244 // Paint with the "immersive mode" light-bar style. | 244 // Paint with the "immersive mode" light-bar style. |
(...skipping 20 matching lines...) Expand all Loading... |
265 // Invoked if data_.network_state changes, or the network_state is not none. | 265 // Invoked if data_.network_state changes, or the network_state is not none. |
266 void AdvanceLoadingAnimation(); | 266 void AdvanceLoadingAnimation(); |
267 | 267 |
268 // Returns the number of favicon-size elements that can fit in the tab's | 268 // Returns the number of favicon-size elements that can fit in the tab's |
269 // current size. | 269 // current size. |
270 int IconCapacity() const; | 270 int IconCapacity() const; |
271 | 271 |
272 // Returns whether the Tab should display a favicon. | 272 // Returns whether the Tab should display a favicon. |
273 bool ShouldShowIcon() const; | 273 bool ShouldShowIcon() const; |
274 | 274 |
275 // Returns whether the Tab should display the media indicator. | 275 // Returns whether the Tab should display the alert indicator. |
276 bool ShouldShowMediaIndicator() const; | 276 bool ShouldShowAlertIndicator() const; |
277 | 277 |
278 // Returns whether the Tab should display a close button. | 278 // Returns whether the Tab should display a close button. |
279 bool ShouldShowCloseBox() const; | 279 bool ShouldShowCloseBox() const; |
280 | 280 |
281 // Returns whether the tab should be rendered as a normal tab as opposed to a | 281 // Returns whether the tab should be rendered as a normal tab as opposed to a |
282 // pinned tab. | 282 // pinned tab. |
283 bool ShouldRenderAsNormalTab() const; | 283 bool ShouldRenderAsNormalTab() const; |
284 | 284 |
285 // Gets the throb value for the tab. When a tab is not selected the | 285 // Gets the throb value for the tab. When a tab is not selected the |
286 // active background is drawn at |GetThrobValue()|%. This is used for hover, | 286 // active background is drawn at |GetThrobValue()|%. This is used for hover, |
287 // mini tab title change and pulsing. | 287 // mini tab title change and pulsing. |
288 double GetThrobValue(); | 288 double GetThrobValue(); |
289 | 289 |
290 // Set the temporary offset for the favicon. This is used during the crash | 290 // Set the temporary offset for the favicon. This is used during the crash |
291 // animation. | 291 // animation. |
292 void SetFaviconHidingOffset(int offset); | 292 void SetFaviconHidingOffset(int offset); |
293 | 293 |
294 void set_should_display_crashed_favicon() { | 294 void set_should_display_crashed_favicon() { |
295 should_display_crashed_favicon_ = true; | 295 should_display_crashed_favicon_ = true; |
296 } | 296 } |
297 | 297 |
298 // Recalculates the correct |button_color_| and resets the title, media | 298 // Recalculates the correct |button_color_| and resets the title, alert |
299 // indicator, and close button colors if necessary. This should be called any | 299 // indicator, and close button colors if necessary. This should be called any |
300 // time the theme or active state may have changed. | 300 // time the theme or active state may have changed. |
301 void OnButtonColorMaybeChanged(); | 301 void OnButtonColorMaybeChanged(); |
302 | 302 |
303 // Schedules repaint task for icon. | 303 // Schedules repaint task for icon. |
304 void ScheduleIconPaint(); | 304 void ScheduleIconPaint(); |
305 | 305 |
306 // Computes a path corresponding to the tab's content region inside the outer | 306 // Computes a path corresponding to the tab's content region inside the outer |
307 // stroke. | 307 // stroke. |
308 void GetFillPath(float scale, SkPath* path) const; | 308 void GetFillPath(float scale, SkPath* path) const; |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
349 scoped_ptr<gfx::ThrobAnimation> pulse_animation_; | 349 scoped_ptr<gfx::ThrobAnimation> pulse_animation_; |
350 | 350 |
351 scoped_ptr<gfx::MultiAnimation> pinned_title_change_animation_; | 351 scoped_ptr<gfx::MultiAnimation> pinned_title_change_animation_; |
352 | 352 |
353 // Crash icon animation (in place of favicon). | 353 // Crash icon animation (in place of favicon). |
354 scoped_ptr<gfx::LinearAnimation> crash_icon_animation_; | 354 scoped_ptr<gfx::LinearAnimation> crash_icon_animation_; |
355 | 355 |
356 scoped_refptr<gfx::AnimationContainer> animation_container_; | 356 scoped_refptr<gfx::AnimationContainer> animation_container_; |
357 | 357 |
358 ThrobberView* throbber_; | 358 ThrobberView* throbber_; |
359 MediaIndicatorButton* media_indicator_button_; | 359 AlertIndicatorButton* alert_indicator_button_; |
360 views::ImageButton* close_button_; | 360 views::ImageButton* close_button_; |
361 views::Label* title_; | 361 views::Label* title_; |
362 | 362 |
363 bool tab_activated_with_last_tap_down_; | 363 bool tab_activated_with_last_tap_down_; |
364 | 364 |
365 views::GlowHoverController hover_controller_; | 365 views::GlowHoverController hover_controller_; |
366 | 366 |
367 // The bounds of various sections of the display. | 367 // The bounds of various sections of the display. |
368 gfx::Rect favicon_bounds_; | 368 gfx::Rect favicon_bounds_; |
369 | 369 |
370 // The offset used to paint the inactive background image. | 370 // The offset used to paint the inactive background image. |
371 gfx::Point background_offset_; | 371 gfx::Point background_offset_; |
372 | 372 |
373 struct TabImages { | 373 struct TabImages { |
374 gfx::ImageSkia* image_l; | 374 gfx::ImageSkia* image_l; |
375 gfx::ImageSkia* image_c; | 375 gfx::ImageSkia* image_c; |
376 gfx::ImageSkia* image_r; | 376 gfx::ImageSkia* image_r; |
377 int l_width; | 377 int l_width; |
378 int r_width; | 378 int r_width; |
379 }; | 379 }; |
380 static TabImages active_images_; | 380 static TabImages active_images_; |
381 static TabImages inactive_images_; | 381 static TabImages inactive_images_; |
382 static TabImages mask_images_; | 382 static TabImages mask_images_; |
383 | 383 |
384 // Whether we're showing the icon. It is cached so that we can detect when it | 384 // Whether we're showing the icon. It is cached so that we can detect when it |
385 // changes and layout appropriately. | 385 // changes and layout appropriately. |
386 bool showing_icon_; | 386 bool showing_icon_; |
387 | 387 |
388 // Whether we're showing the media indicator. It is cached so that we can | 388 // Whether we're showing the alert indicator. It is cached so that we can |
389 // detect when it changes and layout appropriately. | 389 // detect when it changes and layout appropriately. |
390 bool showing_media_indicator_; | 390 bool showing_alert_indicator_; |
391 | 391 |
392 // Whether we are showing the close button. It is cached so that we can | 392 // Whether we are showing the close button. It is cached so that we can |
393 // detect when it changes and layout appropriately. | 393 // detect when it changes and layout appropriately. |
394 bool showing_close_button_; | 394 bool showing_close_button_; |
395 | 395 |
396 // The current color of the media indicator and close button icons. | 396 // The current color of the alert indicator and close button icons. |
397 SkColor button_color_; | 397 SkColor button_color_; |
398 | 398 |
399 // As the majority of the tabs are inactive, and painting tabs is slowish, | 399 // As the majority of the tabs are inactive, and painting tabs is slowish, |
400 // we cache a handful of the inactive tab backgrounds here. | 400 // we cache a handful of the inactive tab backgrounds here. |
401 static ImageCache* image_cache_; | 401 static ImageCache* image_cache_; |
402 | 402 |
403 DISALLOW_COPY_AND_ASSIGN(Tab); | 403 DISALLOW_COPY_AND_ASSIGN(Tab); |
404 }; | 404 }; |
405 | 405 |
406 #endif // CHROME_BROWSER_UI_VIEWS_TABS_TAB_H_ | 406 #endif // CHROME_BROWSER_UI_VIEWS_TABS_TAB_H_ |
OLD | NEW |