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/command_line.h" | 9 #include "base/command_line.h" |
10 #include "base/debug/alias.h" | 10 #include "base/debug/alias.h" |
(...skipping 1164 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1175 if (animation->current_part_index() == 2) { | 1175 if (animation->current_part_index() == 2) { |
1176 uint8 alpha = animation->CurrentValueBetween(255, 0); | 1176 uint8 alpha = animation->CurrentValueBetween(255, 0); |
1177 canvas->DrawImageInt(hover_image, 0, 0, alpha); | 1177 canvas->DrawImageInt(hover_image, 0, 0, alpha); |
1178 } else { | 1178 } else { |
1179 canvas->DrawImageInt(hover_image, 0, 0); | 1179 canvas->DrawImageInt(hover_image, 0, 0); |
1180 } | 1180 } |
1181 } | 1181 } |
1182 | 1182 |
1183 void Tab::PaintInactiveTabBackground(gfx::Canvas* canvas) { | 1183 void Tab::PaintInactiveTabBackground(gfx::Canvas* canvas) { |
1184 int tab_id; | 1184 int tab_id; |
| 1185 int frame_id; |
1185 views::Widget* widget = GetWidget(); | 1186 views::Widget* widget = GetWidget(); |
1186 if (widget && widget->GetTopLevelWidget()->ShouldUseNativeFrame()) { | 1187 if (widget && widget->GetTopLevelWidget()->ShouldUseNativeFrame()) { |
1187 tab_id = IDR_THEME_TAB_BACKGROUND_V; | 1188 tab_id = IDR_THEME_TAB_BACKGROUND_V; |
| 1189 frame_id = 0; |
1188 } else if (data().incognito) { | 1190 } else if (data().incognito) { |
1189 tab_id = IDR_THEME_TAB_BACKGROUND_INCOGNITO; | 1191 tab_id = IDR_THEME_TAB_BACKGROUND_INCOGNITO; |
| 1192 frame_id = IDR_THEME_FRAME_INCOGNITO; |
1190 #if defined(OS_WIN) | 1193 #if defined(OS_WIN) |
1191 } else if (win8::IsSingleWindowMetroMode()) { | 1194 } else if (win8::IsSingleWindowMetroMode()) { |
1192 tab_id = IDR_THEME_TAB_BACKGROUND_V; | 1195 tab_id = IDR_THEME_TAB_BACKGROUND_V; |
| 1196 frame_id = 0; |
1193 #endif | 1197 #endif |
1194 } else { | 1198 } else { |
1195 tab_id = IDR_THEME_TAB_BACKGROUND; | 1199 tab_id = IDR_THEME_TAB_BACKGROUND; |
| 1200 frame_id = IDR_THEME_FRAME; |
1196 } | 1201 } |
1197 // Explicitly map the id so we cache correctly. | 1202 // Explicitly map the id so we cache correctly. |
1198 const chrome::HostDesktopType host_desktop_type = GetHostDesktopType(this); | 1203 const chrome::HostDesktopType host_desktop_type = GetHostDesktopType(this); |
1199 tab_id = chrome::MapThemeImage(host_desktop_type, tab_id); | 1204 tab_id = chrome::MapThemeImage(host_desktop_type, tab_id); |
1200 | 1205 |
1201 const bool can_cache = !GetThemeProvider()->HasCustomImage(tab_id) && | 1206 // HasCustomImage() is only true if the theme provides the image. However, |
| 1207 // even if the theme does not provide a tab background, the theme machinery |
| 1208 // will make one if given a frame image. |
| 1209 ui::ThemeProvider* theme_provider = GetThemeProvider(); |
| 1210 const bool theme_provided_image = theme_provider->HasCustomImage(tab_id) || |
| 1211 (frame_id != 0 && theme_provider->HasCustomImage(frame_id)); |
| 1212 |
| 1213 const bool can_cache = !theme_provided_image && |
1202 !hover_controller_.ShouldDraw(); | 1214 !hover_controller_.ShouldDraw(); |
1203 | 1215 |
1204 if (can_cache) { | 1216 if (can_cache) { |
1205 gfx::ImageSkia cached_image( | 1217 gfx::ImageSkia cached_image( |
1206 GetCachedImage(tab_id, size(), canvas->scale_factor())); | 1218 GetCachedImage(tab_id, size(), canvas->scale_factor())); |
1207 if (cached_image.width() == 0) { | 1219 if (cached_image.width() == 0) { |
1208 gfx::Canvas tmp_canvas(size(), canvas->scale_factor(), false); | 1220 gfx::Canvas tmp_canvas(size(), canvas->scale_factor(), false); |
1209 PaintInactiveTabBackgroundUsingResourceId(&tmp_canvas, tab_id); | 1221 PaintInactiveTabBackgroundUsingResourceId(&tmp_canvas, tab_id); |
1210 cached_image = gfx::ImageSkia(tmp_canvas.ExtractImageRep()); | 1222 cached_image = gfx::ImageSkia(tmp_canvas.ExtractImageRep()); |
1211 SetCachedImage(tab_id, canvas->scale_factor(), cached_image); | 1223 SetCachedImage(tab_id, canvas->scale_factor(), cached_image); |
(...skipping 458 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1670 const gfx::ImageSkia& image) { | 1682 const gfx::ImageSkia& image) { |
1671 DCHECK_NE(scale_factor, ui::SCALE_FACTOR_NONE); | 1683 DCHECK_NE(scale_factor, ui::SCALE_FACTOR_NONE); |
1672 ImageCacheEntry entry; | 1684 ImageCacheEntry entry; |
1673 entry.resource_id = resource_id; | 1685 entry.resource_id = resource_id; |
1674 entry.scale_factor = scale_factor; | 1686 entry.scale_factor = scale_factor; |
1675 entry.image = image; | 1687 entry.image = image; |
1676 image_cache_->push_front(entry); | 1688 image_cache_->push_front(entry); |
1677 if (image_cache_->size() > kMaxImageCacheSize) | 1689 if (image_cache_->size() > kMaxImageCacheSize) |
1678 image_cache_->pop_back(); | 1690 image_cache_->pop_back(); |
1679 } | 1691 } |
OLD | NEW |