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 #include "window_manager_service_utils.h"
17 
18 namespace OHOS {
19 namespace Rosen {
20 
IsFixedOrientation(Orientation orientation,WindowMode mode,uint32_t flags)21 bool WmsUtils::IsFixedOrientation(Orientation orientation, WindowMode mode, uint32_t flags)
22 {
23     if (!FIX_ORIENTATION_ENABLE) {
24         return false;
25     }
26     if (flags & static_cast<uint32_t>(WindowFlag::WINDOW_FLAG_NEED_AVOID)) {
27         return false;
28     }
29     if (mode != WindowMode::WINDOW_MODE_FULLSCREEN) {
30         return false;
31     }
32     if (orientation > Orientation::REVERSE_HORIZONTAL) {
33         return false;
34     }
35     if (orientation < Orientation::VERTICAL) {
36         return false;
37     }
38     return true;
39 }
40 
IsExpectedRotateLandscapeWindow(Orientation requestOrientation,DisplayOrientation currentOrientation,uint32_t flags)41 bool WmsUtils::IsExpectedRotateLandscapeWindow(Orientation requestOrientation,
42     DisplayOrientation currentOrientation, uint32_t flags)
43 {
44     if (requestOrientation != Orientation::HORIZONTAL && requestOrientation != Orientation::REVERSE_HORIZONTAL) {
45         return false;
46     }
47     return IsExpectedRotatableWindow(requestOrientation, currentOrientation, flags);
48 }
49 
IsExpectedRotatableWindow(Orientation requestOrientation,DisplayOrientation currentOrientation,WindowMode mode,uint32_t flags,bool restricted)50 bool WmsUtils::IsExpectedRotatableWindow(Orientation requestOrientation,
51     DisplayOrientation currentOrientation, WindowMode mode, uint32_t flags, bool restricted)
52 {
53     if (mode != WindowMode::WINDOW_MODE_FULLSCREEN) {
54         return false;
55     }
56     return IsExpectedRotatableWindow(requestOrientation, currentOrientation, flags, restricted);
57 }
58 
IsExpectedRotatableWindow(Orientation requestOrientation,DisplayOrientation currentOrientation,uint32_t flags,bool restricted)59 bool WmsUtils::IsExpectedRotatableWindow(Orientation requestOrientation,
60     DisplayOrientation currentOrientation, uint32_t flags, bool restricted)
61 {
62     if (!FIX_ORIENTATION_ENABLE) {
63         return false;
64     }
65     if (flags & static_cast<uint32_t>(WindowFlag::WINDOW_FLAG_NEED_AVOID)) {
66         return false;
67     }
68     if (WINDOW_TO_DISPLAY_ORIENTATION_MAP.count(requestOrientation) == 0) {
69         return false;
70     }
71     DisplayOrientation disOrientation = WINDOW_TO_DISPLAY_ORIENTATION_MAP.at(requestOrientation);
72     if (disOrientation == currentOrientation) {
73         return false;
74     }
75     if (restricted && (static_cast<int32_t>(disOrientation) -
76         static_cast<int32_t>(currentOrientation)) % 2 == 0) { // Divided by 2
77         return false;
78     }
79     return true;
80 }
81 }
82 }