| 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> | 7 #include <winspool.h> |
| 8 | 8 |
| 9 #include <algorithm> | 9 #include <algorithm> |
| 10 | 10 |
| (...skipping 18 matching lines...) Expand all Loading... |
| 29 #if defined(USE_AURA) | 29 #if defined(USE_AURA) |
| 30 #include "ui/aura/remote_root_window_host_win.h" | 30 #include "ui/aura/remote_root_window_host_win.h" |
| 31 #include "ui/aura/root_window.h" | 31 #include "ui/aura/root_window.h" |
| 32 #include "ui/aura/window.h" | 32 #include "ui/aura/window.h" |
| 33 #endif | 33 #endif |
| 34 | 34 |
| 35 using base::Time; | 35 using base::Time; |
| 36 | 36 |
| 37 namespace { | 37 namespace { |
| 38 | 38 |
| 39 // Constants for setting default PDF settings. | |
| 40 const int kPDFDpi = 300; // 300 dpi | |
| 41 // LETTER: 8.5 x 11 inches | |
| 42 const int kPDFLetterWidth = 8.5 * kPDFDpi; | |
| 43 const int kPDFLetterHeight = 11 * kPDFDpi; | |
| 44 // LEGAL: 8.5 x 14 inches | |
| 45 const int kPDFLegalWidth = 8.5 * kPDFDpi; | |
| 46 const int kPDFLegalHeight = 14 * kPDFDpi; | |
| 47 // A4: 8.27 x 11.69 inches | |
| 48 const int kPDFA4Width = 8.27 * kPDFDpi; | |
| 49 const int kPDFA4Height = 11.69 * kPDFDpi; | |
| 50 // A3: 11.69 x 16.54 inches | |
| 51 const int kPDFA3Width = 11.69 * kPDFDpi; | |
| 52 const int kPDFA3Height = 16.54 * kPDFDpi; | |
| 53 | |
| 54 HWND GetRootWindow(gfx::NativeView view) { | 39 HWND GetRootWindow(gfx::NativeView view) { |
| 55 HWND window = NULL; | 40 HWND window = NULL; |
| 56 #if defined(USE_AURA) | 41 #if defined(USE_AURA) |
| 57 if (view) | 42 if (view) |
| 58 window = view->GetDispatcher()->GetAcceleratedWidget(); | 43 window = view->GetDispatcher()->GetAcceleratedWidget(); |
| 59 #else | 44 #else |
| 60 if (view && IsWindow(view)) { | 45 if (view && IsWindow(view)) { |
| 61 window = GetAncestor(view, GA_ROOTOWNER); | 46 window = GetAncestor(view, GA_ROOTOWNER); |
| 62 } | 47 } |
| 63 #endif | 48 #endif |
| (...skipping 236 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 300 } | 285 } |
| 301 if (context_) | 286 if (context_) |
| 302 return OK; | 287 return OK; |
| 303 } | 288 } |
| 304 } | 289 } |
| 305 | 290 |
| 306 ResetSettings(); | 291 ResetSettings(); |
| 307 return FAILED; | 292 return FAILED; |
| 308 } | 293 } |
| 309 | 294 |
| 295 gfx::Size PrintingContextWin::GetPdfPaperSizeDeviceUnits() { |
| 296 // Default fallback to Letter size. |
| 297 gfx::SizeF paper_size(kLetterWidthInch, kLetterHeightInch); |
| 298 |
| 299 // Get settings from locale. Paper type buffer length is at most 4. |
| 300 const int paper_type_buffer_len = 4; |
| 301 wchar_t paper_type_buffer[paper_type_buffer_len] = {0}; |
| 302 GetLocaleInfo(LOCALE_USER_DEFAULT, LOCALE_IPAPERSIZE, paper_type_buffer, |
| 303 paper_type_buffer_len); |
| 304 if (wcslen(paper_type_buffer)) { // The call succeeded. |
| 305 int paper_code = _wtoi(paper_type_buffer); |
| 306 switch (paper_code) { |
| 307 case DMPAPER_LEGAL: |
| 308 paper_size.SetSize(kLegalWidthInch, kLegalHeightInch); |
| 309 break; |
| 310 case DMPAPER_A4: |
| 311 paper_size.SetSize(kA4WidthInch, kA4HeightInch); |
| 312 break; |
| 313 case DMPAPER_A3: |
| 314 paper_size.SetSize(kA3WidthInch, kA3HeightInch); |
| 315 break; |
| 316 default: // DMPAPER_LETTER is used for default fallback. |
| 317 break; |
| 318 } |
| 319 } |
| 320 return gfx::Size( |
| 321 paper_size.width() * settings_.device_units_per_inch(), |
| 322 paper_size.height() * settings_.device_units_per_inch()); |
| 323 } |
| 324 |
| 310 PrintingContext::Result PrintingContextWin::UpdatePrinterSettings( | 325 PrintingContext::Result PrintingContextWin::UpdatePrinterSettings( |
| 311 bool target_is_pdf, | |
| 312 bool external_preview) { | 326 bool external_preview) { |
| 313 DCHECK(!in_print_job_); | 327 DCHECK(!in_print_job_); |
| 314 DCHECK(!external_preview) << "Not implemented"; | 328 DCHECK(!external_preview) << "Not implemented"; |
| 315 | 329 |
| 316 if (target_is_pdf) { | |
| 317 // Default fallback to Letter size. | |
| 318 gfx::Size paper_size; | |
| 319 gfx::Rect paper_rect; | |
| 320 paper_size.SetSize(kPDFLetterWidth, kPDFLetterHeight); | |
| 321 | |
| 322 // Get settings from locale. Paper type buffer length is at most 4. | |
| 323 const int paper_type_buffer_len = 4; | |
| 324 wchar_t paper_type_buffer[paper_type_buffer_len] = {0}; | |
| 325 GetLocaleInfo(LOCALE_USER_DEFAULT, LOCALE_IPAPERSIZE, paper_type_buffer, | |
| 326 paper_type_buffer_len); | |
| 327 if (wcslen(paper_type_buffer)) { // The call succeeded. | |
| 328 int paper_code = _wtoi(paper_type_buffer); | |
| 329 switch (paper_code) { | |
| 330 case DMPAPER_LEGAL: | |
| 331 paper_size.SetSize(kPDFLegalWidth, kPDFLegalHeight); | |
| 332 break; | |
| 333 case DMPAPER_A4: | |
| 334 paper_size.SetSize(kPDFA4Width, kPDFA4Height); | |
| 335 break; | |
| 336 case DMPAPER_A3: | |
| 337 paper_size.SetSize(kPDFA3Width, kPDFA3Height); | |
| 338 break; | |
| 339 default: // DMPAPER_LETTER is used for default fallback. | |
| 340 break; | |
| 341 } | |
| 342 } | |
| 343 paper_rect.SetRect(0, 0, paper_size.width(), paper_size.height()); | |
| 344 settings_.SetPrinterPrintableArea(paper_size, paper_rect, kPDFDpi, true); | |
| 345 settings_.set_dpi(kPDFDpi); | |
| 346 return OK; | |
| 347 } | |
| 348 | |
| 349 ScopedPrinterHandle printer; | 330 ScopedPrinterHandle printer; |
| 350 LPWSTR device_name_wide = | 331 LPWSTR device_name_wide = |
| 351 const_cast<wchar_t*>(settings_.device_name().c_str()); | 332 const_cast<wchar_t*>(settings_.device_name().c_str()); |
| 352 if (!printer.OpenPrinter(device_name_wide)) | 333 if (!printer.OpenPrinter(device_name_wide)) |
| 353 return OnError(); | 334 return OnError(); |
| 354 | 335 |
| 355 // Make printer changes local to Chrome. | 336 // Make printer changes local to Chrome. |
| 356 // See MSDN documentation regarding DocumentProperties. | 337 // See MSDN documentation regarding DocumentProperties. |
| 357 scoped_ptr<uint8[]> buffer; | 338 scoped_ptr<uint8[]> buffer; |
| 358 DEVMODE* dev_mode = NULL; | 339 DEVMODE* dev_mode = NULL; |
| (...skipping 401 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 760 | 741 |
| 761 if (dialog_options.hDevMode != NULL) | 742 if (dialog_options.hDevMode != NULL) |
| 762 GlobalFree(dialog_options.hDevMode); | 743 GlobalFree(dialog_options.hDevMode); |
| 763 if (dialog_options.hDevNames != NULL) | 744 if (dialog_options.hDevNames != NULL) |
| 764 GlobalFree(dialog_options.hDevNames); | 745 GlobalFree(dialog_options.hDevNames); |
| 765 | 746 |
| 766 return context_ ? OK : FAILED; | 747 return context_ ? OK : FAILED; |
| 767 } | 748 } |
| 768 | 749 |
| 769 } // namespace printing | 750 } // namespace printing |
| OLD | NEW |