diff --git a/frameworks/core/components/web/resource/web_delegate.cpp b/frameworks/core/components/web/resource/web_delegate.cpp index 285d1870ccd60c2beffaf523ca47e926e2412930..23967c21616e620f5954619cb0fca66d54fc0804 100644 --- a/frameworks/core/components/web/resource/web_delegate.cpp +++ b/frameworks/core/components/web/resource/web_delegate.cpp @@ -6347,6 +6347,7 @@ bool WebDelegate::OnDragAndDropData(const void* data, size_t len, int width, int bool WebDelegate::OnDragAndDropDataUdmf(std::shared_ptr dragData) { + CHECK_NULL_RETURN(dragData, false); const void* data = nullptr; size_t len = 0; int width = 0; @@ -6367,7 +6368,7 @@ bool WebDelegate::OnDragAndDropDataUdmf(std::shared_ptrIsRootNeedExportTexture()) { return false; } - + allowed_op_ = dragData->GetAllowedDragOperation(); if (dragData->IsDragNewStyle() && (!webPattern->IsNewDragStyle() || !webPattern->IsPreviewImageNodeExist())) { TAG_LOGI(AceLogTag::ACE_WEB, "OnDragAndDropDataUdmf not a new style"); auto context = context_.Upgrade(); @@ -6941,10 +6942,13 @@ void WebDelegate::OnSelectPopupMenu(std::shared_ptr dragEvent = - std::make_shared(x, y, static_cast(dragAction)); + std::shared_ptr dragEvent = std::make_shared( + x, y, static_cast(dragAction), op_, allowed_op_); nweb_->SendDragEvent(dragEvent); } + if (dragAction == DragAction::DRAG_END || dragAction == DragAction::DRAG_CANCEL) { + allowed_op_ = OHOS::NWeb::NWebDragData::DragOperationsMask::DRAG_ALLOW_EVERY; + } } std::string WebDelegate::GetUrl() diff --git a/frameworks/core/components/web/resource/web_delegate.h b/frameworks/core/components/web/resource/web_delegate.h index 740e1becc099d6504b10f889dd11d48c5ca67fdf..047f3733f1a4ba8b53faa88053b3283615d85e85 100644 --- a/frameworks/core/components/web/resource/web_delegate.h +++ b/frameworks/core/components/web/resource/web_delegate.h @@ -524,7 +524,9 @@ class RenderWeb; class NWebDragEventImpl : public OHOS::NWeb::NWebDragEvent { public: - NWebDragEventImpl(double x, double y, NWeb::DragAction action) : x_(x), y_(y), action_(action) {} + NWebDragEventImpl(double x, double y, NWeb::DragAction action, NWeb::NWebDragData::DragOperation op, + NWeb::NWebDragData::DragOperationsMask allowed_op) + : x_(x), y_(y), action_(action), op_(op), allowed_op_(allowed_op) {} ~NWebDragEventImpl() = default; double GetX() override @@ -542,10 +544,27 @@ public: return action_; } + NWeb::NWebDragData::DragOperation GetDragOperation() const override + { + return op_; + } + + NWeb::NWebDragData::DragOperationsMask GetAllowedDragOperation() const override + { + return allowed_op_; + } + + bool IsDragOpValid() const override + { + return true; + } + private: double x_ = 0.0; double y_ = 0.0; NWeb::DragAction action_ = NWeb::DragAction::DRAG_START; + NWeb::NWebDragData::DragOperation op_ = NWeb::NWebDragData::DragOperation::DRAG_OPERATION_COPY; + NWeb::NWebDragData::DragOperationsMask allowed_op_ = NWeb::NWebDragData::DragOperationsMask::DRAG_ALLOW_EVERY; }; class NWebTouchPointInfoImpl : public OHOS::NWeb::NWebTouchPointInfo { @@ -1137,6 +1156,7 @@ public: return op_; } NWeb::NWebDragData::DragOperation op_ = NWeb::NWebDragData::DragOperation::DRAG_OPERATION_NONE; + NWeb::NWebDragData::DragOperationsMask allowed_op_ = NWeb::NWebDragData::DragOperationsMask::DRAG_ALLOW_EVERY; void OnWindowNew(const std::string& targetUrl, bool isAlert, bool isUserTrigger, const std::shared_ptr& handler); void OnActivateContent(); diff --git a/test/unittest/core/pattern/web/web_pattern_add_test_ng.cpp b/test/unittest/core/pattern/web/web_pattern_add_test_ng.cpp index dd7e8b8e335c1a034743a3bf7c90d1b6d28c92be..af5767750a72ad21c49e92c12ebd4f66f6a71f33 100755 --- a/test/unittest/core/pattern/web/web_pattern_add_test_ng.cpp +++ b/test/unittest/core/pattern/web/web_pattern_add_test_ng.cpp @@ -285,6 +285,11 @@ public: return ""; } void ClearImageFileNames() override {} + DragOperationsMask GetAllowedDragOperation() const override + { + return DragOperationsMask::DRAG_ALLOW_EVERY; + } + void SetAllowedDragOperation(DragOperationsMask allowed_op) override {} }; class NWebDragDataTrueDummy : public NWeb::NWebDragData { @@ -347,6 +352,11 @@ public: return "example_image.jpg"; } void ClearImageFileNames() override {} + DragOperationsMask GetAllowedDragOperation() const override + { + return DragOperationsMask::DRAG_ALLOW_EVERY; + } + void SetAllowedDragOperation(DragOperationsMask allowed_op) override {} }; class WebPatternAddTestNg : public testing::Test { diff --git a/test/unittest/core/pattern/web/web_pattern_focus_test_ng.cpp b/test/unittest/core/pattern/web/web_pattern_focus_test_ng.cpp index d489d978192e9ec95b61cac45a8b4d7308a1d08f..4f0da20ef7c00b1570a787f8fa5e444410d01981 100755 --- a/test/unittest/core/pattern/web/web_pattern_focus_test_ng.cpp +++ b/test/unittest/core/pattern/web/web_pattern_focus_test_ng.cpp @@ -121,6 +121,13 @@ public: { // Do nothing or implement actual behavior } + + DragOperationsMask GetAllowedDragOperation() const override + { + return DragOperationsMask::DRAG_ALLOW_EVERY; + } + + void SetAllowedDragOperation(DragOperationsMask allowed_op) override {} }; class CustomNWebTouchHandleState : public OHOS::NWeb::NWebTouchHandleState { diff --git a/test/unittest/core/pattern/web/web_pattern_test_handle_ng.cpp b/test/unittest/core/pattern/web/web_pattern_test_handle_ng.cpp index 2e717d3ce8341e4c57a1ec572cdc5b9d800313e1..f941c6c5e3fcbf45183a548c6ee1b4b6ae3054be 100755 --- a/test/unittest/core/pattern/web/web_pattern_test_handle_ng.cpp +++ b/test/unittest/core/pattern/web/web_pattern_test_handle_ng.cpp @@ -366,6 +366,13 @@ public: { // Do nothing or implement actual behavior } + + DragOperationsMask GetAllowedDragOperation() const override + { + return DragOperationsMask::DRAG_ALLOW_EVERY; + } + + void SetAllowedDragOperation(DragOperationsMask allowed_op) override {} }; class MockTaskExecutorTest : public Ace::TaskExecutor { 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 9072fa17dd5cc4db4b4dff85fe58f21a1b495059..3ec9e993e5d2faa39f940a3e9caacb157b94b7a0 100755 --- a/test/unittest/core/pattern/web/web_pattern_test_ng.cpp +++ b/test/unittest/core/pattern/web/web_pattern_test_ng.cpp @@ -319,6 +319,8 @@ public: MOCK_METHOD(bool, SetFileUri, (const std::string& uri), (override)); MOCK_METHOD(std::string, GetImageFileName, (), (override)); MOCK_METHOD(void, ClearImageFileNames, (), (override)); + MOCK_METHOD(DragOperationsMask, GetAllowedDragOperation, (), (const, override)); + MOCK_METHOD(void, SetAllowedDragOperation, (DragOperationsMask allowed_op), (override)); int kDefaultDragStartX = 10; int kDefaultDragStartY = 20; };