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 #include "core/components_ng/pattern/search/search_model.h" 28 29 namespace OHOS::Ace { 30 31 /** 32 * SearchTheme defines color and styles of SearchComponent. SearchTheme should be built 33 * using SearchTheme::Builder. 34 */ 35 class SearchTheme : public virtual Theme { 36 DECLARE_ACE_TYPE(SearchTheme, Theme); 37 38 public: 39 class Builder { 40 public: 41 Builder() = default; 42 ~Builder() = default; 43 Build(const RefPtr<ThemeConstants> & themeConstants)44 RefPtr<SearchTheme> Build(const RefPtr<ThemeConstants>& themeConstants) const 45 { 46 RefPtr<SearchTheme> theme = AceType::Claim(new SearchTheme()); 47 if (!themeConstants) { 48 return theme; 49 } 50 ParsePattern(themeConstants, theme); 51 return theme; 52 } 53 54 private: ParsePattern(const RefPtr<ThemeConstants> & themeConstants,const RefPtr<SearchTheme> & theme)55 void ParsePattern(const RefPtr<ThemeConstants>& themeConstants, const RefPtr<SearchTheme>& theme) const 56 { 57 if (!theme) { 58 return; 59 } 60 RefPtr<ThemeStyle> pattern = themeConstants->GetPatternByName(THEME_PATTERN_SEARCH); 61 if (!pattern) { 62 LOGW("find pattern of search fail"); 63 return; 64 } 65 theme->height_ = pattern->GetAttr<Dimension>("search_default_height", 0.0_vp); 66 theme->iconSize_ = pattern->GetAttr<Dimension>("search_icon_size", 0.0_vp); 67 theme->closeIconSize_ = pattern->GetAttr<Dimension>("search_close_icon_size", 0.0_vp); 68 theme->closeIconHotZoneSize_ = 69 pattern->GetAttr<Dimension>("search_close_icon_hot_zone_horizontal", 0.0_vp); 70 theme->textFieldWidthReserved_ = theme->closeIconHotZoneSize_; 71 theme->leftPadding_ = pattern->GetAttr<Dimension>("search_text_field_padding_left", 0.0_vp); 72 theme->rightPadding_ = pattern->GetAttr<Dimension>("search_text_field_padding_right", 0.0_vp); 73 theme->fontWeight_ = FontWeight(static_cast<int32_t>(pattern->GetAttr<double>("search_font_weight", 0.0))); 74 theme->borderRadius_ = Radius(pattern->GetAttr<Dimension>("search_text_field_border_radius", 0.0_vp)); 75 theme->blockRightShade_ = static_cast<int32_t>(pattern->GetAttr<double>("search_block_right_shade", 0.0)); 76 theme->placeholderColor_ = pattern->GetAttr<Color>("tips_text_color", Color()); 77 theme->focusPlaceholderColor_ = pattern->GetAttr<Color>("tips_text_color_focused", Color()); 78 theme->textColor_ = pattern->GetAttr<Color>(PATTERN_TEXT_COLOR, Color()); 79 theme->focusTextColor_ = pattern->GetAttr<Color>(PATTERN_TEXT_COLOR_FOCUSED, Color()); 80 theme->fontSize_ = pattern->GetAttr<Dimension>(PATTERN_TEXT_SIZE, 0.0_fp); 81 theme->touchColor_ = pattern->GetAttr<Color>("search_touch_color", Color()); 82 theme->hoverColor_ = pattern->GetAttr<Color>("search_hover_color", Color()); 83 theme->searchDividerColor_ = pattern->GetAttr<Color>("search_divider_color", Color()); 84 theme->searchButtonTextColor_ = pattern->GetAttr<Color>("search_button_text_color", Color()); 85 theme->searchIconColor_ = pattern->GetAttr<Color>("search_icon_color", Color()); 86 theme->searchButtonTextPadding_ = pattern->GetAttr<Dimension>("search_button_text_padding", Dimension()); 87 theme->searchButtonSpace_ = pattern->GetAttr<Dimension>("search_button_space", Dimension()); 88 theme->dividerSideSpace_ = pattern->GetAttr<Dimension>("search_divider_side_space", Dimension()); 89 theme->iconHeight_ = pattern->GetAttr<Dimension>("search_icon_height", Dimension()); 90 theme->searchIconLeftSpace_ = pattern->GetAttr<Dimension>("search_icon_left_space", Dimension()); 91 theme->searchIconRightSpace_ = pattern->GetAttr<Dimension>("search_icon_right_space", Dimension()); 92 } 93 }; 94 95 ~SearchTheme() override = default; 96 GetPlaceholderColor()97 const Color& GetPlaceholderColor() const 98 { 99 return placeholderColor_; 100 } 101 GetFocusPlaceholderColor()102 const Color& GetFocusPlaceholderColor() const 103 { 104 return focusPlaceholderColor_; 105 } 106 GetTextColor()107 const Color& GetTextColor() const 108 { 109 return textColor_; 110 } 111 GetFocusTextColor()112 const Color& GetFocusTextColor() const 113 { 114 return focusTextColor_; 115 } 116 GetTouchColor()117 const Color& GetTouchColor() const 118 { 119 return touchColor_; 120 } 121 GetHoverColor()122 const Color& GetHoverColor() const 123 { 124 return hoverColor_; 125 } 126 GetHeight()127 const Dimension& GetHeight() const 128 { 129 return height_; 130 } 131 GetFontSize()132 const Dimension& GetFontSize() const 133 { 134 return fontSize_; 135 } 136 GetIconSize()137 const Dimension& GetIconSize() const 138 { 139 return iconSize_; 140 } 141 GetCloseIconSize()142 const Dimension& GetCloseIconSize() const 143 { 144 return closeIconSize_; 145 } 146 GetCloseIconHotZoneSize()147 const Dimension& GetCloseIconHotZoneSize() const 148 { 149 return closeIconHotZoneSize_; 150 } 151 GetTextFieldWidthReserved()152 const Dimension& GetTextFieldWidthReserved() const 153 { 154 return textFieldWidthReserved_; 155 } 156 GetLeftPadding()157 const Dimension& GetLeftPadding() const 158 { 159 return leftPadding_; 160 } 161 GetRightPadding()162 const Dimension& GetRightPadding() const 163 { 164 return rightPadding_; 165 } 166 GetFontWeight()167 const FontWeight& GetFontWeight() const 168 { 169 return fontWeight_; 170 } 171 GetBorderRadius()172 const Radius& GetBorderRadius() const 173 { 174 return borderRadius_; 175 } 176 GetBlockRightShade()177 bool GetBlockRightShade() const 178 { 179 return blockRightShade_; 180 } 181 GetDividerSideSpace()182 const Dimension& GetDividerSideSpace() const 183 { 184 return dividerSideSpace_; 185 } 186 GetSearchDividerWidth()187 const Dimension& GetSearchDividerWidth() const 188 { 189 return searchDividerWidth_; 190 } 191 GetSearchButtonTextPadding()192 const Dimension& GetSearchButtonTextPadding() const 193 { 194 return searchButtonTextPadding_; 195 } 196 GetSearchButtonSpace()197 const Dimension& GetSearchButtonSpace() const 198 { 199 return searchButtonSpace_; 200 } 201 GetIconHeight()202 const Dimension& GetIconHeight() const 203 { 204 return iconHeight_; 205 } 206 GetSearchIconLeftSpace()207 const Dimension& GetSearchIconLeftSpace() const 208 { 209 return searchIconLeftSpace_; 210 } 211 GetSearchIconRightSpace()212 const Dimension& GetSearchIconRightSpace() const 213 { 214 return searchIconRightSpace_; 215 } 216 GetSearchDividerColor()217 const Color& GetSearchDividerColor() const 218 { 219 return searchDividerColor_; 220 } 221 GetSearchButtonTextColor()222 const Color& GetSearchButtonTextColor() const 223 { 224 return searchButtonTextColor_; 225 } 226 GetSearchIconColor()227 const Color& GetSearchIconColor() const 228 { 229 return searchIconColor_; 230 } 231 GetCancelButtonStyle()232 const CancelButtonStyle& GetCancelButtonStyle() const 233 { 234 return cancelButtonStyle_; 235 } 236 237 protected: 238 SearchTheme() = default; 239 240 private: 241 Color placeholderColor_; 242 Color focusPlaceholderColor_; 243 Color textColor_; 244 Color focusTextColor_; 245 Color touchColor_; 246 Color hoverColor_; 247 Dimension height_; 248 Dimension fontSize_; 249 Dimension iconSize_; 250 Dimension closeIconSize_; 251 Dimension closeIconHotZoneSize_; 252 Dimension textFieldWidthReserved_; 253 Dimension leftPadding_; 254 Dimension rightPadding_; 255 FontWeight fontWeight_ = FontWeight::NORMAL; 256 Radius borderRadius_; 257 bool blockRightShade_ = false; 258 Dimension dividerSideSpace_; 259 Dimension searchDividerWidth_ = 1.0_px; 260 Dimension searchButtonTextPadding_; 261 Dimension searchButtonSpace_; 262 Dimension iconHeight_; 263 Dimension searchIconLeftSpace_; 264 Dimension searchIconRightSpace_; 265 Color searchDividerColor_; 266 Color searchButtonTextColor_; 267 Color searchIconColor_; 268 CancelButtonStyle cancelButtonStyle_ = CancelButtonStyle::INPUT; 269 }; 270 271 } // namespace OHOS::Ace 272 273 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_SEARCH_SEARCH_THEME_H 274