Pin Chrome's shortcut to the Win10 Start menu on install and OS upgrade.
[chromium-blink-merge.git] / ui / views / controls / throbber.h
blob43288158b8c8bbe611a04eadd4af792ee4801f90
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"
14 namespace views {
16 // Throbbers display an animation, usually used as a status indicator.
18 class VIEWS_EXPORT Throbber : public View {
19 public:
20 Throbber();
21 ~Throbber() override;
23 // Start and stop the throbber animation.
24 virtual void Start();
25 virtual void Stop();
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;
34 protected:
35 // Specifies whether the throbber is currently animating or not
36 bool IsRunning() const;
38 private:
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.
43 bool checked_;
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 {
53 public:
54 SmoothedThrobber();
55 ~SmoothedThrobber() override;
57 void Start() override;
58 void Stop() 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; }
63 private:
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.
70 void StopDelayOver();
72 // Delay after work starts before starting throbber, in milliseconds.
73 int start_delay_ms_;
75 // Delay after work stops before stopping, in milliseconds.
76 int stop_delay_ms_;
78 base::OneShotTimer<SmoothedThrobber> start_timer_;
79 base::OneShotTimer<SmoothedThrobber> stop_timer_;
81 DISALLOW_COPY_AND_ASSIGN(SmoothedThrobber);
84 } // namespace views
86 #endif // UI_VIEWS_CONTROLS_THROBBER_H_