Update V8 to version 4.7.21.
[chromium-blink-merge.git] / win8 / metro_driver / print_handler.h
blobf0779cf2ad8417d30784e315fc76243a4159ec79
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #ifndef CHROME_BROWSER_UI_METRO_DRIVER_PRINT_HANDLER_H_
6 #define CHROME_BROWSER_UI_METRO_DRIVER_PRINT_HANDLER_H_
8 #include <windows.media.playto.h>
9 #include <windows.graphics.printing.h>
10 #include <windows.ui.core.h>
12 #include "base/synchronization/lock.h"
13 #include "base/threading/thread.h"
14 #include "win8/metro_driver/print_document_source.h"
15 #include "win8/metro_driver/winrt_utils.h"
17 namespace base {
19 class Lock;
21 } // namespace base
23 namespace metro_driver {
25 // This class handles the print aspect of the devices charm.
26 class PrintHandler {
27 public:
28 PrintHandler();
29 ~PrintHandler();
31 HRESULT Initialize(winui::Core::ICoreWindow* window);
33 // Called by the exported C functions.
34 static void EnablePrinting(bool printing_enabled);
35 static void SetPageCount(size_t page_count);
36 static void AddPage(size_t page_number, IStream* metafile_stream);
37 static void ShowPrintUI();
39 private:
40 // Callbacks from Metro.
41 HRESULT OnPrintRequested(
42 wingfx::Printing::IPrintManager* print_mgr,
43 wingfx::Printing::IPrintTaskRequestedEventArgs* event_args);
45 HRESULT OnPrintTaskSourceRequest(
46 wingfx::Printing::IPrintTaskSourceRequestedArgs* args);
48 HRESULT OnCompleted(wingfx::Printing::IPrintTask* task,
49 wingfx::Printing::IPrintTaskCompletedEventArgs* args);
50 // Utility methods.
51 void ClearPrintTask();
52 float GetLogicalDpi();
54 // Callback from Metro and entry point called on lockable thread.
55 HRESULT LogicalDpiChanged(IInspectable *sender);
56 static void OnLogicalDpiChanged(float dpi);
58 // Called on the lockable thread to set/release the doc.
59 static void SetPrintDocumentSource(
60 const mswr::ComPtr<PrintDocumentSource>& print_document_source);
61 static void ReleasePrintDocumentSource();
63 // Called on the lockable thread for the exported C functions.
64 static void OnEnablePrinting(bool printing_enabled);
65 static void OnSetPageCount(size_t page_count);
66 static void OnAddPage(size_t page_number,
67 mswr::ComPtr<IStream> metafile_stream);
69 // Opens the prit device charm. Must be called from the metro thread.
70 static void OnShowPrintUI();
72 mswr::ComPtr<wingfx::Printing::IPrintTask> print_task_;
73 EventRegistrationToken print_requested_token_;
74 EventRegistrationToken print_completed_token_;
75 EventRegistrationToken dpi_change_token_;
77 mswr::ComPtr<wingfx::Printing::IPrintManager> print_manager_;
78 PrintDocumentSource::DirectXContext directx_context_;
80 // Hack to give access to the Print Document from the C style entry points.
81 // This will go away once we can pass a pointer to this interface down to
82 // the Chrome Browser as we send the command to print.
83 static mswr::ComPtr<PrintDocumentSource> current_document_source_;
85 // Another hack to enable/disable printing from an exported C function.
86 // TODO(mad): Find a better way to do this...
87 static bool printing_enabled_;
89 // This is also a temporary hack until we can pass down the print document
90 // to Chrome so it can call directly into it. We need to lock the access to
91 // current_document_source_.
92 static base::Lock* lock_;
94 // This thread is used to send blocking jobs
95 // out of threads we don't want to block.
96 static base::Thread* thread_;
99 } // namespace metro_driver
101 // Exported C functions for Chrome to call into the Metro module.
102 extern "C" __declspec(dllexport)
103 void MetroEnablePrinting(BOOL printing_enabled);
105 extern "C" __declspec(dllexport)
106 void MetroSetPrintPageCount(size_t page_count);
108 extern "C" __declspec(dllexport)
109 void MetroSetPrintPageContent(size_t current_page,
110 void* data,
111 size_t data_size);
113 extern "C" __declspec(dllexport)
114 void MetroShowPrintUI();
116 #endif // CHROME_BROWSER_UI_METRO_DRIVER_PRINT_HANDLER_H_