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/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 475 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
486 } | 486 } |
487 | 487 |
488 void Tab::OnMouseMoved(const views::MouseEvent& event) { | 488 void Tab::OnMouseMoved(const views::MouseEvent& event) { |
489 hover_controller().SetLocation(event.location()); | 489 hover_controller().SetLocation(event.location()); |
490 BaseTab::OnMouseMoved(event); | 490 BaseTab::OnMouseMoved(event); |
491 } | 491 } |
492 | 492 |
493 //////////////////////////////////////////////////////////////////////////////// | 493 //////////////////////////////////////////////////////////////////////////////// |
494 // Tab, private | 494 // Tab, private |
495 | 495 |
| 496 gfx::ImageSkia* Tab::GetTabBackgroundImage( |
| 497 chrome::search::Mode::Type mode) const { |
| 498 ui::ThemeProvider* tp = GetThemeProvider(); |
| 499 if (!tp) { |
| 500 DCHECK(tp) << "Unable to get theme provider"; |
| 501 return NULL; |
| 502 } |
| 503 |
| 504 if (!controller() || !controller()->IsInstantExtendedAPIEnabled()) |
| 505 return tp->GetImageSkiaNamed(IDR_THEME_TOOLBAR); |
| 506 |
| 507 switch (mode) { |
| 508 case chrome::search::Mode::MODE_NTP: |
| 509 return tp->GetImageSkiaNamed(IDR_THEME_NTP_BACKGROUND); |
| 510 |
| 511 case chrome::search::Mode::MODE_SEARCH: |
| 512 case chrome::search::Mode::MODE_DEFAULT: |
| 513 default: |
| 514 return tp->GetImageSkiaNamed(IDR_THEME_TOOLBAR_SEARCH); |
| 515 } |
| 516 } |
| 517 |
496 void Tab::PaintTabBackground(gfx::Canvas* canvas) { | 518 void Tab::PaintTabBackground(gfx::Canvas* canvas) { |
497 if (IsActive()) { | 519 if (IsActive()) { |
498 PaintActiveTabBackground(canvas); | 520 bool fading_in = false; |
| 521 // If mode is SEARCH, we might be waiting to fade in or fading in new |
| 522 // background, in which case, the previous background needs to be painted. |
| 523 if (data().mode == chrome::search::Mode::MODE_SEARCH && |
| 524 data().background_state & |
| 525 chrome::search::ToolbarSearchAnimator::BACKGROUND_STATE_NTP) { |
| 526 // Paint background for NTP mode. |
| 527 PaintActiveTabBackground(canvas, |
| 528 GetTabBackgroundImage(chrome::search::Mode::MODE_NTP)); |
| 529 // We're done if we're not showing background for |MODE_SEARCH|. |
| 530 if (!(data().background_state & chrome::search::ToolbarSearchAnimator:: |
| 531 BACKGROUND_STATE_SEARCH)) { |
| 532 return; |
| 533 } |
| 534 // Otherwise, we're fading in the background for |MODE_SEARCH| at |
| 535 // |data().search_background_opacity|. |
| 536 fading_in = true; |
| 537 canvas->SaveLayerAlpha( |
| 538 static_cast<uint8>(data().search_background_opacity * 0xFF), |
| 539 gfx::Rect(width(), height())); |
| 540 } |
| 541 // Paint the background for the current mode. |
| 542 PaintActiveTabBackground(canvas, GetTabBackgroundImage(data().mode)); |
| 543 // If we're fading in and have saved canvas, restore it now. |
| 544 if (fading_in) |
| 545 canvas->Restore(); |
499 } else { | 546 } else { |
500 if (mini_title_animation_.get() && mini_title_animation_->is_animating()) | 547 if (mini_title_animation_.get() && mini_title_animation_->is_animating()) |
501 PaintInactiveTabBackgroundWithTitleChange(canvas); | 548 PaintInactiveTabBackgroundWithTitleChange(canvas); |
502 else | 549 else |
503 PaintInactiveTabBackground(canvas); | 550 PaintInactiveTabBackground(canvas); |
504 | 551 |
505 double throb_value = GetThrobValue(); | 552 double throb_value = GetThrobValue(); |
506 if (throb_value > 0) { | 553 if (throb_value > 0) { |
507 canvas->SaveLayerAlpha(static_cast<int>(throb_value * 0xff), | 554 canvas->SaveLayerAlpha(static_cast<int>(throb_value * 0xff), |
508 gfx::Rect(width(), height())); | 555 gfx::Rect(width(), height())); |
509 canvas->sk_canvas()->drawARGB(0, 255, 255, 255, SkXfermode::kClear_Mode); | 556 canvas->sk_canvas()->drawARGB(0, 255, 255, 255, SkXfermode::kClear_Mode); |
510 PaintActiveTabBackground(canvas); | 557 PaintActiveTabBackground(canvas, GetTabBackgroundImage(data().mode)); |
511 canvas->Restore(); | 558 canvas->Restore(); |
512 } | 559 } |
513 } | 560 } |
514 } | 561 } |
515 | 562 |
516 void Tab::PaintInactiveTabBackgroundWithTitleChange(gfx::Canvas* canvas) { | 563 void Tab::PaintInactiveTabBackgroundWithTitleChange(gfx::Canvas* canvas) { |
517 // Render the inactive tab background. We'll use this for clipping. | 564 // Render the inactive tab background. We'll use this for clipping. |
518 gfx::Canvas background_canvas(size(), false); | 565 gfx::Canvas background_canvas(size(), false); |
519 PaintInactiveTabBackground(&background_canvas); | 566 PaintInactiveTabBackground(&background_canvas); |
520 | 567 |
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
638 canvas->DrawImageInt(*tab_inactive_image->image_l, 0, 0); | 685 canvas->DrawImageInt(*tab_inactive_image->image_l, 0, 0); |
639 canvas->TileImageInt(*tab_inactive_image->image_c, | 686 canvas->TileImageInt(*tab_inactive_image->image_c, |
640 tab_inactive_image->l_width, 0, | 687 tab_inactive_image->l_width, 0, |
641 width() - tab_inactive_image->l_width - | 688 width() - tab_inactive_image->l_width - |
642 tab_inactive_image->r_width, | 689 tab_inactive_image->r_width, |
643 height()); | 690 height()); |
644 canvas->DrawImageInt(*tab_inactive_image->image_r, | 691 canvas->DrawImageInt(*tab_inactive_image->image_r, |
645 width() - tab_inactive_image->r_width, 0); | 692 width() - tab_inactive_image->r_width, 0); |
646 } | 693 } |
647 | 694 |
648 void Tab::PaintActiveTabBackground(gfx::Canvas* canvas) { | 695 void Tab::PaintActiveTabBackground(gfx::Canvas* canvas, |
| 696 gfx::ImageSkia* tab_background) { |
| 697 DCHECK(tab_background); |
| 698 |
649 int offset = GetMirroredX() + background_offset_.x(); | 699 int offset = GetMirroredX() + background_offset_.x(); |
650 ui::ThemeProvider* tp = GetThemeProvider(); | |
651 DCHECK(tp) << "Unable to get theme provider"; | |
652 | |
653 gfx::ImageSkia* tab_bg = | |
654 GetThemeProvider()->GetImageSkiaNamed(IDR_THEME_TOOLBAR); | |
655 | 700 |
656 TabImage* tab_image = &tab_active_; | 701 TabImage* tab_image = &tab_active_; |
657 TabImage* alpha = &tab_alpha_; | 702 TabImage* alpha = &tab_alpha_; |
658 | 703 |
659 // Draw left edge. | 704 // Draw left edge. |
660 gfx::ImageSkia tab_l = SkBitmapOperations::CreateTiledBitmap( | 705 gfx::ImageSkia tab_l = SkBitmapOperations::CreateTiledBitmap( |
661 *tab_bg, offset, 0, tab_image->l_width, height()); | 706 *tab_background, offset, 0, tab_image->l_width, height()); |
662 gfx::ImageSkia theme_l = | 707 gfx::ImageSkia theme_l = |
663 SkBitmapOperations::CreateMaskedBitmap(tab_l, *alpha->image_l); | 708 SkBitmapOperations::CreateMaskedBitmap(tab_l, *alpha->image_l); |
664 canvas->DrawImageInt(theme_l, 0, 0); | 709 canvas->DrawImageInt(theme_l, 0, 0); |
665 | 710 |
666 // Draw right edge. | 711 // Draw right edge. |
667 gfx::ImageSkia tab_r = SkBitmapOperations::CreateTiledBitmap(*tab_bg, | 712 gfx::ImageSkia tab_r = SkBitmapOperations::CreateTiledBitmap(*tab_background, |
668 offset + width() - tab_image->r_width, 0, tab_image->r_width, height()); | 713 offset + width() - tab_image->r_width, 0, tab_image->r_width, height()); |
669 gfx::ImageSkia theme_r = | 714 gfx::ImageSkia theme_r = |
670 SkBitmapOperations::CreateMaskedBitmap(tab_r, *alpha->image_r); | 715 SkBitmapOperations::CreateMaskedBitmap(tab_r, *alpha->image_r); |
671 canvas->DrawImageInt(theme_r, width() - tab_image->r_width, 0); | 716 canvas->DrawImageInt(theme_r, width() - tab_image->r_width, 0); |
672 | 717 |
673 // Draw center. Instead of masking out the top portion we simply skip over it | 718 // Draw center. Instead of masking out the top portion we simply skip over it |
674 // by incrementing by GetDropShadowHeight(), since it's a simple rectangle. | 719 // by incrementing by GetDropShadowHeight(), since it's a simple rectangle. |
675 canvas->TileImageInt(*tab_bg, | 720 canvas->TileImageInt(*tab_background, |
676 offset + tab_image->l_width, | 721 offset + tab_image->l_width, |
677 drop_shadow_height() + tab_image->y_offset, | 722 drop_shadow_height() + tab_image->y_offset, |
678 tab_image->l_width, | 723 tab_image->l_width, |
679 drop_shadow_height() + tab_image->y_offset, | 724 drop_shadow_height() + tab_image->y_offset, |
680 width() - tab_image->l_width - tab_image->r_width, | 725 width() - tab_image->l_width - tab_image->r_width, |
681 height() - drop_shadow_height() - tab_image->y_offset); | 726 height() - drop_shadow_height() - tab_image->y_offset); |
682 | 727 |
683 // Now draw the highlights/shadows around the tab edge. | 728 // Now draw the highlights/shadows around the tab edge. |
684 canvas->DrawImageInt(*tab_image->image_l, 0, 0); | 729 canvas->DrawImageInt(*tab_image->image_l, 0, 0); |
685 canvas->TileImageInt(*tab_image->image_c, tab_image->l_width, 0, | 730 canvas->TileImageInt(*tab_image->image_c, tab_image->l_width, 0, |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
755 tab_active_.image_r = rb.GetImageSkiaNamed(IDR_TAB_ACTIVE_RIGHT); | 800 tab_active_.image_r = rb.GetImageSkiaNamed(IDR_TAB_ACTIVE_RIGHT); |
756 tab_active_.l_width = tab_active_.image_l->width(); | 801 tab_active_.l_width = tab_active_.image_l->width(); |
757 tab_active_.r_width = tab_active_.image_r->width(); | 802 tab_active_.r_width = tab_active_.image_r->width(); |
758 | 803 |
759 tab_inactive_.image_l = rb.GetImageSkiaNamed(IDR_TAB_INACTIVE_LEFT); | 804 tab_inactive_.image_l = rb.GetImageSkiaNamed(IDR_TAB_INACTIVE_LEFT); |
760 tab_inactive_.image_c = rb.GetImageSkiaNamed(IDR_TAB_INACTIVE_CENTER); | 805 tab_inactive_.image_c = rb.GetImageSkiaNamed(IDR_TAB_INACTIVE_CENTER); |
761 tab_inactive_.image_r = rb.GetImageSkiaNamed(IDR_TAB_INACTIVE_RIGHT); | 806 tab_inactive_.image_r = rb.GetImageSkiaNamed(IDR_TAB_INACTIVE_RIGHT); |
762 tab_inactive_.l_width = tab_inactive_.image_l->width(); | 807 tab_inactive_.l_width = tab_inactive_.image_l->width(); |
763 tab_inactive_.r_width = tab_inactive_.image_r->width(); | 808 tab_inactive_.r_width = tab_inactive_.image_r->width(); |
764 } | 809 } |
OLD | NEW |