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