OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "chrome/renderer/print_web_view_helper.h" | 5 #include "chrome/renderer/print_web_view_helper.h" |
6 | 6 |
7 #import <AppKit/AppKit.h> | 7 #import <AppKit/AppKit.h> |
8 | 8 |
9 #include "base/logging.h" | 9 #include "base/logging.h" |
10 #include "base/mac/scoped_nsautorelease_pool.h" | 10 #include "base/mac/scoped_nsautorelease_pool.h" |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
61 | 61 |
62 void PrintWebViewHelper::RenderPreviewPage(int page_number) { | 62 void PrintWebViewHelper::RenderPreviewPage(int page_number) { |
63 float scale_factor = print_preview_context_.frame()->getPrintPageShrink(0); | 63 float scale_factor = print_preview_context_.frame()->getPrintPageShrink(0); |
64 PrintMsg_Print_Params printParams = print_preview_context_.print_params(); | 64 PrintMsg_Print_Params printParams = print_preview_context_.print_params(); |
65 gfx::Rect content_area(printParams.margin_left, printParams.margin_top, | 65 gfx::Rect content_area(printParams.margin_left, printParams.margin_top, |
66 printParams.printable_size.width(), | 66 printParams.printable_size.width(), |
67 printParams.printable_size.height()); | 67 printParams.printable_size.height()); |
68 | 68 |
69 printing::Metafile* initial_render_metafile = | 69 printing::Metafile* initial_render_metafile = |
70 print_preview_context_.metafile(); | 70 print_preview_context_.metafile(); |
| 71 scoped_ptr<printing::Metafile> draft_metafile; |
71 #if !defined(USE_SKIA) | 72 #if !defined(USE_SKIA) |
72 if (print_preview_context_.IsModifiable()) { | 73 if (print_preview_context_.IsModifiable()) { |
73 initial_render_metafile = new printing::PreviewMetafile(); | 74 draft_metafile.reset(new printing::PreviewMetafile); |
74 if (!initial_render_metafile->Init()) { | 75 if (!draft_metafile->Init()) { |
75 DidFinishPrinting(FAIL_PREVIEW); | 76 DidFinishPrinting(FAIL_PREVIEW); |
76 return; | 77 return; |
77 } | 78 } |
| 79 initial_render_metafile = draft_metafile.get(); |
78 } | 80 } |
79 #endif | 81 #endif |
80 | 82 |
81 base::TimeTicks begin_time = base::TimeTicks::Now(); | 83 base::TimeTicks begin_time = base::TimeTicks::Now(); |
82 RenderPage(printParams.page_size, content_area, scale_factor, page_number, | 84 RenderPage(printParams.page_size, content_area, scale_factor, page_number, |
83 print_preview_context_.frame(), initial_render_metafile); | 85 print_preview_context_.frame(), initial_render_metafile); |
84 print_preview_context_.RenderedPreviewPage( | 86 print_preview_context_.RenderedPreviewPage( |
85 base::TimeTicks::Now() - begin_time); | 87 base::TimeTicks::Now() - begin_time); |
86 | 88 |
87 printing::Metafile* draft_metafile = NULL; | |
88 if (print_preview_context_.IsModifiable()) { | 89 if (print_preview_context_.IsModifiable()) { |
89 #if defined(USE_SKIA) | 90 #if defined(USE_SKIA) |
90 draft_metafile = reinterpret_cast<printing::PreviewMetafile*>( | 91 DCHECK(!draft_metafile.get()); |
91 print_preview_context_.metafile())->GetMetafileForCurrentPage(); | 92 draft_metafile.reset(reinterpret_cast<printing::PreviewMetafile*>( |
| 93 print_preview_context_.metafile())->GetMetafileForCurrentPage()); |
92 #else | 94 #else |
93 draft_metafile = initial_render_metafile; | |
94 draft_metafile->FinishDocument(); | 95 draft_metafile->FinishDocument(); |
95 | 96 |
96 // With CG, we rendered into a new metafile so we could get it as a draft | 97 // With CG, we rendered into a new metafile so we could get it as a draft |
97 // document. Now we need to add it to complete document. | 98 // document. Now we need to add it to complete document. |
98 draft_metafile->RenderPage(1, | 99 draft_metafile->RenderPage(1, |
99 print_preview_context_.metafile()->context(), | 100 print_preview_context_.metafile()->context(), |
100 CGRectMake(content_area.x(), content_area.y(), | 101 CGRectMake(content_area.x(), content_area.y(), |
101 content_area.width(), | 102 content_area.width(), |
102 content_area.height()), | 103 content_area.height()), |
103 false /*shrunk_to_fit*/, | 104 false /*shrunk_to_fit*/, |
104 false /*stretch_to_fit*/, | 105 false /*stretch_to_fit*/, |
105 true /*center_horizontally*/, | 106 true /*center_horizontally*/, |
106 true /*center_vertically*/); | 107 true /*center_vertically*/); |
107 #endif | 108 #endif |
108 } | 109 } |
109 | 110 |
110 PreviewPageRendered(page_number, draft_metafile); | 111 PreviewPageRendered(page_number, draft_metafile.get()); |
111 } | 112 } |
112 | 113 |
113 void PrintWebViewHelper::RenderPage( | 114 void PrintWebViewHelper::RenderPage( |
114 const gfx::Size& page_size, const gfx::Rect& content_area, | 115 const gfx::Size& page_size, const gfx::Rect& content_area, |
115 const float& scale_factor, int page_number, WebFrame* frame, | 116 const float& scale_factor, int page_number, WebFrame* frame, |
116 printing::Metafile* metafile) { | 117 printing::Metafile* metafile) { |
117 | 118 |
118 { | 119 { |
119 #if defined(USE_SKIA) | 120 #if defined(USE_SKIA) |
120 SkDevice* device = metafile->StartPageForVectorCanvas( | 121 SkDevice* device = metafile->StartPageForVectorCanvas( |
(...skipping 14 matching lines...) Expand all Loading... |
135 base::mac::ScopedNSAutoreleasePool pool; | 136 base::mac::ScopedNSAutoreleasePool pool; |
136 CGContextRef cgContext = metafile->context(); | 137 CGContextRef cgContext = metafile->context(); |
137 CGContextRef canvasPtr = cgContext; | 138 CGContextRef canvasPtr = cgContext; |
138 #endif | 139 #endif |
139 frame->printPage(page_number, canvasPtr); | 140 frame->printPage(page_number, canvasPtr); |
140 } | 141 } |
141 | 142 |
142 // Done printing. Close the device context to retrieve the compiled metafile. | 143 // Done printing. Close the device context to retrieve the compiled metafile. |
143 metafile->FinishPage(); | 144 metafile->FinishPage(); |
144 } | 145 } |
OLD | NEW |