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

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

Issue 6165004: Refactor UpdatePrintableSizeInPrintParameters() function in print_web_view_helper.cc (Closed) Base URL: http://git.chromium.org/git/chromium.git@trunk
Patch Set: Made code changes as per comments. Created 9 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
« no previous file with comments | « no previous file | no next file » | 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) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 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 "app/l10n_util.h" 7 #include "app/l10n_util.h"
8 #include "base/logging.h" 8 #include "base/logging.h"
9 #include "base/process_util.h" 9 #include "base/process_util.h"
10 #include "base/utf_string_conversions.h" 10 #include "base/utf_string_conversions.h"
(...skipping 349 matching lines...) Expand 10 before | Expand all | Expand 10 after
360 double content_height_in_points; 360 double content_height_in_points;
361 double margin_top_in_points; 361 double margin_top_in_points;
362 double margin_right_in_points; 362 double margin_right_in_points;
363 double margin_bottom_in_points; 363 double margin_bottom_in_points;
364 double margin_left_in_points; 364 double margin_left_in_points;
365 PrepareFrameAndViewForPrint prepare(*params, frame, frame->view()); 365 PrepareFrameAndViewForPrint prepare(*params, frame, frame->view());
366 PrintWebViewHelper::GetPageSizeAndMarginsInPoints(frame, 0, *params, 366 PrintWebViewHelper::GetPageSizeAndMarginsInPoints(frame, 0, *params,
367 &content_width_in_points, &content_height_in_points, 367 &content_width_in_points, &content_height_in_points,
368 &margin_top_in_points, &margin_right_in_points, 368 &margin_top_in_points, &margin_right_in_points,
369 &margin_bottom_in_points, &margin_left_in_points); 369 &margin_bottom_in_points, &margin_left_in_points);
370 #if defined(OS_MACOSX)
371 // On the Mac, the printable area is in points, don't do any scaling based
372 // on dpi.
373 int dpi = printing::kPointsPerInch;
374 #else
375 int dpi = static_cast<int>(params->dpi);
376 #endif // defined(OS_MACOSX)
377 params->printable_size = gfx::Size(
378 static_cast<int>(ConvertUnitDouble(content_width_in_points,
379 printing::kPointsPerInch, dpi)),
380 static_cast<int>(ConvertUnitDouble(content_height_in_points,
381 printing::kPointsPerInch, dpi)));
370 382
371 #if defined(OS_MACOSX)
372 params->page_size = gfx::Size( 383 params->page_size = gfx::Size(
373 static_cast<int>(content_width_in_points + 384 static_cast<int>(ConvertUnitDouble(content_width_in_points +
374 margin_left_in_points + margin_right_in_points), 385 margin_left_in_points + margin_right_in_points,
375 static_cast<int>(content_height_in_points + 386 printing::kPointsPerInch, dpi)),
376 margin_top_in_points + margin_bottom_in_points)); 387 static_cast<int>(ConvertUnitDouble(content_height_in_points +
388 margin_top_in_points + margin_bottom_in_points,
389 printing::kPointsPerInch, dpi)));
377 390
378 params->printable_size = gfx::Size(static_cast<int>(content_width_in_points), 391 params->margin_top = static_cast<int>(ConvertUnitDouble(
379 static_cast<int>(content_height_in_points)); 392 margin_top_in_points, printing::kPointsPerInch, dpi));
380 #else 393 params->margin_left = static_cast<int>(ConvertUnitDouble(
381 params->printable_size = gfx::Size( 394 margin_left_in_points, printing::kPointsPerInch, dpi));
382 static_cast<int>(ConvertUnitDouble(
383 content_width_in_points, printing::kPointsPerInch, params->dpi)),
384 static_cast<int>(ConvertUnitDouble(
385 content_height_in_points, printing::kPointsPerInch, params->dpi)));
386 #endif
387 params->margin_top = static_cast<int>(margin_top_in_points);
388 params->margin_left = static_cast<int>(margin_left_in_points);
389 } 395 }
390 396
391 bool PrintWebViewHelper::InitPrintSettings(WebFrame* frame) { 397 bool PrintWebViewHelper::InitPrintSettings(WebFrame* frame) {
392 ViewMsg_PrintPages_Params settings; 398 ViewMsg_PrintPages_Params settings;
393 if (GetDefaultPrintSettings(frame, &settings.params)) { 399 if (GetDefaultPrintSettings(frame, &settings.params)) {
394 print_pages_params_.reset(new ViewMsg_PrintPages_Params(settings)); 400 print_pages_params_.reset(new ViewMsg_PrintPages_Params(settings));
395 print_pages_params_->pages.clear(); 401 print_pages_params_->pages.clear();
396 return true; 402 return true;
397 } 403 }
398 return false; 404 return false;
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after
498 shared_buf.GiveToProcess(base::GetCurrentProcessHandle(), 504 shared_buf.GiveToProcess(base::GetCurrentProcessHandle(),
499 shared_mem_handle); 505 shared_mem_handle);
500 return true; 506 return true;
501 } 507 }
502 } 508 }
503 } 509 }
504 NOTREACHED(); 510 NOTREACHED();
505 return false; 511 return false;
506 } 512 }
507 #endif 513 #endif
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698