author | darcy |
Thu, 13 Mar 2014 12:40:27 -0700 | |
changeset 23647 | 41d22f2dbeb5 |
parent 23010 | 6dadb192ad81 |
permissions | -rw-r--r-- |
2 | 1 |
/* |
23010
6dadb192ad81
8029235: Update copyright year to match last edit in jdk8 jdk repository for 2013
lana
parents:
18178
diff
changeset
|
2 |
* Copyright (c) 2003, 2013, Oracle and/or its affiliates. All rights reserved. |
2 | 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 |
|
5506 | 7 |
* published by the Free Software Foundation. Oracle designates this |
2 | 8 |
* particular file as subject to the "Classpath" exception as provided |
5506 | 9 |
* by Oracle in the LICENSE file that accompanied this code. |
2 | 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 |
* |
|
5506 | 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. |
|
2 | 24 |
*/ |
25 |
||
26 |
package sun.awt.X11; |
|
27 |
||
28 |
import java.awt.AWTKeyStroke; |
|
29 |
import sun.awt.SunToolkit; |
|
30 |
import java.awt.Component; |
|
31 |
import java.awt.Container; |
|
3938
ef327bd847c0
6879044: Eliminate the dependency on logging from the AWT/2D/Swing classes
mchung
parents:
1974
diff
changeset
|
32 |
import sun.util.logging.PlatformLogger; |
2 | 33 |
|
1974
1e1487c04864
6773985: OutOfMemory (PermGen space) under Linux / Firefox when switching bw. applets
art
parents:
439
diff
changeset
|
34 |
import sun.awt.X11GraphicsConfig; |
1e1487c04864
6773985: OutOfMemory (PermGen space) under Linux / Firefox when switching bw. applets
art
parents:
439
diff
changeset
|
35 |
import sun.awt.X11GraphicsDevice; |
1e1487c04864
6773985: OutOfMemory (PermGen space) under Linux / Firefox when switching bw. applets
art
parents:
439
diff
changeset
|
36 |
|
2 | 37 |
/** |
38 |
* Helper class implementing XEmbed protocol handling routines(client side) |
|
39 |
* Window which wants to participate in a protocol should create an instance, |
|
40 |
* call install and forward all XClientMessageEvents to it. |
|
41 |
*/ |
|
42 |
public class XEmbedClientHelper extends XEmbedHelper implements XEventDispatcher { |
|
3938
ef327bd847c0
6879044: Eliminate the dependency on logging from the AWT/2D/Swing classes
mchung
parents:
1974
diff
changeset
|
43 |
private static final PlatformLogger xembedLog = PlatformLogger.getLogger("sun.awt.X11.xembed.XEmbedClientHelper"); |
2 | 44 |
|
1974
1e1487c04864
6773985: OutOfMemory (PermGen space) under Linux / Firefox when switching bw. applets
art
parents:
439
diff
changeset
|
45 |
private XEmbeddedFramePeer embedded; // XEmbed client |
1e1487c04864
6773985: OutOfMemory (PermGen space) under Linux / Firefox when switching bw. applets
art
parents:
439
diff
changeset
|
46 |
private long server; // XEmbed server |
1e1487c04864
6773985: OutOfMemory (PermGen space) under Linux / Firefox when switching bw. applets
art
parents:
439
diff
changeset
|
47 |
|
2 | 48 |
private boolean active; |
49 |
private boolean applicationActive; |
|
50 |
||
51 |
XEmbedClientHelper() { |
|
52 |
super(); |
|
53 |
} |
|
54 |
||
1974
1e1487c04864
6773985: OutOfMemory (PermGen space) under Linux / Firefox when switching bw. applets
art
parents:
439
diff
changeset
|
55 |
void setClient(XEmbeddedFramePeer client) { |
18178
ee71c923891d
8016747: Replace deprecated PlatformLogger isLoggable(int) with isLoggable(Level)
chegar
parents:
16839
diff
changeset
|
56 |
if (xembedLog.isLoggable(PlatformLogger.Level.FINE)) { |
1974
1e1487c04864
6773985: OutOfMemory (PermGen space) under Linux / Firefox when switching bw. applets
art
parents:
439
diff
changeset
|
57 |
xembedLog.fine("XEmbed client: " + client); |
1e1487c04864
6773985: OutOfMemory (PermGen space) under Linux / Firefox when switching bw. applets
art
parents:
439
diff
changeset
|
58 |
} |
1e1487c04864
6773985: OutOfMemory (PermGen space) under Linux / Firefox when switching bw. applets
art
parents:
439
diff
changeset
|
59 |
if (embedded != null) { |
1e1487c04864
6773985: OutOfMemory (PermGen space) under Linux / Firefox when switching bw. applets
art
parents:
439
diff
changeset
|
60 |
XToolkit.removeEventDispatcher(embedded.getWindow(), this); |
1e1487c04864
6773985: OutOfMemory (PermGen space) under Linux / Firefox when switching bw. applets
art
parents:
439
diff
changeset
|
61 |
active = false; |
1e1487c04864
6773985: OutOfMemory (PermGen space) under Linux / Firefox when switching bw. applets
art
parents:
439
diff
changeset
|
62 |
} |
1e1487c04864
6773985: OutOfMemory (PermGen space) under Linux / Firefox when switching bw. applets
art
parents:
439
diff
changeset
|
63 |
embedded = client; |
1e1487c04864
6773985: OutOfMemory (PermGen space) under Linux / Firefox when switching bw. applets
art
parents:
439
diff
changeset
|
64 |
if (embedded != null) { |
1e1487c04864
6773985: OutOfMemory (PermGen space) under Linux / Firefox when switching bw. applets
art
parents:
439
diff
changeset
|
65 |
XToolkit.addEventDispatcher(embedded.getWindow(), this); |
1e1487c04864
6773985: OutOfMemory (PermGen space) under Linux / Firefox when switching bw. applets
art
parents:
439
diff
changeset
|
66 |
} |
1e1487c04864
6773985: OutOfMemory (PermGen space) under Linux / Firefox when switching bw. applets
art
parents:
439
diff
changeset
|
67 |
} |
2 | 68 |
|
1974
1e1487c04864
6773985: OutOfMemory (PermGen space) under Linux / Firefox when switching bw. applets
art
parents:
439
diff
changeset
|
69 |
void install() { |
18178
ee71c923891d
8016747: Replace deprecated PlatformLogger isLoggable(int) with isLoggable(Level)
chegar
parents:
16839
diff
changeset
|
70 |
if (xembedLog.isLoggable(PlatformLogger.Level.FINE)) { |
1974
1e1487c04864
6773985: OutOfMemory (PermGen space) under Linux / Firefox when switching bw. applets
art
parents:
439
diff
changeset
|
71 |
xembedLog.fine("Installing xembedder on " + embedded); |
1e1487c04864
6773985: OutOfMemory (PermGen space) under Linux / Firefox when switching bw. applets
art
parents:
439
diff
changeset
|
72 |
} |
2 | 73 |
long[] info = new long[] { XEMBED_VERSION, XEMBED_MAPPED }; |
74 |
long data = Native.card32ToData(info); |
|
75 |
try { |
|
76 |
XEmbedInfo.setAtomData(embedded.getWindow(), data, 2); |
|
77 |
} finally { |
|
78 |
unsafe.freeMemory(data); |
|
79 |
} |
|
80 |
// XEmbeddedFrame is initially created with a null parent.. |
|
81 |
// Here it is reparented to the proper parent window. |
|
82 |
long parentWindow = embedded.getParentWindowHandle(); |
|
83 |
if (parentWindow != 0) { |
|
84 |
XToolkit.awtLock(); |
|
85 |
try { |
|
86 |
XlibWrapper.XReparentWindow(XToolkit.getDisplay(), |
|
87 |
embedded.getWindow(), |
|
88 |
parentWindow, |
|
89 |
0, 0); |
|
90 |
} finally { |
|
91 |
XToolkit.awtUnlock(); |
|
92 |
} |
|
93 |
} |
|
94 |
} |
|
95 |
||
96 |
void handleClientMessage(XEvent xev) { |
|
97 |
XClientMessageEvent msg = xev.get_xclient(); |
|
18178
ee71c923891d
8016747: Replace deprecated PlatformLogger isLoggable(int) with isLoggable(Level)
chegar
parents:
16839
diff
changeset
|
98 |
if (xembedLog.isLoggable(PlatformLogger.Level.FINE)) { |
16839
d0f2e97b7359
8010297: Missing isLoggable() checks in logging code
anthony
parents:
13648
diff
changeset
|
99 |
xembedLog.fine(msg.toString()); |
d0f2e97b7359
8010297: Missing isLoggable() checks in logging code
anthony
parents:
13648
diff
changeset
|
100 |
} |
2 | 101 |
if (msg.get_message_type() == XEmbed.getAtom()) { |
18178
ee71c923891d
8016747: Replace deprecated PlatformLogger isLoggable(int) with isLoggable(Level)
chegar
parents:
16839
diff
changeset
|
102 |
if (xembedLog.isLoggable(PlatformLogger.Level.FINE)) { |
16839
d0f2e97b7359
8010297: Missing isLoggable() checks in logging code
anthony
parents:
13648
diff
changeset
|
103 |
xembedLog.fine("Embedded message: " + msgidToString((int)msg.get_data(1))); |
d0f2e97b7359
8010297: Missing isLoggable() checks in logging code
anthony
parents:
13648
diff
changeset
|
104 |
} |
2 | 105 |
switch ((int)msg.get_data(1)) { |
106 |
case XEMBED_EMBEDDED_NOTIFY: // Notification about embedding protocol start |
|
107 |
active = true; |
|
108 |
server = getEmbedder(embedded, msg); |
|
109 |
// Check if window is reparented. If not - it was created with |
|
110 |
// parent and so we should update it here. |
|
111 |
if (!embedded.isReparented()) { |
|
112 |
embedded.setReparented(true); |
|
113 |
embedded.updateSizeHints(); |
|
114 |
} |
|
115 |
embedded.notifyStarted(); |
|
116 |
break; |
|
117 |
case XEMBED_WINDOW_ACTIVATE: |
|
118 |
applicationActive = true; |
|
119 |
break; |
|
120 |
case XEMBED_WINDOW_DEACTIVATE: |
|
121 |
if (applicationActive) { |
|
122 |
applicationActive = false; |
|
123 |
handleWindowFocusOut(); |
|
124 |
} |
|
125 |
break; |
|
126 |
case XEMBED_FOCUS_IN: // We got focus! |
|
127 |
// Check for direction |
|
128 |
handleFocusIn((int)msg.get_data(2)); |
|
129 |
break; |
|
130 |
case XEMBED_FOCUS_OUT: |
|
131 |
if (applicationActive) { |
|
132 |
handleWindowFocusOut(); |
|
133 |
} |
|
134 |
break; |
|
135 |
} |
|
136 |
} |
|
137 |
} |
|
138 |
void handleFocusIn(int detail) { |
|
139 |
if (embedded.focusAllowedFor()) { |
|
4373
6a1c87e2876b
6903890: SWT_AWT focus issues when a dialog is shown/disposed, on X11
ant
parents:
3938
diff
changeset
|
140 |
embedded.handleWindowFocusIn(0); |
2 | 141 |
} |
142 |
switch(detail) { |
|
143 |
case XEMBED_FOCUS_CURRENT: |
|
144 |
// Do nothing - just restore to the current value |
|
145 |
break; |
|
146 |
case XEMBED_FOCUS_FIRST: |
|
147 |
SunToolkit.executeOnEventHandlerThread(embedded.target, new Runnable() { |
|
148 |
public void run() { |
|
149 |
Component comp = ((Container)embedded.target).getFocusTraversalPolicy().getFirstComponent((Container)embedded.target); |
|
150 |
if (comp != null) { |
|
151 |
comp.requestFocusInWindow(); |
|
152 |
} |
|
153 |
}}); |
|
154 |
break; |
|
155 |
case XEMBED_FOCUS_LAST: |
|
156 |
SunToolkit.executeOnEventHandlerThread(embedded.target, new Runnable() { |
|
157 |
public void run() { |
|
158 |
Component comp = ((Container)embedded.target).getFocusTraversalPolicy().getLastComponent((Container)embedded.target); |
|
159 |
if (comp != null) { |
|
160 |
comp.requestFocusInWindow(); |
|
161 |
} |
|
162 |
}}); |
|
163 |
break; |
|
164 |
} |
|
165 |
} |
|
166 |
||
167 |
public void dispatchEvent(XEvent xev) { |
|
168 |
switch(xev.get_type()) { |
|
439
3488710b02f8
6623459: Get rid of XConstant, XProtocolConstants and XUtilConstants antipattern
dav
parents:
120
diff
changeset
|
169 |
case XConstants.ClientMessage: |
2 | 170 |
handleClientMessage(xev); |
171 |
break; |
|
439
3488710b02f8
6623459: Get rid of XConstant, XProtocolConstants and XUtilConstants antipattern
dav
parents:
120
diff
changeset
|
172 |
case XConstants.ReparentNotify: |
2 | 173 |
handleReparentNotify(xev); |
174 |
break; |
|
175 |
} |
|
176 |
} |
|
177 |
public void handleReparentNotify(XEvent xev) { |
|
178 |
XReparentEvent re = xev.get_xreparent(); |
|
1974
1e1487c04864
6773985: OutOfMemory (PermGen space) under Linux / Firefox when switching bw. applets
art
parents:
439
diff
changeset
|
179 |
long newParent = re.get_parent(); |
1e1487c04864
6773985: OutOfMemory (PermGen space) under Linux / Firefox when switching bw. applets
art
parents:
439
diff
changeset
|
180 |
if (active) { |
1e1487c04864
6773985: OutOfMemory (PermGen space) under Linux / Firefox when switching bw. applets
art
parents:
439
diff
changeset
|
181 |
// unregister accelerators, etc. for old parent |
1e1487c04864
6773985: OutOfMemory (PermGen space) under Linux / Firefox when switching bw. applets
art
parents:
439
diff
changeset
|
182 |
embedded.notifyStopped(); |
1e1487c04864
6773985: OutOfMemory (PermGen space) under Linux / Firefox when switching bw. applets
art
parents:
439
diff
changeset
|
183 |
// check if newParent is a root window |
1e1487c04864
6773985: OutOfMemory (PermGen space) under Linux / Firefox when switching bw. applets
art
parents:
439
diff
changeset
|
184 |
X11GraphicsConfig gc = (X11GraphicsConfig)embedded.getGraphicsConfiguration(); |
1e1487c04864
6773985: OutOfMemory (PermGen space) under Linux / Firefox when switching bw. applets
art
parents:
439
diff
changeset
|
185 |
X11GraphicsDevice gd = (X11GraphicsDevice)gc.getDevice(); |
1e1487c04864
6773985: OutOfMemory (PermGen space) under Linux / Firefox when switching bw. applets
art
parents:
439
diff
changeset
|
186 |
if ((newParent == XlibUtil.getRootWindow(gd.getScreen())) || |
1e1487c04864
6773985: OutOfMemory (PermGen space) under Linux / Firefox when switching bw. applets
art
parents:
439
diff
changeset
|
187 |
(newParent == XToolkit.getDefaultRootWindow())) |
1e1487c04864
6773985: OutOfMemory (PermGen space) under Linux / Firefox when switching bw. applets
art
parents:
439
diff
changeset
|
188 |
{ |
1e1487c04864
6773985: OutOfMemory (PermGen space) under Linux / Firefox when switching bw. applets
art
parents:
439
diff
changeset
|
189 |
// reparenting to root means XEmbed termination |
1e1487c04864
6773985: OutOfMemory (PermGen space) under Linux / Firefox when switching bw. applets
art
parents:
439
diff
changeset
|
190 |
active = false; |
1e1487c04864
6773985: OutOfMemory (PermGen space) under Linux / Firefox when switching bw. applets
art
parents:
439
diff
changeset
|
191 |
} else { |
1e1487c04864
6773985: OutOfMemory (PermGen space) under Linux / Firefox when switching bw. applets
art
parents:
439
diff
changeset
|
192 |
// continue XEmbed with a new parent |
1e1487c04864
6773985: OutOfMemory (PermGen space) under Linux / Firefox when switching bw. applets
art
parents:
439
diff
changeset
|
193 |
server = newParent; |
1e1487c04864
6773985: OutOfMemory (PermGen space) under Linux / Firefox when switching bw. applets
art
parents:
439
diff
changeset
|
194 |
embedded.notifyStarted(); |
1e1487c04864
6773985: OutOfMemory (PermGen space) under Linux / Firefox when switching bw. applets
art
parents:
439
diff
changeset
|
195 |
} |
1e1487c04864
6773985: OutOfMemory (PermGen space) under Linux / Firefox when switching bw. applets
art
parents:
439
diff
changeset
|
196 |
} |
2 | 197 |
} |
198 |
boolean requestFocus() { |
|
199 |
if (active && embedded.focusAllowedFor()) { |
|
200 |
sendMessage(server, XEMBED_REQUEST_FOCUS); |
|
201 |
return true; |
|
202 |
} |
|
203 |
return false; |
|
204 |
} |
|
205 |
void handleWindowFocusOut() { |
|
206 |
// fix for 6269309: it is possible that we call this method twice |
|
207 |
// (for example, when receiving XEMBED_WINDOW_DEACTIVATE and then |
|
208 |
// XEMBED_FOCUS_OUT client messages), so we first need to check if |
|
209 |
// embedded is an active window before sending WINDOW_LOST_FOCUS |
|
210 |
// to shared code |
|
13648
90effcfc064f
7124375: [macosx] Focus isn't transfered as expected between components
leonidr
parents:
5506
diff
changeset
|
211 |
if (XKeyboardFocusManagerPeer.getInstance().getCurrentFocusedWindow() == embedded.target) { |
4373
6a1c87e2876b
6903890: SWT_AWT focus issues when a dialog is shown/disposed, on X11
ant
parents:
3938
diff
changeset
|
212 |
embedded.handleWindowFocusOut(null, 0); |
2 | 213 |
} |
214 |
} |
|
215 |
||
216 |
long getEmbedder(XWindowPeer embedded, XClientMessageEvent info) { |
|
217 |
// Embedder is the parent of embedded. |
|
218 |
return XlibUtil.getParentWindow(embedded.getWindow()); |
|
219 |
} |
|
220 |
||
221 |
boolean isApplicationActive() { |
|
222 |
return applicationActive; |
|
223 |
} |
|
224 |
||
225 |
boolean isActive() { |
|
226 |
return active; |
|
227 |
} |
|
228 |
||
229 |
void traverseOutForward() { |
|
230 |
if (active) { |
|
231 |
sendMessage(server, XEMBED_FOCUS_NEXT); |
|
232 |
} |
|
233 |
} |
|
234 |
||
235 |
void traverseOutBackward() { |
|
236 |
if (active) { |
|
237 |
sendMessage(server, XEMBED_FOCUS_PREV); |
|
238 |
} |
|
239 |
} |
|
240 |
||
241 |
void registerAccelerator(AWTKeyStroke stroke, int id) { |
|
1974
1e1487c04864
6773985: OutOfMemory (PermGen space) under Linux / Firefox when switching bw. applets
art
parents:
439
diff
changeset
|
242 |
if (active) { |
1e1487c04864
6773985: OutOfMemory (PermGen space) under Linux / Firefox when switching bw. applets
art
parents:
439
diff
changeset
|
243 |
long sym = getX11KeySym(stroke); |
1e1487c04864
6773985: OutOfMemory (PermGen space) under Linux / Firefox when switching bw. applets
art
parents:
439
diff
changeset
|
244 |
long mods = getX11Mods(stroke); |
1e1487c04864
6773985: OutOfMemory (PermGen space) under Linux / Firefox when switching bw. applets
art
parents:
439
diff
changeset
|
245 |
sendMessage(server, XEMBED_REGISTER_ACCELERATOR, id, sym, mods); |
1e1487c04864
6773985: OutOfMemory (PermGen space) under Linux / Firefox when switching bw. applets
art
parents:
439
diff
changeset
|
246 |
} |
2 | 247 |
} |
248 |
void unregisterAccelerator(int id) { |
|
1974
1e1487c04864
6773985: OutOfMemory (PermGen space) under Linux / Firefox when switching bw. applets
art
parents:
439
diff
changeset
|
249 |
if (active) { |
1e1487c04864
6773985: OutOfMemory (PermGen space) under Linux / Firefox when switching bw. applets
art
parents:
439
diff
changeset
|
250 |
sendMessage(server, XEMBED_UNREGISTER_ACCELERATOR, id, 0, 0); |
1e1487c04864
6773985: OutOfMemory (PermGen space) under Linux / Firefox when switching bw. applets
art
parents:
439
diff
changeset
|
251 |
} |
2 | 252 |
} |
253 |
||
254 |
long getX11KeySym(AWTKeyStroke stroke) { |
|
255 |
XToolkit.awtLock(); |
|
256 |
try { |
|
257 |
return XWindow.getKeySymForAWTKeyCode(stroke.getKeyCode()); |
|
258 |
} finally { |
|
259 |
XToolkit.awtUnlock(); |
|
260 |
} |
|
261 |
} |
|
262 |
||
263 |
long getX11Mods(AWTKeyStroke stroke) { |
|
264 |
return XWindow.getXModifiers(stroke); |
|
265 |
} |
|
266 |
} |