diff options
author | kmadhusu@chromium.org <kmadhusu@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-09-27 22:10:32 +0000 |
---|---|---|
committer | kmadhusu@chromium.org <kmadhusu@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-09-27 22:10:32 +0000 |
commit | e5d982d40c7d6a0e03da2c6772265bbf7455773f (patch) | |
tree | 6402ede7e46fe52c2ac430cf1b6f07669adf5993 | |
parent | 77cc7e0fd794f4eee8e43d5bbb47dc25dae72190 (diff) | |
download | chromium_src-e5d982d40c7d6a0e03da2c6772265bbf7455773f.zip chromium_src-e5d982d40c7d6a0e03da2c6772265bbf7455773f.tar.gz chromium_src-e5d982d40c7d6a0e03da2c6772265bbf7455773f.tar.bz2 |
Revert 103021 - PrintPreview: Printing preview of a PDF on Mac with Skia only previews the last page of the PDF
BUG=93145
TEST=Please refer to bug report.
Review URL: http://codereview.chromium.org/7719014
TBR=kmadhusu@chromium.org
Review URL: http://codereview.chromium.org/8052020
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@103026 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r-- | chrome/renderer/print_web_view_helper.h | 3 | ||||
-rw-r--r-- | chrome/renderer/print_web_view_helper_linux.cc | 6 | ||||
-rw-r--r-- | chrome/renderer/print_web_view_helper_mac.mm | 13 | ||||
-rw-r--r-- | chrome/renderer/print_web_view_helper_win.cc | 6 | ||||
-rw-r--r-- | printing/metafile_skia_wrapper.cc | 34 | ||||
-rw-r--r-- | printing/metafile_skia_wrapper.h | 8 | ||||
-rw-r--r-- | skia/ext/platform_device.cc | 45 | ||||
-rw-r--r-- | skia/ext/platform_device.h | 12 | ||||
-rw-r--r-- | webkit/plugins/ppapi/ppapi_plugin_instance.cc | 23 | ||||
-rw-r--r-- | webkit/plugins/ppapi/ppapi_plugin_instance.h | 16 |
10 files changed, 65 insertions, 101 deletions
diff --git a/chrome/renderer/print_web_view_helper.h b/chrome/renderer/print_web_view_helper.h index 1884f9f..7d0a8ea 100644 --- a/chrome/renderer/print_web_view_helper.h +++ b/chrome/renderer/print_web_view_helper.h @@ -234,8 +234,7 @@ class PrintWebViewHelper : public RenderViewObserver, #elif defined(OS_MACOSX) void RenderPage(const gfx::Size& page_size, const gfx::Rect& content_area, const float& scale_factor, int page_number, - WebKit::WebFrame* frame, bool is_preview, - printing::Metafile* metafile); + WebKit::WebFrame* frame, printing::Metafile* metafile); #elif defined(OS_POSIX) bool RenderPages(const PrintMsg_PrintPages_Params& params, WebKit::WebFrame* frame, const WebKit::WebNode& node, diff --git a/chrome/renderer/print_web_view_helper_linux.cc b/chrome/renderer/print_web_view_helper_linux.cc index 4d03b35..7d93a84 100644 --- a/chrome/renderer/print_web_view_helper_linux.cc +++ b/chrome/renderer/print_web_view_helper_linux.cc @@ -14,7 +14,6 @@ #include "printing/metafile_impl.h" #include "printing/metafile_skia_wrapper.h" #include "printing/page_size_margins.h" -#include "skia/ext/platform_device.h" #include "skia/ext/vector_canvas.h" #include "third_party/skia/include/core/SkRefCnt.h" #include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h" @@ -209,8 +208,9 @@ void PrintWebViewHelper::PrintPageInternal( // can't be a stack object. SkRefPtr<skia::VectorCanvas> canvas = new skia::VectorCanvas(device); canvas->unref(); // SkRefPtr and new both took a reference. - printing::MetafileSkiaWrapper::SetMetafileOnCanvas(*canvas, metafile); - skia::SetIsDraftMode(*canvas, is_print_ready_metafile_sent_); + printing::MetafileSkiaWrapper::SetMetafileOnCanvas(canvas.get(), metafile); + printing::MetafileSkiaWrapper::SetDraftMode(canvas.get(), + is_print_ready_metafile_sent_); frame->printPage(params.page_number, canvas.get()); if (params.params.display_header_footer) { diff --git a/chrome/renderer/print_web_view_helper_mac.mm b/chrome/renderer/print_web_view_helper_mac.mm index 1700f66..0e8c3b2 100644 --- a/chrome/renderer/print_web_view_helper_mac.mm +++ b/chrome/renderer/print_web_view_helper_mac.mm @@ -17,7 +17,6 @@ #if defined(USE_SKIA) #include "printing/metafile_skia_wrapper.h" -#include "skia/ext/platform_device.h" #include "skia/ext/vector_canvas.h" #include "third_party/WebKit/Source/WebKit/chromium/public/WebCanvas.h" #endif @@ -38,7 +37,7 @@ void PrintWebViewHelper::PrintPageInternal( // Render page for printing. gfx::Rect content_area(params.params.printable_size); RenderPage(params.params.printable_size, content_area, scale_factor, - page_number, frame, false, &metafile); + page_number, frame, &metafile); metafile.FinishDocument(); PrintHostMsg_DidPrintPage_Params page_params; @@ -97,7 +96,7 @@ bool PrintWebViewHelper::RenderPreviewPage(int page_number) { base::TimeTicks begin_time = base::TimeTicks::Now(); RenderPage(printParams.page_size, content_area, scale_factor, page_number, - print_preview_context_.frame(), true, initial_render_metafile); + print_preview_context_.frame(), initial_render_metafile); print_preview_context_.RenderedPreviewPage( base::TimeTicks::Now() - begin_time); @@ -145,7 +144,7 @@ bool PrintWebViewHelper::RenderPreviewPage(int page_number) { void PrintWebViewHelper::RenderPage( const gfx::Size& page_size, const gfx::Rect& content_area, const float& scale_factor, int page_number, WebFrame* frame, - bool is_preview, printing::Metafile* metafile) { + printing::Metafile* metafile) { { #if defined(USE_SKIA) @@ -157,9 +156,9 @@ void PrintWebViewHelper::RenderPage( SkRefPtr<skia::VectorCanvas> canvas = new skia::VectorCanvas(device); canvas->unref(); // SkRefPtr and new both took a reference. WebKit::WebCanvas* canvas_ptr = canvas.get(); - printing::MetafileSkiaWrapper::SetMetafileOnCanvas(*canvas, metafile); - skia::SetIsDraftMode(*canvas, is_print_ready_metafile_sent_); - skia::SetIsPreviewMetafile(*canvas, is_preview); + printing::MetafileSkiaWrapper::SetMetafileOnCanvas(canvas.get(), metafile); + printing::MetafileSkiaWrapper::SetDraftMode(canvas.get(), + is_print_ready_metafile_sent_); #else bool success = metafile->StartPage(page_size, content_area, scale_factor); DCHECK(success); diff --git a/chrome/renderer/print_web_view_helper_win.cc b/chrome/renderer/print_web_view_helper_win.cc index fe8e6b6..4ceef0b 100644 --- a/chrome/renderer/print_web_view_helper_win.cc +++ b/chrome/renderer/print_web_view_helper_win.cc @@ -193,9 +193,9 @@ Metafile* PrintWebViewHelper::RenderPage( SkRefPtr<skia::VectorCanvas> canvas = new skia::VectorCanvas(device); canvas->unref(); // SkRefPtr and new both took a reference. if (is_preview) { - printing::MetafileSkiaWrapper::SetMetafileOnCanvas(*canvas, metafile); - skia::SetIsDraftMode(*canvas, is_print_ready_metafile_sent_); - skia::SetIsPreviewMetafile(*canvas, is_preview); + printing::MetafileSkiaWrapper::SetMetafileOnCanvas(canvas.get(), metafile); + printing::MetafileSkiaWrapper::SetDraftMode(canvas.get(), + is_print_ready_metafile_sent_); } float webkit_scale_factor = frame->printPage(page_number, canvas.get()); diff --git a/printing/metafile_skia_wrapper.cc b/printing/metafile_skia_wrapper.cc index ee24a66..cc7fa08 100644 --- a/printing/metafile_skia_wrapper.cc +++ b/printing/metafile_skia_wrapper.cc @@ -2,8 +2,8 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. +#include "base/logging.h" #include "printing/metafile_skia_wrapper.h" -#include "skia/ext/platform_device.h" #include "third_party/skia/include/core/SkCanvas.h" #include "third_party/skia/include/core/SkDevice.h" #include "third_party/skia/include/core/SkMetaData.h" @@ -12,25 +12,34 @@ namespace printing { namespace { +const char* kDraftModeKey = "CrDraftMode"; const char* kMetafileKey = "CrMetafile"; +SkMetaData& getMetaData(SkCanvas* canvas) { + DCHECK(canvas != NULL); + + SkDevice* device = canvas->getDevice(); + DCHECK(device != NULL); + return device->getMetaData(); +} + } // namespace // static -void MetafileSkiaWrapper::SetMetafileOnCanvas(const SkCanvas& canvas, +void MetafileSkiaWrapper::SetMetafileOnCanvas(SkCanvas* canvas, Metafile* metafile) { MetafileSkiaWrapper* wrapper = NULL; if (metafile) wrapper = new MetafileSkiaWrapper(metafile); - SkMetaData& meta = skia::getMetaData(canvas); + SkMetaData& meta = getMetaData(canvas); meta.setRefCnt(kMetafileKey, wrapper); SkSafeUnref(wrapper); } // static -Metafile* MetafileSkiaWrapper::GetMetafileFromCanvas(const SkCanvas& canvas) { - SkMetaData& meta = skia::getMetaData(canvas); +Metafile* MetafileSkiaWrapper::GetMetafileFromCanvas(SkCanvas* canvas) { + SkMetaData& meta = getMetaData(canvas); SkRefCnt* value; if (!meta.findRefCnt(kMetafileKey, &value) || !value) return NULL; @@ -38,6 +47,21 @@ Metafile* MetafileSkiaWrapper::GetMetafileFromCanvas(const SkCanvas& canvas) { return static_cast<MetafileSkiaWrapper*>(value)->metafile_; } +// static +void MetafileSkiaWrapper::SetDraftMode(SkCanvas* canvas, bool draft_mode) { + SkMetaData& meta = getMetaData(canvas); + meta.setBool(kDraftModeKey, draft_mode); +} + +// static +bool MetafileSkiaWrapper::GetDraftMode(SkCanvas* canvas) { + SkMetaData& meta = getMetaData(canvas); + bool draft_mode; + if (!meta.findBool(kDraftModeKey, &draft_mode)) + draft_mode = false; + return draft_mode; +} + MetafileSkiaWrapper::MetafileSkiaWrapper(Metafile* metafile) : metafile_(metafile) { } diff --git a/printing/metafile_skia_wrapper.h b/printing/metafile_skia_wrapper.h index 9010449..40e26e8 100644 --- a/printing/metafile_skia_wrapper.h +++ b/printing/metafile_skia_wrapper.h @@ -20,9 +20,13 @@ class Metafile; // as long as the canvas. class PRINTING_EXPORT MetafileSkiaWrapper : public SkRefCnt { public: - static void SetMetafileOnCanvas(const SkCanvas& canvas, Metafile* metafile); + static void SetMetafileOnCanvas(SkCanvas* canvas, Metafile* metafile); - static Metafile* GetMetafileFromCanvas(const SkCanvas& canvas); + static Metafile* GetMetafileFromCanvas(SkCanvas* canvas); + + static void SetDraftMode(SkCanvas* canvas, bool draft_mode); + + static bool GetDraftMode(SkCanvas* canvas); private: explicit MetafileSkiaWrapper(Metafile* metafile); diff --git a/skia/ext/platform_device.cc b/skia/ext/platform_device.cc index 6292273..9e1dde7 100644 --- a/skia/ext/platform_device.cc +++ b/skia/ext/platform_device.cc @@ -2,7 +2,6 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#include "base/logging.h" #include "skia/ext/platform_device.h" #include "third_party/skia/include/core/SkMetaData.h" @@ -10,29 +9,9 @@ namespace skia { namespace { - const char* kDevicePlatformBehaviour = "CrDevicePlatformBehaviour"; -const char* kDraftModeKey = "CrDraftMode"; - -#if defined(OS_MACOSX) || defined(OS_WIN) -const char* kIsPreviewMetafileKey = "CrIsPreviewMetafile"; -#endif - -void SetBoolMetaData(const SkCanvas& canvas, const char* key, bool value) { - SkMetaData& meta = skia::getMetaData(canvas); - meta.setBool(key, value); -} - -bool GetBoolMetaData(const SkCanvas& canvas, const char* key) { - bool value; - SkMetaData& meta = skia::getMetaData(canvas); - if (!meta.findBool(key, &value)) - value = false; - return value; } -} // namespace - void SetPlatformDevice(SkDevice* device, PlatformDevice* platform_behaviour) { SkMetaData& meta_data = device->getMetaData(); meta_data.setPtr(kDevicePlatformBehaviour, platform_behaviour); @@ -48,30 +27,6 @@ PlatformDevice* GetPlatformDevice(SkDevice* device) { return NULL; } -SkMetaData& getMetaData(const SkCanvas& canvas) { - SkDevice* device = canvas.getDevice(); - DCHECK(device != NULL); - return device->getMetaData(); -} - -void SetIsDraftMode(const SkCanvas& canvas, bool draft_mode) { - SetBoolMetaData(canvas, kDraftModeKey, draft_mode); -} - -bool IsDraftMode(const SkCanvas& canvas) { - return GetBoolMetaData(canvas, kDraftModeKey); -} - -#if defined(OS_MACOSX) || defined(OS_WIN) -void SetIsPreviewMetafile(const SkCanvas& canvas, bool is_preview) { - SetBoolMetaData(canvas, kIsPreviewMetafileKey, is_preview); -} - -bool IsPreviewMetafile(const SkCanvas& canvas) { - return GetBoolMetaData(canvas, kIsPreviewMetafileKey); -} -#endif - bool PlatformDevice::IsNativeFontRenderingAllowed() { return true; } diff --git a/skia/ext/platform_device.h b/skia/ext/platform_device.h index b2972c2..179a8e8 100644 --- a/skia/ext/platform_device.h +++ b/skia/ext/platform_device.h @@ -18,7 +18,6 @@ #include "third_party/skia/include/core/SkColor.h" class SkMatrix; -class SkMetaData; class SkPath; class SkRegion; @@ -79,17 +78,6 @@ SK_API void InitializeDC(HDC context); SK_API CGContextRef GetBitmapContext(SkDevice* device); #endif -// Following routines are used in print preview workflow to mark the draft mode -// metafile and preview metafile. -SkMetaData& getMetaData(const SkCanvas& canvas); -void SetIsDraftMode(const SkCanvas& canvas, bool draft_mode); -bool IsDraftMode(const SkCanvas& canvas); - -#if defined(OS_MACOSX) || defined(OS_WIN) -void SetIsPreviewMetafile(const SkCanvas& canvas, bool is_preview); -bool IsPreviewMetafile(const SkCanvas& canvas); -#endif - // A SkDevice is basically a wrapper around SkBitmap that provides a surface for // SkCanvas to draw into. PlatformDevice provides a surface Windows can also // write to. It also provides functionality to play well with GDI drawing diff --git a/webkit/plugins/ppapi/ppapi_plugin_instance.cc b/webkit/plugins/ppapi/ppapi_plugin_instance.cc index cee7108..4ec22da 100644 --- a/webkit/plugins/ppapi/ppapi_plugin_instance.cc +++ b/webkit/plugins/ppapi/ppapi_plugin_instance.cc @@ -851,10 +851,10 @@ int PluginInstance::PrintBegin(const gfx::Rect& printable_area, if (!num_pages) return 0; current_print_settings_ = print_settings; -#if defined(USE_SKIA) +#if defined(OS_LINUX) || defined(OS_WIN) canvas_ = NULL; ranges_.clear(); -#endif // USE_SKIA +#endif // OS_LINUX || OS_WIN return num_pages; } @@ -862,19 +862,14 @@ bool PluginInstance::PrintPage(int page_number, WebKit::WebCanvas* canvas) { DCHECK(plugin_print_interface_); PP_PrintPageNumberRange_Dev page_range; page_range.first_page_number = page_range.last_page_number = page_number; -#if defined(USE_SKIA) +#if defined(OS_LINUX) || defined(OS_WIN) // The canvas only has a metafile on it for print preview. - bool save_for_later = - (printing::MetafileSkiaWrapper::GetMetafileFromCanvas(*canvas) != NULL); -#if defined(OS_MACOSX) || defined(OS_WIN) - save_for_later = save_for_later && skia::IsPreviewMetafile(*canvas); -#endif - if (save_for_later) { + if (printing::MetafileSkiaWrapper::GetMetafileFromCanvas(canvas)) { ranges_.push_back(page_range); canvas_ = canvas; return true; } else -#endif // USE_SKIA +#endif // OS_LINUX || OS_WIN { return PrintPageHelper(&page_range, 1, canvas); } @@ -906,12 +901,12 @@ bool PluginInstance::PrintPageHelper(PP_PrintPageNumberRange_Dev* page_ranges, void PluginInstance::PrintEnd() { // Keep a reference on the stack. See NOTE above. scoped_refptr<PluginInstance> ref(this); -#if defined(USE_SKIA) +#if defined(OS_LINUX) || defined(OS_WIN) if (!ranges_.empty()) PrintPageHelper(&(ranges_.front()), ranges_.size(), canvas_.get()); canvas_ = NULL; ranges_.clear(); -#endif // USE_SKIA +#endif // OS_LINUX || OS_WIN DCHECK(plugin_print_interface_); if (plugin_print_interface_) @@ -1066,7 +1061,7 @@ bool PluginInstance::PrintPDFOutput(PP_Resource print_output, // (NativeMetafile and PreviewMetafile must have compatible formats, // i.e. both PDF for this to work). printing::Metafile* metafile = - printing::MetafileSkiaWrapper::GetMetafileFromCanvas(*canvas); + printing::MetafileSkiaWrapper::GetMetafileFromCanvas(canvas); DCHECK(metafile != NULL); if (metafile) ret = metafile->InitFromData(mapper.data(), mapper.size()); @@ -1091,7 +1086,7 @@ bool PluginInstance::PrintPDFOutput(PP_Resource print_output, } #elif defined(OS_WIN) printing::Metafile* metafile = - printing::MetafileSkiaWrapper::GetMetafileFromCanvas(*canvas); + printing::MetafileSkiaWrapper::GetMetafileFromCanvas(canvas); if (metafile) { // We only have a metafile when doing print preview, so we just want to // pass the PDF off to preview. diff --git a/webkit/plugins/ppapi/ppapi_plugin_instance.h b/webkit/plugins/ppapi/ppapi_plugin_instance.h index fdb3dce..f46301b 100644 --- a/webkit/plugins/ppapi/ppapi_plugin_instance.h +++ b/webkit/plugins/ppapi/ppapi_plugin_instance.h @@ -466,14 +466,14 @@ class PluginInstance : public base::RefCounted<PluginInstance>, // variable to hold on to the pixels. scoped_refptr<PPB_ImageData_Impl> last_printed_page_; #endif // defined(OS_MACOSX) -#if defined(USE_SKIA) - // Always when printing to PDF on Linux and when printing for preview on Mac - // and Win, the entire document goes into one metafile. However, when users - // print only a subset of all the pages, it is impossible to know if a call - // to PrintPage() is the last call. Thus in PrintPage(), just store the page - // number in |ranges_|. The hack is in PrintEnd(), where a valid |canvas_| - // is preserved in PrintWebViewHelper::PrintPages. This makes it possible - // to generate the entire PDF given the variables below: +#if defined(OS_LINUX) || defined(OS_WIN) + // When printing to PDF (print preview, Linux) the entire document goes into + // one metafile. However, when users print only a subset of all the pages, + // it is impossible to know if a call to PrintPage() is the last call. + // Thus in PrintPage(), just store the page number in |ranges_|. + // The hack is in PrintEnd(), where a valid |canvas_| is preserved in + // PrintWebViewHelper::PrintPages. This makes it possible to generate the + // entire PDF given the variables below: // // The most recently used WebCanvas, guaranteed to be valid. SkRefPtr<WebKit::WebCanvas> canvas_; |