Chromium Code Reviews| 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 "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 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 145 | 145 |
| 146 ComputePageLayoutInPointsForCss(frame, page_number, params, | 146 ComputePageLayoutInPointsForCss(frame, page_number, params, |
| 147 ignore_css_margins_, &scale_factor, | 147 ignore_css_margins_, &scale_factor, |
| 148 &page_layout_in_points); | 148 &page_layout_in_points); |
| 149 GetPageSizeAndContentAreaFromPageLayout(page_layout_in_points, page_size, | 149 GetPageSizeAndContentAreaFromPageLayout(page_layout_in_points, page_size, |
| 150 &content_area); | 150 &content_area); |
| 151 if (content_rect) | 151 if (content_rect) |
| 152 *content_rect = content_area; | 152 *content_rect = content_area; |
| 153 | 153 |
| 154 scale_factor *= webkit_shrink_factor; | 154 scale_factor *= webkit_shrink_factor; |
| 155 | |
| 156 gfx::Rect canvas_area = | |
| 157 params.display_header_footer ? gfx::Rect(*page_size) : content_area; | |
| 158 | |
| 155 { | 159 { |
| 156 #if defined(USE_SKIA) | 160 #if defined(USE_SKIA) |
| 157 SkDevice* device = metafile->StartPageForVectorCanvas( | 161 SkDevice* device = metafile->StartPageForVectorCanvas( |
| 158 *page_size, content_area, scale_factor); | 162 *page_size, canvas_area, scale_factor); |
| 159 if (!device) | 163 if (!device) |
| 160 return; | 164 return; |
| 161 | 165 |
| 162 SkRefPtr<skia::VectorCanvas> canvas = new skia::VectorCanvas(device); | 166 SkRefPtr<skia::VectorCanvas> canvas = new skia::VectorCanvas(device); |
| 163 canvas->unref(); // SkRefPtr and new both took a reference. | 167 canvas->unref(); // SkRefPtr and new both took a reference. |
| 164 WebKit::WebCanvas* canvas_ptr = canvas.get(); | 168 WebKit::WebCanvas* canvas_ptr = canvas.get(); |
| 165 printing::MetafileSkiaWrapper::SetMetafileOnCanvas(*canvas, metafile); | 169 printing::MetafileSkiaWrapper::SetMetafileOnCanvas(*canvas, metafile); |
| 166 skia::SetIsDraftMode(*canvas, is_print_ready_metafile_sent_); | 170 skia::SetIsDraftMode(*canvas, is_print_ready_metafile_sent_); |
| 167 skia::SetIsPreviewMetafile(*canvas, is_preview); | 171 skia::SetIsPreviewMetafile(*canvas, is_preview); |
| 168 #else | 172 #else |
|
Alexei Svitkine (slow)
2012/11/02 18:19:14
You can delete the #else block here and remove the
| |
| 169 bool success = metafile->StartPage(*page_size, content_area, scale_factor); | 173 bool success = metafile->StartPage(*page_size, canvas_area, scale_factor); |
| 170 DCHECK(success); | 174 DCHECK(success); |
| 171 // printPage can create autoreleased references to |context|. PDF contexts | 175 // printPage can create autoreleased references to |context|. PDF contexts |
| 172 // don't write all their data until they are destroyed, so we need to make | 176 // don't write all their data until they are destroyed, so we need to make |
| 173 // certain that there are no lingering references. | 177 // certain that there are no lingering references. |
| 174 base::mac::ScopedNSAutoreleasePool pool; | 178 base::mac::ScopedNSAutoreleasePool pool; |
| 175 CGContextRef cgContext = metafile->context(); | 179 CGContextRef cgContext = metafile->context(); |
| 176 CGContextRef canvas_ptr = cgContext; | 180 CGContextRef canvas_ptr = cgContext; |
| 177 | 181 |
| 178 // For CoreGraphics, print in the margins before printing in the content | 182 #endif // !USE_SKIA |
| 179 // area so that we don't spill over. Webkit draws a white background in the | |
| 180 // content area and this acts as a clip. | |
| 181 // TODO(aayushkumar): Combine the calls to PrintHeaderAndFooter once we | |
| 182 // can draw in the margins safely in Skia in any order. | |
| 183 if (print_pages_params_->params.display_header_footer) { | 183 if (print_pages_params_->params.display_header_footer) { |
| 184 PrintHeaderAndFooter(canvas_ptr, page_number + 1, | 184 PrintHeaderAndFooter(canvas_ptr, page_number + 1, |
| 185 print_preview_context_.total_page_count(), | 185 print_preview_context_.total_page_count(), |
| 186 scale_factor, page_layout_in_points, | 186 scale_factor, page_layout_in_points, |
| 187 *header_footer_info_, params); | 187 *header_footer_info_, params); |
| 188 } | 188 } |
| 189 #endif // !USE_SKIA | 189 canvas_ptr->translate((content_area.x() - canvas_area.x()) / scale_factor, |
| 190 (content_area.y() - canvas_area.y()) / scale_factor); | |
| 190 | 191 |
| 191 frame->printPage(page_number, canvas_ptr); | 192 frame->printPage(page_number, canvas_ptr); |
| 192 | |
| 193 #if defined(USE_SKIA) | |
| 194 if (print_pages_params_->params.display_header_footer) { | |
| 195 // |page_number| is 0-based, so 1 is added. | |
| 196 PrintHeaderAndFooter(canvas_ptr, page_number + 1, | |
| 197 print_preview_context_.total_page_count(), | |
| 198 scale_factor, page_layout_in_points, | |
| 199 *header_footer_info_, params); | |
| 200 } | |
| 201 #endif // defined(USE_SKIA) | |
| 202 } | 193 } |
| 203 | 194 |
| 204 // Done printing. Close the device context to retrieve the compiled metafile. | 195 // Done printing. Close the device context to retrieve the compiled metafile. |
| 205 metafile->FinishPage(); | 196 metafile->FinishPage(); |
| 206 } | 197 } |
| OLD | NEW |