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

Side by Side Diff: components/printing/renderer/print_web_view_helper.cc

Issue 2640983002: Rename paint data structures (Closed)
Patch Set: Clean up comments, fix mac build Created 3 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
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 "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>
11 #include <string> 11 #include <string>
12 #include <utility> 12 #include <utility>
13 13
14 #include "base/auto_reset.h" 14 #include "base/auto_reset.h"
15 #include "base/json/json_writer.h" 15 #include "base/json/json_writer.h"
16 #include "base/location.h" 16 #include "base/location.h"
17 #include "base/logging.h" 17 #include "base/logging.h"
18 #include "base/macros.h" 18 #include "base/macros.h"
19 #include "base/memory/ptr_util.h" 19 #include "base/memory/ptr_util.h"
20 #include "base/metrics/histogram_macros.h" 20 #include "base/metrics/histogram_macros.h"
21 #include "base/process/process_handle.h" 21 #include "base/process/process_handle.h"
22 #include "base/single_thread_task_runner.h" 22 #include "base/single_thread_task_runner.h"
23 #include "base/strings/string_number_conversions.h" 23 #include "base/strings/string_number_conversions.h"
24 #include "base/strings/stringprintf.h" 24 #include "base/strings/stringprintf.h"
25 #include "base/strings/utf_string_conversions.h" 25 #include "base/strings/utf_string_conversions.h"
26 #include "base/threading/thread_task_runner_handle.h" 26 #include "base/threading/thread_task_runner_handle.h"
27 #include "build/build_config.h" 27 #include "build/build_config.h"
28 #include "cc/paint/paint_canvas.h"
28 #include "components/printing/common/print_messages.h" 29 #include "components/printing/common/print_messages.h"
29 #include "content/public/common/web_preferences.h" 30 #include "content/public/common/web_preferences.h"
30 #include "content/public/renderer/render_frame.h" 31 #include "content/public/renderer/render_frame.h"
31 #include "content/public/renderer/render_thread.h" 32 #include "content/public/renderer/render_thread.h"
32 #include "content/public/renderer/render_view.h" 33 #include "content/public/renderer/render_view.h"
33 #include "grit/components_resources.h" 34 #include "grit/components_resources.h"
34 #include "net/base/escape.h" 35 #include "net/base/escape.h"
35 #include "printing/features/features.h" 36 #include "printing/features/features.h"
36 #include "printing/metafile_skia_wrapper.h" 37 #include "printing/metafile_skia_wrapper.h"
37 #include "printing/pdf_metafile_skia.h" 38 #include "printing/pdf_metafile_skia.h"
(...skipping 10 matching lines...) Expand all
48 #include "third_party/WebKit/public/web/WebLocalFrame.h" 49 #include "third_party/WebKit/public/web/WebLocalFrame.h"
49 #include "third_party/WebKit/public/web/WebPlugin.h" 50 #include "third_party/WebKit/public/web/WebPlugin.h"
50 #include "third_party/WebKit/public/web/WebPluginDocument.h" 51 #include "third_party/WebKit/public/web/WebPluginDocument.h"
51 #include "third_party/WebKit/public/web/WebPrintParams.h" 52 #include "third_party/WebKit/public/web/WebPrintParams.h"
52 #include "third_party/WebKit/public/web/WebPrintPresetOptions.h" 53 #include "third_party/WebKit/public/web/WebPrintPresetOptions.h"
53 #include "third_party/WebKit/public/web/WebSandboxFlags.h" 54 #include "third_party/WebKit/public/web/WebSandboxFlags.h"
54 #include "third_party/WebKit/public/web/WebScriptSource.h" 55 #include "third_party/WebKit/public/web/WebScriptSource.h"
55 #include "third_party/WebKit/public/web/WebSettings.h" 56 #include "third_party/WebKit/public/web/WebSettings.h"
56 #include "third_party/WebKit/public/web/WebView.h" 57 #include "third_party/WebKit/public/web/WebView.h"
57 #include "third_party/WebKit/public/web/WebViewClient.h" 58 #include "third_party/WebKit/public/web/WebViewClient.h"
58 #include "third_party/skia/include/core/SkCanvas.h"
59 #include "ui/base/resource/resource_bundle.h" 59 #include "ui/base/resource/resource_bundle.h"
60 60
61 using content::WebPreferences; 61 using content::WebPreferences;
62 62
63 namespace printing { 63 namespace printing {
64 64
65 namespace { 65 namespace {
66 66
67 #define STATIC_ASSERT_ENUM(a, b) \ 67 #define STATIC_ASSERT_ENUM(a, b) \
68 static_assert(static_cast<int>(a) == static_cast<int>(b), \ 68 static_assert(static_cast<int>(a) == static_cast<int>(b), \
(...skipping 497 matching lines...) Expand 10 before | Expand all | Expand 10 after
566 #if BUILDFLAG(ENABLE_PRINT_PREVIEW) 566 #if BUILDFLAG(ENABLE_PRINT_PREVIEW)
567 // static - Not anonymous so that platform implementations can use it. 567 // static - Not anonymous so that platform implementations can use it.
568 void PrintWebViewHelper::PrintHeaderAndFooter( 568 void PrintWebViewHelper::PrintHeaderAndFooter(
569 blink::WebCanvas* canvas, 569 blink::WebCanvas* canvas,
570 int page_number, 570 int page_number,
571 int total_pages, 571 int total_pages,
572 const blink::WebFrame& source_frame, 572 const blink::WebFrame& source_frame,
573 float webkit_scale_factor, 573 float webkit_scale_factor,
574 const PageSizeMargins& page_layout, 574 const PageSizeMargins& page_layout,
575 const PrintMsg_Print_Params& params) { 575 const PrintMsg_Print_Params& params) {
576 SkAutoCanvasRestore auto_restore(canvas, true); 576 cc::PaintCanvasAutoRestore auto_restore(canvas, true);
577 canvas->scale(1 / webkit_scale_factor, 1 / webkit_scale_factor); 577 canvas->scale(1 / webkit_scale_factor, 1 / webkit_scale_factor);
578 578
579 blink::WebSize page_size(page_layout.margin_left + page_layout.margin_right + 579 blink::WebSize page_size(page_layout.margin_left + page_layout.margin_right +
580 page_layout.content_width, 580 page_layout.content_width,
581 page_layout.margin_top + page_layout.margin_bottom + 581 page_layout.margin_top + page_layout.margin_bottom +
582 page_layout.content_height); 582 page_layout.content_height);
583 583
584 blink::WebView* web_view = 584 blink::WebView* web_view =
585 blink::WebView::create(nullptr, blink::WebPageVisibilityStateVisible); 585 blink::WebView::create(nullptr, blink::WebPageVisibilityStateVisible);
586 web_view->settings()->setJavaScriptEnabled(true); 586 web_view->settings()->setJavaScriptEnabled(true);
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
623 } 623 }
624 #endif // BUILDFLAG(ENABLE_PRINT_PREVIEW) 624 #endif // BUILDFLAG(ENABLE_PRINT_PREVIEW)
625 625
626 // static - Not anonymous so that platform implementations can use it. 626 // static - Not anonymous so that platform implementations can use it.
627 float PrintWebViewHelper::RenderPageContent(blink::WebFrame* frame, 627 float PrintWebViewHelper::RenderPageContent(blink::WebFrame* frame,
628 int page_number, 628 int page_number,
629 const gfx::Rect& canvas_area, 629 const gfx::Rect& canvas_area,
630 const gfx::Rect& content_area, 630 const gfx::Rect& content_area,
631 double scale_factor, 631 double scale_factor,
632 blink::WebCanvas* canvas) { 632 blink::WebCanvas* canvas) {
633 SkAutoCanvasRestore auto_restore(canvas, true); 633 cc::PaintCanvasAutoRestore auto_restore(canvas, true);
634 canvas->translate((content_area.x() - canvas_area.x()) / scale_factor, 634 canvas->translate((content_area.x() - canvas_area.x()) / scale_factor,
635 (content_area.y() - canvas_area.y()) / scale_factor); 635 (content_area.y() - canvas_area.y()) / scale_factor);
636 return frame->printPage(page_number, canvas); 636 return frame->printPage(page_number, canvas);
637 } 637 }
638 638
639 // Class that calls the Begin and End print functions on the frame and changes 639 // Class that calls the Begin and End print functions on the frame and changes
640 // the size of the view temporarily to support full page printing.. 640 // the size of the view temporarily to support full page printing..
641 class PrepareFrameAndViewForPrint : public blink::WebViewClient, 641 class PrepareFrameAndViewForPrint : public blink::WebViewClient,
642 public blink::WebFrameClient { 642 public blink::WebFrameClient {
643 public: 643 public:
(...skipping 1226 matching lines...) Expand 10 before | Expand all | Expand 10 after
1870 1870
1871 // TODO(thestig): Figure out why Linux is different. 1871 // TODO(thestig): Figure out why Linux is different.
1872 #if defined(OS_WIN) 1872 #if defined(OS_WIN)
1873 float webkit_page_shrink_factor = 1873 float webkit_page_shrink_factor =
1874 frame->getPrintPageShrink(params.page_number); 1874 frame->getPrintPageShrink(params.page_number);
1875 float scale_factor = css_scale_factor * webkit_page_shrink_factor; 1875 float scale_factor = css_scale_factor * webkit_page_shrink_factor;
1876 #else 1876 #else
1877 float scale_factor = css_scale_factor; 1877 float scale_factor = css_scale_factor;
1878 #endif 1878 #endif
1879 1879
1880 SkCanvas* canvas = metafile->GetVectorCanvasForNewPage( 1880 cc::PaintCanvas* canvas =
danakj 2017/01/20 23:34:14 metafile is a PdfMetafileSkia, it won't return a P
1881 page_size, canvas_area, scale_factor); 1881 metafile->GetVectorCanvasForNewPage(page_size, canvas_area, scale_factor);
1882 if (!canvas) 1882 if (!canvas)
1883 return; 1883 return;
1884 1884
1885 MetafileSkiaWrapper::SetMetafileOnCanvas(*canvas, metafile); 1885 MetafileSkiaWrapper::SetMetafileOnCanvas(*canvas, metafile);
1886 1886
1887 #if BUILDFLAG(ENABLE_PRINT_PREVIEW) 1887 #if BUILDFLAG(ENABLE_PRINT_PREVIEW)
1888 if (params.params.display_header_footer) { 1888 if (params.params.display_header_footer) {
1889 // TODO(thestig): Figure out why Linux needs this. It is almost certainly 1889 // TODO(thestig): Figure out why Linux needs this. It is almost certainly
1890 // |printingMinimumShrinkFactor| from Blink. 1890 // |printingMinimumShrinkFactor| from Blink.
1891 #if defined(OS_WIN) 1891 #if defined(OS_WIN)
(...skipping 456 matching lines...) Expand 10 before | Expand all | Expand 10 after
2348 blink::WebConsoleMessage::LevelWarning, message)); 2348 blink::WebConsoleMessage::LevelWarning, message));
2349 return false; 2349 return false;
2350 } 2350 }
2351 2351
2352 void PrintWebViewHelper::ScriptingThrottler::Reset() { 2352 void PrintWebViewHelper::ScriptingThrottler::Reset() {
2353 // Reset counter on successful print. 2353 // Reset counter on successful print.
2354 count_ = 0; 2354 count_ = 0;
2355 } 2355 }
2356 2356
2357 } // namespace printing 2357 } // namespace printing
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698