Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(265)

Side by Side Diff: chrome/browser/chromeos/setting_level_bubble.h

Issue 8319008: aura: brightness and volume bubble. (Closed) Base URL: http://git.chromium.org/git/chromium.git@trunk
Patch Set: update Created 9 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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"
13 14
14 class SkBitmap; 15 class SkBitmap;
15 16
16 namespace chromeos { 17 namespace chromeos {
17 18
18 class SettingLevelBubbleView; 19 class SettingLevelBubbleView;
19 20
20 // Singleton class controlling a bubble displaying a level-based setting like 21 // Singleton class controlling a bubble displaying a level-based setting like
21 // volume or brightness. 22 // volume or brightness.
22 class SettingLevelBubble : public BubbleDelegate { 23 class SettingLevelBubble : public views::BubbleDelegateView {
23 public: 24 public:
24 // Shows the bubble. |percent| should be in the range [0.0, 100.0]. 25 // Create the bubble delegate and view.
25 void ShowBubble(double percent, bool enabled); 26 // |percent| should be in the range [0.0, 100.0].
26 void HideBubble(); 27 static views::Widget* CreateBubble(SkBitmap* increase_icon,
28 SkBitmap* decrease_icon,
29 SkBitmap* zero_icon,
30 double percent,
31 bool enabled);
32
33 // Show the setting level bubble for this |widget|.
34 static void ShowBubble(views::Widget* widget,
35 double percent,
36 bool enabled);
37
38 virtual ~SettingLevelBubble();
39
40 // BubbleDelegate overrides:
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:
67 // BubbleDelegate overrides:
68 virtual void Init() OVERRIDE;
69
46 SettingLevelBubble(SkBitmap* increase_icon, 70 SettingLevelBubble(SkBitmap* increase_icon,
47 SkBitmap* decrease_icon, 71 SkBitmap* decrease_icon,
48 SkBitmap* zero_icon); 72 SkBitmap* zero_icon,
49 virtual ~SettingLevelBubble(); 73 const gfx::Rect& monitor_area);
50 74
51 private: 75 private:
52 // Overridden from BubbleDelegate. 76 // 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(); 77 void OnHideTimeout();
59 78
60 // Callback for |animation_timer_|. Updates the level displayed by the view, 79 // Callback for |animation_timer_|. Updates the level displayed by the view,
61 // also stopping the animation if we've reached the target. 80 // also stopping the animation if we've reached the target.
62 void OnAnimationTimeout(); 81 void OnAnimationTimeout();
63 82
64 // Animates towards |percent|. Updates |target_percent_| and starts 83 // Animates towards |percent|. Updates |target_percent_| and starts
65 // |animation_timer_| if it's not already running. If this is the first time 84 // |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 85 // that the level is being set, we just update |view_| immediately and don't
67 // animate. 86 // animate.
(...skipping 14 matching lines...) Expand all
82 base::TimeTicks last_animation_update_time_; 101 base::TimeTicks last_animation_update_time_;
83 102
84 // Time at which |target_percent_| was last updated. 103 // Time at which |target_percent_| was last updated.
85 base::TimeTicks last_target_update_time_; 104 base::TimeTicks last_target_update_time_;
86 105
87 // Icons displayed in the bubble when increasing or decreasing the level or 106 // Icons displayed in the bubble when increasing or decreasing the level or
88 // when it's disabled. Not owned by us. 107 // when it's disabled. Not owned by us.
89 SkBitmap* increase_icon_; 108 SkBitmap* increase_icon_;
90 SkBitmap* decrease_icon_; 109 SkBitmap* decrease_icon_;
91 SkBitmap* disabled_icon_; 110 SkBitmap* disabled_icon_;
111 SkBitmap* current_icon_;
92 112
93 // Currently shown bubble or NULL. 113 // Whether the content view, when shown, should be set to |enabled|.
94 Bubble* bubble_; 114 bool enabled_;
95 115
96 // Contents view owned by Bubble. 116 // Contents view owned by Bubble.
97 SettingLevelBubbleView* view_; 117 SettingLevelBubbleView* view_;
98 118
99 // Timer to hide the bubble. 119 // Timer to hide the bubble.
100 base::OneShotTimer<SettingLevelBubble> hide_timer_; 120 base::OneShotTimer<SettingLevelBubble> hide_timer_;
101 121
102 // Timer to animate the currently-shown percent. We use a timer instead of 122 // Timer to animate the currently-shown percent. We use a timer instead of
103 // ui::Animation since our animations are frequently interrupted by additional 123 // ui::Animation since our animations are frequently interrupted by additional
104 // changes to the level, and ui::Animation doesn't provide much control over 124 // changes to the level, and ui::Animation doesn't provide much control over
105 // in-progress animations, leading to mega-jank. 125 // in-progress animations, leading to mega-jank.
106 base::RepeatingTimer<SettingLevelBubble> animation_timer_; 126 base::RepeatingTimer<SettingLevelBubble> animation_timer_;
107 127
108 // Is |animation_timer_| currently running? 128 // Is |animation_timer_| currently running?
109 bool is_animating_; 129 bool is_animating_;
110 130
131 // Monitor area associated with the top level widget.
132 gfx::Rect monitor_area_;
133
134 // Size of the child view.
135 gfx::Size view_size_;
136
137 FRIEND_TEST_ALL_PREFIXES(SettingLevelBubbleTest, CreateAndUpdate);
138 FRIEND_TEST_ALL_PREFIXES(SettingLevelBubbleTest, ShowBubble);
139
111 DISALLOW_COPY_AND_ASSIGN(SettingLevelBubble); 140 DISALLOW_COPY_AND_ASSIGN(SettingLevelBubble);
112 }; 141 };
113 142
114 } // namespace chromeos 143 } // namespace chromeos
115 144
116 #endif // CHROME_BROWSER_CHROMEOS_SETTING_LEVEL_BUBBLE_H_ 145 #endif // CHROME_BROWSER_CHROMEOS_SETTING_LEVEL_BUBBLE_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698