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_WINDOW_SCENE_SESSION_UTILS_H
17 #define OHOS_ROSEN_WINDOW_SCENE_SESSION_UTILS_H
18
19 #include "wm_common_inner.h"
20
21 namespace OHOS::Rosen {
22 namespace SessionUtils {
23
ToLayoutWidth(const int32_t winWidth,float vpr)24 inline float ToLayoutWidth(const int32_t winWidth, float vpr)
25 {
26 return winWidth - 2 * WINDOW_FRAME_WIDTH * vpr; // 2: left and right edge
27 }
28
ToLayoutHeight(const int32_t winHeight,float vpr)29 inline float ToLayoutHeight(const int32_t winHeight, float vpr)
30 {
31 return winHeight - (WINDOW_FRAME_WIDTH + WINDOW_TITLE_BAR_HEIGHT) * vpr;
32 }
33
ToWinWidth(const int32_t layoutWidth,float vpr)34 inline float ToWinWidth(const int32_t layoutWidth, float vpr)
35 {
36 return layoutWidth + 2 * WINDOW_FRAME_WIDTH * vpr; // 2: left and right edge
37 }
38
ToWinHeight(const int32_t layoutHeight,float vpr)39 inline float ToWinHeight(const int32_t layoutHeight, float vpr)
40 {
41 return layoutHeight + (WINDOW_FRAME_WIDTH + WINDOW_TITLE_BAR_HEIGHT) * vpr;
42 }
43
CalcFloatWindowRectLimits(const WindowLimits & limits,uint32_t maxFloatingWindowSize,float vpr,int32_t & minWidth,int32_t & maxWidth,int32_t & minHeight,int32_t & maxHeight)44 inline void CalcFloatWindowRectLimits(const WindowLimits& limits, uint32_t maxFloatingWindowSize, float vpr,
45 int32_t& minWidth, int32_t& maxWidth, int32_t& minHeight, int32_t& maxHeight)
46 {
47 minWidth = limits.minWidth_;
48 maxWidth = (limits.maxWidth_ == 0 || limits.maxWidth_ >= INT32_MAX) ? INT32_MAX : limits.maxWidth_;
49 minHeight = limits.minHeight_;
50 maxHeight = (limits.maxHeight_ == 0 || limits.maxHeight_ >= INT32_MAX) ? INT32_MAX : limits.maxHeight_;
51 minWidth = std::max(minWidth, static_cast<int32_t>(MIN_FLOATING_WIDTH * vpr));
52 maxWidth = std::min(maxWidth, static_cast<int32_t>(maxFloatingWindowSize * vpr));
53 minHeight = std::max(minHeight, static_cast<int32_t>(MIN_FLOATING_HEIGHT * vpr));
54 maxHeight = std::min(maxHeight, static_cast<int32_t>(maxFloatingWindowSize * vpr));
55 }
56
57 } // namespace SessionUtils
58 } // namespace OHOS::Rosen
59 #endif // OHOS_ROSEN_WINDOW_SCENE_SESSION_UTILS_H
60