blob: 9d0284560fe09e9a6964a82772e2f3cf9cdf813f [file] [log] [blame]
Avi Drissman3e1a26c2022-09-15 20:26:031// Copyright 2015 The Chromium Authors
estade4b7d20a2015-05-03 20:21:262// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#ifndef UI_GFX_PAINT_THROBBER_H_
6#define UI_GFX_PAINT_THROBBER_H_
7
avic89eb8d42015-12-23 08:08:188#include <stdint.h>
9
estade618db462015-05-28 00:52:3010#include "base/time/time.h"
Anton Bikineeveed0b26b2021-05-16 03:16:4811#include "third_party/abseil-cpp/absl/types/optional.h"
estade4b7d20a2015-05-03 20:21:2612#include "third_party/skia/include/core/SkColor.h"
13#include "ui/gfx/gfx_export.h"
14
estade4b7d20a2015-05-03 20:21:2615namespace gfx {
16
17class Canvas;
18class Rect;
Peter Boström18a40fa2018-10-31 19:03:5019class RectF;
estade4b7d20a2015-05-03 20:21:2620
David Black869a906b2021-07-23 05:38:0421// This struct describes the "spinning" state of a throb animation.
22struct GFX_EXPORT ThrobberSpinningState {
23 // The start angle of the arc in degrees.
24 SkScalar start_angle = 0.f;
25
26 // The sweep angle of the arc in degrees. Positive is clockwise.
27 SkScalar sweep_angle = 0.f;
28};
29
estade618db462015-05-28 00:52:3030// This struct describes the "waiting" mode of a throb animation. It's useful
31// for building a "spinning" state animation on top of a previous "waiting"
32// mode animation. See PaintThrobberSpinningAfterWaiting.
33struct GFX_EXPORT ThrobberWaitingState {
34 // The amount of time that was spent in the waiting state.
35 base::TimeDelta elapsed_time;
Brett Wilson0e161fe52017-12-01 00:05:2936
estade618db462015-05-28 00:52:3037 // The color of the arc in the waiting state.
Brett Wilson0e161fe52017-12-01 00:05:2938 SkColor color = SK_ColorTRANSPARENT;
39
estade618db462015-05-28 00:52:3040 // An opaque value used to cache calculations made by
41 // PaintThrobberSpinningAfterWaiting.
42 base::TimeDelta arc_time_offset;
43};
44
David Black869a906b2021-07-23 05:38:0445// Returns the calculated state for a single frame of the throbber in the
46// "spinning", aka Material, state. Note that animation duration is a hardcoded
47// value in line with Material design specifications but is cyclic, so the
48// specified `elapsed_time` may exceed animation duration.
49GFX_EXPORT ThrobberSpinningState
50CalculateThrobberSpinningState(base::TimeDelta elapsed_time);
51
estade4b7d20a2015-05-03 20:21:2652// Paints a single frame of the throbber in the "spinning", aka Material, state.
David Black869a906b2021-07-23 05:38:0453// Note that animation duration is a hardcoded value in line with Material
54// design specifications but is cyclic, so the specified `elapsed_time` may
55// exceed animation duration.
Peter Boström7c316e2d2019-01-19 03:26:3856GFX_EXPORT void PaintThrobberSpinning(
57 Canvas* canvas,
58 const Rect& bounds,
59 SkColor color,
60 const base::TimeDelta& elapsed_time,
Anton Bikineeveed0b26b2021-05-16 03:16:4861 absl::optional<SkScalar> stroke_width = absl::nullopt);
estade4b7d20a2015-05-03 20:21:2662
63// Paints a throbber in the "waiting" state. Used when waiting on a network
64// response, for example.
Peter Boström7c316e2d2019-01-19 03:26:3865GFX_EXPORT void PaintThrobberWaiting(
66 Canvas* canvas,
67 const Rect& bounds,
68 SkColor color,
69 const base::TimeDelta& elapsed_time,
Anton Bikineeveed0b26b2021-05-16 03:16:4870 absl::optional<SkScalar> stroke_width = absl::nullopt);
estade618db462015-05-28 00:52:3071
72// Paint a throbber in the "spinning" state, smoothly transitioning from a
73// previous "waiting" state described by |waiting_state|, which is an in-out
74// param.
75GFX_EXPORT void PaintThrobberSpinningAfterWaiting(
76 Canvas* canvas,
77 const Rect& bounds,
78 SkColor color,
79 const base::TimeDelta& elapsed_time,
Peter Boström7c316e2d2019-01-19 03:26:3880 ThrobberWaitingState* waiting_state,
Anton Bikineeveed0b26b2021-05-16 03:16:4881 absl::optional<SkScalar> stroke_width = absl::nullopt);
estade4b7d20a2015-05-03 20:21:2682
Peter Boström18a40fa2018-10-31 19:03:5083// Paints a throbber in the "waiting" state (bouncing back and forth). Used when
84// waiting on a network response, for example.
85GFX_EXPORT void PaintNewThrobberWaiting(Canvas* canvas,
86 const RectF& throbber_container_bounds,
87 SkColor color,
88 const base::TimeDelta& elapsed_time);
estadeb5971752015-05-27 23:30:5789
estade4b7d20a2015-05-03 20:21:2690} // namespace gfx
91
92#endif // UI_GFX_PAINT_THROBBER_H_