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