Skip to content

Commit 47a2916

Browse files
committed
Implement unprefixed :fullscreen pseudo-class
https://bugs.webkit.org/show_bug.cgi?id=246041 rdar://100783064 Reviewed by Antti Koivisto. Defined in https://fullscreen.spec.whatwg.org/#:fullscreen-pseudo-class This differs from :-webkit-full-screen, since :fullscreen applies to all fullscreen element in the top layer, as opposed to :-webkit-full-screen, which applies on the top-most one. Unfortunately, this still does not allow us to remove full style rebuilds for 2 reasons: - We still need to support :-webkit-full-screen-ancestor/document - There seems to be a bug where adding position: fixed; & adding to top layer in the same layout causes dirty renderers. Tests are not necessary, as this is exercised by the user agent stylesheet (which is already well tested by the fullscreen/ directory). * LayoutTests/imported/w3c/web-platform-tests/fullscreen/rendering/fullscreen-css-invalidation-expected.txt: * LayoutTests/imported/w3c/web-platform-tests/fullscreen/rendering/fullscreen-pseudo-class-support-expected.txt: * Source/WebCore/css/CSSSelector.cpp: (WebCore::CSSSelector::selectorText const): * Source/WebCore/css/CSSSelector.h: * Source/WebCore/css/SelectorChecker.cpp: (WebCore::SelectorChecker::checkOne const): * Source/WebCore/css/SelectorCheckerTestFunctions.h: (WebCore::matchesFullscreenPseudoClass): (WebCore::matchesWebkitFullScreenPseudoClass): (WebCore::matchesFullScreenPseudoClass): Deleted. * Source/WebCore/css/SelectorPseudoClassAndCompatibilityElementMap.in: * Source/WebCore/css/fullscreen.css: (#if defined(ENABLE_FULLSCREEN_API) && ENABLE_FULLSCREEN_API): (:root:-webkit-full-screen-document:not(:fullscreen)): (:fullscreen video,): (img:fullscreen): (iframe:fullscreen): (:not(:root):fullscreen::backdrop): (:root:-webkit-full-screen-document:not(:-webkit-full-screen)): Deleted. (:-webkit-full-screen video,): Deleted. (img:-webkit-full-screen): Deleted. (iframe:-webkit-full-screen): Deleted. (:not(:root):-webkit-full-screen::backdrop): Deleted. * Source/WebCore/cssjit/SelectorCompiler.cpp: (WebCore::SelectorCompiler::JSC_DEFINE_JIT_OPERATION): (WebCore::SelectorCompiler::addPseudoClassType): * Source/WebCore/dom/Element.cpp: (WebCore::Element::setFullscreenFlag): * Source/WebCore/dom/FullscreenManager.cpp: (WebCore::FullscreenManager::willEnterFullscreen): Canonical link: https://commits.webkit.org/257542@main
1 parent cfc4f80 commit 47a2916

11 files changed

+55
-24
lines changed
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
Should be green
22

3-
FAIL Invalidate :fullscreen based style assert_equals: Green when :root is fullscreened. expected "rgb(0, 128, 0)" but got "rgb(255, 0, 0)"
3+
PASS Invalidate :fullscreen based style
44

Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11

2-
FAIL :fullscreen pseudo-class support The string did not match the expected pattern.
2+
PASS :fullscreen pseudo-class support
33

Source/WebCore/css/CSSSelector.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -463,7 +463,10 @@ String CSSSelector::selectorText(StringView separator, StringView rightSide) con
463463
builder.append(":-webkit-full-page-media");
464464
break;
465465
#if ENABLE(FULLSCREEN_API)
466-
case CSSSelector::PseudoClassFullScreen:
466+
case CSSSelector::PseudoClassFullscreen:
467+
builder.append(":fullscreen");
468+
break;
469+
case CSSSelector::PseudoClassWebkitFullScreen:
467470
builder.append(":-webkit-full-screen");
468471
break;
469472
case CSSSelector::PseudoClassFullScreenAncestor:

Source/WebCore/css/CSSSelector.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,8 @@ struct PossiblyQuotedIdentifier {
155155
PseudoClassSingleButton,
156156
PseudoClassNoButton,
157157
#if ENABLE(FULLSCREEN_API)
158-
PseudoClassFullScreen,
158+
PseudoClassFullscreen,
159+
PseudoClassWebkitFullScreen,
159160
PseudoClassFullScreenDocument,
160161
PseudoClassFullScreenAncestor,
161162
PseudoClassAnimatingFullScreenTransition,

Source/WebCore/css/SelectorChecker.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1040,8 +1040,10 @@ bool SelectorChecker::checkOne(CheckingContext& checkingContext, const LocalCont
10401040
ASSERT(selector.argumentList() && !selector.argumentList()->isEmpty());
10411041
return matchesLangPseudoClass(element, *selector.argumentList());
10421042
#if ENABLE(FULLSCREEN_API)
1043-
case CSSSelector::PseudoClassFullScreen:
1044-
return matchesFullScreenPseudoClass(element);
1043+
case CSSSelector::PseudoClassFullscreen:
1044+
return matchesFullscreenPseudoClass(element);
1045+
case CSSSelector::PseudoClassWebkitFullScreen:
1046+
return matchesWebkitFullScreenPseudoClass(element);
10451047
case CSSSelector::PseudoClassAnimatingFullScreenTransition:
10461048
return matchesFullScreenAnimatingFullScreenTransitionPseudoClass(element);
10471049
case CSSSelector::PseudoClassFullScreenAncestor:

Source/WebCore/css/SelectorCheckerTestFunctions.h

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@
2929
#include "FocusController.h"
3030
#include "Frame.h"
3131
#include "FrameSelection.h"
32-
#include "FullscreenManager.h"
3332
#include "HTMLDialogElement.h"
3433
#include "HTMLFrameElement.h"
3534
#include "HTMLIFrameElement.h"
@@ -47,6 +46,11 @@
4746
#include "HTMLAttachmentElement.h"
4847
#endif
4948

49+
#if ENABLE(FULLSCREEN_API)
50+
#include "DocumentOrShadowRootFullscreen.h"
51+
#include "FullscreenManager.h"
52+
#endif
53+
5054
#if ENABLE(VIDEO)
5155
#include "HTMLMediaElement.h"
5256
#include "WebVTTElement.h"
@@ -402,7 +406,16 @@ ALWAYS_INLINE bool scrollbarMatchesCornerPresentPseudoClass(const SelectorChecke
402406

403407
#if ENABLE(FULLSCREEN_API)
404408

405-
ALWAYS_INLINE bool matchesFullScreenPseudoClass(const Element& element)
409+
ALWAYS_INLINE bool matchesFullscreenPseudoClass(const Element& element)
410+
{
411+
if (element.hasFullscreenFlag())
412+
return true;
413+
if (element.shadowRoot())
414+
return DocumentOrShadowRootFullscreen::fullscreenElement(element.document()) == &element;
415+
return false;
416+
}
417+
418+
ALWAYS_INLINE bool matchesWebkitFullScreenPseudoClass(const Element& element)
406419
{
407420
// While a Document is in the fullscreen state, and the document's current fullscreen
408421
// element is an element in the document, the 'full-screen' pseudoclass applies to

Source/WebCore/css/SelectorPseudoClassAndCompatibilityElementMap.in

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,8 +74,9 @@ where
7474
window-inactive
7575

7676
#if ENABLE(FULLSCREEN_API)
77+
fullscreen
7778
-webkit-animating-full-screen-transition
78-
-webkit-full-screen
79+
-webkit-full-screen, PseudoClassWebkitFullScreen, PseudoElementUnknown
7980
-webkit-full-screen-ancestor
8081
-webkit-full-screen-document
8182
-webkit-full-screen-controls-hidden

Source/WebCore/css/fullscreen.css

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626

2727
/* https://fullscreen.spec.whatwg.org/#user-agent-level-style-sheet-defaults */
2828

29-
:not(:root):-webkit-full-screen {
29+
:not(:root):fullscreen {
3030
position: fixed !important;
3131
inset: 0 !important;
3232
margin: 0 !important;
@@ -43,27 +43,27 @@
4343
object-fit:contain;
4444
}
4545

46-
:root:-webkit-full-screen-document:not(:-webkit-full-screen) {
46+
:root:-webkit-full-screen-document:not(:fullscreen) {
4747
overflow: hidden !important;
4848
}
4949

50-
:-webkit-full-screen video,
51-
video:-webkit-full-screen {
50+
:fullscreen video,
51+
video:fullscreen {
5252
-webkit-cursor-visibility: auto-hide;
5353
}
5454

55-
img:-webkit-full-screen {
55+
img:fullscreen {
5656
width: auto;
5757
height: 100%;
5858
max-width: 100%;
5959
}
6060

61-
iframe:-webkit-full-screen {
61+
iframe:fullscreen {
6262
border: none !important;
6363
padding: 0 !important;
6464
}
6565

66-
:not(:root):-webkit-full-screen::backdrop {
66+
:not(:root):fullscreen::backdrop {
6767
background: black;
6868
}
6969

Source/WebCore/cssjit/SelectorCompiler.cpp

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,8 @@ static JSC_DECLARE_JIT_OPERATION_WITHOUT_WTF_INTERNAL(operationIsWindowInactive,
104104
static JSC_DECLARE_JIT_OPERATION_WITHOUT_WTF_INTERNAL(operationMatchesDir, bool, (const Element&, uint32_t));
105105
static JSC_DECLARE_JIT_OPERATION_WITHOUT_WTF_INTERNAL(operationMatchesLangPseudoClass, bool, (const Element&, const FixedVector<PossiblyQuotedIdentifier>&));
106106
#if ENABLE(FULLSCREEN_API)
107-
static JSC_DECLARE_JIT_OPERATION_WITHOUT_WTF_INTERNAL(operationMatchesFullScreenPseudoClass, bool, (const Element&));
107+
static JSC_DECLARE_JIT_OPERATION_WITHOUT_WTF_INTERNAL(operationMatchesFullscreenPseudoClass, bool, (const Element&));
108+
static JSC_DECLARE_JIT_OPERATION_WITHOUT_WTF_INTERNAL(operationMatchesWebkitFullScreenPseudoClass, bool, (const Element&));
108109
static JSC_DECLARE_JIT_OPERATION_WITHOUT_WTF_INTERNAL(operationMatchesFullScreenDocumentPseudoClass, bool, (const Element&));
109110
static JSC_DECLARE_JIT_OPERATION_WITHOUT_WTF_INTERNAL(operationMatchesFullScreenAncestorPseudoClass, bool, (const Element&));
110111
static JSC_DECLARE_JIT_OPERATION_WITHOUT_WTF_INTERNAL(operationMatchesFullScreenAnimatingFullScreenTransitionPseudoClass, bool, (const Element&));
@@ -716,9 +717,14 @@ JSC_DEFINE_JIT_OPERATION(operationIsWindowInactive, bool, (const Element& elemen
716717
}
717718

718719
#if ENABLE(FULLSCREEN_API)
719-
JSC_DEFINE_JIT_OPERATION(operationMatchesFullScreenPseudoClass, bool, (const Element& element))
720+
JSC_DEFINE_JIT_OPERATION(operationMatchesFullscreenPseudoClass, bool, (const Element& element))
720721
{
721-
return matchesFullScreenPseudoClass(element);
722+
return matchesFullscreenPseudoClass(element);
723+
}
724+
725+
JSC_DEFINE_JIT_OPERATION(operationMatchesWebkitFullScreenPseudoClass, bool, (const Element& element))
726+
{
727+
return matchesWebkitFullScreenPseudoClass(element);
722728
}
723729

724730
JSC_DEFINE_JIT_OPERATION(operationMatchesFullScreenDocumentPseudoClass, bool, (const Element& element))
@@ -896,8 +902,11 @@ static inline FunctionType addPseudoClassType(const CSSSelector& selector, Selec
896902
return FunctionType::SimpleSelectorChecker;
897903

898904
#if ENABLE(FULLSCREEN_API)
899-
case CSSSelector::PseudoClassFullScreen:
900-
fragment.unoptimizedPseudoClasses.append(CodePtr<JSC::OperationPtrTag>(operationMatchesFullScreenPseudoClass));
905+
case CSSSelector::PseudoClassFullscreen:
906+
fragment.unoptimizedPseudoClasses.append(CodePtr<JSC::OperationPtrTag>(operationMatchesFullscreenPseudoClass));
907+
return FunctionType::SimpleSelectorChecker;
908+
case CSSSelector::PseudoClassWebkitFullScreen:
909+
fragment.unoptimizedPseudoClasses.append(CodePtr<JSC::OperationPtrTag>(operationMatchesWebkitFullScreenPseudoClass));
901910
return FunctionType::SimpleSelectorChecker;
902911
case CSSSelector::PseudoClassFullScreenDocument:
903912
fragment.unoptimizedPseudoClasses.append(CodePtr<JSC::OperationPtrTag>(operationMatchesFullScreenDocumentPseudoClass));

Source/WebCore/dom/Element.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4169,6 +4169,7 @@ void Element::requestFullscreen(FullscreenOptions&&, RefPtr<DeferredPromise>&& p
41694169

41704170
void Element::setFullscreenFlag(bool flag)
41714171
{
4172+
Style::PseudoClassChangeInvalidation styleInvalidation(*this, CSSSelector::PseudoClassFullscreen, flag);
41724173
if (flag)
41734174
setNodeFlag(NodeFlag::IsFullscreen);
41744175
else

0 commit comments

Comments
 (0)