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