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 // Throbbers display an animation, usually used as a status indicator. | 5 // Throbbers display an animation, usually used as a status indicator. |
6 | 6 |
7 #ifndef VIEWS_CONTROLS_THROBBER_H_ | 7 #ifndef VIEWS_CONTROLS_THROBBER_H_ |
8 #define VIEWS_CONTROLS_THROBBER_H_ | 8 #define VIEWS_CONTROLS_THROBBER_H_ |
9 #pragma once | 9 #pragma once |
10 | 10 |
11 #include "base/basictypes.h" | 11 #include "base/basictypes.h" |
12 #include "base/time.h" | 12 #include "base/time.h" |
13 #include "base/timer.h" | 13 #include "base/timer.h" |
14 #include "views/view.h" | 14 #include "views/view.h" |
15 | 15 |
16 class SkBitmap; | 16 class SkBitmap; |
17 | 17 |
18 namespace views { | 18 namespace views { |
19 | 19 |
20 class VIEWS_API Throbber : public View { | 20 class VIEWS_EXPORT Throbber : public View { |
21 public: | 21 public: |
22 // |frame_time_ms| is the amount of time that should elapse between frames | 22 // |frame_time_ms| is the amount of time that should elapse between frames |
23 // (in milliseconds) | 23 // (in milliseconds) |
24 // If |paint_while_stopped| is false, this view will be invisible when not | 24 // If |paint_while_stopped| is false, this view will be invisible when not |
25 // running. | 25 // running. |
26 Throbber(int frame_time_ms, bool paint_while_stopped); | 26 Throbber(int frame_time_ms, bool paint_while_stopped); |
27 Throbber(int frame_time_ms, bool paint_while_stopped, SkBitmap* frames); | 27 Throbber(int frame_time_ms, bool paint_while_stopped, SkBitmap* frames); |
28 virtual ~Throbber(); | 28 virtual ~Throbber(); |
29 | 29 |
30 // Start and stop the throbber animation | 30 // Start and stop the throbber animation |
(...skipping 21 matching lines...) Expand all Loading... |
52 base::TimeDelta frame_time_; // How long one frame is displayed. | 52 base::TimeDelta frame_time_; // How long one frame is displayed. |
53 base::RepeatingTimer<Throbber> timer_; // Used to schedule Run calls. | 53 base::RepeatingTimer<Throbber> timer_; // Used to schedule Run calls. |
54 | 54 |
55 DISALLOW_COPY_AND_ASSIGN(Throbber); | 55 DISALLOW_COPY_AND_ASSIGN(Throbber); |
56 }; | 56 }; |
57 | 57 |
58 // A SmoothedThrobber is a throbber that is representing potentially short | 58 // A SmoothedThrobber is a throbber that is representing potentially short |
59 // and nonoverlapping bursts of work. SmoothedThrobber ignores small | 59 // and nonoverlapping bursts of work. SmoothedThrobber ignores small |
60 // pauses in the work stops and starts, and only starts its throbber after | 60 // pauses in the work stops and starts, and only starts its throbber after |
61 // a small amount of work time has passed. | 61 // a small amount of work time has passed. |
62 class VIEWS_API SmoothedThrobber : public Throbber { | 62 class VIEWS_EXPORT SmoothedThrobber : public Throbber { |
63 public: | 63 public: |
64 SmoothedThrobber(int frame_delay_ms); | 64 SmoothedThrobber(int frame_delay_ms); |
65 SmoothedThrobber(int frame_delay_ms, SkBitmap* frames); | 65 SmoothedThrobber(int frame_delay_ms, SkBitmap* frames); |
66 virtual ~SmoothedThrobber(); | 66 virtual ~SmoothedThrobber(); |
67 | 67 |
68 virtual void Start(); | 68 virtual void Start(); |
69 virtual void Stop(); | 69 virtual void Stop(); |
70 | 70 |
71 void set_start_delay_ms(int value) { start_delay_ms_ = value; } | 71 void set_start_delay_ms(int value) { start_delay_ms_ = value; } |
72 void set_stop_delay_ms(int value) { stop_delay_ms_ = value; } | 72 void set_stop_delay_ms(int value) { stop_delay_ms_ = value; } |
(...skipping 17 matching lines...) Expand all Loading... |
90 base::OneShotTimer<SmoothedThrobber> stop_timer_; | 90 base::OneShotTimer<SmoothedThrobber> stop_timer_; |
91 | 91 |
92 DISALLOW_COPY_AND_ASSIGN(SmoothedThrobber); | 92 DISALLOW_COPY_AND_ASSIGN(SmoothedThrobber); |
93 }; | 93 }; |
94 | 94 |
95 // A CheckmarkThrobber is a special variant of throbber that has three states: | 95 // A CheckmarkThrobber is a special variant of throbber that has three states: |
96 // 1. not yet completed (which paints nothing) | 96 // 1. not yet completed (which paints nothing) |
97 // 2. working (which paints the throbber animation) | 97 // 2. working (which paints the throbber animation) |
98 // 3. completed (which paints a checkmark) | 98 // 3. completed (which paints a checkmark) |
99 // | 99 // |
100 class VIEWS_API CheckmarkThrobber : public Throbber { | 100 class VIEWS_EXPORT CheckmarkThrobber : public Throbber { |
101 public: | 101 public: |
102 CheckmarkThrobber(); | 102 CheckmarkThrobber(); |
103 | 103 |
104 // If checked is true, the throbber stops spinning and displays a checkmark. | 104 // If checked is true, the throbber stops spinning and displays a checkmark. |
105 // If checked is false, the throbber stops spinning and displays nothing. | 105 // If checked is false, the throbber stops spinning and displays nothing. |
106 void SetChecked(bool checked); | 106 void SetChecked(bool checked); |
107 | 107 |
108 // Overridden from Throbber: | 108 // Overridden from Throbber: |
109 virtual void OnPaint(gfx::Canvas* canvas); | 109 virtual void OnPaint(gfx::Canvas* canvas); |
110 | 110 |
111 private: | 111 private: |
112 static const int kFrameTimeMs = 30; | 112 static const int kFrameTimeMs = 30; |
113 | 113 |
114 static void InitClass(); | 114 static void InitClass(); |
115 | 115 |
116 // Whether or not we should display a checkmark. | 116 // Whether or not we should display a checkmark. |
117 bool checked_; | 117 bool checked_; |
118 | 118 |
119 // The checkmark image. | 119 // The checkmark image. |
120 static SkBitmap* checkmark_; | 120 static SkBitmap* checkmark_; |
121 | 121 |
122 DISALLOW_COPY_AND_ASSIGN(CheckmarkThrobber); | 122 DISALLOW_COPY_AND_ASSIGN(CheckmarkThrobber); |
123 }; | 123 }; |
124 | 124 |
125 } // namespace views | 125 } // namespace views |
126 | 126 |
127 #endif // VIEWS_CONTROLS_THROBBER_H_ | 127 #endif // VIEWS_CONTROLS_THROBBER_H_ |
OLD | NEW |