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