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 222606 9f3ee2b72d354e303500e9773a6b6072c54fd4c9
parent 222605 fd2f17917aaeafe67c966b8e5d712a8f88c94f1e
child 222607 2880e05d5e3241105c1874fd364a7f50e0d334c3
push id28068
push usercbook@mozilla.com
push dateThu, 08 Jan 2015 13:16:34 +0000
treeherdermozilla-central@2880e05d5e32 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersroc
bugs1118136
milestone37.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 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,