summaryrefslogtreecommitdiff
path: root/chromium/ui/gfx/animation/animation_mac.mm
blob: 11db964656813b40ffcf48ccd97be38a3fec5e01 (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
// Copyright 2016 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.

#include "ui/gfx/animation/animation.h"

#import <Cocoa/Cocoa.h>

#include "base/mac/mac_util.h"
#include "base/message_loop/message_loop_current.h"

// Only available since 10.12.
@interface NSWorkspace (AvailableSinceSierra)
@property(readonly) BOOL accessibilityDisplayShouldReduceMotion;
@end

namespace gfx {

// static
bool Animation::ShouldRenderRichAnimationImpl() {
  return !PrefersReducedMotion();
}

// static
bool Animation::ScrollAnimationsEnabledBySystem() {
  // Because of sandboxing, OS settings should only be queried from the browser
  // process.
  DCHECK(base::MessageLoopCurrentForUI::IsSet() ||
         base::MessageLoopCurrentForIO::IsSet());

  bool enabled = false;
  id value = nil;
  value = [[NSUserDefaults standardUserDefaults]
      objectForKey:@"NSScrollAnimationEnabled"];
  if (value)
    enabled = [value boolValue];
  return enabled;
}

// static
void Animation::UpdatePrefersReducedMotion() {
  // prefers_reduced_motion_ should only be modified on the UI thread.
  // TODO(crbug.com/927163): DCHECK this assertion once tests are well-behaved.

  // We default to assuming that animations are enabled, to avoid impacting the
  // experience for users on pre-10.12 systems.
  prefers_reduced_motion_ = false;
  SEL sel = @selector(accessibilityDisplayShouldReduceMotion);
  if ([[NSWorkspace sharedWorkspace] respondsToSelector:sel]) {
    prefers_reduced_motion_ =
        [[NSWorkspace sharedWorkspace] accessibilityDisplayShouldReduceMotion];
  }
}

} // namespace gfx