OLD | NEW |
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 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 "chrome/common/render_messages.h" | 9 #include "chrome/common/render_messages.h" |
10 #include "chrome/renderer/render_view.h" | 10 #include "chrome/renderer/render_view.h" |
(...skipping 362 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
373 | 373 |
374 WebSize page_size_in_pixels( | 374 WebSize page_size_in_pixels( |
375 ConvertUnit(default_params.page_size.width(), | 375 ConvertUnit(default_params.page_size.width(), |
376 dpi, printing::kPixelsPerInch), | 376 dpi, printing::kPixelsPerInch), |
377 ConvertUnit(default_params.page_size.height(), | 377 ConvertUnit(default_params.page_size.height(), |
378 dpi, printing::kPixelsPerInch)); | 378 dpi, printing::kPixelsPerInch)); |
379 int margin_top_in_pixels = ConvertUnit( | 379 int margin_top_in_pixels = ConvertUnit( |
380 default_params.margin_top, | 380 default_params.margin_top, |
381 dpi, printing::kPixelsPerInch); | 381 dpi, printing::kPixelsPerInch); |
382 int margin_right_in_pixels = ConvertUnit( | 382 int margin_right_in_pixels = ConvertUnit( |
383 default_params.page_size.width() | 383 default_params.page_size.width() - |
384 - default_params.printable_size.width() - default_params.margin_left, | 384 default_params.printable_size.width() - default_params.margin_left, |
385 dpi, printing::kPixelsPerInch); | 385 dpi, printing::kPixelsPerInch); |
386 int margin_bottom_in_pixels = ConvertUnit( | 386 int margin_bottom_in_pixels = ConvertUnit( |
387 default_params.page_size.height() | 387 default_params.page_size.height() - |
388 - default_params.printable_size.height() - default_params.margin_top, | 388 default_params.printable_size.height() - default_params.margin_top, |
389 dpi, printing::kPixelsPerInch); | 389 dpi, printing::kPixelsPerInch); |
390 int margin_left_in_pixels = ConvertUnit( | 390 int margin_left_in_pixels = ConvertUnit( |
391 default_params.margin_left, | 391 default_params.margin_left, |
392 dpi, printing::kPixelsPerInch); | 392 dpi, printing::kPixelsPerInch); |
393 | 393 |
394 if (frame) { | 394 if (frame) { |
395 frame->pageSizeAndMarginsInPixels(page_index, | 395 frame->pageSizeAndMarginsInPixels(page_index, |
396 page_size_in_pixels, | 396 page_size_in_pixels, |
397 margin_top_in_pixels, | 397 margin_top_in_pixels, |
398 margin_right_in_pixels, | 398 margin_right_in_pixels, |
399 margin_bottom_in_pixels, | 399 margin_bottom_in_pixels, |
400 margin_left_in_pixels); | 400 margin_left_in_pixels); |
401 } | 401 } |
402 | 402 |
403 *content_width_in_points = ConvertPixelsToPoint(page_size_in_pixels.width | 403 *content_width_in_points = ConvertPixelsToPoint(page_size_in_pixels.width - |
404 - margin_left_in_pixels | 404 margin_left_in_pixels - |
405 - margin_right_in_pixels); | 405 margin_right_in_pixels); |
406 *content_height_in_points = ConvertPixelsToPoint(page_size_in_pixels.height | 406 *content_height_in_points = ConvertPixelsToPoint(page_size_in_pixels.height - |
407 - margin_top_in_pixels | 407 margin_top_in_pixels - |
408 - margin_bottom_in_pixels); | 408 margin_bottom_in_pixels); |
409 | 409 |
410 // Invalid page size and/or margins. We just use the default setting. | 410 // Invalid page size and/or margins. We just use the default setting. |
411 if (*content_width_in_points < 1.0 || *content_height_in_points < 1.0) { | 411 if (*content_width_in_points < 1.0 || *content_height_in_points < 1.0) { |
412 GetPageSizeAndMarginsInPoints(NULL, | 412 GetPageSizeAndMarginsInPoints(NULL, |
413 page_index, | 413 page_index, |
414 default_params, | 414 default_params, |
415 content_width_in_points, | 415 content_width_in_points, |
416 content_height_in_points, | 416 content_height_in_points, |
417 margin_top_in_points, | 417 margin_top_in_points, |
418 margin_right_in_points, | 418 margin_right_in_points, |
(...skipping 23 matching lines...) Expand all Loading... |
442 double content_height_in_points; | 442 double content_height_in_points; |
443 PrintWebViewHelper::GetPageSizeAndMarginsInPoints(frame, 0, *params, | 443 PrintWebViewHelper::GetPageSizeAndMarginsInPoints(frame, 0, *params, |
444 &content_width_in_points, | 444 &content_width_in_points, |
445 &content_height_in_points, | 445 &content_height_in_points, |
446 NULL, NULL, NULL, NULL); | 446 NULL, NULL, NULL, NULL); |
447 params->printable_size = gfx::Size( | 447 params->printable_size = gfx::Size( |
448 static_cast<int>(content_width_in_points), | 448 static_cast<int>(content_width_in_points), |
449 static_cast<int>(content_height_in_points)); | 449 static_cast<int>(content_height_in_points)); |
450 #endif | 450 #endif |
451 } | 451 } |
OLD | NEW |