Bug 519972 part.1 Remove IME method wrapper r=smichaud, a=josh
authorMasayuki Nakano <masayuki@d-toybox.com>
Sun, 08 Aug 2010 18:28:20 +0900
changeset 49150 a0ea32596abd9e32ce69403152df60600ed7ad70
parent 49149 4926d6b601f7b2994c4b3c87ed2860a5c83efcf8
child 49151 dea6175f4b0739f2dcf0b568340306250e7f4c93
push id1
push userroot
push dateTue, 26 Apr 2011 22:38:44 +0000
treeherdermozilla-beta@bfdb6e623a36 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerssmichaud, josh
bugs519972
milestone2.0b4pre
first release with
nightly linux32
a0ea32596abd / 4.0b4pre / 20100808025720 / files
nightly linux64
a0ea32596abd / 4.0b4pre / 20100808030703 / files
nightly mac
a0ea32596abd / 4.0b4pre / 20100808030709 / files
nightly win32
a0ea32596abd / 4.0b4pre / 20100808040523 / files
nightly win64
a0ea32596abd / 4.0b4pre / 20100808025040 / files
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
releases
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 519972 part.1 Remove IME method wrapper r=smichaud, a=josh
widget/src/cocoa/nsChildView.h
widget/src/cocoa/nsChildView.mm
--- a/widget/src/cocoa/nsChildView.h
+++ b/widget/src/cocoa/nsChildView.h
@@ -397,87 +397,16 @@ public:
 
   static void ApplyConfiguration(nsIWidget* aExpectedParent,
                                  const nsIWidget::Configuration& aConfiguration,
                                  PRBool aRepaint);
 
   nsCocoaTextInputHandler* TextInputHandler() { return &mTextInputHandler; }
   NSView<mozView>* GetEditorView();
 
-  // Wrapper methods of nsIMEManager and nsTSMManager
-  void IME_OnDestroyView(NSView<mozView> *aDestroyingView)
-  {
-    mTextInputHandler.OnDestroyView(aDestroyingView);
-  }
-
-  void IME_OnStartComposition(NSView<mozView>* aComposingView)
-  {
-    mTextInputHandler.OnStartIMEComposition(aComposingView);
-  }
-
-  void IME_OnUpdateComposition(NSString* aCompositionString)
-  {
-    mTextInputHandler.OnUpdateIMEComposition(aCompositionString);
-  }
-
-  void IME_OnEndComposition()
-  {
-    mTextInputHandler.OnEndIMEComposition();
-  }
-
-  PRBool IME_IsComposing()
-  {
-    return mTextInputHandler.IsIMEComposing();
-  }
-
-  PRBool IME_IsASCIICapableOnly()
-  {
-    return mTextInputHandler.IsASCIICapableOnly();
-  }
-
-  PRBool IME_IsOpened()
-  {
-    return mTextInputHandler.IsIMEOpened();
-  }
-
-  PRBool IME_IsEnabled()
-  {
-    return mTextInputHandler.IsIMEEnabled();
-  }
-
-  PRBool IME_IgnoreCommit()
-  {
-    return mTextInputHandler.IgnoreIMECommit();
-  }
-
-  void IME_CommitComposition()
-  {
-    mTextInputHandler.CommitIMEComposition();
-  }
-
-  void IME_CancelComposition()
-  {
-    mTextInputHandler.CancelIMEComposition();
-  }
-
-  void IME_SetASCIICapableOnly(PRBool aASCIICapableOnly)
-  {
-    mTextInputHandler.SetASCIICapableOnly(aASCIICapableOnly);
-  }
-
-  void IME_SetOpenState(PRBool aOpen)
-  {
-    mTextInputHandler.SetIMEOpenState(aOpen);
-  }
-
-  void IME_Enable(PRBool aEnable)
-  {
-    mTextInputHandler.EnableIME(aEnable);
-  }
-
 protected:
 
   PRBool            ReportDestroyEvent();
   PRBool            ReportMoveEvent();
   PRBool            ReportSizeEvent();
 
   // override to create different kinds of child views. Autoreleases, so
   // caller must retain.
--- a/widget/src/cocoa/nsChildView.mm
+++ b/widget/src/cocoa/nsChildView.mm
@@ -1781,17 +1781,17 @@ void nsChildView::Scroll(const nsIntPoin
 
 // Invokes callback and ProcessEvent methods on Event Listener object
 NS_IMETHODIMP nsChildView::DispatchEvent(nsGUIEvent* event, nsEventStatus& aStatus)
 {
 #ifdef DEBUG
   debug_DumpEvent(stdout, event->widget, event, nsCAutoString("something"), 0);
 #endif
 
-  NS_ASSERTION(!(IME_IsComposing() && NS_IS_KEY_EVENT(event)),
+  NS_ASSERTION(!(mTextInputHandler.IsIMEComposing() && NS_IS_KEY_EVENT(event)),
     "Any key events should not be fired during IME composing");
 
   aStatus = nsEventStatus_eIgnore;
 
   nsCOMPtr<nsIWidget> kungFuDeathGrip = do_QueryInterface(mParentWidget ? mParentWidget : this);
   if (mParentWidget) {
     nsWindowType type;
     mParentWidget->GetWindowType(type);
@@ -1954,91 +1954,92 @@ PRBool nsChildView::HasPendingInputEvent
 // Note that this and other IME methods don't necessarily
 // get called on the same ChildView that input is going through.
 NS_IMETHODIMP nsChildView::ResetInputState()
 {
 #ifdef DEBUG_IME
   NSLog(@"**** ResetInputState");
 #endif
 
-  IME_CommitComposition();
+  mTextInputHandler.CommitIMEComposition();
   return NS_OK;
 }
 
 // 'open' means that it can take non-ASCII chars
 NS_IMETHODIMP nsChildView::SetIMEOpenState(PRBool aState)
 {
 #ifdef DEBUG_IME
   NSLog(@"**** SetIMEOpenState aState = %d", aState);
 #endif
 
-  IME_SetOpenState(aState);
+  mTextInputHandler.SetIMEOpenState(aState);
   return NS_OK;
 }
 
 // 'open' means that it can take non-ASCII chars
 NS_IMETHODIMP nsChildView::GetIMEOpenState(PRBool* aState)
 {
 #ifdef DEBUG_IME
   NSLog(@"**** GetIMEOpenState");
 #endif
 
-  *aState = IME_IsOpened();
+  *aState = mTextInputHandler.IsIMEOpened();
   return NS_OK;
 }
 
 NS_IMETHODIMP nsChildView::SetIMEEnabled(PRUint32 aState)
 {
 #ifdef DEBUG_IME
   NSLog(@"**** SetIMEEnabled aState = %d", aState);
 #endif
 
   switch (aState) {
     case nsIWidget::IME_STATUS_ENABLED:
     case nsIWidget::IME_STATUS_PLUGIN:
-      IME_SetASCIICapableOnly(PR_FALSE);
-      IME_Enable(PR_TRUE);
+      mTextInputHandler.SetASCIICapableOnly(PR_FALSE);
+      mTextInputHandler.EnableIME(PR_TRUE);
       break;
     case nsIWidget::IME_STATUS_DISABLED:
-      IME_SetASCIICapableOnly(PR_FALSE);
-      IME_Enable(PR_FALSE);
+      mTextInputHandler.SetASCIICapableOnly(PR_FALSE);
+      mTextInputHandler.EnableIME(PR_FALSE);
       break;
     case nsIWidget::IME_STATUS_PASSWORD:
-      IME_SetASCIICapableOnly(PR_TRUE);
-      IME_Enable(PR_FALSE);
+      mTextInputHandler.SetASCIICapableOnly(PR_TRUE);
+      mTextInputHandler.EnableIME(PR_FALSE);
       break;
     default:
       NS_ERROR("not implemented!");
   }
   return NS_OK;
 }
 
 NS_IMETHODIMP nsChildView::GetIMEEnabled(PRUint32* aState)
 {
 #ifdef DEBUG_IME
   NSLog(@"**** GetIMEEnabled");
 #endif
 
-  if (IME_IsEnabled())
+  if (mTextInputHandler.IsIMEEnabled()) {
     *aState = nsIWidget::IME_STATUS_ENABLED;
-  else if (IME_IsASCIICapableOnly())
+  } else if (mTextInputHandler.IsASCIICapableOnly()) {
     *aState = nsIWidget::IME_STATUS_PASSWORD;
-  else
+  } else {
     *aState = nsIWidget::IME_STATUS_DISABLED;
+  }
   return NS_OK;
 }
 
 // Destruct and don't commit the IME composition string.
 NS_IMETHODIMP nsChildView::CancelIMEComposition()
 {
 #ifdef DEBUG_IME
   NSLog(@"**** CancelIMEComposition");
 #endif
 
-  IME_CancelComposition();
+  mTextInputHandler.CancelIMEComposition();
   return NS_OK;
 }
 
 NS_IMETHODIMP nsChildView::GetToggledKeyState(PRUint32 aKeyCode,
                                               PRBool* aLEDState)
 {
   NS_OBJC_BEGIN_TRY_ABORT_BLOCK_NSRESULT;
 
@@ -2336,17 +2337,17 @@ NSEvent* gLastDragMouseDownEvent = nil;
     }
   }
 
   NS_OBJC_END_TRY_ABORT_BLOCK;
 }
 
 - (void)widgetDestroyed
 {
-  mGeckoChild->IME_OnDestroyView(self);
+  mGeckoChild->TextInputHandler()->OnDestroyView(self);
   mGeckoChild = nsnull;
 
   // Just in case we're destroyed abruptly and missed the draggingExited
   // or performDragOperation message.
   NS_IF_RELEASE(mDragService);
 }
 
 // mozView method, return our gecko child view widget. Note this does not AddRef.
@@ -4675,24 +4676,24 @@ GetUSLayoutCharFromKeyTranslate(UInt32 a
 
   nsAutoRetainCocoaObject kungFuDeathGrip(self);
 
   if (![insertString isKindOfClass:[NSAttributedString class]])
     insertString = [[[NSAttributedString alloc] initWithString:insertString] autorelease];
 
   NSString *tmpStr = [insertString string];
   unsigned int len = [tmpStr length];
-  if (!mGeckoChild->IME_IsComposing() && len == 0)
+  if (!mGeckoChild->TextInputHandler()->IsIMEComposing() && len == 0)
     return; // nothing to do
   PRUnichar buffer[MAX_BUFFER_SIZE];
   PRUnichar *bufPtr = (len >= MAX_BUFFER_SIZE) ? new PRUnichar[len + 1] : buffer;
   [tmpStr getCharacters:bufPtr];
   bufPtr[len] = PRUnichar('\0');
 
-  if (len == 1 && !mGeckoChild->IME_IsComposing()) {
+  if (len == 1 && !mGeckoChild->TextInputHandler()->IsIMEComposing()) {
     // don't let the same event be fired twice when hitting
     // enter/return! (Bug 420502)
     if (mKeyPressSent)
       return;
 
     // dispatch keypress event with char instead of textEvent
     nsKeyEvent geckoEvent(PR_TRUE, NS_KEY_PRESS, mGeckoChild);
     geckoEvent.time      = PR_IntervalNow();
@@ -4741,42 +4742,42 @@ GetUSLayoutCharFromKeyTranslate(UInt32 a
     // Only record the results of dispatching geckoEvent if we're currently
     // processing a keyDown event.
     if (mCurKeyEvent) {
       mKeyPressHandled = keyPressHandled;
       mKeyPressSent = YES;
     }
   }
   else {
-    if (!mGeckoChild->IME_IsComposing()) {
+    if (!mGeckoChild->TextInputHandler()->IsIMEComposing()) {
       [self sendCompositionEvent:NS_COMPOSITION_START];
       // Note: mGeckoChild might have become null here. Don't count on it from here on.
       if (mGeckoChild) {
-        mGeckoChild->IME_OnStartComposition(self);
+        mGeckoChild->TextInputHandler()->OnStartIMEComposition(self);
         // Note: mGeckoChild might have become null here. Don't count on it from here on.
       }
     }
 
-    if (mGeckoChild && mGeckoChild->IME_IgnoreCommit()) {
+    if (mGeckoChild && mGeckoChild->TextInputHandler()->IgnoreIMECommit()) {
       tmpStr = [tmpStr init];
       len = 0;
       bufPtr[0] = PRUnichar('\0');
       insertString =
         [[[NSAttributedString alloc] initWithString:tmpStr] autorelease];
     }
     [self sendTextEvent:bufPtr attributedString:insertString
                                selectedRange:NSMakeRange(0, len)
                                markedRange:mMarkedRange
                                doCommit:YES];
     // Note: mGeckoChild might have become null here. Don't count on it from here on.
 
     [self sendCompositionEvent:NS_COMPOSITION_END];
     // Note: mGeckoChild might have become null here. Don't count on it from here on.
     if (mGeckoChild) {
-      mGeckoChild->IME_OnEndComposition();
+      mGeckoChild->TextInputHandler()->OnEndIMEComposition();
       // Note: mGeckoChild might have become null here. Don't count on it from here on.
     }
     mMarkedRange = NSMakeRange(NSNotFound, 0);
   }
 
   if (bufPtr != buffer)
     delete[] bufPtr;
 
@@ -4837,43 +4838,43 @@ GetUSLayoutCharFromKeyTranslate(UInt32 a
   PRUint32 maxlen = len > 12 ? 12 : len;
   for (PRUnichar *a = bufPtr; (*a != PRUnichar('\0')) && n<maxlen; a++, n++)
     printf((*a&0xff80) ? "\\u%4X" : "%c", *a); 
   printf("\n");
 #endif
 
   mMarkedRange.length = len;
 
-  if (!mGeckoChild->IME_IsComposing() && len > 0) {
+  if (!mGeckoChild->TextInputHandler()->IsIMEComposing() && len > 0) {
     nsQueryContentEvent selection(PR_TRUE, NS_QUERY_SELECTED_TEXT, mGeckoChild);
     mGeckoChild->DispatchWindowEvent(selection);
     mMarkedRange.location = selection.mSucceeded ? selection.mReply.mOffset : 0;
     [self sendCompositionEvent:NS_COMPOSITION_START];
     // Note: mGeckoChild might have become null here. Don't count on it from here on.
     if (mGeckoChild) {
-      mGeckoChild->IME_OnStartComposition(self);
+      mGeckoChild->TextInputHandler()->OnStartIMEComposition(self);
       // Note: mGeckoChild might have become null here. Don't count on it from here on.
     }
   }
 
-  if (mGeckoChild->IME_IsComposing()) {
-    mGeckoChild->IME_OnUpdateComposition(tmpStr);
+  if (mGeckoChild->TextInputHandler()->IsIMEComposing()) {
+    mGeckoChild->TextInputHandler()->OnUpdateIMEComposition(tmpStr);
 
     BOOL commit = len == 0;
     [self sendTextEvent:bufPtr attributedString:aString
                                   selectedRange:selRange
                                     markedRange:mMarkedRange
                                        doCommit:commit];
     // Note: mGeckoChild might have become null here. Don't count on it from here on.
 
     if (commit) {
       [self sendCompositionEvent:NS_COMPOSITION_END];
       // Note: mGeckoChild might have become null here. Don't count on it from here on.
       if (mGeckoChild) {
-        mGeckoChild->IME_OnEndComposition();
+        mGeckoChild->TextInputHandler()->OnEndIMEComposition();
         // Note: mGeckoChild might have become null here. Don't count on it from here on.
       }
     }
   }
 
   if (bufPtr != buffer)
     delete[] bufPtr;
 
@@ -4882,17 +4883,17 @@ GetUSLayoutCharFromKeyTranslate(UInt32 a
 
 - (void) unmarkText
 {
 #if DEBUG_IME
   NSLog(@"****in unmarkText");
   NSLog(@" markedRange   = %d, %d", mMarkedRange.location, mMarkedRange.length);
 #endif
   if (mGeckoChild)
-    mGeckoChild->IME_CommitComposition();
+    mGeckoChild->TextInputHandler()->CommitIMEComposition();
 }
 
 - (BOOL) hasMarkedText
 {
 #if DEBUG_IME
   NSLog(@"****in hasMarkText");
   NSLog(@" markedRange   = %d, %d", mMarkedRange.location, mMarkedRange.length);
 #endif
@@ -5130,17 +5131,17 @@ static const char* ToEscapedString(NSStr
           [theEvent modifierFlags],
           ToEscapedString([theEvent characters], str1),
           ToEscapedString([theEvent charactersIgnoringModifiers], str2)));
 
   nsAutoRetainCocoaObject kungFuDeathGrip(self);
   mCurKeyEvent = theEvent;
 
   BOOL nonDeadKeyPress = [[theEvent characters] length] > 0;
-  if (nonDeadKeyPress && !mGeckoChild->IME_IsComposing()) {
+  if (nonDeadKeyPress && !mGeckoChild->TextInputHandler()->IsIMEComposing()) {
     if (![theEvent isARepeat]) {
       NSResponder* firstResponder = [[self window] firstResponder];
 
       nsKeyEvent geckoEvent(PR_TRUE, NS_KEY_DOWN, nsnull);
       [self convertCocoaKeyEvent:theEvent toGeckoEvent:&geckoEvent];
 
 #ifndef NP_NO_CARBON
       EventRecord carbonEvent;
@@ -5181,42 +5182,43 @@ static const char* ToEscapedString(NSStr
     nsKeyEvent geckoEvent(PR_TRUE, NS_KEY_PRESS, nsnull);
     [self convertCocoaKeyEvent:theEvent toGeckoEvent:&geckoEvent];
 
     // if this is a non-letter keypress, or the control key is down,
     // dispatch the keydown to gecko, so that we trap delete,
     // control-letter combinations etc before Cocoa tries to use
     // them for keybindings.
     if ((!geckoEvent.isChar || geckoEvent.isControl) &&
-        !mGeckoChild->IME_IsComposing()) {
+        !mGeckoChild->TextInputHandler()->IsIMEComposing()) {
       if (mKeyDownHandled)
         geckoEvent.flags |= NS_EVENT_FLAG_NO_DEFAULT;
       mKeyPressHandled = mGeckoChild->DispatchWindowEvent(geckoEvent);
       mKeyPressSent = YES;
       if (!mGeckoChild)
         return (mKeyDownHandled || mKeyPressHandled);
     }
   }
 
-  // Let Cocoa interpret the key events, caching IsComposing first.
+  // Let Cocoa interpret the key events, caching IsIMEComposing first.
   // We don't do it if this came from performKeyEquivalent because
   // interpretKeyEvents isn't set up to handle those key combinations.
-  PRBool wasComposing = mGeckoChild->IME_IsComposing();
+  PRBool wasComposing = mGeckoChild->TextInputHandler()->IsIMEComposing();
   PRBool interpretKeyEventsCalled = PR_FALSE;
   if (!isKeyEquiv &&
-      (mGeckoChild->IME_IsEnabled() || mGeckoChild->IME_IsASCIICapableOnly())) {
+      (mGeckoChild->TextInputHandler()->IsIMEEnabled() ||
+       mGeckoChild->TextInputHandler()->IsASCIICapableOnly())) {
     [super interpretKeyEvents:[NSArray arrayWithObject:theEvent]];
     interpretKeyEventsCalled = PR_TRUE;
   }
 
   if (!mGeckoChild)
     return (mKeyDownHandled || mKeyPressHandled);;
 
   if (!mKeyPressSent && nonDeadKeyPress && !wasComposing &&
-      !mGeckoChild->IME_IsComposing()) {
+      !mGeckoChild->TextInputHandler()->IsIMEComposing()) {
     nsKeyEvent geckoEvent(PR_TRUE, NS_KEY_PRESS, nsnull);
     [self convertCocoaKeyEvent:theEvent toGeckoEvent:&geckoEvent];
 
     // If we called interpretKeyEvents and this isn't normal character input
     // then IME probably ate the event for some reason. We do not want to
     // send a key press event in that case.
     if (!(interpretKeyEventsCalled && IsNormalCharInputtingEvent(geckoEvent))) {
       if (mKeyDownHandled)
@@ -5411,18 +5413,20 @@ static const char* ToEscapedString(NSStr
       keyUpEvent.pluginEvent = &macKeyUpEvent;
       mGeckoChild->DispatchWindowEvent(keyUpEvent);      
     }
 #endif
     return;
   }
 
   // if we don't have any characters we can't generate a keyUp event
-  if ([[theEvent characters] length] == 0 || mGeckoChild->IME_IsComposing())
+  if ([[theEvent characters] length] == 0 ||
+      mGeckoChild->TextInputHandler()->IsIMEComposing()) {
     return;
+  }
 
   nsKeyEvent geckoEvent(PR_TRUE, NS_KEY_UP, nsnull);
   [self convertCocoaKeyEvent:theEvent toGeckoEvent:&geckoEvent];
 
   mGeckoChild->DispatchWindowEvent(geckoEvent);
 
   NS_OBJC_END_TRY_ABORT_BLOCK;
 }
@@ -5446,18 +5450,19 @@ static const char* ToEscapedString(NSStr
     // Special handling if the other first responder is a ChildView.
     if ([firstResponder isKindOfClass:[ChildView class]])
       return [(ChildView *)firstResponder performKeyEquivalent:theEvent];
     if ([firstResponder isKindOfClass:[NSView class]])
       return [super performKeyEquivalent:theEvent];
   }
 
   // don't process if we're composing, but don't consume the event
-  if (mGeckoChild->IME_IsComposing())
+  if (mGeckoChild->TextInputHandler()->IsIMEComposing()) {
     return NO;
+  }
 
   UInt32 modifierFlags = [theEvent modifierFlags] & NSDeviceIndependentModifierFlagsMask;
 
   // Set to true if embedding menus handled the event when a plugin has focus.
   // We give menus a crack at handling commands before Gecko in the plugin case.
   BOOL handledByEmbedding = NO;
 
   // Perform native menu UI feedback even if we stop the event from propagating to it normally.
@@ -5644,18 +5649,19 @@ static const char* ToEscapedString(NSStr
   return dragSession != nsnull;
 }
 
 - (void)fireKeyEventForFlagsChanged:(NSEvent*)theEvent keyDown:(BOOL)isKeyDown
 {
   NS_OBJC_BEGIN_TRY_ABORT_BLOCK;
 
   if (!mGeckoChild || [theEvent type] != NSFlagsChanged ||
-      mGeckoChild->IME_IsComposing())
+      mGeckoChild->TextInputHandler()->IsIMEComposing()) {
     return;
+  }
 
   nsAutoRetainCocoaObject kungFuDeathGrip(self);
 
   PRUint32 message = isKeyDown ? NS_KEY_DOWN : NS_KEY_UP;
 
   // Fire a key event.
   nsKeyEvent geckoEvent(PR_TRUE, message, nsnull);
   [self convertCocoaKeyEvent:theEvent toGeckoEvent:&geckoEvent];