ambient_util.h 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. // Copyright 2019 The Chromium Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style license that can be
  3. // found in the LICENSE file.
  4. #ifndef ASH_AMBIENT_UTIL_AMBIENT_UTIL_H_
  5. #define ASH_AMBIENT_UTIL_AMBIENT_UTIL_H_
  6. #include <string>
  7. #include "ash/ash_export.h"
  8. #include "ash/login/ui/lock_screen.h"
  9. #include "ash/public/cpp/ambient/ambient_backend_controller.h"
  10. #include "ash/public/cpp/ambient/proto/photo_cache_entry.pb.h"
  11. #include "ash/style/ash_color_provider.h"
  12. #include "base/strings/string_piece.h"
  13. #include "ui/gfx/font_list.h"
  14. #include "ui/gfx/shadow_value.h"
  15. namespace ui {
  16. class ColorProvider;
  17. }
  18. namespace ash {
  19. namespace ambient {
  20. namespace util {
  21. inline constexpr int kDefaultTextShadowElevation = 2;
  22. // Returns true if Ash is showing lock screen.
  23. ASH_EXPORT bool IsShowing(LockScreen::ScreenType type);
  24. // Ambient mode uses non-standard colors for some text and the media icon, so
  25. // provides a wrapper for |AshColorProvider::GetContentLayerColor|. This is
  26. // currently only supported for primary and secondary text and icons.
  27. ASH_EXPORT SkColor
  28. GetContentLayerColor(AshColorProvider::ContentLayerType content_layer_type,
  29. bool dark_mode_enable);
  30. // Version of the above that uses AshColorProvider::IsDarkModeEnabled().
  31. ASH_EXPORT SkColor
  32. GetContentLayerColor(AshColorProvider::ContentLayerType content_layer_type);
  33. // Returns the default fontlist for Ambient Mode.
  34. ASH_EXPORT const gfx::FontList& GetDefaultFontlist();
  35. // Returns the default static text shadow for Ambient Mode. |theme| can be a
  36. // nullptr if the ShadowValues returned are only used to calculate margins, in
  37. // which kPlaceholderColor will be used for the shadow color.
  38. ASH_EXPORT gfx::ShadowValues GetTextShadowValues(
  39. const ui::ColorProvider* color_provider,
  40. int elevation = kDefaultTextShadowElevation);
  41. ASH_EXPORT bool IsAmbientModeTopicTypeAllowed(::ambient::TopicType topic);
  42. // A "dynamic" asset is a placeholder in an ambient Lottie animation where a
  43. // photo of interest goes (ex: from a user’s google photos album). This
  44. // contrasts with a "static" asset, which is a fixed image in the animation that
  45. // does not change between animation cycles.
  46. //
  47. // The dynamic asset ids for ambient mode take the following format:
  48. // "_CrOS_Photo_Position<position_id>_<idx>".
  49. //
  50. // A "position" represents a physical location on the screen where a photo
  51. // appears. Its identifier is arbitrary and opaque. But there may be multiple
  52. // assets assigned to a given position. For example, if an animation has a
  53. // cross-fade transition from image 1 to image 2, there may be 2 image assets
  54. // in the animation that share the same position id. However, their indices
  55. // (the last element of the identifier) will be different. Example:
  56. // "_CrOS_Photo_PositionA_1"
  57. // "_CrOS_Photo_PositionA_2"
  58. // ...
  59. //
  60. // The only requirement for the index is that it must reflect the order in which
  61. // that asset appears at its position. The absolute index values do not matter.
  62. //
  63. // Note this naming convention is agreed upon with the animation designer, so
  64. // any changes to the logic must be confirmed with them.
  65. //
  66. // Returns false and leaves the output argument untouched if the |asset_id|
  67. // does not match the naming convention above.
  68. struct ASH_EXPORT ParsedDynamicAssetId {
  69. // Orders by index first, then by position if indices match:
  70. // "_CrOS_Photo_PositionA_1"
  71. // "_CrOS_Photo_PositionB_1"
  72. // "_CrOS_Photo_PositionA_2"
  73. // "_CrOS_Photo_PositionB_2"
  74. bool operator<(const ParsedDynamicAssetId& other) const;
  75. std::string position_id;
  76. int idx;
  77. };
  78. ASH_EXPORT bool ParseDynamicLottieAssetId(base::StringPiece asset_id,
  79. ParsedDynamicAssetId& parsed_output);
  80. } // namespace util
  81. } // namespace ambient
  82. } // namespace ash
  83. #endif // ASH_AMBIENT_UTIL_AMBIENT_UTIL_H_