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 226 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
237 // Max number of images to cache. This has to be at least two since rounding | 237 // Max number of images to cache. This has to be at least two since rounding |
238 // errors may lead to tabs in the same tabstrip having different sizes. | 238 // errors may lead to tabs in the same tabstrip having different sizes. |
239 const size_t kMaxImageCacheSize = 4; | 239 const size_t kMaxImageCacheSize = 4; |
240 | 240 |
241 // Height of the colored bar representing the favicon in immersive mode. | 241 // Height of the colored bar representing the favicon in immersive mode. |
242 const int kImmersiveBarHeight = 2; | 242 const int kImmersiveBarHeight = 2; |
243 | 243 |
244 // Distance between the favicon bar and the tab bar in immersive mode. | 244 // Distance between the favicon bar and the tab bar in immersive mode. |
245 const int kImmersiveBarSpacing = 2; | 245 const int kImmersiveBarSpacing = 2; |
246 | 246 |
| 247 // Scale to resize the current favicon by when projecting. |
| 248 const double kProjectingFaviconResizeScale = 0.75; |
| 249 |
| 250 // Scale to resize the projection sheet glow by. |
| 251 const double kProjectingGlowResizeScale = 2.0; |
| 252 |
247 // Draws the icon image at the center of |bounds|. | 253 // Draws the icon image at the center of |bounds|. |
248 void DrawIconCenter(gfx::Canvas* canvas, | 254 void DrawIconCenter(gfx::Canvas* canvas, |
249 const gfx::ImageSkia& image, | 255 const gfx::ImageSkia& image, |
250 int image_offset, | 256 int image_offset, |
251 int icon_width, | 257 int icon_width, |
252 int icon_height, | 258 int icon_height, |
253 const gfx::Rect& bounds, | 259 const gfx::Rect& bounds, |
254 bool filter, | 260 bool filter, |
255 const SkPaint& paint) { | 261 const SkPaint& paint) { |
256 // Center the image within bounds. | 262 // Center the image within bounds. |
(...skipping 1043 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1300 canvas->ClipRect(GetLocalBounds()); | 1306 canvas->ClipRect(GetLocalBounds()); |
1301 if (should_display_crashed_favicon_) { | 1307 if (should_display_crashed_favicon_) { |
1302 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); | 1308 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); |
1303 gfx::ImageSkia crashed_favicon(*rb.GetImageSkiaNamed(IDR_SAD_FAVICON)); | 1309 gfx::ImageSkia crashed_favicon(*rb.GetImageSkiaNamed(IDR_SAD_FAVICON)); |
1304 bounds.set_y(bounds.y() + favicon_hiding_offset_); | 1310 bounds.set_y(bounds.y() + favicon_hiding_offset_); |
1305 DrawIconCenter(canvas, crashed_favicon, 0, | 1311 DrawIconCenter(canvas, crashed_favicon, 0, |
1306 crashed_favicon.width(), | 1312 crashed_favicon.width(), |
1307 crashed_favicon.height(), bounds, true, SkPaint()); | 1313 crashed_favicon.height(), bounds, true, SkPaint()); |
1308 } else { | 1314 } else { |
1309 if (!data().favicon.isNull()) { | 1315 if (!data().favicon.isNull()) { |
1310 // TODO(pkasting): Use code in tab_icon_view.cc:PaintIcon() (or switch | 1316 if (data().capture_state == TabRendererData::CAPTURE_STATE_PROJECTING) { |
1311 // to using that class to render the favicon). | 1317 // If projecting, shrink favicon and add projection screen instead. |
1312 DrawIconCenter(canvas, data().favicon, 0, | 1318 gfx::ImageSkia resized_icon = |
1313 data().favicon.width(), | 1319 gfx::ImageSkiaOperations::CreateResizedImage( |
1314 data().favicon.height(), | 1320 data().favicon, |
1315 bounds, true, SkPaint()); | 1321 skia::ImageOperations::RESIZE_BEST, |
| 1322 gfx::Size(data().favicon.width() * |
| 1323 kProjectingFaviconResizeScale, |
| 1324 data().favicon.height() * |
| 1325 kProjectingFaviconResizeScale)); |
| 1326 |
| 1327 gfx::Rect resized_bounds(bounds); |
| 1328 // Need to shift it up a bit vertically because the projection screen |
| 1329 // is thinner on the top and bottom. |
| 1330 resized_bounds.set_y(resized_bounds.y() - 1); |
| 1331 |
| 1332 DrawIconCenter(canvas, resized_icon, 0, |
| 1333 resized_icon.width(), |
| 1334 resized_icon.height(), |
| 1335 resized_bounds, true, SkPaint()); |
| 1336 |
| 1337 ui::ThemeProvider* tp = GetThemeProvider(); |
| 1338 gfx::ImageSkia projection_screen( |
| 1339 *tp->GetImageSkiaNamed(IDR_TAB_CAPTURE)); |
| 1340 |
| 1341 DrawIconCenter(canvas, projection_screen, 0, |
| 1342 data().favicon.width(), |
| 1343 data().favicon.height(), |
| 1344 bounds, true, SkPaint()); |
| 1345 } else { |
| 1346 // TODO(pkasting): Use code in tab_icon_view.cc:PaintIcon() (or switch |
| 1347 // to using that class to render the favicon). |
| 1348 DrawIconCenter(canvas, data().favicon, 0, |
| 1349 data().favicon.width(), |
| 1350 data().favicon.height(), |
| 1351 bounds, true, SkPaint()); |
| 1352 } |
1316 } | 1353 } |
1317 } | 1354 } |
1318 canvas->Restore(); | 1355 canvas->Restore(); |
1319 | 1356 |
1320 // If recording, fade the recording icon on top of the favicon. | 1357 if (data().capture_state != TabRendererData::CAPTURE_STATE_NONE) { |
1321 if (data().recording) { | |
1322 if (!recording_animation_.get()) { | 1358 if (!recording_animation_.get()) { |
1323 recording_animation_.reset(new ui::ThrobAnimation(this)); | 1359 recording_animation_.reset(new ui::ThrobAnimation(this)); |
1324 recording_animation_->SetTweenType(ui::Tween::EASE_IN_OUT); | 1360 recording_animation_->SetTweenType(ui::Tween::EASE_IN_OUT); |
1325 recording_animation_->SetThrobDuration(kRecordingDurationMs); | 1361 recording_animation_->SetThrobDuration(kRecordingDurationMs); |
1326 recording_animation_->StartThrobbing(-1); | 1362 recording_animation_->StartThrobbing(-1); |
1327 } | 1363 } |
| 1364 |
1328 SkPaint paint; | 1365 SkPaint paint; |
1329 paint.setAntiAlias(true); | 1366 paint.setAntiAlias(true); |
1330 U8CPU alpha = recording_animation_->GetCurrentValue() * 0xff; | 1367 U8CPU alpha = recording_animation_->GetCurrentValue() * 0xff; |
1331 paint.setAlpha(alpha); | 1368 paint.setAlpha(alpha); |
1332 ui::ThemeProvider* tp = GetThemeProvider(); | 1369 ui::ThemeProvider* tp = GetThemeProvider(); |
1333 gfx::ImageSkia recording_dot(*tp->GetImageSkiaNamed(IDR_TAB_RECORDING)); | 1370 |
1334 DrawIconCenter(canvas, recording_dot, 0, | 1371 if (data().capture_state == TabRendererData::CAPTURE_STATE_PROJECTING) { |
1335 recording_dot.width(), recording_dot.height(), | 1372 // If projecting, add projection glow animation. |
1336 bounds, false, paint); | 1373 gfx::Rect glow_bounds(bounds); |
| 1374 glow_bounds.set_x(glow_bounds.x() - (32 - 24)); |
| 1375 glow_bounds.set_y(0); |
| 1376 glow_bounds.set_width(glow_bounds.width() * |
| 1377 kProjectingGlowResizeScale); |
| 1378 glow_bounds.set_height(glow_bounds.height() * |
| 1379 kProjectingGlowResizeScale); |
| 1380 |
| 1381 gfx::ImageSkia projection_glow( |
| 1382 *tp->GetImageSkiaNamed(IDR_TAB_CAPTURE_GLOW)); |
| 1383 DrawIconCenter(canvas, projection_glow, 0, |
| 1384 projection_glow.width(), projection_glow.height(), |
| 1385 glow_bounds, false, paint); |
| 1386 } else if (data().capture_state == |
| 1387 TabRendererData::CAPTURE_STATE_RECORDING) { |
| 1388 // If recording, fade the recording icon on top of the favicon. |
| 1389 gfx::ImageSkia recording_dot(*tp->GetImageSkiaNamed(IDR_TAB_RECORDING)); |
| 1390 DrawIconCenter(canvas, recording_dot, 0, |
| 1391 recording_dot.width(), recording_dot.height(), |
| 1392 bounds, false, paint); |
| 1393 } else { |
| 1394 NOTREACHED(); |
| 1395 } |
1337 } else { | 1396 } else { |
1338 recording_animation_.reset(); | 1397 recording_animation_.reset(); |
1339 } | 1398 } |
1340 } | 1399 } |
1341 } | 1400 } |
1342 | 1401 |
1343 void Tab::PaintTitle(gfx::Canvas* canvas, SkColor title_color) { | 1402 void Tab::PaintTitle(gfx::Canvas* canvas, SkColor title_color) { |
1344 // Paint the Title. | 1403 // Paint the Title. |
1345 const gfx::Rect& title_bounds = GetTitleBounds(); | 1404 const gfx::Rect& title_bounds = GetTitleBounds(); |
1346 string16 title = data().title; | 1405 string16 title = data().title; |
(...skipping 220 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1567 const gfx::ImageSkia& image) { | 1626 const gfx::ImageSkia& image) { |
1568 DCHECK_NE(scale_factor, ui::SCALE_FACTOR_NONE); | 1627 DCHECK_NE(scale_factor, ui::SCALE_FACTOR_NONE); |
1569 ImageCacheEntry entry; | 1628 ImageCacheEntry entry; |
1570 entry.resource_id = resource_id; | 1629 entry.resource_id = resource_id; |
1571 entry.scale_factor = scale_factor; | 1630 entry.scale_factor = scale_factor; |
1572 entry.image = image; | 1631 entry.image = image; |
1573 image_cache_->push_front(entry); | 1632 image_cache_->push_front(entry); |
1574 if (image_cache_->size() > kMaxImageCacheSize) | 1633 if (image_cache_->size() > kMaxImageCacheSize) |
1575 image_cache_->pop_back(); | 1634 image_cache_->pop_back(); |
1576 } | 1635 } |
OLD | NEW |