Title: [281358] trunk/Source/WebCore
Revision
281358
Author
za...@apple.com
Date
2021-08-20 19:44:59 -0700 (Fri, 20 Aug 2021)

Log Message

[LFC][Integration] HTMLTextFormControlElement should use the inline iterator to collect content for wrap=hard
https://bugs.webkit.org/show_bug.cgi?id=228882

Reviewed by Antti Koivisto.

getNextSoftBreak is simply returns the position of the last item on the line unless it's a hard line break.
(endsWithBreak -> previousLineBrokeCleanly -> previousLineBrokeAtBR  see https://trac.webkit.org/changeset/6107)

* html/HTMLTextFormControlElement.cpp:
(WebCore::HTMLTextFormControlElement::valueWithHardLineBreaks const):
(WebCore::getNextSoftBreak): Deleted. line->lineBreakPos() translates to the position where the line breaks within the run.
maximumCaretOffset() returns the same value, though the naming is a bit confusing and probably should be renamed or introduce
something similar on the line iterator.
* layout/integration/LayoutIntegrationCoverage.cpp:
(WebCore::LayoutIntegration::canUseForLineLayoutWithReason):

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (281357 => 281358)


--- trunk/Source/WebCore/ChangeLog	2021-08-21 01:45:09 UTC (rev 281357)
+++ trunk/Source/WebCore/ChangeLog	2021-08-21 02:44:59 UTC (rev 281358)
@@ -1,3 +1,21 @@
+2021-08-20  Alan Bujtas  <za...@apple.com>
+
+        [LFC][Integration] HTMLTextFormControlElement should use the inline iterator to collect content for wrap=hard
+        https://bugs.webkit.org/show_bug.cgi?id=228882
+
+        Reviewed by Antti Koivisto.
+
+        getNextSoftBreak is simply returns the position of the last item on the line unless it's a hard line break.
+        (endsWithBreak -> previousLineBrokeCleanly -> previousLineBrokeAtBR  see https://trac.webkit.org/changeset/6107)
+
+        * html/HTMLTextFormControlElement.cpp:
+        (WebCore::HTMLTextFormControlElement::valueWithHardLineBreaks const):
+        (WebCore::getNextSoftBreak): Deleted. line->lineBreakPos() translates to the position where the line breaks within the run.
+        maximumCaretOffset() returns the same value, though the naming is a bit confusing and probably should be renamed or introduce
+        something similar on the line iterator.
+        * layout/integration/LayoutIntegrationCoverage.cpp:
+        (WebCore::LayoutIntegration::canUseForLineLayoutWithReason):
+
 2021-08-20  Zalan Bujtas  <za...@apple.com>
 
         [IFC][Integration] Enable inline level boxes with relative (min/max)width and (min/max)height values

Modified: trunk/Source/WebCore/html/HTMLTextFormControlElement.cpp (281357 => 281358)


--- trunk/Source/WebCore/html/HTMLTextFormControlElement.cpp	2021-08-21 01:45:09 UTC (rev 281357)
+++ trunk/Source/WebCore/html/HTMLTextFormControlElement.cpp	2021-08-21 02:44:59 UTC (rev 281358)
@@ -41,9 +41,12 @@
 #include "HTMLNames.h"
 #include "HTMLParserIdioms.h"
 #include "LayoutDisallowedScope.h"
+#include "LayoutIntegrationLineIterator.h"
+#include "LayoutIntegrationRunIterator.h"
 #include "Logging.h"
 #include "NodeTraversal.h"
 #include "Page.h"
+#include "RenderLineBreak.h"
 #include "RenderTextControlSingleLine.h"
 #include "RenderTheme.h"
 #include "ScriptDisallowedScope.h"
@@ -681,23 +684,6 @@
     return index;
 }
 
-static void getNextSoftBreak(LegacyRootInlineBox*& line, Node*& breakNode, unsigned& breakOffset)
-{
-    LegacyRootInlineBox* next;
-    for (; line; line = next) {
-        next = line->nextRootBox();
-        if (next && !line->endsWithBreak()) {
-            ASSERT(line->lineBreakObj());
-            breakNode = line->lineBreakObj()->node();
-            breakOffset = line->lineBreakPos();
-            line = next;
-            return;
-        }
-    }
-    breakNode = 0;
-    breakOffset = 0;
-}
-
 String HTMLTextFormControlElement::valueWithHardLineBreaks() const
 {
     // FIXME: It's not acceptable to ignore the HardWrap setting when there is no renderer.
@@ -713,14 +699,31 @@
     if (!renderer)
         return value();
 
-    Node* breakNode;
-    unsigned breakOffset;
-    LegacyRootInlineBox* line = renderer->firstRootBox();
-    if (!line)
+    Node* softLineBreakNode = nullptr;
+    unsigned softLineBreakOffset = 0;
+    auto currentLine = LayoutIntegration::firstLineFor(*renderer);
+    if (!currentLine)
         return value();
 
-    getNextSoftBreak(line, breakNode, breakOffset);
+    auto skipToNextSoftLineBreakPosition = [&] {
+        for (; currentLine; currentLine.traverseNext()) {
+            auto lastRun = currentLine.lastRun();
+            ASSERT(lastRun);
+            auto& renderer = lastRun->renderer();
+            auto lineEndsWithBR = is<RenderLineBreak>(renderer) && !downcast<RenderLineBreak>(renderer).isWBR();
+            if (!lineEndsWithBR) {
+                softLineBreakNode = renderer.node();
+                softLineBreakOffset = lastRun->maximumCaretOffset();
+                currentLine.traverseNext();
+                return;
+            }
+        }
+        softLineBreakNode = nullptr;
+        softLineBreakOffset = 0;
+    };
 
+    skipToNextSoftLineBreakPosition();
+
     StringBuilder result;
     for (RefPtr<Node> node = innerText->firstChild(); node; node = NodeTraversal::next(*node, innerText.get())) {
         if (is<HTMLBRElement>(*node))
@@ -729,18 +732,18 @@
             String data = ""
             unsigned length = data.length();
             unsigned position = 0;
-            while (breakNode == node && breakOffset <= length) {
-                if (breakOffset > position) {
-                    result.appendSubstring(data, position, breakOffset - position);
-                    position = breakOffset;
+            while (softLineBreakNode == node && softLineBreakOffset <= length) {
+                if (softLineBreakOffset > position) {
+                    result.appendSubstring(data, position, softLineBreakOffset - position);
+                    position = softLineBreakOffset;
                     result.append(newlineCharacter);
                 }
-                getNextSoftBreak(line, breakNode, breakOffset);
+                skipToNextSoftLineBreakPosition();
             }
             result.appendSubstring(data, position, length - position);
         }
-        while (breakNode == node)
-            getNextSoftBreak(line, breakNode, breakOffset);
+        while (softLineBreakNode == node)
+            skipToNextSoftLineBreakPosition();
     }
     stripTrailingNewline(result);
     return result.toString();

Modified: trunk/Source/WebCore/layout/integration/LayoutIntegrationCoverage.cpp (281357 => 281358)


--- trunk/Source/WebCore/layout/integration/LayoutIntegrationCoverage.cpp	2021-08-21 01:45:09 UTC (rev 281357)
+++ trunk/Source/WebCore/layout/integration/LayoutIntegrationCoverage.cpp	2021-08-21 02:44:59 UTC (rev 281358)
@@ -114,9 +114,6 @@
     case AvoidanceReason::FlowParentIsPlaceholderElement:
         stream << "placeholder element";
         break;
-    case AvoidanceReason::FlowParentIsTextAreaWithWrapping:
-        stream << "wrapping textarea";
-        break;
     case AvoidanceReason::FlowHasNonSupportedChild:
         stream << "unsupported child renderer";
         break;
@@ -757,9 +754,6 @@
     // FIXME: Placeholders do something strange.
     if (is<RenderTextControl>(*flow.parent()) && downcast<RenderTextControl>(*flow.parent()).textFormControlElement().placeholderElement())
         SET_REASON_AND_RETURN_IF_NEEDED(FlowParentIsPlaceholderElement, reasons, includeReasons);
-    // FIXME: Implementation of wrap=hard looks into lineboxes.
-    if (flow.parent()->isTextArea() && flow.parent()->element()->hasAttributeWithoutSynchronization(HTMLNames::wrapAttr))
-        SET_REASON_AND_RETURN_IF_NEEDED(FlowParentIsTextAreaWithWrapping, reasons, includeReasons);
     // This currently covers <blockflow>#text</blockflow>, <blockflow>#text<br></blockflow> and mutiple (sibling) RenderText cases.
     // The <blockflow><inline>#text</inline></blockflow> case is also popular and should be relatively easy to cover.
     for (auto walker = InlineWalker(const_cast<RenderBlockFlow&>(flow)); !walker.atEnd(); walker.advance()) {

Modified: trunk/Source/WebCore/layout/integration/LayoutIntegrationCoverage.h (281357 => 281358)


--- trunk/Source/WebCore/layout/integration/LayoutIntegrationCoverage.h	2021-08-21 01:45:09 UTC (rev 281357)
+++ trunk/Source/WebCore/layout/integration/LayoutIntegrationCoverage.h	2021-08-21 02:44:59 UTC (rev 281358)
@@ -45,7 +45,7 @@
     FlowHasTextOverflow                          = 1LLU  << 5,
     FlowHasLineClamp                             = 1LLU  << 6,
     FlowParentIsPlaceholderElement               = 1LLU  << 7,
-    FlowParentIsTextAreaWithWrapping             = 1LLU  << 8,
+    // Unused                                    = 1LLU  << 8,
     FlowHasNonSupportedChild                     = 1LLU  << 9,
     FlowHasUnsupportedFloat                      = 1LLU  << 10,
     // Unused                                    = 1LLU  << 11,
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to