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