Back out 9967368c7c72:5d817fa463cb (bug 847983) for mochitest-8 crashes
authorPhil Ringnalda <philringnalda@gmail.com>
Thu, 04 Apr 2013 14:28:37 -0700
changeset 138637 55f9e3e3dae7aae2f422cc0f79508d00ffd148a7
parent 138636 3b237165e5c7f73d57c76203fe6f8a5e171c69b3
child 138638 40a228f7438952c95dc75856b9679315e9155ee4
child 138640 6f832cf6485f0e909b2711dbc5fd608cbf3d902e
push id2579
push userakeybl@mozilla.com
push dateMon, 24 Jun 2013 18:52:47 +0000
treeherdermozilla-beta@b69b7de8a05a [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
bugs847983
milestone23.0a1
backs out9967368c7c724e0815db5d0960f7f70d7b3bf3bb
first release with
nightly linux32
55f9e3e3dae7 / 23.0a1 / 20130405030918 / files
nightly linux64
55f9e3e3dae7 / 23.0a1 / 20130405030918 / files
nightly mac
55f9e3e3dae7 / 23.0a1 / 20130405030918 / files
nightly win32
55f9e3e3dae7 / 23.0a1 / 20130405030918 / files
nightly win64
55f9e3e3dae7 / 23.0a1 / 20130405030918 / files
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
releases
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Back out 9967368c7c72:5d817fa463cb (bug 847983) for mochitest-8 crashes CLOSED TREE
content/events/src/nsContentEventHandler.cpp
--- a/content/events/src/nsContentEventHandler.cpp
+++ b/content/events/src/nsContentEventHandler.cpp
@@ -101,19 +101,16 @@ nsContentEventHandler::Init(nsQueryConte
   NS_ENSURE_SUCCESS(rv, NS_ERROR_NOT_AVAILABLE);
   aEvent->mReply.mHasSelection = !isCollapsed;
 
   nsRefPtr<nsCaret> caret = mPresShell->GetCaret();
   NS_ASSERTION(caret, "GetCaret returned null");
 
   nsRect r;
   nsIFrame* frame = caret->GetGeometry(mSelection, &r);
-  if (!frame) {
-    frame = mRootContent->GetPrimaryFrame();
-  }
   NS_ENSURE_TRUE(frame, NS_ERROR_FAILURE);
 
   aEvent->mReply.mFocusedWidget = frame->GetNearestWidget();
 
   return NS_OK;
 }
 
 nsresult
@@ -228,20 +225,16 @@ static uint32_t CountNewlinesInNativeLen
   return newlines;
 }
 #endif
 
 /* static */ uint32_t
 nsContentEventHandler::GetNativeTextLength(nsIContent* aContent, uint32_t aMaxLength)
 {
   if (aContent->IsNodeOfType(nsINode::eTEXT)) {
-    // Skip text nodes without frames, e.g. inside script elements
-    if (!aContent->GetPrimaryFrame()) {
-      return 0;
-    }
     uint32_t textLengthDifference =
 #if defined(XP_MACOSX)
       // On Mac, the length of a native newline ("\r") is equal to the length of
       // the XP newline ("\n"), so the native length is the same as the XP length.
       0;
 #elif defined(XP_WIN)
       // On Windows, the length of a native newline ("\r\n") is twice the length of
       // the XP newline ("\n"), so XP length is equal to the length of the native
@@ -311,20 +304,16 @@ static nsresult GenerateFlatTextContent(
     nsINode* node = iter->GetCurrentNode();
     if (!node)
       break;
     if (!node->IsNodeOfType(nsINode::eCONTENT))
       continue;
     nsIContent* content = static_cast<nsIContent*>(node);
 
     if (content->IsNodeOfType(nsINode::eTEXT)) {
-      // Skip text nodes without frames, e.g. inside script elements
-      if (!content->GetPrimaryFrame()) {
-        continue;
-      }
       if (content == startNode)
         AppendSubString(aString, content, aRange->StartOffset(),
                         content->TextLength() - aRange->StartOffset());
       else if (content == endNode)
         AppendSubString(aString, content, 0, aRange->EndOffset());
       else
         AppendString(aString, content);
     } else if (IsContentBR(content))
@@ -386,37 +375,30 @@ nsContentEventHandler::SetRangeFromFlatT
                               bool aExpandToClusterBoundaries)
 {
   nsCOMPtr<nsIContentIterator> iter = NS_NewPreContentIterator();
   nsresult rv = iter->Init(mRootContent);
   NS_ENSURE_SUCCESS(rv, rv);
 
   uint32_t nativeOffset = 0;
   uint32_t nativeEndOffset = aNativeOffset + aNativeLength;
-  // When we clip the end offset to the end of the root element, set it to after
-  // the last valid node. This way we don't include any extraneous nodes, such
-  // as the bogus editor BR node, in our range.
-  nsINode *lastValidNode = mRootContent;
-  uint32_t lastValidOffset = 0;
   bool startSet = false;
   for (; !iter->IsDone(); iter->Next()) {
     nsINode* node = iter->GetCurrentNode();
     if (!node)
       break;
     if (!node->IsNodeOfType(nsINode::eCONTENT))
       continue;
     nsIContent* content = static_cast<nsIContent*>(node);
 
     uint32_t nativeTextLength;
     nativeTextLength = GetNativeTextLength(content);
     if (nativeTextLength == 0)
       continue;
 
-    lastValidNode = node->GetParent();
-    lastValidOffset = lastValidNode->IndexOf(node) + 1;
     if (nativeOffset <= aNativeOffset &&
         aNativeOffset < nativeOffset + nativeTextLength) {
       nsCOMPtr<nsIDOMNode> domNode(do_QueryInterface(content));
       NS_ASSERTION(domNode, "aContent doesn't have nsIDOMNode!");
 
       uint32_t xpOffset =
         content->IsNodeOfType(nsINode::eTEXT) ?
           ConvertToXPOffset(content, aNativeOffset - nativeOffset) : 0;
@@ -460,26 +442,27 @@ nsContentEventHandler::SetRangeFromFlatT
       rv = aRange->SetEnd(domNode, int32_t(xpOffset));
       NS_ENSURE_SUCCESS(rv, rv);
       return NS_OK;
     }
 
     nativeOffset += nativeTextLength;
   }
 
-  NS_ENSURE_TRUE(aNativeOffset <= nativeOffset, NS_ERROR_FAILURE);
+  if (nativeOffset < aNativeOffset)
+    return NS_ERROR_FAILURE;
 
-  nsCOMPtr<nsIDOMNode> domNode(do_QueryInterface(lastValidNode));
+  nsCOMPtr<nsIDOMNode> domNode(do_QueryInterface(mRootContent));
   NS_ASSERTION(domNode, "lastContent doesn't have nsIDOMNode!");
   if (!startSet) {
-    MOZ_ASSERT(!lastValidNode->IsNodeOfType(nsINode::eTEXT));
-    rv = aRange->SetStart(domNode, int32_t(lastValidOffset));
+    MOZ_ASSERT(!mRootContent->IsNodeOfType(nsINode::eTEXT));
+    rv = aRange->SetStart(domNode, int32_t(mRootContent->GetChildCount()));
     NS_ENSURE_SUCCESS(rv, rv);
   }
-  rv = aRange->SetEnd(domNode, int32_t(lastValidOffset));
+  rv = aRange->SetEnd(domNode, int32_t(mRootContent->GetChildCount()));
   NS_ASSERTION(NS_SUCCEEDED(rv), "nsIDOMRange::SetEnd failed");
   return rv;
 }
 
 nsresult
 nsContentEventHandler::OnQuerySelectedText(nsQueryContentEvent* aEvent)
 {
   nsresult rv = Init(aEvent);