• 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 OHOS_ROSEN_WINDOW_SCENE_MOVE_DRAG_CONTROLLER_H
17 #define OHOS_ROSEN_WINDOW_SCENE_MOVE_DRAG_CONTROLLER_H
18 
19 #include <refbase.h>
20 #include <struct_multimodal.h>
21 
22 #include "common/include/window_session_property.h"
23 
24 namespace OHOS::MMI {
25 class PointerEvent;
26 } // namespace MMI
27 
28 namespace OHOS::Rosen {
29 
30 using SessionRectChangeCallBack = std::function<void(void)>;
31 
32 enum class AreaType : uint32_t {
33     UNDEFINED = 0,
34     LEFT = 1 << 0,
35     TOP = 1 << 1,
36     RIGHT = 1 << 2,
37     BOTTOM = 1 << 3,
38     LEFT_TOP = LEFT | TOP,
39     RIGHT_TOP = RIGHT | TOP,
40     RIGHT_BOTTOM = RIGHT | BOTTOM,
41     LEFT_BOTTOM = LEFT | BOTTOM,
42 };
43 
44 class MoveDragController : public RefBase {
45 public:
46     struct MoveDragProperty {
47         int32_t pointerId_;
48         int32_t originalPointerPosX_;
49         int32_t originalPointerPosY_;
50         WSRect originalRect_;
51         WSRect targetRect_;
52 
isEmptyMoveDragProperty53         bool isEmpty() const
54         {
55             return (pointerId_ == -1 && originalPointerPosX_ == -1 && originalPointerPosY_ == -1);
56         }
57     };
58 
59     MoveDragController(int32_t persistentId);
60     ~MoveDragController() = default;
61 
62     void RegisterSessionRectChangeCallback(const SessionRectChangeCallBack& callBack);
63     void SetStartMoveFlag(bool flag);
64     bool GetStartMoveFlag() const;
65     bool GetStartDragFlag() const;
66     WSRect GetTargetRect() const;
67     void InitMoveDragProperty();
68     void SetAspectRatio(float ratio);
69     WSError ConsumeMoveEvent(const std::shared_ptr<MMI::PointerEvent>& pointerEvent, const WSRect& originalRect);
70     bool ConsumeDragEvent(const std::shared_ptr<MMI::PointerEvent>& pointerEvent, const WSRect& originalRect,
71         const sptr<WindowSessionProperty> property, const SystemSessionConfig& sysConfig);
72     void HandleMouseStyle(const std::shared_ptr<MMI::PointerEvent>& pointerEvent, const WSRect& winRect);
73 
74 private:
75     enum AxisType { UNDEFINED, X_AXIS, Y_AXIS };
76     constexpr static float NEAR_ZERO = 0.001f;
77 
78     void CalcMoveTargetRect(const std::shared_ptr<MMI::PointerEvent>& pointerEvent, const WSRect& originalRect);
79     bool EventDownInit(const std::shared_ptr<MMI::PointerEvent>& pointerEvent, const WSRect& originalRect,
80         const sptr<WindowSessionProperty> property, const SystemSessionConfig& sysConfig);
81     AreaType GetAreaType(int32_t pointWinX, int32_t pointWinY, int32_t sourceType, const WSRect& rect);
82     WSRect CalcFreeformTargetRect(AreaType type, int32_t tranX, int32_t tranY, WSRect originalRect);
83     WSRect CalcFixedAspectRatioTargetRect(AreaType type, int32_t tranX, int32_t tranY, float aspectRatio,
84         WSRect originalRect);
85     void CalcFreeformTranslateLimits(AreaType type);
86     void CalcFixedAspectRatioTranslateLimits(AreaType type, AxisType axis);
87     void FixTranslateByLimits(int32_t& tranX, int32_t& tranY);
88     bool InitMainAxis(AreaType type, int32_t tranX, int32_t tranY);
89     void ConvertXYByAspectRatio(int32_t& tx, int32_t& ty, float aspectRatio);
90     void ProcessSessionRectChange(void);
91     void InitDecorValue(const sptr<WindowSessionProperty> property, const SystemSessionConfig& sysConfig);
92 
93     float GetVirtualPixelRatio() const;
94     void UpdateDragType(int32_t startPointPosX, int32_t startPointPosY);
95     bool IsPointInDragHotZone(int32_t startPointPosX, int32_t startPointPosY,
96         int32_t sourceType, const WSRect& winRect);
97     void CalculateStartRectExceptHotZone(float vpr, const WSRect& winRect);
98 
99     bool isStartMove_ = false;
100     bool isStartDrag_ = false;
101     bool isDecorEnable_ = true;
102     float aspectRatio_ = 0.0f;
103     float vpr_ = 1.0f;
104     int32_t minTranX_ = INT32_MIN;
105     int32_t minTranY_ = INT32_MIN;
106     int32_t maxTranX_ = INT32_MAX;
107     int32_t maxTranY_ = INT32_MAX;
108     AreaType type_ = AreaType::UNDEFINED;
109     AxisType mainMoveAxis_ = AxisType::UNDEFINED;
110     WindowLimits limits_;
111     MoveDragProperty moveDragProperty_ = { -1, -1, -1, { 0, 0, 0, 0 }, { 0, 0, 0, 0 } };
112     SessionRectChangeCallBack sessionRectChangeCallBack_;
113     int32_t persistentId_;
114 
115     enum class DragType : uint32_t {
116         DRAG_UNDEFINED,
117         DRAG_LEFT_OR_RIGHT,
118         DRAG_BOTTOM_OR_TOP,
119         DRAG_LEFT_TOP_CORNER,
120         DRAG_RIGHT_TOP_CORNER,
121     };
122     const std::map<DragType, uint32_t> STYLEID_MAP = {
123         {DragType::DRAG_UNDEFINED,        MMI::MOUSE_ICON::DEFAULT},
124         {DragType::DRAG_BOTTOM_OR_TOP,    MMI::MOUSE_ICON::NORTH_SOUTH},
125         {DragType::DRAG_LEFT_OR_RIGHT,    MMI::MOUSE_ICON::WEST_EAST},
126         {DragType::DRAG_LEFT_TOP_CORNER,  MMI::MOUSE_ICON::NORTH_WEST_SOUTH_EAST},
127         {DragType::DRAG_RIGHT_TOP_CORNER, MMI::MOUSE_ICON::NORTH_EAST_SOUTH_WEST}
128     };
129     Rect rectExceptFrame_ { 0, 0, 0, 0 };
130     Rect rectExceptCorner_ { 0, 0, 0, 0 };
131     uint32_t mouseStyleID_ = 0;
132     DragType dragType_ = DragType::DRAG_UNDEFINED;
133 };
134 } // namespace OHOS::Rosen
135 #endif // OHOS_ROSEN_WINDOW_SCENE_MOVE_DRAG_CONTROLLER_H
136