[Mail] Use the Mail Viewer width as the base for resolving horizontal viewport units
authorzalan@apple.com <zalan@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sat, 23 Jun 2018 21:07:38 +0000 (21:07 +0000)
committerzalan@apple.com <zalan@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sat, 23 Jun 2018 21:07:38 +0000 (21:07 +0000)
https://bugs.webkit.org/show_bug.cgi?id=186585
<rdar://problem/30685325>

Reviewed by Tim Horton.

Source/WebCore:

Use the existing "override viewport size for viewport units" mechanism to compute the preferred
viewport unit values for the Mail Viewer html content.

Test: fast/dynamic/mail-autosize-viewport-unit.html

* page/FrameView.cpp:
(WebCore::FrameView::FrameView):
(WebCore::FrameView::enableAutoSizeMode):
(WebCore::FrameView::clearViewportSizeOverrideForCSSViewportUnits):
(WebCore::FrameView::setViewportSizeForCSSViewportUnits):
(WebCore::FrameView::overrideViewportSizeForCSSViewportUnits):
(WebCore::FrameView::viewportSizeForCSSViewportUnits const):
* page/FrameView.h:

LayoutTests:

* fast/dynamic/mail-autosize-viewport-unit-expected.txt: Added.
* fast/dynamic/mail-autosize-viewport-unit.html: Added.

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

LayoutTests/ChangeLog
LayoutTests/fast/dynamic/mail-autosize-viewport-unit-expected.txt [new file with mode: 0644]
LayoutTests/fast/dynamic/mail-autosize-viewport-unit.html [new file with mode: 0644]
LayoutTests/platform/ios/TestExpectations
Source/WebCore/ChangeLog
Source/WebCore/page/FrameView.cpp
Source/WebCore/page/FrameView.h
Tools/DumpRenderTree/mac/DumpRenderTree.mm

index 7be51e1..497e27a 100644 (file)
@@ -1,3 +1,14 @@
+2018-06-23  Zalan Bujtas  <zalan@apple.com>
+
+        [Mail] Use the Mail Viewer width as the base for resolving horizontal viewport units
+        https://bugs.webkit.org/show_bug.cgi?id=186585
+        <rdar://problem/30685325>
+
+        Reviewed by Tim Horton.
+
+        * fast/dynamic/mail-autosize-viewport-unit-expected.txt: Added.
+        * fast/dynamic/mail-autosize-viewport-unit.html: Added.
+
 2018-06-23  Per Arne Vollan  <pvollan@apple.com>
 
         Layout Test imported/mozilla/css-animations/test_animation-ready.html is failing on Windows.
diff --git a/LayoutTests/fast/dynamic/mail-autosize-viewport-unit-expected.txt b/LayoutTests/fast/dynamic/mail-autosize-viewport-unit-expected.txt
new file mode 100644 (file)
index 0000000..165145d
--- /dev/null
@@ -0,0 +1,2 @@
+
+2000px 1000px 200px 0px
diff --git a/LayoutTests/fast/dynamic/mail-autosize-viewport-unit.html b/LayoutTests/fast/dynamic/mail-autosize-viewport-unit.html
new file mode 100644 (file)
index 0000000..be083c0
--- /dev/null
@@ -0,0 +1,51 @@
+<!DOCTYPE HTML>
+<html>
+<head>
+<title>This tests that autosize uses the min-width as the base for resolving viewport unit values</title>
+<style>
+#w100 {
+    width: 100vw;
+    height: 10px;
+}
+
+#w50 {
+    width: 50vw;
+    height: 10px;
+}
+
+#w10 {
+    width: 10vw;
+    height: 10px;
+}
+
+#w0 {
+    width: 0vw;
+    height: 10px;
+}
+</style>
+<script>
+if (window.internals)
+    internals.enableAutoSizeMode(true, 2000, 600, 4000, 1000);
+
+if (window.testRunner)
+    testRunner.dumpAsText();
+</script>
+</head>
+<body>
+<div id=w100></div>
+<div id=w50></div>
+<div id=w10></div>
+<div id=w0></div>
+<img src="notfound.jpg" width=3000px height=100px>
+<pre id=result></pre>
+<script>
+document.body.offsetWidth;
+result.textContent = window.getComputedStyle(w100, null).getPropertyValue("width") + " "
+    + window.getComputedStyle(w50, null).getPropertyValue("width") + " "
+    + window.getComputedStyle(w10, null).getPropertyValue("width") + " "  
+       + window.getComputedStyle(w0, null).getPropertyValue("width");  
+if (window.internals)
+    internals.enableAutoSizeMode(false, 0, 0, 0, 0);
+</script>
+</body>
+</html>
index 5e0577b..b366d4e 100644 (file)
@@ -3308,3 +3308,6 @@ webkit.org/b/183258 imported/w3c/web-platform-tests/css/css-text/i18n/css3-text-
 webkit.org/b/183258 imported/w3c/web-platform-tests/css/css-text/i18n/css3-text-line-break-opclns-115.html [ ImageOnlyFailure ]
 webkit.org/b/183258 imported/w3c/web-platform-tests/css/css-text/i18n/css3-text-line-break-opclns-116.html [ ImageOnlyFailure ]
 webkit.org/b/183258 imported/w3c/web-platform-tests/css/css-text/word-break/word-break-break-all-006.html [ ImageOnlyFailure ]
+
+# unsupported
+fast/dynamic/mail-autosize-viewport-unit.html [ Failure ]
index 3f45d9c..8ffb021 100644 (file)
@@ -1,5 +1,27 @@
 2018-06-23  Zalan Bujtas  <zalan@apple.com>
 
+        [Mail] Use the Mail Viewer width as the base for resolving horizontal viewport units
+        https://bugs.webkit.org/show_bug.cgi?id=186585
+        <rdar://problem/30685325>
+
+        Reviewed by Tim Horton.
+
+        Use the existing "override viewport size for viewport units" mechanism to compute the preferred
+        viewport unit values for the Mail Viewer html content. 
+
+        Test: fast/dynamic/mail-autosize-viewport-unit.html
+
+        * page/FrameView.cpp:
+        (WebCore::FrameView::FrameView):
+        (WebCore::FrameView::enableAutoSizeMode):
+        (WebCore::FrameView::clearViewportSizeOverrideForCSSViewportUnits):
+        (WebCore::FrameView::setViewportSizeForCSSViewportUnits):
+        (WebCore::FrameView::overrideViewportSizeForCSSViewportUnits):
+        (WebCore::FrameView::viewportSizeForCSSViewportUnits const):
+        * page/FrameView.h:
+
+2018-06-23  Zalan Bujtas  <zalan@apple.com>
+
         [LFC] Relatively positioned renderer needs offsetting for validation
         https://bugs.webkit.org/show_bug.cgi?id=186959
 
index 8619620..8d0d656 100644 (file)
@@ -190,7 +190,6 @@ FrameView::FrameView(Frame& frame)
     , m_useCustomFixedPositionLayoutRect(false)
     , m_useCustomSizeForResizeEvent(false)
 #endif
-    , m_hasOverrideViewportSize(false)
     , m_shouldAutoSize(false)
     , m_inAutoSize(false)
     , m_didRunAutosize(false)
@@ -4368,9 +4367,12 @@ void FrameView::enableAutoSizeMode(bool enable, const IntSize& minSize, const In
 
     setNeedsLayout();
     layoutContext().scheduleLayout();
-    if (m_shouldAutoSize)
+    if (m_shouldAutoSize) {
+        overrideViewportSizeForCSSViewportUnits({ minSize.width(), m_overrideViewportSize ? m_overrideViewportSize->height : std::nullopt });
         return;
+    }
 
+    clearViewportSizeOverrideForCSSViewportUnits();
     // Since autosize mode forces the scrollbar mode, change them to being auto.
     setVerticalScrollbarLock(false);
     setHorizontalScrollbarLock(false);
@@ -5081,30 +5083,57 @@ void FrameView::setViewExposedRect(std::optional<FloatRect> viewExposedRect)
     if (auto* page = frame().page())
         page->pageOverlayController().didChangeViewExposedRect();
 }
-    
+
+void FrameView::clearViewportSizeOverrideForCSSViewportUnits()
+{
+    if (!m_overrideViewportSize)
+        return;
+
+    m_overrideViewportSize = std::nullopt;
+    if (auto* document = frame().document())
+        document->styleScope().didChangeStyleSheetEnvironment();
+}
+
 void FrameView::setViewportSizeForCSSViewportUnits(IntSize size)
 {
-    if (m_hasOverrideViewportSize && m_overrideViewportSize == size)
+    overrideViewportSizeForCSSViewportUnits({ size.width(), size.height() });
+}
+
+void FrameView::overrideViewportSizeForCSSViewportUnits(OverrideViewportSize size)
+{
+    if (m_overrideViewportSize && *m_overrideViewportSize == size)
         return;
-    
+
     m_overrideViewportSize = size;
-    m_hasOverrideViewportSize = true;
-    
-    if (Document* document = frame().document())
+
+    if (auto* document = frame().document())
         document->styleScope().didChangeStyleSheetEnvironment();
 }
-    
+
 IntSize FrameView::viewportSizeForCSSViewportUnits() const
 {
-    if (m_hasOverrideViewportSize)
-        return m_overrideViewportSize;
+    OverrideViewportSize viewportSize;
 
-    if (useFixedLayout())
-        return fixedLayoutSize();
+    if (m_overrideViewportSize) {
+        viewportSize = *m_overrideViewportSize;
+        // auto-size overrides the width only, so we can't always bail out early here.
+        if (viewportSize.width && viewportSize.height)
+            return { *viewportSize.width, *viewportSize.height };
+    }
+
+    if (useFixedLayout()) {
+        auto fixedLayoutSize = this->fixedLayoutSize();
+        viewportSize.width = viewportSize.width.value_or(fixedLayoutSize.width());
+        viewportSize.height = viewportSize.height.value_or(fixedLayoutSize.height());
+        return { *viewportSize.width, *viewportSize.height };
+    }
     
     // FIXME: the value returned should take into account the value of the overflow
     // property on the root element.
-    return visibleContentRectIncludingScrollbars().size();
+    auto visibleContentSizeIncludingScrollbars = visibleContentRectIncludingScrollbars().size();
+    viewportSize.width = viewportSize.width.value_or(visibleContentSizeIncludingScrollbars.width());
+    viewportSize.height = viewportSize.height.value_or(visibleContentSizeIncludingScrollbars.height());
+    return { *viewportSize.width, *viewportSize.height };
 }
 
 bool FrameView::shouldPlaceBlockDirectionScrollbarOnLeft() const
index 8f60e7c..11cffab 100644 (file)
@@ -211,8 +211,9 @@ public:
     WEBCORE_EXPORT void adjustViewSize();
 
     WEBCORE_EXPORT void setViewportSizeForCSSViewportUnits(IntSize);
+    void clearViewportSizeOverrideForCSSViewportUnits();
     IntSize viewportSizeForCSSViewportUnits() const;
-    
+
     IntRect windowClipRect() const final;
     WEBCORE_EXPORT IntRect windowClipRectForFrameOwner(const HTMLFrameOwnerElement*, bool clipToLayerContents) const;
 
@@ -782,6 +783,14 @@ private:
     void willDoLayout(WeakPtr<RenderElement> layoutRoot);
     void didLayout(WeakPtr<RenderElement> layoutRoot);
 
+    struct OverrideViewportSize {
+        std::optional<int> width;
+        std::optional<int> height;
+
+        bool operator==(const OverrideViewportSize& rhs) const { return rhs.width == width && rhs.height == height; }
+    };
+    void overrideViewportSizeForCSSViewportUnits(OverrideViewportSize);
+
     HashSet<Widget*> m_widgetsInRenderTree;
 
     static MonotonicTime sCurrentPaintTimeStamp; // used for detecting decoded resource thrash in the cache
@@ -867,8 +876,7 @@ private:
     IntSize m_customSizeForResizeEvent;
 #endif
 
-    IntSize m_overrideViewportSize;
-    bool m_hasOverrideViewportSize;
+    std::optional<OverrideViewportSize> m_overrideViewportSize;
 
     // If true, automatically resize the frame view around its content.
     bool m_shouldAutoSize;
index f659e94..d69677b 100644 (file)
@@ -1589,10 +1589,9 @@ static void sizeWebViewForCurrentTest()
 
     // W3C SVG tests expect to be 480x360
     bool isSVGW3CTest = (gTestRunner->testURL().find("svg/W3C-SVG-1.1") != string::npos);
-    if (isSVGW3CTest)
-        [[mainFrame webView] setFrameSize:NSMakeSize(TestRunner::w3cSVGViewWidth, TestRunner::w3cSVGViewHeight)];
-    else
-        [[mainFrame webView] setFrameSize:NSMakeSize(TestRunner::viewWidth, TestRunner::viewHeight)];
+    NSSize frameSize = isSVGW3CTest ? NSMakeSize(TestRunner::w3cSVGViewWidth, TestRunner::w3cSVGViewHeight) : NSMakeSize(TestRunner::viewWidth, TestRunner::viewHeight);
+    [[mainFrame webView] setFrameSize:frameSize];
+    [[mainFrame frameView] setFrame:NSMakeRect(0, 0, frameSize.width, frameSize.height)];
 }
 
 static const char *methodNameStringForFailedTest()