1 /* 2 * Copyright (c) 2024 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16 #ifndef FOUNDATION_ACE_INTERFACES_INNER_API_ACE_KIT_INCLUDE_VIEW_THEME_TOKEN_THEME_H 17 #define FOUNDATION_ACE_INTERFACES_INNER_API_ACE_KIT_INCLUDE_VIEW_THEME_TOKEN_THEME_H 18 19 #include "ui/base/ace_type.h" 20 #include "ui/resource/resource_object.h" 21 #include "ui/view/theme/token_colors.h" 22 23 namespace OHOS::Ace { 24 25 using TokenThemeScopeId = int32_t; 26 27 class ACE_FORCE_EXPORT TokenTheme : public virtual AceType { 28 DECLARE_ACE_TYPE(TokenTheme, AceType); 29 30 public: TokenTheme(int32_t id)31 explicit TokenTheme(int32_t id) 32 { 33 id_ = id; 34 } 35 virtual ~TokenTheme() = default; 36 SetColors(const RefPtr<TokenColors> & colors)37 void SetColors(const RefPtr<TokenColors>& colors) 38 { 39 colors_ = colors; 40 } 41 SetDarkColors(const RefPtr<TokenColors> & darkColors)42 void SetDarkColors(const RefPtr<TokenColors>& darkColors) 43 { 44 darkColors_ = darkColors; 45 } 46 Colors()47 const RefPtr<TokenColors>& Colors() const 48 { 49 return IsDark() ? darkColors_ : colors_; 50 } 51 SetColorMode(const ColorMode & colorMode)52 void SetColorMode(const ColorMode& colorMode) 53 { 54 colorMode_ = colorMode; 55 auto colors = IsDark() ? darkColors_ : colors_; 56 if (colors) { 57 colors->SetColorMode(colorMode); 58 } 59 } 60 GetColorMode()61 const ColorMode& GetColorMode() const 62 { 63 return colorMode_; 64 } 65 GetId()66 int32_t GetId() const 67 { 68 return id_; 69 } 70 SetResObjs(std::vector<RefPtr<ResourceObject>> && resObjs)71 void SetResObjs(std::vector<RefPtr<ResourceObject>>&& resObjs) 72 { 73 if (colors_) { 74 colors_->SetResObjs(std::move(resObjs)); 75 } 76 } 77 SetDarkResObjs(std::vector<RefPtr<ResourceObject>> && darkResObjs)78 void SetDarkResObjs(std::vector<RefPtr<ResourceObject>>&& darkResObjs) 79 { 80 if (darkColors_) { 81 darkColors_->SetResObjs(std::move(darkResObjs)); 82 } 83 } 84 GetResObjs()85 std::vector<RefPtr<ResourceObject>>& GetResObjs() 86 { 87 auto colors = IsDark() ? darkColors_ : colors_; 88 if (colors) { 89 resObjs = colors->GetResObjs(); 90 } else { 91 resObjs.clear(); 92 } 93 return resObjs; 94 } 95 96 static bool IsDarkMode(); 97 98 private: 99 int32_t id_ { 0 }; 100 RefPtr<TokenColors> colors_; 101 RefPtr<TokenColors> darkColors_; 102 ColorMode colorMode_ = ColorMode::COLOR_MODE_UNDEFINED; 103 std::vector<RefPtr<ResourceObject>> resObjs; IsDark()104 bool IsDark() const 105 { 106 if (colorMode_ == ColorMode::COLOR_MODE_UNDEFINED) { 107 return IsDarkMode(); 108 } 109 return colorMode_ == ColorMode::DARK; 110 } 111 }; 112 113 } // namespace OHOS::Ace 114 #endif // FOUNDATION_ACE_INTERFACES_INNER_API_ACE_KIT_INCLUDE_VIEW_THEME_TOKEN_THEME_H 115