Commit 7f9a9aac authored by shrike's avatar shrike Committed by Commit bot

A comment in the SpriteView source states that the animation

should not run when the window is minimized, nor in the middle
of a minimize animation; it refers to http://crbug.com/350329
as the bug related to fixing this problem. However, although the
SpriteView registers for the NSWindowWillMiniaturizeNotification it
doesn't check for its occurrence, and so does not actually recognize
when a window is being minimized. As a result, the SpriteView's
animation continues running when its window is miniaturized.

This change adds a check for NSWindowWillMiniaturizeNotification and
stops the animation when caught. This change also adds a unit test to
confirm that the animation stops on window miniaturization.

My SpinnerView class was based on SpriteView, which is how I
discovered this bug. The fix and unit test both come from SpinnerView.

BUG=472836

Review URL: https://codereview.chromium.org/1052973004

Cr-Commit-Position: refs/heads/master@{#323963}
parent f9d2a282
...@@ -73,10 +73,13 @@ static const CGFloat kFrameDuration = 0.03; // 30ms for each animation frame. ...@@ -73,10 +73,13 @@ static const CGFloat kFrameDuration = 0.03; // 30ms for each animation frame.
// Only animate the sprites if we are attached to a window, and that window // Only animate the sprites if we are attached to a window, and that window
// is not currently minimized or in the middle of a minimize animation. // is not currently minimized or in the middle of a minimize animation.
// http://crbug.com/350329 // http://crbug.com/350329
if ([self window] && ![[self window] isMiniaturized]) { if ([self window] && ![[self window] isMiniaturized] &&
if ([imageLayer_ animationForKey:[spriteAnimation_ keyPath]] == nil) ![[notification name] isEqualToString:
NSWindowWillMiniaturizeNotification]) {
if ([imageLayer_ animationForKey:[spriteAnimation_ keyPath]] == nil) {
[imageLayer_ addAnimation:spriteAnimation_.get() [imageLayer_ addAnimation:spriteAnimation_.get()
forKey:[spriteAnimation_ keyPath]]; forKey:[spriteAnimation_ keyPath]];
}
} else { } else {
[imageLayer_ removeAnimationForKey:[spriteAnimation_ keyPath]]; [imageLayer_ removeAnimationForKey:[spriteAnimation_ keyPath]];
} }
......
...@@ -13,6 +13,20 @@ ...@@ -13,6 +13,20 @@
#include "ui/gfx/image/image.h" #include "ui/gfx/image/image.h"
#include "ui/resources/grit/ui_resources.h" #include "ui/resources/grit/ui_resources.h"
@interface SpriteView (ExposedForTesting)
- (BOOL)isAnimating;
@end
@implementation SpriteView (ExposedForTesting)
- (BOOL)isAnimating {
return [imageLayer_ animationForKey:[spriteAnimation_ keyPath]] != nil;
}
@end
namespace { namespace {
class SpriteViewTest : public CocoaTest { class SpriteViewTest : public CocoaTest {
...@@ -41,4 +55,25 @@ TEST_F(SpriteViewTest, TestViewFrame) { ...@@ -41,4 +55,25 @@ TEST_F(SpriteViewTest, TestViewFrame) {
EXPECT_EQ(imageSize.height, NSHeight(frame)); EXPECT_EQ(imageSize.height, NSHeight(frame));
} }
TEST_F(SpriteViewTest, StopAnimationOnMiniaturize) {
EXPECT_TRUE([view_ isAnimating]);
[test_window() miniaturize:nil];
EXPECT_FALSE([view_ isAnimating]);
[test_window() deminiaturize:nil];
EXPECT_TRUE([view_ isAnimating]);
}
TEST_F(SpriteViewTest,
StopAnimationOnRemoveFromSuperview) {
EXPECT_TRUE([view_ isAnimating]);
[view_ removeFromSuperview];
EXPECT_FALSE([view_ isAnimating]);
[[test_window() contentView] addSubview:view_];
EXPECT_TRUE([view_ isAnimating]);
}
} // namespace } // namespace
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment