Get printing working in Aura.
Splits printing_context_cairo into gtk and no system dialog versions. No system dialog versions are used in Chrome OS and Aura. BUG=http://code.google.com/p/chromium-os/issues/detail?id=13915 TEST=Build Chrome with Aura. Hit ctrl-p from any web page. Print preview page should come up and should be able to print via Cloud Print. Review URL: http://codereview.chromium.org/8372030 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@109059 0039d316-1c4b-4281-b951-d872f2087c98
This commit is contained in:
chrome/browser
printing
@ -259,7 +259,7 @@ void ChromeBrowserMainPartsPosix::PostMainMessageLoopStart() {
|
||||
CHECK(sigaction(SIGHUP, &action, NULL) == 0);
|
||||
|
||||
#if defined(TOOLKIT_USES_GTK) && !defined(OS_CHROMEOS)
|
||||
printing::PrintingContextCairo::SetCreatePrintDialogFunction(
|
||||
printing::PrintingContextGtk::SetCreatePrintDialogFunction(
|
||||
&PrintDialogGtk::CreatePrintDialog);
|
||||
#endif
|
||||
}
|
||||
|
@ -93,12 +93,12 @@ class GtkPrinterList {
|
||||
|
||||
// static
|
||||
printing::PrintDialogGtkInterface* PrintDialogGtk::CreatePrintDialog(
|
||||
PrintingContextCairo* context) {
|
||||
PrintingContextGtk* context) {
|
||||
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
|
||||
return new PrintDialogGtk(context);
|
||||
}
|
||||
|
||||
PrintDialogGtk::PrintDialogGtk(PrintingContextCairo* context)
|
||||
PrintDialogGtk::PrintDialogGtk(PrintingContextGtk* context)
|
||||
: callback_(NULL),
|
||||
context_(context),
|
||||
dialog_(NULL),
|
||||
@ -229,7 +229,7 @@ bool PrintDialogGtk::UpdateSettings(const DictionaryValue& job_settings,
|
||||
}
|
||||
|
||||
void PrintDialogGtk::ShowDialog(
|
||||
PrintingContextCairo::PrintSettingsCallback* callback) {
|
||||
PrintingContextGtk::PrintSettingsCallback* callback) {
|
||||
callback_ = callback;
|
||||
|
||||
GtkWindow* parent = BrowserList::GetLastActive()->window()->GetNativeHandle();
|
||||
@ -341,13 +341,13 @@ void PrintDialogGtk::OnResponse(GtkWidget* dialog, int response_id) {
|
||||
printing::PrintSettingsInitializerGtk::InitPrintSettings(
|
||||
gtk_settings_, page_setup_, ranges_vector, false, &settings);
|
||||
context_->InitWithSettings(settings);
|
||||
callback_->Run(PrintingContextCairo::OK);
|
||||
callback_->Run(PrintingContextGtk::OK);
|
||||
callback_ = NULL;
|
||||
return;
|
||||
}
|
||||
case GTK_RESPONSE_DELETE_EVENT: // Fall through.
|
||||
case GTK_RESPONSE_CANCEL: {
|
||||
callback_->Run(PrintingContextCairo::CANCEL);
|
||||
callback_->Run(PrintingContextGtk::CANCEL);
|
||||
callback_ = NULL;
|
||||
return;
|
||||
}
|
||||
|
@ -15,7 +15,7 @@
|
||||
#include "base/memory/scoped_ptr.h"
|
||||
#include "content/public/browser/browser_thread.h"
|
||||
#include "printing/print_dialog_gtk_interface.h"
|
||||
#include "printing/printing_context_cairo.h"
|
||||
#include "printing/printing_context_gtk.h"
|
||||
#include "ui/base/gtk/gtk_signal.h"
|
||||
|
||||
namespace printing {
|
||||
@ -23,7 +23,7 @@ class Metafile;
|
||||
class PrintSettings;
|
||||
}
|
||||
|
||||
using printing::PrintingContextCairo;
|
||||
using printing::PrintingContextGtk;
|
||||
|
||||
// Needs to be freed on the UI thread to clean up its GTK members variables.
|
||||
class PrintDialogGtk
|
||||
@ -33,7 +33,7 @@ class PrintDialogGtk
|
||||
public:
|
||||
// Creates and returns a print dialog.
|
||||
static printing::PrintDialogGtkInterface* CreatePrintDialog(
|
||||
PrintingContextCairo* context);
|
||||
PrintingContextGtk* context);
|
||||
|
||||
// printing::PrintDialogGtkInterface implementation.
|
||||
virtual void UseDefaultSettings() OVERRIDE;
|
||||
@ -41,7 +41,7 @@ class PrintDialogGtk
|
||||
const printing::PageRanges& ranges,
|
||||
printing::PrintSettings* settings) OVERRIDE;
|
||||
virtual void ShowDialog(
|
||||
PrintingContextCairo::PrintSettingsCallback* callback) OVERRIDE;
|
||||
PrintingContextGtk::PrintSettingsCallback* callback) OVERRIDE;
|
||||
virtual void PrintDocument(const printing::Metafile* metafile,
|
||||
const string16& document_name) OVERRIDE;
|
||||
virtual void AddRefToDialog() OVERRIDE;
|
||||
@ -52,7 +52,7 @@ class PrintDialogGtk
|
||||
content::BrowserThread::UI>;
|
||||
friend class DeleteTask<PrintDialogGtk>;
|
||||
|
||||
explicit PrintDialogGtk(PrintingContextCairo* context);
|
||||
explicit PrintDialogGtk(PrintingContextGtk* context);
|
||||
virtual ~PrintDialogGtk();
|
||||
|
||||
// Handles dialog response.
|
||||
@ -73,8 +73,8 @@ class PrintDialogGtk
|
||||
printing::PrintSettings* settings);
|
||||
|
||||
// Printing dialog callback.
|
||||
PrintingContextCairo::PrintSettingsCallback* callback_;
|
||||
PrintingContextCairo* context_;
|
||||
PrintingContextGtk::PrintSettingsCallback* callback_;
|
||||
PrintingContextGtk* context_;
|
||||
|
||||
// Print dialog settings. PrintDialogGtk owns |dialog_| and holds references
|
||||
// to the other objects.
|
||||
|
@ -6,7 +6,7 @@
|
||||
#define PRINTING_PRINT_DIALOG_GTK_INTERFACE_H_
|
||||
|
||||
#include "base/string16.h"
|
||||
#include "printing/printing_context_cairo.h"
|
||||
#include "printing/printing_context_gtk.h"
|
||||
|
||||
namespace printing {
|
||||
|
||||
@ -32,7 +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(
|
||||
PrintingContextCairo::PrintSettingsCallback* callback) = 0;
|
||||
PrintingContextGtk::PrintSettingsCallback* callback) = 0;
|
||||
|
||||
// Prints the document named |document_name| contained in |metafile|.
|
||||
// Called from the print worker thread. Once called, the
|
||||
|
@ -7,7 +7,7 @@
|
||||
#include "base/logging.h"
|
||||
#include "printing/page_number.h"
|
||||
#include "printing/printed_page.h"
|
||||
#include "printing/printing_context_cairo.h"
|
||||
#include "printing/printing_context_gtk.h"
|
||||
|
||||
namespace printing {
|
||||
|
||||
@ -27,7 +27,7 @@ void PrintedDocument::RenderPrintedPage(
|
||||
{
|
||||
base::AutoLock lock(lock_);
|
||||
if (page.page_number() - 1 == mutable_.first_page) {
|
||||
reinterpret_cast<PrintingContextCairo*>(context)->PrintDocument(
|
||||
reinterpret_cast<PrintingContextGtk*>(context)->PrintDocument(
|
||||
page.metafile());
|
||||
}
|
||||
}
|
||||
|
@ -66,13 +66,6 @@
|
||||
'printed_pages_source.h',
|
||||
'printing_context.cc',
|
||||
'printing_context.h',
|
||||
'printing_context_aura.cc',
|
||||
'printing_context_cairo.cc',
|
||||
'printing_context_cairo.h',
|
||||
'printing_context_mac.mm',
|
||||
'printing_context_mac.h',
|
||||
'printing_context_win.cc',
|
||||
'printing_context_win.h',
|
||||
'print_dialog_gtk_interface.h',
|
||||
'print_job_constants.cc',
|
||||
'print_job_constants.h',
|
||||
@ -117,16 +110,25 @@
|
||||
['exclude', 'metafile_skia_wrapper\\.(cc|h)$'],
|
||||
],
|
||||
}],
|
||||
['OS=="mac" and use_aura==0',{
|
||||
'sources': [
|
||||
'printing_context_mac.mm',
|
||||
'printing_context_mac.h',
|
||||
],
|
||||
}],
|
||||
['OS=="win"', {
|
||||
'conditions': [
|
||||
['use_aura==1', {
|
||||
'sources!': [
|
||||
'image_aura.cc',
|
||||
'printed_document_aura.cc',
|
||||
'printing_context_aura.cc',
|
||||
],
|
||||
}],
|
||||
],
|
||||
}, { #else: use_aura==0
|
||||
'sources': [
|
||||
'printing_context_win.cc',
|
||||
'printing_context_win.h',
|
||||
],
|
||||
}]],
|
||||
'defines': [
|
||||
# PRINT_BACKEND_AVAILABLE disables the default dummy implementation
|
||||
# of the print backend and enables a custom implementation instead.
|
||||
@ -138,6 +140,12 @@
|
||||
'backend/print_backend_win.cc',
|
||||
],
|
||||
}],
|
||||
['chromeos==1 or use_aura==1',{
|
||||
'sources': [
|
||||
'printing_context_no_system_dialog.cc',
|
||||
'printing_context_no_system_dialog.h',
|
||||
],
|
||||
}],
|
||||
['use_cups==1', {
|
||||
'dependencies': [
|
||||
'cups',
|
||||
@ -170,6 +178,12 @@
|
||||
'backend/print_backend_chromeos.cc',
|
||||
],
|
||||
}],
|
||||
['OS=="linux" and chromeos==0', {
|
||||
'sources': [
|
||||
'printing_context_gtk.cc',
|
||||
'printing_context_gtk.h',
|
||||
],
|
||||
}],
|
||||
],
|
||||
},
|
||||
{
|
||||
@ -189,18 +203,18 @@
|
||||
'page_setup_unittest.cc',
|
||||
'pdf_metafile_cg_mac_unittest.cc',
|
||||
'printed_page_unittest.cc',
|
||||
'printing_context_win_unittest.cc',
|
||||
'run_all_unittests.cc',
|
||||
'units_unittest.cc',
|
||||
],
|
||||
'conditions': [
|
||||
['toolkit_uses_gtk == 0', {'sources/': [['exclude', '_cairo_unittest\\.cc$']]}],
|
||||
['toolkit_uses_gtk == 0', {'sources/': [['exclude', '_gtk_unittest\\.cc$']]}],
|
||||
['OS!="mac"', {'sources/': [['exclude', '_mac_unittest\\.(cc|mm?)$']]}],
|
||||
['OS!="win"', {'sources/': [['exclude', '_win_unittest\\.cc$']]
|
||||
}, { # else: OS=="win"
|
||||
'sources/': [['exclude', '_cairo_unittest\\.cc$']]
|
||||
}
|
||||
],
|
||||
['OS!="win"', {'sources/': [['exclude', '_win_unittest\\.cc$']]}],
|
||||
['OS=="win" and use_aura == 0', {
|
||||
'sources': [
|
||||
'printing_context_win_unittest.cc',
|
||||
]
|
||||
}],
|
||||
['toolkit_uses_gtk == 1', {
|
||||
'dependencies': [
|
||||
'../build/linux/system.gyp:gtk',
|
||||
|
@ -1,19 +0,0 @@
|
||||
// Copyright (c) 2011 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 "printing/printing_context.h"
|
||||
|
||||
#include "base/logging.h"
|
||||
|
||||
namespace printing {
|
||||
|
||||
// static
|
||||
PrintingContext* PrintingContext::Create(const std::string& app_locale) {
|
||||
// TODO(saintlou): This a stub to allow us to build under Aura.
|
||||
// See issue: http://crbug.com/99282
|
||||
NOTIMPLEMENTED();
|
||||
return NULL;
|
||||
}
|
||||
|
||||
} // namespace printing
|
@ -1,237 +0,0 @@
|
||||
// Copyright (c) 2011 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 "printing/printing_context_cairo.h"
|
||||
|
||||
// TODO(abodenha@chromium.org) The number of #ifdefs here has gotten too
|
||||
// large. Refactor this code into separate files for Linux and Chrome OS.
|
||||
|
||||
#include "base/logging.h"
|
||||
#include "base/values.h"
|
||||
#include "printing/metafile.h"
|
||||
#include "printing/print_job_constants.h"
|
||||
#include "printing/units.h"
|
||||
|
||||
#if defined(OS_CHROMEOS)
|
||||
#include <unicode/ulocdata.h>
|
||||
#include "printing/print_settings_initializer_gtk.h"
|
||||
#else
|
||||
#include <gtk/gtk.h>
|
||||
#include <gtk/gtkprintunixdialog.h>
|
||||
#include "printing/print_dialog_gtk_interface.h"
|
||||
#endif // defined(OS_CHROMEOS)
|
||||
|
||||
#if !defined(OS_CHROMEOS)
|
||||
namespace {
|
||||
// Function pointer for creating print dialogs. |callback| is only used when
|
||||
// |show_dialog| is true.
|
||||
static printing::PrintDialogGtkInterface* (*create_dialog_func_)(
|
||||
printing::PrintingContextCairo* context) = NULL;
|
||||
} // namespace
|
||||
#endif // !defined(OS_CHROMEOS)
|
||||
|
||||
namespace printing {
|
||||
|
||||
// static
|
||||
PrintingContext* PrintingContext::Create(const std::string& app_locale) {
|
||||
return static_cast<PrintingContext*>(new PrintingContextCairo(app_locale));
|
||||
}
|
||||
|
||||
PrintingContextCairo::PrintingContextCairo(const std::string& app_locale)
|
||||
#if defined(OS_CHROMEOS)
|
||||
: PrintingContext(app_locale) {
|
||||
#else
|
||||
: PrintingContext(app_locale),
|
||||
print_dialog_(NULL) {
|
||||
#endif
|
||||
}
|
||||
|
||||
PrintingContextCairo::~PrintingContextCairo() {
|
||||
ReleaseContext();
|
||||
|
||||
#if !defined(OS_CHROMEOS)
|
||||
if (print_dialog_)
|
||||
print_dialog_->ReleaseDialog();
|
||||
#endif
|
||||
}
|
||||
|
||||
#if !defined(OS_CHROMEOS)
|
||||
// static
|
||||
void PrintingContextCairo::SetCreatePrintDialogFunction(
|
||||
PrintDialogGtkInterface* (*create_dialog_func)(
|
||||
PrintingContextCairo* context)) {
|
||||
DCHECK(create_dialog_func);
|
||||
DCHECK(!create_dialog_func_);
|
||||
create_dialog_func_ = create_dialog_func;
|
||||
}
|
||||
|
||||
void PrintingContextCairo::PrintDocument(const Metafile* metafile) {
|
||||
DCHECK(print_dialog_);
|
||||
DCHECK(metafile);
|
||||
print_dialog_->PrintDocument(metafile, document_name_);
|
||||
}
|
||||
#endif // !defined(OS_CHROMEOS)
|
||||
|
||||
void PrintingContextCairo::AskUserForSettings(
|
||||
gfx::NativeView parent_view,
|
||||
int max_pages,
|
||||
bool has_selection,
|
||||
PrintSettingsCallback* callback) {
|
||||
#if defined(OS_CHROMEOS)
|
||||
callback->Run(OK);
|
||||
#else
|
||||
print_dialog_->ShowDialog(callback);
|
||||
#endif // defined(OS_CHROMEOS)
|
||||
}
|
||||
|
||||
PrintingContext::Result PrintingContextCairo::UseDefaultSettings() {
|
||||
DCHECK(!in_print_job_);
|
||||
|
||||
ResetSettings();
|
||||
#if defined(OS_CHROMEOS)
|
||||
// For Chrome OS use default values based on the app locale rather than rely
|
||||
// on GTK. Note that relying on the app locale does not work well if it is
|
||||
// different from the system locale, e.g. a user using Chinese ChromeOS in the
|
||||
// US. Eventually we need to get the defaults from the printer.
|
||||
// TODO(sanjeevr): We need a better feedback loop between the cloud print
|
||||
// dialog and this code.
|
||||
int dpi = 300;
|
||||
gfx::Size physical_size_device_units;
|
||||
gfx::Rect printable_area_device_units;
|
||||
int32_t width = 0;
|
||||
int32_t height = 0;
|
||||
UErrorCode error = U_ZERO_ERROR;
|
||||
ulocdata_getPaperSize(app_locale_.c_str(), &height, &width, &error);
|
||||
if (error != U_ZERO_ERROR) {
|
||||
// If the call failed, assume a paper size of 8.5 x 11 inches.
|
||||
LOG(WARNING) << "ulocdata_getPaperSize failed, using 8.5 x 11, error: "
|
||||
<< error;
|
||||
width = static_cast<int>(8.5 * dpi);
|
||||
height = static_cast<int>(11 * dpi);
|
||||
} else {
|
||||
// ulocdata_getPaperSize returns the width and height in mm.
|
||||
// Convert this to pixels based on the dpi.
|
||||
width = static_cast<int>(ConvertUnitDouble(width, 25.4, 1.0) * dpi);
|
||||
height = static_cast<int>(ConvertUnitDouble(height, 25.4, 1.0) * dpi);
|
||||
}
|
||||
|
||||
physical_size_device_units.SetSize(width, height);
|
||||
printable_area_device_units.SetRect(
|
||||
static_cast<int>(PrintSettingsInitializerGtk::kLeftMarginInInch * dpi),
|
||||
static_cast<int>(PrintSettingsInitializerGtk::kTopMarginInInch * dpi),
|
||||
width - (PrintSettingsInitializerGtk::kLeftMarginInInch +
|
||||
PrintSettingsInitializerGtk::kRightMarginInInch) * dpi,
|
||||
height - (PrintSettingsInitializerGtk::kTopMarginInInch +
|
||||
PrintSettingsInitializerGtk::kBottomMarginInInch) * dpi);
|
||||
|
||||
settings_.set_dpi(dpi);
|
||||
settings_.SetPrinterPrintableArea(physical_size_device_units,
|
||||
printable_area_device_units,
|
||||
dpi);
|
||||
#else
|
||||
if (!print_dialog_) {
|
||||
print_dialog_ = create_dialog_func_(this);
|
||||
print_dialog_->AddRefToDialog();
|
||||
}
|
||||
print_dialog_->UseDefaultSettings();
|
||||
#endif // defined(OS_CHROMEOS)
|
||||
|
||||
return OK;
|
||||
}
|
||||
|
||||
PrintingContext::Result PrintingContextCairo::UpdatePrinterSettings(
|
||||
const DictionaryValue& job_settings, const PageRanges& ranges) {
|
||||
#if defined(OS_CHROMEOS)
|
||||
bool landscape = false;
|
||||
|
||||
if (!job_settings.GetBoolean(kSettingLandscape, &landscape))
|
||||
return OnError();
|
||||
|
||||
if (settings_.dpi() == 0)
|
||||
UseDefaultSettings();
|
||||
|
||||
settings_.SetOrientation(landscape);
|
||||
settings_.ranges = ranges;
|
||||
|
||||
return OK;
|
||||
#else
|
||||
DCHECK(!in_print_job_);
|
||||
|
||||
if (!print_dialog_) {
|
||||
print_dialog_ = create_dialog_func_(this);
|
||||
print_dialog_->AddRefToDialog();
|
||||
}
|
||||
|
||||
if (!print_dialog_->UpdateSettings(job_settings, ranges, &settings_))
|
||||
return OnError();
|
||||
|
||||
return OK;
|
||||
#endif
|
||||
}
|
||||
|
||||
PrintingContext::Result PrintingContextCairo::InitWithSettings(
|
||||
const PrintSettings& settings) {
|
||||
DCHECK(!in_print_job_);
|
||||
|
||||
settings_ = settings;
|
||||
|
||||
return OK;
|
||||
}
|
||||
|
||||
PrintingContext::Result PrintingContextCairo::NewDocument(
|
||||
const string16& document_name) {
|
||||
DCHECK(!in_print_job_);
|
||||
in_print_job_ = true;
|
||||
|
||||
#if !defined(OS_CHROMEOS)
|
||||
document_name_ = document_name;
|
||||
#endif // !defined(OS_CHROMEOS)
|
||||
|
||||
return OK;
|
||||
}
|
||||
|
||||
PrintingContext::Result PrintingContextCairo::NewPage() {
|
||||
if (abort_printing_)
|
||||
return CANCEL;
|
||||
DCHECK(in_print_job_);
|
||||
|
||||
// Intentional No-op.
|
||||
|
||||
return OK;
|
||||
}
|
||||
|
||||
PrintingContext::Result PrintingContextCairo::PageDone() {
|
||||
if (abort_printing_)
|
||||
return CANCEL;
|
||||
DCHECK(in_print_job_);
|
||||
|
||||
// Intentional No-op.
|
||||
|
||||
return OK;
|
||||
}
|
||||
|
||||
PrintingContext::Result PrintingContextCairo::DocumentDone() {
|
||||
if (abort_printing_)
|
||||
return CANCEL;
|
||||
DCHECK(in_print_job_);
|
||||
|
||||
ResetSettings();
|
||||
return OK;
|
||||
}
|
||||
|
||||
void PrintingContextCairo::Cancel() {
|
||||
abort_printing_ = true;
|
||||
in_print_job_ = false;
|
||||
}
|
||||
|
||||
void PrintingContextCairo::ReleaseContext() {
|
||||
// Intentional No-op.
|
||||
}
|
||||
|
||||
gfx::NativeDrawingContext PrintingContextCairo::context() const {
|
||||
// Intentional No-op.
|
||||
return NULL;
|
||||
}
|
||||
|
||||
} // namespace printing
|
157
printing/printing_context_gtk.cc
Normal file
157
printing/printing_context_gtk.cc
Normal file
@ -0,0 +1,157 @@
|
||||
// Copyright (c) 2011 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 "printing/printing_context_gtk.h"
|
||||
|
||||
#include <gtk/gtk.h>
|
||||
#include <gtk/gtkprintunixdialog.h>
|
||||
|
||||
#include "base/logging.h"
|
||||
#include "base/values.h"
|
||||
#include "printing/metafile.h"
|
||||
#include "printing/print_dialog_gtk_interface.h"
|
||||
#include "printing/print_job_constants.h"
|
||||
#include "printing/units.h"
|
||||
|
||||
namespace {
|
||||
// Function pointer for creating print dialogs. |callback| is only used when
|
||||
// |show_dialog| is true.
|
||||
static printing::PrintDialogGtkInterface* (*create_dialog_func_)(
|
||||
printing::PrintingContextGtk* context) = NULL;
|
||||
} // namespace
|
||||
|
||||
namespace printing {
|
||||
|
||||
// static
|
||||
PrintingContext* PrintingContext::Create(const std::string& app_locale) {
|
||||
return static_cast<PrintingContext*>(new PrintingContextGtk(app_locale));
|
||||
}
|
||||
|
||||
PrintingContextGtk::PrintingContextGtk(const std::string& app_locale)
|
||||
: PrintingContext(app_locale),
|
||||
print_dialog_(NULL) {
|
||||
}
|
||||
|
||||
PrintingContextGtk::~PrintingContextGtk() {
|
||||
ReleaseContext();
|
||||
|
||||
if (print_dialog_)
|
||||
print_dialog_->ReleaseDialog();
|
||||
}
|
||||
|
||||
// static
|
||||
void PrintingContextGtk::SetCreatePrintDialogFunction(
|
||||
PrintDialogGtkInterface* (*create_dialog_func)(
|
||||
PrintingContextGtk* context)) {
|
||||
DCHECK(create_dialog_func);
|
||||
DCHECK(!create_dialog_func_);
|
||||
create_dialog_func_ = create_dialog_func;
|
||||
}
|
||||
|
||||
void PrintingContextGtk::PrintDocument(const Metafile* metafile) {
|
||||
DCHECK(print_dialog_);
|
||||
DCHECK(metafile);
|
||||
print_dialog_->PrintDocument(metafile, document_name_);
|
||||
}
|
||||
|
||||
void PrintingContextGtk::AskUserForSettings(
|
||||
gfx::NativeView parent_view,
|
||||
int max_pages,
|
||||
bool has_selection,
|
||||
PrintSettingsCallback* callback) {
|
||||
print_dialog_->ShowDialog(callback);
|
||||
}
|
||||
|
||||
PrintingContext::Result PrintingContextGtk::UseDefaultSettings() {
|
||||
DCHECK(!in_print_job_);
|
||||
|
||||
ResetSettings();
|
||||
if (!print_dialog_) {
|
||||
print_dialog_ = create_dialog_func_(this);
|
||||
print_dialog_->AddRefToDialog();
|
||||
}
|
||||
print_dialog_->UseDefaultSettings();
|
||||
|
||||
return OK;
|
||||
}
|
||||
|
||||
PrintingContext::Result PrintingContextGtk::UpdatePrinterSettings(
|
||||
const DictionaryValue& job_settings, const PageRanges& ranges) {
|
||||
DCHECK(!in_print_job_);
|
||||
|
||||
if (!print_dialog_) {
|
||||
print_dialog_ = create_dialog_func_(this);
|
||||
print_dialog_->AddRefToDialog();
|
||||
}
|
||||
|
||||
if (!print_dialog_->UpdateSettings(job_settings, ranges, &settings_))
|
||||
return OnError();
|
||||
|
||||
return OK;
|
||||
}
|
||||
|
||||
PrintingContext::Result PrintingContextGtk::InitWithSettings(
|
||||
const PrintSettings& settings) {
|
||||
DCHECK(!in_print_job_);
|
||||
|
||||
settings_ = settings;
|
||||
|
||||
return OK;
|
||||
}
|
||||
|
||||
PrintingContext::Result PrintingContextGtk::NewDocument(
|
||||
const string16& document_name) {
|
||||
DCHECK(!in_print_job_);
|
||||
in_print_job_ = true;
|
||||
|
||||
document_name_ = document_name;
|
||||
|
||||
return OK;
|
||||
}
|
||||
|
||||
PrintingContext::Result PrintingContextGtk::NewPage() {
|
||||
if (abort_printing_)
|
||||
return CANCEL;
|
||||
DCHECK(in_print_job_);
|
||||
|
||||
// Intentional No-op.
|
||||
|
||||
return OK;
|
||||
}
|
||||
|
||||
PrintingContext::Result PrintingContextGtk::PageDone() {
|
||||
if (abort_printing_)
|
||||
return CANCEL;
|
||||
DCHECK(in_print_job_);
|
||||
|
||||
// Intentional No-op.
|
||||
|
||||
return OK;
|
||||
}
|
||||
|
||||
PrintingContext::Result PrintingContextGtk::DocumentDone() {
|
||||
if (abort_printing_)
|
||||
return CANCEL;
|
||||
DCHECK(in_print_job_);
|
||||
|
||||
ResetSettings();
|
||||
return OK;
|
||||
}
|
||||
|
||||
void PrintingContextGtk::Cancel() {
|
||||
abort_printing_ = true;
|
||||
in_print_job_ = false;
|
||||
}
|
||||
|
||||
void PrintingContextGtk::ReleaseContext() {
|
||||
// Intentional No-op.
|
||||
}
|
||||
|
||||
gfx::NativeDrawingContext PrintingContextGtk::context() const {
|
||||
// Intentional No-op.
|
||||
return NULL;
|
||||
}
|
||||
|
||||
} // namespace printing
|
||||
|
@ -2,8 +2,8 @@
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
#ifndef PRINTING_PRINTING_CONTEXT_CAIRO_H_
|
||||
#define PRINTING_PRINTING_CONTEXT_CAIRO_H_
|
||||
#ifndef PRINTING_PRINTING_CONTEXT_GTK_H_
|
||||
#define PRINTING_PRINTING_CONTEXT_GTK_H_
|
||||
|
||||
#include <string>
|
||||
|
||||
@ -18,20 +18,18 @@ namespace printing {
|
||||
class Metafile;
|
||||
class PrintDialogGtkInterface;
|
||||
|
||||
class PRINTING_EXPORT PrintingContextCairo : public PrintingContext {
|
||||
class PRINTING_EXPORT PrintingContextGtk : public PrintingContext {
|
||||
public:
|
||||
explicit PrintingContextCairo(const std::string& app_locale);
|
||||
virtual ~PrintingContextCairo();
|
||||
explicit PrintingContextGtk(const std::string& app_locale);
|
||||
virtual ~PrintingContextGtk();
|
||||
|
||||
#if !defined(OS_CHROMEOS)
|
||||
// Sets the function that creates the print dialog.
|
||||
static void SetCreatePrintDialogFunction(
|
||||
PrintDialogGtkInterface* (*create_dialog_func)(
|
||||
PrintingContextCairo* context));
|
||||
PrintingContextGtk* context));
|
||||
|
||||
// Prints the document contained in |metafile|.
|
||||
void PrintDocument(const Metafile* metafile);
|
||||
#endif
|
||||
|
||||
// PrintingContext implementation.
|
||||
virtual void AskUserForSettings(gfx::NativeView parent_view,
|
||||
@ -52,14 +50,13 @@ class PRINTING_EXPORT PrintingContextCairo : public PrintingContext {
|
||||
virtual gfx::NativeDrawingContext context() const;
|
||||
|
||||
private:
|
||||
#if !defined(OS_CHROMEOS)
|
||||
string16 document_name_;
|
||||
PrintDialogGtkInterface* print_dialog_;
|
||||
#endif
|
||||
|
||||
DISALLOW_COPY_AND_ASSIGN(PrintingContextCairo);
|
||||
DISALLOW_COPY_AND_ASSIGN(PrintingContextGtk);
|
||||
};
|
||||
|
||||
} // namespace printing
|
||||
|
||||
#endif // PRINTING_PRINTING_CONTEXT_CAIRO_H_
|
||||
#endif // PRINTING_PRINTING_CONTEXT_GTK_H_
|
||||
|
158
printing/printing_context_no_system_dialog.cc
Normal file
158
printing/printing_context_no_system_dialog.cc
Normal file
@ -0,0 +1,158 @@
|
||||
// Copyright (c) 2011 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 "printing/printing_context_no_system_dialog.h"
|
||||
|
||||
#include <unicode/ulocdata.h>
|
||||
|
||||
#include "base/logging.h"
|
||||
#include "base/values.h"
|
||||
#include "printing/metafile.h"
|
||||
#include "printing/print_job_constants.h"
|
||||
#include "printing/units.h"
|
||||
|
||||
namespace printing {
|
||||
|
||||
// static
|
||||
PrintingContext* PrintingContext::Create(const std::string& app_locale) {
|
||||
return static_cast<PrintingContext*>(
|
||||
new PrintingContextNoSystemDialog(app_locale));
|
||||
}
|
||||
|
||||
PrintingContextNoSystemDialog::PrintingContextNoSystemDialog(
|
||||
const std::string& app_locale) : PrintingContext(app_locale) {
|
||||
}
|
||||
|
||||
PrintingContextNoSystemDialog::~PrintingContextNoSystemDialog() {
|
||||
ReleaseContext();
|
||||
}
|
||||
|
||||
void PrintingContextNoSystemDialog::AskUserForSettings(
|
||||
gfx::NativeView parent_view,
|
||||
int max_pages,
|
||||
bool has_selection,
|
||||
PrintSettingsCallback* callback) {
|
||||
// We don't want to bring up a dialog here. Ever. Just signal the callback.
|
||||
callback->Run(OK);
|
||||
}
|
||||
|
||||
PrintingContext::Result PrintingContextNoSystemDialog::UseDefaultSettings() {
|
||||
DCHECK(!in_print_job_);
|
||||
|
||||
ResetSettings();
|
||||
// TODO(abodenha): Fetch these settings from the OS where possible. See
|
||||
// bug 102583.
|
||||
// TODO(sanjeevr): We need a better feedback loop between the cloud print
|
||||
// dialog and this code.
|
||||
int dpi = 300;
|
||||
gfx::Size physical_size_device_units;
|
||||
gfx::Rect printable_area_device_units;
|
||||
int32_t width = 0;
|
||||
int32_t height = 0;
|
||||
UErrorCode error = U_ZERO_ERROR;
|
||||
ulocdata_getPaperSize(app_locale_.c_str(), &height, &width, &error);
|
||||
if (error != U_ZERO_ERROR) {
|
||||
// If the call failed, assume a paper size of 8.5 x 11 inches.
|
||||
LOG(WARNING) << "ulocdata_getPaperSize failed, using 8.5 x 11, error: "
|
||||
<< error;
|
||||
width = static_cast<int>(8.5 * dpi);
|
||||
height = static_cast<int>(11 * dpi);
|
||||
} else {
|
||||
// ulocdata_getPaperSize returns the width and height in mm.
|
||||
// Convert this to pixels based on the dpi.
|
||||
width = static_cast<int>(ConvertUnitDouble(width, 25.4, 1.0) * dpi);
|
||||
height = static_cast<int>(ConvertUnitDouble(height, 25.4, 1.0) * dpi);
|
||||
}
|
||||
|
||||
physical_size_device_units.SetSize(width, height);
|
||||
|
||||
// Assume full page is printable for now.
|
||||
printable_area_device_units.SetRect(0, 0, width, height);
|
||||
|
||||
settings_.set_dpi(dpi);
|
||||
settings_.SetPrinterPrintableArea(physical_size_device_units,
|
||||
printable_area_device_units,
|
||||
dpi);
|
||||
|
||||
return OK;
|
||||
}
|
||||
|
||||
PrintingContext::Result PrintingContextNoSystemDialog::UpdatePrinterSettings(
|
||||
const DictionaryValue& job_settings, const PageRanges& ranges) {
|
||||
bool landscape = false;
|
||||
|
||||
if (!job_settings.GetBoolean(kSettingLandscape, &landscape))
|
||||
return OnError();
|
||||
|
||||
if (settings_.dpi() == 0)
|
||||
UseDefaultSettings();
|
||||
|
||||
settings_.SetOrientation(landscape);
|
||||
settings_.ranges = ranges;
|
||||
|
||||
return OK;
|
||||
}
|
||||
|
||||
PrintingContext::Result PrintingContextNoSystemDialog::InitWithSettings(
|
||||
const PrintSettings& settings) {
|
||||
DCHECK(!in_print_job_);
|
||||
|
||||
settings_ = settings;
|
||||
|
||||
return OK;
|
||||
}
|
||||
|
||||
PrintingContext::Result PrintingContextNoSystemDialog::NewDocument(
|
||||
const string16& document_name) {
|
||||
DCHECK(!in_print_job_);
|
||||
in_print_job_ = true;
|
||||
|
||||
return OK;
|
||||
}
|
||||
|
||||
PrintingContext::Result PrintingContextNoSystemDialog::NewPage() {
|
||||
if (abort_printing_)
|
||||
return CANCEL;
|
||||
DCHECK(in_print_job_);
|
||||
|
||||
// Intentional No-op.
|
||||
|
||||
return OK;
|
||||
}
|
||||
|
||||
PrintingContext::Result PrintingContextNoSystemDialog::PageDone() {
|
||||
if (abort_printing_)
|
||||
return CANCEL;
|
||||
DCHECK(in_print_job_);
|
||||
|
||||
// Intentional No-op.
|
||||
|
||||
return OK;
|
||||
}
|
||||
|
||||
PrintingContext::Result PrintingContextNoSystemDialog::DocumentDone() {
|
||||
if (abort_printing_)
|
||||
return CANCEL;
|
||||
DCHECK(in_print_job_);
|
||||
|
||||
ResetSettings();
|
||||
return OK;
|
||||
}
|
||||
|
||||
void PrintingContextNoSystemDialog::Cancel() {
|
||||
abort_printing_ = true;
|
||||
in_print_job_ = false;
|
||||
}
|
||||
|
||||
void PrintingContextNoSystemDialog::ReleaseContext() {
|
||||
// Intentional No-op.
|
||||
}
|
||||
|
||||
gfx::NativeDrawingContext PrintingContextNoSystemDialog::context() const {
|
||||
// Intentional No-op.
|
||||
return NULL;
|
||||
}
|
||||
|
||||
} // namespace printing
|
||||
|
50
printing/printing_context_no_system_dialog.h
Normal file
50
printing/printing_context_no_system_dialog.h
Normal file
@ -0,0 +1,50 @@
|
||||
// Copyright (c) 2011 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 PRINTING_PRINTING_CONTEXT_NO_SYSTEM_DIALOG_H_
|
||||
#define PRINTING_PRINTING_CONTEXT_NO_SYSTEM_DIALOG_H_
|
||||
|
||||
#include <string>
|
||||
|
||||
#include "printing/printing_context.h"
|
||||
|
||||
namespace base {
|
||||
class DictionaryValue;
|
||||
}
|
||||
|
||||
namespace printing {
|
||||
|
||||
class Metafile;
|
||||
|
||||
class PRINTING_EXPORT PrintingContextNoSystemDialog : public PrintingContext {
|
||||
public:
|
||||
explicit PrintingContextNoSystemDialog(const std::string& app_locale);
|
||||
virtual ~PrintingContextNoSystemDialog();
|
||||
|
||||
// PrintingContext implementation.
|
||||
virtual void AskUserForSettings(gfx::NativeView parent_view,
|
||||
int max_pages,
|
||||
bool has_selection,
|
||||
PrintSettingsCallback* callback);
|
||||
virtual Result UseDefaultSettings();
|
||||
virtual Result UpdatePrinterSettings(
|
||||
const base::DictionaryValue& job_settings,
|
||||
const PageRanges& ranges);
|
||||
virtual Result InitWithSettings(const PrintSettings& settings);
|
||||
virtual Result NewDocument(const string16& document_name);
|
||||
virtual Result NewPage();
|
||||
virtual Result PageDone();
|
||||
virtual Result DocumentDone();
|
||||
virtual void Cancel();
|
||||
virtual void ReleaseContext();
|
||||
virtual gfx::NativeDrawingContext context() const;
|
||||
|
||||
private:
|
||||
DISALLOW_COPY_AND_ASSIGN(PrintingContextNoSystemDialog);
|
||||
};
|
||||
|
||||
} // namespace printing
|
||||
|
||||
#endif // PRINTING_PRINTING_CONTEXT_NO_SYSTEM_DIALOG_H_
|
||||
|
Reference in New Issue
Block a user