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