1 /* 2 * Copyright (c) 2021 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_FRAMEWORKS_CORE_COMPONENTS_SEMI_MODAL_SEMI_MODAL_THEME_H 17 #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_SEMI_MODAL_SEMI_MODAL_THEME_H 18 19 #include "core/components/common/properties/color.h" 20 #include "core/components/theme/theme.h" 21 #include "core/components/theme/theme_constants.h" 22 #include "core/components/theme/theme_constants_defines.h" 23 24 namespace OHOS::Ace { 25 26 class SemiModalTheme : public virtual Theme { 27 DECLARE_ACE_TYPE(SemiModalTheme, Theme); 28 29 public: 30 class Builder { 31 public: 32 Builder() = default; 33 ~Builder() = default; 34 Build(const RefPtr<ThemeConstants> & themeConstants)35 RefPtr<SemiModalTheme> Build(const RefPtr<ThemeConstants>& themeConstants) const 36 { 37 RefPtr<SemiModalTheme> theme = AceType::Claim(new SemiModalTheme()); 38 if (!themeConstants) { 39 return theme; 40 } 41 theme->bgColor_ = themeConstants->GetColor(THEME_SEMI_MODAL_BACKGROUND_COLOR); 42 ParsePattern(themeConstants, theme); 43 return theme; 44 } 45 private: ParsePattern(const RefPtr<ThemeConstants> & themeConstants,const RefPtr<SemiModalTheme> & theme)46 void ParsePattern(const RefPtr<ThemeConstants>& themeConstants, const RefPtr<SemiModalTheme>& theme) const 47 { 48 RefPtr<ThemeStyle> semiModalPattern = themeConstants->GetPatternByName(THEME_PATTERN_SEMI_MODAL); 49 if (!semiModalPattern) { 50 return; 51 } 52 theme->bgColor_ = semiModalPattern->GetAttr<Color>(PATTERN_BG_COLOR, Color()); 53 } 54 }; 55 ~SemiModalTheme() override = default; 56 GetBgColor()57 const Color& GetBgColor() const 58 { 59 return bgColor_; 60 } 61 62 protected: 63 SemiModalTheme() = default; 64 65 private: 66 Color bgColor_; 67 }; 68 69 } // namespace OHOS::Ace 70 71 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_SEMI_MODAL_SEMI_MODAL_THEME_H 72