Index: chrome/browser/ui/views/tabs/tab.cc |
diff --git a/chrome/browser/ui/views/tabs/tab.cc b/chrome/browser/ui/views/tabs/tab.cc |
index fde98892ecf4e44523e02ef81c9d4da247d205dc..0584344c3213d2ae0cd827d96159917b4b19aff3 100644 |
--- a/chrome/browser/ui/views/tabs/tab.cc |
+++ b/chrome/browser/ui/views/tabs/tab.cc |
@@ -16,6 +16,7 @@ |
#include "chrome/browser/ui/tabs/tab_resources.h" |
#include "chrome/browser/ui/view_ids.h" |
#include "chrome/browser/ui/views/tabs/tab_controller.h" |
+#include "chrome/browser/ui/views/tabs/tab_paint_util.h" |
#include "chrome/browser/ui/views/theme_image_mapper.h" |
#include "chrome/browser/ui/views/touch_uma/touch_uma.h" |
#include "chrome/common/chrome_switches.h" |
@@ -1240,62 +1241,63 @@ void Tab::PaintInactiveTabBackgroundWithTitleChange( |
} |
void Tab::PaintInactiveTabBackground(gfx::Canvas* canvas) { |
- int tab_id; |
- int frame_id; |
+ int background_id; |
+ int background_overlay_id; |
views::Widget* widget = GetWidget(); |
- GetTabIdAndFrameId(widget, &tab_id, &frame_id); |
+ GetInactiveBackgroundIdAndOverlayId(widget, &background_id, |
+ &background_overlay_id); |
// Explicitly map the id so we cache correctly. |
const chrome::HostDesktopType host_desktop_type = GetHostDesktopType(this); |
- tab_id = chrome::MapThemeImage(host_desktop_type, tab_id); |
+ background_id = chrome::MapThemeImage(host_desktop_type, background_id); |
// HasCustomImage() is only true if the theme provides the image. However, |
// even if the theme does not provide a tab background, the theme machinery |
// will make one if given a frame image. |
ui::ThemeProvider* theme_provider = GetThemeProvider(); |
- const bool theme_provided_image = theme_provider->HasCustomImage(tab_id) || |
- (frame_id != 0 && theme_provider->HasCustomImage(frame_id)); |
+ const bool theme_provided_image = |
+ theme_provider->HasCustomImage(IDR_THEME_FRAME) || |
+ theme_provider->HasCustomImage(background_id) || |
+ theme_provider->HasCustomImage(background_overlay_id); |
const bool can_cache = !theme_provided_image && |
!hover_controller_.ShouldDraw(); |
if (can_cache) { |
+ // The default theme does not provide background overlay images. |
gfx::ImageSkia cached_image( |
- GetCachedImage(tab_id, size(), canvas->scale_factor())); |
+ GetCachedImage(background_id, size(), canvas->scale_factor())); |
if (cached_image.width() == 0) { |
gfx::Canvas tmp_canvas(size(), canvas->scale_factor(), false); |
- PaintInactiveTabBackgroundUsingResourceId(&tmp_canvas, tab_id); |
+ PaintInactiveTabBackgroundUsingResourceIds(&tmp_canvas, background_id, |
+ background_overlay_id); |
cached_image = gfx::ImageSkia(tmp_canvas.ExtractImageRep()); |
- SetCachedImage(tab_id, canvas->scale_factor(), cached_image); |
+ SetCachedImage(background_id, canvas->scale_factor(), cached_image); |
} |
canvas->DrawImageInt(cached_image, 0, 0); |
} else { |
- PaintInactiveTabBackgroundUsingResourceId(canvas, tab_id); |
+ PaintInactiveTabBackgroundUsingResourceIds(canvas, background_id, |
+ background_overlay_id); |
} |
} |
-void Tab::PaintInactiveTabBackgroundUsingResourceId(gfx::Canvas* canvas, |
- int tab_id) { |
+void Tab::PaintInactiveTabBackgroundUsingResourceIds( |
+ gfx::Canvas* canvas, |
+ int background_id, |
+ int background_overlay_id) { |
// WARNING: the inactive tab background may be cached. If you change what it |
// is drawn from you may need to update whether it can be cached. |
// The tab image needs to be lined up with the background image |
- // so that it feels partially transparent. These offsets represent the tab |
+ // so that it feels partially transparent. This offset represents the tab |
// position within the frame background image. |
int offset = GetMirroredX() + background_offset_.x(); |
- gfx::ImageSkia* tab_bg = GetThemeProvider()->GetImageSkiaNamed(tab_id); |
- |
+ ui::ThemeProvider* tp = GetThemeProvider(); |
TabImage* tab_image = &tab_active_; |
TabImage* tab_inactive_image = &tab_inactive_; |
TabImage* alpha = &tab_alpha_; |
- // If the theme is providing a custom background image, then its top edge |
- // should be at the top of the tab. Otherwise, we assume that the background |
- // image is a composited foreground + frame image. |
- int bg_offset_y = GetThemeProvider()->HasCustomImage(tab_id) ? |
- 0 : background_offset_.y(); |
- |
// We need a gfx::Canvas object to be able to extract the image from. |
// We draw everything to this canvas and then output it to the canvas |
// parameter in addition to using it to mask the hover glow if needed. |
@@ -1303,8 +1305,9 @@ void Tab::PaintInactiveTabBackgroundUsingResourceId(gfx::Canvas* canvas, |
// Draw left edge. Don't draw over the toolbar, as we're not the foreground |
// tab. |
- gfx::ImageSkia tab_l = gfx::ImageSkiaOperations::CreateTiledImage( |
- *tab_bg, offset, bg_offset_y, tab_image->l_width, height()); |
+ gfx::ImageSkia tab_l = TabPaintUtil::CreateTiledInactiveBackground(tp, |
+ background_id, background_overlay_id, background_offset_.y(), offset, 0, |
+ tab_image->l_width, height()); |
gfx::ImageSkia theme_l = |
gfx::ImageSkiaOperations::CreateMaskedImage(tab_l, *alpha->image_l); |
background_canvas.DrawImageInt(theme_l, |
@@ -1313,9 +1316,9 @@ void Tab::PaintInactiveTabBackgroundUsingResourceId(gfx::Canvas* canvas, |
false); |
// Draw right edge. Again, don't draw over the toolbar. |
- gfx::ImageSkia tab_r = gfx::ImageSkiaOperations::CreateTiledImage(*tab_bg, |
- offset + width() - tab_image->r_width, bg_offset_y, |
- tab_image->r_width, height()); |
+ gfx::ImageSkia tab_r = TabPaintUtil::CreateTiledInactiveBackground(tp, |
+ background_id, background_overlay_id, background_offset_.y(), |
+ offset + width() - tab_image->r_width, 0, tab_image->r_width, height()); |
gfx::ImageSkia theme_r = |
gfx::ImageSkiaOperations::CreateMaskedImage(tab_r, *alpha->image_r); |
background_canvas.DrawImageInt(theme_r, |
@@ -1324,20 +1327,23 @@ void Tab::PaintInactiveTabBackgroundUsingResourceId(gfx::Canvas* canvas, |
theme_r.height() - kToolbarOverlap, false); |
// Draw center. Instead of masking out the top portion we simply skip over |
- // it by incrementing by GetDropShadowHeight(), since it's a simple |
+ // it by incrementing by drop_shadow_height(), since it's a simple |
// rectangle. And again, don't draw over the toolbar. |
- background_canvas.TileImageInt(*tab_bg, |
- offset + tab_image->l_width, |
- bg_offset_y + drop_shadow_height(), |
- tab_image->l_width, |
- drop_shadow_height(), |
- width() - tab_image->l_width - tab_image->r_width, |
- height() - drop_shadow_height() - kToolbarOverlap); |
+ gfx::ImageSkia tab_c = TabPaintUtil::CreateTiledInactiveBackground(tp, |
+ background_id, |
+ background_overlay_id, |
+ background_offset_.y(), |
+ offset + tab_image->l_width, |
+ drop_shadow_height(), |
+ width() - tab_image->l_width - tab_image->r_width, |
+ height() - drop_shadow_height() - kToolbarOverlap); |
+ background_canvas.DrawImageInt(tab_c, tab_image->l_width, |
+ drop_shadow_height()); |
canvas->DrawImageInt( |
gfx::ImageSkia(background_canvas.ExtractImageRep()), 0, 0); |
- if (!GetThemeProvider()->HasCustomImage(tab_id) && |
+ if (!tp->HasCustomImage(background_overlay_id) && |
hover_controller_.ShouldDraw()) { |
hover_controller_.Draw(canvas, gfx::ImageSkia( |
background_canvas.ExtractImageRep())); |
@@ -1504,16 +1510,6 @@ void Tab::PaintCaptureState(gfx::Canvas* canvas, gfx::Rect bounds) { |
gfx::ImageSkia recording_dot(*tp->GetImageSkiaNamed(IDR_TAB_RECORDING)); |
gfx::ImageSkia recording_dot_mask( |
*tp->GetImageSkiaNamed(IDR_TAB_RECORDING_MASK)); |
- gfx::ImageSkia tab_background; |
- if (IsActive()) { |
- tab_background = *tp->GetImageSkiaNamed(IDR_THEME_TOOLBAR); |
- } else { |
- int tab_id; |
- int frame_id_dummy; |
- views::Widget* widget = GetWidget(); |
- GetTabIdAndFrameId(widget, &tab_id, &frame_id_dummy); |
- tab_background = *tp->GetImageSkiaNamed(tab_id); |
- } |
// This is the offset from the favicon bottom right corner for the mask, |
// given that the recording dot is drawn in the bottom right corner. |
@@ -1529,10 +1525,24 @@ void Tab::PaintCaptureState(gfx::Canvas* canvas, gfx::Rect bounds) { |
// from the background. |
int offset_x = GetMirroredX() + background_offset_.x() + mask_dst_x; |
int offset_y = mask_dst_y; |
- gfx::ImageSkia tab_background_cropped = |
- gfx::ImageSkiaOperations::CreateTiledImage( |
- tab_background, offset_x, offset_y, |
- recording_dot_mask.width(), recording_dot_mask.height()); |
+ gfx::ImageSkia tab_background_cropped; |
+ if (IsActive()) { |
+ gfx::ImageSkia tab_background = *tp->GetImageSkiaNamed(IDR_THEME_TOOLBAR); |
+ tab_background_cropped = gfx::ImageSkiaOperations::CreateTiledImage( |
+ tab_background, offset_x, offset_y, |
+ recording_dot_mask.width(), recording_dot_mask.height()); |
+ } else { |
+ int background_id; |
+ int background_overlay_id; |
+ views::Widget* widget = GetWidget(); |
+ GetInactiveBackgroundIdAndOverlayId(widget, &background_id, |
+ &background_overlay_id); |
+ |
+ tab_background_cropped = TabPaintUtil::CreateTiledInactiveBackground(tp, |
+ background_id, background_overlay_id, background_offset_.y(), |
+ offset_x, offset_y, recording_dot_mask.width(), |
+ recording_dot_mask.height()); |
+ } |
gfx::ImageSkia recording_dot_mask_with_bg = |
gfx::ImageSkiaOperations::CreateMaskedImage(tab_background_cropped, |
recording_dot_mask); |
@@ -1547,7 +1557,8 @@ void Tab::PaintCaptureState(gfx::Canvas* canvas, gfx::Rect bounds) { |
// Potentially draw an alpha of the active bg image. |
double throb_value = GetThrobValue(); |
if (!IsActive() && throb_value > 0) { |
- tab_background = *tp->GetImageSkiaNamed(IDR_THEME_TOOLBAR); |
+ gfx::ImageSkia tab_background = |
+ *tp->GetImageSkiaNamed(IDR_THEME_TOOLBAR); |
tab_background_cropped = gfx::ImageSkiaOperations::CreateTiledImage( |
tab_background, offset_x, offset_y, |
recording_dot_mask.width(), recording_dot_mask.height()); |
@@ -1752,23 +1763,24 @@ gfx::Rect Tab::GetImmersiveBarRect() const { |
main_bar_left, 0, main_bar_right - main_bar_left, kImmersiveBarHeight); |
} |
-void Tab::GetTabIdAndFrameId(views::Widget* widget, |
- int* tab_id, |
- int* frame_id) const { |
+void Tab::GetInactiveBackgroundIdAndOverlayId( |
+ views::Widget* widget, |
+ int* background_id, |
+ int* background_overlay_id) const { |
if (widget && widget->GetTopLevelWidget()->ShouldUseNativeFrame()) { |
- *tab_id = IDR_THEME_TAB_BACKGROUND_V; |
- *frame_id = 0; |
+ *background_id = IDR_THEME_TAB_BACKGROUND_V; |
+ *background_overlay_id = IDR_THEME_TAB_BACKGROUND_V_OVERLAY; |
} else if (data().incognito) { |
- *tab_id = IDR_THEME_TAB_BACKGROUND_INCOGNITO; |
- *frame_id = IDR_THEME_FRAME_INCOGNITO; |
+ *background_id = IDR_THEME_TAB_BACKGROUND_INCOGNITO; |
+ *background_overlay_id = IDR_THEME_TAB_BACKGROUND_INCOGNITO_OVERLAY; |
#if defined(OS_WIN) |
} else if (win8::IsSingleWindowMetroMode()) { |
- *tab_id = IDR_THEME_TAB_BACKGROUND_V; |
- *frame_id = 0; |
+ *background_id = IDR_THEME_TAB_BACKGROUND_V; |
+ *background_overlay_id = IDR_THEME_TAB_BACKGROUND_V_OVERLAY; |
#endif |
} else { |
- *tab_id = IDR_THEME_TAB_BACKGROUND; |
- *frame_id = IDR_THEME_FRAME; |
+ *background_id = IDR_THEME_TAB_BACKGROUND; |
+ *background_overlay_id = IDR_THEME_TAB_BACKGROUND_OVERLAY; |
} |
} |