Title: [252330] trunk
Revision
252330
Author
[email protected]
Date
2019-11-11 10:01:20 -0800 (Mon, 11 Nov 2019)

Log Message

[Picture-in-Picture Web API] Support picture-in-picture CSS pseudo-class
https://bugs.webkit.org/show_bug.cgi?id=203493

Patch by Peng Liu <[email protected]> on 2019-11-11
Reviewed by Dean Jackson.

Source/WebCore:

Add CSS pseudo class ":picture-in-picture" for a video element in the picture-in-picture mode.

Test: media/picture-in-picture/picture-in-picture-api-css-selector.html

* Modules/pictureinpicture/HTMLVideoElementPictureInPicture.cpp:
(WebCore::HTMLVideoElementPictureInPicture::didEnterPictureInPicture):
(WebCore::HTMLVideoElementPictureInPicture::didExitPictureInPicture):
* css/CSSSelector.cpp:
(WebCore::CSSSelector::selectorText const):
* css/CSSSelector.h:
* css/SelectorChecker.cpp:
(WebCore::SelectorChecker::checkOne const):
* css/SelectorCheckerTestFunctions.h:
(WebCore::matchesPictureInPicturePseudoClass):
* css/SelectorPseudoClassAndCompatibilityElementMap.in:
* cssjit/SelectorCompiler.cpp:
(WebCore::SelectorCompiler::addPseudoClassType):

LayoutTests:

* media/picture-in-picture/picture-in-picture-api-css-selector-expected.txt: Added.
* media/picture-in-picture/picture-in-picture-api-css-selector.html: Added.

Modified Paths

Added Paths

Diff

Modified: trunk/LayoutTests/ChangeLog (252329 => 252330)


--- trunk/LayoutTests/ChangeLog	2019-11-11 17:49:17 UTC (rev 252329)
+++ trunk/LayoutTests/ChangeLog	2019-11-11 18:01:20 UTC (rev 252330)
@@ -1,3 +1,13 @@
+2019-11-11  Peng Liu  <[email protected]>
+
+        [Picture-in-Picture Web API] Support picture-in-picture CSS pseudo-class
+        https://bugs.webkit.org/show_bug.cgi?id=203493
+
+        Reviewed by Dean Jackson.
+
+        * media/picture-in-picture/picture-in-picture-api-css-selector-expected.txt: Added.
+        * media/picture-in-picture/picture-in-picture-api-css-selector.html: Added.
+
 2019-11-11  Commit Queue  <[email protected]>
 
         Unreviewed, rolling out r251460.

Added: trunk/LayoutTests/media/picture-in-picture/picture-in-picture-api-css-selector-expected.txt (0 => 252330)


--- trunk/LayoutTests/media/picture-in-picture/picture-in-picture-api-css-selector-expected.txt	                        (rev 0)
+++ trunk/LayoutTests/media/picture-in-picture/picture-in-picture-api-css-selector-expected.txt	2019-11-11 18:01:20 UTC (rev 252330)
@@ -0,0 +1,13 @@
+This tests that entering and leaving Picture-in-Picture toggles CSS selector.
+
+RUN(internals.settings.setAllowsPictureInPictureMediaPlayback(true))
+RUN(internals.setPictureInPictureAPITestEnabled(video, true))
+RUN(video.src = "" "../content/test"))
+EVENT(canplaythrough)
+EXPECTED (getComputedStyle(video).color == 'rgb(0, 0, 255)') OK
+EVENT(enterpictureinpicture)
+EXPECTED (getComputedStyle(video).color == 'rgb(0, 255, 0)') OK
+EVENT(leavepictureinpicture)
+EXPECTED (getComputedStyle(video).color == 'rgb(0, 0, 255)') OK
+END OF TEST
+

Added: trunk/LayoutTests/media/picture-in-picture/picture-in-picture-api-css-selector.html (0 => 252330)


--- trunk/LayoutTests/media/picture-in-picture/picture-in-picture-api-css-selector.html	                        (rev 0)
+++ trunk/LayoutTests/media/picture-in-picture/picture-in-picture-api-css-selector.html	2019-11-11 18:01:20 UTC (rev 252330)
@@ -0,0 +1,45 @@
+<!DOCTYPE html>
+<html>
+<head>
+    <script src=""
+    <script src=""
+    <style>
+        video {
+            color: rgb(0, 0, 255);
+        }
+        :picture-in-picture {
+            color: rgb(0, 255, 0);
+        }
+        /* illegal selector list */
+        video, :picture-in-picture(*) {
+            color: rgb(255, 0, 0);
+        }
+    </style>
+    <script>
+        window.addEventListener('load', async event => {
+            findMediaElement();
+
+            run('internals.settings.setAllowsPictureInPictureMediaPlayback(true)');
+            run('internals.setPictureInPictureAPITestEnabled(video, true)');
+
+            run('video.src = "" "../content/test")');
+            await waitFor(video, 'canplaythrough');
+            testExpected('getComputedStyle(video).color', 'rgb(0, 0, 255)');
+
+            runWithKeyDown(function() { video.requestPictureInPicture() });
+            await waitFor(video, 'enterpictureinpicture');
+            testExpected('getComputedStyle(video).color', 'rgb(0, 255, 0)');
+
+            document.exitPictureInPicture();
+            await waitFor(video, 'leavepictureinpicture');
+            testExpected('getComputedStyle(video).color', 'rgb(0, 0, 255)');
+
+            endTest();
+        });
+    </script>
+</head>
+<body>
+    <div>This tests that entering and leaving Picture-in-Picture toggles CSS selector.</div>
+    <video controls></video>
+</body>
+</html>

Modified: trunk/Source/WebCore/ChangeLog (252329 => 252330)


--- trunk/Source/WebCore/ChangeLog	2019-11-11 17:49:17 UTC (rev 252329)
+++ trunk/Source/WebCore/ChangeLog	2019-11-11 18:01:20 UTC (rev 252330)
@@ -1,3 +1,28 @@
+2019-11-11  Peng Liu  <[email protected]>
+
+        [Picture-in-Picture Web API] Support picture-in-picture CSS pseudo-class
+        https://bugs.webkit.org/show_bug.cgi?id=203493
+
+        Reviewed by Dean Jackson.
+
+        Add CSS pseudo class ":picture-in-picture" for a video element in the picture-in-picture mode.
+
+        Test: media/picture-in-picture/picture-in-picture-api-css-selector.html
+
+        * Modules/pictureinpicture/HTMLVideoElementPictureInPicture.cpp:
+        (WebCore::HTMLVideoElementPictureInPicture::didEnterPictureInPicture):
+        (WebCore::HTMLVideoElementPictureInPicture::didExitPictureInPicture):
+        * css/CSSSelector.cpp:
+        (WebCore::CSSSelector::selectorText const):
+        * css/CSSSelector.h:
+        * css/SelectorChecker.cpp:
+        (WebCore::SelectorChecker::checkOne const):
+        * css/SelectorCheckerTestFunctions.h:
+        (WebCore::matchesPictureInPicturePseudoClass):
+        * css/SelectorPseudoClassAndCompatibilityElementMap.in:
+        * cssjit/SelectorCompiler.cpp:
+        (WebCore::SelectorCompiler::addPseudoClassType):
+
 2019-11-11  Commit Queue  <[email protected]>
 
         Unreviewed, rolling out r251460.

Modified: trunk/Source/WebCore/Modules/pictureinpicture/HTMLVideoElementPictureInPicture.cpp (252329 => 252330)


--- trunk/Source/WebCore/Modules/pictureinpicture/HTMLVideoElementPictureInPicture.cpp	2019-11-11 17:49:17 UTC (rev 252329)
+++ trunk/Source/WebCore/Modules/pictureinpicture/HTMLVideoElementPictureInPicture.cpp	2019-11-11 18:01:20 UTC (rev 252330)
@@ -154,6 +154,7 @@
 void HTMLVideoElementPictureInPicture::didEnterPictureInPicture(const IntSize& windowSize)
 {
     INFO_LOG(LOGIDENTIFIER);
+    m_videoElement.invalidateStyle();
     m_videoElement.document().setPictureInPictureElement(&m_videoElement);
     m_pictureInPictureWindow->setSize(windowSize);
 
@@ -171,6 +172,7 @@
 void HTMLVideoElementPictureInPicture::didExitPictureInPicture()
 {
     INFO_LOG(LOGIDENTIFIER);
+    m_videoElement.invalidateStyle();
     m_pictureInPictureWindow->close();
     m_videoElement.document().setPictureInPictureElement(nullptr);
     m_videoElement.scheduleEvent(Event::create(eventNames().leavepictureinpictureEvent, Event::CanBubble::Yes, Event::IsCancelable::No));

Modified: trunk/Source/WebCore/css/CSSSelector.cpp (252329 => 252330)


--- trunk/Source/WebCore/css/CSSSelector.cpp	2019-11-11 17:49:17 UTC (rev 252329)
+++ trunk/Source/WebCore/css/CSSSelector.cpp	2019-11-11 18:01:20 UTC (rev 252330)
@@ -497,6 +497,11 @@
                 builder.appendLiteral(":-webkit-full-screen-controls-hidden");
                 break;
 #endif
+#if ENABLE(PICTURE_IN_PICTURE_API)
+            case CSSSelector::PseudoClassPictureInPicture:
+                builder.appendLiteral(":picture-in-picture");
+                break;
+#endif
             case CSSSelector::PseudoClassActive:
                 builder.appendLiteral(":active");
                 break;

Modified: trunk/Source/WebCore/css/CSSSelector.h (252329 => 252330)


--- trunk/Source/WebCore/css/CSSSelector.h	2019-11-11 17:49:17 UTC (rev 252329)
+++ trunk/Source/WebCore/css/CSSSelector.h	2019-11-11 18:01:20 UTC (rev 252330)
@@ -152,6 +152,9 @@
             PseudoClassAnimatingFullScreenTransition,
             PseudoClassFullScreenControlsHidden,
 #endif
+#if ENABLE(PICTURE_IN_PICTURE_API)
+            PseudoClassPictureInPicture,
+#endif
             PseudoClassInRange,
             PseudoClassOutOfRange,
 #if ENABLE(VIDEO_TRACK)

Modified: trunk/Source/WebCore/css/SelectorChecker.cpp (252329 => 252330)


--- trunk/Source/WebCore/css/SelectorChecker.cpp	2019-11-11 17:49:17 UTC (rev 252329)
+++ trunk/Source/WebCore/css/SelectorChecker.cpp	2019-11-11 18:01:20 UTC (rev 252330)
@@ -1069,6 +1069,10 @@
         case CSSSelector::PseudoClassFullScreenControlsHidden:
             return matchesFullScreenControlsHiddenPseudoClass(element);
 #endif
+#if ENABLE(PICTURE_IN_PICTURE_API)
+        case CSSSelector::PseudoClassPictureInPicture:
+            return matchesPictureInPicturePseudoClass(element);
+#endif
         case CSSSelector::PseudoClassInRange:
             return isInRange(element);
         case CSSSelector::PseudoClassOutOfRange:

Modified: trunk/Source/WebCore/css/SelectorCheckerTestFunctions.h (252329 => 252330)


--- trunk/Source/WebCore/css/SelectorCheckerTestFunctions.h	2019-11-11 17:49:17 UTC (rev 252329)
+++ trunk/Source/WebCore/css/SelectorCheckerTestFunctions.h	2019-11-11 18:01:20 UTC (rev 252330)
@@ -43,6 +43,10 @@
 #include "WebVTTElement.h"
 #endif
 
+#if ENABLE(PICTURE_IN_PICTURE_API)
+#include "HTMLVideoElement.h"
+#endif
+
 namespace WebCore {
 
 ALWAYS_INLINE bool isAutofilled(const Element& element)
@@ -410,6 +414,15 @@
 
 #endif
 
+#if ENABLE(PICTURE_IN_PICTURE_API)
+
+ALWAYS_INLINE bool matchesPictureInPicturePseudoClass(const Element& element)
+{
+    return is<HTMLVideoElement>(element) && element.document().pictureInPictureElement() == &element;
+}
+
+#endif
+
 #if ENABLE(VIDEO_TRACK)
 
 ALWAYS_INLINE bool matchesFutureCuePseudoClass(const Element& element)

Modified: trunk/Source/WebCore/css/SelectorPseudoClassAndCompatibilityElementMap.in (252329 => 252330)


--- trunk/Source/WebCore/css/SelectorPseudoClassAndCompatibilityElementMap.in	2019-11-11 17:49:17 UTC (rev 252329)
+++ trunk/Source/WebCore/css/SelectorPseudoClassAndCompatibilityElementMap.in	2019-11-11 18:01:20 UTC (rev 252330)
@@ -80,6 +80,10 @@
 -webkit-full-screen-controls-hidden
 #endif
 
+#if ENABLE(PICTURE_IN_PICTURE_API)
+picture-in-picture
+#endif
+
 #if ENABLE(VIDEO_TRACK)
 future
 past

Modified: trunk/Source/WebCore/cssjit/SelectorCompiler.cpp (252329 => 252330)


--- trunk/Source/WebCore/cssjit/SelectorCompiler.cpp	2019-11-11 17:49:17 UTC (rev 252329)
+++ trunk/Source/WebCore/cssjit/SelectorCompiler.cpp	2019-11-11 18:01:20 UTC (rev 252330)
@@ -616,6 +616,13 @@
         fragment.unoptimizedPseudoClasses.append(JSC::FunctionPtr<CSSOperationPtrTag>(matchesFullScreenControlsHiddenPseudoClass));
         return FunctionType::SimpleSelectorChecker;
 #endif
+
+#if ENABLE(PICTURE_IN_PICTURE_API)
+    case CSSSelector::PseudoClassPictureInPicture:
+        fragment.unoptimizedPseudoClasses.append(JSC::FunctionPtr<CSSOperationPtrTag>(matchesPictureInPicturePseudoClass));
+        return FunctionType::SimpleSelectorChecker;
+#endif
+
 #if ENABLE(VIDEO_TRACK)
     case CSSSelector::PseudoClassFuture:
         fragment.unoptimizedPseudoClasses.append(JSC::FunctionPtr<CSSOperationPtrTag>(matchesFutureCuePseudoClass));
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to