| OLD | NEW |
| 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 "chrome/browser/ui/gtk/tabs/tab_renderer_gtk.h" | 5 #include "chrome/browser/ui/gtk/tabs/tab_renderer_gtk.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <utility> | 8 #include <utility> |
| 9 | 9 |
| 10 #include "base/utf_string_conversions.h" | 10 #include "base/utf_string_conversions.h" |
| (...skipping 432 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 443 minimum_size.set_width(kLeftPadding + kRightPadding); | 443 minimum_size.set_width(kLeftPadding + kRightPadding); |
| 444 // Since we use bitmap images, the real minimum height of the image is | 444 // Since we use bitmap images, the real minimum height of the image is |
| 445 // defined most accurately by the height of the end cap images. | 445 // defined most accurately by the height of the end cap images. |
| 446 minimum_size.set_height(tab_active_.image_l->height() - kToolbarOverlap); | 446 minimum_size.set_height(tab_active_.image_l->height() - kToolbarOverlap); |
| 447 return minimum_size; | 447 return minimum_size; |
| 448 } | 448 } |
| 449 | 449 |
| 450 // static | 450 // static |
| 451 gfx::Size TabRendererGtk::GetMinimumSelectedSize() { | 451 gfx::Size TabRendererGtk::GetMinimumSelectedSize() { |
| 452 gfx::Size minimum_size = GetMinimumUnselectedSize(); | 452 gfx::Size minimum_size = GetMinimumUnselectedSize(); |
| 453 minimum_size.set_width(kLeftPadding + kFavIconSize + kRightPadding); | 453 minimum_size.set_width(kLeftPadding + kFaviconSize + kRightPadding); |
| 454 return minimum_size; | 454 return minimum_size; |
| 455 } | 455 } |
| 456 | 456 |
| 457 // static | 457 // static |
| 458 gfx::Size TabRendererGtk::GetStandardSize() { | 458 gfx::Size TabRendererGtk::GetStandardSize() { |
| 459 gfx::Size standard_size = GetMinimumUnselectedSize(); | 459 gfx::Size standard_size = GetMinimumUnselectedSize(); |
| 460 standard_size.Enlarge(kFavIconTitleSpacing + kStandardTitleWidth, 0); | 460 standard_size.Enlarge(kFavIconTitleSpacing + kStandardTitleWidth, 0); |
| 461 return standard_size; | 461 return standard_size; |
| 462 } | 462 } |
| 463 | 463 |
| 464 // static | 464 // static |
| 465 int TabRendererGtk::GetMiniWidth() { | 465 int TabRendererGtk::GetMiniWidth() { |
| 466 return browser_defaults::kMiniTabWidth; | 466 return browser_defaults::kMiniTabWidth; |
| 467 } | 467 } |
| 468 | 468 |
| 469 // static | 469 // static |
| 470 int TabRendererGtk::GetContentHeight() { | 470 int TabRendererGtk::GetContentHeight() { |
| 471 // The height of the content of the Tab is the largest of the favicon, | 471 // The height of the content of the Tab is the largest of the favicon, |
| 472 // the title text and the close button graphic. | 472 // the title text and the close button graphic. |
| 473 int content_height = std::max(kFavIconSize, title_font_height_); | 473 int content_height = std::max(kFaviconSize, title_font_height_); |
| 474 return std::max(content_height, close_button_height_); | 474 return std::max(content_height, close_button_height_); |
| 475 } | 475 } |
| 476 | 476 |
| 477 // static | 477 // static |
| 478 void TabRendererGtk::LoadTabImages() { | 478 void TabRendererGtk::LoadTabImages() { |
| 479 ResourceBundle& rb = ResourceBundle::GetSharedInstance(); | 479 ResourceBundle& rb = ResourceBundle::GetSharedInstance(); |
| 480 | 480 |
| 481 tab_alpha_.image_l = rb.GetBitmapNamed(IDR_TAB_ALPHA_LEFT); | 481 tab_alpha_.image_l = rb.GetBitmapNamed(IDR_TAB_ALPHA_LEFT); |
| 482 tab_alpha_.image_r = rb.GetBitmapNamed(IDR_TAB_ALPHA_RIGHT); | 482 tab_alpha_.image_r = rb.GetBitmapNamed(IDR_TAB_ALPHA_RIGHT); |
| 483 | 483 |
| (...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 664 if (local_bounds.IsEmpty()) | 664 if (local_bounds.IsEmpty()) |
| 665 return; | 665 return; |
| 666 local_bounds.Inset(kLeftPadding, kTopPadding, kRightPadding, kBottomPadding); | 666 local_bounds.Inset(kLeftPadding, kTopPadding, kRightPadding, kBottomPadding); |
| 667 | 667 |
| 668 // Figure out who is tallest. | 668 // Figure out who is tallest. |
| 669 int content_height = GetContentHeight(); | 669 int content_height = GetContentHeight(); |
| 670 | 670 |
| 671 // Size the Favicon. | 671 // Size the Favicon. |
| 672 showing_icon_ = ShouldShowIcon(); | 672 showing_icon_ = ShouldShowIcon(); |
| 673 if (showing_icon_) { | 673 if (showing_icon_) { |
| 674 int favicon_top = kTopPadding + (content_height - kFavIconSize) / 2; | 674 int favicon_top = kTopPadding + (content_height - kFaviconSize) / 2; |
| 675 favicon_bounds_.SetRect(local_bounds.x(), favicon_top, | 675 favicon_bounds_.SetRect(local_bounds.x(), favicon_top, |
| 676 kFavIconSize, kFavIconSize); | 676 kFaviconSize, kFaviconSize); |
| 677 if ((mini() || data_.animating_mini_change) && | 677 if ((mini() || data_.animating_mini_change) && |
| 678 bounds_.width() < kMiniTabRendererAsNormalTabWidth) { | 678 bounds_.width() < kMiniTabRendererAsNormalTabWidth) { |
| 679 int mini_delta = kMiniTabRendererAsNormalTabWidth - GetMiniWidth(); | 679 int mini_delta = kMiniTabRendererAsNormalTabWidth - GetMiniWidth(); |
| 680 int ideal_delta = bounds_.width() - GetMiniWidth(); | 680 int ideal_delta = bounds_.width() - GetMiniWidth(); |
| 681 if (ideal_delta < mini_delta) { | 681 if (ideal_delta < mini_delta) { |
| 682 int ideal_x = (GetMiniWidth() - kFavIconSize) / 2; | 682 int ideal_x = (GetMiniWidth() - kFaviconSize) / 2; |
| 683 int x = favicon_bounds_.x() + static_cast<int>( | 683 int x = favicon_bounds_.x() + static_cast<int>( |
| 684 (1 - static_cast<float>(ideal_delta) / | 684 (1 - static_cast<float>(ideal_delta) / |
| 685 static_cast<float>(mini_delta)) * | 685 static_cast<float>(mini_delta)) * |
| 686 (ideal_x - favicon_bounds_.x())); | 686 (ideal_x - favicon_bounds_.x())); |
| 687 favicon_bounds_.set_x(x); | 687 favicon_bounds_.set_x(x); |
| 688 } | 688 } |
| 689 } | 689 } |
| 690 } else { | 690 } else { |
| 691 favicon_bounds_.SetRect(local_bounds.x(), local_bounds.y(), 0, 0); | 691 favicon_bounds_.SetRect(local_bounds.x(), local_bounds.y(), 0, 0); |
| 692 } | 692 } |
| (...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 826 PaintLoadingAnimation(canvas); | 826 PaintLoadingAnimation(canvas); |
| 827 } else { | 827 } else { |
| 828 canvas->Save(); | 828 canvas->Save(); |
| 829 canvas->ClipRectInt(0, 0, width(), height() - kFavIconTitleSpacing); | 829 canvas->ClipRectInt(0, 0, width(), height() - kFavIconTitleSpacing); |
| 830 if (should_display_crashed_favicon_) { | 830 if (should_display_crashed_favicon_) { |
| 831 canvas->DrawBitmapInt(*crashed_fav_icon, 0, 0, | 831 canvas->DrawBitmapInt(*crashed_fav_icon, 0, 0, |
| 832 crashed_fav_icon->width(), | 832 crashed_fav_icon->width(), |
| 833 crashed_fav_icon->height(), | 833 crashed_fav_icon->height(), |
| 834 favicon_bounds_.x(), | 834 favicon_bounds_.x(), |
| 835 favicon_bounds_.y() + fav_icon_hiding_offset_, | 835 favicon_bounds_.y() + fav_icon_hiding_offset_, |
| 836 kFavIconSize, kFavIconSize, | 836 kFaviconSize, kFaviconSize, |
| 837 true); | 837 true); |
| 838 } else { | 838 } else { |
| 839 if (!data_.favicon.isNull()) { | 839 if (!data_.favicon.isNull()) { |
| 840 if (data_.is_default_favicon && theme_provider_->UseGtkTheme()) { | 840 if (data_.is_default_favicon && theme_provider_->UseGtkTheme()) { |
| 841 GdkPixbuf* favicon = GtkThemeProvider::GetDefaultFavicon(true); | 841 GdkPixbuf* favicon = GtkThemeProvider::GetDefaultFavicon(true); |
| 842 canvas->AsCanvasSkia()->DrawGdkPixbuf( | 842 canvas->AsCanvasSkia()->DrawGdkPixbuf( |
| 843 favicon, favicon_bounds_.x(), | 843 favicon, favicon_bounds_.x(), |
| 844 favicon_bounds_.y() + fav_icon_hiding_offset_); | 844 favicon_bounds_.y() + fav_icon_hiding_offset_); |
| 845 } else { | 845 } else { |
| 846 // If the favicon is an app icon, it is allowed to be drawn slightly | 846 // If the favicon is an app icon, it is allowed to be drawn slightly |
| 847 // larger than the standard favicon. | 847 // larger than the standard favicon. |
| 848 int favIconHeightOffset = data_.app ? -2 : 0; | 848 int favIconHeightOffset = data_.app ? -2 : 0; |
| 849 int favIconWidthDelta = data_.app ? | 849 int favIconWidthDelta = data_.app ? |
| 850 data_.favicon.width() - kFavIconSize : 0; | 850 data_.favicon.width() - kFaviconSize : 0; |
| 851 int favIconHeightDelta = data_.app ? | 851 int favIconHeightDelta = data_.app ? |
| 852 data_.favicon.height() - kFavIconSize : 0; | 852 data_.favicon.height() - kFaviconSize : 0; |
| 853 | 853 |
| 854 // TODO(pkasting): Use code in tab_icon_view.cc:PaintIcon() (or switch | 854 // TODO(pkasting): Use code in tab_icon_view.cc:PaintIcon() (or switch |
| 855 // to using that class to render the favicon). | 855 // to using that class to render the favicon). |
| 856 canvas->DrawBitmapInt(data_.favicon, 0, 0, | 856 canvas->DrawBitmapInt(data_.favicon, 0, 0, |
| 857 data_.favicon.width(), | 857 data_.favicon.width(), |
| 858 data_.favicon.height(), | 858 data_.favicon.height(), |
| 859 favicon_bounds_.x() - favIconWidthDelta/2, | 859 favicon_bounds_.x() - favIconWidthDelta/2, |
| 860 favicon_bounds_.y() + favIconHeightOffset | 860 favicon_bounds_.y() + favIconHeightOffset |
| 861 - favIconHeightDelta/2 | 861 - favIconHeightDelta/2 |
| 862 + fav_icon_hiding_offset_, | 862 + fav_icon_hiding_offset_, |
| 863 kFavIconSize + favIconWidthDelta, | 863 kFaviconSize + favIconWidthDelta, |
| 864 kFavIconSize + favIconHeightDelta, | 864 kFaviconSize + favIconHeightDelta, |
| 865 true); | 865 true); |
| 866 } | 866 } |
| 867 } | 867 } |
| 868 } | 868 } |
| 869 canvas->Restore(); | 869 canvas->Restore(); |
| 870 } | 870 } |
| 871 } | 871 } |
| 872 | 872 |
| 873 void TabRendererGtk::PaintTabBackground(gfx::Canvas* canvas) { | 873 void TabRendererGtk::PaintTabBackground(gfx::Canvas* canvas) { |
| 874 if (IsSelected()) { | 874 if (IsSelected()) { |
| (...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 972 favicon_bounds_.x(), favicon_bounds_.y(), image_size, image_size); | 972 favicon_bounds_.x(), favicon_bounds_.y(), image_size, image_size); |
| 973 canvas->DrawBitmapInt(*frames, image_offset, 0, image_size, image_size, | 973 canvas->DrawBitmapInt(*frames, image_offset, 0, image_size, image_size, |
| 974 favicon_bounds_.x(), favicon_bounds_.y(), image_size, image_size, | 974 favicon_bounds_.x(), favicon_bounds_.y(), image_size, image_size, |
| 975 false); | 975 false); |
| 976 canvas->Restore(); | 976 canvas->Restore(); |
| 977 } | 977 } |
| 978 | 978 |
| 979 int TabRendererGtk::IconCapacity() const { | 979 int TabRendererGtk::IconCapacity() const { |
| 980 if (height() < GetMinimumUnselectedSize().height()) | 980 if (height() < GetMinimumUnselectedSize().height()) |
| 981 return 0; | 981 return 0; |
| 982 return (width() - kLeftPadding - kRightPadding) / kFavIconSize; | 982 return (width() - kLeftPadding - kRightPadding) / kFaviconSize; |
| 983 } | 983 } |
| 984 | 984 |
| 985 bool TabRendererGtk::ShouldShowCloseBox() const { | 985 bool TabRendererGtk::ShouldShowCloseBox() const { |
| 986 // The selected tab never clips close button. | 986 // The selected tab never clips close button. |
| 987 return !mini() && (IsSelected() || IconCapacity() >= 3); | 987 return !mini() && (IsSelected() || IconCapacity() >= 3); |
| 988 } | 988 } |
| 989 | 989 |
| 990 CustomDrawButton* TabRendererGtk::MakeCloseButton() { | 990 CustomDrawButton* TabRendererGtk::MakeCloseButton() { |
| 991 CustomDrawButton* button = new CustomDrawButton(IDR_TAB_CLOSE, | 991 CustomDrawButton* button = new CustomDrawButton(IDR_TAB_CLOSE, |
| 992 IDR_TAB_CLOSE_P, IDR_TAB_CLOSE_H, IDR_TAB_CLOSE); | 992 IDR_TAB_CLOSE_P, IDR_TAB_CLOSE_H, IDR_TAB_CLOSE); |
| (...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1080 | 1080 |
| 1081 ResourceBundle& rb = ResourceBundle::GetSharedInstance(); | 1081 ResourceBundle& rb = ResourceBundle::GetSharedInstance(); |
| 1082 const gfx::Font& base_font = rb.GetFont(ResourceBundle::BaseFont); | 1082 const gfx::Font& base_font = rb.GetFont(ResourceBundle::BaseFont); |
| 1083 title_font_ = new gfx::Font(base_font.GetFontName(), kFontPixelSize); | 1083 title_font_ = new gfx::Font(base_font.GetFontName(), kFontPixelSize); |
| 1084 title_font_height_ = title_font_->GetHeight(); | 1084 title_font_height_ = title_font_->GetHeight(); |
| 1085 | 1085 |
| 1086 crashed_fav_icon = rb.GetBitmapNamed(IDR_SAD_FAVICON); | 1086 crashed_fav_icon = rb.GetBitmapNamed(IDR_SAD_FAVICON); |
| 1087 | 1087 |
| 1088 initialized_ = true; | 1088 initialized_ = true; |
| 1089 } | 1089 } |
| OLD | NEW |