Title: [251857] trunk/Source/WebCore
Revision
251857
Author
[email protected]
Date
2019-10-31 10:37:56 -0700 (Thu, 31 Oct 2019)

Log Message

[LFC][IFC] Add expansion context to Line::Run
https://bugs.webkit.org/show_bug.cgi?id=203683
<rdar://problem/56785012>

Reviewed by Antti Koivisto.

This is in preparation for adding text-align: justify support.
The temporary Line::Run holds the number of expansion opportunities, while Display::Run holds both the expansion behavior and
the final expansion width.
The number of opportunities is used to compute the final expansion width for each run.

* layout/displaytree/DisplayPainter.cpp:
(WebCore::Display::paintInlineContent):
* layout/displaytree/DisplayRun.h:
(WebCore::Display::Run::TextContext::TextContext):
(WebCore::Display::Run::TextContext::setExpansion):
(WebCore::Display::Run::TextContext::expansion const):
(WebCore::Display::Run::TextContext::expansionBehavior const): Deleted.
* layout/inlineformatting/InlineLine.h:
(WebCore::Layout::Line::Run::hasExpansionOpportunity const):
(WebCore::Layout::Line::Run::expansionOpportunityCount const):
(WebCore::Layout::Line::Run::expansionBehavior const):
(WebCore::Layout::Line::Run::setHasExpansionOpportunity):
(WebCore::Layout::Line::Run::setComputedHorizontalExpansion):

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (251856 => 251857)


--- trunk/Source/WebCore/ChangeLog	2019-10-31 17:35:06 UTC (rev 251856)
+++ trunk/Source/WebCore/ChangeLog	2019-10-31 17:37:56 UTC (rev 251857)
@@ -1,5 +1,32 @@
 2019-10-31  Zalan Bujtas  <[email protected]>
 
+        [LFC][IFC] Add expansion context to Line::Run
+        https://bugs.webkit.org/show_bug.cgi?id=203683
+        <rdar://problem/56785012>
+
+        Reviewed by Antti Koivisto.
+
+        This is in preparation for adding text-align: justify support.
+        The temporary Line::Run holds the number of expansion opportunities, while Display::Run holds both the expansion behavior and
+        the final expansion width.
+        The number of opportunities is used to compute the final expansion width for each run.
+
+        * layout/displaytree/DisplayPainter.cpp:
+        (WebCore::Display::paintInlineContent):
+        * layout/displaytree/DisplayRun.h:
+        (WebCore::Display::Run::TextContext::TextContext):
+        (WebCore::Display::Run::TextContext::setExpansion):
+        (WebCore::Display::Run::TextContext::expansion const):
+        (WebCore::Display::Run::TextContext::expansionBehavior const): Deleted.
+        * layout/inlineformatting/InlineLine.h:
+        (WebCore::Layout::Line::Run::hasExpansionOpportunity const):
+        (WebCore::Layout::Line::Run::expansionOpportunityCount const):
+        (WebCore::Layout::Line::Run::expansionBehavior const):
+        (WebCore::Layout::Line::Run::setHasExpansionOpportunity):
+        (WebCore::Layout::Line::Run::setComputedHorizontalExpansion):
+
+2019-10-31  Zalan Bujtas  <[email protected]>
+
         [LFC][IFC] Line::Run should not hold a reference to InlineItem
         https://bugs.webkit.org/show_bug.cgi?id=203660
         <rdar://problem/56770286>

Modified: trunk/Source/WebCore/layout/displaytree/DisplayPainter.cpp (251856 => 251857)


--- trunk/Source/WebCore/layout/displaytree/DisplayPainter.cpp	2019-10-31 17:35:06 UTC (rev 251856)
+++ trunk/Source/WebCore/layout/displaytree/DisplayPainter.cpp	2019-10-31 17:37:56 UTC (rev 251857)
@@ -126,9 +126,10 @@
             // FIXME: Add non-baseline align painting
             auto& lineBox = formattingState.lineBoxForRun(*run);
             auto baselineOffset = rootAbsoluteDisplayBox.top() + lineBox.logicalTop() + lineBox.baselineOffset();
-            context.drawText(style.fontCascade(),
-                TextRun { textContext->content(), logicalLeft, textContext->expansion().valueOr(0), textContext->expansionBehavior().valueOr(ForbidLeadingExpansion | ForbidTrailingExpansion)},
-                { logicalLeft, baselineOffset });
+            if (auto expansionContext = textContext->expansion())
+                context.drawText(style.fontCascade(), TextRun { textContext->content(), logicalLeft, expansionContext->horiztontalExpansion, expansionContext->behavior }, { logicalLeft, baselineOffset });
+            else
+                context.drawText(style.fontCascade(), TextRun { textContext->content(), logicalLeft }, { logicalLeft, baselineOffset });
         } else if (auto* cachedImage = run->image()) {
             auto runAbsoluteRect = FloatRect { rootAbsoluteDisplayBox.left() + run->logicalLeft(), rootAbsoluteDisplayBox.top() + run->logicalTop(), run->logicalWidth(), run->logicalHeight() };
             context.drawImage(*cachedImage->image(), runAbsoluteRect);

Modified: trunk/Source/WebCore/layout/displaytree/DisplayRun.h (251856 => 251857)


--- trunk/Source/WebCore/layout/displaytree/DisplayRun.h	2019-10-31 17:35:06 UTC (rev 251856)
+++ trunk/Source/WebCore/layout/displaytree/DisplayRun.h	2019-10-31 17:37:56 UTC (rev 251857)
@@ -43,7 +43,8 @@
     struct TextContext {
         WTF_MAKE_STRUCT_FAST_ALLOCATED;
     public:
-        TextContext(unsigned position, unsigned length, String content, Optional<ExpansionBehavior> = { }, Optional<LayoutUnit> expansion = { });
+        struct ExpansionContext;
+        TextContext(unsigned position, unsigned length, String content, Optional<ExpansionContext> = { });
 
         unsigned start() const { return m_start; }
         unsigned end() const { return start() + length(); }
@@ -50,8 +51,12 @@
         unsigned length() const { return m_length; }
         String content() const { return m_content; }
 
-        Optional<ExpansionBehavior> expansionBehavior() const { return m_expansionBehavior; }
-        Optional<LayoutUnit> expansion() const { return m_expansion; }
+        struct ExpansionContext {
+            ExpansionBehavior behavior;
+            LayoutUnit horiztontalExpansion;
+        };
+        void setExpansion(ExpansionContext expansionContext) { m_expansionContext = expansionContext; }
+        Optional<ExpansionContext> expansion() const { return m_expansionContext; }
 
         void expand(const TextContext& other);
 
@@ -58,8 +63,7 @@
     private:
         unsigned m_start { 0 };
         unsigned m_length { 0 };
-        Optional<ExpansionBehavior> m_expansionBehavior;
-        Optional<LayoutUnit> m_expansion;
+        Optional<ExpansionContext> m_expansionContext;
         // FIXME: This is temporary. We should have some mapping setup to identify associated text content instead.
         String m_content;
     };
@@ -110,11 +114,10 @@
 {
 }
 
-inline Run::TextContext::TextContext(unsigned start, unsigned length, String content, Optional<ExpansionBehavior> expansionBehavior, Optional<LayoutUnit> expansion)
+inline Run::TextContext::TextContext(unsigned start, unsigned length, String content, Optional<ExpansionContext> expansionContext)
     : m_start(start)
     , m_length(length)
-    , m_expansionBehavior(expansionBehavior)
-    , m_expansion(expansion)
+    , m_expansionContext(expansionContext)
     , m_content(content)
 {
 }

Modified: trunk/Source/WebCore/layout/inlineformatting/InlineLine.h (251856 => 251857)


--- trunk/Source/WebCore/layout/inlineformatting/InlineLine.h	2019-10-31 17:35:06 UTC (rev 251856)
+++ trunk/Source/WebCore/layout/inlineformatting/InlineLine.h	2019-10-31 17:37:56 UTC (rev 251857)
@@ -93,6 +93,12 @@
         void setIsCollapsed();
         void setCollapsesToZeroAdvanceWidth();
 
+        void setHasExpansionOpportunity(ExpansionBehavior);
+        bool hasExpansionOpportunity() const { return m_expansionOpportunityCount.hasValue(); }
+        Optional<ExpansionBehavior> expansionBehavior() const;
+        Optional<unsigned> expansionOpportunityCount() const { return m_expansionOpportunityCount; }
+        void setComputedHorizontalExpansion(LayoutUnit logicalExpansion);
+
         bool isCollapsible() const { return m_isCollapsible; }
         bool hasTrailingCollapsedContent() const { return m_hasTrailingCollapsedContent; }
         bool isWhitespace() const { return m_isWhitespace; }
@@ -105,6 +111,7 @@
         bool m_isCollapsed { false };
         bool m_collapsedToZeroAdvanceWidth { false };
         bool m_hasTrailingCollapsedContent { false };
+        Optional<unsigned> m_expansionOpportunityCount;
     };
     using RunList = Vector<std::unique_ptr<Run>>;
     RunList close();
@@ -190,6 +197,31 @@
     m_displayRun.setLogicalWidth({ });
 }
 
+inline Optional<ExpansionBehavior> Line::Run::expansionBehavior() const
+{
+    ASSERT(isText());
+    if (auto expansionContext = m_displayRun.textContext()->expansion())
+        return expansionContext->behavior;
+    return { };
 }
+
+inline void Line::Run::setHasExpansionOpportunity(ExpansionBehavior expansionBehavior)
+{
+    ASSERT(isText());
+    ASSERT(!hasExpansionOpportunity());
+    m_expansionOpportunityCount = 1;
+    m_displayRun.textContext()->setExpansion({ expansionBehavior, { } });
 }
+
+inline void Line::Run::setComputedHorizontalExpansion(LayoutUnit logicalExpansion)
+{
+    ASSERT(isText());
+    ASSERT(hasExpansionOpportunity());
+    ASSERT(m_displayRun.textContext()->expansion());
+    m_displayRun.expandHorizontally(logicalExpansion);
+    m_displayRun.textContext()->setExpansion({ m_displayRun.textContext()->expansion()->behavior, logicalExpansion });
+}
+
+}
+}
 #endif
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to