1e0dac50fSopenharmony_ci/* 2e0dac50fSopenharmony_ci * Copyright (c) 2021-2023 Huawei Device Co., Ltd. 3e0dac50fSopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License"); 4e0dac50fSopenharmony_ci * you may not use this file except in compliance with the License. 5e0dac50fSopenharmony_ci * You may obtain a copy of the License at 6e0dac50fSopenharmony_ci * 7e0dac50fSopenharmony_ci * http://www.apache.org/licenses/LICENSE-2.0 8e0dac50fSopenharmony_ci * 9e0dac50fSopenharmony_ci * Unless required by applicable law or agreed to in writing, software 10e0dac50fSopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS, 11e0dac50fSopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12e0dac50fSopenharmony_ci * See the License for the specific language governing permissions and 13e0dac50fSopenharmony_ci * limitations under the License. 14e0dac50fSopenharmony_ci */ 15e0dac50fSopenharmony_ci 16e0dac50fSopenharmony_ci#ifndef OHOS_ROSEN_DRAG_CONTROLLER_H 17e0dac50fSopenharmony_ci#define OHOS_ROSEN_DRAG_CONTROLLER_H 18e0dac50fSopenharmony_ci 19e0dac50fSopenharmony_ci#include <refbase.h> 20e0dac50fSopenharmony_ci 21e0dac50fSopenharmony_ci#include "display_group_info.h" 22e0dac50fSopenharmony_ci#include "display_info.h" 23e0dac50fSopenharmony_ci#include "event_handler.h" 24e0dac50fSopenharmony_ci#include "event_runner.h" 25e0dac50fSopenharmony_ci#include "input_manager.h" 26e0dac50fSopenharmony_ci#include "pointer_event.h" 27e0dac50fSopenharmony_ci#include "vsync_station.h" 28e0dac50fSopenharmony_ci#include "window_root.h" 29e0dac50fSopenharmony_ci#include "wm_common.h" 30e0dac50fSopenharmony_ci 31e0dac50fSopenharmony_cinamespace OHOS { 32e0dac50fSopenharmony_cinamespace Rosen { 33e0dac50fSopenharmony_ciusing EventRunner = OHOS::AppExecFwk::EventRunner; 34e0dac50fSopenharmony_ciusing EventHandler = OHOS::AppExecFwk::EventHandler; 35e0dac50fSopenharmony_ci/* 36e0dac50fSopenharmony_ci * DragController is the class which is used to handle drag cross window 37e0dac50fSopenharmony_ci */ 38e0dac50fSopenharmony_ciclass DragController : public RefBase { 39e0dac50fSopenharmony_cipublic: 40e0dac50fSopenharmony_ci explicit DragController(sptr<WindowRoot>& root) : windowRoot_(root) {} 41e0dac50fSopenharmony_ci ~DragController() = default; 42e0dac50fSopenharmony_ci void StartDrag(uint32_t windowId); 43e0dac50fSopenharmony_ci void UpdateDragInfo(uint32_t windowId); 44e0dac50fSopenharmony_ci void FinishDrag(uint32_t windowId); 45e0dac50fSopenharmony_ci 46e0dac50fSopenharmony_ciprivate: 47e0dac50fSopenharmony_ci sptr<WindowNode> GetHitWindow(DisplayId id, const PointInfo point); 48e0dac50fSopenharmony_ci bool GetHitPoint(uint32_t windowId, PointInfo& point); 49e0dac50fSopenharmony_ci sptr<WindowRoot> windowRoot_; 50e0dac50fSopenharmony_ci uint64_t hitWindowId_ = 0; 51e0dac50fSopenharmony_ci}; 52e0dac50fSopenharmony_ci 53e0dac50fSopenharmony_ciclass DragInputEventListener : public MMI::IInputEventConsumer { 54e0dac50fSopenharmony_cipublic: 55e0dac50fSopenharmony_ci DragInputEventListener() = default; 56e0dac50fSopenharmony_ci void OnInputEvent(std::shared_ptr<MMI::PointerEvent> pointerEvent) const override; 57e0dac50fSopenharmony_ci void OnInputEvent(std::shared_ptr<MMI::KeyEvent> keyEvent) const override; 58e0dac50fSopenharmony_ci void OnInputEvent(std::shared_ptr<MMI::AxisEvent> axisEvent) const override; 59e0dac50fSopenharmony_ci}; 60e0dac50fSopenharmony_ci 61e0dac50fSopenharmony_ci/* 62e0dac50fSopenharmony_ci * MoveDragController is the class which is used to handle move or drag floating window 63e0dac50fSopenharmony_ci */ 64e0dac50fSopenharmony_ciclass MoveDragController : public RefBase { 65e0dac50fSopenharmony_cipublic: 66e0dac50fSopenharmony_ci MoveDragController() : windowProperty_(new WindowProperty()), moveDragProperty_(new MoveDragProperty()) 67e0dac50fSopenharmony_ci { 68e0dac50fSopenharmony_ci vsyncCallback_->onCallback = 69e0dac50fSopenharmony_ci [this](int64_t timeStamp, int64_t _) { this->OnReceiveVsync(timeStamp); }; 70e0dac50fSopenharmony_ci } 71e0dac50fSopenharmony_ci ~MoveDragController() = default; 72e0dac50fSopenharmony_ci 73e0dac50fSopenharmony_ci bool Init(); 74e0dac50fSopenharmony_ci void Stop(); 75e0dac50fSopenharmony_ci void HandleReadyToMoveOrDrag(uint32_t windowId, sptr<WindowProperty>& windowProperty, 76e0dac50fSopenharmony_ci sptr<MoveDragProperty>& moveDragProperty); 77e0dac50fSopenharmony_ci void HandleEndUpMovingOrDragging(uint32_t windowId); 78e0dac50fSopenharmony_ci void HandleWindowRemovedOrDestroyed(uint32_t windowId); 79e0dac50fSopenharmony_ci void ConsumePointerEvent(const std::shared_ptr<MMI::PointerEvent>& pointerEvent); 80e0dac50fSopenharmony_ci uint32_t GetActiveWindowId() const; 81e0dac50fSopenharmony_ci void HandleDisplayLimitRectChange(const std::map<DisplayId, Rect>& limitRectMap); 82e0dac50fSopenharmony_ci void SetInputEventConsumer(); 83e0dac50fSopenharmony_ci void SetWindowRoot(const sptr<WindowRoot>& windowRoot); 84e0dac50fSopenharmony_ci 85e0dac50fSopenharmony_ciprivate: 86e0dac50fSopenharmony_ci void SetDragProperty(const sptr<MoveDragProperty>& moveDragProperty); 87e0dac50fSopenharmony_ci void SetWindowProperty(const sptr<WindowProperty>& windowProperty); 88e0dac50fSopenharmony_ci void SetActiveWindowId(uint32_t); 89e0dac50fSopenharmony_ci const sptr<MoveDragProperty>& GetMoveDragProperty() const; 90e0dac50fSopenharmony_ci const sptr<WindowProperty>& GetWindowProperty() const; 91e0dac50fSopenharmony_ci Rect GetHotZoneRect(); 92e0dac50fSopenharmony_ci void ConvertPointerPosToDisplayGroupPos(DisplayId displayId, int32_t& posX, int32_t& posY); 93e0dac50fSopenharmony_ci 94e0dac50fSopenharmony_ci void HandlePointerEvent(const std::shared_ptr<MMI::PointerEvent>& pointerEvent); 95e0dac50fSopenharmony_ci void HandleDragEvent(DisplayId displayId, int32_t posX, int32_t posY, int32_t pointId, int32_t sourceType); 96e0dac50fSopenharmony_ci void HandleMoveEvent(DisplayId displayId, int32_t posX, int32_t posY, int32_t pointId, int32_t sourceType); 97e0dac50fSopenharmony_ci void OnReceiveVsync(int64_t timeStamp); 98e0dac50fSopenharmony_ci void ResetMoveOrDragState(); 99e0dac50fSopenharmony_ci bool CheckWindowRect(DisplayId displayId, float vpr, const Rect& rect); 100e0dac50fSopenharmony_ci void CalculateNewWindowRect(Rect& newRect, DisplayId displayId, int32_t posX, int32_t posY); 101e0dac50fSopenharmony_ci std::shared_ptr<VsyncStation> GetVsyncStationByWindowId(uint32_t windowId); 102e0dac50fSopenharmony_ci 103e0dac50fSopenharmony_ci sptr<WindowRoot> windowRoot_; 104e0dac50fSopenharmony_ci sptr<WindowProperty> windowProperty_; 105e0dac50fSopenharmony_ci sptr<MoveDragProperty> moveDragProperty_; 106e0dac50fSopenharmony_ci uint32_t activeWindowId_ = INVALID_WINDOW_ID; 107e0dac50fSopenharmony_ci std::shared_ptr<MMI::PointerEvent> moveEvent_ = nullptr; 108e0dac50fSopenharmony_ci std::shared_ptr<MMI::IInputEventConsumer> inputListener_ = nullptr; 109e0dac50fSopenharmony_ci std::shared_ptr<VsyncCallback> vsyncCallback_ = std::make_shared<VsyncCallback>(VsyncCallback()); 110e0dac50fSopenharmony_ci std::map<DisplayId, Rect> limitRectMap_; 111e0dac50fSopenharmony_ci std::mutex mtx_; 112e0dac50fSopenharmony_ci std::map<NodeId, std::shared_ptr<VsyncStation>> vsyncStationMap_; 113e0dac50fSopenharmony_ci 114e0dac50fSopenharmony_ci // event handler for input event 115e0dac50fSopenharmony_ci std::shared_ptr<EventHandler> inputEventHandler_; 116e0dac50fSopenharmony_ci const std::string INNER_WM_INPUT_THREAD_NAME = "InnerInputManager"; 117e0dac50fSopenharmony_ci}; 118e0dac50fSopenharmony_ci} 119e0dac50fSopenharmony_ci} 120e0dac50fSopenharmony_ci#endif // OHOS_ROSEN_DRAG_CONTROLLER_H 121e0dac50fSopenharmony_ci 122