| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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/gtk/tabs/tab_renderer_gtk.h" | 5 #include "chrome/browser/gtk/tabs/tab_renderer_gtk.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <utility> | 8 #include <utility> |
| 9 | 9 |
| 10 #include "app/l10n_util.h" | 10 #include "app/l10n_util.h" |
| (...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 121 int loading, int waiting, int waiting_to_loading) | 121 int loading, int waiting, int waiting_to_loading) |
| 122 : waiting_animation_frames(NULL), | 122 : waiting_animation_frames(NULL), |
| 123 loading_animation_frames(NULL), | 123 loading_animation_frames(NULL), |
| 124 loading_animation_frame_count(loading), | 124 loading_animation_frame_count(loading), |
| 125 waiting_animation_frame_count(waiting), | 125 waiting_animation_frame_count(waiting), |
| 126 waiting_to_loading_frame_count_ratio(waiting_to_loading) { | 126 waiting_to_loading_frame_count_ratio(waiting_to_loading) { |
| 127 } | 127 } |
| 128 | 128 |
| 129 bool TabRendererGtk::initialized_ = false; | 129 bool TabRendererGtk::initialized_ = false; |
| 130 TabRendererGtk::TabImage TabRendererGtk::tab_active_ = {0}; | 130 TabRendererGtk::TabImage TabRendererGtk::tab_active_ = {0}; |
| 131 TabRendererGtk::TabImage TabRendererGtk::tab_active_nano_ = {0}; | |
| 132 TabRendererGtk::TabImage TabRendererGtk::tab_inactive_ = {0}; | 131 TabRendererGtk::TabImage TabRendererGtk::tab_inactive_ = {0}; |
| 133 TabRendererGtk::TabImage TabRendererGtk::tab_inactive_nano_ = {0}; | |
| 134 TabRendererGtk::TabImage TabRendererGtk::tab_alpha_ = {0}; | 132 TabRendererGtk::TabImage TabRendererGtk::tab_alpha_ = {0}; |
| 135 TabRendererGtk::TabImage TabRendererGtk::tab_alpha_nano_ = {0}; | |
| 136 gfx::Font* TabRendererGtk::title_font_ = NULL; | 133 gfx::Font* TabRendererGtk::title_font_ = NULL; |
| 137 int TabRendererGtk::title_font_height_ = 0; | 134 int TabRendererGtk::title_font_height_ = 0; |
| 138 int TabRendererGtk::close_button_width_ = 0; | 135 int TabRendererGtk::close_button_width_ = 0; |
| 139 int TabRendererGtk::close_button_height_ = 0; | 136 int TabRendererGtk::close_button_height_ = 0; |
| 140 SkColor TabRendererGtk::selected_title_color_ = SK_ColorBLACK; | 137 SkColor TabRendererGtk::selected_title_color_ = SK_ColorBLACK; |
| 141 SkColor TabRendererGtk::unselected_title_color_ = SkColorSetRGB(64, 64, 64); | 138 SkColor TabRendererGtk::unselected_title_color_ = SkColorSetRGB(64, 64, 64); |
| 142 | 139 |
| 143 //////////////////////////////////////////////////////////////////////////////// | 140 //////////////////////////////////////////////////////////////////////////////// |
| 144 // TabRendererGtk::LoadingAnimation, public: | 141 // TabRendererGtk::LoadingAnimation, public: |
| 145 // | 142 // |
| (...skipping 238 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 384 theme_id = IDR_THEME_TOOLBAR; | 381 theme_id = IDR_THEME_TOOLBAR; |
| 385 } else { | 382 } else { |
| 386 if (!data_.off_the_record) { | 383 if (!data_.off_the_record) { |
| 387 theme_id = IDR_THEME_TAB_BACKGROUND; | 384 theme_id = IDR_THEME_TAB_BACKGROUND; |
| 388 } else { | 385 } else { |
| 389 theme_id = IDR_THEME_TAB_BACKGROUND_INCOGNITO; | 386 theme_id = IDR_THEME_TAB_BACKGROUND_INCOGNITO; |
| 390 } | 387 } |
| 391 if (!theme_provider_->HasCustomImage(theme_id)) | 388 if (!theme_provider_->HasCustomImage(theme_id)) |
| 392 offset_y = background_offset_y_; | 389 offset_y = background_offset_y_; |
| 393 } | 390 } |
| 394 | |
| 395 // If the tab is a nanotab, we must take care to only draw the background | |
| 396 // within the height of the nanotab. | |
| 397 int nanoTabOffset = data_.app ? 9 : 0; | |
| 398 SkBitmap* tab_bg = theme_provider_->GetBitmapNamed(theme_id); | 391 SkBitmap* tab_bg = theme_provider_->GetBitmapNamed(theme_id); |
| 399 canvas.TileImageInt(*tab_bg, | 392 canvas.TileImageInt(*tab_bg, |
| 400 x() + favicon_bounds_.x(), | 393 x() + favicon_bounds_.x(), offset_y + favicon_bounds_.y(), |
| 401 offset_y + favicon_bounds_.y() + nanoTabOffset, | 394 favicon_bounds_.x(), favicon_bounds_.y(), |
| 402 favicon_bounds_.x(), | 395 favicon_bounds_.width(), favicon_bounds_.height()); |
| 403 favicon_bounds_.y() + nanoTabOffset, | |
| 404 favicon_bounds_.width(), | |
| 405 favicon_bounds_.height() - nanoTabOffset); | |
| 406 | 396 |
| 407 if (!IsSelected()) { | 397 if (!IsSelected()) { |
| 408 double throb_value = GetThrobValue(); | 398 double throb_value = GetThrobValue(); |
| 409 if (throb_value > 0) { | 399 if (throb_value > 0) { |
| 410 SkRect bounds; | 400 SkRect bounds; |
| 411 bounds.set(favicon_bounds_.x(), favicon_bounds_.y(), | 401 bounds.set(favicon_bounds_.x(), favicon_bounds_.y(), |
| 412 favicon_bounds_.right(), favicon_bounds_.bottom()); | 402 favicon_bounds_.right(), favicon_bounds_.bottom()); |
| 413 canvas.saveLayerAlpha(&bounds, static_cast<int>(throb_value * 0xff), | 403 canvas.saveLayerAlpha(&bounds, static_cast<int>(throb_value * 0xff), |
| 414 SkCanvas::kARGB_ClipLayer_SaveFlag); | 404 SkCanvas::kARGB_ClipLayer_SaveFlag); |
| 415 canvas.drawARGB(0, 255, 255, 255, SkXfermode::kClear_Mode); | 405 canvas.drawARGB(0, 255, 255, 255, SkXfermode::kClear_Mode); |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 465 return std::max(content_height, close_button_height_); | 455 return std::max(content_height, close_button_height_); |
| 466 } | 456 } |
| 467 | 457 |
| 468 // static | 458 // static |
| 469 void TabRendererGtk::LoadTabImages() { | 459 void TabRendererGtk::LoadTabImages() { |
| 470 ResourceBundle& rb = ResourceBundle::GetSharedInstance(); | 460 ResourceBundle& rb = ResourceBundle::GetSharedInstance(); |
| 471 | 461 |
| 472 tab_alpha_.image_l = rb.GetBitmapNamed(IDR_TAB_ALPHA_LEFT); | 462 tab_alpha_.image_l = rb.GetBitmapNamed(IDR_TAB_ALPHA_LEFT); |
| 473 tab_alpha_.image_r = rb.GetBitmapNamed(IDR_TAB_ALPHA_RIGHT); | 463 tab_alpha_.image_r = rb.GetBitmapNamed(IDR_TAB_ALPHA_RIGHT); |
| 474 | 464 |
| 475 tab_alpha_nano_.image_l = rb.GetBitmapNamed(IDR_TAB_ALPHA_NANO_LEFT); | |
| 476 tab_alpha_nano_.image_r = rb.GetBitmapNamed(IDR_TAB_ALPHA_NANO_RIGHT); | |
| 477 | |
| 478 tab_active_.image_l = rb.GetBitmapNamed(IDR_TAB_ACTIVE_LEFT); | 465 tab_active_.image_l = rb.GetBitmapNamed(IDR_TAB_ACTIVE_LEFT); |
| 479 tab_active_.image_c = rb.GetBitmapNamed(IDR_TAB_ACTIVE_CENTER); | 466 tab_active_.image_c = rb.GetBitmapNamed(IDR_TAB_ACTIVE_CENTER); |
| 480 tab_active_.image_r = rb.GetBitmapNamed(IDR_TAB_ACTIVE_RIGHT); | 467 tab_active_.image_r = rb.GetBitmapNamed(IDR_TAB_ACTIVE_RIGHT); |
| 481 tab_active_.l_width = tab_active_.image_l->width(); | 468 tab_active_.l_width = tab_active_.image_l->width(); |
| 482 tab_active_.r_width = tab_active_.image_r->width(); | 469 tab_active_.r_width = tab_active_.image_r->width(); |
| 483 | 470 |
| 484 const int kNanoTabDiffHeight = 13; | |
| 485 | |
| 486 tab_active_nano_.image_l = rb.GetBitmapNamed(IDR_TAB_ACTIVE_NANO_LEFT); | |
| 487 tab_active_nano_.image_c = rb.GetBitmapNamed(IDR_TAB_ACTIVE_NANO_CENTER); | |
| 488 tab_active_nano_.image_r = rb.GetBitmapNamed(IDR_TAB_ACTIVE_NANO_RIGHT); | |
| 489 tab_active_nano_.l_width = tab_active_nano_.image_l->width(); | |
| 490 tab_active_nano_.r_width = tab_active_nano_.image_r->width(); | |
| 491 tab_active_nano_.y_offset = kNanoTabDiffHeight; | |
| 492 | |
| 493 tab_inactive_.image_l = rb.GetBitmapNamed(IDR_TAB_INACTIVE_LEFT); | 471 tab_inactive_.image_l = rb.GetBitmapNamed(IDR_TAB_INACTIVE_LEFT); |
| 494 tab_inactive_.image_c = rb.GetBitmapNamed(IDR_TAB_INACTIVE_CENTER); | 472 tab_inactive_.image_c = rb.GetBitmapNamed(IDR_TAB_INACTIVE_CENTER); |
| 495 tab_inactive_.image_r = rb.GetBitmapNamed(IDR_TAB_INACTIVE_RIGHT); | 473 tab_inactive_.image_r = rb.GetBitmapNamed(IDR_TAB_INACTIVE_RIGHT); |
| 496 tab_inactive_.l_width = tab_inactive_.image_l->width(); | 474 tab_inactive_.l_width = tab_inactive_.image_l->width(); |
| 497 tab_inactive_.r_width = tab_inactive_.image_r->width(); | 475 tab_inactive_.r_width = tab_inactive_.image_r->width(); |
| 498 | 476 |
| 499 tab_inactive_nano_.image_l = rb.GetBitmapNamed(IDR_TAB_INACTIVE_NANO_LEFT); | |
| 500 tab_inactive_nano_.image_c = rb.GetBitmapNamed(IDR_TAB_INACTIVE_NANO_CENTER); | |
| 501 tab_inactive_nano_.image_r = rb.GetBitmapNamed(IDR_TAB_INACTIVE_NANO_RIGHT); | |
| 502 tab_inactive_nano_.l_width = tab_inactive_.image_l->width(); | |
| 503 tab_inactive_nano_.r_width = tab_inactive_.image_r->width(); | |
| 504 tab_inactive_nano_.y_offset = kNanoTabDiffHeight; | |
| 505 | |
| 506 close_button_width_ = rb.GetBitmapNamed(IDR_TAB_CLOSE)->width(); | 477 close_button_width_ = rb.GetBitmapNamed(IDR_TAB_CLOSE)->width(); |
| 507 close_button_height_ = rb.GetBitmapNamed(IDR_TAB_CLOSE)->height(); | 478 close_button_height_ = rb.GetBitmapNamed(IDR_TAB_CLOSE)->height(); |
| 508 } | 479 } |
| 509 | 480 |
| 510 // static | 481 // static |
| 511 void TabRendererGtk::SetSelectedTitleColor(SkColor color) { | 482 void TabRendererGtk::SetSelectedTitleColor(SkColor color) { |
| 512 selected_title_color_ = color; | 483 selected_title_color_ = color; |
| 513 } | 484 } |
| 514 | 485 |
| 515 // static | 486 // static |
| (...skipping 392 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 908 | 879 |
| 909 // The tab image needs to be lined up with the background image | 880 // The tab image needs to be lined up with the background image |
| 910 // so that it feels partially transparent. | 881 // so that it feels partially transparent. |
| 911 int offset_x = background_offset_x_; | 882 int offset_x = background_offset_x_; |
| 912 | 883 |
| 913 int tab_id = is_otr ? | 884 int tab_id = is_otr ? |
| 914 IDR_THEME_TAB_BACKGROUND_INCOGNITO : IDR_THEME_TAB_BACKGROUND; | 885 IDR_THEME_TAB_BACKGROUND_INCOGNITO : IDR_THEME_TAB_BACKGROUND; |
| 915 | 886 |
| 916 SkBitmap* tab_bg = theme_provider_->GetBitmapNamed(tab_id); | 887 SkBitmap* tab_bg = theme_provider_->GetBitmapNamed(tab_id); |
| 917 | 888 |
| 918 // App tabs are drawn slightly differently (as nano tabs). | |
| 919 TabImage* tab_image = data_.app ? &tab_active_nano_ : &tab_active_; | |
| 920 TabImage* tab_inactive_image = data_.app ? &tab_inactive_nano_ : | |
| 921 &tab_inactive_; | |
| 922 TabImage* alpha = data_.app ? &tab_alpha_nano_ : &tab_alpha_; | |
| 923 | |
| 924 // If the theme is providing a custom background image, then its top edge | 889 // If the theme is providing a custom background image, then its top edge |
| 925 // should be at the top of the tab. Otherwise, we assume that the background | 890 // should be at the top of the tab. Otherwise, we assume that the background |
| 926 // image is a composited foreground + frame image. | 891 // image is a composited foreground + frame image. |
| 927 int offset_y = theme_provider_->HasCustomImage(tab_id) ? | 892 int offset_y = theme_provider_->HasCustomImage(tab_id) ? |
| 928 0 : background_offset_y_; | 893 0 : background_offset_y_; |
| 929 | 894 |
| 930 // Draw left edge. | 895 // Draw left edge. |
| 931 SkBitmap* theme_l = GetMaskedBitmap(alpha->image_l, tab_bg, offset_x, | 896 SkBitmap* theme_l = GetMaskedBitmap(tab_alpha_.image_l, tab_bg, offset_x, |
| 932 offset_y); | 897 offset_y); |
| 933 canvas->DrawBitmapInt(*theme_l, 0, 0); | 898 canvas->DrawBitmapInt(*theme_l, 0, 0); |
| 934 | 899 |
| 935 // Draw right edge. | 900 // Draw right edge. |
| 936 SkBitmap* theme_r = GetMaskedBitmap(alpha->image_r, tab_bg, | 901 SkBitmap* theme_r = GetMaskedBitmap(tab_alpha_.image_r, tab_bg, |
| 937 offset_x + width() - tab_image->r_width, offset_y); | 902 offset_x + width() - tab_active_.r_width, offset_y); |
| 938 | 903 |
| 939 canvas->DrawBitmapInt(*theme_r, width() - theme_r->width(), 0); | 904 canvas->DrawBitmapInt(*theme_r, width() - theme_r->width(), 0); |
| 940 | 905 |
| 941 // Draw center. | 906 // Draw center. |
| 942 canvas->TileImageInt( | 907 canvas->TileImageInt(*tab_bg, |
| 943 *tab_bg, | 908 offset_x + tab_active_.l_width, kDropShadowOffset + offset_y, |
| 944 offset_x + tab_image->l_width, | 909 tab_active_.l_width, 2, |
| 945 kDropShadowOffset + offset_y + tab_image->y_offset, | 910 width() - tab_active_.l_width - tab_active_.r_width, height() - 2); |
| 946 tab_image->l_width, | |
| 947 kDropShadowHeight + tab_image->y_offset, | |
| 948 width() - tab_image->l_width - tab_image->r_width, | |
| 949 height() - kDropShadowHeight - tab_image->y_offset); | |
| 950 | 911 |
| 951 canvas->DrawBitmapInt(*tab_inactive_image->image_l, 0, 0); | 912 canvas->DrawBitmapInt(*tab_inactive_.image_l, 0, 0); |
| 952 canvas->TileImageInt( | 913 canvas->TileImageInt(*tab_inactive_.image_c, tab_inactive_.l_width, 0, |
| 953 *tab_inactive_image->image_c, | 914 width() - tab_inactive_.l_width - tab_inactive_.r_width, height()); |
| 954 tab_inactive_image->l_width, | 915 canvas->DrawBitmapInt(*tab_inactive_.image_r, |
| 955 0, | 916 width() - tab_inactive_.r_width, 0); |
| 956 width() - tab_inactive_image->l_width - tab_inactive_image->r_width, | |
| 957 height()); | |
| 958 canvas->DrawBitmapInt(*tab_inactive_image->image_r, | |
| 959 width() - tab_inactive_image->r_width, 0); | |
| 960 } | 917 } |
| 961 | 918 |
| 962 void TabRendererGtk::PaintActiveTabBackground(gfx::Canvas* canvas) { | 919 void TabRendererGtk::PaintActiveTabBackground(gfx::Canvas* canvas) { |
| 963 int offset_x = background_offset_x_; | 920 int offset_x = background_offset_x_; |
| 964 | 921 |
| 965 SkBitmap* tab_bg = theme_provider_->GetBitmapNamed(IDR_THEME_TOOLBAR); | 922 SkBitmap* tab_bg = theme_provider_->GetBitmapNamed(IDR_THEME_TOOLBAR); |
| 966 | 923 |
| 967 // App tabs are drawn slightly differently (as nano tabs). | |
| 968 TabImage* tab_image = data_.app ? &tab_active_nano_ : &tab_active_; | |
| 969 TabImage* alpha = data_.app ? &tab_alpha_nano_ : &tab_alpha_; | |
| 970 | |
| 971 // Draw left edge. | 924 // Draw left edge. |
| 972 SkBitmap* theme_l = GetMaskedBitmap(alpha->image_l, tab_bg, offset_x, 0); | 925 SkBitmap* theme_l = GetMaskedBitmap(tab_alpha_.image_l, tab_bg, offset_x, 0); |
| 973 canvas->DrawBitmapInt(*theme_l, 0, 0); | 926 canvas->DrawBitmapInt(*theme_l, 0, 0); |
| 974 | 927 |
| 975 // Draw right edge. | 928 // Draw right edge. |
| 976 SkBitmap* theme_r = GetMaskedBitmap(alpha->image_r, tab_bg, | 929 SkBitmap* theme_r = GetMaskedBitmap(tab_alpha_.image_r, tab_bg, |
| 977 offset_x + width() - tab_image->r_width, 0); | 930 offset_x + width() - tab_active_.r_width, 0); |
| 978 canvas->DrawBitmapInt(*theme_r, width() - tab_image->r_width, 0); | 931 canvas->DrawBitmapInt(*theme_r, width() - tab_active_.r_width, 0); |
| 979 | 932 |
| 980 // Draw center. | 933 // Draw center. |
| 981 canvas->TileImageInt(*tab_bg, | 934 canvas->TileImageInt(*tab_bg, |
| 982 offset_x + tab_image->l_width, | 935 offset_x + tab_active_.l_width, kDropShadowHeight, |
| 983 kDropShadowHeight + tab_image->y_offset, | 936 tab_active_.l_width, kDropShadowHeight, |
| 984 tab_image->l_width, | 937 width() - tab_active_.l_width - tab_active_.r_width, |
| 985 kDropShadowHeight + tab_image->y_offset, | 938 height() - kDropShadowHeight); |
| 986 width() - tab_image->l_width - tab_image->r_width, | |
| 987 height() - kDropShadowHeight - tab_image->y_offset); | |
| 988 | 939 |
| 989 canvas->DrawBitmapInt(*tab_image->image_l, 0, 0); | 940 canvas->DrawBitmapInt(*tab_active_.image_l, 0, 0); |
| 990 canvas->TileImageInt(*tab_image->image_c, tab_image->l_width, 0, | 941 canvas->TileImageInt(*tab_active_.image_c, tab_active_.l_width, 0, |
| 991 width() - tab_image->l_width - tab_image->r_width, height()); | 942 width() - tab_active_.l_width - tab_active_.r_width, height()); |
| 992 canvas->DrawBitmapInt(*tab_image->image_r, width() - tab_image->r_width, 0); | 943 canvas->DrawBitmapInt(*tab_active_.image_r, width() - tab_active_.r_width, 0); |
| 993 } | 944 } |
| 994 | 945 |
| 995 void TabRendererGtk::PaintLoadingAnimation(gfx::Canvas* canvas) { | 946 void TabRendererGtk::PaintLoadingAnimation(gfx::Canvas* canvas) { |
| 996 const SkBitmap* frames = | 947 const SkBitmap* frames = |
| 997 (loading_animation_.animation_state() == ANIMATION_WAITING) ? | 948 (loading_animation_.animation_state() == ANIMATION_WAITING) ? |
| 998 loading_animation_.waiting_animation_frames() : | 949 loading_animation_.waiting_animation_frames() : |
| 999 loading_animation_.loading_animation_frames(); | 950 loading_animation_.loading_animation_frames(); |
| 1000 const int image_size = frames->height(); | 951 const int image_size = frames->height(); |
| 1001 const int image_offset = loading_animation_.animation_frame() * image_size; | 952 const int image_offset = loading_animation_.animation_frame() * image_size; |
| 1002 DCHECK(image_size == favicon_bounds_.height()); | 953 DCHECK(image_size == favicon_bounds_.height()); |
| (...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1126 // Force the font size to 9pt, which matches Windows' default font size | 1077 // Force the font size to 9pt, which matches Windows' default font size |
| 1127 // (taken from the system). | 1078 // (taken from the system). |
| 1128 const gfx::Font& base_font = rb.GetFont(ResourceBundle::BaseFont); | 1079 const gfx::Font& base_font = rb.GetFont(ResourceBundle::BaseFont); |
| 1129 title_font_ = new gfx::Font(gfx::Font::CreateFont(base_font.FontName(), 9)); | 1080 title_font_ = new gfx::Font(gfx::Font::CreateFont(base_font.FontName(), 9)); |
| 1130 title_font_height_ = title_font_->height(); | 1081 title_font_height_ = title_font_->height(); |
| 1131 | 1082 |
| 1132 crashed_fav_icon = rb.GetBitmapNamed(IDR_SAD_FAVICON); | 1083 crashed_fav_icon = rb.GetBitmapNamed(IDR_SAD_FAVICON); |
| 1133 | 1084 |
| 1134 initialized_ = true; | 1085 initialized_ = true; |
| 1135 } | 1086 } |
| OLD | NEW |