Chromium Code Reviews| 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 496 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 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 |
| 514 } else if ((data_.capture_state == TabRendererData::CAPTURE_STATE_NONE) && | 514 } else if ((data_.capture_state == TabRendererData::CAPTURE_STATE_NONE) && |
| 515 (old.capture_state != TabRendererData::CAPTURE_STATE_NONE)) { | 515 (old.capture_state != TabRendererData::CAPTURE_STATE_NONE)) { |
| 516 StopRecordingAnimation(); | 516 StopRecordingAnimation(); |
| 517 | 517 |
|
sky
2013/02/21 01:58:40
What's with all these empty lines. Can you nuke 51
cpu_(ooo_6.6-7.5)
2013/02/21 03:34:51
I know, it looked really funky but I was just goin
| |
| 518 } else if ((data_.capture_state != TabRendererData::CAPTURE_STATE_NONE) && | 518 } else if ((data_.capture_state != TabRendererData::CAPTURE_STATE_NONE) && |
| 519 (old.capture_state == TabRendererData::CAPTURE_STATE_NONE)) { | 519 (old.capture_state == TabRendererData::CAPTURE_STATE_NONE)) { |
| 520 StartRecordingAnimation(); | 520 StartRecordingAnimation(); |
| 521 | 521 |
| 522 } else if ((data_.audio_state == TabRendererData::AUDIO_STATE_NONE) && | |
| 523 (old.audio_state != TabRendererData::AUDIO_STATE_NONE)) { | |
| 524 StopAudioPlayingAnimation(); | |
| 525 | |
| 526 } else if ((data_.audio_state != TabRendererData::AUDIO_STATE_NONE) && | |
| 527 (old.audio_state == TabRendererData::AUDIO_STATE_NONE)) { | |
| 528 StartAudioPlayingAnimation(); | |
| 529 | |
| 522 } else { | 530 } else { |
| 523 if (IsPerformingCrashAnimation()) | 531 if (IsPerformingCrashAnimation()) |
| 524 StopCrashAnimation(); | 532 StopCrashAnimation(); |
| 525 ResetCrashedFavicon(); | 533 ResetCrashedFavicon(); |
| 526 } | 534 } |
| 527 | 535 |
| 528 if (old.mini != data_.mini) { | 536 if (old.mini != data_.mini) { |
| 529 if (tab_animation_.get() && tab_animation_->is_animating()) { | 537 if (tab_animation_.get() && tab_animation_->is_animating()) { |
| 530 tab_animation_->Stop(); | 538 tab_animation_->Stop(); |
| 531 tab_animation_.reset(NULL); | 539 tab_animation_.reset(NULL); |
| (...skipping 826 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1358 // Paint network activity (aka throbber) animation frame. | 1366 // Paint network activity (aka throbber) animation frame. |
| 1359 if (data().network_state != TabRendererData::NETWORK_STATE_NONE) { | 1367 if (data().network_state != TabRendererData::NETWORK_STATE_NONE) { |
| 1360 ui::ThemeProvider* tp = GetThemeProvider(); | 1368 ui::ThemeProvider* tp = GetThemeProvider(); |
| 1361 gfx::ImageSkia frames(*tp->GetImageSkiaNamed( | 1369 gfx::ImageSkia frames(*tp->GetImageSkiaNamed( |
| 1362 (data().network_state == TabRendererData::NETWORK_STATE_WAITING) ? | 1370 (data().network_state == TabRendererData::NETWORK_STATE_WAITING) ? |
| 1363 IDR_THROBBER_WAITING : IDR_THROBBER)); | 1371 IDR_THROBBER_WAITING : IDR_THROBBER)); |
| 1364 | 1372 |
| 1365 int icon_size = frames.height(); | 1373 int icon_size = frames.height(); |
| 1366 int image_offset = loading_animation_frame_ * icon_size; | 1374 int image_offset = loading_animation_frame_ * icon_size; |
| 1367 DrawIconCenter(canvas, frames, image_offset, | 1375 DrawIconCenter(canvas, frames, image_offset, |
| 1368 icon_size, icon_size, bounds, false, SkPaint()); | 1376 icon_size, icon_size, |
| 1377 bounds, false, SkPaint()); | |
| 1369 return; | 1378 return; |
| 1370 } | 1379 } |
| 1371 | 1380 |
| 1372 // Paint regular icon and potentially overlays. | 1381 // Paint regular icon and potentially overlays. |
| 1373 canvas->Save(); | 1382 canvas->Save(); |
| 1374 canvas->ClipRect(GetLocalBounds()); | 1383 canvas->ClipRect(GetLocalBounds()); |
| 1375 if (should_display_crashed_favicon_) { | 1384 if (should_display_crashed_favicon_) { |
| 1376 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); | 1385 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); |
| 1377 gfx::ImageSkia crashed_favicon(*rb.GetImageSkiaNamed(IDR_SAD_FAVICON)); | 1386 gfx::ImageSkia crashed_favicon(*rb.GetImageSkiaNamed(IDR_SAD_FAVICON)); |
| 1378 bounds.set_y(bounds.y() + favicon_hiding_offset_); | 1387 bounds.set_y(bounds.y() + favicon_hiding_offset_); |
| 1379 DrawIconCenter(canvas, crashed_favicon, 0, | 1388 DrawIconCenter(canvas, crashed_favicon, 0, |
| 1380 crashed_favicon.width(), | 1389 crashed_favicon.width(), |
| 1381 crashed_favicon.height(), bounds, true, SkPaint()); | 1390 crashed_favicon.height(), |
| 1391 bounds, true, SkPaint()); | |
| 1382 } else { | 1392 } else { |
| 1383 if (!data().favicon.isNull()) { | 1393 if (!data().favicon.isNull()) { |
| 1384 if (data().capture_state == TabRendererData::CAPTURE_STATE_PROJECTING) { | 1394 if (data().capture_state == TabRendererData::CAPTURE_STATE_PROJECTING) { |
| 1385 // If projecting, shrink favicon and add projection screen instead. | 1395 // If projecting, shrink favicon and add projection screen instead. |
| 1386 gfx::ImageSkia resized_icon = | 1396 gfx::ImageSkia resized_icon = |
| 1387 gfx::ImageSkiaOperations::CreateResizedImage( | 1397 gfx::ImageSkiaOperations::CreateResizedImage( |
| 1388 data().favicon, | 1398 data().favicon, |
| 1389 skia::ImageOperations::RESIZE_BEST, | 1399 skia::ImageOperations::RESIZE_BEST, |
| 1390 gfx::Size(data().favicon.width() * | 1400 gfx::Size(data().favicon.width() * |
| 1391 kProjectingFaviconResizeScale, | 1401 kProjectingFaviconResizeScale, |
| 1392 data().favicon.height() * | 1402 data().favicon.height() * |
| 1393 kProjectingFaviconResizeScale)); | 1403 kProjectingFaviconResizeScale)); |
| 1394 | 1404 |
| 1395 gfx::Rect resized_bounds(bounds); | 1405 gfx::Rect resized_bounds(bounds); |
| 1396 // Need to shift it up a bit vertically because the projection screen | 1406 // Need to shift it up a bit vertically because the projection screen |
| 1397 // is thinner on the top and bottom. | 1407 // is thinner on the top and bottom. |
| 1398 resized_bounds.set_y(resized_bounds.y() - 1); | 1408 resized_bounds.set_y(resized_bounds.y() - 1); |
| 1399 | 1409 |
| 1400 DrawIconCenter(canvas, resized_icon, 0, | 1410 DrawIconCenter(canvas, resized_icon, 0, |
| 1401 resized_icon.width(), | 1411 resized_icon.width(), |
| 1402 resized_icon.height(), | 1412 resized_icon.height(), |
| 1403 resized_bounds, true, SkPaint()); | 1413 resized_bounds, true, SkPaint()); |
| 1404 | 1414 |
| 1405 ui::ThemeProvider* tp = GetThemeProvider(); | 1415 ui::ThemeProvider* tp = GetThemeProvider(); |
| 1406 gfx::ImageSkia projection_screen( | 1416 gfx::ImageSkia projection_screen( |
| 1407 *tp->GetImageSkiaNamed(IDR_TAB_CAPTURE)); | 1417 *tp->GetImageSkiaNamed(IDR_TAB_CAPTURE)); |
| 1418 DrawIconCenter(canvas, projection_screen, 0, | |
| 1419 data().favicon.width(), | |
| 1420 data().favicon.height(), | |
| 1421 bounds, true, SkPaint()); | |
| 1422 } else { | |
| 1423 DrawIconCenter(canvas, data().favicon, 0, | |
| 1424 data().favicon.width(), | |
| 1425 data().favicon.height(), | |
| 1426 bounds, true, SkPaint()); | |
| 1408 | 1427 |
| 1409 DrawIconCenter(canvas, projection_screen, 0, | 1428 if (data().audio_state == TabRendererData::AUDIO_STATE_PLAYING) { |
| 1410 data().favicon.width(), | 1429 // If audio is playing, we draw on top of the icon the |
| 1411 data().favicon.height(), | 1430 // current equalizer animiation frame. |
| 1412 bounds, true, SkPaint()); | 1431 ui::ThemeProvider* tp = GetThemeProvider(); |
| 1413 } else { | 1432 gfx::ImageSkia equalizer(*tp->GetImageSkiaNamed(IDR_AUDIO_ANIMATION)); |
| 1414 // TODO(pkasting): Use code in tab_icon_view.cc:PaintIcon() (or switch | 1433 int icon_size = equalizer.height(); |
| 1415 // to using that class to render the favicon). | 1434 int number_of_frames = equalizer.width() / icon_size; |
| 1416 DrawIconCenter(canvas, data().favicon, 0, | 1435 int frame = static_cast<int>( |
| 1417 data().favicon.width(), | 1436 icon_animation_->GetCurrentValue() * number_of_frames); |
| 1418 data().favicon.height(), | 1437 int image_offset = frame * icon_size; |
| 1419 bounds, true, SkPaint()); | 1438 DrawIconAtLocation(canvas, equalizer, image_offset, |
| 1439 bounds.x(), bounds.y() + 1, | |
| 1440 icon_size, icon_size, | |
| 1441 false, SkPaint()); | |
| 1442 } | |
| 1420 } | 1443 } |
| 1421 } | 1444 } |
| 1422 } | 1445 } |
| 1423 canvas->Restore(); | 1446 canvas->Restore(); |
| 1424 | 1447 |
| 1425 // Paint recording or projecting animation overlay. | 1448 // Paint recording or projecting animation overlay. |
| 1426 if (data().capture_state != TabRendererData::CAPTURE_STATE_NONE) { | 1449 if (data().capture_state != TabRendererData::CAPTURE_STATE_NONE) { |
| 1427 SkPaint paint; | 1450 SkPaint paint; |
| 1428 paint.setAntiAlias(true); | 1451 paint.setAntiAlias(true); |
| 1429 U8CPU alpha = icon_animation_->GetCurrentValue() * 0xff; | 1452 U8CPU alpha = icon_animation_->GetCurrentValue() * 0xff; |
| (...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1596 icon_animation_.reset(animation); | 1619 icon_animation_.reset(animation); |
| 1597 } | 1620 } |
| 1598 | 1621 |
| 1599 void Tab::StopRecordingAnimation() { | 1622 void Tab::StopRecordingAnimation() { |
| 1600 if (!icon_animation_.get()) | 1623 if (!icon_animation_.get()) |
| 1601 return; | 1624 return; |
| 1602 icon_animation_->Stop(); | 1625 icon_animation_->Stop(); |
| 1603 icon_animation_.reset(); | 1626 icon_animation_.reset(); |
| 1604 } | 1627 } |
| 1605 | 1628 |
| 1629 void Tab::StartAudioPlayingAnimation() { | |
| 1630 ui::ThrobAnimation* animation = new ui::ThrobAnimation(this); | |
| 1631 animation->SetTweenType(ui::Tween::LINEAR); | |
| 1632 animation->SetThrobDuration(2000); | |
| 1633 animation->StartThrobbing(-1); | |
| 1634 icon_animation_.reset(animation); | |
| 1635 } | |
| 1636 | |
| 1637 void Tab::StopAudioPlayingAnimation() { | |
| 1638 if (!icon_animation_.get()) | |
| 1639 return; | |
| 1640 icon_animation_->Stop(); | |
| 1641 icon_animation_.reset(); | |
| 1642 } | |
| 1643 | |
| 1606 bool Tab::IsPerformingCrashAnimation() const { | 1644 bool Tab::IsPerformingCrashAnimation() const { |
| 1607 return icon_animation_.get() && data_.IsCrashed(); | 1645 return icon_animation_.get() && data_.IsCrashed(); |
| 1608 } | 1646 } |
| 1609 | 1647 |
| 1610 void Tab::ScheduleIconPaint() { | 1648 void Tab::ScheduleIconPaint() { |
| 1611 gfx::Rect bounds = GetIconBounds(); | 1649 gfx::Rect bounds = GetIconBounds(); |
| 1612 if (bounds.IsEmpty()) | 1650 if (bounds.IsEmpty()) |
| 1613 return; | 1651 return; |
| 1614 | 1652 |
| 1615 // Extends the area to the bottom when sad_favicon is | 1653 // Extends the area to the bottom when sad_favicon is |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1682 const gfx::ImageSkia& image) { | 1720 const gfx::ImageSkia& image) { |
| 1683 DCHECK_NE(scale_factor, ui::SCALE_FACTOR_NONE); | 1721 DCHECK_NE(scale_factor, ui::SCALE_FACTOR_NONE); |
| 1684 ImageCacheEntry entry; | 1722 ImageCacheEntry entry; |
| 1685 entry.resource_id = resource_id; | 1723 entry.resource_id = resource_id; |
| 1686 entry.scale_factor = scale_factor; | 1724 entry.scale_factor = scale_factor; |
| 1687 entry.image = image; | 1725 entry.image = image; |
| 1688 image_cache_->push_front(entry); | 1726 image_cache_->push_front(entry); |
| 1689 if (image_cache_->size() > kMaxImageCacheSize) | 1727 if (image_cache_->size() > kMaxImageCacheSize) |
| 1690 image_cache_->pop_back(); | 1728 image_cache_->pop_back(); |
| 1691 } | 1729 } |
| OLD | NEW |