Bug 1149542 - Part 2: Track undisplayed characters before empty text frames properly. r=dholbert, a=abillings
authorCameron McCormack <cam@mcc.id.au>
Mon, 06 Apr 2015 09:12:06 -0400
changeset 258302 32d78bac2cfa
parent 258301 984f9cdef799
child 258303 499e1c563939
push id4638
push userryanvm@gmail.com
push date2015-04-06 20:41 +0000
treeherdermozilla-beta@499e1c563939 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersdholbert, abillings
bugs1149542
milestone38.0
Bug 1149542 - Part 2: Track undisplayed characters before empty text frames properly. r=dholbert, a=abillings
layout/svg/SVGTextFrame.cpp
--- a/layout/svg/SVGTextFrame.cpp
+++ b/layout/svg/SVGTextFrame.cpp
@@ -288,32 +288,35 @@ IsNonEmptyTextFrame(nsIFrame* aFrame)
  * @return true if aFrame is a non-empty text frame, false otherwise.
  */
 static bool
 GetNonEmptyTextFrameAndNode(nsIFrame* aFrame,
                             nsTextFrame*& aTextFrame,
                             nsTextNode*& aTextNode)
 {
   nsTextFrame* text = do_QueryFrame(aFrame);
-  if (!text) {
-    return false;
-  }
-
-  nsIContent* content = text->GetContent();
-  NS_ASSERTION(content && content->IsNodeOfType(nsINode::eTEXT),
-               "unexpected content type for nsTextFrame");
-
-  nsTextNode* node = static_cast<nsTextNode*>(content);
-  if (node->TextLength() == 0) {
-    return false;
-  }
-
-  aTextFrame = text;
-  aTextNode = node;
-  return true;
+  bool isNonEmptyTextFrame = text && text->GetContentLength() != 0;
+
+  if (isNonEmptyTextFrame) {
+    nsIContent* content = text->GetContent();
+    NS_ASSERTION(content && content->IsNodeOfType(nsINode::eTEXT),
+                 "unexpected content type for nsTextFrame");
+
+    nsTextNode* node = static_cast<nsTextNode*>(content);
+    MOZ_ASSERT(node->TextLength() != 0,
+               "frame's GetContentLength() should be 0 if the text node "
+               "has no content");
+
+    aTextFrame = text;
+    aTextNode = node;
+  }
+
+  MOZ_ASSERT(IsNonEmptyTextFrame(aFrame) == isNonEmptyTextFrame,
+             "our logic should agree with IsNonEmptyTextFrame");
+  return isNonEmptyTextFrame;
 }
 
 /**
  * Returns whether the specified atom is for one of the five
  * glyph positioning attributes that can appear on SVG text
  * elements -- x, y, dx, dy or rotate.
  */
 static bool
@@ -1306,17 +1309,17 @@ GetUndisplayedCharactersBeforeFrame(nsTe
     return 0;
   }
   return correspondence->mUndisplayedCharacters;
 }
 
 /**
  * Traverses the nsTextFrames for an SVGTextFrame and records a
  * TextNodeCorrespondenceProperty on each for the number of undisplayed DOM
- * characters between each frame.  This is done by iterating simultaenously
+ * characters between each frame.  This is done by iterating simultaneously
  * over the nsTextNodes and nsTextFrames and noting when nsTextNodes (or
  * parts of them) are skipped when finding the next nsTextFrame.
  */
 class TextNodeCorrespondenceRecorder
 {
 public:
   /**
    * Entry point for the TextNodeCorrespondenceProperty recording.