blob: 783decac767cfd71e6240666e7ff79283e4f2c6b [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
Arthur Sonzogni3eb9fd512024-02-09 12:20:4310#include <optional>
11
estade618db462015-05-28 00:52:3012#include "base/time/time.h"
estade4b7d20a2015-05-03 20:21:2613#include "third_party/skia/include/core/SkColor.h"
14#include "ui/gfx/gfx_export.h"
15
estade4b7d20a2015-05-03 20:21:2616namespace gfx {
17
18class Canvas;
19class Rect;
Peter Boström18a40fa2018-10-31 19:03:5020class RectF;
estade4b7d20a2015-05-03 20:21:2621
David Black869a906b2021-07-23 05:38:0422// This struct describes the "spinning" state of a throb animation.
23struct GFX_EXPORT ThrobberSpinningState {
24 // The start angle of the arc in degrees.
25 SkScalar start_angle = 0.f;
26
27 // The sweep angle of the arc in degrees. Positive is clockwise.
28 SkScalar sweep_angle = 0.f;
29};
30
estade618db462015-05-28 00:52:3031// This struct describes the "waiting" mode of a throb animation. It's useful
32// for building a "spinning" state animation on top of a previous "waiting"
33// mode animation. See PaintThrobberSpinningAfterWaiting.
34struct GFX_EXPORT ThrobberWaitingState {
35 // The amount of time that was spent in the waiting state.
36 base::TimeDelta elapsed_time;
Brett Wilson0e161fe52017-12-01 00:05:2937
estade618db462015-05-28 00:52:3038 // The color of the arc in the waiting state.
Brett Wilson0e161fe52017-12-01 00:05:2939 SkColor color = SK_ColorTRANSPARENT;
40
estade618db462015-05-28 00:52:3041 // An opaque value used to cache calculations made by
42 // PaintThrobberSpinningAfterWaiting.
43 base::TimeDelta arc_time_offset;
44};
45
David Black869a906b2021-07-23 05:38:0446// Returns the calculated state for a single frame of the throbber in the
47// "spinning", aka Material, state. Note that animation duration is a hardcoded
48// value in line with Material design specifications but is cyclic, so the
49// specified `elapsed_time` may exceed animation duration.
50GFX_EXPORT ThrobberSpinningState
51CalculateThrobberSpinningState(base::TimeDelta elapsed_time);
52
estade4b7d20a2015-05-03 20:21:2653// Paints a single frame of the throbber in the "spinning", aka Material, state.
David Black869a906b2021-07-23 05:38:0454// Note that animation duration is a hardcoded value in line with Material
55// design specifications but is cyclic, so the specified `elapsed_time` may
56// exceed animation duration.
Peter Boström7c316e2d2019-01-19 03:26:3857GFX_EXPORT void PaintThrobberSpinning(
58 Canvas* canvas,
59 const Rect& bounds,
60 SkColor color,
61 const base::TimeDelta& elapsed_time,
Arthur Sonzogni3eb9fd512024-02-09 12:20:4362 std::optional<SkScalar> stroke_width = std::nullopt);
estade4b7d20a2015-05-03 20:21:2663
64// Paints a throbber in the "waiting" state. Used when waiting on a network
65// response, for example.
Peter Boström7c316e2d2019-01-19 03:26:3866GFX_EXPORT void PaintThrobberWaiting(
67 Canvas* canvas,
68 const Rect& bounds,
69 SkColor color,
70 const base::TimeDelta& elapsed_time,
Arthur Sonzogni3eb9fd512024-02-09 12:20:4371 std::optional<SkScalar> stroke_width = std::nullopt);
estade618db462015-05-28 00:52:3072
73// Paint a throbber in the "spinning" state, smoothly transitioning from a
74// previous "waiting" state described by |waiting_state|, which is an in-out
75// param.
76GFX_EXPORT void PaintThrobberSpinningAfterWaiting(
77 Canvas* canvas,
78 const Rect& bounds,
79 SkColor color,
80 const base::TimeDelta& elapsed_time,
Peter Boström7c316e2d2019-01-19 03:26:3881 ThrobberWaitingState* waiting_state,
Arthur Sonzogni3eb9fd512024-02-09 12:20:4382 std::optional<SkScalar> stroke_width = std::nullopt);
estade4b7d20a2015-05-03 20:21:2683
Peter Boström18a40fa2018-10-31 19:03:5084// Paints a throbber in the "waiting" state (bouncing back and forth). Used when
85// waiting on a network response, for example.
86GFX_EXPORT void PaintNewThrobberWaiting(Canvas* canvas,
87 const RectF& throbber_container_bounds,
88 SkColor color,
89 const base::TimeDelta& elapsed_time);
estadeb5971752015-05-27 23:30:5790
estade4b7d20a2015-05-03 20:21:2691} // namespace gfx
92
93#endif // UI_GFX_PAINT_THROBBER_H_