OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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_CHROMEOS_SETTING_LEVEL_BUBBLE_H_ | 5 #ifndef CHROME_BROWSER_CHROMEOS_SETTING_LEVEL_BUBBLE_H_ |
6 #define CHROME_BROWSER_CHROMEOS_SETTING_LEVEL_BUBBLE_H_ | 6 #define CHROME_BROWSER_CHROMEOS_SETTING_LEVEL_BUBBLE_H_ |
7 #pragma once | 7 #pragma once |
8 | 8 |
9 #include "base/basictypes.h" | 9 #include "base/basictypes.h" |
| 10 #include "base/time.h" |
10 #include "base/timer.h" | 11 #include "base/timer.h" |
11 #include "chrome/browser/ui/views/bubble/bubble.h" | 12 #include "chrome/browser/ui/views/bubble/bubble.h" |
12 #include "ui/base/animation/animation_delegate.h" | |
13 #include "ui/base/animation/slide_animation.h" | |
14 | 13 |
15 class SkBitmap; | 14 class SkBitmap; |
16 | 15 |
17 namespace chromeos { | 16 namespace chromeos { |
18 | 17 |
19 class SettingLevelBubbleView; | 18 class SettingLevelBubbleView; |
20 | 19 |
21 // Singleton class controlling a bubble displaying a level-based setting like | 20 // Singleton class controlling a bubble displaying a level-based setting like |
22 // volume or brightness. | 21 // volume or brightness. |
23 class SettingLevelBubble : public BubbleDelegate, | 22 class SettingLevelBubble : public BubbleDelegate { |
24 public ui::AnimationDelegate { | |
25 public: | 23 public: |
26 void ShowBubble(int percent, bool enabled); | 24 // Shows the bubble. |percent| should be in the range [0.0, 100.0]. |
| 25 void ShowBubble(double percent, bool enabled); |
27 void HideBubble(); | 26 void HideBubble(); |
28 | 27 |
29 // Update the bubble's current level without showing the bubble onscreen. | 28 // Updates the bubble's current level without showing the bubble onscreen. |
30 // We _do_ still animate the level moving to |percent| in case the bubble is | 29 // We _do_ still animate the level moving to |percent| in case the bubble is |
31 // still visible from a previous call to ShowBubble(). | 30 // still visible from a previous call to ShowBubble(). |
32 // | 31 // |
33 // This can be used when the setting has been changed automatically and we | 32 // This can be used when the setting has been changed automatically and we |
34 // want to make sure that it's animated from the correct position the next | 33 // want to make sure that it's animated from the correct position the next |
35 // time that the bubble is shown. For example: | 34 // time that the bubble is shown. For example: |
36 // | 35 // |
37 // 1. Brightness is at 50%. | 36 // 1. Brightness is at 50%. |
38 // 2. Power manager dims brightness to 25% automatically. | 37 // 2. Power manager dims brightness to 25% automatically. |
39 // 3. User hits the "increase brightness" button, setting brightness to 30%. | 38 // 3. User hits the "increase brightness" button, setting brightness to 30%. |
40 // | 39 // |
41 // If we didn't update our internal state to 25% after 2), then the animation | 40 // If we didn't update our internal state to 25% after 2), then the animation |
42 // displayed in response to 3) would show the bubble animating from 50% down | 41 // displayed in response to 3) would show the bubble animating from 50% down |
43 // to 30%, rather than from 25% up to 30%. | 42 // to 30%, rather than from 25% up to 30%. |
44 void UpdateWithoutShowingBubble(int percent, bool enabled); | 43 void UpdateWithoutShowingBubble(double percent, bool enabled); |
45 | 44 |
46 protected: | 45 protected: |
47 SettingLevelBubble(SkBitmap* increase_icon, | 46 SettingLevelBubble(SkBitmap* increase_icon, |
48 SkBitmap* decrease_icon, | 47 SkBitmap* decrease_icon, |
49 SkBitmap* zero_icon); | 48 SkBitmap* zero_icon); |
50 virtual ~SettingLevelBubble(); | 49 virtual ~SettingLevelBubble(); |
51 | 50 |
52 private: | 51 private: |
53 void OnTimeout(); | |
54 | |
55 // Overridden from BubbleDelegate. | 52 // Overridden from BubbleDelegate. |
56 virtual void BubbleClosing(Bubble* bubble, bool closed_by_escape) OVERRIDE; | 53 virtual void BubbleClosing(Bubble* bubble, bool closed_by_escape) OVERRIDE; |
57 virtual bool CloseOnEscape() OVERRIDE; | 54 virtual bool CloseOnEscape() OVERRIDE; |
58 virtual bool FadeInOnShow() OVERRIDE; | 55 virtual bool FadeInOnShow() OVERRIDE; |
59 | 56 |
60 // Overridden from ui::AnimationDelegate. | 57 // Callback for |hide_timer_|. Closes the bubble. |
61 virtual void AnimationEnded(const ui::Animation* animation) OVERRIDE; | 58 void OnHideTimeout(); |
62 virtual void AnimationProgressed(const ui::Animation* animation) OVERRIDE; | |
63 | 59 |
64 // Previous and current percentages, or -1 if not yet shown. | 60 // Callback for |animation_timer_|. Updates the level displayed by the view, |
65 int previous_percent_; | 61 // also stopping the animation if we've reached the target. |
66 int current_percent_; | 62 void OnAnimationTimeout(); |
| 63 |
| 64 // Animates towards |percent|. Updates |target_percent_| and starts |
| 65 // |animation_timer_| if it's not already running. If this is the first time |
| 66 // that the level is being set, we just update |view_| immediately and don't |
| 67 // animate. |
| 68 void UpdateTargetPercent(double percent); |
| 69 |
| 70 // Stops |animation_timer_| if it's running. |
| 71 void StopAnimation(); |
| 72 |
| 73 // Current and target percentages for the progress bar. In the range |
| 74 // [0.0, 100.0], or -1.0 if not yet shown. |
| 75 double current_percent_; |
| 76 double target_percent_; |
| 77 |
| 78 // Time at which we'll reach |target_percent_|. |
| 79 base::TimeTicks target_time_; |
| 80 |
| 81 // Time at which we last updated |current_percent_|. |
| 82 base::TimeTicks last_animation_update_time_; |
| 83 |
| 84 // Time at which |target_percent_| was last updated. |
| 85 base::TimeTicks last_target_update_time_; |
67 | 86 |
68 // Icons displayed in the bubble when increasing or decreasing the level or | 87 // Icons displayed in the bubble when increasing or decreasing the level or |
69 // when it's disabled. Not owned by us. | 88 // when it's disabled. Not owned by us. |
70 SkBitmap* increase_icon_; | 89 SkBitmap* increase_icon_; |
71 SkBitmap* decrease_icon_; | 90 SkBitmap* decrease_icon_; |
72 SkBitmap* disabled_icon_; | 91 SkBitmap* disabled_icon_; |
73 | 92 |
74 // Currently shown bubble or NULL. | 93 // Currently shown bubble or NULL. |
75 Bubble* bubble_; | 94 Bubble* bubble_; |
76 | 95 |
77 // Its contents view, owned by Bubble. | 96 // Contents view owned by Bubble. |
78 SettingLevelBubbleView* view_; | 97 SettingLevelBubbleView* view_; |
79 | 98 |
80 ui::SlideAnimation animation_; | 99 // Timer to hide the bubble. |
81 base::OneShotTimer<SettingLevelBubble> timeout_timer_; | 100 base::OneShotTimer<SettingLevelBubble> hide_timer_; |
| 101 |
| 102 // Timer to animate the currently-shown percent. We use a timer instead of |
| 103 // ui::Animation since our animations are frequently interrupted by additional |
| 104 // changes to the level, and ui::Animation doesn't provide much control over |
| 105 // in-progress animations, leading to mega-jank. |
| 106 base::RepeatingTimer<SettingLevelBubble> animation_timer_; |
| 107 |
| 108 // Is |animation_timer_| currently running? |
| 109 bool is_animating_; |
82 | 110 |
83 DISALLOW_COPY_AND_ASSIGN(SettingLevelBubble); | 111 DISALLOW_COPY_AND_ASSIGN(SettingLevelBubble); |
84 }; | 112 }; |
85 | 113 |
86 } // namespace chromeos | 114 } // namespace chromeos |
87 | 115 |
88 #endif // CHROME_BROWSER_CHROMEOS_SETTING_LEVEL_BUBBLE_H_ | 116 #endif // CHROME_BROWSER_CHROMEOS_SETTING_LEVEL_BUBBLE_H_ |
OLD | NEW |