Changeset 249084 in webkit


Ignore:
Timestamp:
Aug 24, 2019 6:31:50 AM (5 years ago)
Author:
Antti Koivisto
Message:

Implement layout system independent text box iterator
https://bugs.webkit.org/show_bug.cgi?id=201076

Reviewed by Zalan Bujtas.

Add a generic way to traverse line layout without caring about the details of the underlying layout system.

This patch adds basic support for traversing text boxes and uses it to remove layout path specific branches in RenderTreeAsText.

  • Sources.txt:
  • WebCore.xcodeproj/project.pbxproj:
  • rendering/RenderTreeAsText.cpp:

(WebCore::RenderTreeAsText::writeRenderObject):
(WebCore::writeTextBox):
(WebCore::write):
(WebCore::writeTextRun): Deleted.
(WebCore::writeSimpleLine): Deleted.

  • rendering/line/LineLayoutInterfaceTextBoxes.cpp: Added.

(WebCore::LineLayoutInterface::TextBox::rect const):
(WebCore::LineLayoutInterface::TextBox::logicalRect const):
(WebCore::LineLayoutInterface::TextBox::hasHyphen const):
(WebCore::LineLayoutInterface::TextBox::isLeftToRightDirection const):
(WebCore::LineLayoutInterface::TextBox::dirOverride const):
(WebCore::LineLayoutInterface::TextBox::text const):
(WebCore::LineLayoutInterface::TextBoxIterator::TextBoxIterator):
(WebCore::LineLayoutInterface::TextBoxIterator::traverseNext):
(WebCore::LineLayoutInterface::TextBoxIterator::operator== const):
(WebCore::LineLayoutInterface::simpleLineRunResolverForText):
(WebCore::LineLayoutInterface::rangeForText):
(WebCore::LineLayoutInterface::TextBoxRange::TextBoxRange):
(WebCore::LineLayoutInterface::textBoxes):

  • rendering/line/LineLayoutInterfaceTextBoxes.h: Added.

(WebCore::LineLayoutInterface::TextBox::TextBox):
(WebCore::LineLayoutInterface::TextBoxIterator::operator++):
(WebCore::LineLayoutInterface::TextBoxIterator::operator!= const):
(WebCore::LineLayoutInterface::TextBoxIterator::operator* const):
(WebCore::LineLayoutInterface::TextBoxRange::begin const):
(WebCore::LineLayoutInterface::TextBoxRange::end const):

Location:
trunk/Source/WebCore
Files:
2 added
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r249083 r249084  
     12019-08-24  Antti Koivisto  <antti@apple.com>
     2
     3        Implement layout system independent text box iterator
     4        https://bugs.webkit.org/show_bug.cgi?id=201076
     5
     6        Reviewed by Zalan Bujtas.
     7
     8        Add a generic way to traverse line layout without caring about the details of the underlying layout system.
     9
     10        This patch adds basic support for traversing text boxes and uses it to remove layout path specific branches in RenderTreeAsText.
     11
     12        * Sources.txt:
     13        * WebCore.xcodeproj/project.pbxproj:
     14        * rendering/RenderTreeAsText.cpp:
     15        (WebCore::RenderTreeAsText::writeRenderObject):
     16        (WebCore::writeTextBox):
     17        (WebCore::write):
     18        (WebCore::writeTextRun): Deleted.
     19        (WebCore::writeSimpleLine): Deleted.
     20        * rendering/line/LineLayoutInterfaceTextBoxes.cpp: Added.
     21        (WebCore::LineLayoutInterface::TextBox::rect const):
     22        (WebCore::LineLayoutInterface::TextBox::logicalRect const):
     23        (WebCore::LineLayoutInterface::TextBox::hasHyphen const):
     24        (WebCore::LineLayoutInterface::TextBox::isLeftToRightDirection const):
     25        (WebCore::LineLayoutInterface::TextBox::dirOverride const):
     26        (WebCore::LineLayoutInterface::TextBox::text const):
     27        (WebCore::LineLayoutInterface::TextBoxIterator::TextBoxIterator):
     28        (WebCore::LineLayoutInterface::TextBoxIterator::traverseNext):
     29        (WebCore::LineLayoutInterface::TextBoxIterator::operator== const):
     30        (WebCore::LineLayoutInterface::simpleLineRunResolverForText):
     31        (WebCore::LineLayoutInterface::rangeForText):
     32        (WebCore::LineLayoutInterface::TextBoxRange::TextBoxRange):
     33        (WebCore::LineLayoutInterface::textBoxes):
     34        * rendering/line/LineLayoutInterfaceTextBoxes.h: Added.
     35        (WebCore::LineLayoutInterface::TextBox::TextBox):
     36        (WebCore::LineLayoutInterface::TextBoxIterator::operator++):
     37        (WebCore::LineLayoutInterface::TextBoxIterator::operator!= const):
     38        (WebCore::LineLayoutInterface::TextBoxIterator::operator* const):
     39        (WebCore::LineLayoutInterface::TextBoxRange::begin const):
     40        (WebCore::LineLayoutInterface::TextBoxRange::end const):
     41
    1422019-08-24  Zalan Bujtas  <zalan@apple.com>
    243
  • trunk/Source/WebCore/Sources.txt

    r249066 r249084  
    21532153rendering/line/LineBreaker.cpp
    21542154rendering/line/LineInfo.cpp
     2155rendering/line/LineLayoutInterfaceTextBoxes.cpp
    21552156rendering/line/LineWidth.cpp
    21562157rendering/line/TrailingObjects.cpp
  • trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj

    r249066 r249084  
    47904790                E47E276516036ED200EE2AFB /* ExtensionStyleSheets.h in Headers */ = {isa = PBXBuildFile; fileRef = E47E276416036ED200EE2AFB /* ExtensionStyleSheets.h */; settings = {ATTRIBUTES = (Private, ); }; };
    47914791                E48137B91DB3B526005C59BF /* StyleValidity.h in Headers */ = {isa = PBXBuildFile; fileRef = E48137B81DB3B526005C59BF /* StyleValidity.h */; settings = {ATTRIBUTES = (Private, ); }; };
     4792                E484A33E23055325009ADE6A /* LineLayoutInterfaceTextBoxes.h in Headers */ = {isa = PBXBuildFile; fileRef = E484A33B23055303009ADE6A /* LineLayoutInterfaceTextBoxes.h */; };
    47924793                E48944A3180B57D800F165D8 /* SimpleLineLayout.h in Headers */ = {isa = PBXBuildFile; fileRef = E48944A1180B57D800F165D8 /* SimpleLineLayout.h */; settings = {ATTRIBUTES = (Private, ); }; };
    47934794                E4916FF7195DF6A0005AB349 /* LayerFlushThrottleState.h in Headers */ = {isa = PBXBuildFile; fileRef = E4916FF6195DF6A0005AB349 /* LayerFlushThrottleState.h */; settings = {ATTRIBUTES = (Private, ); }; };
     
    1495214953                E47E276716036EDC00EE2AFB /* ExtensionStyleSheets.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = ExtensionStyleSheets.cpp; sourceTree = "<group>"; };
    1495314954                E48137B81DB3B526005C59BF /* StyleValidity.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = StyleValidity.h; sourceTree = "<group>"; };
     14955                E484A33B23055303009ADE6A /* LineLayoutInterfaceTextBoxes.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = LineLayoutInterfaceTextBoxes.h; sourceTree = "<group>"; };
     14956                E484A33D23055303009ADE6A /* LineLayoutInterfaceTextBoxes.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = LineLayoutInterfaceTextBoxes.cpp; sourceTree = "<group>"; };
    1495414957                E48944A0180B57D800F165D8 /* SimpleLineLayout.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = SimpleLineLayout.cpp; sourceTree = "<group>"; };
    1495514958                E48944A1180B57D800F165D8 /* SimpleLineLayout.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SimpleLineLayout.h; sourceTree = "<group>"; };
     
    2817328176                                FFB698CE1833F17600158A31 /* LineInfo.h */,
    2817428177                                FFEFAB2D183BCB6F00514534 /* LineInlineHeaders.h */,
     28178                                E484A33D23055303009ADE6A /* LineLayoutInterfaceTextBoxes.cpp */,
     28179                                E484A33B23055303009ADE6A /* LineLayoutInterfaceTextBoxes.h */,
    2817528180                                FFEFAB2918380DA000514534 /* LineLayoutState.h */,
    2817628181                                FFDBC046183D27B700407109 /* LineWidth.cpp */,
     
    3191831923                                57EF5E601D20C83900171E60 /* TextCodecReplacement.h in Headers */,
    3191931924                                B2C3DA400D006C1D00EF6F26 /* TextCodecUserDefined.h in Headers */,
     31925                                E484A33E23055325009ADE6A /* LineLayoutInterfaceTextBoxes.h in Headers */,
    3192031926                                B2C3DA420D006C1D00EF6F26 /* TextCodecUTF16.h in Headers */,
    3192131927                                9343CB8212F25E510033C5EE /* TextCodecUTF8.h in Headers */,
  • trunk/Source/WebCore/rendering/RenderTreeAsText.cpp

    r245170 r249084  
    3636#include "HTMLSpanElement.h"
    3737#include "InlineTextBox.h"
     38#include "LineLayoutInterfaceTextBoxes.h"
    3839#include "Logging.h"
    3940#include "PrintContext.h"
     
    6465#include "SVGRenderTreeAsText.h"
    6566#include "ShadowRoot.h"
    66 #include "SimpleLineLayoutResolver.h"
    6767#include "StyleProperties.h"
    6868#include <wtf/HexNumber.h>
     
    203203        const RenderText& text = downcast<RenderText>(o);
    204204        r = IntRect(text.firstRunLocation(), text.linesBoundingBox().size());
    205         if (!text.firstTextBox() && !text.simpleLineLayout())
     205        auto textBoxes = LineLayoutInterface::textBoxes(text);
     206        if (textBoxes.begin() == textBoxes.end())
    206207            adjustForTableCells = false;
    207208    } else if (o.isBR()) {
     
    478479}
    479480
    480 static void writeTextRun(TextStream& ts, const RenderText& o, const InlineTextBox& run)
    481 {
    482     // FIXME: For now use an "enclosingIntRect" model for x, y and logicalWidth, although this makes it harder
    483     // to detect any changes caused by the conversion to floating point. :(
    484     int x = run.x();
    485     int y = run.y();
    486     int logicalWidth = ceilf(run.left() + run.logicalWidth()) - x;
     481static void writeTextBox(TextStream& ts, const RenderText& o, const LineLayoutInterface::TextBox& textBox)
     482{
     483    auto rect = textBox.rect();
     484    auto logicalRect = textBox.logicalRect();
     485
     486    int x = rect.x();
     487    int y = rect.y();
     488
     489    // FIXME: Mixing logical and physical here doesn't make sense.
     490    int logicalWidth = ceilf(rect.x() + logicalRect.width()) - x;
    487491
    488492    // FIXME: Table cell adjustment is temporary until results can be updated.
     
    491495       
    492496    ts << "text run at (" << x << "," << y << ") width " << logicalWidth;
    493     if (!run.isLeftToRightDirection() || run.dirOverride()) {
    494         ts << (!run.isLeftToRightDirection() ? " RTL" : " LTR");
    495         if (run.dirOverride())
     497    if (!textBox.isLeftToRightDirection() || textBox.dirOverride()) {
     498        ts << (!textBox.isLeftToRightDirection() ? " RTL" : " LTR");
     499        if (textBox.dirOverride())
    496500            ts << " override";
    497501    }
    498502    ts << ": "
    499         << quoteAndEscapeNonPrintables(String(o.text()).substring(run.start(), run.len()));
    500     if (run.hasHyphen())
     503        << quoteAndEscapeNonPrintables(textBox.text());
     504    if (textBox.hasHyphen())
    501505        ts << " + hyphen string " << quoteAndEscapeNonPrintables(o.style().hyphenString().string());
    502506    ts << "\n";
    503507}
    504508
    505 static void writeSimpleLine(TextStream& ts, const RenderText& renderText, const SimpleLineLayout::RunResolver::Run& run)
    506 {
    507     auto rect = run.rect();
    508     int x = rect.x();
    509     int y = rect.y();
    510     int logicalWidth = ceilf(rect.x() + rect.width()) - x;
    511 
    512     if (is<RenderTableCell>(*renderText.containingBlock()))
    513         y -= floorToInt(downcast<RenderTableCell>(*renderText.containingBlock()).intrinsicPaddingBefore());
    514 
    515     ts << "text run at (" << x << "," << y << ") width " << logicalWidth;
    516     ts << ": " << quoteAndEscapeNonPrintables(run.text());
    517     if (run.hasHyphen())
    518         ts << " + hyphen string " << quoteAndEscapeNonPrintables(renderText.style().hyphenString().string());
    519     ts << "\n";
    520 }
    521 
    522509void write(TextStream& ts, const RenderObject& o, OptionSet<RenderAsTextFlag> behavior)
    523510{
     
    564551    if (is<RenderText>(o)) {
    565552        auto& text = downcast<RenderText>(o);
    566         if (auto layout = text.simpleLineLayout()) {
    567             ASSERT(!text.firstTextBox());
    568             auto resolver = runResolver(downcast<RenderBlockFlow>(*text.parent()), *layout);
    569             for (auto run : resolver.rangeForRenderer(text)) {
    570                 ts << indent;
    571                 writeSimpleLine(ts, text, run);
    572             }
    573         } else {
    574             for (auto* box = text.firstTextBox(); box; box = box->nextTextBox()) {
    575                 ts << indent;
    576                 writeTextRun(ts, text, *box);
    577             }
    578         }
    579 
     553        for (auto textBox : LineLayoutInterface::textBoxes(text)) {
     554            ts << indent;
     555            writeTextBox(ts, text, textBox);
     556        }
    580557    } else {
    581558        for (auto& child : childrenOfType<RenderObject>(downcast<RenderElement>(o))) {
Note: See TracChangeset for help on using the changeset viewer.