Title: [287375] trunk/Source/WebCore
Revision
287375
Author
[email protected]
Date
2021-12-22 15:34:30 -0800 (Wed, 22 Dec 2021)

Log Message

[LFC][IFC] Close/open nested bidi contexts for new lines after force line breaks
https://bugs.webkit.org/show_bug.cgi?id=234611

Reviewed by Antti Koivisto.

Bidi handling requires us to close all the nested bidi contexts at the end of the line (triggered by forced line breaks)
and re-open it for the content on the next line.

* layout/formattingContexts/inline/InlineItemsBuilder.cpp:
(WebCore::Layout::handleEnterExitBidiContext):
(WebCore::Layout::buildBidiParagraph):

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (287374 => 287375)


--- trunk/Source/WebCore/ChangeLog	2021-12-22 23:16:14 UTC (rev 287374)
+++ trunk/Source/WebCore/ChangeLog	2021-12-22 23:34:30 UTC (rev 287375)
@@ -1,5 +1,19 @@
 2021-12-22  Alan Bujtas  <[email protected]>
 
+        [LFC][IFC] Close/open nested bidi contexts for new lines after force line breaks
+        https://bugs.webkit.org/show_bug.cgi?id=234611
+
+        Reviewed by Antti Koivisto.
+
+        Bidi handling requires us to close all the nested bidi contexts at the end of the line (triggered by forced line breaks)
+        and re-open it for the content on the next line. 
+
+        * layout/formattingContexts/inline/InlineItemsBuilder.cpp:
+        (WebCore::Layout::handleEnterExitBidiContext):
+        (WebCore::Layout::buildBidiParagraph):
+
+2021-12-22  Alan Bujtas  <[email protected]>
+
         [LFC][IFC] Soft linebreaks have incorrect bidi paragraph positions
         https://bugs.webkit.org/show_bug.cgi?id=234608
 

Modified: trunk/Source/WebCore/layout/formattingContexts/inline/InlineItemsBuilder.cpp (287374 => 287375)


--- trunk/Source/WebCore/layout/formattingContexts/inline/InlineItemsBuilder.cpp	2021-12-22 23:16:14 UTC (rev 287374)
+++ trunk/Source/WebCore/layout/formattingContexts/inline/InlineItemsBuilder.cpp	2021-12-22 23:34:30 UTC (rev 287375)
@@ -171,7 +171,12 @@
         paragraphContentBuilder.append(textContent.right(contentLength - nonReplacedContentStartPosition));
 }
 
-static inline void handleEnterExitBidiContext(StringBuilder& paragraphContentBuilder, EUnicodeBidi unicodeBidi, bool isLTR, bool isEnteringBidi)
+struct BidiContext {
+    EUnicodeBidi unicodeBidi;
+    bool isLeftToRightDirection { false };
+};
+using BidiContextStack = Vector<BidiContext>;
+static inline void handleEnterExitBidiContext(StringBuilder& paragraphContentBuilder, EUnicodeBidi unicodeBidi, bool isLTR, bool isEnteringBidi, BidiContextStack& bidiContextStack)
 {
     switch (unicodeBidi) {
     case EUnicodeBidi::UBNormal:
@@ -202,12 +207,15 @@
     default:
         ASSERT_NOT_REACHED();
     }
+
+    isEnteringBidi ? bidiContextStack.append({ unicodeBidi, isLTR }) : bidiContextStack.removeLast();
 }
 
 using InlineItemOffsetList = Vector<std::optional<size_t>>;
 static inline void buildBidiParagraph(const RenderStyle& rootStyle, const InlineItems& inlineItems,  StringBuilder& paragraphContentBuilder, InlineItemOffsetList& inlineItemOffsetList)
 {
-    handleEnterExitBidiContext(paragraphContentBuilder, rootStyle.unicodeBidi(), rootStyle.isLeftToRightDirection(), true);
+    auto bidiContextStack = BidiContextStack { };
+    handleEnterExitBidiContext(paragraphContentBuilder, rootStyle.unicodeBidi(), rootStyle.isLeftToRightDirection(), true, bidiContextStack);
 
     const Box* lastInlineTextBox = nullptr;
     size_t inlineTextBoxOffset = 0;
@@ -242,13 +250,29 @@
             }
             inlineItemOffsetList.uncheckedAppend({ paragraphContentBuilder.length() });
             auto isEnteringBidi = inlineItem.isInlineBoxStart();
-            handleEnterExitBidiContext(paragraphContentBuilder, style.unicodeBidi(), style.isLeftToRightDirection(), isEnteringBidi);
+            handleEnterExitBidiContext(paragraphContentBuilder, style.unicodeBidi(), style.isLeftToRightDirection(), isEnteringBidi, bidiContextStack);
         } else if (inlineItem.isSoftLineBreak()) {
+            // FIXME: Unwind the bidi stack for soft line break too.
             appendTextBasedContent();
             inlineItemOffsetList.uncheckedAppend({ inlineTextBoxOffset + downcast<InlineSoftLineBreakItem>(inlineItem).position() });
         } else if (inlineItem.isHardLineBreak()) {
+            auto copyOfBidiStack = bidiContextStack;
+
+            auto unwindBidiContextStack = [&] {
+                // Unwind all the way up to the block entry.
+                for (size_t index = copyOfBidiStack.size(); index-- > 1;)
+                    handleEnterExitBidiContext(paragraphContentBuilder, copyOfBidiStack[index].unicodeBidi, copyOfBidiStack[index].isLeftToRightDirection, false, bidiContextStack);
+            };
+            unwindBidiContextStack();
+
             inlineItemOffsetList.uncheckedAppend({ paragraphContentBuilder.length() });
             paragraphContentBuilder.append(newlineCharacter);
+
+            auto rewindBidiContextStack = [&] {
+                for (size_t index = 1; index < copyOfBidiStack.size(); ++index)
+                    handleEnterExitBidiContext(paragraphContentBuilder, copyOfBidiStack[index].unicodeBidi, copyOfBidiStack[index].isLeftToRightDirection, true, bidiContextStack);
+            };
+            rewindBidiContextStack();
         } else if (inlineItem.isWordBreakOpportunity()) {
             // Soft wrap opportunity markers are opaque to bidi. 
             inlineItemOffsetList.uncheckedAppend({ });            
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to