OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #import "chrome/browser/ui/cocoa/tabs/tab_audio_indicator_view_mac.h" |
| 6 |
| 7 #include "chrome/browser/ui/tabs/tab_audio_indicator.h" |
| 8 #include "ui/gfx/canvas_skia_paint.h" |
| 9 #include "ui/gfx/rect.h" |
| 10 |
| 11 class TabAudioIndicatorDelegateMac : public TabAudioIndicator::Delegate { |
| 12 public: |
| 13 explicit TabAudioIndicatorDelegateMac(TabAudioIndicatorViewMac* view) |
| 14 : view_(view) { |
| 15 } |
| 16 |
| 17 virtual ~TabAudioIndicatorDelegateMac() {} |
| 18 |
| 19 virtual void ScheduleAudioIndicatorPaint() OVERRIDE { |
| 20 [view_ setNeedsDisplay:YES]; |
| 21 } |
| 22 |
| 23 private: |
| 24 TabAudioIndicatorViewMac* view_; |
| 25 |
| 26 DISALLOW_COPY_AND_ASSIGN(TabAudioIndicatorDelegateMac); |
| 27 }; |
| 28 |
| 29 @interface TabAudioIndicatorViewMac () |
| 30 @end |
| 31 |
| 32 @implementation TabAudioIndicatorViewMac |
| 33 |
| 34 - (id)initWithFrame:(NSRect)frame { |
| 35 if ((self = [super initWithFrame:frame])) { |
| 36 delegate_.reset(new TabAudioIndicatorDelegateMac(self)); |
| 37 tabAudioIndicator_.reset(new TabAudioIndicator(delegate_.get())); |
| 38 } |
| 39 return self; |
| 40 } |
| 41 |
| 42 - (void)setIsPlayingAudio:(BOOL)isPlayingAudio { |
| 43 tabAudioIndicator_->SetIsPlayingAudio(isPlayingAudio); |
| 44 } |
| 45 |
| 46 - (void)setBackgroundImage:(NSImage*)backgroundImage { |
| 47 backgroundImage_.reset([backgroundImage retain]); |
| 48 } |
| 49 |
| 50 - (BOOL)isAnimating { |
| 51 return tabAudioIndicator_->IsAnimating(); |
| 52 } |
| 53 |
| 54 - (void)drawRect:(NSRect)rect { |
| 55 [backgroundImage_ drawInRect:[self bounds] |
| 56 fromRect:NSZeroRect |
| 57 operation:NSCompositeSourceOver |
| 58 fraction:1]; |
| 59 |
| 60 gfx::CanvasSkiaPaint canvas(rect, false); |
| 61 canvas.set_composite_alpha(true); |
| 62 tabAudioIndicator_->Paint(&canvas, gfx::Rect(NSRectToCGRect([self bounds]))); |
| 63 } |
| 64 |
| 65 @end |
OLD | NEW |