Add dumping for BorderData and StyleBackgroundData
https://bugs.webkit.org/show_bug.cgi?id=203038

Reviewed by Zalan Bujtas.

As part of adding dumping for all RenderStyle data, add dumping support for
BorderData and StyleBackgroundData.

For large classes it's beneficial to avoid dumping default values; those classes
get a dump() function that can take an argument to say whether values which are default
should be printed.

* Sources.txt:
* WebCore.xcodeproj/project.pbxproj:
* platform/LengthSize.h:
(WebCore::LengthSize::isZero const):
* rendering/style/BorderData.cpp: Added.
(WebCore::operator<<):
(WebCore::BorderData::dump const):
* rendering/style/BorderData.h:
* rendering/style/RenderStyleConstants.h:
* rendering/style/StyleBackgroundData.cpp:
(WebCore::StyleBackgroundData::dump const):
(WebCore::operator<<):
* rendering/style/StyleBackgroundData.h:


git-svn-id: http://svn.webkit.org/repository/webkit/trunk@251207 268f45cc-cd09-0410-ab3c-d52691b4dbfc
diff --git a/Source/WebCore/ChangeLog b/Source/WebCore/ChangeLog
index 33918e9..b7ab961 100644
--- a/Source/WebCore/ChangeLog
+++ b/Source/WebCore/ChangeLog
@@ -1,3 +1,31 @@
+2019-10-16  Simon Fraser  <simon.fraser@apple.com>
+
+        Add dumping for BorderData and StyleBackgroundData
+        https://bugs.webkit.org/show_bug.cgi?id=203038
+
+        Reviewed by Zalan Bujtas.
+
+        As part of adding dumping for all RenderStyle data, add dumping support for 
+        BorderData and StyleBackgroundData.
+        
+        For large classes it's beneficial to avoid dumping default values; those classes
+        get a dump() function that can take an argument to say whether values which are default
+        should be printed.
+
+        * Sources.txt:
+        * WebCore.xcodeproj/project.pbxproj:
+        * platform/LengthSize.h:
+        (WebCore::LengthSize::isZero const):
+        * rendering/style/BorderData.cpp: Added.
+        (WebCore::operator<<):
+        (WebCore::BorderData::dump const):
+        * rendering/style/BorderData.h:
+        * rendering/style/RenderStyleConstants.h:
+        * rendering/style/StyleBackgroundData.cpp:
+        (WebCore::StyleBackgroundData::dump const):
+        (WebCore::operator<<):
+        * rendering/style/StyleBackgroundData.h:
+
 2019-10-16  Chris Dumez  <cdumez@apple.com>
 
         [WK2] Handle back/forward cache entry expiration in the UIProcess instead of the WebProcess
diff --git a/Source/WebCore/Sources.txt b/Source/WebCore/Sources.txt
index e8fcb1e..d9bb9af 100644
--- a/Source/WebCore/Sources.txt
+++ b/Source/WebCore/Sources.txt
@@ -2219,6 +2219,7 @@
 rendering/shapes/ShapeOutsideInfo.cpp
 
 rendering/style/BasicShapes.cpp
+rendering/style/BorderData.cpp
 rendering/style/ContentData.cpp
 rendering/style/FillLayer.cpp
 rendering/style/GapLength.cpp
diff --git a/Source/WebCore/WebCore.xcodeproj/project.pbxproj b/Source/WebCore/WebCore.xcodeproj/project.pbxproj
index b2cab02..3b36679 100644
--- a/Source/WebCore/WebCore.xcodeproj/project.pbxproj
+++ b/Source/WebCore/WebCore.xcodeproj/project.pbxproj
@@ -5632,6 +5632,7 @@
 		0F26A7AC2055C8D70090A141 /* XMLDocument.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = XMLDocument.cpp; sourceTree = "<group>"; };
 		0F26A7AD205626100090A141 /* SVGUnknownElement.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = SVGUnknownElement.cpp; sourceTree = "<group>"; };
 		0F283A8D235582F8004794CA /* ThemeTypes.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = ThemeTypes.cpp; sourceTree = "<group>"; };
+		0F283A9123563126004794CA /* BorderData.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = BorderData.cpp; sourceTree = "<group>"; };
 		0F36E7361BD1837A002DB891 /* LayoutPoint.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = LayoutPoint.cpp; sourceTree = "<group>"; };
 		0F36E7381BD184B9002DB891 /* LayoutSize.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = LayoutSize.cpp; sourceTree = "<group>"; };
 		0F37F0832202AC8F00A89C0B /* ScrollingTreeScrollingNodeDelegateMac.mm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.objcpp; path = ScrollingTreeScrollingNodeDelegateMac.mm; sourceTree = "<group>"; };
@@ -25170,6 +25171,7 @@
 			children = (
 				FBD6AF8215EF21A3008B7110 /* BasicShapes.cpp */,
 				FBD6AF8315EF21A3008B7110 /* BasicShapes.h */,
+				0F283A9123563126004794CA /* BorderData.cpp */,
 				BC5EB5E00E81BE8700B25965 /* BorderData.h */,
 				BC5EB5DA0E81B7EA00B25965 /* BorderValue.h */,
 				BC5EB5DE0E81B9AB00B25965 /* CollapsedBorderValue.h */,
diff --git a/Source/WebCore/platform/LengthSize.h b/Source/WebCore/platform/LengthSize.h
index 22a81bf..bd5741a 100644
--- a/Source/WebCore/platform/LengthSize.h
+++ b/Source/WebCore/platform/LengthSize.h
@@ -28,6 +28,7 @@
     Length height;
 
     bool isEmpty() const { return width.isZero() || height.isZero(); }
+    bool isZero() const { return width.isZero() && height.isZero(); }
 };
 
 ALWAYS_INLINE bool operator==(const LengthSize& a, const LengthSize& b)
diff --git a/Source/WebCore/rendering/style/BorderData.cpp b/Source/WebCore/rendering/style/BorderData.cpp
new file mode 100644
index 0000000..fcb489c
--- /dev/null
+++ b/Source/WebCore/rendering/style/BorderData.cpp
@@ -0,0 +1,76 @@
+/*
+* Copyright (C) 2019 Apple Inc. All rights reserved.
+*
+* Redistribution and use in source and binary forms, with or without
+* modification, are permitted provided that the following conditions
+* are met:
+* 1. Redistributions of source code must retain the above copyright
+*    notice, this list of conditions and the following disclaimer.
+* 2. Redistributions in binary form must reproduce the above copyright
+*    notice, this list of conditions and the following disclaimer in the
+*    documentation and/or other materials provided with the distribution.
+*
+* THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+* THE POSSIBILITY OF SUCH DAMAGE.
+*/
+
+#include "config.h"
+#include "BorderData.h"
+
+#include "OutlineValue.h"
+#include <wtf/text/TextStream.h>
+
+namespace WebCore {
+
+TextStream& operator<<(TextStream& ts, const BorderValue& borderValue)
+{
+    ts << borderValue.width() << " " << borderValue.style() << " " << borderValue.color();
+    return ts;
+}
+
+TextStream& operator<<(TextStream& ts, const OutlineValue& outlineValue)
+{
+    ts << static_cast<const BorderValue&>(outlineValue);
+    ts.dumpProperty("outline-offset", outlineValue.offset());
+    return ts;
+}
+
+void BorderData::dump(TextStream& ts, DumpStyleValues behavior) const
+{
+    if (behavior == DumpStyleValues::All || left() != BorderValue())
+        ts.dumpProperty("left", left());
+    if (behavior == DumpStyleValues::All || right() != BorderValue())
+        ts.dumpProperty("right", right());
+    if (behavior == DumpStyleValues::All || top() != BorderValue())
+        ts.dumpProperty("top", top());
+    if (behavior == DumpStyleValues::All || bottom() != BorderValue())
+        ts.dumpProperty("bottom", bottom());
+
+    ts.dumpProperty("image", image());
+
+    if (behavior == DumpStyleValues::All || !topLeftRadius().isZero())
+        ts.dumpProperty("top-left", topLeftRadius());
+    if (behavior == DumpStyleValues::All || !topRightRadius().isZero())
+        ts.dumpProperty("top-right", topRightRadius());
+    if (behavior == DumpStyleValues::All || !bottomLeftRadius().isZero())
+        ts.dumpProperty("bottom-left", bottomLeftRadius());
+    if (behavior == DumpStyleValues::All || !bottomRightRadius().isZero())
+        ts.dumpProperty("bottom-right", bottomRightRadius());
+}
+
+TextStream& operator<<(TextStream& ts, const BorderData& borderData)
+{
+    borderData.dump(ts);
+    return ts;
+}
+
+} // namespace WebCore
diff --git a/Source/WebCore/rendering/style/BorderData.h b/Source/WebCore/rendering/style/BorderData.h
index 5ccc1c4..6fd5b03 100644
--- a/Source/WebCore/rendering/style/BorderData.h
+++ b/Source/WebCore/rendering/style/BorderData.h
@@ -30,6 +30,8 @@
 
 namespace WebCore {
 
+class OutlineValue;
+
 class BorderData {
 friend class RenderStyle;
 public:
@@ -122,6 +124,8 @@
     const LengthSize& bottomLeftRadius() const { return m_bottomLeftRadius; }
     const LengthSize& bottomRightRadius() const { return m_bottomRightRadius; }
 
+    void dump(TextStream&, DumpStyleValues = DumpStyleValues::All) const;
+
 private:
     BorderValue m_left;
     BorderValue m_right;
@@ -136,4 +140,8 @@
     LengthSize m_bottomRightRadius;
 };
 
+WTF::TextStream& operator<<(WTF::TextStream&, const BorderValue&);
+WTF::TextStream& operator<<(WTF::TextStream&, const OutlineValue&);
+WTF::TextStream& operator<<(WTF::TextStream&, const BorderData&);
+
 } // namespace WebCore
diff --git a/Source/WebCore/rendering/style/RenderStyleConstants.h b/Source/WebCore/rendering/style/RenderStyleConstants.h
index 9b6cfeb..3aebba6 100644
--- a/Source/WebCore/rendering/style/RenderStyleConstants.h
+++ b/Source/WebCore/rendering/style/RenderStyleConstants.h
@@ -33,6 +33,11 @@
 
 namespace WebCore {
 
+enum class DumpStyleValues {
+    All,
+    NonInitial,
+};
+
 static const size_t PrintColorAdjustBits = 1;
 enum class PrintColorAdjust : uint8_t {
     Economy,
diff --git a/Source/WebCore/rendering/style/StyleBackgroundData.cpp b/Source/WebCore/rendering/style/StyleBackgroundData.cpp
index 4b73e40..0afa7c0 100644
--- a/Source/WebCore/rendering/style/StyleBackgroundData.cpp
+++ b/Source/WebCore/rendering/style/StyleBackgroundData.cpp
@@ -60,4 +60,20 @@
     return outline == other.outline;
 }
 
+void StyleBackgroundData::dump(TextStream& ts, DumpStyleValues behavior) const
+{
+    if (behavior == DumpStyleValues::All || background != FillLayer(FillLayerType::Background))
+        ts.dumpProperty("background-image", background);
+    if (behavior == DumpStyleValues::All || color != RenderStyle::initialBackgroundColor())
+        ts.dumpProperty("background-color", color);
+    if (behavior == DumpStyleValues::All || outline != OutlineValue())
+        ts.dumpProperty("outline", outline);
+}
+
+TextStream& operator<<(TextStream& ts, const StyleBackgroundData& backgroundData)
+{
+    backgroundData.dump(ts);
+    return ts;
+}
+
 } // namespace WebCore
diff --git a/Source/WebCore/rendering/style/StyleBackgroundData.h b/Source/WebCore/rendering/style/StyleBackgroundData.h
index 9b95ee0..9793431 100644
--- a/Source/WebCore/rendering/style/StyleBackgroundData.h
+++ b/Source/WebCore/rendering/style/StyleBackgroundData.h
@@ -46,9 +46,13 @@
     Color color;
     OutlineValue outline;
 
+    void dump(TextStream&, DumpStyleValues = DumpStyleValues::All) const;
+
 private:
     StyleBackgroundData();
     StyleBackgroundData(const StyleBackgroundData&);
 };
 
+WTF::TextStream& operator<<(WTF::TextStream&, const StyleBackgroundData&);
+
 } // namespace WebCore