Bug 1111433 - Dispatch the SelectionStateChanged event for blur. r=ehsan
authorpchang <pchang@mozilla.com>
Wed, 07 Jan 2015 01:01:00 -0500
changeset 248588 0257f42048f3c790b101a9715563b376aea4a683
parent 248587 0e842f11691faf166baeae55584aa4b9daed45c0
child 248589 40f4f285ea0c16f522387edb5aa292a0b3955fc7
push id4489
push userraliiev@mozilla.com
push dateMon, 23 Feb 2015 15:17:55 +0000
treeherdermozilla-beta@fd7c3dc24146 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersehsan
bugs1111433
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 1111433 - Dispatch the SelectionStateChanged event for blur. r=ehsan
dom/browser-element/BrowserElementChildPreload.js
layout/base/SelectionCarets.cpp
--- a/dom/browser-element/BrowserElementChildPreload.js
+++ b/dom/browser-element/BrowserElementChildPreload.js
@@ -589,16 +589,21 @@ BrowserElementChild.prototype = {
       scrollX: e.scrollX,
       scrollY: e.scrollY,
     };
     sendAsyncMsg('scrollviewchange', detail);
   },
 
   _selectionStateChangedHandler: function(e) {
     e.stopPropagation();
+
+    if (!this._isContentWindowCreated) {
+      return;
+    }
+
     let boundingClientRect = e.boundingClientRect;
 
     let isCollapsed = (e.selectedText.length == 0);
     let isMouseUp = (e.states.indexOf('mouseup') == 0);
     let canPaste = this._isCommandEnabled("paste");
 
     if (this._selectionStateChangedTarget != e.target) {
       // SelectionStateChanged events with the following states are not
@@ -608,21 +613,23 @@ BrowserElementChild.prototype = {
       if(e.states.length == 0 ||
          e.states.indexOf('drag') == 0 ||
          e.states.indexOf('keypress') == 0 ||
          e.states.indexOf('mousedown') == 0) {
         return;
       }
 
       // The collapsed SelectionStateChanged event is unnecessary to dispatch,
-      // bypass this event by default. But there is one exception to support
-      // the shortcut mode which can paste previous copied content easily
+      // bypass this event by default, but here comes some exceptional cases
       if (isCollapsed) {
         if (isMouseUp && canPaste) {
-          //Dispatch this selection change event to support shortcut mode
+          // Always dispatch to support shortcut mode which can paste previous
+          // copied content easily
+        } else if (e.states.indexOf('blur') == 0) {
+          // Always dispatch to notify the blur for the focus content
         } else {
           return;
         }
       }
     }
 
     // If we select something and selection range is visible, we cache current
     // event's target to selectionStateChangedTarget.
--- a/layout/base/SelectionCarets.cpp
+++ b/layout/base/SelectionCarets.cpp
@@ -1106,16 +1106,17 @@ SelectionCarets::DispatchSelectionStateC
   event->GetInternalNSEvent()->mFlags.mOnlyChromeDispatch = true;
   bool ret;
   doc->DispatchEvent(event, &ret);
 }
 
 void
 SelectionCarets::NotifyBlur(bool aIsLeavingDocument)
 {
+  SELECTIONCARETS_LOG("Send out the blur event");
   SetVisibility(false);
   if (aIsLeavingDocument) {
     CancelLongTapDetector();
   }
   DispatchSelectionStateChangedEvent(nullptr, SelectionState::Blur);
 }
 
 nsresult