diff --git a/frameworks/core/components_ng/event/focus_hub.cpp b/frameworks/core/components_ng/event/focus_hub.cpp index c157c4027797ed9405518449627799b14966362e..01fa0d799c22e16bbaf3c7358ce4561163af99af 100644 --- a/frameworks/core/components_ng/event/focus_hub.cpp +++ b/frameworks/core/components_ng/event/focus_hub.cpp @@ -20,6 +20,7 @@ #include "core/components_ng/pattern/scrollable/scrollable_pattern.h" #include "core/components_ng/pattern/scrollable/scrollable_utils.h" #include "core/components_ng/base/inspector.h" +#include "core/components_ng/token_theme/token_theme_storage.h" #ifdef WINDOW_SCENE_SUPPORTED #include "core/components_ng/pattern/window_scene/helper/window_scene_helper.h" @@ -1591,11 +1592,20 @@ void FocusHub::GetPaintColorFromBox(Color& paintColor) CHECK_NULL_VOID(appTheme); if (box_.paintStyle_ && box_.paintStyle_->strokeColor) { paintColor = box_.paintStyle_->strokeColor.value(); - } else if (HasPaintColor()) { + return; + } + if (HasPaintColor()) { paintColor = GetPaintColor(); - } else { - paintColor = appTheme->GetFocusColor(); + return; + } + auto themeScopeId = frameNode->GetThemeScopeId(); + auto tokenTheme = TokenThemeStorage::GetInstance()->GetTheme(themeScopeId); + auto themeColors = tokenTheme ? tokenTheme->Colors() : nullptr; + if (themeColors) { + paintColor = themeColors->InteractiveFocus(); + return; } + paintColor = appTheme->GetFocusColor(); } void FocusHub::GetPaintWidthFromBox(Dimension& paintWidth) @@ -1741,21 +1751,9 @@ bool FocusHub::PaintInnerFocusState(const RoundRect& paintRect, bool forceUpdate auto appTheme = context->GetTheme(); CHECK_NULL_RETURN(appTheme, false); Color paintColor; - if (box_.paintStyle_ && box_.paintStyle_->strokeColor) { - paintColor = box_.paintStyle_->strokeColor.value(); - } else if (HasPaintColor()) { - paintColor = GetPaintColor(); - } else { - paintColor = appTheme->GetFocusColor(); - } + GetPaintColorFromBox(paintColor); Dimension paintWidth; - if (box_.paintStyle_ && box_.paintStyle_->strokeWidth) { - paintWidth = box_.paintStyle_->strokeWidth.value(); - } else if (HasPaintWidth()) { - paintWidth = GetPaintWidth(); - } else { - paintWidth = appTheme->GetFocusWidthVp(); - } + GetPaintWidthFromBox(paintWidth); renderContext->ClearFocusState(); if (NEAR_ZERO(paintWidth.Value())) { return true; diff --git a/test/unittest/BUILD.gn b/test/unittest/BUILD.gn index 45ce084f98b0b78b4cd75b729b26399fc82dfa73..9c5386b7ad903ff8b64b32f9476329fbc4d5d002 100644 --- a/test/unittest/BUILD.gn +++ b/test/unittest/BUILD.gn @@ -220,13 +220,11 @@ ohos_source_set("ace_components_base") { part_name = ace_engine_part sources = [ "$ace_root/adapter/preview/entrance/ui_session/ui_session_json_util.cpp", - "$ace_root/interfaces/inner_api/ace_kit/src/view/theme/token_colors.cpp", - "$ace_root/frameworks/core/common/resource/resource_manager.cpp", - "$ace_root/frameworks/core/common/resource/resource_wrapper.cpp", "$ace_root/frameworks/core/common/resource/pattern_resource_manager.cpp", + "$ace_root/frameworks/core/common/resource/resource_manager.cpp", "$ace_root/frameworks/core/common/resource/resource_parse_utils.cpp", + "$ace_root/frameworks/core/common/resource/resource_wrapper.cpp", "$ace_root/frameworks/core/components/theme/shadow_theme.cpp", - "$ace_root/frameworks/core/components_ng/token_theme/token_theme_storage.cpp", "$ace_root/frameworks/core/components_ng/base/distributed_ui.cpp", "$ace_root/frameworks/core/components_ng/base/extension_handler.cpp", "$ace_root/frameworks/core/components_ng/base/frame_node.cpp", @@ -245,6 +243,8 @@ ohos_source_set("ace_components_base") { "$ace_root/frameworks/core/components_ng/base/view_stack_processor.cpp", "$ace_root/frameworks/core/components_ng/pattern/pattern.cpp", "$ace_root/frameworks/core/components_ng/pattern/ui_extension/dynamic_component/dynamic_component_manager.cpp", + "$ace_root/frameworks/core/components_ng/token_theme/token_theme_storage.cpp", + "$ace_root/interfaces/inner_api/ace_kit/src/view/theme/token_colors.cpp", ] if (ace_engine_feature_enable_split_mode && defined( @@ -296,7 +296,10 @@ ohos_source_set("ace_components_event") { "$ace_root/frameworks/core/gestures/gesture_referee.cpp", ] configs = [ ":ace_unittest_config" ] - deps = [ "$ace_root/frameworks/core/components/theme:build_theme_code" ] + deps = [ + "$ace_root/frameworks/core/components/theme:build_theme_code", + "$ace_root/test/unittest:ace_components_token_theme", + ] if (current_os == "ohos") { external_deps = [ "c_utils:utils" ] } @@ -466,8 +469,8 @@ ohos_source_set("ace_components_token_theme") { subsystem_name = ace_engine_subsystem part_name = ace_engine_part sources = [ - "$ace_root/interfaces/inner_api/ace_kit/src/view/theme/token_colors.cpp", "$ace_root/frameworks/core/components_ng/token_theme/token_theme_storage.cpp", + "$ace_root/interfaces/inner_api/ace_kit/src/view/theme/token_colors.cpp", ] configs = [ ":ace_unittest_config_ext" ] } diff --git a/test/unittest/core/event/focus_hub_test_ng.cpp b/test/unittest/core/event/focus_hub_test_ng.cpp index 44cb1282d5b2e0d3867d6b13106e1d6ae4518403..69e189ab24d9410935fa1f36c137de883ea0e6c5 100755 --- a/test/unittest/core/event/focus_hub_test_ng.cpp +++ b/test/unittest/core/event/focus_hub_test_ng.cpp @@ -2523,4 +2523,55 @@ HWTEST_F(FocusHubTestNg, GetKeyProcessingMode002, TestSize.Level1) auto result = focusHub->GetKeyProcessingMode(); EXPECT_EQ(result, static_cast(KeyProcessingMode::ANCESTOR_EVENT)); } + +/** + * @tc.name: FocusHubPaintColorTest001 + * @tc.desc: Test the function GetPaintColorFromBox + * @tc.type: FUNC + */ +HWTEST_F(FocusHubTestNg, FocusHubPaintColorTest001, TestSize.Level1) +{ + /** + * @tc.steps: step1. Create focusHub. + */ + auto frameNode = AceType::MakeRefPtr(V2::ROW_ETS_TAG, -1, AceType::MakeRefPtr()); + ASSERT_NE(frameNode, nullptr); + auto focusHub = frameNode->GetOrCreateFocusHub(); + ASSERT_NE(focusHub, nullptr); + auto context = PipelineContext::GetCurrentContext(); + ASSERT_NE(context, nullptr); + Color expectPaintColor; + Color resultPaintColor; + + /** + * @tc.steps: step2. Test without anything. + */ + auto themeManager = AceType::MakeRefPtr(); + MockPipelineContext::GetCurrent()->SetThemeManager(themeManager); + EXPECT_CALL(*themeManager, GetTheme(_)).WillRepeatedly(Return(AceType::MakeRefPtr())); + auto appTheme = context->GetTheme(); + appTheme->focusColor_ = Color::GREEN; + expectPaintColor = Color::GREEN; + focusHub->GetPaintColorFromBox(resultPaintColor); + EXPECT_EQ(expectPaintColor, resultPaintColor); + + /** + * @tc.steps: step3. Test with custom paintColor. + */ + auto testFocusPaintParams = std::make_unique(); + testFocusPaintParams->paintColor = Color::BLACK; + expectPaintColor = Color::BLACK; + focusHub->focusPaintParamsPtr_ = std::move(testFocusPaintParams); + focusHub->GetPaintColorFromBox(resultPaintColor); + EXPECT_EQ(expectPaintColor, resultPaintColor); + + /** + * @tc.steps: step4. Test with custom paintColor and focusbox. + */ + FocusBoxStyle style = { Color::RED }; + expectPaintColor = Color::RED; + focusHub->GetFocusBox().SetStyle(style); + focusHub->GetPaintColorFromBox(resultPaintColor); + EXPECT_EQ(expectPaintColor, resultPaintColor); +} } // namespace OHOS::Ace::NG