Changeset 254875 in webkit
- Timestamp:
- Jan 21, 2020 1:08:55 PM (4 years ago)
- Location:
- trunk/Source/WebCore
- Files:
-
- 12 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WebCore/ChangeLog
r254869 r254875 1 2020-01-21 Antti Koivisto <antti@apple.com> 2 3 [LFC] Typed accessors for formatting states 4 https://bugs.webkit.org/show_bug.cgi?id=206538 5 6 Reviewed by Zalan Bujtas. 7 8 Almost all clients know what sort of formatting state they want and immediately cast it. 9 10 * layout/FormattingContextGeometry.cpp: 11 (WebCore::Layout::FormattingContext::Geometry::contentHeightForFormattingContextRoot const): 12 (WebCore::Layout::FormattingContext::Geometry::shrinkToFitWidth): 13 * layout/LayoutContext.cpp: 14 (WebCore::Layout::LayoutContext::createFormattingContext): 15 * layout/LayoutState.cpp: 16 (WebCore::Layout::LayoutState::formattingStateForBox const): 17 (WebCore::Layout::LayoutState::establishedFormattingState const): 18 (WebCore::Layout::LayoutState::establishedInlineFormattingState const): 19 (WebCore::Layout::LayoutState::establishedBlockFormattingState const): 20 (WebCore::Layout::LayoutState::establishedTableFormattingState const): 21 22 Typed function for getting established states. 23 24 (WebCore::Layout::LayoutState::ensureFormattingState): 25 (WebCore::Layout::LayoutState::ensureInlineFormattingState): 26 27 Also add a fast path for integrated layout. 28 29 (WebCore::Layout::LayoutState::ensureBlockFormattingState): 30 (WebCore::Layout::LayoutState::ensureTableFormattingState): 31 32 Typed function for creating states. 33 34 (WebCore::Layout::LayoutState::createFormattingStateForFormattingRootIfNeeded): Deleted. 35 * layout/LayoutState.h: 36 (WebCore::Layout::LayoutState::hasInlineFormattingState const): 37 (WebCore::Layout::LayoutState::hasFormattingState const): Deleted. 38 * layout/blockformatting/BlockFormattingContextGeometry.cpp: 39 (WebCore::Layout::BlockFormattingContext::Geometry::inFlowNonReplacedHeightAndMargin): 40 * layout/blockformatting/BlockMarginCollapse.cpp: 41 (WebCore::Layout::BlockFormattingContext::MarginCollapse::marginsCollapseThrough const): 42 * layout/displaytree/DisplayPainter.cpp: 43 (WebCore::Display::paintSubtree): 44 (WebCore::Display::Painter::paintInlineFlow): 45 * layout/inlineformatting/InlineFormattingContextQuirks.cpp: 46 (WebCore::Layout::InlineFormattingContext::Quirks::lineDescentNeedsCollapsing const): 47 * layout/inlineformatting/InlineLineBuilder.cpp: 48 (WebCore::Layout::LineBuilder::alignContentVertically): 49 (WebCore::Layout::LineBuilder::adjustBaselineAndLineHeight): 50 * layout/integration/LayoutIntegrationLineLayout.cpp: 51 (WebCore::LayoutIntegration::LineLayout::LineLayout): 52 * layout/layouttree/LayoutTreeBuilder.cpp: 53 (WebCore::Layout::outputInlineRuns): 54 1 55 2020-01-21 Justin Fan <justin_fan@apple.com> 2 56 -
trunk/Source/WebCore/layout/FormattingContextGeometry.cpp
r254666 r254875 134 134 auto& formattingRootContainer = downcast<Container>(layoutBox); 135 135 if (formattingRootContainer.establishesInlineFormattingContext()) { 136 auto& lineBoxes = downcast<InlineFormattingState>(layoutState.establishedFormattingState(formattingRootContainer)).displayInlineContent()->lineBoxes;136 auto& lineBoxes = layoutState.establishedInlineFormattingState(formattingRootContainer).displayInlineContent()->lineBoxes; 137 137 // Even empty containers generate one line. 138 138 ASSERT(!lineBoxes.isEmpty()); … … 288 288 if (is<Container>(formattingRoot)) { 289 289 auto& root = downcast<Container>(formattingRoot); 290 auto& formattingStateForRoot = layoutState(). createFormattingStateForFormattingRootIfNeeded(root);290 auto& formattingStateForRoot = layoutState().ensureFormattingState(root); 291 291 auto precomputedIntrinsicWidthConstraints = formattingStateForRoot.intrinsicWidthConstraints(); 292 292 if (!precomputedIntrinsicWidthConstraints) -
trunk/Source/WebCore/layout/LayoutContext.cpp
r254853 r254875 114 114 ASSERT(formattingContextRoot.establishesFormattingContext()); 115 115 if (formattingContextRoot.establishesInlineFormattingContext()) { 116 auto& inlineFormattingState = downcast<InlineFormattingState>(layoutState.createFormattingStateForFormattingRootIfNeeded(formattingContextRoot));116 auto& inlineFormattingState = layoutState.ensureInlineFormattingState(formattingContextRoot); 117 117 return makeUnique<InlineFormattingContext>(formattingContextRoot, inlineFormattingState); 118 118 } … … 120 120 if (formattingContextRoot.establishesBlockFormattingContext()) { 121 121 ASSERT(formattingContextRoot.establishesBlockFormattingContextOnly()); 122 auto& blockFormattingState = downcast<BlockFormattingState>(layoutState.createFormattingStateForFormattingRootIfNeeded(formattingContextRoot));122 auto& blockFormattingState = layoutState.ensureBlockFormattingState(formattingContextRoot); 123 123 return makeUnique<BlockFormattingContext>(formattingContextRoot, blockFormattingState); 124 124 } 125 125 126 126 if (formattingContextRoot.establishesTableFormattingContext()) { 127 auto& tableFormattingState = downcast<TableFormattingState>(layoutState.createFormattingStateForFormattingRootIfNeeded(formattingContextRoot));127 auto& tableFormattingState = layoutState.ensureTableFormattingState(formattingContextRoot); 128 128 return makeUnique<TableFormattingContext>(formattingContextRoot, tableFormattingState); 129 129 } -
trunk/Source/WebCore/layout/LayoutState.cpp
r254808 r254875 85 85 FormattingState& LayoutState::formattingStateForBox(const Box& layoutBox) const 86 86 { 87 auto& root = layoutBox.formattingContextRoot(); 88 RELEASE_ASSERT(m_formattingStates.contains(&root)); 89 return *m_formattingStates.get(&root); 90 } 91 92 FormattingState& LayoutState::establishedFormattingState(const Container& formattingRoot) const 93 { 94 ASSERT(formattingRoot.establishesFormattingContext()); 95 RELEASE_ASSERT(m_formattingStates.contains(&formattingRoot)); 96 return *m_formattingStates.get(&formattingRoot); 97 } 98 99 FormattingState& LayoutState::createFormattingStateForFormattingRootIfNeeded(const Container& formattingContextRoot) 100 { 101 ASSERT(formattingContextRoot.establishesFormattingContext()); 102 103 if (formattingContextRoot.establishesInlineFormattingContext()) { 104 return *m_formattingStates.ensure(&formattingContextRoot, [&] { 105 106 // If the block container box that initiates this inline formatting context also establishes a block context, the floats outside of the formatting root 107 // should not interfere with the content inside. 108 // <div style="float: left"></div><div style="overflow: hidden"> <- is a non-intrusive float, because overflow: hidden triggers new block formatting context.</div> 109 if (formattingContextRoot.establishesBlockFormattingContext()) { 110 auto formattingState = makeUnique<InlineFormattingState>(FloatingState::create(*this, formattingContextRoot), *this); 111 m_inlineFormattingStates.append(WTFMove(formattingState)); 112 return m_inlineFormattingStates.last().get(); 113 } 114 115 // Otherwise, the formatting context inherits the floats from the parent formatting context. 116 // Find the formatting state in which this formatting root lives, not the one it creates and use its floating state. 117 auto& parentFormattingState = createFormattingStateForFormattingRootIfNeeded(formattingContextRoot.formattingContextRoot()); 118 auto& parentFloatingState = parentFormattingState.floatingState(); 119 auto formattingState = makeUnique<InlineFormattingState>(parentFloatingState, *this); 120 m_inlineFormattingStates.append(WTFMove(formattingState)); 121 return m_inlineFormattingStates.last().get(); 122 }).iterator->value; 123 } 124 125 if (formattingContextRoot.establishesBlockFormattingContext()) { 126 return *m_formattingStates.ensure(&formattingContextRoot, [&] { 127 128 // Block formatting context always establishes a new floating state. 129 auto formattingState = makeUnique<BlockFormattingState>(FloatingState::create(*this, formattingContextRoot), *this); 130 m_blockFormattingStates.append(WTFMove(formattingState)); 131 return m_blockFormattingStates.last().get(); 132 }).iterator->value; 133 } 134 135 if (formattingContextRoot.establishesTableFormattingContext()) { 136 return *m_formattingStates.ensure(&formattingContextRoot, [&] { 137 138 // Table formatting context always establishes a new floating state -and it stays empty. 139 auto formattingState = makeUnique<TableFormattingState>(FloatingState::create(*this, formattingContextRoot), *this); 140 m_tableFormattingStates.append(WTFMove(formattingState)); 141 return m_tableFormattingStates.last().get(); 142 }).iterator->value; 143 } 144 145 CRASH(); 87 return establishedFormattingState(layoutBox.formattingContextRoot()); 88 } 89 90 FormattingState& LayoutState::establishedFormattingState(const Container& formattingContextRoot) const 91 { 92 if (RuntimeEnabledFeatures::sharedFeatures().layoutFormattingContextIntegrationEnabled()) { 93 ASSERT(&formattingContextRoot == m_rootContainer.get()); 94 return *m_rootInlineFormattingStateForIntegration; 95 } 96 97 if (auto* formattingState = m_inlineFormattingStates.get(&formattingContextRoot)) 98 return *formattingState; 99 100 if (auto* formattingState = m_blockFormattingStates.get(&formattingContextRoot)) 101 return *formattingState; 102 103 ASSERT(m_tableFormattingStates.contains(&formattingContextRoot)); 104 return *m_tableFormattingStates.get(&formattingContextRoot); 105 } 106 107 InlineFormattingState& LayoutState::establishedInlineFormattingState(const Container& formattingContextRoot) const 108 { 109 ASSERT(formattingContextRoot.establishesInlineFormattingContext()); 110 111 if (RuntimeEnabledFeatures::sharedFeatures().layoutFormattingContextIntegrationEnabled()) { 112 ASSERT(&formattingContextRoot == m_rootContainer.get()); 113 return *m_rootInlineFormattingStateForIntegration; 114 } 115 116 return *m_inlineFormattingStates.get(&formattingContextRoot); 117 } 118 119 BlockFormattingState& LayoutState::establishedBlockFormattingState(const Container& formattingContextRoot) const 120 { 121 ASSERT(formattingContextRoot.establishesBlockFormattingContext()); 122 return *m_blockFormattingStates.get(&formattingContextRoot); 123 } 124 125 TableFormattingState& LayoutState::establishedTableFormattingState(const Container& formattingContextRoot) const 126 { 127 ASSERT(formattingContextRoot.establishesTableFormattingContext()); 128 return *m_tableFormattingStates.get(&formattingContextRoot); 129 } 130 131 FormattingState& LayoutState::ensureFormattingState(const Container& formattingContextRoot) 132 { 133 if (formattingContextRoot.establishesInlineFormattingContext()) 134 return ensureInlineFormattingState(formattingContextRoot); 135 136 if (formattingContextRoot.establishesBlockFormattingContext()) 137 return ensureBlockFormattingState(formattingContextRoot); 138 139 return ensureTableFormattingState(formattingContextRoot); 140 } 141 142 InlineFormattingState& LayoutState::ensureInlineFormattingState(const Container& formattingContextRoot) 143 { 144 ASSERT(formattingContextRoot.establishesInlineFormattingContext()); 145 146 auto create = [&] { 147 // If the block container box that initiates this inline formatting context also establishes a block context, the floats outside of the formatting root 148 // should not interfere with the content inside. 149 // <div style="float: left"></div><div style="overflow: hidden"> <- is a non-intrusive float, because overflow: hidden triggers new block formatting context.</div> 150 if (formattingContextRoot.establishesBlockFormattingContext()) 151 return makeUnique<InlineFormattingState>(FloatingState::create(*this, formattingContextRoot), *this); 152 153 // Otherwise, the formatting context inherits the floats from the parent formatting context. 154 // Find the formatting state in which this formatting root lives, not the one it creates and use its floating state. 155 auto& parentFormattingState = ensureFormattingState(formattingContextRoot.formattingContextRoot()); 156 auto& parentFloatingState = parentFormattingState.floatingState(); 157 return makeUnique<InlineFormattingState>(parentFloatingState, *this); 158 }; 159 160 if (RuntimeEnabledFeatures::sharedFeatures().layoutFormattingContextIntegrationEnabled()) { 161 if (!m_rootInlineFormattingStateForIntegration) { 162 ASSERT(&formattingContextRoot == m_rootContainer.get()); 163 m_rootInlineFormattingStateForIntegration = create(); 164 } 165 return *m_rootInlineFormattingStateForIntegration; 166 } 167 168 return *m_inlineFormattingStates.ensure(&formattingContextRoot, create).iterator->value; 169 } 170 171 BlockFormattingState& LayoutState::ensureBlockFormattingState(const Container& formattingContextRoot) 172 { 173 ASSERT(formattingContextRoot.establishesBlockFormattingContext()); 174 175 auto create = [&] { 176 return makeUnique<BlockFormattingState>(FloatingState::create(*this, formattingContextRoot), *this); 177 }; 178 179 return *m_blockFormattingStates.ensure(&formattingContextRoot, create).iterator->value; 180 } 181 182 TableFormattingState& LayoutState::ensureTableFormattingState(const Container& formattingContextRoot) 183 { 184 ASSERT(formattingContextRoot.establishesTableFormattingContext()); 185 186 auto create = [&] { 187 // Table formatting context always establishes a new floating state -and it stays empty. 188 return makeUnique<TableFormattingState>(FloatingState::create(*this, formattingContextRoot), *this); 189 }; 190 191 return *m_tableFormattingStates.ensure(&formattingContextRoot, create).iterator->value; 146 192 } 147 193 -
trunk/Source/WebCore/layout/LayoutState.h
r254808 r254875 54 54 ~LayoutState(); 55 55 56 FormattingState& createFormattingStateForFormattingRootIfNeeded(const Container& formattingContextRoot); 56 FormattingState& ensureFormattingState(const Container& formattingContextRoot); 57 InlineFormattingState& ensureInlineFormattingState(const Container& formattingContextRoot); 58 BlockFormattingState& ensureBlockFormattingState(const Container& formattingContextRoot); 59 TableFormattingState& ensureTableFormattingState(const Container& formattingContextRoot); 60 57 61 FormattingState& establishedFormattingState(const Container& formattingRoot) const; 62 InlineFormattingState& establishedInlineFormattingState(const Container& formattingContextRoot) const; 63 BlockFormattingState& establishedBlockFormattingState(const Container& formattingContextRoot) const; 64 TableFormattingState& establishedTableFormattingState(const Container& formattingContextRoot) const; 65 58 66 FormattingState& formattingStateForBox(const Box&) const; 59 bool has FormattingState(const Container& formattingRoot) const { return m_formattingStates.contains(&formattingRoot); }67 bool hasInlineFormattingState(const Container& formattingRoot) const { return m_inlineFormattingStates.contains(&formattingRoot); } 60 68 61 69 #ifndef NDEBUG … … 87 95 Display::Box& ensureDisplayBoxForLayoutBoxSlow(const Box&); 88 96 89 Vector<std::unique_ptr<InlineFormattingState>, 1> m_inlineFormattingStates;90 Vector<std::unique_ptr<BlockFormattingState>, 1> m_blockFormattingStates;91 Vector<std::unique_ptr<TableFormattingState>> m_tableFormattingStates;97 HashMap<const Container*, std::unique_ptr<InlineFormattingState>> m_inlineFormattingStates; 98 HashMap<const Container*, std::unique_ptr<BlockFormattingState>> m_blockFormattingStates; 99 HashMap<const Container*, std::unique_ptr<TableFormattingState>> m_tableFormattingStates; 92 100 93 HashMap<const Container*, FormattingState*> m_formattingStates; 101 std::unique_ptr<InlineFormattingState> m_rootInlineFormattingStateForIntegration; 102 94 103 #ifndef NDEBUG 95 104 HashSet<const FormattingContext*> m_formattingContextList; -
trunk/Source/WebCore/layout/blockformatting/BlockFormattingContextGeometry.cpp
r254666 r254875 75 75 auto& layoutContainer = downcast<Container>(layoutBox); 76 76 if (layoutContainer.establishesInlineFormattingContext()) { 77 auto& lineBoxes = downcast<InlineFormattingState>(layoutState().establishedFormattingState(layoutContainer)).displayInlineContent()->lineBoxes;77 auto& lineBoxes = layoutState().establishedInlineFormattingState(layoutContainer).displayInlineContent()->lineBoxes; 78 78 // Even empty containers generate one line. 79 79 ASSERT(!lineBoxes.isEmpty()); -
trunk/Source/WebCore/layout/blockformatting/BlockMarginCollapse.cpp
r254666 r254875 393 393 // we haven't started laying it out yet. 394 394 auto& layoutContainer = downcast<Container>(layoutBox); 395 if (!layoutState.has FormattingState(layoutContainer))395 if (!layoutState.hasInlineFormattingState(layoutContainer)) 396 396 return false; 397 397 398 398 auto isConsideredEmpty = [&] { 399 auto& formattingState = downcast<InlineFormattingState>(layoutState.establishedFormattingState(layoutContainer));399 auto& formattingState = layoutState.establishedInlineFormattingState(layoutContainer); 400 400 if (auto* inlineContent = formattingState.displayInlineContent()) { 401 401 for (auto& lineBox : inlineContent->lineBoxes) { -
trunk/Source/WebCore/layout/displaytree/DisplayPainter.cpp
r253912 r254875 184 184 if (layoutBox.establishesInlineFormattingContext()) { 185 185 auto& container = downcast<Layout::Container>(layoutBox); 186 paintInlineContent(context, absoluteDisplayBox.topLeft(), downcast<Layout::InlineFormattingState>(layoutState.establishedFormattingState(container)));186 paintInlineContent(context, absoluteDisplayBox.topLeft(), layoutState.establishedInlineFormattingState(container)); 187 187 } 188 188 }; … … 293 293 ASSERT(layoutRoot.establishesInlineFormattingContext()); 294 294 295 paintInlineContent(context, { }, downcast<Layout::InlineFormattingState>(layoutState.establishedFormattingState(layoutRoot)));295 paintInlineContent(context, { }, layoutState.establishedInlineFormattingState(layoutRoot)); 296 296 } 297 297 -
trunk/Source/WebCore/layout/inlineformatting/InlineFormattingContextQuirks.cpp
r254805 r254875 60 60 if (run.isBox()) { 61 61 if (layoutBox.isInlineBlockBox() && layoutBox.establishesInlineFormattingContext()) { 62 auto& formattingState = downcast<InlineFormattingState>(layoutState.establishedFormattingState(downcast<Container>(layoutBox)));62 auto& formattingState = layoutState.establishedInlineFormattingState(downcast<Container>(layoutBox)); 63 63 auto inlineBlockBaseline = formattingState.displayInlineContent()->lineBoxes.last().baseline(); 64 64 if (inlineBlockBaseline.descent()) -
trunk/Source/WebCore/layout/inlineformatting/InlineLineBuilder.cpp
r254827 r254875 156 156 logicalTop = baselineOffset() - ascent - boxGeometry.borderTop() - boxGeometry.paddingTop().valueOr(0); 157 157 } else if (layoutBox.isInlineBlockBox() && layoutBox.establishesInlineFormattingContext()) { 158 auto& formattingState = downcast<InlineFormattingState>(layoutState().establishedFormattingState(downcast<Container>(layoutBox)));158 auto& formattingState = layoutState().establishedInlineFormattingState(downcast<Container>(layoutBox)); 159 159 // Spec makes us generate at least one line -even if it is empty. 160 160 auto inlineBlockBaselineOffset = formattingState.displayInlineContent()->lineBoxes.last().baselineOffset(); … … 566 566 if (layoutBox.isInlineBlockBox() && layoutBox.establishesInlineFormattingContext()) { 567 567 // Inline-blocks with inline content always have baselines. 568 auto& formattingState = downcast<InlineFormattingState>(layoutState().establishedFormattingState(downcast<Container>(layoutBox)));568 auto& formattingState = layoutState().establishedInlineFormattingState(downcast<Container>(layoutBox)); 569 569 // Spec makes us generate at least one line -even if it is empty. 570 570 auto& lastLineBox = formattingState.displayInlineContent()->lineBoxes.last(); -
trunk/Source/WebCore/layout/integration/LayoutIntegrationLineLayout.cpp
r254853 r254875 56 56 , m_boxTree(flow) 57 57 , m_layoutState(m_flow.document(), rootLayoutBox()) 58 , m_inlineFormattingState( downcast<Layout::InlineFormattingState>(m_layoutState.createFormattingStateForFormattingRootIfNeeded(rootLayoutBox())))58 , m_inlineFormattingState(m_layoutState.ensureInlineFormattingState(rootLayoutBox())) 59 59 { 60 60 m_layoutState.setIsIntegratedRootBoxFirstChild(m_flow.parent()->firstChild() == &m_flow); -
trunk/Source/WebCore/layout/layouttree/LayoutTreeBuilder.cpp
r254806 r254875 316 316 static void outputInlineRuns(TextStream& stream, const LayoutState& layoutState, const Container& inlineFormattingRoot, unsigned depth) 317 317 { 318 auto& inlineFormattingState = downcast<InlineFormattingState>(layoutState.establishedFormattingState(inlineFormattingRoot));318 auto& inlineFormattingState = layoutState.establishedInlineFormattingState(inlineFormattingRoot); 319 319 auto* displayInlineContent = inlineFormattingState.displayInlineContent(); 320 320 if (!displayInlineContent)
Note: See TracChangeset
for help on using the changeset viewer.