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 #include "ohos_adapter/cpptoc/ark_display_adapter_vector_cpptoc.h" 22 23 #include "base/bridge/ark_web_bridge_macros.h" 24 25 namespace OHOS::ArkWeb { 26 ArkDisplayManagerAdapterImpl(std::shared_ptr<OHOS::NWeb::DisplayManagerAdapter> ref)27ArkDisplayManagerAdapterImpl::ArkDisplayManagerAdapterImpl(std::shared_ptr<OHOS::NWeb::DisplayManagerAdapter> ref) 28 : real_(ref) 29 {} 30 GetDefaultDisplayId()31uint64_t ArkDisplayManagerAdapterImpl::GetDefaultDisplayId() 32 { 33 return real_->GetDefaultDisplayId(); 34 } 35 GetDefaultDisplay()36ArkWebRefPtr<ArkDisplayAdapter> ArkDisplayManagerAdapterImpl::GetDefaultDisplay() 37 { 38 std::shared_ptr<NWeb::DisplayAdapter> ref = real_->GetDefaultDisplay(); 39 if (CHECK_SHARED_PTR_IS_NULL(ref)) { 40 return nullptr; 41 } 42 43 return new ArkDisplayAdapterImpl(ref); 44 } 45 RegisterDisplayListener(ArkWebRefPtr<ArkDisplayListenerAdapter> listener)46uint32_t ArkDisplayManagerAdapterImpl::RegisterDisplayListener(ArkWebRefPtr<ArkDisplayListenerAdapter> listener) 47 { 48 if (CHECK_REF_PTR_IS_NULL(listener)) { 49 return real_->RegisterDisplayListener(nullptr); 50 } 51 52 return real_->RegisterDisplayListener(std::make_shared<ArkDisplayListenerAdapterWrapper>(listener)); 53 } 54 UnregisterDisplayListener(uint32_t id)55bool ArkDisplayManagerAdapterImpl::UnregisterDisplayListener(uint32_t id) 56 { 57 return real_->UnregisterDisplayListener(id); 58 } 59 IsDefaultPortrait()60bool ArkDisplayManagerAdapterImpl::IsDefaultPortrait() 61 { 62 return real_->IsDefaultPortrait(); 63 } 64 RegisterFoldStatusListener(ArkWebRefPtr<ArkFoldStatusListenerAdapter> listener)65uint32_t ArkDisplayManagerAdapterImpl::RegisterFoldStatusListener(ArkWebRefPtr<ArkFoldStatusListenerAdapter> listener) 66 { 67 if (CHECK_REF_PTR_IS_NULL(listener)) { 68 return real_->RegisterFoldStatusListener(nullptr); 69 } 70 71 return real_->RegisterFoldStatusListener(std::make_shared<ArkFoldStatusListenerAdapterWrapper>(listener)); 72 } 73 UnregisterFoldStatusListener(uint32_t id)74bool ArkDisplayManagerAdapterImpl::UnregisterFoldStatusListener(uint32_t id) 75 { 76 return real_->UnregisterDisplayListener(id); 77 } 78 GetPrimaryDisplay()79ArkWebRefPtr<ArkDisplayAdapter> ArkDisplayManagerAdapterImpl::GetPrimaryDisplay() 80 { 81 std::shared_ptr<NWeb::DisplayAdapter> ref = real_->GetPrimaryDisplay(); 82 if (CHECK_SHARED_PTR_IS_NULL(ref)) { 83 return nullptr; 84 } 85 86 return new ArkDisplayAdapterImpl(ref); 87 } 88 GetAllDisplays()89ArkDisplayAdapterVector ArkDisplayManagerAdapterImpl::GetAllDisplays() 90 { 91 std::vector<std::shared_ptr<NWeb::DisplayAdapter>> displays = real_->GetAllDisplays(); 92 ArkDisplayAdapterVector result = ArkDisplayAdapterVectorClassToStruct(displays); 93 return result; 94 } 95 96 } // namespace OHOS::ArkWeb 97