blob: 8ae3895a22a3ea040193f0fe5e8e35afb517888c [file] [log] [blame]
[email protected]85f1ee1d2012-03-06 19:35:381// Copyright (c) 2012 The Chromium Authors. All rights reserved.
license.botbf09a502008-08-24 00:55:552// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
initial.commit09911bf2008-07-26 23:55:294
[email protected]8fc1b3722011-11-29 20:25:295#ifndef UI_VIEWS_CONTROLS_THROBBER_H_
6#define UI_VIEWS_CONTROLS_THROBBER_H_
initial.commit09911bf2008-07-26 23:55:297
8#include "base/basictypes.h"
[email protected]0590b0192011-11-23 18:10:509#include "base/compiler_specific.h"
[email protected]e1f5f282013-06-28 15:22:5210#include "base/time/time.h"
11#include "base/timer/timer.h"
[email protected]5025f862011-11-30 23:35:2012#include "ui/views/view.h"
initial.commit09911bf2008-07-26 23:55:2913
[email protected]964e09d52012-05-24 15:17:3914namespace gfx {
15class ImageSkia;
16}
[email protected]aeab57ea2008-08-28 20:50:1217
[email protected]c2dacc92008-10-16 23:51:3818namespace views {
initial.commit09911bf2008-07-26 23:55:2919
[email protected]8fc1b3722011-11-29 20:25:2920// Throbbers display an animation, usually used as a status indicator.
21
[email protected]5036f182011-08-05 20:58:2922class VIEWS_EXPORT Throbber : public View {
initial.commit09911bf2008-07-26 23:55:2923 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]964e09d52012-05-24 15:17:3929 Throbber(int frame_time_ms, bool paint_while_stopped, gfx::ImageSkia* frames);
initial.commit09911bf2008-07-26 23:55:2930 virtual ~Throbber();
31
32 // Start and stop the throbber animation
33 virtual void Start();
34 virtual void Stop();
35
[email protected]302cf652010-04-27 11:08:5036 // Set custom throbber frames. Otherwise IDR_THROBBER is loaded.
[email protected]964e09d52012-05-24 15:17:3937 void SetFrames(const gfx::ImageSkia* frames);
[email protected]302cf652010-04-27 11:08:5038
[email protected]85f1ee1d2012-03-06 19:35:3839 // Overridden from View:
[email protected]0590b0192011-11-23 18:10:5040 virtual gfx::Size GetPreferredSize() OVERRIDE;
41 virtual void OnPaint(gfx::Canvas* canvas) OVERRIDE;
initial.commit09911bf2008-07-26 23:55:2942
initial.commit09911bf2008-07-26 23:55:2943 protected:
44 // Specifies whether the throbber is currently animating or not
45 bool running_;
46
47 private:
[email protected]2d316662008-09-03 18:18:1448 void Run();
49
initial.commit09911bf2008-07-26 23:55:2950 bool paint_while_stopped_;
[email protected]d39d60d72009-01-27 15:59:3251 int frame_count_; // How many frames we have.
52 base::Time start_time_; // Time when Start was called.
[email protected]964e09d52012-05-24 15:17:3953 const gfx::ImageSkia* frames_; // Frames images.
[email protected]d39d60d72009-01-27 15:59:3254 base::TimeDelta frame_time_; // How long one frame is displayed.
55 base::RepeatingTimer<Throbber> timer_; // Used to schedule Run calls.
initial.commit09911bf2008-07-26 23:55:2956
[email protected]d39d60d72009-01-27 15:59:3257 DISALLOW_COPY_AND_ASSIGN(Throbber);
initial.commit09911bf2008-07-26 23:55:2958};
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]5036f182011-08-05 20:58:2964class VIEWS_EXPORT SmoothedThrobber : public Throbber {
initial.commit09911bf2008-07-26 23:55:2965 public:
[email protected]3c4fc692012-05-04 17:02:4666 explicit SmoothedThrobber(int frame_delay_ms);
[email protected]964e09d52012-05-24 15:17:3967 SmoothedThrobber(int frame_delay_ms, gfx::ImageSkia* frames);
[email protected]16460642011-03-04 23:15:5368 virtual ~SmoothedThrobber();
initial.commit09911bf2008-07-26 23:55:2969
[email protected]0590b0192011-11-23 18:10:5070 virtual void Start() OVERRIDE;
71 virtual void Stop() OVERRIDE;
initial.commit09911bf2008-07-26 23:55:2972
[email protected]302cf652010-04-27 11:08:5073 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.commit09911bf2008-07-26 23:55:2976 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();