[LFC][IFC] Use start-aligned horizontal adjustment when justify is not eligible.
authorzalan@apple.com <zalan@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sat, 7 Mar 2020 17:52:14 +0000 (17:52 +0000)
committerzalan@apple.com <zalan@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sat, 7 Mar 2020 17:52:14 +0000 (17:52 +0000)
https://bugs.webkit.org/show_bug.cgi?id=208762
<rdar://problem/60188433>

Reviewed by Antti Koivisto.

Make sure we apply "text-align: start" when "text-align: justify" is not eligible.
Currently "text-align: start" is a no-op, so no chnange in functionality (this might change in the future).

* layout/inlineformatting/InlineLineBuilder.cpp:
(WebCore::Layout::LineBuilder::alignHorizontally):
(WebCore::Layout::LineBuilder::removeTrailingTrimmableContent):
* layout/inlineformatting/InlineLineBuilder.h:
(WebCore::Layout::LineBuilder::isTextAlignJustify const): Deleted.
(WebCore::Layout::LineBuilder::isTextAlignRight const): Deleted.

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

Source/WebCore/ChangeLog
Source/WebCore/layout/inlineformatting/InlineLineBuilder.cpp
Source/WebCore/layout/inlineformatting/InlineLineBuilder.h

index 96defc4..f435c95 100644 (file)
@@ -1,5 +1,23 @@
 2020-03-07  Zalan Bujtas  <zalan@apple.com>
 
+        [LFC][IFC] Use start-aligned horizontal adjustment when justify is not eligible.
+        https://bugs.webkit.org/show_bug.cgi?id=208762
+        <rdar://problem/60188433>
+
+        Reviewed by Antti Koivisto.
+
+        Make sure we apply "text-align: start" when "text-align: justify" is not eligible.
+        Currently "text-align: start" is a no-op, so no chnange in functionality (this might change in the future).
+
+        * layout/inlineformatting/InlineLineBuilder.cpp:
+        (WebCore::Layout::LineBuilder::alignHorizontally):
+        (WebCore::Layout::LineBuilder::removeTrailingTrimmableContent):
+        * layout/inlineformatting/InlineLineBuilder.h:
+        (WebCore::Layout::LineBuilder::isTextAlignJustify const): Deleted.
+        (WebCore::Layout::LineBuilder::isTextAlignRight const): Deleted.
+
+2020-03-07  Zalan Bujtas  <zalan@apple.com>
+
         [LFC][IFC] Do not text-align: justify the runs on the current line if they are followed by a forced break
         https://bugs.webkit.org/show_bug.cgi?id=208761
         <rdar://problem/59825136>
index 76017c2..7aec317 100644 (file)
@@ -236,20 +236,30 @@ void LineBuilder::justifyRuns(InlineLayoutUnit availableWidth)
 void LineBuilder::alignHorizontally(const HangingContent& hangingContent, IsLastLineWithInlineContent isLastLine)
 {
     ASSERT(!m_isIntrinsicSizing);
+
     auto availableWidth = this->availableWidth() + hangingContent.width();
     if (m_runs.isEmpty() || availableWidth <= 0)
         return;
 
-    if (isTextAlignJustify()) {
-        // Unless otherwise specified by text-align-last, the last line before a forced break or
-        // the end of the block is start-aligned.
-        if (!m_runs.last().isLineBreak() && isLastLine == IsLastLineWithInlineContent::No)
-            justifyRuns(availableWidth);
+    auto computedHorizontalAlignment = [&] {
+        ASSERT(m_horizontalAlignment);
+        if (m_horizontalAlignment != TextAlignMode::Justify)
+            return *m_horizontalAlignment;
+        // Text is justified according to the method specified by the text-justify property,
+        // in order to exactly fill the line box. Unless otherwise specified by text-align-last,
+        // the last line before a forced break or the end of the block is start-aligned.
+        if (m_runs.last().isLineBreak() || isLastLine == IsLastLineWithInlineContent::Yes)
+            return TextAlignMode::Start;
+        return TextAlignMode::Justify;
+    }();
+
+    if (computedHorizontalAlignment == TextAlignMode::Justify) {
+        justifyRuns(availableWidth);
         return;
     }
 
-    auto adjustmentForAlignment = [&]() -> Optional<InlineLayoutUnit> {
-        switch (*m_horizontalAlignment) {
+    auto adjustmentForAlignment = [] (auto horizontalAlignment, auto availableWidth) -> Optional<InlineLayoutUnit> {
+        switch (horizontalAlignment) {
         case TextAlignMode::Left:
         case TextAlignMode::WebKitLeft:
         case TextAlignMode::Start:
@@ -269,7 +279,7 @@ void LineBuilder::alignHorizontally(const HangingContent& hangingContent, IsLast
         return { };
     };
 
-    auto adjustment = adjustmentForAlignment();
+    auto adjustment = adjustmentForAlignment(computedHorizontalAlignment, availableWidth);
     if (!adjustment)
         return;
     // Horizontal alignment means that we not only adjust the runs but also make sure
@@ -288,7 +298,14 @@ void LineBuilder::removeTrailingTrimmableContent()
 
     // Complex line layout quirk: keep the trailing whitespace around when it is followed by a line break, unless the content overflows the line.
     if (RuntimeEnabledFeatures::sharedFeatures().layoutFormattingContextIntegrationEnabled()) {
-        if (m_runs.last().isLineBreak() && availableWidth() >= 0 && !isTextAlignRight()) {
+        auto isTextAlignRight = [&] {
+            ASSERT(m_horizontalAlignment);
+            return m_horizontalAlignment == TextAlignMode::Right
+                || m_horizontalAlignment == TextAlignMode::WebKitRight
+                || m_horizontalAlignment == TextAlignMode::End;
+            }();
+
+        if (m_runs.last().isLineBreak() && availableWidth() >= 0 && !isTextAlignRight) {
             m_trimmableTrailingContent.reset();
             return;
         }
index 244e3b6..3af5795 100644 (file)
@@ -186,8 +186,6 @@ private:
     void adjustBaselineAndLineHeight(const Run&);
     InlineLayoutUnit runContentHeight(const Run&) const;
 
-    bool isTextAlignJustify() const { return m_horizontalAlignment == TextAlignMode::Justify; };
-    bool isTextAlignRight() const { return m_horizontalAlignment == TextAlignMode::Right || m_horizontalAlignment == TextAlignMode::WebKitRight || m_horizontalAlignment == TextAlignMode::End; }
     void justifyRuns(InlineLayoutUnit availableWidth);
 
     bool isVisuallyNonEmpty(const Run&) const;