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
SetFocusable(bool isFocusable)45 void WindowOption::SetFocusable(bool isFocusable)
46 {
47 focusable_ = isFocusable;
48 }
49
SetTouchable(bool isTouchable)50 void WindowOption::SetTouchable(bool isTouchable)
51 {
52 touchable_ = isTouchable;
53 }
54
SetDisplayId(DisplayId displayId)55 void WindowOption::SetDisplayId(DisplayId displayId)
56 {
57 displayId_ = displayId;
58 }
59
SetParentId(uint32_t parentId)60 void WindowOption::SetParentId(uint32_t parentId)
61 {
62 parentId_ = parentId;
63 }
64
SetWindowName(const std::string & windowName)65 void WindowOption::SetWindowName(const std::string& windowName)
66 {
67 windowName_ = windowName;
68 }
69
AddWindowFlag(WindowFlag flag)70 void WindowOption::AddWindowFlag(WindowFlag flag)
71 {
72 flags_ |= static_cast<uint32_t>(flag);
73 }
74
RemoveWindowFlag(WindowFlag flag)75 void WindowOption::RemoveWindowFlag(WindowFlag flag)
76 {
77 flags_ &= ~(static_cast<uint32_t>(flag));
78 }
79
SetWindowFlags(uint32_t flags)80 void WindowOption::SetWindowFlags(uint32_t flags)
81 {
82 flags_ = flags;
83 }
84
SetSystemBarProperty(WindowType type,const SystemBarProperty & property)85 void WindowOption::SetSystemBarProperty(WindowType type, const SystemBarProperty& property)
86 {
87 if (type == WindowType::WINDOW_TYPE_STATUS_BAR || type == WindowType::WINDOW_TYPE_NAVIGATION_BAR) {
88 sysBarPropMap_[type] = property;
89 }
90 }
91
GetWindowRect() const92 Rect WindowOption::GetWindowRect() const
93 {
94 return windowRect_;
95 }
96
GetWindowType() const97 WindowType WindowOption::GetWindowType() const
98 {
99 return type_;
100 }
101
GetWindowMode() const102 WindowMode WindowOption::GetWindowMode() const
103 {
104 return mode_;
105 }
106
GetFocusable() const107 bool WindowOption::GetFocusable() const
108 {
109 return focusable_;
110 }
111
GetTouchable() const112 bool WindowOption::GetTouchable() const
113 {
114 return touchable_;
115 }
116
GetDisplayId() const117 DisplayId WindowOption::GetDisplayId() const
118 {
119 return displayId_;
120 }
121
GetParentId() const122 uint32_t WindowOption::GetParentId() const
123 {
124 return parentId_;
125 }
126
GetWindowName() const127 const std::string& WindowOption::GetWindowName() const
128 {
129 return windowName_;
130 }
131
GetWindowFlags() const132 uint32_t WindowOption::GetWindowFlags() const
133 {
134 return flags_;
135 }
136
SetHitOffset(int32_t x,int32_t y)137 void WindowOption::SetHitOffset(int32_t x, int32_t y)
138 {
139 hitOffset_.x = x;
140 hitOffset_.y = y;
141 }
142
SetWindowTag(WindowTag windowTag)143 void WindowOption::SetWindowTag(WindowTag windowTag)
144 {
145 windowTag_ = windowTag;
146 }
147
GetWindowTag() const148 WindowTag WindowOption::GetWindowTag() const
149 {
150 return windowTag_;
151 }
152
SetMainHandlerAvailable(bool isMainHandlerAvailable)153 void WindowOption::SetMainHandlerAvailable(bool isMainHandlerAvailable)
154 {
155 isMainHandlerAvailable_ = isMainHandlerAvailable;
156 }
157
GetMainHandlerAvailable() const158 bool WindowOption::GetMainHandlerAvailable() const
159 {
160 return isMainHandlerAvailable_;
161 }
162
GetHitOffset() const163 const PointInfo& WindowOption::GetHitOffset() const
164 {
165 return hitOffset_;
166 }
167
GetSystemBarProperty() const168 const std::unordered_map<WindowType, SystemBarProperty>& WindowOption::GetSystemBarProperty() const
169 {
170 return sysBarPropMap_;
171 }
172
SetKeepScreenOn(bool keepScreenOn)173 void WindowOption::SetKeepScreenOn(bool keepScreenOn)
174 {
175 keepScreenOn_ = keepScreenOn;
176 }
177
IsKeepScreenOn() const178 bool WindowOption::IsKeepScreenOn() const
179 {
180 return keepScreenOn_;
181 }
182
SetTurnScreenOn(bool turnScreenOn)183 void WindowOption::SetTurnScreenOn(bool turnScreenOn)
184 {
185 turnScreenOn_ = turnScreenOn;
186 }
187
IsTurnScreenOn() const188 bool WindowOption::IsTurnScreenOn() const
189 {
190 return turnScreenOn_;
191 }
192
SetBrightness(float brightness)193 void WindowOption::SetBrightness(float brightness)
194 {
195 brightness_ = brightness;
196 }
197
GetBrightness() const198 float WindowOption::GetBrightness() const
199 {
200 return brightness_;
201 }
202
SetCallingWindow(uint32_t windowId)203 void WindowOption::SetCallingWindow(uint32_t windowId)
204 {
205 callingWindow_ = windowId;
206 }
207
GetCallingWindow() const208 uint32_t WindowOption::GetCallingWindow() const
209 {
210 return callingWindow_;
211 }
212
GetRequestedOrientation() const213 Orientation WindowOption::GetRequestedOrientation() const
214 {
215 return requestedOrientation_;
216 }
217
SetRequestedOrientation(Orientation orientation)218 void WindowOption::SetRequestedOrientation(Orientation orientation)
219 {
220 requestedOrientation_ = orientation;
221 }
222 } // namespace Rosen
223 } // namespace OHOS
224
225