• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 <string>
20 
21 #include "extra_data.h"
22 #include "i_input_event_consumer.h"
23 #include "input_manager.h"
24 #include "pixel_map.h"
25 
26 #include "devicestatus_define.h"
27 #include "drag_data.h"
28 #include "drag_drawing.h"
29 #include "i_context.h"
30 #include "state_change_notify.h"
31 #include "stream_session.h"
32 
33 namespace OHOS {
34 namespace Msdp {
35 namespace DeviceStatus {
36 class DragManager : public IDragManager {
37 public:
DragManager()38     DragManager() {}
39     DISALLOW_COPY_AND_MOVE(DragManager);
40     ~DragManager() = default;
41 
42     int32_t Init(IContext* context);
43     void OnSessionLost(SessionPtr session);
44     int32_t AddListener(SessionPtr session);
45     int32_t RemoveListener(SessionPtr session);
46     int32_t StartDrag(const DragData &dragData, SessionPtr sess) override;
47     int32_t StopDrag(DragResult result, bool hasCustomAnimation) override;
48     int32_t GetDragTargetPid() const;
49     int32_t GetUdKey(std::string &udKey) const;
50     void SendDragData(int32_t targetTid, const std::string &udKey);
51     int32_t UpdateDragStyle(DragCursorStyle style, int32_t targetPid, int32_t targetTid);
52     int32_t UpdateShadowPic(const ShadowInfo &shadowInfo);
53     void DragCallback(std::shared_ptr<MMI::PointerEvent> pointerEvent);
54     void OnDragUp(std::shared_ptr<MMI::PointerEvent> pointerEvent);
55     void OnDragMove(std::shared_ptr<MMI::PointerEvent> pointerEvent);
56     int32_t OnSetDragWindowVisible(bool visible) override;
57     MMI::ExtraData GetExtraData(bool appended) const override;
58     int32_t OnGetShadowOffset(int32_t& offsetX, int32_t& offsetY, int32_t& width, int32_t& height);
59     void Dump(int32_t fd) const override;
60     void RegisterStateChange(std::function<void(DragState)> callback) override;
61     void RegisterNotifyPullUp(std::function<void(void)> callback) override;
62     DragResult GetDragResult() const override;
63     DragState GetDragState() const override;
64     void SetDragState(DragState state) override;
65 #ifdef OHOS_DRAG_ENABLE_INTERCEPTOR
66     class InterceptorConsumer : public MMI::IInputEventConsumer {
67     public:
InterceptorConsumer(IContext * context,std::function<void (std::shared_ptr<MMI::PointerEvent>)> cb)68         InterceptorConsumer(IContext *context,
69             std::function<void (std::shared_ptr<MMI::PointerEvent>)> cb) : context_(context), callback_(cb) {}
70         void OnInputEvent(std::shared_ptr<MMI::KeyEvent> keyEvent) const override;
71         void OnInputEvent(std::shared_ptr<MMI::PointerEvent> pointerEvent) const override;
72         void OnInputEvent(std::shared_ptr<MMI::AxisEvent> axisEvent) const override;
73     private:
74         IContext* context_ { nullptr };
75         std::function<void (std::shared_ptr<MMI::PointerEvent>)> callback_ { nullptr };
76     };
77 #endif // OHOS_DRAG_ENABLE_INTERCEPTOR
78 
79 #ifdef OHOS_DRAG_ENABLE_MONITOR
80     class MonitorConsumer : public MMI::IInputEventConsumer {
81     public:
MonitorConsumer(std::function<void (std::shared_ptr<MMI::PointerEvent>)> cb)82         explicit MonitorConsumer(std::function<void (std::shared_ptr<MMI::PointerEvent>)> cb) : callback_(cb) {}
83         void OnInputEvent(std::shared_ptr<MMI::KeyEvent> keyEvent) const override;
84         void OnInputEvent(std::shared_ptr<MMI::PointerEvent> pointerEvent) const override;
85         void OnInputEvent(std::shared_ptr<MMI::AxisEvent> axisEvent) const override;
86     private:
87         std::function<void (std::shared_ptr<MMI::PointerEvent>)> callback_;
88     };
89 #endif //OHOS_DRAG_ENABLE_MONITOR
90 private:
91     int32_t AddDragEventHandler(int32_t sourceType);
92     int32_t NotifyDragResult(DragResult result);
93     int32_t InitDataManager(const DragData &dragData) const;
94     int32_t OnStartDrag();
95     int32_t OnStopDrag(DragResult result, bool hasCustomAnimation);
96     std::string GetDragState(DragState value) const;
97     std::string GetDragResult(DragResult value) const;
98     std::string GetDragCursorStyle(DragCursorStyle value) const;
99     static MMI::ExtraData CreateExtraData(bool appended);
100     void StateChangedNotify(DragState state);
101     int32_t HandleDragResult(DragResult result, bool hasCustomAnimation);
102 private:
103     int32_t timerId_ { -1 };
104     StateChangeNotify stateNotify_;
105     DragState dragState_ { DragState::STOP };
106     DragResult dragResult_ { DragResult::DRAG_FAIL };
107 #ifdef OHOS_DRAG_ENABLE_INTERCEPTOR
108     int32_t interceptorId_ { -1 };
109 #endif // OHOS_DRAG_ENABLE_INTERCEPTOR
110 #ifdef OHOS_DRAG_ENABLE_MONITOR
111     int32_t monitorId_  { -1 };
112 #endif //OHOS_DRAG_ENABLE_MONITOR
113     SessionPtr dragOutSession_ { nullptr };
114     DragDrawing dragDrawing_;
115     IContext* context_ { nullptr };
116     std::function<void(DragState)> stateChangedCallback_ { nullptr };
117     std::function<void(void)> notifyPUllUpCallback_ { nullptr };
118 };
119 } // namespace DeviceStatus
120 } // namespace Msdp
121 } // namespace OHOS
122 #endif // DRAG_MANAGER_H
123