Commit bc3d0e66 authored by Stephen McGruer's avatar Stephen McGruer Committed by Commit Bot

Initial hookup of CSS prefers-reduced-motion for Mac/Win

For now, the hookup is static; changing the OS level settings will not
cause the settings to be recalculated.

Test: Manually verified functional on Mac and Windows.
Bug: 722548
Change-Id: Iccb601a28d26a7ac659677041ce637bdd19e7db3
Reviewed-on: https://chromium-review.googlesource.com/c/1417754
Commit-Queue: Stephen McGruer <smcgruer@chromium.org>
Reviewed-by: default avatarDominic Mazzoni <dmazzoni@chromium.org>
Reviewed-by: default avatarKinuko Yasuda <kinuko@chromium.org>
Reviewed-by: default avatarIan Vollick <vollick@chromium.org>
Cr-Commit-Position: refs/heads/master@{#625249}
parent 4c82cd90
......@@ -532,6 +532,8 @@ const WebPreferences RenderViewHostImpl::ComputeWebPreferences() {
(!command_line.HasSwitch(switches::kDisableSmoothScrolling) &&
gfx::Animation::ScrollAnimationsEnabledBySystem());
prefs.prefers_reduced_motion = gfx::Animation::PrefersReducedMotion();
if (ChildProcessSecurityPolicyImpl::GetInstance()->HasWebUIBindings(
GetProcess()->GetID())) {
prefs.loads_images_automatically = true;
......
......@@ -165,6 +165,7 @@ IPC_STRUCT_TRAITS_BEGIN(content::WebPreferences)
IPC_STRUCT_TRAITS_MEMBER(strictly_block_blockable_mixed_content)
IPC_STRUCT_TRAITS_MEMBER(block_mixed_plugin_content)
IPC_STRUCT_TRAITS_MEMBER(enable_scroll_animator)
IPC_STRUCT_TRAITS_MEMBER(prefers_reduced_motion)
IPC_STRUCT_TRAITS_MEMBER(password_echo_enabled)
IPC_STRUCT_TRAITS_MEMBER(should_clear_document_background)
IPC_STRUCT_TRAITS_MEMBER(touch_event_feature_detection_enabled)
......
......@@ -121,6 +121,7 @@ WebPreferences::WebPreferences()
should_print_backgrounds(false),
should_clear_document_background(true),
enable_scroll_animator(false),
prefers_reduced_motion(false),
touch_event_feature_detection_enabled(false),
touch_adjustment_enabled(true),
pointer_events_max_touch_points(0),
......
......@@ -161,6 +161,7 @@ struct CONTENT_EXPORT WebPreferences {
bool should_print_backgrounds;
bool should_clear_document_background;
bool enable_scroll_animator;
bool prefers_reduced_motion;
bool touch_event_feature_detection_enabled;
bool touch_adjustment_enabled;
int pointer_events_max_touch_points;
......
......@@ -757,6 +757,7 @@ void RenderView::ApplyWebPreferences(const WebPreferences& prefs,
settings->SetShouldClearDocumentBackground(
prefs.should_clear_document_background);
settings->SetEnableScrollAnimator(prefs.enable_scroll_animator);
settings->SetPrefersReducedMotion(prefs.prefers_reduced_motion);
WebRuntimeFeatures::EnableTouchEventFeatureDetection(
prefs.touch_event_feature_detection_enabled);
......
......@@ -152,6 +152,7 @@ class WebSettings {
virtual void SetDownloadableBinaryFontsEnabled(bool) = 0;
virtual void SetEditingBehavior(EditingBehavior) = 0;
virtual void SetEnableScrollAnimator(bool) = 0;
virtual void SetPrefersReducedMotion(bool) = 0;
virtual void SetEnableTouchAdjustment(bool) = 0;
virtual void SetSmoothScrollForFindEnabled(bool) = 0;
virtual void SetWebGL1Enabled(bool) = 0;
......
......@@ -564,6 +564,10 @@ void WebSettingsImpl::SetEnableScrollAnimator(bool enabled) {
settings_->SetScrollAnimatorEnabled(enabled);
}
void WebSettingsImpl::SetPrefersReducedMotion(bool enabled) {
settings_->SetPrefersReducedMotion(enabled);
}
void WebSettingsImpl::SetEnableTouchAdjustment(bool enabled) {
settings_->SetTouchAdjustmentEnabled(enabled);
}
......
......@@ -82,6 +82,7 @@ class CORE_EXPORT WebSettingsImpl final : public WebSettings {
void SetDownloadableBinaryFontsEnabled(bool) override;
void SetEditingBehavior(EditingBehavior) override;
void SetEnableScrollAnimator(bool) override;
void SetPrefersReducedMotion(bool) override;
void SetEnableTouchAdjustment(bool) override;
void SetWebGL1Enabled(bool) override;
void SetWebGL2Enabled(bool) override;
......
......@@ -113,6 +113,12 @@ bool Animation::ScrollAnimationsEnabledBySystem() {
// Defined in platform specific files for Windows and OSX.
return true;
}
bool Animation::PrefersReducedMotion() {
// By default, we assume that animations are enabled, to avoid impacting the
// experience for users on systems that don't have APIs for reduced motion.
return false;
}
#endif
bool Animation::ShouldSendCanceledFromStop() {
......
......@@ -79,6 +79,10 @@ class ANIMATION_EXPORT Animation : public AnimationContainerElement {
// process.
static bool ScrollAnimationsEnabledBySystem();
// Determines whether the user desires reduced motion based on platform APIs.
// Should only be called from the browser process.
static bool PrefersReducedMotion();
protected:
// Invoked from Start to allow subclasses to prepare for the animation.
virtual void AnimationStarted() {}
......
......@@ -4,11 +4,16 @@
#include "ui/gfx/animation/animation.h"
#import <Foundation/Foundation.h>
#import <Cocoa/Cocoa.h>
#include "base/mac/mac_util.h"
#include "base/message_loop/message_loop.h"
// Only available since 10.12.
@interface NSWorkspace (AvailableSinceSierra)
@property(readonly) BOOL accessibilityDisplayShouldReduceMotion;
@end
namespace gfx {
// static
......@@ -27,4 +32,22 @@ bool Animation::ScrollAnimationsEnabledBySystem() {
return enabled;
}
// static
bool Animation::PrefersReducedMotion() {
// Because of sandboxing, OS settings should only be queried from the browser
// process.
DCHECK(base::MessageLoopCurrentForUI::IsSet() ||
base::MessageLoopCurrentForIO::IsSet());
// We default to assuming that animations are enabled, to avoid impacting the
// experience for users on pre-10.12 systems.
bool prefers_reduced_motion = false;
SEL sel = @selector(accessibilityDisplayShouldReduceMotion);
if ([[NSWorkspace sharedWorkspace] respondsToSelector:sel]) {
prefers_reduced_motion =
[[NSWorkspace sharedWorkspace] accessibilityDisplayShouldReduceMotion];
}
return prefers_reduced_motion;
}
} // namespace gfx
......@@ -23,4 +23,13 @@ bool Animation::ScrollAnimationsEnabledBySystem() {
return ShouldRenderRichAnimation();
}
// static
bool Animation::PrefersReducedMotion() {
// We default to assuming that animations are enabled, to avoid impacting the
// experience for users on systems that don't have SPI_GETCLIENTAREAANIMATION.
BOOL win_anim_enabled = true;
SystemParametersInfo(SPI_GETCLIENTAREAANIMATION, 0, &win_anim_enabled, 0);
return !win_anim_enabled;
}
} // namespace gfx
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment