Title: [200593] trunk/Source/WebCore
Revision
200593
Author
simon.fra...@apple.com
Date
2016-05-09 14:57:43 -0700 (Mon, 09 May 2016)

Log Message

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):

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (200592 => 200593)


--- trunk/Source/WebCore/ChangeLog	2016-05-09 21:53:43 UTC (rev 200592)
+++ trunk/Source/WebCore/ChangeLog	2016-05-09 21:57:43 UTC (rev 200593)
@@ -1,3 +1,28 @@
+2016-05-09  Simon Fraser  <simon.fra...@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  <ander...@apple.com>
 
         Add injected bundle SPI for getting favicon and touch icon URLs

Modified: trunk/Source/WebCore/rendering/RenderBlockFlow.cpp (200592 => 200593)


--- trunk/Source/WebCore/rendering/RenderBlockFlow.cpp	2016-05-09 21:53:43 UTC (rev 200592)
+++ trunk/Source/WebCore/rendering/RenderBlockFlow.cpp	2016-05-09 21:57:43 UTC (rev 200593)
@@ -3739,12 +3739,12 @@
     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 @@
     
     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();

Modified: trunk/Source/WebCore/rendering/RenderElement.cpp (200592 => 200593)


--- trunk/Source/WebCore/rendering/RenderElement.cpp	2016-05-09 21:53:43 UTC (rev 200592)
+++ trunk/Source/WebCore/rendering/RenderElement.cpp	2016-05-09 21:57:43 UTC (rev 200593)
@@ -2169,15 +2169,15 @@
 }
 
 #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;

Modified: trunk/Source/WebCore/rendering/RenderObject.cpp (200592 => 200593)


--- trunk/Source/WebCore/rendering/RenderObject.cpp	2016-05-09 21:53:43 UTC (rev 200592)
+++ trunk/Source/WebCore/rendering/RenderObject.cpp	2016-05-09 21:57:43 UTC (rev 200593)
@@ -325,7 +325,7 @@
 
     // 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 @@
         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, 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 @@
         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 @@
             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;
                 }

Modified: trunk/Source/WebCore/rendering/RenderObject.h (200592 => 200593)


--- trunk/Source/WebCore/rendering/RenderObject.h	2016-05-09 21:53:43 UTC (rev 200592)
+++ trunk/Source/WebCore/rendering/RenderObject.h	2016-05-09 21:57:43 UTC (rev 200593)
@@ -190,8 +190,8 @@
     };
 
     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;

Modified: trunk/Source/WebCore/rendering/TextAutoSizing.cpp (200592 => 200593)


--- trunk/Source/WebCore/rendering/TextAutoSizing.cpp	2016-05-09 21:53:43 UTC (rev 200592)
+++ trunk/Source/WebCore/rendering/TextAutoSizing.cpp	2016-05-09 21:57:43 UTC (rev 200593)
@@ -74,41 +74,41 @@
 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 @@
             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 @@
                 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 @@
             }
         }
     }
-    
+
     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 @@
         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);
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to