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
3 // found in the LICENSE file.
5 #ifndef UI_VIEWS_CONTROLS_THROBBER_H_
6 #define UI_VIEWS_CONTROLS_THROBBER_H_
8 #include "base/basictypes.h"
9 #include "base/compiler_specific.h"
10 #include "base/time/time.h"
11 #include "base/timer/timer.h"
12 #include "ui/views/view.h"
16 // Throbbers display an animation, usually used as a status indicator.
18 class VIEWS_EXPORT Throbber
: public View
{
23 // Start and stop the throbber animation.
27 // Stop spinning and, if checked is true, display a checkmark.
28 void SetChecked(bool checked
);
30 // Overridden from View:
31 gfx::Size
GetPreferredSize() const override
;
32 void OnPaint(gfx::Canvas
* canvas
) override
;
35 // Specifies whether the throbber is currently animating or not
36 bool IsRunning() const;
39 base::TimeTicks start_time_
; // Time when Start was called.
40 base::RepeatingTimer
<Throbber
> timer_
; // Used to schedule Run calls.
42 // Whether or not we should display a checkmark.
45 DISALLOW_COPY_AND_ASSIGN(Throbber
);
48 // A SmoothedThrobber is a throbber that is representing potentially short
49 // and nonoverlapping bursts of work. SmoothedThrobber ignores small
50 // pauses in the work stops and starts, and only starts its throbber after
51 // a small amount of work time has passed.
52 class VIEWS_EXPORT SmoothedThrobber
: public Throbber
{
55 ~SmoothedThrobber() override
;
57 void Start() override
;
60 void set_start_delay_ms(int value
) { start_delay_ms_
= value
; }
61 void set_stop_delay_ms(int value
) { stop_delay_ms_
= value
; }
64 // Called when the startup-delay timer fires
65 // This function starts the actual throbbing.
66 void StartDelayOver();
68 // Called when the shutdown-delay timer fires.
69 // This function stops the actual throbbing.
72 // Delay after work starts before starting throbber, in milliseconds.
75 // Delay after work stops before stopping, in milliseconds.
78 base::OneShotTimer
<SmoothedThrobber
> start_timer_
;
79 base::OneShotTimer
<SmoothedThrobber
> stop_timer_
;
81 DISALLOW_COPY_AND_ASSIGN(SmoothedThrobber
);
86 #endif // UI_VIEWS_CONTROLS_THROBBER_H_