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 01c635ef71947ba2309ad72d56e191330be26584..0000000000000000000000000000000000000000 --- 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 a58b9a76e44480976ac6f310c197e5ed46ed368f..f933a08b6f44f126a1f534cbef0c211b2429482f 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 454b0eb52c35e08462f277597db1257019126b22..32d48af5a98fd1279f6ad767b6eb1a4aa732aaba 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 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/bridge/declarative_frontend/jsview/js_search.cpp b/frameworks/bridge/declarative_frontend/jsview/js_search.cpp index 3b528379b2fb85af13f942528baaddccaa6a4f10..823d198180facc24ac906bb23f0944b18dbd4eed 100644 --- a/frameworks/bridge/declarative_frontend/jsview/js_search.cpp +++ b/frameworks/bridge/declarative_frontend/jsview/js_search.cpp @@ -22,7 +22,7 @@ #endif #include "base/log/ace_scoring_log.h" -#include "bridge/declarative_frontend/ark_theme/theme_apply/js_search_theme.h" +#include "bridge/declarative_frontend/ark_theme/theme_apply/js_theme_utils.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" @@ -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) @@ -320,17 +319,21 @@ 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); - } + ObtainSearchButtonFontColor(fontColor); } else { SearchModel::GetInstance()->SetSearchButtonFontColor(fontColor); } } else { SearchModel::GetInstance()->SetSearchButtonFontSize(theme->GetFontSize()); - if (!JSSeacrhTheme::ObtainSearchButtonFontColor(fontColor)) { - SearchModel::GetInstance()->SetSearchButtonFontColor(fontColor); - } + ObtainSearchButtonFontColor(fontColor); + } +} + +void JSSearch::ObtainSearchButtonFontColor(Color &color) +{ + if (auto themeColors = JSThemeUtils::GetThemeColors(); themeColors.has_value()) { + color = themeColors->FontEmphasize(); + SearchModel::GetInstance()->SetSearchButtonFontColor(color); } } diff --git a/frameworks/bridge/declarative_frontend/jsview/js_search.h b/frameworks/bridge/declarative_frontend/jsview/js_search.h index aedd6aa8dd047eca4cfb8fe9fdffc30241ca076b..34b14033727118e9c598eca903c35d0af265bad8 100644 --- a/frameworks/bridge/declarative_frontend/jsview/js_search.h +++ b/frameworks/bridge/declarative_frontend/jsview/js_search.h @@ -95,6 +95,8 @@ public: static void SetCancelSymbolIcon(const JSCallbackInfo& info); static void SetCancelImageIcon(const JSCallbackInfo& info); static void SetEnableHapticFeedback(const JSCallbackInfo& info); +private: + static void ObtainSearchButtonFontColor(Color &color); }; class JSSearchController final : public Referenced { 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..79234ef6aecc477fa2ed3a617e0038d1d6e50710 100644 --- a/frameworks/core/components_ng/pattern/search/search_layout_algorithm.cpp +++ b/frameworks/core/components_ng/pattern/search/search_layout_algorithm.cpp @@ -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(); @@ -586,7 +586,7 @@ void SearchLayoutAlgorithm::CalcChildrenHotZone(LayoutWrapper* layoutWrapper) void SearchLayoutAlgorithm::Layout(LayoutWrapper* layoutWrapper) { auto host = layoutWrapper->GetHostNode(); - CHECK_NULL_VOID(host); + CHECK_NULL_VOID(host); auto children = host->GetChildren(); if (children.empty()) { return; @@ -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_model_ng.cpp b/frameworks/core/components_ng/pattern/search/search_model_ng.cpp index e43e91da58e0b9d2224991b7e74f022ef98e9fe8..f2962b1ad1461538b57a01531714ac84ee935c62 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); @@ -121,6 +121,7 @@ RefPtr SearchModelNG::CreateSearchNode(int32_t nodeId, const std::op pattern->SetSearchController(textFieldPattern->GetTextFieldController()); pattern->UpdateChangeEvent(textFieldPattern->GetTextValue()); + //frameNode->AllowUseParentTheme(false); return frameNode; } @@ -361,6 +362,11 @@ void SearchModelNG::SetPlaceholderFont(const Font& font) void SearchModelNG::SetSelectedBackgroundColor(const Color& value) { auto frameNode = ViewStackProcessor::GetInstance()->GetMainFrameNode(); + SetSelectedBackgroundColor(frameNode, value); +} + +void SearchModelNG::SetSelectedBackgroundColor(FrameNode* frameNode, const Color& value) +{ CHECK_NULL_VOID(frameNode); auto textFieldChild = AceType::DynamicCast(frameNode->GetChildren().front()); CHECK_NULL_VOID(textFieldChild); @@ -745,10 +751,11 @@ 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 textFieldLayoutProperty = frameNode->GetLayoutProperty(); auto textFieldPaintProperty = frameNode->GetPaintProperty(); + textFieldPaintProperty->UpdateSelectedBackgroundColor(Color::TRANSPARENT); std::set allowDropSet({ DROP_TYPE_PLAIN_TEXT, DROP_TYPE_HYPERLINK, DROP_TYPE_STYLED_STRING }); frameNode->SetAllowDrop(allowDropSet); auto parentInspector = parentNode->GetInspectorIdValue(""); @@ -790,7 +797,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 +840,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 +848,10 @@ 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->UpdateBackgroundColor(Color::TRANSPARENT); buttonRenderContext->UpdateClipEdge(true); auto textFrameNode = AceType::DynamicCast(frameNode->GetChildren().front()); auto textLayoutProperty = textFrameNode->GetLayoutProperty(); @@ -882,7 +891,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 +920,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 +930,10 @@ 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); + //cancelButtonRenderContext->UpdateBackgroundColor(Color::TRANSPARENT); auto textFrameNode = AceType::DynamicCast(frameNode->GetChildren().front()); auto textLayoutProperty = textFrameNode->GetLayoutProperty(); textLayoutProperty->UpdateFontSize(searchTheme->GetFontSize()); @@ -1000,20 +1011,6 @@ RefPtr SearchModelNG::GetSearchTextFieldFrameNode() const return textFieldChild; } -void SearchModelNG::SetSearchEnterKeyType(TextInputAction value) -{ - auto frameNode = ViewStackProcessor::GetInstance()->GetMainFrameNode(); - CHECK_NULL_VOID(frameNode); - auto textFieldChild = AceType::DynamicCast(frameNode->GetChildren().front()); - CHECK_NULL_VOID(textFieldChild); - auto pattern = textFieldChild->GetPattern(); - CHECK_NULL_VOID(pattern); - if (value == TextInputAction::UNSPECIFIED) { - value = TextInputAction::SEARCH; - } - pattern->UpdateTextInputAction(value); -} - void SearchModelNG::SetMaxLength(uint32_t value) { auto frameNode = ViewStackProcessor::GetInstance()->GetMainFrameNode(); @@ -1382,6 +1379,12 @@ void SearchModelNG::SetSearchEnterKeyType(FrameNode* frameNode, TextInputAction pattern->UpdateTextInputAction(value); } +void SearchModelNG::SetSearchEnterKeyType(TextInputAction value) +{ + auto frameNode = ViewStackProcessor::GetInstance()->GetMainFrameNode(); + SetSearchEnterKeyType(frameNode, value); +} + void SearchModelNG::SetHeight(FrameNode* frameNode, const Dimension& height) { NG::ViewAbstract::SetHeight(frameNode, NG::CalcLength(height)); @@ -1524,13 +1527,7 @@ void SearchModelNG::SetTextDecoration(FrameNode* frameNode, Ace::TextDecoration void SearchModelNG::SetTextDecorationColor(const Color& value) { 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->UpdateTextDecorationColor(value); - textFieldChild->MarkDirtyNode(PROPERTY_UPDATE_MEASURE); + SetTextDecorationColor(frameNode, value); } void SearchModelNG::SetTextDecorationColor(FrameNode* frameNode, const Color& value) @@ -1547,24 +1544,7 @@ void SearchModelNG::SetTextDecorationColor(FrameNode* frameNode, const Color& va void SearchModelNG::SetTextDecorationStyle(Ace::TextDecorationStyle value) { 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->UpdateTextDecorationStyle(value); - textFieldChild->MarkDirtyNode(PROPERTY_UPDATE_MEASURE); -} - -void SearchModelNG::SetSelectedBackgroundColor(FrameNode* frameNode, const Color& value) -{ - 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); + SetTextDecorationStyle(frameNode, value); } void SearchModelNG::SetTextDecorationStyle(FrameNode* frameNode, Ace::TextDecorationStyle value) diff --git a/frameworks/core/components_ng/pattern/search/search_pattern.cpp b/frameworks/core/components_ng/pattern/search/search_pattern.cpp index a3c4b75cc7409d301fe98154dd2aa9506d7da06c..a095583cbf03671138ef805224a8c9bb41aa64ee 100644 --- a/frameworks/core/components_ng/pattern/search/search_pattern.cpp +++ b/frameworks/core/components_ng/pattern/search/search_pattern.cpp @@ -216,18 +216,8 @@ void SearchPattern::OnModifyDone() auto imageFrameNode = DynamicCast(host->GetChildAtIndex(IMAGE_INDEX)); CHECK_NULL_VOID(imageFrameNode); imageFrameNode->MarkModifyDone(); - auto buttonFrameNode = DynamicCast(host->GetChildAtIndex(BUTTON_INDEX)); - CHECK_NULL_VOID(buttonFrameNode); - auto buttonLayoutProperty = buttonFrameNode->GetLayoutProperty(); - CHECK_NULL_VOID(buttonLayoutProperty); - buttonLayoutProperty->UpdateVisibility(searchButton.has_value() ? VisibleType::VISIBLE : VisibleType::GONE); - buttonLayoutProperty->UpdateLabel(searchButton_); - buttonLayoutProperty->UpdateTextOverflow(TextOverflow::ELLIPSIS); - buttonFrameNode->MarkModifyDone(); - - auto searchButtonEvent = buttonFrameNode->GetEventHub(); - isSearchButtonEnabled_ = searchButtonEvent->IsEnabled(); + UpdateSearchButton(searchButton.has_value()); UpdateCancelButton(); UpdateDivider(); InitButtonAndImageClickEvent(); @@ -246,6 +236,22 @@ void SearchPattern::OnModifyDone() SetAccessibilityAction(); } +void SearchPattern::UpdateSearchButton(bool isVisible) +{ + auto host = GetHost(); + CHECK_NULL_VOID(host); + auto buttonFrameNode = DynamicCast(host->GetChildAtIndex(BUTTON_INDEX)); + CHECK_NULL_VOID(buttonFrameNode); + auto buttonLayoutProperty = buttonFrameNode->GetLayoutProperty(); + CHECK_NULL_VOID(buttonLayoutProperty); + buttonLayoutProperty->UpdateVisibility(isVisible ? VisibleType::VISIBLE : VisibleType::GONE); + buttonLayoutProperty->UpdateLabel(searchButton_); + buttonLayoutProperty->UpdateTextOverflow(TextOverflow::ELLIPSIS); + buttonFrameNode->MarkModifyDone(); + auto searchButtonEvent = buttonFrameNode->GetEventHub(); + isSearchButtonEnabled_ = searchButtonEvent->IsEnabled(); +} + void SearchPattern::UpdateCancelButton() { auto host = GetHost(); @@ -1558,7 +1564,7 @@ void SearchPattern::UpdateDividerColorMode() CHECK_NULL_VOID(dividerFrameNode); auto pipeline = dividerFrameNode->GetContext(); CHECK_NULL_VOID(pipeline); - auto searchTheme = pipeline->GetTheme(); + auto searchTheme = pipeline->GetTheme(dividerFrameNode->GetThemeScopeId()); CHECK_NULL_VOID(searchTheme); auto searchDividerColor = searchTheme->GetSearchDividerColor(); auto dividerRenderProperty = dividerFrameNode->GetPaintProperty(); @@ -1568,67 +1574,71 @@ void SearchPattern::UpdateDividerColorMode() dividerFrameNode->MarkDirtyNode(PROPERTY_UPDATE_MEASURE_SELF); } -void SearchPattern::UpdateCancelButtonColorMode() +void SearchPattern::ApplyButtonColorMode(const RefPtr button) { - auto cancelButtonNode = cancelButtonNode_.Upgrade(); - CHECK_NULL_VOID(cancelButtonNode); - auto pipeline = cancelButtonNode->GetContext(); + CHECK_NULL_VOID(button); + auto pipeline = button->GetContext(); CHECK_NULL_VOID(pipeline); - auto searchTheme = pipeline->GetTheme(); + auto searchTheme = pipeline->GetTheme(button->GetThemeScopeId()); CHECK_NULL_VOID(searchTheme); - auto cancelButtonRenderContext = cancelButtonNode->GetRenderContext(); - CHECK_NULL_VOID(cancelButtonRenderContext); - cancelButtonRenderContext->UpdateBackgroundColor(Color::TRANSPARENT); - auto textFrameNode = AceType::DynamicCast(cancelButtonNode->GetChildren().front()); + auto textFrameNode = AceType::DynamicCast(button->GetChildren().front()); CHECK_NULL_VOID(textFrameNode); auto textLayoutProperty = textFrameNode->GetLayoutProperty(); CHECK_NULL_VOID(textLayoutProperty); textLayoutProperty->UpdateTextColor(searchTheme->GetSearchButtonTextColor()); - cancelButtonNode->MarkModifyDone(); - cancelButtonNode->MarkDirtyNode(PROPERTY_UPDATE_MEASURE_SELF); + button->MarkModifyDone(); + button->MarkDirtyNode(PROPERTY_UPDATE_MEASURE_SELF); +} + +void SearchPattern::UpdateButtonColorMode() +{ + ApplyButtonColorMode(buttonNode_.Upgrade()); +} + +void SearchPattern::UpdateCancelButtonColorMode() +{ + ApplyButtonColorMode(cancelButtonNode_.Upgrade()); +} + +void SearchPattern::UpdateTextFieldColorMode() +{ + auto textField = textField_.Upgrade(); + auto pipeline = textField->GetContext(); + CHECK_NULL_VOID(pipeline); + auto textFieldLayoutProperty = textField->GetLayoutProperty(); + CHECK_NULL_VOID(textFieldLayoutProperty); + auto searchTheme = pipeline->GetTheme(textField->GetThemeScopeId()); + CHECK_NULL_VOID(searchTheme); + textFieldLayoutProperty->UpdateTextColor(searchTheme->GetTextColor()); + textFieldLayoutProperty->UpdatePlaceholderTextColor(searchTheme->GetPlaceholderColor()); + //textFieldLayoutProperty->UpdateBackgroundColor(Color::TRANSPARENT); + textField->MarkModifyDone(); + textField->MarkDirtyNode(PROPERTY_UPDATE_MEASURE_SELF); } void SearchPattern::OnColorConfigurationUpdate() { auto host = GetHost(); CHECK_NULL_VOID(host); - 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(); - CHECK_NULL_VOID(searchTheme); UpdateCancelButtonColorMode(); - auto buttonNode = buttonNode_.Upgrade(); - if (buttonNode) { - auto buttonRenderContext = buttonNode->GetRenderContext(); - CHECK_NULL_VOID(buttonRenderContext); - buttonRenderContext->UpdateBackgroundColor(Color::TRANSPARENT); - auto textFrameNode = AceType::DynamicCast(buttonNode->GetChildren().front()); - CHECK_NULL_VOID(textFrameNode); - auto textLayoutProperty = textFrameNode->GetLayoutProperty(); - CHECK_NULL_VOID(textLayoutProperty); - textLayoutProperty->UpdateTextColor(searchTheme->GetSearchButtonTextColor()); - buttonNode->MarkModifyDone(); - buttonNode->MarkDirtyNode(PROPERTY_UPDATE_MEASURE_SELF); - } - auto textField = textField_.Upgrade(); - if (textField) { - auto textFieldLayoutProperty = textField->GetLayoutProperty(); - CHECK_NULL_VOID(textFieldLayoutProperty); - textFieldLayoutProperty->UpdateTextColor(searchTheme->GetTextColor()); - textFieldLayoutProperty->UpdatePlaceholderTextColor(searchTheme->GetPlaceholderColor()); - textField->MarkModifyDone(); - textField->MarkDirtyNode(PROPERTY_UPDATE_MEASURE_SELF); - } + UpdateButtonColorMode(); + UpdateTextFieldColorMode(); UpdateDividerColorMode(); } +bool SearchPattern::OnThemeScopeUpdate(int32_t themeScopeId){ + OnColorConfigurationUpdate(); + return true; +} + uint32_t SearchPattern::GetMaxLength() const { auto host = GetHost(); @@ -1679,7 +1689,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 +1703,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 +1780,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 +1831,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 +2054,10 @@ void SearchPattern::UpdateImageIconProperties(RefPtr& iconFrameNode, CHECK_NULL_VOID(host); auto pipeline = host->GetContext(); CHECK_NULL_VOID(pipeline); - auto searchTheme = pipeline->GetTheme(); + auto themeId = host->GetThemeScopeId(); + auto searchTheme = pipeline->GetTheme(themeId); CHECK_NULL_VOID(searchTheme); - auto iconTheme = pipeline->GetTheme(); + auto iconTheme = pipeline->GetTheme(themeId); CHECK_NULL_VOID(iconTheme); if (iconOptions.GetSrc().value_or("").empty()) { imageSourceInfo.SetResourceId(index == IMAGE_INDEX ? InternalResource::ResourceId::SEARCH_SVG @@ -2082,7 +2093,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..bb8bb8854b6db00881c112d6bfbcd0fcddecb600 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); @@ -283,9 +284,13 @@ private: void UpdateIconColor(int32_t index, const Color& color); void UpdateIconSize(int32_t index, const Dimension& value); void UpdateDivider(); + void UpdateSearchButton(bool hasValue); void UpdateCancelButton(); void UpdateDividerColorMode(); + void ApplyButtonColorMode(const RefPtr button); + void UpdateButtonColorMode(); void UpdateCancelButtonColorMode(); + void UpdateTextFieldColorMode(); uint32_t GetMaxLength() const; std::string SearchTypeToString() const; 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..fe0d2febbd9339bf52c45288473fbbf20e96d4bf --- /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_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(); + bgColor_ = colors->CompBackgroundTertiary(); + focusBgColor_ = colors->CompBackgroundTertiary(); + cursorColor_ = colors->Brand(); + } + } + +protected: + SearchThemeWrapper() = default; +}; + +} // namespace +#endif diff --git a/frameworks/core/interfaces/native/node/node_utils.h b/frameworks/core/interfaces/native/node/node_utils.h index f156d1dfea658791484e54a5111923bb7cb6b1f3..c5c3c52e4ea3cf03f77f26af37dd2398bd6ac348 100644 --- a/frameworks/core/interfaces/native/node/node_utils.h +++ b/frameworks/core/interfaces/native/node/node_utils.h @@ -44,6 +44,15 @@ template OHOS::Ace::RefPtr GetTheme() CHECK_NULL_RETURN(themeManager, nullptr); return themeManager->GetTheme(); } + +template OHOS::Ace::RefPtr GetTheme(int32_t themeId) +{ + auto pipelineContext = OHOS::Ace::PipelineBase::GetCurrentContextSafely(); + CHECK_NULL_RETURN(pipelineContext, nullptr); + auto themeManager = pipelineContext->GetThemeManager(); + CHECK_NULL_RETURN(themeManager, nullptr); + return themeManager->GetTheme(themeId); +} } #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_INTERFACES_NODE_UTILS_H diff --git a/frameworks/core/interfaces/native/node/search_modifier.cpp b/frameworks/core/interfaces/native/node/search_modifier.cpp index 2895b1b98ed189d33fd05a11cc6940eff6a613f7..817d48d4dd70aa390fede0e0c9cfeb5551baad7c 100644 --- a/frameworks/core/interfaces/native/node/search_modifier.cpp +++ b/frameworks/core/interfaces/native/node/search_modifier.cpp @@ -100,7 +100,7 @@ void ResetSearchCaretStyle(ArkUINodeHandle node) { auto* frameNode = reinterpret_cast(node); CHECK_NULL_VOID(frameNode); - auto textFieldTheme = GetTheme(); + auto textFieldTheme = GetTheme(frameNode->GetThemeScopeId()); CHECK_NULL_VOID(textFieldTheme); CalcDimension caretWidth = textFieldTheme->GetCursorWidth(); uint32_t caretColor = textFieldTheme->GetCursorColor().GetValue(); @@ -367,7 +367,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 +386,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 +411,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) {