• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021 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.h"
17 #include "window_helper.h"
18 #include "window_impl.h"
19 #include "window_manager_hilog.h"
20 #include "wm_common.h"
21 
22 namespace OHOS {
23 namespace Rosen {
24 namespace {
25     constexpr HiviewDFX::HiLogLabel LABEL = {LOG_CORE, HILOG_DOMAIN_WINDOW, "WindowImpl"};
26 }
Create(const std::string & windowName,sptr<WindowOption> & option,const std::shared_ptr<OHOS::AbilityRuntime::Context> & context)27 sptr<Window> Window::Create(const std::string& windowName, sptr<WindowOption>& option,
28     const std::shared_ptr<OHOS::AbilityRuntime::Context>& context)
29 {
30     if (windowName.empty()) {
31         WLOGFE("window name is empty");
32         return nullptr;
33     }
34     if (option == nullptr) {
35         option = new(std::nothrow) WindowOption();
36         if (option == nullptr) {
37             WLOGFE("malloc option failed");
38             return nullptr;
39         }
40     }
41     WindowType type = option->GetWindowType();
42     if (!(WindowHelper::IsAppWindow(type) || WindowHelper::IsSystemWindow(type))) {
43         WLOGFE("window type is invalid %{public}d", type);
44         return nullptr;
45     }
46     option->SetWindowName(windowName);
47     sptr<WindowImpl> windowImpl = new(std::nothrow) WindowImpl(option);
48     if (windowImpl == nullptr) {
49         WLOGFE("malloc windowImpl failed");
50         return nullptr;
51     }
52     WMError error = windowImpl->Create(option->GetParentId(), context);
53     if (error != WMError::WM_OK) {
54         return nullptr;
55     }
56     return windowImpl;
57 }
58 
Find(const std::string & windowName)59 sptr<Window> Window::Find(const std::string& windowName)
60 {
61     return WindowImpl::Find(windowName);
62 }
63 
GetTopWindowWithContext(const std::shared_ptr<AbilityRuntime::Context> & context)64 sptr<Window> Window::GetTopWindowWithContext(const std::shared_ptr<AbilityRuntime::Context>& context)
65 {
66     return WindowImpl::GetTopWindowWithContext(context);
67 }
68 
GetTopWindowWithId(uint32_t mainWinId)69 sptr<Window> Window::GetTopWindowWithId(uint32_t mainWinId)
70 {
71     return WindowImpl::GetTopWindowWithId(mainWinId);
72 }
73 
GetSubWindow(uint32_t parentId)74 std::vector<sptr<Window>> Window::GetSubWindow(uint32_t parentId)
75 {
76     return WindowImpl::GetSubWindow(parentId);
77 }
78 
UpdateConfigurationForAll(const std::shared_ptr<AppExecFwk::Configuration> & configuration)79 void Window::UpdateConfigurationForAll(const std::shared_ptr<AppExecFwk::Configuration>& configuration)
80 {
81     return WindowImpl::UpdateConfigurationForAll(configuration);
82 }
83 
Marshalling(Parcel & parcel) const84 bool OccupiedAreaChangeInfo::Marshalling(Parcel& parcel) const
85 {
86     return parcel.WriteInt32(rect_.posX_) && parcel.WriteInt32(rect_.posY_) &&
87         parcel.WriteUint32(rect_.width_) && parcel.WriteUint32(rect_.height_) &&
88         parcel.WriteUint32(static_cast<uint32_t>(type_));
89 }
90 
Unmarshalling(Parcel & parcel)91 OccupiedAreaChangeInfo* OccupiedAreaChangeInfo::Unmarshalling(Parcel& parcel)
92 {
93     OccupiedAreaChangeInfo* occupiedAreaChangeInfo = new OccupiedAreaChangeInfo();
94     bool res = parcel.ReadInt32(occupiedAreaChangeInfo->rect_.posX_) &&
95         parcel.ReadInt32(occupiedAreaChangeInfo->rect_.posY_) &&
96         parcel.ReadUint32(occupiedAreaChangeInfo->rect_.width_) &&
97         parcel.ReadUint32(occupiedAreaChangeInfo->rect_.height_);
98     if (!res) {
99         delete occupiedAreaChangeInfo;
100         return nullptr;
101     }
102     occupiedAreaChangeInfo->type_ = static_cast<OccupiedAreaType>(parcel.ReadUint32());
103     return occupiedAreaChangeInfo;
104 }
105 } // namespace Rosen
106 } // namespace OHOS
107