Skip to content

Commit

Permalink
Avoid full style rebuild for :-webkit-animating-full-screen-transitio…
Browse files Browse the repository at this point in the history
…n and :-webkit-full-screen-controls-hidden

https://bugs.webkit.org/show_bug.cgi?id=246736
rdar://101325585

Reviewed by Antti Koivisto.

Calling scheduleFullStyleRebuild() is unnecessarily costly here. It is likely copy-paste from
methods that enter/exit fullscreen, which actually do need a rebuild because they need to
re-resolve style for all elements (un)matching :-webkit-full-screen-ancestor.

We can use PseudoClassChangeInvalidation which is more optimized for this purpose.

* Source/WebCore/dom/FullscreenManager.cpp:
(WebCore::FullscreenManager::setAnimatingFullscreen):
(WebCore::FullscreenManager::setFullscreenControlsHidden):
(WebCore::FullscreenManager::didExitFullscreen):
* Source/WebCore/dom/FullscreenManager.h:

Canonical link: https://commits.webkit.org/255748@main
  • Loading branch information
nt1m committed Oct 19, 2022
1 parent 7c3cb91 commit dc6a098
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 12 deletions.
20 changes: 9 additions & 11 deletions Source/WebCore/dom/FullscreenManager.cpp
Expand Up @@ -41,6 +41,7 @@
#include "JSDOMPromiseDeferred.h"
#include "Logging.h"
#include "Page.h"
#include "PseudoClassChangeInvalidation.h"
#include "QualifiedName.h"
#include "Settings.h"
#include <wtf/LoggerHelper.h>
Expand Down Expand Up @@ -520,7 +521,7 @@ bool FullscreenManager::didExitFullscreen()

m_fullscreenElement = nullptr;
m_pendingFullscreenElement = nullptr;
scheduleFullStyleRebuild();
document().scheduleFullStyleRebuild();

// When webkitCancelFullscreen is called, we call webkitExitFullscreen on the topDocument(). That
// means that the events will be queued there. So if we have no events here, start the timer on
Expand Down Expand Up @@ -614,14 +615,13 @@ void FullscreenManager::setAnimatingFullscreen(bool flag)
{
if (m_isAnimatingFullscreen == flag)
return;
m_isAnimatingFullscreen = flag;

INFO_LOG(LOGIDENTIFIER, flag);

if (m_fullscreenElement && m_fullscreenElement->isDescendantOf(document())) {
m_fullscreenElement->invalidateStyleForSubtree();
scheduleFullStyleRebuild();
}
std::optional<Style::PseudoClassChangeInvalidation> styleInvalidation;
if (m_fullscreenElement)
emplace(styleInvalidation, *m_fullscreenElement, { { CSSSelector::PseudoClassAnimatingFullScreenTransition, flag } });
m_isAnimatingFullscreen = flag;
}

bool FullscreenManager::areFullscreenControlsHidden() const
Expand All @@ -636,12 +636,10 @@ void FullscreenManager::setFullscreenControlsHidden(bool flag)

INFO_LOG(LOGIDENTIFIER, flag);

std::optional<Style::PseudoClassChangeInvalidation> styleInvalidation;
if (m_fullscreenElement)
emplace(styleInvalidation, *m_fullscreenElement, { { CSSSelector::PseudoClassFullScreenControlsHidden, flag } });
m_areFullscreenControlsHidden = flag;

if (m_fullscreenElement && m_fullscreenElement->isDescendantOf(document())) {
m_fullscreenElement->invalidateStyleForSubtree();
scheduleFullStyleRebuild();
}
}

void FullscreenManager::clear()
Expand Down
1 change: 0 additions & 1 deletion Source/WebCore/dom/FullscreenManager.h
Expand Up @@ -52,7 +52,6 @@ class FullscreenManager final : public CanMakeWeakPtr<FullscreenManager> {
Frame* frame() const { return m_document.frame(); }
Element* documentElement() const { return m_document.documentElement(); }
Document::BackForwardCacheState backForwardCacheState() const { return m_document.backForwardCacheState(); }
void scheduleFullStyleRebuild() { m_document.scheduleFullStyleRebuild(); }

// W3C Fullscreen API
Element* fullscreenElement() const { return !m_fullscreenElementStack.isEmpty() ? m_fullscreenElementStack.last().get() : nullptr; }
Expand Down

0 comments on commit dc6a098

Please sign in to comment.