1 /*
   2  * Copyright (c) 2011, 2013, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any
  23  * questions.
  24  */
  25 
  26 package sun.lwawt.macosx;
  27 
  28 import java.awt.*;
  29 import java.awt.datatransfer.Clipboard;
  30 import java.awt.dnd.*;
  31 import java.awt.dnd.peer.DragSourceContextPeer;
  32 import java.awt.event.InputEvent;
  33 import java.awt.event.InvocationEvent;
  34 import java.awt.event.KeyEvent;
  35 import java.awt.im.InputMethodHighlight;
  36 import java.awt.peer.*;
  37 import java.lang.reflect.*;
  38 import java.security.*;
  39 import java.util.*;
  40 import java.util.concurrent.Callable;
  41 
  42 import sun.awt.*;
  43 import sun.lwawt.*;
  44 import sun.lwawt.LWWindowPeer.PeerType;
  45 import sun.security.action.GetBooleanAction;
  46 
  47 class NamedCursor extends Cursor {
  48     NamedCursor(String name) {
  49         super(name);
  50     }
  51 }
  52 
  53 /**
  54  * Mac OS X Cocoa-based AWT Toolkit.
  55  */
  56 public final class LWCToolkit extends LWToolkit {
  57     // While it is possible to enumerate all mouse devices
  58     // and query them for the number of buttons, the code
  59     // that does it is rather complex. Instead, we opt for
  60     // the easy way and just support up to 5 mouse buttons,
  61     // like Windows.
  62     private static final int BUTTONS = 5;
  63 
  64     private static native void initIDs();
  65 
  66     private static CInputMethodDescriptor sInputMethodDescriptor;
  67 
  68     static {
  69         System.err.flush();
  70         java.security.AccessController.doPrivileged(new java.security.PrivilegedAction<Object>() {
  71             public Object run() {
  72                 System.loadLibrary("awt");
  73                 System.loadLibrary("fontmanager");
  74                 return null;
  75             }
  76         });
  77         if (!GraphicsEnvironment.isHeadless()) {
  78             initIDs();
  79         }
  80         inAWT = AccessController.doPrivileged(new PrivilegedAction<Boolean>() {
  81             @Override
  82             public Boolean run() {
  83                 return !Boolean.parseBoolean(System.getProperty("javafx.embed.singleThread", "false"));
  84             }
  85         });
  86     }
  87 
  88     /* If we operate in FX/AWT single threaded mode the nested loop should run in default mode */
  89     private static final boolean inAWT;
  90 
  91     public LWCToolkit() {
  92         SunToolkit.setDataTransfererClassName("sun.lwawt.macosx.CDataTransferer");
  93 
  94         areExtraMouseButtonsEnabled = Boolean.parseBoolean(System.getProperty("sun.awt.enableExtraMouseButtons", "true"));
  95         //set system property if not yet assigned
  96         System.setProperty("sun.awt.enableExtraMouseButtons", ""+areExtraMouseButtonsEnabled);
  97     }
  98 
  99     /*
 100      * System colors with default initial values, overwritten by toolkit if system values differ and are available.
 101      */
 102     private final static int NUM_APPLE_COLORS = 3;
 103     public final static int KEYBOARD_FOCUS_COLOR = 0;
 104     public final static int INACTIVE_SELECTION_BACKGROUND_COLOR = 1;
 105     public final static int INACTIVE_SELECTION_FOREGROUND_COLOR = 2;
 106     private static int[] appleColors = {
 107         0xFF808080, // keyboardFocusColor = Color.gray;
 108         0xFFC0C0C0, // secondarySelectedControlColor
 109         0xFF303030, // controlDarkShadowColor
 110     };
 111 
 112     private native void loadNativeColors(final int[] systemColors, final int[] appleColors);
 113 
 114     protected void loadSystemColors(final int[] systemColors) {
 115         if (systemColors == null) return;
 116         loadNativeColors(systemColors, appleColors);
 117     }
 118 
 119     private static class AppleSpecificColor extends Color {
 120         int index;
 121         public AppleSpecificColor(int index) {
 122             super(appleColors[index]);
 123             this.index = index;
 124         }
 125 
 126         public int getRGB() {
 127             return appleColors[index];
 128         }
 129     }
 130 
 131     /**
 132      * Returns Apple specific colors that we may expose going forward.
 133      *
 134      */
 135     public static Color getAppleColor(int color) {
 136         return new AppleSpecificColor(color);
 137     }
 138 
 139     static void systemColorsChanged() {
 140         // This is only called from native code.
 141         EventQueue.invokeLater(new Runnable() {
 142             public void run() {
 143                 AccessController.doPrivileged (new PrivilegedAction<Object>() {
 144                     public Object run() {
 145                         try {
 146                             final Method updateColorsMethod = SystemColor.class.getDeclaredMethod("updateSystemColors", new Class[0]);
 147                             updateColorsMethod.setAccessible(true);
 148                             updateColorsMethod.invoke(null, new Object[0]);
 149                         } catch (final Throwable e) {
 150                             e.printStackTrace();
 151                             // swallow this if something goes horribly wrong
 152                         }
 153                         return null;
 154                     }
 155                 });
 156             }
 157            });
 158     }
 159 
 160     public static LWCToolkit getLWCToolkit() {
 161         return (LWCToolkit)Toolkit.getDefaultToolkit();
 162     }
 163 
 164     @Override
 165     protected PlatformWindow createPlatformWindow(PeerType peerType) {
 166         if (peerType == PeerType.EMBEDDED_FRAME) {
 167             return new CPlatformEmbeddedFrame();
 168         } else if (peerType == PeerType.VIEW_EMBEDDED_FRAME) {
 169             return new CViewPlatformEmbeddedFrame();
 170         } else if (peerType == PeerType.LW_FRAME) {
 171             return new CPlatformLWWindow();
 172         } else {
 173             assert (peerType == PeerType.SIMPLEWINDOW || peerType == PeerType.DIALOG || peerType == PeerType.FRAME);
 174             return new CPlatformWindow();
 175         }
 176     }
 177 
 178     @Override
 179     protected PlatformComponent createPlatformComponent() {
 180         return new CPlatformComponent();
 181     }
 182 
 183     @Override
 184     protected PlatformComponent createLwPlatformComponent() {
 185         return new CPlatformLWComponent();
 186     }
 187 
 188     @Override
 189     protected FileDialogPeer createFileDialogPeer(FileDialog target) {
 190         return new CFileDialog(target);
 191     }
 192 
 193     @Override
 194     public MenuPeer createMenu(Menu target) {
 195         MenuPeer peer = new CMenu(target);
 196         targetCreatedPeer(target, peer);
 197         return peer;
 198     }
 199 
 200     @Override
 201     public MenuBarPeer createMenuBar(MenuBar target) {
 202          MenuBarPeer peer = new CMenuBar(target);
 203          targetCreatedPeer(target, peer);
 204              return peer;
 205     }
 206 
 207     @Override
 208     public MenuItemPeer createMenuItem(MenuItem target) {
 209         MenuItemPeer peer = new CMenuItem(target);
 210         targetCreatedPeer(target, peer);
 211         return peer;
 212     }
 213 
 214     @Override
 215     public CheckboxMenuItemPeer createCheckboxMenuItem(CheckboxMenuItem target) {
 216         CheckboxMenuItemPeer peer = new CCheckboxMenuItem(target);
 217         targetCreatedPeer(target, peer);
 218         return peer;
 219     }
 220 
 221     @Override
 222     public PopupMenuPeer createPopupMenu(PopupMenu target) {
 223         PopupMenuPeer peer = new CPopupMenu(target);
 224         targetCreatedPeer(target, peer);
 225         return peer;
 226 
 227     }
 228 
 229     @Override
 230     public SystemTrayPeer createSystemTray(SystemTray target) {
 231         SystemTrayPeer peer = new CSystemTray();
 232         return peer;
 233     }
 234 
 235     @Override
 236     public TrayIconPeer createTrayIcon(TrayIcon target) {
 237         TrayIconPeer peer = new CTrayIcon(target);
 238         targetCreatedPeer(target, peer);
 239         return peer;
 240     }
 241 
 242     @Override
 243     public LWCursorManager getCursorManager() {
 244         return CCursorManager.getInstance();
 245     }
 246 
 247     @Override
 248     public Cursor createCustomCursor(final Image cursor, final Point hotSpot, final String name) throws IndexOutOfBoundsException, HeadlessException {
 249         return new CCustomCursor(cursor, hotSpot, name);
 250     }
 251 
 252     @Override
 253     public Dimension getBestCursorSize(final int preferredWidth, final int preferredHeight) throws HeadlessException {
 254         return CCustomCursor.getBestCursorSize(preferredWidth, preferredHeight);
 255     }
 256 
 257     @Override
 258     protected void platformCleanup() {
 259         // TODO Auto-generated method stub
 260 
 261     }
 262 
 263     @Override
 264     protected void platformInit() {
 265         // TODO Auto-generated method stub
 266 
 267     }
 268 
 269     @Override
 270     protected void platformRunMessage() {
 271         // TODO Auto-generated method stub
 272 
 273     }
 274 
 275     @Override
 276     protected void platformShutdown() {
 277         // TODO Auto-generated method stub
 278 
 279     }
 280 
 281     class OSXPlatformFont extends sun.awt.PlatformFont
 282     {
 283         public OSXPlatformFont(String name, int style)
 284         {
 285             super(name, style);
 286         }
 287         protected char getMissingGlyphCharacter()
 288         {
 289             // Follow up for real implementation
 290             return (char)0xfff8; // see http://developer.apple.com/fonts/LastResortFont/
 291         }
 292     }
 293     public FontPeer getFontPeer(String name, int style) {
 294         return new OSXPlatformFont(name, style);
 295     }
 296 
 297     @Override
 298     protected MouseInfoPeer createMouseInfoPeerImpl() {
 299         return new CMouseInfoPeer();
 300     }
 301 
 302     @Override
 303     protected int getScreenHeight() {
 304         return GraphicsEnvironment.getLocalGraphicsEnvironment()
 305                 .getDefaultScreenDevice().getDefaultConfiguration().getBounds().height;
 306     }
 307 
 308     @Override
 309     protected int getScreenWidth() {
 310         return GraphicsEnvironment.getLocalGraphicsEnvironment()
 311                 .getDefaultScreenDevice().getDefaultConfiguration().getBounds().width;
 312     }
 313 
 314     @Override
 315     protected void initializeDesktopProperties() {
 316         super.initializeDesktopProperties();
 317         Map <Object, Object> fontHints = new HashMap<Object, Object>();
 318         fontHints.put(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
 319         fontHints.put(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
 320         desktopProperties.put(SunToolkit.DESKTOPFONTHINTS, fontHints);
 321         desktopProperties.put("awt.mouse.numButtons", BUTTONS);
 322 
 323         // These DnD properties must be set, otherwise Swing ends up spewing NPEs
 324         // all over the place. The values came straight off of MToolkit.
 325         desktopProperties.put("DnD.Autoscroll.initialDelay", new Integer(50));
 326         desktopProperties.put("DnD.Autoscroll.interval", new Integer(50));
 327         desktopProperties.put("DnD.Autoscroll.cursorHysteresis", new Integer(5));
 328 
 329         desktopProperties.put("DnD.isDragImageSupported", new Boolean(true));
 330 
 331         // Register DnD cursors
 332         desktopProperties.put("DnD.Cursor.CopyDrop", new NamedCursor("DnD.Cursor.CopyDrop"));
 333         desktopProperties.put("DnD.Cursor.MoveDrop", new NamedCursor("DnD.Cursor.MoveDrop"));
 334         desktopProperties.put("DnD.Cursor.LinkDrop", new NamedCursor("DnD.Cursor.LinkDrop"));
 335         desktopProperties.put("DnD.Cursor.CopyNoDrop", new NamedCursor("DnD.Cursor.CopyNoDrop"));
 336         desktopProperties.put("DnD.Cursor.MoveNoDrop", new NamedCursor("DnD.Cursor.MoveNoDrop"));
 337         desktopProperties.put("DnD.Cursor.LinkNoDrop", new NamedCursor("DnD.Cursor.LinkNoDrop"));
 338 
 339     }
 340 
 341 
 342 /*
 343  * The method returns true if some events were processed during that timeout.
 344  * @see sun.awt.SunToolkit#syncNativeQueue(long)
 345  */
 346     @Override
 347     protected boolean syncNativeQueue(long timeout) {
 348         return nativeSyncQueue(timeout);
 349     }
 350 
 351     @Override
 352     public native void beep();
 353 
 354     @Override
 355     public int getScreenResolution() throws HeadlessException {
 356         return (int) ((CGraphicsDevice) GraphicsEnvironment
 357                 .getLocalGraphicsEnvironment().getDefaultScreenDevice())
 358                 .getXResolution();
 359     }
 360 
 361     @Override
 362     public Insets getScreenInsets(final GraphicsConfiguration gc) {
 363         return ((CGraphicsConfig) gc).getDevice().getScreenInsets();
 364     }
 365 
 366     @Override
 367     public void sync() {
 368         // TODO Auto-generated method stub
 369 
 370     }
 371 
 372     @Override
 373     public RobotPeer createRobot(Robot target, GraphicsDevice screen) {
 374         return new CRobot(target, (CGraphicsDevice)screen);
 375     }
 376 
 377     private native boolean isCapsLockOn();
 378 
 379     /*
 380      * NOTE: Among the keys this method is supposed to check,
 381      * only Caps Lock works as a true locking key with OS X.
 382      * There is no Scroll Lock key on modern Apple keyboards,
 383      * and with a PC keyboard plugged in Scroll Lock is simply
 384      * ignored: no LED lights up if you press it.
 385      * The key located at the same position on Apple keyboards
 386      * as Num Lock on PC keyboards is called Clear, doesn't lock
 387      * anything and is used for entirely different purpose.
 388      */
 389     public boolean getLockingKeyState(int keyCode) throws UnsupportedOperationException {
 390         switch (keyCode) {
 391             case KeyEvent.VK_NUM_LOCK:
 392             case KeyEvent.VK_SCROLL_LOCK:
 393             case KeyEvent.VK_KANA_LOCK:
 394                 throw new UnsupportedOperationException("Toolkit.getLockingKeyState");
 395 
 396             case KeyEvent.VK_CAPS_LOCK:
 397                 return isCapsLockOn();
 398 
 399             default:
 400                 throw new IllegalArgumentException("invalid key for Toolkit.getLockingKeyState");
 401         }
 402     }
 403 
 404     //Is it allowed to generate events assigned to extra mouse buttons.
 405     //Set to true by default.
 406     private static boolean areExtraMouseButtonsEnabled = true;
 407 
 408     public boolean areExtraMouseButtonsEnabled() throws HeadlessException {
 409         return areExtraMouseButtonsEnabled;
 410     }
 411 
 412     public int getNumberOfButtons(){
 413         return BUTTONS;
 414     }
 415 
 416     @Override
 417     public boolean isTraySupported() {
 418         return true;
 419     }
 420 
 421     @Override
 422     public boolean isAlwaysOnTopSupported() {
 423         return true;
 424     }
 425 
 426     // Intended to be called from the LWCToolkit.m only.
 427     private static void installToolkitThreadNameInJava() {
 428         Thread.currentThread().setName(CThreading.APPKIT_THREAD_NAME);
 429     }
 430 
 431     @Override
 432     public boolean isWindowOpacitySupported() {
 433         return true;
 434     }
 435 
 436     @Override
 437     public boolean isFrameStateSupported(int state) throws HeadlessException {
 438         switch (state) {
 439             case Frame.NORMAL:
 440             case Frame.ICONIFIED:
 441             case Frame.MAXIMIZED_BOTH:
 442                 return true;
 443             default:
 444                 return false;
 445         }
 446     }
 447 
 448     /**
 449      * Determines which modifier key is the appropriate accelerator
 450      * key for menu shortcuts.
 451      * <p>
 452      * Menu shortcuts, which are embodied in the
 453      * <code>MenuShortcut</code> class, are handled by the
 454      * <code>MenuBar</code> class.
 455      * <p>
 456      * By default, this method returns <code>Event.CTRL_MASK</code>.
 457      * Toolkit implementations should override this method if the
 458      * <b>Control</b> key isn't the correct key for accelerators.
 459      * @return    the modifier mask on the <code>Event</code> class
 460      *                 that is used for menu shortcuts on this toolkit.
 461      * @see       java.awt.MenuBar
 462      * @see       java.awt.MenuShortcut
 463      * @since     JDK1.1
 464      */
 465     public int getMenuShortcutKeyMask() {
 466         return Event.META_MASK;
 467     }
 468 
 469     @Override
 470     public Image getImage(final String filename) {
 471         final Image nsImage = checkForNSImage(filename);
 472         if (nsImage != null) return nsImage;
 473 
 474         return super.getImage(filename);
 475     }
 476 
 477     static final String nsImagePrefix = "NSImage://";
 478     protected Image checkForNSImage(final String imageName) {
 479         if (imageName == null) return null;
 480         if (!imageName.startsWith(nsImagePrefix)) return null;
 481         return CImage.getCreator().createImageFromName(imageName.substring(nsImagePrefix.length()));
 482     }
 483 
 484     // Thread-safe Object.equals() called from native
 485     public static boolean doEquals(final Object a, final Object b, Component c) {
 486         if (a == b) return true;
 487 
 488         final boolean[] ret = new boolean[1];
 489 
 490         try {  invokeAndWait(new Runnable() { public void run() { synchronized(ret) {
 491             ret[0] = a.equals(b);
 492         }}}, c); } catch (Exception e) { e.printStackTrace(); }
 493 
 494         synchronized(ret) { return ret[0]; }
 495     }
 496 
 497     public static <T> T invokeAndWait(final Callable<T> callable, Component component) throws Exception {
 498         final CallableWrapper<T> wrapper = new CallableWrapper<T>(callable);
 499         invokeAndWait(wrapper, component);
 500         return wrapper.getResult();
 501     }
 502 
 503     static final class CallableWrapper<T> implements Runnable {
 504         final Callable<T> callable;
 505         T object;
 506         Exception e;
 507 
 508         public CallableWrapper(final Callable<T> callable) {
 509             this.callable = callable;
 510         }
 511 
 512         public void run() {
 513             try {
 514                 object = callable.call();
 515             } catch (final Exception e) {
 516                 this.e = e;
 517             }
 518         }
 519 
 520         public T getResult() throws Exception {
 521             if (e != null) throw e;
 522             return object;
 523         }
 524     }
 525 
 526     // Kicks an event over to the appropriate eventqueue and waits for it to finish
 527     // To avoid deadlocking, we manually run the NSRunLoop while waiting
 528     // Any selector invoked using ThreadUtilities performOnMainThread will be processed in doAWTRunLoop
 529     // The InvocationEvent will call LWCToolkit.stopAWTRunLoop() when finished, which will stop our manual runloop
 530     // Does not dispatch native events while in the loop
 531     public static void invokeAndWait(Runnable event, Component component) throws InterruptedException, InvocationTargetException {
 532         final long mediator = createAWTRunLoopMediator();
 533 
 534         InvocationEvent invocationEvent =
 535                 new InvocationEvent(component != null ? component : Toolkit.getDefaultToolkit(), event) {
 536                     @Override
 537                     public void dispatch() {
 538                         try {
 539                             super.dispatch();
 540                         } finally {
 541                             if (mediator != 0) {
 542                                 stopAWTRunLoop(mediator);
 543                             }
 544                         }
 545                     }
 546                 };
 547 
 548         if (component != null) {
 549             AppContext appContext = SunToolkit.targetToAppContext(component);
 550             SunToolkit.postEvent(appContext, invocationEvent);
 551 
 552             // 3746956 - flush events from PostEventQueue to prevent them from getting stuck and causing a deadlock
 553             SunToolkit.flushPendingEvents(appContext);
 554         } else {
 555             // This should be the equivalent to EventQueue.invokeAndWait
 556             ((LWCToolkit)Toolkit.getDefaultToolkit()).getSystemEventQueueForInvokeAndWait().postEvent(invocationEvent);
 557         }
 558 
 559         doAWTRunLoop(mediator, false);
 560 
 561         Throwable eventException = invocationEvent.getException();
 562         if (eventException != null) {
 563             if (eventException instanceof UndeclaredThrowableException) {
 564                 eventException = ((UndeclaredThrowableException)eventException).getUndeclaredThrowable();
 565             }
 566             throw new InvocationTargetException(eventException);
 567         }
 568     }
 569 
 570     public static void invokeLater(Runnable event, Component component) throws InvocationTargetException {
 571         final InvocationEvent invocationEvent =
 572                 new InvocationEvent(component != null ? component : Toolkit.getDefaultToolkit(), event);
 573 
 574         if (component != null) {
 575             final AppContext appContext = SunToolkit.targetToAppContext(component);
 576             SunToolkit.postEvent(appContext, invocationEvent);
 577 
 578             // 3746956 - flush events from PostEventQueue to prevent them from getting stuck and causing a deadlock
 579             SunToolkit.flushPendingEvents(appContext);
 580         } else {
 581             // This should be the equivalent to EventQueue.invokeAndWait
 582             ((LWCToolkit)Toolkit.getDefaultToolkit()).getSystemEventQueueForInvokeAndWait().postEvent(invocationEvent);
 583         }
 584 
 585         final Throwable eventException = invocationEvent.getException();
 586         if (eventException == null) return;
 587 
 588         if (eventException instanceof UndeclaredThrowableException) {
 589             throw new InvocationTargetException(((UndeclaredThrowableException)eventException).getUndeclaredThrowable());
 590         }
 591         throw new InvocationTargetException(eventException);
 592     }
 593 
 594     // This exists purely to get around permissions issues with getSystemEventQueueImpl
 595     EventQueue getSystemEventQueueForInvokeAndWait() {
 596         return getSystemEventQueueImpl();
 597     }
 598 
 599 
 600 // DnD support
 601 
 602     public DragSourceContextPeer createDragSourceContextPeer(DragGestureEvent dge) throws InvalidDnDOperationException {
 603         DragSourceContextPeer dscp = CDragSourceContextPeer.createDragSourceContextPeer(dge);
 604 
 605         return dscp;
 606     }
 607 
 608     public <T extends DragGestureRecognizer> T createDragGestureRecognizer(Class<T> abstractRecognizerClass, DragSource ds, Component c, int srcActions, DragGestureListener dgl) {
 609         DragGestureRecognizer dgr = null;
 610 
 611         // Create a new mouse drag gesture recognizer if we have a class match:
 612         if (MouseDragGestureRecognizer.class.equals(abstractRecognizerClass))
 613             dgr = new CMouseDragGestureRecognizer(ds, c, srcActions, dgl);
 614 
 615         return (T)dgr;
 616     }
 617 
 618 // InputMethodSupport Method
 619     /**
 620      * Returns the default keyboard locale of the underlying operating system
 621      */
 622     public Locale getDefaultKeyboardLocale() {
 623         Locale locale = CInputMethod.getNativeLocale();
 624 
 625         if (locale == null) {
 626             return super.getDefaultKeyboardLocale();
 627         }
 628 
 629         return locale;
 630     }
 631 
 632     public java.awt.im.spi.InputMethodDescriptor getInputMethodAdapterDescriptor() {
 633         if (sInputMethodDescriptor == null)
 634             sInputMethodDescriptor = new CInputMethodDescriptor();
 635 
 636         return sInputMethodDescriptor;
 637     }
 638 
 639     /**
 640      * Returns a map of visual attributes for thelevel description
 641      * of the given input method highlight, or null if no mapping is found.
 642      * The style field of the input method highlight is ignored. The map
 643      * returned is unmodifiable.
 644      * @param highlight input method highlight
 645      * @return style attribute map, or null
 646      * @since 1.3
 647      */
 648     public Map mapInputMethodHighlight(InputMethodHighlight highlight) {
 649         return CInputMethod.mapInputMethodHighlight(highlight);
 650     }
 651 
 652     /**
 653      * Returns key modifiers used by Swing to set up a focus accelerator key stroke.
 654      */
 655     @Override
 656     public int getFocusAcceleratorKeyMask() {
 657         return InputEvent.CTRL_MASK | InputEvent.ALT_MASK;
 658     }
 659 
 660     /**
 661      * Tests whether specified key modifiers mask can be used to enter a printable
 662      * character.
 663      */
 664     @Override
 665     public boolean isPrintableCharacterModifiersMask(int mods) {
 666         return ((mods & (InputEvent.META_MASK | InputEvent.CTRL_MASK)) == 0);
 667     }
 668 
 669     /**
 670      * Returns whether popup is allowed to be shown above the task bar.
 671      */
 672     @Override
 673     public boolean canPopupOverlapTaskBar() {
 674         return false;
 675     }
 676 
 677     private static Boolean sunAwtDisableCALayers = null;
 678 
 679     /**
 680      * Returns the value of "sun.awt.disableCALayers" property. Default
 681      * value is {@code false}.
 682      */
 683     public synchronized static boolean getSunAwtDisableCALayers() {
 684         if (sunAwtDisableCALayers == null) {
 685             sunAwtDisableCALayers = AccessController.doPrivileged(
 686                 new GetBooleanAction("sun.awt.disableCALayers"));
 687         }
 688         return sunAwtDisableCALayers.booleanValue();
 689     }
 690 
 691 
 692     /*
 693      * Returns true if the application (one of its windows) owns keyboard focus.
 694      */
 695     public native boolean isApplicationActive();
 696 
 697     /************************
 698      * Native methods section
 699      ************************/
 700 
 701     static native long createAWTRunLoopMediator();
 702     /**
 703      * Method to run a nested run-loop. The nested loop is spinned in the javaRunLoop mode, so selectors sent
 704      * by [JNFRunLoop performOnMainThreadWaiting] are processed.
 705      * @param mediator a native pointer to the mediator object created by createAWTRunLoopMediator
 706      * @param processEvents if true - dispatches event while in the nested loop. Used in DnD.
 707      *                      Additional attention is needed when using this feature as we short-circuit normal event
 708      *                      processing which could break Appkit.
 709      *                      (One known example is when the window is resized with the mouse)
 710      *
 711      *                      if false - all events come after exit form the nested loop
 712      */
 713     static void doAWTRunLoop(long mediator, boolean processEvents) {
 714         doAWTRunLoopImpl(mediator, processEvents, inAWT);
 715     }
 716     static private native void doAWTRunLoopImpl(long mediator, boolean processEvents, boolean inAWT);
 717     static native void stopAWTRunLoop(long mediator);
 718 
 719     private native boolean nativeSyncQueue(long timeout);
 720 
 721     @Override
 722     public Clipboard createPlatformClipboard() {
 723         return new CClipboard("System");
 724     }
 725 
 726     @Override
 727     public boolean isModalExclusionTypeSupported(Dialog.ModalExclusionType exclusionType) {
 728         return (exclusionType == null) ||
 729             (exclusionType == Dialog.ModalExclusionType.NO_EXCLUDE) ||
 730             (exclusionType == Dialog.ModalExclusionType.APPLICATION_EXCLUDE) ||
 731             (exclusionType == Dialog.ModalExclusionType.TOOLKIT_EXCLUDE);
 732     }
 733 
 734     @Override
 735     public boolean isModalityTypeSupported(Dialog.ModalityType modalityType) {
 736         //TODO: FileDialog blocks excluded windows...
 737         //TODO: Test: 2 file dialogs, separate AppContexts: a) Dialog 1 blocked, shouldn't be. Frame 4 blocked (shouldn't be).
 738         return (modalityType == null) ||
 739             (modalityType == Dialog.ModalityType.MODELESS) ||
 740             (modalityType == Dialog.ModalityType.DOCUMENT_MODAL) ||
 741             (modalityType == Dialog.ModalityType.APPLICATION_MODAL) ||
 742             (modalityType == Dialog.ModalityType.TOOLKIT_MODAL);
 743     }
 744 
 745     @Override
 746     public boolean isWindowShapingSupported() {
 747         return true;
 748     }
 749 
 750     @Override
 751     public boolean isWindowTranslucencySupported() {
 752         return true;
 753     }
 754 
 755     @Override
 756     public boolean isTranslucencyCapable(GraphicsConfiguration gc) {
 757         return true;
 758     }
 759 
 760     public boolean isSwingBackbufferTranslucencySupported() {
 761         return true;
 762     }
 763 
 764     @Override
 765     public boolean enableInputMethodsForTextComponent() {
 766         return true;
 767     }
 768 }