[LFC][IFC] Move detaching rules from InlineFormattingState to InlineItem
authorzalan@apple.com <zalan@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 20 Nov 2018 15:51:00 +0000 (15:51 +0000)
committerzalan@apple.com <zalan@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 20 Nov 2018 15:51:00 +0000 (15:51 +0000)
https://bugs.webkit.org/show_bug.cgi?id=191838

Reviewed by Antti Koivisto.

This is in preparation for adding more context to InlineItem. In addition to
detaching rules it will also hold non-breakable start/end information.

* layout/inlineformatting/InlineFormattingContext.cpp:
(WebCore::Layout::InlineFormattingContext::splitInlineRunIfNeeded const):
(WebCore::Layout::InlineFormattingContext::collectInlineContentForSubtree const):
* layout/inlineformatting/InlineFormattingState.cpp:
(WebCore::Layout::InlineFormattingState::addDetachingRule): Deleted.
(WebCore::Layout::InlineFormattingState::detachingRules const): Deleted.
* layout/inlineformatting/InlineFormattingState.h:
(WebCore::Layout::InlineFormattingState::setDetachingRules): Deleted.
* layout/inlineformatting/InlineItem.h:
(WebCore::Layout::InlineItem::addDetachingRule):
(WebCore::Layout::InlineItem::detachingRules const):

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

Source/WebCore/ChangeLog
Source/WebCore/layout/inlineformatting/InlineFormattingContext.cpp
Source/WebCore/layout/inlineformatting/InlineFormattingState.cpp
Source/WebCore/layout/inlineformatting/InlineFormattingState.h
Source/WebCore/layout/inlineformatting/InlineItem.h

index 679742b..48869eb 100644 (file)
@@ -1,3 +1,25 @@
+2018-11-20  Zalan Bujtas  <zalan@apple.com>
+
+        [LFC][IFC] Move detaching rules from InlineFormattingState to InlineItem
+        https://bugs.webkit.org/show_bug.cgi?id=191838
+
+        Reviewed by Antti Koivisto.
+
+        This is in preparation for adding more context to InlineItem. In addition to
+        detaching rules it will also hold non-breakable start/end information.
+
+        * layout/inlineformatting/InlineFormattingContext.cpp:
+        (WebCore::Layout::InlineFormattingContext::splitInlineRunIfNeeded const):
+        (WebCore::Layout::InlineFormattingContext::collectInlineContentForSubtree const):
+        * layout/inlineformatting/InlineFormattingState.cpp:
+        (WebCore::Layout::InlineFormattingState::addDetachingRule): Deleted.
+        (WebCore::Layout::InlineFormattingState::detachingRules const): Deleted.
+        * layout/inlineformatting/InlineFormattingState.h:
+        (WebCore::Layout::InlineFormattingState::setDetachingRules): Deleted.
+        * layout/inlineformatting/InlineItem.h:
+        (WebCore::Layout::InlineItem::addDetachingRule):
+        (WebCore::Layout::InlineItem::detachingRules const):
+
 2018-11-20  Zalan Bujjtas  <zalan@apple.com>
 
         [LFC][IFC] InlineRunProvider::append() should just take const InlineItem&.
index 5da48b6..75c3f45 100644 (file)
@@ -172,7 +172,7 @@ void InlineFormattingContext::splitInlineRunIfNeeded(const InlineRun& inlineRun,
         // 2. Break at the beginning of the inline element -> commit what we've got so far. Current element becomes the first uncommitted.
         // 3. Break at the end of the inline element -> commit what we've got so far including the current element.
         // 4. Break before/after -> requires dedicated run -> commit what we've got so far and also commit the current inline element as a separate inline run.
-        auto detachingRules = inlineFormattingState().detachingRules(inlineItem.layoutBox());
+        auto detachingRules = inlineItem.detachingRules();
 
         // #1
         if (detachingRules.isEmpty()) {
@@ -194,7 +194,7 @@ void InlineFormattingContext::splitInlineRunIfNeeded(const InlineRun& inlineRun,
         };
 
         // #2
-        if (detachingRules == InlineFormattingState::DetachingRule::BreakAtStart) {
+        if (detachingRules == InlineItem::DetachingRule::BreakAtStart) {
             commit();
             firstUncommittedInlineItem = &inlineItem;
             uncommittedLength = currentLength();
@@ -202,7 +202,7 @@ void InlineFormattingContext::splitInlineRunIfNeeded(const InlineRun& inlineRun,
         }
 
         // #3
-        if (detachingRules == InlineFormattingState::DetachingRule::BreakAtEnd) {
+        if (detachingRules == InlineItem::DetachingRule::BreakAtEnd) {
             ASSERT(firstUncommittedInlineItem);
             uncommittedLength += currentLength();
             commit();
@@ -460,8 +460,8 @@ void InlineFormattingContext::collectInlineContentForSubtree(const Box& root, In
 
     if (root.establishesFormattingContext() && &root != &(this->root())) {
         createAndAppendInlineItem();
+        inlineFormattingState.inlineContent().last()->addDetachingRule({ InlineItem::DetachingRule::BreakAtStart, InlineItem::DetachingRule::BreakAtEnd });
         // Skip formatting root subtree. They are not part of this inline formatting context.
-        inlineFormattingState.setDetachingRules(root, { InlineFormattingState::DetachingRule::BreakAtStart, InlineFormattingState::DetachingRule::BreakAtEnd });
         return;
     }
 
@@ -504,11 +504,11 @@ void InlineFormattingContext::collectInlineContentForSubtree(const Box& root, In
             firstDescendantInlineBox = inlineContent.first().get();
 
         ASSERT(firstDescendantInlineBox);
-        inlineFormattingState.addDetachingRule(firstDescendantInlineBox->layoutBox(), InlineFormattingState::DetachingRule::BreakAtStart);
+        firstDescendantInlineBox->addDetachingRule(InlineItem::DetachingRule::BreakAtStart);
     }
 
     if (rootBreaksAtEnd())
-        inlineFormattingState.addDetachingRule(lastDescendantInlineBox->layoutBox(), InlineFormattingState::DetachingRule::BreakAtEnd);
+        lastDescendantInlineBox->addDetachingRule(InlineItem::DetachingRule::BreakAtEnd);
 }
 
 void InlineFormattingContext::collectInlineContent(InlineRunProvider& inlineRunProvider) const
index 4144f93..92d71a4 100644 (file)
@@ -50,20 +50,6 @@ std::unique_ptr<FormattingContext> InlineFormattingState::formattingContext(cons
     return std::make_unique<InlineFormattingContext>(formattingContextRoot, *this);
 }
 
-void InlineFormattingState::addDetachingRule(const Box& layoutBox, DetachingRule detachingRule)
-{
-    m_detachingRules.add(&layoutBox, DetachingRule { }).iterator->value.add(detachingRule);
-}
-
-OptionSet<InlineFormattingState::DetachingRule> InlineFormattingState::detachingRules(const Box& layoutBox) const
-{
-    auto detachingRules = m_detachingRules.get(&layoutBox);
-    if (!detachingRules)
-        return { };
-
-    return detachingRules;
-}
-
 }
 }
 #endif
index 9d7c048..9bb901b 100644 (file)
@@ -48,43 +48,13 @@ public:
     InlineContent& inlineContent() { return m_inlineContent; }
     InlineItem* lastInlineItem() const { return m_inlineContent.isEmpty() ? nullptr : m_inlineContent.last().get(); }
 
-    // DetachingRule indicates whether the inline element needs to be wrapped in a dediceted run or break from previous/next runs.
-    // <span>start</span><span style="position: relative;"> middle </span><span>end</span>
-    // input to line breaking -> <start middle end>
-    // output of line breaking (considering infinite constraint) -> <start middle end>
-    // due to the in-flow positioning, the final runs are: <start>< middle ><end>
-    // "start" -> n/a
-    // " middle " -> BreakAtStart and BreakAtEnd
-    // "end" -> n/a
-    //
-    // <span>parent </span><span style="padding: 10px;">start<span> middle </span>end</span><span> parent</span>
-    // input to line breaking -> <parent start middle end parent>
-    // output of line breaking (considering infinite constraint) -> <parent start middle end parent>
-    // due to padding, final runs -> <parent><start middle end><parent>
-    // "parent" -> n/a
-    // "start" -> BreakAtStart
-    // " middle " -> n/a
-    // "end" -> BreakAtEnd
-    // "parent" -> n/a
-    enum class DetachingRule {
-        BreakAtStart = 1 << 0,
-        BreakAtEnd = 1 << 1
-    };
-    void addDetachingRule(const Box& layoutBox, DetachingRule);
-
-    OptionSet<DetachingRule> detachingRules(const Box& layoutBox) const;
-    void setDetachingRules(const Box& layoutBox, OptionSet<DetachingRule> detachingRules) { m_detachingRules.set(&layoutBox, detachingRules); }
-
     // Temp
     InlineRuns& inlineRuns() { return m_inlineRuns; }
     void appendInlineRun(InlineRun inlineRun) { m_inlineRuns.append(inlineRun); }
 
 private:
-    using DetachingRulesForInlineItems = HashMap<const Box*, OptionSet<DetachingRule>>;
-
     InlineContent m_inlineContent;
     InlineRuns m_inlineRuns;
-    DetachingRulesForInlineItems m_detachingRules;
 };
 
 }
index bfcb9c8..1d19b8c 100644 (file)
@@ -43,9 +43,34 @@ public:
     const Box& layoutBox() const { return m_layoutBox; }
     const RenderStyle& style() const { return m_layoutBox.style(); }
     String textContent() const;
+    // DetachingRule indicates whether the inline element needs to be wrapped in a dediceted run or break from previous/next runs.
+    // <span>start</span><span style="position: relative;"> middle </span><span>end</span>
+    // input to line breaking -> <start middle end>
+    // output of line breaking (considering infinite constraint) -> <start middle end>
+    // due to the in-flow positioning, the final runs are: <start>< middle ><end>
+    // "start" -> n/a
+    // " middle " -> BreakAtStart and BreakAtEnd
+    // "end" -> n/a
+    //
+    // <span>parent </span><span style="padding: 10px;">start<span> middle </span>end</span><span> parent</span>
+    // input to line breaking -> <parent start middle end parent>
+    // output of line breaking (considering infinite constraint) -> <parent start middle end parent>
+    // due to padding, final runs -> <parent><start middle end><parent>
+    // "parent" -> n/a
+    // "start" -> BreakAtStart
+    // " middle " -> n/a
+    // "end" -> BreakAtEnd
+    // "parent" -> n/a
+    enum class DetachingRule {
+        BreakAtStart = 1 << 0,
+        BreakAtEnd = 1 << 1
+    };
+    void addDetachingRule(OptionSet<DetachingRule> detachingRule) { m_detachingRules.add(detachingRule); }
+    OptionSet<DetachingRule> detachingRules() const { return m_detachingRules; }
 
 private:
     const Box& m_layoutBox;
+    OptionSet<DetachingRule> m_detachingRules;
 };
 
 // FIXME: Fix HashSet/ListHashSet to support smart pointer types.