1e0dac50fSopenharmony_ci/* 2e0dac50fSopenharmony_ci * Copyright (c) 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_SESSION_HELPER_H 17e0dac50fSopenharmony_ci#define OHOS_ROSEN_SESSION_HELPER_H 18e0dac50fSopenharmony_ci 19e0dac50fSopenharmony_ci#include <pointer_event.h> 20e0dac50fSopenharmony_ci 21e0dac50fSopenharmony_ci#include <string> 22e0dac50fSopenharmony_ci#include "ws_common.h" 23e0dac50fSopenharmony_ci#include "ws_common_inner.h" 24e0dac50fSopenharmony_ci#include "wm_common.h" 25e0dac50fSopenharmony_ci#include "wm_common_inner.h" 26e0dac50fSopenharmony_ci 27e0dac50fSopenharmony_cinamespace OHOS { 28e0dac50fSopenharmony_cinamespace Rosen { 29e0dac50fSopenharmony_ciclass SessionHelper { 30e0dac50fSopenharmony_cipublic: 31e0dac50fSopenharmony_ci static WSRect GetOverlap(const WSRect& rect1, const WSRect& rect2, int offsetX, int offsetY) 32e0dac50fSopenharmony_ci { 33e0dac50fSopenharmony_ci int32_t x_begin = std::max(rect1.posX_, rect2.posX_); 34e0dac50fSopenharmony_ci int32_t x_end = std::min(rect1.posX_ + static_cast<int32_t>(rect1.width_), 35e0dac50fSopenharmony_ci rect2.posX_ + static_cast<int32_t>(rect2.width_)); 36e0dac50fSopenharmony_ci int32_t y_begin = std::max(rect1.posY_, rect2.posY_); 37e0dac50fSopenharmony_ci int32_t y_end = std::min(rect1.posY_ + static_cast<int32_t>(rect1.height_), 38e0dac50fSopenharmony_ci rect2.posY_ + static_cast<int32_t>(rect2.height_)); 39e0dac50fSopenharmony_ci if (y_begin >= y_end || x_begin >= x_end) { 40e0dac50fSopenharmony_ci return { 0, 0, 0, 0 }; 41e0dac50fSopenharmony_ci } 42e0dac50fSopenharmony_ci return { x_begin - offsetX, y_begin - offsetY, 43e0dac50fSopenharmony_ci static_cast<uint32_t>(x_end - x_begin), static_cast<uint32_t>(y_end - y_begin) }; 44e0dac50fSopenharmony_ci } 45e0dac50fSopenharmony_ci 46e0dac50fSopenharmony_ci static inline bool IsEmptyRect(const WSRect& r) 47e0dac50fSopenharmony_ci { 48e0dac50fSopenharmony_ci return (r.posX_ == 0 && r.posY_ == 0 && r.width_ == 0 && r.height_ == 0); 49e0dac50fSopenharmony_ci } 50e0dac50fSopenharmony_ci 51e0dac50fSopenharmony_ci static bool IsPointInRect(int32_t pointPosX, int32_t pointPosY, const Rect& rect) 52e0dac50fSopenharmony_ci { 53e0dac50fSopenharmony_ci if ((pointPosX > rect.posX_) && 54e0dac50fSopenharmony_ci (pointPosX < (rect.posX_ + static_cast<int32_t>(rect.width_)) - 1) && 55e0dac50fSopenharmony_ci (pointPosY > rect.posY_) && 56e0dac50fSopenharmony_ci (pointPosY < (rect.posY_ + static_cast<int32_t>(rect.height_)) - 1)) { 57e0dac50fSopenharmony_ci return true; 58e0dac50fSopenharmony_ci } 59e0dac50fSopenharmony_ci return false; 60e0dac50fSopenharmony_ci } 61e0dac50fSopenharmony_ci 62e0dac50fSopenharmony_ci static inline WSRect TransferToWSRect(const Rect& rect) 63e0dac50fSopenharmony_ci { 64e0dac50fSopenharmony_ci WSRect r; 65e0dac50fSopenharmony_ci r.height_ = rect.height_; 66e0dac50fSopenharmony_ci r.width_ = rect.width_; 67e0dac50fSopenharmony_ci r.posX_ = rect.posX_; 68e0dac50fSopenharmony_ci r.posY_ = rect.posY_; 69e0dac50fSopenharmony_ci return r; 70e0dac50fSopenharmony_ci } 71e0dac50fSopenharmony_ci 72e0dac50fSopenharmony_ci static inline Rect TransferToRect(const WSRect& rect) 73e0dac50fSopenharmony_ci { 74e0dac50fSopenharmony_ci Rect r; 75e0dac50fSopenharmony_ci r.height_ = rect.height_; 76e0dac50fSopenharmony_ci r.width_ = rect.width_; 77e0dac50fSopenharmony_ci r.posX_ = rect.posX_; 78e0dac50fSopenharmony_ci r.posY_ = rect.posY_; 79e0dac50fSopenharmony_ci return r; 80e0dac50fSopenharmony_ci } 81e0dac50fSopenharmony_ci 82e0dac50fSopenharmony_ci static inline bool IsBelowSystemWindow(WindowType type) 83e0dac50fSopenharmony_ci { 84e0dac50fSopenharmony_ci return (type >= WindowType::BELOW_APP_SYSTEM_WINDOW_BASE && type < WindowType::BELOW_APP_SYSTEM_WINDOW_END); 85e0dac50fSopenharmony_ci } 86e0dac50fSopenharmony_ci 87e0dac50fSopenharmony_ci static inline bool IsAboveSystemWindow(WindowType type) 88e0dac50fSopenharmony_ci { 89e0dac50fSopenharmony_ci return (type >= WindowType::ABOVE_APP_SYSTEM_WINDOW_BASE && type < WindowType::ABOVE_APP_SYSTEM_WINDOW_END); 90e0dac50fSopenharmony_ci } 91e0dac50fSopenharmony_ci 92e0dac50fSopenharmony_ci static inline bool IsSystemSubWindow(WindowType type) 93e0dac50fSopenharmony_ci { 94e0dac50fSopenharmony_ci return (type >= WindowType::SYSTEM_SUB_WINDOW_BASE && type < WindowType::SYSTEM_SUB_WINDOW_END); 95e0dac50fSopenharmony_ci } 96e0dac50fSopenharmony_ci 97e0dac50fSopenharmony_ci static inline bool IsSystemWindow(WindowType type) 98e0dac50fSopenharmony_ci { 99e0dac50fSopenharmony_ci return (IsBelowSystemWindow(type) || IsAboveSystemWindow(type) || IsSystemSubWindow(type)); 100e0dac50fSopenharmony_ci } 101e0dac50fSopenharmony_ci 102e0dac50fSopenharmony_ci static inline bool IsMainWindow(WindowType type) 103e0dac50fSopenharmony_ci { 104e0dac50fSopenharmony_ci return (type >= WindowType::APP_MAIN_WINDOW_BASE && type < WindowType::APP_MAIN_WINDOW_END); 105e0dac50fSopenharmony_ci } 106e0dac50fSopenharmony_ci 107e0dac50fSopenharmony_ci static inline bool IsSubWindow(WindowType type) 108e0dac50fSopenharmony_ci { 109e0dac50fSopenharmony_ci return (type >= WindowType::APP_SUB_WINDOW_BASE && type < WindowType::APP_SUB_WINDOW_END); 110e0dac50fSopenharmony_ci } 111e0dac50fSopenharmony_ci 112e0dac50fSopenharmony_ci static inline bool IsNonSecureToUIExtension(WindowType type) 113e0dac50fSopenharmony_ci { 114e0dac50fSopenharmony_ci return IsSubWindow(type) || type == WindowType::WINDOW_TYPE_DIALOG; 115e0dac50fSopenharmony_ci } 116e0dac50fSopenharmony_ci 117e0dac50fSopenharmony_ci static AreaType GetAreaType(int32_t pointWinX, int32_t pointWinY, 118e0dac50fSopenharmony_ci int32_t sourceType, int outside, float vpr, const WSRect& rect) 119e0dac50fSopenharmony_ci { 120e0dac50fSopenharmony_ci int32_t insideCorner = WINDOW_FRAME_CORNER_WIDTH * vpr; 121e0dac50fSopenharmony_ci int32_t insideEdge = WINDOW_FRAME_WIDTH * vpr; 122e0dac50fSopenharmony_ci int32_t leftOut = -outside; 123e0dac50fSopenharmony_ci int32_t leftIn = insideEdge; 124e0dac50fSopenharmony_ci int32_t leftCorner = insideCorner; 125e0dac50fSopenharmony_ci int32_t rightCorner = rect.width_ - insideCorner; 126e0dac50fSopenharmony_ci int32_t rightIn = rect.width_ - insideEdge; 127e0dac50fSopenharmony_ci int32_t rightOut = rect.width_ + outside; 128e0dac50fSopenharmony_ci int32_t topOut = -outside; 129e0dac50fSopenharmony_ci int32_t topIn = insideEdge; 130e0dac50fSopenharmony_ci int32_t topCorner = insideCorner; 131e0dac50fSopenharmony_ci int32_t bottomCorner = rect.height_ - insideCorner; 132e0dac50fSopenharmony_ci int32_t bottomIn = rect.height_ - insideEdge; 133e0dac50fSopenharmony_ci int32_t bottomOut = rect.height_ + outside; 134e0dac50fSopenharmony_ci 135e0dac50fSopenharmony_ci auto isInRange = [](int32_t min, int32_t max, int32_t value) { return min <= value && value <= max; }; 136e0dac50fSopenharmony_ci 137e0dac50fSopenharmony_ci AreaType type; 138e0dac50fSopenharmony_ci if (isInRange(leftOut, leftCorner, pointWinX) && isInRange(topOut, topCorner, pointWinY)) { 139e0dac50fSopenharmony_ci type = AreaType::LEFT_TOP; 140e0dac50fSopenharmony_ci } else if (isInRange(rightCorner, rightOut, pointWinX) && isInRange(topOut, topCorner, pointWinY)) { 141e0dac50fSopenharmony_ci type = AreaType::RIGHT_TOP; 142e0dac50fSopenharmony_ci } else if (isInRange(rightCorner, rightOut, pointWinX) && isInRange(bottomCorner, bottomOut, pointWinY)) { 143e0dac50fSopenharmony_ci type = AreaType::RIGHT_BOTTOM; 144e0dac50fSopenharmony_ci } else if (isInRange(leftOut, leftCorner, pointWinX) && isInRange(bottomCorner, bottomOut, pointWinY)) { 145e0dac50fSopenharmony_ci type = AreaType::LEFT_BOTTOM; 146e0dac50fSopenharmony_ci } else if (isInRange(leftOut, leftIn, pointWinX)) { 147e0dac50fSopenharmony_ci type = AreaType::LEFT; 148e0dac50fSopenharmony_ci } else if (isInRange(topOut, topIn, pointWinY)) { 149e0dac50fSopenharmony_ci type = AreaType::TOP; 150e0dac50fSopenharmony_ci } else if (isInRange(rightIn, rightOut, pointWinX)) { 151e0dac50fSopenharmony_ci type = AreaType::RIGHT; 152e0dac50fSopenharmony_ci } else if (isInRange(bottomIn, bottomOut, pointWinY)) { 153e0dac50fSopenharmony_ci type = AreaType::BOTTOM; 154e0dac50fSopenharmony_ci } else { 155e0dac50fSopenharmony_ci type = AreaType::UNDEFINED; 156e0dac50fSopenharmony_ci } 157e0dac50fSopenharmony_ci return type; 158e0dac50fSopenharmony_ci } 159e0dac50fSopenharmony_ci}; 160e0dac50fSopenharmony_ci} // Rosen 161e0dac50fSopenharmony_ci} // OHOS 162e0dac50fSopenharmony_ci#endif // OHOS_ROSEN_SESSION_HELPER_H