1 /*
2  * Copyright (c) 2022 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 DISPLAY_MANAGER_ADAPTER_H
17 #define DISPLAY_MANAGER_ADAPTER_H
18 
19 #include <memory>
20 
21 namespace OHOS::NWeb {
22 
23 using DisplayId = uint64_t;
24 using ListenerId = uint32_t;
25 
26 enum class RotationType : uint32_t {
27     ROTATION_0,
28     ROTATION_90,
29     ROTATION_180,
30     ROTATION_270,
31     ROTATION_BUTT,
32 };
33 
34 enum class OrientationType : uint32_t {
35     UNSPECIFIED = 0,
36     VERTICAL = 1,
37     HORIZONTAL = 2,
38     REVERSE_VERTICAL = 3,
39     REVERSE_HORIZONTAL = 4,
40     SENSOR = 5,
41     SENSOR_VERTICAL = 6,
42     SENSOR_HORIZONTAL = 7,
43     BUTT,
44 };
45 
46 enum class DisplayOrientation : uint32_t {
47     PORTRAIT = 0,
48     LANDSCAPE,
49     PORTRAIT_INVERTED,
50     LANDSCAPE_INVERTED,
51     UNKNOWN,
52 };
53 
54 enum class FoldStatus : uint32_t {
55     UNKNOWN = 0,
56     FULL = 1,
57     MAIN = 2,
58     SUB = 3,
59     COORDINATION = 4,
60 };
61 
62 class DisplayListenerAdapter {
63 public:
64     DisplayListenerAdapter() = default;
65 
66     virtual ~DisplayListenerAdapter() = default;
67 
68     virtual void OnCreate(DisplayId) = 0;
69 
70     virtual void OnDestroy(DisplayId) = 0;
71 
72     virtual void OnChange(DisplayId) = 0;
73 };
74 
75 class FoldStatusListenerAdapter {
76 public:
77     FoldStatusListenerAdapter() = default;
78 
79     virtual ~FoldStatusListenerAdapter() = default;
80 
OnFoldStatusChanged(FoldStatus foldstatus)81     virtual void OnFoldStatusChanged(FoldStatus foldstatus) {}
82 };
83 
84 class DisplayAdapter {
85 public:
86     DisplayAdapter() = default;
87 
88     virtual ~DisplayAdapter() = default;
89 
90     virtual DisplayId GetId() = 0;
91 
92     virtual int32_t GetWidth() = 0;
93 
94     virtual int32_t GetHeight() = 0;
95 
96     virtual float GetVirtualPixelRatio() = 0;
97 
98     virtual RotationType GetRotation() = 0;
99 
100     virtual OrientationType GetOrientation() = 0;
101 
102     virtual int32_t GetDpi() = 0;
103 
104     virtual DisplayOrientation GetDisplayOrientation() = 0;
105 
GetFoldStatus()106     virtual FoldStatus GetFoldStatus()
107     {
108         return FoldStatus::UNKNOWN;
109     }
110 
IsFoldable()111     virtual bool IsFoldable()
112     {
113         return false;
114     }
115 };
116 
117 class DisplayManagerAdapter {
118 public:
119     DisplayManagerAdapter() = default;
120 
121     virtual ~DisplayManagerAdapter() = default;
122 
123     virtual DisplayId GetDefaultDisplayId() = 0;
124 
125     virtual std::shared_ptr<DisplayAdapter> GetDefaultDisplay() = 0;
126 
127     virtual ListenerId RegisterDisplayListener(std::shared_ptr<DisplayListenerAdapter> listener) = 0;
128 
129     virtual bool UnregisterDisplayListener(ListenerId id) = 0;
130 
131     virtual bool IsDefaultPortrait() = 0;
132 
RegisterFoldStatusListener(std::shared_ptr<FoldStatusListenerAdapter> listener)133     virtual uint32_t RegisterFoldStatusListener(std::shared_ptr<FoldStatusListenerAdapter> listener)
134     {
135         return -1;
136     }
137 
UnregisterFoldStatusListener(uint32_t id)138     virtual bool UnregisterFoldStatusListener(uint32_t id)
139     {
140         return false;
141     }
142 };
143 
144 } // namespace OHOS::NWeb
145 
146 #endif // DISPLAY_MANAGER_ADAPTER_H
147