OLD | NEW |
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 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 CHROME_VIEWS_THROBBER_H__ | 7 #ifndef CHROME_VIEWS_THROBBER_H_ |
8 #define CHROME_VIEWS_THROBBER_H__ | 8 #define CHROME_VIEWS_THROBBER_H_ |
9 | 9 |
10 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
| 11 #include "base/time.h" |
11 #include "base/timer.h" | 12 #include "base/timer.h" |
12 #include "chrome/views/view.h" | 13 #include "chrome/views/view.h" |
13 | 14 |
14 class SkBitmap; | 15 class SkBitmap; |
15 | 16 |
16 namespace views { | 17 namespace views { |
17 | 18 |
18 class Throbber : public View { | 19 class Throbber : public View { |
19 public: | 20 public: |
20 // |frame_time_ms| is the amount of time that should elapse between frames | 21 // |frame_time_ms| is the amount of time that should elapse between frames |
(...skipping 12 matching lines...) Expand all Loading... |
33 virtual void Paint(ChromeCanvas* canvas); | 34 virtual void Paint(ChromeCanvas* canvas); |
34 | 35 |
35 protected: | 36 protected: |
36 // Specifies whether the throbber is currently animating or not | 37 // Specifies whether the throbber is currently animating or not |
37 bool running_; | 38 bool running_; |
38 | 39 |
39 private: | 40 private: |
40 void Run(); | 41 void Run(); |
41 | 42 |
42 bool paint_while_stopped_; | 43 bool paint_while_stopped_; |
43 int frame_count_; | 44 int frame_count_; // How many frames we have. |
44 int last_frame_drawn_; | 45 base::Time start_time_; // Time when Start was called. |
45 DWORD start_time_; | 46 SkBitmap* frames_; // Frames bitmaps. |
46 DWORD last_time_recorded_; | 47 base::TimeDelta frame_time_; // How long one frame is displayed. |
47 SkBitmap* frames_; | 48 base::RepeatingTimer<Throbber> timer_; // Used to schedule Run calls. |
48 int frame_time_ms_; | |
49 base::RepeatingTimer<Throbber> timer_; | |
50 | 49 |
51 DISALLOW_EVIL_CONSTRUCTORS(Throbber); | 50 DISALLOW_COPY_AND_ASSIGN(Throbber); |
52 }; | 51 }; |
53 | 52 |
54 // A SmoothedThrobber is a throbber that is representing potentially short | 53 // A SmoothedThrobber is a throbber that is representing potentially short |
55 // and nonoverlapping bursts of work. SmoothedThrobber ignores small | 54 // and nonoverlapping bursts of work. SmoothedThrobber ignores small |
56 // pauses in the work stops and starts, and only starts its throbber after | 55 // pauses in the work stops and starts, and only starts its throbber after |
57 // a small amount of work time has passed. | 56 // a small amount of work time has passed. |
58 class SmoothedThrobber : public Throbber { | 57 class SmoothedThrobber : public Throbber { |
59 public: | 58 public: |
60 SmoothedThrobber(int frame_delay_ms); | 59 SmoothedThrobber(int frame_delay_ms); |
61 | 60 |
62 virtual void Start(); | 61 virtual void Start(); |
63 virtual void Stop(); | 62 virtual void Stop(); |
64 | 63 |
65 private: | 64 private: |
66 // Called when the startup-delay timer fires | 65 // Called when the startup-delay timer fires |
67 // This function starts the actual throbbing. | 66 // This function starts the actual throbbing. |
68 void StartDelayOver(); | 67 void StartDelayOver(); |
69 | 68 |
70 // Called when the shutdown-delay timer fires. | 69 // Called when the shutdown-delay timer fires. |
71 // This function stops the actual throbbing. | 70 // This function stops the actual throbbing. |
72 void StopDelayOver(); | 71 void StopDelayOver(); |
73 | 72 |
74 base::OneShotTimer<SmoothedThrobber> start_timer_; | 73 base::OneShotTimer<SmoothedThrobber> start_timer_; |
75 base::OneShotTimer<SmoothedThrobber> stop_timer_; | 74 base::OneShotTimer<SmoothedThrobber> stop_timer_; |
76 | 75 |
77 DISALLOW_EVIL_CONSTRUCTORS(SmoothedThrobber); | 76 DISALLOW_COPY_AND_ASSIGN(SmoothedThrobber); |
78 }; | 77 }; |
79 | 78 |
80 // A CheckmarkThrobber is a special variant of throbber that has three states: | 79 // A CheckmarkThrobber is a special variant of throbber that has three states: |
81 // 1. not yet completed (which paints nothing) | 80 // 1. not yet completed (which paints nothing) |
82 // 2. working (which paints the throbber animation) | 81 // 2. working (which paints the throbber animation) |
83 // 3. completed (which paints a checkmark) | 82 // 3. completed (which paints a checkmark) |
84 // | 83 // |
85 class CheckmarkThrobber : public Throbber { | 84 class CheckmarkThrobber : public Throbber { |
86 public: | 85 public: |
87 CheckmarkThrobber(); | 86 CheckmarkThrobber(); |
88 | 87 |
89 // If checked is true, the throbber stops spinning and displays a checkmark. | 88 // If checked is true, the throbber stops spinning and displays a checkmark. |
90 // If checked is false, the throbber stops spinning and displays nothing. | 89 // If checked is false, the throbber stops spinning and displays nothing. |
91 void SetChecked(bool checked); | 90 void SetChecked(bool checked); |
92 | 91 |
93 // Overridden from Throbber: | 92 // Overridden from Throbber: |
94 virtual void Paint(ChromeCanvas* canvas); | 93 virtual void Paint(ChromeCanvas* canvas); |
95 | 94 |
96 private: | 95 private: |
97 static const int kFrameTimeMs = 30; | 96 static const int kFrameTimeMs = 30; |
98 | 97 |
99 static void InitClass(); | 98 static void InitClass(); |
100 | 99 |
101 // Whether or not we should display a checkmark. | 100 // Whether or not we should display a checkmark. |
102 bool checked_; | 101 bool checked_; |
103 | 102 |
104 // The checkmark image. | 103 // The checkmark image. |
105 static SkBitmap* checkmark_; | 104 static SkBitmap* checkmark_; |
106 | 105 |
107 DISALLOW_EVIL_CONSTRUCTORS(CheckmarkThrobber); | 106 DISALLOW_COPY_AND_ASSIGN(CheckmarkThrobber); |
108 }; | 107 }; |
109 | 108 |
110 } // namespace views | 109 } // namespace views |
111 | 110 |
112 #endif // CHROME_VIEWS_THROBBER_H__ | 111 #endif // CHROME_VIEWS_THROBBER_H_ |
113 | 112 |
OLD | NEW |