#ifndef UI_VIEWS_CONTROLS_PROGRESS_BAR_H_
#define UI_VIEWS_CONTROLS_PROGRESS_BAR_H_
#include <memory>
#include <optional>
#include "ui/color/color_id.h"
#include "ui/gfx/animation/animation_delegate.h"
#include "ui/gfx/geometry/rounded_corners_f.h"
#include "ui/views/metadata/view_factory.h"
#include "ui/views/view.h"
namespace gfx {
class LinearAnimation;
}
namespace views {
class VIEWS_EXPORT ProgressBar : public View, public gfx::AnimationDelegate {
METADATA_HEADER(ProgressBar, View)
public:
ProgressBar();
ProgressBar(const ProgressBar&) = delete;
ProgressBar& operator=(const ProgressBar&) = delete;
~ProgressBar() override;
gfx::Size CalculatePreferredSize(
const SizeBounds& ) const override;
void VisibilityChanged(View* starting_from, bool is_visible) override;
void AddedToWidget() override;
void OnPaint(gfx::Canvas* canvas) override;
double GetValue() const;
void SetValue(double value);
void SetPaused(bool is_paused);
SkColor GetForegroundColor() const;
void SetForegroundColor(SkColor color);
std::optional<ui::ColorId> GetForegroundColorId() const;
void SetForegroundColorId(std::optional<ui::ColorId> color_id);
SkColor GetBackgroundColor() const;
void SetBackgroundColor(SkColor color);
std::optional<ui::ColorId> GetBackgroundColorId() const;
void SetBackgroundColorId(std::optional<ui::ColorId> color_id);
int GetPreferredHeight() const;
void SetPreferredHeight(int preferred_height);
gfx::RoundedCornersF GetPreferredCornerRadii() const;
void SetPreferredCornerRadii(
std::optional<gfx::RoundedCornersF> preferred_corner_radii);
protected:
int preferred_height() const { return preferred_height_; }
private:
void AnimationProgressed(const gfx::Animation* animation) override;
void AnimationEnded(const gfx::Animation* animation) override;
bool IsIndeterminate();
bool GetPaused() const { return is_paused_; }
void OnPaintIndeterminate(gfx::Canvas* canvas);
void MaybeNotifyAccessibilityValueChanged();
double current_value_ = 0.0;
bool is_paused_ = false;
int preferred_height_ = 5;
std::optional<gfx::RoundedCornersF> preferred_corner_radii_ =
gfx::RoundedCornersF(3);
std::optional<SkColor> foreground_color_;
std::optional<ui::ColorId> foreground_color_id_;
std::optional<SkColor> background_color_;
std::optional<ui::ColorId> background_color_id_;
std::unique_ptr<gfx::LinearAnimation> indeterminate_bar_animation_;
int last_announced_percentage_ = -1;
};
BEGIN_VIEW_BUILDER(VIEWS_EXPORT, ProgressBar, View)
VIEW_BUILDER_PROPERTY(double, Value)
VIEW_BUILDER_PROPERTY(bool, Paused)
VIEW_BUILDER_PROPERTY(SkColor, ForegroundColor)
VIEW_BUILDER_PROPERTY(std::optional<ui::ColorId>, ForegroundColorId)
VIEW_BUILDER_PROPERTY(SkColor, BackgroundColor)
VIEW_BUILDER_PROPERTY(std::optional<ui::ColorId>, BackgroundColorId)
VIEW_BUILDER_PROPERTY(int, PreferredHeight)
VIEW_BUILDER_PROPERTY(std::optional<gfx::RoundedCornersF>, PreferredCornerRadii)
END_VIEW_BUILDER
}
DEFINE_VIEW_BUILDER(VIEWS_EXPORT, ProgressBar)
#endif