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_SEARCH_SEARCH_THEME_H 17 #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_SEARCH_SEARCH_THEME_H 18 19 #include "base/geometry/dimension.h" 20 #include "core/components/common/properties/border.h" 21 #include "core/components/common/properties/color.h" 22 #include "core/components/common/properties/edge.h" 23 #include "core/components/common/properties/radius.h" 24 #include "core/components/theme/theme.h" 25 #include "core/components/theme/theme_constants.h" 26 #include "core/components/theme/theme_constants_defines.h" 27 28 namespace OHOS::Ace { 29 30 /** 31 * SearchTheme defines color and styles of SearchComponent. SearchTheme should be built 32 * using SearchTheme::Builder. 33 */ 34 class SearchTheme : public virtual Theme { 35 DECLARE_ACE_TYPE(SearchTheme, Theme); 36 37 public: 38 class Builder { 39 public: 40 Builder() = default; 41 ~Builder() = default; 42 Build(const RefPtr<ThemeConstants> & themeConstants)43 RefPtr<SearchTheme> Build(const RefPtr<ThemeConstants>& themeConstants) const 44 { 45 RefPtr<SearchTheme> theme = AceType::Claim(new SearchTheme()); 46 if (!themeConstants) { 47 return theme; 48 } 49 theme->height_ = themeConstants->GetDimension(THEME_SEARCH_DEFAULT_HEIGHT); 50 theme->placeholderColor_ = themeConstants->GetColor(THEME_SEARCH_PLACEHOLDER_COLOR); 51 theme->focusPlaceholderColor_ = themeConstants->GetColor(THEME_SEARCH_FOCUS_PLACEHOLDER_COLOR); 52 theme->textColor_ = themeConstants->GetColor(THEME_SEARCH_TEXT_COLOR); 53 theme->focusTextColor_ = themeConstants->GetColor(THEME_SEARCH_FOCUS_TEXT_COLOR); 54 theme->fontSize_ = themeConstants->GetDimension(THEME_SEARCH_FONT_SIZE); 55 theme->iconSize_ = themeConstants->GetDimension(THEME_SEARCH_ICON_SIZE); 56 theme->closeIconSize_ = themeConstants->GetDimension(THEME_SEARCH_CLOSE_ICON_SIZE); 57 theme->closeIconHotZoneSize_ = themeConstants->GetDimension(THEME_SEARCH_CLOSE_ICON_HOT_ZONE_HORIZONTAL); 58 theme->textFieldWidthReserved_ = theme->closeIconHotZoneSize_; 59 theme->leftPadding_ = themeConstants->GetDimension(THEME_SEARCH_TEXT_FIELD_PADDING_LEFT); 60 theme->rightPadding_ = themeConstants->GetDimension(THEME_SEARCH_TEXT_FIELD_PADDING_RIGHT); 61 theme->fontWeight_ = FontWeight(themeConstants->GetInt(THEME_SEARCH_FONT_WEIGHT)); 62 theme->borderRadius_ = Radius(themeConstants->GetDimension(THEME_SEARCH_TEXT_FIELD_BORDER_RADIUS)); 63 theme->blockRightShade_ = themeConstants->GetInt(THEME_SEARCH_BLOCK_RIGHT_SHADE); 64 ParsePattern(themeConstants->GetThemeStyle(), theme); 65 return theme; 66 } 67 68 private: ParsePattern(const RefPtr<ThemeStyle> & themeStyle,const RefPtr<SearchTheme> & theme)69 void ParsePattern(const RefPtr<ThemeStyle>& themeStyle, const RefPtr<SearchTheme>& theme) const 70 { 71 if (!themeStyle || !theme) { 72 return; 73 } 74 theme->placeholderColor_ = themeStyle->GetAttr<Color>(SEARCH_PLACEHOLDER_COLOR, Color()); 75 theme->focusPlaceholderColor_ = themeStyle->GetAttr<Color>(SEARCH_PLACEHOLDER_COLOR, Color()); 76 theme->textColor_ = themeStyle->GetAttr<Color>(SEARCH_TEXT_COLOR, Color()); 77 theme->focusTextColor_ = themeStyle->GetAttr<Color>(SEARCH_TEXT_COLOR, Color()); 78 theme->fontSize_ = themeStyle->GetAttr<Dimension>(SEARCH_TEXT_FONT_SIZE, 0.0_fp); 79 } 80 }; 81 82 ~SearchTheme() override = default; 83 GetPlaceholderColor()84 const Color& GetPlaceholderColor() const 85 { 86 return placeholderColor_; 87 } 88 GetFocusPlaceholderColor()89 const Color& GetFocusPlaceholderColor() const 90 { 91 return focusPlaceholderColor_; 92 } 93 GetTextColor()94 const Color& GetTextColor() const 95 { 96 return textColor_; 97 } 98 GetFocusTextColor()99 const Color& GetFocusTextColor() const 100 { 101 return focusTextColor_; 102 } 103 GetHeight()104 const Dimension& GetHeight() const 105 { 106 return height_; 107 } 108 GetFontSize()109 const Dimension& GetFontSize() const 110 { 111 return fontSize_; 112 } 113 GetIconSize()114 const Dimension& GetIconSize() const 115 { 116 return iconSize_; 117 } 118 GetCloseIconSize()119 const Dimension& GetCloseIconSize() const 120 { 121 return closeIconSize_; 122 } 123 GetCloseIconHotZoneSize()124 const Dimension& GetCloseIconHotZoneSize() const 125 { 126 return closeIconHotZoneSize_; 127 } 128 GetTextFieldWidthReserved()129 const Dimension& GetTextFieldWidthReserved() const 130 { 131 return textFieldWidthReserved_; 132 } 133 GetLeftPadding()134 const Dimension& GetLeftPadding() const 135 { 136 return leftPadding_; 137 } 138 GetRightPadding()139 const Dimension& GetRightPadding() const 140 { 141 return rightPadding_; 142 } 143 GetFontWeight()144 const FontWeight& GetFontWeight() const 145 { 146 return fontWeight_; 147 } 148 GetBorderRadius()149 const Radius& GetBorderRadius() const 150 { 151 return borderRadius_; 152 } 153 GetBlockRightShade()154 bool GetBlockRightShade() const 155 { 156 return blockRightShade_; 157 } 158 159 protected: 160 SearchTheme() = default; 161 162 private: 163 Color placeholderColor_; 164 Color focusPlaceholderColor_; 165 Color textColor_; 166 Color focusTextColor_; 167 Dimension height_; 168 Dimension fontSize_; 169 Dimension iconSize_; 170 Dimension closeIconSize_; 171 Dimension closeIconHotZoneSize_; 172 Dimension textFieldWidthReserved_; 173 Dimension leftPadding_; 174 Dimension rightPadding_; 175 FontWeight fontWeight_ = FontWeight::NORMAL; 176 Radius borderRadius_; 177 bool blockRightShade_ = false; 178 }; 179 180 } // namespace OHOS::Ace 181 182 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_SEARCH_SEARCH_THEME_H 183