Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(39)

Side by Side Diff: chrome/renderer/print_web_view_helper_linux.cc

Issue 8585017: PrintPreview: Honor the print media page size and margin values. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix win and mac issues Created 8 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 #include "base/file_descriptor_posix.h" 7 #include "base/file_descriptor_posix.h"
8 #include "base/logging.h" 8 #include "base/logging.h"
9 #include "base/memory/scoped_ptr.h" 9 #include "base/memory/scoped_ptr.h"
10 #include "base/metrics/histogram.h" 10 #include "base/metrics/histogram.h"
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after
136 #endif // defined(OS_CHROMEOS) 136 #endif // defined(OS_CHROMEOS)
137 } 137 }
138 138
139 bool PrintWebViewHelper::RenderPages(const PrintMsg_PrintPages_Params& params, 139 bool PrintWebViewHelper::RenderPages(const PrintMsg_PrintPages_Params& params,
140 WebKit::WebFrame* frame, 140 WebKit::WebFrame* frame,
141 const WebKit::WebNode& node, 141 const WebKit::WebNode& node,
142 int* page_count, 142 int* page_count,
143 PrepareFrameAndViewForPrint* prepare, 143 PrepareFrameAndViewForPrint* prepare,
144 printing::Metafile* metafile) { 144 printing::Metafile* metafile) {
145 PrintMsg_Print_Params print_params = params.params; 145 PrintMsg_Print_Params print_params = params.params;
146 UpdatePrintableSizeInPrintParameters(frame, node, prepare, &print_params); 146 UpdateFrameAndViewFromCssPageLayout(frame, node, prepare, print_params,
147 ignore_css_margins_, fit_to_page_);
147 148
148 *page_count = prepare->GetExpectedPageCount(); 149 *page_count = prepare->GetExpectedPageCount();
149 if (!*page_count) 150 if (!*page_count)
150 return false; 151 return false;
151 152
152 #if !defined(OS_CHROMEOS) 153 #if !defined(OS_CHROMEOS)
153 Send(new PrintHostMsg_DidGetPrintedPagesCount(routing_id(), 154 Send(new PrintHostMsg_DidGetPrintedPagesCount(routing_id(),
154 print_params.document_cookie, 155 print_params.document_cookie,
155 *page_count)); 156 *page_count));
156 #endif 157 #endif
(...skipping 17 matching lines...) Expand all
174 metafile->FinishDocument(); 175 metafile->FinishDocument();
175 return true; 176 return true;
176 } 177 }
177 178
178 void PrintWebViewHelper::PrintPageInternal( 179 void PrintWebViewHelper::PrintPageInternal(
179 const PrintMsg_PrintPage_Params& params, 180 const PrintMsg_PrintPage_Params& params,
180 const gfx::Size& canvas_size, 181 const gfx::Size& canvas_size,
181 WebFrame* frame, 182 WebFrame* frame,
182 printing::Metafile* metafile) { 183 printing::Metafile* metafile) {
183 printing::PageSizeMargins page_layout_in_points; 184 printing::PageSizeMargins page_layout_in_points;
184 GetPageSizeAndMarginsInPoints(frame, params.page_number, params.params, 185 double scale_factor = 1.0f;
185 &page_layout_in_points); 186 ComputePageLayoutInPoints(frame, params.page_number, params.params,
186 187 ignore_css_margins_, fit_to_page_, &scale_factor,
187 gfx::Size page_size( 188 &page_layout_in_points);
188 page_layout_in_points.content_width + 189 gfx::Size page_size;
189 page_layout_in_points.margin_right + 190 gfx::Rect content_area;
190 page_layout_in_points.margin_left, 191 GetPageSizeAndContentAreaFromPageLayout(page_layout_in_points, &page_size,
191 page_layout_in_points.content_height + 192 &content_area);
192 page_layout_in_points.margin_top +
193 page_layout_in_points.margin_bottom);
194 gfx::Rect content_area(page_layout_in_points.margin_left,
195 page_layout_in_points.margin_top,
196 page_layout_in_points.content_width,
197 page_layout_in_points.content_height);
198
199 SkDevice* device = metafile->StartPageForVectorCanvas( 193 SkDevice* device = metafile->StartPageForVectorCanvas(
200 page_size, content_area, 1.0f); 194 page_size, content_area, scale_factor);
201 if (!device) 195 if (!device)
202 return; 196 return;
203 197
204 // The printPage method take a reference to the canvas we pass down, so it 198 // The printPage method take a reference to the canvas we pass down, so it
205 // can't be a stack object. 199 // can't be a stack object.
206 SkRefPtr<skia::VectorCanvas> canvas = new skia::VectorCanvas(device); 200 SkRefPtr<skia::VectorCanvas> canvas = new skia::VectorCanvas(device);
207 canvas->unref(); // SkRefPtr and new both took a reference. 201 canvas->unref(); // SkRefPtr and new both took a reference.
208 printing::MetafileSkiaWrapper::SetMetafileOnCanvas(*canvas, metafile); 202 printing::MetafileSkiaWrapper::SetMetafileOnCanvas(*canvas, metafile);
209 skia::SetIsDraftMode(*canvas, is_print_ready_metafile_sent_); 203 skia::SetIsDraftMode(*canvas, is_print_ready_metafile_sent_);
210 frame->printPage(params.page_number, canvas.get()); 204 frame->printPage(params.page_number, canvas.get());
211 205
212 if (params.params.display_header_footer) { 206 if (params.params.display_header_footer) {
213 // |page_number| is 0-based, so 1 is added. 207 // |page_number| is 0-based, so 1 is added.
214 // The scale factor on Linux is 1. 208 // The scale factor on Linux is 1.
215 PrintHeaderAndFooter(canvas.get(), params.page_number + 1, 209 PrintHeaderAndFooter(canvas.get(), params.page_number + 1,
216 print_preview_context_.total_page_count(), 1, 210 print_preview_context_.total_page_count(),
217 page_layout_in_points, *header_footer_info_); 211 scale_factor, page_layout_in_points,
212 *header_footer_info_);
218 } 213 }
219 214
220 // Done printing. Close the device context to retrieve the compiled metafile. 215 // Done printing. Close the device context to retrieve the compiled metafile.
221 if (!metafile->FinishPage()) 216 if (!metafile->FinishPage())
222 NOTREACHED() << "metafile failed"; 217 NOTREACHED() << "metafile failed";
223 } 218 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698