Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(246)

Side by Side Diff: ui/views/controls/throbber.h

Issue 10437006: Converts ui/views/controls, ui/views/examples, ui/base/models to ImageSkia (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebased Created 8 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 #pragma once 7 #pragma once
8 8
9 #include "base/basictypes.h" 9 #include "base/basictypes.h"
10 #include "base/compiler_specific.h" 10 #include "base/compiler_specific.h"
11 #include "base/time.h" 11 #include "base/time.h"
12 #include "base/timer.h" 12 #include "base/timer.h"
13 #include "ui/views/view.h" 13 #include "ui/views/view.h"
14 14
15 class SkBitmap; 15 namespace gfx {
16 class ImageSkia;
17 }
16 18
17 namespace views { 19 namespace views {
18 20
19 // Throbbers display an animation, usually used as a status indicator. 21 // Throbbers display an animation, usually used as a status indicator.
20 22
21 class VIEWS_EXPORT Throbber : public View { 23 class VIEWS_EXPORT Throbber : public View {
22 public: 24 public:
23 // |frame_time_ms| is the amount of time that should elapse between frames 25 // |frame_time_ms| is the amount of time that should elapse between frames
24 // (in milliseconds) 26 // (in milliseconds)
25 // If |paint_while_stopped| is false, this view will be invisible when not 27 // If |paint_while_stopped| is false, this view will be invisible when not
26 // running. 28 // running.
27 Throbber(int frame_time_ms, bool paint_while_stopped); 29 Throbber(int frame_time_ms, bool paint_while_stopped);
28 Throbber(int frame_time_ms, bool paint_while_stopped, SkBitmap* frames); 30 Throbber(int frame_time_ms, bool paint_while_stopped, gfx::ImageSkia* frames);
29 virtual ~Throbber(); 31 virtual ~Throbber();
30 32
31 // Start and stop the throbber animation 33 // Start and stop the throbber animation
32 virtual void Start(); 34 virtual void Start();
33 virtual void Stop(); 35 virtual void Stop();
34 36
35 // Set custom throbber frames. Otherwise IDR_THROBBER is loaded. 37 // Set custom throbber frames. Otherwise IDR_THROBBER is loaded.
36 void SetFrames(const SkBitmap* frames); 38 void SetFrames(const gfx::ImageSkia* frames);
37 39
38 // Overridden from View: 40 // Overridden from View:
39 virtual gfx::Size GetPreferredSize() OVERRIDE; 41 virtual gfx::Size GetPreferredSize() OVERRIDE;
40 virtual void OnPaint(gfx::Canvas* canvas) OVERRIDE; 42 virtual void OnPaint(gfx::Canvas* canvas) OVERRIDE;
41 43
42 protected: 44 protected:
43 // Specifies whether the throbber is currently animating or not 45 // Specifies whether the throbber is currently animating or not
44 bool running_; 46 bool running_;
45 47
46 private: 48 private:
47 void Run(); 49 void Run();
48 50
49 bool paint_while_stopped_; 51 bool paint_while_stopped_;
50 int frame_count_; // How many frames we have. 52 int frame_count_; // How many frames we have.
51 base::Time start_time_; // Time when Start was called. 53 base::Time start_time_; // Time when Start was called.
52 const SkBitmap* frames_; // Frames bitmaps. 54 const gfx::ImageSkia* frames_; // Frames images.
53 base::TimeDelta frame_time_; // How long one frame is displayed. 55 base::TimeDelta frame_time_; // How long one frame is displayed.
54 base::RepeatingTimer<Throbber> timer_; // Used to schedule Run calls. 56 base::RepeatingTimer<Throbber> timer_; // Used to schedule Run calls.
55 57
56 DISALLOW_COPY_AND_ASSIGN(Throbber); 58 DISALLOW_COPY_AND_ASSIGN(Throbber);
57 }; 59 };
58 60
59 // A SmoothedThrobber is a throbber that is representing potentially short 61 // A SmoothedThrobber is a throbber that is representing potentially short
60 // and nonoverlapping bursts of work. SmoothedThrobber ignores small 62 // and nonoverlapping bursts of work. SmoothedThrobber ignores small
61 // pauses in the work stops and starts, and only starts its throbber after 63 // pauses in the work stops and starts, and only starts its throbber after
62 // a small amount of work time has passed. 64 // a small amount of work time has passed.
63 class VIEWS_EXPORT SmoothedThrobber : public Throbber { 65 class VIEWS_EXPORT SmoothedThrobber : public Throbber {
64 public: 66 public:
65 explicit SmoothedThrobber(int frame_delay_ms); 67 explicit SmoothedThrobber(int frame_delay_ms);
66 SmoothedThrobber(int frame_delay_ms, SkBitmap* frames); 68 SmoothedThrobber(int frame_delay_ms, gfx::ImageSkia* frames);
67 virtual ~SmoothedThrobber(); 69 virtual ~SmoothedThrobber();
68 70
69 virtual void Start() OVERRIDE; 71 virtual void Start() OVERRIDE;
70 virtual void Stop() OVERRIDE; 72 virtual void Stop() OVERRIDE;
71 73
72 void set_start_delay_ms(int value) { start_delay_ms_ = value; } 74 void set_start_delay_ms(int value) { start_delay_ms_ = value; }
73 void set_stop_delay_ms(int value) { stop_delay_ms_ = value; } 75 void set_stop_delay_ms(int value) { stop_delay_ms_ = value; }
74 76
75 private: 77 private:
76 // Called when the startup-delay timer fires 78 // Called when the startup-delay timer fires
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
109 // Overridden from Throbber: 111 // Overridden from Throbber:
110 virtual void OnPaint(gfx::Canvas* canvas) OVERRIDE; 112 virtual void OnPaint(gfx::Canvas* canvas) OVERRIDE;
111 113
112 private: 114 private:
113 static const int kFrameTimeMs = 30; 115 static const int kFrameTimeMs = 30;
114 116
115 // Whether or not we should display a checkmark. 117 // Whether or not we should display a checkmark.
116 bool checked_; 118 bool checked_;
117 119
118 // The checkmark image. 120 // The checkmark image.
119 const SkBitmap* checkmark_; 121 const gfx::ImageSkia* checkmark_;
120 122
121 DISALLOW_COPY_AND_ASSIGN(CheckmarkThrobber); 123 DISALLOW_COPY_AND_ASSIGN(CheckmarkThrobber);
122 }; 124 };
123 125
124 } // namespace views 126 } // namespace views
125 127
126 #endif // UI_VIEWS_CONTROLS_THROBBER_H_ 128 #endif // UI_VIEWS_CONTROLS_THROBBER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698