Bug 1208944 - Part 8. Don't get selection on start compostion when plugin has foucs. r=masayuki
☠☠ backed out by 54a19e8d57c4 ☠ ☠
authorMakoto Kato <m_kato@ga2.so-net.ne.jp>
Tue, 29 Dec 2015 22:57:38 +0900
changeset 277786 31c47f2980b5f9577c5e729c3552dfe778fe489e
parent 277785 3e0d70a6e8096bb12e585790cb3c2f4ed34ca0f0
child 277787 0e337d912b7dbec542798be02ab021cf74838792
push id69594
push userm_kato@ga2.so-net.ne.jp
push dateTue, 29 Dec 2015 14:00:00 +0000
treeherdermozilla-inbound@3c915942af38 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmasayuki
bugs1208944
milestone46.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 1208944 - Part 8. Don't get selection on start compostion when plugin has foucs. r=masayuki
widget/ContentCache.cpp
widget/nsIWidget.h
widget/windows/nsWindowBase.h
--- a/widget/ContentCache.cpp
+++ b/widget/ContentCache.cpp
@@ -492,16 +492,27 @@ ContentCacheInParent::HandleQueryContent
   aEvent.mReply.mFocusedWidget = aWidget;
 
   switch (aEvent.mMessage) {
     case eQuerySelectedText:
       MOZ_LOG(sContentCacheLog, LogLevel::Info,
         ("ContentCacheInParent: 0x%p HandleQueryContentEvent("
          "aEvent={ mMessage=eQuerySelectedText }, aWidget=0x%p)",
          this, aWidget));
+      if (aWidget->PluginHasFocus()) {
+        MOZ_LOG(sContentCacheLog, LogLevel::Info,
+          ("ContentCacheInParent: 0x%p HandleQueryContentEvent(), "
+           "return emtpy selection becasue plugin has focus",
+           this));
+        aEvent.mSucceeded = true;
+        aEvent.mReply.mOffset = 0;
+        aEvent.mReply.mReversed = false;
+        aEvent.mReply.mHasSelection = false;
+        return true;
+      }
       if (NS_WARN_IF(!IsSelectionValid())) {
         // If content cache hasn't been initialized properly, make the query
         // failed.
         MOZ_LOG(sContentCacheLog, LogLevel::Error,
           ("ContentCacheInParent: 0x%p HandleQueryContentEvent(), "
            "FAILED because mSelection is not valid", this));
         return true;
       }
@@ -830,17 +841,22 @@ ContentCacheInParent::OnCompositionEvent
      this, ToChar(aEvent.mMessage),
      NS_ConvertUTF16toUTF8(aEvent.mData).get(), aEvent.mData.Length(),
      aEvent.mRanges ? aEvent.mRanges->Length() : 0, mPendingEventsNeedingAck,
      GetBoolName(mIsComposing), mCommitStringByRequest));
 
   // We must be able to simulate the selection because
   // we might not receive selection updates in time
   if (!mIsComposing) {
-    mCompositionStart = mSelection.StartOffset();
+    if (aEvent.widget && aEvent.widget->PluginHasFocus()) {
+      // If focus is on plugin, we cannot get selection range
+      mCompositionStart = 0;
+    } else {
+      mCompositionStart = mSelection.StartOffset();
+    }
   }
 
   mIsComposing = !aEvent.CausesDOMCompositionEndEvent();
 
   // During REQUEST_TO_COMMIT_COMPOSITION or REQUEST_TO_CANCEL_COMPOSITION,
   // widget usually sends a eCompositionChange and/or eCompositionCommit event
   // to finalize or clear the composition, respectively.  In this time,
   // we need to intercept all composition events here and pass the commit
--- a/widget/nsIWidget.h
+++ b/widget/nsIWidget.h
@@ -1787,16 +1787,24 @@ public:
      * keyboard focus.  Should be sent when the keyboard focus changes too or
      * from a plugin.
      *
      * aFocused  Whether or not a plugin is focused
      */
     NS_IMETHOD SetPluginFocused(bool& aFocused) = 0;
 
     /*
+     * Tell the plugin has focus.  It is unnecessary to use IPC
+     */
+    bool PluginHasFocus() 
+    {
+      return GetInputContext().mIMEState.mEnabled == IMEState::PLUGIN;
+    }
+
+    /*
      * Notifies the input context changes.
      */
     NS_IMETHOD_(void) SetInputContext(const InputContext& aContext,
                                       const InputContextAction& aAction) = 0;
 
     /*
      * Get current input context.
      */
--- a/widget/windows/nsWindowBase.h
+++ b/widget/windows/nsWindowBase.h
@@ -73,24 +73,16 @@ public:
   virtual bool DispatchContentCommandEvent(mozilla::WidgetContentCommandEvent* aEvent) = 0;
 
   /*
    * Default dispatch of a plugin event.
    */
   virtual bool DispatchPluginEvent(const MSG& aMsg);
 
   /*
-   * Returns true if a plugin has focus on this widget.  Otherwise, false.
-   */
-  virtual bool PluginHasFocus() const final
-  {
-    return (mInputContext.mIMEState.mEnabled == IMEState::PLUGIN);
-  }
-
-  /*
    * Touch input injection apis
    */
   virtual nsresult SynthesizeNativeTouchPoint(uint32_t aPointerId,
                                               TouchPointerState aPointerState,
                                               ScreenIntPoint aPointerScreenPoint,
                                               double aPointerPressure,
                                               uint32_t aPointerOrientation,
                                               nsIObserver* aObserver) override;