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

Side by Side Diff: chrome/renderer/print_web_view_helper.cc

Issue 9380051: Coverity: Fix a few pass-by-values. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 10 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/browser/extensions/api/declarative/initializing_rules_registry.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/print_web_view_helper.h" 5 #include "chrome/renderer/print_web_view_helper.h"
6 6
7 #include <string> 7 #include <string>
8 8
9 #include "base/command_line.h" 9 #include "base/command_line.h"
10 #include "base/logging.h" 10 #include "base/logging.h"
(...skipping 365 matching lines...) Expand 10 before | Expand all | Expand 10 after
376 SkPoint point = SkPoint::Make(x / webkit_scale_factor, 376 SkPoint point = SkPoint::Make(x / webkit_scale_factor,
377 y / webkit_scale_factor); 377 y / webkit_scale_factor);
378 return point; 378 return point;
379 } 379 }
380 380
381 // Given a text, the positions, and the paint object, this method gets the 381 // Given a text, the positions, and the paint object, this method gets the
382 // coordinates and prints the text at those coordinates on the canvas. 382 // coordinates and prints the text at those coordinates on the canvas.
383 void PrintHeaderFooterText( 383 void PrintHeaderFooterText(
384 const string16& text, 384 const string16& text,
385 WebKit::WebCanvas* canvas, 385 WebKit::WebCanvas* canvas,
386 HeaderFooterPaint paint, 386 const HeaderFooterPaint& paint,
387 float webkit_scale_factor, 387 float webkit_scale_factor,
388 const PageSizeMargins& page_layout, 388 const PageSizeMargins& page_layout,
389 printing::HorizontalHeaderFooterPosition horizontal_position, 389 printing::HorizontalHeaderFooterPosition horizontal_position,
390 printing::VerticalHeaderFooterPosition vertical_position, 390 printing::VerticalHeaderFooterPosition vertical_position,
391 double offset_to_baseline) { 391 double offset_to_baseline) {
392 #if defined(USE_SKIA) 392 #if defined(USE_SKIA)
393 size_t text_byte_length = text.length() * sizeof(char16); 393 size_t text_byte_length = text.length() * sizeof(char16);
394 double text_width_in_points = SkScalarToDouble(paint.measureText( 394 double text_width_in_points = SkScalarToDouble(paint.measureText(
395 text.c_str(), text_byte_length)); 395 text.c_str(), text_byte_length));
396 SkPoint point = GetHeaderFooterPosition(webkit_scale_factor, page_layout, 396 SkPoint point = GetHeaderFooterPosition(webkit_scale_factor, page_layout,
397 horizontal_position, 397 horizontal_position,
398 vertical_position, offset_to_baseline, 398 vertical_position, offset_to_baseline,
399 text_width_in_points); 399 text_width_in_points);
400 paint.setTextSize(SkDoubleToScalar( 400 canvas->drawText(text.c_str(), text_byte_length, point.x(), point.y(), paint);
401 paint.getTextSize() / webkit_scale_factor));
402 canvas->drawText(text.c_str(), text_byte_length, point.x(), point.y(),
403 paint);
404 #elif defined(OS_MACOSX) 401 #elif defined(OS_MACOSX)
405 ScopedCFTypeRef<CFStringRef> cf_text(base::SysUTF16ToCFStringRef(text)); 402 ScopedCFTypeRef<CFStringRef> cf_text(base::SysUTF16ToCFStringRef(text));
406 ScopedCFTypeRef<CFAttributedStringRef> cf_attr_text( 403 ScopedCFTypeRef<CFAttributedStringRef> cf_attr_text(
407 CFAttributedStringCreate(NULL, cf_text, paint)); 404 CFAttributedStringCreate(NULL, cf_text, paint));
408 ScopedCFTypeRef<CTLineRef> line(CTLineCreateWithAttributedString( 405 ScopedCFTypeRef<CTLineRef> line(CTLineCreateWithAttributedString(
409 cf_attr_text)); 406 cf_attr_text));
410 double text_width_in_points = 407 double text_width_in_points =
411 CTLineGetTypographicBounds(line, NULL, NULL, NULL) * webkit_scale_factor; 408 CTLineGetTypographicBounds(line, NULL, NULL, NULL) * webkit_scale_factor;
412 SkPoint point = GetHeaderFooterPosition(webkit_scale_factor, 409 SkPoint point = GetHeaderFooterPosition(webkit_scale_factor,
413 page_layout, horizontal_position, 410 page_layout, horizontal_position,
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
478 const PageSizeMargins& page_layout, 475 const PageSizeMargins& page_layout,
479 const DictionaryValue& header_footer_info) { 476 const DictionaryValue& header_footer_info) {
480 #if defined(USE_SKIA) 477 #if defined(USE_SKIA)
481 skia::VectorPlatformDeviceSkia* device = 478 skia::VectorPlatformDeviceSkia* device =
482 static_cast<skia::VectorPlatformDeviceSkia*>(canvas->getTopDevice()); 479 static_cast<skia::VectorPlatformDeviceSkia*>(canvas->getTopDevice());
483 device->setDrawingArea(SkPDFDevice::kMargin_DrawingArea); 480 device->setDrawingArea(SkPDFDevice::kMargin_DrawingArea);
484 481
485 SkPaint paint; 482 SkPaint paint;
486 paint.setColor(SK_ColorBLACK); 483 paint.setColor(SK_ColorBLACK);
487 paint.setTextEncoding(SkPaint::kUTF16_TextEncoding); 484 paint.setTextEncoding(SkPaint::kUTF16_TextEncoding);
488 paint.setTextSize(SkDoubleToScalar(printing::kSettingHeaderFooterFontSize)); 485 paint.setTextSize(SkDoubleToScalar(
486 printing::kSettingHeaderFooterFontSize / webkit_scale_factor));
groby-ooo-7-16 2012/02/13 01:19:34 Are you sure setTextSize can be hoisted up to here
489 paint.setTypeface(SkTypeface::CreateFromName( 487 paint.setTypeface(SkTypeface::CreateFromName(
490 printing::kSettingHeaderFooterFontFamilyName, SkTypeface::kNormal)); 488 printing::kSettingHeaderFooterFontFamilyName, SkTypeface::kNormal));
491 #elif defined(OS_MACOSX) 489 #elif defined(OS_MACOSX)
492 gfx::ScopedCGContextSaveGState CGContextSaveGState(canvas); 490 gfx::ScopedCGContextSaveGState CGContextSaveGState(canvas);
493 CGContextSetCharacterSpacing(canvas, 491 CGContextSetCharacterSpacing(canvas,
494 printing::kSettingHeaderFooterCharacterSpacing); 492 printing::kSettingHeaderFooterCharacterSpacing);
495 CGContextSetTextDrawingMode(canvas, kCGTextFill); 493 CGContextSetTextDrawingMode(canvas, kCGTextFill);
496 CGContextSetGrayFillColor(canvas, kBlackGrayLevel, kOpaqueLevel); 494 CGContextSetGrayFillColor(canvas, kBlackGrayLevel, kOpaqueLevel);
497 CGContextSelectFont(canvas, printing::kSettingHeaderFooterFontName, 495 CGContextSelectFont(canvas, printing::kSettingHeaderFooterFontName,
498 printing::kSettingHeaderFooterFontSize, 496 printing::kSettingHeaderFooterFontSize,
(...skipping 20 matching lines...) Expand all
519 &title) || 517 &title) ||
520 !header_footer_info.GetString(printing::kSettingHeaderFooterDate, 518 !header_footer_info.GetString(printing::kSettingHeaderFooterDate,
521 &date)) { 519 &date)) {
522 NOTREACHED(); 520 NOTREACHED();
523 } 521 }
524 string16 header_text = date + title; 522 string16 header_text = date + title;
525 523
526 // Used for height calculations. Note that the width may be undefined. 524 // Used for height calculations. Note that the width may be undefined.
527 SkRect header_vertical_bounds; 525 SkRect header_vertical_bounds;
528 #if defined(USE_SKIA) 526 #if defined(USE_SKIA)
529 paint.measureText(header_text.c_str(), header_text.length() * sizeof(char16), 527 paint.measureText(header_text.c_str(), header_text.length() * sizeof(char16),
groby-ooo-7-16 2012/02/13 01:19:34 Right here. And I'd assume measureText depends on
530 &header_vertical_bounds, 0); 528 &header_vertical_bounds, 0);
531 #elif defined(OS_MACOSX) 529 #elif defined(OS_MACOSX)
532 header_vertical_bounds.fTop = CTFontGetAscent(ct_font) * webkit_scale_factor; 530 header_vertical_bounds.fTop = CTFontGetAscent(ct_font) * webkit_scale_factor;
533 header_vertical_bounds.fBottom = -CTFontGetDescent(ct_font) * 531 header_vertical_bounds.fBottom = -CTFontGetDescent(ct_font) *
534 webkit_scale_factor; 532 webkit_scale_factor;
535 #endif 533 #endif
536 double text_height = printing::kSettingHeaderFooterInterstice + 534 double text_height = printing::kSettingHeaderFooterInterstice +
537 header_vertical_bounds.height(); 535 header_vertical_bounds.height();
538 if (text_height <= page_layout.margin_top) { 536 if (text_height <= page_layout.margin_top) {
539 PrintHeaderFooterText(date, canvas, paint, webkit_scale_factor, page_layout, 537 PrintHeaderFooterText(date, canvas, paint, webkit_scale_factor, page_layout,
(...skipping 1234 matching lines...) Expand 10 before | Expand all | Expand 10 after
1774 DCHECK(IsRendering()); 1772 DCHECK(IsRendering());
1775 return prep_frame_view_->GetPrintCanvasSize(); 1773 return prep_frame_view_->GetPrintCanvasSize();
1776 } 1774 }
1777 1775
1778 void PrintWebViewHelper::PrintPreviewContext::ClearContext() { 1776 void PrintWebViewHelper::PrintPreviewContext::ClearContext() {
1779 prep_frame_view_.reset(); 1777 prep_frame_view_.reset();
1780 metafile_.reset(); 1778 metafile_.reset();
1781 pages_to_render_.clear(); 1779 pages_to_render_.clear();
1782 error_ = PREVIEW_ERROR_NONE; 1780 error_ = PREVIEW_ERROR_NONE;
1783 } 1781 }
OLDNEW
« no previous file with comments | « chrome/browser/extensions/api/declarative/initializing_rules_registry.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698