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 492 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
503 // switches to them. Don't display animations for these unless they're | 503 // switches to them. Don't display animations for these unless they're |
504 // selected (i.e. in the foreground) -- we won't reload these | 504 // selected (i.e. in the foreground) -- we won't reload these |
505 // automatically since we don't want to get into a crash loop. | 505 // automatically since we don't want to get into a crash loop. |
506 if (IsSelected() || | 506 if (IsSelected() || |
507 data_.crashed_status != base::TERMINATION_STATUS_PROCESS_WAS_KILLED) | 507 data_.crashed_status != base::TERMINATION_STATUS_PROCESS_WAS_KILLED) |
508 StartCrashAnimation(); | 508 StartCrashAnimation(); |
509 #else | 509 #else |
510 StartCrashAnimation(); | 510 StartCrashAnimation(); |
511 #endif | 511 #endif |
512 } | 512 } |
| 513 |
513 } else if ((data_.capture_state == TabRendererData::CAPTURE_STATE_NONE) && | 514 } else if ((data_.capture_state == TabRendererData::CAPTURE_STATE_NONE) && |
514 (old.capture_state != TabRendererData::CAPTURE_STATE_NONE)) { | 515 (old.capture_state != TabRendererData::CAPTURE_STATE_NONE)) { |
515 StopRecordingAnimation(); | 516 StopRecordingAnimation(); |
| 517 |
516 } else if ((data_.capture_state != TabRendererData::CAPTURE_STATE_NONE) && | 518 } else if ((data_.capture_state != TabRendererData::CAPTURE_STATE_NONE) && |
517 (old.capture_state == TabRendererData::CAPTURE_STATE_NONE)) { | 519 (old.capture_state == TabRendererData::CAPTURE_STATE_NONE)) { |
518 StartRecordingAnimation(); | 520 StartRecordingAnimation(); |
519 } else if ((data_.audio_state == TabRendererData::AUDIO_STATE_NONE) && | 521 |
520 (old.audio_state != TabRendererData::AUDIO_STATE_NONE)) { | |
521 StopAudioPlayingAnimation(); | |
522 } else if ((data_.audio_state != TabRendererData::AUDIO_STATE_NONE) && | |
523 (old.audio_state == TabRendererData::AUDIO_STATE_NONE)) { | |
524 StartAudioPlayingAnimation(); | |
525 } else { | 522 } else { |
526 if (IsPerformingCrashAnimation()) | 523 if (IsPerformingCrashAnimation()) |
527 StopCrashAnimation(); | 524 StopCrashAnimation(); |
528 ResetCrashedFavicon(); | 525 ResetCrashedFavicon(); |
529 } | 526 } |
530 | 527 |
531 if (old.mini != data_.mini) { | 528 if (old.mini != data_.mini) { |
532 if (tab_animation_.get() && tab_animation_->is_animating()) { | 529 if (tab_animation_.get() && tab_animation_->is_animating()) { |
533 tab_animation_->Stop(); | 530 tab_animation_->Stop(); |
534 tab_animation_.reset(NULL); | 531 tab_animation_.reset(NULL); |
(...skipping 826 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1361 // Paint network activity (aka throbber) animation frame. | 1358 // Paint network activity (aka throbber) animation frame. |
1362 if (data().network_state != TabRendererData::NETWORK_STATE_NONE) { | 1359 if (data().network_state != TabRendererData::NETWORK_STATE_NONE) { |
1363 ui::ThemeProvider* tp = GetThemeProvider(); | 1360 ui::ThemeProvider* tp = GetThemeProvider(); |
1364 gfx::ImageSkia frames(*tp->GetImageSkiaNamed( | 1361 gfx::ImageSkia frames(*tp->GetImageSkiaNamed( |
1365 (data().network_state == TabRendererData::NETWORK_STATE_WAITING) ? | 1362 (data().network_state == TabRendererData::NETWORK_STATE_WAITING) ? |
1366 IDR_THROBBER_WAITING : IDR_THROBBER)); | 1363 IDR_THROBBER_WAITING : IDR_THROBBER)); |
1367 | 1364 |
1368 int icon_size = frames.height(); | 1365 int icon_size = frames.height(); |
1369 int image_offset = loading_animation_frame_ * icon_size; | 1366 int image_offset = loading_animation_frame_ * icon_size; |
1370 DrawIconCenter(canvas, frames, image_offset, | 1367 DrawIconCenter(canvas, frames, image_offset, |
1371 icon_size, icon_size, | 1368 icon_size, icon_size, bounds, false, SkPaint()); |
1372 bounds, false, SkPaint()); | |
1373 return; | 1369 return; |
1374 } | 1370 } |
1375 | 1371 |
1376 // Paint regular icon and potentially overlays. | 1372 // Paint regular icon and potentially overlays. |
1377 canvas->Save(); | 1373 canvas->Save(); |
1378 canvas->ClipRect(GetLocalBounds()); | 1374 canvas->ClipRect(GetLocalBounds()); |
1379 if (should_display_crashed_favicon_) { | 1375 if (should_display_crashed_favicon_) { |
1380 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); | 1376 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); |
1381 gfx::ImageSkia crashed_favicon(*rb.GetImageSkiaNamed(IDR_SAD_FAVICON)); | 1377 gfx::ImageSkia crashed_favicon(*rb.GetImageSkiaNamed(IDR_SAD_FAVICON)); |
1382 bounds.set_y(bounds.y() + favicon_hiding_offset_); | 1378 bounds.set_y(bounds.y() + favicon_hiding_offset_); |
1383 DrawIconCenter(canvas, crashed_favicon, 0, | 1379 DrawIconCenter(canvas, crashed_favicon, 0, |
1384 crashed_favicon.width(), | 1380 crashed_favicon.width(), |
1385 crashed_favicon.height(), | 1381 crashed_favicon.height(), bounds, true, SkPaint()); |
1386 bounds, true, SkPaint()); | |
1387 } else { | 1382 } else { |
1388 if (!data().favicon.isNull()) { | 1383 if (!data().favicon.isNull()) { |
1389 if (data().capture_state == TabRendererData::CAPTURE_STATE_PROJECTING) { | 1384 if (data().capture_state == TabRendererData::CAPTURE_STATE_PROJECTING) { |
1390 // If projecting, shrink favicon and add projection screen instead. | 1385 // If projecting, shrink favicon and add projection screen instead. |
1391 gfx::ImageSkia resized_icon = | 1386 gfx::ImageSkia resized_icon = |
1392 gfx::ImageSkiaOperations::CreateResizedImage( | 1387 gfx::ImageSkiaOperations::CreateResizedImage( |
1393 data().favicon, | 1388 data().favicon, |
1394 skia::ImageOperations::RESIZE_BEST, | 1389 skia::ImageOperations::RESIZE_BEST, |
1395 gfx::Size(data().favicon.width() * | 1390 gfx::Size(data().favicon.width() * |
1396 kProjectingFaviconResizeScale, | 1391 kProjectingFaviconResizeScale, |
1397 data().favicon.height() * | 1392 data().favicon.height() * |
1398 kProjectingFaviconResizeScale)); | 1393 kProjectingFaviconResizeScale)); |
1399 | 1394 |
1400 gfx::Rect resized_bounds(bounds); | 1395 gfx::Rect resized_bounds(bounds); |
1401 // Need to shift it up a bit vertically because the projection screen | 1396 // Need to shift it up a bit vertically because the projection screen |
1402 // is thinner on the top and bottom. | 1397 // is thinner on the top and bottom. |
1403 resized_bounds.set_y(resized_bounds.y() - 1); | 1398 resized_bounds.set_y(resized_bounds.y() - 1); |
1404 | 1399 |
1405 DrawIconCenter(canvas, resized_icon, 0, | 1400 DrawIconCenter(canvas, resized_icon, 0, |
1406 resized_icon.width(), | 1401 resized_icon.width(), |
1407 resized_icon.height(), | 1402 resized_icon.height(), |
1408 resized_bounds, true, SkPaint()); | 1403 resized_bounds, true, SkPaint()); |
1409 | 1404 |
1410 ui::ThemeProvider* tp = GetThemeProvider(); | 1405 ui::ThemeProvider* tp = GetThemeProvider(); |
1411 gfx::ImageSkia projection_screen( | 1406 gfx::ImageSkia projection_screen( |
1412 *tp->GetImageSkiaNamed(IDR_TAB_CAPTURE)); | 1407 *tp->GetImageSkiaNamed(IDR_TAB_CAPTURE)); |
| 1408 |
1413 DrawIconCenter(canvas, projection_screen, 0, | 1409 DrawIconCenter(canvas, projection_screen, 0, |
1414 data().favicon.width(), | 1410 data().favicon.width(), |
1415 data().favicon.height(), | 1411 data().favicon.height(), |
1416 bounds, true, SkPaint()); | 1412 bounds, true, SkPaint()); |
1417 } else { | 1413 } else { |
| 1414 // TODO(pkasting): Use code in tab_icon_view.cc:PaintIcon() (or switch |
| 1415 // to using that class to render the favicon). |
1418 DrawIconCenter(canvas, data().favicon, 0, | 1416 DrawIconCenter(canvas, data().favicon, 0, |
1419 data().favicon.width(), | 1417 data().favicon.width(), |
1420 data().favicon.height(), | 1418 data().favicon.height(), |
1421 bounds, true, SkPaint()); | 1419 bounds, true, SkPaint()); |
1422 | |
1423 if (data().audio_state == TabRendererData::AUDIO_STATE_PLAYING) { | |
1424 // If audio is playing, we draw on top of the icon the | |
1425 // current equalizer animiation frame. | |
1426 ui::ThemeProvider* tp = GetThemeProvider(); | |
1427 gfx::ImageSkia equalizer(*tp->GetImageSkiaNamed(IDR_AUDIO_ANIMATION)); | |
1428 int icon_size = equalizer.height(); | |
1429 int number_of_frames = equalizer.width() / icon_size; | |
1430 int frame = static_cast<int>( | |
1431 icon_animation_->GetCurrentValue() * number_of_frames); | |
1432 int image_offset = frame * icon_size; | |
1433 DrawIconAtLocation(canvas, equalizer, image_offset, | |
1434 bounds.x(), bounds.y() + 1, | |
1435 icon_size, icon_size, | |
1436 false, SkPaint()); | |
1437 } | |
1438 } | 1420 } |
1439 } | 1421 } |
1440 } | 1422 } |
1441 canvas->Restore(); | 1423 canvas->Restore(); |
1442 | 1424 |
1443 // Paint recording or projecting animation overlay. | 1425 // Paint recording or projecting animation overlay. |
1444 if (data().capture_state != TabRendererData::CAPTURE_STATE_NONE) { | 1426 if (data().capture_state != TabRendererData::CAPTURE_STATE_NONE) { |
1445 SkPaint paint; | 1427 SkPaint paint; |
1446 paint.setAntiAlias(true); | 1428 paint.setAntiAlias(true); |
1447 U8CPU alpha = icon_animation_->GetCurrentValue() * 0xff; | 1429 U8CPU alpha = icon_animation_->GetCurrentValue() * 0xff; |
(...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1614 icon_animation_.reset(animation); | 1596 icon_animation_.reset(animation); |
1615 } | 1597 } |
1616 | 1598 |
1617 void Tab::StopRecordingAnimation() { | 1599 void Tab::StopRecordingAnimation() { |
1618 if (!icon_animation_.get()) | 1600 if (!icon_animation_.get()) |
1619 return; | 1601 return; |
1620 icon_animation_->Stop(); | 1602 icon_animation_->Stop(); |
1621 icon_animation_.reset(); | 1603 icon_animation_.reset(); |
1622 } | 1604 } |
1623 | 1605 |
1624 void Tab::StartAudioPlayingAnimation() { | |
1625 ui::ThrobAnimation* animation = new ui::ThrobAnimation(this); | |
1626 animation->SetTweenType(ui::Tween::LINEAR); | |
1627 animation->SetThrobDuration(2000); | |
1628 animation->StartThrobbing(-1); | |
1629 icon_animation_.reset(animation); | |
1630 } | |
1631 | |
1632 void Tab::StopAudioPlayingAnimation() { | |
1633 if (!icon_animation_.get()) | |
1634 return; | |
1635 icon_animation_->Stop(); | |
1636 icon_animation_.reset(); | |
1637 } | |
1638 | |
1639 bool Tab::IsPerformingCrashAnimation() const { | 1606 bool Tab::IsPerformingCrashAnimation() const { |
1640 return icon_animation_.get() && data_.IsCrashed(); | 1607 return icon_animation_.get() && data_.IsCrashed(); |
1641 } | 1608 } |
1642 | 1609 |
1643 void Tab::ScheduleIconPaint() { | 1610 void Tab::ScheduleIconPaint() { |
1644 gfx::Rect bounds = GetIconBounds(); | 1611 gfx::Rect bounds = GetIconBounds(); |
1645 if (bounds.IsEmpty()) | 1612 if (bounds.IsEmpty()) |
1646 return; | 1613 return; |
1647 | 1614 |
1648 // Extends the area to the bottom when sad_favicon is | 1615 // Extends the area to the bottom when sad_favicon is |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1715 const gfx::ImageSkia& image) { | 1682 const gfx::ImageSkia& image) { |
1716 DCHECK_NE(scale_factor, ui::SCALE_FACTOR_NONE); | 1683 DCHECK_NE(scale_factor, ui::SCALE_FACTOR_NONE); |
1717 ImageCacheEntry entry; | 1684 ImageCacheEntry entry; |
1718 entry.resource_id = resource_id; | 1685 entry.resource_id = resource_id; |
1719 entry.scale_factor = scale_factor; | 1686 entry.scale_factor = scale_factor; |
1720 entry.image = image; | 1687 entry.image = image; |
1721 image_cache_->push_front(entry); | 1688 image_cache_->push_front(entry); |
1722 if (image_cache_->size() > kMaxImageCacheSize) | 1689 if (image_cache_->size() > kMaxImageCacheSize) |
1723 image_cache_->pop_back(); | 1690 image_cache_->pop_back(); |
1724 } | 1691 } |
OLD | NEW |