Changeset 252959 in webkit


Ignore:
Timestamp:
Nov 30, 2019 8:30:54 AM (4 years ago)
Author:
Antti Koivisto
Message:

Move path implementation functions in LineLayoutTraversal to *Path classes
https://bugs.webkit.org/show_bug.cgi?id=204714

Reviewed by Sam Weinig.

Simplify LineLayoutTraversal and make it easier to extend.

  • Turn SimplePath and ComplexPath structs into classes
  • Move them to separate files
  • Make path implementation functions class members, called via generic lambdas
  • Instead of inheriting Box/TextBox to iterators, make it a member variable.
  • Move the path variant to Box, avoiding use of templates.
  • WebCore.xcodeproj/project.pbxproj:
  • rendering/RenderTreeAsText.cpp:

(WebCore::writeTextBox):

  • rendering/line/LineLayoutTraversal.cpp:

(WebCore::LineLayoutTraversal::TextBoxIterator::TextBoxIterator):
(WebCore::LineLayoutTraversal::TextBoxIterator::traverseNextInVisualOrder):
(WebCore::LineLayoutTraversal::TextBoxIterator::traverseNextInTextOrder):
(WebCore::LineLayoutTraversal::TextBoxIterator::operator== const):
(WebCore::LineLayoutTraversal::TextBoxIterator::atEnd const):
(WebCore::LineLayoutTraversal::ElementBoxIterator::ElementBoxIterator):
(WebCore::LineLayoutTraversal::ElementBoxIterator::atEnd const):
(WebCore::LineLayoutTraversal::TextBoxIterator::ComplexPath::nextInlineTextBoxInTextOrder const): Deleted.

  • rendering/line/LineLayoutTraversal.h:

(WebCore::LineLayoutTraversal::TextBoxIterator::TextBoxIterator):
(WebCore::LineLayoutTraversal::TextBoxIterator::operator* const):
(WebCore::LineLayoutTraversal::TextBoxIterator::operator-> const):
(WebCore::LineLayoutTraversal::ElementBoxIterator::ElementBoxIterator):
(WebCore::LineLayoutTraversal::ElementBoxIterator::operator* const):
(WebCore::LineLayoutTraversal::ElementBoxIterator::operator-> const):
(WebCore::LineLayoutTraversal::Box::Box):
(WebCore::LineLayoutTraversal::Box::rect const):
(WebCore::LineLayoutTraversal::Box::logicalRect const):
(WebCore::LineLayoutTraversal::Box::isLeftToRightDirection const):
(WebCore::LineLayoutTraversal::Box::dirOverride const):
(WebCore::LineLayoutTraversal::Box::isLineBreak const):
(WebCore::LineLayoutTraversal::TextBox::hasHyphen const):
(WebCore::LineLayoutTraversal::TextBox::TextBox):
(WebCore::LineLayoutTraversal::TextBox::text const):
(WebCore::LineLayoutTraversal::TextBox::localStartOffset const):
(WebCore::LineLayoutTraversal::TextBox::localEndOffset const):
(WebCore::LineLayoutTraversal::TextBox::length const):
(WebCore::LineLayoutTraversal::TextBox::isLastOnLine const):
(WebCore::LineLayoutTraversal::TextBox::isLast const):
(): Deleted.
(WebCore::LineLayoutTraversal::Box<Iterator>::rect const): Deleted.
(WebCore::LineLayoutTraversal::Box<Iterator>::logicalRect const): Deleted.
(WebCore::LineLayoutTraversal::Box<Iterator>::isLeftToRightDirection const): Deleted.
(WebCore::LineLayoutTraversal::Box<Iterator>::dirOverride const): Deleted.
(WebCore::LineLayoutTraversal::Box<Iterator>::isLineBreak const): Deleted.
(WebCore::LineLayoutTraversal::Box<Iterator>::iterator const): Deleted.
(WebCore::LineLayoutTraversal::TextBox<Iterator>::hasHyphen const): Deleted.
(WebCore::LineLayoutTraversal::TextBox<Iterator>::text const): Deleted.
(WebCore::LineLayoutTraversal::TextBox<Iterator>::localStartOffset const): Deleted.
(WebCore::LineLayoutTraversal::TextBox<Iterator>::localEndOffset const): Deleted.
(WebCore::LineLayoutTraversal::TextBox<Iterator>::length const): Deleted.
(WebCore::LineLayoutTraversal::TextBox<Iterator>::isLastOnLine const): Deleted.
(WebCore::LineLayoutTraversal::TextBox<Iterator>::isLast const): Deleted.

  • rendering/line/LineLayoutTraversalComplexPath.h: Added.

(WebCore::LineLayoutTraversal::ComplexPath::ComplexPath):
(WebCore::LineLayoutTraversal::ComplexPath::rect const):
(WebCore::LineLayoutTraversal::ComplexPath::logicalRect const):
(WebCore::LineLayoutTraversal::ComplexPath::isLeftToRightDirection const):
(WebCore::LineLayoutTraversal::ComplexPath::dirOverride const):
(WebCore::LineLayoutTraversal::ComplexPath::isLineBreak const):
(WebCore::LineLayoutTraversal::ComplexPath::hasHyphen const):
(WebCore::LineLayoutTraversal::ComplexPath::text const):
(WebCore::LineLayoutTraversal::ComplexPath::localStartOffset const):
(WebCore::LineLayoutTraversal::ComplexPath::localEndOffset const):
(WebCore::LineLayoutTraversal::ComplexPath::length const):
(WebCore::LineLayoutTraversal::ComplexPath::isLastOnLine const):
(WebCore::LineLayoutTraversal::ComplexPath::isLast const):
(WebCore::LineLayoutTraversal::ComplexPath::traverseNextTextBoxInVisualOrder):
(WebCore::LineLayoutTraversal::ComplexPath::traverseNextTextBoxInTextOrder):
(WebCore::LineLayoutTraversal::ComplexPath::operator== const):
(WebCore::LineLayoutTraversal::ComplexPath::atEnd const):
(WebCore::LineLayoutTraversal::ComplexPath::inlineTextBox const):
(WebCore::LineLayoutTraversal::ComplexPath::nextInlineTextBoxInTextOrder const):

  • rendering/line/LineLayoutTraversalSimplePath.h: Added.

(WebCore::LineLayoutTraversal::SimplePath::SimplePath):
(WebCore::LineLayoutTraversal::SimplePath::rect const):
(WebCore::LineLayoutTraversal::SimplePath::logicalRect const):
(WebCore::LineLayoutTraversal::SimplePath::isLeftToRightDirection const):
(WebCore::LineLayoutTraversal::SimplePath::dirOverride const):
(WebCore::LineLayoutTraversal::SimplePath::isLineBreak const):
(WebCore::LineLayoutTraversal::SimplePath::hasHyphen const):
(WebCore::LineLayoutTraversal::SimplePath::text const):
(WebCore::LineLayoutTraversal::SimplePath::localStartOffset const):
(WebCore::LineLayoutTraversal::SimplePath::localEndOffset const):
(WebCore::LineLayoutTraversal::SimplePath::length const):
(WebCore::LineLayoutTraversal::SimplePath::isLastOnLine const):
(WebCore::LineLayoutTraversal::SimplePath::isLast const):
(WebCore::LineLayoutTraversal::SimplePath::traverseNextTextBoxInVisualOrder):
(WebCore::LineLayoutTraversal::SimplePath::traverseNextTextBoxInTextOrder):
(WebCore::LineLayoutTraversal::SimplePath::operator== const):
(WebCore::LineLayoutTraversal::SimplePath::atEnd const):

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

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r252958 r252959  
     12019-11-30  Antti Koivisto  <antti@apple.com>
     2
     3        Move path implementation functions in LineLayoutTraversal to *Path classes
     4        https://bugs.webkit.org/show_bug.cgi?id=204714
     5
     6        Reviewed by Sam Weinig.
     7
     8        Simplify LineLayoutTraversal and make it easier to extend.
     9
     10        - Turn SimplePath and ComplexPath structs into classes
     11        - Move them to separate files
     12        - Make path implementation functions class members, called via generic lambdas
     13        - Instead of inheriting Box/TextBox to iterators, make it a member variable.
     14        - Move the path variant to Box, avoiding use of templates.
     15
     16        * WebCore.xcodeproj/project.pbxproj:
     17        * rendering/RenderTreeAsText.cpp:
     18        (WebCore::writeTextBox):
     19        * rendering/line/LineLayoutTraversal.cpp:
     20        (WebCore::LineLayoutTraversal::TextBoxIterator::TextBoxIterator):
     21        (WebCore::LineLayoutTraversal::TextBoxIterator::traverseNextInVisualOrder):
     22        (WebCore::LineLayoutTraversal::TextBoxIterator::traverseNextInTextOrder):
     23        (WebCore::LineLayoutTraversal::TextBoxIterator::operator== const):
     24        (WebCore::LineLayoutTraversal::TextBoxIterator::atEnd const):
     25        (WebCore::LineLayoutTraversal::ElementBoxIterator::ElementBoxIterator):
     26        (WebCore::LineLayoutTraversal::ElementBoxIterator::atEnd const):
     27        (WebCore::LineLayoutTraversal::TextBoxIterator::ComplexPath::nextInlineTextBoxInTextOrder const): Deleted.
     28        * rendering/line/LineLayoutTraversal.h:
     29        (WebCore::LineLayoutTraversal::TextBoxIterator::TextBoxIterator):
     30        (WebCore::LineLayoutTraversal::TextBoxIterator::operator* const):
     31        (WebCore::LineLayoutTraversal::TextBoxIterator::operator-> const):
     32        (WebCore::LineLayoutTraversal::ElementBoxIterator::ElementBoxIterator):
     33        (WebCore::LineLayoutTraversal::ElementBoxIterator::operator* const):
     34        (WebCore::LineLayoutTraversal::ElementBoxIterator::operator-> const):
     35        (WebCore::LineLayoutTraversal::Box::Box):
     36        (WebCore::LineLayoutTraversal::Box::rect const):
     37        (WebCore::LineLayoutTraversal::Box::logicalRect const):
     38        (WebCore::LineLayoutTraversal::Box::isLeftToRightDirection const):
     39        (WebCore::LineLayoutTraversal::Box::dirOverride const):
     40        (WebCore::LineLayoutTraversal::Box::isLineBreak const):
     41        (WebCore::LineLayoutTraversal::TextBox::hasHyphen const):
     42        (WebCore::LineLayoutTraversal::TextBox::TextBox):
     43        (WebCore::LineLayoutTraversal::TextBox::text const):
     44        (WebCore::LineLayoutTraversal::TextBox::localStartOffset const):
     45        (WebCore::LineLayoutTraversal::TextBox::localEndOffset const):
     46        (WebCore::LineLayoutTraversal::TextBox::length const):
     47        (WebCore::LineLayoutTraversal::TextBox::isLastOnLine const):
     48        (WebCore::LineLayoutTraversal::TextBox::isLast const):
     49        (): Deleted.
     50        (WebCore::LineLayoutTraversal::Box<Iterator>::rect const): Deleted.
     51        (WebCore::LineLayoutTraversal::Box<Iterator>::logicalRect const): Deleted.
     52        (WebCore::LineLayoutTraversal::Box<Iterator>::isLeftToRightDirection const): Deleted.
     53        (WebCore::LineLayoutTraversal::Box<Iterator>::dirOverride const): Deleted.
     54        (WebCore::LineLayoutTraversal::Box<Iterator>::isLineBreak const): Deleted.
     55        (WebCore::LineLayoutTraversal::Box<Iterator>::iterator const): Deleted.
     56        (WebCore::LineLayoutTraversal::TextBox<Iterator>::hasHyphen const): Deleted.
     57        (WebCore::LineLayoutTraversal::TextBox<Iterator>::text const): Deleted.
     58        (WebCore::LineLayoutTraversal::TextBox<Iterator>::localStartOffset const): Deleted.
     59        (WebCore::LineLayoutTraversal::TextBox<Iterator>::localEndOffset const): Deleted.
     60        (WebCore::LineLayoutTraversal::TextBox<Iterator>::length const): Deleted.
     61        (WebCore::LineLayoutTraversal::TextBox<Iterator>::isLastOnLine const): Deleted.
     62        (WebCore::LineLayoutTraversal::TextBox<Iterator>::isLast const): Deleted.
     63        * rendering/line/LineLayoutTraversalComplexPath.h: Added.
     64        (WebCore::LineLayoutTraversal::ComplexPath::ComplexPath):
     65        (WebCore::LineLayoutTraversal::ComplexPath::rect const):
     66        (WebCore::LineLayoutTraversal::ComplexPath::logicalRect const):
     67        (WebCore::LineLayoutTraversal::ComplexPath::isLeftToRightDirection const):
     68        (WebCore::LineLayoutTraversal::ComplexPath::dirOverride const):
     69        (WebCore::LineLayoutTraversal::ComplexPath::isLineBreak const):
     70        (WebCore::LineLayoutTraversal::ComplexPath::hasHyphen const):
     71        (WebCore::LineLayoutTraversal::ComplexPath::text const):
     72        (WebCore::LineLayoutTraversal::ComplexPath::localStartOffset const):
     73        (WebCore::LineLayoutTraversal::ComplexPath::localEndOffset const):
     74        (WebCore::LineLayoutTraversal::ComplexPath::length const):
     75        (WebCore::LineLayoutTraversal::ComplexPath::isLastOnLine const):
     76        (WebCore::LineLayoutTraversal::ComplexPath::isLast const):
     77        (WebCore::LineLayoutTraversal::ComplexPath::traverseNextTextBoxInVisualOrder):
     78        (WebCore::LineLayoutTraversal::ComplexPath::traverseNextTextBoxInTextOrder):
     79        (WebCore::LineLayoutTraversal::ComplexPath::operator== const):
     80        (WebCore::LineLayoutTraversal::ComplexPath::atEnd const):
     81        (WebCore::LineLayoutTraversal::ComplexPath::inlineTextBox const):
     82        (WebCore::LineLayoutTraversal::ComplexPath::nextInlineTextBoxInTextOrder const):
     83        * rendering/line/LineLayoutTraversalSimplePath.h: Added.
     84        (WebCore::LineLayoutTraversal::SimplePath::SimplePath):
     85        (WebCore::LineLayoutTraversal::SimplePath::rect const):
     86        (WebCore::LineLayoutTraversal::SimplePath::logicalRect const):
     87        (WebCore::LineLayoutTraversal::SimplePath::isLeftToRightDirection const):
     88        (WebCore::LineLayoutTraversal::SimplePath::dirOverride const):
     89        (WebCore::LineLayoutTraversal::SimplePath::isLineBreak const):
     90        (WebCore::LineLayoutTraversal::SimplePath::hasHyphen const):
     91        (WebCore::LineLayoutTraversal::SimplePath::text const):
     92        (WebCore::LineLayoutTraversal::SimplePath::localStartOffset const):
     93        (WebCore::LineLayoutTraversal::SimplePath::localEndOffset const):
     94        (WebCore::LineLayoutTraversal::SimplePath::length const):
     95        (WebCore::LineLayoutTraversal::SimplePath::isLastOnLine const):
     96        (WebCore::LineLayoutTraversal::SimplePath::isLast const):
     97        (WebCore::LineLayoutTraversal::SimplePath::traverseNextTextBoxInVisualOrder):
     98        (WebCore::LineLayoutTraversal::SimplePath::traverseNextTextBoxInTextOrder):
     99        (WebCore::LineLayoutTraversal::SimplePath::operator== const):
     100        (WebCore::LineLayoutTraversal::SimplePath::atEnd const):
     101
    11022019-11-30  Zalan Bujtas  <zalan@apple.com>
    2103
  • trunk/Source/WebCore/Headers.cmake

    r252839 r252959  
    13211321
    13221322    rendering/line/LineLayoutTraversal.h
     1323    rendering/line/LineLayoutTraversalComplexPath.h
     1324    rendering/line/LineLayoutTraversalSimplePath.h
    13231325    rendering/line/LineWidth.h
    13241326    rendering/line/TrailingObjects.h
  • trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj

    r252893 r252959  
    47954795                E42E76DC1C7AF77600E3614D /* StyleUpdate.h in Headers */ = {isa = PBXBuildFile; fileRef = E42E76DB1C7AF77600E3614D /* StyleUpdate.h */; };
    47964796                E43105BB16750F1600DB2FB8 /* NodeTraversal.h in Headers */ = {isa = PBXBuildFile; fileRef = E43105BA16750F1600DB2FB8 /* NodeTraversal.h */; settings = {ATTRIBUTES = (Private, ); }; };
     4797                E4343D232392778400EBBB66 /* LineLayoutTraversalSimplePath.h in Headers */ = {isa = PBXBuildFile; fileRef = E4343D212392778300EBBB66 /* LineLayoutTraversalSimplePath.h */; settings = {ATTRIBUTES = (Private, ); }; };
     4798                E4343D252392779000EBBB66 /* LineLayoutTraversalComplexPath.h in Headers */ = {isa = PBXBuildFile; fileRef = E4343D242392778F00EBBB66 /* LineLayoutTraversalComplexPath.h */; settings = {ATTRIBUTES = (Private, ); }; };
    47974799                E43A023B17EB370A004CDD25 /* RenderElement.h in Headers */ = {isa = PBXBuildFile; fileRef = E43A023A17EB370A004CDD25 /* RenderElement.h */; settings = {ATTRIBUTES = (Private, ); }; };
    47984800                E43AF8E71AC5B7EC00CA717E /* CacheValidation.h in Headers */ = {isa = PBXBuildFile; fileRef = E43AF8E51AC5B7DD00CA717E /* CacheValidation.h */; settings = {ATTRIBUTES = (Private, ); }; };
     
    1510815110                E43105B716750F0C00DB2FB8 /* NodeTraversal.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = NodeTraversal.cpp; sourceTree = "<group>"; };
    1510915111                E43105BA16750F1600DB2FB8 /* NodeTraversal.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = NodeTraversal.h; sourceTree = "<group>"; };
     15112                E4343D212392778300EBBB66 /* LineLayoutTraversalSimplePath.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = LineLayoutTraversalSimplePath.h; sourceTree = "<group>"; };
     15113                E4343D242392778F00EBBB66 /* LineLayoutTraversalComplexPath.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = LineLayoutTraversalComplexPath.h; sourceTree = "<group>"; };
    1511015114                E43A023A17EB370A004CDD25 /* RenderElement.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RenderElement.h; sourceTree = "<group>"; };
    1511115115                E43A023C17EB3713004CDD25 /* RenderElement.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = RenderElement.cpp; sourceTree = "<group>"; };
     
    2872628730                                E484A33D23055303009ADE6A /* LineLayoutTraversal.cpp */,
    2872728731                                E484A33B23055303009ADE6A /* LineLayoutTraversal.h */,
     28732                                E4343D212392778300EBBB66 /* LineLayoutTraversalSimplePath.h */,
     28733                                E4343D242392778F00EBBB66 /* LineLayoutTraversalComplexPath.h */,
    2872828734                                FFDBC046183D27B700407109 /* LineWidth.cpp */,
    2872928735                                FFDBC045183D27B700407109 /* LineWidth.h */,
     
    3053630542                                833B9E361F508D8500E0E428 /* JSFileSystemFileEntry.h in Headers */,
    3053730543                                712BE4881FE8686A002031CC /* JSFillMode.h in Headers */,
     30544                                E4343D252392779000EBBB66 /* LineLayoutTraversalComplexPath.h in Headers */,
    3053830545                                B6D9D27B14EAC0860090D75E /* JSFocusEvent.h in Headers */,
    3053930546                                C280833F1C6DC26F001451B6 /* JSFontFace.h in Headers */,
     
    3168331690                                57303BEF200980C600355965 /* PublicKeyCredentialDescriptor.h in Headers */,
    3168431691                                57303C0A20099BAD00355965 /* PublicKeyCredentialRequestOptions.h in Headers */,
     31692                                E4343D232392778400EBBB66 /* LineLayoutTraversalSimplePath.h in Headers */,
    3168531693                                57303BEB20097F4000355965 /* PublicKeyCredentialType.h in Headers */,
    3168631694                                0081FF0016B0A2D3008AAA7A /* PublicSuffix.h in Headers */,
  • trunk/Source/WebCore/rendering/RenderTreeAsText.cpp

    r252724 r252959  
    478478}
    479479
    480 static void writeTextBox(TextStream& ts, const RenderText& o, const LineLayoutTraversal::TextBoxIterator::BoxType& textBox)
     480static void writeTextBox(TextStream& ts, const RenderText& o, const LineLayoutTraversal::TextBox& textBox)
    481481{
    482482    auto rect = textBox.rect();
  • trunk/Source/WebCore/rendering/line/LineLayoutTraversal.cpp

    r250519 r252959  
    3333
    3434TextBoxIterator::TextBoxIterator(const InlineTextBox* inlineTextBox)
    35     : m_pathVariant(ComplexPath { inlineTextBox, { } })
     35    : m_textBox(ComplexPath { inlineTextBox, { } })
    3636{
    3737}
    3838TextBoxIterator::TextBoxIterator(Vector<const InlineTextBox*>&& sorted, size_t index)
    39     : m_pathVariant(ComplexPath { index < sorted.size() ? sorted[index] : nullptr, WTFMove(sorted), index })
     39    : m_textBox(ComplexPath { index < sorted.size() ? sorted[index] : nullptr, WTFMove(sorted), index })
    4040{
    4141}
    4242
    4343TextBoxIterator::TextBoxIterator(SimpleLineLayout::RunResolver::Iterator iterator, SimpleLineLayout::RunResolver::Iterator end)
    44     : m_pathVariant(SimplePath { iterator, end })
     44    : m_textBox(SimplePath { iterator, end })
    4545{
    4646}
     
    4848TextBoxIterator& TextBoxIterator::traverseNextInVisualOrder()
    4949{
    50     auto simple = [](SimplePath& path) {
    51         ++path.iterator;
    52     };
    53 
    54     auto complex = [](ComplexPath& path) {
    55         path.inlineBox = path.inlineBox->nextTextBox();
    56     };
    57 
    58     WTF::switchOn(m_pathVariant, simple, complex);
    59 
     50    WTF::switchOn(m_textBox.m_pathVariant, [](auto& path) {
     51        path.traverseNextTextBoxInVisualOrder();
     52    });
    6053    return *this;
    61 }
    62 
    63 const InlineTextBox* TextBoxIterator::ComplexPath::nextInlineTextBoxInTextOrder() const
    64 {
    65     if (!sortedInlineTextBoxes.isEmpty()) {
    66         if (sortedInlineTextBoxIndex + 1 < sortedInlineTextBoxes.size())
    67             return sortedInlineTextBoxes[sortedInlineTextBoxIndex + 1];
    68         return nullptr;
    69     }
    70     return inlineBox->nextTextBox();
    7154}
    7255
    7356TextBoxIterator& TextBoxIterator::traverseNextInTextOrder()
    7457{
    75     auto simple = [](SimplePath& path) {
    76         ++path.iterator;
    77     };
    78 
    79     auto complex = [](ComplexPath& path) {
    80         path.inlineBox = path.nextInlineTextBoxInTextOrder();
    81         if (!path.sortedInlineTextBoxes.isEmpty())
    82             ++path.sortedInlineTextBoxIndex;
    83     };
    84 
    85     WTF::switchOn(m_pathVariant, simple, complex);
    86 
     58    WTF::switchOn(m_textBox.m_pathVariant, [](auto& path) {
     59        path.traverseNextTextBoxInTextOrder();
     60    });
    8761    return *this;
    8862}
     
    9064bool TextBoxIterator::operator==(const TextBoxIterator& other) const
    9165{
    92     if (m_pathVariant.index() != other.m_pathVariant.index())
     66    if (m_textBox.m_pathVariant.index() != other.m_textBox.m_pathVariant.index())
    9367        return false;
    9468
    95     auto simple = [&](const SimplePath& path) {
    96         return path.iterator == WTF::get<SimplePath>(other.m_pathVariant).iterator;
    97     };
    98 
    99     auto complex = [&](const ComplexPath& path) {
    100         return path.inlineBox == WTF::get<ComplexPath>(other.m_pathVariant).inlineBox;
    101     };
    102 
    103     return WTF::switchOn(m_pathVariant, simple, complex);
     69    return WTF::switchOn(m_textBox.m_pathVariant, [&](const auto& path) {
     70        return path == WTF::get<std::decay_t<decltype(path)>>(other.m_textBox.m_pathVariant);
     71    });
    10472}
    10573
    10674bool TextBoxIterator::atEnd() const
    10775{
    108     auto simple = [&](const SimplePath& path) {
    109         return path.iterator == path.end;
    110     };
    111 
    112     auto complex = [&](const ComplexPath& path) {
    113         return !path.inlineBox;
    114     };
    115 
    116     return WTF::switchOn(m_pathVariant, simple, complex);
     76    return WTF::switchOn(m_textBox.m_pathVariant, [](auto& path) {
     77        return path.atEnd();
     78    });
    11779}
    11880
     
    146108
    147109ElementBoxIterator::ElementBoxIterator(const InlineElementBox* inlineElementBox)
    148     : m_pathVariant(ComplexPath { inlineElementBox })
     110    : m_box(ComplexPath { inlineElementBox, { } })
    149111{
    150112}
    151113ElementBoxIterator::ElementBoxIterator(SimpleLineLayout::RunResolver::Iterator iterator, SimpleLineLayout::RunResolver::Iterator end)
    152     : m_pathVariant(SimplePath { iterator, end })
     114    : m_box(SimplePath { iterator, end })
    153115{
    154116}
     
    156118bool ElementBoxIterator::atEnd() const
    157119{
    158     auto simple = [&](const SimplePath& path) {
    159         return path.iterator == path.end;
    160     };
    161 
    162     auto complex = [&](const ComplexPath& path) {
    163         return !path.inlineBox;
    164     };
    165 
    166     return WTF::switchOn(m_pathVariant, simple, complex);
     120    return WTF::switchOn(m_box.m_pathVariant, [](auto& path) {
     121        return path.atEnd();
     122    });
    167123}
    168124
  • trunk/Source/WebCore/rendering/line/LineLayoutTraversal.h

    r250519 r252959  
    2626#pragma once
    2727
    28 #include "FloatRect.h"
    2928#include "InlineElementBox.h"
    30 #include "InlineTextBox.h"
     29#include "LineLayoutTraversalComplexPath.h"
     30#include "LineLayoutTraversalSimplePath.h"
    3131#include "RenderText.h"
    32 #include "SimpleLineLayoutResolver.h"
    3332#include <wtf/HashMap.h>
    3433#include <wtf/IteratorRange.h>
     
    3938
    4039class RenderLineBreak;
    41 class RenderText;
    4240
    4341namespace LineLayoutTraversal {
    4442
    45 class TextBoxContext;
     43class ElementBoxIterator;
    4644class TextBoxIterator;
    4745
    4846struct EndIterator { };
    4947
    50 template<class Iterator>
    5148class Box {
    5249public:
     50    using PathVariant = Variant<SimplePath, ComplexPath>;
     51
     52    Box(PathVariant&&);
     53
    5354    FloatRect rect() const;
    5455    FloatRect logicalRect() const;
     
    5960
    6061protected:
    61     Box() = default;
    62     Box(const Box&) = default;
    63     Box(Box&&) = default;
    64     ~Box() = default;
    65     Box& operator=(const Box&) = default;
    66     Box& operator=(Box&&) = default;
    67 
    68     const Iterator& iterator() const;
    69 };
    70 
    71 template<class Iterator>
    72 class TextBox : public Box<Iterator> {
    73 public:
     62    friend class ElementBoxIterator;
     63    friend class TextBoxIterator;
     64
     65    PathVariant m_pathVariant;
     66};
     67
     68class TextBox : public Box {
     69public:
     70    TextBox(PathVariant&&);
     71
    7472    bool hasHyphen() const;
    7573    StringView text() const;
     
    8280    bool isLastOnLine() const;
    8381    bool isLast() const;
    84 
    85 protected:
    86     TextBox() = default;
    87     TextBox(const TextBox&) = default;
    88     TextBox(TextBox&&) = default;
    89     ~TextBox() = default;
    90     TextBox& operator=(const TextBox&) = default;
    91     TextBox& operator=(TextBox&&) = default;
    92 
    93     using Box<Iterator>::iterator;
    94 };
    95 
    96 class TextBoxIterator : private TextBox<TextBoxIterator> {
    97 public:
    98     TextBoxIterator() : m_pathVariant(ComplexPath { nullptr, { } }) { };
     82};
     83
     84class TextBoxIterator {
     85public:
     86    TextBoxIterator() : m_textBox(ComplexPath { nullptr, { } }) { };
    9987
    10088    explicit TextBoxIterator(const InlineTextBox*);
     
    114102    bool operator!=(EndIterator) const { return !atEnd(); }
    115103
    116     const TextBox& operator*() const { return *this; }
    117     const TextBox* operator->() const { return this; }
     104    const TextBox& operator*() const { return m_textBox; }
     105    const TextBox* operator->() const { return &m_textBox; }
    118106
    119107    bool atEnd() const;
    120108
    121     using BoxType = TextBox<TextBoxIterator>;
    122 
    123109private:
    124     friend class Box<TextBoxIterator>;
    125     friend class TextBox<TextBoxIterator>;
    126 
    127     struct SimplePath {
    128         SimpleLineLayout::RunResolver::Iterator iterator;
    129         SimpleLineLayout::RunResolver::Iterator end;
    130     };
    131     struct ComplexPath {
    132         const InlineTextBox* inlineBox;
    133         Vector<const InlineTextBox*> sortedInlineTextBoxes;
    134         size_t sortedInlineTextBoxIndex { 0 };
    135 
    136         const InlineTextBox* nextInlineTextBoxInTextOrder() const;
    137     };
    138     Variant<SimplePath, ComplexPath> m_pathVariant;
    139 };
    140 
    141 class ElementBoxIterator : private Box<ElementBoxIterator> {
    142 public:
    143     ElementBoxIterator() : m_pathVariant(ComplexPath { nullptr }) { };
     110    TextBox m_textBox;
     111};
     112
     113class ElementBoxIterator {
     114public:
     115    ElementBoxIterator() : m_box(ComplexPath { nullptr, { } }) { };
    144116
    145117    explicit ElementBoxIterator(const InlineElementBox*);
     
    148120    explicit operator bool() const { return !atEnd(); }
    149121
    150     const Box& operator*() const { return *this; }
    151     const Box* operator->() const { return this; }
     122    const Box& operator*() const { return m_box; }
     123    const Box* operator->() const { return &m_box; }
    152124
    153125    bool atEnd() const;
    154126
    155     using BoxType = Box<ElementBoxIterator>;
    156 
    157127private:
    158     friend class Box<ElementBoxIterator>;
    159 
    160     struct SimplePath {
    161         SimpleLineLayout::RunResolver::Iterator iterator;
    162         SimpleLineLayout::RunResolver::Iterator end;
    163     };
    164     struct ComplexPath {
    165         const InlineElementBox* inlineBox;
    166     };
    167     Variant<SimplePath, ComplexPath> m_pathVariant;
     128    Box m_box;
    168129};
    169130
     
    189150// -----------------------------------------------
    190151
    191 template<class Iterator> inline FloatRect Box<Iterator>::rect() const
    192 {
    193     auto simple = [](const typename Iterator::SimplePath& path) {
    194         return (*path.iterator).rect();
    195     };
    196 
    197     auto complex = [](const typename Iterator::ComplexPath& path) {
    198         return path.inlineBox->frameRect();
    199     };
    200 
    201     return WTF::switchOn(iterator().m_pathVariant, simple, complex);
    202 }
    203 
    204 template<class Iterator> inline FloatRect Box<Iterator>::logicalRect() const
    205 {
    206     auto simple = [](const typename Iterator::SimplePath& path) {
    207         return (*path.iterator).rect();
    208     };
    209 
    210     auto complex = [](const typename Iterator::ComplexPath& path) {
    211         return path.inlineBox->logicalFrameRect();
    212     };
    213 
    214     return WTF::switchOn(iterator().m_pathVariant, simple, complex);
    215 }
    216 
    217 template<class Iterator> inline bool Box<Iterator>::isLeftToRightDirection() const
    218 {
    219     auto simple = [](const typename Iterator::SimplePath&) {
    220         return true;
    221     };
    222 
    223     auto complex = [](const typename Iterator::ComplexPath& path) {
    224         return path.inlineBox->isLeftToRightDirection();
    225     };
    226 
    227     return WTF::switchOn(iterator().m_pathVariant, simple, complex);
    228 }
    229 
    230 template<class Iterator> inline bool Box<Iterator>::dirOverride() const
    231 {
    232     auto simple = [](const typename Iterator::SimplePath&) {
    233         return false;
    234     };
    235 
    236     auto complex = [](const typename Iterator::ComplexPath& path) {
    237         return path.inlineBox->dirOverride();
    238     };
    239 
    240     return WTF::switchOn(iterator().m_pathVariant, simple, complex);
    241 }
    242 
    243 template<class Iterator> inline bool Box<Iterator>::isLineBreak() const
    244 {
    245     auto simple = [](const typename Iterator::SimplePath& path) {
    246         return (*path.iterator).isLineBreak();
    247     };
    248 
    249     auto complex = [](const typename Iterator::ComplexPath& path) {
    250         return path.inlineBox->isLineBreak();
    251     };
    252 
    253     return WTF::switchOn(iterator().m_pathVariant, simple, complex);
    254 }
    255 
    256 template<class Iterator> inline const Iterator& Box<Iterator>::iterator() const
    257 {
    258     return static_cast<const Iterator&>(*this);
    259 }
    260 
    261 template<class Iterator> inline bool TextBox<Iterator>::hasHyphen() const
    262 {
    263     auto simple = [](const typename Iterator::SimplePath& path) {
    264         return (*path.iterator).hasHyphen();
    265     };
    266 
    267     auto complex = [](const typename Iterator::ComplexPath& path) {
    268         return path.inlineBox->hasHyphen();
    269     };
    270 
    271     return WTF::switchOn(iterator().m_pathVariant, simple, complex);
    272 }
    273 
    274 template<class Iterator> inline StringView TextBox<Iterator>::text() const
    275 {
    276     auto simple = [](const typename Iterator::SimplePath& path) {
    277         return (*path.iterator).text();
    278     };
    279 
    280     auto complex = [](const typename Iterator::ComplexPath& path) {
    281         return StringView(path.inlineBox->renderer().text()).substring(path.inlineBox->start(), path.inlineBox->len());
    282     };
    283 
    284     return WTF::switchOn(iterator().m_pathVariant, simple, complex);
    285 }
    286 
    287 template<class Iterator> inline unsigned TextBox<Iterator>::localStartOffset() const
    288 {
    289     auto simple = [](const typename Iterator::SimplePath& path) {
    290         return (*path.iterator).localStart();
    291     };
    292 
    293     auto complex = [](const typename Iterator::ComplexPath& path) {
    294         return path.inlineBox->start();
    295     };
    296 
    297     return WTF::switchOn(iterator().m_pathVariant, simple, complex);
    298 }
    299 
    300 template<class Iterator> inline unsigned TextBox<Iterator>::localEndOffset() const
    301 {
    302     auto simple = [](const typename Iterator::SimplePath& path) {
    303         return (*path.iterator).localEnd();
    304     };
    305 
    306     auto complex = [](const typename Iterator::ComplexPath& path) {
    307         return path.inlineBox->end();
    308     };
    309 
    310     return WTF::switchOn(iterator().m_pathVariant, simple, complex);
    311 }
    312 
    313 template<class Iterator> inline unsigned TextBox<Iterator>::length() const
    314 {
    315     auto simple = [](const typename Iterator::SimplePath& path) {
    316         return (*path.iterator).end() - (*path.iterator).start();
    317     };
    318 
    319     auto complex = [](const typename Iterator::ComplexPath& path) {
    320         return path.inlineBox->len();
    321     };
    322 
    323     return WTF::switchOn(iterator().m_pathVariant, simple, complex);
    324 }
    325 
    326 template<class Iterator> inline bool TextBox<Iterator>::isLastOnLine() const
    327 {
    328     auto simple = [](const typename Iterator::SimplePath& path) {
    329         auto next = path.iterator;
    330         ++next;
    331         return next == path.end || (*path.iterator).lineIndex() != (*next).lineIndex();
    332     };
    333 
    334     auto complex = [](const typename Iterator::ComplexPath& path) {
    335         auto* next = path.nextInlineTextBoxInTextOrder();
    336         return !next || &path.inlineBox->root() != &next->root();
    337     };
    338 
    339     return WTF::switchOn(iterator().m_pathVariant, simple, complex);
    340 }
    341 
    342 template<class Iterator> inline bool TextBox<Iterator>::isLast() const
    343 {
    344     auto simple = [](const typename Iterator::SimplePath& path) {
    345         auto next = path.iterator;
    346         ++next;
    347         return next == path.end;
    348     };
    349 
    350     auto complex = [](const typename Iterator::ComplexPath& path) {
    351         return !path.nextInlineTextBoxInTextOrder();
    352     };
    353 
    354     return WTF::switchOn(iterator().m_pathVariant, simple, complex);
    355 }
    356 
    357 }
    358 }
     152inline Box::Box(PathVariant&& path)
     153    : m_pathVariant(WTFMove(path))
     154{
     155}
     156
     157inline FloatRect Box::rect() const
     158{
     159    return WTF::switchOn(m_pathVariant, [](auto& path) {
     160        return path.rect();
     161    });
     162}
     163
     164inline FloatRect Box::logicalRect() const
     165{
     166    return WTF::switchOn(m_pathVariant, [](auto& path) {
     167        return path.logicalRect();
     168    });
     169}
     170
     171inline bool Box::isLeftToRightDirection() const
     172{
     173    return WTF::switchOn(m_pathVariant, [](auto& path) {
     174        return path.isLeftToRightDirection();
     175    });
     176}
     177
     178inline bool Box::dirOverride() const
     179{
     180    return WTF::switchOn(m_pathVariant, [](auto& path) {
     181        return path.dirOverride();
     182    });
     183}
     184
     185inline bool Box::isLineBreak() const
     186{
     187    return WTF::switchOn(m_pathVariant, [](auto& path) {
     188        return path.isLineBreak();
     189    });
     190}
     191
     192inline bool TextBox::hasHyphen() const
     193{
     194    return WTF::switchOn(m_pathVariant, [](auto& path) {
     195        return path.hasHyphen();
     196    });
     197}
     198
     199inline TextBox::TextBox(PathVariant&& path)
     200    : Box(WTFMove(path))
     201{
     202}
     203
     204inline StringView TextBox::text() const
     205{
     206    return WTF::switchOn(m_pathVariant, [](auto& path) {
     207        return path.text();
     208    });
     209}
     210
     211inline unsigned TextBox::localStartOffset() const
     212{
     213    return WTF::switchOn(m_pathVariant, [](auto& path) {
     214        return path.localStartOffset();
     215    });
     216}
     217
     218inline unsigned TextBox::localEndOffset() const
     219{
     220    return WTF::switchOn(m_pathVariant, [](auto& path) {
     221        return path.localEndOffset();
     222    });
     223}
     224
     225inline unsigned TextBox::length() const
     226{
     227    return WTF::switchOn(m_pathVariant, [](auto& path) {
     228        return path.length();
     229    });
     230}
     231
     232inline bool TextBox::isLastOnLine() const
     233{
     234    return WTF::switchOn(m_pathVariant, [](auto& path) {
     235        return path.isLastOnLine();
     236    });
     237}
     238
     239inline bool TextBox::isLast() const
     240{
     241    return WTF::switchOn(m_pathVariant, [](auto& path) {
     242        return path.isLast();
     243    });
     244}
     245
     246}
     247}
Note: See TracChangeset for help on using the changeset viewer.