From 46e493cc715636195d59eb4403a323ea7b3d7569 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=BD=9C=E7=A7=8B=E5=AE=8F?= Date: Wed, 21 May 2025 22:42:31 +0800 Subject: [PATCH] =?UTF-8?q?=E6=94=AF=E6=8C=81=E7=84=A6=E7=82=B9=E6=A1=86?= =?UTF-8?q?=E6=A0=B7=E5=BC=8F=E4=B8=BB=E9=A2=98=E5=92=8C=E5=B9=B3=E5=8F=B0?= =?UTF-8?q?=E9=85=8D=E7=BD=AE=E8=83=BD=E5=8A=9B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 潜秋宏 --- .../core/components_ng/event/focus_hub.cpp | 32 ++++++------ test/unittest/BUILD.gn | 15 +++--- .../unittest/core/event/focus_hub_test_ng.cpp | 51 +++++++++++++++++++ 3 files changed, 75 insertions(+), 23 deletions(-) diff --git a/frameworks/core/components_ng/event/focus_hub.cpp b/frameworks/core/components_ng/event/focus_hub.cpp index c157c402779..01fa0d799c2 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 45ce084f98b..9c5386b7ad9 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 44cb1282d5b..69e189ab24d 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 -- Gitee