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 #include "drag_data_manager.h"
17
18 #include "hitrace_meter.h"
19 #include "pointer_style.h"
20
21 #include "devicestatus_define.h"
22 #include "drag_data.h"
23 #include "fi_log.h"
24
25 namespace OHOS {
26 namespace Msdp {
27 namespace DeviceStatus {
28 namespace {
29 constexpr OHOS::HiviewDFX::HiLogLabel LABEL { LOG_CORE, MSDP_DOMAIN_ID, "DragDataManager" };
30 } // namespace
31
32 DragDataManager::DragDataManager() = default;
33 DragDataManager::~DragDataManager() = default;
34
Init(const DragData & dragData,const MMI::PointerStyle & pointerStyle)35 void DragDataManager::Init(const DragData &dragData, const MMI::PointerStyle &pointerStyle)
36 {
37 CALL_DEBUG_ENTER;
38 dragData_ = dragData;
39 if (dragData.displayId < 0) {
40 dragData_.displayId = 0;
41 FI_HILOGW("The value of displayId(%{public}d) is correcting to 0", dragData.displayId);
42 }
43 pointerStyle_ = pointerStyle;
44 targetTid_ = -1;
45 targetPid_ = -1;
46 }
47
SetDragStyle(DragCursorStyle style)48 void DragDataManager::SetDragStyle(DragCursorStyle style)
49 {
50 dragStyle_ = style;
51 }
52
SetShadowInfo(const ShadowInfo & shadowInfo)53 void DragDataManager::SetShadowInfo(const ShadowInfo &shadowInfo)
54 {
55 dragData_.shadowInfo = shadowInfo;
56 }
57
GetDragStyle() const58 DragCursorStyle DragDataManager::GetDragStyle() const
59 {
60 return dragStyle_;
61 }
62
GetDragMessage() const63 std::u16string DragDataManager::GetDragMessage() const
64 {
65 return dragMessage_;
66 }
67
GetDragData() const68 DragData DragDataManager::GetDragData() const
69 {
70 return dragData_;
71 }
72
SetDragWindowVisible(bool visible)73 void DragDataManager::SetDragWindowVisible(bool visible)
74 {
75 visible_ = visible;
76 }
77
GetDragWindowVisible() const78 bool DragDataManager::GetDragWindowVisible() const
79 {
80 return visible_;
81 }
82
SetTargetTid(int32_t targetTid)83 void DragDataManager::SetTargetTid(int32_t targetTid)
84 {
85 targetTid_ = targetTid;
86 }
87
GetTargetTid() const88 int32_t DragDataManager::GetTargetTid() const
89 {
90 return targetTid_;
91 }
92
SetTargetPid(int32_t pid)93 void DragDataManager::SetTargetPid(int32_t pid)
94 {
95 targetPid_ = pid;
96 }
97
GetTargetPid() const98 int32_t DragDataManager::GetTargetPid() const
99 {
100 return targetPid_;
101 }
102
GetShadowOffset(int32_t & offsetX,int32_t & offsetY,int32_t & width,int32_t & height) const103 int32_t DragDataManager::GetShadowOffset(int32_t& offsetX, int32_t& offsetY, int32_t& width, int32_t& height) const
104 {
105 offsetX = dragData_.shadowInfo.x;
106 offsetY = dragData_.shadowInfo.y;
107 auto pixelMap = dragData_.shadowInfo.pixelMap;
108 CHKPR(pixelMap, RET_ERR);
109 width = pixelMap->GetWidth();
110 height = pixelMap->GetHeight();
111 FI_HILOGD("offsetX:%{public}d, offsetY:%{public}d, width:%{public}d, height:%{public}d",
112 offsetX, offsetY, width, height);
113 return RET_OK;
114 }
115
ResetDragData()116 void DragDataManager::ResetDragData()
117 {
118 CALL_DEBUG_ENTER;
119 ShadowInfo shadowInfo;
120 std::vector<uint8_t> buffer;
121 dragData_ = { shadowInfo, buffer, "", -1, -1, -1, -1, -1, -1, false };
122 }
123
SetMotionDrag(bool isMotionDrag)124 void DragDataManager::SetMotionDrag(bool isMotionDrag)
125 {
126 isMotionDrag_ = isMotionDrag;
127 FI_HILOGD("isMotionDrag_:%{public}d", isMotionDrag_);
128 }
129
IsMotionDrag() const130 bool DragDataManager::IsMotionDrag() const
131 {
132 FI_HILOGD("isMotionDrag_:%{public}d", isMotionDrag_);
133 return isMotionDrag_;
134 }
135 } // namespace DeviceStatus
136 } // namespace Msdp
137 } // namespace OHOS