1 /* 2 * Copyright (c) 2023 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_NG_PATTERN_FORM_FORM_THEME_H 17 #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERN_FORM_FORM_THEME_H 18 19 #include "core/components/common/properties/color.h" 20 #include "core/components/common/properties/text_style.h" 21 #include "core/components/theme/theme.h" 22 #include "core/components/theme/theme_constants.h" 23 #include "core/components/theme/theme_constants_defines.h" 24 25 namespace OHOS::Ace::NG { 26 /** 27 * FormTheme defines color and styles of FormPattern. FormTheme should be built 28 * using FormTheme::Builder. 29 */ 30 class FormTheme : public virtual Theme { 31 DECLARE_ACE_TYPE(FormTheme, Theme); 32 33 public: 34 class Builder { 35 public: 36 Builder() = default; 37 ~Builder() = default; 38 Build(const RefPtr<ThemeConstants> & themeConstants)39 RefPtr<FormTheme> Build(const RefPtr<ThemeConstants>& themeConstants) const 40 { 41 RefPtr<FormTheme> theme = AceType::Claim(new FormTheme()); 42 if (!themeConstants) { 43 return theme; 44 } 45 46 ParsePattern(themeConstants->GetThemeStyle(), theme); 47 return theme; 48 } 49 50 private: ParsePattern(const RefPtr<ThemeStyle> & themeStyle,const RefPtr<FormTheme> & theme)51 void ParsePattern(const RefPtr<ThemeStyle>& themeStyle, const RefPtr<FormTheme>& theme) const 52 { 53 if (!themeStyle) { 54 LOGE("themeStyle is null"); 55 return; 56 } 57 58 auto formPattern = themeStyle->GetAttr<RefPtr<ThemeStyle>>(THEME_PATTERN_FORM, nullptr); 59 if (!formPattern) { 60 LOGE("formPattern is null"); 61 return; 62 } 63 64 theme->unTrustBackgroundColor_ = formPattern->GetAttr<Color>("form_untrust_background_color", Color::RED); 65 } 66 }; 67 68 ~FormTheme() override = default; 69 GetUnTrustBackgroundColor()70 const Color& GetUnTrustBackgroundColor() const 71 { 72 return unTrustBackgroundColor_; 73 } 74 75 protected: 76 FormTheme() = default; 77 78 private: 79 Color unTrustBackgroundColor_ = Color::BLUE; 80 }; 81 } // namespace OHOS::Ace 82 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERN_FORM_FORM_THEME_H 83