--- a/jdk/src/java.desktop/macosx/native/libawt_lwawt/awt/AWTView.m Tue Mar 22 13:07:27 2016 +0300
+++ b/jdk/src/java.desktop/macosx/native/libawt_lwawt/awt/AWTView.m Tue Mar 22 16:07:36 2016 +0530
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2011, 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@@ -43,6 +43,7 @@
-(void) resetTrackingArea;
-(void) deliverJavaKeyEventHelper: (NSEvent*) event;
-(BOOL) isCodePointInUnicodeBlockNeedingIMEvent: (unichar) codePoint;
+-(NSMutableString *) parseString : (id) complexString;
@end
// Uncomment this line to see fprintfs of each InputMethod API being called on this View
@@ -66,26 +67,26 @@
// Note: Must be called on main (AppKit) thread only
- (id) initWithRect: (NSRect) rect
platformView: (jobject) cPlatformView
- windowLayer: (CALayer*) windowLayer
+ windowLayer: (CALayer*) windowLayer
{
-AWT_ASSERT_APPKIT_THREAD;
+ AWT_ASSERT_APPKIT_THREAD;
// Initialize ourselves
self = [super initWithFrame: rect];
if (self == nil) return self;
-
+
m_cPlatformView = cPlatformView;
fInputMethodLOCKABLE = NULL;
fKeyEventsNeeded = NO;
fProcessingKeystroke = NO;
-
+
fEnablePressAndHold = shouldUsePressAndHold();
fInPressAndHold = NO;
fPAHNeedsToSelect = NO;
-
+
mouseIsOver = NO;
[self resetTrackingArea];
[self setAutoresizesSubviews:NO];
-
+
if (windowLayer != nil) {
self.cglLayer = windowLayer;
//Layer hosting view
@@ -96,7 +97,7 @@
//[self setLayerContentsRedrawPolicy: NSViewLayerContentsRedrawDuringViewResize];
//[self setLayerContentsPlacement: NSViewLayerContentsPlacementTopLeft];
//[self setAutoresizingMask: NSViewHeightSizable | NSViewWidthSizable];
-
+
#ifdef REMOTELAYER
CGLLayer *parentLayer = (CGLLayer*)self.cglLayer;
parentLayer.parentLayer = NULL;
@@ -118,36 +119,36 @@
}
#endif /* REMOTELAYER */
}
-
+
return self;
}
- (void) dealloc {
-AWT_ASSERT_APPKIT_THREAD;
-
+ AWT_ASSERT_APPKIT_THREAD;
+
self.cglLayer = nil;
-
+
JNIEnv *env = [ThreadUtilities getJNIEnvUncached];
(*env)->DeleteGlobalRef(env, m_cPlatformView);
m_cPlatformView = NULL;
-
+
if (fInputMethodLOCKABLE != NULL)
{
JNIEnv *env = [ThreadUtilities getJNIEnvUncached];
-
+
JNFDeleteGlobalRef(env, fInputMethodLOCKABLE);
fInputMethodLOCKABLE = NULL;
}
-
-
+
+
[super dealloc];
}
- (void) viewDidMoveToWindow {
-AWT_ASSERT_APPKIT_THREAD;
-
+ AWT_ASSERT_APPKIT_THREAD;
+
[AWTToolkit eventCountPlusPlus];
-
+
[JNFRunLoop performOnMainThreadWaiting:NO withBlock:^() {
[[self window] makeFirstResponder: self];
}];
@@ -231,7 +232,7 @@
NSPoint eventLocation = [event locationInWindow];
NSPoint localPoint = [self convertPoint: eventLocation fromView: nil];
-
+
if ([self mouse: localPoint inRect: [self bounds]]) {
[self deliverJavaMouseEvent: event];
} else {
@@ -275,10 +276,10 @@
- (void) keyDown: (NSEvent *)event {
fProcessingKeystroke = YES;
fKeyEventsNeeded = YES;
-
+
// Allow TSM to look at the event and potentially send back NSTextInputClient messages.
[self interpretKeyEvents:[NSArray arrayWithObject:event]];
-
+
if (fEnablePressAndHold && [event willBeHandledByComplexInputMethod]) {
fProcessingKeystroke = NO;
if (!fInPressAndHold) {
@@ -287,14 +288,14 @@
}
return;
}
-
+
NSString *eventCharacters = [event characters];
BOOL isDeadKey = (eventCharacters != nil && [eventCharacters length] == 0);
-
+
if ((![self hasMarkedText] && fKeyEventsNeeded) || isDeadKey) {
[self deliverJavaKeyEventHelper: event];
}
-
+
fProcessingKeystroke = NO;
}
@@ -307,15 +308,15 @@
}
- (BOOL) performKeyEquivalent: (NSEvent *) event {
- // if IM is active key events should be ignored
+ // if IM is active key events should be ignored
if (![self hasMarkedText] && !fInPressAndHold) {
[self deliverJavaKeyEventHelper: event];
}
-
- // Workaround for 8020209: special case for "Cmd =" and "Cmd ."
- // because Cocoa calls performKeyEquivalent twice for these keystrokes
- NSUInteger modFlags = [event modifierFlags] &
- (NSCommandKeyMask | NSAlternateKeyMask | NSShiftKeyMask | NSControlKeyMask);
+
+ // Workaround for 8020209: special case for "Cmd =" and "Cmd ."
+ // because Cocoa calls performKeyEquivalent twice for these keystrokes
+ NSUInteger modFlags = [event modifierFlags] &
+ (NSCommandKeyMask | NSAlternateKeyMask | NSShiftKeyMask | NSControlKeyMask);
if (modFlags == NSCommandKeyMask) {
NSString *eventChars = [event charactersIgnoringModifiers];
if ([eventChars length] == 1) {
@@ -325,9 +326,9 @@
return YES;
}
}
-
+
}
-
+
return NO;
}
@@ -341,36 +342,36 @@
if ([window isKindOfClass: [AWTWindow_Panel class]] || [window isKindOfClass: [AWTWindow_Normal class]]) {
isEnabled = [(AWTWindow*)[window delegate] isEnabled];
}
-
+
if (!isEnabled) {
return;
}
-
+
NSEventType type = [event type];
-
+
// check synthesized mouse entered/exited events
if ((type == NSMouseEntered && mouseIsOver) || (type == NSMouseExited && !mouseIsOver)) {
return;
}else if ((type == NSMouseEntered && !mouseIsOver) || (type == NSMouseExited && mouseIsOver)) {
mouseIsOver = !mouseIsOver;
}
-
+
[AWTToolkit eventCountPlusPlus];
-
+
JNIEnv *env = [ThreadUtilities getJNIEnv];
-
+
NSPoint eventLocation = [event locationInWindow];
NSPoint localPoint = [self convertPoint: eventLocation fromView: nil];
NSPoint absP = [NSEvent mouseLocation];
-
+
// Convert global numbers between Cocoa's coordinate system and Java.
// TODO: need consitent way for doing that both with global as well as with local coordinates.
// The reason to do it here is one more native method for getting screen dimension otherwise.
-
+
NSRect screenRect = [[[NSScreen screens] objectAtIndex:0] frame];
absP.y = screenRect.size.height - absP.y;
jint clickCount;
-
+
if (type == NSMouseEntered ||
type == NSMouseExited ||
type == NSScrollWheel ||
@@ -379,7 +380,7 @@
} else {
clickCount = [event clickCount];
}
-
+
static JNF_CLASS_CACHE(jc_NSEvent, "sun/lwawt/macosx/NSEvent");
static JNF_CTOR_CACHE(jctor_NSEvent, jc_NSEvent, "(IIIIIIIIDD)V");
jobject jEvent = JNFNewObject(env, jctor_NSEvent,
@@ -392,7 +393,7 @@
[event deltaY],
[event deltaX]);
CHECK_NULL(jEvent);
-
+
static JNF_CLASS_CACHE(jc_PlatformView, "sun/lwawt/macosx/CPlatformView");
static JNF_MEMBER_CACHE(jm_deliverMouseEvent, jc_PlatformView, "deliverMouseEvent", "(Lsun/lwawt/macosx/NSEvent;)V");
JNFCallVoidMethod(env, m_cPlatformView, jm_deliverMouseEvent, jEvent);
@@ -404,10 +405,10 @@
[self removeTrackingArea:rolloverTrackingArea];
[rolloverTrackingArea release];
}
-
+
int options = (NSTrackingActiveAlways | NSTrackingMouseEnteredAndExited |
NSTrackingMouseMoved | NSTrackingEnabledDuringMouseDrag);
-
+
rolloverTrackingArea = [[NSTrackingArea alloc] initWithRect:[self visibleRect]
options: options
owner:self
@@ -434,17 +435,17 @@
}
[sLastKeyEvent release];
sLastKeyEvent = [event retain];
-
+
[AWTToolkit eventCountPlusPlus];
JNIEnv *env = [ThreadUtilities getJNIEnv];
-
+
jstring characters = NULL;
jstring charactersIgnoringModifiers = NULL;
if ([event type] != NSFlagsChanged) {
characters = JNFNSToJavaString(env, [event characters]);
charactersIgnoringModifiers = JNFNSToJavaString(env, [event charactersIgnoringModifiers]);
}
-
+
static JNF_CLASS_CACHE(jc_NSEvent, "sun/lwawt/macosx/NSEvent");
static JNF_CTOR_CACHE(jctor_NSEvent, jc_NSEvent, "(IISLjava/lang/String;Ljava/lang/String;)V");
jobject jEvent = JNFNewObject(env, jctor_NSEvent,
@@ -454,12 +455,12 @@
characters,
charactersIgnoringModifiers);
CHECK_NULL(jEvent);
-
+
static JNF_CLASS_CACHE(jc_PlatformView, "sun/lwawt/macosx/CPlatformView");
static JNF_MEMBER_CACHE(jm_deliverKeyEvent, jc_PlatformView,
"deliverKeyEvent", "(Lsun/lwawt/macosx/NSEvent;)V");
JNFCallVoidMethod(env, m_cPlatformView, jm_deliverKeyEvent, jEvent);
-
+
if (characters != NULL) {
(*env)->DeleteLocalRef(env, characters);
}
@@ -479,34 +480,34 @@
- (void) drawRect:(NSRect)dirtyRect {
-AWT_ASSERT_APPKIT_THREAD;
-
+ AWT_ASSERT_APPKIT_THREAD;
+
[super drawRect:dirtyRect];
JNIEnv *env = [ThreadUtilities getJNIEnv];
if (env != NULL) {
-/*
- if ([self inLiveResize]) {
- NSRect rs[4];
- NSInteger count;
- [self getRectsExposedDuringLiveResize:rs count:&count];
- for (int i = 0; i < count; i++) {
- JNU_CallMethodByName(env, NULL, [m_awtWindow cPlatformView],
- "deliverWindowDidExposeEvent", "(FFFF)V",
- (jfloat)rs[i].origin.x, (jfloat)rs[i].origin.y,
- (jfloat)rs[i].size.width, (jfloat)rs[i].size.height);
- if ((*env)->ExceptionOccurred(env)) {
- (*env)->ExceptionDescribe(env);
- (*env)->ExceptionClear(env);
- }
- }
- } else {
-*/
+ /*
+ if ([self inLiveResize]) {
+ NSRect rs[4];
+ NSInteger count;
+ [self getRectsExposedDuringLiveResize:rs count:&count];
+ for (int i = 0; i < count; i++) {
+ JNU_CallMethodByName(env, NULL, [m_awtWindow cPlatformView],
+ "deliverWindowDidExposeEvent", "(FFFF)V",
+ (jfloat)rs[i].origin.x, (jfloat)rs[i].origin.y,
+ (jfloat)rs[i].size.width, (jfloat)rs[i].size.height);
+ if ((*env)->ExceptionOccurred(env)) {
+ (*env)->ExceptionDescribe(env);
+ (*env)->ExceptionClear(env);
+ }
+ }
+ } else {
+ */
static JNF_CLASS_CACHE(jc_CPlatformView, "sun/lwawt/macosx/CPlatformView");
static JNF_MEMBER_CACHE(jm_deliverWindowDidExposeEvent, jc_CPlatformView, "deliverWindowDidExposeEvent", "()V");
JNFCallVoidMethod(env, m_cPlatformView, jm_deliverWindowDidExposeEvent);
-/*
- }
-*/
+ /*
+ }
+ */
}
}
@@ -518,6 +519,15 @@
return NO;
}
+-(NSMutableString *) parseString : (id) complexString {
+ if ([complexString isKindOfClass:[NSString class]]) {
+ return [complexString mutableCopy];
+ }
+ else {
+ return [complexString mutableString];
+ }
+}
+
// NSAccessibility support
- (jobject)awtComponent:(JNIEnv*)env
{
@@ -557,17 +567,17 @@
- (id)accessibilityAttributeValue:(NSString *)attribute
{
AWT_ASSERT_APPKIT_THREAD;
-
+
if ([attribute isEqualToString:NSAccessibilityChildrenAttribute])
{
JNIEnv *env = [ThreadUtilities getJNIEnv];
-
+
(*env)->PushLocalFrame(env, 4);
-
+
id result = NSAccessibilityUnignoredChildrenForOnlyChild([self getAxData:env]);
-
+
(*env)->PopLocalFrame(env, NULL);
-
+
return result;
}
else
@@ -584,28 +594,28 @@
{
AWT_ASSERT_APPKIT_THREAD;
JNIEnv *env = [ThreadUtilities getJNIEnv];
-
+
(*env)->PushLocalFrame(env, 4);
-
+
id result = [[self getAxData:env] accessibilityHitTest:point withEnv:env];
-
+
(*env)->PopLocalFrame(env, NULL);
-
+
return result;
}
- (id)accessibilityFocusedUIElement
{
AWT_ASSERT_APPKIT_THREAD;
-
+
JNIEnv *env = [ThreadUtilities getJNIEnv];
-
+
(*env)->PushLocalFrame(env, 4);
-
+
id result = [[self getAxData:env] accessibilityFocusedUIElement];
-
+
(*env)->PopLocalFrame(env, NULL);
-
+
return result;
}
@@ -625,7 +635,8 @@
NSString *selectedText = [self accessibleSelectedText];
NSAttributedString *styledText = [[NSAttributedString alloc] initWithString:selectedText];
NSData *rtfdData = [styledText RTFDFromRange:NSMakeRange(0, [styledText length])
- documentAttributes:@{NSDocumentTypeDocumentAttribute: NSRTFTextDocumentType}];
+ documentAttributes:
+ @{NSDocumentTypeDocumentAttribute: NSRTFTextDocumentType}];
[styledText release];
return rtfdData;
}
@@ -643,12 +654,12 @@
- (id)validRequestorForSendType:(NSString *)sendType returnType:(NSString *)returnType
{
if ([[self window] firstResponder] != self) return nil; // let AWT components handle themselves
-
+
if ([sendType isEqual:NSStringPboardType] || [returnType isEqual:NSStringPboardType]) {
NSString *selectedText = [self accessibleSelectedText];
if (selectedText) return self;
}
-
+
return nil;
}
@@ -660,13 +671,13 @@
[pboard declareTypes:[NSArray arrayWithObject:NSStringPboardType] owner:nil];
return [pboard setString:[self accessibleSelectedText] forType:NSStringPboardType];
}
-
+
if ([types containsObject:NSRTFDPboardType])
{
[pboard declareTypes:[NSArray arrayWithObject:NSRTFDPboardType] owner:nil];
return [pboard setData:[self accessibleSelectedTextAsRTFD] forType:NSRTFDPboardType];
}
-
+
return NO;
}
@@ -678,17 +689,17 @@
NSString *text = [pboard stringForType:NSStringPboardType];
return [self replaceAccessibleTextSelection:text];
}
-
+
if ([[pboard types] containsObject:NSRTFDPboardType])
{
NSData *rtfdData = [pboard dataForType:NSRTFDPboardType];
NSAttributedString *styledText = [[NSAttributedString alloc] initWithRTFD:rtfdData documentAttributes:NULL];
NSString *text = [styledText string];
[styledText release];
-
+
return [self replaceAccessibleTextSelection:text];
}
-
+
return NO;
}
@@ -710,12 +721,12 @@
// If draggingSource is nil route the message to the superclass (if responding to the selector):
CDragSource *dragSource = self._dragSource;
NSDragOperation dragOp = NSDragOperationNone;
-
+
if (dragSource != nil)
dragOp = [dragSource draggingSourceOperationMaskForLocal:flag];
else if ([super respondsToSelector:@selector(draggingSourceOperationMaskForLocal:)])
dragOp = [super draggingSourceOperationMaskForLocal:flag];
-
+
return dragOp;
}
@@ -724,12 +735,12 @@
// If draggingSource is nil route the message to the superclass (if responding to the selector):
CDragSource *dragSource = self._dragSource;
NSArray* array = nil;
-
+
if (dragSource != nil)
array = [dragSource namesOfPromisedFilesDroppedAtDestination:dropDestination];
else if ([super respondsToSelector:@selector(namesOfPromisedFilesDroppedAtDestination:)])
array = [super namesOfPromisedFilesDroppedAtDestination:dropDestination];
-
+
return array;
}
@@ -737,7 +748,7 @@
{
// If draggingSource is nil route the message to the superclass (if responding to the selector):
CDragSource *dragSource = self._dragSource;
-
+
if (dragSource != nil)
[dragSource draggedImage:image beganAt:screenPoint];
else if ([super respondsToSelector:@selector(draggedImage::)])
@@ -748,7 +759,7 @@
{
// If draggingSource is nil route the message to the superclass (if responding to the selector):
CDragSource *dragSource = self._dragSource;
-
+
if (dragSource != nil)
[dragSource draggedImage:image endedAt:screenPoint operation:operation];
else if ([super respondsToSelector:@selector(draggedImage:::)])
@@ -759,7 +770,7 @@
{
// If draggingSource is nil route the message to the superclass (if responding to the selector):
CDragSource *dragSource = self._dragSource;
-
+
if (dragSource != nil)
[dragSource draggedImage:image movedTo:screenPoint];
else if ([super respondsToSelector:@selector(draggedImage::)])
@@ -771,12 +782,12 @@
// If draggingSource is nil route the message to the superclass (if responding to the selector):
CDragSource *dragSource = self._dragSource;
BOOL result = FALSE;
-
+
if (dragSource != nil)
result = [dragSource ignoreModifierKeysWhileDragging];
else if ([super respondsToSelector:@selector(ignoreModifierKeysWhileDragging)])
result = [super ignoreModifierKeysWhileDragging];
-
+
return result;
}
@@ -789,12 +800,12 @@
// If draggingDestination is nil route the message to the superclass:
CDropTarget *dropTarget = self._dropTarget;
NSDragOperation dragOp = NSDragOperationNone;
-
+
if (dropTarget != nil)
dragOp = [dropTarget draggingEntered:sender];
else if ([super respondsToSelector:@selector(draggingEntered:)])
dragOp = [super draggingEntered:sender];
-
+
return dragOp;
}
@@ -803,12 +814,12 @@
// If draggingDestination is nil route the message to the superclass:
CDropTarget *dropTarget = self._dropTarget;
NSDragOperation dragOp = NSDragOperationNone;
-
+
if (dropTarget != nil)
dragOp = [dropTarget draggingUpdated:sender];
else if ([super respondsToSelector:@selector(draggingUpdated:)])
dragOp = [super draggingUpdated:sender];
-
+
return dragOp;
}
@@ -816,7 +827,7 @@
{
// If draggingDestination is nil route the message to the superclass:
CDropTarget *dropTarget = self._dropTarget;
-
+
if (dropTarget != nil)
[dropTarget draggingExited:sender];
else if ([super respondsToSelector:@selector(draggingExited:)])
@@ -828,12 +839,12 @@
// If draggingDestination is nil route the message to the superclass:
CDropTarget *dropTarget = self._dropTarget;
BOOL result = FALSE;
-
+
if (dropTarget != nil)
result = [dropTarget prepareForDragOperation:sender];
else if ([super respondsToSelector:@selector(prepareForDragOperation:)])
result = [super prepareForDragOperation:sender];
-
+
return result;
}
@@ -842,12 +853,12 @@
// If draggingDestination is nil route the message to the superclass:
CDropTarget *dropTarget = self._dropTarget;
BOOL result = FALSE;
-
+
if (dropTarget != nil)
result = [dropTarget performDragOperation:sender];
else if ([super respondsToSelector:@selector(performDragOperation:)])
result = [super performDragOperation:sender];
-
+
return result;
}
@@ -855,7 +866,7 @@
{
// If draggingDestination is nil route the message to the superclass:
CDropTarget *dropTarget = self._dropTarget;
-
+
if (dropTarget != nil)
[dropTarget concludeDragOperation:sender];
else if ([super respondsToSelector:@selector(concludeDragOperation:)])
@@ -866,7 +877,7 @@
{
// If draggingDestination is nil route the message to the superclass:
CDropTarget *dropTarget = self._dropTarget;
-
+
if (dropTarget != nil)
[dropTarget draggingEnded:sender];
else if ([super respondsToSelector:@selector(draggingEnded:)])
@@ -885,49 +896,49 @@
#ifdef IM_DEBUG
fprintf(stderr, "AWTView InputMethod Selector Called : [insertText]: %s\n", [aString UTF8String]);
#endif // IM_DEBUG
-
+
if (fInputMethodLOCKABLE == NULL) {
return;
}
-
+
// Insert happens at the end of PAH
fInPressAndHold = NO;
-
+
// insertText gets called when the user commits text generated from an input method. It also gets
// called during ordinary input as well. We only need to send an input method event when we have marked
// text, or 'text in progress'. We also need to send the event if we get an insert text out of the blue!
// (i.e., when the user uses the Character palette or Inkwell), or when the string to insert is a complex
// Unicode value.
- NSUInteger utf16Length = [aString lengthOfBytesUsingEncoding:NSUTF16StringEncoding];
- NSUInteger utf8Length = [aString lengthOfBytesUsingEncoding:NSUTF8StringEncoding];
+
+ NSMutableString * useString = [self parseString:aString];
+ NSUInteger utf16Length = [useString lengthOfBytesUsingEncoding:NSUTF16StringEncoding];
+ NSUInteger utf8Length = [useString lengthOfBytesUsingEncoding:NSUTF8StringEncoding];
BOOL aStringIsComplex = NO;
if ((utf16Length > 2) ||
- ((utf8Length > 1) && [self isCodePointInUnicodeBlockNeedingIMEvent:[aString characterAtIndex:0]])) {
+ ((utf8Length > 1) && [self isCodePointInUnicodeBlockNeedingIMEvent:[useString characterAtIndex:0]])) {
aStringIsComplex = YES;
}
-
+
if ([self hasMarkedText] || !fProcessingKeystroke || aStringIsComplex) {
JNIEnv *env = [ThreadUtilities getJNIEnv];
-
+
static JNF_MEMBER_CACHE(jm_selectPreviousGlyph, jc_CInputMethod, "selectPreviousGlyph", "()V");
// We need to select the previous glyph so that it is overwritten.
if (fPAHNeedsToSelect) {
JNFCallVoidMethod(env, fInputMethodLOCKABLE, jm_selectPreviousGlyph);
fPAHNeedsToSelect = NO;
}
-
+
static JNF_MEMBER_CACHE(jm_insertText, jc_CInputMethod, "insertText", "(Ljava/lang/String;)V");
- jstring insertedText = JNFNSToJavaString(env, aString);
+ jstring insertedText = JNFNSToJavaString(env, useString);
JNFCallVoidMethod(env, fInputMethodLOCKABLE, jm_insertText, insertedText); // AWT_THREADING Safe (AWTRunLoopMode)
(*env)->DeleteLocalRef(env, insertedText);
-
+
// The input method event will create psuedo-key events for each character in the committed string.
// We also don't want to send the character that triggered the insertText, usually a return. [3337563]
fKeyEventsNeeded = NO;
}
-
fPAHNeedsToSelect = NO;
-
}
- (void) doCommandBySelector:(SEL)aSelector
@@ -947,7 +958,7 @@
{
if (!fInputMethodLOCKABLE)
return;
-
+
BOOL isAttributedString = [aString isKindOfClass:[NSAttributedString class]];
NSAttributedString *attrString = (isAttributedString ? (NSAttributedString *)aString : nil);
NSString *incomingString = (isAttributedString ? [aString string] : aString);
@@ -958,14 +969,14 @@
static JNF_MEMBER_CACHE(jm_addAttribute, jc_CInputMethod, "addAttribute", "(ZZII)V");
static JNF_MEMBER_CACHE(jm_dispatchText, jc_CInputMethod, "dispatchText", "(IIZ)V");
JNIEnv *env = [ThreadUtilities getJNIEnv];
-
+
// NSInputContext already did the analysis of the TSM event and created attributes indicating
// the underlining and color that should be done to the string. We need to look at the underline
// style and color to determine what kind of Java hilighting needs to be done.
jstring inProcessText = JNFNSToJavaString(env, incomingString);
JNFCallVoidMethod(env, fInputMethodLOCKABLE, jm_startIMUpdate, inProcessText); // AWT_THREADING Safe (AWTRunLoopMode)
(*env)->DeleteLocalRef(env, inProcessText);
-
+
if (isAttributedString) {
NSUInteger length;
NSRange effectiveRange;
@@ -981,25 +992,25 @@
(NSNumber *)[attributes objectForKey:NSUnderlineStyleAttributeName];
NSInteger underlineSize = [underlineSizeObj integerValue];
isThickUnderline = (underlineSize > 1);
-
+
NSColor *underlineColorObj =
(NSColor *)[attributes objectForKey:NSUnderlineColorAttributeName];
isGray = !([underlineColorObj isEqual:[NSColor blackColor]]);
-
+
JNFCallVoidMethod(env, fInputMethodLOCKABLE, jm_addAttribute, isThickUnderline, isGray, effectiveRange.location, effectiveRange.length); // AWT_THREADING Safe (AWTRunLoopMode)
}
}
}
-
+
static JNF_MEMBER_CACHE(jm_selectPreviousGlyph, jc_CInputMethod, "selectPreviousGlyph", "()V");
// We need to select the previous glyph so that it is overwritten.
if (fPAHNeedsToSelect) {
JNFCallVoidMethod(env, fInputMethodLOCKABLE, jm_selectPreviousGlyph);
fPAHNeedsToSelect = NO;
}
-
+
JNFCallVoidMethod(env, fInputMethodLOCKABLE, jm_dispatchText, selectionRange.location, selectionRange.length, JNI_FALSE); // AWT_THREADING Safe (AWTRunLoopMode)
-
+
// If the marked text is being cleared (zero-length string) don't handle the key event.
if ([incomingString length] == 0) {
fKeyEventsNeeded = NO;
@@ -1011,16 +1022,16 @@
#ifdef IM_DEBUG
fprintf(stderr, "AWTView InputMethod Selector Called : [unmarkText]\n");
#endif // IM_DEBUG
-
+
if (!fInputMethodLOCKABLE) {
return;
}
-
+
// unmarkText cancels any input in progress and commits it to the text field.
static JNF_MEMBER_CACHE(jm_unmarkText, jc_CInputMethod, "unmarkText", "()V");
JNIEnv *env = [ThreadUtilities getJNIEnv];
JNFCallVoidMethod(env, fInputMethodLOCKABLE, jm_unmarkText); // AWT_THREADING Safe (AWTRunLoopMode)
-
+
}
- (BOOL) hasMarkedText
@@ -1028,24 +1039,24 @@
#ifdef IM_DEBUG
fprintf(stderr, "AWTView InputMethod Selector Called : [hasMarkedText]\n");
#endif // IM_DEBUG
-
+
if (!fInputMethodLOCKABLE) {
return NO;
}
-
+
static JNF_MEMBER_CACHE(jf_fCurrentText, jc_CInputMethod, "fCurrentText", "Ljava/text/AttributedString;");
static JNF_MEMBER_CACHE(jf_fCurrentTextLength, jc_CInputMethod, "fCurrentTextLength", "I");
JNIEnv *env = [ThreadUtilities getJNIEnv];
jobject currentText = JNFGetObjectField(env, fInputMethodLOCKABLE, jf_fCurrentText);
-
+
jint currentTextLength = JNFGetIntField(env, fInputMethodLOCKABLE, jf_fCurrentTextLength);
-
+
BOOL hasMarkedText = (currentText != NULL && currentTextLength > 0);
-
+
if (currentText != NULL) {
(*env)->DeleteLocalRef(env, currentText);
}
-
+
return hasMarkedText;
}
@@ -1054,7 +1065,7 @@
#ifdef IM_DEBUG
fprintf(stderr, "AWTView InputMethod Selector Called : [conversationIdentifier]\n");
#endif // IM_DEBUG
-
+
return (NSInteger) self;
}
@@ -1066,16 +1077,16 @@
#ifdef IM_DEBUG
fprintf(stderr, "AWTView InputMethod Selector Called : [attributedSubstringFromRange] location=%lu, length=%lu\n", (unsigned long)theRange.location, (unsigned long)theRange.length);
#endif // IM_DEBUG
-
+
static JNF_MEMBER_CACHE(jm_substringFromRange, jc_CInputMethod, "attributedSubstringFromRange", "(II)Ljava/lang/String;");
JNIEnv *env = [ThreadUtilities getJNIEnv];
jobject theString = JNFCallObjectMethod(env, fInputMethodLOCKABLE, jm_substringFromRange, theRange.location, theRange.length); // AWT_THREADING Safe (AWTRunLoopMode)
-
+
id result = [[[NSAttributedString alloc] initWithString:JNFJavaToNSString(env, theString)] autorelease];
#ifdef IM_DEBUG
NSLog(@"attributedSubstringFromRange returning \"%@\"", result);
#endif // IM_DEBUG
-
+
(*env)->DeleteLocalRef(env, theString);
return result;
}
@@ -1085,24 +1096,24 @@
*/
- (NSRange) markedRange
{
-
+
#ifdef IM_DEBUG
fprintf(stderr, "AWTView InputMethod Selector Called : [markedRange]\n");
#endif // IM_DEBUG
-
+
if (!fInputMethodLOCKABLE) {
return NSMakeRange(NSNotFound, 0);
}
-
+
static JNF_MEMBER_CACHE(jm_markedRange, jc_CInputMethod, "markedRange", "()[I");
JNIEnv *env = [ThreadUtilities getJNIEnv];
jarray array;
jboolean isCopy;
jint *_array;
NSRange range = NSMakeRange(NSNotFound, 0);
-
+
array = JNFCallObjectMethod(env, fInputMethodLOCKABLE, jm_markedRange); // AWT_THREADING Safe (AWTRunLoopMode)
-
+
if (array) {
_array = (*env)->GetIntArrayElements(env, array, &isCopy);
if (_array != NULL) {
@@ -1116,7 +1127,7 @@
}
(*env)->DeleteLocalRef(env, array);
}
-
+
return range;
}
@@ -1128,18 +1139,18 @@
if (!fInputMethodLOCKABLE) {
return NSMakeRange(NSNotFound, 0);
}
-
+
static JNF_MEMBER_CACHE(jm_selectedRange, jc_CInputMethod, "selectedRange", "()[I");
JNIEnv *env = [ThreadUtilities getJNIEnv];
jarray array;
jboolean isCopy;
jint *_array;
NSRange range = NSMakeRange(NSNotFound, 0);
-
+
#ifdef IM_DEBUG
fprintf(stderr, "AWTView InputMethod Selector Called : [selectedRange]\n");
#endif // IM_DEBUG
-
+
array = JNFCallObjectMethod(env, fInputMethodLOCKABLE, jm_selectedRange); // AWT_THREADING Safe (AWTRunLoopMode)
if (array) {
_array = (*env)->GetIntArrayElements(env, array, &isCopy);
@@ -1150,7 +1161,7 @@
}
(*env)->DeleteLocalRef(env, array);
}
-
+
return range;
}
@@ -1161,7 +1172,7 @@
if (!fInputMethodLOCKABLE) {
return NSZeroRect;
}
-
+
static JNF_MEMBER_CACHE(jm_firstRectForCharacterRange, jc_CInputMethod,
"firstRectForCharacterRange", "(I)[I");
JNIEnv *env = [ThreadUtilities getJNIEnv];
@@ -1169,16 +1180,16 @@
jboolean isCopy;
jint *_array;
NSRect rect;
-
+
#ifdef IM_DEBUG
fprintf(stderr,
"AWTView InputMethod Selector Called : [firstRectForCharacterRange:] location=%lu, length=%lu\n",
(unsigned long)theRange.location, (unsigned long)theRange.length);
#endif // IM_DEBUG
-
+
array = JNFCallObjectMethod(env, fInputMethodLOCKABLE, jm_firstRectForCharacterRange,
theRange.location); // AWT_THREADING Safe (AWTRunLoopMode)
-
+
_array = (*env)->GetIntArrayElements(env, array, &isCopy);
if (_array) {
rect = ConvertNSScreenRect(env, NSMakeRect(_array[0], _array[1], _array[2], _array[3]));
@@ -1187,7 +1198,7 @@
rect = NSZeroRect;
}
(*env)->DeleteLocalRef(env, array);
-
+
#ifdef IM_DEBUG
fprintf(stderr,
"firstRectForCharacterRange returning x=%f, y=%f, width=%f, height=%f\n",
@@ -1204,23 +1215,23 @@
if (!fInputMethodLOCKABLE) {
return NSNotFound;
}
-
+
static JNF_MEMBER_CACHE(jm_characterIndexForPoint, jc_CInputMethod,
"characterIndexForPoint", "(II)I");
JNIEnv *env = [ThreadUtilities getJNIEnv];
-
+
NSPoint flippedLocation = ConvertNSScreenPoint(env, thePoint);
-
+
#ifdef IM_DEBUG
fprintf(stderr, "AWTView InputMethod Selector Called : [characterIndexForPoint:(NSPoint)thePoint] x=%f, y=%f\n", flippedLocation.x, flippedLocation.y);
#endif // IM_DEBUG
-
+
jint index = JNFCallIntMethod(env, fInputMethodLOCKABLE, jm_characterIndexForPoint, (jint)flippedLocation.x, (jint)flippedLocation.y); // AWT_THREADING Safe (AWTRunLoopMode)
-
+
#ifdef IM_DEBUG
fprintf(stderr, "characterIndexForPoint returning %ld\n", index);
#endif // IM_DEBUG
-
+
if (index == -1) {
return NSNotFound;
} else {
@@ -1233,7 +1244,7 @@
#ifdef IM_DEBUG
fprintf(stderr, "AWTView InputMethod Selector Called : [validAttributesForMarkedText]\n");
#endif // IM_DEBUG
-
+
return [NSArray array];
}
@@ -1242,14 +1253,14 @@
#ifdef IM_DEBUG
fprintf(stderr, "AWTView InputMethod Selector Called : [setInputMethod]\n");
#endif // IM_DEBUG
-
+
JNIEnv *env = [ThreadUtilities getJNIEnv];
-
+
// Get rid of the old one
if (fInputMethodLOCKABLE) {
JNFDeleteGlobalRef(env, fInputMethodLOCKABLE);
}
-
+
// Save a global ref to the new input method.
if (inputMethod != NULL)
fInputMethodLOCKABLE = JNFNewGlobalRef(env, inputMethod);
@@ -1262,7 +1273,7 @@
#ifdef IM_DEBUG
fprintf(stderr, "AWTView InputMethod Selector Called : [abandonInput]\n");
#endif // IM_DEBUG
-
+
[ThreadUtilities performOnMainThread:@selector(markedTextAbandoned:) on:[NSInputManager currentInputManager] withObject:self waitUntilDone:YES];
[self unmarkText];
}
@@ -1284,22 +1295,22 @@
(JNIEnv *env, jobject obj, jint originX, jint originY, jint width, jint height, jlong windowLayerPtr)
{
__block AWTView *newView = nil;
-
-JNF_COCOA_ENTER(env);
-
+
+ JNF_COCOA_ENTER(env);
+
NSRect rect = NSMakeRect(originX, originY, width, height);
jobject cPlatformView = (*env)->NewGlobalRef(env, obj);
-
+
[ThreadUtilities performOnMainThreadWaiting:YES block:^(){
-
+
CALayer *windowLayer = jlong_to_ptr(windowLayerPtr);
newView = [[AWTView alloc] initWithRect:rect
platformView:cPlatformView
windowLayer:windowLayer];
}];
-
-JNF_COCOA_EXIT(env);
-
+
+ JNF_COCOA_EXIT(env);
+
return ptr_to_jlong(newView);
}
@@ -1313,24 +1324,24 @@
Java_sun_lwawt_macosx_CPlatformView_nativeSetAutoResizable
(JNIEnv *env, jclass cls, jlong viewPtr, jboolean toResize)
{
-JNF_COCOA_ENTER(env);
+ JNF_COCOA_ENTER(env);
+
+ NSView *view = (NSView *)jlong_to_ptr(viewPtr);
- NSView *view = (NSView *)jlong_to_ptr(viewPtr);
-
- [ThreadUtilities performOnMainThreadWaiting:NO block:^(){
-
- if (toResize) {
- [view setAutoresizingMask: NSViewHeightSizable | NSViewWidthSizable];
- } else {
- [view setAutoresizingMask: NSViewMinYMargin | NSViewMaxXMargin];
- }
-
- if ([view superview] != nil) {
- [[view superview] setAutoresizesSubviews:(BOOL)toResize];
- }
-
+ [ThreadUtilities performOnMainThreadWaiting:NO block:^(){
+
+ if (toResize) {
+ [view setAutoresizingMask: NSViewHeightSizable | NSViewWidthSizable];
+ } else {
+ [view setAutoresizingMask: NSViewMinYMargin | NSViewMaxXMargin];
+ }
+
+ if ([view superview] != nil) {
+ [[view superview] setAutoresizesSubviews:(BOOL)toResize];
+ }
+
}];
-JNF_COCOA_EXIT(env);
+ JNF_COCOA_EXIT(env);
}
/*
@@ -1345,17 +1356,17 @@
{
__block jint ret; //CGDirectDisplayID
-JNF_COCOA_ENTER(env);
+ JNF_COCOA_ENTER(env);
- NSView *view = (NSView *)jlong_to_ptr(viewPtr);
+ NSView *view = (NSView *)jlong_to_ptr(viewPtr);
NSWindow *window = [view window];
[ThreadUtilities performOnMainThreadWaiting:YES block:^(){
-
- ret = (jint)[[AWTWindow getNSWindowDisplayID_AppKitThread: window] intValue];
+
+ ret = (jint)[[AWTWindow getNSWindowDisplayID_AppKitThread: window] intValue];
}];
-JNF_COCOA_EXIT(env);
+ JNF_COCOA_EXIT(env);
return ret;
}
@@ -1372,13 +1383,13 @@
{
jobject jRect = NULL;
-JNF_COCOA_ENTER(env);
+ JNF_COCOA_ENTER(env);
__block NSRect rect = NSZeroRect;
- NSView *view = (NSView *)jlong_to_ptr(viewPtr);
+ NSView *view = (NSView *)jlong_to_ptr(viewPtr);
[ThreadUtilities performOnMainThreadWaiting:YES block:^(){
-
+
NSRect viewBounds = [view bounds];
NSRect frameInWindow = [view convertRect:viewBounds toView:nil];
rect = [[view window] convertRectToScreen:frameInWindow];
@@ -1388,7 +1399,7 @@
}];
jRect = NSToJavaRect(env, rect);
-JNF_COCOA_EXIT(env);
+ JNF_COCOA_EXIT(env);
return jRect;
}
@@ -1404,16 +1415,16 @@
{
__block jboolean underMouse = JNI_FALSE;
-JNF_COCOA_ENTER(env);
+ JNF_COCOA_ENTER(env);
NSView *nsView = OBJC(viewPtr);
- [ThreadUtilities performOnMainThreadWaiting:YES block:^(){
- NSPoint ptWindowCoords = [[nsView window] mouseLocationOutsideOfEventStream];
- NSPoint ptViewCoords = [nsView convertPoint:ptWindowCoords fromView:nil];
- underMouse = [nsView hitTest:ptViewCoords] != nil;
+ [ThreadUtilities performOnMainThreadWaiting:YES block:^(){
+ NSPoint ptWindowCoords = [[nsView window] mouseLocationOutsideOfEventStream];
+ NSPoint ptViewCoords = [nsView convertPoint:ptWindowCoords fromView:nil];
+ underMouse = [nsView hitTest:ptViewCoords] != nil;
}];
-JNF_COCOA_EXIT(env);
+ JNF_COCOA_EXIT(env);
return underMouse;
}