Bug 543789 part.2 Initialize data property of compositionstart event in nsEventStateManager::PreHandleEvent() r=smaug
authorMasayuki Nakano <masayuki@d-toybox.com>
Thu, 22 Sep 2011 18:17:40 +0900
changeset 77308 6432301d41ce969204eb1d2aeae808b6f2afeeb2
parent 77307 ebfdff9a84a591f8cca2067861bc433dbaea8659
child 77309 61f11b38c268fe1c9e6337e7c699fe932185832c
push id2056
push usermasayuki@d-toybox.com
push dateThu, 22 Sep 2011 09:18:20 +0000
treeherdermozilla-inbound@cc42e81d78b2 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerssmaug
bugs543789
milestone9.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 543789 part.2 Initialize data property of compositionstart event in nsEventStateManager::PreHandleEvent() r=smaug
content/events/src/nsEventStateManager.cpp
content/events/src/nsEventStateManager.h
--- a/content/events/src/nsEventStateManager.cpp
+++ b/content/events/src/nsEventStateManager.cpp
@@ -1255,22 +1255,17 @@ nsEventStateManager::PreHandleEvent(nsPr
       // When the last line scroll has been canceled, eat the pixel scroll event
       if ((msEvent->scrollFlags & nsMouseScrollEvent::kIsHorizontal) ?
            mLastLineScrollConsumedX : mLastLineScrollConsumedY) {
         *aStatus = nsEventStatus_eConsumeNoDefault;
       }
     }
     break;
   case NS_QUERY_SELECTED_TEXT:
-    {
-      if (RemoteQueryContentEvent(aEvent))
-        break;
-      nsContentEventHandler handler(mPresContext);
-      handler.OnQuerySelectedText((nsQueryContentEvent*)aEvent);
-    }
+    DoQuerySelectedText(static_cast<nsQueryContentEvent*>(aEvent));
     break;
   case NS_QUERY_TEXT_CONTENT:
     {
       if (RemoteQueryContentEvent(aEvent))
         break;
       nsContentEventHandler handler(mPresContext);
       handler.OnQueryTextContent((nsQueryContentEvent*)aEvent);
     }
@@ -1368,16 +1363,28 @@ nsEventStateManager::PreHandleEvent(nsPr
         if (GetCrossProcessTarget()->SendTextEvent(*textEvent)) {
           // Cancel local dispatching
           aEvent->flags |= NS_EVENT_FLAG_STOP_DISPATCH;
         }
       }
     }
     break;
   case NS_COMPOSITION_START:
+    if (NS_IS_TRUSTED_EVENT(aEvent)) {
+      // If the event is trusted event, set the selected text to data of
+      // composition event.
+      nsCompositionEvent *compositionEvent =
+        static_cast<nsCompositionEvent*>(aEvent);
+      nsQueryContentEvent selectedText(PR_TRUE, NS_QUERY_SELECTED_TEXT,
+                                       compositionEvent->widget);
+      DoQuerySelectedText(&selectedText);
+      NS_ASSERTION(selectedText.mSucceeded, "Failed to get selected text");
+      compositionEvent->data = selectedText.mReply.mString;
+    }
+    // through to compositionend handling
   case NS_COMPOSITION_UPDATE:
   case NS_COMPOSITION_END:
     {
       nsCompositionEvent *compositionEvent =
           static_cast<nsCompositionEvent*>(aEvent);
       if (IsTargetCrossProcess(compositionEvent)) {
         // Will not be handled locally, remote the event
         if (GetCrossProcessTarget()->SendCompositionEvent(*compositionEvent)) {
@@ -4894,16 +4901,26 @@ nsEventStateManager::DoQueryScrollTarget
       return;
   }
 
   DoScrollText(aTargetFrame, &msEvent, unit,
                allowOverrideSystemSettings, aEvent);
 }
 
 void
+nsEventStateManager::DoQuerySelectedText(nsQueryContentEvent* aEvent)
+{
+  if (RemoteQueryContentEvent(aEvent)) {
+    return;
+  }
+  nsContentEventHandler handler(mPresContext);
+  handler.OnQuerySelectedText(aEvent);
+}
+
+void
 nsEventStateManager::SetActiveManager(nsEventStateManager* aNewESM,
                                       nsIContent* aContent)
 {
   if (sActiveESM && aNewESM != sActiveESM) {
     sActiveESM->SetContentState(nsnull, NS_EVENT_STATE_ACTIVE);
   }
   sActiveESM = aNewESM;
   if (sActiveESM && aContent) {
--- a/content/events/src/nsEventStateManager.h
+++ b/content/events/src/nsEventStateManager.h
@@ -453,16 +453,17 @@ protected:
    */
   void FillInEventFromGestureDown(nsMouseEvent* aEvent);
 
   nsresult DoContentCommandEvent(nsContentCommandEvent* aEvent);
   nsresult DoContentCommandScrollEvent(nsContentCommandEvent* aEvent);
 
   void DoQueryScrollTargetInfo(nsQueryContentEvent* aEvent,
                                nsIFrame* aTargetFrame);
+  void DoQuerySelectedText(nsQueryContentEvent* aEvent);
 
   PRBool RemoteQueryContentEvent(nsEvent *aEvent);
   mozilla::dom::TabParent *GetCrossProcessTarget();
   PRBool IsTargetCrossProcess(nsGUIEvent *aEvent);
 
   void DispatchCrossProcessEvent(nsEvent* aEvent, nsIFrameLoader* remote);
   PRBool IsRemoteTarget(nsIContent* target);
   PRBool HandleCrossProcessEvent(nsEvent *aEvent,