diff --git a/modules/libpref/init/all.js b/modules/libpref/init/all.js index 07109ff2d5aa..34a969395ba5 100644 --- a/modules/libpref/init/all.js +++ b/modules/libpref/init/all.js @@ -4820,9 +4820,13 @@ pref("dom.beforeAfterKeyboardEvent.enabled", false); pref("dom.presentation.enabled", false); pref("dom.presentation.tcp_server.debug", false); -// Use raw ICU instead of CoreServices API in Unicode collation #ifdef XP_MACOSX +// Use raw ICU instead of CoreServices API in Unicode collation pref("intl.collation.mac.use_icu", true); + +// Enable NSTextInput protocol for use with IMEs that have not +// been updated to use the NSTextInputClient protocol. +pref("intl.ime.nstextinput.enable", false); #endif // Enable meta-viewport support in remote APZ-enabled frames. diff --git a/widget/cocoa/nsChildView.mm b/widget/cocoa/nsChildView.mm index 30f36f87c29c..d67aa42dfe42 100644 --- a/widget/cocoa/nsChildView.mm +++ b/widget/cocoa/nsChildView.mm @@ -1661,7 +1661,7 @@ nsChildView::StartPluginIME(const mozilla::WidgetKeyboardEvent& aKeyboardEvent, // currently exists. So nested IME should never reach here, and so it should // be fine to use the last key-down event received by -[ChildView keyDown:] // (as we currently do). - ctiPanel->InterpretKeyEvent([mView lastKeyDownEvent], aCommitted); + ctiPanel->InterpretKeyEvent([(ChildView*)mView lastKeyDownEvent], aCommitted); return NS_OK; } @@ -5120,6 +5120,25 @@ static int32_t RoundUp(double aDouble) NS_OBJC_END_TRY_ABORT_BLOCK; } +- (BOOL)shouldZoomOnDoubleClick +{ + if ([NSWindow respondsToSelector:@selector(_shouldZoomOnDoubleClick)]) { + return [NSWindow _shouldZoomOnDoubleClick]; + } + return nsCocoaFeatures::OnYosemiteOrLater(); +} + +- (BOOL)shouldMinimizeOnTitlebarDoubleClick +{ + NSString *MDAppleMiniaturizeOnDoubleClickKey = + @"AppleMiniaturizeOnDoubleClick"; + NSUserDefaults *userDefaults = [NSUserDefaults standardUserDefaults]; + bool shouldMinimize = [[userDefaults + objectForKey:MDAppleMiniaturizeOnDoubleClickKey] boolValue]; + + return shouldMinimize; +} + #pragma mark - // NSTextInput implementation @@ -5127,6 +5146,13 @@ static int32_t RoundUp(double aDouble) { NS_OBJC_BEGIN_TRY_ABORT_BLOCK; + // We're considering not implementing NSTextInput. Start by just + // preffing its methods off. + if (!Preferences::GetBool("intl.ime.nstextinput.enable", false)) { + NSLog(@"Set intl.ime.nstextinput.enable to true in about:config to fix input."); + return; + } + NS_ENSURE_TRUE_VOID(mGeckoChild); nsAutoRetainCocoaObject kungFuDeathGrip(self); @@ -5146,29 +5172,67 @@ static int32_t RoundUp(double aDouble) - (void)insertNewline:(id)sender { - [self insertText:@"\n"]; -} - -- (void) doCommandBySelector:(SEL)aSelector -{ - NS_OBJC_BEGIN_TRY_ABORT_BLOCK; - - if (!mGeckoChild || !mTextInputHandler) { + // We're considering not implementing NSTextInput. Start by just + // preffing its methods off. + if (!Preferences::GetBool("intl.ime.nstextinput.enable", false)) { + NSLog(@"Set intl.ime.nstextinput.enable to true in about:config to fix input."); return; } - const char* sel = reinterpret_cast(aSelector); - if (!mTextInputHandler->DoCommandBySelector(sel)) { - [super doCommandBySelector:aSelector]; - } - - NS_OBJC_END_TRY_ABORT_BLOCK; + [self insertText:@"\n"]; } -- (void) setMarkedText:(id)aString selectedRange:(NSRange)selRange +- (NSInteger)conversationIdentifier +{ + // We're considering not implementing NSTextInput. Start by just + // preffing its methods off. + if (!Preferences::GetBool("intl.ime.nstextinput.enable", false)) { + NSLog(@"Set intl.ime.nstextinput.enable to true in about:config to fix input."); + return 0; + } + + NS_ENSURE_TRUE(mTextInputHandler, reinterpret_cast(self)); + return mTextInputHandler->ConversationIdentifier(); +} + +- (NSRect)firstRectForCharacterRange:(NSRange)theRange +{ + // We're considering not implementing NSTextInput. Start by just + // preffing its methods off. + if (!Preferences::GetBool("intl.ime.nstextinput.enable", false)) { + NSLog(@"Set intl.ime.nstextinput.enable to true in about:config to fix input."); + return NSMakeRect(0.0, 0.0, 0.0, 0.0); + } + + NSRect rect; + NS_ENSURE_TRUE(mTextInputHandler, rect); + return mTextInputHandler->FirstRectForCharacterRange(theRange); +} + +- (NSAttributedString *)attributedSubstringFromRange:(NSRange)theRange +{ + // We're considering not implementing NSTextInput. Start by just + // preffing its methods off. + if (!Preferences::GetBool("intl.ime.nstextinput.enable", false)) { + NSLog(@"Set intl.ime.nstextinput.enable to true in about:config to fix input."); + return nil; + } + + NS_ENSURE_TRUE(mTextInputHandler, nil); + return mTextInputHandler->GetAttributedSubstringFromRange(theRange); +} + +- (void)setMarkedText:(id)aString selectedRange:(NSRange)selRange { NS_OBJC_BEGIN_TRY_ABORT_BLOCK; + // We're considering not implementing NSTextInput. Start by just + // preffing its methods off. + if (!Preferences::GetBool("intl.ime.nstextinput.enable", false)) { + NSLog(@"Set intl.ime.nstextinput.enable to true in about:config to fix input."); + return; + } + NS_ENSURE_TRUE_VOID(mTextInputHandler); nsAutoRetainCocoaObject kungFuDeathGrip(self); @@ -5185,50 +5249,10 @@ static int32_t RoundUp(double aDouble) NS_OBJC_END_TRY_ABORT_BLOCK; } -- (void) unmarkText -{ - NS_ENSURE_TRUE(mTextInputHandler, ); - mTextInputHandler->CommitIMEComposition(); -} +#pragma mark - +// NSTextInputClient implementation -- (BOOL) hasMarkedText -{ - NS_ENSURE_TRUE(mTextInputHandler, NO); - return mTextInputHandler->HasMarkedText(); -} - -- (BOOL)shouldZoomOnDoubleClick -{ - if ([NSWindow respondsToSelector:@selector(_shouldZoomOnDoubleClick)]) { - return [NSWindow _shouldZoomOnDoubleClick]; - } - return nsCocoaFeatures::OnYosemiteOrLater(); -} - -- (BOOL)shouldMinimizeOnTitlebarDoubleClick -{ - NSString *MDAppleMiniaturizeOnDoubleClickKey = - @"AppleMiniaturizeOnDoubleClick"; - NSUserDefaults *userDefaults = [NSUserDefaults standardUserDefaults]; - bool shouldMinimize = [[userDefaults - objectForKey:MDAppleMiniaturizeOnDoubleClickKey] boolValue]; - - return shouldMinimize; -} - -- (NSInteger) conversationIdentifier -{ - NS_ENSURE_TRUE(mTextInputHandler, reinterpret_cast(self)); - return mTextInputHandler->ConversationIdentifier(); -} - -- (NSAttributedString *) attributedSubstringFromRange:(NSRange)theRange -{ - NS_ENSURE_TRUE(mTextInputHandler, nil); - return mTextInputHandler->GetAttributedSubstringFromRange(theRange); -} - -- (NSRange) markedRange +- (NSRange)markedRange { NS_OBJC_BEGIN_TRY_ABORT_BLOCK_RETURN; @@ -5238,7 +5262,7 @@ static int32_t RoundUp(double aDouble) NS_OBJC_END_TRY_ABORT_BLOCK_RETURN(NSMakeRange(0, 0)); } -- (NSRange) selectedRange +- (NSRange)selectedRange { NS_OBJC_BEGIN_TRY_ABORT_BLOCK_RETURN; @@ -5257,20 +5281,13 @@ static int32_t RoundUp(double aDouble) return mTextInputHandler->DrawsVerticallyForCharacterAtIndex(charIndex); } -- (NSRect) firstRectForCharacterRange:(NSRange)theRange -{ - NSRect rect; - NS_ENSURE_TRUE(mTextInputHandler, rect); - return mTextInputHandler->FirstRectForCharacterRange(theRange); -} - - (NSUInteger)characterIndexForPoint:(NSPoint)thePoint { NS_ENSURE_TRUE(mTextInputHandler, 0); return mTextInputHandler->CharacterIndexForPoint(thePoint); } -- (NSArray*) validAttributesForMarkedText +- (NSArray*)validAttributesForMarkedText { NS_OBJC_BEGIN_TRY_ABORT_BLOCK_NIL; @@ -5280,9 +5297,6 @@ static int32_t RoundUp(double aDouble) NS_OBJC_END_TRY_ABORT_BLOCK_NIL; } -#pragma mark - -// NSTextInputClient implementation - - (void)insertText:(id)aString replacementRange:(NSRange)replacementRange { NS_OBJC_BEGIN_TRY_ABORT_BLOCK; @@ -5303,6 +5317,34 @@ static int32_t RoundUp(double aDouble) NS_OBJC_END_TRY_ABORT_BLOCK; } +- (void)doCommandBySelector:(SEL)aSelector +{ + NS_OBJC_BEGIN_TRY_ABORT_BLOCK; + + if (!mGeckoChild || !mTextInputHandler) { + return; + } + + const char* sel = reinterpret_cast(aSelector); + if (!mTextInputHandler->DoCommandBySelector(sel)) { + [super doCommandBySelector:aSelector]; + } + + NS_OBJC_END_TRY_ABORT_BLOCK; +} + +- (void)unmarkText +{ + NS_ENSURE_TRUE_VOID(mTextInputHandler); + mTextInputHandler->CommitIMEComposition(); +} + +- (BOOL) hasMarkedText +{ + NS_ENSURE_TRUE(mTextInputHandler, NO); + return mTextInputHandler->HasMarkedText(); +} + - (void)setMarkedText:(id)aString selectedRange:(NSRange)selectedRange replacementRange:(NSRange)replacementRange {