Title: [208466] trunk/Source/WebCore
Revision
208466
Author
[email protected]
Date
2016-11-09 12:22:37 -0800 (Wed, 09 Nov 2016)

Log Message

Allow customization of TextStream-based logging for geometry types
https://bugs.webkit.org/show_bug.cgi?id=164460

Reviewed by Zalan Bujtas.

TextStream-based logging was constrained by the requirement to maintain compatibility
with DRT-style output, which includes cumbersome rect logging ("at (5,0) size 40x40")
and dumping LayoutRects as IntRects.

Add some formatting flags so that other TextStream clients (e.g. logging) can have
more readable output, and opt into automatic FormatNumberRespectingIntegers behavior.

TextStreams whose output appears in test results are given flags to avoid behavior
changes, but in the longer term test results should be updated.

* html/canvas/CanvasRenderingContext2D.cpp:
(WebCore::CanvasRenderingContext2D::replayDisplayListAsText):
* page/scrolling/ScrollingStateNode.cpp:
(WebCore::ScrollingStateNode::scrollingStateTreeAsText):
* platform/graphics/FloatPoint.cpp:
(WebCore::operator<<):
* platform/graphics/FloatRect.cpp:
(WebCore::operator<<):
* platform/graphics/GraphicsLayer.cpp:
(WebCore::GraphicsLayer::layerTreeAsText):
* platform/graphics/IntRect.cpp:
(WebCore::operator<<):
* platform/graphics/LayoutPoint.cpp:
(WebCore::operator<<):
* platform/graphics/LayoutRect.cpp:
(WebCore::operator<<):
* platform/graphics/ca/GraphicsLayerCA.cpp:
(WebCore::GraphicsLayerCA::replayDisplayListAsText):
* platform/graphics/displaylists/DisplayList.cpp:
(WebCore::DisplayList::DisplayList::asText):
* platform/text/TextStream.cpp:
(WebCore::TextStream::operator<<):
* platform/text/TextStream.h:
(WebCore::TextStream::TextStream):
(WebCore::TextStream::formattingFlags):
(WebCore::TextStream::setFormattingFlags):
(WebCore::TextStream::hasFormattingFlag):
(WebCore::TextStream::increaseIndent):
(WebCore::TextStream::decreaseIndent):
* rendering/RenderTreeAsText.cpp:
(WebCore::externalRepresentation):
(WebCore::counterValueForElement):

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (208465 => 208466)


--- trunk/Source/WebCore/ChangeLog	2016-11-09 20:21:49 UTC (rev 208465)
+++ trunk/Source/WebCore/ChangeLog	2016-11-09 20:22:37 UTC (rev 208466)
@@ -1,3 +1,53 @@
+2016-11-09  Simon Fraser  <[email protected]>
+
+        Allow customization of TextStream-based logging for geometry types
+        https://bugs.webkit.org/show_bug.cgi?id=164460
+
+        Reviewed by Zalan Bujtas.
+
+        TextStream-based logging was constrained by the requirement to maintain compatibility
+        with DRT-style output, which includes cumbersome rect logging ("at (5,0) size 40x40")
+        and dumping LayoutRects as IntRects.
+        
+        Add some formatting flags so that other TextStream clients (e.g. logging) can have
+        more readable output, and opt into automatic FormatNumberRespectingIntegers behavior.
+        
+        TextStreams whose output appears in test results are given flags to avoid behavior
+        changes, but in the longer term test results should be updated.
+
+        * html/canvas/CanvasRenderingContext2D.cpp:
+        (WebCore::CanvasRenderingContext2D::replayDisplayListAsText):
+        * page/scrolling/ScrollingStateNode.cpp:
+        (WebCore::ScrollingStateNode::scrollingStateTreeAsText):
+        * platform/graphics/FloatPoint.cpp:
+        (WebCore::operator<<):
+        * platform/graphics/FloatRect.cpp:
+        (WebCore::operator<<):
+        * platform/graphics/GraphicsLayer.cpp:
+        (WebCore::GraphicsLayer::layerTreeAsText):
+        * platform/graphics/IntRect.cpp:
+        (WebCore::operator<<):
+        * platform/graphics/LayoutPoint.cpp:
+        (WebCore::operator<<):
+        * platform/graphics/LayoutRect.cpp:
+        (WebCore::operator<<):
+        * platform/graphics/ca/GraphicsLayerCA.cpp:
+        (WebCore::GraphicsLayerCA::replayDisplayListAsText):
+        * platform/graphics/displaylists/DisplayList.cpp:
+        (WebCore::DisplayList::DisplayList::asText):
+        * platform/text/TextStream.cpp:
+        (WebCore::TextStream::operator<<):
+        * platform/text/TextStream.h:
+        (WebCore::TextStream::TextStream):
+        (WebCore::TextStream::formattingFlags):
+        (WebCore::TextStream::setFormattingFlags):
+        (WebCore::TextStream::hasFormattingFlag):
+        (WebCore::TextStream::increaseIndent):
+        (WebCore::TextStream::decreaseIndent):
+        * rendering/RenderTreeAsText.cpp:
+        (WebCore::externalRepresentation):
+        (WebCore::counterValueForElement):
+
 2016-11-09  Zalan Bujtas  <[email protected]>
 
         RenderFlowThread::flowThreadRelativeWillBeRemoved should take RenderObject& instead of RenderObject*

Modified: trunk/Source/WebCore/html/canvas/CanvasRenderingContext2D.cpp (208465 => 208466)


--- trunk/Source/WebCore/html/canvas/CanvasRenderingContext2D.cpp	2016-11-09 20:21:49 UTC (rev 208465)
+++ trunk/Source/WebCore/html/canvas/CanvasRenderingContext2D.cpp	2016-11-09 20:22:37 UTC (rev 208466)
@@ -1887,11 +1887,8 @@
 String CanvasRenderingContext2D::replayDisplayListAsText(DisplayList::AsTextFlags flags) const
 {
     auto it = contextDisplayListMap().find(this);
-    if (it != contextDisplayListMap().end()) {
-        TextStream stream;
-        stream << it->value->asText(flags);
-        return stream.release();
-    }
+    if (it != contextDisplayListMap().end())
+        return it->value->asText(flags);
 
     return String();
 }

Modified: trunk/Source/WebCore/page/scrolling/ScrollingStateNode.cpp (208465 => 208466)


--- trunk/Source/WebCore/page/scrolling/ScrollingStateNode.cpp	2016-11-09 20:21:49 UTC (rev 208465)
+++ trunk/Source/WebCore/page/scrolling/ScrollingStateNode.cpp	2016-11-09 20:22:37 UTC (rev 208466)
@@ -133,7 +133,7 @@
 
 String ScrollingStateNode::scrollingStateTreeAsText() const
 {
-    TextStream ts;
+    TextStream ts(TextStream::LineMode::MultipleLine, TextStream::Formatting::SVGStyleRect);
 
     dump(ts, 0, ScrollingStateTreeAsTextBehaviorNormal);
     return ts.release();

Modified: trunk/Source/WebCore/platform/graphics/FloatPoint.cpp (208465 => 208466)


--- trunk/Source/WebCore/platform/graphics/FloatPoint.cpp	2016-11-09 20:21:49 UTC (rev 208465)
+++ trunk/Source/WebCore/platform/graphics/FloatPoint.cpp	2016-11-09 20:22:37 UTC (rev 208466)
@@ -90,6 +90,7 @@
 
 TextStream& operator<<(TextStream& ts, const FloatPoint& p)
 {
+    // FIXME: callers should use the NumberRespectingIntegers flag.
     return ts << "(" << TextStream::FormatNumberRespectingIntegers(p.x()) << "," << TextStream::FormatNumberRespectingIntegers(p.y()) << ")";
 }
 

Modified: trunk/Source/WebCore/platform/graphics/FloatRect.cpp (208465 => 208466)


--- trunk/Source/WebCore/platform/graphics/FloatRect.cpp	2016-11-09 20:21:49 UTC (rev 208465)
+++ trunk/Source/WebCore/platform/graphics/FloatRect.cpp	2016-11-09 20:22:37 UTC (rev 208466)
@@ -228,8 +228,13 @@
 
 TextStream& operator<<(TextStream& ts, const FloatRect &r)
 {
-    return ts << "at (" << TextStream::FormatNumberRespectingIntegers(r.x()) << "," << TextStream::FormatNumberRespectingIntegers(r.y())
-        << ") size " << TextStream::FormatNumberRespectingIntegers(r.width()) << "x" << TextStream::FormatNumberRespectingIntegers(r.height());
+    if (ts.hasFormattingFlag(TextStream::Formatting::SVGStyleRect)) {
+        // FIXME: callers should use the NumberRespectingIntegers flag.
+        return ts << "at (" << TextStream::FormatNumberRespectingIntegers(r.x()) << "," << TextStream::FormatNumberRespectingIntegers(r.y())
+            << ") size " << TextStream::FormatNumberRespectingIntegers(r.width()) << "x" << TextStream::FormatNumberRespectingIntegers(r.height());
+    }
+
+    return ts << r.location() << " " << r.size();
 }
 
 }

Modified: trunk/Source/WebCore/platform/graphics/GraphicsLayer.cpp (208465 => 208466)


--- trunk/Source/WebCore/platform/graphics/GraphicsLayer.cpp	2016-11-09 20:21:49 UTC (rev 208465)
+++ trunk/Source/WebCore/platform/graphics/GraphicsLayer.cpp	2016-11-09 20:22:37 UTC (rev 208466)
@@ -904,7 +904,7 @@
 
 String GraphicsLayer::layerTreeAsText(LayerTreeAsTextBehavior behavior) const
 {
-    TextStream ts;
+    TextStream ts(TextStream::LineMode::MultipleLine, TextStream::Formatting::SVGStyleRect);
 
     dumpLayer(ts, 0, behavior);
     return ts.release();

Modified: trunk/Source/WebCore/platform/graphics/IntRect.cpp (208465 => 208466)


--- trunk/Source/WebCore/platform/graphics/IntRect.cpp	2016-11-09 20:21:49 UTC (rev 208465)
+++ trunk/Source/WebCore/platform/graphics/IntRect.cpp	2016-11-09 20:22:37 UTC (rev 208466)
@@ -148,7 +148,10 @@
 
 TextStream& operator<<(TextStream& ts, const IntRect& r)
 {
-    return ts << "at (" << r.x() << "," << r.y() << ") size " << r.width() << "x" << r.height();
+    if (ts.hasFormattingFlag(TextStream::Formatting::SVGStyleRect))
+        return ts << "at (" << r.x() << "," << r.y() << ") size " << r.width() << "x" << r.height();
+
+    return ts << r.location() << " " << r.size();
 }
 
 } // namespace WebCore

Modified: trunk/Source/WebCore/platform/graphics/LayoutPoint.cpp (208465 => 208466)


--- trunk/Source/WebCore/platform/graphics/LayoutPoint.cpp	2016-11-09 20:21:49 UTC (rev 208465)
+++ trunk/Source/WebCore/platform/graphics/LayoutPoint.cpp	2016-11-09 20:22:37 UTC (rev 208466)
@@ -40,8 +40,10 @@
 
 TextStream& operator<<(TextStream& ts, const LayoutPoint& p)
 {
-    // FIXME: These should be printed as floats. Keeping them ints for consistency with pervious test expectations.
-    return ts << "(" << p.x().toInt() << "," << p.y().toInt() << ")";
+    if (ts.hasFormattingFlag(TextStream::Formatting::LayoutUnitsAsIntegers))
+        return ts << "(" << p.x().toInt() << "," << p.y().toInt() << ")";
+
+    return ts << "(" << p.x().toFloat() << "," << p.y().toFloat() << ")";
 }
 
 } // namespace WebCore

Modified: trunk/Source/WebCore/platform/graphics/LayoutRect.cpp (208465 => 208466)


--- trunk/Source/WebCore/platform/graphics/LayoutRect.cpp	2016-11-09 20:21:49 UTC (rev 208465)
+++ trunk/Source/WebCore/platform/graphics/LayoutRect.cpp	2016-11-09 20:22:37 UTC (rev 208466)
@@ -177,8 +177,10 @@
 
 TextStream& operator<<(TextStream& ts, const LayoutRect& r)
 {
-    // FIXME: These should be printed as floats. Keeping them ints for consistency with previous test expectations.
-    return ts << snappedIntRect(r);
+    if (ts.hasFormattingFlag(TextStream::Formatting::LayoutUnitsAsIntegers))
+        return ts << snappedIntRect(r);
+    
+    return ts << FloatRect(r);
 }
 
 } // namespace WebCore

Modified: trunk/Source/WebCore/platform/graphics/ca/GraphicsLayerCA.cpp (208465 => 208466)


--- trunk/Source/WebCore/platform/graphics/ca/GraphicsLayerCA.cpp	2016-11-09 20:21:49 UTC (rev 208465)
+++ trunk/Source/WebCore/platform/graphics/ca/GraphicsLayerCA.cpp	2016-11-09 20:22:37 UTC (rev 208466)
@@ -3411,7 +3411,7 @@
 {
     auto it = layerDisplayListMap().find(this);
     if (it != layerDisplayListMap().end()) {
-        TextStream stream;
+        TextStream stream(TextStream::LineMode::MultipleLine, TextStream::Formatting::SVGStyleRect);
         
         TextStream::GroupScope scope(stream);
         stream.dumpProperty("clip", it->value.first);

Modified: trunk/Source/WebCore/platform/graphics/displaylists/DisplayList.cpp (208465 => 208466)


--- trunk/Source/WebCore/platform/graphics/displaylists/DisplayList.cpp	2016-11-09 20:21:49 UTC (rev 208465)
+++ trunk/Source/WebCore/platform/graphics/displaylists/DisplayList.cpp	2016-11-09 20:22:37 UTC (rev 208466)
@@ -87,7 +87,7 @@
 
 String DisplayList::asText(AsTextFlags flags) const
 {
-    TextStream stream;
+    TextStream stream(TextStream::LineMode::MultipleLine, TextStream::Formatting::SVGStyleRect);
     for (auto& item : m_list) {
         if (!shouldDumpForFlags(flags, item))
             continue;

Modified: trunk/Source/WebCore/platform/text/TextStream.cpp (208465 => 208466)


--- trunk/Source/WebCore/platform/text/TextStream.cpp	2016-11-09 20:21:49 UTC (rev 208465)
+++ trunk/Source/WebCore/platform/text/TextStream.cpp	2016-11-09 20:22:37 UTC (rev 208466)
@@ -89,6 +89,9 @@
 
 TextStream& TextStream::operator<<(float f)
 {
+    if (m_formattingFlags & Formatting::NumberRespectingIntegers)
+        return *this << FormatNumberRespectingIntegers(f);
+
     m_text.appendFixedWidthNumber(f, 2);
     return *this;
 }
@@ -95,6 +98,9 @@
 
 TextStream& TextStream::operator<<(double d)
 {
+    if (m_formattingFlags & Formatting::NumberRespectingIntegers)
+        return *this << FormatNumberRespectingIntegers(d);
+
     m_text.appendFixedWidthNumber(d, 2);
     return *this;
 }
@@ -120,8 +126,10 @@
 
 TextStream& TextStream::operator<<(const FormatNumberRespectingIntegers& numberToFormat)
 {
-    if (hasFractions(numberToFormat.value))
-        return *this << numberToFormat.value;
+    if (hasFractions(numberToFormat.value)) {
+        m_text.appendFixedWidthNumber(numberToFormat.value, 2);
+        return *this;
+    }
 
     m_text.appendNumber(static_cast<int>(numberToFormat.value));
     return *this;

Modified: trunk/Source/WebCore/platform/text/TextStream.h (208465 => 208466)


--- trunk/Source/WebCore/platform/text/TextStream.h	2016-11-09 20:21:49 UTC (rev 208465)
+++ trunk/Source/WebCore/platform/text/TextStream.h	2016-11-09 20:22:37 UTC (rev 208466)
@@ -40,9 +40,18 @@
         double value;
     };
     
+    enum Formatting {
+        SVGStyleRect                = 1 << 0, // "at (0,0) size 10x10"
+        NumberRespectingIntegers    = 1 << 1,
+        LayoutUnitsAsIntegers       = 1 << 2,
+    };
+    
+    using FormattingFlags = unsigned;
+    
     enum class LineMode { SingleLine, MultipleLine };
-    TextStream(LineMode lineMode = LineMode::MultipleLine)
-        : m_multiLineMode(lineMode == LineMode::MultipleLine)
+    TextStream(LineMode lineMode = LineMode::MultipleLine, FormattingFlags formattingFlags = 0)
+        : m_formattingFlags(formattingFlags)
+        , m_multiLineMode(lineMode == LineMode::MultipleLine)
     {
     }
 
@@ -60,8 +69,14 @@
     WEBCORE_EXPORT TextStream& operator<<(const char*);
     WEBCORE_EXPORT TextStream& operator<<(const void*);
     WEBCORE_EXPORT TextStream& operator<<(const String&);
+    // Deprecated. Use the NumberRespectingIntegers FormattingFlag instead.
     WEBCORE_EXPORT TextStream& operator<<(const FormatNumberRespectingIntegers&);
 
+    FormattingFlags formattingFlags() const { return m_formattingFlags; }
+    void setFormattingFlags(FormattingFlags flags) { m_formattingFlags = flags; }
+
+    bool hasFormattingFlag(Formatting flag) const { return m_formattingFlags & flag; }
+
     template<typename T>
     void dumpProperty(const String& name, const T& value)
     {
@@ -77,8 +92,8 @@
     WEBCORE_EXPORT void endGroup();
     WEBCORE_EXPORT void nextLine(); // Output newline and indent.
 
-    void increaseIndent() { ++m_indent; }
-    void decreaseIndent() { --m_indent; ASSERT(m_indent >= 0); }
+    void increaseIndent(int amount = 1) { m_indent += amount; }
+    void decreaseIndent(int amount = 1) { m_indent -= amount; ASSERT(m_indent >= 0); }
 
     WEBCORE_EXPORT void writeIndent();
 
@@ -100,6 +115,7 @@
 
 private:
     StringBuilder m_text;
+    FormattingFlags m_formattingFlags { 0 };
     int m_indent { 0 };
     bool m_multiLineMode { true };
 };

Modified: trunk/Source/WebCore/rendering/RenderTreeAsText.cpp (208465 => 208466)


--- trunk/Source/WebCore/rendering/RenderTreeAsText.cpp	2016-11-09 20:21:49 UTC (rev 208465)
+++ trunk/Source/WebCore/rendering/RenderTreeAsText.cpp	2016-11-09 20:22:37 UTC (rev 208466)
@@ -881,7 +881,7 @@
 
 static String externalRepresentation(RenderBox* renderer, RenderAsTextBehavior behavior)
 {
-    TextStream ts;
+    TextStream ts(TextStream::LineMode::MultipleLine, TextStream::Formatting::SVGStyleRect | TextStream::Formatting::LayoutUnitsAsIntegers);
     if (!renderer->hasLayer())
         return ts.release();
 
@@ -939,7 +939,7 @@
     // Make sure the element is not freed during the layout.
     RefPtr<Element> elementRef(element);
     element->document().updateLayout();
-    TextStream stream;
+    TextStream stream(TextStream::LineMode::MultipleLine, TextStream::Formatting::SVGStyleRect | TextStream::Formatting::LayoutUnitsAsIntegers);
     bool isFirstCounter = true;
     // The counter renderers should be children of :before or :after pseudo-elements.
     if (PseudoElement* before = element->beforePseudoElement())
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to