Bug 1118136 - Check if targets match before forcing dispatch selection state changed event. r=roc
authorMorris Tseng <mtseng@mozilla.com>
Tue, 06 Jan 2015 22:23:00 +0100
changeset 235630 9f3ee2b72d354e303500e9773a6b6072c54fd4c9
parent 235629 fd2f17917aaeafe67c966b8e5d712a8f88c94f1e
child 235631 2880e05d5e3241105c1874fd364a7f50e0d334c3
push id366
push usercmanchester@mozilla.com
push dateThu, 08 Jan 2015 16:40:24 +0000
reviewersroc
bugs1118136
milestone37.0a1
Bug 1118136 - Check if targets match before forcing dispatch selection state changed event. r=roc
dom/browser-element/BrowserElementChildPreload.js
--- a/dom/browser-element/BrowserElementChildPreload.js
+++ b/dom/browser-element/BrowserElementChildPreload.js
@@ -89,17 +89,17 @@ function BrowserElementChild() {
   // true.
   this._forcedVisible = true;
   this._ownerVisible = true;
 
   this._nextPaintHandler = null;
 
   this._isContentWindowCreated = false;
   this._pendingSetInputMethodActive = [];
-  this._forceDispatchSelectionStateChanged = false;
+  this._selectionStateChangedTarget = null;
 
   this._init();
 };
 
 BrowserElementChild.prototype = {
 
   QueryInterface: XPCOMUtils.generateQI([Ci.nsIObserver,
                                          Ci.nsISupportsWeakReference]),
@@ -595,17 +595,17 @@ BrowserElementChild.prototype = {
   _selectionStateChangedHandler: function(e) {
     e.stopPropagation();
     let boundingClientRect = e.boundingClientRect;
 
     let isCollapsed = (e.selectedText.length == 0);
     let isMouseUp = (e.states.indexOf('mouseup') == 0);
     let canPaste = this._isCommandEnabled("paste");
 
-    if (!this._forceDispatchSelectionStateChanged) {
+    if (this._selectionStateChangedTarget != e.target) {
       // SelectionStateChanged events with the following states are not
       // necessary to trigger the text dialog, bypass these events
       // by default.
       //
       if(e.states.length == 0 ||
          e.states.indexOf('drag') == 0 ||
          e.states.indexOf('keypress') == 0 ||
          e.states.indexOf('mousedown') == 0) {
@@ -619,24 +619,25 @@ BrowserElementChild.prototype = {
         if (isMouseUp && canPaste) {
           //Dispatch this selection change event to support shortcut mode
         } else {
           return;
         }
       }
     }
 
-    // If we select something and selection range is visible, we set the
-    // forceDispatchSelectionStateChanged flag as true to dispatch the
-    // next SelectionStateChange event so that the parent side can
-    // hide the text dialog.
+    // If we select something and selection range is visible, we cache current
+    // event's target to selectionStateChangedTarget.
+    // And dispatch the next SelectionStateChagne event if target is matched, so
+    // that the parent side can hide the text dialog.
+    // We clear selectionStateChangedTarget if selection carets are invisible.
     if (e.visible && !isCollapsed) {
-      this._forceDispatchSelectionStateChanged = true;
+      this._selectionStateChangedTarget = e.target;
     } else {
-      this._forceDispatchSelectionStateChanged = false;
+      this._selectionStateChangedTarget = null;
     }
 
     let zoomFactor = content.screen.width / content.innerWidth;
 
     let detail = {
       rect: {
         width: boundingClientRect ? boundingClientRect.width : 0,
         height: boundingClientRect ? boundingClientRect.height : 0,