OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 UI_VIEWS_CONTROLS_THROBBER_H_ | 5 #ifndef UI_VIEWS_CONTROLS_THROBBER_H_ |
6 #define UI_VIEWS_CONTROLS_THROBBER_H_ | 6 #define UI_VIEWS_CONTROLS_THROBBER_H_ |
7 | 7 |
8 #include "base/basictypes.h" | 8 #include "base/basictypes.h" |
9 #include "base/compiler_specific.h" | 9 #include "base/compiler_specific.h" |
10 #include "base/time/time.h" | 10 #include "base/time/time.h" |
11 #include "base/timer/timer.h" | 11 #include "base/timer/timer.h" |
12 #include "ui/views/view.h" | 12 #include "ui/views/view.h" |
13 | 13 |
14 namespace gfx { | 14 namespace gfx { |
15 class ImageSkia; | 15 class ImageSkia; |
16 } | 16 } |
17 | 17 |
18 namespace views { | 18 namespace views { |
19 | 19 |
20 // Throbbers display an animation, usually used as a status indicator. | 20 // Throbbers display an animation, usually used as a status indicator. |
21 | 21 |
22 class VIEWS_EXPORT Throbber : public View { | 22 class VIEWS_EXPORT Throbber : public View { |
sky
2015/04/27 15:15:07
If you want more to cleanup this class should real
| |
23 public: | 23 public: |
24 // |frame_time_ms| is the amount of time that should elapse between frames | 24 // |frame_time_ms| is the amount of time that should elapse between frames |
25 // (in milliseconds) | 25 // (in milliseconds) |
26 // If |paint_while_stopped| is false, this view will be invisible when not | 26 // If |paint_while_stopped| is false, this view will be invisible when not |
27 // running. | 27 // running. |
28 Throbber(int frame_time_ms, bool paint_while_stopped); | 28 Throbber(int frame_time_ms, bool paint_while_stopped); |
29 Throbber(int frame_time_ms, bool paint_while_stopped, gfx::ImageSkia* frames); | 29 Throbber(int frame_time_ms, bool paint_while_stopped, gfx::ImageSkia* frames); |
30 ~Throbber() override; | 30 ~Throbber() override; |
31 | 31 |
32 // Start and stop the throbber animation | 32 // Start and stop the throbber animation |
33 virtual void Start(); | 33 virtual void Start(); |
34 virtual void Stop(); | 34 virtual void Stop(); |
35 | 35 |
36 // Set custom throbber frames. Otherwise IDR_THROBBER is loaded. | 36 // Set custom throbber frames. Otherwise IDR_THROBBER is loaded. |
37 void SetFrames(const gfx::ImageSkia* frames); | 37 void SetFrames(const gfx::ImageSkia* frames); |
38 | 38 |
39 // Overridden from View: | 39 // Overridden from View: |
40 gfx::Size GetPreferredSize() const override; | 40 gfx::Size GetPreferredSize() const override; |
41 void OnPaint(gfx::Canvas* canvas) override; | 41 void OnPaint(gfx::Canvas* canvas) override; |
42 | 42 |
43 protected: | 43 protected: |
44 bool running() const { return running_; } | |
45 base::Time start_time() const { return start_time_; } | |
46 | |
47 // Specifies whether the throbber is currently animating or not | 44 // Specifies whether the throbber is currently animating or not |
45 bool IsRunning() const; | |
46 base::TimeTicks start_time() const { return start_time_; } | |
48 | 47 |
49 private: | 48 private: |
50 void Run(); | |
51 | |
52 bool running_; | |
53 bool paint_while_stopped_; | 49 bool paint_while_stopped_; |
54 int frame_count_; // How many frames we have. | 50 int frame_count_; // How many frames we have. |
55 base::Time start_time_; // Time when Start was called. | 51 base::TimeTicks start_time_; // Time when Start was called. |
56 const gfx::ImageSkia* frames_; // Frames images. | 52 const gfx::ImageSkia* frames_; // Frames images. |
57 base::TimeDelta frame_time_; // How long one frame is displayed. | 53 base::TimeDelta frame_time_; // How long one frame is displayed. |
58 base::RepeatingTimer<Throbber> timer_; // Used to schedule Run calls. | 54 base::RepeatingTimer<Throbber> timer_; // Used to schedule Run calls. |
59 | 55 |
60 DISALLOW_COPY_AND_ASSIGN(Throbber); | 56 DISALLOW_COPY_AND_ASSIGN(Throbber); |
61 }; | 57 }; |
62 | 58 |
63 // A SmoothedThrobber is a throbber that is representing potentially short | 59 // A SmoothedThrobber is a throbber that is representing potentially short |
64 // and nonoverlapping bursts of work. SmoothedThrobber ignores small | 60 // and nonoverlapping bursts of work. SmoothedThrobber ignores small |
65 // pauses in the work stops and starts, and only starts its throbber after | 61 // pauses in the work stops and starts, and only starts its throbber after |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
126 | 122 |
127 // The checkmark image. Will be null until it's used (if ever). | 123 // The checkmark image. Will be null until it's used (if ever). |
128 const gfx::ImageSkia* checkmark_; | 124 const gfx::ImageSkia* checkmark_; |
129 | 125 |
130 DISALLOW_COPY_AND_ASSIGN(MaterialThrobber); | 126 DISALLOW_COPY_AND_ASSIGN(MaterialThrobber); |
131 }; | 127 }; |
132 | 128 |
133 } // namespace views | 129 } // namespace views |
134 | 130 |
135 #endif // UI_VIEWS_CONTROLS_THROBBER_H_ | 131 #endif // UI_VIEWS_CONTROLS_THROBBER_H_ |
OLD | NEW |