• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2025 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_nweb/bridge/ark_web_print_document_adapter_adapter_impl.h"
17 
18 #include "ohos_nweb/bridge/ark_web_print_write_result_callback_adapter_wrapper.h"
19 #include "ohos_nweb/bridge/ark_web_print_attributes_adapter_wrapper.h"
20 
21 #include "base/bridge/ark_web_bridge_macros.h"
22 
23 namespace OHOS::ArkWeb {
24 
ArkWebPrintDocumentAdapterAdapterImpl(std::unique_ptr<OHOS::NWeb::NWebPrintDocumentAdapterAdapter> ref)25 ArkWebPrintDocumentAdapterAdapterImpl::ArkWebPrintDocumentAdapterAdapterImpl(
26     std::unique_ptr<OHOS::NWeb::NWebPrintDocumentAdapterAdapter> ref)
27 {
28     ref_ = std::move(ref);
29 }
30 
OnStartLayoutWrite(const ArkWebString & jobId,ArkWebRefPtr<ArkWebPrintAttributesAdapter> oldAttrs,ArkWebRefPtr<ArkWebPrintAttributesAdapter> newAttrs,uint32_t fd,ArkWebRefPtr<ArkWebPrintWriteResultCallbackAdapter> callback)31 void ArkWebPrintDocumentAdapterAdapterImpl::OnStartLayoutWrite(const ArkWebString& jobId,
32     ArkWebRefPtr<ArkWebPrintAttributesAdapter> oldAttrs, ArkWebRefPtr<ArkWebPrintAttributesAdapter> newAttrs,
33     uint32_t fd, ArkWebRefPtr<ArkWebPrintWriteResultCallbackAdapter> callback)
34 {
35     auto oldAttributes = std::make_shared<NWebPrintAttributesAdapterWrapper>(oldAttrs);
36     auto newAttributes = std::make_shared<NWebPrintAttributesAdapterWrapper>(newAttrs);
37 
38     if (CHECK_REF_PTR_IS_NULL(callback)) {
39         return ref_->OnStartLayoutWrite(ArkWebStringStructToClass(jobId), oldAttributes, newAttributes, fd, nullptr);
40     }
41 
42     ref_->OnStartLayoutWrite(ArkWebStringStructToClass(jobId), oldAttributes, newAttributes, fd,
43         std::make_shared<ArkWebPrintWriteResultCallbackAdapterWrapper>(callback));
44 }
45 
OnJobStateChanged(const ArkWebString & jobId,uint32_t state)46 void ArkWebPrintDocumentAdapterAdapterImpl::OnJobStateChanged(const ArkWebString& jobId, uint32_t state)
47 {
48     ref_->OnJobStateChanged(ArkWebStringStructToClass(jobId), state);
49 }
50 
51 } // namespace OHOS::ArkWeb