Bug 1596339 Part 1 - Implement operator<< for WritingMode, and use it in frame tree dump. r=dholbert
authorTing-Yu Lin <tlin@mozilla.com>
Fri, 15 Nov 2019 03:51:54 +0000
changeset 502115 591e273e2d9e111a9901b2639a593033130d7a10
parent 502114 2007edb47f8ffdda9ef310c833e131ac7efc230f
child 502116 583f09d7e18124985da8eafd546b719f885ae898
push id114172
push userdluca@mozilla.com
push dateTue, 19 Nov 2019 11:31:10 +0000
treeherdermozilla-inbound@b5c5ba07d3db [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersdholbert
bugs1596339
milestone72.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1596339 Part 1 - Implement operator<< for WritingMode, and use it in frame tree dump. r=dholbert WritingMode.h already depends on ostream header implicitly via nsBidiUtils.h -> nsString.h. For completeness, I still add #include <ostream>. While I'm here, I make the format of debug prints in nsLineBox more consistent with the counter-part in nsFrame. Some of them will be revised in the later patches. Differential Revision: https://phabricator.services.mozilla.com/D52962
layout/generic/WritingModes.h
layout/generic/nsFrame.cpp
layout/generic/nsLineBox.cpp
--- a/layout/generic/WritingModes.h
+++ b/layout/generic/WritingModes.h
@@ -2,16 +2,18 @@
 /* vim: set ts=8 sts=2 et sw=2 tw=80: */
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #ifndef WritingModes_h_
 #define WritingModes_h_
 
+#include <ostream>
+
 #include "mozilla/ComputedStyle.h"
 #include "mozilla/ComputedStyleInlines.h"
 
 #include "nsRect.h"
 #include "nsBidiUtils.h"
 
 // It is the caller's responsibility to operate on logical-coordinate objects
 // with matched writing modes. Failure to do so will be a runtime bug; the
@@ -583,26 +585,16 @@ class WritingMode {
 
     NS_ASSERTION(myStartSide % 2 == otherWMStartSide % 2,
                  "Should end up with sides in the same physical axis");
     return myStartSide == otherWMStartSide;
   }
 
   uint8_t GetBits() const { return mWritingMode.bits; }
 
-  const char* DebugString() const {
-    return IsVertical()
-               ? IsVerticalLR()
-                     ? IsBidiLTR() ? IsSideways() ? "sw-lr-ltr" : "v-lr-ltr"
-                                   : IsSideways() ? "sw-lr-rtl" : "v-lr-rtl"
-                     : IsBidiLTR() ? IsSideways() ? "sw-rl-ltr" : "v-rl-ltr"
-                                   : IsSideways() ? "sw-rl-rtl" : "v-rl-rtl"
-               : IsBidiLTR() ? "h-ltr" : "h-rtl";
-  }
-
  private:
   friend class LogicalPoint;
   friend class LogicalSize;
   friend class LogicalMargin;
   friend class LogicalRect;
 
   friend struct IPC::ParamTraits<WritingMode>;
   // IMENotification cannot store this class directly since this has some
@@ -627,16 +619,29 @@ class WritingMode {
 
   enum Masks {
     // Masks for output enums
     eInlineMask = 0x03,  // VERTICAL | INLINE_REVERSED
     eBlockMask = 0x05,   // VERTICAL | VERTICAL_LR
   };
 };
 
+inline std::ostream& operator<<(std::ostream& aStream, const WritingMode& aWM) {
+  return aStream
+         << (aWM.IsVertical()
+                 ? aWM.IsVerticalLR()
+                       ? aWM.IsBidiLTR()
+                             ? aWM.IsSideways() ? "sw-lr-ltr" : "v-lr-ltr"
+                             : aWM.IsSideways() ? "sw-lr-rtl" : "v-lr-rtl"
+                       : aWM.IsBidiLTR()
+                             ? aWM.IsSideways() ? "sw-rl-ltr" : "v-rl-ltr"
+                             : aWM.IsSideways() ? "sw-rl-rtl" : "v-rl-rtl"
+                 : aWM.IsBidiLTR() ? "h-ltr" : "h-rtl");
+}
+
 /**
  * Logical-coordinate classes:
  *
  * There are three sets of coordinate space:
  *   - physical (top, left, bottom, right)
  *       relative to graphics coord system
  *   - flow-relative (block-start, inline-start, block-end, inline-end)
  *       relative to block/inline flow directions
--- a/layout/generic/nsFrame.cpp
+++ b/layout/generic/nsFrame.cpp
@@ -20,16 +20,17 @@
 #include "mozilla/dom/Selection.h"
 #include "mozilla/gfx/2D.h"
 #include "mozilla/gfx/gfxVars.h"
 #include "mozilla/gfx/PathHelpers.h"
 #include "mozilla/PresShell.h"
 #include "mozilla/PresShellInlines.h"
 #include "mozilla/Sprintf.h"
 #include "mozilla/StaticPrefs_layout.h"
+#include "mozilla/ToString.h"
 
 #include "nsCOMPtr.h"
 #include "nsFlexContainerFrame.h"
 #include "nsFrameList.h"
 #include "nsPlaceholderFrame.h"
 #include "nsPluginFrame.h"
 #include "nsIBaseWindow.h"
 #include "nsIContent.h"
@@ -7841,29 +7842,29 @@ void nsIFrame::ListGeneric(nsACString& a
   if (IBprevsibling) {
     aTo += nsPrintfCString(" IBSplitPrevSibling=%p", IBprevsibling);
   }
   aTo += nsPrintfCString(" {%d,%d,%d,%d}", mRect.x, mRect.y, mRect.width,
                          mRect.height);
 
   mozilla::WritingMode wm = GetWritingMode();
   if (wm.IsVertical() || wm.IsBidiRTL()) {
-    aTo += nsPrintfCString(" wm=%s logical-size={%d,%d}", wm.DebugString(),
+    aTo += nsPrintfCString(" wm=%s logical-size={%d,%d}", ToString(wm).c_str(),
                            ISize(), BSize());
   }
 
   nsIFrame* parent = GetParent();
   if (parent) {
     WritingMode pWM = parent->GetWritingMode();
     if (pWM.IsVertical() || pWM.IsBidiRTL()) {
       nsSize containerSize = parent->mRect.Size();
       LogicalRect lr(pWM, mRect, containerSize);
       aTo += nsPrintfCString(
-          " parent-wm=%s cs={%d,%d} logicalRect={%d,%d,%d,%d}",
-          pWM.DebugString(), containerSize.width, containerSize.height,
+          " parent-wm=%s cs={%d,%d} logical-rect={%d,%d,%d,%d}",
+          ToString(pWM).c_str(), containerSize.width, containerSize.height,
           lr.IStart(pWM), lr.BStart(pWM), lr.ISize(pWM), lr.BSize(pWM));
     }
   }
   nsIFrame* f = const_cast<nsIFrame*>(this);
   if (f->HasOverflowAreas()) {
     nsRect vo = f->GetVisualOverflowRect();
     if (!vo.IsEqualEdges(mRect)) {
       aTo += nsPrintfCString(" vis-overflow={%d,%d,%d,%d}", vo.x, vo.y,
--- a/layout/generic/nsLineBox.cpp
+++ b/layout/generic/nsLineBox.cpp
@@ -9,16 +9,17 @@
 #include "nsLineBox.h"
 
 #include "mozilla/ArenaObjectID.h"
 #include "mozilla/Assertions.h"
 #include "mozilla/Likely.h"
 #include "mozilla/PresShell.h"
 #include "mozilla/Sprintf.h"
 #include "mozilla/WritingModes.h"
+#include "mozilla/ToString.h"
 #include "nsBidiPresUtils.h"
 #include "nsFrame.h"
 #include "nsIFrameInlines.h"
 #include "nsPresArena.h"
 #include "nsPrintfCString.h"
 #include "nsWindowSizes.h"
 
 #ifdef DEBUG
@@ -239,20 +240,20 @@ void nsLineBox::List(FILE* out, const ch
                          StateToString(cbuf, sizeof(cbuf)));
   if (IsBlock() && !GetCarriedOutBEndMargin().IsZero()) {
     str += nsPrintfCString("bm=%d ", GetCarriedOutBEndMargin().get());
   }
   nsRect bounds = GetPhysicalBounds();
   str += nsPrintfCString("{%d,%d,%d,%d} ", bounds.x, bounds.y, bounds.width,
                          bounds.height);
   if (mWritingMode.IsVertical() || mWritingMode.IsBidiRTL()) {
-    str +=
-        nsPrintfCString("{%s: %d,%d,%d,%d; cs=%d,%d} ",
-                        mWritingMode.DebugString(), IStart(), BStart(), ISize(),
-                        BSize(), mContainerSize.width, mContainerSize.height);
+    str += nsPrintfCString("wm=%s cs={%d,%d} logical-rect={%d,%d,%d,%d} ",
+                           ToString(mWritingMode).c_str(), mContainerSize.width,
+                           mContainerSize.height, IStart(), BStart(), ISize(),
+                           BSize());
   }
   if (mData &&
       (!mData->mOverflowAreas.VisualOverflow().IsEqualEdges(bounds) ||
        !mData->mOverflowAreas.ScrollableOverflow().IsEqualEdges(bounds))) {
     str += nsPrintfCString("vis-overflow=%d,%d,%d,%d scr-overflow=%d,%d,%d,%d ",
                            mData->mOverflowAreas.VisualOverflow().x,
                            mData->mOverflowAreas.VisualOverflow().y,
                            mData->mOverflowAreas.VisualOverflow().width,