Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/src/macosx/native_NOTIOS/sun/awt/AWTView.m
38829 views
/*1* Copyright (c) 2011, 2018, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation. Oracle designates this7* particular file as subject to the "Classpath" exception as provided8* by Oracle in the LICENSE file that accompanied this code.9*10* This code is distributed in the hope that it will be useful, but WITHOUT11* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or12* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License13* version 2 for more details (a copy is included in the LICENSE file that14* accompanied this code).15*16* You should have received a copy of the GNU General Public License version17* 2 along with this work; if not, write to the Free Software Foundation,18* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.19*20* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA21* or visit www.oracle.com if you need additional information or have any22* questions.23*/2425#import "CGLGraphicsConfig.h"2627#import <JavaNativeFoundation/JavaNativeFoundation.h>28#import <JavaRuntimeSupport/JavaRuntimeSupport.h>2930#import "ThreadUtilities.h"31#import "AWTView.h"32#import "AWTEvent.h"33#import "AWTWindow.h"34#import "LWCToolkit.h"35#import "JavaComponentAccessibility.h"36#import "JavaTextAccessibility.h"37#import "JavaAccessibilityUtilities.h"38#import "GeomUtilities.h"39#import "OSVersion.h"40#import "CGLLayer.h"4142@interface AWTView()43@property (retain) CDropTarget *_dropTarget;44@property (retain) CDragSource *_dragSource;4546-(void) deliverResize: (NSRect) rect;47-(void) resetTrackingArea;48-(void) deliverJavaKeyEventHelper: (NSEvent*) event;49-(BOOL) isCodePointInUnicodeBlockNeedingIMEvent: (unichar) codePoint;50@end5152// Uncomment this line to see fprintfs of each InputMethod API being called on this View53//#define IM_DEBUG TRUE54//#define EXTRA_DEBUG5556static BOOL shouldUsePressAndHold() {57static int shouldUsePressAndHold = -1;58if (shouldUsePressAndHold != -1) return shouldUsePressAndHold;59shouldUsePressAndHold = !isSnowLeopardOrLower();60return shouldUsePressAndHold;61}6263@implementation AWTView6465@synthesize _dropTarget;66@synthesize _dragSource;67@synthesize cglLayer;68@synthesize mouseIsOver;6970// Note: Must be called on main (AppKit) thread only71- (id) initWithRect: (NSRect) rect72platformView: (jobject) cPlatformView73windowLayer: (CALayer*) windowLayer74{75AWT_ASSERT_APPKIT_THREAD;76// Initialize ourselves77self = [super initWithFrame: rect];78if (self == nil) return self;7980m_cPlatformView = cPlatformView;81fInputMethodLOCKABLE = NULL;82fKeyEventsNeeded = NO;83fProcessingKeystroke = NO;8485fEnablePressAndHold = shouldUsePressAndHold();86fInPressAndHold = NO;87fPAHNeedsToSelect = NO;8889mouseIsOver = NO;90[self resetTrackingArea];91[self setAutoresizesSubviews:NO];9293if (windowLayer != nil) {94self.cglLayer = windowLayer;95//Layer hosting view96[self setLayer: cglLayer];97[self setWantsLayer: YES];98//Layer backed view99//[self.layer addSublayer: (CALayer *)cglLayer];100//[self setLayerContentsRedrawPolicy: NSViewLayerContentsRedrawDuringViewResize];101//[self setLayerContentsPlacement: NSViewLayerContentsPlacementTopLeft];102//[self setAutoresizingMask: NSViewHeightSizable | NSViewWidthSizable];103104#ifdef REMOTELAYER105CGLLayer *parentLayer = (CGLLayer*)self.cglLayer;106parentLayer.parentLayer = NULL;107parentLayer.remoteLayer = NULL;108if (JRSRemotePort != 0 && remoteSocketFD > 0) {109CGLLayer *remoteLayer = [[CGLLayer alloc] initWithJavaLayer: parentLayer.javaLayer];110remoteLayer.target = GL_TEXTURE_2D;111NSLog(@"Creating Parent=%p, Remote=%p", parentLayer, remoteLayer);112parentLayer.remoteLayer = remoteLayer;113remoteLayer.parentLayer = parentLayer;114remoteLayer.remoteLayer = NULL;115remoteLayer.jrsRemoteLayer = [remoteLayer createRemoteLayerBoundTo:JRSRemotePort];116[remoteLayer retain]; // REMIND117remoteLayer.frame = CGRectMake(0, 0, 720, 500); // REMIND118[remoteLayer.jrsRemoteLayer retain]; // REMIND119int layerID = [remoteLayer.jrsRemoteLayer layerID];120NSLog(@"layer id to send = %d", layerID);121sendLayerID(layerID);122}123#endif /* REMOTELAYER */124}125126return self;127}128129- (void) dealloc {130AWT_ASSERT_APPKIT_THREAD;131132self.cglLayer = nil;133134JNIEnv *env = [ThreadUtilities getJNIEnvUncached];135(*env)->DeleteWeakGlobalRef(env, m_cPlatformView);136m_cPlatformView = NULL;137138if (fInputMethodLOCKABLE != NULL)139{140JNIEnv *env = [ThreadUtilities getJNIEnvUncached];141142JNFDeleteGlobalRef(env, fInputMethodLOCKABLE);143fInputMethodLOCKABLE = NULL;144}145146if (rolloverTrackingArea != nil) {147[self removeTrackingArea:rolloverTrackingArea];148[rolloverTrackingArea release];149rolloverTrackingArea = nil;150}151152[super dealloc];153}154155- (void) viewDidMoveToWindow {156AWT_ASSERT_APPKIT_THREAD;157158[AWTToolkit eventCountPlusPlus];159160[JNFRunLoop performOnMainThreadWaiting:NO withBlock:^() {161[[self window] makeFirstResponder: self];162}];163if ([self window] != NULL) {164[self resetTrackingArea];165}166}167168- (BOOL) acceptsFirstMouse: (NSEvent *)event {169return YES;170}171172- (BOOL) acceptsFirstResponder {173return YES;174}175176- (BOOL) becomeFirstResponder {177return YES;178}179180- (BOOL) preservesContentDuringLiveResize {181return YES;182}183184/*185* Automatically triggered functions.186*/187188- (void)resizeWithOldSuperviewSize:(NSSize)oldBoundsSize {189[super resizeWithOldSuperviewSize: oldBoundsSize];190[self deliverResize: [self frame]];191}192193/*194* MouseEvents support195*/196197- (void) mouseDown: (NSEvent *)event {198NSInputManager *inputManager = [NSInputManager currentInputManager];199if ([inputManager wantsToHandleMouseEvents]) {200#if IM_DEBUG201NSLog(@"-> IM wants to handle event");202#endif203if (![inputManager handleMouseEvent:event]) {204[self deliverJavaMouseEvent: event];205} else {206#if IM_DEBUG207NSLog(@"-> Event was handled.");208#endif209}210} else {211#if IM_DEBUG212NSLog(@"-> IM does not want to handle event");213#endif214[self deliverJavaMouseEvent: event];215}216}217218- (void) mouseUp: (NSEvent *)event {219[self deliverJavaMouseEvent: event];220}221222- (void) rightMouseDown: (NSEvent *)event {223[self deliverJavaMouseEvent: event];224}225226- (void) rightMouseUp: (NSEvent *)event {227[self deliverJavaMouseEvent: event];228}229230- (void) otherMouseDown: (NSEvent *)event {231[self deliverJavaMouseEvent: event];232}233234- (void) otherMouseUp: (NSEvent *)event {235[self deliverJavaMouseEvent: event];236}237238- (void) mouseMoved: (NSEvent *)event {239// TODO: better way to redirect move events to the "under" view240241NSPoint eventLocation = [event locationInWindow];242NSPoint localPoint = [self convertPoint: eventLocation fromView: nil];243244if ([self mouse: localPoint inRect: [self bounds]]) {245[self deliverJavaMouseEvent: event];246} else {247[[self nextResponder] mouseDown:event];248}249}250251- (void) mouseDragged: (NSEvent *)event {252[self deliverJavaMouseEvent: event];253}254255- (void) rightMouseDragged: (NSEvent *)event {256[self deliverJavaMouseEvent: event];257}258259- (void) otherMouseDragged: (NSEvent *)event {260[self deliverJavaMouseEvent: event];261}262263- (void) mouseEntered: (NSEvent *)event {264[[self window] setAcceptsMouseMovedEvents:YES];265//[[self window] makeFirstResponder:self];266[self deliverJavaMouseEvent: event];267}268269- (void) mouseExited: (NSEvent *)event {270[[self window] setAcceptsMouseMovedEvents:NO];271[self deliverJavaMouseEvent: event];272//Restore the cursor back.273//[CCursorManager _setCursor: [NSCursor arrowCursor]];274}275276- (void) scrollWheel: (NSEvent*) event {277[self deliverJavaMouseEvent: event];278}279280/*281* KeyEvents support282*/283284- (void) keyDown: (NSEvent *)event {285fProcessingKeystroke = YES;286fKeyEventsNeeded = YES;287288// Allow TSM to look at the event and potentially send back NSTextInputClient messages.289[self interpretKeyEvents:[NSArray arrayWithObject:event]];290291if (fEnablePressAndHold && [event willBeHandledByComplexInputMethod] && fInputMethodLOCKABLE) {292fProcessingKeystroke = NO;293if (!fInPressAndHold) {294fInPressAndHold = YES;295fPAHNeedsToSelect = YES;296}297return;298}299300NSString *eventCharacters = [event characters];301BOOL isDeadKey = (eventCharacters != nil && [eventCharacters length] == 0);302303if ((![self hasMarkedText] && fKeyEventsNeeded) || isDeadKey) {304[self deliverJavaKeyEventHelper: event];305}306307fProcessingKeystroke = NO;308}309310- (void) keyUp: (NSEvent *)event {311[self deliverJavaKeyEventHelper: event];312}313314- (void) flagsChanged: (NSEvent *)event {315[self deliverJavaKeyEventHelper: event];316}317318- (BOOL) performKeyEquivalent: (NSEvent *) event {319// if IM is active key events should be ignored320if (![self hasMarkedText] && !fInPressAndHold) {321[self deliverJavaKeyEventHelper: event];322}323324// Workaround for 8020209: special case for "Cmd =" and "Cmd ."325// because Cocoa calls performKeyEquivalent twice for these keystrokes326NSUInteger modFlags = [event modifierFlags] &327(NSCommandKeyMask | NSAlternateKeyMask | NSShiftKeyMask | NSControlKeyMask);328if (modFlags == NSCommandKeyMask) {329NSString *eventChars = [event charactersIgnoringModifiers];330if ([eventChars length] == 1) {331unichar ch = [eventChars characterAtIndex:0];332if (ch == '=' || ch == '.') {333[[NSApp mainMenu] performKeyEquivalent: event];334return YES;335}336}337338}339340return NO;341}342343/**344* Utility methods and accessors345*/346347-(void) deliverJavaMouseEvent: (NSEvent *) event {348BOOL isEnabled = YES;349NSWindow* window = [self window];350if ([window isKindOfClass: [AWTWindow_Panel class]] || [window isKindOfClass: [AWTWindow_Normal class]]) {351isEnabled = [(AWTWindow*)[window delegate] isEnabled];352}353354if (!isEnabled) {355return;356}357358NSEventType type = [event type];359360// check synthesized mouse entered/exited events361if ((type == NSMouseEntered && mouseIsOver) || (type == NSMouseExited && !mouseIsOver)) {362return;363}else if ((type == NSMouseEntered && !mouseIsOver) || (type == NSMouseExited && mouseIsOver)) {364mouseIsOver = !mouseIsOver;365}366367[AWTToolkit eventCountPlusPlus];368369JNIEnv *env = [ThreadUtilities getJNIEnv];370371NSPoint eventLocation = [event locationInWindow];372NSPoint localPoint = [self convertPoint: eventLocation fromView: nil];373NSPoint absP = [NSEvent mouseLocation];374375// Convert global numbers between Cocoa's coordinate system and Java.376// TODO: need consitent way for doing that both with global as well as with local coordinates.377// The reason to do it here is one more native method for getting screen dimension otherwise.378379NSRect screenRect = [[[NSScreen screens] objectAtIndex:0] frame];380absP.y = screenRect.size.height - absP.y;381jint clickCount;382383if (type == NSMouseEntered ||384type == NSMouseExited ||385type == NSScrollWheel ||386type == NSMouseMoved) {387clickCount = 0;388} else {389clickCount = [event clickCount];390}391392jdouble deltaX = [event deltaX];393jdouble deltaY = [event deltaY];394if ([AWTToolkit hasPreciseScrollingDeltas: event]) {395deltaX = [event scrollingDeltaX] * 0.1;396deltaY = [event scrollingDeltaY] * 0.1;397}398399static JNF_CLASS_CACHE(jc_NSEvent, "sun/lwawt/macosx/NSEvent");400static JNF_CTOR_CACHE(jctor_NSEvent, jc_NSEvent, "(IIIIIIIIDDI)V");401jobject jEvent = JNFNewObject(env, jctor_NSEvent,402[event type],403[event modifierFlags],404clickCount,405[event buttonNumber],406(jint)localPoint.x, (jint)localPoint.y,407(jint)absP.x, (jint)absP.y,408deltaY,409deltaX,410[AWTToolkit scrollStateWithEvent: event]);411if (jEvent == nil) {412// Unable to create event by some reason.413return;414}415416static JNF_CLASS_CACHE(jc_PlatformView, "sun/lwawt/macosx/CPlatformView");417static JNF_MEMBER_CACHE(jm_deliverMouseEvent, jc_PlatformView, "deliverMouseEvent", "(Lsun/lwawt/macosx/NSEvent;)V");418419jobject jlocal = (*env)->NewLocalRef(env, m_cPlatformView);420if (!(*env)->IsSameObject(env, jlocal, NULL)) {421JNFCallVoidMethod(env, jlocal, jm_deliverMouseEvent, jEvent);422(*env)->DeleteLocalRef(env, jlocal);423}424}425426- (void) resetTrackingArea {427if (rolloverTrackingArea != nil) {428[self removeTrackingArea:rolloverTrackingArea];429[rolloverTrackingArea release];430}431432int options = (NSTrackingActiveAlways | NSTrackingMouseEnteredAndExited |433NSTrackingMouseMoved | NSTrackingEnabledDuringMouseDrag);434435rolloverTrackingArea = [[NSTrackingArea alloc] initWithRect:[self visibleRect]436options: options437owner:self438userInfo:nil439];440[self addTrackingArea:rolloverTrackingArea];441}442443- (void)updateTrackingAreas {444[super updateTrackingAreas];445[self resetTrackingArea];446}447448- (void) resetCursorRects {449[super resetCursorRects];450[self resetTrackingArea];451}452453-(void) deliverJavaKeyEventHelper: (NSEvent *) event {454static NSEvent* sLastKeyEvent = nil;455if (event == sLastKeyEvent) {456// The event is repeatedly delivered by keyDown: after performKeyEquivalent:457return;458}459[sLastKeyEvent release];460sLastKeyEvent = [event retain];461462[AWTToolkit eventCountPlusPlus];463JNIEnv *env = [ThreadUtilities getJNIEnv];464465jstring characters = NULL;466jstring charactersIgnoringModifiers = NULL;467if ([event type] != NSFlagsChanged) {468characters = JNFNSToJavaString(env, [event characters]);469charactersIgnoringModifiers = JNFNSToJavaString(env, [event charactersIgnoringModifiers]);470}471472static JNF_CLASS_CACHE(jc_NSEvent, "sun/lwawt/macosx/NSEvent");473static JNF_CTOR_CACHE(jctor_NSEvent, jc_NSEvent, "(IISLjava/lang/String;Ljava/lang/String;)V");474jobject jevent = JNFNewObject(env, jctor_NSEvent,475[event type],476[event modifierFlags],477[event keyCode],478characters,479charactersIgnoringModifiers);480481static JNF_CLASS_CACHE(jc_PlatformView, "sun/lwawt/macosx/CPlatformView");482static JNF_MEMBER_CACHE(jm_deliverKeyEvent, jc_PlatformView,483"deliverKeyEvent", "(Lsun/lwawt/macosx/NSEvent;)V");484485jobject jlocal = (*env)->NewLocalRef(env, m_cPlatformView);486if (!(*env)->IsSameObject(env, jlocal, NULL)) {487JNFCallVoidMethod(env, jlocal, jm_deliverKeyEvent, jevent);488(*env)->DeleteLocalRef(env, jlocal);489}490491if (characters != NULL) {492(*env)->DeleteLocalRef(env, characters);493}494}495496-(void) deliverResize: (NSRect) rect {497jint x = (jint) rect.origin.x;498jint y = (jint) rect.origin.y;499jint w = (jint) rect.size.width;500jint h = (jint) rect.size.height;501JNIEnv *env = [ThreadUtilities getJNIEnv];502static JNF_CLASS_CACHE(jc_PlatformView, "sun/lwawt/macosx/CPlatformView");503static JNF_MEMBER_CACHE(jm_deliverResize, jc_PlatformView, "deliverResize", "(IIII)V");504505jobject jlocal = (*env)->NewLocalRef(env, m_cPlatformView);506if (!(*env)->IsSameObject(env, jlocal, NULL)) {507JNFCallVoidMethod(env, jlocal, jm_deliverResize, x,y,w,h);508(*env)->DeleteLocalRef(env, jlocal);509}510}511512513- (void) drawRect:(NSRect)dirtyRect {514AWT_ASSERT_APPKIT_THREAD;515516[super drawRect:dirtyRect];517JNIEnv *env = [ThreadUtilities getJNIEnv];518if (env != NULL) {519/*520if ([self inLiveResize]) {521NSRect rs[4];522NSInteger count;523[self getRectsExposedDuringLiveResize:rs count:&count];524for (int i = 0; i < count; i++) {525JNU_CallMethodByName(env, NULL, [m_awtWindow cPlatformView],526"deliverWindowDidExposeEvent", "(FFFF)V",527(jfloat)rs[i].origin.x, (jfloat)rs[i].origin.y,528(jfloat)rs[i].size.width, (jfloat)rs[i].size.height);529if ((*env)->ExceptionOccurred(env)) {530(*env)->ExceptionDescribe(env);531(*env)->ExceptionClear(env);532}533}534} else {535*/536static JNF_CLASS_CACHE(jc_CPlatformView, "sun/lwawt/macosx/CPlatformView");537static JNF_MEMBER_CACHE(jm_deliverWindowDidExposeEvent, jc_CPlatformView, "deliverWindowDidExposeEvent", "()V");538539jobject jlocal = (*env)->NewLocalRef(env, m_cPlatformView);540if (!(*env)->IsSameObject(env, jlocal, NULL)) {541JNFCallVoidMethod(env, jlocal, jm_deliverWindowDidExposeEvent);542(*env)->DeleteLocalRef(env, jlocal);543}544/*545}546*/547}548}549550-(BOOL) isCodePointInUnicodeBlockNeedingIMEvent: (unichar) codePoint {551if ((codePoint == 0x0024) || (codePoint == 0x00A3) ||552(codePoint == 0x00A5) ||553((codePoint >= 0x20A3) && (codePoint <= 0x20BF)) ||554((codePoint >= 0x3000) && (codePoint <= 0x303F)) ||555((codePoint >= 0xFF00) && (codePoint <= 0xFFEF))) {556// Code point is in 'CJK Symbols and Punctuation' or557// 'Halfwidth and Fullwidth Forms' Unicode block or558// currency symbols unicode559return YES;560}561return NO;562}563564// NSAccessibility support565- (jobject)awtComponent:(JNIEnv*)env566{567static JNF_CLASS_CACHE(jc_CPlatformView, "sun/lwawt/macosx/CPlatformView");568static JNF_MEMBER_CACHE(jf_Peer, jc_CPlatformView, "peer", "Lsun/lwawt/LWWindowPeer;");569if ((env == NULL) || (m_cPlatformView == NULL)) {570NSLog(@"Apple AWT : Error AWTView:awtComponent given bad parameters.");571if (env != NULL)572{573JNFDumpJavaStack(env);574}575return NULL;576}577578jobject peer = NULL;579jobject jlocal = (*env)->NewLocalRef(env, m_cPlatformView);580if (!(*env)->IsSameObject(env, jlocal, NULL)) {581peer = JNFGetObjectField(env, jlocal, jf_Peer);582(*env)->DeleteLocalRef(env, jlocal);583}584static JNF_CLASS_CACHE(jc_LWWindowPeer, "sun/lwawt/LWWindowPeer");585static JNF_MEMBER_CACHE(jf_Target, jc_LWWindowPeer, "target", "Ljava/awt/Component;");586if (peer == NULL) {587NSLog(@"Apple AWT : Error AWTView:awtComponent got null peer from CPlatformView");588JNFDumpJavaStack(env);589return NULL;590}591jobject comp = JNFGetObjectField(env, peer, jf_Target);592(*env)->DeleteLocalRef(env, peer);593return comp;594}595596+ (AWTView *) awtView:(JNIEnv*)env ofAccessible:(jobject)jaccessible597{598static JNF_STATIC_MEMBER_CACHE(jm_getAWTView, sjc_CAccessibility, "getAWTView", "(Ljavax/accessibility/Accessible;)J");599600jlong jptr = JNFCallStaticLongMethod(env, jm_getAWTView, jaccessible);601if (jptr == 0) return nil;602603return (AWTView *)jlong_to_ptr(jptr);604}605606- (id)getAxData:(JNIEnv*)env607{608jobject jcomponent = [self awtComponent:env];609id ax = [[[JavaComponentAccessibility alloc] initWithParent:self withEnv:env withAccessible:jcomponent withIndex:-1 withView:self withJavaRole:nil] autorelease];610(*env)->DeleteLocalRef(env, jcomponent);611return ax;612}613614- (NSArray *)accessibilityAttributeNames615{616return [[super accessibilityAttributeNames] arrayByAddingObject:NSAccessibilityChildrenAttribute];617}618619// NSAccessibility messages620// attribute methods621- (id)accessibilityAttributeValue:(NSString *)attribute622{623AWT_ASSERT_APPKIT_THREAD;624625if ([attribute isEqualToString:NSAccessibilityChildrenAttribute])626{627JNIEnv *env = [ThreadUtilities getJNIEnv];628629(*env)->PushLocalFrame(env, 4);630631id result = NSAccessibilityUnignoredChildrenForOnlyChild([self getAxData:env]);632633(*env)->PopLocalFrame(env, NULL);634635return result;636}637else638{639return [super accessibilityAttributeValue:attribute];640}641}642- (BOOL)accessibilityIsIgnored643{644return YES;645}646647- (id)accessibilityHitTest:(NSPoint)point648{649AWT_ASSERT_APPKIT_THREAD;650JNIEnv *env = [ThreadUtilities getJNIEnv];651652(*env)->PushLocalFrame(env, 4);653654id result = [[self getAxData:env] accessibilityHitTest:point withEnv:env];655656(*env)->PopLocalFrame(env, NULL);657658return result;659}660661- (id)accessibilityFocusedUIElement662{663AWT_ASSERT_APPKIT_THREAD;664665JNIEnv *env = [ThreadUtilities getJNIEnv];666667(*env)->PushLocalFrame(env, 4);668669id result = [[self getAxData:env] accessibilityFocusedUIElement];670671(*env)->PopLocalFrame(env, NULL);672673return result;674}675676// --- Services menu support for lightweights ---677678// finds the focused accessible element, and if it is a text element, obtains the text from it679- (NSString *)accessibleSelectedText680{681id focused = [self accessibilityFocusedUIElement];682if (![focused isKindOfClass:[JavaTextAccessibility class]]) return nil;683return [(JavaTextAccessibility *)focused accessibilitySelectedTextAttribute];684}685686// same as above, but converts to RTFD687- (NSData *)accessibleSelectedTextAsRTFD688{689NSString *selectedText = [self accessibleSelectedText];690NSAttributedString *styledText = [[NSAttributedString alloc] initWithString:selectedText];691NSData *rtfdData = [styledText RTFDFromRange:NSMakeRange(0, [styledText length]) documentAttributes:nil];692[styledText release];693return rtfdData;694}695696// finds the focused accessible element, and if it is a text element, sets the text in it697- (BOOL)replaceAccessibleTextSelection:(NSString *)text698{699id focused = [self accessibilityFocusedUIElement];700if (![focused isKindOfClass:[JavaTextAccessibility class]]) return NO;701[(JavaTextAccessibility *)focused accessibilitySetSelectedTextAttribute:text];702return YES;703}704705// called for each service in the Services menu - only handle text for now706- (id)validRequestorForSendType:(NSString *)sendType returnType:(NSString *)returnType707{708if ([[self window] firstResponder] != self) return nil; // let AWT components handle themselves709710if ([sendType isEqual:NSStringPboardType] || [returnType isEqual:NSStringPboardType]) {711NSString *selectedText = [self accessibleSelectedText];712if (selectedText) return self;713}714715return nil;716}717718// fetch text from Java and hand off to the service719- (BOOL)writeSelectionToPasteboard:(NSPasteboard *)pboard types:(NSArray *)types720{721if ([types containsObject:NSStringPboardType])722{723[pboard declareTypes:[NSArray arrayWithObject:NSStringPboardType] owner:nil];724return [pboard setString:[self accessibleSelectedText] forType:NSStringPboardType];725}726727if ([types containsObject:NSRTFDPboardType])728{729[pboard declareTypes:[NSArray arrayWithObject:NSRTFDPboardType] owner:nil];730return [pboard setData:[self accessibleSelectedTextAsRTFD] forType:NSRTFDPboardType];731}732733return NO;734}735736// write text back to Java from the service737- (BOOL)readSelectionFromPasteboard:(NSPasteboard *)pboard738{739if ([[pboard types] containsObject:NSStringPboardType])740{741NSString *text = [pboard stringForType:NSStringPboardType];742return [self replaceAccessibleTextSelection:text];743}744745if ([[pboard types] containsObject:NSRTFDPboardType])746{747NSData *rtfdData = [pboard dataForType:NSRTFDPboardType];748NSAttributedString *styledText = [[NSAttributedString alloc] initWithRTFD:rtfdData documentAttributes:nil];749NSString *text = [styledText string];750[styledText release];751752return [self replaceAccessibleTextSelection:text];753}754755return NO;756}757758759-(void) setDragSource:(CDragSource *)source {760self._dragSource = source;761}762763764- (void) setDropTarget:(CDropTarget *)target {765self._dropTarget = target;766[ThreadUtilities performOnMainThread:@selector(controlModelControlValid) on:self._dropTarget withObject:nil waitUntilDone:YES];767}768769/******************************** BEGIN NSDraggingSource Interface ********************************/770771- (NSDragOperation)draggingSourceOperationMaskForLocal:(BOOL)flag772{773// If draggingSource is nil route the message to the superclass (if responding to the selector):774CDragSource *dragSource = self._dragSource;775NSDragOperation dragOp = NSDragOperationNone;776777if (dragSource != nil)778dragOp = [dragSource draggingSourceOperationMaskForLocal:flag];779else if ([super respondsToSelector:@selector(draggingSourceOperationMaskForLocal:)])780dragOp = [super draggingSourceOperationMaskForLocal:flag];781782return dragOp;783}784785- (NSArray *)namesOfPromisedFilesDroppedAtDestination:(NSURL *)dropDestination786{787// If draggingSource is nil route the message to the superclass (if responding to the selector):788CDragSource *dragSource = self._dragSource;789NSArray* array = nil;790791if (dragSource != nil)792array = [dragSource namesOfPromisedFilesDroppedAtDestination:dropDestination];793else if ([super respondsToSelector:@selector(namesOfPromisedFilesDroppedAtDestination:)])794array = [super namesOfPromisedFilesDroppedAtDestination:dropDestination];795796return array;797}798799- (void)draggedImage:(NSImage *)image beganAt:(NSPoint)screenPoint800{801// If draggingSource is nil route the message to the superclass (if responding to the selector):802CDragSource *dragSource = self._dragSource;803804if (dragSource != nil)805[dragSource draggedImage:image beganAt:screenPoint];806else if ([super respondsToSelector:@selector(draggedImage::)])807[super draggedImage:image beganAt:screenPoint];808}809810- (void)draggedImage:(NSImage *)image endedAt:(NSPoint)screenPoint operation:(NSDragOperation)operation811{812// If draggingSource is nil route the message to the superclass (if responding to the selector):813CDragSource *dragSource = self._dragSource;814815if (dragSource != nil)816[dragSource draggedImage:image endedAt:screenPoint operation:operation];817else if ([super respondsToSelector:@selector(draggedImage:::)])818[super draggedImage:image endedAt:screenPoint operation:operation];819}820821- (void)draggedImage:(NSImage *)image movedTo:(NSPoint)screenPoint822{823// If draggingSource is nil route the message to the superclass (if responding to the selector):824CDragSource *dragSource = self._dragSource;825826if (dragSource != nil)827[dragSource draggedImage:image movedTo:screenPoint];828else if ([super respondsToSelector:@selector(draggedImage::)])829[super draggedImage:image movedTo:screenPoint];830}831832- (BOOL)ignoreModifierKeysWhileDragging833{834// If draggingSource is nil route the message to the superclass (if responding to the selector):835CDragSource *dragSource = self._dragSource;836BOOL result = FALSE;837838if (dragSource != nil)839result = [dragSource ignoreModifierKeysWhileDragging];840else if ([super respondsToSelector:@selector(ignoreModifierKeysWhileDragging)])841result = [super ignoreModifierKeysWhileDragging];842843return result;844}845846/******************************** END NSDraggingSource Interface ********************************/847848/******************************** BEGIN NSDraggingDestination Interface ********************************/849850- (NSDragOperation)draggingEntered:(id <NSDraggingInfo>)sender851{852// If draggingDestination is nil route the message to the superclass:853CDropTarget *dropTarget = self._dropTarget;854NSDragOperation dragOp = NSDragOperationNone;855856if (dropTarget != nil)857dragOp = [dropTarget draggingEntered:sender];858else if ([super respondsToSelector:@selector(draggingEntered:)])859dragOp = [super draggingEntered:sender];860861return dragOp;862}863864- (NSDragOperation)draggingUpdated:(id <NSDraggingInfo>)sender865{866// If draggingDestination is nil route the message to the superclass:867CDropTarget *dropTarget = self._dropTarget;868NSDragOperation dragOp = NSDragOperationNone;869870if (dropTarget != nil)871dragOp = [dropTarget draggingUpdated:sender];872else if ([super respondsToSelector:@selector(draggingUpdated:)])873dragOp = [super draggingUpdated:sender];874875return dragOp;876}877878- (void)draggingExited:(id <NSDraggingInfo>)sender879{880// If draggingDestination is nil route the message to the superclass:881CDropTarget *dropTarget = self._dropTarget;882883if (dropTarget != nil)884[dropTarget draggingExited:sender];885else if ([super respondsToSelector:@selector(draggingExited:)])886[super draggingExited:sender];887}888889- (BOOL)prepareForDragOperation:(id <NSDraggingInfo>)sender890{891// If draggingDestination is nil route the message to the superclass:892CDropTarget *dropTarget = self._dropTarget;893BOOL result = FALSE;894895if (dropTarget != nil)896result = [dropTarget prepareForDragOperation:sender];897else if ([super respondsToSelector:@selector(prepareForDragOperation:)])898result = [super prepareForDragOperation:sender];899900return result;901}902903- (BOOL)performDragOperation:(id <NSDraggingInfo>)sender904{905// If draggingDestination is nil route the message to the superclass:906CDropTarget *dropTarget = self._dropTarget;907BOOL result = FALSE;908909if (dropTarget != nil)910result = [dropTarget performDragOperation:sender];911else if ([super respondsToSelector:@selector(performDragOperation:)])912result = [super performDragOperation:sender];913914return result;915}916917- (void)concludeDragOperation:(id <NSDraggingInfo>)sender918{919// If draggingDestination is nil route the message to the superclass:920CDropTarget *dropTarget = self._dropTarget;921922if (dropTarget != nil)923[dropTarget concludeDragOperation:sender];924else if ([super respondsToSelector:@selector(concludeDragOperation:)])925[super concludeDragOperation:sender];926}927928- (void)draggingEnded:(id <NSDraggingInfo>)sender929{930// If draggingDestination is nil route the message to the superclass:931CDropTarget *dropTarget = self._dropTarget;932933if (dropTarget != nil)934[dropTarget draggingEnded:sender];935else if ([super respondsToSelector:@selector(draggingEnded:)])936[super draggingEnded:sender];937}938939/******************************** END NSDraggingDestination Interface ********************************/940941/******************************** BEGIN NSTextInputClient Protocol ********************************/942943944JNF_CLASS_CACHE(jc_CInputMethod, "sun/lwawt/macosx/CInputMethod");945946- (void) insertText:(id)aString replacementRange:(NSRange)replacementRange947{948#ifdef IM_DEBUG949fprintf(stderr, "AWTView InputMethod Selector Called : [insertText]: %s\n", [aString UTF8String]);950#endif // IM_DEBUG951952if (fInputMethodLOCKABLE == NULL) {953return;954}955956// Insert happens at the end of PAH957fInPressAndHold = NO;958959// insertText gets called when the user commits text generated from an input method. It also gets960// called during ordinary input as well. We only need to send an input method event when we have marked961// text, or 'text in progress'. We also need to send the event if we get an insert text out of the blue!962// (i.e., when the user uses the Character palette or Inkwell), or when the string to insert is a complex963// Unicode value.964NSUInteger utf16Length = [aString lengthOfBytesUsingEncoding:NSUTF16StringEncoding];965NSUInteger utf8Length = [aString lengthOfBytesUsingEncoding:NSUTF8StringEncoding];966BOOL aStringIsComplex = NO;967if ((utf16Length > 2) ||968((utf8Length > 1) && [self isCodePointInUnicodeBlockNeedingIMEvent:[aString characterAtIndex:0]])) {969aStringIsComplex = YES;970}971972if ([self hasMarkedText] || !fProcessingKeystroke || aStringIsComplex) {973JNIEnv *env = [ThreadUtilities getJNIEnv];974975static JNF_MEMBER_CACHE(jm_selectPreviousGlyph, jc_CInputMethod, "selectPreviousGlyph", "()V");976// We need to select the previous glyph so that it is overwritten.977if (fPAHNeedsToSelect) {978JNFCallVoidMethod(env, fInputMethodLOCKABLE, jm_selectPreviousGlyph);979fPAHNeedsToSelect = NO;980}981982static JNF_MEMBER_CACHE(jm_insertText, jc_CInputMethod, "insertText", "(Ljava/lang/String;)V");983jstring insertedText = JNFNSToJavaString(env, aString);984JNFCallVoidMethod(env, fInputMethodLOCKABLE, jm_insertText, insertedText); // AWT_THREADING Safe (AWTRunLoopMode)985(*env)->DeleteLocalRef(env, insertedText);986987// The input method event will create psuedo-key events for each character in the committed string.988// We also don't want to send the character that triggered the insertText, usually a return. [3337563]989fKeyEventsNeeded = NO;990}991else {992// Need to set back the fKeyEventsNeeded flag so that the string following the993// marked text is not ignored by keyDown994if (utf16Length > 0 || utf8Length > 0) {995fKeyEventsNeeded = YES;996}997}998999fPAHNeedsToSelect = NO;10001001}10021003- (void) doCommandBySelector:(SEL)aSelector1004{1005#ifdef IM_DEBUG1006fprintf(stderr, "AWTView InputMethod Selector Called : [doCommandBySelector]\n");1007NSLog(@"%@", NSStringFromSelector(aSelector));1008#endif // IM_DEBUG1009if (@selector(insertNewline:) == aSelector || @selector(insertTab:) == aSelector || @selector(deleteBackward:) == aSelector)1010{1011fKeyEventsNeeded = YES;1012}1013}10141015// setMarkedText: cannot take a nil first argument. aString can be NSString or NSAttributedString1016- (void) setMarkedText:(id)aString selectedRange:(NSRange)selectionRange replacementRange:(NSRange)replacementRange1017{1018if (!fInputMethodLOCKABLE)1019return;10201021BOOL isAttributedString = [aString isKindOfClass:[NSAttributedString class]];1022NSAttributedString *attrString = (isAttributedString ? (NSAttributedString *)aString : nil);1023NSString *incomingString = (isAttributedString ? [aString string] : aString);1024#ifdef IM_DEBUG1025fprintf(stderr, "AWTView InputMethod Selector Called : [setMarkedText] \"%s\", loc=%lu, length=%lu\n", [incomingString UTF8String], (unsigned long)selectionRange.location, (unsigned long)selectionRange.length);1026#endif // IM_DEBUG1027static JNF_MEMBER_CACHE(jm_startIMUpdate, jc_CInputMethod, "startIMUpdate", "(Ljava/lang/String;)V");1028static JNF_MEMBER_CACHE(jm_addAttribute, jc_CInputMethod, "addAttribute", "(ZZII)V");1029static JNF_MEMBER_CACHE(jm_dispatchText, jc_CInputMethod, "dispatchText", "(IIZ)V");1030JNIEnv *env = [ThreadUtilities getJNIEnv];10311032// NSInputContext already did the analysis of the TSM event and created attributes indicating1033// the underlining and color that should be done to the string. We need to look at the underline1034// style and color to determine what kind of Java hilighting needs to be done.1035jstring inProcessText = JNFNSToJavaString(env, incomingString);1036JNFCallVoidMethod(env, fInputMethodLOCKABLE, jm_startIMUpdate, inProcessText); // AWT_THREADING Safe (AWTRunLoopMode)1037(*env)->DeleteLocalRef(env, inProcessText);10381039if (isAttributedString) {1040NSUInteger length;1041NSRange effectiveRange;1042NSDictionary *attributes;1043length = [attrString length];1044effectiveRange = NSMakeRange(0, 0);1045while (NSMaxRange(effectiveRange) < length) {1046attributes = [attrString attributesAtIndex:NSMaxRange(effectiveRange)1047effectiveRange:&effectiveRange];1048if (attributes) {1049BOOL isThickUnderline, isGray;1050NSNumber *underlineSizeObj =1051(NSNumber *)[attributes objectForKey:NSUnderlineStyleAttributeName];1052NSInteger underlineSize = [underlineSizeObj integerValue];1053isThickUnderline = (underlineSize > 1);10541055NSColor *underlineColorObj =1056(NSColor *)[attributes objectForKey:NSUnderlineColorAttributeName];1057isGray = !([underlineColorObj isEqual:[NSColor blackColor]]);10581059JNFCallVoidMethod(env, fInputMethodLOCKABLE, jm_addAttribute, isThickUnderline, isGray, effectiveRange.location, effectiveRange.length); // AWT_THREADING Safe (AWTRunLoopMode)1060}1061}1062}10631064static JNF_MEMBER_CACHE(jm_selectPreviousGlyph, jc_CInputMethod, "selectPreviousGlyph", "()V");1065// We need to select the previous glyph so that it is overwritten.1066if (fPAHNeedsToSelect) {1067JNFCallVoidMethod(env, fInputMethodLOCKABLE, jm_selectPreviousGlyph);1068fPAHNeedsToSelect = NO;1069}10701071JNFCallVoidMethod(env, fInputMethodLOCKABLE, jm_dispatchText, selectionRange.location, selectionRange.length, JNI_FALSE); // AWT_THREADING Safe (AWTRunLoopMode)10721073// If the marked text is being cleared (zero-length string) don't handle the key event.1074if ([incomingString length] == 0) {1075fKeyEventsNeeded = NO;1076}1077}10781079- (void) unmarkText1080{1081#ifdef IM_DEBUG1082fprintf(stderr, "AWTView InputMethod Selector Called : [unmarkText]\n");1083#endif // IM_DEBUG10841085if (!fInputMethodLOCKABLE) {1086return;1087}10881089// unmarkText cancels any input in progress and commits it to the text field.1090static JNF_MEMBER_CACHE(jm_unmarkText, jc_CInputMethod, "unmarkText", "()V");1091JNIEnv *env = [ThreadUtilities getJNIEnv];1092JNFCallVoidMethod(env, fInputMethodLOCKABLE, jm_unmarkText); // AWT_THREADING Safe (AWTRunLoopMode)10931094}10951096- (BOOL) hasMarkedText1097{1098#ifdef IM_DEBUG1099fprintf(stderr, "AWTView InputMethod Selector Called : [hasMarkedText]\n");1100#endif // IM_DEBUG11011102if (!fInputMethodLOCKABLE) {1103return NO;1104}11051106static JNF_MEMBER_CACHE(jf_fCurrentText, jc_CInputMethod, "fCurrentText", "Ljava/text/AttributedString;");1107static JNF_MEMBER_CACHE(jf_fCurrentTextLength, jc_CInputMethod, "fCurrentTextLength", "I");1108JNIEnv *env = [ThreadUtilities getJNIEnv];1109jobject currentText = JNFGetObjectField(env, fInputMethodLOCKABLE, jf_fCurrentText);11101111jint currentTextLength = JNFGetIntField(env, fInputMethodLOCKABLE, jf_fCurrentTextLength);11121113BOOL hasMarkedText = (currentText != NULL && currentTextLength > 0);11141115if (currentText != NULL) {1116(*env)->DeleteLocalRef(env, currentText);1117}11181119return hasMarkedText;1120}11211122- (NSInteger) conversationIdentifier1123{1124#ifdef IM_DEBUG1125fprintf(stderr, "AWTView InputMethod Selector Called : [conversationIdentifier]\n");1126#endif // IM_DEBUG11271128return (NSInteger) self;1129}11301131/* Returns attributed string at the range. This allows input mangers to1132query any range in backing-store (Andy's request)1133*/1134- (NSAttributedString *) attributedSubstringForProposedRange:(NSRange)theRange actualRange:(NSRangePointer)actualRange1135{1136#ifdef IM_DEBUG1137fprintf(stderr, "AWTView InputMethod Selector Called : [attributedSubstringFromRange] location=%lu, length=%lu\n", (unsigned long)theRange.location, (unsigned long)theRange.length);1138#endif // IM_DEBUG11391140static JNF_MEMBER_CACHE(jm_substringFromRange, jc_CInputMethod, "attributedSubstringFromRange", "(II)Ljava/lang/String;");1141JNIEnv *env = [ThreadUtilities getJNIEnv];1142jobject theString = JNFCallObjectMethod(env, fInputMethodLOCKABLE, jm_substringFromRange, theRange.location, theRange.length); // AWT_THREADING Safe (AWTRunLoopMode)11431144id result = [[[NSAttributedString alloc] initWithString:JNFJavaToNSString(env, theString)] autorelease];1145#ifdef IM_DEBUG1146NSLog(@"attributedSubstringFromRange returning \"%@\"", result);1147#endif // IM_DEBUG11481149(*env)->DeleteLocalRef(env, theString);1150return result;1151}11521153/* This method returns the range for marked region. If hasMarkedText == false,1154it'll return NSNotFound location & 0 length range.1155*/1156- (NSRange) markedRange1157{11581159#ifdef IM_DEBUG1160fprintf(stderr, "AWTView InputMethod Selector Called : [markedRange]\n");1161#endif // IM_DEBUG11621163if (!fInputMethodLOCKABLE) {1164return NSMakeRange(NSNotFound, 0);1165}11661167static JNF_MEMBER_CACHE(jm_markedRange, jc_CInputMethod, "markedRange", "()[I");1168JNIEnv *env = [ThreadUtilities getJNIEnv];1169jarray array;1170jboolean isCopy;1171jint *_array;1172NSRange range = NSMakeRange(NSNotFound, 0);11731174array = JNFCallObjectMethod(env, fInputMethodLOCKABLE, jm_markedRange); // AWT_THREADING Safe (AWTRunLoopMode)11751176if (array) {1177_array = (*env)->GetIntArrayElements(env, array, &isCopy);1178if (_array != NULL) {1179range.location = _array[0];1180range.length = _array[1];1181#ifdef IM_DEBUG1182fprintf(stderr, "markedRange returning (%lu, %lu)\n",1183(unsigned long)range.location, (unsigned long)range.length);1184#endif // IM_DEBUG1185(*env)->ReleaseIntArrayElements(env, array, _array, 0);1186}1187(*env)->DeleteLocalRef(env, array);1188}11891190return range;1191}11921193/* This method returns the range for selected region. Just like markedRange method,1194its location field contains char index from the text beginning.1195*/1196- (NSRange) selectedRange1197{1198if (!fInputMethodLOCKABLE) {1199return NSMakeRange(NSNotFound, 0);1200}12011202static JNF_MEMBER_CACHE(jm_selectedRange, jc_CInputMethod, "selectedRange", "()[I");1203JNIEnv *env = [ThreadUtilities getJNIEnv];1204jarray array;1205jboolean isCopy;1206jint *_array;1207NSRange range = NSMakeRange(NSNotFound, 0);12081209#ifdef IM_DEBUG1210fprintf(stderr, "AWTView InputMethod Selector Called : [selectedRange]\n");1211#endif // IM_DEBUG12121213array = JNFCallObjectMethod(env, fInputMethodLOCKABLE, jm_selectedRange); // AWT_THREADING Safe (AWTRunLoopMode)1214if (array) {1215_array = (*env)->GetIntArrayElements(env, array, &isCopy);1216if (_array != NULL) {1217range.location = _array[0];1218range.length = _array[1];1219(*env)->ReleaseIntArrayElements(env, array, _array, 0);1220}1221(*env)->DeleteLocalRef(env, array);1222}12231224return range;1225}12261227/* This method returns the first frame of rects for theRange in screen coordindate system.1228*/1229- (NSRect) firstRectForCharacterRange:(NSRange)theRange actualRange:(NSRangePointer)actualRange1230{1231if (!fInputMethodLOCKABLE) {1232return NSZeroRect;1233}12341235static JNF_MEMBER_CACHE(jm_firstRectForCharacterRange, jc_CInputMethod,1236"firstRectForCharacterRange", "(I)[I");1237JNIEnv *env = [ThreadUtilities getJNIEnv];1238jarray array;1239jboolean isCopy;1240jint *_array;1241NSRect rect;12421243#ifdef IM_DEBUG1244fprintf(stderr,1245"AWTView InputMethod Selector Called : [firstRectForCharacterRange:] location=%lu, length=%lu\n",1246(unsigned long)theRange.location, (unsigned long)theRange.length);1247#endif // IM_DEBUG12481249array = JNFCallObjectMethod(env, fInputMethodLOCKABLE, jm_firstRectForCharacterRange,1250theRange.location); // AWT_THREADING Safe (AWTRunLoopMode)12511252_array = (*env)->GetIntArrayElements(env, array, &isCopy);1253if (_array) {1254rect = ConvertNSScreenRect(env, NSMakeRect(_array[0], _array[1], _array[2], _array[3]));1255(*env)->ReleaseIntArrayElements(env, array, _array, 0);1256} else {1257rect = NSZeroRect;1258}1259(*env)->DeleteLocalRef(env, array);12601261#ifdef IM_DEBUG1262fprintf(stderr,1263"firstRectForCharacterRange returning x=%f, y=%f, width=%f, height=%f\n",1264rect.origin.x, rect.origin.y, rect.size.width, rect.size.height);1265#endif // IM_DEBUG1266return rect;1267}12681269/* This method returns the index for character that is nearest to thePoint. thPoint is in1270screen coordinate system.1271*/1272- (NSUInteger)characterIndexForPoint:(NSPoint)thePoint1273{1274if (!fInputMethodLOCKABLE) {1275return NSNotFound;1276}12771278static JNF_MEMBER_CACHE(jm_characterIndexForPoint, jc_CInputMethod,1279"characterIndexForPoint", "(II)I");1280JNIEnv *env = [ThreadUtilities getJNIEnv];12811282NSPoint flippedLocation = ConvertNSScreenPoint(env, thePoint);12831284#ifdef IM_DEBUG1285fprintf(stderr, "AWTView InputMethod Selector Called : [characterIndexForPoint:(NSPoint)thePoint] x=%f, y=%f\n", flippedLocation.x, flippedLocation.y);1286#endif // IM_DEBUG12871288jint index = JNFCallIntMethod(env, fInputMethodLOCKABLE, jm_characterIndexForPoint, (jint)flippedLocation.x, (jint)flippedLocation.y); // AWT_THREADING Safe (AWTRunLoopMode)12891290#ifdef IM_DEBUG1291fprintf(stderr, "characterIndexForPoint returning %ld\n", index);1292#endif // IM_DEBUG12931294if (index == -1) {1295return NSNotFound;1296} else {1297return (NSUInteger)index;1298}1299}13001301- (NSArray*) validAttributesForMarkedText1302{1303#ifdef IM_DEBUG1304fprintf(stderr, "AWTView InputMethod Selector Called : [validAttributesForMarkedText]\n");1305#endif // IM_DEBUG13061307return [NSArray array];1308}13091310- (void)setInputMethod:(jobject)inputMethod1311{1312#ifdef IM_DEBUG1313fprintf(stderr, "AWTView InputMethod Selector Called : [setInputMethod]\n");1314#endif // IM_DEBUG13151316JNIEnv *env = [ThreadUtilities getJNIEnv];13171318// Get rid of the old one1319if (fInputMethodLOCKABLE) {1320JNFDeleteGlobalRef(env, fInputMethodLOCKABLE);1321}13221323// Save a global ref to the new input method.1324if (inputMethod != NULL)1325fInputMethodLOCKABLE = JNFNewGlobalRef(env, inputMethod);1326else1327fInputMethodLOCKABLE = NULL;1328}13291330- (void)abandonInput1331{1332#ifdef IM_DEBUG1333fprintf(stderr, "AWTView InputMethod Selector Called : [abandonInput]\n");1334#endif // IM_DEBUG13351336[ThreadUtilities performOnMainThread:@selector(markedTextAbandoned:) on:[NSInputManager currentInputManager] withObject:self waitUntilDone:YES];1337[self unmarkText];1338}13391340/******************************** END NSTextInputClient Protocol ********************************/13411342134313441345@end // AWTView13461347/*1348* Class: sun_lwawt_macosx_CPlatformView1349* Method: nativeCreateView1350* Signature: (IIII)J1351*/1352JNIEXPORT jlong JNICALL1353Java_sun_lwawt_macosx_CPlatformView_nativeCreateView1354(JNIEnv *env, jobject obj, jint originX, jint originY, jint width, jint height, jlong windowLayerPtr)1355{1356__block AWTView *newView = nil;13571358JNF_COCOA_ENTER(env);13591360NSRect rect = NSMakeRect(originX, originY, width, height);1361jobject cPlatformView = (*env)->NewWeakGlobalRef(env, obj);13621363[ThreadUtilities performOnMainThreadWaiting:YES block:^(){13641365CALayer *windowLayer = jlong_to_ptr(windowLayerPtr);1366newView = [[AWTView alloc] initWithRect:rect1367platformView:cPlatformView1368windowLayer:windowLayer];1369}];13701371JNF_COCOA_EXIT(env);13721373return ptr_to_jlong(newView);1374}13751376/*1377* Class: sun_lwawt_macosx_CPlatformView1378* Method: nativeSetAutoResizable1379* Signature: (JZ)V;1380*/13811382JNIEXPORT void JNICALL1383Java_sun_lwawt_macosx_CPlatformView_nativeSetAutoResizable1384(JNIEnv *env, jclass cls, jlong viewPtr, jboolean toResize)1385{1386JNF_COCOA_ENTER(env);13871388NSView *view = (NSView *)jlong_to_ptr(viewPtr);13891390[ThreadUtilities performOnMainThreadWaiting:NO block:^(){13911392if (toResize) {1393[view setAutoresizingMask: NSViewHeightSizable | NSViewWidthSizable];1394} else {1395[view setAutoresizingMask: NSViewMinYMargin | NSViewMaxXMargin];1396}13971398if ([view superview] != nil) {1399[[view superview] setAutoresizesSubviews:(BOOL)toResize];1400}14011402}];1403JNF_COCOA_EXIT(env);1404}14051406/*1407* Class: sun_lwawt_macosx_CPlatformView1408* Method: nativeGetNSViewDisplayID1409* Signature: (J)I;1410*/14111412JNIEXPORT jint JNICALL1413Java_sun_lwawt_macosx_CPlatformView_nativeGetNSViewDisplayID1414(JNIEnv *env, jclass cls, jlong viewPtr)1415{1416__block jint ret; //CGDirectDisplayID14171418JNF_COCOA_ENTER(env);14191420NSView *view = (NSView *)jlong_to_ptr(viewPtr);1421NSWindow *window = [view window];14221423[ThreadUtilities performOnMainThreadWaiting:YES block:^(){14241425ret = (jint)[[AWTWindow getNSWindowDisplayID_AppKitThread: window] intValue];1426}];14271428JNF_COCOA_EXIT(env);14291430return ret;1431}14321433/*1434* Class: sun_lwawt_macosx_CPlatformView1435* Method: nativeGetLocationOnScreen1436* Signature: (J)Ljava/awt/Rectangle;1437*/14381439JNIEXPORT jobject JNICALL1440Java_sun_lwawt_macosx_CPlatformView_nativeGetLocationOnScreen1441(JNIEnv *env, jclass cls, jlong viewPtr)1442{1443jobject jRect = NULL;14441445JNF_COCOA_ENTER(env);14461447__block NSRect rect = NSZeroRect;14481449NSView *view = (NSView *)jlong_to_ptr(viewPtr);1450[ThreadUtilities performOnMainThreadWaiting:YES block:^(){14511452NSRect viewBounds = [view bounds];1453NSRect frameInWindow = [view convertRect:viewBounds toView:nil];1454rect = [[view window] convertRectToScreen:frameInWindow];1455NSRect screenRect = [[NSScreen mainScreen] frame];1456//Convert coordinates to top-left corner origin1457rect.origin.y = screenRect.size.height - rect.origin.y - viewBounds.size.height;1458}];1459jRect = NSToJavaRect(env, rect);14601461JNF_COCOA_EXIT(env);14621463return jRect;1464}14651466/*1467* Class: sun_lwawt_macosx_CPlatformView1468* Method: nativeIsViewUnderMouse1469* Signature: (J)Z;1470*/14711472JNIEXPORT jboolean JNICALL Java_sun_lwawt_macosx_CPlatformView_nativeIsViewUnderMouse1473(JNIEnv *env, jclass clazz, jlong viewPtr)1474{1475__block jboolean underMouse = JNI_FALSE;14761477JNF_COCOA_ENTER(env);14781479NSView *nsView = OBJC(viewPtr);1480[ThreadUtilities performOnMainThreadWaiting:YES block:^(){1481NSPoint ptWindowCoords = [[nsView window] mouseLocationOutsideOfEventStream];1482NSPoint ptViewCoords = [nsView convertPoint:ptWindowCoords fromView:nil];1483underMouse = [nsView hitTest:ptViewCoords] != nil;1484}];14851486JNF_COCOA_EXIT(env);14871488return underMouse;1489}14901491149214931494