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/gtest_prod_util.h" |
10 #include "base/time.h" | 11 #include "base/time.h" |
11 #include "base/timer.h" | 12 #include "base/timer.h" |
12 #include "chrome/browser/ui/views/bubble/bubble.h" | 13 #include "views/bubble/bubble_delegate.h" |
| 14 #include "views/widget/widget.h" |
13 | 15 |
14 class SkBitmap; | 16 class SkBitmap; |
15 | 17 |
16 namespace chromeos { | 18 namespace chromeos { |
17 | 19 |
18 class SettingLevelBubbleView; | 20 class SettingLevelBubbleView; |
19 | 21 |
20 // Singleton class controlling a bubble displaying a level-based setting like | 22 // Controls a bubble displaying a level-based setting like |
21 // volume or brightness. | 23 // volume or brightness. |
22 class SettingLevelBubble : public BubbleDelegate { | 24 class SettingLevelBubble : public views::Widget::Observer { |
23 public: | 25 public: |
24 // Shows the bubble. |percent| should be in the range [0.0, 100.0]. | 26 // Shows the bubble with the target |percent| and |enabled| setting. |
| 27 // |percent| should be in the range [0.0, 100.0]. |
25 void ShowBubble(double percent, bool enabled); | 28 void ShowBubble(double percent, bool enabled); |
| 29 |
| 30 // Hides the Bubble, closing the view. |
26 void HideBubble(); | 31 void HideBubble(); |
27 | 32 |
28 // Updates the bubble's current level without showing the bubble onscreen. | 33 // Updates the bubble's current level without showing the bubble onscreen. |
29 // We _do_ still animate the level moving to |percent| in case the bubble is | 34 // We _do_ still animate the level moving to |percent| in case the bubble is |
30 // still visible from a previous call to ShowBubble(). | 35 // still visible from a previous call to ShowBubble(). |
31 // | 36 // |
32 // This can be used when the setting has been changed automatically and we | 37 // This can be used when the setting has been changed automatically and we |
33 // want to make sure that it's animated from the correct position the next | 38 // want to make sure that it's animated from the correct position the next |
34 // time that the bubble is shown. For example: | 39 // time that the bubble is shown. For example: |
35 // | 40 // |
36 // 1. Brightness is at 50%. | 41 // 1. Brightness is at 50%. |
37 // 2. Power manager dims brightness to 25% automatically. | 42 // 2. Power manager dims brightness to 25% automatically. |
38 // 3. User hits the "increase brightness" button, setting brightness to 30%. | 43 // 3. User hits the "increase brightness" button, setting brightness to 30%. |
39 // | 44 // |
40 // If we didn't update our internal state to 25% after 2), then the animation | 45 // If we didn't update our internal state to 25% after 2), then the animation |
41 // displayed in response to 3) would show the bubble animating from 50% down | 46 // displayed in response to 3) would show the bubble animating from 50% down |
42 // to 30%, rather than from 25% up to 30%. | 47 // to 30%, rather than from 25% up to 30%. |
43 void UpdateWithoutShowingBubble(double percent, bool enabled); | 48 void UpdateWithoutShowingBubble(double percent, bool enabled); |
44 | 49 |
45 protected: | 50 protected: |
46 SettingLevelBubble(SkBitmap* increase_icon, | 51 SettingLevelBubble(SkBitmap* increase_icon, |
47 SkBitmap* decrease_icon, | 52 SkBitmap* decrease_icon, |
48 SkBitmap* zero_icon); | 53 SkBitmap* zero_icon); |
| 54 |
49 virtual ~SettingLevelBubble(); | 55 virtual ~SettingLevelBubble(); |
50 | 56 |
51 private: | 57 private: |
52 // Overridden from BubbleDelegate. | 58 // views::Widget::Observer overrides: |
53 virtual void BubbleClosing(Bubble* bubble, bool closed_by_escape) OVERRIDE; | 59 void OnWidgetClosing(views::Widget* widget) OVERRIDE; |
54 virtual bool CloseOnEscape() OVERRIDE; | |
55 virtual bool FadeInOnShow() OVERRIDE; | |
56 | 60 |
57 // Callback for |hide_timer_|. Closes the bubble. | 61 // Creates the bubble content view. |
| 62 // Caller should call Init() on the returned SettingLevelBubbleView. |
| 63 SettingLevelBubbleView* CreateView(); |
| 64 |
| 65 // Callback for |hide_timer_|. Starts fading out. |
58 void OnHideTimeout(); | 66 void OnHideTimeout(); |
59 | 67 |
60 // Callback for |animation_timer_|. Updates the level displayed by the view, | 68 // Callback for |animation_timer_|. Updates the level displayed by the view, |
61 // also stopping the animation if we've reached the target. | 69 // also stopping the animation if we've reached the target. |
62 void OnAnimationTimeout(); | 70 void OnAnimationTimeout(); |
63 | 71 |
64 // Animates towards |percent|. Updates |target_percent_| and starts | 72 // Animates towards |percent|. Updates |target_percent_| and starts |
65 // |animation_timer_| if it's not already running. If this is the first time | 73 // |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 | 74 // that the level is being set, we just update |view_| immediately and don't |
67 // animate. | 75 // animate. |
(...skipping 15 matching lines...) Expand all Loading... |
83 | 91 |
84 // Time at which |target_percent_| was last updated. | 92 // Time at which |target_percent_| was last updated. |
85 base::TimeTicks last_target_update_time_; | 93 base::TimeTicks last_target_update_time_; |
86 | 94 |
87 // Icons displayed in the bubble when increasing or decreasing the level or | 95 // Icons displayed in the bubble when increasing or decreasing the level or |
88 // when it's disabled. Not owned by us. | 96 // when it's disabled. Not owned by us. |
89 SkBitmap* increase_icon_; | 97 SkBitmap* increase_icon_; |
90 SkBitmap* decrease_icon_; | 98 SkBitmap* decrease_icon_; |
91 SkBitmap* disabled_icon_; | 99 SkBitmap* disabled_icon_; |
92 | 100 |
93 // Currently shown bubble or NULL. | |
94 Bubble* bubble_; | |
95 | |
96 // Contents view owned by Bubble. | 101 // Contents view owned by Bubble. |
97 SettingLevelBubbleView* view_; | 102 SettingLevelBubbleView* view_; |
98 | 103 |
99 // Timer to hide the bubble. | 104 // Timer to hide the bubble. |
100 base::OneShotTimer<SettingLevelBubble> hide_timer_; | 105 base::OneShotTimer<SettingLevelBubble> hide_timer_; |
101 | 106 |
102 // Timer to animate the currently-shown percent. We use a timer instead of | 107 // Timer to animate the currently-shown percent. We use a timer instead of |
103 // ui::Animation since our animations are frequently interrupted by additional | 108 // ui::Animation since our animations are frequently interrupted by additional |
104 // changes to the level, and ui::Animation doesn't provide much control over | 109 // changes to the level, and ui::Animation doesn't provide much control over |
105 // in-progress animations, leading to mega-jank. | 110 // in-progress animations, leading to mega-jank. |
106 base::RepeatingTimer<SettingLevelBubble> animation_timer_; | 111 base::RepeatingTimer<SettingLevelBubble> animation_timer_; |
107 | 112 |
108 // Is |animation_timer_| currently running? | 113 // Is |animation_timer_| currently running? |
109 bool is_animating_; | 114 bool is_animating_; |
110 | 115 |
| 116 FRIEND_TEST_ALL_PREFIXES(SettingLevelBubbleTest, CreateAndUpdate); |
| 117 FRIEND_TEST_ALL_PREFIXES(SettingLevelBubbleTest, ShowBubble); |
| 118 FRIEND_TEST_ALL_PREFIXES(BrightnessBubbleTest, UpdateWithoutShowing); |
| 119 FRIEND_TEST_ALL_PREFIXES(VolumeBubbleTest, GetInstanceAndShow); |
| 120 |
111 DISALLOW_COPY_AND_ASSIGN(SettingLevelBubble); | 121 DISALLOW_COPY_AND_ASSIGN(SettingLevelBubble); |
112 }; | 122 }; |
113 | 123 |
114 } // namespace chromeos | 124 } // namespace chromeos |
115 | 125 |
116 #endif // CHROME_BROWSER_CHROMEOS_SETTING_LEVEL_BUBBLE_H_ | 126 #endif // CHROME_BROWSER_CHROMEOS_SETTING_LEVEL_BUBBLE_H_ |
OLD | NEW |