summaryrefslogtreecommitdiffstats
path: root/chrome/browser/printing
diff options
context:
space:
mode:
authorsverrir@google.com <sverrir@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2009-06-08 17:05:21 +0000
committersverrir@google.com <sverrir@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2009-06-08 17:05:21 +0000
commitc8ad40c6b02751c1cc942abe4ecaffbf68bfa611 (patch)
treed34b6d63f8a66fb06c3f87ce1914eefb755cf441 /chrome/browser/printing
parenta91d541c58ad5e3b46309ee279bc569734a22564 (diff)
downloadchromium_src-c8ad40c6b02751c1cc942abe4ecaffbf68bfa611.zip
chromium_src-c8ad40c6b02751c1cc942abe4ecaffbf68bfa611.tar.gz
chromium_src-c8ad40c6b02751c1cc942abe4ecaffbf68bfa611.tar.bz2
Add support for printing selection only flag. This only adds the flag to the IPC and implements the Windows dialog interaction but does not enable this just yet.
BUG=http://crbug.com/1682 TEST=none Review URL: http://codereview.chromium.org/118338 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@17867 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/printing')
-rw-r--r--chrome/browser/printing/print_job_worker.cc6
-rw-r--r--chrome/browser/printing/print_job_worker.h3
-rw-r--r--chrome/browser/printing/print_settings.cc7
-rw-r--r--chrome/browser/printing/print_settings.h6
-rw-r--r--chrome/browser/printing/printer_query.cc4
-rw-r--r--chrome/browser/printing/printer_query.h1
-rw-r--r--chrome/browser/printing/win_printing_context.cc65
-rw-r--r--chrome/browser/printing/win_printing_context.h11
8 files changed, 67 insertions, 36 deletions
diff --git a/chrome/browser/printing/print_job_worker.cc b/chrome/browser/printing/print_job_worker.cc
index d325bb9..19c2add 100644
--- a/chrome/browser/printing/print_job_worker.cc
+++ b/chrome/browser/printing/print_job_worker.cc
@@ -66,7 +66,8 @@ void PrintJobWorker::SetNewOwner(PrintJobWorkerOwner* new_owner) {
void PrintJobWorker::GetSettings(bool ask_user_for_settings,
HWND parent_window,
- int document_page_count) {
+ int document_page_count,
+ bool has_selection) {
DCHECK_EQ(message_loop(), MessageLoop::current());
DCHECK_EQ(page_number_, PageNumber::npos());
@@ -77,7 +78,8 @@ void PrintJobWorker::GetSettings(bool ask_user_for_settings,
PrintingContext::Result result;
if (ask_user_for_settings) {
result = printing_context_.AskUserForSettings(parent_window,
- document_page_count);
+ document_page_count,
+ has_selection);
} else {
result = printing_context_.UseDefaultSettings();
}
diff --git a/chrome/browser/printing/print_job_worker.h b/chrome/browser/printing/print_job_worker.h
index 3142567..cc1bde1 100644
--- a/chrome/browser/printing/print_job_worker.h
+++ b/chrome/browser/printing/print_job_worker.h
@@ -34,7 +34,8 @@ class PrintJobWorker : public base::Thread {
// Print... dialog box will be shown to ask the user his preference.
void GetSettings(bool ask_user_for_settings,
HWND parent_window,
- int document_page_count);
+ int document_page_count,
+ bool has_selection);
// Starts the printing loop. Every pages are printed as soon as the data is
// available. Makes sure the new_document is the right one.
diff --git a/chrome/browser/printing/print_settings.cc b/chrome/browser/printing/print_settings.cc
index 8c33acd..e25a937 100644
--- a/chrome/browser/printing/print_settings.cc
+++ b/chrome/browser/printing/print_settings.cc
@@ -18,6 +18,7 @@ PrintSettings::PrintSettings()
: min_shrink(1.25),
max_shrink(2.0),
desired_dpi(72),
+ selection_only(false),
dpi_(0),
landscape_(false) {
}
@@ -27,6 +28,7 @@ void PrintSettings::Clear() {
min_shrink = 1.25;
max_shrink = 2.;
desired_dpi = 72;
+ selection_only = false;
printer_name_.clear();
device_name_.clear();
page_setup_pixels_.Clear();
@@ -38,12 +40,14 @@ void PrintSettings::Clear() {
void PrintSettings::Init(HDC hdc,
const DEVMODE& dev_mode,
const PageRanges& new_ranges,
- const std::wstring& new_device_name) {
+ const std::wstring& new_device_name,
+ bool print_selection_only) {
DCHECK(hdc);
printer_name_ = dev_mode.dmDeviceName;
device_name_ = new_device_name;
ranges = new_ranges;
landscape_ = dev_mode.dmOrientation == DMORIENT_LANDSCAPE;
+ selection_only = print_selection_only;
dpi_ = GetDeviceCaps(hdc, LOGPIXELSX);
// No printer device is known to advertise different dpi in X and Y axis; even
@@ -101,6 +105,7 @@ void PrintSettings::RenderParams(ViewMsg_Print_Params* params) const {
params->desired_dpi = desired_dpi;
// Always use an invalid cookie.
params->document_cookie = 0;
+ params->selection_only = selection_only;
}
bool PrintSettings::Equals(const PrintSettings& rhs) const {
diff --git a/chrome/browser/printing/print_settings.h b/chrome/browser/printing/print_settings.h
index da65cb3..a82af96 100644
--- a/chrome/browser/printing/print_settings.h
+++ b/chrome/browser/printing/print_settings.h
@@ -30,7 +30,8 @@ class PrintSettings {
void Init(HDC hdc,
const DEVMODE& dev_mode,
const PageRanges& new_ranges,
- const std::wstring& new_device_name);
+ const std::wstring& new_device_name,
+ bool selection_only);
#endif
// Set printer printable area in in pixels.
@@ -78,6 +79,9 @@ class PrintSettings {
// The various overlays (headers and footers).
PageOverlays overlays;
+ // Indicates if the user only wants to print the current selection.
+ bool selection_only;
+
// Cookie generator. It is used to initialize PrintedDocument with its
// associated PrintSettings, to be sure that each generated PrintedPage is
// correctly associated with its corresponding PrintedDocument.
diff --git a/chrome/browser/printing/printer_query.cc b/chrome/browser/printing/printer_query.cc
index f5ca6a5..3bcee7a 100644
--- a/chrome/browser/printing/printer_query.cc
+++ b/chrome/browser/printing/printer_query.cc
@@ -64,6 +64,7 @@ PrintJobWorker* PrinterQuery::DetachWorker(PrintJobWorkerOwner* new_owner) {
void PrinterQuery::GetSettings(GetSettingsAskParam ask_user_for_settings,
HWND parent_window,
int expected_page_count,
+ bool has_selection,
CancelableTask* callback) {
DCHECK_EQ(ui_message_loop_, MessageLoop::current());
DCHECK(!is_print_dialog_box_shown_);
@@ -91,7 +92,8 @@ void PrinterQuery::GetSettings(GetSettingsAskParam ask_user_for_settings,
&PrintJobWorker::GetSettings,
is_print_dialog_box_shown_,
parent_window,
- expected_page_count));
+ expected_page_count,
+ has_selection));
}
void PrinterQuery::StopWorker() {
diff --git a/chrome/browser/printing/printer_query.h b/chrome/browser/printing/printer_query.h
index 3d389db..6d6fd88 100644
--- a/chrome/browser/printing/printer_query.h
+++ b/chrome/browser/printing/printer_query.h
@@ -57,6 +57,7 @@ class PrinterQuery : public base::RefCountedThreadSafe<PrinterQuery>,
void GetSettings(GetSettingsAskParam ask_user_for_settings,
HWND parent_window,
int expected_page_count,
+ bool has_selection,
CancelableTask* callback);
// Stops the worker thread since the client is done with this object.
diff --git a/chrome/browser/printing/win_printing_context.cc b/chrome/browser/printing/win_printing_context.cc
index 7a43b4d..7aaaf8e 100644
--- a/chrome/browser/printing/win_printing_context.cc
+++ b/chrome/browser/printing/win_printing_context.cc
@@ -152,8 +152,10 @@ PrintingContext::~PrintingContext() {
ResetSettings();
}
-PrintingContext::Result PrintingContext::AskUserForSettings(HWND window,
- int max_pages) {
+PrintingContext::Result PrintingContext::AskUserForSettings(
+ HWND window,
+ int max_pages,
+ bool has_selection) {
DCHECK(window);
DCHECK(!in_print_job_);
dialog_box_dismissed_ = false;
@@ -168,12 +170,13 @@ PrintingContext::Result PrintingContext::AskUserForSettings(HWND window,
// On failure, the settings are reset and FAILED is returned.
PRINTDLGEX dialog_options = { sizeof(PRINTDLGEX) };
dialog_options.hwndOwner = window;
- // Disables the Current Page and Selection radio buttons since WebKit can't
- // print a part of the webpage and we don't know which page is the current
- // one.
+ // Disable options we don't support currently.
// TODO(maruel): Reuse the previously loaded settings!
dialog_options.Flags = PD_RETURNDC | PD_USEDEVMODECOPIESANDCOLLATE |
- PD_NOSELECTION | PD_NOCURRENTPAGE | PD_HIDEPRINTTOFILE;
+ PD_NOCURRENTPAGE | PD_HIDEPRINTTOFILE;
+ if (!has_selection)
+ dialog_options.Flags |= PD_NOSELECTION;
+
PRINTPAGERANGE ranges[32];
dialog_options.nStartPage = START_PAGE_GENERAL;
if (max_pages) {
@@ -253,7 +256,7 @@ PrintingContext::Result PrintingContext::NewDocument(
const std::wstring& document_name) {
DCHECK(!in_print_job_);
if (!hdc_)
- return OnErrror();
+ return OnError();
// Set the flag used by the AbortPrintJob dialog procedure.
abort_printing_ = false;
@@ -262,7 +265,7 @@ PrintingContext::Result PrintingContext::NewDocument(
// Register the application's AbortProc function with GDI.
if (SP_ERROR == SetAbortProc(hdc_, &AbortProc))
- return OnErrror();
+ return OnError();
DOCINFO di = { sizeof(DOCINFO) };
di.lpszDocName = document_name.c_str();
@@ -297,7 +300,7 @@ PrintingContext::Result PrintingContext::NewDocument(
// NOTE: StartDoc() starts a message loop. That causes a lot of problems with
// IPC. Make sure recursive task processing is disabled.
if (StartDoc(hdc_, &di) <= 0)
- return OnErrror();
+ return OnError();
#ifndef NDEBUG
page_number_ = 0;
@@ -312,7 +315,7 @@ PrintingContext::Result PrintingContext::NewPage() {
// Inform the driver that the application is about to begin sending data.
if (StartPage(hdc_) <= 0)
- return OnErrror();
+ return OnError();
#ifndef NDEBUG
++page_number_;
@@ -327,7 +330,7 @@ PrintingContext::Result PrintingContext::PageDone() {
DCHECK(in_print_job_);
if (EndPage(hdc_) <= 0)
- return OnErrror();
+ return OnError();
return OK;
}
@@ -338,7 +341,7 @@ PrintingContext::Result PrintingContext::DocumentDone() {
// Inform the driver that document has ended.
if (EndDoc(hdc_) <= 0)
- return OnErrror();
+ return OnError();
ResetSettings();
return OK;
@@ -359,7 +362,7 @@ void PrintingContext::DismissDialog() {
}
}
-PrintingContext::Result PrintingContext::OnErrror() {
+PrintingContext::Result PrintingContext::OnError() {
// This will close hdc_ and clear settings_.
ResetSettings();
return abort_printing_ ? CANCEL : FAILED;
@@ -378,7 +381,8 @@ BOOL PrintingContext::AbortProc(HDC hdc, int nCode) {
bool PrintingContext::InitializeSettings(const DEVMODE& dev_mode,
const std::wstring& new_device_name,
const PRINTPAGERANGE* ranges,
- int number_ranges) {
+ int number_ranges,
+ bool selection_only) {
skia::PlatformDeviceWin::InitializeDC(hdc_);
DCHECK(GetDeviceCaps(hdc_, CLIPCAPS));
DCHECK(GetDeviceCaps(hdc_, RASTERCAPS) & RC_STRETCHDIB);
@@ -408,7 +412,11 @@ bool PrintingContext::InitializeSettings(const DEVMODE& dev_mode,
range.to = ranges[i].nToPage - 1;
ranges_vector.push_back(range);
}
- settings_.Init(hdc_, dev_mode, ranges_vector, new_device_name);
+ settings_.Init(hdc_,
+ dev_mode,
+ ranges_vector,
+ new_device_name,
+ selection_only);
return true;
}
@@ -427,7 +435,7 @@ bool PrintingContext::GetPrinterSettings(HANDLE printer,
ResetSettings();
return false;
}
- return InitializeSettings(*info_9->pDevMode, device_name, NULL, 0);
+ return InitializeSettings(*info_9->pDevMode, device_name, NULL, 0, false);
}
buffer.reset();
}
@@ -441,7 +449,7 @@ bool PrintingContext::GetPrinterSettings(HANDLE printer,
ResetSettings();
return false;
}
- return InitializeSettings(*info_8->pDevMode, device_name, NULL, 0);
+ return InitializeSettings(*info_8->pDevMode, device_name, NULL, 0, false);
}
buffer.reset();
}
@@ -456,7 +464,7 @@ bool PrintingContext::GetPrinterSettings(HANDLE printer,
ResetSettings();
return false;
}
- return InitializeSettings(*info_2->pDevMode, device_name, NULL, 0);
+ return InitializeSettings(*info_2->pDevMode, device_name, NULL, 0, false);
}
buffer.reset();
}
@@ -503,14 +511,21 @@ PrintingContext::Result PrintingContext::ParseDialogResultEx(
bool success = false;
if (dev_mode && !device_name.empty()) {
hdc_ = dialog_options.hDC;
+ PRINTPAGERANGE* page_ranges = NULL;
+ DWORD num_page_ranges = 0;
+ bool print_selection_only = false;
if (dialog_options.Flags & PD_PAGENUMS) {
- success = InitializeSettings(*dev_mode,
- device_name,
- dialog_options.lpPageRanges,
- dialog_options.nPageRanges);
- } else {
- success = InitializeSettings(*dev_mode, device_name, NULL, 0);
+ page_ranges = dialog_options.lpPageRanges;
+ num_page_ranges = dialog_options.nPageRanges;
+ }
+ if (dialog_options.Flags & PD_SELECTION) {
+ print_selection_only = true;
}
+ success = InitializeSettings(*dev_mode,
+ device_name,
+ dialog_options.lpPageRanges,
+ dialog_options.nPageRanges,
+ print_selection_only);
}
if (!success && dialog_options.hDC) {
@@ -574,7 +589,7 @@ PrintingContext::Result PrintingContext::ParseDialogResult(
bool success = false;
if (dev_mode && !device_name.empty()) {
hdc_ = dialog_options.hDC;
- success = InitializeSettings(*dev_mode, device_name, NULL, 0);
+ success = InitializeSettings(*dev_mode, device_name, NULL, 0, false);
}
if (!success && dialog_options.hDC) {
diff --git a/chrome/browser/printing/win_printing_context.h b/chrome/browser/printing/win_printing_context.h
index eaacc02..320a512 100644
--- a/chrome/browser/printing/win_printing_context.h
+++ b/chrome/browser/printing/win_printing_context.h
@@ -31,7 +31,7 @@ class PrintingContext {
// Asks the user what printer and format should be used to print. Updates the
// context with the select device settings.
- Result AskUserForSettings(HWND window, int max_pages);
+ Result AskUserForSettings(HWND window, int max_pages, bool has_selection);
// Selects the user's default printer and format. Updates the context with the
// default device settings.
@@ -81,10 +81,10 @@ class PrintingContext {
// temporary object used during the Print... dialog display.
class CallbackHandler;
- // Does bookeeping when an error occurs.
- PrintingContext::Result OnErrror();
+ // Does bookkeeping when an error occurs.
+ PrintingContext::Result OnError();
- // Used in response to the user cancelling the printing.
+ // Used in response to the user canceling the printing.
static BOOL CALLBACK AbortProc(HDC hdc, int nCode);
// Reads the settings from the selected device context. Updates settings_ and
@@ -92,7 +92,8 @@ class PrintingContext {
bool InitializeSettings(const DEVMODE& dev_mode,
const std::wstring& new_device_name,
const PRINTPAGERANGE* ranges,
- int number_ranges);
+ int number_ranges,
+ bool selection_only);
// Retrieves the printer's default low-level settings. hdc_ is allocated with
// this call.