Changeset 256304 in webkit
- Timestamp:
- Feb 11, 2020 7:13:15 AM (4 years ago)
- Location:
- trunk/Source/WebCore
- Files:
-
- 20 edited
- 1 copied
- 1 moved
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WebCore/ChangeLog
r256301 r256304 1 2020-02-11 Zalan Bujtas <zalan@apple.com> 2 3 [LFC] Introduce Layout::InlineTextBox 4 https://bugs.webkit.org/show_bug.cgi?id=207530 5 <rdar://problem/59336020> 6 7 Reviewed by Antti Koivisto. 8 9 Any text that is directly contained inside a block container element (not inside an inline element) must be treated as an anonymous inline element. 10 11 * Sources.txt: 12 * layout/Verification.cpp: 13 (WebCore::Layout::checkForMatchingTextRuns): 14 * layout/inlineformatting/InlineFormattingContext.cpp: 15 (WebCore::Layout::InlineFormattingContext::collectInlineContentIfNeeded): 16 * layout/inlineformatting/InlineLineBreaker.cpp: 17 (WebCore::Layout::LineBreaker::tryBreakingTextRun const): 18 * layout/inlineformatting/InlineLineBuilder.cpp: 19 (WebCore::Layout::m_textContext): 20 * layout/inlineformatting/InlineSoftLineBreakItem.h: 21 (WebCore::Layout::InlineSoftLineBreakItem::createSoftLineBreakItem): 22 (WebCore::Layout::InlineSoftLineBreakItem::InlineSoftLineBreakItem): 23 * layout/inlineformatting/InlineTextItem.cpp: 24 (WebCore::Layout::InlineTextItem::createAndAppendTextItems): 25 (WebCore::Layout::InlineTextItem::isEmptyContent const): 26 * layout/inlineformatting/InlineTextItem.h: 27 (WebCore::Layout::InlineTextItem::inlineTextBox const): 28 (WebCore::Layout::InlineTextItem::createWhitespaceItem): 29 (WebCore::Layout::InlineTextItem::createNonWhitespaceItem): 30 (WebCore::Layout::InlineTextItem::createEmptyItem): 31 (WebCore::Layout::InlineTextItem::InlineTextItem): 32 (WebCore::Layout::InlineTextItem::left const): 33 (WebCore::Layout::InlineTextItem::right const): 34 * layout/inlineformatting/LineLayoutContext.cpp: 35 (WebCore::Layout::endsWithSoftWrapOpportunity): 36 * layout/inlineformatting/text/TextUtil.cpp: 37 (WebCore::Layout::TextUtil::width): 38 (WebCore::Layout::TextUtil::split): 39 * layout/inlineformatting/text/TextUtil.h: 40 * layout/integration/LayoutIntegrationBoxTree.cpp: 41 (WebCore::LayoutIntegration::BoxTree::buildTree): 42 * layout/layouttree/LayoutBox.cpp: 43 (WebCore::Layout::Box::Box): 44 (): Deleted. 45 * layout/layouttree/LayoutBox.h: 46 (WebCore::Layout::Box::isInlineTextBox const): 47 (WebCore::Layout::Box::hasTextContent const): Deleted. 48 (WebCore::Layout::Box::textContext const): Deleted. 49 * layout/layouttree/LayoutContainer.cpp: 50 (WebCore::Layout::Container::Container): 51 (): Deleted. 52 * layout/layouttree/LayoutInlineTextBox.cpp: Copied from Source/WebCore/layout/layouttree/TextContext.h. 53 (WebCore::Layout::InlineTextBox::InlineTextBox): 54 (WebCore::Layout::m_canUseSimplifiedContentMeasuring): 55 * layout/layouttree/LayoutInlineTextBox.h: Renamed from Source/WebCore/layout/layouttree/TextContext.h. 56 (WebCore::Layout::InlineTextBox::content const): 57 (WebCore::Layout::InlineTextBox::canUseSimplifiedContentMeasuring const): 58 * layout/layouttree/LayoutTreeBuilder.cpp: 59 (WebCore::Layout::TreeBuilder::createTextBox): 60 (WebCore::Layout::TreeBuilder::createLayoutBox): 61 (WebCore::Layout::outputLayoutBox): 62 * layout/layouttree/LayoutTreeBuilder.h: 63 1 64 2020-02-11 Carlos Garcia Campos <cgarcia@igalia.com> 2 65 -
trunk/Source/WebCore/Headers.cmake
r256196 r256304 687 687 layout/layouttree/LayoutBox.h 688 688 layout/layouttree/LayoutReplaced.h 689 layout/layouttree/TextContext.h690 689 691 690 loader/AdClickAttribution.h -
trunk/Source/WebCore/Sources.txt
r256196 r256304 1452 1452 layout/layouttree/LayoutBox.cpp 1453 1453 layout/layouttree/LayoutContainer.cpp 1454 layout/layouttree/LayoutInlineTextBox.cpp 1454 1455 layout/layouttree/LayoutReplaced.cpp 1455 1456 layout/layouttree/LayoutTreeBuilder.cpp -
trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj
r256196 r256304 380 380 11310CF720BA4A620065A8D0 /* LayoutAncestorIterator.h in Headers */ = {isa = PBXBuildFile; fileRef = 11100FCA2092868D0081AA6C /* LayoutAncestorIterator.h */; settings = {ATTRIBUTES = (Private, ); }; }; 381 381 113409DA203E038000C66915 /* RenderTreeBuilderContinuation.h in Headers */ = {isa = PBXBuildFile; fileRef = 113409D8203E038000C66915 /* RenderTreeBuilderContinuation.h */; }; 382 113A3CB42385860100AE3ECE /* TextContext.h in Headers */ = {isa = PBXBuildFile; fileRef = 113A3CB22385860000AE3ECE /* TextContext.h */; settings = {ATTRIBUTES = (Private, ); }; };383 382 113D0B521F9FDD2B00F611BB /* FrameViewLayoutContext.h in Headers */ = {isa = PBXBuildFile; fileRef = 113D0B501F9FDD2B00F611BB /* FrameViewLayoutContext.h */; settings = {ATTRIBUTES = (Private, ); }; }; 384 383 115CFA6A208AF7D0001E6991 /* FormattingContext.h in Headers */ = {isa = PBXBuildFile; fileRef = 115CFA68208AF7D0001E6991 /* FormattingContext.h */; settings = {ATTRIBUTES = (Private, ); }; }; … … 2051 2050 6ED8C37A183BFF8C009E53BD /* BoxShape.h in Headers */ = {isa = PBXBuildFile; fileRef = 6ED8C378183BFF8C009E53BD /* BoxShape.h */; settings = {ATTRIBUTES = (Private, ); }; }; 2052 2051 6EE8A77310F803F3005A4A24 /* JSWebGLContextAttributes.h in Headers */ = {isa = PBXBuildFile; fileRef = 6EE8A77110F803F3005A4A24 /* JSWebGLContextAttributes.h */; }; 2052 6F0B98B523F268EC00EEC2F2 /* LayoutInlineTextBox.h in Headers */ = {isa = PBXBuildFile; fileRef = 6F0B98B323F268EB00EEC2F2 /* LayoutInlineTextBox.h */; settings = {ATTRIBUTES = (Private, ); }; }; 2053 2053 6F0CD695229ED32700C5994E /* InlineLineBuilder.h in Headers */ = {isa = PBXBuildFile; fileRef = 6F0CD694229ED32700C5994E /* InlineLineBuilder.h */; }; 2054 2054 6F1CC1DE225F8B4900720AD2 /* InlineTextItem.h in Headers */ = {isa = PBXBuildFile; fileRef = 6F1CC1DD225F8B4200720AD2 /* InlineTextItem.h */; settings = {ATTRIBUTES = (Private, ); }; }; … … 5916 5916 113409D7203E038000C66915 /* RenderTreeBuilderContinuation.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = RenderTreeBuilderContinuation.cpp; sourceTree = "<group>"; }; 5917 5917 113409D8203E038000C66915 /* RenderTreeBuilderContinuation.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = RenderTreeBuilderContinuation.h; sourceTree = "<group>"; }; 5918 113A3CB22385860000AE3ECE /* TextContext.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = TextContext.h; sourceTree = "<group>"; };5919 5918 113D0B4F1F9FDD2B00F611BB /* FrameViewLayoutContext.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = FrameViewLayoutContext.cpp; sourceTree = "<group>"; }; 5920 5919 113D0B501F9FDD2B00F611BB /* FrameViewLayoutContext.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = FrameViewLayoutContext.h; sourceTree = "<group>"; }; … … 9295 9294 6EE8A77110F803F3005A4A24 /* JSWebGLContextAttributes.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = JSWebGLContextAttributes.h; sourceTree = "<group>"; }; 9296 9295 6F0830DF20B46951008A945B /* BlockFormattingContextGeometry.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = BlockFormattingContextGeometry.cpp; sourceTree = "<group>"; }; 9296 6F0B98B323F268EB00EEC2F2 /* LayoutInlineTextBox.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = LayoutInlineTextBox.h; sourceTree = "<group>"; }; 9297 6F0B98B623F2690600EEC2F2 /* LayoutInlineTextBox.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = LayoutInlineTextBox.cpp; sourceTree = "<group>"; }; 9297 9298 6F0CD692229ED31900C5994E /* InlineLineBuilder.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = InlineLineBuilder.cpp; sourceTree = "<group>"; }; 9298 9299 6F0CD694229ED32700C5994E /* InlineLineBuilder.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = InlineLineBuilder.h; sourceTree = "<group>"; }; … … 16744 16745 1199FA44208E35A3002358CC /* LayoutContainer.h */, 16745 16746 11B042FB20B0E21400828A6B /* LayoutDescendantIterator.h */, 16747 6F0B98B623F2690600EEC2F2 /* LayoutInlineTextBox.cpp */, 16748 6F0B98B323F268EB00EEC2F2 /* LayoutInlineTextBox.h */, 16746 16749 11100FC72092764C0081AA6C /* LayoutIterator.h */, 16747 16750 111C615720AD1AE1005B82FA /* LayoutReplaced.cpp */, … … 16749 16752 11100FD5209514DE0081AA6C /* LayoutTreeBuilder.cpp */, 16750 16753 11100FD7209514DF0081AA6C /* LayoutTreeBuilder.h */, 16751 113A3CB22385860000AE3ECE /* TextContext.h */,16752 16754 ); 16753 16755 path = layouttree; … … 31302 31304 6F26BB6C23343E6F002F2BEA /* LayoutContext.h in Headers */, 31303 31305 11310CF520BA4A4C0065A8D0 /* LayoutDescendantIterator.h in Headers */, 31306 6F0B98B523F268EC00EEC2F2 /* LayoutInlineTextBox.h in Headers */, 31304 31307 E418025523D4549B00FFB071 /* LayoutIntegrationBoxTree.h in Headers */, 31305 31308 E4ABABDD236088FE00FA4345 /* LayoutIntegrationLineLayout.h in Headers */, … … 32699 32702 B2C3DA420D006C1D00EF6F26 /* TextCodecUTF16.h in Headers */, 32700 32703 9343CB8212F25E510033C5EE /* TextCodecUTF8.h in Headers */, 32701 113A3CB42385860100AE3ECE /* TextContext.h in Headers */,32702 32704 142B97CA13138943008BEF4B /* TextControlInnerElements.h in Headers */, 32703 32705 582DE3251C30C85400BE02A8 /* TextDecorationPainter.h in Headers */, -
trunk/Source/WebCore/layout/Verification.cpp
r255143 r256304 126 126 127 127 128 static bool checkForMatchingTextRuns(const Display::Run& inlineRun, const InlineTextBox& inlineTextBox)128 static bool checkForMatchingTextRuns(const Display::Run& inlineRun, const WebCore::InlineTextBox& inlineTextBox) 129 129 { 130 130 return areEssentiallyEqual(inlineTextBox.left(), inlineRun.left()) -
trunk/Source/WebCore/layout/inlineformatting/InlineFormattingContext.cpp
r256101 r256304 37 37 #include "LayoutContainer.h" 38 38 #include "LayoutContext.h" 39 #include "LayoutInlineTextBox.h" 39 40 #include "LayoutState.h" 40 41 #include "Logging.h" … … 339 340 formattingState.addInlineItem({ layoutBox, InlineItem::Type::Box }); 340 341 else if (layoutBox.isAnonymous()) { 341 ASSERT(layoutBox. hasTextContent());342 InlineTextItem::createAndAppendTextItems(formattingState.inlineItems(), layoutBox);342 ASSERT(layoutBox.isInlineTextBox()); 343 InlineTextItem::createAndAppendTextItems(formattingState.inlineItems(), downcast<InlineTextBox>(layoutBox)); 343 344 } else if (layoutBox.isInlineBox()) 344 345 formattingState.addInlineItem({ layoutBox, InlineItem::Type::ContainerEnd }); -
trunk/Source/WebCore/layout/inlineformatting/InlineLineBreaker.cpp
r254661 r256304 314 314 } 315 315 // FIXME: Pass in the content logical left to be able to measure tabs. 316 auto splitData = TextUtil::split(inlineTextItem. layoutBox(), inlineTextItem.start(), inlineTextItem.length(), overflowRun.logicalWidth, availableWidth, { });316 auto splitData = TextUtil::split(inlineTextItem.inlineTextBox(), inlineTextItem.start(), inlineTextItem.length(), overflowRun.logicalWidth, availableWidth, { }); 317 317 return PartialRun { splitData.length, splitData.logicalWidth, false }; 318 318 } … … 337 337 if (availableWidthExcludingHyphen <= 0 || !enoughWidthForHyphenation(availableWidthExcludingHyphen, fontCascade.pixelSize())) 338 338 return { }; 339 leftSideLength = TextUtil::split(inlineTextItem. layoutBox(), inlineTextItem.start(), runLength, overflowRun.logicalWidth, availableWidthExcludingHyphen, { }).length;339 leftSideLength = TextUtil::split(inlineTextItem.inlineTextBox(), inlineTextItem.start(), runLength, overflowRun.logicalWidth, availableWidthExcludingHyphen, { }).length; 340 340 } 341 341 if (leftSideLength < limitBefore) 342 342 return { }; 343 auto textContent = inlineTextItem.layoutBox().textContext()->content;344 343 // Adjust before index to accommodate the limit-after value (it's the last potential hyphen location in this run). 345 344 auto hyphenBefore = std::min(leftSideLength, runLength - limitAfter) + 1; 346 unsigned hyphenLocation = lastHyphenLocation(StringView( textContent).substring(inlineTextItem.start(), inlineTextItem.length()), hyphenBefore, style.locale());345 unsigned hyphenLocation = lastHyphenLocation(StringView(inlineTextItem.inlineTextBox().content()).substring(inlineTextItem.start(), inlineTextItem.length()), hyphenBefore, style.locale()); 347 346 if (!hyphenLocation || hyphenLocation < limitBefore) 348 347 return { }; -
trunk/Source/WebCore/layout/inlineformatting/InlineLineBuilder.cpp
r255257 r256304 751 751 , m_layoutBox(&softLineBreakItem.layoutBox()) 752 752 , m_logicalRect({ 0, logicalLeft, 0, 0 }) 753 , m_textContext({ softLineBreakItem.position(), 1, softLineBreakItem. layoutBox().textContext()->content})753 , m_textContext({ softLineBreakItem.position(), 1, softLineBreakItem.inlineTextBox().content() }) 754 754 { 755 755 } … … 760 760 , m_logicalRect({ 0, logicalLeft, logicalWidth, 0 }) 761 761 , m_trailingWhitespaceType(trailingWhitespaceType(inlineTextItem)) 762 , m_textContext({ inlineTextItem.start(), m_trailingWhitespaceType == TrailingWhitespace::Collapsed ? 1 : inlineTextItem.length(), inlineTextItem. layoutBox().textContext()->content})762 , m_textContext({ inlineTextItem.start(), m_trailingWhitespaceType == TrailingWhitespace::Collapsed ? 1 : inlineTextItem.length(), inlineTextItem.inlineTextBox().content() }) 763 763 { 764 764 if (m_trailingWhitespaceType != TrailingWhitespace::None) { -
trunk/Source/WebCore/layout/inlineformatting/InlineSoftLineBreakItem.h
r254749 r256304 35 35 class InlineSoftLineBreakItem : public InlineItem { 36 36 public: 37 static InlineSoftLineBreakItem createSoftLineBreakItem(const Box&, unsigned position);37 static InlineSoftLineBreakItem createSoftLineBreakItem(const InlineTextBox&, unsigned position); 38 38 39 39 unsigned position() const { return m_startOrPosition; } 40 const InlineTextBox& inlineTextBox() const { return downcast<InlineTextBox>(layoutBox()); } 40 41 41 InlineSoftLineBreakItem(const Box&, unsigned position);42 InlineSoftLineBreakItem(const InlineTextBox&, unsigned position); 42 43 }; 43 44 44 inline InlineSoftLineBreakItem InlineSoftLineBreakItem::createSoftLineBreakItem(const Box& inlineBox, unsigned position)45 inline InlineSoftLineBreakItem InlineSoftLineBreakItem::createSoftLineBreakItem(const InlineTextBox& inlineTextBox, unsigned position) 45 46 { 46 return { inline Box, position };47 return { inlineTextBox, position }; 47 48 } 48 49 49 inline InlineSoftLineBreakItem::InlineSoftLineBreakItem(const Box& inlineBox, unsigned position)50 : InlineItem(inline Box, Type::SoftLineBreak)50 inline InlineSoftLineBreakItem::InlineSoftLineBreakItem(const InlineTextBox& inlineTextBox, unsigned position) 51 : InlineItem(inlineTextBox, Type::SoftLineBreak) 51 52 { 52 53 m_startOrPosition = position; -
trunk/Source/WebCore/layout/inlineformatting/InlineTextItem.cpp
r254754 r256304 66 66 } 67 67 68 void InlineTextItem::createAndAppendTextItems(InlineItems& inlineContent, const Box& inlineBox)68 void InlineTextItem::createAndAppendTextItems(InlineItems& inlineContent, const InlineTextBox& inlineTextBox) 69 69 { 70 auto& textContext = *inlineBox.textContext(); 71 auto text = textContext.content; 70 auto text = inlineTextBox.content(); 72 71 if (!text.length()) 73 return inlineContent.append(InlineTextItem::createEmptyItem(inline Box));72 return inlineContent.append(InlineTextItem::createEmptyItem(inlineTextBox)); 74 73 75 auto& style = inline Box.style();74 auto& style = inlineTextBox.style(); 76 75 auto& font = style.fontCascade(); 77 76 LazyLineBreakIterator lineBreakIterator(text); … … 79 78 80 79 auto inlineItemWidth = [&](auto startPosition, auto length) -> Optional<InlineLayoutUnit> { 81 if (! textContext.canUseSimplifiedContentMeasuring)80 if (!inlineTextBox.canUseSimplifiedContentMeasuring()) 82 81 return { }; 83 return TextUtil::width(inline Box, startPosition, startPosition + length);82 return TextUtil::width(inlineTextBox, startPosition, startPosition + length); 84 83 }; 85 84 … … 91 90 // Segment breaks with preserve new line style (white-space: pre, pre-wrap, break-spaces and pre-line) compute to forced line break. 92 91 if (isSegmentBreakCandidate(text[currentPosition]) && style.preserveNewline()) { 93 inlineContent.append(InlineSoftLineBreakItem::createSoftLineBreakItem(inline Box, currentPosition));92 inlineContent.append(InlineSoftLineBreakItem::createSoftLineBreakItem(inlineTextBox, currentPosition)); 94 93 ++currentPosition; 95 94 continue; … … 98 97 if (isWhitespaceCharacter(text[currentPosition], style.preserveNewline())) { 99 98 auto appendWhitespaceItem = [&] (auto startPosition, auto itemLength) { 100 auto simpleSingleWhitespaceContent = textContext.canUseSimplifiedContentMeasuring&& (itemLength == 1 || style.collapseWhiteSpace());99 auto simpleSingleWhitespaceContent = inlineTextBox.canUseSimplifiedContentMeasuring() && (itemLength == 1 || style.collapseWhiteSpace()); 101 100 auto width = simpleSingleWhitespaceContent ? makeOptional(InlineLayoutUnit { font.spaceWidth() }) : inlineItemWidth(startPosition, itemLength); 102 inlineContent.append(InlineTextItem::createWhitespaceItem(inline Box, startPosition, itemLength, width));101 inlineContent.append(InlineTextItem::createWhitespaceItem(inlineTextBox, startPosition, itemLength, width)); 103 102 }; 104 103 … … 117 116 118 117 auto length = moveToNextBreakablePosition(currentPosition, lineBreakIterator, style); 119 inlineContent.append(InlineTextItem::createNonWhitespaceItem(inline Box, currentPosition, length, inlineItemWidth(currentPosition, length)));118 inlineContent.append(InlineTextItem::createNonWhitespaceItem(inlineTextBox, currentPosition, length, inlineItemWidth(currentPosition, length))); 120 119 currentPosition += length; 121 120 } … … 125 124 { 126 125 // FIXME: We should check for more zero width content and not just U+200B. 127 return !m_length || (m_length == 1 && layoutBox().textContext()->content[start()] == zeroWidthSpace);126 return !m_length || (m_length == 1 && inlineTextBox().content()[start()] == zeroWidthSpace); 128 127 } 129 128 -
trunk/Source/WebCore/layout/inlineformatting/InlineTextItem.h
r254754 r256304 30 30 #include "InlineFormattingState.h" 31 31 #include "InlineItem.h" 32 #include "LayoutInlineTextBox.h" 32 33 33 34 namespace WebCore { … … 36 37 class InlineTextItem : public InlineItem { 37 38 public: 38 static void createAndAppendTextItems(InlineItems&, const Box&);39 static void createAndAppendTextItems(InlineItems&, const InlineTextBox&); 39 40 40 41 unsigned start() const { return m_startOrPosition; } … … 47 48 bool isEmptyContent() const; 48 49 50 const InlineTextBox& inlineTextBox() const { return downcast<InlineTextBox>(layoutBox()); } 51 49 52 InlineTextItem left(unsigned length) const; 50 53 InlineTextItem right(unsigned length) const; … … 53 56 using InlineItem::TextItemType; 54 57 55 InlineTextItem(const Box&, unsigned start, unsigned length, Optional<InlineLayoutUnit> width, TextItemType);56 InlineTextItem(const Box&);58 InlineTextItem(const InlineTextBox&, unsigned start, unsigned length, Optional<InlineLayoutUnit> width, TextItemType); 59 InlineTextItem(const InlineTextBox&); 57 60 58 static InlineTextItem createWhitespaceItem(const Box&, unsigned start, unsigned length, Optional<InlineLayoutUnit> width);59 static InlineTextItem createNonWhitespaceItem(const Box&, unsigned start, unsigned length, Optional<InlineLayoutUnit> width);60 static InlineTextItem createEmptyItem(const Box&);61 static InlineTextItem createWhitespaceItem(const InlineTextBox&, unsigned start, unsigned length, Optional<InlineLayoutUnit> width); 62 static InlineTextItem createNonWhitespaceItem(const InlineTextBox&, unsigned start, unsigned length, Optional<InlineLayoutUnit> width); 63 static InlineTextItem createEmptyItem(const InlineTextBox&); 61 64 }; 62 65 63 inline InlineTextItem InlineTextItem::createWhitespaceItem(const Box& inlineBox, unsigned start, unsigned length, Optional<InlineLayoutUnit> width)66 inline InlineTextItem InlineTextItem::createWhitespaceItem(const InlineTextBox& inlineTextBox, unsigned start, unsigned length, Optional<InlineLayoutUnit> width) 64 67 { 65 return { inline Box, start, length, width, TextItemType::Whitespace };68 return { inlineTextBox, start, length, width, TextItemType::Whitespace }; 66 69 } 67 70 68 inline InlineTextItem InlineTextItem::createNonWhitespaceItem(const Box& inlineBox, unsigned start, unsigned length, Optional<InlineLayoutUnit> width)71 inline InlineTextItem InlineTextItem::createNonWhitespaceItem(const InlineTextBox& inlineTextBox, unsigned start, unsigned length, Optional<InlineLayoutUnit> width) 69 72 { 70 return { inline Box, start, length, width, TextItemType::NonWhitespace };73 return { inlineTextBox, start, length, width, TextItemType::NonWhitespace }; 71 74 } 72 75 73 inline InlineTextItem InlineTextItem::createEmptyItem(const Box& inlineBox)76 inline InlineTextItem InlineTextItem::createEmptyItem(const InlineTextBox& inlineTextBox) 74 77 { 75 return { inline Box };78 return { inlineTextBox }; 76 79 } 77 80 78 inline InlineTextItem::InlineTextItem(const Box& inlineBox, unsigned start, unsigned length, Optional<InlineLayoutUnit> width, TextItemType textItemType)79 : InlineItem(inline Box, Type::Text)81 inline InlineTextItem::InlineTextItem(const InlineTextBox& inlineTextBox, unsigned start, unsigned length, Optional<InlineLayoutUnit> width, TextItemType textItemType) 82 : InlineItem(inlineTextBox, Type::Text) 80 83 { 81 84 m_startOrPosition = start; 82 85 m_length = length; 83 86 m_hasWidth = !!width; 84 m_isCollapsible = textItemType == TextItemType::Whitespace && inline Box.style().collapseWhiteSpace();87 m_isCollapsible = textItemType == TextItemType::Whitespace && inlineTextBox.style().collapseWhiteSpace(); 85 88 m_width = width.valueOr(0); 86 89 m_textItemType = textItemType; 87 90 } 88 91 89 inline InlineTextItem::InlineTextItem(const Box& inlineBox)90 : InlineItem(inline Box, Type::Text)92 inline InlineTextItem::InlineTextItem(const InlineTextBox& inlineTextBox) 93 : InlineItem(inlineTextBox, Type::Text) 91 94 { 92 95 } … … 97 100 ASSERT(m_textItemType != TextItemType::Undefined); 98 101 ASSERT(length); 99 return { layoutBox(), start(), length, WTF::nullopt, m_textItemType };102 return { inlineTextBox(), start(), length, WTF::nullopt, m_textItemType }; 100 103 } 101 104 … … 105 108 ASSERT(m_textItemType != TextItemType::Undefined); 106 109 ASSERT(length); 107 return { layoutBox(), end() - length, length, WTF::nullopt, m_textItemType };110 return { inlineTextBox(), end() - length, length, WTF::nullopt, m_textItemType }; 108 111 } 109 112 -
trunk/Source/WebCore/layout/inlineformatting/LineLayoutContext.cpp
r255273 r256304 44 44 // When both these non-whitespace runs belong to the same layout box, it's guaranteed that 45 45 // they are split at a soft breaking opportunity. See InlineTextItem::moveToNextBreakablePosition. 46 if (¤tTextItem. layoutBox() == &nextInlineTextItem.layoutBox())46 if (¤tTextItem.inlineTextBox() == &nextInlineTextItem.inlineTextBox()) 47 47 return true; 48 48 // Now we need to collect at least 3 adjacent characters to be able to make a decision whether the previous text item ends with breaking opportunity. 49 49 // [ex-][ample] <- second to last[x] last[-] current[a] 50 50 // We need at least 1 character in the current inline text item and 2 more from previous inline items. 51 auto previousContent = currentTextItem. layoutBox().textContext()->content;52 auto lineBreakIterator = LazyLineBreakIterator { nextInlineTextItem. layoutBox().textContext()->content};51 auto previousContent = currentTextItem.inlineTextBox().content(); 52 auto lineBreakIterator = LazyLineBreakIterator { nextInlineTextItem.inlineTextBox().content() }; 53 53 auto previousContentLength = previousContent.length(); 54 54 // FIXME: We should look into the entire uncommitted content for more text context. -
trunk/Source/WebCore/layout/inlineformatting/text/TextUtil.cpp
r254750 r256304 32 32 #include "FontCascade.h" 33 33 #include "InlineTextItem.h" 34 #include "LayoutInlineTextBox.h" 34 35 #include "RenderBox.h" 35 36 #include "RenderStyle.h" … … 45 46 return font.spaceWidth() + font.wordSpacing(); 46 47 } 47 return TextUtil::width(inlineTextItem. layoutBox(), from, to, contentLogicalLeft);48 return TextUtil::width(inlineTextItem.inlineTextBox(), from, to, contentLogicalLeft); 48 49 } 49 50 50 InlineLayoutUnit TextUtil::width(const Box& inlineBox, unsigned from, unsigned to, InlineLayoutUnit contentLogicalLeft)51 InlineLayoutUnit TextUtil::width(const InlineTextBox& inlineTextBox, unsigned from, unsigned to, InlineLayoutUnit contentLogicalLeft) 51 52 { 52 auto& style = inline Box.style();53 auto& style = inlineTextBox.style(); 53 54 auto& font = style.fontCascade(); 54 55 if (!font.size() || from == to) 55 56 return 0; 56 57 57 auto& textContext = *inlineBox.textContext(); 58 auto& text = textContext.content; 58 auto text = inlineTextBox.content(); 59 59 ASSERT(to <= text.length()); 60 60 auto hasKerningOrLigatures = font.enableKerning() || font.requiresShaping(); … … 63 63 ++to; 64 64 float width = 0; 65 if ( textContext.canUseSimplifiedContentMeasuring) {65 if (inlineTextBox.canUseSimplifiedContentMeasuring()) { 66 66 if (font.isFixedPitch()) 67 67 width = fixedPitchWidth(text, style, from, to, contentLogicalLeft); … … 101 101 } 102 102 103 TextUtil::SplitData TextUtil::split(const Box& inlineBox, unsigned startPosition, unsigned length, InlineLayoutUnit textWidth, InlineLayoutUnit availableWidth, InlineLayoutUnit contentLogicalLeft)103 TextUtil::SplitData TextUtil::split(const InlineTextBox& inlineTextBox, unsigned startPosition, unsigned length, InlineLayoutUnit textWidth, InlineLayoutUnit availableWidth, InlineLayoutUnit contentLogicalLeft) 104 104 { 105 105 ASSERT(availableWidth >= 0); … … 114 114 while (left < right) { 115 115 auto middle = (left + right) / 2; 116 auto width = TextUtil::width(inline Box, startPosition, middle + 1, contentLogicalLeft);116 auto width = TextUtil::width(inlineTextBox, startPosition, middle + 1, contentLogicalLeft); 117 117 if (width < availableWidth) { 118 118 left = middle + 1; -
trunk/Source/WebCore/layout/inlineformatting/text/TextUtil.h
r254750 r256304 38 38 namespace Layout { 39 39 40 class InlineTextBox; 40 41 class InlineTextItem; 41 42 … … 43 44 public: 44 45 static InlineLayoutUnit width(const InlineTextItem&, unsigned from, unsigned to, InlineLayoutUnit contentLogicalLeft = 0); 45 static InlineLayoutUnit width(const Box&, unsigned from, unsigned to, InlineLayoutUnit contentLogicalLeft = 0);46 static InlineLayoutUnit width(const InlineTextBox&, unsigned from, unsigned to, InlineLayoutUnit contentLogicalLeft = 0); 46 47 struct SplitData { 47 48 unsigned start { 0 }; … … 49 50 InlineLayoutUnit logicalWidth { 0 }; 50 51 }; 51 static SplitData split(const Box&, unsigned startPosition, unsigned length, InlineLayoutUnit textWidth, InlineLayoutUnit availableWidth, InlineLayoutUnit contentLogicalLeft);52 static SplitData split(const InlineTextBox&, unsigned startPosition, unsigned length, InlineLayoutUnit textWidth, InlineLayoutUnit availableWidth, InlineLayoutUnit contentLogicalLeft); 52 53 static bool shouldPreserveTrailingWhitespace(const RenderStyle&); 53 54 static unsigned findNextBreakablePosition(LazyLineBreakIterator&, unsigned startPosition, const RenderStyle&); -
trunk/Source/WebCore/layout/integration/LayoutIntegrationBoxTree.cpp
r254825 r256304 59 59 if (is<RenderText>(childRenderer)) { 60 60 auto& textRenderer = downcast<RenderText>(childRenderer); 61 auto textContent = Layout::TextContext { textRenderer.text(), textRenderer.canUseSimplifiedTextMeasuring() }; 62 childBox = makeUnique<Layout::Box>(WTFMove(textContent), RenderStyle::createAnonymousStyleWithDisplay(m_root.style(), DisplayType::Inline)); 63 childBox->setIsAnonymous(); 61 childBox = makeUnique<Layout::InlineTextBox>(textRenderer.text(), textRenderer.canUseSimplifiedTextMeasuring(), RenderStyle::createAnonymousStyleWithDisplay(m_root.style(), DisplayType::Inline)); 64 62 } else if (childRenderer.isLineBreak()) { 65 63 auto clonedStyle = RenderStyle::clone(childRenderer.style()); -
trunk/Source/WebCore/layout/layouttree/LayoutBox.cpp
r256098 r256304 41 41 WTF_MAKE_ISO_ALLOCATED_IMPL(Box); 42 42 43 Box::Box(Optional<ElementAttributes> attributes, Optional<TextContext> textContext,RenderStyle&& style, BaseTypeFlags baseTypeFlags)43 Box::Box(Optional<ElementAttributes> attributes, RenderStyle&& style, BaseTypeFlags baseTypeFlags) 44 44 : m_style(WTFMove(style)) 45 45 , m_elementAttributes(attributes) 46 , m_textContext(textContext)47 46 , m_baseTypeFlags(baseTypeFlags) 48 47 , m_hasRareData(false) … … 54 53 55 54 Box::Box(Optional<ElementAttributes> attributes, RenderStyle&& style) 56 : Box(attributes, { }, WTFMove(style), BaseTypeFlag::BoxFlag) 57 { 58 } 59 60 Box::Box(TextContext&& textContext, RenderStyle&& style) 61 : Box({ }, WTFMove(textContext), WTFMove(style), BaseTypeFlag::BoxFlag) 62 { 63 ASSERT(isInlineLevelBox()); 55 : Box(attributes, WTFMove(style), BaseTypeFlag::BoxFlag) 56 { 64 57 } 65 58 -
trunk/Source/WebCore/layout/layouttree/LayoutBox.h
r256098 r256304 30 30 #include "LayoutReplaced.h" 31 31 #include "RenderStyle.h" 32 #include "TextContext.h"33 32 #include <wtf/IsoMalloc.h> 34 33 #include <wtf/WeakPtr.h> … … 65 64 66 65 enum BaseTypeFlag { 67 BoxFlag = 1 << 0, 68 ContainerFlag = 1 << 1 66 BoxFlag = 1 << 0, 67 InlineTextBox = 1 << 1, 68 ContainerFlag = 1 << 2 69 69 }; 70 70 typedef unsigned BaseTypeFlags; 71 71 72 72 Box(Optional<ElementAttributes>, RenderStyle&&); 73 Box(TextContext&&, RenderStyle&&); 74 ~Box(); 73 virtual ~Box(); 75 74 76 75 bool establishesFormattingContext() const; … … 143 142 144 143 bool isContainer() const { return m_baseTypeFlags & ContainerFlag; } 144 bool isInlineTextBox() const { return m_baseTypeFlags & InlineTextBox; } 145 145 146 146 bool isPaddingApplicable() const; … … 153 153 // FIXME: Temporary until after intrinsic size change is tracked by Replaced. 154 154 Replaced* replaced(); 155 bool hasTextContent() const { return !!m_textContext; }156 const Optional<TextContext>& textContext() const { return m_textContext; }157 155 158 156 // FIXME: Find a better place for random DOM things. … … 177 175 178 176 protected: 179 Box(Optional<ElementAttributes>, Optional<TextContext>,RenderStyle&&, BaseTypeFlags);177 Box(Optional<ElementAttributes>, RenderStyle&&, BaseTypeFlags); 180 178 181 179 private: … … 208 206 Box* m_nextSibling { nullptr }; 209 207 210 const Optional<TextContext> m_textContext;211 212 208 // First LayoutState gets a direct cache. 213 209 mutable WeakPtr<LayoutState> m_cachedLayoutState; -
trunk/Source/WebCore/layout/layouttree/LayoutContainer.cpp
r254806 r256304 38 38 39 39 Container::Container(Optional<ElementAttributes> attributes, RenderStyle&& style, BaseTypeFlags baseTypeFlags) 40 : Box(attributes, { },WTFMove(style), baseTypeFlags | ContainerFlag)40 : Box(attributes, WTFMove(style), baseTypeFlags | ContainerFlag) 41 41 { 42 42 } -
trunk/Source/WebCore/layout/layouttree/LayoutInlineTextBox.cpp
r256303 r256304 1 1 /* 2 * Copyright (C) 20 19Apple Inc. All rights reserved.2 * Copyright (C) 2020 Apple Inc. All rights reserved. 3 3 * 4 4 * Redistribution and use in source and binary forms, with or without … … 24 24 */ 25 25 26 #pragma once 26 #include "config.h" 27 #include "LayoutInlineTextBox.h" 27 28 28 29 #if ENABLE(LAYOUT_FORMATTING_CONTEXT) 29 30 30 #include <wtf/text/StringView.h> 31 #include "RenderStyle.h" 32 #include <wtf/IsoMallocInlines.h> 31 33 32 34 namespace WebCore { 33 35 namespace Layout { 34 36 35 struct TextContext { 36 WTF_MAKE_FAST_ALLOCATED; 37 public: 38 String content; 39 bool canUseSimplifiedContentMeasuring { false }; 40 }; 37 WTF_MAKE_ISO_ALLOCATED_IMPL(InlineTextBox); 38 39 InlineTextBox::InlineTextBox(String content, bool canUseSimplifiedContentMeasuring, RenderStyle&& style) 40 : Box({ }, WTFMove(style), Box::InlineTextBox) 41 , m_content(content) 42 , m_canUseSimplifiedContentMeasuring(canUseSimplifiedContentMeasuring) 43 { 44 setIsAnonymous(); 45 } 41 46 42 47 } 43 48 } 49 44 50 #endif -
trunk/Source/WebCore/layout/layouttree/LayoutInlineTextBox.h
r256303 r256304 1 1 /* 2 * Copyright (C) 20 19Apple Inc. All rights reserved.2 * Copyright (C) 2020 Apple Inc. All rights reserved. 3 3 * 4 4 * Redistribution and use in source and binary forms, with or without … … 28 28 #if ENABLE(LAYOUT_FORMATTING_CONTEXT) 29 29 30 #include <wtf/text/StringView.h> 30 #include "LayoutBox.h" 31 #include <wtf/IsoMalloc.h> 31 32 32 33 namespace WebCore { 34 33 35 namespace Layout { 34 36 35 struct TextContext{36 WTF_MAKE_ FAST_ALLOCATED;37 class InlineTextBox : public Box { 38 WTF_MAKE_ISO_ALLOCATED(InlineTextBox); 37 39 public: 38 String content; 39 bool canUseSimplifiedContentMeasuring { false }; 40 InlineTextBox(String, bool canUseSimplifiedContentMeasuring, RenderStyle&&); 41 virtual ~InlineTextBox() = default; 42 43 String content() const { return m_content; } 44 // FIXME: This should not be a box's property. 45 bool canUseSimplifiedContentMeasuring() const { return m_canUseSimplifiedContentMeasuring; } 46 47 private: 48 String m_content; 49 bool m_canUseSimplifiedContentMeasuring { false }; 40 50 }; 41 51 42 52 } 43 53 } 54 55 SPECIALIZE_TYPE_TRAITS_LAYOUT_BOX(InlineTextBox, isInlineTextBox()) 56 44 57 #endif -
trunk/Source/WebCore/layout/layouttree/LayoutTreeBuilder.cpp
r255257 r256304 43 43 #include "LayoutContext.h" 44 44 #include "LayoutDescendantIterator.h" 45 #include "LayoutInlineTextBox.h" 45 46 #include "LayoutPhase.h" 46 47 #include "LayoutSize.h" … … 151 152 } 152 153 153 Box& TreeBuilder::createTextBox( TextContext&& textContent, RenderStyle&& style)154 { 155 auto newBox = makeUnique< Box>(WTFMove(textContent), WTFMove(style));154 Box& TreeBuilder::createTextBox(String text, bool canUseSimplifiedTextMeasuring, RenderStyle&& style) 155 { 156 auto newBox = makeUnique<InlineTextBox>(text, canUseSimplifiedTextMeasuring, WTFMove(style)); 156 157 auto& box = *newBox; 157 158 m_layoutTreeContent.addBox(WTFMove(newBox)); … … 192 193 // RenderText::text() has already applied text-transform and text-security properties. 193 194 String text = textRenderer.text(); 194 auto textContent = TextContext { text, canUseSimplifiedTextMeasuring(text, parentContainer.style().fontCascade(), parentContainer.style().collapseWhiteSpace()) };195 auto useSimplifiedTextMeasuring = canUseSimplifiedTextMeasuring(text, parentContainer.style().fontCascade(), parentContainer.style().collapseWhiteSpace()); 195 196 if (parentContainer.style().display() == DisplayType::Inline) 196 childLayoutBox = &createTextBox( WTFMove(textContent), RenderStyle::clone(parentContainer.style()));197 childLayoutBox = &createTextBox(text, useSimplifiedTextMeasuring, RenderStyle::clone(parentContainer.style())); 197 198 else 198 childLayoutBox = &createTextBox(WTFMove(textContent), RenderStyle::createAnonymousStyleWithDisplay(parentContainer.style(), DisplayType::Inline)); 199 childLayoutBox->setIsAnonymous(); 199 childLayoutBox = &createTextBox(text, useSimplifiedTextMeasuring, RenderStyle::createAnonymousStyleWithDisplay(parentContainer.style(), DisplayType::Inline)); 200 200 } else { 201 201 auto& renderer = downcast<RenderElement>(childRenderer); … … 407 407 stream << " at (" << displayBox->left() << "," << displayBox->top() << ") size " << displayBox->width() << "x" << displayBox->height(); 408 408 stream << " layout box->(" << &layoutBox << ")"; 409 if ( layoutBox.isInlineLevelBox() && layoutBox.isAnonymous())410 stream << " text content [\"" << layoutBox.textContext()->content.utf8().data() << "\"]";409 if (is<InlineTextBox>(layoutBox)) 410 stream << " text content [\"" << downcast<InlineTextBox>(layoutBox).content().utf8().data() << "\"]"; 411 411 412 412 stream.nextLine(); -
trunk/Source/WebCore/layout/layouttree/LayoutTreeBuilder.h
r254806 r256304 92 92 93 93 Box& createBox(Optional<Box::ElementAttributes>, RenderStyle&&); 94 Box& createTextBox( TextContext&&, RenderStyle&&);94 Box& createTextBox(String text, bool canUseSimplifiedTextMeasuring, RenderStyle&&); 95 95 Container& createContainer(Optional<Box::ElementAttributes>, RenderStyle&&); 96 96
Note: See TracChangeset
for help on using the changeset viewer.