Add TextStream-based logging for Position and VisiblePosition
authorsimon.fraser@apple.com <simon.fraser@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 18 Jan 2016 21:27:53 +0000 (21:27 +0000)
committersimon.fraser@apple.com <simon.fraser@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 18 Jan 2016 21:27:53 +0000 (21:27 +0000)
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:

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

Source/WebCore/ChangeLog
Source/WebCore/dom/Position.cpp
Source/WebCore/dom/Position.h
Source/WebCore/editing/VisiblePosition.cpp
Source/WebCore/editing/VisiblePosition.h

index 131c5d8..c1d1293 100644 (file)
@@ -1,3 +1,19 @@
+2016-01-18  Simon Fraser  <simon.fraser@apple.com>
+
+        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  <zdobersek@igalia.com>
 
         Sink the Vector<uint8_t> buffer into the SerializedScriptValue constructor
index f876308..f6828d1 100644 (file)
@@ -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 @@ bool Position::equals(const Position& other) const
     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)
index 78e082e..ab07051 100644 (file)
@@ -44,6 +44,7 @@ class Range;
 class RenderElement;
 class RenderObject;
 class Text;
+class TextStream;
 
 enum PositionMoveType {
     CodePoint,       // Move by a single code point.
@@ -343,6 +344,8 @@ inline bool offsetIsBeforeLastNodeOffset(int offset, Node* anchorNode)
     return offset < currentOffset;
 }
 
+TextStream& operator<<(TextStream&, const Position&);
+
 } // namespace WebCore
 
 #if ENABLE(TREE_DEBUGGING)
index e3f1e57..e3cd7a6 100644 (file)
@@ -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 @@ bool VisiblePosition::equals(const VisiblePosition& other) const
     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)
index 85ad177..5e64ef5 100644 (file)
@@ -47,6 +47,7 @@ namespace WebCore {
 
 class InlineBox;
 class Node;
+class TextStream;
 
 class VisiblePosition {
 public:
@@ -163,6 +164,9 @@ WEBCORE_EXPORT Element* enclosingBlockFlowElement(const VisiblePosition&);
 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)