From 3fa58108a00b538fb57a4734c9ba35cfd93d2c00 Mon Sep 17 00:00:00 2001 From: kseniazakharova Date: Wed, 18 Dec 2024 10:56:05 +0300 Subject: [PATCH] Implementation for Search Theme Wrapper --- .../ark_theme/theme_apply/js_search_theme.h | 69 ---------- .../src/theme/ArkThemeWhiteList.ts | 1 - .../declarative_frontend/engine/arkTheme.js | 1 - .../arkts_native_search_bridge.cpp | 3 - .../declarative_frontend/jsview/js_search.cpp | 41 +++--- .../declarative_frontend/jsview/js_search.h | 1 + .../jsview/models/search_model_impl.cpp | 1 - .../jsview/models/search_model_impl.h | 8 ++ .../core/components/search/search_theme.h | 13 +- .../components/theme/theme_manager_impl.cpp | 4 +- .../search/search_layout_algorithm.cpp | 28 ++-- .../pattern/search/search_layout_property.h | 6 + .../pattern/search/search_model.h | 8 ++ .../pattern/search/search_model_ng.cpp | 119 ++++++++++++++-- .../pattern/search/search_model_ng.h | 8 ++ .../pattern/search/search_pattern.cpp | 127 +++++++++++++++--- .../pattern/search/search_pattern.h | 1 + .../pattern/search/search_theme_wrapper.h | 72 ++++++++++ .../native/node/search_modifier.cpp | 10 +- 19 files changed, 377 insertions(+), 144 deletions(-) delete mode 100644 frameworks/bridge/declarative_frontend/ark_theme/theme_apply/js_search_theme.h create mode 100644 frameworks/core/components_ng/pattern/search/search_theme_wrapper.h diff --git a/frameworks/bridge/declarative_frontend/ark_theme/theme_apply/js_search_theme.h b/frameworks/bridge/declarative_frontend/ark_theme/theme_apply/js_search_theme.h deleted file mode 100644 index 01c635ef7194..000000000000 --- a/frameworks/bridge/declarative_frontend/ark_theme/theme_apply/js_search_theme.h +++ /dev/null @@ -1,69 +0,0 @@ -/* - * Copyright (c) 2024 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef FRAMEWORKS_BRIDGE_DECLARATIVE_FRONTEND_THEME_JS_SEARCH_THEME_H -#define FRAMEWORKS_BRIDGE_DECLARATIVE_FRONTEND_THEME_JS_SEARCH_THEME_H - -#include "bridge/declarative_frontend/ark_theme/theme_apply/js_theme_utils.h" -#include "core/components_ng/pattern/search/search_model.h" -#include "core/components_ng/base/view_abstract_model.h" - -namespace OHOS::Ace::Framework { -class JSSeacrhTheme { -public: - static void ApplyTheme() - { - // check whether we have Theme for id or not - auto themeColors = JSThemeUtils::GetThemeColors(); - if (!themeColors) { - // no need to apply custom theme colors - return; - } - SearchModel::GetInstance()->SetTextColor(themeColors.value().FontPrimary()); - SearchModel::GetInstance()->SetPlaceholderColor(themeColors.value().FontSecondary()); - SearchModel::GetInstance()->SetSearchIconColor(themeColors.value().IconSecondary()); - SearchModel::GetInstance()->SetCaretColor(themeColors.value().Brand()); - SearchModel::GetInstance()->SetCancelIconColor(themeColors.value().IconSecondary()); - SearchModel::GetInstance()->SetSearchButtonFontColor(themeColors.value().FontEmphasize()); - Color selectedColor = themeColors.value().Brand(); - // Alpha = 255 means opaque - if (selectedColor.GetAlpha() == JSThemeUtils::DEFAULT_ALPHA) { - // Default setting of 20% opacity - selectedColor = selectedColor.ChangeOpacity(JSThemeUtils::DEFAULT_OPACITY); - } - SearchModel::GetInstance()->SetSelectedBackgroundColor(selectedColor); - ViewAbstractModel::GetInstance()->SetBackgroundColor(themeColors.value().CompBackgroundTertiary()); - } - - static bool ObtainCancelIconColor(Color &color) - { - if (auto themeColors = JSThemeUtils::GetThemeColors(); themeColors.has_value()) { - color = themeColors->IconSecondary(); - return true; - } - return false; - } - - static bool ObtainSearchButtonFontColor(Color &color) - { - if (auto themeColors = JSThemeUtils::GetThemeColors(); themeColors.has_value()) { - color = themeColors->FontEmphasize(); - return true; - } - return false; - } -}; -} // namespace OHOS::Ace::Framework -#endif // FRAMEWORKS_BRIDGE_DECLARATIVE_FRONTEND_THEME_JS_SEARCH_THEME_H \ No newline at end of file diff --git a/frameworks/bridge/declarative_frontend/ark_theme/theme_manager/src/theme/ArkThemeWhiteList.ts b/frameworks/bridge/declarative_frontend/ark_theme/theme_manager/src/theme/ArkThemeWhiteList.ts index a58b9a76e444..f933a08b6f44 100644 --- a/frameworks/bridge/declarative_frontend/ark_theme/theme_manager/src/theme/ArkThemeWhiteList.ts +++ b/frameworks/bridge/declarative_frontend/ark_theme/theme_manager/src/theme/ArkThemeWhiteList.ts @@ -21,7 +21,6 @@ class ArkThemeWhiteList { // strongly recommended to use alphabetical order private static whiteList: Array = [ 'Badge', - 'Search' ]; /** diff --git a/frameworks/bridge/declarative_frontend/engine/arkTheme.js b/frameworks/bridge/declarative_frontend/engine/arkTheme.js index 454b0eb52c35..32d48af5a98f 100644 --- a/frameworks/bridge/declarative_frontend/engine/arkTheme.js +++ b/frameworks/bridge/declarative_frontend/engine/arkTheme.js @@ -1075,5 +1075,4 @@ class ArkThemeWhiteList { } ArkThemeWhiteList.whiteList = [ 'Badge', - 'Search' ]; diff --git a/frameworks/bridge/declarative_frontend/engine/jsi/nativeModule/arkts_native_search_bridge.cpp b/frameworks/bridge/declarative_frontend/engine/jsi/nativeModule/arkts_native_search_bridge.cpp index 28f5e5e933ed..82e6fb1d69f9 100644 --- a/frameworks/bridge/declarative_frontend/engine/jsi/nativeModule/arkts_native_search_bridge.cpp +++ b/frameworks/bridge/declarative_frontend/engine/jsi/nativeModule/arkts_native_search_bridge.cpp @@ -23,7 +23,6 @@ #include "base/utils/utils.h" #include "base/memory/ace_type.h" #include "frameworks/core/components_ng/pattern/search/search_model_ng.h" -#include "frameworks/bridge/declarative_frontend/ark_theme/theme_apply/js_search_theme.h" #include "frameworks/bridge/declarative_frontend/jsview/js_text_editable_controller.h" #include "frameworks/bridge/declarative_frontend/jsview/js_utils.h" @@ -80,7 +79,6 @@ ArkUINativeModuleValue SearchBridge::SetSearchInitialize(ArkUIRuntimeCallInfo* r } SearchModel::GetInstance()->SetFocusable(true); SearchModel::GetInstance()->SetFocusNode(true); - Framework::JSSeacrhTheme::ApplyTheme(); return panda::JSValueRef::Undefined(vm); } @@ -90,7 +88,6 @@ ArkUINativeModuleValue SearchBridge::ResetSearchInitialize(ArkUIRuntimeCallInfo* CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr)); SearchModel::GetInstance()->SetFocusable(true); SearchModel::GetInstance()->SetFocusNode(true); - Framework::JSSeacrhTheme::ApplyTheme(); return panda::JSValueRef::Undefined(vm); } diff --git a/frameworks/bridge/declarative_frontend/jsview/js_search.cpp b/frameworks/bridge/declarative_frontend/jsview/js_search.cpp index 3b528379b2fb..af44c428da59 100644 --- a/frameworks/bridge/declarative_frontend/jsview/js_search.cpp +++ b/frameworks/bridge/declarative_frontend/jsview/js_search.cpp @@ -22,7 +22,6 @@ #endif #include "base/log/ace_scoring_log.h" -#include "bridge/declarative_frontend/ark_theme/theme_apply/js_search_theme.h" #include "bridge/declarative_frontend/engine/functions/js_clipboard_function.h" #include "bridge/declarative_frontend/engine/functions/js_function.h" #include "bridge/declarative_frontend/engine/jsi/js_ui_index.h" @@ -99,6 +98,7 @@ void JSSearch::JSBind(BindingTarget globalObj) JSClass::StaticMethod("searchButton", &JSSearch::SetSearchButton, opt); JSClass::StaticMethod("searchIcon", &JSSearch::SetSearchIcon, opt); JSClass::StaticMethod("cancelButton", &JSSearch::SetCancelButton, opt); + JSClass::StaticMethod("backgroundColor", &JSSearch::SetBackgroundColor, opt); JSClass::StaticMethod("fontColor", &JSSearch::SetTextColor, opt); JSClass::StaticMethod("caretStyle", &JSSearch::SetCaret, opt); JSClass::StaticMethod("placeholderColor", &JSSearch::SetPlaceholderColor, opt); @@ -243,7 +243,6 @@ void JSSearch::Create(const JSCallbackInfo& info) if (!changeEventVal->IsUndefined() && changeEventVal->IsFunction()) { ParseSearchValueObject(info, changeEventVal); } - JSSeacrhTheme::ApplyTheme(); } void JSSearch::SetSelectedBackgroundColor(const JSCallbackInfo& info) @@ -267,6 +266,19 @@ void JSSearch::SetSelectedBackgroundColor(const JSCallbackInfo& info) SearchModel::GetInstance()->SetSelectedBackgroundColor(selectedColor); } +void JSSearch::SetBackgroundColor(const JSCallbackInfo& info) +{ + if (info.Length() < 1) { + return; + } + Color backgroundColor; + if (!ParseJsColor(info[0], backgroundColor)) { + SearchModel::GetInstance()->ResetBackgroundColor(); + return; + } + SearchModel::GetInstance()->SetBackgroundColor(backgroundColor); +} + void JSSearch::SetEnableKeyboardOnFocus(const JSCallbackInfo& info) { if (info[0]->IsUndefined() || !info[0]->IsBoolean()) { @@ -320,17 +332,12 @@ void JSSearch::SetSearchButton(const JSCallbackInfo& info) auto fontColorProp = param->GetProperty("fontColor"); if (fontColorProp->IsUndefined() || fontColorProp->IsNull() || !ParseJsColor(fontColorProp, fontColor)) { - if (!JSSeacrhTheme::ObtainSearchButtonFontColor(fontColor)) { - SearchModel::GetInstance()->SetSearchButtonFontColor(fontColor); - } + SearchModel::GetInstance()->ResetSearchButtonFontColor(); } else { SearchModel::GetInstance()->SetSearchButtonFontColor(fontColor); } } else { SearchModel::GetInstance()->SetSearchButtonFontSize(theme->GetFontSize()); - if (!JSSeacrhTheme::ObtainSearchButtonFontColor(fontColor)) { - SearchModel::GetInstance()->SetSearchButtonFontColor(fontColor); - } } } @@ -458,6 +465,10 @@ void JSSearch::SetSearchImageIcon(const JSCallbackInfo& info) auto colorProp = param->GetProperty("color"); if (!colorProp->IsUndefined() && !colorProp->IsNull()) { ParseJsColor(colorProp, colorVal); + SearchModel::GetInstance()->SetSearchCancelIconColor(colorVal); + } + else { + SearchModel::GetInstance()->ResetSearchCancelIconColor(); } std::string bundleName; @@ -529,13 +540,11 @@ void JSSearch::SetIconStyle(const JSCallbackInfo& info) void JSSearch::SetTextColor(const JSCallbackInfo& info) { - auto theme = GetTheme(); - CHECK_NULL_VOID(theme); - auto value = JSRef::Cast(info[0]); Color colorVal; if (!ParseJsColor(value, colorVal)) { - colorVal = theme->GetTextColor(); + SearchModel::GetInstance()->ResetTextColor(); + return; } SearchModel::GetInstance()->SetTextColor(colorVal); } @@ -559,7 +568,8 @@ void JSSearch::SetCaret(const JSCallbackInfo& info) Color caretColor; auto caretColorProp = param->GetProperty("color"); if (caretColorProp->IsUndefined() || caretColorProp->IsNull() || !ParseJsColor(caretColorProp, caretColor)) { - caretColor = textFieldTheme->GetCursorColor(); + SearchModel::GetInstance()->ResetCaretColor(); + return; } SearchModel::GetInstance()->SetCaretColor(caretColor); } @@ -620,9 +630,8 @@ void JSSearch::SetPlaceholderColor(const JSCallbackInfo& info) auto value = JSRef::Cast(info[0]); Color colorVal; if (!ParseJsColor(value, colorVal)) { - auto theme = GetTheme(); - CHECK_NULL_VOID(theme); - colorVal = theme->GetPlaceholderColor(); + SearchModel::GetInstance()->ResetPlaceholderColor(); + return; } SearchModel::GetInstance()->SetPlaceholderColor(colorVal); } diff --git a/frameworks/bridge/declarative_frontend/jsview/js_search.h b/frameworks/bridge/declarative_frontend/jsview/js_search.h index aedd6aa8dd04..4a191086c8e0 100644 --- a/frameworks/bridge/declarative_frontend/jsview/js_search.h +++ b/frameworks/bridge/declarative_frontend/jsview/js_search.h @@ -33,6 +33,7 @@ public: static void SetSearchButton(const JSCallbackInfo& info); static void SetSearchIcon(const JSCallbackInfo& info); static void SetCancelButton(const JSCallbackInfo& info); + static void SetBackgroundColor(const JSCallbackInfo& info); static void SetTextColor(const JSCallbackInfo& info); static void SetCaret(const JSCallbackInfo& info); static void SetPlaceholderColor(const JSCallbackInfo& info); diff --git a/frameworks/bridge/declarative_frontend/jsview/models/search_model_impl.cpp b/frameworks/bridge/declarative_frontend/jsview/models/search_model_impl.cpp index 51d5ad3e06cd..b5dc9a6e5785 100644 --- a/frameworks/bridge/declarative_frontend/jsview/models/search_model_impl.cpp +++ b/frameworks/bridge/declarative_frontend/jsview/models/search_model_impl.cpp @@ -86,7 +86,6 @@ void SearchModelImpl::SetPlaceholderColor(const Color& color) LOGE("text component error"); return; } - textFieldComponent->SetPlaceholderColor(color); textFieldComponent->SetFocusPlaceholderColor(color); } diff --git a/frameworks/bridge/declarative_frontend/jsview/models/search_model_impl.h b/frameworks/bridge/declarative_frontend/jsview/models/search_model_impl.h index e584e5a709f5..567887efeb89 100644 --- a/frameworks/bridge/declarative_frontend/jsview/models/search_model_impl.h +++ b/frameworks/bridge/declarative_frontend/jsview/models/search_model_impl.h @@ -32,6 +32,7 @@ public: void SetSearchButton(const std::string& text) override; void SetCaretWidth(const Dimension& value) override {} void SetCaretColor(const Color& color) override {} + void ResetCaretColor() override {} void SetSearchIconSize(const Dimension& value) override {} void SetSearchIconColor(const Color& color) override {} void SetSearchSrcPath( @@ -43,15 +44,22 @@ public: void SetCancelSymbolIcon(std::function)> iconSymbol) override{} void SetCancelDefaultIcon() override{} void SetCancelImageIcon(NG::IconOptions& iconOptions) override{} + void SetSearchCancelIconColor(const Color& color) override {} + void ResetSearchCancelIconColor() override {} void SetCancelButtonStyle(OHOS::Ace::CancelButtonStyle cancelButtonStyle) override {} void SetCancelIconSize(const Dimension& value) override {} void SetCancelIconColor(const Color& color) override {} void SetSearchButtonFontSize(const Dimension& value) override {} void SetSearchButtonFontColor(const Color& color) override {} + void ResetSearchButtonFontColor() override {} void SetPlaceholderColor(const Color& color) override; + void ResetPlaceholderColor() override {} void SetPlaceholderFont(const Font& font) override; void SetTextFont(const Font& font) override; void SetTextColor(const Color& color) override {} + void ResetTextColor() override {} + void SetBackgroundColor(const Color& color) override {} + void ResetBackgroundColor() override {} void SetTextAlign(const TextAlign& textAlign) override; void SetCopyOption(const CopyOptions& copyOptions) override; void SetFocusable(bool focusable) override; diff --git a/frameworks/core/components/search/search_theme.h b/frameworks/core/components/search/search_theme.h index da37f2de94a1..691475cf40bf 100644 --- a/frameworks/core/components/search/search_theme.h +++ b/frameworks/core/components/search/search_theme.h @@ -51,7 +51,6 @@ public: return theme; } - private: void ParsePattern(const RefPtr& themeConstants, const RefPtr& theme) const { if (!theme) { @@ -266,11 +265,15 @@ public: protected: SearchTheme() = default; + Color placeholderColor_; + Color textColor_; + Color searchIconColor_; + Color symbolIconColor_; + Color searchDividerColor_; + Color searchButtonTextColor_; private: - Color placeholderColor_; Color focusPlaceholderColor_; - Color textColor_; Color focusTextColor_; Color touchColor_; Color hoverColor_; @@ -292,14 +295,10 @@ private: Dimension iconHeight_; Dimension searchIconLeftSpace_; Dimension searchIconRightSpace_; - Color searchDividerColor_; - Color searchButtonTextColor_; - Color searchIconColor_; CancelButtonStyle cancelButtonStyle_ = CancelButtonStyle::INPUT; TextStyle textStyle_; uint32_t searchSymbolId_ = 0; uint32_t cancelSymbolId_ = 0; - Color symbolIconColor_; Dimension rightPaddingWithoutButton_; }; diff --git a/frameworks/core/components/theme/theme_manager_impl.cpp b/frameworks/core/components/theme/theme_manager_impl.cpp index b9572d329e82..ad8c80e1e95a 100644 --- a/frameworks/core/components/theme/theme_manager_impl.cpp +++ b/frameworks/core/components/theme/theme_manager_impl.cpp @@ -96,6 +96,7 @@ #include "core/components_ng/pattern/dialog/dialog_theme_wrapper.h" #include "core/components_ng/pattern/toggle/switch_theme_wrapper.h" #include "core/components_ng/pattern/toggle/toggle_theme_wrapper.h" +#include "core/components_ng/pattern/search/search_theme_wrapper.h" #include "core/components_ng/token_theme/token_theme_storage.h" namespace OHOS::Ace { @@ -201,7 +202,8 @@ const std::unordered_map(*)(const RefPt { DialogTheme::TypeId(), &ThemeWrapperBuildFunc }, { ToggleTheme::TypeId(), &ThemeWrapperBuildFunc }, { CounterTheme::TypeId(), &ThemeWrapperBuildFunc }, - { SwitchTheme::TypeId(), &ThemeWrapperBuildFunc } + { SwitchTheme::TypeId(), &ThemeWrapperBuildFunc }, + { SearchTheme::TypeId(), &ThemeWrapperBuildFunc } }; } // namespace diff --git a/frameworks/core/components_ng/pattern/search/search_layout_algorithm.cpp b/frameworks/core/components_ng/pattern/search/search_layout_algorithm.cpp index 28a8914e648c..5a87f14f4fae 100644 --- a/frameworks/core/components_ng/pattern/search/search_layout_algorithm.cpp +++ b/frameworks/core/components_ng/pattern/search/search_layout_algorithm.cpp @@ -58,7 +58,7 @@ void SearchLayoutAlgorithm::CancelImageMeasure(LayoutWrapper* layoutWrapper) CHECK_NULL_VOID(searchHost); auto pipeline = searchHost->GetContext(); CHECK_NULL_VOID(pipeline); - auto searchTheme = pipeline->GetTheme(); + auto searchTheme = pipeline->GetTheme(searchHost->GetThemeScopeId()); CHECK_NULL_VOID(searchTheme); auto constraint = layoutProperty->GetLayoutConstraint(); auto searchHeight = CalcSearchHeight(constraint.value(), layoutWrapper); @@ -93,7 +93,7 @@ void SearchLayoutAlgorithm::CancelButtonMeasure(LayoutWrapper* layoutWrapper) CHECK_NULL_VOID(searchHost); auto pipeline = searchHost->GetContext(); CHECK_NULL_VOID(pipeline); - auto searchTheme = pipeline->GetTheme(); + auto searchTheme = pipeline->GetTheme(searchHost->GetThemeScopeId()); CHECK_NULL_VOID(searchTheme); // calculate theme space from cancel button to cancel image @@ -118,7 +118,7 @@ void SearchLayoutAlgorithm::TextFieldMeasure(LayoutWrapper* layoutWrapper) CHECK_NULL_VOID(searchHost); auto pipeline = searchHost->GetContext(); CHECK_NULL_VOID(pipeline); - auto searchTheme = pipeline->GetTheme(); + auto searchTheme = pipeline->GetTheme(searchHost->GetThemeScopeId()); auto layoutProperty = AceType::DynamicCast(layoutWrapper->GetLayoutProperty()); CHECK_NULL_VOID(layoutProperty); auto textFieldWrapper = layoutWrapper->GetOrCreateChildByIndex(TEXTFIELD_INDEX); @@ -223,7 +223,7 @@ void SearchLayoutAlgorithm::ImageMeasure(LayoutWrapper* layoutWrapper) CHECK_NULL_VOID(searchHost); auto pipeline = searchHost->GetContext(); CHECK_NULL_VOID(pipeline); - auto searchTheme = pipeline->GetTheme(); + auto searchTheme = pipeline->GetTheme(searchHost->GetThemeScopeId()); CHECK_NULL_VOID(searchTheme); auto constraint = layoutProperty->GetLayoutConstraint(); auto searchHeight = CalcSearchHeight(constraint.value(), layoutWrapper); @@ -258,7 +258,7 @@ void SearchLayoutAlgorithm::SearchButtonMeasure(LayoutWrapper* layoutWrapper) CHECK_NULL_VOID(searchHost); auto pipeline = searchHost->GetContext(); CHECK_NULL_VOID(pipeline); - auto searchTheme = pipeline->GetTheme(); + auto searchTheme = pipeline->GetTheme(searchHost->GetThemeScopeId()); CHECK_NULL_VOID(searchTheme); // calculate theme space from search button to font @@ -316,11 +316,11 @@ void SearchLayoutAlgorithm::DividerMeasure(LayoutWrapper* layoutWrapper) CHECK_NULL_VOID(dividerGeometryNode); auto dividerLayoutProperty = dividerWrapper->GetLayoutProperty(); CHECK_NULL_VOID(dividerLayoutProperty); - auto host = layoutWrapper->GetHostNode(); - CHECK_NULL_VOID(host); - auto pipeline = host->GetContext(); + auto searchHost = layoutWrapper->GetHostNode(); + CHECK_NULL_VOID(searchHost); + auto pipeline = searchHost->GetContext(); CHECK_NULL_VOID(pipeline); - auto searchTheme = pipeline->GetTheme(); + auto searchTheme = pipeline->GetTheme(searchHost->GetThemeScopeId()); CHECK_NULL_VOID(searchTheme); auto constraint = layoutProperty->GetLayoutConstraint(); @@ -346,7 +346,7 @@ double SearchLayoutAlgorithm::CalcSearchAdaptHeight(LayoutWrapper* layoutWrapper CHECK_NULL_RETURN(host, 0); auto pipeline = host->GetContext(); CHECK_NULL_RETURN(pipeline, 0); - auto searchTheme = pipeline->GetTheme(); + auto searchTheme = pipeline->GetTheme(host->GetThemeScopeId()); CHECK_NULL_RETURN(searchTheme, 0); auto layoutProperty = AceType::DynamicCast(layoutWrapper->GetLayoutProperty()); CHECK_NULL_RETURN(layoutProperty, 0); @@ -462,7 +462,7 @@ double SearchLayoutAlgorithm::CalcSearchHeight( CHECK_NULL_RETURN(pipeline, 0.0); auto renderContext = host->GetRenderContext(); CHECK_NULL_RETURN(renderContext, 0.0); - auto searchTheme = pipeline->GetTheme(); + auto searchTheme = pipeline->GetTheme(host->GetThemeScopeId()); CHECK_NULL_RETURN(searchTheme, 0.0); auto themeHeight = searchTheme->GetHeight().ConvertToPx(); auto searchHeight = @@ -550,7 +550,7 @@ void SearchLayoutAlgorithm::CalcChildrenHotZone(LayoutWrapper* layoutWrapper) auto pipeline = searchButtonFrameNode->GetContext(); CHECK_NULL_VOID(pipeline); - auto searchTheme = pipeline->GetTheme(); + auto searchTheme = pipeline->GetTheme(searchButtonFrameNode->GetThemeScopeId()); auto buttonSpace = searchTheme->GetSearchButtonSpace().ConvertToPx(); // calculate cancel button hot zone cancelButtonFrameNode->RemoveLastHotZoneRect(); @@ -599,7 +599,7 @@ void SearchLayoutAlgorithm::Layout(LayoutWrapper* layoutWrapper) auto pipeline = host->GetContext(); CHECK_NULL_VOID(pipeline); - auto searchTheme = pipeline->GetTheme(); + auto searchTheme = pipeline->GetTheme(host->GetThemeScopeId()); auto geometryNode = layoutWrapper->GetGeometryNode(); CHECK_NULL_VOID(geometryNode); @@ -849,7 +849,7 @@ void SearchLayoutAlgorithm::UpdateClipBounds(LayoutWrapper* layoutWrapper, float if (!layoutProperty->HasSearchIconUDSize() && !layoutProperty->HasCancelButtonUDSize()) { auto pipeline = host->GetContext(); CHECK_NULL_VOID(pipeline); - auto searchTheme = pipeline->GetTheme(); + auto searchTheme = pipeline->GetTheme(host->GetThemeScopeId()); CHECK_NULL_VOID(searchTheme); auto defaultImageHeight = searchTheme->GetIconSize().ConvertToPx(); auto isClip = LessNotEqual(height, defaultImageHeight); diff --git a/frameworks/core/components_ng/pattern/search/search_layout_property.h b/frameworks/core/components_ng/pattern/search/search_layout_property.h index ff34145da0c9..8b1c0f023649 100644 --- a/frameworks/core/components_ng/pattern/search/search_layout_property.h +++ b/frameworks/core/components_ng/pattern/search/search_layout_property.h @@ -42,6 +42,8 @@ public: value->propCaretUDWidth_ = CloneCaretUDWidth(); value->propSearchButtonFontSize_ = CloneSearchButtonFontSize(); value->propFontFeature_ = CloneFontFeature(); + value->propSymbolIconColor_ = CloneSymbolIconColor(); + value->propBackgroundColor_ = CloneBackgroundColor(); return value; } @@ -55,6 +57,8 @@ public: ResetCaretUDWidth(); ResetSearchButtonFontSize(); ResetFontFeature(); + ResetSymbolIconColor(); + ResetBackgroundColor(); } void ToJsonValue(std::unique_ptr& json, const InspectorFilter& filter) const override @@ -94,6 +98,8 @@ public: ACE_DEFINE_PROPERTY_ITEM_WITHOUT_GROUP(CaretUDWidth, Dimension, PROPERTY_UPDATE_MEASURE); ACE_DEFINE_PROPERTY_ITEM_WITHOUT_GROUP(SearchButtonFontSize, Dimension, PROPERTY_UPDATE_MEASURE); ACE_DEFINE_PROPERTY_ITEM_WITHOUT_GROUP(FontFeature, FONT_FEATURES_LIST, PROPERTY_UPDATE_MEASURE); + ACE_DEFINE_PROPERTY_ITEM_WITHOUT_GROUP(SymbolIconColor, Color, PROPERTY_UPDATE_MEASURE); + ACE_DEFINE_PROPERTY_ITEM_WITHOUT_GROUP(BackgroundColor, Color, PROPERTY_UPDATE_MEASURE); private: std::function)> searchIconSymbol_; diff --git a/frameworks/core/components_ng/pattern/search/search_model.h b/frameworks/core/components_ng/pattern/search/search_model.h index 3c07daaf46a5..a1f42c44eae3 100644 --- a/frameworks/core/components_ng/pattern/search/search_model.h +++ b/frameworks/core/components_ng/pattern/search/search_model.h @@ -35,6 +35,7 @@ public: virtual void SetSearchButton(const std::string& text); virtual void SetCaretWidth(const Dimension& value); virtual void SetCaretColor(const Color& color); + virtual void ResetCaretColor(); virtual void SetSearchIconSize(const Dimension& value); virtual void SetSearchIconColor(const Color& color); virtual void SetSearchSrcPath(const std::string& src, const std::string& bundleName, const std::string& moduleName); @@ -44,16 +45,23 @@ public: virtual void SetCancelSymbolIcon(std::function)> iconSymbol); virtual void SetCancelDefaultIcon(); virtual void SetCancelImageIcon(NG::IconOptions &iconOptions); + virtual void SetSearchCancelIconColor(const Color& color); + virtual void ResetSearchCancelIconColor(); virtual void SetRightIconSrcPath(const std::string& src); virtual void SetCancelButtonStyle(CancelButtonStyle cancelButtonStyle); virtual void SetCancelIconSize(const Dimension& value); virtual void SetCancelIconColor(const Color& color); virtual void SetSearchButtonFontSize(const Dimension& value); virtual void SetSearchButtonFontColor(const Color& color); + virtual void ResetSearchButtonFontColor(); virtual void SetPlaceholderColor(const Color& color); + virtual void ResetPlaceholderColor(); virtual void SetPlaceholderFont(const Font& font); virtual void SetTextFont(const Font& font); virtual void SetTextColor(const Color& color); + virtual void ResetTextColor(); + virtual void SetBackgroundColor(const Color& color); + virtual void ResetBackgroundColor(); virtual void SetTextAlign(const TextAlign& textAlign); virtual void SetCopyOption(const CopyOptions& copyOptions); virtual void SetFocusable(bool focusable) {}; diff --git a/frameworks/core/components_ng/pattern/search/search_model_ng.cpp b/frameworks/core/components_ng/pattern/search/search_model_ng.cpp index e43e91da58e0..a48364624082 100644 --- a/frameworks/core/components_ng/pattern/search/search_model_ng.cpp +++ b/frameworks/core/components_ng/pattern/search/search_model_ng.cpp @@ -77,6 +77,7 @@ RefPtr SearchModelNG::Create(const std::optionalPush(searchNode); auto pattern = searchNode->GetPattern(); + searchNode->SetNeedCallChildrenUpdate(false); return pattern->GetSearchController(); } @@ -152,6 +153,20 @@ void SearchModelNG::SetCaretColor(const Color& color) auto textPaintProperty = textFrameNode->GetPaintProperty(); CHECK_NULL_VOID(textPaintProperty); textPaintProperty->UpdateCursorColor(color); + textPaintProperty->UpdateCaretColorFlagByUser(color); + textFrameNode->MarkDirtyNode(PROPERTY_UPDATE_MEASURE); +} + +void SearchModelNG::ResetCaretColor() +{ + auto frameNode = ViewStackProcessor::GetInstance()->GetMainFrameNode(); + CHECK_NULL_VOID(frameNode); + auto textFrameNode = AceType::DynamicCast(frameNode->GetChildAtIndex(TEXTFIELD_INDEX)); + CHECK_NULL_VOID(textFrameNode); + auto textPaintProperty = textFrameNode->GetPaintProperty(); + CHECK_NULL_VOID(textPaintProperty); + textPaintProperty->ResetCursorColor(); + textPaintProperty->ResetCaretColorFlagByUser(); textFrameNode->MarkDirtyNode(PROPERTY_UPDATE_MEASURE); } @@ -221,6 +236,16 @@ void SearchModelNG::SetSearchImageIcon(IconOptions &iconOptions) SearchLayoutProperty, SearchIconUDSize, pattern->ConvertImageIconSizeValue(iconOptions.GetSize().value())); } +void SearchModelNG::SetSearchCancelIconColor(const Color& color) +{ + ACE_UPDATE_LAYOUT_PROPERTY(SearchLayoutProperty, SymbolIconColor, color); +} + +void SearchModelNG::ResetSearchCancelIconColor() +{ + ACE_RESET_LAYOUT_PROPERTY_WITH_FLAG(SearchLayoutProperty, SymbolIconColor, PROPERTY_UPDATE_MEASURE); +} + void SearchModelNG::SetSearchSymbolIcon(std::function)> iconSymbol) { auto frameNode = ViewStackProcessor::GetInstance()->GetMainFrameNode(); @@ -322,6 +347,21 @@ void SearchModelNG::SetSearchButtonFontColor(const Color& color) buttonFrameNode->MarkDirtyNode(PROPERTY_UPDATE_MEASURE); } +void SearchModelNG::ResetSearchButtonFontColor() +{ + auto frameNode = ViewStackProcessor::GetInstance()->GetMainFrameNode(); + CHECK_NULL_VOID(frameNode); + auto buttonFrameNode = AceType::DynamicCast(frameNode->GetChildAtIndex(BUTTON_INDEX)); + CHECK_NULL_VOID(buttonFrameNode); + + auto buttonLayoutProperty = buttonFrameNode->GetLayoutProperty(); + CHECK_NULL_VOID(buttonLayoutProperty); + buttonLayoutProperty->ResetFontColor(); + + buttonFrameNode->MarkModifyDone(); + buttonFrameNode->MarkDirtyNode(PROPERTY_UPDATE_MEASURE); +} + void SearchModelNG::SetPlaceholderColor(const Color& color) { auto frameNode = ViewStackProcessor::GetInstance()->GetMainFrameNode(); @@ -330,7 +370,27 @@ void SearchModelNG::SetPlaceholderColor(const Color& color) CHECK_NULL_VOID(textFieldChild); auto textFieldLayoutProperty = textFieldChild->GetLayoutProperty(); CHECK_NULL_VOID(textFieldLayoutProperty); + auto textFieldPaintProperty = textFieldChild->GetPaintProperty(); + CHECK_NULL_VOID(textFieldPaintProperty); textFieldLayoutProperty->UpdatePlaceholderTextColor(color); + textFieldPaintProperty->UpdatePlaceholderColorFlagByUser(color); + textFieldChild->MarkDirtyNode(PROPERTY_UPDATE_MEASURE); +} + +void SearchModelNG::ResetPlaceholderColor() +{ + auto frameNode = ViewStackProcessor::GetInstance()->GetMainFrameNode(); + CHECK_NULL_VOID(frameNode); + auto textFieldChild = AceType::DynamicCast(frameNode->GetChildren().front()); + CHECK_NULL_VOID(textFieldChild); + auto textFieldLayoutProperty = textFieldChild->GetLayoutProperty(); + CHECK_NULL_VOID(textFieldLayoutProperty); + auto textFieldPaintProperty = textFieldChild->GetPaintProperty(); + CHECK_NULL_VOID(textFieldPaintProperty); + + textFieldLayoutProperty->ResetPlaceholderTextColor(); + textFieldPaintProperty->ResetPlaceholderColorFlagByUser(); + textFieldChild->MarkDirtyNode(PROPERTY_UPDATE_MEASURE); } @@ -402,11 +462,51 @@ void SearchModelNG::SetTextColor(const Color& color) CHECK_NULL_VOID(textFieldChild); auto textFieldLayoutProperty = textFieldChild->GetLayoutProperty(); CHECK_NULL_VOID(textFieldLayoutProperty); + auto textFieldPaintProperty = textFieldChild->GetPaintProperty(); + CHECK_NULL_VOID(textFieldPaintProperty); textFieldLayoutProperty->UpdateTextColor(color); + textFieldPaintProperty->UpdateTextColorFlagByUser(color); textFieldChild->MarkDirtyNode(PROPERTY_UPDATE_MEASURE); } +void SearchModelNG::ResetTextColor() +{ + auto frameNode = ViewStackProcessor::GetInstance()->GetMainFrameNode(); + CHECK_NULL_VOID(frameNode); + auto textFieldChild = AceType::DynamicCast(frameNode->GetChildren().front()); + CHECK_NULL_VOID(textFieldChild); + auto textFieldLayoutProperty = textFieldChild->GetLayoutProperty(); + CHECK_NULL_VOID(textFieldLayoutProperty); + auto textFieldPaintProperty = textFieldChild->GetPaintProperty(); + CHECK_NULL_VOID(textFieldPaintProperty); + + textFieldLayoutProperty->ResetTextColor(); + textFieldPaintProperty->ResetTextColorFlagByUser(); + + textFieldChild->MarkDirtyNode(PROPERTY_UPDATE_MEASURE_SELF); +} + +void SearchModelNG::SetBackgroundColor(const Color& color) +{ + NG::ViewAbstract::SetBackgroundColor(color); + + auto frameNode = ViewStackProcessor::GetInstance()->GetMainFrameNode(); + CHECK_NULL_VOID(frameNode); + auto textFieldChild = AceType::DynamicCast(frameNode->GetChildren().front()); + CHECK_NULL_VOID(textFieldChild); + auto textFieldPaintProperty = textFieldChild->GetPaintProperty(); + CHECK_NULL_VOID(textFieldPaintProperty); + + textFieldPaintProperty->UpdateBackgroundColor(Color::TRANSPARENT); + ACE_UPDATE_LAYOUT_PROPERTY(SearchLayoutProperty, BackgroundColor, color); +} + +void SearchModelNG::ResetBackgroundColor() +{ + ACE_RESET_LAYOUT_PROPERTY_WITH_FLAG(SearchLayoutProperty, BackgroundColor, PROPERTY_UPDATE_MEASURE); +} + void SearchModelNG::SetInputFilter( FrameNode* frameNode, const std::string& value, const std::function& onError) { @@ -745,7 +845,7 @@ void SearchModelNG::CreateTextField(const RefPtr& parentNode, const V2::SEARCH_Field_ETS_TAG, nodeId, []() { return AceType::MakeRefPtr(); }); auto pipeline = frameNode->GetContext(); CHECK_NULL_VOID(pipeline); - auto searchTheme = pipeline->GetTheme(); + auto searchTheme = pipeline->GetTheme(frameNode->GetThemeScopeId()); CHECK_NULL_VOID(searchTheme); auto textFieldLayoutProperty = frameNode->GetLayoutProperty(); auto textFieldPaintProperty = frameNode->GetPaintProperty(); @@ -763,6 +863,7 @@ void SearchModelNG::CreateTextField(const RefPtr& parentNode, const textFieldLayoutProperty->UpdatePlaceholder(placeholder.value_or("")); textFieldLayoutProperty->UpdateMaxLines(1); textFieldLayoutProperty->UpdatePlaceholderMaxLines(1); + textFieldPaintProperty->UpdateBackgroundColor(Color::TRANSPARENT); if (!textFieldPaintProperty || !textFieldPaintProperty->HasTextColorFlagByUser()) { textFieldLayoutProperty->UpdateTextColor(searchTheme->GetTextColor()); } @@ -833,22 +934,21 @@ void SearchModelNG::CreateButton(const RefPtr& parentNode, bool hasB CHECK_NULL_VOID(frameNode); auto pipeline = frameNode->GetContext(); CHECK_NULL_VOID(pipeline); - auto searchTheme = pipeline->GetTheme(); + auto searchTheme = pipeline->GetTheme(frameNode->GetThemeScopeId()); if (frameNode->GetChildren().empty()) { auto textNode = FrameNode::CreateFrameNode( V2::TEXT_ETS_TAG, ElementRegister::GetInstance()->MakeUniqueId(), AceType::MakeRefPtr()); CHECK_NULL_VOID(textNode); frameNode->AddChild(textNode); } - + auto layoutProperty = frameNode->GetLayoutProperty(); + layoutProperty->UpdateButtonStyle(ButtonStyleMode::TEXT); auto buttonRenderContext = frameNode->GetRenderContext(); - buttonRenderContext->UpdateBackgroundColor(Color::TRANSPARENT); buttonRenderContext->UpdateClipEdge(true); auto textFrameNode = AceType::DynamicCast(frameNode->GetChildren().front()); auto textLayoutProperty = textFrameNode->GetLayoutProperty(); std::string defaultText = "Search"; textLayoutProperty->UpdateContent(defaultText); - textLayoutProperty->UpdateTextColor(searchTheme->GetSearchButtonTextColor()); textLayoutProperty->UpdateFontSize(searchTheme->GetFontSize()); textLayoutProperty->UpdateMaxFontScale(MAX_FONT_SCALE); textLayoutProperty->UpdateMaxLines(1); @@ -882,7 +982,7 @@ void SearchModelNG::CreateDivider(const RefPtr& parentNode, bool has auto pipeline = dividerNode->GetContext(); CHECK_NULL_VOID(pipeline); - auto searchTheme = pipeline->GetTheme(); + auto searchTheme = pipeline->GetTheme(dividerNode->GetThemeScopeId()); CHECK_NULL_VOID(searchTheme); auto searchDividerColor = searchTheme->GetSearchDividerColor(); auto dividerRenderProperty = dividerNode->GetPaintProperty(); @@ -911,7 +1011,7 @@ void SearchModelNG::CreateCancelButton(const RefPtr& parentNode, boo CHECK_NULL_VOID(frameNode); auto pipeline = frameNode->GetContext(); CHECK_NULL_VOID(pipeline); - auto searchTheme = pipeline->GetTheme(); + auto searchTheme = pipeline->GetTheme(frameNode->GetThemeScopeId()); CHECK_NULL_VOID(searchTheme); if (frameNode->GetChildren().empty()) { auto textNode = FrameNode::CreateFrameNode( @@ -921,10 +1021,11 @@ void SearchModelNG::CreateCancelButton(const RefPtr& parentNode, boo } frameNode->UpdateInspectorId(INSPECTOR_PREFIX + SPECICALIZED_INSPECTOR_INDEXS[CANCEL_BUTTON_INDEX] + parentInspector); - auto cancelButtonRenderContext = frameNode->GetRenderContext(); - cancelButtonRenderContext->UpdateBackgroundColor(Color::TRANSPARENT); + auto layoutProperty = frameNode->GetLayoutProperty(); + layoutProperty->UpdateButtonStyle(ButtonStyleMode::TEXT); auto textFrameNode = AceType::DynamicCast(frameNode->GetChildren().front()); auto textLayoutProperty = textFrameNode->GetLayoutProperty(); + textLayoutProperty->UpdateUseCustomColorTextFlag(false); textLayoutProperty->UpdateFontSize(searchTheme->GetFontSize()); auto cancelButtonLayoutProperty = frameNode->GetLayoutProperty(); cancelButtonLayoutProperty->UpdateType(ButtonType::CIRCLE); diff --git a/frameworks/core/components_ng/pattern/search/search_model_ng.h b/frameworks/core/components_ng/pattern/search/search_model_ng.h index bd6ba98f9d46..049f8884dbac 100644 --- a/frameworks/core/components_ng/pattern/search/search_model_ng.h +++ b/frameworks/core/components_ng/pattern/search/search_model_ng.h @@ -31,6 +31,7 @@ public: void SetSearchButton(const std::string& text) override; void SetCaretWidth(const Dimension& value) override; void SetCaretColor(const Color& color) override; + void ResetCaretColor() override; void SetSearchIconSize(const Dimension& value) override; void SetSearchIconColor(const Color& color) override; void SetSearchSrcPath( @@ -41,16 +42,23 @@ public: void SetCancelSymbolIcon(std::function)> iconSymbol) override; void SetCancelDefaultIcon() override; void SetCancelImageIcon(NG::IconOptions& iconOptions) override; + void SetSearchCancelIconColor(const Color& color) override; + void ResetSearchCancelIconColor() override; void SetRightIconSrcPath(const std::string& src) override; void SetCancelButtonStyle(CancelButtonStyle cancelButtonStyle) override; void SetCancelIconSize(const Dimension& value) override; void SetCancelIconColor(const Color& color) override; void SetSearchButtonFontSize(const Dimension& value) override; void SetSearchButtonFontColor(const Color& color) override; + void ResetSearchButtonFontColor() override; void SetPlaceholderColor(const Color& color) override; + void ResetPlaceholderColor() override; void SetPlaceholderFont(const Font& font) override; void SetTextFont(const Font& font) override; void SetTextColor(const Color& color) override; + void ResetTextColor() override; + void SetBackgroundColor(const Color& color) override; + void ResetBackgroundColor() override; void SetTextAlign(const TextAlign& textAlign) override; void SetCopyOption(const CopyOptions& copyOptions) override; void SetHeight(const Dimension& height) override; diff --git a/frameworks/core/components_ng/pattern/search/search_pattern.cpp b/frameworks/core/components_ng/pattern/search/search_pattern.cpp index a3c4b75cc740..f4eb0673b67b 100644 --- a/frameworks/core/components_ng/pattern/search/search_pattern.cpp +++ b/frameworks/core/components_ng/pattern/search/search_pattern.cpp @@ -363,9 +363,12 @@ void SearchPattern::HandleBackgroundColor() CHECK_NULL_VOID(renderContext); auto pipeline = host->GetContext(); CHECK_NULL_VOID(pipeline); - auto textFieldTheme = pipeline->GetTheme(); + auto textFieldTheme = pipeline->GetTheme(host->GetThemeScopeId()); CHECK_NULL_VOID(textFieldTheme); - if (!renderContext->HasBackgroundColor()) { + auto searchLayoutProperty = host->GetLayoutProperty(); + CHECK_NULL_VOID(searchLayoutProperty); + + if (!searchLayoutProperty->HasBackgroundColor()) { renderContext->UpdateBackgroundColor(textFieldTheme->GetBgColor()); } } @@ -1558,7 +1561,7 @@ void SearchPattern::UpdateDividerColorMode() CHECK_NULL_VOID(dividerFrameNode); auto pipeline = dividerFrameNode->GetContext(); CHECK_NULL_VOID(pipeline); - auto searchTheme = pipeline->GetTheme(); + auto searchTheme = pipeline->GetTheme(host->GetThemeScopeId()); CHECK_NULL_VOID(searchTheme); auto searchDividerColor = searchTheme->GetSearchDividerColor(); auto dividerRenderProperty = dividerFrameNode->GetPaintProperty(); @@ -1574,7 +1577,7 @@ void SearchPattern::UpdateCancelButtonColorMode() CHECK_NULL_VOID(cancelButtonNode); auto pipeline = cancelButtonNode->GetContext(); CHECK_NULL_VOID(pipeline); - auto searchTheme = pipeline->GetTheme(); + auto searchTheme = pipeline->GetTheme(cancelButtonNode->GetThemeScopeId()); CHECK_NULL_VOID(searchTheme); auto cancelButtonRenderContext = cancelButtonNode->GetRenderContext(); CHECK_NULL_VOID(cancelButtonRenderContext); @@ -1583,7 +1586,11 @@ void SearchPattern::UpdateCancelButtonColorMode() CHECK_NULL_VOID(textFrameNode); auto textLayoutProperty = textFrameNode->GetLayoutProperty(); CHECK_NULL_VOID(textLayoutProperty); - textLayoutProperty->UpdateTextColor(searchTheme->GetSearchButtonTextColor()); + auto buttonLayoutProperty = cancelButtonNode->GetLayoutProperty(); + CHECK_NULL_VOID(buttonLayoutProperty); + if (!buttonLayoutProperty->HasFontColor()) { + textLayoutProperty->UpdateTextColor(searchTheme->GetSearchButtonTextColor()); + } cancelButtonNode->MarkModifyDone(); cancelButtonNode->MarkDirtyNode(PROPERTY_UPDATE_MEASURE_SELF); } @@ -1595,13 +1602,12 @@ void SearchPattern::OnColorConfigurationUpdate() host->SetNeedCallChildrenUpdate(false); auto pipeline = host->GetContext(); CHECK_NULL_VOID(pipeline); - auto textFieldTheme = pipeline->GetTheme(); + auto textFieldTheme = pipeline->GetTheme(host->GetThemeScopeId()); CHECK_NULL_VOID(textFieldTheme); auto renderContext = host->GetRenderContext(); CHECK_NULL_VOID(renderContext); - renderContext->UpdateBackgroundColor(textFieldTheme->GetBgColor()); CHECK_NULL_VOID(pipeline); - auto searchTheme = pipeline->GetTheme(); + auto searchTheme = pipeline->GetTheme(host->GetThemeScopeId()); CHECK_NULL_VOID(searchTheme); UpdateCancelButtonColorMode(); auto buttonNode = buttonNode_.Upgrade(); @@ -1613,7 +1619,11 @@ void SearchPattern::OnColorConfigurationUpdate() CHECK_NULL_VOID(textFrameNode); auto textLayoutProperty = textFrameNode->GetLayoutProperty(); CHECK_NULL_VOID(textLayoutProperty); - textLayoutProperty->UpdateTextColor(searchTheme->GetSearchButtonTextColor()); + auto buttonLayoutProperty = buttonNode->GetLayoutProperty(); + CHECK_NULL_VOID(buttonLayoutProperty); + if (!buttonLayoutProperty->HasFontColor()) { + textLayoutProperty->UpdateTextColor(searchTheme->GetSearchButtonTextColor()); + } buttonNode->MarkModifyDone(); buttonNode->MarkDirtyNode(PROPERTY_UPDATE_MEASURE_SELF); } @@ -1629,6 +1639,79 @@ void SearchPattern::OnColorConfigurationUpdate() UpdateDividerColorMode(); } +bool SearchPattern::OnThemeScopeUpdate(int32_t themeScopeId) +{ + auto result = false; + auto host = GetHost(); + CHECK_NULL_RETURN(host, result); + + auto pipeline = host->GetContext(); + CHECK_NULL_RETURN(pipeline, result); + auto searchTheme = pipeline->GetTheme(themeScopeId); + CHECK_NULL_RETURN(searchTheme, result); + + auto buttonNode = buttonNode_.Upgrade(); + + if (buttonNode) { + auto textFrameNode = AceType::DynamicCast(buttonNode->GetChildren().front()); + CHECK_NULL_RETURN(textFrameNode, result); + auto textLayoutProperty = textFrameNode->GetLayoutProperty(); + CHECK_NULL_RETURN(textLayoutProperty, result); + auto buttonLayoutProperty = buttonNode->GetLayoutProperty(); + CHECK_NULL_RETURN(buttonLayoutProperty, result); + + if (!buttonLayoutProperty->HasFontColor()) { + textLayoutProperty->UpdateTextColor(searchTheme->GetSearchButtonTextColor()); + buttonNode->MarkModifyDone(); + buttonNode->MarkDirtyNode(PROPERTY_UPDATE_MEASURE_SELF); + } + } + + auto searchLayoutProperty = host->GetLayoutProperty(); + CHECK_NULL_RETURN(searchLayoutProperty, false); + + if (!searchLayoutProperty->HasSymbolIconColor()) { + SetSearchIconColor(Color(searchTheme->GetSymbolIconColor())); + SetCancelIconColor(Color(searchTheme->GetSymbolIconColor())); + } + + HandleBackgroundColor(); + UpdateDividerColorMode(); + + auto textField = textField_.Upgrade(); + + if (textField) { + auto needUpdateNode = false; + auto textFieldTheme = pipeline->GetTheme(themeScopeId); + CHECK_NULL_RETURN(textFieldTheme, false); + auto textFieldLayoutProperty = textField->GetLayoutProperty(); + CHECK_NULL_RETURN(textFieldLayoutProperty, false); + auto textPaintProperty = textField->GetPaintProperty(); + CHECK_NULL_RETURN(textPaintProperty, false); + + if (!textPaintProperty->HasTextColorFlagByUser()) { + textFieldLayoutProperty->UpdateTextColor(searchTheme->GetTextColor()); + needUpdateNode = true; + } + + if (!textPaintProperty->HasPlaceholderColorFlagByUser()) { + textFieldLayoutProperty->UpdatePlaceholderTextColor(searchTheme->GetPlaceholderColor()); + needUpdateNode = true; + } + + if (!textPaintProperty->HasCaretColorFlagByUser()) { + textPaintProperty->UpdateCursorColor(textFieldTheme->GetCursorColor()); + needUpdateNode = true; + } + + if (needUpdateNode) { + textField->MarkDirtyNode(PROPERTY_UPDATE_MEASURE_SELF); + } + } + + return result; +} + uint32_t SearchPattern::GetMaxLength() const { auto host = GetHost(); @@ -1679,7 +1762,7 @@ void SearchPattern::InitSearchIconColorSize() CHECK_NULL_VOID(host); auto pipeline = host->GetContext(); CHECK_NULL_VOID(pipeline); - auto searchTheme = pipeline->GetTheme(); + auto searchTheme = pipeline->GetTheme(host->GetThemeScopeId()); CHECK_NULL_VOID(searchTheme); GetSearchNode()->SetSearchSymbolIconColor(Color(searchTheme->GetSymbolIconColor())); GetSearchNode()->SetSearchSymbolIconSize(SYMBOL_ICON_HEIGHT); @@ -1693,7 +1776,7 @@ void SearchPattern::InitCancelIconColorSize() CHECK_NULL_VOID(host); auto pipeline = host->GetContext(); CHECK_NULL_VOID(pipeline); - auto searchTheme = pipeline->GetTheme(); + auto searchTheme = pipeline->GetTheme(host->GetThemeScopeId()); CHECK_NULL_VOID(searchTheme); GetSearchNode()->SetCancelSymbolIconColor(Color(searchTheme->GetSymbolIconColor())); GetSearchNode()->SetCancelSymbolIconSize(SYMBOL_ICON_HEIGHT); @@ -1726,8 +1809,8 @@ void SearchPattern::UpdateSearchSymbolIconColor() auto host = GetHost(); CHECK_NULL_VOID(host); CHECK_NULL_VOID(GetSearchNode()); - auto cancelButtonFrameNode = DynamicCast(host->GetChildAtIndex(IMAGE_INDEX)); - auto layoutProperty = cancelButtonFrameNode->GetLayoutProperty(); + auto searchButtonFrameNode = DynamicCast(host->GetChildAtIndex(IMAGE_INDEX)); + auto layoutProperty = searchButtonFrameNode->GetLayoutProperty(); CHECK_NULL_VOID(layoutProperty); layoutProperty->UpdateSymbolColorList({ GetSearchNode()->GetSearchSymbolIconColor() }); } @@ -1770,15 +1853,17 @@ void SearchPattern::CreateOrUpdateSymbol(int32_t index, bool isCreateNode, bool CHECK_NULL_VOID(host); auto pipeline = host->GetContext(); auto nodeId = ElementRegister::GetInstance()->MakeUniqueId(); - auto searchTheme = pipeline->GetTheme(); + auto searchTheme = pipeline->GetTheme(host->GetThemeScopeId()); CHECK_NULL_VOID(searchTheme); auto iconFrameNode = FrameNode::GetOrCreateFrameNode( V2::SYMBOL_ETS_TAG, nodeId, []() { return AceType::MakeRefPtr(); }); auto layoutProperty = iconFrameNode->GetLayoutProperty(); + layoutProperty->UpdateUseCustomColorTextFlag(false); layoutProperty->UpdateSymbolSourceInfo(index == IMAGE_INDEX ? SymbolSourceInfo(searchTheme->GetSearchSymbolId()) : SymbolSourceInfo(searchTheme->GetCancelSymbolId())); layoutProperty->UpdateFontSize( index == IMAGE_INDEX ? GetSearchNode()->GetSearchSymbolIconSize() : GetSearchNode()->GetCancelSymbolIconSize()); + layoutProperty->UpdateSymbolColorList({index == IMAGE_INDEX ? GetSearchNode()->GetSearchSymbolIconColor() : GetSearchNode()->GetCancelSymbolIconColor()}); float maxFontScale = MAX_FONT_SCALE; @@ -1821,7 +1906,7 @@ void SearchPattern::CreateOrUpdateImage(int32_t index, bool isCreateNode) CHECK_NULL_VOID(host); auto pipeline = host->GetContext(); CHECK_NULL_VOID(pipeline); - auto searchTheme = pipeline->GetTheme(); + auto searchTheme = pipeline->GetTheme(host->GetThemeScopeId()); CHECK_NULL_VOID(searchTheme); auto iconFrameNode = FrameNode::GetOrCreateFrameNode(V2::IMAGE_ETS_TAG, ElementRegister::GetInstance()->MakeUniqueId(), @@ -2031,23 +2116,28 @@ void SearchPattern::UpdateImageIconProperties(RefPtr& iconFrameNode, { CHECK_NULL_VOID(iconFrameNode); if (iconFrameNode->GetTag() == V2::IMAGE_ETS_TAG) { + auto iconOptions = index == IMAGE_INDEX ? GetSearchNode()->GetSearchImageIconOptions() : GetSearchNode()->GetCancelImageIconOptions(); + auto imageLayoutProperty = iconFrameNode->GetLayoutProperty(); CHECK_NULL_VOID(imageLayoutProperty); ImageSourceInfo imageSourceInfo(""); auto imageSourceInfoOp = imageLayoutProperty->GetImageSourceInfo(); + if (imageSourceInfoOp.has_value()) { imageSourceInfo = imageSourceInfoOp.value(); } + auto host = GetHost(); CHECK_NULL_VOID(host); auto pipeline = host->GetContext(); CHECK_NULL_VOID(pipeline); - auto searchTheme = pipeline->GetTheme(); + auto searchTheme = pipeline->GetTheme(host->GetThemeScopeId()); CHECK_NULL_VOID(searchTheme); - auto iconTheme = pipeline->GetTheme(); + auto iconTheme = pipeline->GetTheme(host->GetThemeScopeId()); CHECK_NULL_VOID(iconTheme); + if (iconOptions.GetSrc().value_or("").empty()) { imageSourceInfo.SetResourceId(index == IMAGE_INDEX ? InternalResource::ResourceId::SEARCH_SVG : InternalResource::ResourceId::CLOSE_SVG); @@ -2057,6 +2147,7 @@ void SearchPattern::UpdateImageIconProperties(RefPtr& iconFrameNode, } else { imageSourceInfo.SetSrc(iconOptions.GetSrc().value()); } + imageSourceInfo.SetBundleName(iconOptions.GetBundleName().value_or("")); imageSourceInfo.SetModuleName(iconOptions.GetModuleName().value_or("")); imageSourceInfo.SetFillColor(iconOptions.GetColor().value_or(searchTheme->GetSearchIconColor())); @@ -2082,7 +2173,7 @@ void SearchPattern::UpdateSymbolIconProperties(RefPtr& iconFrameNode, CHECK_NULL_VOID(iconFrameNode); auto pipeline = host->GetContext(); CHECK_NULL_VOID(pipeline); - auto searchTheme = pipeline->GetTheme(); + auto searchTheme = pipeline->GetTheme(host->GetThemeScopeId()); CHECK_NULL_VOID(searchTheme); auto layoutProperty = host->GetLayoutProperty(); CHECK_NULL_VOID(layoutProperty); diff --git a/frameworks/core/components_ng/pattern/search/search_pattern.h b/frameworks/core/components_ng/pattern/search/search_pattern.h index ad2d759cde9b..da3860305f9d 100644 --- a/frameworks/core/components_ng/pattern/search/search_pattern.h +++ b/frameworks/core/components_ng/pattern/search/search_pattern.h @@ -181,6 +181,7 @@ public: void ResetDragOption() override; void OnColorConfigurationUpdate() override; + bool OnThemeScopeUpdate(int32_t themeScopeId) override; void SetSearchIconSize(const Dimension& value); void SetSearchIconColor(const Color& color); diff --git a/frameworks/core/components_ng/pattern/search/search_theme_wrapper.h b/frameworks/core/components_ng/pattern/search/search_theme_wrapper.h new file mode 100644 index 000000000000..00572f146c26 --- /dev/null +++ b/frameworks/core/components_ng/pattern/search/search_theme_wrapper.h @@ -0,0 +1,72 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef FRAMEWORKS_CORE_COMPONENTS_NG_PATTERN_SEARCH_SEARCH_THEME_WRAPPER_H +#define FRAMEWORKS_CORE_COMPONENTS_NG_PATTERN_SEARCH_SEARCH_THEME_WRAPPER_H + +#include + +#include "base/memory/ace_type.h" +#include "core/components/search/search_theme.h" +#include "core/components_ng/token_theme/token_theme_wrapper.h" + +namespace OHOS::Ace::NG { + +/** + * TextThemeWrapper defines color and styles of TextComponent basing on TokenTheme's data. + * TextThemeWrapper should be built using TextThemeWrapper::Builder. + */ +class SearchThemeWrapper : public SearchTheme, public TokenThemeWrapper +{ + DECLARE_ACE_TYPE(SearchThemeWrapper, SearchTheme); + +public: + class WrapperBuilder : public Builder + { + public: + WrapperBuilder() = default; + ~WrapperBuilder() = default; + + RefPtr BuildWrapper(const RefPtr& themeConstants) const + { + auto wrapper = AceType::Claim(new SearchThemeWrapper()); + auto theme = AceType::DynamicCast(wrapper); + if (!themeConstants) { + return wrapper; + } + ParsePattern(themeConstants, theme); + return wrapper; + } + }; + + ~SearchThemeWrapper() override = default; + + void ApplyTokenTheme(const TokenTheme& theme) override + { + if (auto colors = theme.Colors(); colors) { + textColor_ = colors->FontPrimary(); + placeholderColor_ = colors->FontSecondary(); + searchIconColor_ = colors->IconSecondary(); + symbolIconColor_ = colors->IconSecondary(); + searchButtonTextColor_ = colors->FontEmphasize(); + } + } + +protected: + SearchThemeWrapper() = default; +}; + +} // namespace +#endif \ No newline at end of file diff --git a/frameworks/core/interfaces/native/node/search_modifier.cpp b/frameworks/core/interfaces/native/node/search_modifier.cpp index 2895b1b98ed1..ccf8b25c02dd 100644 --- a/frameworks/core/interfaces/native/node/search_modifier.cpp +++ b/frameworks/core/interfaces/native/node/search_modifier.cpp @@ -100,7 +100,9 @@ void ResetSearchCaretStyle(ArkUINodeHandle node) { auto* frameNode = reinterpret_cast(node); CHECK_NULL_VOID(frameNode); - auto textFieldTheme = GetTheme(); + auto pipelineContext = PipelineBase::GetCurrentContext(); + CHECK_NULL_VOID(pipelineContext); + auto textFieldTheme = pipelineContext->GetTheme(frameNode->GetThemeScopeId()); CHECK_NULL_VOID(textFieldTheme); CalcDimension caretWidth = textFieldTheme->GetCursorWidth(); uint32_t caretColor = textFieldTheme->GetCursorColor().GetValue(); @@ -367,7 +369,7 @@ void ResetSearchAdaptMinFontSize(ArkUINodeHandle node) CHECK_NULL_VOID(frameNode); auto pipelineContext = PipelineBase::GetCurrentContext(); CHECK_NULL_VOID(pipelineContext); - auto theme = pipelineContext->GetTheme(); + auto theme = pipelineContext->GetTheme(frameNode->GetThemeScopeId()); CHECK_NULL_VOID(theme); CalcDimension minFontSize = theme->GetTextStyle().GetAdaptMinFontSize(); SearchModelNG::SetAdaptMinFontSize(frameNode, minFontSize); @@ -386,7 +388,7 @@ void ResetSearchAdaptMaxFontSize(ArkUINodeHandle node) CHECK_NULL_VOID(frameNode); auto pipelineContext = PipelineBase::GetCurrentContext(); CHECK_NULL_VOID(pipelineContext); - auto theme = pipelineContext->GetTheme(); + auto theme = pipelineContext->GetTheme(frameNode->GetThemeScopeId()); CHECK_NULL_VOID(theme); CalcDimension maxFontSize = theme->GetTextStyle().GetAdaptMaxFontSize(); SearchModelNG::SetAdaptMaxFontSize(frameNode, maxFontSize); @@ -411,7 +413,7 @@ void ResetSearchSelectedBackgroundColor(ArkUINodeHandle node) Color selectedColor; auto pipeline = PipelineBase::GetCurrentContext(); CHECK_NULL_VOID(pipeline); - auto theme = pipeline->GetTheme(); + auto theme = pipeline->GetTheme(frameNode->GetThemeScopeId()); CHECK_NULL_VOID(theme); selectedColor = theme->GetSelectedColor(); if (selectedColor.GetAlpha() == DEFAULT_ALPHA) { -- Gitee