summaryrefslogtreecommitdiffstats
path: root/ui/shell_dialogs
diff options
context:
space:
mode:
authorscottmg@chromium.org <scottmg@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-10-22 22:43:58 +0000
committerscottmg@chromium.org <scottmg@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-10-22 22:43:58 +0000
commitcc0542991896f555eb6296e818a997ea15d3e8bd (patch)
treea88dd3cfd847fd58e1ffecfeb80568fae03712c9 /ui/shell_dialogs
parentddabf40051999238dbb8257ba05de15d1efb44bc (diff)
downloadchromium_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 'ui/shell_dialogs')
-rw-r--r--ui/shell_dialogs/base_shell_dialog_win.cc4
-rw-r--r--ui/shell_dialogs/print_settings_dialog_win.cc58
-rw-r--r--ui/shell_dialogs/print_settings_dialog_win.h83
3 files changed, 144 insertions, 1 deletions
diff --git a/ui/shell_dialogs/base_shell_dialog_win.cc b/ui/shell_dialogs/base_shell_dialog_win.cc
index 9ccd1bb..e121fbf 100644
--- a/ui/shell_dialogs/base_shell_dialog_win.cc
+++ b/ui/shell_dialogs/base_shell_dialog_win.cc
@@ -30,7 +30,9 @@ 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.
- DCHECK(!owner || owner == GetAncestor(owner, GA_ROOT));
+ // TODO(scottmg): This should be re-enabled when Chrome Frame is removed.
+ // http://crbug.com/310264
+ // 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
new file mode 100644
index 0000000..f3f89b3
--- /dev/null
+++ b/ui/shell_dialogs/print_settings_dialog_win.cc
@@ -0,0 +1,58 @@
+// 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
new file mode 100644
index 0000000..6a1efed
--- /dev/null
+++ b/ui/shell_dialogs/print_settings_dialog_win.h
@@ -0,0 +1,83 @@
+// 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_