OLD | NEW |
(Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #ifndef CHROME_BROWSER_CHROMEOS_SETTING_LEVEL_BUBBLE_VIEW_VIEWS_H_ |
| 6 #define CHROME_BROWSER_CHROMEOS_SETTING_LEVEL_BUBBLE_VIEW_VIEWS_H_ |
| 7 #pragma once |
| 8 |
| 9 #include "base/basictypes.h" |
| 10 #include "base/timer.h" |
| 11 #include "views/bubble/bubble_delegate.h" |
| 12 |
| 13 class SkBitmap; |
| 14 |
| 15 namespace chromeos { |
| 16 |
| 17 class SettingLevelBubbleView; |
| 18 |
| 19 // Singleton class controlling a bubble displaying a level-based setting like |
| 20 // volume or brightness. |
| 21 class SettingLevelBubbleViewViews : public views::BubbleDelegateView { |
| 22 public: |
| 23 // Create the bubble delegate and view. |
| 24 // |percent| should be in the range [0.0, 100.0]. |
| 25 static views::Widget* ConstructSettingLevelBubble( |
| 26 SkBitmap* increase_icon, |
| 27 SkBitmap* decrease_icon, |
| 28 SkBitmap* zero_icon, |
| 29 double percent, bool enabled); |
| 30 virtual ~SettingLevelBubbleViewViews(); |
| 31 |
| 32 // Updates the bubble's current level without showing the bubble onscreen. |
| 33 // We _do_ still animate the level moving to |percent| in case the bubble is |
| 34 // still visible from a previous call to ShowBubble(). |
| 35 // |
| 36 // This can be used when the setting has been changed automatically and we |
| 37 // want to make sure that it's animated from the correct position the next |
| 38 // time that the bubble is shown. For example: |
| 39 // |
| 40 // 1. Brightness is at 50%. |
| 41 // 2. Power manager dims brightness to 25% automatically. |
| 42 // 3. User hits the "increase brightness" button, setting brightness to 30%. |
| 43 // |
| 44 // If we didn't update our internal state to 25% after 2), then the animation |
| 45 // displayed in response to 3) would show the bubble animating from 50% down |
| 46 // to 30%, rather than from 25% up to 30%. |
| 47 void UpdateWithoutShowingBubble(double percent, bool enabled); |
| 48 |
| 49 void UpdateSettingLevel(double percent, bool enabled); |
| 50 |
| 51 // BubbleDelegate overrides: |
| 52 virtual void Init() OVERRIDE; |
| 53 virtual views::BubbleBorder::ArrowLocation GetArrowLocation() const OVERRIDE; |
| 54 virtual SkColor GetColor() const OVERRIDE; |
| 55 virtual bool GetEnableAccelerator() const OVERRIDE; |
| 56 // WidgetDeletgate overrides: |
| 57 virtual void WindowClosing() OVERRIDE; |
| 58 |
| 59 void StartHideTimer(); |
| 60 |
| 61 protected: |
| 62 SettingLevelBubbleViewViews(SkBitmap* increase_icon, |
| 63 SkBitmap* decrease_icon, |
| 64 SkBitmap* zero_icon); |
| 65 |
| 66 private: |
| 67 // Callback for |animation_timer_|. Updates the level displayed by the view, |
| 68 // also stopping the animation if we've reached the target. |
| 69 void OnAnimationTimeout(); |
| 70 |
| 71 // Callback for |hide_timer_|. Closes the bubble. |
| 72 void OnHideTimeout(); |
| 73 |
| 74 // Animates towards |percent|. Updates |target_percent_| and starts |
| 75 // |animation_timer_| if it's not already running. If this is the first time |
| 76 // that the level is being set, we just update |view_| immediately and don't |
| 77 // animate. |
| 78 void UpdateTargetPercent(double percent); |
| 79 |
| 80 // Stops |animation_timer_| if it's running. |
| 81 void StopAnimation(); |
| 82 |
| 83 // Current and target percentages for the progress bar. In the range |
| 84 // [0.0, 100.0], or -1.0 if not yet shown. |
| 85 double current_percent_; |
| 86 double target_percent_; |
| 87 |
| 88 // Time at which we'll reach |target_percent_|. |
| 89 base::TimeTicks target_time_; |
| 90 |
| 91 // Time at which we last updated |current_percent_|. |
| 92 base::TimeTicks last_animation_update_time_; |
| 93 |
| 94 // Time at which |target_percent_| was last updated. |
| 95 base::TimeTicks last_target_update_time_; |
| 96 |
| 97 // Icons displayed in the bubble when increasing or decreasing the level or |
| 98 // when it's disabled. Not owned by us. |
| 99 SkBitmap* increase_icon_; |
| 100 SkBitmap* decrease_icon_; |
| 101 SkBitmap* disabled_icon_; |
| 102 SkBitmap* current_icon_; |
| 103 |
| 104 bool enabled_; |
| 105 // Contents view of BubbleView |
| 106 SettingLevelBubbleView* view_; |
| 107 |
| 108 // Timer to hide the bubble. |
| 109 base::OneShotTimer<SettingLevelBubbleViewViews> hide_timer_; |
| 110 |
| 111 // Timer to animate the currently-shown percent. We use a timer instead of |
| 112 // ui::Animation since our animations are frequently interrupted by additional |
| 113 // changes to the level, and ui::Animation doesn't provide much control over |
| 114 // in-progress animations, leading to mega-jank. |
| 115 base::RepeatingTimer<SettingLevelBubbleViewViews> animation_timer_; |
| 116 |
| 117 // Is |animation_timer_| currently running? |
| 118 bool is_animating_; |
| 119 |
| 120 gfx::Rect position_relative_to_; |
| 121 |
| 122 DISALLOW_COPY_AND_ASSIGN(SettingLevelBubbleViewViews); |
| 123 }; |
| 124 |
| 125 } // namespace chromeos |
| 126 |
| 127 #endif // CHROME_BROWSER_CHROMEOS_SETTING_LEVEL_BUBBLE_VIEW_VIEWS_H_ |
OLD | NEW |