Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(145)

Side by Side Diff: printing/printing_context_win.cc

Issue 15817004: Enabled system print dialog on Windows Aura. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « printing/printing.gyp ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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> 7 #include <winspool.h>
8 8
9 #include <algorithm> 9 #include <algorithm>
10 10
11 #include "base/i18n/file_util_icu.h" 11 #include "base/i18n/file_util_icu.h"
12 #include "base/i18n/time_formatting.h" 12 #include "base/i18n/time_formatting.h"
13 #include "base/message_loop.h" 13 #include "base/message_loop.h"
14 #include "base/metrics/histogram.h" 14 #include "base/metrics/histogram.h"
15 #include "base/time.h" 15 #include "base/time.h"
16 #include "base/utf_string_conversions.h" 16 #include "base/utf_string_conversions.h"
17 #include "base/values.h" 17 #include "base/values.h"
18 #include "base/win/metro.h" 18 #include "base/win/metro.h"
19 #include "printing/backend/print_backend.h" 19 #include "printing/backend/print_backend.h"
20 #include "printing/backend/printing_info_win.h" 20 #include "printing/backend/printing_info_win.h"
21 #include "printing/backend/win_helper.h" 21 #include "printing/backend/win_helper.h"
22 #include "printing/print_job_constants.h" 22 #include "printing/print_job_constants.h"
23 #include "printing/print_settings_initializer_win.h" 23 #include "printing/print_settings_initializer_win.h"
24 #include "printing/printed_document.h" 24 #include "printing/printed_document.h"
25 #include "printing/units.h" 25 #include "printing/units.h"
26 #include "skia/ext/platform_device.h" 26 #include "skia/ext/platform_device.h"
27 #include "win8/util/win8_util.h" 27 #include "win8/util/win8_util.h"
28 28
29 #if defined(USE_AURA)
30 #include "ui/aura/remote_root_window_host_win.h"
31 #include "ui/aura/root_window.h"
32 #include "ui/aura/window.h"
33 #endif
34
29 using base::Time; 35 using base::Time;
30 36
31 namespace { 37 namespace {
32 38
33 // Constants for setting default PDF settings. 39 // Constants for setting default PDF settings.
34 const int kPDFDpi = 300; // 300 dpi 40 const int kPDFDpi = 300; // 300 dpi
35 // LETTER: 8.5 x 11 inches 41 // LETTER: 8.5 x 11 inches
36 const int kPDFLetterWidth = 8.5 * kPDFDpi; 42 const int kPDFLetterWidth = 8.5 * kPDFDpi;
37 const int kPDFLetterHeight = 11 * kPDFDpi; 43 const int kPDFLetterHeight = 11 * kPDFDpi;
38 // LEGAL: 8.5 x 14 inches 44 // LEGAL: 8.5 x 14 inches
39 const int kPDFLegalWidth = 8.5 * kPDFDpi; 45 const int kPDFLegalWidth = 8.5 * kPDFDpi;
40 const int kPDFLegalHeight = 14 * kPDFDpi; 46 const int kPDFLegalHeight = 14 * kPDFDpi;
41 // A4: 8.27 x 11.69 inches 47 // A4: 8.27 x 11.69 inches
42 const int kPDFA4Width = 8.27 * kPDFDpi; 48 const int kPDFA4Width = 8.27 * kPDFDpi;
43 const int kPDFA4Height = 11.69 * kPDFDpi; 49 const int kPDFA4Height = 11.69 * kPDFDpi;
44 // A3: 11.69 x 16.54 inches 50 // A3: 11.69 x 16.54 inches
45 const int kPDFA3Width = 11.69 * kPDFDpi; 51 const int kPDFA3Width = 11.69 * kPDFDpi;
46 const int kPDFA3Height = 16.54 * kPDFDpi; 52 const int kPDFA3Height = 16.54 * kPDFDpi;
47 53
54 HWND GetRootWindow(gfx::NativeView view) {
55 HWND window = NULL;
56 #if defined(USE_AURA)
57 if (view)
58 window = view->GetRootWindow()->GetAcceleratedWidget();
59 #else
60 if (view && IsWindow(view)) {
61 window = GetAncestor(view, GA_ROOTOWNER);
62 }
63 #endif
64 if (!window) {
65 // TODO(maruel): bug 1214347 Get the right browser window instead.
66 return GetDesktopWindow();
67 }
68 return window;
69 }
70
48 } // anonymous namespace 71 } // anonymous namespace
49 72
50 namespace printing { 73 namespace printing {
51 74
52 class PrintingContextWin::CallbackHandler : public IPrintDialogCallback, 75 class PrintingContextWin::CallbackHandler : public IPrintDialogCallback,
53 public IObjectWithSite { 76 public IObjectWithSite {
54 public: 77 public:
55 CallbackHandler(PrintingContextWin& owner, HWND owner_hwnd) 78 CallbackHandler(PrintingContextWin& owner, HWND owner_hwnd)
56 : owner_(owner), 79 : owner_(owner),
57 owner_hwnd_(owner_hwnd), 80 owner_hwnd_(owner_hwnd),
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after
159 : PrintingContext(app_locale), 182 : PrintingContext(app_locale),
160 context_(NULL), 183 context_(NULL),
161 dialog_box_(NULL), 184 dialog_box_(NULL),
162 print_dialog_func_(&PrintDlgEx) { 185 print_dialog_func_(&PrintDlgEx) {
163 } 186 }
164 187
165 PrintingContextWin::~PrintingContextWin() { 188 PrintingContextWin::~PrintingContextWin() {
166 ReleaseContext(); 189 ReleaseContext();
167 } 190 }
168 191
192 // TODO(vitalybuka): Implement as ui::BaseShellDialog crbug.com/180997.
169 void PrintingContextWin::AskUserForSettings( 193 void PrintingContextWin::AskUserForSettings(
170 gfx::NativeView view, int max_pages, bool has_selection, 194 gfx::NativeView view, int max_pages, bool has_selection,
171 const PrintSettingsCallback& callback) { 195 const PrintSettingsCallback& callback) {
172 #if !defined(USE_AURA)
173 DCHECK(!in_print_job_); 196 DCHECK(!in_print_job_);
174
175 if (win8::IsSingleWindowMetroMode()) { 197 if (win8::IsSingleWindowMetroMode()) {
176 // The system dialog can not be opened while running in Metro. 198 // The system dialog can not be opened while running in Metro.
177 // But we can programatically launch the Metro print device charm though. 199 // But we can programatically launch the Metro print device charm though.
178 HMODULE metro_module = base::win::GetMetroModule(); 200 HMODULE metro_module = base::win::GetMetroModule();
179 if (metro_module != NULL) { 201 if (metro_module != NULL) {
180 typedef void (*MetroShowPrintUI)(); 202 typedef void (*MetroShowPrintUI)();
181 MetroShowPrintUI metro_show_print_ui = 203 MetroShowPrintUI metro_show_print_ui =
182 reinterpret_cast<MetroShowPrintUI>( 204 reinterpret_cast<MetroShowPrintUI>(
183 ::GetProcAddress(metro_module, "MetroShowPrintUI")); 205 ::GetProcAddress(metro_module, "MetroShowPrintUI"));
184 if (metro_show_print_ui) { 206 if (metro_show_print_ui) {
185 // TODO(mad): Remove this once we can send user metrics from the metro 207 // TODO(mad): Remove this once we can send user metrics from the metro
186 // driver. crbug.com/142330 208 // driver. crbug.com/142330
187 UMA_HISTOGRAM_ENUMERATION("Metro.Print", 1, 2); 209 UMA_HISTOGRAM_ENUMERATION("Metro.Print", 1, 2);
188 metro_show_print_ui(); 210 metro_show_print_ui();
189 } 211 }
190 } 212 }
191 return callback.Run(CANCEL); 213 return callback.Run(CANCEL);
192 } 214 }
193 dialog_box_dismissed_ = false; 215 dialog_box_dismissed_ = false;
194 216
195 HWND window; 217 HWND window = GetRootWindow(view);
196 if (!view || !IsWindow(view)) {
197 // TODO(maruel): bug 1214347 Get the right browser window instead.
198 window = GetDesktopWindow();
199 } else {
200 window = GetAncestor(view, GA_ROOTOWNER);
201 }
202 DCHECK(window); 218 DCHECK(window);
203 219
204 // Show the OS-dependent dialog box. 220 // Show the OS-dependent dialog box.
205 // If the user press 221 // If the user press
206 // - OK, the settings are reset and reinitialized with the new settings. OK is 222 // - OK, the settings are reset and reinitialized with the new settings. OK is
207 // returned. 223 // returned.
208 // - Apply then Cancel, the settings are reset and reinitialized with the new 224 // - Apply then Cancel, the settings are reset and reinitialized with the new
209 // settings. CANCEL is returned. 225 // settings. CANCEL is returned.
210 // - Cancel, the settings are not changed, the previous setting, if it was 226 // - Cancel, the settings are not changed, the previous setting, if it was
211 // initialized before, are kept. CANCEL is returned. 227 // initialized before, are kept. CANCEL is returned.
(...skipping 17 matching lines...) Expand all
229 dialog_options.nPageRanges = 1; 245 dialog_options.nPageRanges = 1;
230 dialog_options.nMaxPageRanges = arraysize(ranges); 246 dialog_options.nMaxPageRanges = arraysize(ranges);
231 dialog_options.nMinPage = 1; 247 dialog_options.nMinPage = 1;
232 dialog_options.nMaxPage = max_pages; 248 dialog_options.nMaxPage = max_pages;
233 dialog_options.lpPageRanges = ranges; 249 dialog_options.lpPageRanges = ranges;
234 } else { 250 } else {
235 // No need to bother, we don't know how many pages are available. 251 // No need to bother, we don't know how many pages are available.
236 dialog_options.Flags |= PD_NOPAGENUMS; 252 dialog_options.Flags |= PD_NOPAGENUMS;
237 } 253 }
238 254
239 if ((*print_dialog_func_)(&dialog_options) != S_OK) { 255 HRESULT hr = (*print_dialog_func_)(&dialog_options);
256 if (hr != S_OK) {
240 ResetSettings(); 257 ResetSettings();
241 callback.Run(FAILED); 258 callback.Run(FAILED);
242 } 259 }
243 260
244 // TODO(maruel): Support PD_PRINTTOFILE. 261 // TODO(maruel): Support PD_PRINTTOFILE.
245 callback.Run(ParseDialogResultEx(dialog_options)); 262 callback.Run(ParseDialogResultEx(dialog_options));
246 #endif
247 } 263 }
248 264
249 PrintingContext::Result PrintingContextWin::UseDefaultSettings() { 265 PrintingContext::Result PrintingContextWin::UseDefaultSettings() {
250 DCHECK(!in_print_job_); 266 DCHECK(!in_print_job_);
251 267
252 PRINTDLG dialog_options = { sizeof(PRINTDLG) }; 268 PRINTDLG dialog_options = { sizeof(PRINTDLG) };
253 dialog_options.Flags = PD_RETURNDC | PD_RETURNDEFAULT; 269 dialog_options.Flags = PD_RETURNDC | PD_RETURNDEFAULT;
254 if (PrintDlg(&dialog_options)) 270 if (PrintDlg(&dialog_options))
255 return ParseDialogResult(dialog_options); 271 return ParseDialogResult(dialog_options);
256 272
(...skipping 496 matching lines...) Expand 10 before | Expand all | Expand 10 after
753 769
754 if (dialog_options.hDevMode != NULL) 770 if (dialog_options.hDevMode != NULL)
755 GlobalFree(dialog_options.hDevMode); 771 GlobalFree(dialog_options.hDevMode);
756 if (dialog_options.hDevNames != NULL) 772 if (dialog_options.hDevNames != NULL)
757 GlobalFree(dialog_options.hDevNames); 773 GlobalFree(dialog_options.hDevNames);
758 774
759 return context_ ? OK : FAILED; 775 return context_ ? OK : FAILED;
760 } 776 }
761 777
762 } // namespace printing 778 } // namespace printing
OLDNEW
« no previous file with comments | « printing/printing.gyp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698