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 a58b9a76e44480976ac6f310c197e5ed46ed368f..810e6c8f8023fe4410621cc0adde36d93fc784bf 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 @@ -20,8 +20,7 @@ class ArkThemeWhiteList { // add to list only names of built-in components which support ArkTheme // strongly recommended to use alphabetical order private static whiteList: Array = [ - 'Badge', - 'Search' + 'Badge' ]; /** diff --git a/frameworks/bridge/declarative_frontend/engine/arkTheme.js b/frameworks/bridge/declarative_frontend/engine/arkTheme.js index 454b0eb52c35e08462f277597db1257019126b22..b96142c14c8adeecadfb502e755f0c2d93165369 100644 --- a/frameworks/bridge/declarative_frontend/engine/arkTheme.js +++ b/frameworks/bridge/declarative_frontend/engine/arkTheme.js @@ -1074,6 +1074,5 @@ class ArkThemeWhiteList { } } ArkThemeWhiteList.whiteList = [ - 'Badge', - 'Search' + 'Badge' ]; 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 28f5e5e933ed6af36fe9a48e7ad2a1b0c4d8a837..82e6fb1d69f948961b3c310cb023372d7eee51c0 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/core/components_ng/pattern/search/search_layout_algorithm.cpp b/frameworks/core/components_ng/pattern/search/search_layout_algorithm.cpp index 28a8914e648c7165461451cf9d6701ce53c82286..c1efc0c5e95b711418866bdf8181730104610cb7 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 @@ -320,7 +320,7 @@ void SearchLayoutAlgorithm::DividerMeasure(LayoutWrapper* layoutWrapper) 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 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 ff34145da0c9a4916e83d8c1cd7c8ea9ee42a998..935cecc88c551564f0792fad91bc25c8cc837925 100644 --- a/frameworks/core/components_ng/pattern/search/search_layout_property.h +++ b/frameworks/core/components_ng/pattern/search/search_layout_property.h @@ -94,7 +94,6 @@ 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); - private: std::function)> searchIconSymbol_; std::function)> cancelIconSymbol_; 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 e43e91da58e0b9d2224991b7e74f022ef98e9fe8..b5b13ee168972b05781cf4601375f1243e495971 100644 --- a/frameworks/core/components_ng/pattern/search/search_model_ng.cpp +++ b/frameworks/core/components_ng/pattern/search/search_model_ng.cpp @@ -110,7 +110,7 @@ RefPtr SearchModelNG::CreateSearchNode(int32_t nodeId, const std::op // Set search background auto renderContext = frameNode->GetRenderContext(); - auto textFieldTheme = frameNode->GetContext()->GetTheme(); + auto textFieldTheme = frameNode->GetContext()->GetTheme(frameNode->GetThemeScopeId()); auto radius = textFieldTheme->GetBorderRadius(); BorderRadiusProperty borderRadius { radius.GetX(), radius.GetY(), radius.GetY(), radius.GetX() }; renderContext->UpdateBorderRadius(borderRadius); @@ -146,13 +146,7 @@ void SearchModelNG::SetCaretWidth(const Dimension& value) void SearchModelNG::SetCaretColor(const Color& color) { 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->UpdateCursorColor(color); - textFrameNode->MarkDirtyNode(PROPERTY_UPDATE_MEASURE); + SetCaretColor(frameNode, color); } void SearchModelNG::SetSearchButton(const std::string& text) @@ -325,13 +319,7 @@ void SearchModelNG::SetSearchButtonFontColor(const Color& color) void SearchModelNG::SetPlaceholderColor(const Color& color) { 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); - textFieldLayoutProperty->UpdatePlaceholderTextColor(color); - textFieldChild->MarkDirtyNode(PROPERTY_UPDATE_MEASURE); + SetPlaceholderColor(frameNode, color); } void SearchModelNG::SetPlaceholderFont(const Font& font) @@ -361,13 +349,7 @@ void SearchModelNG::SetPlaceholderFont(const Font& font) void SearchModelNG::SetSelectedBackgroundColor(const Color& value) { 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->UpdateSelectedBackgroundColor(value); - textFieldChild->MarkDirtyNode(PROPERTY_UPDATE_RENDER); + SetSelectedBackgroundColor(frameNode, value); } void SearchModelNG::SetTextFont(const Font& font) @@ -397,14 +379,7 @@ void SearchModelNG::SetTextFont(const Font& font) void SearchModelNG::SetTextColor(const Color& color) { 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); - - textFieldLayoutProperty->UpdateTextColor(color); - textFieldChild->MarkDirtyNode(PROPERTY_UPDATE_MEASURE); + SetTextColor(frameNode, color); } void SearchModelNG::SetInputFilter( @@ -745,7 +720,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,10 +738,12 @@ void SearchModelNG::CreateTextField(const RefPtr& parentNode, const textFieldLayoutProperty->UpdatePlaceholder(placeholder.value_or("")); textFieldLayoutProperty->UpdateMaxLines(1); textFieldLayoutProperty->UpdatePlaceholderMaxLines(1); - if (!textFieldPaintProperty || !textFieldPaintProperty->HasTextColorFlagByUser()) { + // IS THIS A RUDEMENT CHECK? LOOKS LIKE ALWAYS TRUE! + if (!textFieldPaintProperty || !textFieldPaintProperty->HasTextColorFlagByUser()) { textFieldLayoutProperty->UpdateTextColor(searchTheme->GetTextColor()); } } + pattern->SetTextFieldController(AceType::MakeRefPtr()); pattern->GetTextFieldController()->SetPattern(AceType::WeakClaim(AceType::RawPtr(pattern))); pattern->SetTextEditController(AceType::MakeRefPtr()); @@ -790,7 +767,7 @@ void SearchModelNG::TextFieldUpdateContext(const RefPtr& frameNode) CHECK_NULL_VOID(frameNode); auto pipeline = frameNode->GetContext(); CHECK_NULL_VOID(pipeline); - auto textFieldTheme = pipeline->GetTheme(); + auto textFieldTheme = pipeline->GetTheme(frameNode->GetThemeScopeId()); CHECK_NULL_VOID(textFieldTheme); auto textFieldPaintProperty = frameNode->GetPaintProperty(); CHECK_NULL_VOID(textFieldPaintProperty); @@ -833,7 +810,7 @@ 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()); @@ -841,8 +818,9 @@ void SearchModelNG::CreateButton(const RefPtr& parentNode, bool hasB 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(); @@ -882,7 +860,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 +889,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,8 +899,9 @@ void SearchModelNG::CreateCancelButton(const RefPtr& parentNode, boo } frameNode->UpdateInspectorId(INSPECTOR_PREFIX + SPECICALIZED_INSPECTOR_INDEXS[CANCEL_BUTTON_INDEX] + parentInspector); + auto layoutProperty = frameNode->GetLayoutProperty(); + layoutProperty->UpdateButtonStyle(ButtonStyleMode::TEXT); auto cancelButtonRenderContext = frameNode->GetRenderContext(); - cancelButtonRenderContext->UpdateBackgroundColor(Color::TRANSPARENT); auto textFrameNode = AceType::DynamicCast(frameNode->GetChildren().front()); auto textLayoutProperty = textFrameNode->GetLayoutProperty(); textLayoutProperty->UpdateFontSize(searchTheme->GetFontSize()); @@ -1274,6 +1253,7 @@ void SearchModelNG::SetPlaceholderColor(FrameNode* frameNode, const Color& color CHECK_NULL_VOID(textFieldChild); auto textFieldLayoutProperty = textFieldChild->GetLayoutProperty(); CHECK_NULL_VOID(textFieldLayoutProperty); + ACE_UPDATE_NODE_PAINT_PROPERTY(TextFieldPaintProperty, PlaceholderColorFlagByUser, color, textFieldChild); textFieldLayoutProperty->UpdatePlaceholderTextColor(color); textFieldChild->MarkDirtyNode(PROPERTY_UPDATE_MEASURE); } @@ -1308,6 +1288,7 @@ void SearchModelNG::SetCaretColor(FrameNode* frameNode, const Color& color) auto textPaintProperty = textFrameNode->GetPaintProperty(); CHECK_NULL_VOID(textPaintProperty); textPaintProperty->UpdateCursorColor(color); + ACE_UPDATE_NODE_PAINT_PROPERTY(TextFieldPaintProperty, CaretColorFlagByUser, color, textFrameNode); textFrameNode->MarkDirtyNode(PROPERTY_UPDATE_MEASURE); } @@ -1564,6 +1545,7 @@ void SearchModelNG::SetSelectedBackgroundColor(FrameNode* frameNode, const Color auto textFieldPaintProperty = textFieldChild->GetPaintProperty(); CHECK_NULL_VOID(textFieldPaintProperty); textFieldPaintProperty->UpdateSelectedBackgroundColor(value); + ACE_UPDATE_NODE_PAINT_PROPERTY(TextFieldPaintProperty, SelectedBackgroundColorFlagByUser, value, textFieldChild); textFieldChild->MarkDirtyNode(PROPERTY_UPDATE_RENDER); } diff --git a/frameworks/core/components_ng/pattern/search/search_pattern.cpp b/frameworks/core/components_ng/pattern/search/search_pattern.cpp index a3c4b75cc7409d301fe98154dd2aa9506d7da06c..bd37dd0be51086db43a1bf0aa696cbc487cb0fcc 100644 --- a/frameworks/core/components_ng/pattern/search/search_pattern.cpp +++ b/frameworks/core/components_ng/pattern/search/search_pattern.cpp @@ -363,7 +363,7 @@ 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()) { renderContext->UpdateBackgroundColor(textFieldTheme->GetBgColor()); @@ -1558,7 +1558,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 +1574,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); @@ -1592,16 +1592,17 @@ void SearchPattern::OnColorConfigurationUpdate() { auto host = GetHost(); CHECK_NULL_VOID(host); + auto themeId = host->GetThemeScopeId(); host->SetNeedCallChildrenUpdate(false); auto pipeline = host->GetContext(); CHECK_NULL_VOID(pipeline); - auto textFieldTheme = pipeline->GetTheme(); + auto textFieldTheme = pipeline->GetTheme(themeId); 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(themeId); CHECK_NULL_VOID(searchTheme); UpdateCancelButtonColorMode(); auto buttonNode = buttonNode_.Upgrade(); @@ -1623,12 +1624,59 @@ void SearchPattern::OnColorConfigurationUpdate() CHECK_NULL_VOID(textFieldLayoutProperty); textFieldLayoutProperty->UpdateTextColor(searchTheme->GetTextColor()); textFieldLayoutProperty->UpdatePlaceholderTextColor(searchTheme->GetPlaceholderColor()); + auto renderContext = textField->GetRenderContext(); + CHECK_NULL_VOID(renderContext); + renderContext->UpdateBackgroundColor(Color::TRANSPARENT); textField->MarkModifyDone(); textField->MarkDirtyNode(PROPERTY_UPDATE_MEASURE_SELF); } 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); + + //host->SetNeedCallChildrenUpdate(false); + + APP_LOGE("%{public}d -> %{public}d", host->GetThemeScopeId(), themeScopeId); + + //Search Button + auto button = buttonNode_.Upgrade(); + auto textNode = DynamicCast(button->GetFirstChild()); + auto buttonLayoutProperty = textNode->GetLayoutProperty(); + if (!buttonLayoutProperty->HasFontColor()) { + buttonLayoutProperty->UpdateTextColor(searchTheme->GetSearchButtonTextColor()); + textNode->MarkDirtyNode(); + result = true; + } + + + auto textField = textField_.Upgrade(); + auto textPaintProperty = textField->GetPaintProperty(); + if (!textPaintProperty->HasTextColorFlagByUser() + || !textPaintProperty->HasCaretColorFlagByUser() + || !textPaintProperty->HasPlaceholderColorFlagByUser() + || !textPaintProperty->HasSelectedBackgroundColorFlagByUser()) + { + auto textTheme = pipeline->GetTheme(themeScopeId); + auto textLayoutProperty = textField->GetLayoutProperty(); + textLayoutProperty->UpdateTextColor(searchTheme->GetTextColor()); + textLayoutProperty->UpdatePlaceholderTextColor(searchTheme->GetPlaceholderColor()); + textPaintProperty->UpdateCursorColor(textTheme->GetCursorColor()); + host->MarkDirtyNode(PROPERTY_UPDATE_MEASURE); + result = true; + } + + return result; +} + + uint32_t SearchPattern::GetMaxLength() const { auto host = GetHost(); @@ -1679,7 +1727,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 +1741,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); @@ -1770,7 +1818,7 @@ 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(); }); @@ -1821,7 +1869,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(), @@ -2044,9 +2092,9 @@ void SearchPattern::UpdateImageIconProperties(RefPtr& iconFrameNode, 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 @@ -2082,7 +2130,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 ad2d759cde9b0051fbf20a6513a7186f4317739b..da3860305f9ddc10f1f73198aaddf718285e59ef 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 0000000000000000000000000000000000000000..02c88b33b52cca2f46b23012e8d3c1797b1db451 --- /dev/null +++ b/frameworks/core/components_ng/pattern/search/search_theme_wrapper.h @@ -0,0 +1,73 @@ +/* + * 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_TEXT_FIELD_TEXT_FIELD_THEME_WRAPPER_H +#define FRAMEWORKS_CORE_COMPONENTS_NG_PATTERN_TEXT_FIELD_TEXT_FIELD_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->GetThemeStyle(), theme); + return wrapper; + } + }; + + ~SearchThemeWrapper() override = default; + + void ApplyTokenTheme(const TokenTheme& theme) override + { + if (auto colors = theme.Colors(); colors) { + textColor_ = colors->FontPrimary(); + placeholderColor_ = colors->FontSecondary(); + symbolIconColor_ = colors->IconSecondary(); + symbolIconColor_ = colors->IconSecondary(); + searchButtonTextColor_ = colors->FontEmphasize(); + focusPlaceholderColor_ = colors->CompBackgroundTertiary(); + } + } + +protected: + SearchThemeWrapper() = default; +}; + +} // namespace +#endif \ No newline at end of file diff --git a/frameworks/core/components_ng/pattern/text_field/text_field_paint_property.h b/frameworks/core/components_ng/pattern/text_field/text_field_paint_property.h index 1698bd12e48314cc1de67279d5e8d76fbe8defa9..391b8badaba1c0a0ac34cbce7b26a67d99fcec13 100644 --- a/frameworks/core/components_ng/pattern/text_field/text_field_paint_property.h +++ b/frameworks/core/components_ng/pattern/text_field/text_field_paint_property.h @@ -98,7 +98,8 @@ public: // 用于记录开发者设置的值 ACE_DEFINE_PROPERTY_ITEM_WITHOUT_GROUP(TextColorFlagByUser, Color, PROPERTY_UPDATE_RENDER); ACE_DEFINE_PROPERTY_ITEM_WITHOUT_GROUP(CaretColorFlagByUser, Color, PROPERTY_UPDATE_RENDER); - ACE_DEFINE_PROPERTY_ITEM_WITHOUT_GROUP(PlaceholderColorFlagByUser, Color, PROPERTY_UPDATE_RENDER); + ACE_DEFINE_PROPERTY_ITEM_WITHOUT_GROUP(PlaceholderColorFlagByUser, Color, PROPERTY_UPDATE_RENDER); + ACE_DEFINE_PROPERTY_ITEM_WITHOUT_GROUP(SelectedBackgroundColorFlagByUser, Color, PROPERTY_UPDATE_RENDER); ACE_DEFINE_PROPERTY_ITEM_WITHOUT_GROUP(BorderRadiusFlagByUser, BorderRadiusProperty, PROPERTY_UPDATE_RENDER); ACE_DEFINE_PROPERTY_ITEM_WITHOUT_GROUP(BorderColorFlagByUser, BorderColorProperty, PROPERTY_UPDATE_RENDER); ACE_DEFINE_PROPERTY_ITEM_WITHOUT_GROUP(BorderWidthFlagByUser, BorderWidthProperty, PROPERTY_UPDATE_RENDER); diff --git a/frameworks/core/components_ng/pattern/text_field/text_field_pattern.cpp b/frameworks/core/components_ng/pattern/text_field/text_field_pattern.cpp index 798aed8a2449464a52f20283aacd63e1ab1380ff..1f1d343262eceefb758a3f6fcac514549be560c6 100644 --- a/frameworks/core/components_ng/pattern/text_field/text_field_pattern.cpp +++ b/frameworks/core/components_ng/pattern/text_field/text_field_pattern.cpp @@ -4096,7 +4096,7 @@ bool TextFieldPattern::OnThemeScopeUpdate(int32_t themeScopeId) CHECK_NULL_RETURN(renderContext, result); renderContext->UpdateBackgroundColor(bgColor); result = true; - } + } if (!paintProperty->HasTextColorFlagByUser()) { textFieldLayoutProperty->UpdateTextColor(textFieldTheme->GetTextColor()); diff --git a/frameworks/core/interfaces/native/node/search_modifier.cpp b/frameworks/core/interfaces/native/node/search_modifier.cpp index 2895b1b98ed189d33fd05a11cc6940eff6a613f7..c47502a55565676f0fe97ef73553ddba35e5e01f 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 = OHOS::Ace::PipelineBase::GetCurrentContextSafely(); + 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) {