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

Side by Side Diff: chrome/renderer/printing/print_web_view_helper_linux.cc

Issue 11953010: Cleanup of PrepareFrameAndViewForPrint code. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 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 | « chrome/renderer/printing/print_web_view_helper.cc ('k') | 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) 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 "chrome/renderer/printing/print_web_view_helper.h" 5 #include "chrome/renderer/printing/print_web_view_helper.h"
6 6
7 #include "base/file_descriptor_posix.h" 7 #include "base/file_descriptor_posix.h"
8 #include "base/logging.h" 8 #include "base/logging.h"
9 #include "base/memory/scoped_ptr.h" 9 #include "base/memory/scoped_ptr.h"
10 #include "base/metrics/histogram.h" 10 #include "base/metrics/histogram.h"
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
50 draft_metafile->FinishDocument(); 50 draft_metafile->FinishDocument();
51 } else if (print_preview_context_.IsModifiable() && 51 } else if (print_preview_context_.IsModifiable() &&
52 print_preview_context_.generate_draft_pages()) { 52 print_preview_context_.generate_draft_pages()) {
53 DCHECK(!draft_metafile.get()); 53 DCHECK(!draft_metafile.get());
54 draft_metafile.reset( 54 draft_metafile.reset(
55 print_preview_context_.metafile()->GetMetafileForCurrentPage()); 55 print_preview_context_.metafile()->GetMetafileForCurrentPage());
56 } 56 }
57 return PreviewPageRendered(page_number, draft_metafile.get()); 57 return PreviewPageRendered(page_number, draft_metafile.get());
58 } 58 }
59 59
60 bool PrintWebViewHelper::PrintPages(WebFrame* frame, const WebNode& node) { 60 bool PrintWebViewHelper::PrintPagesNative(WebKit::WebFrame* frame,
61 const WebKit::WebNode& node,
62 int page_count,
63 const gfx::Size& canvas_size) {
61 NativeMetafile metafile; 64 NativeMetafile metafile;
62 if (!metafile.Init()) 65 if (!metafile.Init())
63 return false; 66 return false;
64 67
65 const PrintMsg_PrintPages_Params& params = *print_pages_params_; 68 const PrintMsg_PrintPages_Params& params = *print_pages_params_;
66 std::vector<int> printed_pages; 69 std::vector<int> printed_pages;
67 if (!RenderPages(params, frame, node, &printed_pages, &metafile)) { 70
71 if (params.pages.empty()) {
72 for (int i = 0; i < page_count; ++i) {
73 printed_pages.push_back(i);
74 }
75 } else {
76 // TODO(vitalybuka): redesign to make more code cross platform.
77 for (size_t i = 0; i < params.pages.size(); ++i) {
78 if (params.pages[i] >= 0 && params.pages[i] < page_count) {
79 printed_pages.push_back(params.pages[i]);
80 }
81 }
82 }
83
84 if (printed_pages.empty())
68 return false; 85 return false;
86
87 PrintMsg_PrintPage_Params page_params;
88 page_params.params = params.params;
89 for (size_t i = 0; i < printed_pages.size(); ++i) {
90 page_params.page_number = printed_pages[i];
91 PrintPageInternal(page_params, canvas_size, frame, &metafile);
69 } 92 }
70 93
71 metafile.FinishDocument(); 94 metafile.FinishDocument();
72 95
73 // Get the size of the resulting metafile. 96 // Get the size of the resulting metafile.
74 uint32 buf_size = metafile.GetDataSize(); 97 uint32 buf_size = metafile.GetDataSize();
75 DCHECK_GT(buf_size, 0u); 98 DCHECK_GT(buf_size, 0u);
76 99
77 #if defined(OS_CHROMEOS) 100 #if defined(OS_CHROMEOS)
78 int sequence_number = -1; 101 int sequence_number = -1;
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
114 for (size_t i = 0; i < printed_pages.size(); ++i) { 137 for (size_t i = 0; i < printed_pages.size(); ++i) {
115 printed_page_params.page_number = printed_pages[i]; 138 printed_page_params.page_number = printed_pages[i];
116 Send(new PrintHostMsg_DidPrintPage(routing_id(), printed_page_params)); 139 Send(new PrintHostMsg_DidPrintPage(routing_id(), printed_page_params));
117 // Send the rest of the pages with an invalid metafile handle. 140 // Send the rest of the pages with an invalid metafile handle.
118 printed_page_params.metafile_data_handle.fd = -1; 141 printed_page_params.metafile_data_handle.fd = -1;
119 } 142 }
120 return true; 143 return true;
121 #endif // defined(OS_CHROMEOS) 144 #endif // defined(OS_CHROMEOS)
122 } 145 }
123 146
124 bool PrintWebViewHelper::RenderPages(const PrintMsg_PrintPages_Params& params,
125 WebKit::WebFrame* frame,
126 const WebKit::WebNode& node,
127 std::vector<int>* printed_pages,
128 Metafile* metafile) {
129 PrepareFrameAndViewForPrint prepare(params.params, frame, node);
130 PrintMsg_Print_Params print_params = params.params;
131 UpdateFrameAndViewFromCssPageLayout(frame, node, &prepare, print_params,
132 ignore_css_margins_);
133
134 int page_count = prepare.GetExpectedPageCount();
135 if (!page_count)
136 return false;
137
138 #if !defined(OS_CHROMEOS)
139 // TODO(vitalybuka): should be page_count or valid pages from params.pages.
140 // See http://crbug.com/161576
141 Send(new PrintHostMsg_DidGetPrintedPagesCount(routing_id(),
142 print_params.document_cookie,
143 page_count));
144 #endif
145
146 if (params.pages.empty()) {
147 for (int i = 0; i < page_count; ++i) {
148 printed_pages->push_back(i);
149 }
150 } else {
151 // TODO(vitalybuka): redesign to make more code cross platform.
152 for (size_t i = 0; i < params.pages.size(); ++i) {
153 if (params.pages[i] >= 0 && params.pages[i] < page_count) {
154 printed_pages->push_back(params.pages[i]);
155 }
156 }
157 }
158
159 if (printed_pages->empty())
160 return false;
161
162 PrintMsg_PrintPage_Params page_params;
163 page_params.params = print_params;
164 const gfx::Size& canvas_size = prepare.GetPrintCanvasSize();
165 for (size_t i = 0; i < printed_pages->size(); ++i) {
166 page_params.page_number = (*printed_pages)[i];
167 PrintPageInternal(page_params, canvas_size, frame, metafile);
168 }
169
170 return true;
171 }
172
173 void PrintWebViewHelper::PrintPageInternal( 147 void PrintWebViewHelper::PrintPageInternal(
174 const PrintMsg_PrintPage_Params& params, 148 const PrintMsg_PrintPage_Params& params,
175 const gfx::Size& canvas_size, 149 const gfx::Size& canvas_size,
176 WebFrame* frame, 150 WebFrame* frame,
177 Metafile* metafile) { 151 Metafile* metafile) {
178 PageSizeMargins page_layout_in_points; 152 PageSizeMargins page_layout_in_points;
179 double scale_factor = 1.0f; 153 double scale_factor = 1.0f;
180 ComputePageLayoutInPointsForCss(frame, params.page_number, params.params, 154 ComputePageLayoutInPointsForCss(frame, params.page_number, params.params,
181 ignore_css_margins_, &scale_factor, 155 ignore_css_margins_, &scale_factor,
182 &page_layout_in_points); 156 &page_layout_in_points);
(...skipping 27 matching lines...) Expand all
210 } 184 }
211 RenderPageContent(frame, params.page_number, canvas_area, content_area, 185 RenderPageContent(frame, params.page_number, canvas_area, content_area,
212 scale_factor, canvas.get()); 186 scale_factor, canvas.get());
213 187
214 // Done printing. Close the device context to retrieve the compiled metafile. 188 // Done printing. Close the device context to retrieve the compiled metafile.
215 if (!metafile->FinishPage()) 189 if (!metafile->FinishPage())
216 NOTREACHED() << "metafile failed"; 190 NOTREACHED() << "metafile failed";
217 } 191 }
218 192
219 } // namespace printing 193 } // namespace printing
OLDNEW
« no previous file with comments | « chrome/renderer/printing/print_web_view_helper.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698