Changeset 252959 in webkit
- Timestamp:
- Nov 30, 2019 8:30:54 AM (4 years ago)
- Location:
- trunk/Source/WebCore
- Files:
-
- 2 added
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WebCore/ChangeLog
r252958 r252959 1 2019-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 1 102 2019-11-30 Zalan Bujtas <zalan@apple.com> 2 103 -
trunk/Source/WebCore/Headers.cmake
r252839 r252959 1321 1321 1322 1322 rendering/line/LineLayoutTraversal.h 1323 rendering/line/LineLayoutTraversalComplexPath.h 1324 rendering/line/LineLayoutTraversalSimplePath.h 1323 1325 rendering/line/LineWidth.h 1324 1326 rendering/line/TrailingObjects.h -
trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj
r252893 r252959 4795 4795 E42E76DC1C7AF77600E3614D /* StyleUpdate.h in Headers */ = {isa = PBXBuildFile; fileRef = E42E76DB1C7AF77600E3614D /* StyleUpdate.h */; }; 4796 4796 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, ); }; }; 4797 4799 E43A023B17EB370A004CDD25 /* RenderElement.h in Headers */ = {isa = PBXBuildFile; fileRef = E43A023A17EB370A004CDD25 /* RenderElement.h */; settings = {ATTRIBUTES = (Private, ); }; }; 4798 4800 E43AF8E71AC5B7EC00CA717E /* CacheValidation.h in Headers */ = {isa = PBXBuildFile; fileRef = E43AF8E51AC5B7DD00CA717E /* CacheValidation.h */; settings = {ATTRIBUTES = (Private, ); }; }; … … 15108 15110 E43105B716750F0C00DB2FB8 /* NodeTraversal.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = NodeTraversal.cpp; sourceTree = "<group>"; }; 15109 15111 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>"; }; 15110 15114 E43A023A17EB370A004CDD25 /* RenderElement.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RenderElement.h; sourceTree = "<group>"; }; 15111 15115 E43A023C17EB3713004CDD25 /* RenderElement.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = RenderElement.cpp; sourceTree = "<group>"; }; … … 28726 28730 E484A33D23055303009ADE6A /* LineLayoutTraversal.cpp */, 28727 28731 E484A33B23055303009ADE6A /* LineLayoutTraversal.h */, 28732 E4343D212392778300EBBB66 /* LineLayoutTraversalSimplePath.h */, 28733 E4343D242392778F00EBBB66 /* LineLayoutTraversalComplexPath.h */, 28728 28734 FFDBC046183D27B700407109 /* LineWidth.cpp */, 28729 28735 FFDBC045183D27B700407109 /* LineWidth.h */, … … 30536 30542 833B9E361F508D8500E0E428 /* JSFileSystemFileEntry.h in Headers */, 30537 30543 712BE4881FE8686A002031CC /* JSFillMode.h in Headers */, 30544 E4343D252392779000EBBB66 /* LineLayoutTraversalComplexPath.h in Headers */, 30538 30545 B6D9D27B14EAC0860090D75E /* JSFocusEvent.h in Headers */, 30539 30546 C280833F1C6DC26F001451B6 /* JSFontFace.h in Headers */, … … 31683 31690 57303BEF200980C600355965 /* PublicKeyCredentialDescriptor.h in Headers */, 31684 31691 57303C0A20099BAD00355965 /* PublicKeyCredentialRequestOptions.h in Headers */, 31692 E4343D232392778400EBBB66 /* LineLayoutTraversalSimplePath.h in Headers */, 31685 31693 57303BEB20097F4000355965 /* PublicKeyCredentialType.h in Headers */, 31686 31694 0081FF0016B0A2D3008AAA7A /* PublicSuffix.h in Headers */, -
trunk/Source/WebCore/rendering/RenderTreeAsText.cpp
r252724 r252959 478 478 } 479 479 480 static void writeTextBox(TextStream& ts, const RenderText& o, const LineLayoutTraversal::TextBox Iterator::BoxType& textBox)480 static void writeTextBox(TextStream& ts, const RenderText& o, const LineLayoutTraversal::TextBox& textBox) 481 481 { 482 482 auto rect = textBox.rect(); -
trunk/Source/WebCore/rendering/line/LineLayoutTraversal.cpp
r250519 r252959 33 33 34 34 TextBoxIterator::TextBoxIterator(const InlineTextBox* inlineTextBox) 35 : m_ pathVariant(ComplexPath { inlineTextBox, { } })35 : m_textBox(ComplexPath { inlineTextBox, { } }) 36 36 { 37 37 } 38 38 TextBoxIterator::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 }) 40 40 { 41 41 } 42 42 43 43 TextBoxIterator::TextBoxIterator(SimpleLineLayout::RunResolver::Iterator iterator, SimpleLineLayout::RunResolver::Iterator end) 44 : m_ pathVariant(SimplePath { iterator, end })44 : m_textBox(SimplePath { iterator, end }) 45 45 { 46 46 } … … 48 48 TextBoxIterator& TextBoxIterator::traverseNextInVisualOrder() 49 49 { 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 }); 60 53 return *this; 61 }62 63 const InlineTextBox* TextBoxIterator::ComplexPath::nextInlineTextBoxInTextOrder() const64 {65 if (!sortedInlineTextBoxes.isEmpty()) {66 if (sortedInlineTextBoxIndex + 1 < sortedInlineTextBoxes.size())67 return sortedInlineTextBoxes[sortedInlineTextBoxIndex + 1];68 return nullptr;69 }70 return inlineBox->nextTextBox();71 54 } 72 55 73 56 TextBoxIterator& TextBoxIterator::traverseNextInTextOrder() 74 57 { 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 }); 87 61 return *this; 88 62 } … … 90 64 bool TextBoxIterator::operator==(const TextBoxIterator& other) const 91 65 { 92 if (m_ pathVariant.index() != other.m_pathVariant.index())66 if (m_textBox.m_pathVariant.index() != other.m_textBox.m_pathVariant.index()) 93 67 return false; 94 68 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 }); 104 72 } 105 73 106 74 bool TextBoxIterator::atEnd() const 107 75 { 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 }); 117 79 } 118 80 … … 146 108 147 109 ElementBoxIterator::ElementBoxIterator(const InlineElementBox* inlineElementBox) 148 : m_ pathVariant(ComplexPath { inlineElementBox})110 : m_box(ComplexPath { inlineElementBox, { } }) 149 111 { 150 112 } 151 113 ElementBoxIterator::ElementBoxIterator(SimpleLineLayout::RunResolver::Iterator iterator, SimpleLineLayout::RunResolver::Iterator end) 152 : m_ pathVariant(SimplePath { iterator, end })114 : m_box(SimplePath { iterator, end }) 153 115 { 154 116 } … … 156 118 bool ElementBoxIterator::atEnd() const 157 119 { 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 }); 167 123 } 168 124 -
trunk/Source/WebCore/rendering/line/LineLayoutTraversal.h
r250519 r252959 26 26 #pragma once 27 27 28 #include "FloatRect.h"29 28 #include "InlineElementBox.h" 30 #include "InlineTextBox.h" 29 #include "LineLayoutTraversalComplexPath.h" 30 #include "LineLayoutTraversalSimplePath.h" 31 31 #include "RenderText.h" 32 #include "SimpleLineLayoutResolver.h"33 32 #include <wtf/HashMap.h> 34 33 #include <wtf/IteratorRange.h> … … 39 38 40 39 class RenderLineBreak; 41 class RenderText;42 40 43 41 namespace LineLayoutTraversal { 44 42 45 class TextBoxContext;43 class ElementBoxIterator; 46 44 class TextBoxIterator; 47 45 48 46 struct EndIterator { }; 49 47 50 template<class Iterator>51 48 class Box { 52 49 public: 50 using PathVariant = Variant<SimplePath, ComplexPath>; 51 52 Box(PathVariant&&); 53 53 54 FloatRect rect() const; 54 55 FloatRect logicalRect() const; … … 59 60 60 61 protected: 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 68 class TextBox : public Box { 69 public: 70 TextBox(PathVariant&&); 71 74 72 bool hasHyphen() const; 75 73 StringView text() const; … … 82 80 bool isLastOnLine() const; 83 81 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 84 class TextBoxIterator { 85 public: 86 TextBoxIterator() : m_textBox(ComplexPath { nullptr, { } }) { }; 99 87 100 88 explicit TextBoxIterator(const InlineTextBox*); … … 114 102 bool operator!=(EndIterator) const { return !atEnd(); } 115 103 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; } 118 106 119 107 bool atEnd() const; 120 108 121 using BoxType = TextBox<TextBoxIterator>;122 123 109 private: 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 113 class ElementBoxIterator { 114 public: 115 ElementBoxIterator() : m_box(ComplexPath { nullptr, { } }) { }; 144 116 145 117 explicit ElementBoxIterator(const InlineElementBox*); … … 148 120 explicit operator bool() const { return !atEnd(); } 149 121 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; } 152 124 153 125 bool atEnd() const; 154 126 155 using BoxType = Box<ElementBoxIterator>;156 157 127 private: 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; 168 129 }; 169 130 … … 189 150 // ----------------------------------------------- 190 151 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 } 152 inline Box::Box(PathVariant&& path) 153 : m_pathVariant(WTFMove(path)) 154 { 155 } 156 157 inline FloatRect Box::rect() const 158 { 159 return WTF::switchOn(m_pathVariant, [](auto& path) { 160 return path.rect(); 161 }); 162 } 163 164 inline FloatRect Box::logicalRect() const 165 { 166 return WTF::switchOn(m_pathVariant, [](auto& path) { 167 return path.logicalRect(); 168 }); 169 } 170 171 inline bool Box::isLeftToRightDirection() const 172 { 173 return WTF::switchOn(m_pathVariant, [](auto& path) { 174 return path.isLeftToRightDirection(); 175 }); 176 } 177 178 inline bool Box::dirOverride() const 179 { 180 return WTF::switchOn(m_pathVariant, [](auto& path) { 181 return path.dirOverride(); 182 }); 183 } 184 185 inline bool Box::isLineBreak() const 186 { 187 return WTF::switchOn(m_pathVariant, [](auto& path) { 188 return path.isLineBreak(); 189 }); 190 } 191 192 inline bool TextBox::hasHyphen() const 193 { 194 return WTF::switchOn(m_pathVariant, [](auto& path) { 195 return path.hasHyphen(); 196 }); 197 } 198 199 inline TextBox::TextBox(PathVariant&& path) 200 : Box(WTFMove(path)) 201 { 202 } 203 204 inline StringView TextBox::text() const 205 { 206 return WTF::switchOn(m_pathVariant, [](auto& path) { 207 return path.text(); 208 }); 209 } 210 211 inline unsigned TextBox::localStartOffset() const 212 { 213 return WTF::switchOn(m_pathVariant, [](auto& path) { 214 return path.localStartOffset(); 215 }); 216 } 217 218 inline unsigned TextBox::localEndOffset() const 219 { 220 return WTF::switchOn(m_pathVariant, [](auto& path) { 221 return path.localEndOffset(); 222 }); 223 } 224 225 inline unsigned TextBox::length() const 226 { 227 return WTF::switchOn(m_pathVariant, [](auto& path) { 228 return path.length(); 229 }); 230 } 231 232 inline bool TextBox::isLastOnLine() const 233 { 234 return WTF::switchOn(m_pathVariant, [](auto& path) { 235 return path.isLastOnLine(); 236 }); 237 } 238 239 inline 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.