• 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 #ifndef NWEB_WEBVIEW_CONTROLLER_PRINT_STRUCTS_H
17 #define NWEB_WEBVIEW_CONTROLLER_PRINT_STRUCTS_H
18 
19 #include <memory>
20 #include <string>
21 #include <vector>
22 
23 #include "nweb.h"
24 #include "nweb_helper.h"
25 #include "print_manager_adapter.h"
26 
27 namespace OHOS {
28 namespace NWeb {
29 
30 class WebPrintAttributes : public NWebPrintAttributesAdapter {
31 public:
WebPrintAttributes(const PrintAttributesAdapter & attrs)32     explicit WebPrintAttributes(const PrintAttributesAdapter& attrs) : attrs_(attrs) {}
33     bool GetBool(uint32_t attrId) override;
34     uint32_t GetUInt32(uint32_t attrId) override;
35     std::string GetString(uint32_t attrId) override;
36     std::vector<uint32_t> GetUint32Vector(uint32_t attrId) override;
37 private:
38     PrintAttributesAdapter attrs_;
39 };
40 
41 class WebPrintDocument {
42 public:
WebPrintDocument(PrintDocumentAdapterAdapter * webPrintdoc)43     explicit WebPrintDocument(PrintDocumentAdapterAdapter* webPrintdoc) : printDocAdapter_(webPrintdoc) {}
WebPrintDocument(NWebPrintDocumentAdapterAdapter * webPrintdocV2)44     explicit WebPrintDocument(NWebPrintDocumentAdapterAdapter* webPrintdocV2) : printDocAdapterV2_(webPrintdocV2) {}
45     ~WebPrintDocument() = default;
46     void OnStartLayoutWrite(const std::string& jobId, const PrintAttributesAdapter& oldAttrs,
47         const PrintAttributesAdapter& newAttrs, uint32_t fd,
48         std::function<void(std::string, uint32_t)> writeResultCallback);
49 
50     void OnJobStateChanged(const std::string& jobId, uint32_t state);
51 
52 private:
53     std::unique_ptr<PrintDocumentAdapterAdapter> printDocAdapter_ = nullptr;
54     std::unique_ptr<NWebPrintDocumentAdapterAdapter> printDocAdapterV2_ = nullptr;
55 };
56 
57 class WebPrintWriteResultCallbackAdapter : public PrintWriteResultCallbackAdapter {
58 public:
WebPrintWriteResultCallbackAdapter(std::function<void (std::string,uint32_t)> & cb)59     explicit WebPrintWriteResultCallbackAdapter(std::function<void(std::string, uint32_t)>& cb) : cb_(cb) {}
60 
61     void WriteResultCallback(std::string jobId, uint32_t code) override;
62 
63 private:
64     std::function<void(std::string, uint32_t)> cb_ = nullptr;
65 };
66 
67 class WebPrintWriteResultCallbackAdapterV2 : public NWebPrintWriteResultCallbackAdapter {
68 public:
WebPrintWriteResultCallbackAdapterV2(std::function<void (std::string,uint32_t)> & cb)69     explicit WebPrintWriteResultCallbackAdapterV2(std::function<void(std::string, uint32_t)>& cb) : cb_(cb) {}
70 
71     void WriteResultCallback(const std::string& jobId, uint32_t code) override;
72 
73 private:
74     std::function<void(std::string, uint32_t)> cb_ = nullptr;
75 };
76 } // namespace NWeb
77 } // namespace OHOS
78 
79 #endif // NWEB_WEBVIEW_CONTROLLER_PRINT_STRUCTS_H