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

Print this page




  22  * or visit www.oracle.com if you need additional information or have any
  23  * questions.
  24  */
  25 
  26 
  27 package sun.lwawt.macosx;
  28 
  29 import java.awt.AWTKeyStroke;
  30 import java.awt.Point;
  31 import java.awt.Toolkit;
  32 
  33 import sun.awt.EmbeddedFrame;
  34 import sun.lwawt.LWWindowPeer;
  35 
  36 @SuppressWarnings("serial") // JDK implementation class
  37 public class CEmbeddedFrame extends EmbeddedFrame {
  38 
  39     private CPlatformResponder responder;
  40     private static final Object classLock = new Object();
  41     private static volatile CEmbeddedFrame focusedWindow;

  42     private boolean parentWindowActive = true;
  43 
  44     public CEmbeddedFrame() {
  45         show();
  46     }
  47 
  48     public void addNotify() {
  49         if (getPeer() == null) {
  50             LWCToolkit toolkit = (LWCToolkit)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 


 128     }
 129 
 130     /**
 131      * When the parent window is activated this method is called for all EmbeddedFrames in it.
 132      *
 133      * For the CEmbeddedFrame which had focus before the deactivation this method triggers
 134      * focus events in the following order:
 135      *  1. WINDOW_ACTIVATED for this EmbeddedFrame
 136      *  2. WINDOW_GAINED_FOCUS for this EmbeddedFrame
 137      *  3. FOCUS_GAINED for the most recent focus owner in this EmbeddedFrame
 138      *
 139      * The caller must not requestFocus on the EmbeddedFrame together with calling this method.
 140      *
 141      * @param parentWindowActive true if the window is activated, false otherwise
 142      */
 143     // handleWindowFocusEvent is called for all applets, when the browser
 144     // becomes active/inactive. This event should be filtered out for
 145     // non-focused applet. This method can be called from different threads.
 146     public void handleWindowFocusEvent(boolean parentWindowActive) {
 147         this.parentWindowActive = parentWindowActive;



















 148         // ignore focus "lost" native request as it may mistakenly
 149         // deactivate active window (see 8001161)
 150         if (focusedWindow == this && parentWindowActive) {
 151             responder.handleWindowFocusEvent(parentWindowActive, null);
 152         }
 153     }
 154 
 155     public boolean isParentWindowActive() {
 156         return parentWindowActive;
 157     }
 158 }


  22  * or visit www.oracle.com if you need additional information or have any
  23  * questions.
  24  */
  25 
  26 
  27 package sun.lwawt.macosx;
  28 
  29 import java.awt.AWTKeyStroke;
  30 import java.awt.Point;
  31 import java.awt.Toolkit;
  32 
  33 import sun.awt.EmbeddedFrame;
  34 import sun.lwawt.LWWindowPeer;
  35 
  36 @SuppressWarnings("serial") // JDK implementation class
  37 public class CEmbeddedFrame extends EmbeddedFrame {
  38 
  39     private CPlatformResponder responder;
  40     private static final Object classLock = new Object();
  41     private static volatile CEmbeddedFrame focusedWindow;
  42     private CEmbeddedFrame previousFocusedWindow;
  43     private boolean parentWindowActive = true;
  44 
  45     public CEmbeddedFrame() {
  46         show();
  47     }
  48 
  49     public void addNotify() {
  50         if (getPeer() == null) {
  51             LWCToolkit toolkit = (LWCToolkit)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 


 129     }
 130 
 131     /**
 132      * When the parent window is activated this method is called for all EmbeddedFrames in it.
 133      *
 134      * For the CEmbeddedFrame which had focus before the deactivation this method triggers
 135      * focus events in the following order:
 136      *  1. WINDOW_ACTIVATED for this EmbeddedFrame
 137      *  2. WINDOW_GAINED_FOCUS for this EmbeddedFrame
 138      *  3. FOCUS_GAINED for the most recent focus owner in this EmbeddedFrame
 139      *
 140      * The caller must not requestFocus on the EmbeddedFrame together with calling this method.
 141      *
 142      * @param parentWindowActive true if the window is activated, false otherwise
 143      */
 144     // handleWindowFocusEvent is called for all applets, when the browser
 145     // becomes active/inactive. This event should be filtered out for
 146     // non-focused applet. This method can be called from different threads.
 147     public void handleWindowFocusEvent(boolean parentWindowActive) {
 148         this.parentWindowActive = parentWindowActive;
 149         // If several applets are running in different browser's windows, it is necessary to
 150         // detect the switching between the parent windows and update focusedWindow accordingly.
 151         synchronized (classLock) {
 152             if (!parentWindowActive) {
 153                 this.previousFocusedWindow = focusedWindow;
 154             }
 155             if (parentWindowActive && focusedWindow != this &&
 156                 (focusedWindow == null || (focusedWindow != null && !focusedWindow.isParentWindowActive()))) {
 157                 // It looks like we have switched to another browser window, let's restore focus to
 158                 // the previously focused applet in this window.
 159                 if (this.previousFocusedWindow != null) {
 160                     focusedWindow = this.previousFocusedWindow;
 161                 } else {
 162                     // No applets were focused in this window, so set focus to the first
 163                     // applet in the window
 164                     focusedWindow = this;
 165                 }
 166             }
 167         }
 168         // ignore focus "lost" native request as it may mistakenly
 169         // deactivate active window (see 8001161)
 170         if (focusedWindow == this && parentWindowActive) {
 171             responder.handleWindowFocusEvent(parentWindowActive, null);
 172         }
 173     }
 174 
 175     public boolean isParentWindowActive() {
 176         return parentWindowActive;
 177     }
 178 }