1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "ui/shell_dialogs/print_settings_dialog_win.h"
6
7 #include "base/bind.h"
8 #include "base/threading/thread.h"
9
10 #if defined(USE_AURA)
11 #include "ui/aura/root_window.h"
12 #endif
13
14 namespace ui {
15
PrintSettingsDialogWin(PrintSettingsDialogWin::Observer * observer)16 PrintSettingsDialogWin::PrintSettingsDialogWin(
17 PrintSettingsDialogWin::Observer* observer)
18 : observer_(observer) {
19 }
20
~PrintSettingsDialogWin()21 PrintSettingsDialogWin::~PrintSettingsDialogWin() {
22 }
23
GetPrintSettings(PrintDialogFunc print_dialog_func,HWND owning_window,PRINTDLGEX * dialog_options)24 void PrintSettingsDialogWin::GetPrintSettings(PrintDialogFunc print_dialog_func,
25 HWND owning_window,
26 PRINTDLGEX* dialog_options) {
27 DCHECK(observer_);
28
29 ExecutePrintSettingsParams execute_params(BeginRun(owning_window),
30 owning_window,
31 print_dialog_func,
32 dialog_options);
33 execute_params.run_state.dialog_thread->message_loop()->PostTask(
34 FROM_HERE,
35 base::Bind(
36 &PrintSettingsDialogWin::ExecutePrintSettings, this, execute_params));
37 }
38
ExecutePrintSettings(const ExecutePrintSettingsParams & params)39 void PrintSettingsDialogWin::ExecutePrintSettings(
40 const ExecutePrintSettingsParams& params) {
41 HRESULT hr = (*params.print_dialog_func)(params.dialog_options);
42 params.ui_proxy->PostTask(
43 FROM_HERE,
44 base::Bind(
45 &PrintSettingsDialogWin::PrintSettingsCompleted, this, hr, params));
46 }
47
PrintSettingsCompleted(HRESULT hresult,const ExecutePrintSettingsParams & params)48 void PrintSettingsDialogWin::PrintSettingsCompleted(
49 HRESULT hresult,
50 const ExecutePrintSettingsParams& params) {
51 EndRun(params.run_state);
52 if (hresult != S_OK)
53 observer_->PrintSettingsCancelled(params.dialog_options);
54 else
55 observer_->PrintSettingsConfirmed(params.dialog_options);
56 }
57
58 } // namespace ui
59