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* CreateBubble(SkBitmap* increase_icon, |
27 SkBitmap* decrease_icon, | |
28 SkBitmap* zero_icon, | |
29 double percent, | |
30 bool enabled); | |
31 | |
32 // Show the setting level bubble for this |widget|. | |
33 static void ShowBubble(views::Widget* widget, | |
34 double percent, | |
35 bool enabled); | |
36 | |
37 virtual ~SettingLevelBubble(); | |
38 | |
39 // BubbleDelegate overrides: | |
40 virtual void Init() OVERRIDE; | |
msw
2011/10/22 00:44:48
BubbleDelegateView::Init is declared protected, th
alicet1
2011/10/24 15:46:38
Done.
| |
41 virtual gfx::Point GetAnchorPoint() const OVERRIDE; | |
42 | |
43 // WidgetDelegate overrides: | |
44 virtual void WindowClosing() OVERRIDE; | |
27 | 45 |
28 // Updates the bubble's current level without showing the bubble onscreen. | 46 // 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 | 47 // We _do_ still animate the level moving to |percent| in case the bubble is |
30 // still visible from a previous call to ShowBubble(). | 48 // still visible from a previous call to ShowBubble(). |
31 // | 49 // |
32 // This can be used when the setting has been changed automatically and we | 50 // 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 | 51 // want to make sure that it's animated from the correct position the next |
34 // time that the bubble is shown. For example: | 52 // time that the bubble is shown. For example: |
35 // | 53 // |
36 // 1. Brightness is at 50%. | 54 // 1. Brightness is at 50%. |
37 // 2. Power manager dims brightness to 25% automatically. | 55 // 2. Power manager dims brightness to 25% automatically. |
38 // 3. User hits the "increase brightness" button, setting brightness to 30%. | 56 // 3. User hits the "increase brightness" button, setting brightness to 30%. |
39 // | 57 // |
40 // If we didn't update our internal state to 25% after 2), then the animation | 58 // 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 | 59 // displayed in response to 3) would show the bubble animating from 50% down |
42 // to 30%, rather than from 25% up to 30%. | 60 // to 30%, rather than from 25% up to 30%. |
43 void UpdateWithoutShowingBubble(double percent, bool enabled); | 61 void UpdateWithoutShowingBubble(double percent, bool enabled); |
44 | 62 |
63 // Start the |hide_timer_| for this bubble. | |
64 void StartHideTimer(); | |
65 | |
45 protected: | 66 protected: |
46 SettingLevelBubble(SkBitmap* increase_icon, | 67 SettingLevelBubble(SkBitmap* increase_icon, |
47 SkBitmap* decrease_icon, | 68 SkBitmap* decrease_icon, |
48 SkBitmap* zero_icon); | 69 SkBitmap* zero_icon, |
49 virtual ~SettingLevelBubble(); | 70 const gfx::Rect& monitor_area); |
50 | 71 |
51 private: | 72 private: |
52 // Overridden from BubbleDelegate. | 73 // Callback for |hide_timer_|. Starts fading out. |
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. | |
58 void OnHideTimeout(); | 74 void OnHideTimeout(); |
59 | 75 |
60 // Callback for |animation_timer_|. Updates the level displayed by the view, | 76 // Callback for |animation_timer_|. Updates the level displayed by the view, |
61 // also stopping the animation if we've reached the target. | 77 // also stopping the animation if we've reached the target. |
62 void OnAnimationTimeout(); | 78 void OnAnimationTimeout(); |
63 | 79 |
64 // Animates towards |percent|. Updates |target_percent_| and starts | 80 // Animates towards |percent|. Updates |target_percent_| and starts |
65 // |animation_timer_| if it's not already running. If this is the first time | 81 // |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 | 82 // that the level is being set, we just update |view_| immediately and don't |
67 // animate. | 83 // animate. |
(...skipping 14 matching lines...) Expand all Loading... | |
82 base::TimeTicks last_animation_update_time_; | 98 base::TimeTicks last_animation_update_time_; |
83 | 99 |
84 // Time at which |target_percent_| was last updated. | 100 // Time at which |target_percent_| was last updated. |
85 base::TimeTicks last_target_update_time_; | 101 base::TimeTicks last_target_update_time_; |
86 | 102 |
87 // Icons displayed in the bubble when increasing or decreasing the level or | 103 // Icons displayed in the bubble when increasing or decreasing the level or |
88 // when it's disabled. Not owned by us. | 104 // when it's disabled. Not owned by us. |
89 SkBitmap* increase_icon_; | 105 SkBitmap* increase_icon_; |
90 SkBitmap* decrease_icon_; | 106 SkBitmap* decrease_icon_; |
91 SkBitmap* disabled_icon_; | 107 SkBitmap* disabled_icon_; |
108 SkBitmap* current_icon_; | |
92 | 109 |
93 // Currently shown bubble or NULL. | 110 bool enabled_; |
msw
2011/10/22 00:44:48
Comment?
alicet1
2011/10/24 15:46:38
Done.
| |
94 Bubble* bubble_; | |
95 | 111 |
96 // Contents view owned by Bubble. | 112 // Contents view owned by Bubble. |
97 SettingLevelBubbleView* view_; | 113 SettingLevelBubbleView* view_; |
98 | 114 |
99 // Timer to hide the bubble. | 115 // Timer to hide the bubble. |
100 base::OneShotTimer<SettingLevelBubble> hide_timer_; | 116 base::OneShotTimer<SettingLevelBubble> hide_timer_; |
101 | 117 |
102 // Timer to animate the currently-shown percent. We use a timer instead of | 118 // Timer to animate the currently-shown percent. We use a timer instead of |
103 // ui::Animation since our animations are frequently interrupted by additional | 119 // ui::Animation since our animations are frequently interrupted by additional |
104 // changes to the level, and ui::Animation doesn't provide much control over | 120 // changes to the level, and ui::Animation doesn't provide much control over |
105 // in-progress animations, leading to mega-jank. | 121 // in-progress animations, leading to mega-jank. |
106 base::RepeatingTimer<SettingLevelBubble> animation_timer_; | 122 base::RepeatingTimer<SettingLevelBubble> animation_timer_; |
107 | 123 |
108 // Is |animation_timer_| currently running? | 124 // Is |animation_timer_| currently running? |
109 bool is_animating_; | 125 bool is_animating_; |
110 | 126 |
127 // |monitor_area_| associated with the top level widget. | |
msw
2011/10/22 00:44:48
I think plain text "Monitor area" makes more sense
alicet1
2011/10/24 15:46:38
Done.
| |
128 gfx::Rect monitor_area_; | |
129 | |
130 // size of the child view. | |
msw
2011/10/22 00:44:48
capitalize 'size'
alicet1
2011/10/24 15:46:38
Done.
| |
131 gfx::Size view_size_; | |
132 | |
111 DISALLOW_COPY_AND_ASSIGN(SettingLevelBubble); | 133 DISALLOW_COPY_AND_ASSIGN(SettingLevelBubble); |
112 }; | 134 }; |
113 | 135 |
114 } // namespace chromeos | 136 } // namespace chromeos |
115 | 137 |
116 #endif // CHROME_BROWSER_CHROMEOS_SETTING_LEVEL_BUBBLE_H_ | 138 #endif // CHROME_BROWSER_CHROMEOS_SETTING_LEVEL_BUBBLE_H_ |
OLD | NEW |