Commit 90f98272 authored by Tom Anderson's avatar Tom Anderson Committed by Commit Bot

Respect animation settings on Linux

GTK has a setting to globally disable animations.  This CL uses it to
disable animations in Chrome when the setting is set to disabled.

R=sky

Bug: 1043808
Change-Id: Idcaee97fdad3a26bb795d496599c745c83da6d9c
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2011442Reviewed-by: default avatarScott Violet <sky@chromium.org>
Commit-Queue: Thomas Anderson <thomasanderson@chromium.org>
Cr-Commit-Position: refs/heads/master@{#734314}
parent c0600e19
......@@ -740,6 +740,13 @@ bool GtkUi::PreferDarkTheme() const {
return dark;
}
bool GtkUi::AnimationsEnabled() const {
gboolean animations_enabled = false;
g_object_get(gtk_settings_get_default(), "gtk-enable-animations",
&animations_enabled, nullptr);
return animations_enabled;
}
#if BUILDFLAG(ENABLE_NATIVE_WINDOW_NAV_BUTTONS)
std::unique_ptr<views::NavButtonProvider> GtkUi::CreateNavButtonProvider() {
if (GtkVersionCheck(3, 14))
......
......@@ -100,6 +100,7 @@ class GtkUi : public views::LinuxUI {
void RemoveDeviceScaleFactorObserver(
views::DeviceScaleFactorObserver* observer) override;
bool PreferDarkTheme() const override;
bool AnimationsEnabled() const override;
#if BUILDFLAG(ENABLE_NATIVE_WINDOW_NAV_BUTTONS)
std::unique_ptr<views::NavButtonProvider> CreateNavButtonProvider() override;
#endif
......
......@@ -51,6 +51,14 @@ jumbo_component("animation") {
sources += [ "animation_win.cc" ]
}
if (is_desktop_linux) {
sources += [
"animation_linux.cc",
"animation_settings_provider_linux.cc",
"animation_settings_provider_linux.h",
]
}
if (!is_android) {
sources += [
"throb_animation.cc",
......
......@@ -112,17 +112,18 @@ bool Animation::ShouldRenderRichAnimation() {
RichAnimationRenderMode::FORCE_ENABLED;
}
#if !defined(OS_WIN) && (!defined(OS_MACOSX) || defined(OS_IOS))
#if defined(OS_ANDROID) || defined(OS_CHROMEOS) || defined(OS_IOS) || \
defined(OS_FUCHSIA)
// static
bool Animation::ShouldRenderRichAnimationImpl() {
// Defined in platform specific file for Windows and OSX.
return true;
// Defined in platform specific file for Windows and OSX and Linux.
}
// static
bool Animation::ScrollAnimationsEnabledBySystem() {
// Defined in platform specific files for Windows and OSX.
return true;
// Defined in platform specific files for Windows and OSX and Linux.
}
#if !defined(OS_ANDROID)
......@@ -136,7 +137,8 @@ void Animation::UpdatePrefersReducedMotion() {
prefers_reduced_motion_ = false;
}
#endif // !defined(OS_ANDROID)
#endif // !defined(OS_WIN) && (!defined(OS_MACOSX) || defined(OS_IOS))
#endif // defined(OS_ANDROID) || defined(OS_CHROMEOS) || defined(OS_IOS) ||
// defined(OS_FUCHSIA)
// static
bool Animation::PrefersReducedMotion() {
......
// Copyright 2020 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"
#include "ui/gfx/animation/animation_settings_provider_linux.h"
namespace gfx {
namespace {
// GTK only has a global setting for whether animations should be enabled. So
// use it for all of the specific settings that Chrome needs.
bool AnimationsEnabled() {
auto* provider = AnimationSettingsProviderLinux::GetInstance();
return !provider || provider->AnimationsEnabled();
}
} // namespace
// static
bool Animation::ShouldRenderRichAnimationImpl() {
return AnimationsEnabled();
}
// static
bool Animation::ScrollAnimationsEnabledBySystem() {
return AnimationsEnabled();
}
// static
void Animation::UpdatePrefersReducedMotion() {
prefers_reduced_motion_ = !AnimationsEnabled();
}
} // namespace gfx
// Copyright 2020 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_settings_provider_linux.h"
#include "base/logging.h"
namespace gfx {
// static
AnimationSettingsProviderLinux* AnimationSettingsProviderLinux::instance_ =
nullptr;
// static
AnimationSettingsProviderLinux* AnimationSettingsProviderLinux::GetInstance() {
return instance_;
}
AnimationSettingsProviderLinux::AnimationSettingsProviderLinux() {
DCHECK(!instance_);
instance_ = this;
}
AnimationSettingsProviderLinux::~AnimationSettingsProviderLinux() {
DCHECK_EQ(instance_, this);
instance_ = nullptr;
}
} // namespace gfx
// Copyright 2020 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 UI_GFX_ANIMATION_ANIMATION_SETTINGS_PROVIDER_LINUX_H_
#define UI_GFX_ANIMATION_ANIMATION_SETTINGS_PROVIDER_LINUX_H_
#include "base/macros.h"
#include "ui/gfx/animation/animation_export.h"
namespace gfx {
class ANIMATION_EXPORT AnimationSettingsProviderLinux {
public:
virtual ~AnimationSettingsProviderLinux();
// Indicates if animations are enabled by the toolkit.
virtual bool AnimationsEnabled() const = 0;
static AnimationSettingsProviderLinux* GetInstance();
protected:
AnimationSettingsProviderLinux();
private:
static AnimationSettingsProviderLinux* instance_;
DISALLOW_COPY_AND_ASSIGN(AnimationSettingsProviderLinux);
};
} // namespace gfx
#endif // UI_GFX_ANIMATION_ANIMATION_SETTINGS_PROVIDER_LINUX_H_
......@@ -14,6 +14,7 @@
#include "ui/base/cursor/cursor_theme_manager_linux.h"
#include "ui/base/ime/linux/linux_input_method_context_factory.h"
#include "ui/base/ime/linux/text_edit_key_bindings_delegate_auralinux.h"
#include "ui/gfx/animation/animation_settings_provider_linux.h"
#include "ui/gfx/skia_font_delegate.h"
#include "ui/shell_dialogs/shell_dialog_linux.h"
#include "ui/views/buildflags.h"
......@@ -58,7 +59,8 @@ class VIEWS_EXPORT LinuxUI : public ui::LinuxInputMethodContextFactory,
public gfx::SkiaFontDelegate,
public ui::ShellDialogLinux,
public ui::TextEditKeyBindingsDelegateAuraLinux,
public ui::CursorThemeManagerLinux {
public ui::CursorThemeManagerLinux,
public gfx::AnimationSettingsProviderLinux {
public:
using UseSystemThemeCallback =
base::RepeatingCallback<bool(aura::Window* window)>;
......
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