Clean up iOS text autosizing code
authorsimon.fraser@apple.com <simon.fraser@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 9 May 2016 21:57:43 +0000 (21:57 +0000)
committersimon.fraser@apple.com <simon.fraser@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 9 May 2016 21:57:43 +0000 (21:57 +0000)
https://bugs.webkit.org/show_bug.cgi?id=157489

Reviewed by Zalan Bujtas.

Change the TraverseNextInclusionFunction and HeightTypeTraverseNextInclusionFunction
to take references.

Use downcast<> more.

Whitespace cleanup.

* rendering/RenderBlockFlow.cpp:
(WebCore::isNonBlocksOrNonFixedHeightListItems):
* rendering/RenderElement.cpp:
(WebCore::includeNonFixedHeight):
* rendering/RenderObject.cpp:
(WebCore::RenderObject::traverseNext):
* rendering/RenderObject.h:
* rendering/TextAutoSizing.cpp:
(WebCore::TextAutoSizingValue::adjustNodeSizes):
(WebCore::TextAutoSizingValue::reset):

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@200593 268f45cc-cd09-0410-ab3c-d52691b4dbfc

Source/WebCore/ChangeLog
Source/WebCore/rendering/RenderBlockFlow.cpp
Source/WebCore/rendering/RenderElement.cpp
Source/WebCore/rendering/RenderObject.cpp
Source/WebCore/rendering/RenderObject.h
Source/WebCore/rendering/TextAutoSizing.cpp

index f57c401..7cfe33f 100644 (file)
@@ -1,3 +1,28 @@
+2016-05-09  Simon Fraser  <simon.fraser@apple.com>
+
+        Clean up iOS text autosizing code
+        https://bugs.webkit.org/show_bug.cgi?id=157489
+
+        Reviewed by Zalan Bujtas.
+
+        Change the TraverseNextInclusionFunction and HeightTypeTraverseNextInclusionFunction
+        to take references.
+        
+        Use downcast<> more.
+        
+        Whitespace cleanup.
+
+        * rendering/RenderBlockFlow.cpp:
+        (WebCore::isNonBlocksOrNonFixedHeightListItems):
+        * rendering/RenderElement.cpp:
+        (WebCore::includeNonFixedHeight):
+        * rendering/RenderObject.cpp:
+        (WebCore::RenderObject::traverseNext):
+        * rendering/RenderObject.h:
+        * rendering/TextAutoSizing.cpp:
+        (WebCore::TextAutoSizingValue::adjustNodeSizes):
+        (WebCore::TextAutoSizingValue::reset):
+
 2016-05-09  Anders Carlsson  <andersca@apple.com>
 
         Add injected bundle SPI for getting favicon and touch icon URLs
index 0e6e3a8..55361a3 100644 (file)
@@ -3739,12 +3739,12 @@ int RenderBlockFlow::lineCountForTextAutosizing()
     return count;
 }
 
-static bool isNonBlocksOrNonFixedHeightListItems(const RenderObject* render)
+static bool isNonBlocksOrNonFixedHeightListItems(const RenderObject& render)
 {
-    if (!render->isRenderBlock())
+    if (!render.isRenderBlock())
         return true;
-    if (render->isListItem())
-        return render->style().height().type() != Fixed;
+    if (render.isListItem())
+        return render.style().height().type() != Fixed;
     return false;
 }
 
@@ -3790,7 +3790,7 @@ void RenderBlockFlow::adjustComputedFontSizes(float size, float visibleWidth)
     
     for (RenderObject* descendent = traverseNext(this, isNonBlocksOrNonFixedHeightListItems); descendent; descendent = descendent->traverseNext(this, isNonBlocksOrNonFixedHeightListItems)) {
         if (isVisibleRenderText(descendent) && resizeTextPermitted(descendent)) {
-            RenderText& text = downcast<RenderText>(*descendent);
+            auto& text = downcast<RenderText>(*descendent);
             auto& oldStyle = text.style();
             auto fontDescription = oldStyle.fontDescription();
             float specifiedSize = fontDescription.specifiedSize();
index f3e8b4f..4440e54 100644 (file)
@@ -2169,15 +2169,15 @@ void RenderElement::updateOutlineAutoAncestor(bool hasOutlineAuto) const
 }
 
 #if ENABLE(IOS_TEXT_AUTOSIZING)
-static RenderObject::BlockContentHeightType includeNonFixedHeight(const RenderObject* renderer)
+static RenderObject::BlockContentHeightType includeNonFixedHeight(const RenderObject& renderer)
 {
-    const RenderStyle& style = renderer->style();
+    const RenderStyle& style = renderer.style();
     if (style.height().type() == Fixed) {
-        if (is<RenderBlock>(*renderer)) {
+        if (is<RenderBlock>(renderer)) {
             // For fixed height styles, if the overflow size of the element spills out of the specified
             // height, assume we can apply text auto-sizing.
             if (style.overflowY() == OVISIBLE
-                && style.height().value() < downcast<RenderBlock>(renderer)->layoutOverflowRect().maxY())
+                && style.height().value() < downcast<RenderBlock>(renderer).layoutOverflowRect().maxY())
                 return RenderObject::OverflowHeight;
         }
         return RenderObject::FixedHeight;
index 4d7a733..1a6a1d4 100644 (file)
@@ -325,7 +325,7 @@ RenderObject* RenderObject::traverseNext(const RenderObject* stayWithin, HeightT
 
     // Check for suitable children.
     for (RenderObject* child = firstChildSlow(); child; child = child->nextSibling()) {
-        overflowType = inclusionFunction(child);
+        overflowType = inclusionFunction(*child);
         if (overflowType != FixedHeight) {
             currentDepth++;
             if (overflowType == OverflowHeight)
@@ -349,7 +349,7 @@ RenderObject* RenderObject::traverseNext(const RenderObject* stayWithin, HeightT
         if (!n)
             return nullptr;
         for (RenderObject* sibling = n->nextSibling(); sibling; sibling = sibling->nextSibling()) {
-            overflowType = inclusionFunction(sibling);
+            overflowType = inclusionFunction(*sibling);
             if (overflowType != FixedHeight) {
                 if (overflowType == OverflowHeight)
                     newFixedDepth = currentDepth;
@@ -369,7 +369,7 @@ RenderObject* RenderObject::traverseNext(const RenderObject* stayWithin, HeightT
 RenderObject* RenderObject::traverseNext(const RenderObject* stayWithin, TraverseNextInclusionFunction inclusionFunction) const
 {
     for (RenderObject* child = firstChildSlow(); child; child = child->nextSibling()) {
-        if (inclusionFunction(child)) {
+        if (inclusionFunction(*child)) {
             ASSERT(!stayWithin || child->isDescendantOf(stayWithin));
             return child;
         }
@@ -379,7 +379,7 @@ RenderObject* RenderObject::traverseNext(const RenderObject* stayWithin, Travers
         return nullptr;
 
     for (RenderObject* sibling = nextSibling(); sibling; sibling = sibling->nextSibling()) {
-        if (inclusionFunction(sibling)) {
+        if (inclusionFunction(*sibling)) {
             ASSERT(!stayWithin || sibling->isDescendantOf(stayWithin));
             return sibling;
         }
@@ -391,7 +391,7 @@ RenderObject* RenderObject::traverseNext(const RenderObject* stayWithin, Travers
             n = n->parent();
         if (n) {
             for (RenderObject* sibling = n->nextSibling(); sibling; sibling = sibling->nextSibling()) {
-                if (inclusionFunction(sibling)) {
+                if (inclusionFunction(*sibling)) {
                     ASSERT(!stayWithin || !n->nextSibling() || n->nextSibling()->isDescendantOf(stayWithin));
                     return sibling;
                 }
index d144b72..b9bb6ef 100644 (file)
@@ -190,8 +190,8 @@ public:
     };
 
     RenderObject* traverseNext(const RenderObject* stayWithin) const;
-    typedef bool (*TraverseNextInclusionFunction)(const RenderObject*);
-    typedef BlockContentHeightType (*HeightTypeTraverseNextInclusionFunction)(const RenderObject*);
+    typedef bool (*TraverseNextInclusionFunction)(const RenderObject&);
+    typedef BlockContentHeightType (*HeightTypeTraverseNextInclusionFunction)(const RenderObject&);
 
     RenderObject* traverseNext(const RenderObject* stayWithin, TraverseNextInclusionFunction) const;
     RenderObject* traverseNext(const RenderObject* stayWithin, HeightTypeTraverseNextInclusionFunction, int& currentDepth,  int& newFixedDepth) const;
index 159e0a0..a81f3f1 100644 (file)
@@ -74,41 +74,41 @@ void TextAutoSizingValue::addNode(Node* node, float size)
 bool TextAutoSizingValue::adjustNodeSizes()
 {
     bool objectsRemoved = false;
-    
+
     // Remove stale nodes.  Nodes may have had their renderers detached.  We'll
     // also need to remove the style from the documents m_textAutoSizedNodes
     // collection.  Return true indicates we need to do that removal.
     Vector<RefPtr<Node> > nodesForRemoval;
     for (auto& autoSizingNode : m_autoSizedNodes) {
-        RenderText* text = static_cast<RenderText*>(autoSizingNode->renderer());
+        auto* text = downcast<RenderText>(autoSizingNode->renderer());
         if (!text || !text->style().textSizeAdjust().isAuto() || !text->candidateComputedTextSize()) {
             // remove node.
             nodesForRemoval.append(autoSizingNode);
             objectsRemoved = true;
         }
     }
-    
+
     for (auto& node : nodesForRemoval)
         m_autoSizedNodes.remove(node);
-    
+
     // If we only have one piece of text with the style on the page don't
     // adjust it's size.
     if (m_autoSizedNodes.size() <= 1)
         return objectsRemoved;
-    
+
     // Compute average size
     float cumulativeSize = 0;
     for (auto& autoSizingNode : m_autoSizedNodes) {
-        RenderText* renderText = static_cast<RenderText*>(autoSizingNode->renderer());
-        cumulativeSize += renderText->candidateComputedTextSize();
+        RenderText& renderText = downcast<RenderText>(*autoSizingNode->renderer());
+        cumulativeSize += renderText.candidateComputedTextSize();
     }
-    
+
     float averageSize = roundf(cumulativeSize / m_autoSizedNodes.size());
-    
+
     // Adjust sizes
     bool firstPass = true;
     for (auto& autoSizingNode : m_autoSizedNodes) {
-        RenderText* text = static_cast<RenderText*>(autoSizingNode->renderer());
+        auto* text = downcast<RenderText>(autoSizingNode->renderer());
         if (text && text->style().fontDescription().computedSize() != averageSize) {
             float specifiedSize = text->style().fontDescription().specifiedSize();
             float scaleChange = averageSize / specifiedSize;
@@ -126,11 +126,11 @@ bool TextAutoSizingValue::adjustNodeSizes()
             style.setFontDescription(fontDescription);
             style.fontCascade().update(&autoSizingNode->document().fontSelector());
             text->parent()->setStyle(WTFMove(style));
-            
+
             RenderElement* parentRenderer = text->parent();
             if (parentRenderer->isAnonymousBlock())
                 parentRenderer = parentRenderer->parent();
-            
+
             // If we have a list we should resize ListMarkers separately.
             RenderObject* listMarkerRenderer = parentRenderer->firstChild();
             if (listMarkerRenderer->isListMarker()) {
@@ -139,17 +139,17 @@ bool TextAutoSizingValue::adjustNodeSizes()
                 style.fontCascade().update(&autoSizingNode->document().fontSelector());
                 downcast<RenderListMarker>(*listMarkerRenderer).setStyle(WTFMove(style));
             }
-            
+
             // Resize the line height of the parent.
-            const RenderStyle& parentStyle = parentRenderer->style();
+            auto& parentStyle = parentRenderer->style();
             Length lineHeightLength = parentStyle.specifiedLineHeight();
-            
+
             int specifiedLineHeight = 0;
             if (lineHeightLength.isPercent())
                 specifiedLineHeight = minimumValueForLength(lineHeightLength, fontDescription.specifiedSize());
             else
                 specifiedLineHeight = lineHeightLength.value();
-            
+
             int lineHeight = specifiedLineHeight * scaleChange;
             if (!lineHeightLength.isFixed() || lineHeightLength.value() != lineHeight) {
                 auto newParentStyle = cloneRenderStyleWithState(parentStyle);
@@ -161,14 +161,14 @@ bool TextAutoSizingValue::adjustNodeSizes()
             }
         }
     }
-    
+
     return objectsRemoved;
 }
 
 void TextAutoSizingValue::reset()
 {
     for (auto& autoSizingNode : m_autoSizedNodes) {
-        RenderText* text = static_cast<RenderText*>(autoSizingNode->renderer());
+        auto* text = downcast<RenderText>(autoSizingNode->renderer());
         if (!text)
             continue;
         // Reset the font size back to the original specified size
@@ -185,11 +185,11 @@ void TextAutoSizingValue::reset()
         RenderElement* parentRenderer = text->parent();
         if (!parentRenderer)
             continue;
-        
+
         if (parentRenderer->isAnonymousBlock())
             parentRenderer = parentRenderer->parent();
-        
-        const RenderStyle& parentStyle = parentRenderer->style();
+
+        auto& parentStyle = parentRenderer->style();
         Length originalLineHeight = parentStyle.specifiedLineHeight();
         if (originalLineHeight != parentStyle.lineHeight()) {
             auto newParentStyle = cloneRenderStyleWithState(parentStyle);