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

Side by Side Diff: chrome/renderer/print_web_view_helper_mac.mm

Issue 7365003: Print Preview: Make preview generation event driven to eliminate synchronous messages. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: clang fix Created 9 years, 5 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
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 #import <AppKit/AppKit.h> 7 #import <AppKit/AppKit.h>
8 8
9 #include "base/logging.h" 9 #include "base/logging.h"
10 #include "base/mac/scoped_nsautorelease_pool.h" 10 #include "base/mac/scoped_nsautorelease_pool.h"
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
52 52
53 // Ask the browser to create the shared memory for us. 53 // Ask the browser to create the shared memory for us.
54 if (!CopyMetafileDataToSharedMem(&metafile, 54 if (!CopyMetafileDataToSharedMem(&metafile,
55 &(page_params.metafile_data_handle))) { 55 &(page_params.metafile_data_handle))) {
56 page_params.data_size = 0; 56 page_params.data_size = 0;
57 } 57 }
58 58
59 Send(new PrintHostMsg_DidPrintPage(routing_id(), page_params)); 59 Send(new PrintHostMsg_DidPrintPage(routing_id(), page_params));
60 } 60 }
61 61
62 bool PrintWebViewHelper::CreatePreviewDocument( 62 void PrintWebViewHelper::RenderPreviewPage(int page_number) {
63 const PrintMsg_PrintPages_Params& params, WebKit::WebFrame* frame, 63 float scale_factor = print_preview_context_.frame()->getPrintPageShrink(0);
64 WebKit::WebNode* node) { 64 PrintMsg_Print_Params printParams = print_preview_context_.print_params();
65 if (!PreviewPageRendered(-1))
66 return false;
67
68 PrintMsg_Print_Params printParams = params.params;
69 UpdatePrintableSizeInPrintParameters(frame, node, &printParams);
70
71 PrepareFrameAndViewForPrint prep_frame_view(printParams,
72 frame, node, frame->view());
73 if (!PreviewPageRendered(-1))
74 return false;
75
76 preview_page_count_ = prep_frame_view.GetExpectedPageCount();
77 if (!preview_page_count_)
78 return false;
79 Send(new PrintHostMsg_DidGetPreviewPageCount(routing_id(),
80 preview_page_count_));
81
82 printing::PreviewMetafile metafile;
83 if (!metafile.Init())
84 return false;
85
86 float scale_factor = frame->getPrintPageShrink(0);
87 gfx::Rect content_area(printParams.margin_left, printParams.margin_top, 65 gfx::Rect content_area(printParams.margin_left, printParams.margin_top,
88 printParams.printable_size.width(), 66 printParams.printable_size.width(),
89 printParams.printable_size.height()); 67 printParams.printable_size.height());
90 68
91 base::TimeTicks begin_time = base::TimeTicks::Now(); 69 base::TimeTicks begin_time = base::TimeTicks::Now();
92 base::TimeTicks page_begin_time = begin_time; 70 RenderPage(printParams.page_size, content_area, scale_factor, page_number,
93 71 print_preview_context_.frame(), print_preview_context_.metafile());
94 if (params.pages.empty()) { 72 print_preview_context_.RenderedPreviewPage(
95 for (int i = 0; i < preview_page_count_; ++i) { 73 base::TimeTicks::Now() - begin_time);
96 RenderPage(printParams.page_size, content_area, scale_factor, i, frame, 74 PreviewPageRendered(page_number);
97 &metafile);
98 page_begin_time = ReportPreviewPageRenderTime(page_begin_time);
99 if (!PreviewPageRendered(i))
100 return false;
101 }
102 } else {
103 for (size_t i = 0; i < params.pages.size(); ++i) {
104 if (params.pages[i] >= preview_page_count_)
105 break;
106 RenderPage(printParams.page_size, content_area, scale_factor,
107 params.pages[i], frame, &metafile);
108 page_begin_time = ReportPreviewPageRenderTime(page_begin_time);
109 if (!PreviewPageRendered(params.pages[i]))
110 return false;
111 }
112 }
113
114 base::TimeDelta render_time = base::TimeTicks::Now() - begin_time;
115
116 prep_frame_view.FinishPrinting();
117 metafile.FinishDocument();
118
119 ReportTotalPreviewGenerationTime(params.pages.size(),
120 preview_page_count_,
121 render_time,
122 base::TimeTicks::Now() - begin_time);
123
124 PrintHostMsg_DidPreviewDocument_Params preview_params;
125 preview_params.reuse_existing_data = false;
126 preview_params.data_size = metafile.GetDataSize();
127 preview_params.document_cookie = params.params.document_cookie;
128 preview_params.expected_pages_count = preview_page_count_;
129 preview_params.modifiable = IsModifiable(frame, node);
130 preview_params.preview_request_id = params.params.preview_request_id;
131
132 // Ask the browser to create the shared memory for us.
133 if (!CopyMetafileDataToSharedMem(&metafile,
134 &(preview_params.metafile_data_handle))) {
135 return false;
136 }
137 Send(new PrintHostMsg_PagesReadyForPreview(routing_id(), preview_params));
138 return true;
139 } 75 }
140 76
141 void PrintWebViewHelper::RenderPage( 77 void PrintWebViewHelper::RenderPage(
142 const gfx::Size& page_size, const gfx::Rect& content_area, 78 const gfx::Size& page_size, const gfx::Rect& content_area,
143 const float& scale_factor, int page_number, WebFrame* frame, 79 const float& scale_factor, int page_number, WebFrame* frame,
144 printing::Metafile* metafile) { 80 printing::Metafile* metafile) {
145 81
146 { 82 {
147 #if defined(USE_SKIA) 83 #if defined(USE_SKIA)
148 SkDevice* device = metafile->StartPageForVectorCanvas( 84 SkDevice* device = metafile->StartPageForVectorCanvas(
(...skipping 14 matching lines...) Expand all
163 base::mac::ScopedNSAutoreleasePool pool; 99 base::mac::ScopedNSAutoreleasePool pool;
164 CGContextRef cgContext = metafile->context(); 100 CGContextRef cgContext = metafile->context();
165 CGContextRef canvasPtr = cgContext; 101 CGContextRef canvasPtr = cgContext;
166 #endif 102 #endif
167 frame->printPage(page_number, canvasPtr); 103 frame->printPage(page_number, canvasPtr);
168 } 104 }
169 105
170 // Done printing. Close the device context to retrieve the compiled metafile. 106 // Done printing. Close the device context to retrieve the compiled metafile.
171 metafile->FinishPage(); 107 metafile->FinishPage();
172 } 108 }
OLDNEW
« no previous file with comments | « chrome/renderer/print_web_view_helper_linux.cc ('k') | chrome/renderer/print_web_view_helper_win.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698