author | pchelko |
Wed, 02 Oct 2013 16:58:13 +0400 | |
changeset 20448 | 0eef03207781 |
parent 20445 | 9440dd9e78d1 |
child 20457 | ecb935d774a3 |
permissions | -rw-r--r-- |
12047 | 1 |
/* |
15323
9087838098e6
8006417: JComboBox.showPopup(), hidePopup() fails in JRE 1.7 on OS X
alitvinov
parents:
14753
diff
changeset
|
2 |
* Copyright (c) 2011, 2013, Oracle and/or its affiliates. All rights reserved. |
12047 | 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; |
|
27 |
||
28 |
import java.awt.*; |
|
29 |
import java.awt.event.*; |
|
30 |
import java.awt.peer.*; |
|
31 |
import java.util.List; |
|
32 |
||
33 |
import javax.swing.*; |
|
34 |
||
35 |
import sun.awt.*; |
|
36 |
import sun.java2d.*; |
|
37 |
import sun.java2d.loops.Blit; |
|
38 |
import sun.java2d.loops.CompositeType; |
|
13233 | 39 |
import sun.java2d.pipe.Region; |
12047 | 40 |
import sun.util.logging.PlatformLogger; |
41 |
||
42 |
public class LWWindowPeer |
|
43 |
extends LWContainerPeer<Window, JComponent> |
|
18249 | 44 |
implements FramePeer, DialogPeer, FullScreenCapable, DisplayChangedListener, PlatformEventNotifier |
12047 | 45 |
{ |
20153 | 46 |
public enum PeerType { |
12047 | 47 |
SIMPLEWINDOW, |
48 |
FRAME, |
|
49 |
DIALOG, |
|
14753
a56a685d137f
7154778: [macosx] NSView-based implementation of sun.awt.EmbeddedFrame
serb
parents:
14647
diff
changeset
|
50 |
EMBEDDED_FRAME, |
15983
26a673dec5b2
8006406: lightweight embedding in other Java UI toolkits
ant
parents:
15331
diff
changeset
|
51 |
VIEW_EMBEDDED_FRAME, |
26a673dec5b2
8006406: lightweight embedding in other Java UI toolkits
ant
parents:
15331
diff
changeset
|
52 |
LW_FRAME |
12047 | 53 |
} |
54 |
||
12662
184d8d3b7fff
7145768: [macosx] Regression: failure in b11 of ModalDialogInFocusEventTest
ant
parents:
12640
diff
changeset
|
55 |
private static final PlatformLogger focusLog = PlatformLogger.getLogger("sun.lwawt.focus.LWWindowPeer"); |
12047 | 56 |
|
15331
410070becfef
8003173: [macosx] Fullscreen on Mac leaves an empty rectangle
serb
parents:
15323
diff
changeset
|
57 |
private final PlatformWindow platformWindow; |
12047 | 58 |
|
59 |
// Window bounds reported by the native system (as opposed to |
|
60 |
// regular bounds inherited from LWComponentPeer which are |
|
61 |
// requested by user and may haven't been applied yet because |
|
62 |
// of asynchronous requests to the windowing system) |
|
63 |
private int sysX; |
|
64 |
private int sysY; |
|
65 |
private int sysW; |
|
66 |
private int sysH; |
|
67 |
||
68 |
private static final int MINIMUM_WIDTH = 1; |
|
69 |
private static final int MINIMUM_HEIGHT = 1; |
|
70 |
||
71 |
private Insets insets = new Insets(0, 0, 0, 0); |
|
72 |
||
12816
b4cabffcb0de
7160293: [macosx] FileDialog appears on secondary display
dcherepanov
parents:
12663
diff
changeset
|
73 |
private GraphicsDevice graphicsDevice; |
12047 | 74 |
private GraphicsConfiguration graphicsConfig; |
75 |
||
76 |
private SurfaceData surfaceData; |
|
77 |
private final Object surfaceDataLock = new Object(); |
|
78 |
||
79 |
private volatile int windowState = Frame.NORMAL; |
|
80 |
||
13647
de61414bbcf2
7171045: [macosx] There are no enter or exit events reported against 8b39 for MouseEventsDuringDrag.
alexsch
parents:
13550
diff
changeset
|
81 |
// check that the mouse is over the window |
de61414bbcf2
7171045: [macosx] There are no enter or exit events reported against 8b39 for MouseEventsDuringDrag.
alexsch
parents:
13550
diff
changeset
|
82 |
private volatile boolean isMouseOver = false; |
de61414bbcf2
7171045: [macosx] There are no enter or exit events reported against 8b39 for MouseEventsDuringDrag.
alexsch
parents:
13550
diff
changeset
|
83 |
|
de61414bbcf2
7171045: [macosx] There are no enter or exit events reported against 8b39 for MouseEventsDuringDrag.
alexsch
parents:
13550
diff
changeset
|
84 |
// A peer where the last mouse event came to. Used by cursor manager to |
de61414bbcf2
7171045: [macosx] There are no enter or exit events reported against 8b39 for MouseEventsDuringDrag.
alexsch
parents:
13550
diff
changeset
|
85 |
// find the component under cursor |
20153 | 86 |
private static volatile LWComponentPeer<?, ?> lastCommonMouseEventPeer; |
13647
de61414bbcf2
7171045: [macosx] There are no enter or exit events reported against 8b39 for MouseEventsDuringDrag.
alexsch
parents:
13550
diff
changeset
|
87 |
|
12047 | 88 |
// A peer where the last mouse event came to. Used to generate |
13647
de61414bbcf2
7171045: [macosx] There are no enter or exit events reported against 8b39 for MouseEventsDuringDrag.
alexsch
parents:
13550
diff
changeset
|
89 |
// MOUSE_ENTERED/EXITED notifications |
20153 | 90 |
private volatile LWComponentPeer<?, ?> lastMouseEventPeer; |
12047 | 91 |
|
92 |
// Peers where all dragged/released events should come to, |
|
93 |
// depending on what mouse button is being dragged according to Cocoa |
|
20153 | 94 |
private static final LWComponentPeer<?, ?>[] mouseDownTarget = new LWComponentPeer<?, ?>[3]; |
12047 | 95 |
|
96 |
// A bitmask that indicates what mouse buttons produce MOUSE_CLICKED events |
|
97 |
// on MOUSE_RELEASE. Click events are only generated if there were no drag |
|
98 |
// events between MOUSE_PRESSED and MOUSE_RELEASED for particular button |
|
99 |
private static int mouseClickButtons = 0; |
|
100 |
||
101 |
private volatile boolean isOpaque = true; |
|
102 |
||
103 |
private static final Font DEFAULT_FONT = new Font("Lucida Grande", Font.PLAIN, 13); |
|
104 |
||
105 |
private static LWWindowPeer grabbingWindow; |
|
106 |
||
107 |
private volatile boolean skipNextFocusChange; |
|
108 |
||
13233 | 109 |
private static final Color nonOpaqueBackground = new Color(0, 0, 0, 0); |
110 |
||
13234
9437e5985d73
7124513: [macosx] Support NSTexturedBackgroundWindowMask/different titlebar styles to create unified toolbar
serb
parents:
13233
diff
changeset
|
111 |
private volatile boolean textured; |
9437e5985d73
7124513: [macosx] Support NSTexturedBackgroundWindowMask/different titlebar styles to create unified toolbar
serb
parents:
13233
diff
changeset
|
112 |
|
14753
a56a685d137f
7154778: [macosx] NSView-based implementation of sun.awt.EmbeddedFrame
serb
parents:
14647
diff
changeset
|
113 |
private final PeerType peerType; |
a56a685d137f
7154778: [macosx] NSView-based implementation of sun.awt.EmbeddedFrame
serb
parents:
14647
diff
changeset
|
114 |
|
18241 | 115 |
private final SecurityWarningWindow warningWindow; |
116 |
||
12047 | 117 |
/** |
118 |
* Current modal blocker or null. |
|
119 |
* |
|
120 |
* Synchronization: peerTreeLock. |
|
121 |
*/ |
|
122 |
private LWWindowPeer blocker; |
|
123 |
||
124 |
public LWWindowPeer(Window target, PlatformComponent platformComponent, |
|
14753
a56a685d137f
7154778: [macosx] NSView-based implementation of sun.awt.EmbeddedFrame
serb
parents:
14647
diff
changeset
|
125 |
PlatformWindow platformWindow, PeerType peerType) |
12047 | 126 |
{ |
127 |
super(target, platformComponent); |
|
128 |
this.platformWindow = platformWindow; |
|
14753
a56a685d137f
7154778: [macosx] NSView-based implementation of sun.awt.EmbeddedFrame
serb
parents:
14647
diff
changeset
|
129 |
this.peerType = peerType; |
12047 | 130 |
|
131 |
Window owner = target.getOwner(); |
|
20153 | 132 |
LWWindowPeer ownerPeer = owner == null ? null : |
133 |
(LWWindowPeer) AWTAccessor.getComponentAccessor().getPeer(owner); |
|
12047 | 134 |
PlatformWindow ownerDelegate = (ownerPeer != null) ? ownerPeer.getPlatformWindow() : null; |
135 |
||
136 |
// The delegate.initialize() needs a non-null GC on X11. |
|
137 |
GraphicsConfiguration gc = getTarget().getGraphicsConfiguration(); |
|
138 |
synchronized (getStateLock()) { |
|
139 |
// graphicsConfig should be updated according to the real window |
|
140 |
// bounds when the window is shown, see 4868278 |
|
141 |
this.graphicsConfig = gc; |
|
142 |
} |
|
143 |
||
144 |
if (!target.isFontSet()) { |
|
145 |
target.setFont(DEFAULT_FONT); |
|
146 |
} |
|
147 |
||
148 |
if (!target.isBackgroundSet()) { |
|
149 |
target.setBackground(SystemColor.window); |
|
150 |
} else { |
|
151 |
// first we check if user provided alpha for background. This is |
|
152 |
// similar to what Apple's Java do. |
|
153 |
// Since JDK7 we should rely on setOpacity() only. |
|
154 |
// this.opacity = c.getAlpha(); |
|
155 |
} |
|
156 |
||
157 |
if (!target.isForegroundSet()) { |
|
158 |
target.setForeground(SystemColor.windowText); |
|
159 |
// we should not call setForeground because it will call a repaint |
|
160 |
// which the peer may not be ready to do yet. |
|
161 |
} |
|
162 |
||
163 |
platformWindow.initialize(target, this, ownerDelegate); |
|
18241 | 164 |
|
165 |
// Init warning window(for applets) |
|
166 |
SecurityWarningWindow warn = null; |
|
20153 | 167 |
if (target.getWarningString() != null) { |
18241 | 168 |
// accessSystemTray permission allows to display TrayIcon, TrayIcon tooltip |
169 |
// and TrayIcon balloon windows without a warning window. |
|
20153 | 170 |
if (!AWTAccessor.getWindowAccessor().isTrayIconWindow(target)) { |
18241 | 171 |
LWToolkit toolkit = (LWToolkit)Toolkit.getDefaultToolkit(); |
172 |
warn = toolkit.createSecurityWarning(target, this); |
|
173 |
} |
|
174 |
} |
|
175 |
||
176 |
warningWindow = warn; |
|
12047 | 177 |
} |
178 |
||
179 |
@Override |
|
13143
31c70a66a053
7142091: [macosx] RFE: Refactoring of peer initialization/disposing
serb
parents:
12816
diff
changeset
|
180 |
void initializeImpl() { |
31c70a66a053
7142091: [macosx] RFE: Refactoring of peer initialization/disposing
serb
parents:
12816
diff
changeset
|
181 |
super.initializeImpl(); |
18241 | 182 |
|
183 |
||
12047 | 184 |
if (getTarget() instanceof Frame) { |
13143
31c70a66a053
7142091: [macosx] RFE: Refactoring of peer initialization/disposing
serb
parents:
12816
diff
changeset
|
185 |
setTitle(((Frame) getTarget()).getTitle()); |
31c70a66a053
7142091: [macosx] RFE: Refactoring of peer initialization/disposing
serb
parents:
12816
diff
changeset
|
186 |
setState(((Frame) getTarget()).getExtendedState()); |
12047 | 187 |
} else if (getTarget() instanceof Dialog) { |
13143
31c70a66a053
7142091: [macosx] RFE: Refactoring of peer initialization/disposing
serb
parents:
12816
diff
changeset
|
188 |
setTitle(((Dialog) getTarget()).getTitle()); |
12047 | 189 |
} |
190 |
||
16892 | 191 |
updateAlwaysOnTopState(); |
12047 | 192 |
updateMinimumSize(); |
193 |
||
13233 | 194 |
final Shape shape = getTarget().getShape(); |
195 |
if (shape != null) { |
|
196 |
applyShape(Region.getInstance(shape, null)); |
|
197 |
} |
|
198 |
||
13143
31c70a66a053
7142091: [macosx] RFE: Refactoring of peer initialization/disposing
serb
parents:
12816
diff
changeset
|
199 |
final float opacity = getTarget().getOpacity(); |
31c70a66a053
7142091: [macosx] RFE: Refactoring of peer initialization/disposing
serb
parents:
12816
diff
changeset
|
200 |
if (opacity < 1.0f) { |
31c70a66a053
7142091: [macosx] RFE: Refactoring of peer initialization/disposing
serb
parents:
12816
diff
changeset
|
201 |
setOpacity(opacity); |
31c70a66a053
7142091: [macosx] RFE: Refactoring of peer initialization/disposing
serb
parents:
12816
diff
changeset
|
202 |
} |
31c70a66a053
7142091: [macosx] RFE: Refactoring of peer initialization/disposing
serb
parents:
12816
diff
changeset
|
203 |
|
12047 | 204 |
setOpaque(getTarget().isOpaque()); |
205 |
||
206 |
updateInsets(platformWindow.getInsets()); |
|
13143
31c70a66a053
7142091: [macosx] RFE: Refactoring of peer initialization/disposing
serb
parents:
12816
diff
changeset
|
207 |
if (getSurfaceData() == null) { |
13233 | 208 |
replaceSurfaceData(false); |
13143
31c70a66a053
7142091: [macosx] RFE: Refactoring of peer initialization/disposing
serb
parents:
12816
diff
changeset
|
209 |
} |
17151
9bfcf2a592fc
8009012: [macosx] DisplayChangedListener is not implemented in LWWindowPeer/CGraphicsEnvironment
serb
parents:
17150
diff
changeset
|
210 |
activateDisplayListener(); |
12047 | 211 |
} |
212 |
||
213 |
// Just a helper method |
|
20153 | 214 |
@Override |
12047 | 215 |
public PlatformWindow getPlatformWindow() { |
216 |
return platformWindow; |
|
217 |
} |
|
218 |
||
219 |
@Override |
|
220 |
protected LWWindowPeer getWindowPeerOrSelf() { |
|
221 |
return this; |
|
222 |
} |
|
223 |
||
224 |
// ---- PEER METHODS ---- // |
|
225 |
||
226 |
@Override |
|
227 |
protected void disposeImpl() { |
|
17151
9bfcf2a592fc
8009012: [macosx] DisplayChangedListener is not implemented in LWWindowPeer/CGraphicsEnvironment
serb
parents:
17150
diff
changeset
|
228 |
deactivateDisplayListener(); |
12047 | 229 |
SurfaceData oldData = getSurfaceData(); |
230 |
synchronized (surfaceDataLock){ |
|
231 |
surfaceData = null; |
|
232 |
} |
|
233 |
if (oldData != null) { |
|
234 |
oldData.invalidate(); |
|
235 |
} |
|
236 |
if (isGrabbing()) { |
|
237 |
ungrab(); |
|
238 |
} |
|
18241 | 239 |
if (warningWindow != null) { |
240 |
warningWindow.dispose(); |
|
241 |
} |
|
242 |
||
12047 | 243 |
platformWindow.dispose(); |
244 |
super.disposeImpl(); |
|
245 |
} |
|
246 |
||
247 |
@Override |
|
13143
31c70a66a053
7142091: [macosx] RFE: Refactoring of peer initialization/disposing
serb
parents:
12816
diff
changeset
|
248 |
protected void setVisibleImpl(final boolean visible) { |
18241 | 249 |
if (!visible && warningWindow != null) { |
250 |
warningWindow.setVisible(false, false); |
|
251 |
} |
|
252 |
||
13143
31c70a66a053
7142091: [macosx] RFE: Refactoring of peer initialization/disposing
serb
parents:
12816
diff
changeset
|
253 |
super.setVisibleImpl(visible); |
12047 | 254 |
// TODO: update graphicsConfig, see 4868278 |
13143
31c70a66a053
7142091: [macosx] RFE: Refactoring of peer initialization/disposing
serb
parents:
12816
diff
changeset
|
255 |
platformWindow.setVisible(visible); |
31c70a66a053
7142091: [macosx] RFE: Refactoring of peer initialization/disposing
serb
parents:
12816
diff
changeset
|
256 |
if (isSimpleWindow()) { |
13648
90effcfc064f
7124375: [macosx] Focus isn't transfered as expected between components
leonidr
parents:
13647
diff
changeset
|
257 |
KeyboardFocusManagerPeer kfmPeer = LWKeyboardFocusManagerPeer.getInstance(); |
12047 | 258 |
|
13143
31c70a66a053
7142091: [macosx] RFE: Refactoring of peer initialization/disposing
serb
parents:
12816
diff
changeset
|
259 |
if (visible) { |
31c70a66a053
7142091: [macosx] RFE: Refactoring of peer initialization/disposing
serb
parents:
12816
diff
changeset
|
260 |
if (!getTarget().isAutoRequestFocus()) { |
31c70a66a053
7142091: [macosx] RFE: Refactoring of peer initialization/disposing
serb
parents:
12816
diff
changeset
|
261 |
return; |
31c70a66a053
7142091: [macosx] RFE: Refactoring of peer initialization/disposing
serb
parents:
12816
diff
changeset
|
262 |
} else { |
31c70a66a053
7142091: [macosx] RFE: Refactoring of peer initialization/disposing
serb
parents:
12816
diff
changeset
|
263 |
requestWindowFocus(CausedFocusEvent.Cause.ACTIVATION); |
31c70a66a053
7142091: [macosx] RFE: Refactoring of peer initialization/disposing
serb
parents:
12816
diff
changeset
|
264 |
} |
31c70a66a053
7142091: [macosx] RFE: Refactoring of peer initialization/disposing
serb
parents:
12816
diff
changeset
|
265 |
// Focus the owner in case this window is focused. |
13648
90effcfc064f
7124375: [macosx] Focus isn't transfered as expected between components
leonidr
parents:
13647
diff
changeset
|
266 |
} else if (kfmPeer.getCurrentFocusedWindow() == getTarget()) { |
13143
31c70a66a053
7142091: [macosx] RFE: Refactoring of peer initialization/disposing
serb
parents:
12816
diff
changeset
|
267 |
// Transfer focus to the owner. |
31c70a66a053
7142091: [macosx] RFE: Refactoring of peer initialization/disposing
serb
parents:
12816
diff
changeset
|
268 |
LWWindowPeer owner = getOwnerFrameDialog(LWWindowPeer.this); |
31c70a66a053
7142091: [macosx] RFE: Refactoring of peer initialization/disposing
serb
parents:
12816
diff
changeset
|
269 |
if (owner != null) { |
31c70a66a053
7142091: [macosx] RFE: Refactoring of peer initialization/disposing
serb
parents:
12816
diff
changeset
|
270 |
owner.requestWindowFocus(CausedFocusEvent.Cause.ACTIVATION); |
12047 | 271 |
} |
272 |
} |
|
13143
31c70a66a053
7142091: [macosx] RFE: Refactoring of peer initialization/disposing
serb
parents:
12816
diff
changeset
|
273 |
} |
12047 | 274 |
} |
275 |
||
276 |
@Override |
|
14647
bacc2d4f4b27
7124552: [macosx] NullPointerException in getBufferStrategy()
serb
parents:
14311
diff
changeset
|
277 |
public final GraphicsConfiguration getGraphicsConfiguration() { |
bacc2d4f4b27
7124552: [macosx] NullPointerException in getBufferStrategy()
serb
parents:
14311
diff
changeset
|
278 |
synchronized (getStateLock()) { |
bacc2d4f4b27
7124552: [macosx] NullPointerException in getBufferStrategy()
serb
parents:
14311
diff
changeset
|
279 |
return graphicsConfig; |
bacc2d4f4b27
7124552: [macosx] NullPointerException in getBufferStrategy()
serb
parents:
14311
diff
changeset
|
280 |
} |
12047 | 281 |
} |
282 |
||
283 |
@Override |
|
284 |
public boolean updateGraphicsData(GraphicsConfiguration gc) { |
|
285 |
setGraphicsConfig(gc); |
|
286 |
return false; |
|
287 |
} |
|
288 |
||
289 |
protected final Graphics getOnscreenGraphics(Color fg, Color bg, Font f) { |
|
290 |
if (getSurfaceData() == null) { |
|
291 |
return null; |
|
292 |
} |
|
293 |
if (fg == null) { |
|
294 |
fg = SystemColor.windowText; |
|
295 |
} |
|
296 |
if (bg == null) { |
|
297 |
bg = SystemColor.window; |
|
298 |
} |
|
299 |
if (f == null) { |
|
300 |
f = DEFAULT_FONT; |
|
301 |
} |
|
302 |
return platformWindow.transformGraphics(new SunGraphics2D(getSurfaceData(), fg, bg, f)); |
|
303 |
} |
|
304 |
||
305 |
@Override |
|
306 |
public void setBounds(int x, int y, int w, int h, int op) { |
|
14753
a56a685d137f
7154778: [macosx] NSView-based implementation of sun.awt.EmbeddedFrame
serb
parents:
14647
diff
changeset
|
307 |
|
a56a685d137f
7154778: [macosx] NSView-based implementation of sun.awt.EmbeddedFrame
serb
parents:
14647
diff
changeset
|
308 |
if((op & NO_EMBEDDED_CHECK) == 0 && getPeerType() == PeerType.VIEW_EMBEDDED_FRAME) { |
a56a685d137f
7154778: [macosx] NSView-based implementation of sun.awt.EmbeddedFrame
serb
parents:
14647
diff
changeset
|
309 |
return; |
a56a685d137f
7154778: [macosx] NSView-based implementation of sun.awt.EmbeddedFrame
serb
parents:
14647
diff
changeset
|
310 |
} |
a56a685d137f
7154778: [macosx] NSView-based implementation of sun.awt.EmbeddedFrame
serb
parents:
14647
diff
changeset
|
311 |
|
12047 | 312 |
if ((op & SET_CLIENT_SIZE) != 0) { |
313 |
// SET_CLIENT_SIZE is only applicable to window peers, so handle it here |
|
314 |
// instead of pulling 'insets' field up to LWComponentPeer |
|
315 |
// no need to add insets since Window's notion of width and height includes insets. |
|
316 |
op &= ~SET_CLIENT_SIZE; |
|
317 |
op |= SET_SIZE; |
|
318 |
} |
|
319 |
||
320 |
if (w < MINIMUM_WIDTH) { |
|
321 |
w = MINIMUM_WIDTH; |
|
322 |
} |
|
323 |
if (h < MINIMUM_HEIGHT) { |
|
324 |
h = MINIMUM_HEIGHT; |
|
325 |
} |
|
326 |
||
14647
bacc2d4f4b27
7124552: [macosx] NullPointerException in getBufferStrategy()
serb
parents:
14311
diff
changeset
|
327 |
final int maxW = getLWGC().getMaxTextureWidth(); |
bacc2d4f4b27
7124552: [macosx] NullPointerException in getBufferStrategy()
serb
parents:
14311
diff
changeset
|
328 |
final int maxH = getLWGC().getMaxTextureHeight(); |
13550
648dd6fa0dee
7160609: [macosx] JDK crash in libjvm.dylib ( C [GeForceGLDriver+0x675a] gldAttachDrawable+0x941)
anthony
parents:
13234
diff
changeset
|
329 |
|
14647
bacc2d4f4b27
7124552: [macosx] NullPointerException in getBufferStrategy()
serb
parents:
14311
diff
changeset
|
330 |
if (w > maxW) { |
bacc2d4f4b27
7124552: [macosx] NullPointerException in getBufferStrategy()
serb
parents:
14311
diff
changeset
|
331 |
w = maxW; |
bacc2d4f4b27
7124552: [macosx] NullPointerException in getBufferStrategy()
serb
parents:
14311
diff
changeset
|
332 |
} |
bacc2d4f4b27
7124552: [macosx] NullPointerException in getBufferStrategy()
serb
parents:
14311
diff
changeset
|
333 |
if (h > maxH) { |
bacc2d4f4b27
7124552: [macosx] NullPointerException in getBufferStrategy()
serb
parents:
14311
diff
changeset
|
334 |
h = maxH; |
13550
648dd6fa0dee
7160609: [macosx] JDK crash in libjvm.dylib ( C [GeForceGLDriver+0x675a] gldAttachDrawable+0x941)
anthony
parents:
13234
diff
changeset
|
335 |
} |
648dd6fa0dee
7160609: [macosx] JDK crash in libjvm.dylib ( C [GeForceGLDriver+0x675a] gldAttachDrawable+0x941)
anthony
parents:
13234
diff
changeset
|
336 |
|
12047 | 337 |
// Don't post ComponentMoved/Resized and Paint events |
338 |
// until we've got a notification from the delegate |
|
339 |
setBounds(x, y, w, h, op, false, false); |
|
340 |
// Get updated bounds, so we don't have to handle 'op' here manually |
|
341 |
Rectangle r = getBounds(); |
|
342 |
platformWindow.setBounds(r.x, r.y, r.width, r.height); |
|
343 |
} |
|
344 |
||
345 |
@Override |
|
346 |
public Point getLocationOnScreen() { |
|
347 |
return platformWindow.getLocationOnScreen(); |
|
348 |
} |
|
349 |
||
350 |
/** |
|
351 |
* Overridden from LWContainerPeer to return the correct insets. |
|
352 |
* Insets are queried from the delegate and are kept up to date by |
|
353 |
* requiering when needed (i.e. when the window geometry is changed). |
|
354 |
*/ |
|
355 |
@Override |
|
356 |
public Insets getInsets() { |
|
357 |
synchronized (getStateLock()) { |
|
358 |
return insets; |
|
359 |
} |
|
360 |
} |
|
361 |
||
362 |
@Override |
|
363 |
public FontMetrics getFontMetrics(Font f) { |
|
364 |
// TODO: check for "use platform metrics" settings |
|
365 |
return platformWindow.getFontMetrics(f); |
|
366 |
} |
|
367 |
||
368 |
@Override |
|
369 |
public void toFront() { |
|
370 |
platformWindow.toFront(); |
|
371 |
} |
|
372 |
||
373 |
@Override |
|
374 |
public void toBack() { |
|
375 |
platformWindow.toBack(); |
|
376 |
} |
|
377 |
||
378 |
@Override |
|
379 |
public void setZOrder(ComponentPeer above) { |
|
380 |
throw new RuntimeException("not implemented"); |
|
381 |
} |
|
382 |
||
383 |
@Override |
|
16892 | 384 |
public void updateAlwaysOnTopState() { |
385 |
platformWindow.setAlwaysOnTop(getTarget().isAlwaysOnTop()); |
|
12047 | 386 |
} |
387 |
||
388 |
@Override |
|
389 |
public void updateFocusableWindowState() { |
|
390 |
platformWindow.updateFocusableWindowState(); |
|
391 |
} |
|
392 |
||
393 |
@Override |
|
394 |
public void setModalBlocked(Dialog blocker, boolean blocked) { |
|
395 |
synchronized (getPeerTreeLock()) { |
|
20445
9440dd9e78d1
7124363: [macosx] ClassCastException: CFileDialog cannot be cast to LWWindowPeer
pchelko
parents:
20153
diff
changeset
|
396 |
ComponentPeer peer = AWTAccessor.getComponentAccessor().getPeer(blocker); |
9440dd9e78d1
7124363: [macosx] ClassCastException: CFileDialog cannot be cast to LWWindowPeer
pchelko
parents:
20153
diff
changeset
|
397 |
if (blocked && (peer instanceof LWWindowPeer)) { |
9440dd9e78d1
7124363: [macosx] ClassCastException: CFileDialog cannot be cast to LWWindowPeer
pchelko
parents:
20153
diff
changeset
|
398 |
this.blocker = (LWWindowPeer) peer; |
9440dd9e78d1
7124363: [macosx] ClassCastException: CFileDialog cannot be cast to LWWindowPeer
pchelko
parents:
20153
diff
changeset
|
399 |
} else { |
9440dd9e78d1
7124363: [macosx] ClassCastException: CFileDialog cannot be cast to LWWindowPeer
pchelko
parents:
20153
diff
changeset
|
400 |
this.blocker = null; |
9440dd9e78d1
7124363: [macosx] ClassCastException: CFileDialog cannot be cast to LWWindowPeer
pchelko
parents:
20153
diff
changeset
|
401 |
} |
12047 | 402 |
} |
12640 | 403 |
|
404 |
platformWindow.setModalBlocked(blocked); |
|
12047 | 405 |
} |
406 |
||
407 |
@Override |
|
408 |
public void updateMinimumSize() { |
|
13550
648dd6fa0dee
7160609: [macosx] JDK crash in libjvm.dylib ( C [GeForceGLDriver+0x675a] gldAttachDrawable+0x941)
anthony
parents:
13234
diff
changeset
|
409 |
final Dimension min; |
12047 | 410 |
if (getTarget().isMinimumSizeSet()) { |
13550
648dd6fa0dee
7160609: [macosx] JDK crash in libjvm.dylib ( C [GeForceGLDriver+0x675a] gldAttachDrawable+0x941)
anthony
parents:
13234
diff
changeset
|
411 |
min = getTarget().getMinimumSize(); |
648dd6fa0dee
7160609: [macosx] JDK crash in libjvm.dylib ( C [GeForceGLDriver+0x675a] gldAttachDrawable+0x941)
anthony
parents:
13234
diff
changeset
|
412 |
min.width = Math.max(min.width, MINIMUM_WIDTH); |
648dd6fa0dee
7160609: [macosx] JDK crash in libjvm.dylib ( C [GeForceGLDriver+0x675a] gldAttachDrawable+0x941)
anthony
parents:
13234
diff
changeset
|
413 |
min.height = Math.max(min.height, MINIMUM_HEIGHT); |
648dd6fa0dee
7160609: [macosx] JDK crash in libjvm.dylib ( C [GeForceGLDriver+0x675a] gldAttachDrawable+0x941)
anthony
parents:
13234
diff
changeset
|
414 |
} else { |
648dd6fa0dee
7160609: [macosx] JDK crash in libjvm.dylib ( C [GeForceGLDriver+0x675a] gldAttachDrawable+0x941)
anthony
parents:
13234
diff
changeset
|
415 |
min = new Dimension(MINIMUM_WIDTH, MINIMUM_HEIGHT); |
12047 | 416 |
} |
13550
648dd6fa0dee
7160609: [macosx] JDK crash in libjvm.dylib ( C [GeForceGLDriver+0x675a] gldAttachDrawable+0x941)
anthony
parents:
13234
diff
changeset
|
417 |
|
648dd6fa0dee
7160609: [macosx] JDK crash in libjvm.dylib ( C [GeForceGLDriver+0x675a] gldAttachDrawable+0x941)
anthony
parents:
13234
diff
changeset
|
418 |
final Dimension max; |
648dd6fa0dee
7160609: [macosx] JDK crash in libjvm.dylib ( C [GeForceGLDriver+0x675a] gldAttachDrawable+0x941)
anthony
parents:
13234
diff
changeset
|
419 |
if (getTarget().isMaximumSizeSet()) { |
648dd6fa0dee
7160609: [macosx] JDK crash in libjvm.dylib ( C [GeForceGLDriver+0x675a] gldAttachDrawable+0x941)
anthony
parents:
13234
diff
changeset
|
420 |
max = getTarget().getMaximumSize(); |
14647
bacc2d4f4b27
7124552: [macosx] NullPointerException in getBufferStrategy()
serb
parents:
14311
diff
changeset
|
421 |
max.width = Math.min(max.width, getLWGC().getMaxTextureWidth()); |
bacc2d4f4b27
7124552: [macosx] NullPointerException in getBufferStrategy()
serb
parents:
14311
diff
changeset
|
422 |
max.height = Math.min(max.height, getLWGC().getMaxTextureHeight()); |
13550
648dd6fa0dee
7160609: [macosx] JDK crash in libjvm.dylib ( C [GeForceGLDriver+0x675a] gldAttachDrawable+0x941)
anthony
parents:
13234
diff
changeset
|
423 |
} else { |
14647
bacc2d4f4b27
7124552: [macosx] NullPointerException in getBufferStrategy()
serb
parents:
14311
diff
changeset
|
424 |
max = new Dimension(getLWGC().getMaxTextureWidth(), |
bacc2d4f4b27
7124552: [macosx] NullPointerException in getBufferStrategy()
serb
parents:
14311
diff
changeset
|
425 |
getLWGC().getMaxTextureHeight()); |
13550
648dd6fa0dee
7160609: [macosx] JDK crash in libjvm.dylib ( C [GeForceGLDriver+0x675a] gldAttachDrawable+0x941)
anthony
parents:
13234
diff
changeset
|
426 |
} |
648dd6fa0dee
7160609: [macosx] JDK crash in libjvm.dylib ( C [GeForceGLDriver+0x675a] gldAttachDrawable+0x941)
anthony
parents:
13234
diff
changeset
|
427 |
|
648dd6fa0dee
7160609: [macosx] JDK crash in libjvm.dylib ( C [GeForceGLDriver+0x675a] gldAttachDrawable+0x941)
anthony
parents:
13234
diff
changeset
|
428 |
platformWindow.setSizeConstraints(min.width, min.height, max.width, max.height); |
12047 | 429 |
} |
430 |
||
431 |
@Override |
|
432 |
public void updateIconImages() { |
|
433 |
getPlatformWindow().updateIconImages(); |
|
434 |
} |
|
435 |
||
436 |
@Override |
|
437 |
public void setOpacity(float opacity) { |
|
438 |
getPlatformWindow().setOpacity(opacity); |
|
439 |
repaintPeer(); |
|
440 |
} |
|
441 |
||
442 |
@Override |
|
443 |
public final void setOpaque(final boolean isOpaque) { |
|
444 |
if (this.isOpaque != isOpaque) { |
|
445 |
this.isOpaque = isOpaque; |
|
13233 | 446 |
updateOpaque(); |
12047 | 447 |
} |
448 |
} |
|
449 |
||
13233 | 450 |
private void updateOpaque() { |
451 |
getPlatformWindow().setOpaque(!isTranslucent()); |
|
452 |
replaceSurfaceData(false); |
|
453 |
repaintPeer(); |
|
12047 | 454 |
} |
455 |
||
456 |
@Override |
|
457 |
public void updateWindow() { |
|
13233 | 458 |
} |
459 |
||
13234
9437e5985d73
7124513: [macosx] Support NSTexturedBackgroundWindowMask/different titlebar styles to create unified toolbar
serb
parents:
13233
diff
changeset
|
460 |
public final boolean isTextured() { |
9437e5985d73
7124513: [macosx] Support NSTexturedBackgroundWindowMask/different titlebar styles to create unified toolbar
serb
parents:
13233
diff
changeset
|
461 |
return textured; |
9437e5985d73
7124513: [macosx] Support NSTexturedBackgroundWindowMask/different titlebar styles to create unified toolbar
serb
parents:
13233
diff
changeset
|
462 |
} |
9437e5985d73
7124513: [macosx] Support NSTexturedBackgroundWindowMask/different titlebar styles to create unified toolbar
serb
parents:
13233
diff
changeset
|
463 |
|
9437e5985d73
7124513: [macosx] Support NSTexturedBackgroundWindowMask/different titlebar styles to create unified toolbar
serb
parents:
13233
diff
changeset
|
464 |
public final void setTextured(final boolean isTextured) { |
9437e5985d73
7124513: [macosx] Support NSTexturedBackgroundWindowMask/different titlebar styles to create unified toolbar
serb
parents:
13233
diff
changeset
|
465 |
textured = isTextured; |
9437e5985d73
7124513: [macosx] Support NSTexturedBackgroundWindowMask/different titlebar styles to create unified toolbar
serb
parents:
13233
diff
changeset
|
466 |
} |
9437e5985d73
7124513: [macosx] Support NSTexturedBackgroundWindowMask/different titlebar styles to create unified toolbar
serb
parents:
13233
diff
changeset
|
467 |
|
20153 | 468 |
@Override |
13233 | 469 |
public final boolean isTranslucent() { |
470 |
synchronized (getStateLock()) { |
|
13234
9437e5985d73
7124513: [macosx] Support NSTexturedBackgroundWindowMask/different titlebar styles to create unified toolbar
serb
parents:
13233
diff
changeset
|
471 |
/* |
9437e5985d73
7124513: [macosx] Support NSTexturedBackgroundWindowMask/different titlebar styles to create unified toolbar
serb
parents:
13233
diff
changeset
|
472 |
* Textured window is a special case of translucent window. |
9437e5985d73
7124513: [macosx] Support NSTexturedBackgroundWindowMask/different titlebar styles to create unified toolbar
serb
parents:
13233
diff
changeset
|
473 |
* The difference is only in nswindow background. So when we set |
9437e5985d73
7124513: [macosx] Support NSTexturedBackgroundWindowMask/different titlebar styles to create unified toolbar
serb
parents:
13233
diff
changeset
|
474 |
* texture property our peer became fully translucent. It doesn't |
9437e5985d73
7124513: [macosx] Support NSTexturedBackgroundWindowMask/different titlebar styles to create unified toolbar
serb
parents:
13233
diff
changeset
|
475 |
* fill background, create non opaque backbuffers and layer etc. |
9437e5985d73
7124513: [macosx] Support NSTexturedBackgroundWindowMask/different titlebar styles to create unified toolbar
serb
parents:
13233
diff
changeset
|
476 |
*/ |
9437e5985d73
7124513: [macosx] Support NSTexturedBackgroundWindowMask/different titlebar styles to create unified toolbar
serb
parents:
13233
diff
changeset
|
477 |
return !isOpaque || isShaped() || isTextured(); |
13233 | 478 |
} |
479 |
} |
|
480 |
||
481 |
@Override |
|
482 |
final void applyShapeImpl(final Region shape) { |
|
483 |
super.applyShapeImpl(shape); |
|
484 |
updateOpaque(); |
|
12047 | 485 |
} |
486 |
||
487 |
@Override |
|
488 |
public void repositionSecurityWarning() { |
|
18241 | 489 |
if (warningWindow != null) { |
490 |
AWTAccessor.ComponentAccessor compAccessor = AWTAccessor.getComponentAccessor(); |
|
491 |
Window target = getTarget(); |
|
492 |
int x = compAccessor.getX(target); |
|
493 |
int y = compAccessor.getY(target); |
|
494 |
int width = compAccessor.getWidth(target); |
|
495 |
int height = compAccessor.getHeight(target); |
|
496 |
warningWindow.reposition(x, y, width, height); |
|
497 |
} |
|
12047 | 498 |
} |
499 |
||
500 |
// ---- FRAME PEER METHODS ---- // |
|
501 |
||
502 |
@Override // FramePeer and DialogPeer |
|
503 |
public void setTitle(String title) { |
|
504 |
platformWindow.setTitle(title == null ? "" : title); |
|
505 |
} |
|
506 |
||
507 |
@Override |
|
508 |
public void setMenuBar(MenuBar mb) { |
|
509 |
platformWindow.setMenuBar(mb); |
|
510 |
} |
|
511 |
||
512 |
@Override // FramePeer and DialogPeer |
|
513 |
public void setResizable(boolean resizable) { |
|
514 |
platformWindow.setResizable(resizable); |
|
515 |
} |
|
516 |
||
517 |
@Override |
|
518 |
public void setState(int state) { |
|
519 |
platformWindow.setWindowState(state); |
|
520 |
} |
|
521 |
||
522 |
@Override |
|
523 |
public int getState() { |
|
524 |
return windowState; |
|
525 |
} |
|
526 |
||
527 |
@Override |
|
528 |
public void setMaximizedBounds(Rectangle bounds) { |
|
529 |
// TODO: not implemented |
|
530 |
} |
|
531 |
||
532 |
@Override |
|
533 |
public void setBoundsPrivate(int x, int y, int width, int height) { |
|
534 |
setBounds(x, y, width, height, SET_BOUNDS | NO_EMBEDDED_CHECK); |
|
535 |
} |
|
536 |
||
537 |
@Override |
|
538 |
public Rectangle getBoundsPrivate() { |
|
539 |
throw new RuntimeException("not implemented"); |
|
540 |
} |
|
541 |
||
542 |
// ---- DIALOG PEER METHODS ---- // |
|
543 |
||
544 |
@Override |
|
545 |
public void blockWindows(List<Window> windows) { |
|
546 |
//TODO: LWX will probably need some collectJavaToplevels to speed this up |
|
547 |
for (Window w : windows) { |
|
20153 | 548 |
WindowPeer wp = |
549 |
(WindowPeer) AWTAccessor.getComponentAccessor().getPeer(w); |
|
12047 | 550 |
if (wp != null) { |
551 |
wp.setModalBlocked((Dialog)getTarget(), true); |
|
552 |
} |
|
553 |
} |
|
554 |
} |
|
555 |
||
556 |
// ---- PEER NOTIFICATIONS ---- // |
|
557 |
||
18241 | 558 |
@Override |
12047 | 559 |
public void notifyIconify(boolean iconify) { |
560 |
//The toplevel target is Frame and states are applicable to it. |
|
561 |
//Otherwise, the target is Window and it don't have state property. |
|
562 |
//Hopefully, no such events are posted in the queue so consider the |
|
563 |
//target as Frame in all cases. |
|
564 |
||
565 |
// REMIND: should we send it anyway if the state not changed since last |
|
566 |
// time? |
|
567 |
WindowEvent iconifyEvent = new WindowEvent(getTarget(), |
|
568 |
iconify ? WindowEvent.WINDOW_ICONIFIED |
|
569 |
: WindowEvent.WINDOW_DEICONIFIED); |
|
570 |
postEvent(iconifyEvent); |
|
571 |
||
572 |
int newWindowState = iconify ? Frame.ICONIFIED : Frame.NORMAL; |
|
573 |
postWindowStateChangedEvent(newWindowState); |
|
574 |
||
575 |
// REMIND: RepaintManager doesn't repaint iconified windows and |
|
576 |
// hence ignores any repaint request during deiconification. |
|
577 |
// So, we need to repaint window explicitly when it becomes normal. |
|
578 |
if (!iconify) { |
|
579 |
repaintPeer(); |
|
580 |
} |
|
581 |
} |
|
582 |
||
18241 | 583 |
@Override |
12047 | 584 |
public void notifyZoom(boolean isZoomed) { |
585 |
int newWindowState = isZoomed ? Frame.MAXIMIZED_BOTH : Frame.NORMAL; |
|
586 |
postWindowStateChangedEvent(newWindowState); |
|
587 |
} |
|
588 |
||
589 |
/** |
|
14306
8d823e84507a
7198229: Painting during resizing of the frame should be more smooth
serb
parents:
13652
diff
changeset
|
590 |
* Called by the {@code PlatformWindow} when any part of the window should |
8d823e84507a
7198229: Painting during resizing of the frame should be more smooth
serb
parents:
13652
diff
changeset
|
591 |
* be repainted. |
12047 | 592 |
*/ |
18241 | 593 |
@Override |
594 |
public void notifyExpose(final Rectangle r) { |
|
14306
8d823e84507a
7198229: Painting during resizing of the frame should be more smooth
serb
parents:
13652
diff
changeset
|
595 |
repaintPeer(r); |
12047 | 596 |
} |
597 |
||
598 |
/** |
|
14306
8d823e84507a
7198229: Painting during resizing of the frame should be more smooth
serb
parents:
13652
diff
changeset
|
599 |
* Called by the {@code PlatformWindow} when this window is moved/resized by |
15331
410070becfef
8003173: [macosx] Fullscreen on Mac leaves an empty rectangle
serb
parents:
15323
diff
changeset
|
600 |
* user or window insets are changed. There's no notifyReshape() in |
410070becfef
8003173: [macosx] Fullscreen on Mac leaves an empty rectangle
serb
parents:
15323
diff
changeset
|
601 |
* LWComponentPeer as the only components which could be resized by user are |
410070becfef
8003173: [macosx] Fullscreen on Mac leaves an empty rectangle
serb
parents:
15323
diff
changeset
|
602 |
* top-level windows. |
12047 | 603 |
*/ |
18241 | 604 |
@Override |
605 |
public void notifyReshape(int x, int y, int w, int h) { |
|
14306
8d823e84507a
7198229: Painting during resizing of the frame should be more smooth
serb
parents:
13652
diff
changeset
|
606 |
final boolean moved; |
8d823e84507a
7198229: Painting during resizing of the frame should be more smooth
serb
parents:
13652
diff
changeset
|
607 |
final boolean resized; |
15331
410070becfef
8003173: [macosx] Fullscreen on Mac leaves an empty rectangle
serb
parents:
15323
diff
changeset
|
608 |
final boolean invalid = updateInsets(platformWindow.getInsets()); |
12047 | 609 |
synchronized (getStateLock()) { |
610 |
moved = (x != sysX) || (y != sysY); |
|
611 |
resized = (w != sysW) || (h != sysH); |
|
612 |
sysX = x; |
|
613 |
sysY = y; |
|
614 |
sysW = w; |
|
615 |
sysH = h; |
|
616 |
} |
|
617 |
||
618 |
// Check if anything changed |
|
15331
410070becfef
8003173: [macosx] Fullscreen on Mac leaves an empty rectangle
serb
parents:
15323
diff
changeset
|
619 |
if (!moved && !resized && !invalid) { |
12047 | 620 |
return; |
621 |
} |
|
622 |
// First, update peer's bounds |
|
623 |
setBounds(x, y, w, h, SET_BOUNDS, false, false); |
|
624 |
||
625 |
// Second, update the graphics config and surface data |
|
16840
64446d4710c4
8000629: [macosx] Blurry rendering with Java 7 on Retina display
serb
parents:
16839
diff
changeset
|
626 |
final boolean isNewDevice = updateGraphicsDevice(); |
64446d4710c4
8000629: [macosx] Blurry rendering with Java 7 on Retina display
serb
parents:
16839
diff
changeset
|
627 |
if (resized || isNewDevice) { |
12047 | 628 |
replaceSurfaceData(); |
629 |
} |
|
630 |
||
14306
8d823e84507a
7198229: Painting during resizing of the frame should be more smooth
serb
parents:
13652
diff
changeset
|
631 |
// Third, COMPONENT_MOVED/COMPONENT_RESIZED/PAINT events |
15331
410070becfef
8003173: [macosx] Fullscreen on Mac leaves an empty rectangle
serb
parents:
15323
diff
changeset
|
632 |
if (moved || invalid) { |
12047 | 633 |
handleMove(x, y, true); |
634 |
} |
|
16840
64446d4710c4
8000629: [macosx] Blurry rendering with Java 7 on Retina display
serb
parents:
16839
diff
changeset
|
635 |
if (resized || invalid || isNewDevice) { |
14306
8d823e84507a
7198229: Painting during resizing of the frame should be more smooth
serb
parents:
13652
diff
changeset
|
636 |
handleResize(w, h, true); |
8d823e84507a
7198229: Painting during resizing of the frame should be more smooth
serb
parents:
13652
diff
changeset
|
637 |
repaintPeer(); |
12047 | 638 |
} |
18241 | 639 |
|
640 |
repositionSecurityWarning(); |
|
12047 | 641 |
} |
642 |
||
643 |
private void clearBackground(final int w, final int h) { |
|
644 |
final Graphics g = getOnscreenGraphics(getForeground(), getBackground(), |
|
645 |
getFont()); |
|
646 |
if (g != null) { |
|
647 |
try { |
|
13233 | 648 |
if (g instanceof Graphics2D) { |
649 |
((Graphics2D) g).setComposite(AlphaComposite.Src); |
|
650 |
} |
|
651 |
if (isTranslucent()) { |
|
652 |
g.setColor(nonOpaqueBackground); |
|
653 |
g.fillRect(0, 0, w, h); |
|
654 |
} |
|
13234
9437e5985d73
7124513: [macosx] Support NSTexturedBackgroundWindowMask/different titlebar styles to create unified toolbar
serb
parents:
13233
diff
changeset
|
655 |
if (!isTextured()) { |
9437e5985d73
7124513: [macosx] Support NSTexturedBackgroundWindowMask/different titlebar styles to create unified toolbar
serb
parents:
13233
diff
changeset
|
656 |
if (g instanceof SunGraphics2D) { |
16840
64446d4710c4
8000629: [macosx] Blurry rendering with Java 7 on Retina display
serb
parents:
16839
diff
changeset
|
657 |
((SunGraphics2D) g).constrain(0, 0, w, h, getRegion()); |
13234
9437e5985d73
7124513: [macosx] Support NSTexturedBackgroundWindowMask/different titlebar styles to create unified toolbar
serb
parents:
13233
diff
changeset
|
658 |
} |
9437e5985d73
7124513: [macosx] Support NSTexturedBackgroundWindowMask/different titlebar styles to create unified toolbar
serb
parents:
13233
diff
changeset
|
659 |
g.setColor(getBackground()); |
9437e5985d73
7124513: [macosx] Support NSTexturedBackgroundWindowMask/different titlebar styles to create unified toolbar
serb
parents:
13233
diff
changeset
|
660 |
g.fillRect(0, 0, w, h); |
13233 | 661 |
} |
12047 | 662 |
} finally { |
663 |
g.dispose(); |
|
664 |
} |
|
665 |
} |
|
666 |
} |
|
667 |
||
18241 | 668 |
@Override |
12047 | 669 |
public void notifyUpdateCursor() { |
670 |
getLWToolkit().getCursorManager().updateCursorLater(this); |
|
671 |
} |
|
672 |
||
18241 | 673 |
@Override |
14311
b2492ea8d08e
7124310: [macosx] "opposite" seems always null in focus events
leonidr
parents:
14306
diff
changeset
|
674 |
public void notifyActivation(boolean activation, LWWindowPeer opposite) { |
b2492ea8d08e
7124310: [macosx] "opposite" seems always null in focus events
leonidr
parents:
14306
diff
changeset
|
675 |
Window oppositeWindow = (opposite == null)? null : opposite.getTarget(); |
b2492ea8d08e
7124310: [macosx] "opposite" seems always null in focus events
leonidr
parents:
14306
diff
changeset
|
676 |
changeFocusedWindow(activation, oppositeWindow); |
12047 | 677 |
} |
678 |
||
679 |
// MouseDown in non-client area |
|
18241 | 680 |
@Override |
12047 | 681 |
public void notifyNCMouseDown() { |
682 |
// Ungrab except for a click on a Dialog with the grabbing owner |
|
683 |
if (grabbingWindow != null && |
|
684 |
grabbingWindow != getOwnerFrameDialog(this)) |
|
685 |
{ |
|
686 |
grabbingWindow.ungrab(); |
|
687 |
} |
|
688 |
} |
|
689 |
||
690 |
// ---- EVENTS ---- // |
|
691 |
||
692 |
/* |
|
693 |
* Called by the delegate to dispatch the event to Java. Event |
|
694 |
* coordinates are relative to non-client window are, i.e. the top-left |
|
695 |
* point of the client area is (insets.top, insets.left). |
|
696 |
*/ |
|
18241 | 697 |
@Override |
698 |
public void notifyMouseEvent(int id, long when, int button, |
|
699 |
int x, int y, int screenX, int screenY, |
|
700 |
int modifiers, int clickCount, boolean popupTrigger, |
|
701 |
byte[] bdata) |
|
12047 | 702 |
{ |
703 |
// TODO: fill "bdata" member of AWTEvent |
|
704 |
Rectangle r = getBounds(); |
|
705 |
// findPeerAt() expects parent coordinates |
|
20153 | 706 |
LWComponentPeer<?, ?> targetPeer = findPeerAt(r.x + x, r.y + y); |
12047 | 707 |
|
708 |
if (id == MouseEvent.MOUSE_EXITED) { |
|
13647
de61414bbcf2
7171045: [macosx] There are no enter or exit events reported against 8b39 for MouseEventsDuringDrag.
alexsch
parents:
13550
diff
changeset
|
709 |
isMouseOver = false; |
de61414bbcf2
7171045: [macosx] There are no enter or exit events reported against 8b39 for MouseEventsDuringDrag.
alexsch
parents:
13550
diff
changeset
|
710 |
if (lastMouseEventPeer != null) { |
de61414bbcf2
7171045: [macosx] There are no enter or exit events reported against 8b39 for MouseEventsDuringDrag.
alexsch
parents:
13550
diff
changeset
|
711 |
if (lastMouseEventPeer.isEnabled()) { |
12047 | 712 |
Point lp = lastMouseEventPeer.windowToLocal(x, y, |
13647
de61414bbcf2
7171045: [macosx] There are no enter or exit events reported against 8b39 for MouseEventsDuringDrag.
alexsch
parents:
13550
diff
changeset
|
713 |
this); |
18241 | 714 |
Component target = lastMouseEventPeer.getTarget(); |
715 |
postMouseExitedEvent(target, when, modifiers, lp, |
|
716 |
screenX, screenY, clickCount, popupTrigger, button); |
|
13647
de61414bbcf2
7171045: [macosx] There are no enter or exit events reported against 8b39 for MouseEventsDuringDrag.
alexsch
parents:
13550
diff
changeset
|
717 |
} |
de61414bbcf2
7171045: [macosx] There are no enter or exit events reported against 8b39 for MouseEventsDuringDrag.
alexsch
parents:
13550
diff
changeset
|
718 |
|
de61414bbcf2
7171045: [macosx] There are no enter or exit events reported against 8b39 for MouseEventsDuringDrag.
alexsch
parents:
13550
diff
changeset
|
719 |
// Sometimes we may get MOUSE_EXITED after lastCommonMouseEventPeer is switched |
de61414bbcf2
7171045: [macosx] There are no enter or exit events reported against 8b39 for MouseEventsDuringDrag.
alexsch
parents:
13550
diff
changeset
|
720 |
// to a peer from another window. So we must first check if this peer is |
de61414bbcf2
7171045: [macosx] There are no enter or exit events reported against 8b39 for MouseEventsDuringDrag.
alexsch
parents:
13550
diff
changeset
|
721 |
// the same as lastWindowPeer |
de61414bbcf2
7171045: [macosx] There are no enter or exit events reported against 8b39 for MouseEventsDuringDrag.
alexsch
parents:
13550
diff
changeset
|
722 |
if (lastCommonMouseEventPeer != null && lastCommonMouseEventPeer.getWindowPeerOrSelf() == this) { |
de61414bbcf2
7171045: [macosx] There are no enter or exit events reported against 8b39 for MouseEventsDuringDrag.
alexsch
parents:
13550
diff
changeset
|
723 |
lastCommonMouseEventPeer = null; |
12047 | 724 |
} |
725 |
lastMouseEventPeer = null; |
|
726 |
} |
|
13647
de61414bbcf2
7171045: [macosx] There are no enter or exit events reported against 8b39 for MouseEventsDuringDrag.
alexsch
parents:
13550
diff
changeset
|
727 |
} else if(id == MouseEvent.MOUSE_ENTERED) { |
de61414bbcf2
7171045: [macosx] There are no enter or exit events reported against 8b39 for MouseEventsDuringDrag.
alexsch
parents:
13550
diff
changeset
|
728 |
isMouseOver = true; |
de61414bbcf2
7171045: [macosx] There are no enter or exit events reported against 8b39 for MouseEventsDuringDrag.
alexsch
parents:
13550
diff
changeset
|
729 |
if (targetPeer != null) { |
de61414bbcf2
7171045: [macosx] There are no enter or exit events reported against 8b39 for MouseEventsDuringDrag.
alexsch
parents:
13550
diff
changeset
|
730 |
if (targetPeer.isEnabled()) { |
de61414bbcf2
7171045: [macosx] There are no enter or exit events reported against 8b39 for MouseEventsDuringDrag.
alexsch
parents:
13550
diff
changeset
|
731 |
Point lp = targetPeer.windowToLocal(x, y, this); |
18241 | 732 |
Component target = targetPeer.getTarget(); |
733 |
postMouseEnteredEvent(target, when, modifiers, lp, |
|
734 |
screenX, screenY, clickCount, popupTrigger, button); |
|
12047 | 735 |
} |
13647
de61414bbcf2
7171045: [macosx] There are no enter or exit events reported against 8b39 for MouseEventsDuringDrag.
alexsch
parents:
13550
diff
changeset
|
736 |
lastCommonMouseEventPeer = targetPeer; |
12047 | 737 |
lastMouseEventPeer = targetPeer; |
738 |
} |
|
13647
de61414bbcf2
7171045: [macosx] There are no enter or exit events reported against 8b39 for MouseEventsDuringDrag.
alexsch
parents:
13550
diff
changeset
|
739 |
} else { |
de61414bbcf2
7171045: [macosx] There are no enter or exit events reported against 8b39 for MouseEventsDuringDrag.
alexsch
parents:
13550
diff
changeset
|
740 |
PlatformWindow topmostPlatforWindow = |
de61414bbcf2
7171045: [macosx] There are no enter or exit events reported against 8b39 for MouseEventsDuringDrag.
alexsch
parents:
13550
diff
changeset
|
741 |
platformWindow.getTopmostPlatformWindowUnderMouse(); |
de61414bbcf2
7171045: [macosx] There are no enter or exit events reported against 8b39 for MouseEventsDuringDrag.
alexsch
parents:
13550
diff
changeset
|
742 |
|
de61414bbcf2
7171045: [macosx] There are no enter or exit events reported against 8b39 for MouseEventsDuringDrag.
alexsch
parents:
13550
diff
changeset
|
743 |
LWWindowPeer topmostWindowPeer = |
de61414bbcf2
7171045: [macosx] There are no enter or exit events reported against 8b39 for MouseEventsDuringDrag.
alexsch
parents:
13550
diff
changeset
|
744 |
topmostPlatforWindow != null ? topmostPlatforWindow.getPeer() : null; |
de61414bbcf2
7171045: [macosx] There are no enter or exit events reported against 8b39 for MouseEventsDuringDrag.
alexsch
parents:
13550
diff
changeset
|
745 |
|
de61414bbcf2
7171045: [macosx] There are no enter or exit events reported against 8b39 for MouseEventsDuringDrag.
alexsch
parents:
13550
diff
changeset
|
746 |
// topmostWindowPeer == null condition is added for the backward |
de61414bbcf2
7171045: [macosx] There are no enter or exit events reported against 8b39 for MouseEventsDuringDrag.
alexsch
parents:
13550
diff
changeset
|
747 |
// compatibility with applets. It can be removed when the |
de61414bbcf2
7171045: [macosx] There are no enter or exit events reported against 8b39 for MouseEventsDuringDrag.
alexsch
parents:
13550
diff
changeset
|
748 |
// getTopmostPlatformWindowUnderMouse() method will be properly |
de61414bbcf2
7171045: [macosx] There are no enter or exit events reported against 8b39 for MouseEventsDuringDrag.
alexsch
parents:
13550
diff
changeset
|
749 |
// implemented in CPlatformEmbeddedFrame class |
de61414bbcf2
7171045: [macosx] There are no enter or exit events reported against 8b39 for MouseEventsDuringDrag.
alexsch
parents:
13550
diff
changeset
|
750 |
if (topmostWindowPeer == this || topmostWindowPeer == null) { |
de61414bbcf2
7171045: [macosx] There are no enter or exit events reported against 8b39 for MouseEventsDuringDrag.
alexsch
parents:
13550
diff
changeset
|
751 |
generateMouseEnterExitEventsForComponents(when, button, x, y, |
de61414bbcf2
7171045: [macosx] There are no enter or exit events reported against 8b39 for MouseEventsDuringDrag.
alexsch
parents:
13550
diff
changeset
|
752 |
screenX, screenY, modifiers, clickCount, popupTrigger, |
de61414bbcf2
7171045: [macosx] There are no enter or exit events reported against 8b39 for MouseEventsDuringDrag.
alexsch
parents:
13550
diff
changeset
|
753 |
targetPeer); |
de61414bbcf2
7171045: [macosx] There are no enter or exit events reported against 8b39 for MouseEventsDuringDrag.
alexsch
parents:
13550
diff
changeset
|
754 |
} else { |
20153 | 755 |
LWComponentPeer<?, ?> topmostTargetPeer = |
13647
de61414bbcf2
7171045: [macosx] There are no enter or exit events reported against 8b39 for MouseEventsDuringDrag.
alexsch
parents:
13550
diff
changeset
|
756 |
topmostWindowPeer != null ? topmostWindowPeer.findPeerAt(r.x + x, r.y + y) : null; |
de61414bbcf2
7171045: [macosx] There are no enter or exit events reported against 8b39 for MouseEventsDuringDrag.
alexsch
parents:
13550
diff
changeset
|
757 |
topmostWindowPeer.generateMouseEnterExitEventsForComponents(when, button, x, y, |
de61414bbcf2
7171045: [macosx] There are no enter or exit events reported against 8b39 for MouseEventsDuringDrag.
alexsch
parents:
13550
diff
changeset
|
758 |
screenX, screenY, modifiers, clickCount, popupTrigger, |
de61414bbcf2
7171045: [macosx] There are no enter or exit events reported against 8b39 for MouseEventsDuringDrag.
alexsch
parents:
13550
diff
changeset
|
759 |
topmostTargetPeer); |
de61414bbcf2
7171045: [macosx] There are no enter or exit events reported against 8b39 for MouseEventsDuringDrag.
alexsch
parents:
13550
diff
changeset
|
760 |
} |
de61414bbcf2
7171045: [macosx] There are no enter or exit events reported against 8b39 for MouseEventsDuringDrag.
alexsch
parents:
13550
diff
changeset
|
761 |
|
12047 | 762 |
// TODO: fill "bdata" member of AWTEvent |
763 |
||
764 |
int eventButtonMask = (button > 0)? MouseEvent.getMaskForButton(button) : 0; |
|
765 |
int otherButtonsPressed = modifiers & ~eventButtonMask; |
|
766 |
||
767 |
// For pressed/dragged/released events OS X treats other |
|
768 |
// mouse buttons as if they were BUTTON2, so we do the same |
|
769 |
int targetIdx = (button > 3) ? MouseEvent.BUTTON2 - 1 : button - 1; |
|
770 |
||
771 |
// MOUSE_ENTERED/EXITED are generated for the components strictly under |
|
772 |
// mouse even when dragging. That's why we first update lastMouseEventPeer |
|
773 |
// based on initial targetPeer value and only then recalculate targetPeer |
|
774 |
// for MOUSE_DRAGGED/RELEASED events |
|
775 |
if (id == MouseEvent.MOUSE_PRESSED) { |
|
776 |
||
777 |
// Ungrab only if this window is not an owned window of the grabbing one. |
|
778 |
if (!isGrabbing() && grabbingWindow != null && |
|
779 |
grabbingWindow != getOwnerFrameDialog(this)) |
|
780 |
{ |
|
781 |
grabbingWindow.ungrab(); |
|
782 |
} |
|
783 |
if (otherButtonsPressed == 0) { |
|
784 |
mouseClickButtons = eventButtonMask; |
|
785 |
} else { |
|
786 |
mouseClickButtons |= eventButtonMask; |
|
787 |
} |
|
788 |
||
13652
42544e68dc39
6981400: Tabbing between textfield do not work properly when ALT+TAB
ant
parents:
13648
diff
changeset
|
789 |
// The window should be focused on mouse click. If it gets activated by the native platform, |
42544e68dc39
6981400: Tabbing between textfield do not work properly when ALT+TAB
ant
parents:
13648
diff
changeset
|
790 |
// this request will be no op. It will take effect when: |
42544e68dc39
6981400: Tabbing between textfield do not work properly when ALT+TAB
ant
parents:
13648
diff
changeset
|
791 |
// 1. A simple not focused window is clicked. |
42544e68dc39
6981400: Tabbing between textfield do not work properly when ALT+TAB
ant
parents:
13648
diff
changeset
|
792 |
// 2. An active but not focused owner frame/dialog is clicked. |
42544e68dc39
6981400: Tabbing between textfield do not work properly when ALT+TAB
ant
parents:
13648
diff
changeset
|
793 |
// The mouse event then will trigger a focus request "in window" to the component, so the window |
42544e68dc39
6981400: Tabbing between textfield do not work properly when ALT+TAB
ant
parents:
13648
diff
changeset
|
794 |
// should gain focus before. |
42544e68dc39
6981400: Tabbing between textfield do not work properly when ALT+TAB
ant
parents:
13648
diff
changeset
|
795 |
requestWindowFocus(CausedFocusEvent.Cause.MOUSE_EVENT); |
42544e68dc39
6981400: Tabbing between textfield do not work properly when ALT+TAB
ant
parents:
13648
diff
changeset
|
796 |
|
12047 | 797 |
mouseDownTarget[targetIdx] = targetPeer; |
798 |
} else if (id == MouseEvent.MOUSE_DRAGGED) { |
|
799 |
// Cocoa dragged event has the information about which mouse |
|
800 |
// button is being dragged. Use it to determine the peer that |
|
801 |
// should receive the dragged event. |
|
802 |
targetPeer = mouseDownTarget[targetIdx]; |
|
803 |
mouseClickButtons &= ~modifiers; |
|
804 |
} else if (id == MouseEvent.MOUSE_RELEASED) { |
|
805 |
// TODO: currently, mouse released event goes to the same component |
|
806 |
// that received corresponding mouse pressed event. For most cases, |
|
807 |
// it's OK, however, we need to make sure that our behavior is consistent |
|
808 |
// with 1.6 for cases where component in question have been |
|
809 |
// hidden/removed in between of mouse pressed/released events. |
|
810 |
targetPeer = mouseDownTarget[targetIdx]; |
|
811 |
||
812 |
if ((modifiers & eventButtonMask) == 0) { |
|
813 |
mouseDownTarget[targetIdx] = null; |
|
814 |
} |
|
815 |
||
816 |
// mouseClickButtons is updated below, after MOUSE_CLICK is sent |
|
817 |
} |
|
818 |
||
819 |
if (targetPeer == null) { |
|
820 |
//TODO This can happen if this window is invisible. this is correct behavior in this case? |
|
821 |
targetPeer = this; |
|
822 |
} |
|
823 |
||
824 |
||
13647
de61414bbcf2
7171045: [macosx] There are no enter or exit events reported against 8b39 for MouseEventsDuringDrag.
alexsch
parents:
13550
diff
changeset
|
825 |
Point lp = targetPeer.windowToLocal(x, y, this); |
12047 | 826 |
if (targetPeer.isEnabled()) { |
827 |
MouseEvent event = new MouseEvent(targetPeer.getTarget(), id, |
|
828 |
when, modifiers, lp.x, lp.y, |
|
829 |
screenX, screenY, clickCount, |
|
830 |
popupTrigger, button); |
|
831 |
postEvent(event); |
|
832 |
} |
|
833 |
||
834 |
if (id == MouseEvent.MOUSE_RELEASED) { |
|
835 |
if ((mouseClickButtons & eventButtonMask) != 0 |
|
836 |
&& targetPeer.isEnabled()) { |
|
837 |
postEvent(new MouseEvent(targetPeer.getTarget(), |
|
838 |
MouseEvent.MOUSE_CLICKED, |
|
839 |
when, modifiers, |
|
840 |
lp.x, lp.y, screenX, screenY, |
|
841 |
clickCount, popupTrigger, button)); |
|
842 |
} |
|
843 |
mouseClickButtons &= ~eventButtonMask; |
|
844 |
} |
|
845 |
} |
|
12396
79c64c6eb61e
7150105: [macosx] four scroll-buttons don't display. scroll-sliders cursors are TextCursor.
serb
parents:
12176
diff
changeset
|
846 |
notifyUpdateCursor(); |
12047 | 847 |
} |
848 |
||
13647
de61414bbcf2
7171045: [macosx] There are no enter or exit events reported against 8b39 for MouseEventsDuringDrag.
alexsch
parents:
13550
diff
changeset
|
849 |
private void generateMouseEnterExitEventsForComponents(long when, |
de61414bbcf2
7171045: [macosx] There are no enter or exit events reported against 8b39 for MouseEventsDuringDrag.
alexsch
parents:
13550
diff
changeset
|
850 |
int button, int x, int y, int screenX, int screenY, |
de61414bbcf2
7171045: [macosx] There are no enter or exit events reported against 8b39 for MouseEventsDuringDrag.
alexsch
parents:
13550
diff
changeset
|
851 |
int modifiers, int clickCount, boolean popupTrigger, |
20153 | 852 |
final LWComponentPeer<?, ?> targetPeer) { |
13647
de61414bbcf2
7171045: [macosx] There are no enter or exit events reported against 8b39 for MouseEventsDuringDrag.
alexsch
parents:
13550
diff
changeset
|
853 |
|
de61414bbcf2
7171045: [macosx] There are no enter or exit events reported against 8b39 for MouseEventsDuringDrag.
alexsch
parents:
13550
diff
changeset
|
854 |
if (!isMouseOver || targetPeer == lastMouseEventPeer) { |
de61414bbcf2
7171045: [macosx] There are no enter or exit events reported against 8b39 for MouseEventsDuringDrag.
alexsch
parents:
13550
diff
changeset
|
855 |
return; |
de61414bbcf2
7171045: [macosx] There are no enter or exit events reported against 8b39 for MouseEventsDuringDrag.
alexsch
parents:
13550
diff
changeset
|
856 |
} |
de61414bbcf2
7171045: [macosx] There are no enter or exit events reported against 8b39 for MouseEventsDuringDrag.
alexsch
parents:
13550
diff
changeset
|
857 |
|
de61414bbcf2
7171045: [macosx] There are no enter or exit events reported against 8b39 for MouseEventsDuringDrag.
alexsch
parents:
13550
diff
changeset
|
858 |
// Generate Mouse Exit for components |
de61414bbcf2
7171045: [macosx] There are no enter or exit events reported against 8b39 for MouseEventsDuringDrag.
alexsch
parents:
13550
diff
changeset
|
859 |
if (lastMouseEventPeer != null && lastMouseEventPeer.isEnabled()) { |
de61414bbcf2
7171045: [macosx] There are no enter or exit events reported against 8b39 for MouseEventsDuringDrag.
alexsch
parents:
13550
diff
changeset
|
860 |
Point oldp = lastMouseEventPeer.windowToLocal(x, y, this); |
18241 | 861 |
Component target = lastMouseEventPeer.getTarget(); |
862 |
postMouseExitedEvent(target, when, modifiers, oldp, screenX, screenY, |
|
863 |
clickCount, popupTrigger, button); |
|
13647
de61414bbcf2
7171045: [macosx] There are no enter or exit events reported against 8b39 for MouseEventsDuringDrag.
alexsch
parents:
13550
diff
changeset
|
864 |
} |
de61414bbcf2
7171045: [macosx] There are no enter or exit events reported against 8b39 for MouseEventsDuringDrag.
alexsch
parents:
13550
diff
changeset
|
865 |
lastCommonMouseEventPeer = targetPeer; |
de61414bbcf2
7171045: [macosx] There are no enter or exit events reported against 8b39 for MouseEventsDuringDrag.
alexsch
parents:
13550
diff
changeset
|
866 |
lastMouseEventPeer = targetPeer; |
de61414bbcf2
7171045: [macosx] There are no enter or exit events reported against 8b39 for MouseEventsDuringDrag.
alexsch
parents:
13550
diff
changeset
|
867 |
|
de61414bbcf2
7171045: [macosx] There are no enter or exit events reported against 8b39 for MouseEventsDuringDrag.
alexsch
parents:
13550
diff
changeset
|
868 |
// Generate Mouse Enter for components |
de61414bbcf2
7171045: [macosx] There are no enter or exit events reported against 8b39 for MouseEventsDuringDrag.
alexsch
parents:
13550
diff
changeset
|
869 |
if (targetPeer != null && targetPeer.isEnabled()) { |
de61414bbcf2
7171045: [macosx] There are no enter or exit events reported against 8b39 for MouseEventsDuringDrag.
alexsch
parents:
13550
diff
changeset
|
870 |
Point newp = targetPeer.windowToLocal(x, y, this); |
18241 | 871 |
Component target = targetPeer.getTarget(); |
872 |
postMouseEnteredEvent(target, when, modifiers, newp, screenX, screenY, clickCount, popupTrigger, button); |
|
13647
de61414bbcf2
7171045: [macosx] There are no enter or exit events reported against 8b39 for MouseEventsDuringDrag.
alexsch
parents:
13550
diff
changeset
|
873 |
} |
de61414bbcf2
7171045: [macosx] There are no enter or exit events reported against 8b39 for MouseEventsDuringDrag.
alexsch
parents:
13550
diff
changeset
|
874 |
} |
de61414bbcf2
7171045: [macosx] There are no enter or exit events reported against 8b39 for MouseEventsDuringDrag.
alexsch
parents:
13550
diff
changeset
|
875 |
|
18241 | 876 |
private void postMouseEnteredEvent(Component target, long when, int modifiers, |
877 |
Point loc, int xAbs, int yAbs, |
|
878 |
int clickCount, boolean popupTrigger, int button) { |
|
879 |
||
880 |
updateSecurityWarningVisibility(); |
|
881 |
||
882 |
postEvent(new MouseEvent(target, |
|
883 |
MouseEvent.MOUSE_ENTERED, |
|
884 |
when, modifiers, |
|
885 |
loc.x, loc.y, xAbs, yAbs, |
|
886 |
clickCount, popupTrigger, button)); |
|
887 |
} |
|
888 |
||
889 |
private void postMouseExitedEvent(Component target, long when, int modifiers, |
|
890 |
Point loc, int xAbs, int yAbs, |
|
891 |
int clickCount, boolean popupTrigger, int button) { |
|
892 |
||
893 |
updateSecurityWarningVisibility(); |
|
894 |
||
895 |
postEvent(new MouseEvent(target, |
|
896 |
MouseEvent.MOUSE_EXITED, |
|
897 |
when, modifiers, |
|
898 |
loc.x, loc.y, xAbs, yAbs, |
|
899 |
clickCount, popupTrigger, button)); |
|
900 |
} |
|
901 |
||
902 |
@Override |
|
903 |
public void notifyMouseWheelEvent(long when, int x, int y, int modifiers, |
|
904 |
int scrollType, int scrollAmount, |
|
905 |
int wheelRotation, double preciseWheelRotation, |
|
906 |
byte[] bdata) |
|
12047 | 907 |
{ |
908 |
// TODO: could we just use the last mouse event target here? |
|
909 |
Rectangle r = getBounds(); |
|
910 |
// findPeerAt() expects parent coordinates |
|
20153 | 911 |
final LWComponentPeer<?, ?> targetPeer = findPeerAt(r.x + x, r.y + y); |
12047 | 912 |
if (targetPeer == null || !targetPeer.isEnabled()) { |
913 |
return; |
|
914 |
} |
|
915 |
||
916 |
Point lp = targetPeer.windowToLocal(x, y, this); |
|
917 |
// TODO: fill "bdata" member of AWTEvent |
|
918 |
// TODO: screenX/screenY |
|
919 |
postEvent(new MouseWheelEvent(targetPeer.getTarget(), |
|
920 |
MouseEvent.MOUSE_WHEEL, |
|
921 |
when, modifiers, |
|
922 |
lp.x, lp.y, |
|
923 |
0, 0, /* screenX, Y */ |
|
924 |
0 /* clickCount */, false /* popupTrigger */, |
|
925 |
scrollType, scrollAmount, |
|
926 |
wheelRotation, preciseWheelRotation)); |
|
927 |
} |
|
928 |
||
929 |
/* |
|
930 |
* Called by the delegate when a key is pressed. |
|
931 |
*/ |
|
18241 | 932 |
@Override |
933 |
public void notifyKeyEvent(int id, long when, int modifiers, |
|
934 |
int keyCode, char keyChar, int keyLocation) |
|
12047 | 935 |
{ |
13652
42544e68dc39
6981400: Tabbing between textfield do not work properly when ALT+TAB
ant
parents:
13648
diff
changeset
|
936 |
LWKeyboardFocusManagerPeer kfmPeer = LWKeyboardFocusManagerPeer.getInstance(); |
13648
90effcfc064f
7124375: [macosx] Focus isn't transfered as expected between components
leonidr
parents:
13647
diff
changeset
|
937 |
Component focusOwner = kfmPeer.getCurrentFocusOwner(); |
12047 | 938 |
|
13652
42544e68dc39
6981400: Tabbing between textfield do not work properly when ALT+TAB
ant
parents:
13648
diff
changeset
|
939 |
if (focusOwner == null) { |
42544e68dc39
6981400: Tabbing between textfield do not work properly when ALT+TAB
ant
parents:
13648
diff
changeset
|
940 |
focusOwner = kfmPeer.getCurrentFocusedWindow(); |
42544e68dc39
6981400: Tabbing between textfield do not work properly when ALT+TAB
ant
parents:
13648
diff
changeset
|
941 |
if (focusOwner == null) { |
42544e68dc39
6981400: Tabbing between textfield do not work properly when ALT+TAB
ant
parents:
13648
diff
changeset
|
942 |
focusOwner = this.getTarget(); |
42544e68dc39
6981400: Tabbing between textfield do not work properly when ALT+TAB
ant
parents:
13648
diff
changeset
|
943 |
} |
12047 | 944 |
} |
20109
e568ad7e1bf3
8007156: [macosx] Wrong events in processKeyBinding of JTable Submit Date
alexsch
parents:
18275
diff
changeset
|
945 |
|
e568ad7e1bf3
8007156: [macosx] Wrong events in processKeyBinding of JTable Submit Date
alexsch
parents:
18275
diff
changeset
|
946 |
KeyEvent keyEvent = new KeyEvent(focusOwner, id, when, modifiers, |
e568ad7e1bf3
8007156: [macosx] Wrong events in processKeyBinding of JTable Submit Date
alexsch
parents:
18275
diff
changeset
|
947 |
keyCode, keyChar, keyLocation); |
e568ad7e1bf3
8007156: [macosx] Wrong events in processKeyBinding of JTable Submit Date
alexsch
parents:
18275
diff
changeset
|
948 |
AWTAccessor.getKeyEventAccessor().setExtendedKeyCode(keyEvent, |
e568ad7e1bf3
8007156: [macosx] Wrong events in processKeyBinding of JTable Submit Date
alexsch
parents:
18275
diff
changeset
|
949 |
ExtendedKeyCodes.getExtendedKeyCodeForChar(keyChar)); |
e568ad7e1bf3
8007156: [macosx] Wrong events in processKeyBinding of JTable Submit Date
alexsch
parents:
18275
diff
changeset
|
950 |
postEvent(keyEvent); |
12047 | 951 |
} |
952 |
||
953 |
// ---- UTILITY METHODS ---- // |
|
954 |
||
17151
9bfcf2a592fc
8009012: [macosx] DisplayChangedListener is not implemented in LWWindowPeer/CGraphicsEnvironment
serb
parents:
17150
diff
changeset
|
955 |
private void activateDisplayListener() { |
9bfcf2a592fc
8009012: [macosx] DisplayChangedListener is not implemented in LWWindowPeer/CGraphicsEnvironment
serb
parents:
17150
diff
changeset
|
956 |
final GraphicsEnvironment ge = |
9bfcf2a592fc
8009012: [macosx] DisplayChangedListener is not implemented in LWWindowPeer/CGraphicsEnvironment
serb
parents:
17150
diff
changeset
|
957 |
GraphicsEnvironment.getLocalGraphicsEnvironment(); |
9bfcf2a592fc
8009012: [macosx] DisplayChangedListener is not implemented in LWWindowPeer/CGraphicsEnvironment
serb
parents:
17150
diff
changeset
|
958 |
((SunGraphicsEnvironment) ge).addDisplayChangedListener(this); |
9bfcf2a592fc
8009012: [macosx] DisplayChangedListener is not implemented in LWWindowPeer/CGraphicsEnvironment
serb
parents:
17150
diff
changeset
|
959 |
} |
9bfcf2a592fc
8009012: [macosx] DisplayChangedListener is not implemented in LWWindowPeer/CGraphicsEnvironment
serb
parents:
17150
diff
changeset
|
960 |
|
9bfcf2a592fc
8009012: [macosx] DisplayChangedListener is not implemented in LWWindowPeer/CGraphicsEnvironment
serb
parents:
17150
diff
changeset
|
961 |
private void deactivateDisplayListener() { |
9bfcf2a592fc
8009012: [macosx] DisplayChangedListener is not implemented in LWWindowPeer/CGraphicsEnvironment
serb
parents:
17150
diff
changeset
|
962 |
final GraphicsEnvironment ge = |
9bfcf2a592fc
8009012: [macosx] DisplayChangedListener is not implemented in LWWindowPeer/CGraphicsEnvironment
serb
parents:
17150
diff
changeset
|
963 |
GraphicsEnvironment.getLocalGraphicsEnvironment(); |
9bfcf2a592fc
8009012: [macosx] DisplayChangedListener is not implemented in LWWindowPeer/CGraphicsEnvironment
serb
parents:
17150
diff
changeset
|
964 |
((SunGraphicsEnvironment) ge).removeDisplayChangedListener(this); |
9bfcf2a592fc
8009012: [macosx] DisplayChangedListener is not implemented in LWWindowPeer/CGraphicsEnvironment
serb
parents:
17150
diff
changeset
|
965 |
} |
9bfcf2a592fc
8009012: [macosx] DisplayChangedListener is not implemented in LWWindowPeer/CGraphicsEnvironment
serb
parents:
17150
diff
changeset
|
966 |
|
12047 | 967 |
private void postWindowStateChangedEvent(int newWindowState) { |
968 |
if (getTarget() instanceof Frame) { |
|
969 |
AWTAccessor.getFrameAccessor().setExtendedState( |
|
970 |
(Frame)getTarget(), newWindowState); |
|
971 |
} |
|
18241 | 972 |
|
12047 | 973 |
WindowEvent stateChangedEvent = new WindowEvent(getTarget(), |
974 |
WindowEvent.WINDOW_STATE_CHANGED, |
|
975 |
windowState, newWindowState); |
|
976 |
postEvent(stateChangedEvent); |
|
977 |
windowState = newWindowState; |
|
18241 | 978 |
|
979 |
updateSecurityWarningVisibility(); |
|
12047 | 980 |
} |
981 |
||
982 |
private static int getGraphicsConfigScreen(GraphicsConfiguration gc) { |
|
983 |
// TODO: this method can be implemented in a more |
|
984 |
// efficient way by forwarding to the delegate |
|
985 |
GraphicsDevice gd = gc.getDevice(); |
|
986 |
GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment(); |
|
987 |
GraphicsDevice[] gds = ge.getScreenDevices(); |
|
988 |
for (int i = 0; i < gds.length; i++) { |
|
989 |
if (gds[i] == gd) { |
|
990 |
return i; |
|
991 |
} |
|
992 |
} |
|
993 |
// Should never happen if gc is a screen device config |
|
994 |
return 0; |
|
995 |
} |
|
996 |
||
997 |
/* |
|
998 |
* This method is called when window's graphics config is changed from |
|
999 |
* the app code (e.g. when the window is made non-opaque) or when |
|
1000 |
* the window is moved to another screen by user. |
|
1001 |
* |
|
1002 |
* Returns true if the graphics config has been changed, false otherwise. |
|
1003 |
*/ |
|
1004 |
private boolean setGraphicsConfig(GraphicsConfiguration gc) { |
|
1005 |
synchronized (getStateLock()) { |
|
1006 |
if (graphicsConfig == gc) { |
|
1007 |
return false; |
|
1008 |
} |
|
1009 |
// If window's graphics config is changed from the app code, the |
|
1010 |
// config correspond to the same device as before; when the window |
|
16840
64446d4710c4
8000629: [macosx] Blurry rendering with Java 7 on Retina display
serb
parents:
16839
diff
changeset
|
1011 |
// is moved by user, graphicsDevice is updated in notifyReshape(). |
12047 | 1012 |
// In either case, there's nothing to do with screenOn here |
1013 |
graphicsConfig = gc; |
|
1014 |
} |
|
1015 |
// SurfaceData is replaced later in updateGraphicsData() |
|
1016 |
return true; |
|
1017 |
} |
|
1018 |
||
16840
64446d4710c4
8000629: [macosx] Blurry rendering with Java 7 on Retina display
serb
parents:
16839
diff
changeset
|
1019 |
/** |
64446d4710c4
8000629: [macosx] Blurry rendering with Java 7 on Retina display
serb
parents:
16839
diff
changeset
|
1020 |
* Returns true if the GraphicsDevice has been changed, false otherwise. |
64446d4710c4
8000629: [macosx] Blurry rendering with Java 7 on Retina display
serb
parents:
16839
diff
changeset
|
1021 |
*/ |
64446d4710c4
8000629: [macosx] Blurry rendering with Java 7 on Retina display
serb
parents:
16839
diff
changeset
|
1022 |
public boolean updateGraphicsDevice() { |
12816
b4cabffcb0de
7160293: [macosx] FileDialog appears on secondary display
dcherepanov
parents:
12663
diff
changeset
|
1023 |
GraphicsDevice newGraphicsDevice = platformWindow.getGraphicsDevice(); |
12047 | 1024 |
synchronized (getStateLock()) { |
12816
b4cabffcb0de
7160293: [macosx] FileDialog appears on secondary display
dcherepanov
parents:
12663
diff
changeset
|
1025 |
if (graphicsDevice == newGraphicsDevice) { |
16840
64446d4710c4
8000629: [macosx] Blurry rendering with Java 7 on Retina display
serb
parents:
16839
diff
changeset
|
1026 |
return false; |
12047 | 1027 |
} |
12816
b4cabffcb0de
7160293: [macosx] FileDialog appears on secondary display
dcherepanov
parents:
12663
diff
changeset
|
1028 |
graphicsDevice = newGraphicsDevice; |
12047 | 1029 |
} |
1030 |
||
12816
b4cabffcb0de
7160293: [macosx] FileDialog appears on secondary display
dcherepanov
parents:
12663
diff
changeset
|
1031 |
final GraphicsConfiguration newGC = newGraphicsDevice.getDefaultConfiguration(); |
b4cabffcb0de
7160293: [macosx] FileDialog appears on secondary display
dcherepanov
parents:
12663
diff
changeset
|
1032 |
|
16840
64446d4710c4
8000629: [macosx] Blurry rendering with Java 7 on Retina display
serb
parents:
16839
diff
changeset
|
1033 |
if (!setGraphicsConfig(newGC)) return false; |
12047 | 1034 |
|
1035 |
SunToolkit.executeOnEventHandlerThread(getTarget(), new Runnable() { |
|
1036 |
public void run() { |
|
1037 |
AWTAccessor.getComponentAccessor().setGraphicsConfiguration(getTarget(), newGC); |
|
1038 |
} |
|
1039 |
}); |
|
16840
64446d4710c4
8000629: [macosx] Blurry rendering with Java 7 on Retina display
serb
parents:
16839
diff
changeset
|
1040 |
return true; |
12047 | 1041 |
} |
1042 |
||
17151
9bfcf2a592fc
8009012: [macosx] DisplayChangedListener is not implemented in LWWindowPeer/CGraphicsEnvironment
serb
parents:
17150
diff
changeset
|
1043 |
@Override |
9bfcf2a592fc
8009012: [macosx] DisplayChangedListener is not implemented in LWWindowPeer/CGraphicsEnvironment
serb
parents:
17150
diff
changeset
|
1044 |
public final void displayChanged() { |
9bfcf2a592fc
8009012: [macosx] DisplayChangedListener is not implemented in LWWindowPeer/CGraphicsEnvironment
serb
parents:
17150
diff
changeset
|
1045 |
updateGraphicsDevice(); |
9bfcf2a592fc
8009012: [macosx] DisplayChangedListener is not implemented in LWWindowPeer/CGraphicsEnvironment
serb
parents:
17150
diff
changeset
|
1046 |
// Replace surface unconditionally, because internal state of the |
9bfcf2a592fc
8009012: [macosx] DisplayChangedListener is not implemented in LWWindowPeer/CGraphicsEnvironment
serb
parents:
17150
diff
changeset
|
1047 |
// GraphicsDevice could be changed. |
9bfcf2a592fc
8009012: [macosx] DisplayChangedListener is not implemented in LWWindowPeer/CGraphicsEnvironment
serb
parents:
17150
diff
changeset
|
1048 |
replaceSurfaceData(); |
9bfcf2a592fc
8009012: [macosx] DisplayChangedListener is not implemented in LWWindowPeer/CGraphicsEnvironment
serb
parents:
17150
diff
changeset
|
1049 |
repaintPeer(); |
9bfcf2a592fc
8009012: [macosx] DisplayChangedListener is not implemented in LWWindowPeer/CGraphicsEnvironment
serb
parents:
17150
diff
changeset
|
1050 |
} |
9bfcf2a592fc
8009012: [macosx] DisplayChangedListener is not implemented in LWWindowPeer/CGraphicsEnvironment
serb
parents:
17150
diff
changeset
|
1051 |
|
9bfcf2a592fc
8009012: [macosx] DisplayChangedListener is not implemented in LWWindowPeer/CGraphicsEnvironment
serb
parents:
17150
diff
changeset
|
1052 |
@Override |
9bfcf2a592fc
8009012: [macosx] DisplayChangedListener is not implemented in LWWindowPeer/CGraphicsEnvironment
serb
parents:
17150
diff
changeset
|
1053 |
public final void paletteChanged() { |
9bfcf2a592fc
8009012: [macosx] DisplayChangedListener is not implemented in LWWindowPeer/CGraphicsEnvironment
serb
parents:
17150
diff
changeset
|
1054 |
// components do not need to react to this event. |
9bfcf2a592fc
8009012: [macosx] DisplayChangedListener is not implemented in LWWindowPeer/CGraphicsEnvironment
serb
parents:
17150
diff
changeset
|
1055 |
} |
9bfcf2a592fc
8009012: [macosx] DisplayChangedListener is not implemented in LWWindowPeer/CGraphicsEnvironment
serb
parents:
17150
diff
changeset
|
1056 |
|
12047 | 1057 |
/* |
1058 |
* May be called by delegate to provide SD to Java2D code. |
|
1059 |
*/ |
|
1060 |
public SurfaceData getSurfaceData() { |
|
1061 |
synchronized (surfaceDataLock) { |
|
1062 |
return surfaceData; |
|
1063 |
} |
|
1064 |
} |
|
1065 |
||
1066 |
private void replaceSurfaceData() { |
|
13233 | 1067 |
replaceSurfaceData(true); |
1068 |
} |
|
1069 |
||
14647
bacc2d4f4b27
7124552: [macosx] NullPointerException in getBufferStrategy()
serb
parents:
14311
diff
changeset
|
1070 |
private void replaceSurfaceData(final boolean blit) { |
12047 | 1071 |
synchronized (surfaceDataLock) { |
1072 |
final SurfaceData oldData = getSurfaceData(); |
|
1073 |
surfaceData = platformWindow.replaceSurfaceData(); |
|
1074 |
final Rectangle size = getSize(); |
|
1075 |
if (getSurfaceData() != null && oldData != getSurfaceData()) { |
|
1076 |
clearBackground(size.width, size.height); |
|
1077 |
} |
|
13233 | 1078 |
|
1079 |
if (blit) { |
|
1080 |
blitSurfaceData(oldData, getSurfaceData()); |
|
1081 |
} |
|
12047 | 1082 |
|
1083 |
if (oldData != null && oldData != getSurfaceData()) { |
|
1084 |
// TODO: drop oldData for D3D/WGL pipelines |
|
1085 |
// This can only happen when this peer is being created |
|
1086 |
oldData.flush(); |
|
1087 |
} |
|
1088 |
} |
|
16840
64446d4710c4
8000629: [macosx] Blurry rendering with Java 7 on Retina display
serb
parents:
16839
diff
changeset
|
1089 |
flushOnscreenGraphics(); |
12047 | 1090 |
} |
1091 |
||
1092 |
private void blitSurfaceData(final SurfaceData src, final SurfaceData dst) { |
|
1093 |
//TODO blit. proof-of-concept |
|
1094 |
if (src != dst && src != null && dst != null |
|
1095 |
&& !(dst instanceof NullSurfaceData) |
|
1096 |
&& !(src instanceof NullSurfaceData) |
|
16840
64446d4710c4
8000629: [macosx] Blurry rendering with Java 7 on Retina display
serb
parents:
16839
diff
changeset
|
1097 |
&& src.getSurfaceType().equals(dst.getSurfaceType()) |
64446d4710c4
8000629: [macosx] Blurry rendering with Java 7 on Retina display
serb
parents:
16839
diff
changeset
|
1098 |
&& src.getDefaultScale() == dst.getDefaultScale()) { |
64446d4710c4
8000629: [macosx] Blurry rendering with Java 7 on Retina display
serb
parents:
16839
diff
changeset
|
1099 |
final Rectangle size = src.getBounds(); |
12047 | 1100 |
final Blit blit = Blit.locate(src.getSurfaceType(), |
1101 |
CompositeType.Src, |
|
1102 |
dst.getSurfaceType()); |
|
1103 |
if (blit != null) { |
|
16840
64446d4710c4
8000629: [macosx] Blurry rendering with Java 7 on Retina display
serb
parents:
16839
diff
changeset
|
1104 |
blit.Blit(src, dst, AlphaComposite.Src, null, 0, 0, 0, 0, |
64446d4710c4
8000629: [macosx] Blurry rendering with Java 7 on Retina display
serb
parents:
16839
diff
changeset
|
1105 |
size.width, size.height); |
12047 | 1106 |
} |
1107 |
} |
|
1108 |
} |
|
1109 |
||
15331
410070becfef
8003173: [macosx] Fullscreen on Mac leaves an empty rectangle
serb
parents:
15323
diff
changeset
|
1110 |
/** |
410070becfef
8003173: [macosx] Fullscreen on Mac leaves an empty rectangle
serb
parents:
15323
diff
changeset
|
1111 |
* Request the window insets from the delegate and compares it with the |
410070becfef
8003173: [macosx] Fullscreen on Mac leaves an empty rectangle
serb
parents:
15323
diff
changeset
|
1112 |
* current one. This method is mostly called by the delegate, e.g. when the |
410070becfef
8003173: [macosx] Fullscreen on Mac leaves an empty rectangle
serb
parents:
15323
diff
changeset
|
1113 |
* window state is changed and insets should be recalculated. |
410070becfef
8003173: [macosx] Fullscreen on Mac leaves an empty rectangle
serb
parents:
15323
diff
changeset
|
1114 |
* <p/> |
12047 | 1115 |
* This method may be called on the toolkit thread. |
1116 |
*/ |
|
15331
410070becfef
8003173: [macosx] Fullscreen on Mac leaves an empty rectangle
serb
parents:
15323
diff
changeset
|
1117 |
public final boolean updateInsets(final Insets newInsets) { |
12047 | 1118 |
synchronized (getStateLock()) { |
15331
410070becfef
8003173: [macosx] Fullscreen on Mac leaves an empty rectangle
serb
parents:
15323
diff
changeset
|
1119 |
if (insets.equals(newInsets)) { |
410070becfef
8003173: [macosx] Fullscreen on Mac leaves an empty rectangle
serb
parents:
15323
diff
changeset
|
1120 |
return false; |
410070becfef
8003173: [macosx] Fullscreen on Mac leaves an empty rectangle
serb
parents:
15323
diff
changeset
|
1121 |
} |
12047 | 1122 |
insets = newInsets; |
1123 |
} |
|
15331
410070becfef
8003173: [macosx] Fullscreen on Mac leaves an empty rectangle
serb
parents:
15323
diff
changeset
|
1124 |
return true; |
12047 | 1125 |
} |
1126 |
||
1127 |
public static LWWindowPeer getWindowUnderCursor() { |
|
13647
de61414bbcf2
7171045: [macosx] There are no enter or exit events reported against 8b39 for MouseEventsDuringDrag.
alexsch
parents:
13550
diff
changeset
|
1128 |
return lastCommonMouseEventPeer != null ? lastCommonMouseEventPeer.getWindowPeerOrSelf() : null; |
12047 | 1129 |
} |
1130 |
||
12396
79c64c6eb61e
7150105: [macosx] four scroll-buttons don't display. scroll-sliders cursors are TextCursor.
serb
parents:
12176
diff
changeset
|
1131 |
public static LWComponentPeer<?, ?> getPeerUnderCursor() { |
13647
de61414bbcf2
7171045: [macosx] There are no enter or exit events reported against 8b39 for MouseEventsDuringDrag.
alexsch
parents:
13550
diff
changeset
|
1132 |
return lastCommonMouseEventPeer; |
12396
79c64c6eb61e
7150105: [macosx] four scroll-buttons don't display. scroll-sliders cursors are TextCursor.
serb
parents:
12176
diff
changeset
|
1133 |
} |
79c64c6eb61e
7150105: [macosx] four scroll-buttons don't display. scroll-sliders cursors are TextCursor.
serb
parents:
12176
diff
changeset
|
1134 |
|
12662
184d8d3b7fff
7145768: [macosx] Regression: failure in b11 of ModalDialogInFocusEventTest
ant
parents:
12640
diff
changeset
|
1135 |
/* |
184d8d3b7fff
7145768: [macosx] Regression: failure in b11 of ModalDialogInFocusEventTest
ant
parents:
12640
diff
changeset
|
1136 |
* Requests platform to set native focus on a frame/dialog. |
184d8d3b7fff
7145768: [macosx] Regression: failure in b11 of ModalDialogInFocusEventTest
ant
parents:
12640
diff
changeset
|
1137 |
* In case of a simple window, triggers appropriate java focus change. |
184d8d3b7fff
7145768: [macosx] Regression: failure in b11 of ModalDialogInFocusEventTest
ant
parents:
12640
diff
changeset
|
1138 |
*/ |
12047 | 1139 |
public boolean requestWindowFocus(CausedFocusEvent.Cause cause) { |
18178
ee71c923891d
8016747: Replace deprecated PlatformLogger isLoggable(int) with isLoggable(Level)
chegar
parents:
17151
diff
changeset
|
1140 |
if (focusLog.isLoggable(PlatformLogger.Level.FINE)) { |
12047 | 1141 |
focusLog.fine("requesting native focus to " + this); |
1142 |
} |
|
1143 |
||
1144 |
if (!focusAllowedFor()) { |
|
1145 |
focusLog.fine("focus is not allowed"); |
|
1146 |
return false; |
|
1147 |
} |
|
1148 |
||
12176 | 1149 |
if (platformWindow.rejectFocusRequest(cause)) { |
12047 | 1150 |
return false; |
1151 |
} |
|
1152 |
||
20448
0eef03207781
8024158: [macosx] java/awt/EventDispatchThread/LoopRobustness/LoopRobustness still failed after fix JDK-8022247; since jdk8b96
pchelko
parents:
20445
diff
changeset
|
1153 |
AppContext targetAppContext = AWTAccessor.getComponentAccessor().getAppContext(getTarget()); |
0eef03207781
8024158: [macosx] java/awt/EventDispatchThread/LoopRobustness/LoopRobustness still failed after fix JDK-8022247; since jdk8b96
pchelko
parents:
20445
diff
changeset
|
1154 |
KeyboardFocusManager kfm = AWTAccessor.getKeyboardFocusManagerAccessor() |
0eef03207781
8024158: [macosx] java/awt/EventDispatchThread/LoopRobustness/LoopRobustness still failed after fix JDK-8022247; since jdk8b96
pchelko
parents:
20445
diff
changeset
|
1155 |
.getCurrentKeyboardFocusManager(targetAppContext); |
0eef03207781
8024158: [macosx] java/awt/EventDispatchThread/LoopRobustness/LoopRobustness still failed after fix JDK-8022247; since jdk8b96
pchelko
parents:
20445
diff
changeset
|
1156 |
Window currentActive = kfm.getActiveWindow(); |
0eef03207781
8024158: [macosx] java/awt/EventDispatchThread/LoopRobustness/LoopRobustness still failed after fix JDK-8022247; since jdk8b96
pchelko
parents:
20445
diff
changeset
|
1157 |
|
12047 | 1158 |
|
14311
b2492ea8d08e
7124310: [macosx] "opposite" seems always null in focus events
leonidr
parents:
14306
diff
changeset
|
1159 |
Window opposite = LWKeyboardFocusManagerPeer.getInstance(). |
b2492ea8d08e
7124310: [macosx] "opposite" seems always null in focus events
leonidr
parents:
14306
diff
changeset
|
1160 |
getCurrentFocusedWindow(); |
b2492ea8d08e
7124310: [macosx] "opposite" seems always null in focus events
leonidr
parents:
14306
diff
changeset
|
1161 |
|
12047 | 1162 |
// Make the owner active window. |
1163 |
if (isSimpleWindow()) { |
|
1164 |
LWWindowPeer owner = getOwnerFrameDialog(this); |
|
1165 |
||
1166 |
// If owner is not natively active, request native |
|
1167 |
// activation on it w/o sending events up to java. |
|
1168 |
if (owner != null && !owner.platformWindow.isActive()) { |
|
18178
ee71c923891d
8016747: Replace deprecated PlatformLogger isLoggable(int) with isLoggable(Level)
chegar
parents:
17151
diff
changeset
|
1169 |
if (focusLog.isLoggable(PlatformLogger.Level.FINE)) { |
12047 | 1170 |
focusLog.fine("requesting native focus to the owner " + owner); |
1171 |
} |
|
20153 | 1172 |
LWWindowPeer currentActivePeer = currentActive == null ? null : |
1173 |
(LWWindowPeer) AWTAccessor.getComponentAccessor().getPeer( |
|
1174 |
currentActive); |
|
12047 | 1175 |
|
1176 |
// Ensure the opposite is natively active and suppress sending events. |
|
1177 |
if (currentActivePeer != null && currentActivePeer.platformWindow.isActive()) { |
|
18178
ee71c923891d
8016747: Replace deprecated PlatformLogger isLoggable(int) with isLoggable(Level)
chegar
parents:
17151
diff
changeset
|
1178 |
if (focusLog.isLoggable(PlatformLogger.Level.FINE)) { |
12047 | 1179 |
focusLog.fine("the opposite is " + currentActivePeer); |
1180 |
} |
|
1181 |
currentActivePeer.skipNextFocusChange = true; |
|
1182 |
} |
|
1183 |
owner.skipNextFocusChange = true; |
|
1184 |
||
1185 |
owner.platformWindow.requestWindowFocus(); |
|
1186 |
} |
|
1187 |
||
1188 |
// DKFM will synthesize all the focus/activation events correctly. |
|
14311
b2492ea8d08e
7124310: [macosx] "opposite" seems always null in focus events
leonidr
parents:
14306
diff
changeset
|
1189 |
changeFocusedWindow(true, opposite); |
12047 | 1190 |
return true; |
1191 |
||
1192 |
// In case the toplevel is active but not focused, change focus directly, |
|
1193 |
// as requesting native focus on it will not have effect. |
|
1194 |
} else if (getTarget() == currentActive && !getTarget().hasFocus()) { |
|
1195 |
||
14311
b2492ea8d08e
7124310: [macosx] "opposite" seems always null in focus events
leonidr
parents:
14306
diff
changeset
|
1196 |
changeFocusedWindow(true, opposite); |
12047 | 1197 |
return true; |
1198 |
} |
|
14311
b2492ea8d08e
7124310: [macosx] "opposite" seems always null in focus events
leonidr
parents:
14306
diff
changeset
|
1199 |
|
12047 | 1200 |
return platformWindow.requestWindowFocus(); |
1201 |
} |
|
1202 |
||
15983
26a673dec5b2
8006406: lightweight embedding in other Java UI toolkits
ant
parents:
15331
diff
changeset
|
1203 |
protected boolean focusAllowedFor() { |
12047 | 1204 |
Window window = getTarget(); |
1205 |
// TODO: check if modal blocked |
|
12663
58d40d4a87b3
7145827: [macosx] JCK failure in b11: FocusableWindow3
ant
parents:
12662
diff
changeset
|
1206 |
return window.isVisible() && window.isEnabled() && isFocusableWindow(); |
58d40d4a87b3
7145827: [macosx] JCK failure in b11: FocusableWindow3
ant
parents:
12662
diff
changeset
|
1207 |
} |
58d40d4a87b3
7145827: [macosx] JCK failure in b11: FocusableWindow3
ant
parents:
12662
diff
changeset
|
1208 |
|
58d40d4a87b3
7145827: [macosx] JCK failure in b11: FocusableWindow3
ant
parents:
12662
diff
changeset
|
1209 |
private boolean isFocusableWindow() { |
58d40d4a87b3
7145827: [macosx] JCK failure in b11: FocusableWindow3
ant
parents:
12662
diff
changeset
|
1210 |
boolean focusable = getTarget().isFocusableWindow(); |
58d40d4a87b3
7145827: [macosx] JCK failure in b11: FocusableWindow3
ant
parents:
12662
diff
changeset
|
1211 |
if (isSimpleWindow()) { |
58d40d4a87b3
7145827: [macosx] JCK failure in b11: FocusableWindow3
ant
parents:
12662
diff
changeset
|
1212 |
LWWindowPeer ownerPeer = getOwnerFrameDialog(this); |
58d40d4a87b3
7145827: [macosx] JCK failure in b11: FocusableWindow3
ant
parents:
12662
diff
changeset
|
1213 |
if (ownerPeer == null) { |
58d40d4a87b3
7145827: [macosx] JCK failure in b11: FocusableWindow3
ant
parents:
12662
diff
changeset
|
1214 |
return false; |
58d40d4a87b3
7145827: [macosx] JCK failure in b11: FocusableWindow3
ant
parents:
12662
diff
changeset
|
1215 |
} |
58d40d4a87b3
7145827: [macosx] JCK failure in b11: FocusableWindow3
ant
parents:
12662
diff
changeset
|
1216 |
return focusable && ownerPeer.getTarget().isFocusableWindow(); |
58d40d4a87b3
7145827: [macosx] JCK failure in b11: FocusableWindow3
ant
parents:
12662
diff
changeset
|
1217 |
} |
58d40d4a87b3
7145827: [macosx] JCK failure in b11: FocusableWindow3
ant
parents:
12662
diff
changeset
|
1218 |
return focusable; |
12047 | 1219 |
} |
1220 |
||
1221 |
public boolean isSimpleWindow() { |
|
1222 |
Window window = getTarget(); |
|
1223 |
return !(window instanceof Dialog || window instanceof Frame); |
|
1224 |
} |
|
1225 |
||
15983
26a673dec5b2
8006406: lightweight embedding in other Java UI toolkits
ant
parents:
15331
diff
changeset
|
1226 |
@Override |
26a673dec5b2
8006406: lightweight embedding in other Java UI toolkits
ant
parents:
15331
diff
changeset
|
1227 |
public void emulateActivation(boolean activate) { |
26a673dec5b2
8006406: lightweight embedding in other Java UI toolkits
ant
parents:
15331
diff
changeset
|
1228 |
changeFocusedWindow(activate, null); |
26a673dec5b2
8006406: lightweight embedding in other Java UI toolkits
ant
parents:
15331
diff
changeset
|
1229 |
} |
26a673dec5b2
8006406: lightweight embedding in other Java UI toolkits
ant
parents:
15331
diff
changeset
|
1230 |
|
12047 | 1231 |
/* |
12662
184d8d3b7fff
7145768: [macosx] Regression: failure in b11 of ModalDialogInFocusEventTest
ant
parents:
12640
diff
changeset
|
1232 |
* Changes focused window on java level. |
12047 | 1233 |
*/ |
15983
26a673dec5b2
8006406: lightweight embedding in other Java UI toolkits
ant
parents:
15331
diff
changeset
|
1234 |
protected void changeFocusedWindow(boolean becomesFocused, Window opposite) { |
18178
ee71c923891d
8016747: Replace deprecated PlatformLogger isLoggable(int) with isLoggable(Level)
chegar
parents:
17151
diff
changeset
|
1235 |
if (focusLog.isLoggable(PlatformLogger.Level.FINE)) { |
12047 | 1236 |
focusLog.fine((becomesFocused?"gaining":"loosing") + " focus window: " + this); |
1237 |
} |
|
12662
184d8d3b7fff
7145768: [macosx] Regression: failure in b11 of ModalDialogInFocusEventTest
ant
parents:
12640
diff
changeset
|
1238 |
if (skipNextFocusChange) { |
12047 | 1239 |
focusLog.fine("skipping focus change"); |
1240 |
skipNextFocusChange = false; |
|
1241 |
return; |
|
1242 |
} |
|
12663
58d40d4a87b3
7145827: [macosx] JCK failure in b11: FocusableWindow3
ant
parents:
12662
diff
changeset
|
1243 |
if (!isFocusableWindow() && becomesFocused) { |
58d40d4a87b3
7145827: [macosx] JCK failure in b11: FocusableWindow3
ant
parents:
12662
diff
changeset
|
1244 |
focusLog.fine("the window is not focusable"); |
12047 | 1245 |
return; |
1246 |
} |
|
1247 |
if (becomesFocused) { |
|
1248 |
synchronized (getPeerTreeLock()) { |
|
1249 |
if (blocker != null) { |
|
18178
ee71c923891d
8016747: Replace deprecated PlatformLogger isLoggable(int) with isLoggable(Level)
chegar
parents:
17151
diff
changeset
|
1250 |
if (focusLog.isLoggable(PlatformLogger.Level.FINEST)) { |
12047 | 1251 |
focusLog.finest("the window is blocked by " + blocker); |
1252 |
} |
|
1253 |
return; |
|
1254 |
} |
|
1255 |
} |
|
1256 |
} |
|
1257 |
||
1258 |
// Note, the method is not called: |
|
1259 |
// - when the opposite (gaining focus) window is an owned/owner window. |
|
1260 |
// - for a simple window in any case. |
|
1261 |
if (!becomesFocused && |
|
1262 |
(isGrabbing() || getOwnerFrameDialog(grabbingWindow) == this)) |
|
1263 |
{ |
|
18178
ee71c923891d
8016747: Replace deprecated PlatformLogger isLoggable(int) with isLoggable(Level)
chegar
parents:
17151
diff
changeset
|
1264 |
if (focusLog.isLoggable(PlatformLogger.Level.FINE)) { |
16839
d0f2e97b7359
8010297: Missing isLoggable() checks in logging code
anthony
parents:
15983
diff
changeset
|
1265 |
focusLog.fine("ungrabbing on " + grabbingWindow); |
d0f2e97b7359
8010297: Missing isLoggable() checks in logging code
anthony
parents:
15983
diff
changeset
|
1266 |
} |
12047 | 1267 |
// ungrab a simple window if its owner looses activation. |
1268 |
grabbingWindow.ungrab(); |
|
1269 |
} |
|
1270 |
||
14311
b2492ea8d08e
7124310: [macosx] "opposite" seems always null in focus events
leonidr
parents:
14306
diff
changeset
|
1271 |
KeyboardFocusManagerPeer kfmPeer = LWKeyboardFocusManagerPeer.getInstance(); |
13648
90effcfc064f
7124375: [macosx] Focus isn't transfered as expected between components
leonidr
parents:
13647
diff
changeset
|
1272 |
kfmPeer.setCurrentFocusedWindow(becomesFocused ? getTarget() : null); |
12047 | 1273 |
|
1274 |
int eventID = becomesFocused ? WindowEvent.WINDOW_GAINED_FOCUS : WindowEvent.WINDOW_LOST_FOCUS; |
|
14311
b2492ea8d08e
7124310: [macosx] "opposite" seems always null in focus events
leonidr
parents:
14306
diff
changeset
|
1275 |
WindowEvent windowEvent = new TimedWindowEvent(getTarget(), eventID, opposite, System.currentTimeMillis()); |
12047 | 1276 |
|
1277 |
// TODO: wrap in SequencedEvent |
|
1278 |
postEvent(windowEvent); |
|
1279 |
} |
|
1280 |
||
12662
184d8d3b7fff
7145768: [macosx] Regression: failure in b11 of ModalDialogInFocusEventTest
ant
parents:
12640
diff
changeset
|
1281 |
static LWWindowPeer getOwnerFrameDialog(LWWindowPeer peer) { |
12047 | 1282 |
Window owner = (peer != null ? peer.getTarget().getOwner() : null); |
1283 |
while (owner != null && !(owner instanceof Frame || owner instanceof Dialog)) { |
|
1284 |
owner = owner.getOwner(); |
|
1285 |
} |
|
20153 | 1286 |
return owner == null ? null : |
1287 |
(LWWindowPeer) AWTAccessor.getComponentAccessor().getPeer(owner); |
|
12047 | 1288 |
} |
1289 |
||
1290 |
/** |
|
1291 |
* Returns the foremost modal blocker of this window, or null. |
|
1292 |
*/ |
|
1293 |
public LWWindowPeer getBlocker() { |
|
1294 |
synchronized (getPeerTreeLock()) { |
|
1295 |
LWWindowPeer blocker = this.blocker; |
|
1296 |
if (blocker == null) { |
|
1297 |
return null; |
|
1298 |
} |
|
1299 |
while (blocker.blocker != null) { |
|
1300 |
blocker = blocker.blocker; |
|
1301 |
} |
|
1302 |
return blocker; |
|
1303 |
} |
|
1304 |
} |
|
1305 |
||
20153 | 1306 |
@Override |
12047 | 1307 |
public void enterFullScreenMode() { |
1308 |
platformWindow.enterFullScreenMode(); |
|
18241 | 1309 |
updateSecurityWarningVisibility(); |
12047 | 1310 |
} |
1311 |
||
20153 | 1312 |
@Override |
12047 | 1313 |
public void exitFullScreenMode() { |
1314 |
platformWindow.exitFullScreenMode(); |
|
18241 | 1315 |
updateSecurityWarningVisibility(); |
12047 | 1316 |
} |
1317 |
||
1318 |
public long getLayerPtr() { |
|
1319 |
return getPlatformWindow().getLayerPtr(); |
|
1320 |
} |
|
1321 |
||
1322 |
void grab() { |
|
1323 |
if (grabbingWindow != null && !isGrabbing()) { |
|
1324 |
grabbingWindow.ungrab(); |
|
1325 |
} |
|
1326 |
grabbingWindow = this; |
|
1327 |
} |
|
1328 |
||
15323
9087838098e6
8006417: JComboBox.showPopup(), hidePopup() fails in JRE 1.7 on OS X
alitvinov
parents:
14753
diff
changeset
|
1329 |
final void ungrab(boolean doPost) { |
12047 | 1330 |
if (isGrabbing()) { |
1331 |
grabbingWindow = null; |
|
15323
9087838098e6
8006417: JComboBox.showPopup(), hidePopup() fails in JRE 1.7 on OS X
alitvinov
parents:
14753
diff
changeset
|
1332 |
if (doPost) { |
9087838098e6
8006417: JComboBox.showPopup(), hidePopup() fails in JRE 1.7 on OS X
alitvinov
parents:
14753
diff
changeset
|
1333 |
postEvent(new UngrabEvent(getTarget())); |
9087838098e6
8006417: JComboBox.showPopup(), hidePopup() fails in JRE 1.7 on OS X
alitvinov
parents:
14753
diff
changeset
|
1334 |
} |
12047 | 1335 |
} |
1336 |
} |
|
1337 |
||
15323
9087838098e6
8006417: JComboBox.showPopup(), hidePopup() fails in JRE 1.7 on OS X
alitvinov
parents:
14753
diff
changeset
|
1338 |
void ungrab() { |
9087838098e6
8006417: JComboBox.showPopup(), hidePopup() fails in JRE 1.7 on OS X
alitvinov
parents:
14753
diff
changeset
|
1339 |
ungrab(true); |
9087838098e6
8006417: JComboBox.showPopup(), hidePopup() fails in JRE 1.7 on OS X
alitvinov
parents:
14753
diff
changeset
|
1340 |
} |
9087838098e6
8006417: JComboBox.showPopup(), hidePopup() fails in JRE 1.7 on OS X
alitvinov
parents:
14753
diff
changeset
|
1341 |
|
12047 | 1342 |
private boolean isGrabbing() { |
1343 |
return this == grabbingWindow; |
|
1344 |
} |
|
1345 |
||
14753
a56a685d137f
7154778: [macosx] NSView-based implementation of sun.awt.EmbeddedFrame
serb
parents:
14647
diff
changeset
|
1346 |
public PeerType getPeerType() { |
a56a685d137f
7154778: [macosx] NSView-based implementation of sun.awt.EmbeddedFrame
serb
parents:
14647
diff
changeset
|
1347 |
return peerType; |
a56a685d137f
7154778: [macosx] NSView-based implementation of sun.awt.EmbeddedFrame
serb
parents:
14647
diff
changeset
|
1348 |
} |
a56a685d137f
7154778: [macosx] NSView-based implementation of sun.awt.EmbeddedFrame
serb
parents:
14647
diff
changeset
|
1349 |
|
18241 | 1350 |
public void updateSecurityWarningVisibility() { |
1351 |
if (warningWindow == null) { |
|
1352 |
return; |
|
1353 |
} |
|
1354 |
||
1355 |
if (!isVisible()) { |
|
1356 |
return; // The warning window should already be hidden. |
|
1357 |
} |
|
1358 |
||
1359 |
boolean show = false; |
|
1360 |
||
1361 |
if (!platformWindow.isFullScreenMode()) { |
|
1362 |
if (isVisible()) { |
|
1363 |
if (LWKeyboardFocusManagerPeer.getInstance().getCurrentFocusedWindow() == |
|
1364 |
getTarget()) { |
|
1365 |
show = true; |
|
1366 |
} |
|
1367 |
||
1368 |
if (platformWindow.isUnderMouse() || warningWindow.isUnderMouse()) { |
|
1369 |
show = true; |
|
1370 |
} |
|
1371 |
} |
|
1372 |
} |
|
1373 |
||
1374 |
warningWindow.setVisible(show, true); |
|
1375 |
} |
|
1376 |
||
12047 | 1377 |
@Override |
1378 |
public String toString() { |
|
1379 |
return super.toString() + " [target is " + getTarget() + "]"; |
|
1380 |
} |
|
1381 |
} |