diff options
author | bokan <bokan@chromium.org> | 2016-02-17 15:22:10 -0800 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2016-02-17 23:22:59 +0000 |
commit | b9c004266f7f0d0380935dfc8a527bb08409627d (patch) | |
tree | a7677af0bd80ed3826c69d47762c05d9b4224ca5 | |
parent | 324897d72015abb00a5f7c682fbdc2e5d82619b0 (diff) | |
download | chromium_src-b9c004266f7f0d0380935dfc8a527bb08409627d.zip chromium_src-b9c004266f7f0d0380935dfc8a527bb08409627d.tar.gz chromium_src-b9c004266f7f0d0380935dfc8a527bb08409627d.tar.bz2 |
Make scrollAnimatorEnabled work on Mac like it does on other platforms
Mac currently has a separate path to enable/disable scroll animations in
Blink. Instead of using the existing Blink setting for scroll animations,
ScrollbarThemeMacCommon sets a flag scrollAnimationEnabledForSystem which
is then checked along side the Blink setting. A side-effect of this is
that --(disable|enable)-scroll-animator doesn't work on Mac and layout
tests default to scroll animations disabled with no way to turn them on.
This patch removes the scrollAnimationEnabledForSystem flag and instead
unifies this setting with how it's handled on other platforms. When Blink
settings are computed, the OSX setting is queried and set into the usual
enable_scroll_animator setting. Changes to the OSX setting cause the
browser process to recalculate and apply new Blink settings.
This allows layout tests to use internals.settings.setScrollAnimatorEnabled
to allow testing of scroll animation semantics on Mac.
BUG=
Review URL: https://codereview.chromium.org/1653003002
Cr-Commit-Position: refs/heads/master@{#376025}
-rw-r--r-- | content/browser/renderer_host/render_process_host_impl.cc | 32 | ||||
-rw-r--r-- | content/browser/renderer_host/render_process_host_impl.h | 2 | ||||
-rw-r--r-- | content/browser/renderer_host/render_view_host_impl.cc | 2 | ||||
-rw-r--r-- | content/browser/theme_helper_mac.mm | 31 | ||||
-rw-r--r-- | content/common/view_messages.h | 1 | ||||
-rw-r--r-- | content/renderer/render_thread_impl.cc | 2 | ||||
-rw-r--r-- | third_party/WebKit/Source/platform/mac/ScrollAnimatorMac.mm | 5 | ||||
-rw-r--r-- | third_party/WebKit/Source/platform/scroll/ScrollbarThemeMacCommon.h | 2 | ||||
-rw-r--r-- | third_party/WebKit/Source/platform/scroll/ScrollbarThemeMacCommon.mm | 9 | ||||
-rw-r--r-- | third_party/WebKit/Source/web/mac/WebScrollbarTheme.mm | 4 | ||||
-rw-r--r-- | third_party/WebKit/public/web/mac/WebScrollbarTheme.h | 3 | ||||
-rw-r--r-- | ui/gfx/BUILD.gn | 2 | ||||
-rw-r--r-- | ui/gfx/animation/animation.cc | 24 | ||||
-rw-r--r-- | ui/gfx/animation/animation.h | 5 | ||||
-rw-r--r-- | ui/gfx/animation/animation_mac.mm | 33 | ||||
-rw-r--r-- | ui/gfx/animation/animation_win.cc | 28 | ||||
-rw-r--r-- | ui/gfx/gfx.gyp | 2 |
17 files changed, 119 insertions, 68 deletions
diff --git a/content/browser/renderer_host/render_process_host_impl.cc b/content/browser/renderer_host/render_process_host_impl.cc index 18d3601..c355fa2 100644 --- a/content/browser/renderer_host/render_process_host_impl.cc +++ b/content/browser/renderer_host/render_process_host_impl.cc @@ -2640,20 +2640,7 @@ void RenderProcessHostImpl::OnCloseACK(int old_route_id) { } void RenderProcessHostImpl::OnGpuSwitched() { - // We are updating all widgets including swapped out ones. - scoped_ptr<RenderWidgetHostIterator> widgets( - RenderWidgetHostImpl::GetAllRenderWidgetHosts()); - while (RenderWidgetHost* widget = widgets->GetNextHost()) { - RenderViewHost* rvh = RenderViewHost::From(widget); - if (!rvh) - continue; - - // Skip widgets in other processes. - if (rvh->GetProcess()->GetID() != GetID()) - continue; - - rvh->OnWebkitPreferencesChanged(); - } + RecomputeAndUpdateWebKitPreferences(); } #if defined(ENABLE_WEBRTC) @@ -2797,4 +2784,21 @@ BluetoothDispatcherHost* RenderProcessHostImpl::GetBluetoothDispatcherHost() { return bluetooth_dispatcher_host_.get(); } +void RenderProcessHostImpl::RecomputeAndUpdateWebKitPreferences() { + // We are updating all widgets including swapped out ones. + scoped_ptr<RenderWidgetHostIterator> widgets( + RenderWidgetHostImpl::GetAllRenderWidgetHosts()); + while (RenderWidgetHost* widget = widgets->GetNextHost()) { + RenderViewHost* rvh = RenderViewHost::From(widget); + if (!rvh) + continue; + + // Skip widgets in other processes. + if (rvh->GetProcess()->GetID() != GetID()) + continue; + + rvh->OnWebkitPreferencesChanged(); + } +} + } // namespace content diff --git a/content/browser/renderer_host/render_process_host_impl.h b/content/browser/renderer_host/render_process_host_impl.h index 78190a5..fbe8f66 100644 --- a/content/browser/renderer_host/render_process_host_impl.h +++ b/content/browser/renderer_host/render_process_host_impl.h @@ -268,6 +268,8 @@ class CONTENT_EXPORT RenderProcessHostImpl static void EarlyZygoteLaunch(); #endif // defined(OS_POSIX) && !defined(OS_ANDROID) && !defined(OS_MACOSX) + void RecomputeAndUpdateWebKitPreferences(); + protected: // A proxy for our IPC::Channel that lives on the IO thread. scoped_ptr<IPC::ChannelProxy> channel_; diff --git a/content/browser/renderer_host/render_view_host_impl.cc b/content/browser/renderer_host/render_view_host_impl.cc index 5aa3313..2dc2f74 100644 --- a/content/browser/renderer_host/render_view_host_impl.cc +++ b/content/browser/renderer_host/render_view_host_impl.cc @@ -480,7 +480,7 @@ WebPreferences RenderViewHostImpl::ComputeWebkitPrefs() { prefs.enable_scroll_animator = !command_line.HasSwitch(switches::kDisableSmoothScrolling) && - gfx::Animation::ShouldRenderRichAnimation(); + gfx::Animation::ScrollAnimationsEnabledBySystem(); // Certain GPU features might have been blacklisted. GpuDataManagerImpl::GetInstance()->UpdateRendererWebPrefs(&prefs); diff --git a/content/browser/theme_helper_mac.mm b/content/browser/theme_helper_mac.mm index aa5ebd0..8ae332e 100644 --- a/content/browser/theme_helper_mac.mm +++ b/content/browser/theme_helper_mac.mm @@ -10,6 +10,7 @@ #include "base/mac/mac_util.h" #include "base/mac/sdk_forward_declarations.h" #include "base/strings/sys_string_conversions.h" +#include "content/browser/renderer_host/render_process_host_impl.h" #include "content/common/view_messages.h" #include "content/public/browser/browser_thread.h" #include "content/public/browser/notification_service.h" @@ -18,25 +19,11 @@ #include "content/public/common/content_switches.h" using content::RenderProcessHost; +using content::RenderProcessHostImpl; using content::ThemeHelperMac; namespace { -bool GetScrollAnimationEnabled() { - bool enabled = false; - id value = nil; - if (base::mac::IsOSMountainLionOrLater()) { - value = [[NSUserDefaults standardUserDefaults] - objectForKey:@"NSScrollAnimationEnabled"]; - } else { - value = [[NSUserDefaults standardUserDefaults] - objectForKey:@"AppleScrollAnimationEnabled"]; - } - if (value) - enabled = [value boolValue]; - return enabled; -} - blink::WebScrollbarButtonsPlacement GetButtonPlacement() { NSString* scrollbar_variant = [[NSUserDefaults standardUserDefaults] objectForKey:@"AppleScrollBarVariant"]; @@ -64,7 +51,6 @@ void FillScrollbarThemeParams(ViewMsg_UpdateScrollbarTheme_Params* params) { [defaults boolForKey:@"AppleScrollerPagingBehavior"]; params->preferred_scroller_style = ThemeHelperMac::GetPreferredScrollerStyle(); - params->scroll_animation_enabled = GetScrollAnimationEnabled(); params->button_placement = GetButtonPlacement(); } @@ -177,7 +163,10 @@ ViewMsg_SystemColorsChanged* CreateSystemColorsChangedMessage() { for (RenderProcessHost::iterator it(RenderProcessHost::AllHostsIterator()); !it.IsAtEnd(); it.Advance()) { - it.GetCurrentValue()->Send(new ViewMsg_UpdateScrollbarTheme(params)); + RenderProcessHostImpl* rphi = + static_cast<RenderProcessHostImpl*>(it.GetCurrentValue()); + rphi->RecomputeAndUpdateWebKitPreferences(); + rphi->Send(new ViewMsg_UpdateScrollbarTheme(params)); } } @@ -219,9 +208,11 @@ void ThemeHelperMac::Observe(int type, FillScrollbarThemeParams(¶ms); params.redraw = false; - RenderProcessHost* rph = Source<RenderProcessHost>(source).ptr(); - rph->Send(new ViewMsg_UpdateScrollbarTheme(params)); - rph->Send(CreateSystemColorsChangedMessage()); + RenderProcessHostImpl* rphi = + Source<content::RenderProcessHostImpl>(source).ptr(); + rphi->RecomputeAndUpdateWebKitPreferences(); + rphi->Send(new ViewMsg_UpdateScrollbarTheme(params)); + rphi->Send(CreateSystemColorsChangedMessage()); } } // namespace content diff --git a/content/common/view_messages.h b/content/common/view_messages.h index 42a6e04..db9b38d 100644 --- a/content/common/view_messages.h +++ b/content/common/view_messages.h @@ -553,7 +553,6 @@ IPC_STRUCT_BEGIN(ViewMsg_UpdateScrollbarTheme_Params) IPC_STRUCT_MEMBER(bool, jump_on_track_click) IPC_STRUCT_MEMBER(blink::ScrollerStyle, preferred_scroller_style) IPC_STRUCT_MEMBER(bool, redraw) - IPC_STRUCT_MEMBER(bool, scroll_animation_enabled) IPC_STRUCT_MEMBER(blink::WebScrollbarButtonsPlacement, button_placement) IPC_STRUCT_END() #endif diff --git a/content/renderer/render_thread_impl.cc b/content/renderer/render_thread_impl.cc index 0746e71..0fec9ed 100644 --- a/content/renderer/render_thread_impl.cc +++ b/content/renderer/render_thread_impl.cc @@ -1981,7 +1981,7 @@ void RenderThreadImpl::OnUpdateScrollbarTheme( blink::WebScrollbarTheme::updateScrollbarsWithNSDefaults( params.initial_button_delay, params.autoscroll_button_delay, params.preferred_scroller_style, params.redraw, - params.scroll_animation_enabled, params.button_placement); + params.button_placement); } void RenderThreadImpl::OnSystemColorsChanged( diff --git a/third_party/WebKit/Source/platform/mac/ScrollAnimatorMac.mm b/third_party/WebKit/Source/platform/mac/ScrollAnimatorMac.mm index 981d57c..6f940cb 100644 --- a/third_party/WebKit/Source/platform/mac/ScrollAnimatorMac.mm +++ b/third_party/WebKit/Source/platform/mac/ScrollAnimatorMac.mm @@ -728,12 +728,9 @@ void ScrollAnimatorMac::dispose() ScrollResultOneDimensional ScrollAnimatorMac::userScroll(ScrollbarOrientation orientation, ScrollGranularity granularity, float step, float delta) { - bool scrollAnimationEnabledForSystem = static_cast<ScrollbarThemeMacCommon&>( - ScrollbarTheme::theme()) - .scrollAnimationEnabledForSystem(); m_haveScrolledSincePageLoad = true; - if (!scrollAnimationEnabledForSystem || !m_scrollableArea->scrollAnimatorEnabled()) + if (!m_scrollableArea->scrollAnimatorEnabled()) return ScrollAnimatorBase::userScroll(orientation, granularity, step, delta); if (granularity == ScrollByPixel || granularity == ScrollByPrecisePixel) diff --git a/third_party/WebKit/Source/platform/scroll/ScrollbarThemeMacCommon.h b/third_party/WebKit/Source/platform/scroll/ScrollbarThemeMacCommon.h index 185ba2a..84ce2cb 100644 --- a/third_party/WebKit/Source/platform/scroll/ScrollbarThemeMacCommon.h +++ b/third_party/WebKit/Source/platform/scroll/ScrollbarThemeMacCommon.h @@ -41,7 +41,7 @@ public: void registerScrollbar(ScrollbarThemeClient&) override; void unregisterScrollbar(ScrollbarThemeClient&) override; - void preferencesChanged(float initialButtonDelay, float autoscrollButtonDelay, NSScrollerStyle preferredScrollerStyle, bool redraw, bool scrollAnimationEnabled, WebScrollbarButtonsPlacement); + void preferencesChanged(float initialButtonDelay, float autoscrollButtonDelay, NSScrollerStyle preferredScrollerStyle, bool redraw, WebScrollbarButtonsPlacement); bool supportsControlTints() const override { return true; } diff --git a/third_party/WebKit/Source/platform/scroll/ScrollbarThemeMacCommon.mm b/third_party/WebKit/Source/platform/scroll/ScrollbarThemeMacCommon.mm index b85fcfd..a190907 100644 --- a/third_party/WebKit/Source/platform/scroll/ScrollbarThemeMacCommon.mm +++ b/third_party/WebKit/Source/platform/scroll/ScrollbarThemeMacCommon.mm @@ -66,7 +66,6 @@ static ScrollbarSet& scrollbarSet() static float gInitialButtonDelay = 0.5f; static float gAutoscrollButtonDelay = 0.05f; static NSScrollerStyle gPreferredScrollerStyle = NSScrollerStyleLegacy; -static bool gScrollAnimationEnabledForSystem = false; ScrollbarTheme& ScrollbarTheme::nativeTheme() { @@ -159,12 +158,11 @@ ScrollbarThemeMacCommon::~ScrollbarThemeMacCommon() { } -void ScrollbarThemeMacCommon::preferencesChanged(float initialButtonDelay, float autoscrollButtonDelay, NSScrollerStyle preferredScrollerStyle, bool redraw, bool scrollAnimationEnabled, WebScrollbarButtonsPlacement buttonPlacement) +void ScrollbarThemeMacCommon::preferencesChanged(float initialButtonDelay, float autoscrollButtonDelay, NSScrollerStyle preferredScrollerStyle, bool redraw, WebScrollbarButtonsPlacement buttonPlacement) { updateButtonPlacement(buttonPlacement); gInitialButtonDelay = initialButtonDelay; gAutoscrollButtonDelay = autoscrollButtonDelay; - gScrollAnimationEnabledForSystem = scrollAnimationEnabled; bool sendScrollerStyleNotification = gPreferredScrollerStyle != preferredScrollerStyle; gPreferredScrollerStyle = preferredScrollerStyle; if (redraw && !scrollbarSet().isEmpty()) { @@ -182,11 +180,6 @@ void ScrollbarThemeMacCommon::preferencesChanged(float initialButtonDelay, float } } -bool ScrollbarThemeMacCommon::scrollAnimationEnabledForSystem() -{ - return gScrollAnimationEnabledForSystem; -} - double ScrollbarThemeMacCommon::initialAutoscrollTimerDelay() { return gInitialButtonDelay; diff --git a/third_party/WebKit/Source/web/mac/WebScrollbarTheme.mm b/third_party/WebKit/Source/web/mac/WebScrollbarTheme.mm index f40ecbb..6751c46 100644 --- a/third_party/WebKit/Source/web/mac/WebScrollbarTheme.mm +++ b/third_party/WebKit/Source/web/mac/WebScrollbarTheme.mm @@ -44,7 +44,7 @@ static_assert(static_cast<NSScrollerStyle>(ScrollerStyleOverlay) == NSScrollerSt void WebScrollbarTheme::updateScrollbarsWithNSDefaults( float initialButtonDelay, float autoscrollButtonDelay, - ScrollerStyle preferredScrollerStyle, bool redraw, bool scrollAnimationEnabled, WebScrollbarButtonsPlacement buttonPlacement) + ScrollerStyle preferredScrollerStyle, bool redraw, WebScrollbarButtonsPlacement buttonPlacement) { ScrollbarTheme& theme = ScrollbarTheme::theme(); if (theme.isMockTheme()) @@ -53,7 +53,7 @@ void WebScrollbarTheme::updateScrollbarsWithNSDefaults( static_cast<ScrollbarThemeMacCommon&>(theme).preferencesChanged( initialButtonDelay, autoscrollButtonDelay, static_cast<NSScrollerStyle>(preferredScrollerStyle), - redraw, scrollAnimationEnabled, buttonPlacement); + redraw, buttonPlacement); } } // namespace blink diff --git a/third_party/WebKit/public/web/mac/WebScrollbarTheme.h b/third_party/WebKit/public/web/mac/WebScrollbarTheme.h index a610ac9..61385e8 100644 --- a/third_party/WebKit/public/web/mac/WebScrollbarTheme.h +++ b/third_party/WebKit/public/web/mac/WebScrollbarTheme.h @@ -49,12 +49,11 @@ public: // |autoscrollButtonDelay| is the current value of NSScrollerButtonPeriod from NSUserDefaults. // |preferredScrollerStyle| is the current value of +[NSScroller preferredScrollerStyle]. // |redraw| is true if the update requires a redraw to include the change. - // |scrollAnimationEnabled| is the current value of NSScrollAnimationEnabled or AppleScrollAnimationEnabled from NSUserDefaults. // |buttonPlacement| is the current value of AppleScrollBarVariant BLINK_EXPORT static void updateScrollbarsWithNSDefaults( float initialButtonDelay, float autoscrollButtonDelay, ScrollerStyle preferredScrollerStyle, bool redraw, - bool scrollAnimationEnabled, WebScrollbarButtonsPlacement); + WebScrollbarButtonsPlacement); }; } // namespace blink diff --git a/ui/gfx/BUILD.gn b/ui/gfx/BUILD.gn index 114d3b0..d014bd7 100644 --- a/ui/gfx/BUILD.gn +++ b/ui/gfx/BUILD.gn @@ -42,6 +42,8 @@ component("gfx") { "animation/animation_container_element.h", "animation/animation_container_observer.h", "animation/animation_delegate.h", + "animation/animation_mac.mm", + "animation/animation_win.cc", "animation/linear_animation.cc", "animation/linear_animation.h", "animation/multi_animation.cc", diff --git a/ui/gfx/animation/animation.cc b/ui/gfx/animation/animation.cc index 3c29828..4bc1b24 100644 --- a/ui/gfx/animation/animation.cc +++ b/ui/gfx/animation/animation.cc @@ -10,10 +10,6 @@ #include "ui/gfx/animation/tween.h" #include "ui/gfx/geometry/rect.h" -#if defined(OS_WIN) -#include "base/win/windows_version.h" -#endif - namespace gfx { Animation::Animation(base::TimeDelta timer_interval) @@ -92,21 +88,21 @@ void Animation::SetContainer(AnimationContainer* container) { container_->Start(this); } +#if !defined(OS_WIN) // static bool Animation::ShouldRenderRichAnimation() { -#if defined(OS_WIN) - if (base::win::GetVersion() >= base::win::VERSION_VISTA) { - BOOL result; - // Get "Turn off all unnecessary animations" value. - if (::SystemParametersInfo(SPI_GETCLIENTAREAANIMATION, 0, &result, 0)) { - return !!result; - } - } - return !::GetSystemMetrics(SM_REMOTESESSION); -#else + // Defined in platform specific file for Windows. return true; +} #endif + +#if !defined(OS_WIN) && !defined(OS_MACOSX) +// static +bool Animation::ScrollAnimationsEnabledBySystem() { + // Defined in platform specific files for Windows and OSX. + return true; } +#endif bool Animation::ShouldSendCanceledFromStop() { return false; diff --git a/ui/gfx/animation/animation.h b/ui/gfx/animation/animation.h index 44823b0..8d8b4d0 100644 --- a/ui/gfx/animation/animation.h +++ b/ui/gfx/animation/animation.h @@ -64,6 +64,11 @@ class GFX_EXPORT Animation : public AnimationContainerElement { // to give guidance for heavy animations such as "start download" arrow. static bool ShouldRenderRichAnimation(); + // Determines on a per-platform basis whether scroll animations (e.g. produced + // by home/end key) should be enabled. Should only be called from the browser + // process. + static bool ScrollAnimationsEnabledBySystem(); + protected: // Invoked from Start to allow subclasses to prepare for the animation. virtual void AnimationStarted() {} diff --git a/ui/gfx/animation/animation_mac.mm b/ui/gfx/animation/animation_mac.mm new file mode 100644 index 0000000..e3a4ff2 --- /dev/null +++ b/ui/gfx/animation/animation_mac.mm @@ -0,0 +1,33 @@ +// 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" + +#include "base/mac/mac_util.h" +#include "base/message_loop/message_loop.h" + +namespace gfx { + +// static +bool Animation::ScrollAnimationsEnabledBySystem() { + // Because of sandboxing, OS settings should only be queried from the browser + // process. + DCHECK(base::MessageLoopForUI::IsCurrent() || + base::MessageLoopForIO::IsCurrent()); + + bool enabled = false; + id value = nil; + if (base::mac::IsOSMountainLionOrLater()) { + value = [[NSUserDefaults standardUserDefaults] + objectForKey:@"NSScrollAnimationEnabled"]; + } else { + value = [[NSUserDefaults standardUserDefaults] + objectForKey:@"AppleScrollAnimationEnabled"]; + } + if (value) + enabled = [value boolValue]; + return enabled; +} + +} // namespace gfx diff --git a/ui/gfx/animation/animation_win.cc b/ui/gfx/animation/animation_win.cc new file mode 100644 index 0000000..b8a7d28 --- /dev/null +++ b/ui/gfx/animation/animation_win.cc @@ -0,0 +1,28 @@ +// 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" + +#include "base/win/windows_version.h" + +namespace gfx { + +// static +bool Animation::ShouldRenderRichAnimation() { + if (base::win::GetVersion() >= base::win::VERSION_VISTA) { + BOOL result; + // Get "Turn off all unnecessary animations" value. + if (::SystemParametersInfo(SPI_GETCLIENTAREAANIMATION, 0, &result, 0)) { + return !!result; + } + } + return !::GetSystemMetrics(SM_REMOTESESSION); +} + +// static +bool Animation::ScrollAnimationsEnabledBySystem() { + return ShouldRenderRichAnimation(); +} + +} // namespace gfx diff --git a/ui/gfx/gfx.gyp b/ui/gfx/gfx.gyp index e211997..4519db9 100644 --- a/ui/gfx/gfx.gyp +++ b/ui/gfx/gfx.gyp @@ -113,6 +113,8 @@ 'animation/animation_container_element.h', 'animation/animation_container_observer.h', 'animation/animation_delegate.h', + 'animation/animation_mac.mm', + 'animation/animation_win.cc', 'animation/linear_animation.cc', 'animation/linear_animation.h', 'animation/multi_animation.cc', |