Home | History | Annotate | Download | only in cocoa
      1 // Copyright (c) 2011 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 #ifndef CHROME_BROWSER_UI_COCOA_ANIMATABLE_IMAGE_H_
      6 #define CHROME_BROWSER_UI_COCOA_ANIMATABLE_IMAGE_H_
      7 #pragma once
      8 
      9 #import <Cocoa/Cocoa.h>
     10 #import <QuartzCore/QuartzCore.h>
     11 
     12 #include "base/memory/scoped_nsobject.h"
     13 
     14 // This class helps animate an NSImage's frame and opacity. It works by creating
     15 // a blank NSWindow in the size specified and giving it a layer on which the
     16 // image can be animated. Clients are free to embed this object as a child
     17 // window for easier window management. This class will clean itself up when
     18 // the animation has finished. Clients that install this as a child window
     19 // should listen for the NSWindowWillCloseNotification to perform any additional
     20 // cleanup.
     21 @interface AnimatableImage : NSWindow {
     22  @private
     23   // The image to animate.
     24   scoped_nsobject<NSImage> image_;
     25 
     26   // The frame of the image before and after the animation. This is in this
     27   // window's coordinate system.
     28   CGRect startFrame_;
     29   CGRect endFrame_;
     30 
     31   // Opacity values for the animation.
     32   CGFloat startOpacity_;
     33   CGFloat endOpacity_;
     34 
     35   // The amount of time it takes to animate the image.
     36   CGFloat duration_;
     37 }
     38 
     39 @property(nonatomic) CGRect startFrame;
     40 @property(nonatomic) CGRect endFrame;
     41 @property(nonatomic) CGFloat startOpacity;
     42 @property(nonatomic) CGFloat endOpacity;
     43 @property(nonatomic) CGFloat duration;
     44 
     45 // Designated initializer. Do not use any other NSWindow initializers. Creates
     46 // but does not show the blank animation window of the given size. The
     47 // |animationFrame| should usually be big enough to contain the |startFrame|
     48 // and |endFrame| properties of the animation.
     49 - (id)initWithImage:(NSImage*)image
     50      animationFrame:(NSRect)animationFrame;
     51 
     52 // Begins the animation.
     53 - (void)startAnimation;
     54 
     55 @end
     56 
     57 #endif  // CHROME_BROWSER_UI_COCOA_ANIMATABLE_IMAGE_H_
     58