1
    2
    3
    4
    5
    6
    7
    8
    9
   10
   11
   12
   13
   14
   15
   16
   17
   18
   19
   20
   21
   22
   23
   24
   25
   26
   27
   28
   29
   30
   31
   32
   33
   34
   35
   36
   37
   38
   39
   40
   41
   42
   43
   44
   45
   46
   47
   48
   49
   50
   51
   52
   53
   54
   55
   56
   57
   58
   59
   60
   61
   62
   63

ash / system / eche / eche_icon_loading_indicator_view.h [blame]

// Copyright 2022 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef ASH_SYSTEM_ECHE_ECHE_ICON_LOADING_INDICATOR_VIEW_H_
#define ASH_SYSTEM_ECHE_ECHE_ICON_LOADING_INDICATOR_VIEW_H_

#include "ash/ash_export.h"
#include "base/memory/raw_ptr.h"
#include "base/scoped_observation.h"
#include "base/time/time.h"
#include "ui/base/metadata/metadata_header_macros.h"
#include "ui/gfx/animation/animation_delegate.h"
#include "ui/gfx/animation/throb_animation.h"
#include "ui/views/view.h"
#include "ui/views/view_observer.h"

namespace gfx {
class Canvas;
class Animation;
}  // namespace gfx

namespace ash {

// Draws a spinner around a given parent view.
class ASH_EXPORT EcheIconLoadingIndicatorView : public views::View,
                                                public views::ViewObserver,
                                                public gfx::AnimationDelegate {
  METADATA_HEADER(EcheIconLoadingIndicatorView, views::View)

 public:
  explicit EcheIconLoadingIndicatorView(views::View* parent);
  EcheIconLoadingIndicatorView(const EcheIconLoadingIndicatorView&) = delete;
  EcheIconLoadingIndicatorView& operator=(const EcheIconLoadingIndicatorView&) =
      delete;
  ~EcheIconLoadingIndicatorView() override;

  void SetAnimating(bool animating);
  bool GetAnimating() const;

  // views::View:
  void OnPaint(gfx::Canvas* canvas) override;

  // views::ViewObserver:
  void OnViewBoundsChanged(views::View* observed_view) override;

  // gfx::AnimationDelegate:
  void AnimationProgressed(const gfx::Animation* animation) override;

 private:
  std::optional<base::TimeTicks> throbber_start_time_;

  raw_ptr<views::View> parent_ = nullptr;  // Unowned.

  base::ScopedObservation<views::View, views::ViewObserver> observed_session_{
      this};

  gfx::ThrobAnimation animation_{this};
};

}  // namespace ash

#endif  // ASH_SYSTEM_ECHE_ECHE_ICON_LOADING_INDICATOR_VIEW_H_