diff options
author | scottmg@chromium.org <scottmg@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-10-22 22:43:58 +0000 |
---|---|---|
committer | scottmg@chromium.org <scottmg@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-10-22 22:43:58 +0000 |
commit | cc0542991896f555eb6296e818a997ea15d3e8bd (patch) | |
tree | a88dd3cfd847fd58e1ffecfeb80568fae03712c9 /printing | |
parent | ddabf40051999238dbb8257ba05de15d1efb44bc (diff) | |
download | chromium_src-cc0542991896f555eb6296e818a997ea15d3e8bd.zip chromium_src-cc0542991896f555eb6296e818a997ea15d3e8bd.tar.gz chromium_src-cc0542991896f555eb6296e818a997ea15d3e8bd.tar.bz2 |
Use BaseShellDialog for print dialog on Windows
This puts the print dialog on a background thread which is necessary so other
top level windows can keep painting as Aura does the compositor swaps on the
UI thread.
R=sky@chromium.org,vitalybuka@chromium.org
BUG=180997
Review URL: https://codereview.chromium.org/27441003
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@230235 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'printing')
-rw-r--r-- | printing/DEPS | 1 | ||||
-rw-r--r-- | printing/printing.gyp | 1 | ||||
-rw-r--r-- | printing/printing_context_win.cc | 58 | ||||
-rw-r--r-- | printing/printing_context_win.h | 15 |
4 files changed, 52 insertions, 23 deletions
diff --git a/printing/DEPS b/printing/DEPS index 00c20e2..64123b8 100644 --- a/printing/DEPS +++ b/printing/DEPS @@ -7,5 +7,6 @@ include_rules = [ "+ui/base/resource", "+ui/base/text", "+ui/gfx", + "+ui/shell_dialogs", "+win8/util", ] diff --git a/printing/printing.gyp b/printing/printing.gyp index 455786e..c7ff11e 100644 --- a/printing/printing.gyp +++ b/printing/printing.gyp @@ -18,6 +18,7 @@ '../third_party/icu/icu.gyp:icui18n', '../third_party/icu/icu.gyp:icuuc', '../ui/gfx/gfx.gyp:gfx', + '../ui/ui.gyp:shell_dialogs', '../ui/ui.gyp:ui', '../url/url.gyp:url_lib', ], diff --git a/printing/printing_context_win.cc b/printing/printing_context_win.cc index 642ada6..29b2604 100644 --- a/printing/printing_context_win.cc +++ b/printing/printing_context_win.cc @@ -189,11 +189,11 @@ PrintingContextWin::~PrintingContextWin() { ReleaseContext(); } -// TODO(vitalybuka): Implement as ui::BaseShellDialog crbug.com/180997. void PrintingContextWin::AskUserForSettings( gfx::NativeView view, int max_pages, bool has_selection, const PrintSettingsCallback& callback) { DCHECK(!in_print_job_); + // TODO(scottmg): Possibly this has to move into the threaded runner too? if (win8::IsSingleWindowMetroMode()) { // The system dialog can not be opened while running in Metro. // But we can programatically launch the Metro print device charm though. @@ -226,40 +226,40 @@ void PrintingContextWin::AskUserForSettings( // - Cancel, the settings are not changed, the previous setting, if it was // initialized before, are kept. CANCEL is returned. // On failure, the settings are reset and FAILED is returned. - PRINTDLGEX dialog_options = { sizeof(PRINTDLGEX) }; - dialog_options.hwndOwner = window; + PRINTDLGEX* dialog_options = + reinterpret_cast<PRINTDLGEX*>(malloc(sizeof(PRINTDLGEX))); + ZeroMemory(dialog_options, sizeof(PRINTDLGEX)); + dialog_options->lStructSize = sizeof(PRINTDLGEX); + dialog_options->hwndOwner = window; // Disable options we don't support currently. // TODO(maruel): Reuse the previously loaded settings! - dialog_options.Flags = PD_RETURNDC | PD_USEDEVMODECOPIESANDCOLLATE | - PD_NOCURRENTPAGE | PD_HIDEPRINTTOFILE; + dialog_options->Flags = PD_RETURNDC | PD_USEDEVMODECOPIESANDCOLLATE | + PD_NOCURRENTPAGE | PD_HIDEPRINTTOFILE; if (!has_selection) - dialog_options.Flags |= PD_NOSELECTION; + dialog_options->Flags |= PD_NOSELECTION; - PRINTPAGERANGE ranges[32]; - dialog_options.nStartPage = START_PAGE_GENERAL; + const size_t max_page_ranges = 32; + PRINTPAGERANGE* ranges = new PRINTPAGERANGE[max_page_ranges]; + dialog_options->lpPageRanges = ranges; + dialog_options->nStartPage = START_PAGE_GENERAL; if (max_pages) { // Default initialize to print all the pages. memset(ranges, 0, sizeof(ranges)); ranges[0].nFromPage = 1; ranges[0].nToPage = max_pages; - dialog_options.nPageRanges = 1; - dialog_options.nMaxPageRanges = arraysize(ranges); - dialog_options.nMinPage = 1; - dialog_options.nMaxPage = max_pages; - dialog_options.lpPageRanges = ranges; + dialog_options->nPageRanges = 1; + dialog_options->nMaxPageRanges = max_page_ranges; + dialog_options->nMinPage = 1; + dialog_options->nMaxPage = max_pages; } else { // No need to bother, we don't know how many pages are available. - dialog_options.Flags |= PD_NOPAGENUMS; + dialog_options->Flags |= PD_NOPAGENUMS; } - HRESULT hr = (*print_dialog_func_)(&dialog_options); - if (hr != S_OK) { - ResetSettings(); - callback.Run(FAILED); - } - - // TODO(maruel): Support PD_PRINTTOFILE. - callback.Run(ParseDialogResultEx(dialog_options)); + callback_ = callback; + print_settings_dialog_ = new ui::PrintSettingsDialogWin(this); + print_settings_dialog_->GetPrintSettings( + print_dialog_func_, window, dialog_options); } PrintingContext::Result PrintingContextWin::UseDefaultSettings() { @@ -565,6 +565,20 @@ gfx::NativeDrawingContext PrintingContextWin::context() const { return context_; } +void PrintingContextWin::PrintSettingsConfirmed(PRINTDLGEX* dialog_options) { + // TODO(maruel): Support PD_PRINTTOFILE. + callback_.Run(ParseDialogResultEx(*dialog_options)); + delete [] dialog_options->lpPageRanges; + free(dialog_options); +} + +void PrintingContextWin::PrintSettingsCancelled(PRINTDLGEX* dialog_options) { + ResetSettings(); + callback_.Run(FAILED); + delete [] dialog_options->lpPageRanges; + free(dialog_options); +} + // static BOOL PrintingContextWin::AbortProc(HDC hdc, int nCode) { if (nCode) { diff --git a/printing/printing_context_win.h b/printing/printing_context_win.h index c54b531..06226b2 100644 --- a/printing/printing_context_win.h +++ b/printing/printing_context_win.h @@ -14,10 +14,13 @@ #include "build/build_config.h" #include "printing/printing_context.h" #include "ui/gfx/native_widget_types.h" +#include "ui/shell_dialogs/print_settings_dialog_win.h" namespace printing { -class PRINTING_EXPORT PrintingContextWin : public PrintingContext { +class PRINTING_EXPORT PrintingContextWin + : public PrintingContext, + public ui::PrintSettingsDialogWin::Observer { public: explicit PrintingContextWin(const std::string& app_locale); ~PrintingContextWin(); @@ -41,6 +44,10 @@ class PRINTING_EXPORT PrintingContextWin : public PrintingContext { virtual void ReleaseContext() OVERRIDE; virtual gfx::NativeDrawingContext context() const OVERRIDE; + // PrintSettingsDialogWin::Observer implementation: + virtual void PrintSettingsConfirmed(PRINTDLGEX* dialog_options) OVERRIDE; + virtual void PrintSettingsCancelled(PRINTDLGEX* dialog_options) OVERRIDE; + #if defined(UNIT_TEST) || defined(PRINTING_IMPLEMENTATION) // Sets a fake PrintDlgEx function pointer in tests. void SetPrintDialog(HRESULT (__stdcall *print_dialog_func)(LPPRINTDLGEX)) { @@ -88,6 +95,12 @@ class PRINTING_EXPORT PrintingContextWin : public PrintingContext { // SetPrintDialog() in tests. HRESULT (__stdcall *print_dialog_func_)(LPPRINTDLGEX); + // Where to notify when the dialog is closed. + PrintSettingsCallback callback_; + + // Wrapper around native print dialog that runs it on a background thread. + scoped_refptr<ui::PrintSettingsDialogWin> print_settings_dialog_; + DISALLOW_COPY_AND_ASSIGN(PrintingContextWin); }; |