| OLD | NEW |
| 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 "components/printing/renderer/print_web_view_helper.h" | 5 #include "components/printing/renderer/print_web_view_helper.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 #include <stdint.h> | 8 #include <stdint.h> |
| 9 | 9 |
| 10 #include <algorithm> | 10 #include <algorithm> |
| (...skipping 1329 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1340 const PrintMsg_Print_Params& print_params) { | 1340 const PrintMsg_Print_Params& print_params) { |
| 1341 std::unique_ptr<PdfMetafileSkia> draft_metafile; | 1341 std::unique_ptr<PdfMetafileSkia> draft_metafile; |
| 1342 PdfMetafileSkia* initial_render_metafile = print_preview_context_.metafile(); | 1342 PdfMetafileSkia* initial_render_metafile = print_preview_context_.metafile(); |
| 1343 if (print_preview_context_.IsModifiable() && is_print_ready_metafile_sent_) { | 1343 if (print_preview_context_.IsModifiable() && is_print_ready_metafile_sent_) { |
| 1344 draft_metafile = base::MakeUnique<PdfMetafileSkia>(PDF_SKIA_DOCUMENT_TYPE); | 1344 draft_metafile = base::MakeUnique<PdfMetafileSkia>(PDF_SKIA_DOCUMENT_TYPE); |
| 1345 initial_render_metafile = draft_metafile.get(); | 1345 initial_render_metafile = draft_metafile.get(); |
| 1346 } | 1346 } |
| 1347 | 1347 |
| 1348 base::TimeTicks begin_time = base::TimeTicks::Now(); | 1348 base::TimeTicks begin_time = base::TimeTicks::Now(); |
| 1349 PrintPageInternal(print_params, page_number, | 1349 PrintPageInternal(print_params, page_number, |
| 1350 print_preview_context_.total_page_count(), |
| 1350 print_preview_context_.prepared_frame(), | 1351 print_preview_context_.prepared_frame(), |
| 1351 initial_render_metafile, nullptr, nullptr, nullptr); | 1352 initial_render_metafile, nullptr, nullptr, nullptr); |
| 1352 print_preview_context_.RenderedPreviewPage( | 1353 print_preview_context_.RenderedPreviewPage( |
| 1353 base::TimeTicks::Now() - begin_time); | 1354 base::TimeTicks::Now() - begin_time); |
| 1354 if (draft_metafile.get()) { | 1355 if (draft_metafile.get()) { |
| 1355 draft_metafile->FinishDocument(); | 1356 draft_metafile->FinishDocument(); |
| 1356 } else if (print_preview_context_.IsModifiable() && | 1357 } else if (print_preview_context_.IsModifiable() && |
| 1357 print_preview_context_.generate_draft_pages()) { | 1358 print_preview_context_.generate_draft_pages()) { |
| 1358 DCHECK(!draft_metafile.get()); | 1359 DCHECK(!draft_metafile.get()); |
| 1359 draft_metafile = | 1360 draft_metafile = |
| (...skipping 480 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1840 render_frame()->GetWebkitPreferences(), | 1841 render_frame()->GetWebkitPreferences(), |
| 1841 base::Bind(&PrintWebViewHelper::OnFramePreparedForPrintPages, | 1842 base::Bind(&PrintWebViewHelper::OnFramePreparedForPrintPages, |
| 1842 base::Unretained(this))); | 1843 base::Unretained(this))); |
| 1843 return true; | 1844 return true; |
| 1844 } | 1845 } |
| 1845 #endif // BUILDFLAG(ENABLE_BASIC_PRINTING) | 1846 #endif // BUILDFLAG(ENABLE_BASIC_PRINTING) |
| 1846 | 1847 |
| 1847 #if !defined(OS_MACOSX) | 1848 #if !defined(OS_MACOSX) |
| 1848 void PrintWebViewHelper::PrintPageInternal(const PrintMsg_Print_Params& params, | 1849 void PrintWebViewHelper::PrintPageInternal(const PrintMsg_Print_Params& params, |
| 1849 int page_number, | 1850 int page_number, |
| 1851 int page_count, |
| 1850 blink::WebLocalFrame* frame, | 1852 blink::WebLocalFrame* frame, |
| 1851 PdfMetafileSkia* metafile, | 1853 PdfMetafileSkia* metafile, |
| 1852 gfx::Size* page_size_in_dpi, | 1854 gfx::Size* page_size_in_dpi, |
| 1853 gfx::Rect* content_area_in_dpi, | 1855 gfx::Rect* content_area_in_dpi, |
| 1854 gfx::Rect* printable_area_in_dpi) { | 1856 gfx::Rect* printable_area_in_dpi) { |
| 1855 PageSizeMargins page_layout_in_points; | 1857 PageSizeMargins page_layout_in_points; |
| 1856 | 1858 |
| 1857 double css_scale_factor = 1.0f; | 1859 double css_scale_factor = 1.0f; |
| 1858 #if BUILDFLAG(ENABLE_PRINT_PREVIEW) | 1860 #if BUILDFLAG(ENABLE_PRINT_PREVIEW) |
| 1859 if (params.scale_factor >= kEpsilon) | 1861 if (params.scale_factor >= kEpsilon) |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1908 #if BUILDFLAG(ENABLE_PRINT_PREVIEW) | 1910 #if BUILDFLAG(ENABLE_PRINT_PREVIEW) |
| 1909 if (params.display_header_footer) { | 1911 if (params.display_header_footer) { |
| 1910 #if defined(OS_WIN) | 1912 #if defined(OS_WIN) |
| 1911 const float fudge_factor = 1; | 1913 const float fudge_factor = 1; |
| 1912 #else | 1914 #else |
| 1913 // TODO(thestig): Figure out why Linux needs this. It is almost certainly | 1915 // TODO(thestig): Figure out why Linux needs this. It is almost certainly |
| 1914 // |kPrintingMinimumShrinkFactor| from Blink. | 1916 // |kPrintingMinimumShrinkFactor| from Blink. |
| 1915 const float fudge_factor = kPrintingMinimumShrinkFactor; | 1917 const float fudge_factor = kPrintingMinimumShrinkFactor; |
| 1916 #endif | 1918 #endif |
| 1917 // |page_number| is 0-based, so 1 is added. | 1919 // |page_number| is 0-based, so 1 is added. |
| 1918 PrintHeaderAndFooter( | 1920 PrintHeaderAndFooter(canvas, page_number + 1, page_count, *frame, |
| 1919 canvas, page_number + 1, print_preview_context_.total_page_count(), | 1921 scale_factor / fudge_factor, page_layout_in_points, |
| 1920 *frame, scale_factor / fudge_factor, page_layout_in_points, params); | 1922 params); |
| 1921 } | 1923 } |
| 1922 #endif // BUILDFLAG(ENABLE_PRINT_PREVIEW) | 1924 #endif // BUILDFLAG(ENABLE_PRINT_PREVIEW) |
| 1923 | 1925 |
| 1924 float webkit_scale_factor = RenderPageContent( | 1926 float webkit_scale_factor = RenderPageContent( |
| 1925 frame, page_number, canvas_area, content_area, scale_factor, canvas); | 1927 frame, page_number, canvas_area, content_area, scale_factor, canvas); |
| 1926 DCHECK_GT(webkit_scale_factor, 0.0f); | 1928 DCHECK_GT(webkit_scale_factor, 0.0f); |
| 1927 | 1929 |
| 1928 // Done printing. Close the canvas to retrieve the compiled metafile. | 1930 // Done printing. Close the canvas to retrieve the compiled metafile. |
| 1929 if (!metafile->FinishPage()) | 1931 if (!metafile->FinishPage()) |
| 1930 NOTREACHED() << "metafile failed"; | 1932 NOTREACHED() << "metafile failed"; |
| (...skipping 436 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2367 blink::WebConsoleMessage::kLevelWarning, message)); | 2369 blink::WebConsoleMessage::kLevelWarning, message)); |
| 2368 return false; | 2370 return false; |
| 2369 } | 2371 } |
| 2370 | 2372 |
| 2371 void PrintWebViewHelper::ScriptingThrottler::Reset() { | 2373 void PrintWebViewHelper::ScriptingThrottler::Reset() { |
| 2372 // Reset counter on successful print. | 2374 // Reset counter on successful print. |
| 2373 count_ = 0; | 2375 count_ = 0; |
| 2374 } | 2376 } |
| 2375 | 2377 |
| 2376 } // namespace printing | 2378 } // namespace printing |
| OLD | NEW |