Bug 932370 - Properly measure offsets for deleted BR nodes; r=masayuki
authorJim Chen <nchen@mozilla.com>
Tue, 11 Mar 2014 12:04:33 -0400
changeset 191270 c4f51e54c14d393d50f6cc8e94ec939be9ad2186
parent 191189 63c25c5fa758a08f1141aa0b3e4faaf196f50d6a
child 191271 1bcd1fea2e736c1df5d6ff956be3509872130bd7
push id474
push userasasaki@mozilla.com
push dateMon, 02 Jun 2014 21:01:02 +0000
treeherdermozilla-release@967f4cf1b31c [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmasayuki
bugs932370
milestone30.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 932370 - Properly measure offsets for deleted BR nodes; r=masayuki
dom/events/ContentEventHandler.cpp
--- a/dom/events/ContentEventHandler.cpp
+++ b/dom/events/ContentEventHandler.cpp
@@ -1002,20 +1002,31 @@ ContentEventHandler::GetFlatTextOffsetOf
   NS_ASSERTION(aNativeOffset, "param is invalid");
 
   nsRefPtr<nsRange> prev = new nsRange(aRootContent);
   nsCOMPtr<nsIDOMNode> rootDOMNode(do_QueryInterface(aRootContent));
   prev->SetStart(rootDOMNode, 0);
 
   nsCOMPtr<nsIDOMNode> startDOMNode(do_QueryInterface(aNode));
   NS_ASSERTION(startDOMNode, "startNode doesn't have nsIDOMNode");
-  prev->SetEnd(startDOMNode, aNodeOffset);
 
   nsCOMPtr<nsIContentIterator> iter = NS_NewContentIterator();
-  iter->Init(prev);
+
+  if (aNode->Length() >= aNodeOffset) {
+    // Offset is within node's length; set end of range to that offset
+    prev->SetEnd(startDOMNode, aNodeOffset);
+    iter->Init(prev);
+  } else if (aNode != static_cast<nsINode*>(aRootContent)) {
+    // Offset is past node's length; set end of range to end of node
+    prev->SetEndAfter(startDOMNode);
+    iter->Init(prev);
+  } else {
+    // Offset is past the root node; set end of range to end of root node
+    iter->Init(aRootContent);
+  }
 
   nsCOMPtr<nsINode> startNode = do_QueryInterface(startDOMNode);
   nsINode* endNode = aNode;
 
   *aNativeOffset = 0;
   for (; !iter->IsDone(); iter->Next()) {
     nsINode* node = iter->GetCurrentNode();
     if (!node) {