Title: [195237] trunk/Source/WebCore
Revision
195237
Author
[email protected]
Date
2016-01-18 13:27:53 -0800 (Mon, 18 Jan 2016)

Log Message

Add TextStream-based logging for Position and VisiblePosition
https://bugs.webkit.org/show_bug.cgi?id=153195

Reviewed by Ryosuke Niwa.

Make it easy to dump Positions and VisiblePositions with a TextStream.

* dom/Position.cpp:
(WebCore::operator<<):
* dom/Position.h:
* editing/VisiblePosition.cpp:
(WebCore::operator<<):
* editing/VisiblePosition.h:

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (195236 => 195237)


--- trunk/Source/WebCore/ChangeLog	2016-01-18 21:07:08 UTC (rev 195236)
+++ trunk/Source/WebCore/ChangeLog	2016-01-18 21:27:53 UTC (rev 195237)
@@ -1,3 +1,19 @@
+2016-01-18  Simon Fraser  <[email protected]>
+
+        Add TextStream-based logging for Position and VisiblePosition
+        https://bugs.webkit.org/show_bug.cgi?id=153195
+
+        Reviewed by Ryosuke Niwa.
+
+        Make it easy to dump Positions and VisiblePositions with a TextStream.
+
+        * dom/Position.cpp:
+        (WebCore::operator<<):
+        * dom/Position.h:
+        * editing/VisiblePosition.cpp:
+        (WebCore::operator<<):
+        * editing/VisiblePosition.h:
+
 2016-01-18  Zan Dobersek  <[email protected]>
 
         Sink the Vector<uint8_t> buffer into the SerializedScriptValue constructor

Modified: trunk/Source/WebCore/dom/Position.cpp (195236 => 195237)


--- trunk/Source/WebCore/dom/Position.cpp	2016-01-18 21:07:08 UTC (rev 195236)
+++ trunk/Source/WebCore/dom/Position.cpp	2016-01-18 21:27:53 UTC (rev 195237)
@@ -44,6 +44,7 @@
 #include "RuntimeEnabledFeatures.h"
 #include "Text.h"
 #include "TextIterator.h"
+#include "TextStream.h"
 #include "VisiblePosition.h"
 #include "VisibleUnits.h"
 #include "htmlediting.h"
@@ -1549,6 +1550,40 @@
     return false;
 }
 
+static TextStream& operator<<(TextStream& stream, Position::AnchorType anchorType)
+{
+    switch (anchorType) {
+    case Position::PositionIsOffsetInAnchor:
+        stream << "offset in anchor";
+        break;
+    case Position::PositionIsBeforeAnchor:
+        stream << "before anchor";
+        break;
+    case Position::PositionIsAfterAnchor:
+        stream << "after anchor";
+        break;
+    case Position::PositionIsBeforeChildren:
+        stream << "before children";
+        break;
+    case Position::PositionIsAfterChildren:
+        stream << "after children";
+        break;
+    }
+    return stream;
+}
+
+TextStream& operator<<(TextStream& stream, const Position& position)
+{
+    TextStream::GroupScope scope(stream);
+    stream << "Position " << &position;
+
+    stream.dumpProperty("anchor node", position.anchorNode());
+    stream.dumpProperty("offset", position.offsetInContainerNode());
+    stream.dumpProperty("anchor type", position.anchorType());
+
+    return stream;
+}
+
 } // namespace WebCore
 
 #if ENABLE(TREE_DEBUGGING)

Modified: trunk/Source/WebCore/dom/Position.h (195236 => 195237)


--- trunk/Source/WebCore/dom/Position.h	2016-01-18 21:07:08 UTC (rev 195236)
+++ trunk/Source/WebCore/dom/Position.h	2016-01-18 21:27:53 UTC (rev 195237)
@@ -44,6 +44,7 @@
 class RenderElement;
 class RenderObject;
 class Text;
+class TextStream;
 
 enum PositionMoveType {
     CodePoint,       // Move by a single code point.
@@ -343,6 +344,8 @@
     return offset < currentOffset;
 }
 
+TextStream& operator<<(TextStream&, const Position&);
+
 } // namespace WebCore
 
 #if ENABLE(TREE_DEBUGGING)

Modified: trunk/Source/WebCore/editing/VisiblePosition.cpp (195236 => 195237)


--- trunk/Source/WebCore/editing/VisiblePosition.cpp	2016-01-18 21:07:08 UTC (rev 195236)
+++ trunk/Source/WebCore/editing/VisiblePosition.cpp	2016-01-18 21:27:53 UTC (rev 195237)
@@ -37,6 +37,7 @@
 #include "RenderBlock.h"
 #include "RootInlineBox.h"
 #include "Text.h"
+#include "TextStream.h"
 #include "VisibleUnits.h"
 #include "htmlediting.h"
 #include <stdio.h>
@@ -748,6 +749,30 @@
     return m_affinity == other.m_affinity && m_deepPosition.equals(other.m_deepPosition);
 }
 
+TextStream& operator<<(TextStream& stream, EAffinity affinity)
+{
+    switch (affinity) {
+    case UPSTREAM:
+        stream << "upstream";
+        break;
+    case DOWNSTREAM:
+        stream << "downstream";
+        break;
+    }
+    return stream;
+}
+
+TextStream& operator<<(TextStream& stream, const VisiblePosition& visiblePosition)
+{
+    TextStream::GroupScope scope(stream);
+    stream << "VisiblePosition " << &visiblePosition;
+
+    stream.dumpProperty("position", visiblePosition.deepEquivalent());
+    stream.dumpProperty("affinity", visiblePosition.affinity());
+
+    return stream;
+}
+
 }  // namespace WebCore
 
 #if ENABLE(TREE_DEBUGGING)

Modified: trunk/Source/WebCore/editing/VisiblePosition.h (195236 => 195237)


--- trunk/Source/WebCore/editing/VisiblePosition.h	2016-01-18 21:07:08 UTC (rev 195236)
+++ trunk/Source/WebCore/editing/VisiblePosition.h	2016-01-18 21:27:53 UTC (rev 195237)
@@ -47,6 +47,7 @@
 
 class InlineBox;
 class Node;
+class TextStream;
 
 class VisiblePosition {
 public:
@@ -163,6 +164,9 @@
 bool isFirstVisiblePositionInNode(const VisiblePosition&, const Node*);
 bool isLastVisiblePositionInNode(const VisiblePosition&, const Node*);
 
+TextStream& operator<<(TextStream&, EAffinity);
+TextStream& operator<<(TextStream&, const VisiblePosition&);
+
 } // namespace WebCore
 
 #if ENABLE(TREE_DEBUGGING)
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to