Bug 792928 - Don't select entire text when event offsets are out of bounds; r=masayuki
authorJim Chen <nchen@mozilla.com>
Fri, 19 Oct 2012 14:45:54 -0400
changeset 110935 c395a0974676355687e14f81d59b5280fbe27a94
parent 110934 7ae0ccc256502ad66709f890bf0587e8b82a91b3
child 110936 77e5b3ac81e91da18020d854e3759181f504f733
push id93
push usernmatsakis@mozilla.com
push dateWed, 31 Oct 2012 21:26:57 +0000
reviewersmasayuki
bugs792928
milestone19.0a1
Bug 792928 - Don't select entire text when event offsets are out of bounds; r=masayuki
content/events/src/nsContentEventHandler.cpp
widget/android/nsWindow.cpp
--- a/content/events/src/nsContentEventHandler.cpp
+++ b/content/events/src/nsContentEventHandler.cpp
@@ -370,17 +370,17 @@ nsContentEventHandler::SetRangeFromFlatT
                               bool aExpandToClusterBoundaries)
 {
   nsCOMPtr<nsIContentIterator> iter = NS_NewContentIterator();
   nsresult rv = iter->Init(mRootContent);
   NS_ENSURE_SUCCESS(rv, rv);
 
   uint32_t nativeOffset = 0;
   uint32_t nativeEndOffset = aNativeOffset + aNativeLength;
-  nsCOMPtr<nsIContent> content;
+  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);
 
@@ -400,16 +400,17 @@ nsContentEventHandler::SetRangeFromFlatT
 
       if (aExpandToClusterBoundaries) {
         rv = ExpandToClusterBoundary(content, false, &xpOffset);
         NS_ENSURE_SUCCESS(rv, rv);
       }
 
       rv = aRange->SetStart(domNode, int32_t(xpOffset));
       NS_ENSURE_SUCCESS(rv, rv);
+      startSet = true;
       if (aNativeLength == 0) {
         // Ensure that the end offset and the start offset are same.
         rv = aRange->SetEnd(domNode, int32_t(xpOffset));
         NS_ENSURE_SUCCESS(rv, rv);
         return NS_OK;
       }
     }
     if (nativeEndOffset <= nativeOffset + nativeTextLength) {
@@ -441,18 +442,19 @@ nsContentEventHandler::SetRangeFromFlatT
     nativeOffset += nativeTextLength;
   }
 
   if (nativeOffset < aNativeOffset)
     return NS_ERROR_FAILURE;
 
   nsCOMPtr<nsIDOMNode> domNode(do_QueryInterface(mRootContent));
   NS_ASSERTION(domNode, "lastContent doesn't have nsIDOMNode!");
-  if (!content) {
-    rv = aRange->SetStart(domNode, 0);
+  if (!startSet) {
+    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(mRootContent->GetChildCount()));
   NS_ASSERTION(NS_SUCCEEDED(rv), "nsIDOMRange::SetEnd failed");
   return rv;
 }
 
 nsresult
--- a/widget/android/nsWindow.cpp
+++ b/widget/android/nsWindow.cpp
@@ -1951,16 +1951,17 @@ nsWindow::OnIMEEvent(AndroidGeckoEvent *
             nsSelectionEvent selEvent(true, NS_SELECTION_SET, this);
             InitEvent(selEvent, nullptr);
 
             selEvent.mOffset = uint32_t(ae->Count() >= 0 ?
                                         ae->Offset() :
                                         ae->Offset() + ae->Count());
             selEvent.mLength = uint32_t(NS_ABS(ae->Count()));
             selEvent.mReversed = ae->Count() >= 0 ? false : true;
+            selEvent.mExpandToClusterBoundary = false;
 
             DispatchEvent(&selEvent);
         }
         return;
     case AndroidGeckoEvent::IME_GET_SELECTION:
         {
             ALOGIME("IME: IME_GET_SELECTION");