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 #include "drag_controller.h"
17
18 #include <vector>
19
20 #include "display.h"
21 #include "window_helper.h"
22 #include "window_inner_manager.h"
23 #include "window_manager_hilog.h"
24 #include "window_manager_service.h"
25 #include "window_node.h"
26 #include "window_node_container.h"
27 #include "window_property.h"
28 #include "wm_common.h"
29 #include "wm_math.h"
30 #include "xcollie/watchdog.h"
31
32 namespace OHOS {
33 namespace Rosen {
34 namespace {
35 constexpr HiviewDFX::HiLogLabel LABEL = {LOG_CORE, HILOG_DOMAIN_WINDOW, "DragController"};
36 }
37
UpdateDragInfo(uint32_t windowId)38 void DragController::UpdateDragInfo(uint32_t windowId)
39 {
40 PointInfo point;
41 if (!GetHitPoint(windowId, point)) {
42 return;
43 }
44 sptr<WindowNode> dragNode = windowRoot_->GetWindowNode(windowId);
45 if (dragNode == nullptr) {
46 return;
47 }
48 sptr<WindowNode> hitWindowNode = GetHitWindow(dragNode->GetDisplayId(), point);
49 if (hitWindowNode == nullptr) {
50 WLOGFE("Get point failed %{public}d %{public}d", point.x, point.y);
51 return;
52 }
53 auto token = hitWindowNode->GetWindowToken();
54 if (token) {
55 if (hitWindowNode->GetWindowId() == hitWindowId_) {
56 token->UpdateWindowDragInfo(point, DragEvent::DRAG_EVENT_MOVE);
57 return;
58 }
59 token->UpdateWindowDragInfo(point, DragEvent::DRAG_EVENT_IN);
60 }
61 sptr<WindowNode> oldHitWindow = windowRoot_->GetWindowNode(hitWindowId_);
62 if (oldHitWindow != nullptr && oldHitWindow->GetWindowToken()) {
63 oldHitWindow->GetWindowToken()->UpdateWindowDragInfo(point, DragEvent::DRAG_EVENT_OUT);
64 }
65 hitWindowId_ = hitWindowNode->GetWindowId();
66 }
67
StartDrag(uint32_t windowId)68 void DragController::StartDrag(uint32_t windowId)
69 {
70 PointInfo point;
71 if (!GetHitPoint(windowId, point)) {
72 WLOGFE("Get hit point failed");
73 return;
74 }
75 sptr<WindowNode> dragNode = windowRoot_->GetWindowNode(windowId);
76 if (dragNode == nullptr) {
77 return;
78 }
79 sptr<WindowNode> hitWindow = GetHitWindow(dragNode->GetDisplayId(), point);
80 if (hitWindow == nullptr) {
81 WLOGFE("Get point failed %{public}d %{public}d", point.x, point.y);
82 return;
83 }
84 if (hitWindow->GetWindowToken()) {
85 hitWindow->GetWindowToken()->UpdateWindowDragInfo(point, DragEvent::DRAG_EVENT_IN);
86 }
87 hitWindowId_ = windowId;
88 WLOGI("start Drag");
89 }
90
FinishDrag(uint32_t windowId)91 void DragController::FinishDrag(uint32_t windowId)
92 {
93 sptr<WindowNode> node = windowRoot_->GetWindowNode(windowId);
94 if (node == nullptr) {
95 WLOGFE("get node failed");
96 return;
97 }
98 if (node->GetWindowType() != WindowType::WINDOW_TYPE_DRAGGING_EFFECT) {
99 return;
100 }
101
102 sptr<WindowNode> hitWindow = windowRoot_->GetWindowNode(hitWindowId_);
103 if (hitWindow != nullptr) {
104 auto property = node->GetWindowProperty();
105 PointInfo point = {property->GetWindowRect().posX_ + property->GetHitOffset().x,
106 property->GetWindowRect().posY_ + property->GetHitOffset().y};
107 if (hitWindow->GetWindowToken()) {
108 hitWindow->GetWindowToken()->UpdateWindowDragInfo(point, DragEvent::DRAG_EVENT_END);
109 }
110 }
111 WLOGI("end drag");
112 }
113
GetHitWindow(DisplayId id,PointInfo point)114 sptr<WindowNode> DragController::GetHitWindow(DisplayId id, PointInfo point)
115 {
116 // Need get display by point
117 if (id == DISPLAY_ID_INVALID) {
118 WLOGFE("Get invalid display");
119 return nullptr;
120 }
121 sptr<WindowNodeContainer> container = windowRoot_->GetOrCreateWindowNodeContainer(id);
122 if (container == nullptr) {
123 WLOGFE("get container failed %{public}" PRIu64"", id);
124 return nullptr;
125 }
126
127 std::vector<sptr<WindowNode>> windowNodes;
128 container->TraverseContainer(windowNodes);
129 for (auto windowNode : windowNodes) {
130 if (windowNode->GetWindowType() >= WindowType::WINDOW_TYPE_PANEL) {
131 continue;
132 }
133 if (WindowHelper::IsPointInTargetRect(point.x, point.y, windowNode->GetWindowRect())) {
134 return windowNode;
135 }
136 }
137 return nullptr;
138 }
139
GetHitPoint(uint32_t windowId,PointInfo & point)140 bool DragController::GetHitPoint(uint32_t windowId, PointInfo& point)
141 {
142 sptr<WindowNode> windowNode = windowRoot_->GetWindowNode(windowId);
143 if (windowNode == nullptr || windowNode->GetWindowType() != WindowType::WINDOW_TYPE_DRAGGING_EFFECT) {
144 WLOGFE("Get hit point failed");
145 return false;
146 }
147 sptr<WindowProperty> property = windowNode->GetWindowProperty();
148 point.x = property->GetWindowRect().posX_ + property->GetHitOffset().x;
149 point.y = property->GetWindowRect().posY_ + property->GetHitOffset().y;
150 return true;
151 }
152
OnInputEvent(std::shared_ptr<MMI::KeyEvent> keyEvent) const153 void DragInputEventListener::OnInputEvent(std::shared_ptr<MMI::KeyEvent> keyEvent) const
154 {
155 if (keyEvent == nullptr) {
156 WLOGFE("KeyEvent is nullptr");
157 return;
158 }
159 uint32_t windowId = static_cast<uint32_t>(keyEvent->GetAgentWindowId());
160 WLOGFD("[WMS] Receive keyEvent, windowId: %{public}u", windowId);
161 keyEvent->MarkProcessed();
162 }
163
OnInputEvent(std::shared_ptr<MMI::AxisEvent> axisEvent) const164 void DragInputEventListener::OnInputEvent(std::shared_ptr<MMI::AxisEvent> axisEvent) const
165 {
166 if (axisEvent == nullptr) {
167 WLOGFE("AxisEvent is nullptr");
168 return;
169 };
170 WLOGFD("[WMS] Receive axisEvent, windowId: %{public}u", axisEvent->GetAgentWindowId());
171 axisEvent->MarkProcessed();
172 }
173
OnInputEvent(std::shared_ptr<MMI::PointerEvent> pointerEvent) const174 void DragInputEventListener::OnInputEvent(std::shared_ptr<MMI::PointerEvent> pointerEvent) const
175 {
176 if (pointerEvent == nullptr) {
177 WLOGFE("PointerEvent is nullptr");
178 return;
179 }
180 uint32_t windowId = static_cast<uint32_t>(pointerEvent->GetAgentWindowId());
181 WLOGFD("[WMS] Receive pointerEvent, windowId: %{public}u", windowId);
182
183 WindowInnerManager::GetInstance().ConsumePointerEvent(pointerEvent);
184 }
185
SetInputEventConsumer()186 void MoveDragController::SetInputEventConsumer()
187 {
188 if (!inputListener_ || !inputEventHandler_) {
189 WLOGFE("InputListener or inputEventHandler is nullptr");
190 return;
191 }
192 MMI::InputManager::GetInstance()->SetWindowInputEventConsumer(inputListener_, inputEventHandler_);
193 }
194
SetWindowRoot(const sptr<WindowRoot> & windowRoot)195 void MoveDragController::SetWindowRoot(const sptr<WindowRoot>& windowRoot)
196 {
197 windowRoot_ = windowRoot;
198 }
199
Init()200 bool MoveDragController::Init()
201 {
202 // create handler for input event
203 inputEventHandler_ = std::make_shared<AppExecFwk::EventHandler>(
204 AppExecFwk::EventRunner::Create(INNER_WM_INPUT_THREAD_NAME));
205 if (inputEventHandler_ == nullptr) {
206 return false;
207 }
208 int ret = HiviewDFX::Watchdog::GetInstance().AddThread(INNER_WM_INPUT_THREAD_NAME, inputEventHandler_);
209 if (ret != 0) {
210 WLOGFE("Add watchdog thread failed");
211 }
212 inputListener_ = std::make_shared<DragInputEventListener>(DragInputEventListener());
213 SetInputEventConsumer();
214 return true;
215 }
216
Stop()217 void MoveDragController::Stop()
218 {
219 if (inputEventHandler_ != nullptr) {
220 inputEventHandler_.reset();
221 }
222 }
223
HandleReadyToMoveOrDrag(uint32_t windowId,sptr<WindowProperty> & windowProperty,sptr<MoveDragProperty> & moveDragProperty)224 void MoveDragController::HandleReadyToMoveOrDrag(uint32_t windowId, sptr<WindowProperty>& windowProperty,
225 sptr<MoveDragProperty>& moveDragProperty)
226 {
227 SetActiveWindowId(windowId);
228 SetWindowProperty(windowProperty);
229 SetDragProperty(moveDragProperty);
230 }
231
HandleEndUpMovingOrDragging(uint32_t windowId)232 void MoveDragController::HandleEndUpMovingOrDragging(uint32_t windowId)
233 {
234 if (activeWindowId_ != windowId) {
235 WLOGFE("end up moving or dragging failed, windowId: %{public}u", windowId);
236 return;
237 }
238 ResetMoveOrDragState();
239 }
240
HandleWindowRemovedOrDestroyed(uint32_t windowId)241 void MoveDragController::HandleWindowRemovedOrDestroyed(uint32_t windowId)
242 {
243 if (GetMoveDragProperty() == nullptr) {
244 return;
245 }
246 if (!(GetMoveDragProperty()->startMoveFlag_ || GetMoveDragProperty()->startDragFlag_)) {
247 return;
248 }
249
250 {
251 std::lock_guard<std::mutex> lock(mtx_);
252 auto iter = vsyncStationMap_.find(windowId);
253 if (iter != vsyncStationMap_.end()) {
254 auto vsyncStation = iter->second;
255 vsyncStation->RemoveCallback();
256 vsyncStationMap_.erase(windowId);
257 }
258 }
259
260 ResetMoveOrDragState();
261 }
262
ConvertPointerPosToDisplayGroupPos(DisplayId displayId,int32_t & posX,int32_t & posY)263 void MoveDragController::ConvertPointerPosToDisplayGroupPos(DisplayId displayId, int32_t& posX, int32_t& posY)
264 {
265 auto displayRect = DisplayGroupInfo::GetInstance().GetDisplayRect(displayId);
266 posX += displayRect.posX_;
267 posY += displayRect.posY_;
268 }
269
HandleDisplayLimitRectChange(const std::map<DisplayId,Rect> & limitRectMap)270 void MoveDragController::HandleDisplayLimitRectChange(const std::map<DisplayId, Rect>& limitRectMap)
271 {
272 limitRectMap_.clear();
273 for (auto& elem : limitRectMap) {
274 limitRectMap_.insert(elem);
275 }
276 }
277
ConsumePointerEvent(const std::shared_ptr<MMI::PointerEvent> & pointerEvent)278 void MoveDragController::ConsumePointerEvent(const std::shared_ptr<MMI::PointerEvent>& pointerEvent)
279 {
280 if (pointerEvent == nullptr) {
281 WLOGFE("pointerEvent is nullptr or is handling pointer event");
282 return;
283 }
284 if (pointerEvent->GetPointerAction() == MMI::PointerEvent::POINTER_ACTION_MOVE) {
285 moveEvent_ = pointerEvent;
286 uint32_t windowId = static_cast<uint32_t>(pointerEvent->GetAgentWindowId());
287 auto vsyncStation = GetVsyncStationByWindowId(windowId);
288 if (vsyncStation != nullptr) {
289 vsyncStation->RequestVsync(vsyncCallback_);
290 }
291 } else {
292 WLOGFD("[WMS] Dispatch non-move event, action: %{public}d", pointerEvent->GetPointerAction());
293 HandlePointerEvent(pointerEvent);
294 pointerEvent->MarkProcessed();
295 }
296 }
297
OnReceiveVsync(int64_t timeStamp)298 void MoveDragController::OnReceiveVsync(int64_t timeStamp)
299 {
300 if (moveEvent_ == nullptr) {
301 WLOGFE("moveEvent is nullptr");
302 return;
303 }
304 WLOGFD("[OnReceiveVsync] receive move event, action: %{public}d", moveEvent_->GetPointerAction());
305 HandlePointerEvent(moveEvent_);
306 moveEvent_->MarkProcessed();
307 }
308
GetHotZoneRect()309 Rect MoveDragController::GetHotZoneRect()
310 {
311 auto startPointPosX = moveDragProperty_->startPointPosX_;
312 auto startPointPosY = moveDragProperty_->startPointPosY_;
313 ConvertPointerPosToDisplayGroupPos(moveDragProperty_->targetDisplayId_, startPointPosX, startPointPosY);
314
315 Rect hotZoneRect;
316 const auto& startRectExceptCorner = moveDragProperty_->startRectExceptCorner_;
317 const auto& startRectExceptFrame = moveDragProperty_->startRectExceptFrame_;
318 if ((startPointPosX > startRectExceptCorner.posX_ &&
319 (startPointPosX < startRectExceptCorner.posX_ +
320 static_cast<int32_t>(startRectExceptCorner.width_))) &&
321 (startPointPosY > startRectExceptCorner.posY_ &&
322 (startPointPosY < startRectExceptCorner.posY_ +
323 static_cast<int32_t>(startRectExceptCorner.height_)))) {
324 hotZoneRect = startRectExceptFrame; // drag type: left/right/top/bottom
325 } else {
326 hotZoneRect = startRectExceptCorner; // drag type: left_top/right_top/left_bottom/right_bottom
327 }
328 return hotZoneRect;
329 }
330
CheckWindowRect(DisplayId displayId,float vpr,const Rect & rect)331 bool MoveDragController::CheckWindowRect(DisplayId displayId, float vpr, const Rect& rect)
332 {
333 uint32_t titleBarHeight = static_cast<uint32_t>(WINDOW_TITLE_BAR_HEIGHT * vpr);
334 auto iter = limitRectMap_.find(displayId);
335 Rect limitRect;
336 if (iter != limitRectMap_.end()) {
337 limitRect = iter->second;
338 }
339 if (WindowHelper::IsEmptyRect(limitRect) || MathHelper::NearZero(vpr)) {
340 return true; // If limitRect is empty, we can't use limitRect to check window rect
341 }
342
343 if ((rect.posX_ > static_cast<int32_t>(limitRect.posX_ + limitRect.width_ - titleBarHeight)) ||
344 (rect.posX_ + static_cast<int32_t>(rect.width_) <
345 static_cast<int32_t>(limitRect.posX_ + titleBarHeight)) ||
346 (rect.posY_ < limitRect.posY_) ||
347 (rect.posY_ > static_cast<int32_t>(limitRect.posY_ + limitRect.height_ - titleBarHeight))) {
348 WLOGFD("[WMS] Invalid window rect, id: %{public}u, rect: [%{public}d, %{public}d, %{public}d, %{public}d]",
349 windowProperty_->GetWindowId(), rect.posX_, rect.posY_, rect.width_, rect.height_);
350 return false;
351 }
352 return true;
353 }
354
CalculateNewWindowRect(Rect & newRect,DisplayId displayId,int32_t posX,int32_t posY)355 void MoveDragController::CalculateNewWindowRect(Rect& newRect, DisplayId displayId, int32_t posX, int32_t posY)
356 {
357 auto startPointPosX = moveDragProperty_->startPointPosX_;
358 auto startPointPosY = moveDragProperty_->startPointPosY_;
359 ConvertPointerPosToDisplayGroupPos(moveDragProperty_->targetDisplayId_, startPointPosX, startPointPosY);
360 const auto& startPointRect = moveDragProperty_->startPointRect_;
361 Rect hotZoneRect = GetHotZoneRect();
362 int32_t diffX = posX - startPointPosX;
363 int32_t diffY = posY - startPointPosY;
364
365 float vpr = DisplayGroupInfo::GetInstance().GetDisplayVirtualPixelRatio(displayId);
366 if (MathHelper::NearZero(vpr)) {
367 return;
368 }
369 uint32_t minWidth = static_cast<uint32_t>(MIN_FLOATING_WIDTH * vpr);
370 uint32_t minHeight = static_cast<uint32_t>(MIN_FLOATING_HEIGHT * vpr);
371 if (startPointPosX <= hotZoneRect.posX_) {
372 if (diffX > static_cast<int32_t>(startPointRect.width_ - minWidth)) {
373 diffX = static_cast<int32_t>(startPointRect.width_ - minWidth);
374 }
375 newRect.posX_ += diffX;
376 newRect.width_ = static_cast<uint32_t>(static_cast<int32_t>(newRect.width_) - diffX);
377 } else if (startPointPosX >= hotZoneRect.posX_ + static_cast<int32_t>(hotZoneRect.width_)) {
378 if (diffX < 0 && (-diffX > static_cast<int32_t>(startPointRect.width_ - minWidth))) {
379 diffX = -(static_cast<int32_t>(startPointRect.width_ - minWidth));
380 }
381 newRect.width_ = static_cast<uint32_t>(static_cast<int32_t>(newRect.width_) + diffX);
382 }
383 if (startPointPosY <= hotZoneRect.posY_) {
384 if (diffY > static_cast<int32_t>(startPointRect.height_ - minHeight)) {
385 diffY = static_cast<int32_t>(startPointRect.height_ - minHeight);
386 }
387 newRect.posY_ += diffY;
388 newRect.height_ = static_cast<uint32_t>(static_cast<int32_t>(newRect.height_) - diffY);
389 } else if (startPointPosY >= hotZoneRect.posY_ + static_cast<int32_t>(hotZoneRect.height_)) {
390 if (diffY < 0 && (-diffY > static_cast<int32_t>(startPointRect.height_ - minHeight))) {
391 diffY = -(static_cast<int32_t>(startPointRect.height_ - minHeight));
392 }
393 newRect.height_ = static_cast<uint32_t>(static_cast<int32_t>(newRect.height_) + diffY);
394 }
395 }
396
HandleDragEvent(DisplayId displayId,int32_t posX,int32_t posY,int32_t pointId,int32_t sourceType)397 void MoveDragController::HandleDragEvent(DisplayId displayId, int32_t posX, int32_t posY,
398 int32_t pointId, int32_t sourceType)
399 {
400 if (moveDragProperty_ == nullptr || !moveDragProperty_->startDragFlag_ ||
401 (pointId != moveDragProperty_->startPointerId_) || (sourceType != moveDragProperty_->sourceType_)) {
402 return;
403 }
404
405 Rect newRect = moveDragProperty_->startPointRect_;
406 CalculateNewWindowRect(newRect, displayId, posX, posY);
407
408 if (!CheckWindowRect(displayId, DisplayGroupInfo::GetInstance().GetDisplayVirtualPixelRatio(displayId), newRect)) {
409 return;
410 }
411
412 WLOGFD("[WMS] HandleDragEvent, id: %{public}u, newRect: [%{public}d, %{public}d, %{public}d, %{public}d]",
413 windowProperty_->GetWindowId(), newRect.posX_, newRect.posY_, newRect.width_, newRect.height_);
414 windowProperty_->SetRequestRect(newRect);
415 windowProperty_->SetWindowSizeChangeReason(WindowSizeChangeReason::DRAG);
416 windowProperty_->SetDragType(moveDragProperty_->dragType_);
417 WindowManagerService::GetInstance().UpdateProperty(windowProperty_, PropertyChangeAction::ACTION_UPDATE_RECT, true);
418 }
419
HandleMoveEvent(DisplayId displayId,int32_t posX,int32_t posY,int32_t pointId,int32_t sourceType)420 void MoveDragController::HandleMoveEvent(DisplayId displayId, int32_t posX, int32_t posY,
421 int32_t pointId, int32_t sourceType)
422 {
423 if (moveDragProperty_ == nullptr) {
424 return;
425 }
426 if (!moveDragProperty_->startMoveFlag_ ||
427 (pointId != moveDragProperty_->startPointerId_) ||
428 (sourceType != moveDragProperty_->sourceType_)) {
429 return;
430 }
431 auto startPointPosX = moveDragProperty_->startPointPosX_;
432 auto startPointPosY = moveDragProperty_->startPointPosY_;
433 ConvertPointerPosToDisplayGroupPos(moveDragProperty_->targetDisplayId_, startPointPosX, startPointPosY);
434 int32_t targetX = moveDragProperty_->startPointRect_.posX_ + (posX - startPointPosX);
435 int32_t targetY = moveDragProperty_->startPointRect_.posY_ + (posY - startPointPosY);
436
437 const Rect& oriRect = moveDragProperty_->startPointRect_;
438 Rect newRect = { targetX, targetY, oriRect.width_, oriRect.height_ };
439 if (limitRectMap_.find(displayId) != limitRectMap_.end()) {
440 newRect.posY_ = std::max(newRect.posY_, limitRectMap_[displayId].posY_);
441 }
442 WLOGFD("[WMS] HandleMoveEvent, id: %{public}u, newRect: [%{public}d, %{public}d, %{public}d, %{public}d]",
443 windowProperty_->GetWindowId(), newRect.posX_, newRect.posY_, newRect.width_, newRect.height_);
444 windowProperty_->SetRequestRect(newRect);
445 windowProperty_->SetWindowSizeChangeReason(WindowSizeChangeReason::DRAG_MOVE);
446 WindowManagerService::GetInstance().UpdateProperty(windowProperty_, PropertyChangeAction::ACTION_UPDATE_RECT, true);
447 }
448
HandlePointerEvent(const std::shared_ptr<MMI::PointerEvent> & pointerEvent)449 void MoveDragController::HandlePointerEvent(const std::shared_ptr<MMI::PointerEvent>& pointerEvent)
450 {
451 if (windowProperty_) {
452 windowProperty_->UpdatePointerEvent(pointerEvent);
453 }
454 MMI::PointerEvent::PointerItem pointerItem;
455 int32_t pointId = pointerEvent->GetPointerId();
456 int32_t sourceType = pointerEvent->GetSourceType();
457 if (!pointerEvent->GetPointerItem(pointId, pointerItem) ||
458 (sourceType == MMI::PointerEvent::SOURCE_TYPE_MOUSE &&
459 pointerEvent->GetButtonId() != MMI::PointerEvent::MOUSE_BUTTON_LEFT)) {
460 WLOGFW("invalid pointerEvent");
461 return;
462 }
463
464 int32_t pointPosX = pointerItem.GetDisplayX();
465 int32_t pointPosY = pointerItem.GetDisplayY();
466 int32_t action = pointerEvent->GetPointerAction();
467 int32_t targetDisplayId = pointerEvent->GetTargetDisplayId();
468 ConvertPointerPosToDisplayGroupPos(targetDisplayId, pointPosX, pointPosY);
469 switch (action) {
470 case MMI::PointerEvent::POINTER_ACTION_DOWN:
471 case MMI::PointerEvent::POINTER_ACTION_BUTTON_DOWN: {
472 if (pointId == moveDragProperty_->startPointerId_ && sourceType == moveDragProperty_->sourceType_) {
473 moveDragProperty_->startMoveFlag_ = false;
474 moveDragProperty_->startDragFlag_ = false;
475 }
476 TLOGD(WmsLogTag::WMS_EVENT, "windowId:%{public}u, pointId:%{public}d, sourceType:%{public}d, "
477 "hasPointStarted:%{public}d, startMove:%{public}d, startDrag:%{public}d, targetDisplayId:"
478 "%{public}d, pointPos:[%{private}d, %{private}d]", activeWindowId_, pointId, sourceType,
479 moveDragProperty_->pointEventStarted_, moveDragProperty_->startMoveFlag_,
480 moveDragProperty_->startDragFlag_, targetDisplayId, pointPosX, pointPosY);
481 break;
482 }
483 // ready to move or drag
484 case MMI::PointerEvent::POINTER_ACTION_MOVE: {
485 HandleMoveEvent(targetDisplayId, pointPosX, pointPosY, pointId, sourceType);
486 HandleDragEvent(targetDisplayId, pointPosX, pointPosY, pointId, sourceType);
487 break;
488 }
489 // End move or drag
490 case MMI::PointerEvent::POINTER_ACTION_UP:
491 case MMI::PointerEvent::POINTER_ACTION_BUTTON_UP:
492 case MMI::PointerEvent::POINTER_ACTION_CANCEL: {
493 WindowManagerService::GetInstance().NotifyWindowClientPointUp(activeWindowId_, pointerEvent);
494 WLOGFD("[Server Point Up/Cancel]: windowId: %{public}u, action: %{public}d, sourceType: %{public}d",
495 activeWindowId_, action, sourceType);
496 break;
497 }
498 default:
499 break;
500 }
501 }
502
SetDragProperty(const sptr<MoveDragProperty> & moveDragProperty)503 void MoveDragController::SetDragProperty(const sptr<MoveDragProperty>& moveDragProperty)
504 {
505 moveDragProperty_->CopyFrom(moveDragProperty);
506 }
507
SetWindowProperty(const sptr<WindowProperty> & windowProperty)508 void MoveDragController::SetWindowProperty(const sptr<WindowProperty>& windowProperty)
509 {
510 windowProperty_->CopyFrom(windowProperty);
511 }
512
GetMoveDragProperty() const513 const sptr<MoveDragProperty>& MoveDragController::GetMoveDragProperty() const
514 {
515 return moveDragProperty_;
516 }
517
GetWindowProperty() const518 const sptr<WindowProperty>& MoveDragController::GetWindowProperty() const
519 {
520 return windowProperty_;
521 }
522
ResetMoveOrDragState()523 void MoveDragController::ResetMoveOrDragState()
524 {
525 activeWindowId_ = INVALID_WINDOW_ID;
526 auto moveDragProperty = new MoveDragProperty();
527 SetDragProperty(moveDragProperty);
528 }
529
SetActiveWindowId(uint32_t activeWindowId)530 void MoveDragController::SetActiveWindowId(uint32_t activeWindowId)
531 {
532 activeWindowId_ = activeWindowId;
533 }
534
GetActiveWindowId() const535 uint32_t MoveDragController::GetActiveWindowId() const
536 {
537 return activeWindowId_;
538 }
539
GetVsyncStationByWindowId(uint32_t windowId)540 std::shared_ptr<VsyncStation> MoveDragController::GetVsyncStationByWindowId(uint32_t windowId)
541 {
542 {
543 std::lock_guard<std::mutex> lock(mtx_);
544 auto iter = vsyncStationMap_.find(windowId);
545 if (iter != vsyncStationMap_.end()) {
546 return iter->second;
547 }
548 }
549
550 if (windowRoot_ == nullptr) {
551 TLOGE(WmsLogTag::WMS_MAIN, "Get vsync station failed, windowRoot is nullptr");
552 return nullptr;
553 }
554
555 sptr<WindowNode> node = windowRoot_->GetWindowNode(windowId);
556 if (node == nullptr || node->surfaceNode_ == nullptr) {
557 TLOGE(WmsLogTag::WMS_MAIN, "Get vsync station failed, surfaceNode is nullptr");
558 return nullptr;
559 }
560
561 auto vsyncStation = std::make_shared<VsyncStation>(node->surfaceNode_->GetId(), inputEventHandler_);
562 if (vsyncStation == nullptr) {
563 TLOGE(WmsLogTag::WMS_MAIN, "Get vsync station failed, create vsyncStation is nullptr");
564 return nullptr;
565 }
566
567 {
568 std::lock_guard<std::mutex> lock(mtx_);
569 vsyncStationMap_.emplace(windowId, vsyncStation);
570 }
571
572 return vsyncStation;
573 }
574 }
575 }
576