Changeset 200593 in webkit
- Timestamp:
- May 9, 2016 2:57:43 PM (8 years ago)
- Location:
- trunk/Source/WebCore
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WebCore/ChangeLog
r200591 r200593 1 2016-05-09 Simon Fraser <simon.fraser@apple.com> 2 3 Clean up iOS text autosizing code 4 https://bugs.webkit.org/show_bug.cgi?id=157489 5 6 Reviewed by Zalan Bujtas. 7 8 Change the TraverseNextInclusionFunction and HeightTypeTraverseNextInclusionFunction 9 to take references. 10 11 Use downcast<> more. 12 13 Whitespace cleanup. 14 15 * rendering/RenderBlockFlow.cpp: 16 (WebCore::isNonBlocksOrNonFixedHeightListItems): 17 * rendering/RenderElement.cpp: 18 (WebCore::includeNonFixedHeight): 19 * rendering/RenderObject.cpp: 20 (WebCore::RenderObject::traverseNext): 21 * rendering/RenderObject.h: 22 * rendering/TextAutoSizing.cpp: 23 (WebCore::TextAutoSizingValue::adjustNodeSizes): 24 (WebCore::TextAutoSizingValue::reset): 25 1 26 2016-05-09 Anders Carlsson <andersca@apple.com> 2 27 -
trunk/Source/WebCore/rendering/RenderBlockFlow.cpp
r200534 r200593 3740 3740 } 3741 3741 3742 static bool isNonBlocksOrNonFixedHeightListItems(const RenderObject *render)3743 { 3744 if (!render ->isRenderBlock())3742 static bool isNonBlocksOrNonFixedHeightListItems(const RenderObject& render) 3743 { 3744 if (!render.isRenderBlock()) 3745 3745 return true; 3746 if (render ->isListItem())3747 return render ->style().height().type() != Fixed;3746 if (render.isListItem()) 3747 return render.style().height().type() != Fixed; 3748 3748 return false; 3749 3749 } … … 3791 3791 for (RenderObject* descendent = traverseNext(this, isNonBlocksOrNonFixedHeightListItems); descendent; descendent = descendent->traverseNext(this, isNonBlocksOrNonFixedHeightListItems)) { 3792 3792 if (isVisibleRenderText(descendent) && resizeTextPermitted(descendent)) { 3793 RenderText& text = downcast<RenderText>(*descendent);3793 auto& text = downcast<RenderText>(*descendent); 3794 3794 auto& oldStyle = text.style(); 3795 3795 auto fontDescription = oldStyle.fontDescription(); -
trunk/Source/WebCore/rendering/RenderElement.cpp
r200588 r200593 2170 2170 2171 2171 #if ENABLE(IOS_TEXT_AUTOSIZING) 2172 static RenderObject::BlockContentHeightType includeNonFixedHeight(const RenderObject *renderer)2173 { 2174 const RenderStyle& style = renderer ->style();2172 static RenderObject::BlockContentHeightType includeNonFixedHeight(const RenderObject& renderer) 2173 { 2174 const RenderStyle& style = renderer.style(); 2175 2175 if (style.height().type() == Fixed) { 2176 if (is<RenderBlock>( *renderer)) {2176 if (is<RenderBlock>(renderer)) { 2177 2177 // For fixed height styles, if the overflow size of the element spills out of the specified 2178 2178 // height, assume we can apply text auto-sizing. 2179 2179 if (style.overflowY() == OVISIBLE 2180 && style.height().value() < downcast<RenderBlock>(renderer) ->layoutOverflowRect().maxY())2180 && style.height().value() < downcast<RenderBlock>(renderer).layoutOverflowRect().maxY()) 2181 2181 return RenderObject::OverflowHeight; 2182 2182 } -
trunk/Source/WebCore/rendering/RenderObject.cpp
r200534 r200593 326 326 // Check for suitable children. 327 327 for (RenderObject* child = firstChildSlow(); child; child = child->nextSibling()) { 328 overflowType = inclusionFunction( child);328 overflowType = inclusionFunction(*child); 329 329 if (overflowType != FixedHeight) { 330 330 currentDepth++; … … 350 350 return nullptr; 351 351 for (RenderObject* sibling = n->nextSibling(); sibling; sibling = sibling->nextSibling()) { 352 overflowType = inclusionFunction( sibling);352 overflowType = inclusionFunction(*sibling); 353 353 if (overflowType != FixedHeight) { 354 354 if (overflowType == OverflowHeight) … … 370 370 { 371 371 for (RenderObject* child = firstChildSlow(); child; child = child->nextSibling()) { 372 if (inclusionFunction( child)) {372 if (inclusionFunction(*child)) { 373 373 ASSERT(!stayWithin || child->isDescendantOf(stayWithin)); 374 374 return child; … … 380 380 381 381 for (RenderObject* sibling = nextSibling(); sibling; sibling = sibling->nextSibling()) { 382 if (inclusionFunction( sibling)) {382 if (inclusionFunction(*sibling)) { 383 383 ASSERT(!stayWithin || sibling->isDescendantOf(stayWithin)); 384 384 return sibling; … … 392 392 if (n) { 393 393 for (RenderObject* sibling = n->nextSibling(); sibling; sibling = sibling->nextSibling()) { 394 if (inclusionFunction( sibling)) {394 if (inclusionFunction(*sibling)) { 395 395 ASSERT(!stayWithin || !n->nextSibling() || n->nextSibling()->isDescendantOf(stayWithin)); 396 396 return sibling; -
trunk/Source/WebCore/rendering/RenderObject.h
r200534 r200593 191 191 192 192 RenderObject* traverseNext(const RenderObject* stayWithin) const; 193 typedef bool (*TraverseNextInclusionFunction)(const RenderObject *);194 typedef BlockContentHeightType (*HeightTypeTraverseNextInclusionFunction)(const RenderObject *);193 typedef bool (*TraverseNextInclusionFunction)(const RenderObject&); 194 typedef BlockContentHeightType (*HeightTypeTraverseNextInclusionFunction)(const RenderObject&); 195 195 196 196 RenderObject* traverseNext(const RenderObject* stayWithin, TraverseNextInclusionFunction) const; -
trunk/Source/WebCore/rendering/TextAutoSizing.cpp
r200534 r200593 75 75 { 76 76 bool objectsRemoved = false; 77 77 78 78 // Remove stale nodes. Nodes may have had their renderers detached. We'll 79 79 // also need to remove the style from the documents m_textAutoSizedNodes … … 81 81 Vector<RefPtr<Node> > nodesForRemoval; 82 82 for (auto& autoSizingNode : m_autoSizedNodes) { 83 RenderText* text = static_cast<RenderText*>(autoSizingNode->renderer());83 auto* text = downcast<RenderText>(autoSizingNode->renderer()); 84 84 if (!text || !text->style().textSizeAdjust().isAuto() || !text->candidateComputedTextSize()) { 85 85 // remove node. … … 88 88 } 89 89 } 90 90 91 91 for (auto& node : nodesForRemoval) 92 92 m_autoSizedNodes.remove(node); 93 93 94 94 // If we only have one piece of text with the style on the page don't 95 95 // adjust it's size. 96 96 if (m_autoSizedNodes.size() <= 1) 97 97 return objectsRemoved; 98 98 99 99 // Compute average size 100 100 float cumulativeSize = 0; 101 101 for (auto& autoSizingNode : m_autoSizedNodes) { 102 RenderText * renderText = static_cast<RenderText*>(autoSizingNode->renderer());103 cumulativeSize += renderText ->candidateComputedTextSize();104 } 105 102 RenderText& renderText = downcast<RenderText>(*autoSizingNode->renderer()); 103 cumulativeSize += renderText.candidateComputedTextSize(); 104 } 105 106 106 float averageSize = roundf(cumulativeSize / m_autoSizedNodes.size()); 107 107 108 108 // Adjust sizes 109 109 bool firstPass = true; 110 110 for (auto& autoSizingNode : m_autoSizedNodes) { 111 RenderText* text = static_cast<RenderText*>(autoSizingNode->renderer());111 auto* text = downcast<RenderText>(autoSizingNode->renderer()); 112 112 if (text && text->style().fontDescription().computedSize() != averageSize) { 113 113 float specifiedSize = text->style().fontDescription().specifiedSize(); … … 127 127 style.fontCascade().update(&autoSizingNode->document().fontSelector()); 128 128 text->parent()->setStyle(WTFMove(style)); 129 129 130 130 RenderElement* parentRenderer = text->parent(); 131 131 if (parentRenderer->isAnonymousBlock()) 132 132 parentRenderer = parentRenderer->parent(); 133 133 134 134 // If we have a list we should resize ListMarkers separately. 135 135 RenderObject* listMarkerRenderer = parentRenderer->firstChild(); … … 140 140 downcast<RenderListMarker>(*listMarkerRenderer).setStyle(WTFMove(style)); 141 141 } 142 142 143 143 // Resize the line height of the parent. 144 const RenderStyle& parentStyle = parentRenderer->style();144 auto& parentStyle = parentRenderer->style(); 145 145 Length lineHeightLength = parentStyle.specifiedLineHeight(); 146 146 147 147 int specifiedLineHeight = 0; 148 148 if (lineHeightLength.isPercent()) … … 150 150 else 151 151 specifiedLineHeight = lineHeightLength.value(); 152 152 153 153 int lineHeight = specifiedLineHeight * scaleChange; 154 154 if (!lineHeightLength.isFixed() || lineHeightLength.value() != lineHeight) { … … 162 162 } 163 163 } 164 164 165 165 return objectsRemoved; 166 166 } … … 169 169 { 170 170 for (auto& autoSizingNode : m_autoSizedNodes) { 171 RenderText* text = static_cast<RenderText*>(autoSizingNode->renderer());171 auto* text = downcast<RenderText>(autoSizingNode->renderer()); 172 172 if (!text) 173 173 continue; … … 186 186 if (!parentRenderer) 187 187 continue; 188 188 189 189 if (parentRenderer->isAnonymousBlock()) 190 190 parentRenderer = parentRenderer->parent(); 191 192 const RenderStyle& parentStyle = parentRenderer->style();191 192 auto& parentStyle = parentRenderer->style(); 193 193 Length originalLineHeight = parentStyle.specifiedLineHeight(); 194 194 if (originalLineHeight != parentStyle.lineHeight()) {
Note: See TracChangeset
for help on using the changeset viewer.