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/time.h" |
11 #include "base/timer.h" | 11 #include "base/timer.h" |
12 #include "chrome/browser/ui/views/bubble/bubble.h" | 12 #include "views/bubble/bubble_delegate.h" |
13 | 13 |
14 class SkBitmap; | 14 class SkBitmap; |
15 | 15 |
16 namespace chromeos { | 16 namespace chromeos { |
17 | 17 |
18 class SettingLevelBubbleView; | 18 class SettingLevelBubbleView; |
19 | 19 |
20 // Singleton class controlling a bubble displaying a level-based setting like | 20 // Singleton class controlling a bubble displaying a level-based setting like |
21 // volume or brightness. | 21 // volume or brightness. |
22 class SettingLevelBubble : public BubbleDelegate { | 22 class SettingLevelBubble : public views::BubbleDelegateView { |
23 public: | 23 public: |
24 // Shows the bubble. |percent| should be in the range [0.0, 100.0]. | 24 // Create the bubble delegate and view. |
25 void ShowBubble(double percent, bool enabled); | 25 // |percent| should be in the range [0.0, 100.0]. |
26 void HideBubble(); | 26 static views::Widget* CreateSettingLevelBubble( |
Daniel Erat
2011/10/21 00:25:21
nit: CreateBubble()?
alicet1
2011/10/21 18:11:36
Done.
| |
27 SkBitmap* increase_icon, | |
28 SkBitmap* decrease_icon, | |
29 SkBitmap* zero_icon, | |
30 double percent, | |
31 bool enabled); | |
32 | |
33 virtual ~SettingLevelBubble(); | |
msw
2011/10/21 02:42:06
The destructor probably belongs below these static
alicet1
2011/10/21 18:11:36
Done.
| |
34 | |
35 // Show the setting level bubble for this |widget|, or if |widget| is | |
36 // null, create and return it also. | |
37 static views::Widget* ShowBubble(views::Widget* widget, | |
Daniel Erat
2011/10/21 00:25:21
the semantics of this method seem strange. i'd re
alicet1
2011/10/21 18:11:36
Done.
| |
38 SkBitmap* increase_icon, | |
39 SkBitmap* decrease_icon, | |
40 SkBitmap* disabled_icon, | |
41 double percent, | |
42 bool enabled); | |
27 | 43 |
28 // Updates the bubble's current level without showing the bubble onscreen. | 44 // 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 | 45 // We _do_ still animate the level moving to |percent| in case the bubble is |
30 // still visible from a previous call to ShowBubble(). | 46 // still visible from a previous call to ShowBubble(). |
31 // | 47 // |
32 // This can be used when the setting has been changed automatically and we | 48 // 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 | 49 // want to make sure that it's animated from the correct position the next |
34 // time that the bubble is shown. For example: | 50 // time that the bubble is shown. For example: |
35 // | 51 // |
36 // 1. Brightness is at 50%. | 52 // 1. Brightness is at 50%. |
37 // 2. Power manager dims brightness to 25% automatically. | 53 // 2. Power manager dims brightness to 25% automatically. |
38 // 3. User hits the "increase brightness" button, setting brightness to 30%. | 54 // 3. User hits the "increase brightness" button, setting brightness to 30%. |
39 // | 55 // |
40 // If we didn't update our internal state to 25% after 2), then the animation | 56 // 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 | 57 // displayed in response to 3) would show the bubble animating from 50% down |
42 // to 30%, rather than from 25% up to 30%. | 58 // to 30%, rather than from 25% up to 30%. |
43 void UpdateWithoutShowingBubble(double percent, bool enabled); | 59 void UpdateWithoutShowingBubble(double percent, bool enabled); |
44 | 60 |
61 // Calculate target percent and icon to be used when setting level changes. | |
62 void UpdateSetting(double percent, bool enabled); | |
63 | |
64 // Start the |hide_timer_| for this bubble. | |
65 void StartHideTimer(); | |
66 | |
67 // BubbleDelegate overrides: | |
Daniel Erat
2011/10/21 00:25:21
i think that other chrome code that i've seen usua
alicet1
2011/10/21 18:11:36
Done.
| |
68 virtual void Init() OVERRIDE; | |
69 gfx::Point GetAnchorPoint() OVERRIDE; | |
70 | |
71 // WidgetDeletgate overrides: | |
Daniel Erat
2011/10/21 00:25:21
WidgetDeletgate -> WidgetDelegate
alicet1
2011/10/21 18:11:36
Done.
| |
72 virtual void WindowClosing() OVERRIDE; | |
73 | |
45 protected: | 74 protected: |
46 SettingLevelBubble(SkBitmap* increase_icon, | 75 SettingLevelBubble(SkBitmap* increase_icon, |
47 SkBitmap* decrease_icon, | 76 SkBitmap* decrease_icon, |
48 SkBitmap* zero_icon); | 77 SkBitmap* zero_icon); |
49 virtual ~SettingLevelBubble(); | |
50 | 78 |
51 private: | 79 private: |
52 // Overridden from BubbleDelegate. | |
53 virtual void BubbleClosing(Bubble* bubble, bool closed_by_escape) OVERRIDE; | |
54 virtual bool CloseOnEscape() OVERRIDE; | |
55 virtual bool FadeInOnShow() OVERRIDE; | |
56 | |
57 // Callback for |hide_timer_|. Closes the bubble. | 80 // Callback for |hide_timer_|. Closes the bubble. |
58 void OnHideTimeout(); | 81 void OnHideTimeout(); |
59 | 82 |
60 // Callback for |animation_timer_|. Updates the level displayed by the view, | 83 // Callback for |animation_timer_|. Updates the level displayed by the view, |
61 // also stopping the animation if we've reached the target. | 84 // also stopping the animation if we've reached the target. |
62 void OnAnimationTimeout(); | 85 void OnAnimationTimeout(); |
63 | 86 |
64 // Animates towards |percent|. Updates |target_percent_| and starts | 87 // Animates towards |percent|. Updates |target_percent_| and starts |
65 // |animation_timer_| if it's not already running. If this is the first time | 88 // |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 | 89 // that the level is being set, we just update |view_| immediately and don't |
(...skipping 15 matching lines...) Expand all Loading... | |
82 base::TimeTicks last_animation_update_time_; | 105 base::TimeTicks last_animation_update_time_; |
83 | 106 |
84 // Time at which |target_percent_| was last updated. | 107 // Time at which |target_percent_| was last updated. |
85 base::TimeTicks last_target_update_time_; | 108 base::TimeTicks last_target_update_time_; |
86 | 109 |
87 // Icons displayed in the bubble when increasing or decreasing the level or | 110 // Icons displayed in the bubble when increasing or decreasing the level or |
88 // when it's disabled. Not owned by us. | 111 // when it's disabled. Not owned by us. |
89 SkBitmap* increase_icon_; | 112 SkBitmap* increase_icon_; |
90 SkBitmap* decrease_icon_; | 113 SkBitmap* decrease_icon_; |
91 SkBitmap* disabled_icon_; | 114 SkBitmap* disabled_icon_; |
115 SkBitmap* current_icon_; | |
92 | 116 |
93 // Currently shown bubble or NULL. | 117 bool enabled_; |
94 Bubble* bubble_; | |
95 | 118 |
96 // Contents view owned by Bubble. | 119 // Contents view owned by Bubble. |
97 SettingLevelBubbleView* view_; | 120 SettingLevelBubbleView* view_; |
98 | 121 |
99 // Timer to hide the bubble. | 122 // Timer to hide the bubble. |
100 base::OneShotTimer<SettingLevelBubble> hide_timer_; | 123 base::OneShotTimer<SettingLevelBubble> hide_timer_; |
101 | 124 |
102 // Timer to animate the currently-shown percent. We use a timer instead of | 125 // Timer to animate the currently-shown percent. We use a timer instead of |
103 // ui::Animation since our animations are frequently interrupted by additional | 126 // ui::Animation since our animations are frequently interrupted by additional |
104 // changes to the level, and ui::Animation doesn't provide much control over | 127 // changes to the level, and ui::Animation doesn't provide much control over |
105 // in-progress animations, leading to mega-jank. | 128 // in-progress animations, leading to mega-jank. |
106 base::RepeatingTimer<SettingLevelBubble> animation_timer_; | 129 base::RepeatingTimer<SettingLevelBubble> animation_timer_; |
107 | 130 |
108 // Is |animation_timer_| currently running? | 131 // Is |animation_timer_| currently running? |
109 bool is_animating_; | 132 bool is_animating_; |
110 | 133 |
111 DISALLOW_COPY_AND_ASSIGN(SettingLevelBubble); | 134 DISALLOW_COPY_AND_ASSIGN(SettingLevelBubble); |
112 }; | 135 }; |
113 | 136 |
114 } // namespace chromeos | 137 } // namespace chromeos |
115 | 138 |
116 #endif // CHROME_BROWSER_CHROMEOS_SETTING_LEVEL_BUBBLE_H_ | 139 #endif // CHROME_BROWSER_CHROMEOS_SETTING_LEVEL_BUBBLE_H_ |
OLD | NEW |