blob: 1f1be79e116755d1b68de26e2ade138b7bd82719 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
|
// Copyright (c) 2011 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef CHROME_BROWSER_UI_COCOA_ANIMATION_UTILS_H
#define CHROME_BROWSER_UI_COCOA_ANIMATION_UTILS_H
#pragma once
#import <Cocoa/Cocoa.h>
#import <QuartzCore/QuartzCore.h>
// This class is a stack-based helper useful for unit testing of Cocoa UI,
// and any other situation where you want to temporarily turn off Cocoa
// animation for the life of a function call or other limited scope.
// Just declare one of these, and all animations will complete instantly until
// this goes out of scope and pops our state off the Core Animation stack.
//
// Example:
// MyUnitTest() {
// WithNoAnimation at_all; // Turn off Cocoa auto animation in this scope.
class WithNoAnimation {
public:
WithNoAnimation() {
[NSAnimationContext beginGrouping];
[[NSAnimationContext currentContext] setDuration:0.0];
}
~WithNoAnimation() {
[NSAnimationContext endGrouping];
}
};
// Disables actions within a scope.
class ScopedCAActionDisabler {
public:
ScopedCAActionDisabler() {
[CATransaction begin];
[CATransaction setValue:[NSNumber numberWithBool:YES]
forKey:kCATransactionDisableActions];
}
~ScopedCAActionDisabler() {
[CATransaction commit];
}
};
// Sets a duration on actions within a scope.
class ScopedCAActionSetDuration {
public:
explicit ScopedCAActionSetDuration(NSTimeInterval duration) {
[CATransaction begin];
[CATransaction setValue:[NSNumber numberWithFloat:duration]
forKey:kCATransactionAnimationDuration];
}
~ScopedCAActionSetDuration() {
[CATransaction commit];
}
};
#endif // CHROME_BROWSER_UI_COCOA_ANIMATION_UTILS_H
|