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_option.h"
17
18 #include "window_helper.h"
19 #include "wm_common.h"
20
21 namespace OHOS {
22 namespace Rosen {
WindowOption()23 WindowOption::WindowOption(): windowTag_(WindowTag::SYSTEM_WINDOW)
24 {
25 AddWindowFlag(WindowFlag::WINDOW_FLAG_NEED_AVOID);
26 }
27
SetWindowMode(WindowMode mode)28 void WindowOption::SetWindowMode(WindowMode mode)
29 {
30 if (!WindowHelper::IsValidWindowMode(mode)) {
31 return;
32 }
33 mode_ = mode;
34 }
35
SetWindowRect(const Rect & rect)36 void WindowOption::SetWindowRect(const Rect& rect)
37 {
38 windowRect_ = rect;
39 }
40
SetWindowType(WindowType type)41 void WindowOption::SetWindowType(WindowType type)
42 {
43 type_ = type;
44 }
45
SetParentId(uint32_t parentId)46 void WindowOption::SetParentId(uint32_t parentId)
47 {
48 parentId_ = parentId;
49 }
50
SetDisplayId(DisplayId displayId)51 void WindowOption::SetDisplayId(DisplayId displayId)
52 {
53 displayId_ = displayId;
54 }
55
SetFocusable(bool isFocusable)56 void WindowOption::SetFocusable(bool isFocusable)
57 {
58 focusable_ = isFocusable;
59 }
60
SetTouchable(bool isTouchable)61 void WindowOption::SetTouchable(bool isTouchable)
62 {
63 touchable_ = isTouchable;
64 }
65
SetWindowName(const std::string & windowName)66 void WindowOption::SetWindowName(const std::string& windowName)
67 {
68 windowName_ = windowName;
69 }
70
SetWindowFlags(uint32_t flags)71 void WindowOption::SetWindowFlags(uint32_t flags)
72 {
73 flags_ = flags;
74 }
75
RemoveWindowFlag(WindowFlag flag)76 void WindowOption::RemoveWindowFlag(WindowFlag flag)
77 {
78 flags_ &= ~(static_cast<uint32_t>(flag));
79 }
80
AddWindowFlag(WindowFlag flag)81 void WindowOption::AddWindowFlag(WindowFlag flag)
82 {
83 flags_ |= static_cast<uint32_t>(flag);
84 }
85
SetWindowTag(WindowTag windowTag)86 void WindowOption::SetWindowTag(WindowTag windowTag)
87 {
88 windowTag_ = windowTag;
89 }
90
SetSystemBarProperty(WindowType type,const SystemBarProperty & property)91 void WindowOption::SetSystemBarProperty(WindowType type, const SystemBarProperty& property)
92 {
93 if (type == WindowType::WINDOW_TYPE_STATUS_BAR || type == WindowType::WINDOW_TYPE_NAVIGATION_BAR) {
94 sysBarPropMap_[type] = property;
95 }
96 }
97
SetWindowSessionType(WindowSessionType sessionType)98 void WindowOption::SetWindowSessionType(WindowSessionType sessionType)
99 {
100 sessionType_ = sessionType;
101 }
102
SetHitOffset(int32_t x,int32_t y)103 void WindowOption::SetHitOffset(int32_t x, int32_t y)
104 {
105 hitOffset_.x = x;
106 hitOffset_.y = y;
107 }
108
IsTurnScreenOn() const109 bool WindowOption::IsTurnScreenOn() const
110 {
111 return turnScreenOn_;
112 }
113
SetTurnScreenOn(bool turnScreenOn)114 void WindowOption::SetTurnScreenOn(bool turnScreenOn)
115 {
116 turnScreenOn_ = turnScreenOn;
117 }
118
IsKeepScreenOn() const119 bool WindowOption::IsKeepScreenOn() const
120 {
121 return keepScreenOn_;
122 }
123
SetKeepScreenOn(bool keepScreenOn)124 void WindowOption::SetKeepScreenOn(bool keepScreenOn)
125 {
126 keepScreenOn_ = keepScreenOn;
127 }
128
SetCallingWindow(uint32_t windowId)129 void WindowOption::SetCallingWindow(uint32_t windowId)
130 {
131 callingWindow_ = windowId;
132 }
133
SetRequestedOrientation(Orientation orientation)134 void WindowOption::SetRequestedOrientation(Orientation orientation)
135 {
136 requestedOrientation_ = orientation;
137 }
138
SetBrightness(float brightness)139 void WindowOption::SetBrightness(float brightness)
140 {
141 brightness_ = brightness;
142 }
143
SetMainHandlerAvailable(bool isMainHandlerAvailable)144 void WindowOption::SetMainHandlerAvailable(bool isMainHandlerAvailable)
145 {
146 isMainHandlerAvailable_ = isMainHandlerAvailable;
147 }
148
SetSubWindowDecorEnable(bool subWindowDecorEnable)149 void WindowOption::SetSubWindowDecorEnable(bool subWindowDecorEnable)
150 {
151 subWindowDecorEnable_ = subWindowDecorEnable;
152 }
153
SetSubWindowTitle(const std::string & subWindowTitle)154 void WindowOption::SetSubWindowTitle(const std::string& subWindowTitle)
155 {
156 subWindowTitle_ = subWindowTitle;
157 }
158
SetSubWindowMaximizeSupported(bool maximizeSupported)159 void WindowOption::SetSubWindowMaximizeSupported(bool maximizeSupported)
160 {
161 subWindowMaximizeSupported_ = maximizeSupported;
162 }
163
SetOnlySupportSceneBoard(bool onlySupportSceneBoard)164 void WindowOption::SetOnlySupportSceneBoard(bool onlySupportSceneBoard)
165 {
166 onlySupportSceneBoard_ = onlySupportSceneBoard;
167 }
168
SetWindowTopmost(bool isTopmost)169 void WindowOption::SetWindowTopmost(bool isTopmost)
170 {
171 isTopmost_ = isTopmost;
172 }
173
SetSubWindowZLevel(int32_t zLevel)174 void WindowOption::SetSubWindowZLevel(int32_t zLevel)
175 {
176 zLevel_ = zLevel;
177 }
178
GetSubWindowZLevel() const179 int32_t WindowOption::GetSubWindowZLevel() const
180 {
181 return zLevel_;
182 }
183
GetWindowMode() const184 WindowMode WindowOption::GetWindowMode() const
185 {
186 return mode_;
187 }
188
GetWindowType() const189 WindowType WindowOption::GetWindowType() const
190 {
191 return type_;
192 }
193
GetWindowRect() const194 Rect WindowOption::GetWindowRect() const
195 {
196 return windowRect_;
197 }
198
GetWindowTag() const199 WindowTag WindowOption::GetWindowTag() const
200 {
201 return windowTag_;
202 }
203
GetParentId() const204 uint32_t WindowOption::GetParentId() const
205 {
206 return parentId_;
207 }
208
GetDisplayId() const209 DisplayId WindowOption::GetDisplayId() const
210 {
211 return displayId_;
212 }
213
GetWindowFlags() const214 uint32_t WindowOption::GetWindowFlags() const
215 {
216 return flags_;
217 }
218
GetTouchable() const219 bool WindowOption::GetTouchable() const
220 {
221 return touchable_;
222 }
223
GetFocusable() const224 bool WindowOption::GetFocusable() const
225 {
226 return focusable_;
227 }
228
GetHitOffset() const229 const PointInfo& WindowOption::GetHitOffset() const
230 {
231 return hitOffset_;
232 }
233
GetWindowName() const234 const std::string& WindowOption::GetWindowName() const
235 {
236 return windowName_;
237 }
238
GetWindowSessionType() const239 WindowSessionType WindowOption::GetWindowSessionType() const
240 {
241 return sessionType_;
242 }
243
GetMainHandlerAvailable() const244 bool WindowOption::GetMainHandlerAvailable() const
245 {
246 return isMainHandlerAvailable_;
247 }
248
GetSystemBarProperty() const249 const std::unordered_map<WindowType, SystemBarProperty>& WindowOption::GetSystemBarProperty() const
250 {
251 return sysBarPropMap_;
252 }
253
GetOnlySupportSceneBoard() const254 bool WindowOption::GetOnlySupportSceneBoard() const
255 {
256 return onlySupportSceneBoard_;
257 }
258
GetBrightness() const259 float WindowOption::GetBrightness() const
260 {
261 return brightness_;
262 }
263
GetRequestedOrientation() const264 Orientation WindowOption::GetRequestedOrientation() const
265 {
266 return requestedOrientation_;
267 }
268
GetCallingWindow() const269 uint32_t WindowOption::GetCallingWindow() const
270 {
271 return callingWindow_;
272 }
273
GetSubWindowDecorEnable() const274 bool WindowOption::GetSubWindowDecorEnable() const
275 {
276 return subWindowDecorEnable_;
277 }
278
GetSubWindowTitle() const279 std::string WindowOption::GetSubWindowTitle() const
280 {
281 return subWindowTitle_;
282 }
283
GetWindowTopmost() const284 bool WindowOption::GetWindowTopmost() const
285 {
286 return isTopmost_;
287 }
288
GetSubWindowMaximizeSupported() const289 bool WindowOption::GetSubWindowMaximizeSupported() const
290 {
291 return subWindowMaximizeSupported_;
292 }
293 } // namespace Rosen
294 } // namespace OHOS
295
296