diff --git a/frameworks/native/interaction/include/drag_manager_impl.h b/frameworks/native/interaction/include/drag_manager_impl.h index 13a1421c1..01d787eca 100644 --- a/frameworks/native/interaction/include/drag_manager_impl.h +++ b/frameworks/native/interaction/include/drag_manager_impl.h @@ -50,12 +50,13 @@ public: int32_t UpdateDragStyle(DragCursorStyle style); int32_t UpdateShadowPic(const ShadowInfo &shadowInfo); int32_t GetDragTargetPid(); - int32_t GetDragState(DragState &dragState); int32_t GetUdKey(std::string &udKey); int32_t GetShadowOffset(int32_t& offsetX, int32_t& offsetY, int32_t& width, int32_t& height); int32_t GetDragData(DragData &dragData); int32_t UpdateDragItemStyle(const DragItemStyle& dragItemStyle); int32_t GetDragSummary(std::map &summarys); + int32_t GetDragState(DragState &dragState); + int32_t GetDropType(DropType& dropType); private: std::mutex mtx_; diff --git a/frameworks/native/interaction/include/interaction_manager_impl.h b/frameworks/native/interaction/include/interaction_manager_impl.h index 7b68237a8..6fda64c29 100644 --- a/frameworks/native/interaction/include/interaction_manager_impl.h +++ b/frameworks/native/interaction/include/interaction_manager_impl.h @@ -59,6 +59,7 @@ public: int32_t RemoveHotAreaListener(std::shared_ptr listener = nullptr); int32_t UpdateDragItemStyle(const DragItemStyle &dragItemStyle); int32_t GetDragSummary(std::map &summarys); + int32_t GetDropType(DropType &dropType); private: void InitMsgHandler(); diff --git a/frameworks/native/interaction/src/drag_manager_impl.cpp b/frameworks/native/interaction/src/drag_manager_impl.cpp index 5a54c3b3d..1ab80c03c 100644 --- a/frameworks/native/interaction/src/drag_manager_impl.cpp +++ b/frameworks/native/interaction/src/drag_manager_impl.cpp @@ -267,7 +267,6 @@ int32_t DragManagerImpl::GetDragState(DragState &dragState) int32_t DragManagerImpl::UpdateDragItemStyle(const DragItemStyle &dragItemStyle) { - CALL_DEBUG_ENTER; return DeviceStatusClient::GetInstance().UpdateDragItemStyle(dragItemStyle); } @@ -276,6 +275,11 @@ int32_t DragManagerImpl::GetDragSummary(std::map &summarys CALL_DEBUG_ENTER; return DeviceStatusClient::GetInstance().GetDragSummary(summarys); } + +int32_t DragManagerImpl::GetDropType(DropType& dropType) +{ + return DeviceStatusClient::GetInstance().GetDropType(dropType); +} } // namespace DeviceStatus } // namespace Msdp } // namespace OHOS \ No newline at end of file diff --git a/frameworks/native/interaction/src/interaction_manager.cpp b/frameworks/native/interaction/src/interaction_manager.cpp index ffa0ac51b..f326da65a 100644 --- a/frameworks/native/interaction/src/interaction_manager.cpp +++ b/frameworks/native/interaction/src/interaction_manager.cpp @@ -157,6 +157,11 @@ int32_t InteractionManager::GetDragSummary(std::map &summa { return INTER_MGR_IMPL.GetDragSummary(summarys); } + +int32_t InteractionManager::GetDropType(DropType &dropType) +{ + return INTER_MGR_IMPL.GetDropType(dropType); +} } // namespace DeviceStatus } // namespace Msdp } // namespace OHOS diff --git a/frameworks/native/interaction/src/interaction_manager_impl.cpp b/frameworks/native/interaction/src/interaction_manager_impl.cpp index e602b2968..bcf398806 100644 --- a/frameworks/native/interaction/src/interaction_manager_impl.cpp +++ b/frameworks/native/interaction/src/interaction_manager_impl.cpp @@ -299,6 +299,12 @@ int32_t InteractionManagerImpl::GetDragState(DragState &dragState) return dragManagerImpl_.GetDragState(dragState); } +int32_t InteractionManagerImpl::GetDropType(DropType &dropType) +{ + CALL_DEBUG_ENTER; + return dragManagerImpl_.GetDropType(dropType); +} + int32_t InteractionManagerImpl::AddHotAreaListener(std::shared_ptr listener) { CALL_DEBUG_ENTER; diff --git a/frameworks/native/interaction/test/unittest/src/interaction_drag_drawing_test.cpp b/frameworks/native/interaction/test/unittest/src/interaction_drag_drawing_test.cpp index 7b66eef21..35acac309 100644 --- a/frameworks/native/interaction/test/unittest/src/interaction_drag_drawing_test.cpp +++ b/frameworks/native/interaction/test/unittest/src/interaction_drag_drawing_test.cpp @@ -426,7 +426,7 @@ HWTEST_F(InteractionDragDrawingTest, InteractionDragDrawingTest_UpdateDragItemSt ASSERT_TRUE(dragData); int32_t ret = InteractionManager::GetInstance()->StartDrag(dragData.value(), callback); ASSERT_EQ(ret, RET_OK); - DragItemStyle dragItemStyle { 0x99FF0000, 41, 51}; + DragItemStyle dragItemStyle { 0x99FF0000, 41, 51 }; ret = InteractionManager::GetInstance()->UpdateDragItemStyle(dragItemStyle); ASSERT_EQ(ret, RET_OK); ret = InteractionManager::GetInstance()->SetDragWindowVisible(DRAG_WINDOW_VISIBLE); diff --git a/frameworks/native/src/devicestatus_client.cpp b/frameworks/native/src/devicestatus_client.cpp index afc2d847e..5591ad5d2 100644 --- a/frameworks/native/src/devicestatus_client.cpp +++ b/frameworks/native/src/devicestatus_client.cpp @@ -437,6 +437,13 @@ int32_t DeviceStatusClient::GetDragState(DragState &dragState) return devicestatusProxy_->GetDragState(dragState); } +int32_t DeviceStatusClient::GetDropType(DropType& dropType) +{ + CALL_DEBUG_ENTER; + DEV_RET_IF_NULL_WITH_RET((Connect() != RET_OK), RET_ERR); + return devicestatusProxy_->GetDropType(dropType); +} + int32_t DeviceStatusClient::AddHotAreaListener() { CALL_DEBUG_ENTER; @@ -453,7 +460,6 @@ int32_t DeviceStatusClient::RemoveHotAreaListener() int32_t DeviceStatusClient::UpdateDragItemStyle(const DragItemStyle &dragItemStyle) { - CALL_DEBUG_ENTER; DEV_RET_IF_NULL_WITH_RET((Connect() != RET_OK), RET_ERR); return devicestatusProxy_->UpdateDragItemStyle(dragItemStyle); } diff --git a/interfaces/innerkits/include/devicestatus_client.h b/interfaces/innerkits/include/devicestatus_client.h index 9c39fa9c8..67f54c51e 100644 --- a/interfaces/innerkits/include/devicestatus_client.h +++ b/interfaces/innerkits/include/devicestatus_client.h @@ -67,6 +67,7 @@ public: int32_t UpdateShadowPic(const ShadowInfo &shadowInfo); int32_t GetDragData(DragData &dragData); int32_t GetDragState(DragState &dragState); + int32_t GetDropType(DropType& dropType); int32_t AllocSocketPair(int32_t moduleType); int32_t GetClientSocketFdOfAllocedSocketPair() const; int32_t AddHotAreaListener(); diff --git a/interfaces/innerkits/interaction/include/drag_data.h b/interfaces/innerkits/interaction/include/drag_data.h index 133d64b1e..bdde06f3f 100644 --- a/interfaces/innerkits/interaction/include/drag_data.h +++ b/interfaces/innerkits/interaction/include/drag_data.h @@ -28,6 +28,7 @@ namespace DeviceStatus { constexpr size_t MAX_BUFFER_SIZE { 512 }; constexpr size_t MAX_UDKEY_SIZE { 100 }; constexpr size_t MAX_SUMMARY_SIZE { 200 }; +constexpr size_t MAX_SHADOW_INFO_MEMO_SIZE { 10000000 }; // shadowInfo 的最大内存占用 struct ShadowInfo { std::shared_ptr pixelMap { nullptr }; int32_t x { -1 }; @@ -90,6 +91,14 @@ struct DragItemStyle { uint32_t foregroundColor; int32_t radius; int32_t alpha; + bool operator==(const DragItemStyle &style) const { + return foregroundColor == style.foregroundColor && + radius == style.radius && + alpha == style.alpha; + } + bool operator!=(const DragItemStyle &style) const { + return !(*this == style); + } }; enum class DragCursorStyle { @@ -98,6 +107,12 @@ enum class DragCursorStyle { COPY, MOVE }; + +enum class DropType { + INVALID = -1, + MOVE = 0, + COPY = 1 +}; } // namespace DeviceStatus } // namespace Msdp } // namespace OHOS diff --git a/interfaces/innerkits/interaction/include/interaction_manager.h b/interfaces/innerkits/interaction/include/interaction_manager.h index 6ed076c24..b3deb46fe 100644 --- a/interfaces/innerkits/interaction/include/interaction_manager.h +++ b/interfaces/innerkits/interaction/include/interaction_manager.h @@ -215,6 +215,14 @@ public: */ int32_t GetDragData(DragData &dragData); + /** + * @brief Obtains the current droping type. + * @param dropType dropping type while user pressed ctrl or not. + * @return Returns 0 if the operation is successful; returns other values if the operation fails. + * @since 10 + */ + int32_t GetDropType(DropType &dropType); + /** * @brief Registers a listener for screen hot area of the mouse pointer. * @param listener Indicates the listener for screen hot area of the mouse pointer. @@ -243,7 +251,7 @@ public: * @brief Update item style when dragging. * @param dragItemStyle Indicates the style param for dragged item. * @return Returns 0 if the operation is successful; returns a non-zero value otherwise. - * @since 10 + * @since 11 */ int32_t UpdateDragItemStyle(const DragItemStyle &dragItemStyle); diff --git a/interfaces/innerkits/libdevicestatus_client_map b/interfaces/innerkits/libdevicestatus_client_map index 3ee1c576d..da491b8cb 100644 --- a/interfaces/innerkits/libdevicestatus_client_map +++ b/interfaces/innerkits/libdevicestatus_client_map @@ -55,6 +55,7 @@ "OHOS::Msdp::DeviceStatus::InteractionManager::UpdateDragItemStyle(OHOS::Msdp::DeviceStatus::DragItemStyle const&)"; "OHOS::Msdp::DeviceStatus::InteractionManager::GetDragSummary(std::__h::map, std::__h::allocator>, long long, std::__h::less, std::__h::allocator>>, std::__h::allocator, std::__h::allocator> const, long long>>>&)"; "OHOS::Msdp::DeviceStatus::InteractionManager::GetDragSummary(std::__h::map, std::__h::allocator>, long, std::__h::less, std::__h::allocator>>, std::__h::allocator, std::__h::allocator> const, long>>>&)"; + "OHOS::Msdp::DeviceStatus::InteractionManager::GetDropType(OHOS::Msdp::DeviceStatus::DropType&)"; }; local: *; diff --git a/services/communication/base/i_devicestatus.h b/services/communication/base/i_devicestatus.h index 0eae360e6..45b57996c 100644 --- a/services/communication/base/i_devicestatus.h +++ b/services/communication/base/i_devicestatus.h @@ -62,6 +62,7 @@ public: virtual int32_t GetDragData(DragData &dragData) = 0; virtual int32_t GetDragState(DragState &dragState) = 0; virtual int32_t GetDragSummary(std::map &summarys) = 0; + virtual int32_t GetDropType(DropType &dropType) = 0; virtual bool IsRunning() const { return true; diff --git a/services/communication/base/msdp_ipc_interface_code.h b/services/communication/base/msdp_ipc_interface_code.h index 909fc3021..e86441d30 100644 --- a/services/communication/base/msdp_ipc_interface_code.h +++ b/services/communication/base/msdp_ipc_interface_code.h @@ -45,10 +45,11 @@ enum class DeviceInterfaceCode { UNREGISTER_SUBSCRIPT_MONITOR, GET_DRAG_STATE, GET_DRAG_SUMMARY, - ALLOC_SOCKET_FD = 40, - ADD_HOT_AREA_MONITOR = 50, + GET_DROP_TYPE, + UPDATE_DRAG_ITEM_STYLE, + ALLOC_SOCKET_FD = 60, + ADD_HOT_AREA_MONITOR = 70, REMOVE_HOT_AREA_MONITOR, - UPDATE_DRAG_ITEM_STYLE }; } // namespace Msdp } // namespace OHOS diff --git a/services/communication/client/include/devicestatus_srv_proxy.h b/services/communication/client/include/devicestatus_srv_proxy.h index 8bac3a907..55e59cd4d 100644 --- a/services/communication/client/include/devicestatus_srv_proxy.h +++ b/services/communication/client/include/devicestatus_srv_proxy.h @@ -65,6 +65,7 @@ public: virtual int32_t RemoveHotAreaListener() override; virtual int32_t UpdateDragItemStyle(const DragItemStyle &dragItemStyle) override; virtual int32_t GetDragSummary(std::map &summarys) override; + virtual int32_t GetDropType(DropType& dropType) override; private: static inline BrokerDelegator delegator_; diff --git a/services/communication/client/src/devicestatus_srv_proxy.cpp b/services/communication/client/src/devicestatus_srv_proxy.cpp index 158ebb0ba..79d3aa7ee 100644 --- a/services/communication/client/src/devicestatus_srv_proxy.cpp +++ b/services/communication/client/src/devicestatus_srv_proxy.cpp @@ -759,6 +759,29 @@ int32_t DeviceStatusSrvProxy::GetDragSummary(std::map &sum } return ret; } + +int32_t DeviceStatusSrvProxy::GetDropType(DropType& dropType) +{ + CALL_DEBUG_ENTER; + MessageParcel data; + if (!data.WriteInterfaceToken(DeviceStatusSrvProxy::GetDescriptor())) { + FI_HILOGE("Failed to write descriptor"); + return ERR_INVALID_VALUE; + } + MessageParcel reply; + MessageOption option; + sptr remote = Remote(); + CHKPR(remote, RET_ERR); + int32_t ret = remote->SendRequest(static_cast(DeviceInterfaceCode::GET_DROP_TYPE), + data, reply, option); + if (ret != RET_OK) { + FI_HILOGE("Send request failed, ret:%{public}d", ret); + } + int32_t type; + READINT32(reply, type, IPC_PROXY_DEAD_OBJECT_ERR); + dropType = static_cast(type); + return ret; +} } // namespace DeviceStatus } // namespace Msdp } // namespace OHOS diff --git a/services/communication/service/include/devicestatus_srv_stub.h b/services/communication/service/include/devicestatus_srv_stub.h index b7f4cf69e..dd0386557 100644 --- a/services/communication/service/include/devicestatus_srv_stub.h +++ b/services/communication/service/include/devicestatus_srv_stub.h @@ -64,6 +64,7 @@ private: int32_t UpdateShadowPicStub(MessageParcel& data, MessageParcel& reply); int32_t GetDragDataStub(MessageParcel& data, MessageParcel& reply); int32_t GetDragStateStub(MessageParcel &data, MessageParcel &reply); + int32_t GetDropTypeStub(MessageParcel &data, MessageParcel &reply); int32_t AddHotAreaListenerStub(MessageParcel& data, MessageParcel& reply); int32_t RemoveHotAreaListenerStub(MessageParcel& data, MessageParcel& reply); int32_t UpdateDragItemStyleStub(MessageParcel& data, MessageParcel& reply); diff --git a/services/communication/service/src/devicestatus_srv_stub.cpp b/services/communication/service/src/devicestatus_srv_stub.cpp index b3307e592..ce76ce7e5 100644 --- a/services/communication/service/src/devicestatus_srv_stub.cpp +++ b/services/communication/service/src/devicestatus_srv_stub.cpp @@ -113,7 +113,9 @@ void DeviceStatusSrvStub::InitDrag() { static_cast(DeviceInterfaceCode::GET_DRAG_STATE), &DeviceStatusSrvStub::GetDragStateStub }, { static_cast(DeviceInterfaceCode::GET_DRAG_SUMMARY), - &DeviceStatusSrvStub::GetDragSummaryStub } + &DeviceStatusSrvStub::GetDragSummaryStub }, + {static_cast(DeviceInterfaceCode::GET_DROP_TYPE), + &DeviceStatusSrvStub::GetDropTypeStub } }; connFuncs_.insert(dragFuncs_.begin(), dragFuncs_.end()); } @@ -631,6 +633,18 @@ int32_t DeviceStatusSrvStub::GetDragSummaryStub(MessageParcel& data, MessageParc } return RET_OK; } + +int32_t DeviceStatusSrvStub::GetDropTypeStub(MessageParcel &data, MessageParcel &reply) +{ + CALL_DEBUG_ENTER; + DropType dropType; + int32_t ret = GetDropType(dropType); + if (ret != RET_OK) { + return RET_ERR; + } + WRITEINT32(reply, static_cast(dropType), IPC_STUB_WRITE_PARCEL_ERR); + return RET_OK; +} } // namespace DeviceStatus } // namespace Msdp } // namespace OHOS \ No newline at end of file diff --git a/services/interaction/drag/include/drag_data_manager.h b/services/interaction/drag/include/drag_data_manager.h index ffcbb7db1..9e8cda64f 100644 --- a/services/interaction/drag/include/drag_data_manager.h +++ b/services/interaction/drag/include/drag_data_manager.h @@ -48,6 +48,8 @@ public: int32_t GetTargetPid() const; void SetMotionDrag(bool isMotionDrag); bool IsMotionDrag() const; + void SetDragItemStyle(const DragItemStyle &dragItemStyle); + DragItemStyle GetDragItemStyle(); private: DragData dragData_; DragCursorStyle dragStyle_ { DragCursorStyle::DEFAULT }; @@ -56,6 +58,7 @@ private: int32_t targetTid_ { -1 }; int32_t targetPid_ { -1 }; bool isMotionDrag_ { false }; + DragItemStyle dragItemStyle_; }; #define DRAG_DATA_MGR OHOS::Singleton::GetInstance() diff --git a/services/interaction/drag/include/drag_manager.h b/services/interaction/drag/include/drag_manager.h index 50b843de0..bdedb8fdb 100644 --- a/services/interaction/drag/include/drag_manager.h +++ b/services/interaction/drag/include/drag_manager.h @@ -16,6 +16,7 @@ #ifndef DRAG_MANAGER_H #define DRAG_MANAGER_H +#include #include #include "extra_data.h" @@ -70,34 +71,43 @@ public: void SetDragState(DragState state) override; int32_t UpdateDragItemStyle(const DragItemStyle &dragItemStyle) override; int32_t GetDragSummary(std::map &summarys); + void DragKeyEventCallback(std::shared_ptr keyEvent); + int32_t GetDropType(DropType& dropType) const; #ifdef OHOS_DRAG_ENABLE_INTERCEPTOR class InterceptorConsumer : public MMI::IInputEventConsumer { public: InterceptorConsumer(IContext *context, - std::function)> cb) : context_(context), callback_(cb) {} + std::function)> cb) + : context_(context), + pointerEventCallback_(cb) {} void OnInputEvent(std::shared_ptr keyEvent) const override; void OnInputEvent(std::shared_ptr pointerEvent) const override; void OnInputEvent(std::shared_ptr axisEvent) const override; private: IContext* context_ { nullptr }; - std::function)> callback_ { nullptr }; + std::function)> pointerEventCallback_ { nullptr }; }; #endif // OHOS_DRAG_ENABLE_INTERCEPTOR #ifdef OHOS_DRAG_ENABLE_MONITOR class MonitorConsumer : public MMI::IInputEventConsumer { public: - explicit MonitorConsumer(std::function)> cb) : callback_(cb) {} + explicit MonitorConsumer( + std::function)> cb) : pointerEventCallback_(cb) {} void OnInputEvent(std::shared_ptr keyEvent) const override; void OnInputEvent(std::shared_ptr pointerEvent) const override; void OnInputEvent(std::shared_ptr axisEvent) const override; private: - std::function)> callback_; + std::function)> pointerEventCallback_; }; #endif //OHOS_DRAG_ENABLE_MONITOR private: void PrintDragData(const DragData &dragData); int32_t AddDragEventHandler(int32_t sourceType); + int32_t AddPointerEventHandler(uint32_t deviceTags); + int32_t AddKeyEventMointor(); + int32_t RemoveKeyEventMointor(); + int32_t RemovePointerEventHandler(); int32_t NotifyDragResult(DragResult result); int32_t InitDataManager(const DragData &dragData) const; int32_t OnStartDrag(); @@ -113,11 +123,13 @@ private: StateChangeNotify stateNotify_; DragState dragState_ { DragState::STOP }; DragResult dragResult_ { DragResult::DRAG_FAIL }; + int32_t keyEventMonitorId_ { -1 }; + std::atomic dropType_ { DropType::MOVE }; #ifdef OHOS_DRAG_ENABLE_INTERCEPTOR - int32_t interceptorId_ { -1 }; + int32_t pointerEventInterceptorId_ { -1 }; #endif // OHOS_DRAG_ENABLE_INTERCEPTOR #ifdef OHOS_DRAG_ENABLE_MONITOR - int32_t monitorId_ { -1 }; + int32_t pointerEventMonitorId_ { -1 }; #endif //OHOS_DRAG_ENABLE_MONITOR SessionPtr dragOutSession_ { nullptr }; DragDrawing dragDrawing_; diff --git a/services/interaction/drag/src/drag_data_manager.cpp b/services/interaction/drag/src/drag_data_manager.cpp index d2355f38a..269e2092a 100644 --- a/services/interaction/drag/src/drag_data_manager.cpp +++ b/services/interaction/drag/src/drag_data_manager.cpp @@ -126,6 +126,16 @@ bool DragDataManager::IsMotionDrag() const FI_HILOGD("isMotionDrag_:%{public}d", isMotionDrag_); return isMotionDrag_; } + +void DragDataManager::SetDragItemStyle(const DragItemStyle &dragItemStyle) +{ + dragItemStyle_ = dragItemStyle; +} + +DragItemStyle DragDataManager::GetDragItemStyle() +{ + return dragItemStyle_; +} } // namespace DeviceStatus } // namespace Msdp } // namespace OHOS \ No newline at end of file diff --git a/services/interaction/drag/src/drag_drawing.cpp b/services/interaction/drag/src/drag_drawing.cpp index 8bd3a4404..7f4546730 100644 --- a/services/interaction/drag/src/drag_drawing.cpp +++ b/services/interaction/drag/src/drag_drawing.cpp @@ -92,7 +92,6 @@ constexpr int32_t DEFAULT_COLOR_VALUE { 0 }; constexpr int32_t INVALID_COLOR_VALUE { -1 }; constexpr int32_t GLOBAL_WINDOW_ID { -1 }; constexpr int32_t MOUSE_DRAG_CURSOR_CIRCLE_STYLE { 41 }; -constexpr int32_t ICON_CORNER_RADIUS { 41 }; constexpr int32_t CURSOR_CIRCLE_MIDDLE { 2 }; constexpr int32_t TRANSPARENT_COLOR { 0x00000000 }; const Rosen::RSAnimationTimingCurve SHARP_CURVE = Rosen::RSAnimationTimingCurve::CreateCubicCurve(0.33, 0, 0.67, 1); @@ -257,11 +256,6 @@ void DragDrawing::Draw(int32_t displayId, int32_t displayX, int32_t displayY) if (displayY < 0) { g_drawingInfo.displayY = 0; } - // if (displayY >= 500 && displayY <= 510) { - // FI_HILOGI("Here in GradientForegroundColor"); - // UpdateDragItemStyle(DragItemStyle());//Just use to test animation interface usage - // FI_HILOGI("Here out GradientForegroundColor"); - // } int32_t adjustSize = TWELVE_SIZE * GetScaling(); int32_t positionY = g_drawingInfo.displayY + g_drawingInfo.pixelMapY - adjustSize; int32_t positionX = g_drawingInfo.displayX + g_drawingInfo.pixelMapX; diff --git a/services/interaction/drag/src/drag_manager.cpp b/services/interaction/drag/src/drag_manager.cpp index 8661ecf81..92cc58f83 100644 --- a/services/interaction/drag/src/drag_manager.cpp +++ b/services/interaction/drag/src/drag_manager.cpp @@ -15,6 +15,8 @@ #include "drag_manager.h" +#include + #include "extra_data.h" #include "hitrace_meter.h" #include "pixel_map.h" @@ -33,6 +35,7 @@ namespace DeviceStatus { namespace { constexpr OHOS::HiviewDFX::HiLogLabel LABEL { LOG_CORE, MSDP_DOMAIN_ID, "DragManager" }; constexpr int32_t TIMEOUT_MS { 2000 }; +constexpr size_t SIGNLE_KEY_ITEM { 1 }; #ifdef OHOS_DRAG_ENABLE_INTERCEPTOR constexpr int32_t DRAG_PRIORITY { 500 }; std::atomic g_startFilterTime { -1 }; @@ -360,9 +363,9 @@ void DragManager::InterceptorConsumer::OnInputEvent(std::shared_ptrAddFlag(MMI::InputEvent::EVENT_FLAG_NO_INTERCEPT); auto fun = [] (std::shared_ptr pointerEvent) -> int32_t { MMI::InputManager::GetInstance()->SimulateInputEvent(pointerEvent); @@ -394,8 +397,8 @@ void DragManager::MonitorConsumer::OnInputEvent(std::shared_ptrGetPointerAction() == MMI::PointerEvent::POINTER_ACTION_PULL_UP) { FI_HILOGI("Pointer button is released, appened extra data"); MMI::InputManager::GetInstance()->AppendExtraData(DragManager::CreateExtraData(false)); @@ -418,14 +421,14 @@ void DragManager::Dump(int32_t fd) const dprintf(fd, "dragState:%s | dragResult:%s | interceptorId:%d | dragTargetPid:%d | dragTargetTid:%d | " "cursorStyle:%s | isWindowVisble:%s\n", GetDragState(dragState_).c_str(), - GetDragResult(dragResult_).c_str(), interceptorId_, GetDragTargetPid(), targetTid, + GetDragResult(dragResult_).c_str(), pointerEventInterceptorId_, GetDragTargetPid(), targetTid, GetDragCursorStyle(style).c_str(), DRAG_DATA_MGR.GetDragWindowVisible() ? "true" : "false"); #endif // OHOS_DRAG_ENABLE_INTERCEPTOR #ifdef OHOS_DRAG_ENABLE_MONITOR dprintf(fd, "dragState:%s | dragResult:%s | monitorId:%d | dragTargetPid:%d | dragTargetTid:%d | " "cursorStyle:%s | isWindowVisble:%s\n", GetDragState(dragState_).c_str(), - GetDragResult(dragResult_).c_str(), monitorId_, GetDragTargetPid(), targetTid, + GetDragResult(dragResult_).c_str(), pointerEventMonitorId_, GetDragTargetPid(), targetTid, GetDragCursorStyle(style).c_str(), DRAG_DATA_MGR.GetDragWindowVisible() ? "true" : "false"); #endif // OHOS_DRAG_ENABLE_MONITOR DragData dragData = DRAG_DATA_MGR.GetDragData(); @@ -531,25 +534,90 @@ int32_t DragManager::AddDragEventHandler(int32_t sourceType) return RET_ERR; } #endif // OHOS_DRAG_ENABLE_INTERCEPTOR + if (AddPointerEventHandler(deviceTags) != RET_OK) { + FI_HILOGE("Failed to add pointer event handler"); + return RET_ERR; + } + if (AddKeyEventMointor() != RET_OK) { + FI_HILOGE("Failed to add key event handler"); + return RET_ERR; + } + return RET_OK; +} + +int32_t DragManager::AddPointerEventHandler(uint32_t deviceTags) +{ + CALL_INFO_TRACE; #ifdef OHOS_DRAG_ENABLE_MONITOR auto monitor = std::make_shared(std::bind(&DragManager::DragCallback, this, std::placeholders::_1)); - FI_HILOGI("Add drag event monitor"); - monitorId_ = MMI::InputManager::GetInstance()->AddMonitor(monitor); - if (monitorId_ <= 0) { - FI_HILOGE("Failed to add monitor, error code:%{public}d", monitorId_); + pointerEventMonitorId_ = MMI::InputManager::GetInstance()->AddMonitor(monitor); + if (pointerEventMonitorId_ <= 0) { + FI_HILOGE("Failed to add pointer event monitor"); return RET_ERR; } #else auto callback = std::bind(&DragManager::DragCallback, this, std::placeholders::_1); auto interceptor = std::make_shared(context_, callback); - FI_HILOGI("Add drag event interceptor"); - interceptorId_ = MMI::InputManager::GetInstance()->AddInterceptor(interceptor, DRAG_PRIORITY, deviceTags); - if (interceptorId_ <= 0) { - FI_HILOGE("Failed to add interceptor, error code:%{public}d", interceptorId_); + pointerEventInterceptorId_ = MMI::InputManager::GetInstance()->AddInterceptor( + interceptor, DRAG_PRIORITY, deviceTags); + if (pointerEventInterceptorId_ <= 0) { + FI_HILOGE("Failed to add pointer event interceptor"); return RET_ERR; } #endif // OHOS_DRAG_ENABLE_MONITOR + FI_HILOGI("Add drag poniter event handle successfully"); + return RET_OK; +} + +int32_t DragManager::AddKeyEventMointor() +{ + CALL_INFO_TRACE; + keyEventMonitorId_ = MMI::InputManager::GetInstance()->AddMonitor( + std::bind(&DragManager::DragKeyEventCallback, this, std::placeholders::_1)); + if (keyEventMonitorId_ <= 0) { + FI_HILOGE("Failed to add key event monitor"); + return RET_ERR; + } + FI_HILOGI("Add drag key event monitor successfully"); + return RET_OK; +} + +int32_t DragManager::RemovePointerEventHandler() +{ + CALL_INFO_TRACE; +#ifdef OHOS_DRAG_ENABLE_MONITOR + if (pointerEventMonitorId_ <= 0) { + FI_HILOGE("Invalid pointer event monitor id:%{public}d", pointerEventMonitorId_); + return RET_ERR; + } + MMI::InputManager::GetInstance()->RemoveMonitor(pointerEventMonitorId_); + pointerEventMonitorId_ = -1; + if (RemoveKeyEventMointor() != RET_OK) { + FI_HILOGE("Failed to remove key event monitor"); + return RET_ERR; + } +#else + if (pointerEventInterceptorId_ <= 0) { + FI_HILOGE("Invalid pointer event interceptor id:%{public}d", pointerEventInterceptorId_); + } + MMI::InputManager::GetInstance()->RemoveInterceptor(pointerEventInterceptorId_); + pointerEventInterceptorId_ = -1; +#endif // OHOS_DRAG_ENABLE_MONITOR + FI_HILOGI("Remove drag pointer event handler successfully"); + return RET_OK; +} + +int32_t DragManager::RemoveKeyEventMointor() +{ + CALL_INFO_TRACE; + if (keyEventMonitorId_ <= 0) { + FI_HILOGE("Invalid key event monitor id:%{public}d", keyEventMonitorId_); + return RET_ERR; + } + MMI::InputManager::GetInstance()->RemoveMonitor(keyEventMonitorId_); + keyEventMonitorId_ = -1; + FI_HILOGI("Remove drag key event handle successfully"); return RET_OK; } @@ -573,11 +641,7 @@ int32_t DragManager::OnStartDrag() MMI::InputManager::GetInstance()->AppendExtraData(extraData); ret = AddDragEventHandler(dragData.sourceType); if (ret != RET_OK) { -#ifdef OHOS_DRAG_ENABLE_MONITOR - FI_HILOGE("Failed to add drag event monitor"); -#else - FI_HILOGE("Failed to add drag event interceptor"); -#endif // OHOS_DRAG_ENABLE_MONITOR + FI_HILOGE("Failed to add drag event handler"); dragDrawing_.DestroyDragWindow(); return RET_ERR; } @@ -592,23 +656,14 @@ int32_t DragManager::OnStopDrag(DragResult result, bool hasCustomAnimation) { CALL_INFO_TRACE; FI_HILOGI("Add custom animation:%{public}s", hasCustomAnimation ? "true" : "false"); -#ifdef OHOS_DRAG_ENABLE_MONITOR - if (monitorId_ <= 0) { - FI_HILOGE("Invalid monitor to be removed, monitorId_:%{public}d", monitorId_); + if (RemovePointerEventHandler() != RET_OK) { + FI_HILOGE("Failed to remove pointer event handler"); return RET_ERR; } - FI_HILOGI("Remove drag event monitor"); - MMI::InputManager::GetInstance()->RemoveMonitor(monitorId_); - monitorId_ = -1; -#else - if (interceptorId_ <= 0) { - FI_HILOGE("Invalid interceptorId_:%{public}d", interceptorId_); + if (RemoveKeyEventMointor() != RET_OK) { + FI_HILOGE("Failed to remove key event handler"); return RET_ERR; } - FI_HILOGI("Remove drag event interceptor"); - MMI::InputManager::GetInstance()->RemoveInterceptor(interceptorId_); - interceptorId_ = -1; -#endif // OHOS_DRAG_ENABLE_MONITOR DragData dragData = DRAG_DATA_MGR.GetDragData(); if ((dragData.sourceType == MMI::PointerEvent::SOURCE_TYPE_MOUSE) && !DRAG_DATA_MGR.IsMotionDrag()) { dragDrawing_.EraseMouseIcon(); @@ -763,7 +818,43 @@ int32_t DragManager::UpdateDragItemStyle(const DragItemStyle &dragItemStyle) FI_HILOGE("Drag instance not running"); return RET_ERR; } - dragDrawing_.UpdateDragItemStyle(dragItemStyle); + if (dragItemStyle == DRAG_DATA_MGR.GetDragItemStyle()) { + FI_HILOGD("Not need update drag item style"); + return RET_OK; + } + FI_HILOGI("Update drag item style successfully"); + DRAG_DATA_MGR.SetDragItemStyle(dragItemStyle); + return dragDrawing_.UpdateDragItemStyle(dragItemStyle); +} + +void DragManager::DragKeyEventCallback(std::shared_ptr keyEvent) +{ + CHKPV(keyEvent); + auto keys = keyEvent->GetKeyItems(); + int32_t keyCode = keyEvent->GetKeyCode(); + int32_t keyAction = keyEvent->GetKeyAction(); + if (keys.size() != SIGNLE_KEY_ITEM) { + dropType_.store(DropType::MOVE); + return; + } + if (keyAction == MMI::KeyEvent::KEY_ACTION_DOWN && ( + keyCode == MMI::KeyEvent::KEYCODE_CTRL_LEFT || + keyCode == MMI::KeyEvent::KEYCODE_CTRL_RIGHT)) { + dropType_.store(DropType::COPY); + FI_HILOGI("the current drop type is copy"); + } else { + dropType_.store(DropType::MOVE); + } +} + +int32_t DragManager::GetDropType(DropType& dropType) const +{ + CALL_DEBUG_ENTER; + if (dragState_ != DragState::START) { + FI_HILOGE("No drag instance running, can not get drag drop type"); + return RET_ERR; + } + dropType = dropType_.load(); return RET_OK; } } // namespace DeviceStatus diff --git a/services/native/include/devicestatus_service.h b/services/native/include/devicestatus_service.h index 1d1c162cc..91cd81ef9 100644 --- a/services/native/include/devicestatus_service.h +++ b/services/native/include/devicestatus_service.h @@ -85,6 +85,7 @@ public: int32_t UpdateShadowPic(const ShadowInfo &shadowInfo) override; int32_t GetDragData(DragData &dragData) override; int32_t GetDragState(DragState &dragState) override; + int32_t GetDropType(DropType& dropType) override; int32_t AllocSocketFd(const std::string &programName, int32_t moduleType, int32_t &toReturnClientFd, int32_t &tokenType) override; void OnConnected(SessionPtr s) override; diff --git a/services/native/src/devicestatus_service.cpp b/services/native/src/devicestatus_service.cpp index 2f1eb90d7..75efd818f 100644 --- a/services/native/src/devicestatus_service.cpp +++ b/services/native/src/devicestatus_service.cpp @@ -827,6 +827,16 @@ int32_t DeviceStatusService::GetDragTargetPid() return ret; } +int32_t DeviceStatusService::GetDropType(DropType& dropType) +{ + int32_t ret = delegateTasks_.PostSyncTask( + std::bind(&DragManager::GetDropType, &dragMgr_, std::ref(dropType))); + if (ret != RET_OK) { + FI_HILOGE("Get drop type failed, ret:%{public}d", ret); + } + return ret; +} + #ifdef OHOS_BUILD_ENABLE_COORDINATION int32_t DeviceStatusService::OnRegisterCoordinationListener(int32_t pid) { diff --git a/utils/common/include/drag_item_style_packer.h b/utils/common/include/drag_item_style_packer.h index 876b49bcc..3100ad8e0 100644 --- a/utils/common/include/drag_item_style_packer.h +++ b/utils/common/include/drag_item_style_packer.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022-2023 Huawei Device Co., Ltd. + * Copyright (c) 2023 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