#ifndef UI_VIEWS_CONTROLS_THROBBER_H_
#define UI_VIEWS_CONTROLS_THROBBER_H_
#include "base/time/time.h"
#include "base/timer/timer.h"
#include "ui/color/color_provider.h"
#include "ui/views/view.h"
namespace views {
class VIEWS_EXPORT Throbber : public View {
METADATA_HEADER(Throbber, View)
public:
explicit Throbber(int diameter = kDefaultDiameter);
Throbber(const Throbber&) = delete;
Throbber& operator=(const Throbber&) = delete;
~Throbber() override;
virtual void Start();
virtual void Stop();
bool GetChecked() const;
void SetChecked(bool checked);
gfx::Size CalculatePreferredSize(
const SizeBounds& ) const override;
void OnPaint(gfx::Canvas* canvas) override;
int GetDiameter() const { return diameter_; }
void SetColorId(ui::ColorId color) { color_id_ = color; }
std::optional<ui::ColorId> GetColorId() { return color_id_; }
protected:
bool IsRunning() const;
static constexpr int kDefaultDiameter = 16;
private:
base::TimeTicks start_time_;
base::RepeatingTimer timer_;
bool checked_ = false;
const int diameter_;
std::optional<ui::ColorId> color_id_;
base::WeakPtrFactory<Throbber> weak_ptr_factory_{this};
};
BEGIN_VIEW_BUILDER(VIEWS_EXPORT, Throbber, View)
VIEW_BUILDER_PROPERTY(bool, Checked)
END_VIEW_BUILDER
class VIEWS_EXPORT SmoothedThrobber : public Throbber {
METADATA_HEADER(SmoothedThrobber, Throbber)
public:
explicit SmoothedThrobber(int diameter = kDefaultDiameter);
SmoothedThrobber(const SmoothedThrobber&) = delete;
SmoothedThrobber& operator=(const SmoothedThrobber&) = delete;
~SmoothedThrobber() override;
void Start() override;
void Stop() override;
base::TimeDelta GetStartDelay() const;
void SetStartDelay(const base::TimeDelta& start_delay);
base::TimeDelta GetStopDelay() const;
void SetStopDelay(const base::TimeDelta& stop_delay);
private:
void StartDelayOver();
void StopDelayOver();
base::TimeDelta start_delay_;
base::TimeDelta stop_delay_;
base::OneShotTimer start_timer_;
base::OneShotTimer stop_timer_;
};
BEGIN_VIEW_BUILDER(VIEWS_EXPORT, SmoothedThrobber, Throbber)
VIEW_BUILDER_PROPERTY(const base::TimeDelta&, StartDelay)
VIEW_BUILDER_PROPERTY(const base::TimeDelta&, StopDelay)
END_VIEW_BUILDER
}
DEFINE_VIEW_BUILDER(VIEWS_EXPORT, Throbber)
DEFINE_VIEW_BUILDER(VIEWS_EXPORT, SmoothedThrobber)
#endif