From 1bd6c0e2c1f4988141d8ee93484ad02fac14bd27 Mon Sep 17 00:00:00 2001 From: dong_bin1118 Date: Fri, 15 Aug 2025 19:09:33 +0800 Subject: [PATCH 1/4] pip Signed-off-by: dong_bin1118 --- .../components_ng/pattern/web/web_pattern.cpp | 25 ++++++ .../components_ng/pattern/web/web_pattern.h | 1 + .../core/pattern/web/web_pattern_test_ng.cpp | 79 +++++++++++++++++++ 3 files changed, 105 insertions(+) diff --git a/frameworks/core/components_ng/pattern/web/web_pattern.cpp b/frameworks/core/components_ng/pattern/web/web_pattern.cpp index 2d068eff7ff..98328a81f41 100644 --- a/frameworks/core/components_ng/pattern/web/web_pattern.cpp +++ b/frameworks/core/components_ng/pattern/web/web_pattern.cpp @@ -215,6 +215,8 @@ enum PictureInPictureState { PIP_STATE_HLS_EXIT, PIP_STATE_RESIZE, PIP_STATE_NONE, + PIP_STATE_UPDATE_SURFACE, + PIP_STATE_PAGE_CLOSE, }; struct PipData { @@ -8528,6 +8530,10 @@ bool WebPattern::Pip(int status, result = StopPip(delegateId, childId, frameRoutingId); break; } + case PIP_STATE_PAGE_CLOSE: { + result = PageClosePip(delegateId, childId, frameRoutingId); + break; + } case PIP_STATE_PLAY: { result = PlayPip(delegateId, childId, frameRoutingId); break; @@ -8695,6 +8701,25 @@ bool WebPattern::StopPip(int delegateId, int childId, int frameRoutingId) return false; } +bool WebPattern::PageClosePip(int delegateId, int childId, int frameRoutingId) +{ + std::lock_guard lock(pipCallbackMapMutex_); + for (auto &it : pipCallbackMap_) { + auto pip = it.second; + if (pip.delegateId == delegateId && pip.childId == childId && + pip.frameRoutingId == frameRoutingId) { + bool result = true; + auto errCode = OH_PictureInPicture_StopPip(it.first); + if (errCode != 0) { + TAG_LOGE(AceLogTag::ACE_WEB, "OH_PictureInPicture_StopPip err: %{public}d", errCode); + result = false; + } + return result; + } + } + return false; +} + bool WebPattern::PlayPip(int delegateId, int childId, int frameRoutingId) { bool flag = false; diff --git a/frameworks/core/components_ng/pattern/web/web_pattern.h b/frameworks/core/components_ng/pattern/web/web_pattern.h index 4faedd4ce2a..d14a752d955 100644 --- a/frameworks/core/components_ng/pattern/web/web_pattern.h +++ b/frameworks/core/components_ng/pattern/web/web_pattern.h @@ -909,6 +909,7 @@ private: bool StopPip(int delegateId, int childId, int frameRoutingId); bool PlayPip(int delegateId, int childId, int frameRoutingId); bool PausePip(int delegateId, int childId, int frameRoutingId); + bool PageClosePip(int delegateId, int childId, int frameRoutingId); void GetPreviewImageOffsetAndSize(bool isImage, Offset& previewOffset, SizeF& previewSize); RefPtr CreatePreviewImageFrameNode(bool isImage); void ShowPreviewMenu(WebElementType type); diff --git a/test/unittest/core/pattern/web/web_pattern_test_ng.cpp b/test/unittest/core/pattern/web/web_pattern_test_ng.cpp index 28c29f3b54c..c14c7a70f28 100755 --- a/test/unittest/core/pattern/web/web_pattern_test_ng.cpp +++ b/test/unittest/core/pattern/web/web_pattern_test_ng.cpp @@ -48,6 +48,8 @@ enum PictureInPictureState { PIP_STATE_HLS_EXIT, PIP_STATE_RESIZE, PIP_STATE_NONE, + PIP_STATE_UPDATE_SURFACE, + PIP_STATE_PAGE_CLOSE, }; enum PictureInPictureCallback { @@ -4631,6 +4633,83 @@ HWTEST_F(WebPatternTestNg, StopPipPip_004, TestSize.Level1) #endif } +/** + * @tc.name: PageClosePip_001 + * @tc.desc: PageClosePip. + * @tc.type: FUNC + */ +HWTEST_F(WebPatternTestNg, PageClosePip_001, TestSize.Level1) +{ +#ifdef OHOS_STANDARD_SYSTEM + WebPattern webPattern; + webPattern.delegate_ = nullptr; + EXPECT_EQ(webPattern.delegate_, nullptr); + bool init = false; + uint32_t pipController = 0; + napi_env env = nullptr; + PipInfo info{1, 0, 0, 0, PIP_WIDTH, PIP_HEIGHT}; + bool ret = webPattern.PageClosePip(info.delegateId, info.childId, info.frameRoutingId); + ret = webPattern.CreatePip(PIP_STATE_ENTER, env, init, pipController, info); + ASSERT_EQ(ret, true); + ret = webPattern.RegisterPip(pipController); + ASSERT_EQ(ret, true); + ret = webPattern.StartPip(pipController); + ASSERT_EQ(ret, true); + webPattern.EnablePip(pipController); + ret = webPattern.PageClosePip(info.delegateId, info.childId, info.frameRoutingId); + ASSERT_EQ(ret, true); + ret = webPattern.PageClosePip(info.delegateId + 1, info.childId, info.frameRoutingId); + ASSERT_EQ(ret, false); + ret = webPattern.PageClosePip(info.delegateId, info.childId + 1, info.frameRoutingId); + ASSERT_EQ(ret, false); + ret = webPattern.PageClosePip(info.delegateId, info.childId, info.frameRoutingId + 1); + ASSERT_EQ(ret, false); +#endif +} + +/** + * @tc.name: PageClosePip_002 + * @tc.desc: PageClosePip. + * @tc.type: FUNC + */ +HWTEST_F(WebPatternTestNg, PageClosePip_002, TestSize.Level1) +{ +#ifdef OHOS_STANDARD_SYSTEM + WebPattern webPattern; + webPattern.delegate_ = nullptr; + EXPECT_EQ(webPattern.delegate_, nullptr); + bool init = false; + uint32_t pipController = PIP_ID_OK_2; + napi_env env = nullptr; + PipInfo info{1, 0, 0, 0, PIP_WIDTH, PIP_HEIGHT}; + bool ret = webPattern.CreatePip(PIP_STATE_ENTER, env, init, pipController, info); + ASSERT_EQ(ret, true); + ret = webPattern.PageClosePip(info.delegateId, info.childId, info.frameRoutingId); + ASSERT_EQ(ret, false); +#endif +} + +/** + * @tc.name: OnPipPip_007 + * @tc.desc: OnPipPip. + * @tc.type: FUNC + */ +HWTEST_F(WebPatternTestNg, OnPipPip_007, TestSize.Level1) +{ +#ifdef OHOS_STANDARD_SYSTEM + WebPattern webPattern; + webPattern.delegate_ = nullptr; + EXPECT_EQ(webPattern.delegate_, nullptr); + bool init = false; + uint32_t pipController = 0; + napi_env env = nullptr; + PipInfo pipInfo{0, 0, 0, 0, PIP_WIDTH, PIP_HEIGHT}; + bool ret = webPattern.CreatePip(PIP_STATE_ENTER, env, init, pipController, pipInfo); + ASSERT_EQ(ret, true); + webPattern.OnPip(PIP_STATE_PAGE_CLOSE, 0, 0, 0, 0, 0); +#endif +} + /** * @tc.name: CreateSnapshotImageFrameNode_001 * @tc.desc: CreateSnapshotImageFrameNode. -- Gitee From dba3583db08a2273ab966d003889011a019cb85f Mon Sep 17 00:00:00 2001 From: dongbin Date: Tue, 19 Aug 2025 03:15:15 +0000 Subject: [PATCH 2/4] update frameworks/core/components_ng/pattern/web/web_pattern.cpp. Signed-off-by: dongbin --- frameworks/core/components_ng/pattern/web/web_pattern.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/frameworks/core/components_ng/pattern/web/web_pattern.cpp b/frameworks/core/components_ng/pattern/web/web_pattern.cpp index 98328a81f41..3336fb0720c 100644 --- a/frameworks/core/components_ng/pattern/web/web_pattern.cpp +++ b/frameworks/core/components_ng/pattern/web/web_pattern.cpp @@ -8709,8 +8709,7 @@ bool WebPattern::PageClosePip(int delegateId, int childId, int frameRoutingId) if (pip.delegateId == delegateId && pip.childId == childId && pip.frameRoutingId == frameRoutingId) { bool result = true; - auto errCode = OH_PictureInPicture_StopPip(it.first); - if (errCode != 0) { + if (OH_PictureInPicture_StopPip(it.first) != 0) { TAG_LOGE(AceLogTag::ACE_WEB, "OH_PictureInPicture_StopPip err: %{public}d", errCode); result = false; } -- Gitee From fa0608b998076f46bf4bab654ffa8a74142a5e03 Mon Sep 17 00:00:00 2001 From: dongbin Date: Tue, 19 Aug 2025 04:39:30 +0000 Subject: [PATCH 3/4] update frameworks/core/components_ng/pattern/web/web_pattern.cpp. Signed-off-by: dongbin --- frameworks/core/components_ng/pattern/web/web_pattern.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/frameworks/core/components_ng/pattern/web/web_pattern.cpp b/frameworks/core/components_ng/pattern/web/web_pattern.cpp index 3336fb0720c..98328a81f41 100644 --- a/frameworks/core/components_ng/pattern/web/web_pattern.cpp +++ b/frameworks/core/components_ng/pattern/web/web_pattern.cpp @@ -8709,7 +8709,8 @@ bool WebPattern::PageClosePip(int delegateId, int childId, int frameRoutingId) if (pip.delegateId == delegateId && pip.childId == childId && pip.frameRoutingId == frameRoutingId) { bool result = true; - if (OH_PictureInPicture_StopPip(it.first) != 0) { + auto errCode = OH_PictureInPicture_StopPip(it.first); + if (errCode != 0) { TAG_LOGE(AceLogTag::ACE_WEB, "OH_PictureInPicture_StopPip err: %{public}d", errCode); result = false; } -- Gitee From 814d5ca4332daf69d67d5a6e87709252dd1d0361 Mon Sep 17 00:00:00 2001 From: dongbin Date: Tue, 19 Aug 2025 07:00:44 +0000 Subject: [PATCH 4/4] update frameworks/core/components_ng/pattern/web/web_pattern.cpp. Signed-off-by: dongbin --- frameworks/core/components_ng/pattern/web/web_pattern.cpp | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/frameworks/core/components_ng/pattern/web/web_pattern.cpp b/frameworks/core/components_ng/pattern/web/web_pattern.cpp index 98328a81f41..e38e4d2f0db 100644 --- a/frameworks/core/components_ng/pattern/web/web_pattern.cpp +++ b/frameworks/core/components_ng/pattern/web/web_pattern.cpp @@ -8708,13 +8708,11 @@ bool WebPattern::PageClosePip(int delegateId, int childId, int frameRoutingId) auto pip = it.second; if (pip.delegateId == delegateId && pip.childId == childId && pip.frameRoutingId == frameRoutingId) { - bool result = true; auto errCode = OH_PictureInPicture_StopPip(it.first); if (errCode != 0) { TAG_LOGE(AceLogTag::ACE_WEB, "OH_PictureInPicture_StopPip err: %{public}d", errCode); - result = false; } - return result; + return errCode == 0; } } return false; -- Gitee