| 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/timer.h" | 10 #include "base/timer.h" |
| 11 #include "chrome/browser/ui/views/bubble/bubble.h" | 11 #include "chrome/browser/ui/views/bubble/bubble.h" |
| 12 #include "ui/base/animation/animation_delegate.h" | 12 #include "ui/base/animation/animation_delegate.h" |
| 13 #include "ui/base/animation/slide_animation.h" | 13 #include "ui/base/animation/slide_animation.h" |
| 14 | 14 |
| 15 class SkBitmap; | 15 class SkBitmap; |
| 16 | 16 |
| 17 namespace chromeos { | 17 namespace chromeos { |
| 18 | 18 |
| 19 class SettingLevelBubbleView; | 19 class SettingLevelBubbleView; |
| 20 | 20 |
| 21 // Singleton class controlling a bubble displaying a level-based setting like | 21 // Singleton class controlling a bubble displaying a level-based setting like |
| 22 // volume or brightness. | 22 // volume or brightness. |
| 23 class SettingLevelBubble : public BubbleDelegate, | 23 class SettingLevelBubble : public BubbleDelegate, |
| 24 public ui::AnimationDelegate { | 24 public ui::AnimationDelegate { |
| 25 public: | 25 public: |
| 26 void ShowBubble(int percent); | 26 void ShowBubble(int percent, bool enabled); |
| 27 void HideBubble(); | 27 void HideBubble(); |
| 28 | 28 |
| 29 // Update the bubble's current level without showing the bubble onscreen. | 29 // Update the bubble's current level without showing the bubble onscreen. |
| 30 // We _do_ still animate the level moving to |percent| in case the bubble is | 30 // We _do_ still animate the level moving to |percent| in case the bubble is |
| 31 // still visible from a previous call to ShowBubble(). | 31 // still visible from a previous call to ShowBubble(). |
| 32 // | 32 // |
| 33 // This can be used when the setting has been changed automatically and we | 33 // This can be used when the setting has been changed automatically and we |
| 34 // want to make sure that it's animated from the correct position the next | 34 // want to make sure that it's animated from the correct position the next |
| 35 // time that the bubble is shown. For example: | 35 // time that the bubble is shown. For example: |
| 36 // | 36 // |
| 37 // 1. Brightness is at 50%. | 37 // 1. Brightness is at 50%. |
| 38 // 2. Power manager dims brightness to 25% automatically. | 38 // 2. Power manager dims brightness to 25% automatically. |
| 39 // 3. User hits the "increase brightness" button, setting brightness to 30%. | 39 // 3. User hits the "increase brightness" button, setting brightness to 30%. |
| 40 // | 40 // |
| 41 // If we didn't update our internal state to 25% after 2), then the animation | 41 // If we didn't update our internal state to 25% after 2), then the animation |
| 42 // displayed in response to 3) would show the bubble animating from 50% down | 42 // displayed in response to 3) would show the bubble animating from 50% down |
| 43 // to 30%, rather than from 25% up to 30%. | 43 // to 30%, rather than from 25% up to 30%. |
| 44 void UpdateWithoutShowingBubble(int percent); | 44 void UpdateWithoutShowingBubble(int percent, bool enabled); |
| 45 | 45 |
| 46 protected: | 46 protected: |
| 47 SettingLevelBubble(SkBitmap* increase_icon, | 47 SettingLevelBubble(SkBitmap* increase_icon, |
| 48 SkBitmap* decrease_icon, | 48 SkBitmap* decrease_icon, |
| 49 SkBitmap* zero_icon); | 49 SkBitmap* zero_icon); |
| 50 virtual ~SettingLevelBubble(); | 50 virtual ~SettingLevelBubble(); |
| 51 | 51 |
| 52 private: | 52 private: |
| 53 void OnTimeout(); | 53 void OnTimeout(); |
| 54 | 54 |
| 55 // Overridden from BubbleDelegate. | 55 // Overridden from BubbleDelegate. |
| 56 virtual void BubbleClosing(Bubble* bubble, bool closed_by_escape); | 56 virtual void BubbleClosing(Bubble* bubble, bool closed_by_escape) OVERRIDE; |
| 57 virtual bool CloseOnEscape(); | 57 virtual bool CloseOnEscape() OVERRIDE; |
| 58 virtual bool FadeInOnShow(); | 58 virtual bool FadeInOnShow() OVERRIDE; |
| 59 | 59 |
| 60 // Overridden from ui::AnimationDelegate. | 60 // Overridden from ui::AnimationDelegate. |
| 61 virtual void AnimationEnded(const ui::Animation* animation); | 61 virtual void AnimationEnded(const ui::Animation* animation) OVERRIDE; |
| 62 virtual void AnimationProgressed(const ui::Animation* animation); | 62 virtual void AnimationProgressed(const ui::Animation* animation) OVERRIDE; |
| 63 | 63 |
| 64 // Previous and current percentages, or -1 if not yet shown. | 64 // Previous and current percentages, or -1 if not yet shown. |
| 65 int previous_percent_; | 65 int previous_percent_; |
| 66 int current_percent_; | 66 int current_percent_; |
| 67 | 67 |
| 68 // Icons displayed in the bubble when increasing or decreasing the level or | 68 // Icons displayed in the bubble when increasing or decreasing the level or |
| 69 // setting it to zero. Not owned by us. | 69 // when it's disabled. Not owned by us. |
| 70 SkBitmap* increase_icon_; | 70 SkBitmap* increase_icon_; |
| 71 SkBitmap* decrease_icon_; | 71 SkBitmap* decrease_icon_; |
| 72 SkBitmap* zero_icon_; | 72 SkBitmap* disabled_icon_; |
| 73 | 73 |
| 74 // Currently shown bubble or NULL. | 74 // Currently shown bubble or NULL. |
| 75 Bubble* bubble_; | 75 Bubble* bubble_; |
| 76 | 76 |
| 77 // Its contents view, owned by Bubble. | 77 // Its contents view, owned by Bubble. |
| 78 SettingLevelBubbleView* view_; | 78 SettingLevelBubbleView* view_; |
| 79 | 79 |
| 80 ui::SlideAnimation animation_; | 80 ui::SlideAnimation animation_; |
| 81 base::OneShotTimer<SettingLevelBubble> timeout_timer_; | 81 base::OneShotTimer<SettingLevelBubble> timeout_timer_; |
| 82 | 82 |
| 83 DISALLOW_COPY_AND_ASSIGN(SettingLevelBubble); | 83 DISALLOW_COPY_AND_ASSIGN(SettingLevelBubble); |
| 84 }; | 84 }; |
| 85 | 85 |
| 86 } // namespace chromeos | 86 } // namespace chromeos |
| 87 | 87 |
| 88 #endif // CHROME_BROWSER_CHROMEOS_SETTING_LEVEL_BUBBLE_H_ | 88 #endif // CHROME_BROWSER_CHROMEOS_SETTING_LEVEL_BUBBLE_H_ |
| OLD | NEW |