Bug 615935: Cancel any complex text composition for a Cocoa NPAPI plugin when it doesn't return kNPEventStartIME for a key down event. r=smichaud a=blocking2.0betaN+
authorJosh Aas <joshmoz@gmail.com>
Fri, 03 Dec 2010 00:22:20 -0500
changeset 58536 e42651bbc73ef45b2d6f76b6ad3e85cb43a4cfae
parent 58535 9280c6d82204bdea2901e5e24726186370f86624
child 58538 0ff6d59842870cf6c29e07f082a66d4e15306567
push id1
push usershaver@mozilla.com
push dateTue, 04 Jan 2011 17:58:04 +0000
reviewerssmichaud, blocking2
bugs615935
milestone2.0b8pre
Bug 615935: Cancel any complex text composition for a Cocoa NPAPI plugin when it doesn't return kNPEventStartIME for a key down event. r=smichaud a=blocking2.0betaN+
widget/src/cocoa/ComplexTextInputPanel.h
widget/src/cocoa/ComplexTextInputPanel.mm
widget/src/cocoa/nsChildView.mm
--- a/widget/src/cocoa/ComplexTextInputPanel.h
+++ b/widget/src/cocoa/ComplexTextInputPanel.h
@@ -33,12 +33,13 @@
 @interface ComplexTextInputPanel : NSPanel {
   NSTextView *mInputTextView;
 }
 
 + (ComplexTextInputPanel*)sharedComplexTextInputPanel;
 
 - (NSTextInputContext*)inputContext;
 - (BOOL)interpretKeyEvent:(NSEvent*)event string:(NSString**)string;
+- (void)cancelComposition;
 
 @end
 
 #endif // ComplexTextInputPanel_h_
--- a/widget/src/cocoa/ComplexTextInputPanel.mm
+++ b/widget/src/cocoa/ComplexTextInputPanel.mm
@@ -78,18 +78,17 @@
   
   [mInputTextView release];
   
   [super dealloc];
 }
 
 - (void)keyboardInputSourceChanged:(NSNotification *)notification
 {
-  [mInputTextView setString:@""];
-  [self orderOut:nil];
+  [self cancelComposition];
 }
 
 - (BOOL)interpretKeyEvent:(NSEvent*)event string:(NSString**)string
 {
   BOOL hadMarkedText = [mInputTextView hasMarkedText];
 
   *string = nil;
 
@@ -114,9 +113,15 @@
   return hadMarkedText;
 }
 
 - (NSTextInputContext*)inputContext
 {
   return [mInputTextView inputContext];
 }
 
+- (void)cancelComposition
+{
+  [mInputTextView setString:@""];
+  [self orderOut:nil];
+}
+
 @end
--- a/widget/src/cocoa/nsChildView.mm
+++ b/widget/src/cocoa/nsChildView.mm
@@ -5360,19 +5360,25 @@ static const char* ToEscapedString(NSStr
       // Send key down event.
       nsGUIEvent pluginEvent(PR_TRUE, NS_NON_RETARGETED_PLUGIN_EVENT, mGeckoChild);
       NPCocoaEvent cocoaEvent;
       ConvertCocoaKeyEventToNPCocoaEvent(theEvent, cocoaEvent);
       pluginEvent.pluginEvent = &cocoaEvent;
       mGeckoChild->DispatchWindowEvent(pluginEvent);
       if (!mGeckoChild)
         return;
-      
+
       if (!mPluginComplexTextInputRequested) {
-        // Ideally we'd cancel any TSM composition here.
+#ifdef NP_NO_CARBON
+        [[ComplexTextInputPanel sharedComplexTextInputPanel] cancelComposition];
+#else
+        if (mPluginTSMDoc) {
+          ::FixTSMDocument(mPluginTSMDoc);
+        }
+#endif
         return;
       }
 
 #ifdef NP_NO_CARBON
       ComplexTextInputPanel* ctInputPanel = [ComplexTextInputPanel sharedComplexTextInputPanel];
       NSString* textString = nil;
       [ctInputPanel interpretKeyEvent:theEvent string:&textString];
       if (textString) {