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 331 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
342 if (data_.blocked == blocked) | 342 if (data_.blocked == blocked) |
343 return; | 343 return; |
344 data_.blocked = blocked; | 344 data_.blocked = blocked; |
345 // TODO(zelidrag) bug 32399: Make tabs pulse on Linux as well. | 345 // TODO(zelidrag) bug 32399: Make tabs pulse on Linux as well. |
346 } | 346 } |
347 | 347 |
348 bool TabRendererGtk::is_blocked() const { | 348 bool TabRendererGtk::is_blocked() const { |
349 return data_.blocked; | 349 return data_.blocked; |
350 } | 350 } |
351 | 351 |
352 bool TabRendererGtk::IsActive() const { | |
353 return true; | |
354 } | |
355 | |
352 bool TabRendererGtk::IsSelected() const { | 356 bool TabRendererGtk::IsSelected() const { |
353 return true; | 357 return true; |
354 } | 358 } |
355 | 359 |
356 bool TabRendererGtk::IsVisible() const { | 360 bool TabRendererGtk::IsVisible() const { |
357 return GTK_WIDGET_FLAGS(tab_.get()) & GTK_VISIBLE; | 361 return GTK_WIDGET_FLAGS(tab_.get()) & GTK_VISIBLE; |
358 } | 362 } |
359 | 363 |
360 void TabRendererGtk::SetVisible(bool visible) const { | 364 void TabRendererGtk::SetVisible(bool visible) const { |
361 if (visible) { | 365 if (visible) { |
(...skipping 21 matching lines...) Expand all Loading... | |
383 event->area.height = favicon_bounds_.height(); | 387 event->area.height = favicon_bounds_.height(); |
384 gfx::CanvasSkiaPaint canvas(event, false); | 388 gfx::CanvasSkiaPaint canvas(event, false); |
385 | 389 |
386 // The actual paint methods expect 0, 0 to be the tab top left (see | 390 // The actual paint methods expect 0, 0 to be the tab top left (see |
387 // PaintTab). | 391 // PaintTab). |
388 canvas.TranslateInt(x(), y()); | 392 canvas.TranslateInt(x(), y()); |
389 | 393 |
390 // Paint the background behind the favicon. | 394 // Paint the background behind the favicon. |
391 int theme_id; | 395 int theme_id; |
392 int offset_y = 0; | 396 int offset_y = 0; |
393 if (IsSelected()) { | 397 if (IsActive()) { |
394 theme_id = IDR_THEME_TOOLBAR; | 398 theme_id = IDR_THEME_TOOLBAR; |
395 } else { | 399 } else { |
396 if (!data_.incognito) { | 400 if (!data_.incognito) { |
397 theme_id = IDR_THEME_TAB_BACKGROUND; | 401 theme_id = IDR_THEME_TAB_BACKGROUND; |
398 } else { | 402 } else { |
399 theme_id = IDR_THEME_TAB_BACKGROUND_INCOGNITO; | 403 theme_id = IDR_THEME_TAB_BACKGROUND_INCOGNITO; |
400 } | 404 } |
401 if (!theme_service_->HasCustomImage(theme_id)) | 405 if (!theme_service_->HasCustomImage(theme_id)) |
402 offset_y = background_offset_y_; | 406 offset_y = background_offset_y_; |
403 } | 407 } |
404 SkBitmap* tab_bg = theme_service_->GetBitmapNamed(theme_id); | 408 SkBitmap* tab_bg = theme_service_->GetBitmapNamed(theme_id); |
405 canvas.TileImageInt(*tab_bg, | 409 canvas.TileImageInt(*tab_bg, |
406 x() + favicon_bounds_.x(), offset_y + favicon_bounds_.y(), | 410 x() + favicon_bounds_.x(), offset_y + favicon_bounds_.y(), |
407 favicon_bounds_.x(), favicon_bounds_.y(), | 411 favicon_bounds_.x(), favicon_bounds_.y(), |
408 favicon_bounds_.width(), favicon_bounds_.height()); | 412 favicon_bounds_.width(), favicon_bounds_.height()); |
409 | 413 |
410 if (!IsSelected()) { | 414 if (!IsActive()) { |
411 double throb_value = GetThrobValue(); | 415 double throb_value = GetThrobValue(); |
412 if (throb_value > 0) { | 416 if (throb_value > 0) { |
413 SkRect bounds; | 417 SkRect bounds; |
414 bounds.set(favicon_bounds_.x(), favicon_bounds_.y(), | 418 bounds.set(favicon_bounds_.x(), favicon_bounds_.y(), |
415 favicon_bounds_.right(), favicon_bounds_.bottom()); | 419 favicon_bounds_.right(), favicon_bounds_.bottom()); |
416 canvas.saveLayerAlpha(&bounds, static_cast<int>(throb_value * 0xff), | 420 canvas.saveLayerAlpha(&bounds, static_cast<int>(throb_value * 0xff), |
417 SkCanvas::kARGB_ClipLayer_SaveFlag); | 421 SkCanvas::kARGB_ClipLayer_SaveFlag); |
418 canvas.drawARGB(0, 255, 255, 255, SkXfermode::kClear_Mode); | 422 canvas.drawARGB(0, 255, 255, 255, SkXfermode::kClear_Mode); |
419 SkBitmap* active_bg = theme_service_->GetBitmapNamed(IDR_THEME_TOOLBAR); | 423 SkBitmap* active_bg = theme_service_->GetBitmapNamed(IDR_THEME_TOOLBAR); |
420 canvas.TileImageInt(*active_bg, | 424 canvas.TileImageInt(*active_bg, |
421 x() + favicon_bounds_.x(), favicon_bounds_.y(), | 425 x() + favicon_bounds_.x(), favicon_bounds_.y(), |
422 favicon_bounds_.x(), favicon_bounds_.y(), | 426 favicon_bounds_.x(), favicon_bounds_.y(), |
423 favicon_bounds_.width(), favicon_bounds_.height()); | 427 favicon_bounds_.width(), favicon_bounds_.height()); |
424 canvas.restore(); | 428 canvas.restore(); |
425 } | 429 } |
426 } | 430 } |
427 | 431 |
428 // Now paint the icon. | 432 // Now paint the icon. |
429 PaintIcon(&canvas); | 433 PaintIcon(&canvas); |
430 } | 434 } |
431 | 435 |
432 bool TabRendererGtk::ShouldShowIcon() const { | 436 bool TabRendererGtk::ShouldShowIcon() const { |
433 if (mini() && height() >= GetMinimumUnselectedSize().height()) { | 437 if (mini() && height() >= GetMinimumUnselectedSize().height()) { |
434 return true; | 438 return true; |
435 } else if (!data_.show_icon) { | 439 } else if (!data_.show_icon) { |
436 return false; | 440 return false; |
437 } else if (IsSelected()) { | 441 } else if (IsActive()) { |
438 // The selected tab clips favicon before close button. | 442 // The selected tab clips favicon before close button. |
439 return IconCapacity() >= 2; | 443 return IconCapacity() >= 2; |
440 } | 444 } |
441 // Non-selected tabs clip close button before favicon. | 445 // Non-selected tabs clip close button before favicon. |
442 return IconCapacity() >= 1; | 446 return IconCapacity() >= 1; |
443 } | 447 } |
444 | 448 |
445 // static | 449 // static |
446 gfx::Size TabRendererGtk::GetMinimumUnselectedSize() { | 450 gfx::Size TabRendererGtk::GetMinimumUnselectedSize() { |
447 InitResources(); | 451 InitResources(); |
(...skipping 366 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
814 // Paint the Title. | 818 // Paint the Title. |
815 string16 title = data_.title; | 819 string16 title = data_.title; |
816 if (title.empty()) { | 820 if (title.empty()) { |
817 title = data_.loading ? | 821 title = data_.loading ? |
818 l10n_util::GetStringUTF16(IDS_TAB_LOADING_TITLE) : | 822 l10n_util::GetStringUTF16(IDS_TAB_LOADING_TITLE) : |
819 TabContentsWrapper::GetDefaultTitle(); | 823 TabContentsWrapper::GetDefaultTitle(); |
820 } else { | 824 } else { |
821 Browser::FormatTitleForDisplay(&title); | 825 Browser::FormatTitleForDisplay(&title); |
822 } | 826 } |
823 | 827 |
824 SkColor title_color = IsSelected() ? selected_title_color_ | 828 SkColor title_color = IsActive() ? selected_title_color_ |
825 : unselected_title_color_; | 829 : unselected_title_color_; |
826 canvas->DrawStringInt(title, *title_font_, title_color, | 830 canvas->DrawStringInt(title, *title_font_, title_color, |
827 title_bounds_.x(), title_bounds_.y(), | 831 title_bounds_.x(), title_bounds_.y(), |
828 title_bounds_.width(), title_bounds_.height()); | 832 title_bounds_.width(), title_bounds_.height()); |
829 } | 833 } |
830 | 834 |
831 void TabRendererGtk::PaintIcon(gfx::Canvas* canvas) { | 835 void TabRendererGtk::PaintIcon(gfx::Canvas* canvas) { |
832 if (loading_animation_.animation_state() != ANIMATION_NONE) { | 836 if (loading_animation_.animation_state() != ANIMATION_NONE) { |
833 PaintLoadingAnimation(canvas); | 837 PaintLoadingAnimation(canvas); |
834 } else { | 838 } else { |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
871 kFaviconSize + faviconHeightDelta, | 875 kFaviconSize + faviconHeightDelta, |
872 true); | 876 true); |
873 } | 877 } |
874 } | 878 } |
875 } | 879 } |
876 canvas->Restore(); | 880 canvas->Restore(); |
877 } | 881 } |
878 } | 882 } |
879 | 883 |
880 void TabRendererGtk::PaintTabBackground(gfx::Canvas* canvas) { | 884 void TabRendererGtk::PaintTabBackground(gfx::Canvas* canvas) { |
881 if (IsSelected()) { | 885 if (IsActive()) { |
882 PaintActiveTabBackground(canvas); | 886 PaintActiveTabBackground(canvas); |
883 } else { | 887 } else { |
884 PaintInactiveTabBackground(canvas); | 888 PaintInactiveTabBackground(canvas); |
885 | 889 |
886 double throb_value = GetThrobValue(); | 890 double throb_value = GetThrobValue(); |
887 if (throb_value > 0) { | 891 if (throb_value > 0) { |
888 canvas->SaveLayerAlpha(static_cast<int>(throb_value * 0xff), | 892 canvas->SaveLayerAlpha(static_cast<int>(throb_value * 0xff), |
889 gfx::Rect(width(), height())); | 893 gfx::Rect(width(), height())); |
890 canvas->AsCanvasSkia()->drawARGB(0, 255, 255, 255, | 894 canvas->AsCanvasSkia()->drawARGB(0, 255, 255, 255, |
891 SkXfermode::kClear_Mode); | 895 SkXfermode::kClear_Mode); |
892 PaintActiveTabBackground(canvas); | 896 PaintActiveTabBackground(canvas); |
893 canvas->Restore(); | 897 canvas->Restore(); |
894 } | 898 } |
895 } | 899 } |
896 } | 900 } |
897 | 901 |
898 void TabRendererGtk::PaintInactiveTabBackground(gfx::Canvas* canvas) { | 902 void TabRendererGtk::PaintInactiveTabBackground(gfx::Canvas* canvas) { |
899 | 903 |
900 // The tab image needs to be lined up with the background image | 904 // The tab image needs to be lined up with the background image |
901 // so that it feels partially transparent. | 905 // so that it feels partially transparent. |
902 int offset_x = background_offset_x_; | 906 int offset_x = background_offset_x_; |
903 | 907 |
904 int tab_id = data_.incognito ? | 908 int tab_id = data_.incognito ? |
905 IDR_THEME_TAB_BACKGROUND_INCOGNITO : IDR_THEME_TAB_BACKGROUND; | 909 IDR_THEME_TAB_BACKGROUND_INCOGNITO : IDR_THEME_TAB_BACKGROUND; |
910 if (IsSelected()) | |
911 tab_id = IDR_THEME_TAB_BACKGROUND_V; | |
James Hawkins
2011/05/12 00:53:54
What does the 'V' stand for?
dpapad
2011/05/12 16:37:08
I do not know what V stands for and also it does n
| |
906 | 912 |
907 SkBitmap* tab_bg = theme_service_->GetBitmapNamed(tab_id); | 913 SkBitmap* tab_bg = theme_service_->GetBitmapNamed(tab_id); |
908 | 914 |
909 // If the theme is providing a custom background image, then its top edge | 915 // If the theme is providing a custom background image, then its top edge |
910 // should be at the top of the tab. Otherwise, we assume that the background | 916 // should be at the top of the tab. Otherwise, we assume that the background |
911 // image is a composited foreground + frame image. | 917 // image is a composited foreground + frame image. |
912 int offset_y = theme_service_->HasCustomImage(tab_id) ? | 918 int offset_y = theme_service_->HasCustomImage(tab_id) ? |
913 0 : background_offset_y_; | 919 0 : background_offset_y_; |
914 | 920 |
915 // Draw left edge. | 921 // Draw left edge. |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
984 } | 990 } |
985 | 991 |
986 int TabRendererGtk::IconCapacity() const { | 992 int TabRendererGtk::IconCapacity() const { |
987 if (height() < GetMinimumUnselectedSize().height()) | 993 if (height() < GetMinimumUnselectedSize().height()) |
988 return 0; | 994 return 0; |
989 return (width() - kLeftPadding - kRightPadding) / kFaviconSize; | 995 return (width() - kLeftPadding - kRightPadding) / kFaviconSize; |
990 } | 996 } |
991 | 997 |
992 bool TabRendererGtk::ShouldShowCloseBox() const { | 998 bool TabRendererGtk::ShouldShowCloseBox() const { |
993 // The selected tab never clips close button. | 999 // The selected tab never clips close button. |
994 return !mini() && (IsSelected() || IconCapacity() >= 3); | 1000 return !mini() && (IsActive() || IconCapacity() >= 3); |
995 } | 1001 } |
996 | 1002 |
997 CustomDrawButton* TabRendererGtk::MakeCloseButton() { | 1003 CustomDrawButton* TabRendererGtk::MakeCloseButton() { |
998 CustomDrawButton* button = new CustomDrawButton(IDR_TAB_CLOSE, | 1004 CustomDrawButton* button = new CustomDrawButton(IDR_TAB_CLOSE, |
999 IDR_TAB_CLOSE_P, IDR_TAB_CLOSE_H, IDR_TAB_CLOSE); | 1005 IDR_TAB_CLOSE_P, IDR_TAB_CLOSE_H, IDR_TAB_CLOSE); |
1000 | 1006 |
1001 gtk_widget_set_tooltip_text(button->widget(), | 1007 gtk_widget_set_tooltip_text(button->widget(), |
1002 l10n_util::GetStringUTF8(IDS_TOOLTIP_CLOSE_TAB).c_str()); | 1008 l10n_util::GetStringUTF8(IDS_TOOLTIP_CLOSE_TAB).c_str()); |
1003 | 1009 |
1004 g_signal_connect(button->widget(), "clicked", | 1010 g_signal_connect(button->widget(), "clicked", |
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1087 | 1093 |
1088 ResourceBundle& rb = ResourceBundle::GetSharedInstance(); | 1094 ResourceBundle& rb = ResourceBundle::GetSharedInstance(); |
1089 const gfx::Font& base_font = rb.GetFont(ResourceBundle::BaseFont); | 1095 const gfx::Font& base_font = rb.GetFont(ResourceBundle::BaseFont); |
1090 title_font_ = new gfx::Font(base_font.GetFontName(), kFontPixelSize); | 1096 title_font_ = new gfx::Font(base_font.GetFontName(), kFontPixelSize); |
1091 title_font_height_ = title_font_->GetHeight(); | 1097 title_font_height_ = title_font_->GetHeight(); |
1092 | 1098 |
1093 crashed_favicon = rb.GetBitmapNamed(IDR_SAD_FAVICON); | 1099 crashed_favicon = rb.GetBitmapNamed(IDR_SAD_FAVICON); |
1094 | 1100 |
1095 initialized_ = true; | 1101 initialized_ = true; |
1096 } | 1102 } |
OLD | NEW |