diff options
-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 | ||||
-rw-r--r-- | ui/shell_dialogs/base_shell_dialog_win.cc | 4 | ||||
-rw-r--r-- | ui/shell_dialogs/print_settings_dialog_win.cc | 58 | ||||
-rw-r--r-- | ui/shell_dialogs/print_settings_dialog_win.h | 83 |
7 files changed, 24 insertions, 196 deletions
diff --git a/printing/DEPS b/printing/DEPS index bc43b41..97c498b 100644 --- a/printing/DEPS +++ b/printing/DEPS @@ -8,6 +8,5 @@ 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 4b4646b..adcab4b 100644 --- a/printing/printing.gyp +++ b/printing/printing.gyp @@ -19,7 +19,6 @@ '../third_party/icu/icu.gyp:icuuc', '../ui/gfx/gfx.gyp:gfx', '../ui/gfx/gfx.gyp:gfx_geometry', - '../ui/shell_dialogs/shell_dialogs.gyp:shell_dialogs', '../url/url.gyp:url_lib', ], 'defines': [ diff --git a/printing/printing_context_win.cc b/printing/printing_context_win.cc index 1c1e3af..a2c3ada 100644 --- a/printing/printing_context_win.cc +++ b/printing/printing_context_win.cc @@ -175,11 +175,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. @@ -212,40 +212,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 = - reinterpret_cast<PRINTDLGEX*>(malloc(sizeof(PRINTDLGEX))); - ZeroMemory(dialog_options, sizeof(PRINTDLGEX)); - dialog_options->lStructSize = sizeof(PRINTDLGEX); - dialog_options->hwndOwner = window; + PRINTDLGEX dialog_options = { 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; - const size_t max_page_ranges = 32; - PRINTPAGERANGE* ranges = new PRINTPAGERANGE[max_page_ranges]; - dialog_options->lpPageRanges = ranges; - dialog_options->nStartPage = START_PAGE_GENERAL; + PRINTPAGERANGE ranges[32]; + 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 = max_page_ranges; - dialog_options->nMinPage = 1; - dialog_options->nMaxPage = max_pages; + dialog_options.nPageRanges = 1; + dialog_options.nMaxPageRanges = arraysize(ranges); + dialog_options.nMinPage = 1; + dialog_options.nMaxPage = max_pages; + dialog_options.lpPageRanges = ranges; } else { // No need to bother, we don't know how many pages are available. - dialog_options->Flags |= PD_NOPAGENUMS; + dialog_options.Flags |= PD_NOPAGENUMS; } - callback_ = callback; - print_settings_dialog_ = new ui::PrintSettingsDialogWin(this); - print_settings_dialog_->GetPrintSettings( - print_dialog_func_, window, dialog_options); + 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)); } PrintingContext::Result PrintingContextWin::UseDefaultSettings() { @@ -527,20 +527,6 @@ 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 3be4917..d0cd2fb 100644 --- a/printing/printing_context_win.h +++ b/printing/printing_context_win.h @@ -14,13 +14,10 @@ #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, - public ui::PrintSettingsDialogWin::Observer { +class PRINTING_EXPORT PrintingContextWin : public PrintingContext { public: explicit PrintingContextWin(const std::string& app_locale); ~PrintingContextWin(); @@ -43,10 +40,6 @@ class PRINTING_EXPORT PrintingContextWin 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)) { @@ -94,12 +87,6 @@ class PRINTING_EXPORT PrintingContextWin // 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); }; diff --git a/ui/shell_dialogs/base_shell_dialog_win.cc b/ui/shell_dialogs/base_shell_dialog_win.cc index e121fbf..9ccd1bb 100644 --- a/ui/shell_dialogs/base_shell_dialog_win.cc +++ b/ui/shell_dialogs/base_shell_dialog_win.cc @@ -30,9 +30,7 @@ BaseShellDialogImpl::RunState BaseShellDialogImpl::BeginRun(HWND owner) { DCHECK(!IsRunningDialogForOwner(owner)); // The owner must be a top level window, otherwise we could end up with two // entries in our map for the same top level window. - // TODO(scottmg): This should be re-enabled when Chrome Frame is removed. - // http://crbug.com/310264 - // DCHECK(!owner || owner == GetAncestor(owner, GA_ROOT)); + DCHECK(!owner || owner == GetAncestor(owner, GA_ROOT)); RunState run_state; run_state.dialog_thread = CreateDialogThread(); run_state.owner = owner; diff --git a/ui/shell_dialogs/print_settings_dialog_win.cc b/ui/shell_dialogs/print_settings_dialog_win.cc deleted file mode 100644 index f3f89b3..0000000 --- a/ui/shell_dialogs/print_settings_dialog_win.cc +++ /dev/null @@ -1,58 +0,0 @@ -// Copyright 2013 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#include "ui/shell_dialogs/print_settings_dialog_win.h" - -#include "base/bind.h" -#include "base/threading/thread.h" - -#if defined(USE_AURA) -#include "ui/aura/root_window.h" -#endif - -namespace ui { - -PrintSettingsDialogWin::PrintSettingsDialogWin( - PrintSettingsDialogWin::Observer* observer) - : observer_(observer) { -} - -PrintSettingsDialogWin::~PrintSettingsDialogWin() { -} - -void PrintSettingsDialogWin::GetPrintSettings(PrintDialogFunc print_dialog_func, - HWND owning_window, - PRINTDLGEX* dialog_options) { - DCHECK(observer_); - - ExecutePrintSettingsParams execute_params(BeginRun(owning_window), - owning_window, - print_dialog_func, - dialog_options); - execute_params.run_state.dialog_thread->message_loop()->PostTask( - FROM_HERE, - base::Bind( - &PrintSettingsDialogWin::ExecutePrintSettings, this, execute_params)); -} - -void PrintSettingsDialogWin::ExecutePrintSettings( - const ExecutePrintSettingsParams& params) { - HRESULT hr = (*params.print_dialog_func)(params.dialog_options); - params.ui_proxy->PostTask( - FROM_HERE, - base::Bind( - &PrintSettingsDialogWin::PrintSettingsCompleted, this, hr, params)); -} - -void PrintSettingsDialogWin::PrintSettingsCompleted( - HRESULT hresult, - const ExecutePrintSettingsParams& params) { - EndRun(params.run_state); - if (hresult != S_OK) - observer_->PrintSettingsCancelled(params.dialog_options); - else - observer_->PrintSettingsConfirmed(params.dialog_options); -} - -} // namespace ui diff --git a/ui/shell_dialogs/print_settings_dialog_win.h b/ui/shell_dialogs/print_settings_dialog_win.h deleted file mode 100644 index 6a1efed..0000000 --- a/ui/shell_dialogs/print_settings_dialog_win.h +++ /dev/null @@ -1,83 +0,0 @@ -// Copyright 2013 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#ifndef UI_SHELL_DIALOGS_PRINT_SETTINGS_DIALOG_WIN_H_ -#define UI_SHELL_DIALOGS_PRINT_SETTINGS_DIALOG_WIN_H_ - -#include <ocidl.h> -#include <commdlg.h> - -#include "base/memory/ref_counted.h" -#include "base/memory/scoped_ptr.h" -#include "base/message_loop/message_loop.h" -#include "base/message_loop/message_loop_proxy.h" -#include "ui/shell_dialogs/base_shell_dialog_win.h" -#include "ui/shell_dialogs/shell_dialogs_export.h" - -namespace ui { - -// A thin wrapper around the native window print dialog that uses -// BaseShellDialog to have the dialog run on a background thread. -class SHELL_DIALOGS_EXPORT PrintSettingsDialogWin - : public base::RefCountedThreadSafe<PrintSettingsDialogWin>, - public BaseShellDialogImpl { - public: - class SHELL_DIALOGS_EXPORT Observer { - public: - virtual void PrintSettingsConfirmed(PRINTDLGEX* dialog_options) = 0; - virtual void PrintSettingsCancelled(PRINTDLGEX* dialog_options) = 0; - }; - typedef HRESULT(__stdcall* PrintDialogFunc)(PRINTDLGEX*); - - explicit PrintSettingsDialogWin(Observer* observer); - virtual ~PrintSettingsDialogWin(); - - // Called to open the system print dialog on a background thread. - // |print_dialog_func| should generally be ::PrintDlgEx, however alternate - // functions are used for testing. |owning_window| is the parent HWND, and - // |dialog_options| is passed to |print_dialog_func|. - void GetPrintSettings( - PrintDialogFunc print_dialog_func, - HWND owning_window, - PRINTDLGEX* dialog_options); - - private: - // A struct for holding all the state necessary for displaying the print - // settings dialog. - struct ExecutePrintSettingsParams { - ExecutePrintSettingsParams(RunState run_state, - HWND owner, - PrintDialogFunc print_dialog_func, - PRINTDLGEX* dialog_options) - : run_state(run_state), - owner(owner), - print_dialog_func(print_dialog_func), - dialog_options(dialog_options), - ui_proxy(base::MessageLoopForUI::current()->message_loop_proxy()) {} - - RunState run_state; - HWND owner; - PrintDialogFunc print_dialog_func; - PRINTDLGEX* dialog_options; - scoped_refptr<base::MessageLoopProxy> ui_proxy; - }; - - // Runs the print dialog. Should be run on the the BaseShellDialogImpl thread. - // Posts back to PrintSettingsCompleted on the UI thread on completion. - void ExecutePrintSettings(const ExecutePrintSettingsParams& params); - - // Handler for the result of the print settings dialog. Should be run on the - // UI thread, and notifies the observer of the result of the dialog. - void PrintSettingsCompleted(HRESULT hresult, - const ExecutePrintSettingsParams& params); - - // Observer that's notified when the dialog is confirmed or cancelled. - Observer* observer_; - - DISALLOW_COPY_AND_ASSIGN(PrintSettingsDialogWin); -}; - -} // namespace ui - -#endif // UI_SHELL_DIALOGS_PRINT_SETTINGS_DIALOG_WIN_H_ |