Bug 1118136 - Check if targets match before forcing dispatch selection state changed event. r=roc
--- 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,