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

Side by Side Diff: ui/gfx/canvas_skia_win.cc

Issue 6823020: Fix crash in fade tab title change (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 9 years, 8 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 | « no previous file | 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) 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 "ui/gfx/canvas_skia.h" 5 #include "ui/gfx/canvas_skia.h"
6 6
7 #include <limits> 7 #include <limits>
8 8
9 #include "base/i18n/rtl.h" 9 #include "base/i18n/rtl.h"
10 #include "base/logging.h" 10 #include "base/logging.h"
(...skipping 451 matching lines...) Expand 10 before | Expand all | Expand 10 after
462 const gfx::Font& font, 462 const gfx::Font& font,
463 const SkColor& color, 463 const SkColor& color,
464 const gfx::Rect& display_rect) { 464 const gfx::Rect& display_rect) {
465 int flags = NO_ELLIPSIS; 465 int flags = NO_ELLIPSIS;
466 466
467 // If the whole string fits in the destination then just draw it directly. 467 // If the whole string fits in the destination then just draw it directly.
468 int total_string_width; 468 int total_string_width;
469 int total_string_height; 469 int total_string_height;
470 SizeStringInt(text, font, &total_string_width, &total_string_height, 470 SizeStringInt(text, font, &total_string_width, &total_string_height,
471 flags | TEXT_VALIGN_TOP); 471 flags | TEXT_VALIGN_TOP);
472 if (total_string_width <= display_rect.width()) { 472 bool should_draw_directly = total_string_width <= display_rect.width();
473
474 // Create a temporary bitmap to draw the gradient to.
Peter Kasting 2011/04/09 00:56:44 If this is really just a temporary hack, you shoul
475 scoped_ptr<skia::BitmapPlatformDevice> gradient_bitmap;
476 if (!should_draw_directly) {
477 gradient_bitmap.reset(skia::BitmapPlatformDevice::create(
478 NULL, display_rect.width(), display_rect.height(), false, NULL));
479 should_draw_directly = gradient_bitmap.get() != NULL;
480 }
481
482 if (should_draw_directly) {
473 DrawStringInt(text, font, color, display_rect.x(), display_rect.y(), 483 DrawStringInt(text, font, color, display_rect.x(), display_rect.y(),
474 display_rect.width(), display_rect.height(), flags); 484 display_rect.width(), display_rect.height(), 0);
475 return; 485 return;
476 } 486 }
477 487
478 int average_character_width = font.GetAverageCharacterWidth(); 488 int average_character_width = font.GetAverageCharacterWidth();
479 int clipped_string_width = total_string_width - display_rect.width(); 489 int clipped_string_width = total_string_width - display_rect.width();
480 490
481 // Clip the string by drawing it to the left by |offset_x|. 491 // Clip the string by drawing it to the left by |offset_x|.
482 int offset_x = 0; 492 int offset_x = 0;
483 switch (truncate_mode) { 493 switch (truncate_mode) {
484 case TruncateFadeHead: 494 case TruncateFadeHead:
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
549 text_rect.set_width(text_rect.width() + offset_x); 559 text_rect.set_width(text_rect.width() + offset_x);
550 560
551 // Disable clear type. This makes the text render in gray scale which 561 // Disable clear type. This makes the text render in gray scale which
552 // makes it easier to compute the alpha value. 562 // makes it easier to compute the alpha value.
553 LOGFONT font_info; 563 LOGFONT font_info;
554 GetObject(font.GetNativeFont(), sizeof(font_info), &font_info); 564 GetObject(font.GetNativeFont(), sizeof(font_info), &font_info);
555 font_info.lfQuality = ANTIALIASED_QUALITY; 565 font_info.lfQuality = ANTIALIASED_QUALITY;
556 HFONT gray_scale_font = CreateFontIndirect(&font_info); 566 HFONT gray_scale_font = CreateFontIndirect(&font_info);
557 567
558 HDC hdc = beginPlatformPaint(); 568 HDC hdc = beginPlatformPaint();
559 scoped_ptr<skia::BitmapPlatformDevice> gradient_bitmap(
560 skia::BitmapPlatformDevice::create(NULL, display_rect.width(),
561 display_rect.height(), false, NULL));
562 if (is_truncating_head) 569 if (is_truncating_head)
563 DrawTextGradientPart(hdc, *gradient_bitmap, text, color, gray_scale_font, 570 DrawTextGradientPart(hdc, *gradient_bitmap, text, color, gray_scale_font,
564 text_rect, head_part, is_rtl, flags); 571 text_rect, head_part, is_rtl, flags);
565 if (is_truncating_tail) 572 if (is_truncating_tail)
566 DrawTextGradientPart(hdc, *gradient_bitmap, text, color, gray_scale_font, 573 DrawTextGradientPart(hdc, *gradient_bitmap, text, color, gray_scale_font,
567 text_rect, tail_part, !is_rtl, flags); 574 text_rect, tail_part, !is_rtl, flags);
568 endPlatformPaint(); 575 endPlatformPaint();
569 576
570 // Draw the solid part. 577 // Draw the solid part.
571 save(kClip_SaveFlag); 578 save(kClip_SaveFlag);
572 ClipRectInt(solid_part.x(), solid_part.y(), 579 ClipRectInt(solid_part.x(), solid_part.y(),
573 solid_part.width(), solid_part.height()); 580 solid_part.width(), solid_part.height());
574 DrawStringInt(text, font, color, 581 DrawStringInt(text, font, color,
575 text_rect.x(), text_rect.y(), 582 text_rect.x(), text_rect.y(),
576 text_rect.width(), text_rect.height(), 583 text_rect.width(), text_rect.height(),
577 flags); 584 flags);
578 restore(); 585 restore();
579 restore(); 586 restore();
580 } 587 }
581 588
582 } // namespace gfx 589 } // namespace gfx
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698