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_H_
6#define CHROME_BROWSER_CHROMEOS_SETTING_LEVEL_BUBBLE_H_
7#pragma once
8
9#include "base/basictypes.h"
10#include "base/timer.h"
11#include "chrome/browser/ui/views/bubble/bubble.h"
12#include "ui/base/animation/animation_delegate.h"
13#include "ui/base/animation/slide_animation.h"
14
15class SkBitmap;
16
17namespace chromeos {
18
19class SettingLevelBubbleView;
20
21// Singleton class controlling a bubble displaying a level-based setting like
22// volume or brightness.
23class SettingLevelBubble : public BubbleDelegate,
24                           public ui::AnimationDelegate {
25 public:
26  void ShowBubble(int percent);
27  void HideBubble();
28
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
31  // still visible from a previous call to ShowBubble().
32  //
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
35  // time that the bubble is shown.  For example:
36  //
37  // 1. Brightness is at 50%.
38  // 2. Power manager dims brightness to 25% automatically.
39  // 3. User hits the "increase brightness" button, setting brightness to 30%.
40  //
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
43  // to 30%, rather than from 25% up to 30%.
44  void UpdateWithoutShowingBubble(int percent);
45
46 protected:
47  explicit SettingLevelBubble(SkBitmap* increase_icon,
48                              SkBitmap* decrease_icon,
49                              SkBitmap* zero_icon);
50  virtual ~SettingLevelBubble() {}
51
52 private:
53  void OnTimeout();
54
55  // Overridden from BubbleDelegate.
56  virtual void BubbleClosing(Bubble* bubble, bool closed_by_escape);
57  virtual bool CloseOnEscape() { return true; }
58  virtual bool FadeInOnShow() { return false; }
59
60  // Overridden from ui::AnimationDelegate.
61  virtual void AnimationEnded(const ui::Animation* animation);
62  virtual void AnimationProgressed(const ui::Animation* animation);
63
64  // Previous and current percentages, or -1 if not yet shown.
65  int previous_percent_;
66  int current_percent_;
67
68  // Icons displayed in the bubble when increasing or decreasing the level or
69  // setting it to zero.  Not owned by us.
70  SkBitmap* increase_icon_;
71  SkBitmap* decrease_icon_;
72  SkBitmap* zero_icon_;
73
74  // Currently shown bubble or NULL.
75  Bubble* bubble_;
76
77  // Its contents view, owned by Bubble.
78  SettingLevelBubbleView* view_;
79
80  ui::SlideAnimation animation_;
81  base::OneShotTimer<SettingLevelBubble> timeout_timer_;
82
83  DISALLOW_COPY_AND_ASSIGN(SettingLevelBubble);
84};
85
86}  // namespace chromeos
87
88#endif  // CHROME_BROWSER_CHROMEOS_SETTING_LEVEL_BUBBLE_H_
89