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

Side by Side Diff: chrome/browser/ui/cocoa/tabs/media_indicator_view.mm

Issue 69143003: [Mac] Fix title text re-expanding after tab media indicator shuts off. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 1 month 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
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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 #import "chrome/browser/ui/cocoa/tabs/media_indicator_view.h" 5 #import "chrome/browser/ui/cocoa/tabs/media_indicator_view.h"
6 6
7 #include "ui/gfx/animation/animation.h" 7 #include "ui/gfx/animation/animation.h"
8 #include "ui/gfx/animation/animation_delegate.h" 8 #include "ui/gfx/animation/animation_delegate.h"
9 #include "ui/gfx/image/image.h" 9 #include "ui/gfx/image/image.h"
10 10
11 class MediaIndicatorViewAnimationDelegate : public gfx::AnimationDelegate { 11 class MediaIndicatorViewAnimationDelegate : public gfx::AnimationDelegate {
12 public: 12 public:
13 MediaIndicatorViewAnimationDelegate(NSView* view, 13 MediaIndicatorViewAnimationDelegate(NSView* view,
14 TabMediaState* mediaState, 14 TabMediaState* mediaState,
15 TabMediaState* animatingMediaState) 15 TabMediaState* animatingMediaState)
16 : view_(view), mediaState_(mediaState), 16 : view_(view), mediaState_(mediaState),
17 animatingMediaState_(animatingMediaState) {} 17 animatingMediaState_(animatingMediaState),
18 doneCallbackObject_(nil), doneCallbackSelector_(nil) {}
18 virtual ~MediaIndicatorViewAnimationDelegate() {} 19 virtual ~MediaIndicatorViewAnimationDelegate() {}
19 20
21 void SetAnimationDoneCallback(id anObject, SEL selector) {
22 doneCallbackObject_ = anObject;
23 doneCallbackSelector_ = selector;
24 }
25
20 virtual void AnimationEnded(const gfx::Animation* animation) OVERRIDE { 26 virtual void AnimationEnded(const gfx::Animation* animation) OVERRIDE {
21 *animatingMediaState_ = *mediaState_; 27 *animatingMediaState_ = *mediaState_;
22 [view_ setNeedsDisplay:YES]; 28 [view_ setNeedsDisplay:YES];
29 [doneCallbackObject_ performSelector:doneCallbackSelector_];
23 } 30 }
24 virtual void AnimationProgressed(const gfx::Animation* animation) OVERRIDE { 31 virtual void AnimationProgressed(const gfx::Animation* animation) OVERRIDE {
25 [view_ setNeedsDisplay:YES]; 32 [view_ setNeedsDisplay:YES];
26 } 33 }
27 virtual void AnimationCanceled(const gfx::Animation* animation) OVERRIDE { 34 virtual void AnimationCanceled(const gfx::Animation* animation) OVERRIDE {
28 *animatingMediaState_ = *mediaState_; 35 AnimationEnded(animation);
29 [view_ setNeedsDisplay:YES];
30 } 36 }
31 37
32 private: 38 private:
33 NSView* const view_; 39 NSView* const view_;
34 TabMediaState* const mediaState_; 40 TabMediaState* const mediaState_;
35 TabMediaState* const animatingMediaState_; 41 TabMediaState* const animatingMediaState_;
42
43 id doneCallbackObject_;
44 SEL doneCallbackSelector_;
36 }; 45 };
37 46
38 @implementation MediaIndicatorView 47 @implementation MediaIndicatorView
39 48
40 @synthesize mediaState = mediaState_; 49 @synthesize mediaState = mediaState_;
41 @synthesize animatingMediaState = animatingMediaState_; 50 @synthesize animatingMediaState = animatingMediaState_;
42 51
43 - (id)init { 52 - (id)init {
44 if ((self = [super initWithFrame:NSZeroRect])) { 53 if ((self = [super initWithFrame:NSZeroRect])) {
45 mediaState_ = animatingMediaState_ = TAB_MEDIA_STATE_NONE; 54 mediaState_ = animatingMediaState_ = TAB_MEDIA_STATE_NONE;
(...skipping 26 matching lines...) Expand all
72 if (!delegate_) { 81 if (!delegate_) {
73 animatingMediaState_ = mediaState_; 82 animatingMediaState_ = mediaState_;
74 return; 83 return;
75 } 84 }
76 85
77 animation_ = chrome::CreateTabMediaIndicatorFadeAnimation(mediaState_); 86 animation_ = chrome::CreateTabMediaIndicatorFadeAnimation(mediaState_);
78 animation_->set_delegate(delegate_.get()); 87 animation_->set_delegate(delegate_.get());
79 animation_->Start(); 88 animation_->Start();
80 } 89 }
81 90
91 - (void)setAnimationDoneCallbackObject:(id)anObject withSelector:(SEL)selector {
92 if (delegate_)
93 delegate_->SetAnimationDoneCallback(anObject, selector);
94 }
95
82 - (void)drawRect:(NSRect)rect { 96 - (void)drawRect:(NSRect)rect {
83 if (!animation_) 97 if (!animation_)
84 return; 98 return;
85 99
86 double opaqueness = animation_->GetCurrentValue(); 100 double opaqueness = animation_->GetCurrentValue();
87 if (mediaState_ == TAB_MEDIA_STATE_NONE) 101 if (mediaState_ == TAB_MEDIA_STATE_NONE)
88 opaqueness = 1.0 - opaqueness; // Fading out, not in. 102 opaqueness = 1.0 - opaqueness; // Fading out, not in.
89 103
90 [[self image] drawInRect:[self bounds] 104 [[self image] drawInRect:[self bounds]
91 fromRect:NSZeroRect 105 fromRect:NSZeroRect
92 operation:NSCompositeSourceOver 106 operation:NSCompositeSourceOver
93 fraction:opaqueness]; 107 fraction:opaqueness];
94 } 108 }
95 109
96 - (void)disableAnimations { 110 - (void)disableAnimations {
97 delegate_.reset(); 111 delegate_.reset();
98 } 112 }
99 113
100 @end 114 @end
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698