1 /*
2  * Copyright (c) 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 "ohos_adapter/bridge/ark_display_manager_adapter_impl.h"
17 
18 #include "ohos_adapter/bridge/ark_display_adapter_impl.h"
19 #include "ohos_adapter/bridge/ark_display_listener_adapter_wrapper.h"
20 #include "ohos_adapter/bridge/ark_fold_status_listener_adapter_wrapper.h"
21 
22 #include "base/bridge/ark_web_bridge_macros.h"
23 
24 namespace OHOS::ArkWeb {
25 
ArkDisplayManagerAdapterImpl(std::shared_ptr<OHOS::NWeb::DisplayManagerAdapter> ref)26 ArkDisplayManagerAdapterImpl::ArkDisplayManagerAdapterImpl(std::shared_ptr<OHOS::NWeb::DisplayManagerAdapter> ref)
27     : real_(ref)
28 {}
29 
GetDefaultDisplayId()30 uint64_t ArkDisplayManagerAdapterImpl::GetDefaultDisplayId()
31 {
32     return real_->GetDefaultDisplayId();
33 }
34 
GetDefaultDisplay()35 ArkWebRefPtr<ArkDisplayAdapter> ArkDisplayManagerAdapterImpl::GetDefaultDisplay()
36 {
37     std::shared_ptr<NWeb::DisplayAdapter> ref = real_->GetDefaultDisplay();
38     if (CHECK_SHARED_PTR_IS_NULL(ref)) {
39         return nullptr;
40     }
41 
42     return new ArkDisplayAdapterImpl(ref);
43 }
44 
RegisterDisplayListener(ArkWebRefPtr<ArkDisplayListenerAdapter> listener)45 uint32_t ArkDisplayManagerAdapterImpl::RegisterDisplayListener(ArkWebRefPtr<ArkDisplayListenerAdapter> listener)
46 {
47     if (CHECK_REF_PTR_IS_NULL(listener)) {
48         return real_->RegisterDisplayListener(nullptr);
49     }
50 
51     return real_->RegisterDisplayListener(std::make_shared<ArkDisplayListenerAdapterWrapper>(listener));
52 }
53 
UnregisterDisplayListener(uint32_t id)54 bool ArkDisplayManagerAdapterImpl::UnregisterDisplayListener(uint32_t id)
55 {
56     return real_->UnregisterDisplayListener(id);
57 }
58 
IsDefaultPortrait()59 bool ArkDisplayManagerAdapterImpl::IsDefaultPortrait()
60 {
61     return real_->IsDefaultPortrait();
62 }
63 
RegisterFoldStatusListener(ArkWebRefPtr<ArkFoldStatusListenerAdapter> listener)64 uint32_t ArkDisplayManagerAdapterImpl::RegisterFoldStatusListener(ArkWebRefPtr<ArkFoldStatusListenerAdapter> listener)
65 {
66     if (CHECK_REF_PTR_IS_NULL(listener)) {
67         return real_->RegisterFoldStatusListener(nullptr);
68     }
69 
70     return real_->RegisterFoldStatusListener(std::make_shared<ArkFoldStatusListenerAdapterWrapper>(listener));
71 }
72 
UnregisterFoldStatusListener(uint32_t id)73 bool ArkDisplayManagerAdapterImpl::UnregisterFoldStatusListener(uint32_t id)
74 {
75     return real_->UnregisterDisplayListener(id);
76 }
77 } // namespace OHOS::ArkWeb
78