src/macosx/classes/sun/lwawt/macosx/CEmbeddedFrame.java

Print this page




  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 sun.lwawt.LWToolkit;
  29 import sun.lwawt.LWWindowPeer;
  30 import sun.lwawt.macosx.CocoaConstants;
  31 import sun.lwawt.macosx.event.NSEvent;
  32 
  33 import sun.awt.EmbeddedFrame;
  34 
  35 import java.awt.*;
  36 import java.awt.event.*;
  37 
  38 public class CEmbeddedFrame extends EmbeddedFrame {
  39 
  40     private CPlatformResponder responder;
  41     private boolean focused = true;

  42     private boolean parentWindowActive = true;
  43 
  44     public CEmbeddedFrame() {
  45         show();
  46     }
  47 
  48     public void addNotify() {
  49         if (getPeer() == null) {
  50             LWToolkit toolkit = (LWToolkit)Toolkit.getDefaultToolkit();
  51             LWWindowPeer peer = toolkit.createEmbeddedFrame(this);
  52             setPeer(peer);
  53             responder = new CPlatformResponder(peer, true);
  54         }
  55         super.addNotify();
  56     }
  57 
  58     public void registerAccelerator(AWTKeyStroke stroke) {}
  59 
  60     public void unregisterAccelerator(AWTKeyStroke stroke) {}
  61 


  93 
  94         responder.handleScrollEvent(x, y, modifierFlags, deltaX, deltaY);
  95     }
  96 
  97     public void handleKeyEvent(int eventType, int modifierFlags, String characters,
  98                                String charsIgnoringMods, boolean isRepeat, short keyCode,
  99                                boolean needsKeyTyped) {
 100         responder.handleKeyEvent(eventType, modifierFlags, charsIgnoringMods, keyCode, needsKeyTyped, isRepeat);
 101     }
 102 
 103     // REMIND: delete this method once 'deploy' changes for 7156194 is pushed
 104     public void handleKeyEvent(int eventType, int modifierFlags, String characters,
 105                                String charsIgnoringMods, boolean isRepeat, short keyCode) {
 106         handleKeyEvent(eventType, modifierFlags, characters, charsIgnoringMods, isRepeat, keyCode, true);
 107     }
 108 
 109     public void handleInputEvent(String text) {
 110         responder.handleInputEvent(text);
 111     }
 112 


 113     public void handleFocusEvent(boolean focused) {
 114         this.focused = focused;
 115         if (focused) {





 116             // see bug 8010925
 117             // we can't put this to handleWindowFocusEvent because
 118             // it won't be invoced if focuse is moved to a html element
 119             // on the same page.
 120             CClipboard clipboard = (CClipboard) Toolkit.getDefaultToolkit().getSystemClipboard();
 121             clipboard.checkPasteboard();
 122         }
 123         if (parentWindowActive) {
 124             responder.handleWindowFocusEvent(focused, null);
 125         }
 126     }
 127 
 128     /**




 129      * When the window is activated and had focus before the deactivation
 130      * calling this method triggers focus events in the following order:
 131      *  1. WINDOW_ACTIVATED for this EmbeddedFrame
 132      *  2. WINDOW_GAINED_FOCUS for this EmbeddedFrame
 133      *  3. FOCUS_GAINED for the most recent focus owner in this EmbeddedFrame
 134      *
 135      * The caller must not requestFocus on the EmbeddedFrame together with calling this method.
 136      *
 137      * @param parentWindowActive true if the window is activated, false otherwise
 138      */
 139     public void handleWindowFocusEvent(boolean parentWindowActive) {
 140         this.parentWindowActive = parentWindowActive;
 141         // ignore focus "lost" native request as it may mistakenly
 142         // deactivate active window (see 8001161)
 143         if (focused && parentWindowActive) {
 144             responder.handleWindowFocusEvent(parentWindowActive, null);
 145         }
 146     }
 147 
 148     public boolean isParentWindowActive() {
 149         return parentWindowActive;
 150     }
 151 }


  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 sun.lwawt.LWToolkit;
  29 import sun.lwawt.LWWindowPeer;
  30 import sun.lwawt.macosx.CocoaConstants;
  31 import sun.lwawt.macosx.event.NSEvent;
  32 
  33 import sun.awt.EmbeddedFrame;
  34 
  35 import java.awt.*;
  36 import java.awt.event.*;
  37 
  38 public class CEmbeddedFrame extends EmbeddedFrame {
  39 
  40     private CPlatformResponder responder;
  41     private static final Object classLock = new Object();
  42     private static volatile CEmbeddedFrame focusedWindow;
  43     private boolean parentWindowActive = true;
  44 
  45     public CEmbeddedFrame() {
  46         show();
  47     }
  48 
  49     public void addNotify() {
  50         if (getPeer() == null) {
  51             LWToolkit toolkit = (LWToolkit)Toolkit.getDefaultToolkit();
  52             LWWindowPeer peer = toolkit.createEmbeddedFrame(this);
  53             setPeer(peer);
  54             responder = new CPlatformResponder(peer, true);
  55         }
  56         super.addNotify();
  57     }
  58 
  59     public void registerAccelerator(AWTKeyStroke stroke) {}
  60 
  61     public void unregisterAccelerator(AWTKeyStroke stroke) {}
  62 


  94 
  95         responder.handleScrollEvent(x, y, modifierFlags, deltaX, deltaY);
  96     }
  97 
  98     public void handleKeyEvent(int eventType, int modifierFlags, String characters,
  99                                String charsIgnoringMods, boolean isRepeat, short keyCode,
 100                                boolean needsKeyTyped) {
 101         responder.handleKeyEvent(eventType, modifierFlags, charsIgnoringMods, keyCode, needsKeyTyped, isRepeat);
 102     }
 103 
 104     // REMIND: delete this method once 'deploy' changes for 7156194 is pushed
 105     public void handleKeyEvent(int eventType, int modifierFlags, String characters,
 106                                String charsIgnoringMods, boolean isRepeat, short keyCode) {
 107         handleKeyEvent(eventType, modifierFlags, characters, charsIgnoringMods, isRepeat, keyCode, true);
 108     }
 109 
 110     public void handleInputEvent(String text) {
 111         responder.handleInputEvent(text);
 112     }
 113 
 114     // handleFocusEvent is called when the applet becames focused/unfocused.
 115     // This method can be called from different threads.
 116     public void handleFocusEvent(boolean focused) {
 117         synchronized (classLock) {
 118             // In some cases an applet may not receive the focus lost event
 119             // from the parent window (see 8012330)
 120             focusedWindow = (focused) ? this
 121                     : ((focusedWindow == this) ? null : focusedWindow);
 122         }
 123         if (focusedWindow == this) {
 124             // see bug 8010925
 125             // we can't put this to handleWindowFocusEvent because
 126             // it won't be invoced if focuse is moved to a html element
 127             // on the same page.
 128             CClipboard clipboard = (CClipboard) Toolkit.getDefaultToolkit().getSystemClipboard();
 129             clipboard.checkPasteboard();
 130         }
 131         if (parentWindowActive) {
 132             responder.handleWindowFocusEvent(focused, null);
 133         }
 134     }
 135 
 136     /**
 137      * handleWindowFocusEvent is called for all applets, when the browser
 138      * becames active/inactive. This event should be filtered out for
 139      * non-focused applet. This method can be called from different threads.
 140      *
 141      * When the window is activated and had focus before the deactivation
 142      * calling this method triggers focus events in the following order:
 143      *  1. WINDOW_ACTIVATED for this EmbeddedFrame
 144      *  2. WINDOW_GAINED_FOCUS for this EmbeddedFrame
 145      *  3. FOCUS_GAINED for the most recent focus owner in this EmbeddedFrame
 146      *
 147      * The caller must not requestFocus on the EmbeddedFrame together with calling this method.
 148      *
 149      * @param parentWindowActive true if the window is activated, false otherwise
 150      */
 151     public void handleWindowFocusEvent(boolean parentWindowActive) {
 152         this.parentWindowActive = parentWindowActive;
 153         // ignore focus "lost" native request as it may mistakenly
 154         // deactivate active window (see 8001161)
 155         if (focusedWindow == this && parentWindowActive) {
 156             responder.handleWindowFocusEvent(parentWindowActive, null);
 157         }
 158     }
 159 
 160     public boolean isParentWindowActive() {
 161         return parentWindowActive;
 162     }
 163 }