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

Side by Side Diff: chrome/browser/ui/views/tabs/tab.cc

Issue 10453101: Convert most of the rest of chrome to ImageSkia (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 6 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/ui/views/tabs/tab.h ('k') | chrome/browser/ui/views/tabs/tab_drag_controller.cc » ('j') | 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/browser/ui/views/tabs/tab.h" 5 #include "chrome/browser/ui/views/tabs/tab.h"
6 6
7 #include <limits> 7 #include <limits>
8 8
9 #include "base/utf_string_conversions.h" 9 #include "base/utf_string_conversions.h"
10 #include "chrome/browser/defaults.h" 10 #include "chrome/browser/defaults.h"
(...skipping 244 matching lines...) Expand 10 before | Expand all | Expand 10 after
255 if (mini_title_animation_.get()) 255 if (mini_title_animation_.get())
256 mini_title_animation_->Stop(); 256 mini_title_animation_->Stop();
257 } 257 }
258 258
259 // static 259 // static
260 gfx::Size Tab::GetBasicMinimumUnselectedSize() { 260 gfx::Size Tab::GetBasicMinimumUnselectedSize() {
261 InitTabResources(); 261 InitTabResources();
262 262
263 gfx::Size minimum_size; 263 gfx::Size minimum_size;
264 minimum_size.set_width(left_padding() + right_padding()); 264 minimum_size.set_width(left_padding() + right_padding());
265 // Since we use bitmap images, the real minimum height of the image is 265 // Since we use image images, the real minimum height of the image is
266 // defined most accurately by the height of the end cap images. 266 // defined most accurately by the height of the end cap images.
267 minimum_size.set_height(tab_active_.image_l->height()); 267 minimum_size.set_height(tab_active_.image_l->height());
268 return minimum_size; 268 return minimum_size;
269 } 269 }
270 270
271 gfx::Size Tab::GetMinimumUnselectedSize() { 271 gfx::Size Tab::GetMinimumUnselectedSize() {
272 return GetBasicMinimumUnselectedSize(); 272 return GetBasicMinimumUnselectedSize();
273 } 273 }
274 274
275 // static 275 // static
(...skipping 235 matching lines...) Expand 10 before | Expand all | Expand 10 after
511 canvas->Restore(); 511 canvas->Restore();
512 } 512 }
513 } 513 }
514 } 514 }
515 515
516 void Tab::PaintInactiveTabBackgroundWithTitleChange(gfx::Canvas* canvas) { 516 void Tab::PaintInactiveTabBackgroundWithTitleChange(gfx::Canvas* canvas) {
517 // Render the inactive tab background. We'll use this for clipping. 517 // Render the inactive tab background. We'll use this for clipping.
518 gfx::Canvas background_canvas(size(), false); 518 gfx::Canvas background_canvas(size(), false);
519 PaintInactiveTabBackground(&background_canvas); 519 PaintInactiveTabBackground(&background_canvas);
520 520
521 SkBitmap background_image = background_canvas.ExtractBitmap(); 521 gfx::ImageSkia background_image = background_canvas.ExtractBitmap();
522 522
523 // Draw a radial gradient to hover_canvas. 523 // Draw a radial gradient to hover_canvas.
524 gfx::Canvas hover_canvas(size(), false); 524 gfx::Canvas hover_canvas(size(), false);
525 int radius = kMiniTitleChangeGradientRadius; 525 int radius = kMiniTitleChangeGradientRadius;
526 int x0 = width() + radius - kMiniTitleChangeInitialXOffset; 526 int x0 = width() + radius - kMiniTitleChangeInitialXOffset;
527 int x1 = radius; 527 int x1 = radius;
528 int x2 = -radius; 528 int x2 = -radius;
529 int x; 529 int x;
530 if (mini_title_animation_->current_part_index() == 0) { 530 if (mini_title_animation_->current_part_index() == 0) {
531 x = mini_title_animation_->CurrentValueBetween(x0, x1); 531 x = mini_title_animation_->CurrentValueBetween(x0, x1);
532 } else if (mini_title_animation_->current_part_index() == 1) { 532 } else if (mini_title_animation_->current_part_index() == 1) {
533 x = x1; 533 x = x1;
534 } else { 534 } else {
535 x = mini_title_animation_->CurrentValueBetween(x1, x2); 535 x = mini_title_animation_->CurrentValueBetween(x1, x2);
536 } 536 }
537 SkPoint center_point; 537 SkPoint center_point;
538 center_point.iset(x, 0); 538 center_point.iset(x, 0);
539 SkColor colors[2] = { kMiniTitleChangeGradientColor1, 539 SkColor colors[2] = { kMiniTitleChangeGradientColor1,
540 kMiniTitleChangeGradientColor2 }; 540 kMiniTitleChangeGradientColor2 };
541 SkShader* shader = SkGradientShader::CreateRadial(center_point, 541 SkShader* shader = SkGradientShader::CreateRadial(center_point,
542 SkIntToScalar(radius), colors, NULL, 2, SkShader::kClamp_TileMode); 542 SkIntToScalar(radius), colors, NULL, 2, SkShader::kClamp_TileMode);
543 SkPaint paint; 543 SkPaint paint;
544 paint.setShader(shader); 544 paint.setShader(shader);
545 shader->unref(); 545 shader->unref();
546 hover_canvas.DrawRect(gfx::Rect(x - radius, -radius, radius * 2, radius * 2), 546 hover_canvas.DrawRect(gfx::Rect(x - radius, -radius, radius * 2, radius * 2),
547 paint); 547 paint);
548 548
549 // Draw the radial gradient clipped to the background into hover_image. 549 // Draw the radial gradient clipped to the background into hover_image.
550 SkBitmap hover_image = SkBitmapOperations::CreateMaskedBitmap( 550 gfx::ImageSkia hover_image = SkBitmapOperations::CreateMaskedBitmap(
551 hover_canvas.ExtractBitmap(), background_image); 551 hover_canvas.ExtractBitmap(), background_image);
552 552
553 // Draw the tab background to the canvas. 553 // Draw the tab background to the canvas.
554 canvas->DrawBitmapInt(background_image, 0, 0); 554 canvas->DrawBitmapInt(background_image, 0, 0);
555 555
556 // And then the gradient on top of that. 556 // And then the gradient on top of that.
557 if (mini_title_animation_->current_part_index() == 2) { 557 if (mini_title_animation_->current_part_index() == 2) {
558 canvas->SaveLayerAlpha(mini_title_animation_->CurrentValueBetween(255, 0)); 558 canvas->SaveLayerAlpha(mini_title_animation_->CurrentValueBetween(255, 0));
559 canvas->DrawBitmapInt(hover_image, 0, 0); 559 canvas->DrawBitmapInt(hover_image, 0, 0);
560 canvas->Restore(); 560 canvas->Restore();
561 } else { 561 } else {
562 canvas->DrawBitmapInt(hover_image, 0, 0); 562 canvas->DrawBitmapInt(hover_image, 0, 0);
563 } 563 }
564 } 564 }
565 565
566 void Tab::PaintInactiveTabBackground(gfx::Canvas* canvas) { 566 void Tab::PaintInactiveTabBackground(gfx::Canvas* canvas) {
567 // The tab image needs to be lined up with the background image 567 // The tab image needs to be lined up with the background image
568 // so that it feels partially transparent. These offsets represent the tab 568 // so that it feels partially transparent. These offsets represent the tab
569 // position within the frame background image. 569 // position within the frame background image.
570 int offset = GetMirroredX() + background_offset_.x(); 570 int offset = GetMirroredX() + background_offset_.x();
571 571
572 int tab_id; 572 int tab_id;
573 if (GetWidget() && GetWidget()->GetTopLevelWidget()->ShouldUseNativeFrame()) { 573 if (GetWidget() && GetWidget()->GetTopLevelWidget()->ShouldUseNativeFrame()) {
574 tab_id = IDR_THEME_TAB_BACKGROUND_V; 574 tab_id = IDR_THEME_TAB_BACKGROUND_V;
575 } else { 575 } else {
576 tab_id = data().incognito ? IDR_THEME_TAB_BACKGROUND_INCOGNITO : 576 tab_id = data().incognito ? IDR_THEME_TAB_BACKGROUND_INCOGNITO :
577 IDR_THEME_TAB_BACKGROUND; 577 IDR_THEME_TAB_BACKGROUND;
578 } 578 }
579 579
580 SkBitmap* tab_bg = GetThemeProvider()->GetBitmapNamed(tab_id); 580 gfx::ImageSkia* tab_bg = GetThemeProvider()->GetImageSkiaNamed(tab_id);
581 581
582 TabImage* tab_image = &tab_active_; 582 TabImage* tab_image = &tab_active_;
583 TabImage* tab_inactive_image = &tab_inactive_; 583 TabImage* tab_inactive_image = &tab_inactive_;
584 TabImage* alpha = &tab_alpha_; 584 TabImage* alpha = &tab_alpha_;
585 585
586 // If the theme is providing a custom background image, then its top edge 586 // If the theme is providing a custom background image, then its top edge
587 // should be at the top of the tab. Otherwise, we assume that the background 587 // should be at the top of the tab. Otherwise, we assume that the background
588 // image is a composited foreground + frame image. 588 // image is a composited foreground + frame image.
589 int bg_offset_y = GetThemeProvider()->HasCustomImage(tab_id) ? 589 int bg_offset_y = GetThemeProvider()->HasCustomImage(tab_id) ?
590 0 : background_offset_.y(); 590 0 : background_offset_.y();
591 591
592 // We need a gfx::Canvas object to be able to extract the bitmap from. 592 // We need a gfx::Canvas object to be able to extract the image from.
593 // We draw everything to this canvas and then output it to the canvas 593 // We draw everything to this canvas and then output it to the canvas
594 // parameter in addition to using it to mask the hover glow if needed. 594 // parameter in addition to using it to mask the hover glow if needed.
595 gfx::Canvas background_canvas(size(), false); 595 gfx::Canvas background_canvas(size(), false);
596 596
597 // Draw left edge. Don't draw over the toolbar, as we're not the foreground 597 // Draw left edge. Don't draw over the toolbar, as we're not the foreground
598 // tab. 598 // tab.
599 SkBitmap tab_l = SkBitmapOperations::CreateTiledBitmap( 599 gfx::ImageSkia tab_l = SkBitmapOperations::CreateTiledBitmap(
600 *tab_bg, offset, bg_offset_y, tab_image->l_width, height()); 600 *tab_bg, offset, bg_offset_y, tab_image->l_width, height());
601 SkBitmap theme_l = 601 gfx::ImageSkia theme_l =
602 SkBitmapOperations::CreateMaskedBitmap(tab_l, *alpha->image_l); 602 SkBitmapOperations::CreateMaskedBitmap(tab_l, *alpha->image_l);
603 background_canvas.DrawBitmapInt(theme_l, 603 background_canvas.DrawBitmapInt(theme_l,
604 0, 0, theme_l.width(), theme_l.height() - kToolbarOverlap, 604 0, 0, theme_l.width(), theme_l.height() - kToolbarOverlap,
605 0, 0, theme_l.width(), theme_l.height() - kToolbarOverlap, 605 0, 0, theme_l.width(), theme_l.height() - kToolbarOverlap,
606 false); 606 false);
607 607
608 // Draw right edge. Again, don't draw over the toolbar. 608 // Draw right edge. Again, don't draw over the toolbar.
609 SkBitmap tab_r = SkBitmapOperations::CreateTiledBitmap(*tab_bg, 609 gfx::ImageSkia tab_r = SkBitmapOperations::CreateTiledBitmap(*tab_bg,
610 offset + width() - tab_image->r_width, bg_offset_y, 610 offset + width() - tab_image->r_width, bg_offset_y,
611 tab_image->r_width, height()); 611 tab_image->r_width, height());
612 SkBitmap theme_r = 612 gfx::ImageSkia theme_r =
613 SkBitmapOperations::CreateMaskedBitmap(tab_r, *alpha->image_r); 613 SkBitmapOperations::CreateMaskedBitmap(tab_r, *alpha->image_r);
614 background_canvas.DrawBitmapInt(theme_r, 614 background_canvas.DrawBitmapInt(theme_r,
615 0, 0, theme_r.width(), theme_r.height() - kToolbarOverlap, 615 0, 0, theme_r.width(), theme_r.height() - kToolbarOverlap,
616 width() - theme_r.width(), 0, theme_r.width(), 616 width() - theme_r.width(), 0, theme_r.width(),
617 theme_r.height() - kToolbarOverlap, false); 617 theme_r.height() - kToolbarOverlap, false);
618 618
619 // Draw center. Instead of masking out the top portion we simply skip over 619 // Draw center. Instead of masking out the top portion we simply skip over
620 // it by incrementing by GetDropShadowHeight(), since it's a simple 620 // it by incrementing by GetDropShadowHeight(), since it's a simple
621 // rectangle. And again, don't draw over the toolbar. 621 // rectangle. And again, don't draw over the toolbar.
622 background_canvas.TileImageInt(*tab_bg, 622 background_canvas.TileImageInt(*tab_bg,
(...skipping 20 matching lines...) Expand all
643 height()); 643 height());
644 canvas->DrawBitmapInt(*tab_inactive_image->image_r, 644 canvas->DrawBitmapInt(*tab_inactive_image->image_r,
645 width() - tab_inactive_image->r_width, 0); 645 width() - tab_inactive_image->r_width, 0);
646 } 646 }
647 647
648 void Tab::PaintActiveTabBackground(gfx::Canvas* canvas) { 648 void Tab::PaintActiveTabBackground(gfx::Canvas* canvas) {
649 int offset = GetMirroredX() + background_offset_.x(); 649 int offset = GetMirroredX() + background_offset_.x();
650 ui::ThemeProvider* tp = GetThemeProvider(); 650 ui::ThemeProvider* tp = GetThemeProvider();
651 DCHECK(tp) << "Unable to get theme provider"; 651 DCHECK(tp) << "Unable to get theme provider";
652 652
653 SkBitmap* tab_bg = GetThemeProvider()->GetBitmapNamed(IDR_THEME_TOOLBAR); 653 gfx::ImageSkia* tab_bg =
654 GetThemeProvider()->GetImageSkiaNamed(IDR_THEME_TOOLBAR);
654 655
655 TabImage* tab_image = &tab_active_; 656 TabImage* tab_image = &tab_active_;
656 TabImage* alpha = &tab_alpha_; 657 TabImage* alpha = &tab_alpha_;
657 658
658 // Draw left edge. 659 // Draw left edge.
659 SkBitmap tab_l = SkBitmapOperations::CreateTiledBitmap( 660 gfx::ImageSkia tab_l = SkBitmapOperations::CreateTiledBitmap(
660 *tab_bg, offset, 0, tab_image->l_width, height()); 661 *tab_bg, offset, 0, tab_image->l_width, height());
661 SkBitmap theme_l = 662 gfx::ImageSkia theme_l =
662 SkBitmapOperations::CreateMaskedBitmap(tab_l, *alpha->image_l); 663 SkBitmapOperations::CreateMaskedBitmap(tab_l, *alpha->image_l);
663 canvas->DrawBitmapInt(theme_l, 0, 0); 664 canvas->DrawBitmapInt(theme_l, 0, 0);
664 665
665 // Draw right edge. 666 // Draw right edge.
666 SkBitmap tab_r = SkBitmapOperations::CreateTiledBitmap(*tab_bg, 667 gfx::ImageSkia tab_r = SkBitmapOperations::CreateTiledBitmap(*tab_bg,
667 offset + width() - tab_image->r_width, 0, tab_image->r_width, height()); 668 offset + width() - tab_image->r_width, 0, tab_image->r_width, height());
668 SkBitmap theme_r = 669 gfx::ImageSkia theme_r =
669 SkBitmapOperations::CreateMaskedBitmap(tab_r, *alpha->image_r); 670 SkBitmapOperations::CreateMaskedBitmap(tab_r, *alpha->image_r);
670 canvas->DrawBitmapInt(theme_r, width() - tab_image->r_width, 0); 671 canvas->DrawBitmapInt(theme_r, width() - tab_image->r_width, 0);
671 672
672 // Draw center. Instead of masking out the top portion we simply skip over it 673 // Draw center. Instead of masking out the top portion we simply skip over it
673 // by incrementing by GetDropShadowHeight(), since it's a simple rectangle. 674 // by incrementing by GetDropShadowHeight(), since it's a simple rectangle.
674 canvas->TileImageInt(*tab_bg, 675 canvas->TileImageInt(*tab_bg,
675 offset + tab_image->l_width, 676 offset + tab_image->l_width,
676 drop_shadow_height() + tab_image->y_offset, 677 drop_shadow_height() + tab_image->y_offset,
677 tab_image->l_width, 678 tab_image->l_width,
678 drop_shadow_height() + tab_image->y_offset, 679 drop_shadow_height() + tab_image->y_offset,
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
739 740
740 // Load the tab images once now, and maybe again later if the theme changes. 741 // Load the tab images once now, and maybe again later if the theme changes.
741 LoadTabImages(); 742 LoadTabImages();
742 } 743 }
743 744
744 // static 745 // static
745 void Tab::LoadTabImages() { 746 void Tab::LoadTabImages() {
746 // We're not letting people override tab images just yet. 747 // We're not letting people override tab images just yet.
747 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); 748 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance();
748 749
749 tab_alpha_.image_l = rb.GetBitmapNamed(IDR_TAB_ALPHA_LEFT); 750 tab_alpha_.image_l = rb.GetImageSkiaNamed(IDR_TAB_ALPHA_LEFT);
750 tab_alpha_.image_r = rb.GetBitmapNamed(IDR_TAB_ALPHA_RIGHT); 751 tab_alpha_.image_r = rb.GetImageSkiaNamed(IDR_TAB_ALPHA_RIGHT);
751 752
752 tab_active_.image_l = rb.GetBitmapNamed(IDR_TAB_ACTIVE_LEFT); 753 tab_active_.image_l = rb.GetImageSkiaNamed(IDR_TAB_ACTIVE_LEFT);
753 tab_active_.image_c = rb.GetBitmapNamed(IDR_TAB_ACTIVE_CENTER); 754 tab_active_.image_c = rb.GetImageSkiaNamed(IDR_TAB_ACTIVE_CENTER);
754 tab_active_.image_r = rb.GetBitmapNamed(IDR_TAB_ACTIVE_RIGHT); 755 tab_active_.image_r = rb.GetImageSkiaNamed(IDR_TAB_ACTIVE_RIGHT);
755 tab_active_.l_width = tab_active_.image_l->width(); 756 tab_active_.l_width = tab_active_.image_l->width();
756 tab_active_.r_width = tab_active_.image_r->width(); 757 tab_active_.r_width = tab_active_.image_r->width();
757 758
758 tab_inactive_.image_l = rb.GetBitmapNamed(IDR_TAB_INACTIVE_LEFT); 759 tab_inactive_.image_l = rb.GetImageSkiaNamed(IDR_TAB_INACTIVE_LEFT);
759 tab_inactive_.image_c = rb.GetBitmapNamed(IDR_TAB_INACTIVE_CENTER); 760 tab_inactive_.image_c = rb.GetImageSkiaNamed(IDR_TAB_INACTIVE_CENTER);
760 tab_inactive_.image_r = rb.GetBitmapNamed(IDR_TAB_INACTIVE_RIGHT); 761 tab_inactive_.image_r = rb.GetImageSkiaNamed(IDR_TAB_INACTIVE_RIGHT);
761 tab_inactive_.l_width = tab_inactive_.image_l->width(); 762 tab_inactive_.l_width = tab_inactive_.image_l->width();
762 tab_inactive_.r_width = tab_inactive_.image_r->width(); 763 tab_inactive_.r_width = tab_inactive_.image_r->width();
763 } 764 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/views/tabs/tab.h ('k') | chrome/browser/ui/views/tabs/tab_drag_controller.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698