File: ambient_util.h

package info (click to toggle)
chromium 139.0.7258.127-1
  • links: PTS, VCS
  • area: main
  • in suites:
  • size: 6,122,068 kB
  • sloc: cpp: 35,100,771; ansic: 7,163,530; javascript: 4,103,002; python: 1,436,920; asm: 946,517; xml: 746,709; pascal: 187,653; perl: 88,691; sh: 88,436; objc: 79,953; sql: 51,488; cs: 44,583; fortran: 24,137; makefile: 22,147; tcl: 15,277; php: 13,980; yacc: 8,984; ruby: 7,485; awk: 3,720; lisp: 3,096; lex: 1,327; ada: 727; jsp: 228; sed: 36
file content (108 lines) | stat: -rw-r--r-- 4,244 bytes parent folder | download | duplicates (6)
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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
// Copyright 2019 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_AMBIENT_UTIL_AMBIENT_UTIL_H_
#define ASH_AMBIENT_UTIL_AMBIENT_UTIL_H_

#include <string>
#include <string_view>

#include "ash/ash_export.h"
#include "ash/login/ui/lock_screen.h"
#include "ash/public/cpp/ambient/ambient_backend_controller.h"
#include "ash/public/cpp/ambient/proto/photo_cache_entry.pb.h"
#include "ash/style/ash_color_provider.h"
#include "ash/webui/personalization_app/mojom/personalization_app.mojom-shared.h"

#include "ui/gfx/font_list.h"
#include "ui/gfx/shadow_value.h"

namespace ui {
class ColorProvider;
}

namespace ash {

namespace ambient {
namespace util {

inline constexpr int kDefaultTextShadowElevation = 2;

// Returns true if Ash is showing lock screen.
ASH_EXPORT bool IsShowing(LockScreen::ScreenType type);

// Ambient mode uses non-standard colors for some text and the media icon, so
// provides a wrapper for |ColorProvider::GetColor|. This is currently only
// supported for primary and secondary text and icons.
ASH_EXPORT SkColor GetColor(const ui::ColorProvider* color_provider,
                            ui::ColorId color_id,
                            bool dark_mode_enabled);

// Version of the above that uses AshColorProvider::IsDarkModeEnabled().
ASH_EXPORT SkColor GetColor(const ui::ColorProvider* color_provider,
                            ui::ColorId color_id);

// Returns the default fontlist for Ambient Mode.
ASH_EXPORT const gfx::FontList& GetDefaultFontlist();

// Returns the default static text shadow for Ambient Mode. |theme| can be a
// nullptr if the ShadowValues returned are only used to calculate margins, in
// which kPlaceholderColor will be used for the shadow color.
ASH_EXPORT gfx::ShadowValues GetTextShadowValues(
    const ui::ColorProvider* color_provider,
    int elevation = kDefaultTextShadowElevation);

ASH_EXPORT bool IsAmbientModeTopicTypeAllowed(::ambient::TopicType topic);

// A "dynamic" asset is a placeholder in an ambient Lottie animation where a
// photo of interest goes (ex: from a user’s google photos album). This
// contrasts with a "static" asset, which is a fixed image in the animation that
// does not change between animation cycles.
//
// The dynamic asset ids for ambient mode take the following format:
// "_CrOS_Photo_Position<position_id>_<idx>".
//
// A "position" represents a physical location on the screen where a photo
// appears. Its identifier is arbitrary and opaque. But there may be multiple
// assets assigned to a given position. For example, if an animation has a
// cross-fade transition from image 1 to image 2, there may be 2 image assets
// in the animation that share the same position id. However, their indices
// (the last element of the identifier) will be different. Example:
// "_CrOS_Photo_PositionA_1"
// "_CrOS_Photo_PositionA_2"
// ...
//
// The only requirement for the index is that it must reflect the order in which
// that asset appears at its position. The absolute index values do not matter.
//
// Note this naming convention is agreed upon with the animation designer, so
// any changes to the logic must be confirmed with them.
//
// Returns false and leaves the output argument untouched if the |asset_id|
// does not match the naming convention above.
struct ASH_EXPORT ParsedDynamicAssetId {
  // Orders by index first, then by position if indices match:
  // "_CrOS_Photo_PositionA_1"
  // "_CrOS_Photo_PositionB_1"
  // "_CrOS_Photo_PositionA_2"
  // "_CrOS_Photo_PositionB_2"
  bool operator<(const ParsedDynamicAssetId& other) const;

  std::string position_id;
  int idx;
};
ASH_EXPORT bool ParseDynamicLottieAssetId(std::string_view asset_id,
                                          ParsedDynamicAssetId& parsed_output);

// AmbientTheme converted to a string for readability. The returned
// std::string_view is guaranteed to be null-terminated and point to memory
// valid for the lifetime of the program.
ASH_EXPORT std::string_view AmbientThemeToString(
    personalization_app::mojom::AmbientTheme theme);

}  // namespace util
}  // namespace ambient
}  // namespace ash

#endif  // ASH_AMBIENT_UTIL_AMBIENT_UTIL_H_