| 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 FRIEND_TEST_ALL_PREFIXES(SettingLevelBubbleTest, CreateAndUpdate); |
| 53 virtual void BubbleClosing(Bubble* bubble, bool closed_by_escape) OVERRIDE; | 59 FRIEND_TEST_ALL_PREFIXES(SettingLevelBubbleTest, ShowBubble); |
| 54 virtual bool CloseOnEscape() OVERRIDE; | 60 FRIEND_TEST_ALL_PREFIXES(BrightnessBubbleTest, UpdateWithoutShowing); |
| 55 virtual bool FadeInOnShow() OVERRIDE; | 61 FRIEND_TEST_ALL_PREFIXES(VolumeBubbleTest, GetInstanceAndShow); |
| 56 | 62 |
| 57 // Callback for |hide_timer_|. Closes the bubble. | 63 // views::Widget::Observer overrides: |
| 64 void OnWidgetClosing(views::Widget* widget) OVERRIDE; |
| 65 |
| 66 // Creates the bubble content view. |
| 67 // Caller should call Init() on the returned SettingLevelBubbleView. |
| 68 SettingLevelBubbleView* CreateView(); |
| 69 |
| 70 // Callback for |hide_timer_|. Starts fading out. |
| 58 void OnHideTimeout(); | 71 void OnHideTimeout(); |
| 59 | 72 |
| 60 // Callback for |animation_timer_|. Updates the level displayed by the view, | 73 // Callback for |animation_timer_|. Updates the level displayed by the view, |
| 61 // also stopping the animation if we've reached the target. | 74 // also stopping the animation if we've reached the target. |
| 62 void OnAnimationTimeout(); | 75 void OnAnimationTimeout(); |
| 63 | 76 |
| 64 // Animates towards |percent|. Updates |target_percent_| and starts | 77 // Animates towards |percent|. Updates |target_percent_| and starts |
| 65 // |animation_timer_| if it's not already running. If this is the first time | 78 // |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 | 79 // that the level is being set, we just update |view_| immediately and don't |
| 67 // animate. | 80 // animate. |
| (...skipping 15 matching lines...) Expand all Loading... |
| 83 | 96 |
| 84 // Time at which |target_percent_| was last updated. | 97 // Time at which |target_percent_| was last updated. |
| 85 base::TimeTicks last_target_update_time_; | 98 base::TimeTicks last_target_update_time_; |
| 86 | 99 |
| 87 // Icons displayed in the bubble when increasing or decreasing the level or | 100 // Icons displayed in the bubble when increasing or decreasing the level or |
| 88 // when it's disabled. Not owned by us. | 101 // when it's disabled. Not owned by us. |
| 89 SkBitmap* increase_icon_; | 102 SkBitmap* increase_icon_; |
| 90 SkBitmap* decrease_icon_; | 103 SkBitmap* decrease_icon_; |
| 91 SkBitmap* disabled_icon_; | 104 SkBitmap* disabled_icon_; |
| 92 | 105 |
| 93 // Currently shown bubble or NULL. | |
| 94 Bubble* bubble_; | |
| 95 | |
| 96 // Contents view owned by Bubble. | 106 // Contents view owned by Bubble. |
| 97 SettingLevelBubbleView* view_; | 107 SettingLevelBubbleView* view_; |
| 98 | 108 |
| 99 // Timer to hide the bubble. | 109 // Timer to hide the bubble. |
| 100 base::OneShotTimer<SettingLevelBubble> hide_timer_; | 110 base::OneShotTimer<SettingLevelBubble> hide_timer_; |
| 101 | 111 |
| 102 // Timer to animate the currently-shown percent. We use a timer instead of | 112 // Timer to animate the currently-shown percent. We use a timer instead of |
| 103 // ui::Animation since our animations are frequently interrupted by additional | 113 // ui::Animation since our animations are frequently interrupted by additional |
| 104 // changes to the level, and ui::Animation doesn't provide much control over | 114 // changes to the level, and ui::Animation doesn't provide much control over |
| 105 // in-progress animations, leading to mega-jank. | 115 // in-progress animations, leading to mega-jank. |
| 106 base::RepeatingTimer<SettingLevelBubble> animation_timer_; | 116 base::RepeatingTimer<SettingLevelBubble> animation_timer_; |
| 107 | 117 |
| 108 // Is |animation_timer_| currently running? | 118 // Is |animation_timer_| currently running? |
| 109 bool is_animating_; | 119 bool is_animating_; |
| 110 | 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 |