diff options
author | peter@pcc.me.uk <peter@pcc.me.uk@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-02-14 03:58:06 +0000 |
---|---|---|
committer | peter@pcc.me.uk <peter@pcc.me.uk@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-02-14 03:58:06 +0000 |
commit | 437f9d8f59d8891eb20f3a5b83976b0d1b107464 (patch) | |
tree | 4432d4b9820d8e5428fb1248882c541220ae28a8 | |
parent | 6f0db2b2c15a0919bbeeb6568c69b7196b186d27 (diff) | |
download | chromium_src-437f9d8f59d8891eb20f3a5b83976b0d1b107464.zip chromium_src-437f9d8f59d8891eb20f3a5b83976b0d1b107464.tar.gz chromium_src-437f9d8f59d8891eb20f3a5b83976b0d1b107464.tar.bz2 |
GTK: implement "print selection".
BUG=83481
TEST=mouse select text from http://en.wikipedia.org/wiki/Main_Page
Toolbox -> Print -> Print to File -> Selection -> Print, verify that PDF contains only selection.
Toolbox -> Print -> Print to File -> All Pages -> Print, verify that PDF contains all pages.
Toolbox -> Print -> Print to File -> Pages: 1 -> Print, verify that PDF contains only page 1.
Review URL: http://codereview.chromium.org/9379039
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@121844 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r-- | AUTHORS | 1 | ||||
-rw-r--r-- | chrome/browser/printing/print_dialog_gtk.cc | 44 | ||||
-rw-r--r-- | chrome/browser/printing/print_dialog_gtk.h | 3 | ||||
-rw-r--r-- | printing/print_dialog_gtk_interface.h | 3 | ||||
-rw-r--r-- | printing/printing_context_gtk.cc | 4 |
5 files changed, 40 insertions, 15 deletions
@@ -163,3 +163,4 @@ Francois Kritzinger <francoisk777@gmail.com> Erik Hill <erikghill@gmail.com> Mao Yujie <maojie0924@gmail.com> Aaron Leventhal <aaronlevbugs@gmail.com> +Peter Collingbourne <peter@pcc.me.uk> diff --git a/chrome/browser/printing/print_dialog_gtk.cc b/chrome/browser/printing/print_dialog_gtk.cc index 789ded4..efaaf24 100644 --- a/chrome/browser/printing/print_dialog_gtk.cc +++ b/chrome/browser/printing/print_dialog_gtk.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Copyright (c) 2012 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. @@ -231,6 +231,7 @@ bool PrintDialogGtk::UpdateSettings(const DictionaryValue& job_settings, } void PrintDialogGtk::ShowDialog( + bool has_selection, const PrintingContextGtk::PrintSettingsCallback& callback) { callback_ = callback; @@ -256,6 +257,10 @@ void PrintDialogGtk::ShowDialog( cap); gtk_print_unix_dialog_set_embed_page_setup(GTK_PRINT_UNIX_DIALOG(dialog_), TRUE); + gtk_print_unix_dialog_set_support_selection(GTK_PRINT_UNIX_DIALOG(dialog_), + TRUE); + gtk_print_unix_dialog_set_has_selection(GTK_PRINT_UNIX_DIALOG(dialog_), + has_selection); g_signal_connect(dialog_, "response", G_CALLBACK(OnResponseThunk), this); gtk_widget_show(dialog_); } @@ -326,21 +331,38 @@ void PrintDialogGtk::OnResponse(GtkWidget* dialog, int response_id) { // Handle page ranges. PageRanges ranges_vector; gint num_ranges; - GtkPageRange* gtk_range = - gtk_print_settings_get_page_ranges(gtk_settings_, &num_ranges); - if (gtk_range) { - for (int i = 0; i < num_ranges; ++i) { - printing::PageRange range; - range.from = gtk_range[i].start; - range.to = gtk_range[i].end; - ranges_vector.push_back(range); + bool print_selection_only = false; + switch (gtk_print_settings_get_print_pages(gtk_settings_)) { + case GTK_PRINT_PAGES_RANGES: { + GtkPageRange* gtk_range = + gtk_print_settings_get_page_ranges(gtk_settings_, &num_ranges); + if (gtk_range) { + for (int i = 0; i < num_ranges; ++i) { + printing::PageRange range; + range.from = gtk_range[i].start; + range.to = gtk_range[i].end; + ranges_vector.push_back(range); + } + g_free(gtk_range); + } + break; } - g_free(gtk_range); + case GTK_PRINT_PAGES_SELECTION: + print_selection_only = true; + break; + case GTK_PRINT_PAGES_ALL: + // Leave |ranges_vector| empty to indicate print all pages. + break; + case GTK_PRINT_PAGES_CURRENT: + default: + NOTREACHED(); + break; } PrintSettings settings; printing::PrintSettingsInitializerGtk::InitPrintSettings( - gtk_settings_, page_setup_, ranges_vector, false, &settings); + gtk_settings_, page_setup_, ranges_vector, print_selection_only, + &settings); context_->InitWithSettings(settings); callback_.Run(PrintingContextGtk::OK); callback_.Reset(); diff --git a/chrome/browser/printing/print_dialog_gtk.h b/chrome/browser/printing/print_dialog_gtk.h index 5b60006..355f6b8 100644 --- a/chrome/browser/printing/print_dialog_gtk.h +++ b/chrome/browser/printing/print_dialog_gtk.h @@ -1,4 +1,4 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Copyright (c) 2012 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. @@ -42,6 +42,7 @@ class PrintDialogGtk const printing::PageRanges& ranges, printing::PrintSettings* settings) OVERRIDE; virtual void ShowDialog( + bool has_selection, const PrintingContextGtk::PrintSettingsCallback& callback) OVERRIDE; virtual void PrintDocument(const printing::Metafile* metafile, const string16& document_name) OVERRIDE; diff --git a/printing/print_dialog_gtk_interface.h b/printing/print_dialog_gtk_interface.h index b63076e..41fafe0 100644 --- a/printing/print_dialog_gtk_interface.h +++ b/printing/print_dialog_gtk_interface.h @@ -1,4 +1,4 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Copyright (c) 2012 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. @@ -32,6 +32,7 @@ class PrintDialogGtkInterface { // Shows the dialog and handles the response with |callback|. Only used when // printing with the native print dialog. virtual void ShowDialog( + bool has_selection, const PrintingContextGtk::PrintSettingsCallback& callback) = 0; // Prints the document named |document_name| contained in |metafile|. diff --git a/printing/printing_context_gtk.cc b/printing/printing_context_gtk.cc index af97906..2e06c02 100644 --- a/printing/printing_context_gtk.cc +++ b/printing/printing_context_gtk.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Copyright (c) 2012 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. @@ -62,7 +62,7 @@ void PrintingContextGtk::AskUserForSettings( int max_pages, bool has_selection, const PrintSettingsCallback& callback) { - print_dialog_->ShowDialog(callback); + print_dialog_->ShowDialog(has_selection, callback); } PrintingContext::Result PrintingContextGtk::UseDefaultSettings() { |