OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "printing/printing_context_win.h" | 5 #include "printing/printing_context_win.h" |
6 | 6 |
7 #include <winspool.h> | |
8 | |
9 #include <algorithm> | 7 #include <algorithm> |
10 | 8 |
11 #include "base/message_loop/message_loop.h" | |
12 #include "base/metrics/histogram.h" | |
13 #include "base/strings/string_number_conversions.h" | 9 #include "base/strings/string_number_conversions.h" |
14 #include "base/strings/utf_string_conversions.h" | 10 #include "base/strings/utf_string_conversions.h" |
15 #include "base/values.h" | |
16 #include "printing/backend/print_backend.h" | 11 #include "printing/backend/print_backend.h" |
17 #include "printing/backend/printing_info_win.h" | |
18 #include "printing/backend/win_helper.h" | 12 #include "printing/backend/win_helper.h" |
19 #include "printing/print_job_constants.h" | |
20 #include "printing/print_settings_initializer_win.h" | 13 #include "printing/print_settings_initializer_win.h" |
21 #include "printing/printed_document.h" | 14 #include "printing/printed_document.h" |
22 #include "printing/printing_utils.h" | 15 #include "printing/printing_utils.h" |
23 #include "printing/units.h" | 16 #include "printing/units.h" |
24 #include "skia/ext/platform_device.h" | 17 #include "skia/ext/platform_device.h" |
25 | 18 |
26 #if defined(USE_AURA) | 19 #if defined(USE_AURA) |
27 #include "ui/aura/remote_window_tree_host_win.h" | 20 #include "ui/aura/remote_window_tree_host_win.h" |
28 #include "ui/aura/window.h" | 21 #include "ui/aura/window.h" |
29 #include "ui/aura/window_event_dispatcher.h" | |
30 #endif | 22 #endif |
31 | 23 |
32 namespace { | 24 namespace { |
33 | 25 |
34 HWND GetRootWindow(gfx::NativeView view) { | 26 HWND GetRootWindow(gfx::NativeView view) { |
35 HWND window = NULL; | 27 HWND window = NULL; |
36 #if defined(USE_AURA) | 28 #if defined(USE_AURA) |
37 if (view) | 29 if (view) |
38 window = view->GetHost()->GetAcceleratedWidget(); | 30 window = view->GetHost()->GetAcceleratedWidget(); |
39 #else | 31 #else |
40 if (view && IsWindow(view)) { | 32 if (view && IsWindow(view)) { |
41 window = GetAncestor(view, GA_ROOTOWNER); | 33 window = GetAncestor(view, GA_ROOTOWNER); |
42 } | 34 } |
43 #endif | 35 #endif |
44 if (!window) { | 36 if (!window) { |
45 // TODO(maruel): bug 1214347 Get the right browser window instead. | 37 // TODO(maruel): bug 1214347 Get the right browser window instead. |
46 return GetDesktopWindow(); | 38 return GetDesktopWindow(); |
47 } | 39 } |
48 return window; | 40 return window; |
49 } | 41 } |
50 | 42 |
51 } // anonymous namespace | 43 } // anonymous namespace |
52 | 44 |
53 namespace printing { | 45 namespace printing { |
54 | 46 |
55 class PrintingContextWin::CallbackHandler : public IPrintDialogCallback, | |
56 public IObjectWithSite { | |
57 public: | |
58 CallbackHandler(PrintingContextWin& owner, HWND owner_hwnd) | |
59 : owner_(owner), | |
60 owner_hwnd_(owner_hwnd), | |
61 services_(NULL) { | |
62 } | |
63 | |
64 ~CallbackHandler() { | |
65 if (services_) | |
66 services_->Release(); | |
67 } | |
68 | |
69 IUnknown* ToIUnknown() { | |
70 return static_cast<IUnknown*>(static_cast<IPrintDialogCallback*>(this)); | |
71 } | |
72 | |
73 // IUnknown | |
74 virtual HRESULT WINAPI QueryInterface(REFIID riid, void**object) { | |
75 if (riid == IID_IUnknown) { | |
76 *object = ToIUnknown(); | |
77 } else if (riid == IID_IPrintDialogCallback) { | |
78 *object = static_cast<IPrintDialogCallback*>(this); | |
79 } else if (riid == IID_IObjectWithSite) { | |
80 *object = static_cast<IObjectWithSite*>(this); | |
81 } else { | |
82 return E_NOINTERFACE; | |
83 } | |
84 return S_OK; | |
85 } | |
86 | |
87 // No real ref counting. | |
88 virtual ULONG WINAPI AddRef() { | |
89 return 1; | |
90 } | |
91 virtual ULONG WINAPI Release() { | |
92 return 1; | |
93 } | |
94 | |
95 // IPrintDialogCallback methods | |
96 virtual HRESULT WINAPI InitDone() { | |
97 return S_OK; | |
98 } | |
99 | |
100 virtual HRESULT WINAPI SelectionChange() { | |
101 if (services_) { | |
102 // TODO(maruel): Get the devmode for the new printer with | |
103 // services_->GetCurrentDevMode(&devmode, &size), send that information | |
104 // back to our client and continue. The client needs to recalculate the | |
105 // number of rendered pages and send back this information here. | |
106 } | |
107 return S_OK; | |
108 } | |
109 | |
110 virtual HRESULT WINAPI HandleMessage(HWND dialog, | |
111 UINT message, | |
112 WPARAM wparam, | |
113 LPARAM lparam, | |
114 LRESULT* result) { | |
115 // Cheap way to retrieve the window handle. | |
116 if (!owner_.dialog_box_) { | |
117 // The handle we receive is the one of the groupbox in the General tab. We | |
118 // need to get the grand-father to get the dialog box handle. | |
119 owner_.dialog_box_ = GetAncestor(dialog, GA_ROOT); | |
120 // Trick to enable the owner window. This can cause issues with navigation | |
121 // events so it may have to be disabled if we don't fix the side-effects. | |
122 EnableWindow(owner_hwnd_, TRUE); | |
123 } | |
124 return S_FALSE; | |
125 } | |
126 | |
127 virtual HRESULT WINAPI SetSite(IUnknown* site) { | |
128 if (!site) { | |
129 DCHECK(services_); | |
130 services_->Release(); | |
131 services_ = NULL; | |
132 // The dialog box is destroying, PrintJob::Worker don't need the handle | |
133 // anymore. | |
134 owner_.dialog_box_ = NULL; | |
135 } else { | |
136 DCHECK(services_ == NULL); | |
137 HRESULT hr = site->QueryInterface(IID_IPrintDialogServices, | |
138 reinterpret_cast<void**>(&services_)); | |
139 DCHECK(SUCCEEDED(hr)); | |
140 } | |
141 return S_OK; | |
142 } | |
143 | |
144 virtual HRESULT WINAPI GetSite(REFIID riid, void** site) { | |
145 return E_NOTIMPL; | |
146 } | |
147 | |
148 private: | |
149 PrintingContextWin& owner_; | |
150 HWND owner_hwnd_; | |
151 IPrintDialogServices* services_; | |
152 | |
153 DISALLOW_COPY_AND_ASSIGN(CallbackHandler); | |
154 }; | |
155 | |
156 // static | 47 // static |
157 PrintingContext* PrintingContext::Create(const std::string& app_locale) { | 48 PrintingContext* PrintingContext::Create(const std::string& app_locale) { |
158 return static_cast<PrintingContext*>(new PrintingContextWin(app_locale)); | 49 return static_cast<PrintingContext*>(new PrintingContextWin(app_locale)); |
159 } | 50 } |
160 | 51 |
161 PrintingContextWin::PrintingContextWin(const std::string& app_locale) | 52 PrintingContextWin::PrintingContextWin(const std::string& app_locale) |
162 : PrintingContext(app_locale), context_(NULL), dialog_box_(NULL) {} | 53 : PrintingContext(app_locale), context_(NULL), dialog_box_(NULL) {} |
163 | 54 |
164 PrintingContextWin::~PrintingContextWin() { | 55 PrintingContextWin::~PrintingContextWin() { |
165 ReleaseContext(); | 56 ReleaseContext(); |
(...skipping 546 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
712 | 603 |
713 if (dialog_options.hDevMode != NULL) | 604 if (dialog_options.hDevMode != NULL) |
714 GlobalFree(dialog_options.hDevMode); | 605 GlobalFree(dialog_options.hDevMode); |
715 if (dialog_options.hDevNames != NULL) | 606 if (dialog_options.hDevNames != NULL) |
716 GlobalFree(dialog_options.hDevNames); | 607 GlobalFree(dialog_options.hDevNames); |
717 | 608 |
718 return context_ ? OK : FAILED; | 609 return context_ ? OK : FAILED; |
719 } | 610 } |
720 | 611 |
721 } // namespace printing | 612 } // namespace printing |
OLD | NEW |