/* * Copyright (c) 2021-2023 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #ifndef OHOS_ROSEN_DRAG_CONTROLLER_H #define OHOS_ROSEN_DRAG_CONTROLLER_H #include #include "display_group_info.h" #include "display_info.h" #include "event_handler.h" #include "event_runner.h" #include "input_manager.h" #include "pointer_event.h" #include "vsync_station.h" #include "window_root.h" #include "wm_common.h" namespace OHOS { namespace Rosen { using EventRunner = OHOS::AppExecFwk::EventRunner; using EventHandler = OHOS::AppExecFwk::EventHandler; /* * DragController is the class which is used to handle drag cross window */ class DragController : public RefBase { public: explicit DragController(sptr& root) : windowRoot_(root) {} ~DragController() = default; void StartDrag(uint32_t windowId); void UpdateDragInfo(uint32_t windowId); void FinishDrag(uint32_t windowId); private: sptr GetHitWindow(DisplayId id, const PointInfo point); bool GetHitPoint(uint32_t windowId, PointInfo& point); sptr windowRoot_; uint64_t hitWindowId_ = 0; }; class DragInputEventListener : public MMI::IInputEventConsumer { public: DragInputEventListener() = default; void OnInputEvent(std::shared_ptr pointerEvent) const override; void OnInputEvent(std::shared_ptr keyEvent) const override; void OnInputEvent(std::shared_ptr axisEvent) const override; }; /* * MoveDragController is the class which is used to handle move or drag floating window */ class MoveDragController : public RefBase { public: MoveDragController() : windowProperty_(new WindowProperty()), moveDragProperty_(new MoveDragProperty()) { vsyncCallback_->onCallback = [this](int64_t timeStamp, int64_t _) { this->OnReceiveVsync(timeStamp); }; } ~MoveDragController() = default; bool Init(); void Stop(); void HandleReadyToMoveOrDrag(uint32_t windowId, sptr& windowProperty, sptr& moveDragProperty); void HandleEndUpMovingOrDragging(uint32_t windowId); void HandleWindowRemovedOrDestroyed(uint32_t windowId); void ConsumePointerEvent(const std::shared_ptr& pointerEvent); uint32_t GetActiveWindowId() const; void HandleDisplayLimitRectChange(const std::map& limitRectMap); void SetInputEventConsumer(); void SetWindowRoot(const sptr& windowRoot); private: void SetDragProperty(const sptr& moveDragProperty); void SetWindowProperty(const sptr& windowProperty); void SetActiveWindowId(uint32_t); const sptr& GetMoveDragProperty() const; const sptr& GetWindowProperty() const; Rect GetHotZoneRect(); void ConvertPointerPosToDisplayGroupPos(DisplayId displayId, int32_t& posX, int32_t& posY); void HandlePointerEvent(const std::shared_ptr& pointerEvent); void HandleDragEvent(DisplayId displayId, int32_t posX, int32_t posY, int32_t pointId, int32_t sourceType); void HandleMoveEvent(DisplayId displayId, int32_t posX, int32_t posY, int32_t pointId, int32_t sourceType); void OnReceiveVsync(int64_t timeStamp); void ResetMoveOrDragState(); bool CheckWindowRect(DisplayId displayId, float vpr, const Rect& rect); void CalculateNewWindowRect(Rect& newRect, DisplayId displayId, int32_t posX, int32_t posY); std::shared_ptr GetVsyncStationByWindowId(uint32_t windowId); sptr windowRoot_; sptr windowProperty_; sptr moveDragProperty_; uint32_t activeWindowId_ = INVALID_WINDOW_ID; std::shared_ptr moveEvent_ = nullptr; std::shared_ptr inputListener_ = nullptr; std::shared_ptr vsyncCallback_ = std::make_shared(VsyncCallback()); std::map limitRectMap_; std::mutex mtx_; std::map> vsyncStationMap_; // event handler for input event std::shared_ptr inputEventHandler_; const std::string INNER_WM_INPUT_THREAD_NAME = "InnerInputManager"; }; } } #endif // OHOS_ROSEN_DRAG_CONTROLLER_H