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

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

Issue 11367033: "Using" cleanup. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 1 month 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
« no previous file with comments | « chrome/renderer/print_web_view_helper.h ('k') | chrome/renderer/print_web_view_helper_linux.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 <string> 7 #include <string>
8 8
9 #include "base/auto_reset.h" 9 #include "base/auto_reset.h"
10 #include "base/command_line.h" 10 #include "base/command_line.h"
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
53 53
54 #if defined(OS_WIN) || defined(OS_MACOSX) 54 #if defined(OS_WIN) || defined(OS_MACOSX)
55 #define USE_RENDER_TEXT 55 #define USE_RENDER_TEXT
56 #endif 56 #endif
57 57
58 #if defined(USE_RENDER_TEXT) 58 #if defined(USE_RENDER_TEXT)
59 #include "ui/gfx/canvas.h" 59 #include "ui/gfx/canvas.h"
60 #include "ui/gfx/render_text.h" 60 #include "ui/gfx/render_text.h"
61 #endif 61 #endif
62 62
63 using printing::ConvertPixelsToPoint;
64 using printing::ConvertPixelsToPointDouble;
65 using printing::ConvertPointsToPixelDouble;
66 using printing::ConvertUnit;
67 using printing::ConvertUnitDouble;
68 using printing::GetHeaderFooterSegmentWidth;
69 using printing::PageSizeMargins;
70 using WebKit::WebConsoleMessage;
71 using WebKit::WebDocument;
72 using WebKit::WebElement;
73 using WebKit::WebFrame;
74 using WebKit::WebNode;
75 using WebKit::WebPlugin;
76 using WebKit::WebPluginDocument;
77 using WebKit::WebPrintParams;
78 using WebKit::WebSize;
79 using WebKit::WebString;
80 using WebKit::WebURLRequest;
81 using WebKit::WebView;
82
83 namespace { 63 namespace {
84 64
85 #if defined(USE_RENDER_TEXT) 65 #if defined(USE_RENDER_TEXT)
86 typedef gfx::RenderText* HeaderFooterPaint; 66 typedef gfx::RenderText* HeaderFooterPaint;
87 #else 67 #else
88 typedef SkPaint HeaderFooterPaint; 68 typedef SkPaint HeaderFooterPaint;
89 #endif 69 #endif
90 70
91 const double kMinDpi = 1.0; 71 const double kMinDpi = 1.0;
92 72
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
134 oldParams.params.display_header_footer == 114 oldParams.params.display_header_footer ==
135 newParams.params.display_header_footer && 115 newParams.params.display_header_footer &&
136 oldParams.params.date == newParams.params.date && 116 oldParams.params.date == newParams.params.date &&
137 oldParams.params.title == newParams.params.title && 117 oldParams.params.title == newParams.params.title &&
138 oldParams.params.url == newParams.params.url && 118 oldParams.params.url == newParams.params.url &&
139 std::equal(oldParams.pages.begin(), oldParams.pages.end(), 119 std::equal(oldParams.pages.begin(), oldParams.pages.end(),
140 newParams.pages.begin()); 120 newParams.pages.begin());
141 } 121 }
142 122
143 PrintMsg_Print_Params GetCssPrintParams( 123 PrintMsg_Print_Params GetCssPrintParams(
144 WebFrame* frame, 124 WebKit::WebFrame* frame,
145 int page_index, 125 int page_index,
146 const PrintMsg_Print_Params& page_params) { 126 const PrintMsg_Print_Params& page_params) {
147 PrintMsg_Print_Params page_css_params = page_params; 127 PrintMsg_Print_Params page_css_params = page_params;
148 int dpi = GetDPI(&page_params); 128 int dpi = GetDPI(&page_params);
149 WebSize page_size_in_pixels( 129
150 ConvertUnit(page_params.page_size.width(), 130 using printing::ConvertUnit;
151 dpi, printing::kPixelsPerInch), 131 using printing::kPixelsPerInch;
152 ConvertUnit(page_params.page_size.height(), 132 WebKit::WebSize page_size_in_pixels(
153 dpi, printing::kPixelsPerInch)); 133 ConvertUnit(page_params.page_size.width(), dpi, kPixelsPerInch),
154 int margin_top_in_pixels = ConvertUnit( 134 ConvertUnit(page_params.page_size.height(), dpi, kPixelsPerInch));
155 page_params.margin_top, 135 int margin_top_in_pixels =
156 dpi, printing::kPixelsPerInch); 136 ConvertUnit(page_params.margin_top, dpi, kPixelsPerInch);
157 int margin_right_in_pixels = ConvertUnit( 137 int margin_right_in_pixels = ConvertUnit(
158 page_params.page_size.width() - 138 page_params.page_size.width() -
159 page_params.content_size.width() - page_params.margin_left, 139 page_params.content_size.width() - page_params.margin_left,
160 dpi, printing::kPixelsPerInch); 140 dpi, kPixelsPerInch);
161 int margin_bottom_in_pixels = ConvertUnit( 141 int margin_bottom_in_pixels = ConvertUnit(
162 page_params.page_size.height() - 142 page_params.page_size.height() -
163 page_params.content_size.height() - page_params.margin_top, 143 page_params.content_size.height() - page_params.margin_top,
164 dpi, printing::kPixelsPerInch); 144 dpi, kPixelsPerInch);
165 int margin_left_in_pixels = ConvertUnit( 145 int margin_left_in_pixels = ConvertUnit(
166 page_params.margin_left, 146 page_params.margin_left,
167 dpi, printing::kPixelsPerInch); 147 dpi, kPixelsPerInch);
168 148
169 WebSize original_page_size_in_pixels = page_size_in_pixels; 149 WebKit::WebSize original_page_size_in_pixels = page_size_in_pixels;
170 150
171 if (frame) { 151 if (frame) {
172 frame->pageSizeAndMarginsInPixels(page_index, 152 frame->pageSizeAndMarginsInPixels(page_index,
173 page_size_in_pixels, 153 page_size_in_pixels,
174 margin_top_in_pixels, 154 margin_top_in_pixels,
175 margin_right_in_pixels, 155 margin_right_in_pixels,
176 margin_bottom_in_pixels, 156 margin_bottom_in_pixels,
177 margin_left_in_pixels); 157 margin_left_in_pixels);
178 } 158 }
179 159
180 int new_content_width = page_size_in_pixels.width - 160 int new_content_width = page_size_in_pixels.width -
181 margin_left_in_pixels - margin_right_in_pixels; 161 margin_left_in_pixels - margin_right_in_pixels;
182 int new_content_height = page_size_in_pixels.height - 162 int new_content_height = page_size_in_pixels.height -
183 margin_top_in_pixels - margin_bottom_in_pixels; 163 margin_top_in_pixels - margin_bottom_in_pixels;
184 164
185 // Invalid page size and/or margins. We just use the default setting. 165 // Invalid page size and/or margins. We just use the default setting.
186 if (new_content_width < 1 || new_content_height < 1) { 166 if (new_content_width < 1 || new_content_height < 1) {
187 CHECK(frame != NULL); 167 CHECK(frame != NULL);
188 page_css_params = GetCssPrintParams(NULL, page_index, page_params); 168 page_css_params = GetCssPrintParams(NULL, page_index, page_params);
189 return page_css_params; 169 return page_css_params;
190 } 170 }
191 171
192 page_css_params.content_size = gfx::Size( 172 page_css_params.content_size = gfx::Size(
193 static_cast<int>(ConvertUnit(new_content_width, 173 ConvertUnit(new_content_width, kPixelsPerInch, dpi),
194 printing::kPixelsPerInch, dpi)), 174 ConvertUnit(new_content_height, kPixelsPerInch, dpi));
195 static_cast<int>(ConvertUnit(new_content_height,
196 printing::kPixelsPerInch, dpi)));
197 175
198 if (original_page_size_in_pixels != page_size_in_pixels) { 176 if (original_page_size_in_pixels != page_size_in_pixels) {
199 page_css_params.page_size = gfx::Size( 177 page_css_params.page_size = gfx::Size(
200 static_cast<int>(ConvertUnit(page_size_in_pixels.width, 178 ConvertUnit(page_size_in_pixels.width, kPixelsPerInch, dpi),
201 printing::kPixelsPerInch, dpi)), 179 ConvertUnit(page_size_in_pixels.height, kPixelsPerInch, dpi));
202 static_cast<int>(ConvertUnit(page_size_in_pixels.height,
203 printing::kPixelsPerInch, dpi)));
204 } else { 180 } else {
205 // Printing frame doesn't have any page size css. Pixels to dpi conversion 181 // Printing frame doesn't have any page size css. Pixels to dpi conversion
206 // causes rounding off errors. Therefore use the default page size values 182 // causes rounding off errors. Therefore use the default page size values
207 // directly. 183 // directly.
208 page_css_params.page_size = page_params.page_size; 184 page_css_params.page_size = page_params.page_size;
209 } 185 }
210 186
211 page_css_params.margin_top = 187 page_css_params.margin_top =
212 static_cast<int>(ConvertUnit(margin_top_in_pixels, 188 ConvertUnit(margin_top_in_pixels, kPixelsPerInch, dpi);
213 printing::kPixelsPerInch, dpi));
214
215 page_css_params.margin_left = 189 page_css_params.margin_left =
216 static_cast<int>(ConvertUnit(margin_left_in_pixels, 190 ConvertUnit(margin_left_in_pixels, kPixelsPerInch, dpi);
217 printing::kPixelsPerInch, dpi));
218 return page_css_params; 191 return page_css_params;
219 } 192 }
220 193
221 double FitPrintParamsToPage(const PrintMsg_Print_Params& page_params, 194 double FitPrintParamsToPage(const PrintMsg_Print_Params& page_params,
222 PrintMsg_Print_Params* params_to_fit) { 195 PrintMsg_Print_Params* params_to_fit) {
223 double content_width = 196 double content_width =
224 static_cast<double>(params_to_fit->content_size.width()); 197 static_cast<double>(params_to_fit->content_size.width());
225 double content_height = 198 double content_height =
226 static_cast<double>(params_to_fit->content_size.height()); 199 static_cast<double>(params_to_fit->content_size.height());
227 int default_page_size_height = page_params.page_size.height(); 200 int default_page_size_height = page_params.page_size.height();
(...skipping 22 matching lines...) Expand all
250 (default_page_size_width - css_page_size_width * scale_factor) / 2 + 223 (default_page_size_width - css_page_size_width * scale_factor) / 2 +
251 (params_to_fit->margin_left * scale_factor)); 224 (params_to_fit->margin_left * scale_factor));
252 params_to_fit->content_size = gfx::Size( 225 params_to_fit->content_size = gfx::Size(
253 static_cast<int>(content_width), static_cast<int>(content_height)); 226 static_cast<int>(content_width), static_cast<int>(content_height));
254 params_to_fit->page_size = page_params.page_size; 227 params_to_fit->page_size = page_params.page_size;
255 return scale_factor; 228 return scale_factor;
256 } 229 }
257 230
258 void CalculatePageLayoutFromPrintParams( 231 void CalculatePageLayoutFromPrintParams(
259 const PrintMsg_Print_Params& params, 232 const PrintMsg_Print_Params& params,
260 PageSizeMargins* page_layout_in_points) { 233 printing::PageSizeMargins* page_layout_in_points) {
261 int dpi = GetDPI(&params); 234 int dpi = GetDPI(&params);
262 int content_width = params.content_size.width(); 235 int content_width = params.content_size.width();
263 int content_height = params.content_size.height(); 236 int content_height = params.content_size.height();
264 237
265 int margin_bottom = params.page_size.height() - 238 int margin_bottom = params.page_size.height() -
266 content_height - params.margin_top; 239 content_height - params.margin_top;
267 int margin_right = params.page_size.width() - 240 int margin_right = params.page_size.width() -
268 content_width - params.margin_left; 241 content_width - params.margin_left;
269 242
270 page_layout_in_points->content_width = ConvertUnit( 243 using printing::ConvertUnit;
271 content_width, dpi, printing::kPointsPerInch); 244 using printing::kPointsPerInch;
272 page_layout_in_points->content_height = ConvertUnit( 245 page_layout_in_points->content_width =
273 content_height, dpi, printing::kPointsPerInch); 246 ConvertUnit(content_width, dpi, kPointsPerInch);
274 page_layout_in_points->margin_top = ConvertUnit( 247 page_layout_in_points->content_height =
275 params.margin_top, dpi, printing::kPointsPerInch); 248 ConvertUnit(content_height, dpi, kPointsPerInch);
276 page_layout_in_points->margin_right = ConvertUnit( 249 page_layout_in_points->margin_top =
277 margin_right, dpi, printing::kPointsPerInch); 250 ConvertUnit(params.margin_top, dpi, kPointsPerInch);
278 page_layout_in_points->margin_bottom = ConvertUnit( 251 page_layout_in_points->margin_right =
279 margin_bottom, dpi, printing::kPointsPerInch); 252 ConvertUnit(margin_right, dpi, kPointsPerInch);
280 page_layout_in_points->margin_left = ConvertUnit( 253 page_layout_in_points->margin_bottom =
281 params.margin_left, dpi, printing::kPointsPerInch); 254 ConvertUnit(margin_bottom, dpi, kPointsPerInch);
255 page_layout_in_points->margin_left =
256 ConvertUnit(params.margin_left, dpi, kPointsPerInch);
282 } 257 }
283 258
284 void EnsureOrientationMatches(const PrintMsg_Print_Params& css_params, 259 void EnsureOrientationMatches(const PrintMsg_Print_Params& css_params,
285 PrintMsg_Print_Params* page_params) { 260 PrintMsg_Print_Params* page_params) {
286 if ((page_params->page_size.width() > page_params->page_size.height()) == 261 if ((page_params->page_size.width() > page_params->page_size.height()) ==
287 (css_params.page_size.width() > css_params.page_size.height())) { 262 (css_params.page_size.width() > css_params.page_size.height())) {
288 return; 263 return;
289 } 264 }
290 265
291 // Swap the |width| and |height| values. 266 // Swap the |width| and |height| values.
292 page_params->page_size.SetSize(page_params->page_size.height(), 267 page_params->page_size.SetSize(page_params->page_size.height(),
293 page_params->page_size.width()); 268 page_params->page_size.width());
294 page_params->content_size.SetSize(page_params->content_size.height(), 269 page_params->content_size.SetSize(page_params->content_size.height(),
295 page_params->content_size.width()); 270 page_params->content_size.width());
296 page_params->printable_area.set_size( 271 page_params->printable_area.set_size(
297 gfx::Size(page_params->printable_area.height(), 272 gfx::Size(page_params->printable_area.height(),
298 page_params->printable_area.width())); 273 page_params->printable_area.width()));
299 } 274 }
300 275
301 void ComputeWebKitPrintParamsInDesiredDpi( 276 void ComputeWebKitPrintParamsInDesiredDpi(
302 const PrintMsg_Print_Params& print_params, 277 const PrintMsg_Print_Params& print_params,
303 WebPrintParams* webkit_print_params) { 278 WebKit::WebPrintParams* webkit_print_params) {
304 int dpi = GetDPI(&print_params); 279 int dpi = GetDPI(&print_params);
305 webkit_print_params->printerDPI = dpi; 280 webkit_print_params->printerDPI = dpi;
306 webkit_print_params->printScalingOption = print_params.print_scaling_option; 281 webkit_print_params->printScalingOption = print_params.print_scaling_option;
307 282
283 using printing::ConvertUnit;
308 webkit_print_params->printContentArea.width = 284 webkit_print_params->printContentArea.width =
309 ConvertUnit(print_params.content_size.width(), dpi, 285 ConvertUnit(print_params.content_size.width(), dpi,
310 print_params.desired_dpi); 286 print_params.desired_dpi);
311 webkit_print_params->printContentArea.height = 287 webkit_print_params->printContentArea.height =
312 ConvertUnit(print_params.content_size.height(), dpi, 288 ConvertUnit(print_params.content_size.height(), dpi,
313 print_params.desired_dpi); 289 print_params.desired_dpi);
314 290
315 webkit_print_params->printableArea.x = 291 webkit_print_params->printableArea.x =
316 ConvertUnit(print_params.printable_area.x(), dpi, 292 ConvertUnit(print_params.printable_area.x(), dpi,
317 print_params.desired_dpi); 293 print_params.desired_dpi);
318 webkit_print_params->printableArea.y = 294 webkit_print_params->printableArea.y =
319 ConvertUnit(print_params.printable_area.y(), dpi, 295 ConvertUnit(print_params.printable_area.y(), dpi,
320 print_params.desired_dpi); 296 print_params.desired_dpi);
321 webkit_print_params->printableArea.width = 297 webkit_print_params->printableArea.width =
322 ConvertUnit(print_params.printable_area.width(), dpi, 298 ConvertUnit(print_params.printable_area.width(), dpi,
323 print_params.desired_dpi); 299 print_params.desired_dpi);
324 webkit_print_params->printableArea.height = 300 webkit_print_params->printableArea.height =
325 ConvertUnit(print_params.printable_area.height(), 301 ConvertUnit(print_params.printable_area.height(),
326 dpi, print_params.desired_dpi); 302 dpi, print_params.desired_dpi);
327 303
328 webkit_print_params->paperSize.width = 304 webkit_print_params->paperSize.width =
329 ConvertUnit(print_params.page_size.width(), dpi, 305 ConvertUnit(print_params.page_size.width(), dpi,
330 print_params.desired_dpi); 306 print_params.desired_dpi);
331 webkit_print_params->paperSize.height = 307 webkit_print_params->paperSize.height =
332 ConvertUnit(print_params.page_size.height(), dpi, 308 ConvertUnit(print_params.page_size.height(), dpi,
333 print_params.desired_dpi); 309 print_params.desired_dpi);
334 } 310 }
335 311
336 bool PrintingNodeOrPdfFrame(const WebFrame* frame, const WebNode& node) { 312 bool PrintingNodeOrPdfFrame(const WebKit::WebFrame* frame,
313 const WebKit::WebNode& node) {
337 if (!node.isNull()) 314 if (!node.isNull())
338 return true; 315 return true;
339 if (!frame->document().isPluginDocument()) 316 if (!frame->document().isPluginDocument())
340 return false; 317 return false;
341 WebPlugin* plugin = frame->document().to<WebPluginDocument>().plugin(); 318 WebKit::WebPlugin* plugin =
319 frame->document().to<WebKit::WebPluginDocument>().plugin();
342 return plugin && plugin->supportsPaginatedPrint(); 320 return plugin && plugin->supportsPaginatedPrint();
343 } 321 }
344 322
345 bool PrintingFrameHasPageSizeStyle(WebFrame* frame, int total_page_count) { 323 bool PrintingFrameHasPageSizeStyle(WebKit::WebFrame* frame,
324 int total_page_count) {
346 if (!frame) 325 if (!frame)
347 return false; 326 return false;
348 bool frame_has_custom_page_size_style = false; 327 bool frame_has_custom_page_size_style = false;
349 for (int i = 0; i < total_page_count; ++i) { 328 for (int i = 0; i < total_page_count; ++i) {
350 if (frame->hasCustomPageSizeStyle(i)) { 329 if (frame->hasCustomPageSizeStyle(i)) {
351 frame_has_custom_page_size_style = true; 330 frame_has_custom_page_size_style = true;
352 break; 331 break;
353 } 332 }
354 } 333 }
355 return frame_has_custom_page_size_style; 334 return frame_has_custom_page_size_style;
356 } 335 }
357 336
358 printing::MarginType GetMarginsForPdf(WebFrame* frame, const WebNode& node) { 337 printing::MarginType GetMarginsForPdf(WebKit::WebFrame* frame,
338 const WebKit::WebNode& node) {
359 if (frame->isPrintScalingDisabledForPlugin(node)) 339 if (frame->isPrintScalingDisabledForPlugin(node))
360 return printing::NO_MARGINS; 340 return printing::NO_MARGINS;
361 else 341 else
362 return printing::PRINTABLE_AREA_MARGINS; 342 return printing::PRINTABLE_AREA_MARGINS;
363 } 343 }
364 344
365 bool FitToPageEnabled(const DictionaryValue& job_settings) { 345 bool FitToPageEnabled(const DictionaryValue& job_settings) {
366 bool fit_to_paper_size = false; 346 bool fit_to_paper_size = false;
367 if (!job_settings.GetBoolean(printing::kSettingFitToPageEnabled, 347 if (!job_settings.GetBoolean(printing::kSettingFitToPageEnabled,
368 &fit_to_paper_size)) { 348 &fit_to_paper_size)) {
369 NOTREACHED(); 349 NOTREACHED();
370 } 350 }
371 return fit_to_paper_size; 351 return fit_to_paper_size;
372 } 352 }
373 353
374 // Get the (x, y) coordinate from where printing of the current text should 354 // Get the (x, y) coordinate from where printing of the current text should
375 // start depending on the horizontal alignment (LEFT, RIGHT, CENTER) and 355 // start depending on the horizontal alignment (LEFT, RIGHT, CENTER) and
376 // vertical alignment (TOP, BOTTOM). 356 // vertical alignment (TOP, BOTTOM).
377 SkPoint GetHeaderFooterPosition( 357 SkPoint GetHeaderFooterPosition(
378 float webkit_scale_factor, 358 float webkit_scale_factor,
379 const PageSizeMargins& page_layout, 359 const printing::PageSizeMargins& page_layout,
380 printing::HorizontalHeaderFooterPosition horizontal_position, 360 printing::HorizontalHeaderFooterPosition horizontal_position,
381 printing::VerticalHeaderFooterPosition vertical_position, 361 printing::VerticalHeaderFooterPosition vertical_position,
382 double offset_to_baseline, 362 double offset_to_baseline,
383 double text_width_in_points) { 363 double text_width_in_points) {
384 SkScalar x = 0; 364 SkScalar x = 0;
385 switch (horizontal_position) { 365 switch (horizontal_position) {
386 case printing::LEFT: { 366 case printing::LEFT: {
387 x = printing::kSettingHeaderFooterInterstice - page_layout.margin_left; 367 x = printing::kSettingHeaderFooterInterstice - page_layout.margin_left;
388 break; 368 break;
389 } 369 }
390 case printing::RIGHT: { 370 case printing::RIGHT: {
391 x = page_layout.content_width + page_layout.margin_right - 371 x = page_layout.content_width + page_layout.margin_right -
392 printing::kSettingHeaderFooterInterstice - text_width_in_points; 372 printing::kSettingHeaderFooterInterstice - text_width_in_points;
393 break; 373 break;
394 } 374 }
395 case printing::CENTER: { 375 case printing::CENTER: {
396 SkScalar available_width = GetHeaderFooterSegmentWidth( 376 SkScalar available_width = printing::GetHeaderFooterSegmentWidth(
397 page_layout.margin_left + page_layout.margin_right + 377 page_layout.margin_left + page_layout.margin_right +
398 page_layout.content_width); 378 page_layout.content_width);
399 x = available_width - page_layout.margin_left + 379 x = available_width - page_layout.margin_left +
400 (available_width - text_width_in_points) / 2; 380 (available_width - text_width_in_points) / 2;
401 break; 381 break;
402 } 382 }
403 default: { 383 default: {
404 NOTREACHED(); 384 NOTREACHED();
405 } 385 }
406 } 386 }
(...skipping 17 matching lines...) Expand all
424 return point; 404 return point;
425 } 405 }
426 406
427 // Given a text, the positions, and the paint object, this method gets the 407 // Given a text, the positions, and the paint object, this method gets the
428 // coordinates and prints the text at those coordinates on the canvas. 408 // coordinates and prints the text at those coordinates on the canvas.
429 void PrintHeaderFooterText( 409 void PrintHeaderFooterText(
430 const string16& text, 410 const string16& text,
431 WebKit::WebCanvas* canvas, 411 WebKit::WebCanvas* canvas,
432 HeaderFooterPaint paint, 412 HeaderFooterPaint paint,
433 float webkit_scale_factor, 413 float webkit_scale_factor,
434 const PageSizeMargins& page_layout, 414 const printing::PageSizeMargins& page_layout,
435 printing::HorizontalHeaderFooterPosition horizontal_position, 415 printing::HorizontalHeaderFooterPosition horizontal_position,
436 printing::VerticalHeaderFooterPosition vertical_position, 416 printing::VerticalHeaderFooterPosition vertical_position,
437 double offset_to_baseline) { 417 double offset_to_baseline) {
438 #if defined(USE_RENDER_TEXT) 418 #if defined(USE_RENDER_TEXT)
439 paint->SetText(text); 419 paint->SetText(text);
440 paint->SetFontSize(printing::kSettingHeaderFooterFontSize); 420 paint->SetFontSize(printing::kSettingHeaderFooterFontSize);
441 double text_width_in_points = paint->GetStringSize().width(); 421 double text_width_in_points = paint->GetStringSize().width();
442 SkPoint point = GetHeaderFooterPosition(webkit_scale_factor, page_layout, 422 SkPoint point = GetHeaderFooterPosition(webkit_scale_factor, page_layout,
443 horizontal_position, 423 horizontal_position,
444 vertical_position, offset_to_baseline, 424 vertical_position, offset_to_baseline,
(...skipping 28 matching lines...) Expand all
473 vertical_position, offset_to_baseline, 453 vertical_position, offset_to_baseline,
474 text_width_in_points); 454 text_width_in_points);
475 paint.setTextSize(SkDoubleToScalar( 455 paint.setTextSize(SkDoubleToScalar(
476 paint.getTextSize() / webkit_scale_factor)); 456 paint.getTextSize() / webkit_scale_factor));
477 canvas->drawText(text.c_str(), text_byte_length, point.x(), point.y(), 457 canvas->drawText(text.c_str(), text_byte_length, point.x(), point.y(),
478 paint); 458 paint);
479 #endif 459 #endif
480 } 460 }
481 461
482 PrintMsg_Print_Params CalculatePrintParamsForCss( 462 PrintMsg_Print_Params CalculatePrintParamsForCss(
483 WebFrame* frame, 463 WebKit::WebFrame* frame,
484 int page_index, 464 int page_index,
485 const PrintMsg_Print_Params& page_params, 465 const PrintMsg_Print_Params& page_params,
486 bool ignore_css_margins, 466 bool ignore_css_margins,
487 bool fit_to_page, 467 bool fit_to_page,
488 double* scale_factor) { 468 double* scale_factor) {
489 PrintMsg_Print_Params css_params = GetCssPrintParams(frame, page_index, 469 PrintMsg_Print_Params css_params = GetCssPrintParams(frame, page_index,
490 page_params); 470 page_params);
491 471
492 PrintMsg_Print_Params params = page_params; 472 PrintMsg_Print_Params params = page_params;
493 EnsureOrientationMatches(css_params, &params); 473 EnsureOrientationMatches(css_params, &params);
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
533 } 513 }
534 514
535 } // namespace 515 } // namespace
536 516
537 // static - Not anonymous so that platform implementations can use it. 517 // static - Not anonymous so that platform implementations can use it.
538 void PrintWebViewHelper::PrintHeaderAndFooter( 518 void PrintWebViewHelper::PrintHeaderAndFooter(
539 WebKit::WebCanvas* canvas, 519 WebKit::WebCanvas* canvas,
540 int page_number, 520 int page_number,
541 int total_pages, 521 int total_pages,
542 float webkit_scale_factor, 522 float webkit_scale_factor,
543 const PageSizeMargins& page_layout, 523 const printing::PageSizeMargins& page_layout,
544 const DictionaryValue& header_footer_info) { 524 const DictionaryValue& header_footer_info,
525 const PrintMsg_Print_Params& params) {
545 skia::VectorPlatformDeviceSkia* device = 526 skia::VectorPlatformDeviceSkia* device =
546 static_cast<skia::VectorPlatformDeviceSkia*>(canvas->getTopDevice()); 527 static_cast<skia::VectorPlatformDeviceSkia*>(canvas->getTopDevice());
547 device->setDrawingArea(SkPDFDevice::kMargin_DrawingArea); 528 device->setDrawingArea(SkPDFDevice::kMargin_DrawingArea);
548 529
549 #if defined(USE_RENDER_TEXT) 530 #if defined(USE_RENDER_TEXT)
550 scoped_ptr<gfx::RenderText> render_text(gfx::RenderText::CreateInstance()); 531 scoped_ptr<gfx::RenderText> render_text(gfx::RenderText::CreateInstance());
551 // TODO(asvitkine): The below line is to workaround http://crbug.com/133548. 532 // TODO(asvitkine): The below line is to workaround http://crbug.com/133548.
552 // Remove it when the underlying Skia bug has been fixed. 533 // Remove it when the underlying Skia bug has been fixed.
553 render_text->set_clip_to_display_rect(false); 534 render_text->set_clip_to_display_rect(false);
554 gfx::FontList font_list( 535 gfx::FontList font_list(
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
601 page_layout, printing::CENTER, printing::TOP, 582 page_layout, printing::CENTER, printing::TOP,
602 header_vertical_bounds.top()); 583 header_vertical_bounds.top());
603 } 584 }
604 585
605 // Prints the footers onto the |canvas| if there is enough space to print 586 // Prints the footers onto the |canvas| if there is enough space to print
606 // them. 587 // them.
607 string16 page_of_total_pages = base::IntToString16(page_number) + 588 string16 page_of_total_pages = base::IntToString16(page_number) +
608 UTF8ToUTF16("/") + 589 UTF8ToUTF16("/") +
609 base::IntToString16(total_pages); 590 base::IntToString16(total_pages);
610 string16 url; 591 string16 url;
611 if (!header_footer_info.GetString(printing::kSettingHeaderFooterURL, 592 if (!header_footer_info.GetString(printing::kSettingHeaderFooterURL, &url)) {
612 &url)) {
613 NOTREACHED(); 593 NOTREACHED();
614 } 594 }
615 string16 footer_text = page_of_total_pages + url; 595 string16 footer_text = page_of_total_pages + url;
616 596
617 // Used for height calculations. Note that the width may be undefined. 597 // Used for height calculations. Note that the width may be undefined.
618 SkRect footer_vertical_bounds; 598 SkRect footer_vertical_bounds;
619 #if defined(USE_RENDER_TEXT) 599 #if defined(USE_RENDER_TEXT)
620 paint->SetFontList(font_list); 600 paint->SetFontList(font_list);
621 paint->SetText(footer_text); 601 paint->SetText(footer_text);
622 { 602 {
(...skipping 15 matching lines...) Expand all
638 PrintHeaderFooterText(url, canvas, paint, webkit_scale_factor, page_layout, 618 PrintHeaderFooterText(url, canvas, paint, webkit_scale_factor, page_layout,
639 printing::LEFT, printing::BOTTOM, 619 printing::LEFT, printing::BOTTOM,
640 footer_vertical_bounds.bottom()); 620 footer_vertical_bounds.bottom());
641 } 621 }
642 622
643 device->setDrawingArea(SkPDFDevice::kContent_DrawingArea); 623 device->setDrawingArea(SkPDFDevice::kContent_DrawingArea);
644 } 624 }
645 625
646 PrepareFrameAndViewForPrint::PrepareFrameAndViewForPrint( 626 PrepareFrameAndViewForPrint::PrepareFrameAndViewForPrint(
647 const PrintMsg_Print_Params& print_params, 627 const PrintMsg_Print_Params& print_params,
648 WebFrame* frame, 628 WebKit::WebFrame* frame,
649 const WebNode& node) 629 const WebKit::WebNode& node)
650 : frame_(frame), 630 : frame_(frame),
651 node_to_print_(node), 631 node_to_print_(node),
652 web_view_(frame->view()), 632 web_view_(frame->view()),
653 expected_pages_count_(0), 633 expected_pages_count_(0),
654 use_browser_overlays_(true), 634 use_browser_overlays_(true),
655 finished_(false) { 635 finished_(false) {
656 WebPrintParams webkit_print_params; 636 WebKit::WebPrintParams webkit_print_params;
657 ComputeWebKitPrintParamsInDesiredDpi(print_params, &webkit_print_params); 637 ComputeWebKitPrintParamsInDesiredDpi(print_params, &webkit_print_params);
658 638
659 if (WebFrame* web_frame = web_view_->mainFrame()) 639 if (WebKit::WebFrame* web_frame = web_view_->mainFrame())
660 prev_scroll_offset_ = web_frame->scrollOffset(); 640 prev_scroll_offset_ = web_frame->scrollOffset();
661 prev_view_size_ = web_view_->size(); 641 prev_view_size_ = web_view_->size();
662 642
663 StartPrinting(webkit_print_params); 643 StartPrinting(webkit_print_params);
664 } 644 }
665 645
666 PrepareFrameAndViewForPrint::~PrepareFrameAndViewForPrint() { 646 PrepareFrameAndViewForPrint::~PrepareFrameAndViewForPrint() {
667 FinishPrinting(); 647 FinishPrinting();
668 } 648 }
669 649
670 void PrepareFrameAndViewForPrint::UpdatePrintParams( 650 void PrepareFrameAndViewForPrint::UpdatePrintParams(
671 const PrintMsg_Print_Params& print_params) { 651 const PrintMsg_Print_Params& print_params) {
672 DCHECK(!finished_); 652 DCHECK(!finished_);
673 WebPrintParams webkit_print_params; 653 WebKit::WebPrintParams webkit_print_params;
674 ComputeWebKitPrintParamsInDesiredDpi(print_params, &webkit_print_params); 654 ComputeWebKitPrintParamsInDesiredDpi(print_params, &webkit_print_params);
675 655
676 if (webkit_print_params.printContentArea == 656 if (webkit_print_params.printContentArea ==
677 web_print_params_.printContentArea && 657 web_print_params_.printContentArea &&
678 webkit_print_params.printableArea == web_print_params_.printableArea && 658 webkit_print_params.printableArea == web_print_params_.printableArea &&
679 webkit_print_params.paperSize == web_print_params_.paperSize && 659 webkit_print_params.paperSize == web_print_params_.paperSize &&
680 webkit_print_params.printScalingOption == 660 webkit_print_params.printScalingOption ==
681 web_print_params_.printScalingOption) { 661 web_print_params_.printScalingOption) {
682 return; 662 return;
683 } 663 }
684 664
685 frame_->printEnd(); 665 frame_->printEnd();
686 StartPrinting(webkit_print_params); 666 StartPrinting(webkit_print_params);
687 } 667 }
688 668
669 gfx::Size PrepareFrameAndViewForPrint::GetPrintCanvasSize() const {
670 return gfx::Size(web_print_params_.printContentArea.width,
671 web_print_params_.printContentArea.height);
672 }
673
689 void PrepareFrameAndViewForPrint::StartPrinting( 674 void PrepareFrameAndViewForPrint::StartPrinting(
690 const WebPrintParams& webkit_print_params) { 675 const WebKit::WebPrintParams& webkit_print_params) {
691 web_print_params_ = webkit_print_params; 676 web_print_params_ = webkit_print_params;
692 677
693 // Layout page according to printer page size. Since WebKit shrinks the 678 // Layout page according to printer page size. Since WebKit shrinks the
694 // size of the page automatically (from 125% to 200%) we trick it to 679 // size of the page automatically (from 125% to 200%) we trick it to
695 // think the page is 125% larger so the size of the page is correct for 680 // think the page is 125% larger so the size of the page is correct for
696 // minimum (default) scaling. 681 // minimum (default) scaling.
697 // This is important for sites that try to fill the page. 682 // This is important for sites that try to fill the page.
698 gfx::Size print_layout_size(web_print_params_.printContentArea.width, 683 gfx::Size print_layout_size(web_print_params_.printContentArea.width,
699 web_print_params_.printContentArea.height); 684 web_print_params_.printContentArea.height);
700 print_layout_size.set_height(static_cast<int>( 685 print_layout_size.set_height(static_cast<int>(
701 static_cast<double>(print_layout_size.height()) * 1.25)); 686 static_cast<double>(print_layout_size.height()) * 1.25));
702 687
703 web_view_->resize(print_layout_size); 688 web_view_->resize(print_layout_size);
704 689
705 expected_pages_count_ = frame_->printBegin(web_print_params_, 690 expected_pages_count_ = frame_->printBegin(web_print_params_,
706 node_to_print_, 691 node_to_print_,
707 &use_browser_overlays_); 692 &use_browser_overlays_);
708 } 693 }
709 694
710 void PrepareFrameAndViewForPrint::FinishPrinting() { 695 void PrepareFrameAndViewForPrint::FinishPrinting() {
711 if (!finished_) { 696 if (!finished_) {
712 finished_ = true; 697 finished_ = true;
713 frame_->printEnd(); 698 frame_->printEnd();
714 web_view_->resize(prev_view_size_); 699 web_view_->resize(prev_view_size_);
715 if (WebFrame* web_frame = web_view_->mainFrame()) 700 if (WebKit::WebFrame* web_frame = web_view_->mainFrame())
716 web_frame->setScrollOffset(prev_scroll_offset_); 701 web_frame->setScrollOffset(prev_scroll_offset_);
717 } 702 }
718 } 703 }
719 704
720 PrintWebViewHelper::PrintWebViewHelper(content::RenderView* render_view) 705 PrintWebViewHelper::PrintWebViewHelper(content::RenderView* render_view)
721 : content::RenderViewObserver(render_view), 706 : content::RenderViewObserver(render_view),
722 content::RenderViewObserverTracker<PrintWebViewHelper>(render_view), 707 content::RenderViewObserverTracker<PrintWebViewHelper>(render_view),
723 print_web_view_(NULL), 708 print_web_view_(NULL),
724 is_preview_enabled_(IsPrintPreviewEnabled()), 709 is_preview_enabled_(IsPrintPreviewEnabled()),
725 is_scripted_print_throttling_disabled_(IsPrintThrottlingDisabled()), 710 is_scripted_print_throttling_disabled_(IsPrintThrottlingDisabled()),
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
760 } 745 }
761 746
762 if (!IsScriptInitiatedPrintAllowed(frame, user_initiated)) 747 if (!IsScriptInitiatedPrintAllowed(frame, user_initiated))
763 return; 748 return;
764 IncrementScriptedPrintCount(); 749 IncrementScriptedPrintCount();
765 750
766 if (is_preview_enabled_) { 751 if (is_preview_enabled_) {
767 print_preview_context_.InitWithFrame(frame); 752 print_preview_context_.InitWithFrame(frame);
768 RequestPrintPreview(PRINT_PREVIEW_SCRIPTED); 753 RequestPrintPreview(PRINT_PREVIEW_SCRIPTED);
769 } else { 754 } else {
770 Print(frame, WebNode()); 755 Print(frame, WebKit::WebNode());
771 } 756 }
772 } 757 }
773 758
774 bool PrintWebViewHelper::OnMessageReceived(const IPC::Message& message) { 759 bool PrintWebViewHelper::OnMessageReceived(const IPC::Message& message) {
775 bool handled = true; 760 bool handled = true;
776 IPC_BEGIN_MESSAGE_MAP(PrintWebViewHelper, message) 761 IPC_BEGIN_MESSAGE_MAP(PrintWebViewHelper, message)
777 IPC_MESSAGE_HANDLER(PrintMsg_PrintPages, OnPrintPages) 762 IPC_MESSAGE_HANDLER(PrintMsg_PrintPages, OnPrintPages)
778 IPC_MESSAGE_HANDLER(PrintMsg_PrintForSystemDialog, OnPrintForSystemDialog) 763 IPC_MESSAGE_HANDLER(PrintMsg_PrintForSystemDialog, OnPrintForSystemDialog)
779 IPC_MESSAGE_HANDLER(PrintMsg_InitiatePrintPreview, OnInitiatePrintPreview) 764 IPC_MESSAGE_HANDLER(PrintMsg_InitiatePrintPreview, OnInitiatePrintPreview)
780 IPC_MESSAGE_HANDLER(PrintMsg_PrintNodeUnderContextMenu, 765 IPC_MESSAGE_HANDLER(PrintMsg_PrintNodeUnderContextMenu,
(...skipping 12 matching lines...) Expand all
793 778
794 void PrintWebViewHelper::OnPrintForPrintPreview( 779 void PrintWebViewHelper::OnPrintForPrintPreview(
795 const DictionaryValue& job_settings) { 780 const DictionaryValue& job_settings) {
796 DCHECK(is_preview_enabled_); 781 DCHECK(is_preview_enabled_);
797 // If still not finished with earlier print request simply ignore. 782 // If still not finished with earlier print request simply ignore.
798 if (print_web_view_) 783 if (print_web_view_)
799 return; 784 return;
800 785
801 if (!render_view()->GetWebView()) 786 if (!render_view()->GetWebView())
802 return; 787 return;
803 WebFrame* main_frame = render_view()->GetWebView()->mainFrame(); 788 WebKit::WebFrame* main_frame = render_view()->GetWebView()->mainFrame();
804 if (!main_frame) 789 if (!main_frame)
805 return; 790 return;
806 791
807 WebDocument document = main_frame->document(); 792 WebKit::WebDocument document = main_frame->document();
808 // <object> with id="pdf-viewer" is created in 793 // <object> with id="pdf-viewer" is created in
809 // chrome/browser/resources/print_preview/print_preview.js 794 // chrome/browser/resources/print_preview/print_preview.js
810 WebElement pdf_element = document.getElementById("pdf-viewer"); 795 WebKit::WebElement pdf_element = document.getElementById("pdf-viewer");
811 if (pdf_element.isNull()) { 796 if (pdf_element.isNull()) {
812 NOTREACHED(); 797 NOTREACHED();
813 return; 798 return;
814 } 799 }
815 800
816 // Set |print_for_preview_| flag and autoreset it to back to original 801 // Set |print_for_preview_| flag and autoreset it to back to original
817 // on return. 802 // on return.
818 AutoReset<bool> set_printing_flag(&print_for_preview_, true); 803 AutoReset<bool> set_printing_flag(&print_for_preview_, true);
819 804
820 WebFrame* pdf_frame = pdf_element.document().frame(); 805 WebKit::WebFrame* pdf_frame = pdf_element.document().frame();
821 if (!UpdatePrintSettings(pdf_frame, pdf_element, job_settings)) { 806 if (!UpdatePrintSettings(pdf_frame, pdf_element, job_settings)) {
822 LOG(ERROR) << "UpdatePrintSettings failed"; 807 LOG(ERROR) << "UpdatePrintSettings failed";
823 DidFinishPrinting(FAIL_PRINT); 808 DidFinishPrinting(FAIL_PRINT);
824 return; 809 return;
825 } 810 }
826 811
827 // Print page onto entire page not just printable area. Preview PDF already 812 // Print page onto entire page not just printable area. Preview PDF already
828 // has content in correct position taking into account page size and printable 813 // has content in correct position taking into account page size and printable
829 // area. 814 // area.
830 // TODO(vitalybuka) : Make this consistent on all platform. This change 815 // TODO(vitalybuka) : Make this consistent on all platform. This change
(...skipping 20 matching lines...) Expand all
851 836
852 // If the user has selected text in the currently focused frame we print 837 // If the user has selected text in the currently focused frame we print
853 // only that frame (this makes print selection work for multiple frames). 838 // only that frame (this makes print selection work for multiple frames).
854 *frame = render_view()->GetWebView()->focusedFrame()->hasSelection() ? 839 *frame = render_view()->GetWebView()->focusedFrame()->hasSelection() ?
855 render_view()->GetWebView()->focusedFrame() : 840 render_view()->GetWebView()->focusedFrame() :
856 render_view()->GetWebView()->mainFrame(); 841 render_view()->GetWebView()->mainFrame();
857 return true; 842 return true;
858 } 843 }
859 844
860 void PrintWebViewHelper::OnPrintPages() { 845 void PrintWebViewHelper::OnPrintPages() {
861 WebFrame* frame; 846 WebKit::WebFrame* frame;
862 if (GetPrintFrame(&frame)) 847 if (GetPrintFrame(&frame))
863 Print(frame, WebNode()); 848 Print(frame, WebKit::WebNode());
864 } 849 }
865 850
866 void PrintWebViewHelper::OnPrintForSystemDialog() { 851 void PrintWebViewHelper::OnPrintForSystemDialog() {
867 WebFrame* frame = print_preview_context_.frame(); 852 WebKit::WebFrame* frame = print_preview_context_.frame();
868 if (!frame) { 853 if (!frame) {
869 NOTREACHED(); 854 NOTREACHED();
870 return; 855 return;
871 } 856 }
872 857
873 Print(frame, print_preview_context_.node()); 858 Print(frame, print_preview_context_.node());
874 } 859 }
875 860
876 void PrintWebViewHelper::GetPageSizeAndContentAreaFromPageLayout( 861 void PrintWebViewHelper::GetPageSizeAndContentAreaFromPageLayout(
877 const printing::PageSizeMargins& page_layout_in_points, 862 const printing::PageSizeMargins& page_layout_in_points,
(...skipping 10 matching lines...) Expand all
888 page_layout_in_points.margin_top, 873 page_layout_in_points.margin_top,
889 page_layout_in_points.content_width, 874 page_layout_in_points.content_width,
890 page_layout_in_points.content_height); 875 page_layout_in_points.content_height);
891 } 876 }
892 877
893 void PrintWebViewHelper::UpdateFrameMarginsCssInfo( 878 void PrintWebViewHelper::UpdateFrameMarginsCssInfo(
894 const DictionaryValue& settings) { 879 const DictionaryValue& settings) {
895 int margins_type = 0; 880 int margins_type = 0;
896 if (!settings.GetInteger(printing::kSettingMarginsType, &margins_type)) 881 if (!settings.GetInteger(printing::kSettingMarginsType, &margins_type))
897 margins_type = printing::DEFAULT_MARGINS; 882 margins_type = printing::DEFAULT_MARGINS;
898 ignore_css_margins_ = margins_type != printing::DEFAULT_MARGINS; 883 ignore_css_margins_ = (margins_type != printing::DEFAULT_MARGINS);
899 } 884 }
900 885
901 bool PrintWebViewHelper::IsPrintToPdfRequested( 886 bool PrintWebViewHelper::IsPrintToPdfRequested(
902 const DictionaryValue& job_settings) { 887 const DictionaryValue& job_settings) {
903 bool print_to_pdf = false; 888 bool print_to_pdf = false;
904 if (!job_settings.GetBoolean(printing::kSettingPrintToPDF, &print_to_pdf)) 889 if (!job_settings.GetBoolean(printing::kSettingPrintToPDF, &print_to_pdf))
905 NOTREACHED(); 890 NOTREACHED();
906 return print_to_pdf; 891 return print_to_pdf;
907 } 892 }
908 893
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
989 if (CreatePreviewDocument()) { 974 if (CreatePreviewDocument()) {
990 DidFinishPrinting(OK); 975 DidFinishPrinting(OK);
991 } else { 976 } else {
992 if (notify_browser_of_print_failure_) 977 if (notify_browser_of_print_failure_)
993 LOG(ERROR) << "CreatePreviewDocument failed"; 978 LOG(ERROR) << "CreatePreviewDocument failed";
994 DidFinishPrinting(FAIL_PREVIEW); 979 DidFinishPrinting(FAIL_PREVIEW);
995 } 980 }
996 } 981 }
997 982
998 bool PrintWebViewHelper::CreatePreviewDocument() { 983 bool PrintWebViewHelper::CreatePreviewDocument() {
999 PrintMsg_Print_Params print_params = print_pages_params_->params; 984 const PrintMsg_Print_Params& print_params = print_pages_params_->params;
1000 const std::vector<int>& pages = print_pages_params_->pages; 985 const std::vector<int>& pages = print_pages_params_->pages;
1001 if (!print_preview_context_.CreatePreviewDocument(&print_params, pages, 986 if (!print_preview_context_.CreatePreviewDocument(print_params, pages,
1002 ignore_css_margins_)) { 987 ignore_css_margins_)) {
1003 return false; 988 return false;
1004 } 989 }
1005 990
1006 PageSizeMargins default_page_layout; 991 printing::PageSizeMargins default_page_layout;
1007 ComputePageLayoutInPointsForCss(print_preview_context_.frame(), 0, 992 ComputePageLayoutInPointsForCss(print_preview_context_.frame(), 0,
1008 print_params, ignore_css_margins_, NULL, 993 print_params, ignore_css_margins_, NULL,
1009 &default_page_layout); 994 &default_page_layout);
1010 995
1011 if (!old_print_pages_params_.get() || 996 if (!old_print_pages_params_.get() ||
1012 !PageLayoutIsEqual(*old_print_pages_params_, *print_pages_params_)) { 997 !PageLayoutIsEqual(*old_print_pages_params_, *print_pages_params_)) {
1013 bool has_page_size_style = PrintingFrameHasPageSizeStyle( 998 bool has_page_size_style = PrintingFrameHasPageSizeStyle(
1014 print_preview_context_.frame(), 999 print_preview_context_.frame(),
1015 print_preview_context_.total_page_count()); 1000 print_preview_context_.total_page_count());
1016 int dpi = GetDPI(&print_params); 1001 int dpi = GetDPI(&print_params);
1002
1003 using printing::ConvertUnit;
1004 using printing::kPointsPerInch;
1017 gfx::Rect printable_area_in_points( 1005 gfx::Rect printable_area_in_points(
1018 ConvertUnit(print_pages_params_->params.printable_area.x(), 1006 ConvertUnit(print_params.printable_area.x(), dpi, kPointsPerInch),
1019 dpi, printing::kPointsPerInch), 1007 ConvertUnit(print_params.printable_area.y(), dpi, kPointsPerInch),
1020 ConvertUnit(print_pages_params_->params.printable_area.y(), 1008 ConvertUnit(print_params.printable_area.width(), dpi, kPointsPerInch),
1021 dpi, printing::kPointsPerInch), 1009 ConvertUnit(print_params.printable_area.height(), dpi, kPointsPerInch));
1022 ConvertUnit(print_pages_params_->params.printable_area.width(),
1023 dpi, printing::kPointsPerInch),
1024 ConvertUnit(print_pages_params_->params.printable_area.height(),
1025 dpi, printing::kPointsPerInch));
1026 1010
1027 // Margins: Send default page layout to browser process. 1011 // Margins: Send default page layout to browser process.
1028 Send(new PrintHostMsg_DidGetDefaultPageLayout(routing_id(), 1012 Send(new PrintHostMsg_DidGetDefaultPageLayout(routing_id(),
1029 default_page_layout, 1013 default_page_layout,
1030 printable_area_in_points, 1014 printable_area_in_points,
1031 has_page_size_style)); 1015 has_page_size_style));
1032 } 1016 }
1033 1017
1034 PrintHostMsg_DidGetPreviewPageCount_Params params; 1018 PrintHostMsg_DidGetPreviewPageCount_Params params;
1035 params.page_count = print_preview_context_.total_page_count(); 1019 params.page_count = print_preview_context_.total_page_count();
1036 params.is_modifiable = print_preview_context_.IsModifiable(); 1020 params.is_modifiable = print_preview_context_.IsModifiable();
1037 params.document_cookie = print_pages_params_->params.document_cookie; 1021 params.document_cookie = print_params.document_cookie;
1038 params.preview_request_id = print_pages_params_->params.preview_request_id; 1022 params.preview_request_id = print_params.preview_request_id;
1039 params.clear_preview_data = print_preview_context_.generate_draft_pages(); 1023 params.clear_preview_data = print_preview_context_.generate_draft_pages();
1040 Send(new PrintHostMsg_DidGetPreviewPageCount(routing_id(), params)); 1024 Send(new PrintHostMsg_DidGetPreviewPageCount(routing_id(), params));
1041 if (CheckForCancel()) 1025 if (CheckForCancel())
1042 return false; 1026 return false;
1043 1027
1044 while (!print_preview_context_.IsFinalPageRendered()) { 1028 while (!print_preview_context_.IsFinalPageRendered()) {
1045 int page_number = print_preview_context_.GetNextPageNumber(); 1029 int page_number = print_preview_context_.GetNextPageNumber();
1046 DCHECK_GE(page_number, 0); 1030 DCHECK_GE(page_number, 0);
1047 if (!RenderPreviewPage(page_number)) 1031 if (!RenderPreviewPage(page_number, print_params))
1048 return false; 1032 return false;
1049 1033
1050 if (CheckForCancel()) 1034 if (CheckForCancel())
1051 return false; 1035 return false;
1052 1036
1053 // We must call PrepareFrameAndViewForPrint::FinishPrinting() (by way of 1037 // We must call PrepareFrameAndViewForPrint::FinishPrinting() (by way of
1054 // print_preview_context_.AllPagesRendered()) before calling 1038 // print_preview_context_.AllPagesRendered()) before calling
1055 // FinalizePrintReadyDocument() when printing a PDF because the plugin 1039 // FinalizePrintReadyDocument() when printing a PDF because the plugin
1056 // code does not generate output until we call FinishPrinting(). We do not 1040 // code does not generate output until we call FinishPrinting(). We do not
1057 // generate draft pages for PDFs, so IsFinalPageRendered() and 1041 // generate draft pages for PDFs, so IsFinalPageRendered() and
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
1108 if (!success) 1092 if (!success)
1109 LOG(ERROR) << "Failure in OnPrintingDone"; 1093 LOG(ERROR) << "Failure in OnPrintingDone";
1110 DidFinishPrinting(success ? OK : FAIL_PRINT); 1094 DidFinishPrinting(success ? OK : FAIL_PRINT);
1111 } 1095 }
1112 1096
1113 void PrintWebViewHelper::SetScriptedPrintBlocked(bool blocked) { 1097 void PrintWebViewHelper::SetScriptedPrintBlocked(bool blocked) {
1114 is_scripted_printing_blocked_ = blocked; 1098 is_scripted_printing_blocked_ = blocked;
1115 } 1099 }
1116 1100
1117 void PrintWebViewHelper::OnPrintNodeUnderContextMenu() { 1101 void PrintWebViewHelper::OnPrintNodeUnderContextMenu() {
1118 const WebNode& context_menu_node = render_view()->GetContextMenuNode(); 1102 PrintNode(render_view()->GetContextMenuNode());
1119 PrintNode(context_menu_node);
1120 } 1103 }
1121 1104
1122 void PrintWebViewHelper::OnInitiatePrintPreview() { 1105 void PrintWebViewHelper::OnInitiatePrintPreview() {
1123 DCHECK(is_preview_enabled_); 1106 DCHECK(is_preview_enabled_);
1124 WebFrame* frame; 1107 WebKit::WebFrame* frame;
1125 if (GetPrintFrame(&frame)) { 1108 if (GetPrintFrame(&frame)) {
1126 print_preview_context_.InitWithFrame(frame); 1109 print_preview_context_.InitWithFrame(frame);
1127 RequestPrintPreview(PRINT_PREVIEW_USER_INITIATED_ENTIRE_FRAME); 1110 RequestPrintPreview(PRINT_PREVIEW_USER_INITIATED_ENTIRE_FRAME);
1128 } else { 1111 } else {
1129 // This should not happen. Let's add a CHECK here to see how often this 1112 // This should not happen. Let's add a CHECK here to see how often this
1130 // gets hit. 1113 // gets hit.
1131 // TODO(thestig) Remove this later when we have sufficient usage of this 1114 // TODO(thestig) Remove this later when we have sufficient usage of this
1132 // code on the M19 stable channel. 1115 // code on the M19 stable channel.
1133 CHECK(false); 1116 CHECK(false);
1134 } 1117 }
1135 } 1118 }
1136 1119
1137 void PrintWebViewHelper::PrintNode(const WebNode& node) { 1120 void PrintWebViewHelper::PrintNode(const WebKit::WebNode& node) {
1138 if (node.isNull() || !node.document().frame()) { 1121 if (node.isNull() || !node.document().frame()) {
1139 // This can occur when the context menu refers to an invalid WebNode. 1122 // This can occur when the context menu refers to an invalid WebNode.
1140 // See http://crbug.com/100890#c17 for a repro case. 1123 // See http://crbug.com/100890#c17 for a repro case.
1141 return; 1124 return;
1142 } 1125 }
1143 1126
1144 // Make a copy of the node, in case RenderView::OnContextMenuClosed resets 1127 // Make a copy of the node, in case RenderView::OnContextMenuClosed resets
1145 // its |context_menu_node_|. 1128 // its |context_menu_node_|.
1146 if (is_preview_enabled_) { 1129 if (is_preview_enabled_) {
1147 print_preview_context_.InitWithNode(node); 1130 print_preview_context_.InitWithNode(node);
1148 RequestPrintPreview(PRINT_PREVIEW_USER_INITIATED_CONTEXT_NODE); 1131 RequestPrintPreview(PRINT_PREVIEW_USER_INITIATED_CONTEXT_NODE);
1149 } else { 1132 } else {
1150 WebNode duplicate_node(node); 1133 WebKit::WebNode duplicate_node(node);
1151 Print(duplicate_node.document().frame(), duplicate_node); 1134 Print(duplicate_node.document().frame(), duplicate_node);
1152 } 1135 }
1153 } 1136 }
1154 1137
1155 void PrintWebViewHelper::Print(WebKit::WebFrame* frame, 1138 void PrintWebViewHelper::Print(WebKit::WebFrame* frame,
1156 const WebKit::WebNode& node) { 1139 const WebKit::WebNode& node) {
1157 // If still not finished with earlier print request simply ignore. 1140 // If still not finished with earlier print request simply ignore.
1158 if (print_web_view_) 1141 if (print_web_view_)
1159 return; 1142 return;
1160 1143
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
1243 } 1226 }
1244 1227
1245 bool PrintWebViewHelper::CopyAndPrint(WebKit::WebFrame* web_frame) { 1228 bool PrintWebViewHelper::CopyAndPrint(WebKit::WebFrame* web_frame) {
1246 // Create a new WebView with the same settings as the current display one. 1229 // Create a new WebView with the same settings as the current display one.
1247 // Except that we disable javascript (don't want any active content running 1230 // Except that we disable javascript (don't want any active content running
1248 // on the page). 1231 // on the page).
1249 webkit_glue::WebPreferences prefs = render_view()->GetWebkitPreferences(); 1232 webkit_glue::WebPreferences prefs = render_view()->GetWebkitPreferences();
1250 prefs.javascript_enabled = false; 1233 prefs.javascript_enabled = false;
1251 prefs.java_enabled = false; 1234 prefs.java_enabled = false;
1252 1235
1253 print_web_view_ = WebView::create(this); 1236 print_web_view_ = WebKit::WebView::create(this);
1254 prefs.Apply(print_web_view_); 1237 prefs.Apply(print_web_view_);
1255 print_web_view_->initializeMainFrame(this); 1238 print_web_view_->initializeMainFrame(this);
1256 1239
1257 print_pages_params_->pages.clear(); // Print all pages of selection. 1240 print_pages_params_->pages.clear(); // Print all pages of selection.
1258 1241
1259 std::string html = web_frame->selectionAsMarkup().utf8(); 1242 std::string html = web_frame->selectionAsMarkup().utf8();
1260 std::string url_str = "data:text/html;charset=utf-8,"; 1243 std::string url_str = "data:text/html;charset=utf-8,";
1261 url_str.append(html); 1244 url_str.append(html);
1262 GURL url(url_str); 1245 GURL url(url_str);
1263 1246
1264 // When loading is done this will call didStopLoading() and that will do the 1247 // When loading is done this will call didStopLoading() and that will do the
1265 // actual printing. 1248 // actual printing.
1266 print_web_view_->mainFrame()->loadRequest(WebURLRequest(url)); 1249 print_web_view_->mainFrame()->loadRequest(WebKit::WebURLRequest(url));
1267 1250
1268 return true; 1251 return true;
1269 } 1252 }
1270 1253
1271 #if defined(OS_MACOSX) || defined(OS_WIN) 1254 #if defined(OS_MACOSX) || defined(OS_WIN)
1272 bool PrintWebViewHelper::PrintPages(WebFrame* frame, const WebNode& node) { 1255 bool PrintWebViewHelper::PrintPages(WebKit::WebFrame* frame,
1256 const WebKit::WebNode& node) {
1273 const PrintMsg_PrintPages_Params& params = *print_pages_params_; 1257 const PrintMsg_PrintPages_Params& params = *print_pages_params_;
1274 const PrintMsg_Print_Params& print_params = params.params; 1258 const PrintMsg_Print_Params& print_params = params.params;
1275 PrepareFrameAndViewForPrint prep_frame_view(print_params, frame, node); 1259 PrepareFrameAndViewForPrint prep_frame_view(print_params, frame, node);
1276 UpdateFrameAndViewFromCssPageLayout(frame, node, &prep_frame_view, 1260 UpdateFrameAndViewFromCssPageLayout(frame, node, &prep_frame_view,
1277 print_params, ignore_css_margins_); 1261 print_params, ignore_css_margins_);
1278 1262
1279 int page_count = prep_frame_view.GetExpectedPageCount(); 1263 int page_count = prep_frame_view.GetExpectedPageCount();
1280 if (!page_count) 1264 if (!page_count)
1281 return false; 1265 return false;
1282 Send(new PrintHostMsg_DidGetPrintedPagesCount(routing_id(), 1266 Send(new PrintHostMsg_DidGetPrintedPagesCount(routing_id(),
(...skipping 14 matching lines...) Expand all
1297 break; 1281 break;
1298 page_params.page_number = params.pages[i]; 1282 page_params.page_number = params.pages[i];
1299 PrintPageInternal(page_params, canvas_size, frame); 1283 PrintPageInternal(page_params, canvas_size, frame);
1300 } 1284 }
1301 } 1285 }
1302 return true; 1286 return true;
1303 } 1287 }
1304 #endif // OS_MACOSX || OS_WIN 1288 #endif // OS_MACOSX || OS_WIN
1305 1289
1306 void PrintWebViewHelper::didStopLoading() { 1290 void PrintWebViewHelper::didStopLoading() {
1307 PrintPages(print_web_view_->mainFrame(), WebNode()); 1291 PrintPages(print_web_view_->mainFrame(), WebKit::WebNode());
1308 } 1292 }
1309 1293
1310 // static - Not anonymous so that platform implementations can use it. 1294 // static - Not anonymous so that platform implementations can use it.
1311 void PrintWebViewHelper::ComputePageLayoutInPointsForCss( 1295 void PrintWebViewHelper::ComputePageLayoutInPointsForCss(
1312 WebFrame* frame, 1296 WebKit::WebFrame* frame,
1313 int page_index, 1297 int page_index,
1314 const PrintMsg_Print_Params& page_params, 1298 const PrintMsg_Print_Params& page_params,
1315 bool ignore_css_margins, 1299 bool ignore_css_margins,
1316 double* scale_factor, 1300 double* scale_factor,
1317 PageSizeMargins* page_layout_in_points) { 1301 printing::PageSizeMargins* page_layout_in_points) {
1318 PrintMsg_Print_Params params = CalculatePrintParamsForCss( 1302 PrintMsg_Print_Params params = CalculatePrintParamsForCss(
1319 frame, page_index, page_params, ignore_css_margins, 1303 frame, page_index, page_params, ignore_css_margins,
1320 page_params.print_scaling_option == 1304 page_params.print_scaling_option ==
1321 WebKit::WebPrintScalingOptionFitToPrintableArea, 1305 WebKit::WebPrintScalingOptionFitToPrintableArea,
1322 scale_factor); 1306 scale_factor);
1323 CalculatePageLayoutFromPrintParams(params, page_layout_in_points); 1307 CalculatePageLayoutFromPrintParams(params, page_layout_in_points);
1324 } 1308 }
1325 1309
1326 // static - Not anonymous so that platform implementations can use it. 1310 // static - Not anonymous so that platform implementations can use it.
1327 void PrintWebViewHelper::UpdateFrameAndViewFromCssPageLayout( 1311 void PrintWebViewHelper::UpdateFrameAndViewFromCssPageLayout(
1328 WebFrame* frame, 1312 WebKit::WebFrame* frame,
1329 const WebNode& node, 1313 const WebKit::WebNode& node,
1330 PrepareFrameAndViewForPrint* prepare, 1314 PrepareFrameAndViewForPrint* prepare,
1331 const PrintMsg_Print_Params& params, 1315 const PrintMsg_Print_Params& params,
1332 bool ignore_css_margins) { 1316 bool ignore_css_margins) {
1333 if (PrintingNodeOrPdfFrame(frame, node)) 1317 if (PrintingNodeOrPdfFrame(frame, node))
1334 return; 1318 return;
1335 bool fit_to_page = ignore_css_margins && 1319 bool fit_to_page = ignore_css_margins &&
1336 params.print_scaling_option == 1320 params.print_scaling_option ==
1337 WebKit::WebPrintScalingOptionFitToPrintableArea; 1321 WebKit::WebPrintScalingOptionFitToPrintableArea;
1338 PrintMsg_Print_Params print_params = CalculatePrintParamsForCss( 1322 PrintMsg_Print_Params print_params = CalculatePrintParamsForCss(
1339 frame, 0, params, ignore_css_margins, fit_to_page, NULL); 1323 frame, 0, params, ignore_css_margins, fit_to_page, NULL);
(...skipping 27 matching lines...) Expand all
1367 if (fit_to_paper_size) { 1351 if (fit_to_paper_size) {
1368 settings.params.print_scaling_option = 1352 settings.params.print_scaling_option =
1369 WebKit::WebPrintScalingOptionFitToPrintableArea; 1353 WebKit::WebPrintScalingOptionFitToPrintableArea;
1370 } 1354 }
1371 1355
1372 print_pages_params_.reset(new PrintMsg_PrintPages_Params(settings)); 1356 print_pages_params_.reset(new PrintMsg_PrintPages_Params(settings));
1373 return result; 1357 return result;
1374 } 1358 }
1375 1359
1376 bool PrintWebViewHelper::InitPrintSettingsAndPrepareFrame( 1360 bool PrintWebViewHelper::InitPrintSettingsAndPrepareFrame(
1377 WebKit::WebFrame* frame, const WebKit::WebNode& node, 1361 WebKit::WebFrame* frame,
1362 const WebKit::WebNode& node,
1378 scoped_ptr<PrepareFrameAndViewForPrint>* prepare) { 1363 scoped_ptr<PrepareFrameAndViewForPrint>* prepare) {
1379 DCHECK(frame); 1364 DCHECK(frame);
1380 1365
1381 bool fit_to_paper_size = !(PrintingNodeOrPdfFrame(frame, node)); 1366 bool fit_to_paper_size = !(PrintingNodeOrPdfFrame(frame, node));
1382 if (!InitPrintSettings(fit_to_paper_size)) { 1367 if (!InitPrintSettings(fit_to_paper_size)) {
1383 notify_browser_of_print_failure_ = false; 1368 notify_browser_of_print_failure_ = false;
1384 render_view()->RunModalAlertDialog( 1369 render_view()->RunModalAlertDialog(
1385 frame, 1370 frame,
1386 l10n_util::GetStringUTF16(IDS_PRINT_PREVIEW_INVALID_PRINTER_SETTINGS)); 1371 l10n_util::GetStringUTF16(IDS_PRINT_PREVIEW_INVALID_PRINTER_SETTINGS));
1387 return false; 1372 return false;
1388 } 1373 }
1389 1374
1390 DCHECK(!prepare->get()); 1375 DCHECK(!prepare->get());
1391 prepare->reset(new PrepareFrameAndViewForPrint(print_pages_params_->params, 1376 prepare->reset(new PrepareFrameAndViewForPrint(print_pages_params_->params,
1392 frame, node)); 1377 frame, node));
1393 UpdateFrameAndViewFromCssPageLayout(frame, node, prepare->get(), 1378 UpdateFrameAndViewFromCssPageLayout(frame, node, prepare->get(),
1394 print_pages_params_->params, 1379 print_pages_params_->params,
1395 ignore_css_margins_); 1380 ignore_css_margins_);
1396 Send(new PrintHostMsg_DidGetDocumentCookie( 1381 Send(new PrintHostMsg_DidGetDocumentCookie(
1397 routing_id(), print_pages_params_->params.document_cookie)); 1382 routing_id(), print_pages_params_->params.document_cookie));
1398 return true; 1383 return true;
1399 } 1384 }
1400 1385
1401 bool PrintWebViewHelper::UpdatePrintSettings( 1386 bool PrintWebViewHelper::UpdatePrintSettings(
1402 WebKit::WebFrame* frame, const WebKit::WebNode& node, 1387 WebKit::WebFrame* frame,
1388 const WebKit::WebNode& node,
1403 const DictionaryValue& passed_job_settings) { 1389 const DictionaryValue& passed_job_settings) {
1404 DCHECK(is_preview_enabled_); 1390 DCHECK(is_preview_enabled_);
1405 const DictionaryValue* job_settings = &passed_job_settings; 1391 const DictionaryValue* job_settings = &passed_job_settings;
1406 DictionaryValue modified_job_settings; 1392 DictionaryValue modified_job_settings;
1407 if (job_settings->empty()) { 1393 if (job_settings->empty()) {
1408 if (!print_for_preview_) 1394 if (!print_for_preview_)
1409 print_preview_context_.set_error(PREVIEW_ERROR_BAD_SETTING); 1395 print_preview_context_.set_error(PREVIEW_ERROR_BAD_SETTING);
1410 return false; 1396 return false;
1411 } 1397 }
1412 1398
(...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after
1582 kMaxSecondsToIgnoreJavascriptInitiatedPrint); 1568 kMaxSecondsToIgnoreJavascriptInitiatedPrint);
1583 } 1569 }
1584 if (diff.InSeconds() < min_wait_seconds) { 1570 if (diff.InSeconds() < min_wait_seconds) {
1585 too_frequent = true; 1571 too_frequent = true;
1586 } 1572 }
1587 } 1573 }
1588 1574
1589 if (!too_frequent) 1575 if (!too_frequent)
1590 return false; 1576 return false;
1591 1577
1592 WebString message(WebString::fromUTF8( 1578 WebKit::WebString message(
1593 "Ignoring too frequent calls to print().")); 1579 WebKit::WebString::fromUTF8("Ignoring too frequent calls to print()."));
1594 frame->addMessageToConsole(WebConsoleMessage(WebConsoleMessage::LevelWarning, 1580 frame->addMessageToConsole(
1595 message)); 1581 WebKit::WebConsoleMessage(
1582 WebKit::WebConsoleMessage::LevelWarning, message));
1596 return true; 1583 return true;
1597 } 1584 }
1598 1585
1599 void PrintWebViewHelper::ResetScriptedPrintCount() { 1586 void PrintWebViewHelper::ResetScriptedPrintCount() {
1600 // Reset cancel counter on successful print. 1587 // Reset cancel counter on successful print.
1601 user_cancelled_scripted_print_count_ = 0; 1588 user_cancelled_scripted_print_count_ = 0;
1602 } 1589 }
1603 1590
1604 void PrintWebViewHelper::IncrementScriptedPrintCount() { 1591 void PrintWebViewHelper::IncrementScriptedPrintCount() {
1605 ++user_cancelled_scripted_print_count_; 1592 ++user_cancelled_scripted_print_count_;
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after
1716 frame_ = web_node.document().frame(); 1703 frame_ = web_node.document().frame();
1717 node_ = web_node; 1704 node_ = web_node;
1718 } 1705 }
1719 1706
1720 void PrintWebViewHelper::PrintPreviewContext::OnPrintPreview() { 1707 void PrintWebViewHelper::PrintPreviewContext::OnPrintPreview() {
1721 DCHECK_EQ(INITIALIZED, state_); 1708 DCHECK_EQ(INITIALIZED, state_);
1722 ClearContext(); 1709 ClearContext();
1723 } 1710 }
1724 1711
1725 bool PrintWebViewHelper::PrintPreviewContext::CreatePreviewDocument( 1712 bool PrintWebViewHelper::PrintPreviewContext::CreatePreviewDocument(
1726 PrintMsg_Print_Params* print_params, 1713 const PrintMsg_Print_Params& print_params,
1727 const std::vector<int>& pages, 1714 const std::vector<int>& pages,
1728 bool ignore_css_margins) { 1715 bool ignore_css_margins) {
1729 DCHECK_EQ(INITIALIZED, state_); 1716 DCHECK_EQ(INITIALIZED, state_);
1730 state_ = RENDERING; 1717 state_ = RENDERING;
1731 1718
1732 metafile_.reset(new printing::PreviewMetafile); 1719 metafile_.reset(new printing::PreviewMetafile);
1733 if (!metafile_->Init()) { 1720 if (!metafile_->Init()) {
1734 set_error(PREVIEW_ERROR_METAFILE_INIT_FAILED); 1721 set_error(PREVIEW_ERROR_METAFILE_INIT_FAILED);
1735 LOG(ERROR) << "PreviewMetafile Init failed"; 1722 LOG(ERROR) << "PreviewMetafile Init failed";
1736 return false; 1723 return false;
1737 } 1724 }
1738 1725
1739 // Need to make sure old object gets destroyed first. 1726 // Need to make sure old object gets destroyed first.
1740 prep_frame_view_.reset(new PrepareFrameAndViewForPrint(*print_params, frame(), 1727 prep_frame_view_.reset(new PrepareFrameAndViewForPrint(print_params, frame(),
1741 node())); 1728 node()));
1742 UpdateFrameAndViewFromCssPageLayout(frame_, node_, prep_frame_view_.get(), 1729 UpdateFrameAndViewFromCssPageLayout(frame_, node_, prep_frame_view_.get(),
1743 *print_params, ignore_css_margins); 1730 print_params, ignore_css_margins);
1744
1745 print_params_.reset(new PrintMsg_Print_Params(*print_params));
1746 1731
1747 total_page_count_ = prep_frame_view_->GetExpectedPageCount(); 1732 total_page_count_ = prep_frame_view_->GetExpectedPageCount();
1748 if (total_page_count_ == 0) { 1733 if (total_page_count_ == 0) {
1749 LOG(ERROR) << "CreatePreviewDocument got 0 page count"; 1734 LOG(ERROR) << "CreatePreviewDocument got 0 page count";
1750 set_error(PREVIEW_ERROR_ZERO_PAGES); 1735 set_error(PREVIEW_ERROR_ZERO_PAGES);
1751 return false; 1736 return false;
1752 } 1737 }
1753 1738
1754 int selected_page_count = pages.size(); 1739 int selected_page_count = pages.size();
1755 current_page_index_ = 0; 1740 current_page_index_ = 0;
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after
1886 1871
1887 bool PrintWebViewHelper::PrintPreviewContext::generate_draft_pages() const { 1872 bool PrintWebViewHelper::PrintPreviewContext::generate_draft_pages() const {
1888 return generate_draft_pages_; 1873 return generate_draft_pages_;
1889 } 1874 }
1890 1875
1891 printing::PreviewMetafile* PrintWebViewHelper::PrintPreviewContext::metafile() { 1876 printing::PreviewMetafile* PrintWebViewHelper::PrintPreviewContext::metafile() {
1892 DCHECK(IsRendering()); 1877 DCHECK(IsRendering());
1893 return metafile_.get(); 1878 return metafile_.get();
1894 } 1879 }
1895 1880
1896 const PrintMsg_Print_Params&
1897 PrintWebViewHelper::PrintPreviewContext::print_params() const {
1898 DCHECK(state_ != UNINITIALIZED);
1899 return *print_params_;
1900 }
1901
1902 int PrintWebViewHelper::PrintPreviewContext::last_error() const { 1881 int PrintWebViewHelper::PrintPreviewContext::last_error() const {
1903 return error_; 1882 return error_;
1904 } 1883 }
1905 1884
1906 gfx::Size PrintWebViewHelper::PrintPreviewContext::GetPrintCanvasSize() const { 1885 gfx::Size PrintWebViewHelper::PrintPreviewContext::GetPrintCanvasSize() const {
1907 DCHECK(IsRendering()); 1886 DCHECK(IsRendering());
1908 return prep_frame_view_->GetPrintCanvasSize(); 1887 return prep_frame_view_->GetPrintCanvasSize();
1909 } 1888 }
1910 1889
1911 void PrintWebViewHelper::PrintPreviewContext::ClearContext() { 1890 void PrintWebViewHelper::PrintPreviewContext::ClearContext() {
1912 prep_frame_view_.reset(); 1891 prep_frame_view_.reset();
1913 metafile_.reset(); 1892 metafile_.reset();
1914 pages_to_render_.clear(); 1893 pages_to_render_.clear();
1915 error_ = PREVIEW_ERROR_NONE; 1894 error_ = PREVIEW_ERROR_NONE;
1916 } 1895 }
OLDNEW
« no previous file with comments | « chrome/renderer/print_web_view_helper.h ('k') | chrome/renderer/print_web_view_helper_linux.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698