Title: [246540] trunk/Source/WebCore
Revision
246540
Author
za...@apple.com
Date
2019-06-18 09:04:54 -0700 (Tue, 18 Jun 2019)

Log Message

[LFC][IFC] Inline quirks should have their dedicated class.
https://bugs.webkit.org/show_bug.cgi?id=198962
<rdar://problem/51848170>

Reviewed by Antti Koivisto.

* Sources.txt:
* WebCore.xcodeproj/project.pbxproj:
* layout/LayoutState.h:
* layout/inlineformatting/InlineFormattingContext.h:
* layout/inlineformatting/InlineFormattingContextLineLayout.cpp:
(WebCore::Layout::InlineFormattingContext::LineLayout::createDisplayRuns const):
* layout/inlineformatting/InlineFormattingContextQuirks.cpp: Added.
(WebCore::Layout::InlineFormattingContext::Quirks::collapseLineDescent):
* layout/inlineformatting/InlineLine.cpp:
(WebCore::Layout::Line::close):
* layout/inlineformatting/InlineLineBreaker.cpp:
* layout/inlineformatting/InlineLineBreaker.h:

Modified Paths

Added Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (246539 => 246540)


--- trunk/Source/WebCore/ChangeLog	2019-06-18 15:23:47 UTC (rev 246539)
+++ trunk/Source/WebCore/ChangeLog	2019-06-18 16:04:54 UTC (rev 246540)
@@ -1,5 +1,26 @@
 2019-06-18  Zalan Bujtas  <za...@apple.com>
 
+        [LFC][IFC] Inline quirks should have their dedicated class.
+        https://bugs.webkit.org/show_bug.cgi?id=198962
+        <rdar://problem/51848170>
+
+        Reviewed by Antti Koivisto.
+
+        * Sources.txt:
+        * WebCore.xcodeproj/project.pbxproj:
+        * layout/LayoutState.h:
+        * layout/inlineformatting/InlineFormattingContext.h:
+        * layout/inlineformatting/InlineFormattingContextLineLayout.cpp:
+        (WebCore::Layout::InlineFormattingContext::LineLayout::createDisplayRuns const):
+        * layout/inlineformatting/InlineFormattingContextQuirks.cpp: Added.
+        (WebCore::Layout::InlineFormattingContext::Quirks::collapseLineDescent):
+        * layout/inlineformatting/InlineLine.cpp:
+        (WebCore::Layout::Line::close):
+        * layout/inlineformatting/InlineLineBreaker.cpp:
+        * layout/inlineformatting/InlineLineBreaker.h:
+
+2019-06-18  Zalan Bujtas  <za...@apple.com>
+
         [LFC][IFC] Line::append() should take care of all the inline types.
         https://bugs.webkit.org/show_bug.cgi?id=198961
         <rdar://problem/51847712>

Modified: trunk/Source/WebCore/Sources.txt (246539 => 246540)


--- trunk/Source/WebCore/Sources.txt	2019-06-18 15:23:47 UTC (rev 246539)
+++ trunk/Source/WebCore/Sources.txt	2019-06-18 16:04:54 UTC (rev 246540)
@@ -1351,6 +1351,7 @@
 layout/inlineformatting/InlineFormattingContext.cpp
 layout/inlineformatting/InlineFormattingContextGeometry.cpp
 layout/inlineformatting/InlineFormattingContextLineLayout.cpp
+layout/inlineformatting/InlineFormattingContextQuirks.cpp
 layout/inlineformatting/InlineFormattingState.cpp
 layout/inlineformatting/InlineInvalidation.cpp
 layout/inlineformatting/InlineLine.cpp

Modified: trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj (246539 => 246540)


--- trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj	2019-06-18 15:23:47 UTC (rev 246539)
+++ trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj	2019-06-18 16:04:54 UTC (rev 246540)
@@ -9144,6 +9144,7 @@
 		6F0830DF20B46951008A945B /* BlockFormattingContextGeometry.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = BlockFormattingContextGeometry.cpp; sourceTree = "<group>"; };
 		6F0CD692229ED31900C5994E /* InlineLine.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = InlineLine.cpp; sourceTree = "<group>"; };
 		6F0CD694229ED32700C5994E /* InlineLine.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = InlineLine.h; sourceTree = "<group>"; };
+		6F10B08622B8568D0090E69C /* InlineFormattingContextQuirks.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = InlineFormattingContextQuirks.cpp; sourceTree = "<group>"; };
 		6F1CC1DC225F8B4100720AD2 /* InlineTextItem.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = InlineTextItem.cpp; sourceTree = "<group>"; };
 		6F1CC1DD225F8B4200720AD2 /* InlineTextItem.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = InlineTextItem.h; sourceTree = "<group>"; };
 		6F222B741AB52D640094651A /* WebGLVertexArrayObjectBase.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = WebGLVertexArrayObjectBase.h; sourceTree = "<group>"; };
@@ -16402,6 +16403,7 @@
 				6F7CA3C8208C2B2E002F29AB /* InlineFormattingContext.h */,
 				6F35EFAF2187CBD50044E0F4 /* InlineFormattingContextGeometry.cpp */,
 				6F25B200220A85AB0000011B /* InlineFormattingContextLineLayout.cpp */,
+				6F10B08622B8568D0090E69C /* InlineFormattingContextQuirks.cpp */,
 				115CFA7D208B8E10001E6991 /* InlineFormattingState.cpp */,
 				115CFA7C208B8E10001E6991 /* InlineFormattingState.h */,
 				1123AFDD209ABBBA00736ACC /* InlineInvalidation.cpp */,

Modified: trunk/Source/WebCore/layout/LayoutState.h (246539 => 246540)


--- trunk/Source/WebCore/layout/LayoutState.h	2019-06-18 15:23:47 UTC (rev 246539)
+++ trunk/Source/WebCore/layout/LayoutState.h	2019-06-18 16:04:54 UTC (rev 246540)
@@ -31,6 +31,7 @@
 #include <wtf/HashSet.h>
 #include <wtf/IsoMalloc.h>
 #include <wtf/OptionSet.h>
+#include <wtf/WeakPtr.h>
 
 namespace WebCore {
 

Modified: trunk/Source/WebCore/layout/inlineformatting/InlineFormattingContext.h (246539 => 246540)


--- trunk/Source/WebCore/layout/inlineformatting/InlineFormattingContext.h	2019-06-18 15:23:47 UTC (rev 246539)
+++ trunk/Source/WebCore/layout/inlineformatting/InlineFormattingContext.h	2019-06-18 16:04:54 UTC (rev 246540)
@@ -95,6 +95,11 @@
         const Container& m_formattingRoot;
     };
 
+    class Quirks {
+    public:
+        static bool lineDescentNeedsCollapsing(const LayoutState&, const Line::Content&);
+    };
+
     class Geometry : public FormattingContext::Geometry {
     public:
         static HeightAndMargin inlineBlockHeightAndMargin(const LayoutState&, const Box&);
@@ -114,6 +119,8 @@
     void collectInlineContent() const;
 
     InlineFormattingState& formattingState() const { return downcast<InlineFormattingState>(FormattingContext::formattingState()); }
+    // FIXME: Come up with a structure that requires no friending.
+    friend class Line;
 };
 
 }

Modified: trunk/Source/WebCore/layout/inlineformatting/InlineFormattingContextLineLayout.cpp (246539 => 246540)


--- trunk/Source/WebCore/layout/inlineformatting/InlineFormattingContextLineLayout.cpp	2019-06-18 15:23:47 UTC (rev 246539)
+++ trunk/Source/WebCore/layout/inlineformatting/InlineFormattingContextLineLayout.cpp	2019-06-18 16:04:54 UTC (rev 246540)
@@ -310,8 +310,6 @@
     Optional<unsigned> previousLineLastRunIndex = inlineDisplayRuns.isEmpty() ? Optional<unsigned>() : inlineDisplayRuns.size() - 1;
     // 9.4.2 Inline formatting contexts
     // A line box is always tall enough for all of the boxes it contains.
-
-    // Ignore the initial strut.
     auto lineBoxRect = Display::Rect { lineContent.logicalTop(), lineContent.logicalLeft(), 0, lineContent.logicalHeight()};
     // Create final display runs.
     auto& lineRuns = lineContent.runs();

Added: trunk/Source/WebCore/layout/inlineformatting/InlineFormattingContextQuirks.cpp (0 => 246540)


--- trunk/Source/WebCore/layout/inlineformatting/InlineFormattingContextQuirks.cpp	                        (rev 0)
+++ trunk/Source/WebCore/layout/inlineformatting/InlineFormattingContextQuirks.cpp	2019-06-18 16:04:54 UTC (rev 246540)
@@ -0,0 +1,88 @@
+/*
+ * Copyright (C) 2019 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 "InlineFormattingContext.h"
+
+#if ENABLE(LAYOUT_FORMATTING_CONTEXT)
+
+#include "InlineItem.h"
+#include "InlineLine.h"
+#include "InlineTextItem.h"
+#include "LayoutState.h"
+
+namespace WebCore {
+namespace Layout {
+
+bool InlineFormattingContext::Quirks::lineDescentNeedsCollapsing(const LayoutState& layoutState, const Line::Content& lineContent)
+{
+    // Collapse line descent in limited and full quirk mode when there's no baseline aligned content or
+    // the baseline aligned content has no descent.
+    if (!layoutState.inQuirksMode() && !layoutState.inLimitedQuirksMode())
+        return false;
+
+    for (auto& run : lineContent.runs()) {
+        auto& inlineItem = run->inlineItem;
+        if (inlineItem.style().verticalAlign() != VerticalAlign::Baseline)
+            continue;
+
+        switch (inlineItem.type()) {
+        case InlineItem::Type::Text:
+            if (!run->isCollapsed)
+                return false;
+            break;
+        case InlineItem::Type::HardLineBreak:
+            return false;
+        case InlineItem::Type::ContainerStart: {
+            auto& displayBox = layoutState.displayBoxForLayoutBox(inlineItem.layoutBox());
+            if (displayBox.horizontalBorder() || (displayBox.horizontalPadding() && displayBox.horizontalPadding().value()))
+                return false;
+            break;
+        }
+        case InlineItem::Type::ContainerEnd:
+            break;
+        case InlineItem::Type::Box: {
+            auto& layoutBox = inlineItem.layoutBox();
+            if (layoutBox.isInlineBlockBox() && layoutBox.establishesInlineFormattingContext()) {
+                auto& formattingState = downcast<InlineFormattingState>(layoutState.establishedFormattingState(layoutBox));
+                ASSERT(!formattingState.lineBoxes().isEmpty());
+                auto inlineBlockBaseline = formattingState.lineBoxes().last().baseline();
+                if (inlineBlockBaseline.descent)
+                    return false;
+            }
+            break;
+        }
+        default:
+            ASSERT_NOT_REACHED();
+            break;
+        }
+    }
+    return true;
+}
+
+}
+}
+
+#endif

Modified: trunk/Source/WebCore/layout/inlineformatting/InlineLine.cpp (246539 => 246540)


--- trunk/Source/WebCore/layout/inlineformatting/InlineLine.cpp	2019-06-18 15:23:47 UTC (rev 246539)
+++ trunk/Source/WebCore/layout/inlineformatting/InlineLine.cpp	2019-06-18 16:04:54 UTC (rev 246540)
@@ -101,8 +101,12 @@
             m_contentLogicalHeight = { };
         }
 
-        auto hasDescent = false;
-        auto hasNonBaselineAlignedContent = false;
+        // Remove descent when all content is baseline aligned but none of them have descent.
+        if (InlineFormattingContext::Quirks::lineDescentNeedsCollapsing(m_layoutState, *m_content)) {
+            m_contentLogicalHeight -= m_baseline.descent;
+            m_baseline.descent = { };
+        }
+
         for (auto& run : m_content->runs()) {
             LayoutUnit logicalTop;
             auto& inlineItem = run->inlineItem;
@@ -112,13 +116,11 @@
 
             switch (verticalAlign) {
             case VerticalAlign::Baseline:
-                if (inlineItem.isLineBreak() || inlineItem.isText()) {
+                if (inlineItem.isLineBreak() || inlineItem.isText())
                     logicalTop = baselineOffset() - ascent;
-                    hasDescent = hasDescent || !run->isCollapsed;
-                } else if (inlineItem.isContainerStart()) {
+                else if (inlineItem.isContainerStart()) {
                     auto& displayBox = m_layoutState.displayBoxForLayoutBox(layoutBox);
                     logicalTop = baselineOffset() - ascent - displayBox.borderTop() - displayBox.paddingTop().valueOr(0);
-                    hasDescent = hasDescent || (displayBox.horizontalBorder() || (displayBox.horizontalPadding() && displayBox.horizontalPadding().value()));
                 } else if (layoutBox.isInlineBlockBox() && layoutBox.establishesInlineFormattingContext()) {
                     auto& formattingState = downcast<InlineFormattingState>(m_layoutState.establishedFormattingState(layoutBox));
                     // Spec makes us generate at least one line -even if it is empty.
@@ -125,7 +127,6 @@
                     ASSERT(!formattingState.lineBoxes().isEmpty());
                     auto inlineBlockBaseline = formattingState.lineBoxes().last().baseline();
                     logicalTop = baselineOffset() - inlineBlockBaseline.ascent;
-                    hasDescent = hasDescent || inlineBlockBaseline.descent;
                 } else
                     logicalTop = baselineOffset() - run->logicalRect.height();
                 break;
@@ -139,14 +140,8 @@
                 ASSERT_NOT_IMPLEMENTED_YET();
                 break;
             }
-            hasNonBaselineAlignedContent = hasNonBaselineAlignedContent || verticalAlign != VerticalAlign::Baseline;
             run->logicalRect.setTop(logicalTop);
         }
-        // Remove descent when all content is baseline aligned but none of them have descent.
-        if (!m_layoutState.inNoQuirksMode() && !hasNonBaselineAlignedContent && !hasDescent) {
-            m_contentLogicalHeight -= m_baseline.descent;
-            m_baseline.descent = { };
-        }
     }
     m_content->setLogicalRect({ logicalTop(), logicalLeft(), contentLogicalWidth(), logicalHeight() });
     m_content->setBaseline(m_baseline);

Modified: trunk/Source/WebCore/layout/inlineformatting/InlineLineBreaker.cpp (246539 => 246540)


--- trunk/Source/WebCore/layout/inlineformatting/InlineLineBreaker.cpp	2019-06-18 15:23:47 UTC (rev 246539)
+++ trunk/Source/WebCore/layout/inlineformatting/InlineLineBreaker.cpp	2019-06-18 16:04:54 UTC (rev 246540)
@@ -29,6 +29,8 @@
 #if ENABLE(LAYOUT_FORMATTING_CONTEXT)
 
 #include "Hyphenation.h"
+#include "InlineItem.h"
+#include "InlineTextItem.h"
 #include "LayoutState.h"
 
 namespace WebCore {

Modified: trunk/Source/WebCore/layout/inlineformatting/InlineLineBreaker.h (246539 => 246540)


--- trunk/Source/WebCore/layout/inlineformatting/InlineLineBreaker.h	2019-06-18 15:23:47 UTC (rev 246539)
+++ trunk/Source/WebCore/layout/inlineformatting/InlineLineBreaker.h	2019-06-18 16:04:54 UTC (rev 246540)
@@ -27,9 +27,12 @@
 
 #if ENABLE(LAYOUT_FORMATTING_CONTEXT)
 
+#include "LayoutUnit.h"
+
 namespace WebCore {
 namespace Layout {
 
+class InlineItem;
 class InlineTextItem;
 
 class LineBreaker {
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to