Skip to content

Commit

Permalink
Cherry-pick 3839864. rdar://117215059
Browse files Browse the repository at this point in the history
    AX: Sometimes unable to see play/pause animation context menu item when setting is toggled
    https://bugs.webkit.org/show_bug.cgi?id=263735
    rdar://117215059

    Reviewed by Tyler Wilcock.

    When deciding whether to add the "Play/Pause all animations" or "Play/Pause animation" context menu item, we had previously
    used a softlink to reference _AXSReduceMotionAutoplayAnimatedImagesEnabled. The issue with using this from the web content
    process, however, is that distributed notifications are not permitted as per the sandbox, so updates to this setting were
    not reaching that process.

    To resolve this, this patch now piggybacks onto our existing cross-process update for the animation setting using the
    AccessibilityPreferencesChanged notification and WebPage::updateImageAnimationEnabled. A new flag, m_systemAllowsAnimationControls,
    now maintains the state of this setting, and allows the Page to have an up-to-date view of the setting without relying on the
    softlink.

    * Source/WebCore/page/ContextMenuController.cpp:
    (WebCore::ContextMenuController::populate):
    * Source/WebCore/page/Page.cpp:
    (WebCore::Page::setSystemAllowsAnimationControls):
    * Source/WebCore/page/Page.h:
    (WebCore::Page::systemAllowsAnimationControls const):
    * Source/WebKit/WebProcess/WebPage/WebPage.cpp:
    (WebKit::WebPage::updateImageAnimationEnabled):

    Canonical link: https://commits.webkit.org/269878@main

Identifier: 267815.551@safari-7617.1.17.12-branch
  • Loading branch information
Dan Robson committed Nov 9, 2023
1 parent 00283a2 commit abae04a
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 11 deletions.
11 changes: 1 addition & 10 deletions Source/WebCore/page/ContextMenuController.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -95,12 +95,6 @@
#include <wtf/cocoa/RuntimeApplicationChecksCocoa.h>
#endif

#if ENABLE(ACCESSIBILITY_ANIMATION_CONTROL)
#include <wtf/SoftLinking.h>
SOFT_LINK_LIBRARY_OPTIONAL(libAccessibility)
SOFT_LINK_OPTIONAL(libAccessibility, _AXSReduceMotionAutoplayAnimatedImagesEnabled, Boolean, (), ());
#endif

namespace WebCore {

using namespace WTF::Unicode;
Expand Down Expand Up @@ -1044,10 +1038,7 @@ void ContextMenuController::populate()
if (!frame->page() || !frame->page()->settings().imageAnimationControlEnabled())
return false;

auto* autoplayAnimatedImagesFunction = _AXSReduceMotionAutoplayAnimatedImagesEnabledPtr();
// Only show these controls if autoplay of animated images has been disabled.
bool systemAllowsAnimationControls = autoplayAnimatedImagesFunction && !autoplayAnimatedImagesFunction();
return systemAllowsAnimationControls || frame->page()->settings().allowAnimationControlsOverride();
return frame->page()->systemAllowsAnimationControls() || frame->page()->settings().allowAnimationControlsOverride();
};

bool shouldAddPlayAllPauseAllAnimationsItem = canAddAnimationControls();
Expand Down
7 changes: 6 additions & 1 deletion Source/WebCore/page/Page.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2179,7 +2179,12 @@ void Page::setImageAnimationEnabled(bool enabled)
updatePlayStateForAllAnimations();
chrome().client().isAnyAnimationAllowedToPlayDidChange(enabled);
}
#endif

void Page::setSystemAllowsAnimationControls(bool isAllowed)
{
m_systemAllowsAnimationControls = isAllowed;
}
#endif // ENABLE(ACCESSIBILITY_ANIMATION_CONTROL)

void Page::suspendScriptedAnimations()
{
Expand Down
3 changes: 3 additions & 0 deletions Source/WebCore/page/Page.h
Original file line number Diff line number Diff line change
Expand Up @@ -697,10 +697,12 @@ class Page : public Supplementable<Page>, public CanMakeWeakPtr<Page> {
#if ENABLE(ACCESSIBILITY_ANIMATION_CONTROL)
void updatePlayStateForAllAnimations();
WEBCORE_EXPORT void setImageAnimationEnabled(bool);
WEBCORE_EXPORT void setSystemAllowsAnimationControls(bool isAllowed);
void addIndividuallyPlayingAnimationElement(HTMLImageElement&);
void removeIndividuallyPlayingAnimationElement(HTMLImageElement&);
#endif
bool imageAnimationEnabled() const { return m_imageAnimationEnabled; }
bool systemAllowsAnimationControls() const { return m_systemAllowsAnimationControls; }

void userStyleSheetLocationChanged();
const String& userStyleSheet() const;
Expand Down Expand Up @@ -1225,6 +1227,7 @@ class Page : public Supplementable<Page>, public CanMakeWeakPtr<Page> {

bool m_canStartMedia { true };
bool m_imageAnimationEnabled { true };
bool m_systemAllowsAnimationControls { false };
// Elements containing animations that are individually playing (potentially overriding the page-wide m_imageAnimationEnabled state).
WeakHashSet<HTMLImageElement, WeakPtrImplWithEventTargetData> m_individuallyPlayingAnimationElements;

Expand Down
1 change: 1 addition & 0 deletions Source/WebKit/WebProcess/WebPage/WebPage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8783,6 +8783,7 @@ void WebPage::generateTestReport(String&& message, String&& group)
void WebPage::updateImageAnimationEnabled()
{
corePage()->setImageAnimationEnabled(WebProcess::singleton().imageAnimationEnabled());
corePage()->setSystemAllowsAnimationControls(!WebProcess::singleton().imageAnimationEnabled());
}

void WebPage::pauseAllAnimations(CompletionHandler<void()>&& completionHandler)
Expand Down

0 comments on commit abae04a

Please sign in to comment.