Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(392)

Side by Side Diff: chrome/browser/ui/views/tabs/tab.cc

Issue 12328027: Audio indicator in each tab (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Created 7 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « chrome/browser/ui/views/tabs/tab.h ('k') | chrome/browser/ui/views/tabs/tab_renderer_data.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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
514 } else if ((data_.capture_state == TabRendererData::CAPTURE_STATE_NONE) && 513 } else if ((data_.capture_state == TabRendererData::CAPTURE_STATE_NONE) &&
515 (old.capture_state != TabRendererData::CAPTURE_STATE_NONE)) { 514 (old.capture_state != TabRendererData::CAPTURE_STATE_NONE)) {
516 StopRecordingAnimation(); 515 StopRecordingAnimation();
517
518 } else if ((data_.capture_state != TabRendererData::CAPTURE_STATE_NONE) && 516 } else if ((data_.capture_state != TabRendererData::CAPTURE_STATE_NONE) &&
519 (old.capture_state == TabRendererData::CAPTURE_STATE_NONE)) { 517 (old.capture_state == TabRendererData::CAPTURE_STATE_NONE)) {
520 StartRecordingAnimation(); 518 StartRecordingAnimation();
521 519 } else if ((data_.audio_state == TabRendererData::AUDIO_STATE_NONE) &&
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();
522 } else { 525 } else {
523 if (IsPerformingCrashAnimation()) 526 if (IsPerformingCrashAnimation())
524 StopCrashAnimation(); 527 StopCrashAnimation();
525 ResetCrashedFavicon(); 528 ResetCrashedFavicon();
526 } 529 }
527 530
528 if (old.mini != data_.mini) { 531 if (old.mini != data_.mini) {
529 if (tab_animation_.get() && tab_animation_->is_animating()) { 532 if (tab_animation_.get() && tab_animation_->is_animating()) {
530 tab_animation_->Stop(); 533 tab_animation_->Stop();
531 tab_animation_.reset(NULL); 534 tab_animation_.reset(NULL);
(...skipping 826 matching lines...) Expand 10 before | Expand all | Expand 10 after
1358 // Paint network activity (aka throbber) animation frame. 1361 // Paint network activity (aka throbber) animation frame.
1359 if (data().network_state != TabRendererData::NETWORK_STATE_NONE) { 1362 if (data().network_state != TabRendererData::NETWORK_STATE_NONE) {
1360 ui::ThemeProvider* tp = GetThemeProvider(); 1363 ui::ThemeProvider* tp = GetThemeProvider();
1361 gfx::ImageSkia frames(*tp->GetImageSkiaNamed( 1364 gfx::ImageSkia frames(*tp->GetImageSkiaNamed(
1362 (data().network_state == TabRendererData::NETWORK_STATE_WAITING) ? 1365 (data().network_state == TabRendererData::NETWORK_STATE_WAITING) ?
1363 IDR_THROBBER_WAITING : IDR_THROBBER)); 1366 IDR_THROBBER_WAITING : IDR_THROBBER));
1364 1367
1365 int icon_size = frames.height(); 1368 int icon_size = frames.height();
1366 int image_offset = loading_animation_frame_ * icon_size; 1369 int image_offset = loading_animation_frame_ * icon_size;
1367 DrawIconCenter(canvas, frames, image_offset, 1370 DrawIconCenter(canvas, frames, image_offset,
1368 icon_size, icon_size, bounds, false, SkPaint()); 1371 icon_size, icon_size,
1372 bounds, false, SkPaint());
1369 return; 1373 return;
1370 } 1374 }
1371 1375
1372 // Paint regular icon and potentially overlays. 1376 // Paint regular icon and potentially overlays.
1373 canvas->Save(); 1377 canvas->Save();
1374 canvas->ClipRect(GetLocalBounds()); 1378 canvas->ClipRect(GetLocalBounds());
1375 if (should_display_crashed_favicon_) { 1379 if (should_display_crashed_favicon_) {
1376 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); 1380 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance();
1377 gfx::ImageSkia crashed_favicon(*rb.GetImageSkiaNamed(IDR_SAD_FAVICON)); 1381 gfx::ImageSkia crashed_favicon(*rb.GetImageSkiaNamed(IDR_SAD_FAVICON));
1378 bounds.set_y(bounds.y() + favicon_hiding_offset_); 1382 bounds.set_y(bounds.y() + favicon_hiding_offset_);
1379 DrawIconCenter(canvas, crashed_favicon, 0, 1383 DrawIconCenter(canvas, crashed_favicon, 0,
1380 crashed_favicon.width(), 1384 crashed_favicon.width(),
1381 crashed_favicon.height(), bounds, true, SkPaint()); 1385 crashed_favicon.height(),
1386 bounds, true, SkPaint());
1382 } else { 1387 } else {
1383 if (!data().favicon.isNull()) { 1388 if (!data().favicon.isNull()) {
1384 if (data().capture_state == TabRendererData::CAPTURE_STATE_PROJECTING) { 1389 if (data().capture_state == TabRendererData::CAPTURE_STATE_PROJECTING) {
1385 // If projecting, shrink favicon and add projection screen instead. 1390 // If projecting, shrink favicon and add projection screen instead.
1386 gfx::ImageSkia resized_icon = 1391 gfx::ImageSkia resized_icon =
1387 gfx::ImageSkiaOperations::CreateResizedImage( 1392 gfx::ImageSkiaOperations::CreateResizedImage(
1388 data().favicon, 1393 data().favicon,
1389 skia::ImageOperations::RESIZE_BEST, 1394 skia::ImageOperations::RESIZE_BEST,
1390 gfx::Size(data().favicon.width() * 1395 gfx::Size(data().favicon.width() *
1391 kProjectingFaviconResizeScale, 1396 kProjectingFaviconResizeScale,
1392 data().favicon.height() * 1397 data().favicon.height() *
1393 kProjectingFaviconResizeScale)); 1398 kProjectingFaviconResizeScale));
1394 1399
1395 gfx::Rect resized_bounds(bounds); 1400 gfx::Rect resized_bounds(bounds);
1396 // Need to shift it up a bit vertically because the projection screen 1401 // Need to shift it up a bit vertically because the projection screen
1397 // is thinner on the top and bottom. 1402 // is thinner on the top and bottom.
1398 resized_bounds.set_y(resized_bounds.y() - 1); 1403 resized_bounds.set_y(resized_bounds.y() - 1);
1399 1404
1400 DrawIconCenter(canvas, resized_icon, 0, 1405 DrawIconCenter(canvas, resized_icon, 0,
1401 resized_icon.width(), 1406 resized_icon.width(),
1402 resized_icon.height(), 1407 resized_icon.height(),
1403 resized_bounds, true, SkPaint()); 1408 resized_bounds, true, SkPaint());
1404 1409
1405 ui::ThemeProvider* tp = GetThemeProvider(); 1410 ui::ThemeProvider* tp = GetThemeProvider();
1406 gfx::ImageSkia projection_screen( 1411 gfx::ImageSkia projection_screen(
1407 *tp->GetImageSkiaNamed(IDR_TAB_CAPTURE)); 1412 *tp->GetImageSkiaNamed(IDR_TAB_CAPTURE));
1413 DrawIconCenter(canvas, projection_screen, 0,
1414 data().favicon.width(),
1415 data().favicon.height(),
1416 bounds, true, SkPaint());
1417 } else {
1418 DrawIconCenter(canvas, data().favicon, 0,
1419 data().favicon.width(),
1420 data().favicon.height(),
1421 bounds, true, SkPaint());
1408 1422
1409 DrawIconCenter(canvas, projection_screen, 0, 1423 if (data().audio_state == TabRendererData::AUDIO_STATE_PLAYING) {
1410 data().favicon.width(), 1424 // If audio is playing, we draw on top of the icon the
1411 data().favicon.height(), 1425 // current equalizer animiation frame.
1412 bounds, true, SkPaint()); 1426 ui::ThemeProvider* tp = GetThemeProvider();
1413 } else { 1427 gfx::ImageSkia equalizer(*tp->GetImageSkiaNamed(IDR_AUDIO_ANIMATION));
1414 // TODO(pkasting): Use code in tab_icon_view.cc:PaintIcon() (or switch 1428 int icon_size = equalizer.height();
1415 // to using that class to render the favicon). 1429 int number_of_frames = equalizer.width() / icon_size;
1416 DrawIconCenter(canvas, data().favicon, 0, 1430 int frame = static_cast<int>(
1417 data().favicon.width(), 1431 icon_animation_->GetCurrentValue() * number_of_frames);
1418 data().favicon.height(), 1432 int image_offset = frame * icon_size;
1419 bounds, true, SkPaint()); 1433 DrawIconAtLocation(canvas, equalizer, image_offset,
1434 bounds.x(), bounds.y() + 1,
1435 icon_size, icon_size,
1436 false, SkPaint());
1437 }
1420 } 1438 }
1421 } 1439 }
1422 } 1440 }
1423 canvas->Restore(); 1441 canvas->Restore();
1424 1442
1425 // Paint recording or projecting animation overlay. 1443 // Paint recording or projecting animation overlay.
1426 if (data().capture_state != TabRendererData::CAPTURE_STATE_NONE) { 1444 if (data().capture_state != TabRendererData::CAPTURE_STATE_NONE) {
1427 SkPaint paint; 1445 SkPaint paint;
1428 paint.setAntiAlias(true); 1446 paint.setAntiAlias(true);
1429 U8CPU alpha = icon_animation_->GetCurrentValue() * 0xff; 1447 U8CPU alpha = icon_animation_->GetCurrentValue() * 0xff;
(...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after
1596 icon_animation_.reset(animation); 1614 icon_animation_.reset(animation);
1597 } 1615 }
1598 1616
1599 void Tab::StopRecordingAnimation() { 1617 void Tab::StopRecordingAnimation() {
1600 if (!icon_animation_.get()) 1618 if (!icon_animation_.get())
1601 return; 1619 return;
1602 icon_animation_->Stop(); 1620 icon_animation_->Stop();
1603 icon_animation_.reset(); 1621 icon_animation_.reset();
1604 } 1622 }
1605 1623
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
1606 bool Tab::IsPerformingCrashAnimation() const { 1639 bool Tab::IsPerformingCrashAnimation() const {
1607 return icon_animation_.get() && data_.IsCrashed(); 1640 return icon_animation_.get() && data_.IsCrashed();
1608 } 1641 }
1609 1642
1610 void Tab::ScheduleIconPaint() { 1643 void Tab::ScheduleIconPaint() {
1611 gfx::Rect bounds = GetIconBounds(); 1644 gfx::Rect bounds = GetIconBounds();
1612 if (bounds.IsEmpty()) 1645 if (bounds.IsEmpty())
1613 return; 1646 return;
1614 1647
1615 // Extends the area to the bottom when sad_favicon is 1648 // Extends the area to the bottom when sad_favicon is
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
1682 const gfx::ImageSkia& image) { 1715 const gfx::ImageSkia& image) {
1683 DCHECK_NE(scale_factor, ui::SCALE_FACTOR_NONE); 1716 DCHECK_NE(scale_factor, ui::SCALE_FACTOR_NONE);
1684 ImageCacheEntry entry; 1717 ImageCacheEntry entry;
1685 entry.resource_id = resource_id; 1718 entry.resource_id = resource_id;
1686 entry.scale_factor = scale_factor; 1719 entry.scale_factor = scale_factor;
1687 entry.image = image; 1720 entry.image = image;
1688 image_cache_->push_front(entry); 1721 image_cache_->push_front(entry);
1689 if (image_cache_->size() > kMaxImageCacheSize) 1722 if (image_cache_->size() > kMaxImageCacheSize)
1690 image_cache_->pop_back(); 1723 image_cache_->pop_back();
1691 } 1724 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/views/tabs/tab.h ('k') | chrome/browser/ui/views/tabs/tab_renderer_data.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698