1 /*
2 * Copyright (c) 2021-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 #include "window_option.h"
17 #include "window_helper.h"
18 #include "wm_common.h"
19
20 namespace OHOS {
21 namespace Rosen {
WindowOption()22 WindowOption::WindowOption(): windowTag_(WindowTag::SYSTEM_WINDOW)
23 {
24 AddWindowFlag(WindowFlag::WINDOW_FLAG_NEED_AVOID);
25 }
26
SetWindowRect(const struct Rect & rect)27 void WindowOption::SetWindowRect(const struct Rect& rect)
28 {
29 windowRect_ = rect;
30 }
31
SetWindowType(WindowType type)32 void WindowOption::SetWindowType(WindowType type)
33 {
34 type_ = type;
35 }
36
SetWindowMode(WindowMode mode)37 void WindowOption::SetWindowMode(WindowMode mode)
38 {
39 if (!WindowHelper::IsValidWindowMode(mode)) {
40 return;
41 }
42 mode_ = mode;
43 }
44
SetWindowBackgroundBlur(WindowBlurLevel level)45 void WindowOption::SetWindowBackgroundBlur(WindowBlurLevel level)
46 {
47 if (!WindowHelper::IsValidWindowBlurLevel(level)) {
48 return;
49 }
50 level_ = level;
51 }
52
SetAlpha(float alpha)53 void WindowOption::SetAlpha(float alpha)
54 {
55 alpha_ = alpha;
56 }
57
SetFocusable(bool isFocusable)58 void WindowOption::SetFocusable(bool isFocusable)
59 {
60 focusable_ = isFocusable;
61 }
62
SetTouchable(bool isTouchable)63 void WindowOption::SetTouchable(bool isTouchable)
64 {
65 touchable_ = isTouchable;
66 }
67
SetDisplayId(DisplayId displayId)68 void WindowOption::SetDisplayId(DisplayId displayId)
69 {
70 displayId_ = displayId;
71 }
72
SetParentName(const std::string & parentName)73 void WindowOption::SetParentName(const std::string& parentName)
74 {
75 parentName_ = parentName;
76 }
77
SetWindowName(const std::string & windowName)78 void WindowOption::SetWindowName(const std::string& windowName)
79 {
80 windowName_ = windowName;
81 }
82
AddWindowFlag(WindowFlag flag)83 void WindowOption::AddWindowFlag(WindowFlag flag)
84 {
85 flags_ |= static_cast<uint32_t>(flag);
86 }
87
RemoveWindowFlag(WindowFlag flag)88 void WindowOption::RemoveWindowFlag(WindowFlag flag)
89 {
90 flags_ &= ~(static_cast<uint32_t>(flag));
91 }
92
SetWindowFlags(uint32_t flags)93 void WindowOption::SetWindowFlags(uint32_t flags)
94 {
95 flags_ = flags;
96 }
97
SetSystemBarProperty(WindowType type,const SystemBarProperty & property)98 void WindowOption::SetSystemBarProperty(WindowType type, const SystemBarProperty& property)
99 {
100 if (type == WindowType::WINDOW_TYPE_STATUS_BAR || type == WindowType::WINDOW_TYPE_NAVIGATION_BAR) {
101 sysBarPropMap_[type] = property;
102 }
103 }
104
GetWindowRect() const105 Rect WindowOption::GetWindowRect() const
106 {
107 return windowRect_;
108 }
109
GetWindowType() const110 WindowType WindowOption::GetWindowType() const
111 {
112 return type_;
113 }
114
GetWindowMode() const115 WindowMode WindowOption::GetWindowMode() const
116 {
117 return mode_;
118 }
119
GetWindowBackgroundBlur() const120 WindowBlurLevel WindowOption::GetWindowBackgroundBlur() const
121 {
122 return level_;
123 }
124
GetAlpha() const125 float WindowOption::GetAlpha() const
126 {
127 return alpha_;
128 }
129
GetFocusable() const130 bool WindowOption::GetFocusable() const
131 {
132 return focusable_;
133 }
134
GetTouchable() const135 bool WindowOption::GetTouchable() const
136 {
137 return touchable_;
138 }
139
GetDisplayId() const140 DisplayId WindowOption::GetDisplayId() const
141 {
142 return displayId_;
143 }
144
GetParentName() const145 const std::string& WindowOption::GetParentName() const
146 {
147 return parentName_;
148 }
149
GetWindowName() const150 const std::string& WindowOption::GetWindowName() const
151 {
152 return windowName_;
153 }
154
GetWindowFlags() const155 uint32_t WindowOption::GetWindowFlags() const
156 {
157 return flags_;
158 }
159
SetHitOffset(int32_t x,int32_t y)160 void WindowOption::SetHitOffset(int32_t x, int32_t y)
161 {
162 hitOffset_.x = x;
163 hitOffset_.y = y;
164 }
165
SetWindowTag(WindowTag windowTag)166 void WindowOption::SetWindowTag(WindowTag windowTag)
167 {
168 windowTag_ = windowTag;
169 }
170
GetWindowTag() const171 WindowTag WindowOption::GetWindowTag() const
172 {
173 return windowTag_;
174 }
175
GetHitOffset() const176 const PointInfo& WindowOption::GetHitOffset() const
177 {
178 return hitOffset_;
179 }
180
GetSystemBarProperty() const181 const std::unordered_map<WindowType, SystemBarProperty>& WindowOption::GetSystemBarProperty() const
182 {
183 return sysBarPropMap_;
184 }
185
SetKeepScreenOn(bool keepScreenOn)186 void WindowOption::SetKeepScreenOn(bool keepScreenOn)
187 {
188 keepScreenOn_ = keepScreenOn;
189 }
190
IsKeepScreenOn() const191 bool WindowOption::IsKeepScreenOn() const
192 {
193 return keepScreenOn_;
194 }
195
SetTurnScreenOn(bool turnScreenOn)196 void WindowOption::SetTurnScreenOn(bool turnScreenOn)
197 {
198 turnScreenOn_ = turnScreenOn;
199 }
200
IsTurnScreenOn() const201 bool WindowOption::IsTurnScreenOn() const
202 {
203 return turnScreenOn_;
204 }
205
SetBrightness(float brightness)206 void WindowOption::SetBrightness(float brightness)
207 {
208 brightness_ = brightness;
209 }
210
GetBrightness() const211 float WindowOption::GetBrightness() const
212 {
213 return brightness_;
214 }
215
SetCallingWindow(uint32_t windowId)216 void WindowOption::SetCallingWindow(uint32_t windowId)
217 {
218 callingWindow_ = windowId;
219 }
220
GetCallingWindow() const221 uint32_t WindowOption::GetCallingWindow() const
222 {
223 return callingWindow_;
224 }
225
GetRequestedOrientation() const226 Orientation WindowOption::GetRequestedOrientation() const
227 {
228 return requestedOrientation_;
229 }
230
SetRequestedOrientation(Orientation orientation)231 void WindowOption::SetRequestedOrientation(Orientation orientation)
232 {
233 requestedOrientation_ = orientation;
234 }
235 } // namespace Rosen
236 } // namespace OHOS
237
238