summaryrefslogtreecommitdiffstats
path: root/printing/printing_context_cairo.cc
diff options
context:
space:
mode:
authorthestig@chromium.org <thestig@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-02-19 00:09:22 +0000
committerthestig@chromium.org <thestig@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-02-19 00:09:22 +0000
commit5cc4c42d46ac837b79333091b110391c2ca1c996 (patch)
tree02764336dcbc316b1725fc614f658f391de8326c /printing/printing_context_cairo.cc
parent38a0a14f438057e1c8c0ddcf1e903c8d53620141 (diff)
downloadchromium_src-5cc4c42d46ac837b79333091b110391c2ca1c996.zip
chromium_src-5cc4c42d46ac837b79333091b110391c2ca1c996.tar.gz
chromium_src-5cc4c42d46ac837b79333091b110391c2ca1c996.tar.bz2
Linux: Refactor printing to be more linux Windows/Mac.
BUG=41543,59732 TEST=Printing works on Linux and CrOS, Linux printing respect print dialog settings. Review URL: http://codereview.chromium.org/6516022 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@75475 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'printing/printing_context_cairo.cc')
-rw-r--r--printing/printing_context_cairo.cc93
1 files changed, 70 insertions, 23 deletions
diff --git a/printing/printing_context_cairo.cc b/printing/printing_context_cairo.cc
index 5976878..d0110b1 100644
--- a/printing/printing_context_cairo.cc
+++ b/printing/printing_context_cairo.cc
@@ -1,17 +1,35 @@
-// Copyright (c) 2009 The Chromium Authors. All rights reserved.
+// 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"
+#include "base/logging.h"
+#include "printing/units.h"
+
+#if defined(OS_CHROMEOS)
+#include <unicode/ulocdata.h>
+#include <printing/native_metafile.h>
+#else
#include <gtk/gtk.h>
#include <gtk/gtkprintunixdialog.h>
-#include <unicode/ulocdata.h>
-#include "base/logging.h"
-#include "printing/native_metafile.h"
#include "printing/print_settings_initializer_gtk.h"
-#include "printing/units.h"
+#endif // defined(OS_CHROMEOS)
+
+#if !defined(OS_CHROMEOS)
+namespace {
+ // Function pointer for creating print dialogs.
+ static void* (*create_dialog_func_)(
+ printing::PrintingContext::PrintSettingsCallback* callback,
+ printing::PrintingContextCairo* context) = NULL;
+ // Function pointer for printing documents.
+ static void (*print_document_func_)(
+ void* print_dialog,
+ const printing::NativeMetafile* metafile,
+ const string16& document_name) = NULL;
+} // namespace
+#endif // !defined(OS_CHROMEOS)
namespace printing {
@@ -20,21 +38,52 @@ namespace printing {
return static_cast<PrintingContext*>(new PrintingContextCairo(app_locale));
}
- PrintingContextCairo::PrintingContextCairo(const std::string& app_locale)
- : PrintingContext(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)
+// static
+void PrintingContextCairo::SetPrintingFunctions(
+ void* (*create_dialog_func)(PrintSettingsCallback* callback,
+ PrintingContextCairo* context),
+ void (*print_document_func)(void* print_dialog,
+ const NativeMetafile* metafile,
+ const string16& document_name)) {
+ DCHECK(create_dialog_func);
+ DCHECK(print_document_func);
+ DCHECK(!create_dialog_func_);
+ DCHECK(!print_document_func_);
+ create_dialog_func_ = create_dialog_func;
+ print_document_func_ = print_document_func;
+}
+
+void PrintingContextCairo::PrintDocument(const NativeMetafile* metafile) {
+ DCHECK(print_dialog_);
+ DCHECK(metafile);
+ print_document_func_(print_dialog_, metafile, document_name_);
+}
+#endif // !defined(OS_CHROMEOS)
+
void PrintingContextCairo::AskUserForSettings(
gfx::NativeView parent_view,
int max_pages,
bool has_selection,
PrintSettingsCallback* callback) {
- NOTIMPLEMENTED();
+#if defined(OS_CHROMEOS)
callback->Run(OK);
+#else
+ print_dialog_ = create_dialog_func_(callback, this);
+#endif // defined(OS_CHROMEOS)
}
PrintingContext::Result PrintingContextCairo::UseDefaultSettings() {
@@ -106,18 +155,19 @@ PrintingContext::Result PrintingContextCairo::InitWithSettings(
settings_ = settings;
- NOTIMPLEMENTED();
-
- return FAILED;
+ return OK;
}
PrintingContext::Result PrintingContextCairo::NewDocument(
const string16& document_name) {
DCHECK(!in_print_job_);
+ in_print_job_ = true;
- NOTIMPLEMENTED();
+#if !defined(OS_CHROMEOS)
+ document_name_ = document_name;
+#endif // !defined(OS_CHROMEOS)
- return FAILED;
+ return OK;
}
PrintingContext::Result PrintingContextCairo::NewPage() {
@@ -125,9 +175,9 @@ PrintingContext::Result PrintingContextCairo::NewPage() {
return CANCEL;
DCHECK(in_print_job_);
- NOTIMPLEMENTED();
+ // Intentional No-op.
- return FAILED;
+ return OK;
}
PrintingContext::Result PrintingContextCairo::PageDone() {
@@ -135,9 +185,9 @@ PrintingContext::Result PrintingContextCairo::PageDone() {
return CANCEL;
DCHECK(in_print_job_);
- NOTIMPLEMENTED();
+ // Intentional No-op.
- return FAILED;
+ return OK;
}
PrintingContext::Result PrintingContextCairo::DocumentDone() {
@@ -145,24 +195,21 @@ PrintingContext::Result PrintingContextCairo::DocumentDone() {
return CANCEL;
DCHECK(in_print_job_);
- NOTIMPLEMENTED();
-
ResetSettings();
- return FAILED;
+ return OK;
}
void PrintingContextCairo::Cancel() {
abort_printing_ = true;
in_print_job_ = false;
-
- NOTIMPLEMENTED();
}
void PrintingContextCairo::ReleaseContext() {
- // Nothing to do yet.
+ // Intentional No-op.
}
gfx::NativeDrawingContext PrintingContextCairo::context() const {
+ // Intentional No-op.
return NULL;
}