fullscreen env() variables should have initial values
authordino@apple.com <dino@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 23 Jul 2018 16:53:54 +0000 (16:53 +0000)
committerdino@apple.com <dino@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 23 Jul 2018 16:53:54 +0000 (16:53 +0000)
https://bugs.webkit.org/show_bug.cgi?id=187897
<rdar://problem/42485682>

Reviewed by Sam Weinig.

Source/WebCore:

The env() values for fullscreen properties need to be
initialized, rather than wait for values to be set from WebKit.
Without this, feature detection doesn't work, and properties
won't parse correctly.

Test: fullscreen/fullscreen-env-initial.html

* dom/ConstantPropertyMap.cpp:
(WebCore::ConstantPropertyMap::buildValues): Initialize the fullscreen values.
(WebCore::ConstantPropertyMap::updateConstantsForFullscreen): Renamed function, because it
also updates the duration value.
(WebCore::ConstantPropertyMap::didChangeFullscreenInsets): Call new name.
(WebCore::ConstantPropertyMap::updateConstantsForFullscreenInsets): Deleted.
* dom/ConstantPropertyMap.h:
* page/Page.cpp:
(WebCore::Page::setFullscreenAutoHideDuration): Don't change the value if it doesn't need it.
* page/Page.h: Add accessor for fullscreenAutoHideDuration. Also add a member variable.
(WebCore::Page::fullscreenAutoHideDuration const):

LayoutTests:

* fullscreen/fullscreen-env-initial-expected.html: Added.
* fullscreen/fullscreen-env-initial.html: Added.

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@234098 268f45cc-cd09-0410-ab3c-d52691b4dbfc

LayoutTests/ChangeLog
LayoutTests/fullscreen/fullscreen-env-initial-expected.html [new file with mode: 0644]
LayoutTests/fullscreen/fullscreen-env-initial.html [new file with mode: 0644]
Source/WebCore/ChangeLog
Source/WebCore/dom/ConstantPropertyMap.cpp
Source/WebCore/dom/ConstantPropertyMap.h
Source/WebCore/page/Page.cpp
Source/WebCore/page/Page.h

index 31bbf64..8f8a34c 100644 (file)
@@ -1,3 +1,14 @@
+2018-07-22  Dean Jackson  <dino@apple.com>
+
+        fullscreen env() variables should have initial values
+        https://bugs.webkit.org/show_bug.cgi?id=187897
+        <rdar://problem/42485682>
+
+        Reviewed by Sam Weinig.
+
+        * fullscreen/fullscreen-env-initial-expected.html: Added.
+        * fullscreen/fullscreen-env-initial.html: Added.
+
 2018-07-20  John Wilander  <wilander@apple.com>
 
         Resource Load Statistics: Enable basic functionality in experimental debug mode
diff --git a/LayoutTests/fullscreen/fullscreen-env-initial-expected.html b/LayoutTests/fullscreen/fullscreen-env-initial-expected.html
new file mode 100644 (file)
index 0000000..d8e3ce0
--- /dev/null
@@ -0,0 +1,15 @@
+<!DOCTYPE html>
+<html>
+<head>
+  <title>fullscreen-env-initial</title>
+  <style>
+      #should-be-green {
+          background-color: green;
+      }
+  </style>
+</head>
+<body>
+<p id="should-be-green">This paragraph should have a green background.</p>
+<p id="results">fullscreen-inset-top fullscreen-inset-right fullscreen-inset-bottom fullscreen-inset-left fullscreen-auto-hide-duration all had initial values.</p>
+</body>
+</html>
diff --git a/LayoutTests/fullscreen/fullscreen-env-initial.html b/LayoutTests/fullscreen/fullscreen-env-initial.html
new file mode 100644 (file)
index 0000000..a3a31d5
--- /dev/null
@@ -0,0 +1,49 @@
+<!DOCTYPE html>
+<html>
+<head>
+  <title>fullscreen-env-initial</title>
+  <style>
+      #dummy {
+          position: absolute;
+          top: 0;
+          left: 0;
+          width: 0;
+          height: 0;
+          --fullscreen-inset-top: env(fullscreen-inset-top);
+          --fullscreen-inset-right: env(fullscreen-inset-right);
+          --fullscreen-inset-bottom: env(fullscreen-inset-bottom);
+          --fullscreen-inset-left: env(fullscreen-inset-left);
+          --fullscreen-auto-hide-duration: env(fullscreen-auto-hide-duration);
+      }
+      @supports (padding: env(fullscreen-inset-top)) {
+          #should-be-green {
+              background-color: green;
+          }
+      }
+  </style>
+  <script>
+      const ENVS = ["fullscreen-inset-top", "fullscreen-inset-right", "fullscreen-inset-bottom", "fullscreen-inset-left", "fullscreen-auto-hide-duration"];
+      function runTest() {
+          const results = document.getElementById("results");
+          const dummyStyle = window.getComputedStyle(document.getElementById("dummy"));
+          const checkForValue = (accumulator, value) => {
+              if (!accumulator)
+                  return false;
+              return dummyStyle.getPropertyValue(`--${value}`) != "";
+          };
+          if (ENVS.reduce(checkForValue))
+              results.textContent = `${ENVS.join(" ")} all had initial values.`;
+          else
+              results.textContent = `Some/all of ${ENVS.join(" ")} had missing initial values.`;
+      }
+
+
+window.addEventListener("load", runTest, false);
+  </script>
+</head>
+<body>
+<span id="dummy"></span>
+<p id="should-be-green">This paragraph should have a green background.</p>
+<p id="results"></p>
+</body>
+</html>
index 6cc423a..354dd08 100644 (file)
@@ -1,3 +1,30 @@
+2018-07-22  Dean Jackson  <dino@apple.com>
+
+        fullscreen env() variables should have initial values
+        https://bugs.webkit.org/show_bug.cgi?id=187897
+        <rdar://problem/42485682>
+
+        Reviewed by Sam Weinig.
+
+        The env() values for fullscreen properties need to be
+        initialized, rather than wait for values to be set from WebKit.
+        Without this, feature detection doesn't work, and properties
+        won't parse correctly.
+
+        Test: fullscreen/fullscreen-env-initial.html
+
+        * dom/ConstantPropertyMap.cpp:
+        (WebCore::ConstantPropertyMap::buildValues): Initialize the fullscreen values.
+        (WebCore::ConstantPropertyMap::updateConstantsForFullscreen): Renamed function, because it
+        also updates the duration value.
+        (WebCore::ConstantPropertyMap::didChangeFullscreenInsets): Call new name.
+        (WebCore::ConstantPropertyMap::updateConstantsForFullscreenInsets): Deleted.
+        * dom/ConstantPropertyMap.h:
+        * page/Page.cpp:
+        (WebCore::Page::setFullscreenAutoHideDuration): Don't change the value if it doesn't need it.
+        * page/Page.h: Add accessor for fullscreenAutoHideDuration. Also add a member variable.
+        (WebCore::Page::fullscreenAutoHideDuration const):
+
 2018-07-22  Zalan Bujtas  <zalan@apple.com>
 
         [LFC][IFC] Add center/right/justify line alignment support.
index 84bdfe8..90fd139 100644 (file)
@@ -98,6 +98,7 @@ void ConstantPropertyMap::buildValues()
     m_values = Values { };
 
     updateConstantsForSafeAreaInsets();
+    updateConstantsForFullscreen();
 }
 
 static Ref<CSSVariableData> variableDataForPositivePixelLength(float lengthInPx)
@@ -139,18 +140,21 @@ void ConstantPropertyMap::didChangeSafeAreaInsets()
     m_document.invalidateMatchedPropertiesCacheAndForceStyleRecalc();
 }
 
-void ConstantPropertyMap::updateConstantsForFullscreenInsets()
+void ConstantPropertyMap::updateConstantsForFullscreen()
 {
     FloatBoxExtent fullscreenInsets = m_document.page() ? m_document.page()->fullscreenInsets() : FloatBoxExtent();
     setValueForProperty(ConstantProperty::FullscreenInsetTop, variableDataForPositivePixelLength(fullscreenInsets.top()));
     setValueForProperty(ConstantProperty::FullscreenInsetRight, variableDataForPositivePixelLength(fullscreenInsets.right()));
     setValueForProperty(ConstantProperty::FullscreenInsetBottom, variableDataForPositivePixelLength(fullscreenInsets.bottom()));
     setValueForProperty(ConstantProperty::FullscreenInsetLeft, variableDataForPositivePixelLength(fullscreenInsets.left()));
+
+    Seconds fullscreenAutoHideDuration = m_document.page() ? m_document.page()->fullscreenAutoHideDuration() : 0_s;
+    setValueForProperty(ConstantProperty::FullscreenAutoHideDuration, variableDataForPositiveDuration(fullscreenAutoHideDuration));
 }
 
 void ConstantPropertyMap::didChangeFullscreenInsets()
 {
-    updateConstantsForFullscreenInsets();
+    updateConstantsForFullscreen();
     m_document.invalidateMatchedPropertiesCacheAndForceStyleRecalc();
 }
 
index 8d3239b..9a9cd22 100644 (file)
@@ -68,7 +68,7 @@ private:
     void setValueForProperty(ConstantProperty, Ref<CSSVariableData>&&);
 
     void updateConstantsForSafeAreaInsets();
-    void updateConstantsForFullscreenInsets();
+    void updateConstantsForFullscreen();
 
     std::optional<Values> m_values;
 
index 61e2f63..ee86ccd 100644 (file)
@@ -2454,6 +2454,9 @@ void Page::setFullscreenInsets(const FloatBoxExtent& insets)
 
 void Page::setFullscreenAutoHideDuration(Seconds duration)
 {
+    if (duration == m_fullscreenAutoHideDuration)
+        return;
+    m_fullscreenAutoHideDuration = duration;
     for (Frame* frame = &mainFrame(); frame; frame = frame->tree().traverseNext()) {
         if (!frame->document())
             continue;
index 0d16963..e069674 100644 (file)
@@ -352,9 +352,10 @@ public:
     void setTextAutosizingWidth(float textAutosizingWidth) { m_textAutosizingWidth = textAutosizingWidth; }
 #endif
 
-    WEBCORE_EXPORT void setFullscreenInsets(const FloatBoxExtent&);
     const FloatBoxExtent& fullscreenInsets() const { return m_fullscreenInsets; }
+    WEBCORE_EXPORT void setFullscreenInsets(const FloatBoxExtent&);
 
+    const Seconds fullscreenAutoHideDuration() const { return m_fullscreenAutoHideDuration; }
     WEBCORE_EXPORT void setFullscreenAutoHideDuration(Seconds);
     WEBCORE_EXPORT void setFullscreenControlsHidden(bool);
 
@@ -754,6 +755,7 @@ private:
     FloatBoxExtent m_obscuredInsets;
     FloatBoxExtent m_unobscuredSafeAreaInsets;
     FloatBoxExtent m_fullscreenInsets;
+    Seconds m_fullscreenAutoHideDuration { 0_s };
 
 #if PLATFORM(IOS)
     bool m_enclosedInScrollableAncestorView { false };