summaryrefslogtreecommitdiffstats
path: root/printing
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
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')
-rw-r--r--printing/printed_document.cc14
-rw-r--r--printing/printed_document.h8
-rw-r--r--printing/printed_document_cairo.cc14
-rw-r--r--printing/printing_context_cairo.cc93
-rw-r--r--printing/printing_context_cairo.h25
5 files changed, 121 insertions, 33 deletions
diff --git a/printing/printed_document.cc b/printing/printed_document.cc
index d33751c..3d8f156 100644
--- a/printing/printed_document.cc
+++ b/printing/printed_document.cc
@@ -1,4 +1,4 @@
-// Copyright (c) 2010 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.
@@ -109,10 +109,18 @@ bool PrintedDocument::IsComplete() const {
PageNumber page(immutable_.settings_, mutable_.page_count_);
if (page == PageNumber::npos())
return false;
+
for (; page != PageNumber::npos(); ++page) {
+ bool metafile_must_be_valid =
+#if defined(OS_WIN) || defined(OS_MAC)
+ true;
+#elif defined(OS_POSIX)
+ (page.ToInt() == 0);
+#endif
PrintedPages::const_iterator itr = mutable_.pages_.find(page.ToInt());
- if (itr == mutable_.pages_.end() || !itr->second.get() ||
- !itr->second->native_metafile())
+ if (itr == mutable_.pages_.end() || !itr->second.get())
+ return false;
+ if (metafile_must_be_valid && !itr->second->native_metafile())
return false;
}
return true;
diff --git a/printing/printed_document.h b/printing/printed_document.h
index e71f431..f95ddcf 100644
--- a/printing/printed_document.h
+++ b/printing/printed_document.h
@@ -1,4 +1,4 @@
-// Copyright (c) 2010 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.
@@ -27,6 +27,7 @@ namespace printing {
class PrintedPage;
class PrintedPagesSource;
+class PrintingContext;
// A collection of rendered pages. The settings are immutable. If the print
// settings are changed, a new PrintedDocument must be created.
@@ -55,8 +56,13 @@ class PrintedDocument : public base::RefCountedThreadSafe<PrintedDocument> {
// Draws the page in the context.
// Note: locks for a short amount of time in debug only.
+#if defined(OS_WIN) || defined(OS_MACOSX)
void RenderPrintedPage(const PrintedPage& page,
gfx::NativeDrawingContext context) const;
+#elif defined(OS_POSIX)
+ void RenderPrintedPage(const PrintedPage& page,
+ PrintingContext* context) const;
+#endif
// Returns true if all the necessary pages for the settings are already
// rendered.
diff --git a/printing/printed_document_cairo.cc b/printing/printed_document_cairo.cc
index d24fef9..9992bc6 100644
--- a/printing/printed_document_cairo.cc
+++ b/printing/printed_document_cairo.cc
@@ -1,19 +1,18 @@
-// 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/printed_document.h"
-#include "base/file_util.h"
#include "base/logging.h"
-#include "base/message_loop.h"
#include "printing/page_number.h"
#include "printing/printed_page.h"
+#include "printing/printing_context_cairo.h"
namespace printing {
void PrintedDocument::RenderPrintedPage(
- const PrintedPage& page, gfx::NativeDrawingContext context) const {
+ const PrintedPage& page, PrintingContext* context) const {
#ifndef NDEBUG
{
// Make sure the page is from our list.
@@ -24,7 +23,12 @@ void PrintedDocument::RenderPrintedPage(
DCHECK(context);
- NOTIMPLEMENTED();
+#if !defined(OS_CHROMEOS)
+ if (page.page_number() == 1) {
+ reinterpret_cast<PrintingContextCairo*>(context)->PrintDocument(
+ page.native_metafile());
+ }
+#endif // !defined(OS_CHROMEOS)
}
void PrintedDocument::DrawHeaderFooter(gfx::NativeDrawingContext context,
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;
}
diff --git a/printing/printing_context_cairo.h b/printing/printing_context_cairo.h
index ac42239..9a88eae 100644
--- a/printing/printing_context_cairo.h
+++ b/printing/printing_context_cairo.h
@@ -1,4 +1,4 @@
-// Copyright (c) 2010 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.
@@ -9,6 +9,10 @@
#include "printing/printing_context.h"
+#if !defined(OS_CHROMEOS)
+#include "printing/native_metafile.h"
+#endif
+
namespace printing {
class PrintingContextCairo : public PrintingContext {
@@ -16,6 +20,20 @@ class PrintingContextCairo : public PrintingContext {
explicit PrintingContextCairo(const std::string& app_locale);
~PrintingContextCairo();
+#if !defined(OS_CHROMEOS)
+ // Sets the function that creates the print dialog, and the function that
+ // prints the document.
+ static void SetPrintingFunctions(
+ void* (*create_dialog_func)(PrintSettingsCallback* callback,
+ PrintingContextCairo* context),
+ void (*print_document_func)(void* print_dialog,
+ const NativeMetafile* metafile,
+ const string16& document_name));
+
+ // Prints the document contained in |metafile|.
+ void PrintDocument(const NativeMetafile* metafile);
+#endif
+
// PrintingContext implementation.
virtual void AskUserForSettings(gfx::NativeView parent_view,
int max_pages,
@@ -32,6 +50,11 @@ class PrintingContextCairo : public PrintingContext {
virtual gfx::NativeDrawingContext context() const;
private:
+#if !defined(OS_CHROMEOS)
+ string16 document_name_;
+ void* print_dialog_;
+#endif
+
DISALLOW_COPY_AND_ASSIGN(PrintingContextCairo);
};