1 /* 2 * Copyright (c) 2023 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16 #ifndef DRAG_MANAGER_H 17 #define DRAG_MANAGER_H 18 19 #include <atomic> 20 #include <string> 21 22 #include "extra_data.h" 23 #include "i_input_event_consumer.h" 24 #include "input_manager.h" 25 #include "pixel_map.h" 26 27 #include "display_change_event_listener.h" 28 #include "devicestatus_define.h" 29 #include "drag_data.h" 30 #include "drag_drawing.h" 31 #include "event_hub.h" 32 #include "i_context.h" 33 #include "state_change_notify.h" 34 #include "stream_session.h" 35 36 namespace OHOS { 37 namespace Msdp { 38 namespace DeviceStatus { 39 class DragManager : public IDragManager { 40 public: DragManager()41 DragManager() {} 42 DISALLOW_COPY_AND_MOVE(DragManager); 43 ~DragManager(); 44 45 int32_t Init(IContext* context); 46 void OnSessionLost(SessionPtr session); 47 int32_t AddListener(SessionPtr session); 48 int32_t RemoveListener(SessionPtr session); 49 int32_t AddSubscriptListener(SessionPtr session); 50 int32_t RemoveSubscriptListener(SessionPtr session); 51 int32_t StartDrag(const DragData &dragData, SessionPtr sess) override; 52 int32_t StopDrag(const DragDropResult &dropResult) override; 53 int32_t GetDragTargetPid() const; 54 int32_t GetUdKey(std::string &udKey) const; 55 void SendDragData(int32_t targetTid, const std::string &udKey); 56 int32_t UpdateDragStyle(DragCursorStyle style, int32_t targetPid, int32_t targetTid); 57 int32_t UpdateShadowPic(const ShadowInfo &shadowInfo); 58 int32_t GetDragData(DragData &dragData); 59 int32_t GetDragState(DragState &dragState); 60 void GetAllowDragState(bool &isAllowDrag) override; 61 void DragCallback(std::shared_ptr<MMI::PointerEvent> pointerEvent); 62 void OnDragUp(std::shared_ptr<MMI::PointerEvent> pointerEvent); 63 void OnDragMove(std::shared_ptr<MMI::PointerEvent> pointerEvent); 64 int32_t OnSetDragWindowVisible(bool visible, bool isForce = false) override; 65 MMI::ExtraData GetExtraData(bool appended) const override; 66 int32_t OnGetShadowOffset(int32_t &offsetX, int32_t &offsetY, int32_t &width, int32_t &height); 67 void Dump(int32_t fd) const override; 68 void RegisterStateChange(std::function<void(DragState)> callback) override; 69 void RegisterNotifyPullUp(std::function<void(bool)> callback) override; 70 void SetPointerEventFilterTime(int64_t filterTime) override; 71 void MoveTo(int32_t x, int32_t y) override; 72 DragResult GetDragResult() const override; 73 DragState GetDragState() const override; 74 void SetDragState(DragState state) override; 75 int32_t UpdatePreviewStyle(const PreviewStyle &previewStyle) override; 76 int32_t UpdatePreviewStyleWithAnimation(const PreviewStyle &previewStyle, 77 const PreviewAnimation &animation) override; 78 int32_t GetDragSummary(std::map<std::string, int64_t> &summarys); 79 void DragKeyEventCallback(std::shared_ptr<MMI::KeyEvent> keyEvent); 80 int32_t EnterTextEditorArea(bool enable); 81 int32_t GetDragAction(DragAction &dragAction) const; 82 int32_t GetExtraInfo(std::string &extraInfo) const; 83 int32_t AddPrivilege(int32_t tokenId); 84 int32_t RotateDragWindow(Rosen::Rotation rotation) override; 85 #ifdef OHOS_DRAG_ENABLE_INTERCEPTOR 86 class InterceptorConsumer : public MMI::IInputEventConsumer { 87 public: InterceptorConsumer(std::function<void (std::shared_ptr<MMI::PointerEvent>)> cb)88 InterceptorConsumer(std::function<void (std::shared_ptr<MMI::PointerEvent>)> cb) 89 : pointerEventCallback_(cb) {} 90 void OnInputEvent(std::shared_ptr<MMI::KeyEvent> keyEvent) const override; 91 void OnInputEvent(std::shared_ptr<MMI::PointerEvent> pointerEvent) const override; 92 void OnInputEvent(std::shared_ptr<MMI::AxisEvent> axisEvent) const override; 93 private: 94 std::function<void (std::shared_ptr<MMI::PointerEvent>)> pointerEventCallback_ { nullptr }; 95 }; 96 #endif // OHOS_DRAG_ENABLE_INTERCEPTOR 97 98 #ifdef OHOS_DRAG_ENABLE_MONITOR 99 class MonitorConsumer : public MMI::IInputEventConsumer { 100 public: MonitorConsumer(std::function<void (std::shared_ptr<MMI::PointerEvent>)> cb)101 explicit MonitorConsumer( 102 std::function<void (std::shared_ptr<MMI::PointerEvent>)> cb) : pointerEventCallback_(cb) {} 103 void OnInputEvent(std::shared_ptr<MMI::KeyEvent> keyEvent) const override; 104 void OnInputEvent(std::shared_ptr<MMI::PointerEvent> pointerEvent) const override; 105 void OnInputEvent(std::shared_ptr<MMI::AxisEvent> axisEvent) const override; 106 private: 107 std::function<void (std::shared_ptr<MMI::PointerEvent>)> pointerEventCallback_; 108 }; 109 #endif //OHOS_DRAG_ENABLE_MONITOR 110 private: 111 void PrintDragData(const DragData &dragData); 112 int32_t AddDragEventHandler(int32_t sourceType); 113 int32_t AddPointerEventHandler(uint32_t deviceTags); 114 int32_t AddKeyEventMointor(); 115 int32_t RemoveKeyEventMointor(); 116 int32_t RemovePointerEventHandler(); 117 int32_t NotifyDragResult(DragResult result); 118 int32_t NotifyHideIcon(); 119 int32_t InitDataManager(const DragData &dragData) const; 120 int32_t OnStartDrag(); 121 int32_t OnStopDrag(DragResult result, bool hasCustomAnimation); 122 std::string GetDragState(DragState value) const; 123 std::string GetDragResult(DragResult value) const; 124 std::string GetDragCursorStyle(DragCursorStyle value) const; 125 static MMI::ExtraData CreateExtraData(bool appended); 126 void StateChangedNotify(DragState state); 127 void CtrlKeyStyleChangedNotify(DragCursorStyle style, DragAction action); 128 int32_t HandleDragResult(DragResult result, bool hasCustomAnimation); 129 void HandleCtrlKeyEvent(DragCursorStyle style, DragAction action); 130 int32_t OnUpdateDragStyle(DragCursorStyle style); 131 void UpdateDragStyleCross(); 132 inline std::string GetDragStyleName(DragCursorStyle style); 133 DragCursorStyle GetRealDragStyle(DragCursorStyle style); 134 135 private: 136 int32_t timerId_ { -1 }; 137 StateChangeNotify stateNotify_; 138 DragState dragState_ { DragState::STOP }; 139 DragResult dragResult_ { DragResult::DRAG_FAIL }; 140 int32_t keyEventMonitorId_ { -1 }; 141 std::atomic<DragAction> dragAction_ { DragAction::MOVE }; 142 #ifdef OHOS_DRAG_ENABLE_INTERCEPTOR 143 int32_t pointerEventInterceptorId_ { -1 }; 144 #endif // OHOS_DRAG_ENABLE_INTERCEPTOR 145 #ifdef OHOS_DRAG_ENABLE_MONITOR 146 int32_t pointerEventMonitorId_ { -1 }; 147 #endif //OHOS_DRAG_ENABLE_MONITOR 148 SessionPtr dragOutSession_ { nullptr }; 149 DragDrawing dragDrawing_; 150 IContext* context_ { nullptr }; 151 std::function<void(DragState)> stateChangedCallback_ { nullptr }; 152 std::function<void(bool)> notifyPUllUpCallback_ { nullptr }; 153 std::shared_ptr<EventHub> eventHub_ { nullptr }; 154 sptr<ISystemAbilityStatusChange> statusListener_ { nullptr }; 155 bool isControlMultiScreenVisible_ = false; 156 sptr<ISystemAbilityStatusChange> displayAbilityStatusChange_ { nullptr }; 157 }; 158 } // namespace DeviceStatus 159 } // namespace Msdp 160 } // namespace OHOS 161 #endif // DRAG_MANAGER_H 162