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

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

Issue 8687031: views: Move the remaining files to ui/views/controls/. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 9 years 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
« no previous file with comments | « views/controls/single_split_view_unittest.cc ('k') | views/controls/throbber.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
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 // Throbbers display an animation, usually used as a status indicator.
6
7 #ifndef VIEWS_CONTROLS_THROBBER_H_
8 #define VIEWS_CONTROLS_THROBBER_H_
9 #pragma once
10
11 #include "base/basictypes.h"
12 #include "base/compiler_specific.h"
13 #include "base/time.h"
14 #include "base/timer.h"
15 #include "views/view.h"
16
17 class SkBitmap;
18
19 namespace views {
20
21 class VIEWS_EXPORT Throbber : public View {
22 public:
23 // |frame_time_ms| is the amount of time that should elapse between frames
24 // (in milliseconds)
25 // If |paint_while_stopped| is false, this view will be invisible when not
26 // running.
27 Throbber(int frame_time_ms, bool paint_while_stopped);
28 Throbber(int frame_time_ms, bool paint_while_stopped, SkBitmap* frames);
29 virtual ~Throbber();
30
31 // Start and stop the throbber animation
32 virtual void Start();
33 virtual void Stop();
34
35 // Set custom throbber frames. Otherwise IDR_THROBBER is loaded.
36 void SetFrames(SkBitmap* frames);
37
38 // overridden from View
39 virtual gfx::Size GetPreferredSize() OVERRIDE;
40 virtual void OnPaint(gfx::Canvas* canvas) OVERRIDE;
41
42 protected:
43 // Specifies whether the throbber is currently animating or not
44 bool running_;
45
46 private:
47 void Run();
48
49 bool paint_while_stopped_;
50 int frame_count_; // How many frames we have.
51 base::Time start_time_; // Time when Start was called.
52 SkBitmap* frames_; // Frames bitmaps.
53 base::TimeDelta frame_time_; // How long one frame is displayed.
54 base::RepeatingTimer<Throbber> timer_; // Used to schedule Run calls.
55
56 DISALLOW_COPY_AND_ASSIGN(Throbber);
57 };
58
59 // A SmoothedThrobber is a throbber that is representing potentially short
60 // and nonoverlapping bursts of work. SmoothedThrobber ignores small
61 // pauses in the work stops and starts, and only starts its throbber after
62 // a small amount of work time has passed.
63 class VIEWS_EXPORT SmoothedThrobber : public Throbber {
64 public:
65 SmoothedThrobber(int frame_delay_ms);
66 SmoothedThrobber(int frame_delay_ms, SkBitmap* frames);
67 virtual ~SmoothedThrobber();
68
69 virtual void Start() OVERRIDE;
70 virtual void Stop() OVERRIDE;
71
72 void set_start_delay_ms(int value) { start_delay_ms_ = value; }
73 void set_stop_delay_ms(int value) { stop_delay_ms_ = value; }
74
75 private:
76 // Called when the startup-delay timer fires
77 // This function starts the actual throbbing.
78 void StartDelayOver();
79
80 // Called when the shutdown-delay timer fires.
81 // This function stops the actual throbbing.
82 void StopDelayOver();
83
84 // Delay after work starts before starting throbber, in milliseconds.
85 int start_delay_ms_;
86
87 // Delay after work stops before stopping, in milliseconds.
88 int stop_delay_ms_;
89
90 base::OneShotTimer<SmoothedThrobber> start_timer_;
91 base::OneShotTimer<SmoothedThrobber> stop_timer_;
92
93 DISALLOW_COPY_AND_ASSIGN(SmoothedThrobber);
94 };
95
96 // A CheckmarkThrobber is a special variant of throbber that has three states:
97 // 1. not yet completed (which paints nothing)
98 // 2. working (which paints the throbber animation)
99 // 3. completed (which paints a checkmark)
100 //
101 class VIEWS_EXPORT CheckmarkThrobber : public Throbber {
102 public:
103 CheckmarkThrobber();
104
105 // If checked is true, the throbber stops spinning and displays a checkmark.
106 // If checked is false, the throbber stops spinning and displays nothing.
107 void SetChecked(bool checked);
108
109 // Overridden from Throbber:
110 virtual void OnPaint(gfx::Canvas* canvas) OVERRIDE;
111
112 private:
113 static const int kFrameTimeMs = 30;
114
115 static void InitClass();
116
117 // Whether or not we should display a checkmark.
118 bool checked_;
119
120 // The checkmark image.
121 static SkBitmap* checkmark_;
122
123 DISALLOW_COPY_AND_ASSIGN(CheckmarkThrobber);
124 };
125
126 } // namespace views
127
128 #endif // VIEWS_CONTROLS_THROBBER_H_
OLDNEW
« no previous file with comments | « views/controls/single_split_view_unittest.cc ('k') | views/controls/throbber.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698