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 1173 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1184 PaintActiveTabBackground(canvas); | 1184 PaintActiveTabBackground(canvas); |
1185 canvas->Restore(); | 1185 canvas->Restore(); |
1186 } | 1186 } |
1187 } | 1187 } |
1188 } | 1188 } |
1189 | 1189 |
1190 void Tab::PaintInactiveTabBackgroundWithTitleChange( | 1190 void Tab::PaintInactiveTabBackgroundWithTitleChange( |
1191 gfx::Canvas* canvas, | 1191 gfx::Canvas* canvas, |
1192 gfx::MultiAnimation* animation) { | 1192 gfx::MultiAnimation* animation) { |
1193 // Render the inactive tab background. We'll use this for clipping. | 1193 // Render the inactive tab background. We'll use this for clipping. |
1194 gfx::Canvas background_canvas(size(), canvas->scale_factor(), false); | 1194 gfx::Canvas background_canvas(size(), canvas->image_scale(), false); |
1195 PaintInactiveTabBackground(&background_canvas); | 1195 PaintInactiveTabBackground(&background_canvas); |
1196 | 1196 |
1197 gfx::ImageSkia background_image(background_canvas.ExtractImageRep()); | 1197 gfx::ImageSkia background_image(background_canvas.ExtractImageRep()); |
1198 | 1198 |
1199 // Draw a radial gradient to hover_canvas. | 1199 // Draw a radial gradient to hover_canvas. |
1200 gfx::Canvas hover_canvas(size(), canvas->scale_factor(), false); | 1200 gfx::Canvas hover_canvas(size(), canvas->image_scale(), false); |
1201 int radius = kMiniTitleChangeGradientRadius; | 1201 int radius = kMiniTitleChangeGradientRadius; |
1202 int x0 = width() + radius - kMiniTitleChangeInitialXOffset; | 1202 int x0 = width() + radius - kMiniTitleChangeInitialXOffset; |
1203 int x1 = radius; | 1203 int x1 = radius; |
1204 int x2 = -radius; | 1204 int x2 = -radius; |
1205 int x; | 1205 int x; |
1206 if (animation->current_part_index() == 0) { | 1206 if (animation->current_part_index() == 0) { |
1207 x = animation->CurrentValueBetween(x0, x1); | 1207 x = animation->CurrentValueBetween(x0, x1); |
1208 } else if (animation->current_part_index() == 1) { | 1208 } else if (animation->current_part_index() == 1) { |
1209 x = x1; | 1209 x = x1; |
1210 } else { | 1210 } else { |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1253 // even if the theme does not provide a tab background, the theme machinery | 1253 // even if the theme does not provide a tab background, the theme machinery |
1254 // will make one if given a frame image. | 1254 // will make one if given a frame image. |
1255 ui::ThemeProvider* theme_provider = GetThemeProvider(); | 1255 ui::ThemeProvider* theme_provider = GetThemeProvider(); |
1256 const bool theme_provided_image = theme_provider->HasCustomImage(tab_id) || | 1256 const bool theme_provided_image = theme_provider->HasCustomImage(tab_id) || |
1257 (frame_id != 0 && theme_provider->HasCustomImage(frame_id)); | 1257 (frame_id != 0 && theme_provider->HasCustomImage(frame_id)); |
1258 | 1258 |
1259 const bool can_cache = !theme_provided_image && | 1259 const bool can_cache = !theme_provided_image && |
1260 !hover_controller_.ShouldDraw(); | 1260 !hover_controller_.ShouldDraw(); |
1261 | 1261 |
1262 if (can_cache) { | 1262 if (can_cache) { |
1263 gfx::ImageSkia cached_image( | 1263 ui::ScaleFactor scale_factor = |
1264 GetCachedImage(tab_id, size(), canvas->scale_factor())); | 1264 ui::GetSupportedScaleFactor(canvas->image_scale()); |
| 1265 gfx::ImageSkia cached_image(GetCachedImage(tab_id, size(), scale_factor)); |
1265 if (cached_image.width() == 0) { | 1266 if (cached_image.width() == 0) { |
1266 gfx::Canvas tmp_canvas(size(), canvas->scale_factor(), false); | 1267 gfx::Canvas tmp_canvas(size(), canvas->image_scale(), false); |
1267 PaintInactiveTabBackgroundUsingResourceId(&tmp_canvas, tab_id); | 1268 PaintInactiveTabBackgroundUsingResourceId(&tmp_canvas, tab_id); |
1268 cached_image = gfx::ImageSkia(tmp_canvas.ExtractImageRep()); | 1269 cached_image = gfx::ImageSkia(tmp_canvas.ExtractImageRep()); |
1269 SetCachedImage(tab_id, canvas->scale_factor(), cached_image); | 1270 SetCachedImage(tab_id, scale_factor, cached_image); |
1270 } | 1271 } |
1271 canvas->DrawImageInt(cached_image, 0, 0); | 1272 canvas->DrawImageInt(cached_image, 0, 0); |
1272 } else { | 1273 } else { |
1273 PaintInactiveTabBackgroundUsingResourceId(canvas, tab_id); | 1274 PaintInactiveTabBackgroundUsingResourceId(canvas, tab_id); |
1274 } | 1275 } |
1275 } | 1276 } |
1276 | 1277 |
1277 void Tab::PaintInactiveTabBackgroundUsingResourceId(gfx::Canvas* canvas, | 1278 void Tab::PaintInactiveTabBackgroundUsingResourceId(gfx::Canvas* canvas, |
1278 int tab_id) { | 1279 int tab_id) { |
1279 // WARNING: the inactive tab background may be cached. If you change what it | 1280 // WARNING: the inactive tab background may be cached. If you change what it |
(...skipping 12 matching lines...) Expand all Loading... |
1292 | 1293 |
1293 // If the theme is providing a custom background image, then its top edge | 1294 // If the theme is providing a custom background image, then its top edge |
1294 // should be at the top of the tab. Otherwise, we assume that the background | 1295 // should be at the top of the tab. Otherwise, we assume that the background |
1295 // image is a composited foreground + frame image. | 1296 // image is a composited foreground + frame image. |
1296 int bg_offset_y = GetThemeProvider()->HasCustomImage(tab_id) ? | 1297 int bg_offset_y = GetThemeProvider()->HasCustomImage(tab_id) ? |
1297 0 : background_offset_.y(); | 1298 0 : background_offset_.y(); |
1298 | 1299 |
1299 // We need a gfx::Canvas object to be able to extract the image from. | 1300 // We need a gfx::Canvas object to be able to extract the image from. |
1300 // We draw everything to this canvas and then output it to the canvas | 1301 // We draw everything to this canvas and then output it to the canvas |
1301 // parameter in addition to using it to mask the hover glow if needed. | 1302 // parameter in addition to using it to mask the hover glow if needed. |
1302 gfx::Canvas background_canvas(size(), canvas->scale_factor(), false); | 1303 gfx::Canvas background_canvas(size(), canvas->image_scale(), false); |
1303 | 1304 |
1304 // Draw left edge. Don't draw over the toolbar, as we're not the foreground | 1305 // Draw left edge. Don't draw over the toolbar, as we're not the foreground |
1305 // tab. | 1306 // tab. |
1306 gfx::ImageSkia tab_l = gfx::ImageSkiaOperations::CreateTiledImage( | 1307 gfx::ImageSkia tab_l = gfx::ImageSkiaOperations::CreateTiledImage( |
1307 *tab_bg, offset, bg_offset_y, tab_image->l_width, height()); | 1308 *tab_bg, offset, bg_offset_y, tab_image->l_width, height()); |
1308 gfx::ImageSkia theme_l = | 1309 gfx::ImageSkia theme_l = |
1309 gfx::ImageSkiaOperations::CreateMaskedImage(tab_l, *alpha->image_l); | 1310 gfx::ImageSkiaOperations::CreateMaskedImage(tab_l, *alpha->image_l); |
1310 background_canvas.DrawImageInt(theme_l, | 1311 background_canvas.DrawImageInt(theme_l, |
1311 0, 0, theme_l.width(), theme_l.height() - kToolbarOverlap, | 1312 0, 0, theme_l.width(), theme_l.height() - kToolbarOverlap, |
1312 0, 0, theme_l.width(), theme_l.height() - kToolbarOverlap, | 1313 0, 0, theme_l.width(), theme_l.height() - kToolbarOverlap, |
(...skipping 521 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1834 const gfx::ImageSkia& image) { | 1835 const gfx::ImageSkia& image) { |
1835 DCHECK_NE(scale_factor, ui::SCALE_FACTOR_NONE); | 1836 DCHECK_NE(scale_factor, ui::SCALE_FACTOR_NONE); |
1836 ImageCacheEntry entry; | 1837 ImageCacheEntry entry; |
1837 entry.resource_id = resource_id; | 1838 entry.resource_id = resource_id; |
1838 entry.scale_factor = scale_factor; | 1839 entry.scale_factor = scale_factor; |
1839 entry.image = image; | 1840 entry.image = image; |
1840 image_cache_->push_front(entry); | 1841 image_cache_->push_front(entry); |
1841 if (image_cache_->size() > kMaxImageCacheSize) | 1842 if (image_cache_->size() > kMaxImageCacheSize) |
1842 image_cache_->pop_back(); | 1843 image_cache_->pop_back(); |
1843 } | 1844 } |
OLD | NEW |