Pin Chrome's shortcut to the Win10 Start menu on install and OS upgrade.
[chromium-blink-merge.git] / ui / base / cocoa / animation_utils.h
blob89e8fff8e02ecb0b5c2a26a18aa9ba22d17ffc21
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
3 // found in the LICENSE file.
5 #ifndef UI_BASE_COCOA_ANIMATION_UTILS_H
6 #define UI_BASE_COCOA_ANIMATION_UTILS_H
8 #import <Cocoa/Cocoa.h>
9 #import <QuartzCore/QuartzCore.h>
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.
17 // Example:
18 // MyUnitTest() {
19 // WithNoAnimation at_all; // Turn off Cocoa auto animation in this scope.
22 class WithNoAnimation {
23 public:
24 WithNoAnimation() {
25 [NSAnimationContext beginGrouping];
26 [[NSAnimationContext currentContext] setDuration:0.0];
29 ~WithNoAnimation() {
30 [NSAnimationContext endGrouping];
34 // Disables actions within a scope.
35 class ScopedCAActionDisabler {
36 public:
37 ScopedCAActionDisabler() {
38 [CATransaction begin];
39 [CATransaction setValue:[NSNumber numberWithBool:YES]
40 forKey:kCATransactionDisableActions];
43 ~ScopedCAActionDisabler() {
44 [CATransaction commit];
48 // Sets a duration on actions within a scope.
49 class ScopedCAActionSetDuration {
50 public:
51 explicit ScopedCAActionSetDuration(NSTimeInterval duration) {
52 [CATransaction begin];
53 [CATransaction setValue:[NSNumber numberWithFloat:duration]
54 forKey:kCATransactionAnimationDuration];
57 ~ScopedCAActionSetDuration() {
58 [CATransaction commit];
62 #endif // UI_BASE_COCOA_ANIMATION_UTILS_H