Title: [287483] trunk/Source/WebCore
Revision
287483
Author
[email protected]
Date
2021-12-29 17:29:37 -0800 (Wed, 29 Dec 2021)

Log Message

[LFC][IFC] Add support for -webkit-rtl-ordering
https://bugs.webkit.org/show_bug.cgi?id=234715

Reviewed by Antti Koivisto.

"-webkit-rtl-ordering: visual" introduces EUnicodeBidi::Override on the block level
(apparently it has no effect on inline boxes).

* layout/formattingContexts/inline/InlineItemsBuilder.cpp:
(WebCore::Layout::handleEnterExitBidiContext):
(WebCore::Layout::buildBidiParagraph):
* layout/integration/LayoutIntegrationCoverage.cpp:
(WebCore::LayoutIntegration::printReason):
(WebCore::LayoutIntegration::canUseForStyle):
* layout/integration/LayoutIntegrationCoverage.h:

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (287482 => 287483)


--- trunk/Source/WebCore/ChangeLog	2021-12-29 21:07:10 UTC (rev 287482)
+++ trunk/Source/WebCore/ChangeLog	2021-12-30 01:29:37 UTC (rev 287483)
@@ -1,5 +1,23 @@
 2021-12-29  Alan Bujtas  <[email protected]>
 
+        [LFC][IFC] Add support for -webkit-rtl-ordering
+        https://bugs.webkit.org/show_bug.cgi?id=234715
+
+        Reviewed by Antti Koivisto.
+
+        "-webkit-rtl-ordering: visual" introduces EUnicodeBidi::Override on the block level
+        (apparently it has no effect on inline boxes).
+
+        * layout/formattingContexts/inline/InlineItemsBuilder.cpp:
+        (WebCore::Layout::handleEnterExitBidiContext):
+        (WebCore::Layout::buildBidiParagraph):
+        * layout/integration/LayoutIntegrationCoverage.cpp:
+        (WebCore::LayoutIntegration::printReason):
+        (WebCore::LayoutIntegration::canUseForStyle):
+        * layout/integration/LayoutIntegrationCoverage.h:
+
+2021-12-29  Alan Bujtas  <[email protected]>
+
         [LFC][IFC] Collapsed trailing whitespace may introduce stray inline box
         https://bugs.webkit.org/show_bug.cgi?id=234735
 

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


--- trunk/Source/WebCore/layout/formattingContexts/inline/InlineItemsBuilder.cpp	2021-12-29 21:07:10 UTC (rev 287482)
+++ trunk/Source/WebCore/layout/formattingContexts/inline/InlineItemsBuilder.cpp	2021-12-30 01:29:37 UTC (rev 287483)
@@ -174,10 +174,19 @@
 struct BidiContext {
     EUnicodeBidi unicodeBidi;
     bool isLeftToRightDirection { false };
+    bool isBlockLevel { false };
 };
 using BidiContextStack = Vector<BidiContext>;
-static inline void handleEnterExitBidiContext(StringBuilder& paragraphContentBuilder, EUnicodeBidi unicodeBidi, bool isLTR, bool isEnteringBidi, BidiContextStack& bidiContextStack)
+
+enum class EnterExitType : uint8_t {
+    EnteringBlock,
+    ExitingBlock,
+    EnteringInlineBox,
+    ExitingInlineBox
+};
+static inline void handleEnterExitBidiContext(StringBuilder& paragraphContentBuilder, EUnicodeBidi unicodeBidi, bool isLTR, EnterExitType enterExitType, BidiContextStack& bidiContextStack)
 {
+    auto isEnteringBidi = enterExitType == EnterExitType::EnteringBlock || enterExitType == EnterExitType::EnteringInlineBox;
     switch (unicodeBidi) {
     case EUnicodeBidi::UBNormal:
         // The box does not open an additional level of embedding with respect to the bidirectional algorithm.
@@ -208,7 +217,7 @@
         ASSERT_NOT_REACHED();
     }
 
-    isEnteringBidi ? bidiContextStack.append({ unicodeBidi, isLTR }) : bidiContextStack.removeLast();
+    isEnteringBidi ? bidiContextStack.append({ unicodeBidi, isLTR, enterExitType == EnterExitType::EnteringBlock }) : bidiContextStack.removeLast();
 }
 
 using InlineItemOffsetList = Vector<std::optional<size_t>>;
@@ -215,7 +224,9 @@
 static inline void buildBidiParagraph(const RenderStyle& rootStyle, const InlineItems& inlineItems,  StringBuilder& paragraphContentBuilder, InlineItemOffsetList& inlineItemOffsetList)
 {
     auto bidiContextStack = BidiContextStack { };
-    handleEnterExitBidiContext(paragraphContentBuilder, rootStyle.unicodeBidi(), rootStyle.isLeftToRightDirection(), true, bidiContextStack);
+    handleEnterExitBidiContext(paragraphContentBuilder, rootStyle.unicodeBidi(), rootStyle.isLeftToRightDirection(), EnterExitType::EnteringBlock, bidiContextStack);
+    if (rootStyle.rtlOrdering() != Order::Logical)
+        handleEnterExitBidiContext(paragraphContentBuilder, EUnicodeBidi::Override, rootStyle.isLeftToRightDirection(), EnterExitType::EnteringBlock, bidiContextStack);
 
     const Box* lastInlineTextBox = nullptr;
     size_t inlineTextBoxOffset = 0;
@@ -249,7 +260,12 @@
             }
             inlineItemOffsetList.uncheckedAppend({ paragraphContentBuilder.length() });
             auto isEnteringBidi = inlineItem.isInlineBoxStart();
-            handleEnterExitBidiContext(paragraphContentBuilder, style.unicodeBidi(), style.isLeftToRightDirection(), isEnteringBidi, bidiContextStack);
+            handleEnterExitBidiContext(paragraphContentBuilder
+                , style.unicodeBidi()
+                , style.isLeftToRightDirection()
+                , isEnteringBidi ? EnterExitType::EnteringInlineBox : EnterExitType::ExitingInlineBox
+                , bidiContextStack
+            );
         } else if (inlineItem.isSoftLineBreak()) {
             // FIXME: Unwind the bidi stack for soft line break too.
             appendTextBasedContent();
@@ -257,10 +273,21 @@
         } else if (inlineItem.isHardLineBreak()) {
             auto copyOfBidiStack = bidiContextStack;
 
+            size_t blockLevelBidiContextIndex = 0;
             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);
+                ASSERT(!bidiContextStack.isEmpty());
+                size_t unwindingIndex = copyOfBidiStack.size() - 1; 
+                while (unwindingIndex && !copyOfBidiStack[unwindingIndex].isBlockLevel) {
+                    handleEnterExitBidiContext(paragraphContentBuilder
+                        , copyOfBidiStack[unwindingIndex].unicodeBidi
+                        , copyOfBidiStack[unwindingIndex].isLeftToRightDirection
+                        , EnterExitType::ExitingInlineBox
+                        , bidiContextStack
+                    );
+                    --unwindingIndex;
+                }
+                blockLevelBidiContextIndex = unwindingIndex; 
             };
             unwindBidiContextStack();
 
@@ -268,8 +295,14 @@
             paragraphContentBuilder.append(newlineCharacter);
 
             auto rewindBidiContextStack = [&] {
-                for (size_t index = 1; index < copyOfBidiStack.size(); ++index)
-                    handleEnterExitBidiContext(paragraphContentBuilder, copyOfBidiStack[index].unicodeBidi, copyOfBidiStack[index].isLeftToRightDirection, true, bidiContextStack);
+                for (size_t index = blockLevelBidiContextIndex + 1; index < copyOfBidiStack.size(); ++index) {
+                    handleEnterExitBidiContext(paragraphContentBuilder
+                        , copyOfBidiStack[index].unicodeBidi
+                        , copyOfBidiStack[index].isLeftToRightDirection
+                        , EnterExitType::EnteringInlineBox
+                        , bidiContextStack
+                    );
+                }
             };
             rewindBidiContextStack();
         } else if (inlineItem.isWordBreakOpportunity()) {

Modified: trunk/Source/WebCore/layout/integration/LayoutIntegrationCoverage.cpp (287482 => 287483)


--- trunk/Source/WebCore/layout/integration/LayoutIntegrationCoverage.cpp	2021-12-29 21:07:10 UTC (rev 287482)
+++ trunk/Source/WebCore/layout/integration/LayoutIntegrationCoverage.cpp	2021-12-30 01:29:37 UTC (rev 287483)
@@ -125,9 +125,6 @@
     case AvoidanceReason::FlowIsNotTopToBottom:
         stream << "non top-to-bottom flow";
         break;
-    case AvoidanceReason::FlowHasRTLOrdering:
-        stream << "-webkit-rtl-ordering";
-        break;
     case AvoidanceReason::FlowHasLineAlignEdges:
         stream << "-webkit-line-align edges";
         break;
@@ -438,8 +435,6 @@
         SET_REASON_AND_RETURN_IF_NEEDED(FlowMayNotBeLTR, reasons, includeReasons);
     if (style.writingMode() != WritingMode::TopToBottom)
         SET_REASON_AND_RETURN_IF_NEEDED(FlowIsNotTopToBottom, reasons, includeReasons);
-    if (style.rtlOrdering() != Order::Logical)
-        SET_REASON_AND_RETURN_IF_NEEDED(FlowHasRTLOrdering, reasons, includeReasons);
     if (style.textEmphasisFill() != TextEmphasisFill::Filled || style.textEmphasisMark() != TextEmphasisMark::None)
         SET_REASON_AND_RETURN_IF_NEEDED(FlowHasTextEmphasisFillOrMark, reasons, includeReasons);
     if (style.hasPseudoStyle(PseudoId::FirstLetter))

Modified: trunk/Source/WebCore/layout/integration/LayoutIntegrationCoverage.h (287482 => 287483)


--- trunk/Source/WebCore/layout/integration/LayoutIntegrationCoverage.h	2021-12-29 21:07:10 UTC (rev 287482)
+++ trunk/Source/WebCore/layout/integration/LayoutIntegrationCoverage.h	2021-12-30 01:29:37 UTC (rev 287483)
@@ -57,7 +57,7 @@
     FlowHasLineBoxContainProperty                = 1LLU  << 16,
     FlowIsNotTopToBottom                         = 1LLU  << 17,
     // Unused                                    = 1LLU  << 18,
-    FlowHasRTLOrdering                           = 1LLU  << 19,
+    // Unused                                    = 1LLU  << 19,
     FlowHasLineAlignEdges                        = 1LLU  << 20,
     FlowHasLineSnap                              = 1LLU  << 21,
     FlowHasTextEmphasisFillOrMark                = 1LLU  << 22,
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to