1f857971dSopenharmony_ci/* 2f857971dSopenharmony_ci * Copyright (c) 2023-2024 Huawei Device Co., Ltd. 3f857971dSopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License"); 4f857971dSopenharmony_ci * you may not use this file except in compliance with the License. 5f857971dSopenharmony_ci * You may obtain a copy of the License at 6f857971dSopenharmony_ci * 7f857971dSopenharmony_ci * http://www.apache.org/licenses/LICENSE-2.0 8f857971dSopenharmony_ci * 9f857971dSopenharmony_ci * Unless required by applicable law or agreed to in writing, software 10f857971dSopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS, 11f857971dSopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12f857971dSopenharmony_ci * See the License for the specific language governing permissions and 13f857971dSopenharmony_ci * limitations under the License. 14f857971dSopenharmony_ci */ 15f857971dSopenharmony_ci 16f857971dSopenharmony_ci#ifndef DRAG_MANAGER_H 17f857971dSopenharmony_ci#define DRAG_MANAGER_H 18f857971dSopenharmony_ci 19f857971dSopenharmony_ci#include <atomic> 20f857971dSopenharmony_ci#include <string> 21f857971dSopenharmony_ci 22f857971dSopenharmony_ci#ifndef OHOS_BUILD_ENABLE_ARKUI_X 23f857971dSopenharmony_ci#include "extra_data.h" 24f857971dSopenharmony_ci#include "i_input_event_consumer.h" 25f857971dSopenharmony_ci#include "input_manager.h" 26f857971dSopenharmony_ci#endif // OHOS_BUILD_ENABLE_ARKUI_X 27f857971dSopenharmony_ci#include "pixel_map.h" 28f857971dSopenharmony_ci 29f857971dSopenharmony_ci#ifndef OHOS_BUILD_ENABLE_ARKUI_X 30f857971dSopenharmony_ci#include "collaboration_service_status_change.h" 31f857971dSopenharmony_ci#include "display_change_event_listener.h" 32f857971dSopenharmony_ci#endif // OHOS_BUILD_ENABLE_ARKUI_X 33f857971dSopenharmony_ci#include "devicestatus_define.h" 34f857971dSopenharmony_ci#include "drag_data.h" 35f857971dSopenharmony_ci#include "drag_drawing.h" 36f857971dSopenharmony_ci#include "id_factory.h" 37f857971dSopenharmony_ci#ifndef OHOS_BUILD_ENABLE_ARKUI_X 38f857971dSopenharmony_ci#include "event_hub.h" 39f857971dSopenharmony_ci#include "i_context.h" 40f857971dSopenharmony_ci#include "state_change_notify.h" 41f857971dSopenharmony_ci#else 42f857971dSopenharmony_ci#include "i_drag_manager.h" 43f857971dSopenharmony_ci#endif // OHOS_BUILD_ENABLE_ARKUI_X 44f857971dSopenharmony_ci 45f857971dSopenharmony_cinamespace OHOS { 46f857971dSopenharmony_cinamespace Msdp { 47f857971dSopenharmony_cinamespace DeviceStatus { 48f857971dSopenharmony_ciclass DragManager : public IDragManager, 49f857971dSopenharmony_ci public IdFactory<int32_t> { 50f857971dSopenharmony_cipublic: 51f857971dSopenharmony_ci#ifdef OHOS_BUILD_ENABLE_ARKUI_X 52f857971dSopenharmony_ci static DragManager &GetInstance(); 53f857971dSopenharmony_ci#endif // OHOS_BUILD_ENABLE_ARKUI_X 54f857971dSopenharmony_ci DragManager() = default; 55f857971dSopenharmony_ci DISALLOW_COPY_AND_MOVE(DragManager); 56f857971dSopenharmony_ci ~DragManager(); 57f857971dSopenharmony_ci 58f857971dSopenharmony_ci#ifndef OHOS_BUILD_ENABLE_ARKUI_X 59f857971dSopenharmony_ci int32_t Init(IContext* context); 60f857971dSopenharmony_ci void OnSessionLost(SocketSessionPtr session); 61f857971dSopenharmony_ci int32_t AddListener(int32_t pid) override; 62f857971dSopenharmony_ci int32_t RemoveListener(int32_t pid) override; 63f857971dSopenharmony_ci int32_t AddSubscriptListener(int32_t pid) override; 64f857971dSopenharmony_ci int32_t RemoveSubscriptListener(int32_t pid) override; 65f857971dSopenharmony_ci int32_t StartDrag(const DragData &dragData, int32_t pid, const std::string &peerNetId = "") override; 66f857971dSopenharmony_ci#else 67f857971dSopenharmony_ci int32_t StartDrag(const DragData &dragData) override; 68f857971dSopenharmony_ci int32_t UpdatePointerAction(std::shared_ptr<MMI::PointerEvent> pointerEvent); 69f857971dSopenharmony_ci#endif // OHOS_BUILD_ENABLE_ARKUI_X 70f857971dSopenharmony_ci int32_t StopDrag(const DragDropResult &dropResult, const std::string &packageName = "", int32_t pid = -1) override; 71f857971dSopenharmony_ci int32_t GetDragTargetPid() const override; 72f857971dSopenharmony_ci int32_t GetUdKey(std::string &udKey) const override; 73f857971dSopenharmony_ci void SendDragData(int32_t targetTid, const std::string &udKey); 74f857971dSopenharmony_ci#ifndef OHOS_BUILD_ENABLE_ARKUI_X 75f857971dSopenharmony_ci int32_t UpdateDragStyle( 76f857971dSopenharmony_ci DragCursorStyle style, int32_t targetPid, int32_t targetTid, int32_t eventId = -1) override; 77f857971dSopenharmony_ci#else 78f857971dSopenharmony_ci int32_t UpdateDragStyle(DragCursorStyle style) override; 79f857971dSopenharmony_ci#endif // OHOS_BUILD_ENABLE_ARKUI_X 80f857971dSopenharmony_ci int32_t UpdateShadowPic(const ShadowInfo &shadowInfo) override; 81f857971dSopenharmony_ci int32_t GetDragData(DragData &dragData) override; 82f857971dSopenharmony_ci int32_t GetDragState(DragState &dragState) override; 83f857971dSopenharmony_ci DragCursorStyle GetDragStyle() const override; 84f857971dSopenharmony_ci void GetAllowDragState(bool &isAllowDrag) override; 85f857971dSopenharmony_ci void DragCallback(std::shared_ptr<MMI::PointerEvent> pointerEvent); 86f857971dSopenharmony_ci int32_t OnDragUp(std::shared_ptr<MMI::PointerEvent> pointerEvent); 87f857971dSopenharmony_ci#ifndef OHOS_BUILD_ENABLE_ARKUI_X 88f857971dSopenharmony_ci void OnDragMove(std::shared_ptr<MMI::PointerEvent> pointerEvent); 89f857971dSopenharmony_ci#else 90f857971dSopenharmony_ci int32_t OnDragMove(std::shared_ptr<MMI::PointerEvent> pointerEvent); 91f857971dSopenharmony_ci#endif // OHOS_BUILD_ENABLE_ARKUI_X 92f857971dSopenharmony_ci int32_t OnSetDragWindowVisible(bool visible, bool isForce = false) override; 93f857971dSopenharmony_ci MMI::ExtraData GetExtraData(bool appended) const override; 94f857971dSopenharmony_ci int32_t OnGetShadowOffset(ShadowOffset &shadowOffset) override; 95f857971dSopenharmony_ci#ifndef OHOS_BUILD_ENABLE_ARKUI_X 96f857971dSopenharmony_ci void Dump(int32_t fd) const override; 97f857971dSopenharmony_ci void RegisterStateChange(std::function<void(DragState)> callback) override; 98f857971dSopenharmony_ci void UnregisterStateChange() override; 99f857971dSopenharmony_ci void RegisterNotifyPullUp(std::function<void(bool)> callback) override; 100f857971dSopenharmony_ci void UnregisterNotifyPullUp() override; 101f857971dSopenharmony_ci void RegisterCrossDrag(std::function<void(bool)> callback) override; 102f857971dSopenharmony_ci void UnregisterCrossDrag() override; 103f857971dSopenharmony_ci void NotifyCrossDrag(bool isButtonDown) override; 104f857971dSopenharmony_ci#endif // OHOS_BUILD_ENABLE_ARKUI_X 105f857971dSopenharmony_ci void SetPointerEventFilterTime(int64_t filterTime) override; 106f857971dSopenharmony_ci void MoveTo(int32_t x, int32_t y, bool isMultiSelectedAnimation = true) override; 107f857971dSopenharmony_ci DragResult GetDragResult() const override; 108f857971dSopenharmony_ci DragState GetDragState() const override; 109f857971dSopenharmony_ci void SetDragState(DragState state) override; 110f857971dSopenharmony_ci void SetDragOriginDpi(float dragOriginDpi) override; 111f857971dSopenharmony_ci int32_t UpdatePreviewStyle(const PreviewStyle &previewStyle) override; 112f857971dSopenharmony_ci int32_t UpdatePreviewStyleWithAnimation(const PreviewStyle &previewStyle, 113f857971dSopenharmony_ci const PreviewAnimation &animation) override; 114f857971dSopenharmony_ci int32_t RotateDragWindowSync(const std::shared_ptr<Rosen::RSTransaction>& rsTransaction = nullptr) override; 115f857971dSopenharmony_ci int32_t GetDragSummary(std::map<std::string, int64_t> &summarys) override; 116f857971dSopenharmony_ci void DragKeyEventCallback(std::shared_ptr<MMI::KeyEvent> keyEvent); 117f857971dSopenharmony_ci int32_t EnterTextEditorArea(bool enable) override; 118f857971dSopenharmony_ci int32_t GetDragAction(DragAction &dragAction) const override; 119f857971dSopenharmony_ci int32_t GetExtraInfo(std::string &extraInfo) const override; 120f857971dSopenharmony_ci int32_t AddPrivilege(int32_t tokenId) override; 121f857971dSopenharmony_ci int32_t EraseMouseIcon() override; 122f857971dSopenharmony_ci#ifndef OHOS_BUILD_ENABLE_ARKUI_X 123f857971dSopenharmony_ci int32_t AddSelectedPixelMap(std::shared_ptr<OHOS::Media::PixelMap> pixelMap) override; 124f857971dSopenharmony_ci#endif // OHOS_BUILD_ENABLE_ARKUI_X 125f857971dSopenharmony_ci int32_t RotateDragWindow(Rosen::Rotation rotation) override; 126f857971dSopenharmony_ci int32_t ScreenRotate(Rosen::Rotation rotation, Rosen::Rotation lastRotation) override; 127f857971dSopenharmony_ci void SetDragWindowScreenId(uint64_t displayId, uint64_t screenId) override; 128f857971dSopenharmony_ci#ifndef OHOS_BUILD_ENABLE_ARKUI_X 129f857971dSopenharmony_ci int32_t SetMouseDragMonitorState(bool state) override; 130f857971dSopenharmony_ci#ifdef OHOS_DRAG_ENABLE_INTERCEPTOR 131f857971dSopenharmony_ci class InterceptorConsumer : public MMI::IInputEventConsumer { 132f857971dSopenharmony_ci public: 133f857971dSopenharmony_ci InterceptorConsumer(std::function<void (std::shared_ptr<MMI::PointerEvent>)> cb) 134f857971dSopenharmony_ci : pointerEventCallback_(cb) {} 135f857971dSopenharmony_ci void OnInputEvent(std::shared_ptr<MMI::KeyEvent> keyEvent) const override; 136f857971dSopenharmony_ci void OnInputEvent(std::shared_ptr<MMI::PointerEvent> pointerEvent) const override; 137f857971dSopenharmony_ci void OnInputEvent(std::shared_ptr<MMI::AxisEvent> axisEvent) const override; 138f857971dSopenharmony_ci private: 139f857971dSopenharmony_ci std::function<void (std::shared_ptr<MMI::PointerEvent>)> pointerEventCallback_ { nullptr }; 140f857971dSopenharmony_ci }; 141f857971dSopenharmony_ci#endif // OHOS_DRAG_ENABLE_INTERCEPTOR 142f857971dSopenharmony_ci 143f857971dSopenharmony_ci#ifdef OHOS_DRAG_ENABLE_MONITOR 144f857971dSopenharmony_ci class MonitorConsumer : public MMI::IInputEventConsumer { 145f857971dSopenharmony_ci public: 146f857971dSopenharmony_ci explicit MonitorConsumer( 147f857971dSopenharmony_ci std::function<void (std::shared_ptr<MMI::PointerEvent>)> cb) : pointerEventCallback_(cb) {} 148f857971dSopenharmony_ci void OnInputEvent(std::shared_ptr<MMI::KeyEvent> keyEvent) const override; 149f857971dSopenharmony_ci void OnInputEvent(std::shared_ptr<MMI::PointerEvent> pointerEvent) const override; 150f857971dSopenharmony_ci void OnInputEvent(std::shared_ptr<MMI::AxisEvent> axisEvent) const override; 151f857971dSopenharmony_ci private: 152f857971dSopenharmony_ci std::function<void (std::shared_ptr<MMI::PointerEvent>)> pointerEventCallback_; 153f857971dSopenharmony_ci }; 154f857971dSopenharmony_ci#endif //OHOS_DRAG_ENABLE_MONITOR 155f857971dSopenharmony_ci#else 156f857971dSopenharmony_ci void SetDragWindow(std::shared_ptr<OHOS::Rosen::Window> window) override; 157f857971dSopenharmony_ci void AddDragDestroy(std::function<void()> cb) override; 158f857971dSopenharmony_ci void SetSVGFilePath(const std::string &filePath) override; 159f857971dSopenharmony_ci#endif // OHOS_BUILD_ENABLE_ARKUI_X 160f857971dSopenharmony_ciprivate: 161f857971dSopenharmony_ci void PrintDragData(const DragData &dragData, const std::string &packageName = ""); 162f857971dSopenharmony_ci#ifndef OHOS_BUILD_ENABLE_ARKUI_X 163f857971dSopenharmony_ci int32_t AddDragEventHandler(int32_t sourceType); 164f857971dSopenharmony_ci int32_t AddPointerEventHandler(uint32_t deviceTags); 165f857971dSopenharmony_ci int32_t AddKeyEventMonitor(); 166f857971dSopenharmony_ci int32_t RemoveDragEventHandler(); 167f857971dSopenharmony_ci int32_t RemoveKeyEventMonitor(); 168f857971dSopenharmony_ci int32_t RemovePointerEventHandler(); 169f857971dSopenharmony_ci int32_t NotifyDragResult(DragResult result, DragBehavior dragBehavior); 170f857971dSopenharmony_ci int32_t NotifyHideIcon(); 171f857971dSopenharmony_ci#endif // OHOS_BUILD_ENABLE_ARKUI_X 172f857971dSopenharmony_ci int32_t InitDataManager(const DragData &dragData) const; 173f857971dSopenharmony_ci int32_t OnStartDrag(const std::string &packageName = "", int32_t pid = -1); 174f857971dSopenharmony_ci int32_t OnStopDrag(DragResult result, bool hasCustomAnimation, const std::string &packageName = "", 175f857971dSopenharmony_ci int32_t pid = -1); 176f857971dSopenharmony_ci std::string GetDragState(DragState value) const; 177f857971dSopenharmony_ci std::string GetDragResult(DragResult value) const; 178f857971dSopenharmony_ci std::string GetDragCursorStyle(DragCursorStyle value) const; 179f857971dSopenharmony_ci static MMI::ExtraData CreateExtraData(bool appended); 180f857971dSopenharmony_ci#ifndef OHOS_BUILD_ENABLE_ARKUI_X 181f857971dSopenharmony_ci void StateChangedNotify(DragState state); 182f857971dSopenharmony_ci int32_t AddDragEvent(const DragData &dragData, const std::string &packageName); 183f857971dSopenharmony_ci#endif // OHOS_BUILD_ENABLE_ARKUI_X 184f857971dSopenharmony_ci void CtrlKeyStyleChangedNotify(DragCursorStyle style, DragAction action); 185f857971dSopenharmony_ci int32_t HandleDragResult(DragResult result, bool hasCustomAnimation); 186f857971dSopenharmony_ci void HandleCtrlKeyEvent(DragCursorStyle style, DragAction action); 187f857971dSopenharmony_ci int32_t OnUpdateDragStyle(DragCursorStyle style); 188f857971dSopenharmony_ci void UpdateDragStyleCross(); 189f857971dSopenharmony_ci inline std::string GetDragStyleName(DragCursorStyle style); 190f857971dSopenharmony_ci DragCursorStyle GetRealDragStyle(DragCursorStyle style); 191f857971dSopenharmony_ci void GetDragBehavior(const DragDropResult &dropResult, DragBehavior &dragBehavior); 192f857971dSopenharmony_ci#ifndef OHOS_BUILD_ENABLE_ARKUI_X 193f857971dSopenharmony_ci int32_t NotifyAddSelectedPixelMapResult(bool result); 194f857971dSopenharmony_ci void ResetMouseDragMonitorInfo(); 195f857971dSopenharmony_ci void ResetMouseDragMonitorTimerId(const DragData &dragData); 196f857971dSopenharmony_ci#endif // OHOS_BUILD_ENABLE_ARKUI_X 197f857971dSopenharmony_ci#ifndef OHOS_BUILD_ENABLE_ARKUI_X 198f857971dSopenharmony_ci void ReportDragWindowVisibleRadarInfo(StageRes stageRes, DragRadarErrCode errCode, const std::string &funcName); 199f857971dSopenharmony_ci void ReportDragRadarInfo(struct DragRadarInfo &dragRadarInfo); 200f857971dSopenharmony_ci void ReportStartDragRadarInfo(BizState bizState, StageRes stageRes, DragRadarErrCode errCode, 201f857971dSopenharmony_ci const std::string &packageName, const std::string &peerNetId); 202f857971dSopenharmony_ci void ReportStopDragRadarInfo(BizState bizState, StageRes stageRes, DragRadarErrCode errCode, int32_t pid, 203f857971dSopenharmony_ci const std::string &packageName); 204f857971dSopenharmony_ci void ReportStartDragFailedRadarInfo(StageRes stageRes, DragRadarErrCode errCode, const std::string &funcName, 205f857971dSopenharmony_ci const std::string &packageName); 206f857971dSopenharmony_ci#endif // OHOS_BUILD_ENABLE_ARKUI_X 207f857971dSopenharmony_ciprivate: 208f857971dSopenharmony_ci int32_t timerId_ { -1 }; 209f857971dSopenharmony_ci int32_t mouseDragMonitorTimerId_ { -1 }; 210f857971dSopenharmony_ci DragState dragState_ { DragState::STOP }; 211f857971dSopenharmony_ci DragResult dragResult_ { DragResult::DRAG_FAIL }; 212f857971dSopenharmony_ci std::atomic<DragAction> dragAction_ { DragAction::MOVE }; 213f857971dSopenharmony_ci DragDrawing dragDrawing_; 214f857971dSopenharmony_ci bool isControlMultiScreenVisible_ = false; 215f857971dSopenharmony_ci inline static std::atomic<int32_t> pullId_ { -1 }; 216f857971dSopenharmony_ci#ifndef OHOS_BUILD_ENABLE_ARKUI_X 217f857971dSopenharmony_ci StateChangeNotify stateNotify_; 218f857971dSopenharmony_ci int32_t keyEventMonitorId_ { -1 }; 219f857971dSopenharmony_ci IContext* context_ { nullptr }; 220f857971dSopenharmony_ci#ifdef OHOS_DRAG_ENABLE_INTERCEPTOR 221f857971dSopenharmony_ci int32_t pointerEventInterceptorId_ { -1 }; 222f857971dSopenharmony_ci#endif // OHOS_DRAG_ENABLE_INTERCEPTOR 223f857971dSopenharmony_ci#ifdef OHOS_DRAG_ENABLE_MONITOR 224f857971dSopenharmony_ci int32_t pointerEventMonitorId_ { -1 }; 225f857971dSopenharmony_ci#endif //OHOS_DRAG_ENABLE_MONITOR 226f857971dSopenharmony_ci SocketSessionPtr dragOutSession_ { nullptr }; 227f857971dSopenharmony_ci std::function<void(DragState)> stateChangedCallback_ { nullptr }; 228f857971dSopenharmony_ci std::function<void(bool)> notifyPUllUpCallback_ { nullptr }; 229f857971dSopenharmony_ci std::function<void(bool)> crossDragCallback_ { nullptr }; 230f857971dSopenharmony_ci std::shared_ptr<EventHub> eventHub_ { nullptr }; 231f857971dSopenharmony_ci sptr<ISystemAbilityStatusChange> statusListener_ { nullptr }; 232f857971dSopenharmony_ci sptr<ISystemAbilityStatusChange> displayAbilityStatusChange_ { nullptr }; 233f857971dSopenharmony_ci sptr<ISystemAbilityStatusChange> appStateObserverStatusChange_ { nullptr }; 234f857971dSopenharmony_ci sptr<ISystemAbilityStatusChange> CollaborationServiceStatusChange_ { nullptr }; 235f857971dSopenharmony_ci#endif // OHOS_BUILD_ENABLE_ARKUI_X 236f857971dSopenharmony_ci uint64_t displayId_ { 0 }; 237f857971dSopenharmony_ci uint64_t screenId_ { 0 }; 238f857971dSopenharmony_ci int32_t lastEventId_ { -1 }; 239f857971dSopenharmony_ci int64_t mouseDragMonitorDisplayX_ { -1 }; 240f857971dSopenharmony_ci int64_t mouseDragMonitorDisplayY_ { -1 }; 241f857971dSopenharmony_ci bool mouseDragMonitorState_ { false }; 242f857971dSopenharmony_ci bool existMouseMoveDragCallback_ { false }; 243f857971dSopenharmony_ci int32_t lastDisplayId_ { -1 }; 244f857971dSopenharmony_ci}; 245f857971dSopenharmony_ci} // namespace DeviceStatus 246f857971dSopenharmony_ci} // namespace Msdp 247f857971dSopenharmony_ci} // namespace OHOS 248f857971dSopenharmony_ci 249f857971dSopenharmony_ci#ifdef OHOS_BUILD_ENABLE_ARKUI_X 250f857971dSopenharmony_ci#define DRAG_MANAGER OHOS::Msdp::DeviceStatus::DragManager::GetInstance() 251f857971dSopenharmony_ci#endif // OHOS_BUILD_ENABLE_ARKUI_X 252f857971dSopenharmony_ci#endif // DRAG_MANAGER_H 253