• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021-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 OHOS_ROSEN_DRAG_CONTROLLER_H
17 #define OHOS_ROSEN_DRAG_CONTROLLER_H
18 
19 #include <refbase.h>
20 
21 #include "display_group_info.h"
22 #include "display_info.h"
23 #include "event_handler.h"
24 #include "event_runner.h"
25 #include "input_manager.h"
26 #include "pointer_event.h"
27 #include "window_root.h"
28 #include "wm_common.h"
29 
30 namespace OHOS {
31 namespace Rosen {
32 using EventRunner = OHOS::AppExecFwk::EventRunner;
33 using EventHandler = OHOS::AppExecFwk::EventHandler;
34 /*
35  * DragController is the class which is used to handle drag cross window
36  */
37 class DragController : public RefBase {
38 public:
DragController(sptr<WindowRoot> & root)39     explicit DragController(sptr<WindowRoot>& root) : windowRoot_(root) {}
40     ~DragController() = default;
41     void StartDrag(uint32_t windowId);
42     void UpdateDragInfo(uint32_t windowId);
43     void FinishDrag(uint32_t windowId);
44 private:
45     sptr<WindowNode> GetHitWindow(DisplayId id, const PointInfo point);
46     bool GetHitPoint(uint32_t windowId, PointInfo& point);
47     sptr<WindowRoot> windowRoot_;
48     uint64_t hitWindowId_ = 0;
49 };
50 
51 class DragInputEventListener : public MMI::IInputEventConsumer {
52 public:
53     DragInputEventListener() = default;
54     void OnInputEvent(std::shared_ptr<MMI::PointerEvent> pointerEvent) const override;
55     void OnInputEvent(std::shared_ptr<MMI::KeyEvent> keyEvent) const override;
56     void OnInputEvent(std::shared_ptr<MMI::AxisEvent> axisEvent) const override;
57 };
58 
59 /*
60  * MoveDragController is the class which is used to handle move or drag floating window
61  */
62 class MoveDragController : public RefBase {
63 public:
MoveDragController()64     MoveDragController() : windowProperty_(new WindowProperty()), moveDragProperty_(new MoveDragProperty())
65     {
66         vsyncCallback_->onCallback = std::bind(&MoveDragController::OnReceiveVsync, this, std::placeholders::_1);
67     }
68     ~MoveDragController() = default;
69 
70     bool Init();
71     void Stop();
72     void HandleReadyToMoveOrDrag(uint32_t windowId, sptr<WindowProperty>& windowProperty,
73         sptr<MoveDragProperty>& moveDragProperty);
74     void HandleEndUpMovingOrDragging(uint32_t windowId);
75     void HandleWindowRemovedOrDestroyed(uint32_t windowId);
76     void ConsumePointerEvent(const std::shared_ptr<MMI::PointerEvent>& pointerEvent);
77     uint32_t GetActiveWindowId() const;
78     void HandleDisplayLimitRectChange(const std::map<DisplayId, Rect>& limitRectMap);
79     void SetInputEventConsumer();
80 
81 private:
82     void SetDragProperty(const sptr<MoveDragProperty>& moveDragProperty);
83     void SetWindowProperty(const sptr<WindowProperty>& windowProperty);
84     void SetActiveWindowId(uint32_t);
85     const sptr<MoveDragProperty>& GetMoveDragProperty() const;
86     const sptr<WindowProperty>& GetWindowProperty() const;
87     Rect GetHotZoneRect();
88     void ConvertPointerPosToDisplayGroupPos(DisplayId displayId, int32_t& posX, int32_t& posY);
89 
90     void HandlePointerEvent(const std::shared_ptr<MMI::PointerEvent>& pointerEvent);
91     void HandleDragEvent(DisplayId displayId, int32_t posX, int32_t posY, int32_t pointId, int32_t sourceType);
92     void HandleMoveEvent(DisplayId displayId, int32_t posX, int32_t posY, int32_t pointId, int32_t sourceType);
93     void OnReceiveVsync(int64_t timeStamp);
94     void ResetMoveOrDragState();
95     bool CheckWindowRect(DisplayId displayId, float vpr, const Rect& rect);
96     void CalculateNewWindowRect(Rect& newRect, DisplayId displayId, int32_t posX, int32_t posY);
97 
98     sptr<WindowProperty> windowProperty_;
99     sptr<MoveDragProperty> moveDragProperty_;
100     uint32_t activeWindowId_ = INVALID_WINDOW_ID;
101     std::shared_ptr<MMI::PointerEvent> moveEvent_ = nullptr;
102     std::shared_ptr<MMI::IInputEventConsumer> inputListener_ = nullptr;
103     std::shared_ptr<VsyncCallback> vsyncCallback_ = std::make_shared<VsyncCallback>(VsyncCallback());
104     std::map<DisplayId, Rect> limitRectMap_;
105 
106     // event handler for input event
107     std::shared_ptr<EventHandler> inputEventHandler_;
108     const std::string INNER_WM_INPUT_THREAD_NAME = "InnerInputManager";
109 };
110 }
111 }
112 #endif // OHOS_ROSEN_DRAG_CONTROLLER_H
113 
114