[LFC] Move replaced logic from Layout::Box to Layout::Replaced class
authorzalan@apple.com <zalan@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 17 May 2018 14:11:08 +0000 (14:11 +0000)
committerzalan@apple.com <zalan@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 17 May 2018 14:11:08 +0000 (14:11 +0000)
https://bugs.webkit.org/show_bug.cgi?id=185711

Reviewed by Antti Koivisto.

* Sources.txt:
* WebCore.xcodeproj/project.pbxproj:
* layout/FormattingContext.cpp:
(WebCore::Layout::FormattingContext::computeOutOfFlowWidth const):
(WebCore::Layout::FormattingContext::computeFloatingWidth const):
(WebCore::Layout::FormattingContext::computeOutOfFlowHeight const):
(WebCore::Layout::FormattingContext::computeInFlowReplacedWidth const):
* layout/blockformatting/BlockFormattingContext.cpp:
(WebCore::Layout::BlockFormattingContext::computeInFlowWidth const):
(WebCore::Layout::BlockFormattingContext::computeInFlowHeight const):
* layout/layouttree/LayoutBox.cpp:
(WebCore::Layout::Box::isReplaced const): Deleted.
(WebCore::Layout::Box::hasIntrinsicWidth const): Deleted.
(WebCore::Layout::Box::hasIntrinsicHeight const): Deleted.
(WebCore::Layout::Box::hasIntrinsicRatio const): Deleted.
(WebCore::Layout::Box::intrinsicWidth const): Deleted.
(WebCore::Layout::Box::intrinsicHeight const): Deleted.
(WebCore::Layout::Box::intrinsicRatio const): Deleted.
* layout/layouttree/LayoutBox.h:
(WebCore::Layout::Box::replaced const):

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

Source/WebCore/ChangeLog
Source/WebCore/Sources.txt
Source/WebCore/WebCore.xcodeproj/project.pbxproj
Source/WebCore/layout/FormattingContext.cpp
Source/WebCore/layout/blockformatting/BlockFormattingContext.cpp
Source/WebCore/layout/layouttree/LayoutBox.cpp
Source/WebCore/layout/layouttree/LayoutBox.h
Source/WebCore/layout/layouttree/LayoutReplaced.cpp [new file with mode: 0644]
Source/WebCore/layout/layouttree/LayoutReplaced.h [new file with mode: 0644]

index a9688de..04999ee 100644 (file)
@@ -1,5 +1,33 @@
 2018-05-17  Zalan Bujtas  <zalan@apple.com>
 
+        [LFC] Move replaced logic from Layout::Box to Layout::Replaced class
+        https://bugs.webkit.org/show_bug.cgi?id=185711
+
+        Reviewed by Antti Koivisto.
+
+        * Sources.txt:
+        * WebCore.xcodeproj/project.pbxproj:
+        * layout/FormattingContext.cpp:
+        (WebCore::Layout::FormattingContext::computeOutOfFlowWidth const):
+        (WebCore::Layout::FormattingContext::computeFloatingWidth const):
+        (WebCore::Layout::FormattingContext::computeOutOfFlowHeight const):
+        (WebCore::Layout::FormattingContext::computeInFlowReplacedWidth const):
+        * layout/blockformatting/BlockFormattingContext.cpp:
+        (WebCore::Layout::BlockFormattingContext::computeInFlowWidth const):
+        (WebCore::Layout::BlockFormattingContext::computeInFlowHeight const):
+        * layout/layouttree/LayoutBox.cpp:
+        (WebCore::Layout::Box::isReplaced const): Deleted.
+        (WebCore::Layout::Box::hasIntrinsicWidth const): Deleted.
+        (WebCore::Layout::Box::hasIntrinsicHeight const): Deleted.
+        (WebCore::Layout::Box::hasIntrinsicRatio const): Deleted.
+        (WebCore::Layout::Box::intrinsicWidth const): Deleted.
+        (WebCore::Layout::Box::intrinsicHeight const): Deleted.
+        (WebCore::Layout::Box::intrinsicRatio const): Deleted.
+        * layout/layouttree/LayoutBox.h:
+        (WebCore::Layout::Box::replaced const):
+
+2018-05-17  Zalan Bujtas  <zalan@apple.com>
+
         [LFC] Implement width computation for replaced out if flow elements.
         https://bugs.webkit.org/show_bug.cgi?id=185701
 
index 9c938a5..db31065 100644 (file)
@@ -1231,6 +1231,7 @@ layout/layouttree/LayoutBox.cpp
 layout/layouttree/LayoutContainer.cpp
 layout/layouttree/LayoutInlineBox.cpp
 layout/layouttree/LayoutInlineContainer.cpp
+layout/layouttree/LayoutReplaced.cpp
 layout/layouttree/LayoutTreeBuilder.cpp
 
 loader/ContentFilter.cpp
index 534b470..7065759 100644 (file)
                11100FCA2092868D0081AA6C /* LayoutAncestorIterator.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = LayoutAncestorIterator.h; sourceTree = "<group>"; };
                11100FD5209514DE0081AA6C /* LayoutTreeBuilder.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = LayoutTreeBuilder.cpp; sourceTree = "<group>"; };
                11100FD7209514DF0081AA6C /* LayoutTreeBuilder.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = LayoutTreeBuilder.h; sourceTree = "<group>"; };
+               111C615620AD1AE1005B82FA /* LayoutReplaced.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = LayoutReplaced.h; sourceTree = "<group>"; };
+               111C615720AD1AE1005B82FA /* LayoutReplaced.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = LayoutReplaced.cpp; sourceTree = "<group>"; };
                1123AFD9209ABB2000736ACC /* BlockInvalidation.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = BlockInvalidation.h; sourceTree = "<group>"; };
                1123AFDA209ABB2000736ACC /* BlockInvalidation.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = BlockInvalidation.cpp; sourceTree = "<group>"; };
                1123AFDC209ABBBA00736ACC /* InlineInvalidation.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = InlineInvalidation.h; sourceTree = "<group>"; };
                                1199FA4E208E3899002358CC /* LayoutInlineContainer.cpp */,
                                1199FA4D208E3899002358CC /* LayoutInlineContainer.h */,
                                11100FC72092764C0081AA6C /* LayoutIterator.h */,
+                               111C615720AD1AE1005B82FA /* LayoutReplaced.cpp */,
+                               111C615620AD1AE1005B82FA /* LayoutReplaced.h */,
                                11100FD5209514DE0081AA6C /* LayoutTreeBuilder.cpp */,
                                11100FD7209514DF0081AA6C /* LayoutTreeBuilder.h */,
                        );
index 65f6369..deb596b 100644 (file)
@@ -80,7 +80,7 @@ void FormattingContext::computeHeight(LayoutContext& layoutContext, const Box& l
 
 void FormattingContext::computeOutOfFlowWidth(LayoutContext& layoutContext, const Box& layoutBox, Display::Box& displayBox) const
 {
-    if (!layoutBox.isReplaced()) {
+    if (!layoutBox.replaced()) {
         computeOutOfFlowNonReplacedWidth(layoutContext, layoutBox, displayBox);
         return;
     }
@@ -89,7 +89,7 @@ void FormattingContext::computeOutOfFlowWidth(LayoutContext& layoutContext, cons
 
 void FormattingContext::computeFloatingWidth(LayoutContext& layoutContext, const Box& layoutBox, Display::Box& displayBox) const
 {
-    if (!layoutBox.isReplaced()) {
+    if (!layoutBox.replaced()) {
         ASSERT_NOT_REACHED();
         return;
     }
@@ -98,7 +98,7 @@ void FormattingContext::computeFloatingWidth(LayoutContext& layoutContext, const
 
 void FormattingContext::computeOutOfFlowHeight(LayoutContext& layoutContext, const Box& layoutBox, Display::Box& displayBox) const
 {
-    if (!layoutBox.isReplaced()) {
+    if (!layoutBox.replaced()) {
         computeOutOfFlowNonReplacedHeight(layoutContext, layoutBox, displayBox);
         return;
     }
@@ -241,21 +241,23 @@ void FormattingContext::computeReplacedWidth(LayoutContext&, const Box& layoutBo
     auto height = style.logicalHeight();
 
     LayoutUnit computedWidthValue;
+    auto replaced = layoutBox.replaced();
+    ASSERT(replaced);
 
-    if (width.isAuto() && height.isAuto() && layoutBox.hasIntrinsicWidth()) {
+    if (width.isAuto() && height.isAuto() && replaced->hasIntrinsicWidth()) {
         // #1
-        computedWidthValue = layoutBox.intrinsicWidth();
-    } else if (width.isAuto() && (height.isCalculated() || layoutBox.hasIntrinsicHeight()) && layoutBox.hasIntrinsicRatio()) {
+        computedWidthValue = replaced->intrinsicWidth();
+    } else if (width.isAuto() && (height.isCalculated() || replaced->hasIntrinsicHeight()) && replaced->hasIntrinsicRatio()) {
         // #2
-        auto usedHeight = height.isCalculated() ? LayoutUnit(height.value()) : layoutBox.intrinsicHeight();   
-        computedWidthValue = usedHeight * layoutBox.intrinsicRatio();
-    } else if (width.isAuto() && height.isAuto() && layoutBox.hasIntrinsicRatio()) {
+        auto usedHeight = height.isCalculated() ? LayoutUnit(height.value()) : replaced->intrinsicHeight();   
+        computedWidthValue = usedHeight * replaced->intrinsicRatio();
+    } else if (width.isAuto() && height.isAuto() && replaced->hasIntrinsicRatio()) {
         // #3
         // FIXME: undefined but surely doable.
         ASSERT_NOT_REACHED();
-    } else if (width.isAuto() && layoutBox.hasIntrinsicWidth()) {
+    } else if (width.isAuto() && replaced->hasIntrinsicWidth()) {
         // #4
-        computedWidthValue = layoutBox.intrinsicWidth();
+        computedWidthValue = replaced->intrinsicWidth();
     } else {
         // #5
         computedWidthValue = 300;
index 3c6889a..978dfea 100644 (file)
@@ -145,7 +145,7 @@ void BlockFormattingContext::computeStaticPosition(LayoutContext& layoutContext,
 
 void BlockFormattingContext::computeInFlowWidth(LayoutContext& layoutContext, const Box& layoutBox, Display::Box& displayBox) const
 {
-    if (!layoutBox.isReplaced()) {
+    if (!layoutBox.replaced()) {
         computeInFlowNonReplacedWidth(layoutContext, layoutBox, displayBox);
         return;
     }
@@ -185,7 +185,7 @@ void BlockFormattingContext::computeInFlowNonReplacedWidth(LayoutContext& layout
 
 void BlockFormattingContext::computeInFlowHeight(LayoutContext& layoutContext, const Box& layoutBox, Display::Box& displayBox) const
 {
-    if (!layoutBox.isReplaced()) {
+    if (!layoutBox.replaced()) {
         computeInFlowNonReplacedHeight(layoutContext, layoutBox, displayBox);
         return;
     }
index 940f908..44797af 100644 (file)
@@ -179,12 +179,6 @@ bool Box::isInitialContainingBlock() const
     return !parent();
 }
 
-bool Box::isReplaced() const
-{
-    // HTMLAudioElement || HTMLCanvasElement || HTMLEmbedElement || HTMLIFrameElement || HTMLImageElement || HTMLInputElement || HTMLObjectElement || HTMLVideoElement
-    return false;
-}
-
 const Box* Box::nextInFlowSibling() const
 {
     if (auto* nextSibling = this->nextSibling()) {
@@ -230,39 +224,6 @@ bool Box::isOverflowVisible() const
     return m_style.overflowX() == OVISIBLE || m_style.overflowY() == OVISIBLE;
 }
 
-bool Box::hasIntrinsicWidth() const
-{
-    return false;
-}
-
-bool Box::hasIntrinsicHeight() const
-{
-    return false;
-}
-
-bool Box::hasIntrinsicRatio() const
-{
-    return false;
-}
-
-LayoutUnit Box::intrinsicWidth() const
-{
-    ASSERT(hasIntrinsicWidth());
-    return { };
-}
-
-LayoutUnit Box::intrinsicHeight() const
-{
-    ASSERT(hasIntrinsicHeight());
-    return { };
-}
-
-LayoutUnit Box::intrinsicRatio() const
-{
-    ASSERT(hasIntrinsicRatio());
-    return { };
-}
-
 }
 }
 
index 70437c9..10f60ab 100644 (file)
@@ -27,6 +27,7 @@
 
 #if ENABLE(LAYOUT_FORMATTING_CONTEXT)
 
+#include "LayoutReplaced.h"
 #include "RenderStyle.h"
 #include <wtf/IsoMalloc.h>
 #include <wtf/WeakPtr.h>
@@ -90,14 +91,7 @@ public:
     const RenderStyle& style() const { return m_style; }
     auto& weakPtrFactory() const { return m_weakFactory; }
 
-    bool isReplaced() const;
-    // FIXME: find out how to not pollute the Box interface
-    bool hasIntrinsicWidth() const;
-    bool hasIntrinsicHeight() const;
-    bool hasIntrinsicRatio() const;
-    LayoutUnit intrinsicWidth() const;
-    LayoutUnit intrinsicHeight() const;
-    LayoutUnit intrinsicRatio() const;
+    std::optional<const Replaced> replaced() const { return m_replaced; }
 
 protected:
     enum BaseTypeFlag {
@@ -123,6 +117,8 @@ private:
     Box* m_previousSibling { nullptr };
     Box* m_nextSibling { nullptr };
 
+    std::optional<const Replaced> m_replaced;
+
     unsigned m_baseTypeFlags : 4;
     unsigned m_isAnonymous : 1;
 
diff --git a/Source/WebCore/layout/layouttree/LayoutReplaced.cpp b/Source/WebCore/layout/layouttree/LayoutReplaced.cpp
new file mode 100644 (file)
index 0000000..b9ad103
--- /dev/null
@@ -0,0 +1,44 @@
+/*
+ * Copyright (C) 2018 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "config.h"
+#include "LayoutReplaced.h"
+
+#if ENABLE(LAYOUT_FORMATTING_CONTEXT)
+
+#include "LayoutBox.h"
+#include <wtf/IsoMallocInlines.h>
+
+namespace WebCore {
+namespace Layout {
+
+Replaced::Replaced(const LayoutBox&)
+{
+}
+
+}
+}
+
+#endif
diff --git a/Source/WebCore/layout/layouttree/LayoutReplaced.h b/Source/WebCore/layout/layouttree/LayoutReplaced.h
new file mode 100644 (file)
index 0000000..cfc18e6
--- /dev/null
@@ -0,0 +1,80 @@
+/*
+ * Copyright (C) 2018 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#pragma once
+
+#if ENABLE(LAYOUT_FORMATTING_CONTEXT)
+
+#include "LayoutUnit.h"
+#include <wtf/IsoMalloc.h>
+
+namespace WebCore {
+
+namespace Layout {
+class LayoutBox;
+
+// HTMLAudioElement, HTMLCanvasElement. HTMLEmbedElement, HTMLIFrameElement, HTMLImageElement, HTMLInputElement, HTMLObjectElement, HTMLVideoElement.
+class Replaced {
+    WTF_MAKE_ISO_ALLOCATED(Replaced);
+public:
+    friend class LayoutBox;
+
+    bool hasIntrinsicWidth() const { return m_intrinsicWidth.has_value(); }
+    bool hasIntrinsicHeight() const { return m_intrinsicHeight.has_value(); }
+    bool hasIntrinsicRatio() const { return m_intrinsicRatio.has_value(); }
+    LayoutUnit intrinsicWidth() const;
+    LayoutUnit intrinsicHeight() const;
+    LayoutUnit intrinsicRatio() const;
+
+private:
+    Replaced(const LayoutBox&);
+
+    std::optional<LayoutUnit> m_intrinsicWidth;
+    std::optional<LayoutUnit> m_intrinsicHeight;
+    std::optional<LayoutUnit> m_intrinsicRatio;
+};
+
+inline LayoutUnit Replaced::intrinsicWidth() const
+{
+    ASSERT(hasIntrinsicWidth());
+    return m_intrinsicWidth.value_or(LayoutUnit::max());
+}
+
+inline LayoutUnit Replaced::intrinsicHeight() const
+{
+    ASSERT(hasIntrinsicHeight());
+    return m_intrinsicHeight.value_or(LayoutUnit::max());
+}
+
+inline LayoutUnit Replaced::intrinsicRatio() const
+{
+    ASSERT(hasIntrinsicRatio());
+    return m_intrinsicRatio.value_or(LayoutUnit::max());
+}
+
+}
+}
+
+#endif