[email protected] | 85f1ee1d | 2012-03-06 19:35:38 | [diff] [blame] | 1 | // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
license.bot | bf09a50 | 2008-08-24 00:55:55 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
3 | // found in the LICENSE file. | ||||
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 4 | |
[email protected] | 8fc1b372 | 2011-11-29 20:25:29 | [diff] [blame] | 5 | #ifndef UI_VIEWS_CONTROLS_THROBBER_H_ |
6 | #define UI_VIEWS_CONTROLS_THROBBER_H_ | ||||
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 7 | |
8 | #include "base/basictypes.h" | ||||
[email protected] | 0590b019 | 2011-11-23 18:10:50 | [diff] [blame] | 9 | #include "base/compiler_specific.h" |
[email protected] | e1f5f28 | 2013-06-28 15:22:52 | [diff] [blame^] | 10 | #include "base/time/time.h" |
11 | #include "base/timer/timer.h" | ||||
[email protected] | 5025f86 | 2011-11-30 23:35:20 | [diff] [blame] | 12 | #include "ui/views/view.h" |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 13 | |
[email protected] | 964e09d5 | 2012-05-24 15:17:39 | [diff] [blame] | 14 | namespace gfx { |
15 | class ImageSkia; | ||||
16 | } | ||||
[email protected] | aeab57ea | 2008-08-28 20:50:12 | [diff] [blame] | 17 | |
[email protected] | c2dacc9 | 2008-10-16 23:51:38 | [diff] [blame] | 18 | namespace views { |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 19 | |
[email protected] | 8fc1b372 | 2011-11-29 20:25:29 | [diff] [blame] | 20 | // Throbbers display an animation, usually used as a status indicator. |
21 | |||||
[email protected] | 5036f18 | 2011-08-05 20:58:29 | [diff] [blame] | 22 | class VIEWS_EXPORT Throbber : public View { |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 23 | public: |
24 | // |frame_time_ms| is the amount of time that should elapse between frames | ||||
25 | // (in milliseconds) | ||||
26 | // If |paint_while_stopped| is false, this view will be invisible when not | ||||
27 | // running. | ||||
28 | Throbber(int frame_time_ms, bool paint_while_stopped); | ||||
[email protected] | 964e09d5 | 2012-05-24 15:17:39 | [diff] [blame] | 29 | Throbber(int frame_time_ms, bool paint_while_stopped, gfx::ImageSkia* frames); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 30 | virtual ~Throbber(); |
31 | |||||
32 | // Start and stop the throbber animation | ||||
33 | virtual void Start(); | ||||
34 | virtual void Stop(); | ||||
35 | |||||
[email protected] | 302cf65 | 2010-04-27 11:08:50 | [diff] [blame] | 36 | // Set custom throbber frames. Otherwise IDR_THROBBER is loaded. |
[email protected] | 964e09d5 | 2012-05-24 15:17:39 | [diff] [blame] | 37 | void SetFrames(const gfx::ImageSkia* frames); |
[email protected] | 302cf65 | 2010-04-27 11:08:50 | [diff] [blame] | 38 | |
[email protected] | 85f1ee1d | 2012-03-06 19:35:38 | [diff] [blame] | 39 | // Overridden from View: |
[email protected] | 0590b019 | 2011-11-23 18:10:50 | [diff] [blame] | 40 | virtual gfx::Size GetPreferredSize() OVERRIDE; |
41 | virtual void OnPaint(gfx::Canvas* canvas) OVERRIDE; | ||||
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 42 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 43 | protected: |
44 | // Specifies whether the throbber is currently animating or not | ||||
45 | bool running_; | ||||
46 | |||||
47 | private: | ||||
[email protected] | 2d31666 | 2008-09-03 18:18:14 | [diff] [blame] | 48 | void Run(); |
49 | |||||
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 50 | bool paint_while_stopped_; |
[email protected] | d39d60d7 | 2009-01-27 15:59:32 | [diff] [blame] | 51 | int frame_count_; // How many frames we have. |
52 | base::Time start_time_; // Time when Start was called. | ||||
[email protected] | 964e09d5 | 2012-05-24 15:17:39 | [diff] [blame] | 53 | const gfx::ImageSkia* frames_; // Frames images. |
[email protected] | d39d60d7 | 2009-01-27 15:59:32 | [diff] [blame] | 54 | base::TimeDelta frame_time_; // How long one frame is displayed. |
55 | base::RepeatingTimer<Throbber> timer_; // Used to schedule Run calls. | ||||
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 56 | |
[email protected] | d39d60d7 | 2009-01-27 15:59:32 | [diff] [blame] | 57 | DISALLOW_COPY_AND_ASSIGN(Throbber); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 58 | }; |
59 | |||||
60 | // A SmoothedThrobber is a throbber that is representing potentially short | ||||
61 | // and nonoverlapping bursts of work. SmoothedThrobber ignores small | ||||
62 | // pauses in the work stops and starts, and only starts its throbber after | ||||
63 | // a small amount of work time has passed. | ||||
[email protected] | 5036f18 | 2011-08-05 20:58:29 | [diff] [blame] | 64 | class VIEWS_EXPORT SmoothedThrobber : public Throbber { |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 65 | public: |
[email protected] | 3c4fc69 | 2012-05-04 17:02:46 | [diff] [blame] | 66 | explicit SmoothedThrobber(int frame_delay_ms); |
[email protected] | 964e09d5 | 2012-05-24 15:17:39 | [diff] [blame] | 67 | SmoothedThrobber(int frame_delay_ms, gfx::ImageSkia* frames); |
[email protected] | 1646064 | 2011-03-04 23:15:53 | [diff] [blame] | 68 | virtual ~SmoothedThrobber(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 69 | |
[email protected] | 0590b019 | 2011-11-23 18:10:50 | [diff] [blame] | 70 | virtual void Start() OVERRIDE; |
71 | virtual void Stop() OVERRIDE; | ||||
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 72 | |
[email protected] | 302cf65 | 2010-04-27 11:08:50 | [diff] [blame] | 73 | void set_start_delay_ms(int value) { start_delay_ms_ = value; } |
74 | void set_stop_delay_ms(int value) { stop_delay_ms_ = value; } | ||||
75 | |||||
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 76 | private: |
77 | // Called when the startup-delay timer fires | ||||
78 | // This function starts the actual throbbing. | ||||
79 | void StartDelayOver(); | ||||
80 | |||||
81 | // Called when the shutdown-delay timer fires. | ||||
82 | // This function stops the actual throbbing. | ||||
83 | void StopDelayOver(); | ||||