printing_context_win.h 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. // Copyright (c) 2011 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.
  4. #ifndef PRINTING_PRINTING_CONTEXT_WIN_H_
  5. #define PRINTING_PRINTING_CONTEXT_WIN_H_
  6. #include <windows.h>
  7. #include <memory>
  8. #include <string>
  9. #include "printing/mojom/print.mojom.h"
  10. #include "printing/printing_context.h"
  11. #include "ui/gfx/native_widget_types.h"
  12. namespace printing {
  13. class PrintSettings;
  14. class COMPONENT_EXPORT(PRINTING) PrintingContextWin : public PrintingContext {
  15. public:
  16. explicit PrintingContextWin(Delegate* delegate);
  17. PrintingContextWin(const PrintingContextWin&) = delete;
  18. PrintingContextWin& operator=(const PrintingContextWin&) = delete;
  19. ~PrintingContextWin() override;
  20. // PrintingContext implementation.
  21. void AskUserForSettings(int max_pages,
  22. bool has_selection,
  23. bool is_scripted,
  24. PrintSettingsCallback callback) override;
  25. mojom::ResultCode UseDefaultSettings() override;
  26. gfx::Size GetPdfPaperSizeDeviceUnits() override;
  27. mojom::ResultCode UpdatePrinterSettings(
  28. const PrinterSettings& printer_settings) override;
  29. mojom::ResultCode NewDocument(const std::u16string& document_name) override;
  30. mojom::ResultCode RenderPage(const PrintedPage& page,
  31. const PageSetup& page_setup) override;
  32. mojom::ResultCode PrintDocument(const MetafilePlayer& metafile,
  33. const PrintSettings& settings,
  34. uint32_t num_pages) override;
  35. mojom::ResultCode DocumentDone() override;
  36. void Cancel() override;
  37. void ReleaseContext() override;
  38. printing::NativeDrawingContext context() const override;
  39. mojom::ResultCode InitWithSettingsForTest(
  40. std::unique_ptr<PrintSettings> settings) override;
  41. protected:
  42. static HWND GetRootWindow(gfx::NativeView view);
  43. // Reads the settings from the selected device context. Updates settings_ and
  44. // its margins.
  45. virtual mojom::ResultCode InitializeSettings(const std::wstring& device_name,
  46. DEVMODE* dev_mode);
  47. // PrintingContext implementation.
  48. mojom::ResultCode OnError() override;
  49. void set_context(HDC context) { context_ = context; }
  50. private:
  51. // Used in response to the user canceling the printing.
  52. static BOOL CALLBACK AbortProc(HDC hdc, int nCode);
  53. // The selected printer context.
  54. HDC context_;
  55. };
  56. } // namespace printing
  57. #endif // PRINTING_PRINTING_CONTEXT_WIN_H_