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

Side by Side Diff: chrome/browser/views/tabs/tab_renderer.cc

Issue 113443: ChromeCanvas->gfx::Canvas (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: '' Created 11 years, 7 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/views/tabs/tab_renderer.h ('k') | chrome/browser/views/tabs/tab_strip.h » ('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) 2006-2008 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2006-2008 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/views/tabs/tab_renderer.h" 5 #include "chrome/browser/views/tabs/tab_renderer.h"
6 6
7 #include <limits> 7 #include <limits>
8 8
9 #include "app/gfx/chrome_canvas.h" 9 #include "app/gfx/canvas.h"
10 #include "app/gfx/chrome_font.h" 10 #include "app/gfx/font.h"
11 #include "app/l10n_util.h" 11 #include "app/l10n_util.h"
12 #include "app/resource_bundle.h" 12 #include "app/resource_bundle.h"
13 #include "app/win_util.h" 13 #include "app/win_util.h"
14 #include "chrome/browser/browser.h" 14 #include "chrome/browser/browser.h"
15 #include "chrome/browser/browser_theme_provider.h" 15 #include "chrome/browser/browser_theme_provider.h"
16 #include "chrome/browser/profile.h" 16 #include "chrome/browser/profile.h"
17 #include "chrome/browser/tab_contents/tab_contents.h" 17 #include "chrome/browser/tab_contents/tab_contents.h"
18 #include "chrome/browser/tabs/tab_strip_model.h" 18 #include "chrome/browser/tabs/tab_strip_model.h"
19 #include "grit/generated_resources.h" 19 #include "grit/generated_resources.h"
20 #include "grit/theme_resources.h" 20 #include "grit/theme_resources.h"
(...skipping 339 matching lines...) Expand 10 before | Expand all | Expand 10 after
360 //////////////////////////////////////////////////////////////////////////////// 360 ////////////////////////////////////////////////////////////////////////////////
361 // TabRenderer, protected: 361 // TabRenderer, protected:
362 362
363 std::wstring TabRenderer::GetTitle() const { 363 std::wstring TabRenderer::GetTitle() const {
364 return data_.title; 364 return data_.title;
365 } 365 }
366 366
367 //////////////////////////////////////////////////////////////////////////////// 367 ////////////////////////////////////////////////////////////////////////////////
368 // TabRenderer, views::View overrides: 368 // TabRenderer, views::View overrides:
369 369
370 void TabRenderer::Paint(ChromeCanvas* canvas) { 370 void TabRenderer::Paint(gfx::Canvas* canvas) {
371 // Don't paint if we're narrower than we can render correctly. (This should 371 // Don't paint if we're narrower than we can render correctly. (This should
372 // only happen during animations). 372 // only happen during animations).
373 if (width() < GetMinimumUnselectedSize().width()) 373 if (width() < GetMinimumUnselectedSize().width())
374 return; 374 return;
375 375
376 // See if the model changes whether the icons should be painted. 376 // See if the model changes whether the icons should be painted.
377 const bool show_icon = ShouldShowIcon(); 377 const bool show_icon = ShouldShowIcon();
378 const bool show_download_icon = data_.show_download_icon; 378 const bool show_download_icon = data_.show_download_icon;
379 const bool show_close_button = ShouldShowCloseBox(); 379 const bool show_close_button = ShouldShowCloseBox();
380 if (show_icon != showing_icon_ || 380 if (show_icon != showing_icon_ ||
(...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after
548 AnimationEnded(animation); 548 AnimationEnded(animation);
549 } 549 }
550 550
551 void TabRenderer::AnimationEnded(const Animation* animation) { 551 void TabRenderer::AnimationEnded(const Animation* animation) {
552 SchedulePaint(); 552 SchedulePaint();
553 } 553 }
554 554
555 //////////////////////////////////////////////////////////////////////////////// 555 ////////////////////////////////////////////////////////////////////////////////
556 // TabRenderer, private 556 // TabRenderer, private
557 557
558 void TabRenderer::PaintTabBackground(ChromeCanvas* canvas) { 558 void TabRenderer::PaintTabBackground(gfx::Canvas* canvas) {
559 if (IsSelected()) { 559 if (IsSelected()) {
560 // Sometimes detaching a tab quickly can result in the model reporting it 560 // Sometimes detaching a tab quickly can result in the model reporting it
561 // as not being selected, so is_drag_clone_ ensures that we always paint 561 // as not being selected, so is_drag_clone_ ensures that we always paint
562 // the active representation for the dragged tab. 562 // the active representation for the dragged tab.
563 PaintActiveTabBackground(canvas); 563 PaintActiveTabBackground(canvas);
564 } else { 564 } else {
565 // Draw our hover state. 565 // Draw our hover state.
566 Animation* animation = hover_animation_.get(); 566 Animation* animation = hover_animation_.get();
567 if (pulse_animation_->IsAnimating()) 567 if (pulse_animation_->IsAnimating())
568 animation = pulse_animation_.get(); 568 animation = pulse_animation_.get();
569 569
570 PaintInactiveTabBackground(canvas); 570 PaintInactiveTabBackground(canvas);
571 if (animation->GetCurrentValue() > 0) { 571 if (animation->GetCurrentValue() > 0) {
572 SkRect bounds; 572 SkRect bounds;
573 bounds.set(0, 0, SkIntToScalar(width()), SkIntToScalar(height())); 573 bounds.set(0, 0, SkIntToScalar(width()), SkIntToScalar(height()));
574 canvas->saveLayerAlpha(&bounds, 574 canvas->saveLayerAlpha(&bounds,
575 static_cast<int>(animation->GetCurrentValue() * kHoverOpacity * 0xff), 575 static_cast<int>(animation->GetCurrentValue() * kHoverOpacity * 0xff),
576 SkCanvas::kARGB_ClipLayer_SaveFlag); 576 SkCanvas::kARGB_ClipLayer_SaveFlag);
577 canvas->drawARGB(0, 255, 255, 255, SkPorterDuff::kClear_Mode); 577 canvas->drawARGB(0, 255, 255, 255, SkPorterDuff::kClear_Mode);
578 PaintActiveTabBackground(canvas); 578 PaintActiveTabBackground(canvas);
579 canvas->restore(); 579 canvas->restore();
580 } 580 }
581 } 581 }
582 } 582 }
583 583
584 void TabRenderer::PaintInactiveTabBackground(ChromeCanvas* canvas) { 584 void TabRenderer::PaintInactiveTabBackground(gfx::Canvas* canvas) {
585 bool is_otr = data_.off_the_record; 585 bool is_otr = data_.off_the_record;
586 586
587 // The tab image needs to be lined up with the background image 587 // The tab image needs to be lined up with the background image
588 // so that it feels partially transparent. 588 // so that it feels partially transparent.
589 int offset = GetX(views::View::APPLY_MIRRORING_TRANSFORMATION) + 1; 589 int offset = GetX(views::View::APPLY_MIRRORING_TRANSFORMATION) + 1;
590 int offset_y = 20; 590 int offset_y = 20;
591 591
592 int tab_id; 592 int tab_id;
593 if (GetWidget() && 593 if (GetWidget() &&
594 GetWidget()->GetWindow()->GetNonClientView()->UseNativeFrame()) { 594 GetWidget()->GetWindow()->GetNonClientView()->UseNativeFrame()) {
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
631 631
632 canvas->DrawBitmapInt(*tab_inactive.image_l, 0, 0); 632 canvas->DrawBitmapInt(*tab_inactive.image_l, 0, 0);
633 canvas->TileImageInt(*tab_inactive.image_c, 633 canvas->TileImageInt(*tab_inactive.image_c,
634 tab_inactive.l_width, 0, 634 tab_inactive.l_width, 0,
635 width() - tab_inactive.l_width - tab_inactive.r_width, 635 width() - tab_inactive.l_width - tab_inactive.r_width,
636 height()); 636 height());
637 canvas->DrawBitmapInt(*tab_inactive.image_r, 637 canvas->DrawBitmapInt(*tab_inactive.image_r,
638 width() - tab_inactive.r_width, 0); 638 width() - tab_inactive.r_width, 0);
639 } 639 }
640 640
641 void TabRenderer::PaintActiveTabBackground(ChromeCanvas* canvas) { 641 void TabRenderer::PaintActiveTabBackground(gfx::Canvas* canvas) {
642 int offset = GetX(views::View::APPLY_MIRRORING_TRANSFORMATION) + 1; 642 int offset = GetX(views::View::APPLY_MIRRORING_TRANSFORMATION) + 1;
643 ThemeProvider* tp = GetThemeProvider(); 643 ThemeProvider* tp = GetThemeProvider();
644 if (!tp) 644 if (!tp)
645 NOTREACHED() << "Unable to get theme provider"; 645 NOTREACHED() << "Unable to get theme provider";
646 646
647 SkBitmap* tab_bg = GetThemeProvider()->GetBitmapNamed(IDR_THEME_TOOLBAR); 647 SkBitmap* tab_bg = GetThemeProvider()->GetBitmapNamed(IDR_THEME_TOOLBAR);
648 648
649 // Draw left edge. 649 // Draw left edge.
650 SkBitmap tab_l = skia::ImageOperations::CreateTiledBitmap( 650 SkBitmap tab_l = skia::ImageOperations::CreateTiledBitmap(
651 *tab_bg, offset, 0, tab_active.l_width, height()); 651 *tab_bg, offset, 0, tab_active.l_width, height());
(...skipping 15 matching lines...) Expand all
667 offset + tab_active.l_width, 2, 667 offset + tab_active.l_width, 2,
668 tab_active.l_width, 2, 668 tab_active.l_width, 2,
669 width() - tab_active.l_width - tab_active.r_width, height() - 2); 669 width() - tab_active.l_width - tab_active.r_width, height() - 2);
670 670
671 canvas->DrawBitmapInt(*tab_active.image_l, 0, 0); 671 canvas->DrawBitmapInt(*tab_active.image_l, 0, 0);
672 canvas->TileImageInt(*tab_active.image_c, tab_active.l_width, 0, 672 canvas->TileImageInt(*tab_active.image_c, tab_active.l_width, 0,
673 width() - tab_active.l_width - tab_active.r_width, height()); 673 width() - tab_active.l_width - tab_active.r_width, height());
674 canvas->DrawBitmapInt(*tab_active.image_r, width() - tab_active.r_width, 0); 674 canvas->DrawBitmapInt(*tab_active.image_r, width() - tab_active.r_width, 0);
675 } 675 }
676 676
677 void TabRenderer::PaintHoverTabBackground(ChromeCanvas* canvas, 677 void TabRenderer::PaintHoverTabBackground(gfx::Canvas* canvas,
678 double opacity) { 678 double opacity) {
679 bool is_otr = data_.off_the_record; 679 bool is_otr = data_.off_the_record;
680 SkBitmap left = skia::ImageOperations::CreateBlendedBitmap( 680 SkBitmap left = skia::ImageOperations::CreateBlendedBitmap(
681 *tab_inactive.image_l, *tab_active.image_l, opacity); 681 *tab_inactive.image_l, *tab_active.image_l, opacity);
682 SkBitmap center = skia::ImageOperations::CreateBlendedBitmap( 682 SkBitmap center = skia::ImageOperations::CreateBlendedBitmap(
683 *tab_inactive.image_c, *tab_active.image_c, opacity); 683 *tab_inactive.image_c, *tab_active.image_c, opacity);
684 SkBitmap right = skia::ImageOperations::CreateBlendedBitmap( 684 SkBitmap right = skia::ImageOperations::CreateBlendedBitmap(
685 *tab_inactive.image_r, *tab_active.image_r, opacity); 685 *tab_inactive.image_r, *tab_active.image_r, opacity);
686 686
687 canvas->DrawBitmapInt(left, 0, 0); 687 canvas->DrawBitmapInt(left, 0, 0);
688 canvas->TileImageInt(center, tab_active.l_width, 0, 688 canvas->TileImageInt(center, tab_active.l_width, 0,
689 width() - tab_active.l_width - tab_active.r_width, height()); 689 width() - tab_active.l_width - tab_active.r_width, height());
690 canvas->DrawBitmapInt(right, width() - tab_active.r_width, 0); 690 canvas->DrawBitmapInt(right, width() - tab_active.r_width, 0);
691 } 691 }
692 692
693 void TabRenderer::PaintLoadingAnimation(ChromeCanvas* canvas) { 693 void TabRenderer::PaintLoadingAnimation(gfx::Canvas* canvas) {
694 SkBitmap* frames = (animation_state_ == ANIMATION_WAITING) ? 694 SkBitmap* frames = (animation_state_ == ANIMATION_WAITING) ?
695 waiting_animation_frames : loading_animation_frames; 695 waiting_animation_frames : loading_animation_frames;
696 int image_size = frames->height(); 696 int image_size = frames->height();
697 int image_offset = animation_frame_ * image_size; 697 int image_offset = animation_frame_ * image_size;
698 int dst_y = (height() - image_size) / 2; 698 int dst_y = (height() - image_size) / 2;
699 699
700 // Just like with the Tab's title and favicon, the position for the page 700 // Just like with the Tab's title and favicon, the position for the page
701 // loading animation also needs to be mirrored if the View's UI layout is 701 // loading animation also needs to be mirrored if the View's UI layout is
702 // right-to-left. 702 // right-to-left.
703 int dst_x; 703 int dst_x;
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
783 tab_inactive.image_l = rb.GetBitmapNamed(IDR_TAB_INACTIVE_LEFT); 783 tab_inactive.image_l = rb.GetBitmapNamed(IDR_TAB_INACTIVE_LEFT);
784 tab_inactive.image_c = rb.GetBitmapNamed(IDR_TAB_INACTIVE_CENTER); 784 tab_inactive.image_c = rb.GetBitmapNamed(IDR_TAB_INACTIVE_CENTER);
785 tab_inactive.image_r = rb.GetBitmapNamed(IDR_TAB_INACTIVE_RIGHT); 785 tab_inactive.image_r = rb.GetBitmapNamed(IDR_TAB_INACTIVE_RIGHT);
786 786
787 tab_inactive.l_width = tab_inactive.image_l->width(); 787 tab_inactive.l_width = tab_inactive.image_l->width();
788 tab_inactive.r_width = tab_inactive.image_r->width(); 788 tab_inactive.r_width = tab_inactive.image_r->width();
789 789
790 loading_animation_frames = rb.GetBitmapNamed(IDR_THROBBER); 790 loading_animation_frames = rb.GetBitmapNamed(IDR_THROBBER);
791 waiting_animation_frames = rb.GetBitmapNamed(IDR_THROBBER_WAITING); 791 waiting_animation_frames = rb.GetBitmapNamed(IDR_THROBBER_WAITING);
792 } 792 }
OLDNEW
« no previous file with comments | « chrome/browser/views/tabs/tab_renderer.h ('k') | chrome/browser/views/tabs/tab_strip.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698