summaryrefslogtreecommitdiffstats
path: root/chrome/renderer/print_web_view_helper_linux.cc
diff options
context:
space:
mode:
authorvandebo@chromium.org <vandebo@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-05-24 16:12:13 +0000
committervandebo@chromium.org <vandebo@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-05-24 16:12:13 +0000
commit220cf4d0b875b6c066e3a9bcab152f5572834d4f (patch)
treea187f00660f6c0f5a8f1c2f3a9eddd65db256d51 /chrome/renderer/print_web_view_helper_linux.cc
parente2ca8cc8afff4e85bdb090e487c9b1ff70b677c8 (diff)
downloadchromium_src-220cf4d0b875b6c066e3a9bcab152f5572834d4f.zip
chromium_src-220cf4d0b875b6c066e3a9bcab152f5572834d4f.tar.gz
chromium_src-220cf4d0b875b6c066e3a9bcab152f5572834d4f.tar.bz2
Change printing of PDFs for preview on Windows to not rasterize.
Also cleaned up a few hacks. BUG=80220 TEST=Navigate to a PDF and start print preview. Review URL: http://codereview.chromium.org/7065011 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@86431 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/renderer/print_web_view_helper_linux.cc')
-rw-r--r--chrome/renderer/print_web_view_helper_linux.cc68
1 files changed, 30 insertions, 38 deletions
diff --git a/chrome/renderer/print_web_view_helper_linux.cc b/chrome/renderer/print_web_view_helper_linux.cc
index 6f190594..c5e8e5a 100644
--- a/chrome/renderer/print_web_view_helper_linux.cc
+++ b/chrome/renderer/print_web_view_helper_linux.cc
@@ -14,6 +14,7 @@
#include "printing/metafile_impl.h"
#include "printing/metafile_skia_wrapper.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"
#include "ui/gfx/point.h"
@@ -156,42 +157,32 @@ bool PrintWebViewHelper::RenderPages(const PrintMsg_PrintPages_Params& params,
int* page_count,
printing::Metafile* metafile) {
PrintMsg_Print_Params printParams = params.params;
- scoped_ptr<skia::VectorCanvas> canvas;
UpdatePrintableSizeInPrintParameters(frame, node, &printParams);
- {
- // Hack - when |prep_frame_view| goes out of scope, PrintEnd() gets called.
- // Doing this before closing |metafile| below ensures
- // webkit::ppapi::PluginInstance::PrintEnd() has a valid canvas/metafile to
- // save the final output to. See pepper_plugin_instance.cc for the whole
- // story.
- PrepareFrameAndViewForPrint prep_frame_view(printParams,
- frame,
- node,
- frame->view());
- *page_count = prep_frame_view.GetExpectedPageCount();
- if (send_expected_page_count) {
- Send(new PrintHostMsg_DidGetPrintedPagesCount(routing_id(),
- printParams.document_cookie,
- *page_count));
- }
- if (!*page_count)
- return false;
+ PrepareFrameAndViewForPrint prep_frame_view(printParams, frame, node,
+ frame->view());
+ *page_count = prep_frame_view.GetExpectedPageCount();
+ if (send_expected_page_count) {
+ Send(new PrintHostMsg_DidGetPrintedPagesCount(routing_id(),
+ printParams.document_cookie,
+ *page_count));
+ }
+ if (!*page_count)
+ return false;
- PrintMsg_PrintPage_Params page_params;
- page_params.params = printParams;
- const gfx::Size& canvas_size = prep_frame_view.GetPrintCanvasSize();
- if (params.pages.empty()) {
- for (int i = 0; i < *page_count; ++i) {
- page_params.page_number = i;
- PrintPageInternal(page_params, canvas_size, frame, metafile, &canvas);
- }
- } else {
- for (size_t i = 0; i < params.pages.size(); ++i) {
- page_params.page_number = params.pages[i];
- PrintPageInternal(page_params, canvas_size, frame, metafile, &canvas);
- }
+ PrintMsg_PrintPage_Params page_params;
+ page_params.params = printParams;
+ const gfx::Size& canvas_size = prep_frame_view.GetPrintCanvasSize();
+ if (params.pages.empty()) {
+ for (int i = 0; i < *page_count; ++i) {
+ page_params.page_number = i;
+ PrintPageInternal(page_params, canvas_size, frame, metafile);
+ }
+ } else {
+ for (size_t i = 0; i < params.pages.size(); ++i) {
+ page_params.page_number = params.pages[i];
+ PrintPageInternal(page_params, canvas_size, frame, metafile);
}
}
@@ -204,8 +195,7 @@ void PrintWebViewHelper::PrintPageInternal(
const PrintMsg_PrintPage_Params& params,
const gfx::Size& canvas_size,
WebFrame* frame,
- printing::Metafile* metafile,
- scoped_ptr<skia::VectorCanvas>* canvas) {
+ printing::Metafile* metafile) {
double content_width_in_points;
double content_height_in_points;
double margin_top_in_points;
@@ -235,11 +225,13 @@ void PrintWebViewHelper::PrintPageInternal(
if (!device)
return;
- canvas->reset(new skia::VectorCanvas(device));
- printing::MetafileSkiaWrapper::SetMetafileOnCanvas(canvas->get(), metafile);
- frame->printPage(params.page_number, canvas->get());
+ // The printPage method take a reference to the canvas we pass down, so it
+ // 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.get(), metafile);
+ frame->printPage(params.page_number, canvas.get());
- // TODO(myhuang): We should handle transformation for paper margins.
// TODO(myhuang): We should render the header and the footer.
// Done printing. Close the device context to retrieve the compiled metafile.