Modernize RenderTreeAsText code
authorsimon.fraser@apple.com <simon.fraser@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sat, 29 Apr 2017 00:48:08 +0000 (00:48 +0000)
committersimon.fraser@apple.com <simon.fraser@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sat, 29 Apr 2017 00:48:08 +0000 (00:48 +0000)
https://bugs.webkit.org/show_bug.cgi?id=171458

Reviewed by Zalan Bujtas.

Use modern loops. More references to render objects and layers.

* rendering/RenderTreeAsText.cpp:
(WebCore::write):
(WebCore::writeRenderNamedFlowThreads):
(WebCore::writeLayers):
(WebCore::writeSelection):
(WebCore::externalRepresentation):

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

Source/WebCore/ChangeLog
Source/WebCore/rendering/RenderTreeAsText.cpp

index 0cc4895..f9f9e77 100644 (file)
@@ -1,3 +1,19 @@
+2017-04-28  Simon Fraser  <simon.fraser@apple.com>
+
+        Modernize RenderTreeAsText code
+        https://bugs.webkit.org/show_bug.cgi?id=171458
+
+        Reviewed by Zalan Bujtas.
+
+        Use modern loops. More references to render objects and layers.
+
+        * rendering/RenderTreeAsText.cpp:
+        (WebCore::write):
+        (WebCore::writeRenderNamedFlowThreads):
+        (WebCore::writeLayers):
+        (WebCore::writeSelection):
+        (WebCore::externalRepresentation):
+
 2017-04-28  Wenson Hsieh  <wenson_hsieh@apple.com>
 
         Fix and re-enable data interaction unit tests
index 403b5b4..8d2290c 100644 (file)
@@ -81,7 +81,7 @@ namespace WebCore {
 
 using namespace HTMLNames;
 
-static void writeLayers(TextStream&, const RenderLayer* rootLayer, RenderLayer*, const LayoutRect& paintDirtyRect, int indent = 0, RenderAsTextBehavior = RenderAsTextBehaviorNormal);
+static void writeLayers(TextStream&, const RenderLayer& rootLayer, RenderLayer&, const LayoutRect& paintDirtyRect, int indent = 0, RenderAsTextBehavior = RenderAsTextBehaviorNormal);
 
 static void printBorderStyle(TextStream& ts, const EBorderStyle borderStyle)
 {
@@ -598,7 +598,7 @@ void write(TextStream& ts, const RenderObject& o, int indent, RenderAsTextBehavi
                 if (!(behavior & RenderAsTextDontUpdateLayout))
                     view.layout();
                 if (RenderLayer* layer = root->layer())
-                    writeLayers(ts, layer, layer, layer->rect(), indent + 1, behavior);
+                    writeLayers(ts, *layer, *layer, layer->rect(), indent + 1, behavior);
             }
         }
     }
@@ -719,25 +719,20 @@ static void writeRenderRegionList(const RenderRegionList& flowThreadRegionList,
     }
 }
 
-static void writeRenderNamedFlowThreads(TextStream& ts, RenderView& renderView, const RenderLayer* rootLayer,
-    const LayoutRect& paintRect, int indent, RenderAsTextBehavior behavior)
+static void writeRenderNamedFlowThreads(TextStream& ts, RenderView& renderView, const RenderLayer& rootLayer, const LayoutRect& paintRect, int indent, RenderAsTextBehavior behavior)
 {
     if (!renderView.hasRenderNamedFlowThreads())
         return;
 
-    const RenderNamedFlowThreadList* list = renderView.flowThreadController().renderNamedFlowThreadList();
-
     writeIndent(ts, indent);
     ts << "Named flows\n";
 
-    for (RenderNamedFlowThreadList::const_iterator iter = list->begin(); iter != list->end(); ++iter) {
-        const RenderNamedFlowThread* renderFlowThread = *iter;
-
+    for (const auto* renderFlowThread : *renderView.flowThreadController().renderNamedFlowThreadList()) {
         writeIndent(ts, indent + 1);
         ts << "Named flow '" << renderFlowThread->flowThreadName() << "'\n";
 
         RenderLayer* layer = renderFlowThread->layer();
-        writeLayers(ts, rootLayer, layer, paintRect, indent + 2, behavior);
+        writeLayers(ts, rootLayer, *layer, paintRect, indent + 2, behavior);
 
         // Display the valid and invalid render regions attached to this flow thread.
         const RenderRegionList& validRegionsList = renderFlowThread->renderRegionList();
@@ -761,75 +756,79 @@ static LayoutSize maxLayoutOverflow(const RenderBox* box)
     return LayoutSize(overflowRect.maxX(), overflowRect.maxY());
 }
 
-static void writeLayers(TextStream& ts, const RenderLayer* rootLayer, RenderLayer* l,
-                        const LayoutRect& paintRect, int indent, RenderAsTextBehavior behavior)
+static void writeLayers(TextStream& ts, const RenderLayer& rootLayer, RenderLayer& layer, const LayoutRect& paintRect, int indent, RenderAsTextBehavior behavior)
 {
-    // FIXME: Apply overflow to the root layer to not break every test.  Complete hack.  Sigh.
+    // FIXME: Apply overflow to the root layer to not break every test. Complete hack. Sigh.
     LayoutRect paintDirtyRect(paintRect);
-    if (rootLayer == l) {
-        paintDirtyRect.setWidth(std::max<LayoutUnit>(paintDirtyRect.width(), rootLayer->renderBox()->layoutOverflowRect().maxX()));
-        paintDirtyRect.setHeight(std::max<LayoutUnit>(paintDirtyRect.height(), rootLayer->renderBox()->layoutOverflowRect().maxY()));
-        l->setSize(l->size().expandedTo(snappedIntSize(maxLayoutOverflow(l->renderBox()), LayoutPoint(0, 0))));
+    if (&rootLayer == &layer) {
+        paintDirtyRect.setWidth(std::max<LayoutUnit>(paintDirtyRect.width(), rootLayer.renderBox()->layoutOverflowRect().maxX()));
+        paintDirtyRect.setHeight(std::max<LayoutUnit>(paintDirtyRect.height(), rootLayer.renderBox()->layoutOverflowRect().maxY()));
+        layer.setSize(layer.size().expandedTo(snappedIntSize(maxLayoutOverflow(layer.renderBox()), LayoutPoint(0, 0))));
     }
     
     // Calculate the clip rects we should use.
     LayoutRect layerBounds;
     ClipRect damageRect;
     ClipRect clipRectToApply;
-    l->calculateRects(RenderLayer::ClipRectsContext(rootLayer, TemporaryClipRects), paintDirtyRect, layerBounds, damageRect, clipRectToApply, l->offsetFromAncestor(rootLayer));
+    layer.calculateRects(RenderLayer::ClipRectsContext(&rootLayer, TemporaryClipRects), paintDirtyRect, layerBounds, damageRect, clipRectToApply, layer.offsetFromAncestor(&rootLayer));
 
     // Ensure our lists are up-to-date.
-    l->updateLayerListsIfNeeded();
+    layer.updateLayerListsIfNeeded();
 
-    bool shouldPaint = (behavior & RenderAsTextShowAllLayers) ? true : l->intersectsDamageRect(layerBounds, damageRect.rect(), rootLayer, l->offsetFromAncestor(rootLayer));
-    Vector<RenderLayer*>* negList = l->negZOrderList();
-    bool paintsBackgroundSeparately = negList && negList->size() > 0;
+    bool shouldPaint = (behavior & RenderAsTextShowAllLayers) ? true : layer.intersectsDamageRect(layerBounds, damageRect.rect(), &rootLayer, layer.offsetFromAncestor(&rootLayer));
+    Vector<RenderLayer*>* negativeZOrderList = layer.negZOrderList();
+    bool paintsBackgroundSeparately = negativeZOrderList && negativeZOrderList->size() > 0;
     if (shouldPaint && paintsBackgroundSeparately)
-        write(ts, *l, layerBounds, damageRect.rect(), clipRectToApply.rect(), LayerPaintPhaseBackground, indent, behavior);
+        write(ts, layer, layerBounds, damageRect.rect(), clipRectToApply.rect(), LayerPaintPhaseBackground, indent, behavior);
 
-    if (negList) {
+    if (negativeZOrderList) {
         int currIndent = indent;
         if (behavior & RenderAsTextShowLayerNesting) {
             writeIndent(ts, indent);
-            ts << " negative z-order list(" << negList->size() << ")\n";
+            ts << " negative z-order list(" << negativeZOrderList->size() << ")\n";
             ++currIndent;
         }
-        for (unsigned i = 0; i != negList->size(); ++i)
-            writeLayers(ts, rootLayer, negList->at(i), paintDirtyRect, currIndent, behavior);
+        
+        for (auto* currLayer : *negativeZOrderList)
+            writeLayers(ts, rootLayer, *currLayer, paintDirtyRect, currIndent, behavior);
     }
 
     if (shouldPaint)
-        write(ts, *l, layerBounds, damageRect.rect(), clipRectToApply.rect(), paintsBackgroundSeparately ? LayerPaintPhaseForeground : LayerPaintPhaseAll, indent, behavior);
+        write(ts, layer, layerBounds, damageRect.rect(), clipRectToApply.rect(), paintsBackgroundSeparately ? LayerPaintPhaseForeground : LayerPaintPhaseAll, indent, behavior);
 
-    if (Vector<RenderLayer*>* normalFlowList = l->normalFlowList()) {
+    if (Vector<RenderLayer*>* normalFlowList = layer.normalFlowList()) {
         int currIndent = indent;
         if (behavior & RenderAsTextShowLayerNesting) {
             writeIndent(ts, indent);
             ts << " normal flow list(" << normalFlowList->size() << ")\n";
             ++currIndent;
         }
-        for (unsigned i = 0; i != normalFlowList->size(); ++i)
-            writeLayers(ts, rootLayer, normalFlowList->at(i), paintDirtyRect, currIndent, behavior);
+        
+        for (auto* currLayer : *normalFlowList)
+            writeLayers(ts, rootLayer, *currLayer, paintDirtyRect, currIndent, behavior);
     }
 
-    if (Vector<RenderLayer*>* posList = l->posZOrderList()) {
+    if (Vector<RenderLayer*>* positiveZOrderList = layer.posZOrderList()) {
         size_t layerCount = 0;
-        for (unsigned i = 0; i != posList->size(); ++i)
-            if (!posList->at(i)->isFlowThreadCollectingGraphicsLayersUnderRegions())
+        for (auto* currLayer : *positiveZOrderList) {
+            if (!currLayer->isFlowThreadCollectingGraphicsLayersUnderRegions())
                 ++layerCount;
+        }
+        
         if (layerCount) {
             int currIndent = indent;
             // We only print the header if there's at list a non-RenderNamedFlowThread part of the list.
-            if (!posList->size() || !posList->at(0)->isFlowThreadCollectingGraphicsLayersUnderRegions()) {
+            if (!positiveZOrderList->size() || !positiveZOrderList->at(0)->isFlowThreadCollectingGraphicsLayersUnderRegions()) {
                 if (behavior & RenderAsTextShowLayerNesting) {
                     writeIndent(ts, indent);
-                    ts << " positive z-order list(" << posList->size() << ")\n";
+                    ts << " positive z-order list(" << positiveZOrderList->size() << ")\n";
                     ++currIndent;
                 }
-                for (unsigned i = 0; i != posList->size(); ++i) {
+                
+                for (auto* currLayer : *positiveZOrderList) {
                     // Do not print named flows twice.
-                    if (!posList->at(i)->isFlowThreadCollectingGraphicsLayersUnderRegions())
-                        writeLayers(ts, rootLayer, posList->at(i), paintDirtyRect, currIndent, behavior);
+                    if (!currLayer->isFlowThreadCollectingGraphicsLayersUnderRegions())
+                        writeLayers(ts, rootLayer, *currLayer, paintDirtyRect, currIndent, behavior);
                 }
             }
         }
@@ -837,8 +836,8 @@ static void writeLayers(TextStream& ts, const RenderLayer* rootLayer, RenderLaye
     
     // Altough the RenderFlowThread requires a layer, it is not collected by its parent,
     // so we have to treat it as a special case.
-    if (is<RenderView>(l->renderer()))
-        writeRenderNamedFlowThreads(ts, downcast<RenderView>(l->renderer()), rootLayer, paintDirtyRect, indent, behavior);
+    if (is<RenderView>(layer.renderer()))
+        writeRenderNamedFlowThreads(ts, downcast<RenderView>(layer.renderer()), rootLayer, paintDirtyRect, indent, behavior);
 }
 
 static String nodePosition(Node* node)
@@ -875,12 +874,12 @@ static String nodePosition(Node* node)
     return result.toString();
 }
 
-static void writeSelection(TextStream& ts, const RenderObject* renderer)
+static void writeSelection(TextStream& ts, const RenderBox& renderer)
 {
-    if (!renderer->isRenderView())
+    if (!renderer.isRenderView())
         return;
 
-    Frame* frame = renderer->document().frame();
+    Frame* frame = renderer.document().frame();
     if (!frame)
         return;
 
@@ -895,16 +894,16 @@ static void writeSelection(TextStream& ts, const RenderObject* renderer)
            << "selection end:   position " << selection.end().deprecatedEditingOffset() << " of " << nodePosition(selection.end().deprecatedNode()) << "\n";
 }
 
-static String externalRepresentation(RenderBox* renderer, RenderAsTextBehavior behavior)
+static String externalRepresentation(RenderBox& renderer, RenderAsTextBehavior behavior)
 {
     TextStream ts(TextStream::LineMode::MultipleLine, TextStream::Formatting::SVGStyleRect | TextStream::Formatting::LayoutUnitsAsIntegers);
-    if (!renderer->hasLayer())
+    if (!renderer.hasLayer())
         return ts.release();
 
     LOG(Layout, "externalRepresentation: dumping layer tree");
 
-    RenderLayer* layer = renderer->layer();
-    writeLayers(ts, layer, layer, layer->rect(), 0, behavior);
+    RenderLayer& layer = *renderer.layer();
+    writeLayers(ts, layer, layer, layer.rect(), 0, behavior);
     writeSelection(ts, renderer);
     return ts.release();
 }
@@ -921,7 +920,7 @@ String externalRepresentation(Frame* frame, RenderAsTextBehavior behavior)
     if (!(behavior & RenderAsTextDontUpdateLayout))
         frame->document()->updateLayout();
 
-    return externalRepresentation(renderer, behavior);
+    return externalRepresentation(*renderer, behavior);
 }
 
 String externalRepresentation(Element* element, RenderAsTextBehavior behavior)
@@ -934,7 +933,7 @@ String externalRepresentation(Element* element, RenderAsTextBehavior behavior)
     if (!(behavior & RenderAsTextDontUpdateLayout))
         element->document().updateLayout();
     
-    return externalRepresentation(downcast<RenderBox>(renderer), behavior | RenderAsTextShowAllLayers);
+    return externalRepresentation(downcast<RenderBox>(*renderer), behavior | RenderAsTextShowAllLayers);
 }
 
 static void writeCounterValuesFromChildren(TextStream& stream, const RenderElement* parent, bool& isFirstCounter)