• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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_ANIMATION_UTILS_H
6 #define CHROME_BROWSER_UI_COCOA_ANIMATION_UTILS_H
7 #pragma once
8 
9 #import <Cocoa/Cocoa.h>
10 
11 // This class is a stack-based helper useful for unit testing of Cocoa UI,
12 // and any other situation where you want to temporarily turn off Cocoa
13 // animation for the life of a function call or other limited scope.
14 // Just declare one of these, and all animations will complete instantly until
15 // this goes out of scope and pops our state off the Core Animation stack.
16 //
17 // Example:
18 //  MyUnitTest() {
19 //    WithNoAnimation at_all; // Turn off Cocoa auto animation in this scope.
20 
21 
22 class WithNoAnimation {
23  public:
WithNoAnimation()24   WithNoAnimation() {
25     [NSAnimationContext beginGrouping];
26     [[NSAnimationContext currentContext] setDuration:0.0];
27   }
28 
~WithNoAnimation()29   ~WithNoAnimation() {
30    [NSAnimationContext endGrouping];
31   }
32 };
33 
34 
35 #endif // CHROME_BROWSER_UI_COCOA_ANIMATION_UTILS_H
36