- Revision
- 259557
- Author
- [email protected]
- Date
- 2020-04-05 16:23:59 -0700 (Sun, 05 Apr 2020)
Log Message
Make RenderObject TextStream-loggable
https://bugs.webkit.org/show_bug.cgi?id=210035
Reviewed by Zalan Bujtas.
Add operator<<(TextStream, const RenderObject&) and add virtual debugDescription() functions on
Node and RenderObject which should eventually replace the awkward formatForDebugger(char* buffer, unsigned length).
Convert RenderLayer to use renderer's debug description.
* dom/Element.cpp:
(WebCore::Element::debugDescription const):
* dom/Element.h:
* dom/Node.cpp:
(WebCore::Node::debugDescription const):
(WebCore::operator<<):
* dom/Node.h:
* rendering/RenderLayer.cpp:
(WebCore::RenderLayer::name const):
* rendering/RenderObject.cpp:
(WebCore::RenderObject::debugDescription const):
(WebCore::operator<<):
* rendering/RenderObject.h:
Modified Paths
Diff
Modified: trunk/Source/WebCore/ChangeLog (259556 => 259557)
--- trunk/Source/WebCore/ChangeLog 2020-04-05 22:59:45 UTC (rev 259556)
+++ trunk/Source/WebCore/ChangeLog 2020-04-05 23:23:59 UTC (rev 259557)
@@ -1,3 +1,29 @@
+2020-04-05 Simon Fraser <[email protected]>
+
+ Make RenderObject TextStream-loggable
+ https://bugs.webkit.org/show_bug.cgi?id=210035
+
+ Reviewed by Zalan Bujtas.
+
+ Add operator<<(TextStream, const RenderObject&) and add virtual debugDescription() functions on
+ Node and RenderObject which should eventually replace the awkward formatForDebugger(char* buffer, unsigned length).
+
+ Convert RenderLayer to use renderer's debug description.
+
+ * dom/Element.cpp:
+ (WebCore::Element::debugDescription const):
+ * dom/Element.h:
+ * dom/Node.cpp:
+ (WebCore::Node::debugDescription const):
+ (WebCore::operator<<):
+ * dom/Node.h:
+ * rendering/RenderLayer.cpp:
+ (WebCore::RenderLayer::name const):
+ * rendering/RenderObject.cpp:
+ (WebCore::RenderObject::debugDescription const):
+ (WebCore::operator<<):
+ * rendering/RenderObject.h:
+
2020-04-05 Zan Dobersek <[email protected]>
Unreviewed, adding missing header inclusions to get
Modified: trunk/Source/WebCore/dom/Element.cpp (259556 => 259557)
--- trunk/Source/WebCore/dom/Element.cpp 2020-04-05 22:59:45 UTC (rev 259556)
+++ trunk/Source/WebCore/dom/Element.cpp 2020-04-05 23:23:59 UTC (rev 259557)
@@ -2641,6 +2641,41 @@
checkForSiblingStyleChanges(*this, FinishedParsingChildren, ElementTraversal::lastChild(*this), nullptr);
}
+String Element::debugDescription() const
+{
+ StringBuilder builder;
+
+ builder.append(nodeName());
+
+ if (hasID()) {
+ builder.appendLiteral(" id=\'");
+ builder.append(getIdAttribute());
+ builder.append('\'');
+ }
+
+ if (hasClass()) {
+ builder.appendLiteral(" class=\'");
+ size_t classNamesToDump = classNames().size();
+ const size_t maxNumClassNames = 7;
+ bool addEllipsis = false;
+ if (classNamesToDump > maxNumClassNames) {
+ classNamesToDump = maxNumClassNames;
+ addEllipsis = true;
+ }
+
+ for (size_t i = 0; i < classNamesToDump; ++i) {
+ if (i > 0)
+ builder.append(' ');
+ builder.append(classNames()[i]);
+ }
+ if (addEllipsis)
+ builder.append("...");
+ builder.append('\'');
+ }
+
+ return builder.toString();
+}
+
#if ENABLE(TREE_DEBUGGING)
void Element::formatForDebugger(char* buffer, unsigned length) const
Modified: trunk/Source/WebCore/dom/Element.h (259556 => 259557)
--- trunk/Source/WebCore/dom/Element.h 2020-04-05 22:59:45 UTC (rev 259556)
+++ trunk/Source/WebCore/dom/Element.h 2020-04-05 23:23:59 UTC (rev 259557)
@@ -615,6 +615,8 @@
ElementIdentifier createElementIdentifier();
+ String debugDescription() const override;
+
protected:
Element(const QualifiedName&, Document&, ConstructionType);
@@ -686,7 +688,7 @@
LayoutRect absoluteEventBounds(bool& boundsIncludeAllDescendantElements, bool& includesFixedPositionElements);
LayoutRect absoluteEventBoundsOfElementAndDescendants(bool& includesFixedPositionElements);
-
+
#if ENABLE(TREE_DEBUGGING)
void formatForDebugger(char* buffer, unsigned length) const override;
#endif
Modified: trunk/Source/WebCore/dom/Node.cpp (259556 => 259557)
--- trunk/Source/WebCore/dom/Node.cpp 2020-04-05 22:59:45 UTC (rev 259556)
+++ trunk/Source/WebCore/dom/Node.cpp 2020-04-05 23:23:59 UTC (rev 259557)
@@ -1751,6 +1751,32 @@
return p;
}
+String Node::debugDescription() const
+{
+ StringBuilder builder;
+
+ builder.append(nodeName());
+
+ if (isTextNode()) {
+ String value = nodeValue();
+ value.replaceWithLiteral('\\', "\\\\");
+ value.replaceWithLiteral('\n', "\\n");
+
+ const size_t maxDumpLength = 30;
+ if (value.length() > maxDumpLength) {
+ value.truncate(maxDumpLength - 10);
+ value.append("..."_s);
+ }
+
+ builder.append(' ');
+ builder.append('\"');
+ builder.append(value);
+ builder.append('\"');
+ }
+
+ return builder.toString();
+}
+
#if ENABLE(TREE_DEBUGGING)
static void appendAttributeDesc(const Node* node, StringBuilder& stringBuilder, const QualifiedName& name, const char* attrDesc)
@@ -2619,15 +2645,7 @@
TextStream& operator<<(TextStream& ts, const Node& node)
{
-#if ENABLE(TREE_DEBUGGING)
- const size_t FormatBufferSize = 512;
- char s[FormatBufferSize];
- node.formatForDebugger(s, FormatBufferSize);
- ts << "node " << &node << " " << s;
-#else
- ts << "node " << &node << " " << node.nodeName();
-#endif
-
+ ts << "node " << &node << " " << node.debugDescription();
return ts;
}
Modified: trunk/Source/WebCore/dom/Node.h (259556 => 259557)
--- trunk/Source/WebCore/dom/Node.h 2020-04-05 22:59:45 UTC (rev 259556)
+++ trunk/Source/WebCore/dom/Node.h 2020-04-05 23:23:59 UTC (rev 259557)
@@ -431,6 +431,8 @@
};
virtual void removedFromAncestor(RemovalType, ContainerNode& oldParentOfRemovedTree);
+ virtual String debugDescription() const;
+
#if ENABLE(TREE_DEBUGGING)
virtual void formatForDebugger(char* buffer, unsigned length) const;
Modified: trunk/Source/WebCore/rendering/RenderLayer.cpp (259556 => 259557)
--- trunk/Source/WebCore/rendering/RenderLayer.cpp 2020-04-05 22:59:45 UTC (rev 259556)
+++ trunk/Source/WebCore/rendering/RenderLayer.cpp 2020-04-05 23:23:59 UTC (rev 259557)
@@ -830,40 +830,8 @@
String RenderLayer::name() const
{
StringBuilder name;
+ name.append(renderer().debugDescription());
- if (Element* element = renderer().element()) {
- name.append(" <");
- name.append(element->tagName().convertToLowercaseWithoutLocale());
- name.append('>');
-
- if (element->hasID()) {
- name.appendLiteral(" id=\'");
- name.append(element->getIdAttribute());
- name.append('\'');
- }
-
- if (element->hasClass()) {
- name.appendLiteral(" class=\'");
- size_t classNamesToDump = element->classNames().size();
- const size_t maxNumClassNames = 7;
- bool addEllipsis = false;
- if (classNamesToDump > maxNumClassNames) {
- classNamesToDump = maxNumClassNames;
- addEllipsis = true;
- }
-
- for (size_t i = 0; i < classNamesToDump; ++i) {
- if (i > 0)
- name.append(' ');
- name.append(element->classNames()[i]);
- }
- if (addEllipsis)
- name.append("...");
- name.append('\'');
- }
- } else
- name.append(renderer().renderName());
-
if (isReflection())
name.appendLiteral(" (reflection)");
Modified: trunk/Source/WebCore/rendering/RenderObject.cpp (259556 => 259557)
--- trunk/Source/WebCore/rendering/RenderObject.cpp 2020-04-05 22:59:45 UTC (rev 259556)
+++ trunk/Source/WebCore/rendering/RenderObject.cpp 2020-04-05 23:23:59 UTC (rev 259557)
@@ -71,6 +71,7 @@
#include "TransformState.h"
#include <algorithm>
#include <stdio.h>
+#include <wtf/HexNumber.h>
#include <wtf/IsoMallocInlines.h>
#include <wtf/RefCountedLeakCounter.h>
#include <wtf/text/TextStream.h>
@@ -1907,6 +1908,27 @@
return false;
}
+String RenderObject::debugDescription() const
+{
+ StringBuilder builder;
+
+ builder.append(renderName());
+ builder.append(" 0x"_s);
+ builder.append(hex(reinterpret_cast<uintptr_t>(this), Lowercase));
+ builder.append(' ');
+
+ if (node())
+ builder.append(node()->debugDescription());
+
+ return builder.toString();
+}
+
+TextStream& operator<<(TextStream& ts, const RenderObject& renderer)
+{
+ ts << renderer.debugDescription();
+ return ts;
+}
+
#if ENABLE(TREE_DEBUGGING)
void printRenderTreeForLiveDocuments()
Modified: trunk/Source/WebCore/rendering/RenderObject.h (259556 => 259557)
--- trunk/Source/WebCore/rendering/RenderObject.h 2020-04-05 22:59:45 UTC (rev 259556)
+++ trunk/Source/WebCore/rendering/RenderObject.h 2020-04-05 23:23:59 UTC (rev 259557)
@@ -39,6 +39,10 @@
#include <wtf/IsoMalloc.h>
#include <wtf/WeakPtr.h>
+namespace WTF {
+class TextStream;
+}
+
namespace WebCore {
class AffineTransform;
@@ -779,6 +783,8 @@
void initializeFragmentedFlowStateOnInsertion();
virtual void insertedIntoTree();
+ virtual String debugDescription() const;
+
protected:
//////////////////////////////////////////
// Helper functions. Dangerous to use!
@@ -1106,6 +1112,8 @@
inline void Node::setRenderer(RenderObject* renderer) { m_rendererWithStyleFlags.setPointer(renderer); }
+WTF::TextStream& operator<<(WTF::TextStream&, const RenderObject&);
+
#if ENABLE(TREE_DEBUGGING)
void printRenderTreeForLiveDocuments();
void printLayerTreeForLiveDocuments();