Bug 1116037 part 1 - Move TextContainerIterator to RubyUtils. r=dbaron
authorXidorn Quan <quanxunzhen@gmail.com>
Mon, 29 Dec 2014 11:14:53 +1100
changeset 247650 cee6e1f4eec926d90a6d2a98052d8aabd35a7ee4
parent 247649 50d9b80dd7a8f56272b1c5fe7605c6ede4a80bb9
child 247651 48d1aa74f0022c979262645f2cc37c1f69526eb9
push id4489
push userraliiev@mozilla.com
push dateMon, 23 Feb 2015 15:17:55 +0000
treeherdermozilla-beta@fd7c3dc24146 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersdbaron
bugs1116037
milestone37.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 1116037 part 1 - Move TextContainerIterator to RubyUtils. r=dbaron
layout/generic/RubyUtils.cpp
layout/generic/RubyUtils.h
layout/generic/nsRubyFrame.cpp
--- a/layout/generic/RubyUtils.cpp
+++ b/layout/generic/RubyUtils.cpp
@@ -1,16 +1,15 @@
 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
 /* 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/. */
 
 #include "RubyUtils.h"
-#include "nsIFrame.h"
 
 using namespace mozilla;
 
 NS_DECLARE_FRAME_PROPERTY(ReservedISize, nullptr);
 
 union NSCoordValue
 {
   nscoord mCoord;
@@ -37,8 +36,25 @@ RubyUtils::ClearReservedISize(nsIFrame* 
 /* static */ nscoord
 RubyUtils::GetReservedISize(nsIFrame* aFrame)
 {
   MOZ_ASSERT(IsExpandableRubyBox(aFrame));
   NSCoordValue value;
   value.mPointer = aFrame->Properties().Get(ReservedISize());
   return value.mCoord;
 }
+
+RubyTextContainerIterator::RubyTextContainerIterator(
+  nsRubyBaseContainerFrame* aBaseContainer)
+{
+  mFrame = aBaseContainer;
+  Next();
+}
+
+void
+RubyTextContainerIterator::Next()
+{
+  MOZ_ASSERT(mFrame, "Should have checked AtEnd()");
+  mFrame = mFrame->GetNextSibling();
+  if (mFrame && mFrame->GetType() != nsGkAtoms::rubyTextContainerFrame) {
+    mFrame = nullptr;
+  }
+}
--- a/layout/generic/RubyUtils.h
+++ b/layout/generic/RubyUtils.h
@@ -3,17 +3,18 @@
 /* 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 mozilla_RubyUtils_h_
 #define mozilla_RubyUtils_h_
 
 #include "nsGkAtoms.h"
-#include "nsIFrame.h"
+#include "nsRubyBaseContainerFrame.h"
+#include "nsRubyTextContainerFrame.h"
 
 namespace mozilla {
 
 /**
  * Reserved ISize
  *
  * With some exceptions, each ruby internal box has two isizes, which
  * are the reflowed isize and the final isize. The reflowed isize is
@@ -53,11 +54,31 @@ public:
            type == nsGkAtoms::rubyTextContainerFrame;
   }
 
   static void SetReservedISize(nsIFrame* aFrame, nscoord aISize);
   static void ClearReservedISize(nsIFrame* aFrame);
   static nscoord GetReservedISize(nsIFrame* aFrame);
 };
 
+/**
+ * This class iterates all ruby text containers paired with
+ * the given ruby base container.
+ */
+class MOZ_STACK_CLASS RubyTextContainerIterator
+{
+public:
+  explicit RubyTextContainerIterator(nsRubyBaseContainerFrame* aBaseContainer);
+
+  void Next();
+  bool AtEnd() const { return !mFrame; }
+  nsRubyTextContainerFrame* GetTextContainer() const
+  {
+    return static_cast<nsRubyTextContainerFrame*>(mFrame);
+  }
+
+private:
+  nsIFrame* mFrame;
+};
+
 }
 
 #endif /* !defined(mozilla_RubyUtils_h_) */
--- a/layout/generic/nsRubyFrame.cpp
+++ b/layout/generic/nsRubyFrame.cpp
@@ -5,16 +5,17 @@
  * http://mozilla.org/MPL/2.0/. */
 
 /* rendering object for CSS "display: ruby" */
 #include "nsRubyFrame.h"
 #include "nsLineLayout.h"
 #include "nsPresContext.h"
 #include "nsStyleContext.h"
 #include "WritingModes.h"
+#include "RubyUtils.h"
 #include "nsRubyBaseContainerFrame.h"
 #include "nsRubyTextContainerFrame.h"
 
 using namespace mozilla;
 
 //----------------------------------------------------------------------
 
 // Frame class boilerplate
@@ -54,49 +55,16 @@ nsRubyFrame::IsFrameOfType(uint32_t aFla
 #ifdef DEBUG_FRAME_DUMP
 nsresult
 nsRubyFrame::GetFrameName(nsAString& aResult) const
 {
   return MakeFrameName(NS_LITERAL_STRING("Ruby"), aResult);
 }
 #endif
 
-class MOZ_STACK_CLASS TextContainerIterator
-{
-public:
-  explicit TextContainerIterator(nsRubyBaseContainerFrame* aBaseContainer);
-  void Next();
-  bool AtEnd() const { return !mFrame; }
-  nsRubyTextContainerFrame* GetTextContainer() const
-  {
-    return static_cast<nsRubyTextContainerFrame*>(mFrame);
-  }
-
-private:
-  nsIFrame* mFrame;
-};
-
-TextContainerIterator::TextContainerIterator(
-    nsRubyBaseContainerFrame* aBaseContainer)
-{
-  mFrame = aBaseContainer;
-  Next();
-}
-
-void
-TextContainerIterator::Next()
-{
-  if (mFrame) {
-    mFrame = mFrame->GetNextSibling();
-    if (mFrame && mFrame->GetType() != nsGkAtoms::rubyTextContainerFrame) {
-      mFrame = nullptr;
-    }
-  }
-}
-
 /**
  * This class is responsible for appending and clearing
  * text container list of the base container.
  */
 class MOZ_STACK_CLASS AutoSetTextContainers
 {
 public:
   explicit AutoSetTextContainers(nsRubyBaseContainerFrame* aBaseContainer);
@@ -108,17 +76,17 @@ private:
 
 AutoSetTextContainers::AutoSetTextContainers(
     nsRubyBaseContainerFrame* aBaseContainer)
   : mBaseContainer(aBaseContainer)
 {
 #ifdef DEBUG
   aBaseContainer->AssertTextContainersEmpty();
 #endif
-  for (TextContainerIterator iter(aBaseContainer);
+  for (RubyTextContainerIterator iter(aBaseContainer);
        !iter.AtEnd(); iter.Next()) {
     aBaseContainer->AppendTextContainer(iter.GetTextContainer());
   }
 }
 
 AutoSetTextContainers::~AutoSetTextContainers()
 {
   mBaseContainer->ClearTextContainers();
@@ -295,17 +263,17 @@ nsRubyFrame::ReflowSegment(nsPresContext
                            nsReflowStatus& aStatus)
 {
   AutoSetTextContainers holder(aBaseContainer);
   WritingMode lineWM = aReflowState.mLineLayout->GetWritingMode();
   LogicalSize availSize(lineWM, aReflowState.AvailableISize(),
                         aReflowState.AvailableBSize());
 
   nsAutoTArray<nsRubyTextContainerFrame*, RTC_ARRAY_SIZE> textContainers;
-  for (TextContainerIterator iter(aBaseContainer); !iter.AtEnd(); iter.Next()) {
+  for (RubyTextContainerIterator iter(aBaseContainer); !iter.AtEnd(); iter.Next()) {
     textContainers.AppendElement(iter.GetTextContainer());
   }
   const uint32_t rtcCount = textContainers.Length();
 
   nsHTMLReflowMetrics baseMetrics(aReflowState);
   bool pushedFrame;
   aReflowState.mLineLayout->ReflowFrame(aBaseContainer, aStatus,
                                         &baseMetrics, pushedFrame);