提交 f2471e53 编写于 作者: Y yan

Merge

......@@ -6666,7 +6666,7 @@ public abstract class Component implements ImageObserver, MenuContainer,
// Update stacking order
peer.setZOrder(getHWPeerAboveMe());
updateZOrder();
if (!isAddNotifyComplete) {
mixOnShowing();
......@@ -9838,4 +9838,11 @@ public abstract class Component implements ImageObserver, MenuContainer,
return doesClassImplement(obj.getClass(), interfaceName);
}
// Note that the method is overriden in the Window class,
// a window doesn't need to be updated in the Z-order.
void updateZOrder() {
peer.setZOrder(getHWPeerAboveMe());
}
}
......@@ -840,7 +840,7 @@ public class Container extends Component {
// Native container changed - need to reparent native widgets
newNativeContainer.reparentChild(comp);
}
comp.peer.setZOrder(comp.getHWPeerAboveMe());
comp.updateZOrder();
if (!comp.isLightweight() && isLightweight()) {
// If component is heavyweight and one of the containers is lightweight
......@@ -3977,10 +3977,8 @@ public class Container extends Component {
Component comp = getComponent(index);
if (!comp.isLightweight()) {
comp.applyCurrentShape();
if (comp instanceof Container && ((Container)comp).getLayout() == null) {
((Container)comp).recursiveApplyCurrentShape();
}
} else if (comp instanceof Container &&
}
if (comp instanceof Container &&
((Container)comp).hasHeavyweightDescendants()) {
((Container)comp).recursiveApplyCurrentShape();
}
......
......@@ -440,13 +440,14 @@ public abstract class GraphicsConfiguration {
* the {@link GraphicsDevice.WindowTranslucency#PERPIXEL_TRANSLUCENT
* PERPIXEL_TRANSLUCENT} kind of translucency.
*
* @param gc GraphicsConfiguration
* @throws NullPointerException if the gc argument is null
* @return whether the given GraphicsConfiguration supports
* the translucency effects.
*
* @see Window#setBackground(Color)
*
* @since 1.7
*/
/*public */boolean isTranslucencyCapable() {
public boolean isTranslucencyCapable() {
// Overridden in subclasses
return false;
}
......
......@@ -112,10 +112,14 @@ public abstract class GraphicsDevice {
*/
public final static int TYPE_IMAGE_BUFFER = 2;
/** Kinds of translucency supported by the underlying system.
* @see #isTranslucencySupported
/**
* Kinds of translucency supported by the underlying system.
*
* @see #isWindowTranslucencySupported
*
* @since 1.7
*/
/*public */static enum WindowTranslucency {
public static enum WindowTranslucency {
/**
* Represents support in the underlying system for windows each pixel
* of which is guaranteed to be either completely opaque, with
......@@ -246,38 +250,44 @@ public abstract class GraphicsDevice {
* full-screen window is not visible, this method will make it visible.
* It will remain visible when returning to windowed mode.
* <p>
* When returning to windowed mode from an exclusive full-screen window, any
* display changes made by calling <code>setDisplayMode</code> are
* When entering full-screen mode, all the translucency effects are reset for
* the window. Its shape is set to {@code null}, the opacity value is set to
* 1.0f, and the background color alpha is set to 255 (completely opaque).
* These values are not restored when returning to windowed mode.
* <p>
* When returning to windowed mode from an exclusive full-screen window,
* any display changes made by calling {@code setDisplayMode} are
* automatically restored to their original state.
*
* @param w a window to use as the full-screen window; <code>null</code>
* @param w a window to use as the full-screen window; {@code null}
* if returning to windowed mode. Some platforms expect the
* fullscreen window to be a top-level component (i.e., a Frame);
* therefore it is preferable to use a Frame here rather than a
* Window.
*
* @see #isFullScreenSupported
* @see #getFullScreenWindow
* @see #setDisplayMode
* @see Component#enableInputMethods
* @see Component#setVisible
*
* @since 1.4
*/
public void setFullScreenWindow(Window w) {
if (w != null) {
//XXX: The actions should be documented in some non-update release.
/*
if (w.getShape() != null) {
w.setShape(w, null);
}
if (!w.isOpaque()) {
w.setOpaque(false);
w.setShape(null);
}
if (w.getOpacity() < 1.0f) {
w.setOpacity(1.0f);
}
*/
Color bgColor = w.getBackground();
if (bgColor.getAlpha() < 255) {
bgColor = new Color(bgColor.getRed(), bgColor.getGreen(),
bgColor.getBlue(), 255);
w.setBackground(bgColor);
}
}
if (fullScreenWindow != null && windowedModeBounds != null) {
// if the window went into fs mode before it was realized it may
// have (0,0) dimensions
......@@ -469,13 +479,15 @@ public abstract class GraphicsDevice {
}
/**
* Returns whether the given level of translucency is supported
* Returns whether the given level of translucency is supported by
* this graphics device.
*
* @param translucencyKind a kind of translucency support
* @return whether the given translucency kind is supported
*
* @since 1.7
*/
/*public */boolean isWindowTranslucencySupported(WindowTranslucency translucencyKind) {
public boolean isWindowTranslucencySupported(WindowTranslucency translucencyKind) {
switch (translucencyKind) {
case PERPIXEL_TRANSPARENT:
return isWindowShapingSupported();
......
......@@ -25,6 +25,7 @@
package java.awt;
import java.awt.event.*;
import java.awt.geom.Path2D;
import java.awt.geom.Point2D;
import java.awt.im.InputContext;
import java.awt.image.BufferStrategy;
......@@ -297,6 +298,7 @@ public class Window extends Container implements Accessible {
/*
* Opacity level of the window
*
* @serial
* @see #setOpacity(float)
* @see #getOpacity()
* @since 1.7
......@@ -307,6 +309,7 @@ public class Window extends Container implements Accessible {
* The shape assigned to this window. This field is set to null if
* no shape is set (rectangular window).
*
* @serial
* @see #getShape()
* @see #setShape(Shape)
* @since 1.7
......@@ -3340,32 +3343,78 @@ public class Window extends Container implements Accessible {
// ******************** SHAPES & TRANSPARENCY CODE ********************
/**
* JavaDoc
* Returns the opacity of the window.
*
* @return the opacity of the window
*
* @see Window#setOpacity
* @see GraphicsDevice.WindowTranslucency
*
* @since 1.7
*/
/*public */float getOpacity() {
public float getOpacity() {
synchronized (getTreeLock()) {
return opacity;
}
}
/**
* JavaDoc
* Sets the opacity of the window.
* <p>
* The opacity value is in the range [0..1]. Note that setting the opacity
* level of 0 may or may not disable the mouse event handling on this
* window. This is a platform-dependent behavior.
* <p>
* In order for this method to enable the translucency effect, the {@link
* GraphicsDevice#isWindowTranslucencySupported()} method must indicate that
* the {@link GraphicsDevice.WindowTranslucency#TRANSLUCENT TRANSLUCENT}
* translucency is supported.
* <p>
* Also note that the window must not be in the full-screen mode when
* setting the opacity value &lt; 1.0f. Otherwise the {@code
* IllegalComponentStateException} is thrown.
* <p>
* The translucency levels of individual pixels may also be effected by the
* alpha component of their color (see {@link setBackground()}) and the
* current shape of this window (see {@link setShape()}).
*
* @param opacity the opacity level to set to the window
*
* @throws IllegalArgumentException if the opacity is out of the range
* [0..1]
* @throws IllegalComponentStateException if the window is in full screen
* mode, and the opacity is less than 1.0f
* @throws UnsupportedOperationException if the {@code
* GraphicsDevice.WindowTranslucency#TRANSLUCENT TRANSLUCENT}
* translucency kind is not supported and the opacity is less than 1.0f
*
* @see Window#getOpacity
* @see Window#setBackground()
* @see Window#setShape()
* @see GraphicsDevice.WindowTranslucency
* @see GraphicsDevice#isWindowTranslucencySupported()
*
* @since 1.7
*/
/*public */void setOpacity(float opacity) {
public void setOpacity(float opacity) {
synchronized (getTreeLock()) {
if (opacity < 0.0f || opacity > 1.0f) {
throw new IllegalArgumentException(
"The value of opacity should be in the range [0.0f .. 1.0f].");
}
GraphicsConfiguration gc = getGraphicsConfiguration();
GraphicsDevice gd = gc.getDevice();
if (!gd.isWindowTranslucencySupported(GraphicsDevice.WindowTranslucency.TRANSLUCENT)) {
throw new UnsupportedOperationException(
if (opacity < 1.0f) {
GraphicsConfiguration gc = getGraphicsConfiguration();
GraphicsDevice gd = gc.getDevice();
if (gc.getDevice().getFullScreenWindow() == this) {
throw new IllegalComponentStateException(
"Setting opacity for full-screen window is not supported.");
}
if (!gd.isWindowTranslucencySupported(
GraphicsDevice.WindowTranslucency.TRANSLUCENT))
{
throw new UnsupportedOperationException(
"TRANSLUCENT translucency is not supported.");
}
if ((gc.getDevice().getFullScreenWindow() == this) && (opacity < 1.0f)) {
throw new IllegalArgumentException(
"Setting opacity for full-screen window is not supported.");
}
}
this.opacity = opacity;
WindowPeer peer = (WindowPeer)getPeer();
......@@ -3376,37 +3425,86 @@ public class Window extends Container implements Accessible {
}
/**
* JavaDoc
* Returns the shape of the window.
*
* The value returned by this method may not be the same as
* previously set with {@code setShape(shape)}, but it is guaranteed
* to represent the same shape.
*
* @return the shape of the window or {@code null} if no
* shape is specified for the window
*
* @see Window#setShape
* @see GraphicsDevice.WindowTranslucency
*
* @since 1.7
*/
/*public */Shape getShape() {
public Shape getShape() {
synchronized (getTreeLock()) {
return shape;
return shape == null ? null : new Path2D.Float(shape);
}
}
/**
* JavaDoc
* Sets the shape of the window.
* <p>
* Setting a shape enables cutting off some parts of the window, leaving
* visible and clickable only those parts belonging to the given shape
* (see {@link Shape}). If the shape argument is null, this methods
* restores the default shape (making the window rectangular on most
* platforms.)
* <p>
* The following conditions must be met in order to set a non-null shape:
* <ul>
* <li>The {@link GraphicsDevice.WindowTranslucency#PERPIXEL_TRANSPARENT
* PERPIXEL_TRANSPARENT} translucency kind must be supported by the
* underlying system (see {@link })
* <i>and</i>
* <li>The window must not be in the full-screen mode (see
* {@link GraphicsDevice#setFullScreenWindow()})
* </ul>
* If a certain condition is not met, either the {@code
* UnsupportedOperationException} or {@code IllegalComponentStateException}
* is thrown.
* <p>
* The tranlucency levels of individual pixels may also be effected by the
* alpha component of their color (see {@link setBackground()}) and the
* opacity value (see {@link setOpacity()}). See {@link
* GraphicsDevice#WindowTranslucency} for more details.
*
* @param window the window to set the shape to
* @param shape the shape to set to the window
* @throws IllegalArgumentException if the window is in full screen mode,
* and the shape is not null
*
* @throws IllegalComponentStateException if the shape is not {@code
* null} and the window is in full-screen mode
* @throws UnsupportedOperationException if the shape is not {@code
* null} and {@link GraphicsDevice.WindowTranslucency#PERPIXEL_TRANSPARENT
* PERPIXEL_TRANSPARENT} translucency is not supported
*
* @see Window#getShape()
* @see Window#setBackgound()
* @see Window#setOpacity()
* @see GraphicsDevice.WindowTranslucency
* @see GraphicsDevice#isWindowTranslucencySupported()
*
* @since 1.7
*/
/*public */void setShape(Shape shape) {
public void setShape(Shape shape) {
synchronized (getTreeLock()) {
GraphicsConfiguration gc = getGraphicsConfiguration();
GraphicsDevice gd = gc.getDevice();
if (!gd.isWindowTranslucencySupported(
GraphicsDevice.WindowTranslucency.PERPIXEL_TRANSPARENT))
{
throw new UnsupportedOperationException(
if (shape != null) {
GraphicsConfiguration gc = getGraphicsConfiguration();
GraphicsDevice gd = gc.getDevice();
if (gc.getDevice().getFullScreenWindow() == this) {
throw new IllegalComponentStateException(
"Setting shape for full-screen window is not supported.");
}
if (!gd.isWindowTranslucencySupported(
GraphicsDevice.WindowTranslucency.PERPIXEL_TRANSPARENT))
{
throw new UnsupportedOperationException(
"PERPIXEL_TRANSPARENT translucency is not supported.");
}
}
if ((gc.getDevice().getFullScreenWindow() == this) && (shape != null)) {
throw new IllegalArgumentException(
"Setting shape for full-screen window is not supported.");
}
this.shape = shape;
this.shape = (shape == null) ? null : new Path2D.Float(shape);
WindowPeer peer = (WindowPeer)getPeer();
if (peer != null) {
peer.applyShape(shape == null ? null : Region.getInstance(shape, null));
......@@ -3415,66 +3513,115 @@ public class Window extends Container implements Accessible {
}
/**
* JavaDoc
* Gets the background color of this window.
* <p>
* Note that the alpha component of the returned color indicates whether
* the window is in the non-opaque (per-pixel translucent) mode.
*
* @return this component's background color
*
* @see Window#setBackground
* @see GraphicsDevice.WindowTranslucency
*/
@Override
public Color getBackground() {
return super.getBackground();
}
/**
* Sets the background color of this window.
* <p>
* If the windowing system supports the {@link
* GraphicsDevice.WindowTranslucency#PERPIXEL_TRANSLUCENT PERPIXEL_TRANSLUCENT}
* tranclucency, the alpha component of the given background color
* may effect the mode of operation for this window: it indicates whether
* this window must be opaque (alpha == 1.0f) or per-pixel translucent
* (alpha &lt; 1.0f). All the following conditions must be met in order
* to be able to enable the per-pixel transparency mode for this window:
* <ul>
* <li>The {@link GraphicsDevice.WindowTranslucency#PERPIXEL_TRANSLUCENT
* PERPIXEL_TRANSLUCENT} translucency must be supported
* by the graphics device where this window is located <i>and</i>
* <li>The window must not be in the full-screen mode (see {@link
* GraphicsDevice#setFullScreenWindow()})
* </ul>
* If a certain condition is not met at the time of calling this method,
* the alpha component of the given background color will not effect the
* mode of operation for this window.
* <p>
* When the window is per-pixel translucent, the drawing sub-system
* respects the alpha value of each individual pixel. If a pixel gets
* painted with the alpha color component equal to zero, it becomes
* visually transparent, if the alpha of the pixel is equal to 1.0f, the
* pixel is fully opaque. Interim values of the alpha color component make
* the pixel semi-transparent. In this mode the background of the window
* gets painted with the alpha value of the given background color (meaning
* that it is not painted at all if the alpha value of the argument of this
* method is equal to zero.)
* <p>
* The actual level of translucency of a given pixel also depends on window
* opacity (see {@link setOpacity()}), as well as the current shape of
* this window (see {@link setShape()}).
* <p>
* Note that painting a pixel with the alpha value of 0 may or may not
* disable the mouse event handling on this pixel. This is a
* platform-dependent behavior. To make sure the mouse clicks do not get
* dispatched to a particular pixel, the pixel must be excluded from the
* shape of the window.
* <p>
* Enabling the per-pixel translucency mode may change the graphics
* configuration of this window due to the native platform requirements.
*
* @param bgColor the color to become this window's background color.
*
* @throws IllegalComponentStateException if the alpha value of the given
* background color is less than 1.0f and the window is in
* full-screen mode
* @throws UnsupportedOperationException if the alpha value of the given
* background color is less than 1.0f and
* {@link GraphicsDevice.WindowTranslucency#PERPIXEL_TRANSLUCENT
* PERPIXEL_TRANSLUCENT} translucency is not supported
*
* @see Window#getBackground
* @see Window#setOpacity()
* @see Window#setShape()
* @see GraphicsDevice.WindowTranslucency
* @see GraphicsDevice#isWindowTranslucencySupported()
* @see GraphicsConfiguration#isTranslucencyCapable()
*/
/*
@Override
public void setBackground(Color bgColor) {
Color oldBg = getBackground();
if (oldBg != null && oldBg.equals(bgColor)) {
return;
}
super.setBackground(bgColor);
int oldAlpha = oldBg != null ? oldBg.getAlpha() : 255;
int alpha = bgColor.getAlpha();
if (alpha < 255) { // non-opaque window
if ((oldAlpha == 255) && (alpha < 255)) { // non-opaque window
GraphicsConfiguration gc = getGraphicsConfiguration();
GraphicsDevice gd = gc.getDevice();
if (gc.getDevice().getFullScreenWindow() == this) {
throw new IllegalArgumentException(
throw new IllegalComponentStateException(
"Making full-screen window non opaque is not supported.");
}
if (!gc.isTranslucencyCapable()) {
GraphicsConfiguration capableGC = gd.getTranslucencyCapableGC();
if (capableGC == null) {
throw new IllegalArgumentException(
throw new UnsupportedOperationException(
"PERPIXEL_TRANSLUCENT translucency is not supported");
}
// TODO: change GC
setGraphicsConfiguration(capableGC);
}
setLayersOpaque(this, false);
} else if ((oldAlpha < 255) && (alpha == 255)) {
setLayersOpaque(this, true);
}
super.setBackground(bgColor);
WindowPeer peer = (WindowPeer)getPeer();
if (peer != null) {
peer.setOpaque(alpha == 255);
}
}
*/
private transient boolean opaque = true;
void setOpaque(boolean opaque) {
synchronized (getTreeLock()) {
GraphicsConfiguration gc = getGraphicsConfiguration();
if (!opaque && !com.sun.awt.AWTUtilities.isTranslucencyCapable(gc)) {
throw new IllegalArgumentException(
"The window must use a translucency-compatible graphics configuration");
}
if (!com.sun.awt.AWTUtilities.isTranslucencySupported(
com.sun.awt.AWTUtilities.Translucency.PERPIXEL_TRANSLUCENT))
{
throw new UnsupportedOperationException(
"PERPIXEL_TRANSLUCENT translucency is not supported.");
}
if ((gc.getDevice().getFullScreenWindow() == this) && !opaque) {
throw new IllegalArgumentException(
"Making full-screen window non opaque is not supported.");
}
setLayersOpaque(this, opaque);
this.opaque = opaque;
WindowPeer peer = (WindowPeer)getPeer();
if (peer != null) {
peer.setOpaque(opaque);
}
}
}
private void updateWindow(BufferedImage backBuffer) {
synchronized (getTreeLock()) {
......@@ -3505,10 +3652,10 @@ public class Window extends Container implements Accessible {
}
lp.setOpaque(isOpaque);
root.setOpaque(isOpaque);
root.setDoubleBuffered(isOpaque); //XXX: the "white rect" workaround
root.setDoubleBuffered(isOpaque);
if (content != null) {
content.setOpaque(isOpaque);
content.setDoubleBuffered(isOpaque); //XXX: the "white rect" workaround
content.setDoubleBuffered(isOpaque);
// Iterate down one level to see whether we have a JApplet
// (which is also a RootPaneContainer) which requires processing
......@@ -3523,36 +3670,6 @@ public class Window extends Container implements Accessible {
}
}
}
Color bg = component.getBackground();
boolean hasTransparentBg = TRANSPARENT_BACKGROUND_COLOR.equals(bg);
Container container = null;
if (component instanceof Container) {
container = (Container) component;
}
if (isOpaque) {
if (hasTransparentBg) {
// Note: we use the SystemColor.window color as the default.
// This color is used in the WindowPeer implementations to
// initialize the background color of the window if it is null.
// (This might not be the right thing to do for other
// RootPaneContainers we might be invoked with)
Color newColor = null;
if (container != null && container.preserveBackgroundColor != null) {
newColor = container.preserveBackgroundColor;
} else {
newColor = SystemColor.window;
}
component.setBackground(newColor);
}
} else {
if (!hasTransparentBg && container != null) {
container.preserveBackgroundColor = bg;
}
component.setBackground(TRANSPARENT_BACKGROUND_COLOR);
}
}
......@@ -3620,20 +3737,16 @@ public class Window extends Container implements Accessible {
window.setShape(shape);
}
public boolean isOpaque(Window window) {
/*
return window.getBackground().getAlpha() < 255;
*/
synchronized (window.getTreeLock()) {
return window.opaque;
}
Color bg = window.getBackground();
return (bg != null) ? bg.getAlpha() == 255 : true;
}
public void setOpaque(Window window, boolean opaque) {
/*
Color bg = window.getBackground();
if (bg == null) {
bg = new Color(0, 0, 0, 0);
}
window.setBackground(new Color(bg.getRed(), bg.getGreen(), bg.getBlue(),
opaque ? 255 : 0));
*/
window.setOpaque(opaque);
}
public void updateWindow(Window window, BufferedImage backBuffer) {
window.updateWindow(backBuffer);
......@@ -3674,6 +3787,10 @@ public class Window extends Container implements Accessible {
}); // WindowAccessor
} // static
// a window doesn't need to be updated in the Z-order.
@Override
void updateZOrder() {}
} // class Window
......
......@@ -45,7 +45,6 @@ import java.util.*;
import java.util.Collections;
import java.util.Locale;
import java.util.WeakHashMap;
import javax.swing.SwingUtilities;
import sun.awt.AppContext;
import sun.awt.EmbeddedFrame;
import sun.awt.SunToolkit;
......@@ -450,7 +449,7 @@ abstract class AppletPanel extends Panel implements AppletStub, Runnable {
try {
final AppletPanel p = this;
SwingUtilities.invokeAndWait(new Runnable() {
EventQueue.invokeAndWait(new Runnable() {
public void run() {
p.validate();
}
......@@ -480,7 +479,7 @@ abstract class AppletPanel extends Panel implements AppletStub, Runnable {
final AppletPanel p = this;
final Applet a = applet;
SwingUtilities.invokeAndWait(new Runnable() {
EventQueue.invokeAndWait(new Runnable() {
public void run() {
p.validate();
a.setVisible(true);
......@@ -514,7 +513,7 @@ abstract class AppletPanel extends Panel implements AppletStub, Runnable {
try {
final Applet a = applet;
SwingUtilities.invokeAndWait(new Runnable() {
EventQueue.invokeAndWait(new Runnable() {
public void run()
{
a.setVisible(false);
......
......@@ -588,9 +588,11 @@ public abstract class EmbeddedFrame extends Frame
public void setOpacity(float opacity) {
}
public void setOpaque(boolean isOpaque) {
}
public void updateWindow(BufferedImage backBuffer) {
public void updateWindow(BufferedImage bi) {
}
public void repositionSecurityWarning() {
}
......
......@@ -2038,37 +2038,34 @@ public abstract class SunToolkit extends Toolkit
/**
* Returns whether or not a containing top level window for the passed
* component is
* {@link com.sun.awt.AWTUtilities.Translucency#PERPIXEL_TRANSLUCENT PERPIXEL_TRANSLUCENT}.
* {@link GraphicsDevice.WindowTranslucency#PERPIXEL_TRANSLUCENT PERPIXEL_TRANSLUCENT}.
*
* @param c a Component which toplevel's to check
* @return {@code true} if the passed component is not null and has a
* containing toplevel window which is opaque (so per-pixel translucency
* is not enabled), {@code false} otherwise
* @see com.sun.awt.AWTUtilities.Translucency#PERPIXEL_TRANSLUCENT
* @see com.sun.awt.AWTUtilities#isWindowOpaque(Window)
* @see GraphicsDevice.WindowTranslucency#PERPIXEL_TRANSLUCENT
*/
public static boolean isContainingTopLevelOpaque(Component c) {
Window w = getContainingWindow(c);
// return w != null && (w).isOpaque();
return w != null && com.sun.awt.AWTUtilities.isWindowOpaque(w);
return w != null && ((Window)w).getBackground() != null &&
((Window)w).getBackground().getAlpha() == 255;
}
/**
* Returns whether or not a containing top level window for the passed
* component is
* {@link com.sun.awt.AWTUtilities.Translucency#TRANSLUCENT TRANSLUCENT}.
* {@link GraphicsDevice.WindowTranslucency#TRANSLUCENT TRANSLUCENT}.
*
* @param c a Component which toplevel's to check
* @return {@code true} if the passed component is not null and has a
* containing toplevel window which has opacity less than
* 1.0f (which means that it is translucent), {@code false} otherwise
* @see com.sun.awt.AWTUtilities.Translucency#TRANSLUCENT
* @see com.sun.awt.AWTUtilities#getWindowOpacity(Window)
* @see GraphicsDevice.WindowTranslucency#TRANSLUCENT
*/
public static boolean isContainingTopLevelTranslucent(Component c) {
Window w = getContainingWindow(c);
// return w != null && (w).getOpacity() < 1.0f;
return w != null && com.sun.awt.AWTUtilities.getWindowOpacity((Window)w) < 1.0f;
return w != null && ((Window)w).getOpacity() < 1.0f;
}
/**
......
......@@ -65,10 +65,13 @@ import java.lang.reflect.Modifier;
import java.rmi.MarshalledObject;
import java.security.AccessControlContext;
import java.security.AccessControlException;
import java.security.AccessController;
import java.security.PrivilegedAction;
import java.security.PrivilegedActionException;
import java.security.PrivilegedExceptionAction;
import java.security.ProtectionDomain;
import java.util.ArrayList;
import java.util.Arrays;
......@@ -111,6 +114,8 @@ import javax.imageio.stream.ImageOutputStream;
import sun.awt.image.ImageRepresentation;
import sun.awt.image.ToolkitImage;
import java.io.FilePermission;
/**
* Provides a set of functions to be shared among the DataFlavor class and
......@@ -1177,8 +1182,10 @@ search:
(String.class.equals(flavor.getRepresentationClass()) &&
isFlavorCharsetTextType(flavor) && isTextFormat(format))) {
String str = removeSuspectedData(flavor, contents, (String)obj);
return translateTransferableString(
(String)obj,
str,
format);
// Source data is a Reader. Convert to a String and recur. In the
......@@ -1286,6 +1293,11 @@ search:
throw new IOException("data translation failed");
}
final List list = (List)obj;
final ArrayList fileList = new ArrayList();
final ProtectionDomain userProtectionDomain = getUserProtectionDomain(contents);
int nFiles = 0;
for (int i = 0; i < list.size(); i++) {
Object o = list.get(i);
......@@ -1293,17 +1305,18 @@ search:
nFiles++;
}
}
final String[] files = new String[nFiles];
try {
AccessController.doPrivileged(new PrivilegedExceptionAction() {
public Object run() throws IOException {
for (int i = 0, j = 0; i < list.size(); i++) {
Object o = list.get(i);
if (o instanceof File) {
files[j++] = ((File)o).getCanonicalPath();
} else if (o instanceof String) {
files[j++] = (String)o;
for (Object fileObject : list)
{
File file = castToFile(fileObject);
if (null == System.getSecurityManager() ||
!(isFileInWebstartedCache(file) ||
isForbiddenToRead(file, userProtectionDomain)))
{
fileList.add(file.getCanonicalPath());
}
}
return null;
......@@ -1313,10 +1326,11 @@ search:
throw new IOException(pae.getMessage());
}
for (int i = 0; i < files.length; i++) {
byte[] bytes = files[i].getBytes();
if (i != 0) bos.write(0);
bos.write(bytes, 0, bytes.length);
for (int i = 0; i < fileList.size(); i++)
{
byte[] bytes = ((String)fileList.get(i)).getBytes();
if (i != 0) bos.write(0);
bos.write(bytes, 0, bytes.length);
}
// Source data is an InputStream. For arbitrary flavors, just grab the
......@@ -1366,6 +1380,123 @@ search:
return ret;
}
private String removeSuspectedData(DataFlavor flavor, final Transferable contents, final String str)
throws IOException
{
if (null == System.getSecurityManager()
|| !flavor.isMimeTypeEqual("text/uri-list"))
{
return str;
}
String ret_val = "";
final ProtectionDomain userProtectionDomain = getUserProtectionDomain(contents);
try {
ret_val = (String) AccessController.doPrivileged(new PrivilegedExceptionAction() {
public Object run() {
StringBuffer allowedFiles = new StringBuffer(str.length());
String [] uriArray = str.split("(\\s)+");
for (String fileName : uriArray)
{
File file = new File(fileName);
if (file.exists() &&
!(isFileInWebstartedCache(file) ||
isForbiddenToRead(file, userProtectionDomain)))
{
if (0 != allowedFiles.length())
{
allowedFiles.append("\\r\\n");
}
allowedFiles.append(fileName);
}
}
return allowedFiles.toString();
}
});
} catch (PrivilegedActionException pae) {
throw new IOException(pae.getMessage(), pae);
}
return ret_val;
}
private static ProtectionDomain getUserProtectionDomain(Transferable contents) {
return contents.getClass().getProtectionDomain();
}
private boolean isForbiddenToRead (File file, ProtectionDomain protectionDomain)
{
if (null == protectionDomain) {
return false;
}
try {
FilePermission filePermission =
new FilePermission(file.getCanonicalPath(), "read, delete");
if (protectionDomain.implies(filePermission)) {
return false;
}
} catch (IOException e) {}
return true;
}
// It is important do not use user's successors
// of File class.
private File castToFile(Object fileObject) throws IOException {
String filePath = null;
if (fileObject instanceof File) {
filePath = ((File)fileObject).getCanonicalPath();
} else if (fileObject instanceof String) {
filePath = (String) fileObject;
}
return new File(filePath);
}
private final static String[] DEPLOYMENT_CACHE_PROPERTIES = {
"deployment.system.cachedir",
"deployment.user.cachedir",
"deployment.javaws.cachedir",
"deployment.javapi.cachedir"
};
private final static ArrayList <File> deploymentCacheDirectoryList =
new ArrayList<File>();
private static boolean isFileInWebstartedCache(File f) {
if (deploymentCacheDirectoryList.isEmpty()) {
for (String cacheDirectoryProperty : DEPLOYMENT_CACHE_PROPERTIES) {
String cacheDirectoryPath = System.getProperty(cacheDirectoryProperty);
if (cacheDirectoryPath != null) {
try {
File cacheDirectory = (new File(cacheDirectoryPath)).getCanonicalFile();
if (cacheDirectory != null) {
deploymentCacheDirectoryList.add(cacheDirectory);
}
} catch (IOException ioe) {}
}
}
}
for (File deploymentCacheDirectory : deploymentCacheDirectoryList) {
for (File dir = f; dir != null; dir = dir.getParentFile()) {
if (dir.equals(deploymentCacheDirectory)) {
return true;
}
}
}
return false;
}
public Object translateBytes(byte[] bytes, DataFlavor flavor,
long format, Transferable localeTransferable)
throws IOException
......
......@@ -490,8 +490,7 @@ abstract class XDecoratedPeer extends XWindowPeer {
// if the window manager or any other part of the windowing
// system sets inappropriate size for this window, we can
// do nothing but accept it.
Rectangle reqBounds = newDimensions.getBounds();
Rectangle newBounds = constrainBounds(reqBounds.x, reqBounds.y, reqBounds.width, reqBounds.height);
Rectangle newBounds = newDimensions.getBounds();
Insets insets = newDimensions.getInsets();
// Inherit isClientSizeSet from newDimensions
if (newDimensions.isClientSizeSet()) {
......@@ -619,46 +618,6 @@ abstract class XDecoratedPeer extends XWindowPeer {
// This method gets overriden in XFramePeer & XDialogPeer.
abstract boolean isTargetUndecorated();
@Override
Rectangle constrainBounds(int x, int y, int width, int height) {
// We don't restrict the setBounds() operation if the code is trusted.
if (!hasWarningWindow()) {
return new Rectangle(x, y, width, height);
}
// If it's undecorated or is not currently visible,
// apply the same constraints as for the Window.
if (!isVisible() || isTargetUndecorated()) {
return super.constrainBounds(x, y, width, height);
}
// If it's visible & decorated, constraint the size only
int newX = x;
int newY = y;
int newW = width;
int newH = height;
GraphicsConfiguration gc = ((Window)target).getGraphicsConfiguration();
Rectangle sB = gc.getBounds();
Insets sIn = ((Window)target).getToolkit().getScreenInsets(gc);
Rectangle curBounds = getBounds();
int maxW = Math.max(sB.width - sIn.left - sIn.right, curBounds.width);
int maxH = Math.max(sB.height - sIn.top - sIn.bottom, curBounds.height);
// First make sure the size is withing the visible part of the screen
if (newW > maxW) {
newW = maxW;
}
if (newH > maxH) {
newH = maxH;
}
return new Rectangle(newX, newY, newW, newH);
}
/**
* @see java.awt.peer.ComponentPeer#setBounds
*/
......
......@@ -196,12 +196,6 @@ public class XEmbeddedFramePeer extends XFramePeer {
}
}
@Override
Rectangle constrainBounds(int x, int y, int width, int height) {
// We don't constrain the bounds of the EmbeddedFrames
return new Rectangle(x, y, width, height);
}
// don't use getBounds() inherited from XDecoratedPeer
public Rectangle getBounds() {
return new Rectangle(x, y, width, height);
......
......@@ -156,11 +156,11 @@ public class XWindow extends XBaseWindow implements X11ComponentPeer {
}
XWindow(Component target, long parentWindow) {
this(target, parentWindow, target.getBounds());
this(target, parentWindow, new Rectangle(target.getBounds()));
}
XWindow(Component target) {
this(target, (target.getParent() == null) ? 0 : getParentWindowID(target), target.getBounds());
this(target, (target.getParent() == null) ? 0 : getParentWindowID(target), new Rectangle(target.getBounds()));
}
XWindow(Object target) {
......@@ -198,7 +198,7 @@ public class XWindow extends XBaseWindow implements X11ComponentPeer {
| XConstants.ButtonMotionMask | XConstants.ExposureMask | XConstants.StructureNotifyMask);
if (target != null) {
params.putIfNull(BOUNDS, target.getBounds());
params.putIfNull(BOUNDS, new Rectangle(target.getBounds()));
} else {
params.putIfNull(BOUNDS, new Rectangle(0, 0, MIN_SIZE, MIN_SIZE));
}
......
......@@ -146,6 +146,13 @@ class XWindowPeer extends XPanelPeer implements WindowPeer,
params.put(OVERRIDE_REDIRECT, Boolean.valueOf(isOverrideRedirect()));
SunToolkit.awtLock();
try {
windows.add(this);
} finally {
SunToolkit.awtUnlock();
}
cachedFocusableWindow = isFocusableWindow();
Font f = target.getFont();
......@@ -173,9 +180,6 @@ class XWindowPeer extends XPanelPeer implements WindowPeer,
GraphicsConfiguration gc = getGraphicsConfiguration();
((X11GraphicsDevice)gc.getDevice()).addDisplayChangedListener(this);
Rectangle bounds = (Rectangle)(params.get(BOUNDS));
params.put(BOUNDS, constrainBounds(bounds.x, bounds.y, bounds.width, bounds.height));
}
protected String getWMName() {
......@@ -430,56 +434,6 @@ class XWindowPeer extends XPanelPeer implements WindowPeer,
return ownerPeer;
}
// This method is overriden at the XDecoratedPeer to handle
// decorated windows a bit differently.
Rectangle constrainBounds(int x, int y, int width, int height) {
// We don't restrict the setBounds() operation if the code is trusted.
if (!hasWarningWindow()) {
return new Rectangle(x, y, width, height);
}
// The window bounds should be within the visible part of the screen
int newX = x;
int newY = y;
int newW = width;
int newH = height;
// Now check each point is within the visible part of the screen
GraphicsConfiguration gc = ((Window)target).getGraphicsConfiguration();
Rectangle sB = gc.getBounds();
Insets sIn = ((Window)target).getToolkit().getScreenInsets(gc);
int screenX = sB.x + sIn.left;
int screenY = sB.y + sIn.top;
int screenW = sB.width - sIn.left - sIn.right;
int screenH = sB.height - sIn.top - sIn.bottom;
// First make sure the size is withing the visible part of the screen
if (newW > screenW) {
newW = screenW;
}
if (newH > screenH) {
newH = screenH;
}
// Tweak the location if needed
if (newX < screenX) {
newX = screenX;
} else if (newX + newW > screenX + screenW) {
newX = screenX + screenW - newW;
}
if (newY < screenY) {
newY = screenY;
} else if (newY + newH > screenY + screenH) {
newY = screenY + screenH - newH;
}
return new Rectangle(newX, newY, newW, newH);
}
//Fix for 6318144: PIT:Setting Min Size bigger than current size enlarges
//the window but fails to revalidate, Sol-CDE
//This bug is regression for
......@@ -488,13 +442,11 @@ class XWindowPeer extends XPanelPeer implements WindowPeer,
//Note that this function is overriden in XDecoratedPeer so event
//posting is not changing for decorated peers
public void setBounds(int x, int y, int width, int height, int op) {
Rectangle newBounds = constrainBounds(x, y, width, height);
XToolkit.awtLock();
try {
Rectangle oldBounds = getBounds();
super.setBounds(newBounds.x, newBounds.y, newBounds.width, newBounds.height, op);
super.setBounds(x, y, width, height, op);
Rectangle bounds = getBounds();
......
......@@ -451,9 +451,7 @@ public class X11GraphicsConfig extends GraphicsConfiguration
}
}
/*
@Override
*/
public boolean isTranslucencyCapable() {
return isTranslucencyCapable(getAData());
}
......
......@@ -332,9 +332,7 @@ public class Win32GraphicsConfig extends GraphicsConfiguration
// the rest of the flip actions are not supported
}
/*
@Override
*/
public boolean isTranslucencyCapable() {
//XXX: worth checking if 8-bit? Anyway, it doesn't hurt.
return true;
......
......@@ -970,11 +970,12 @@ public abstract class WComponentPeer extends WObjectPeer
*
* Conditions which could prevent hw acceleration include the toplevel
* window containing this component being
* {@link com.sun.awt.AWTUtilities.Translucency#TRANSLUCENT TRANSLUCENT}.
* {@link GraphicsDevice.WindowTranslucency#PERPIXEL_TRANSLUCENT
* PERPIXEL_TRANSLUCENT}.
*
* @return {@code true} if this component is capable of being hw
* accelerated, {@code false} otherwise
* @see com.sun.awt.AWTUtilities.Translucency#TRANSLUCENT
* @see GraphicsDevice.WindowTranslucency#PERPIXEL_TRANSLUCENT
*/
public boolean isAccelCapable() {
boolean isTranslucent =
......
......@@ -114,12 +114,10 @@ class WDialogPeer extends WWindowPeer implements DialogPeer {
}
public void reshape(int x, int y, int width, int height) {
Rectangle newBounds = constrainBounds(x, y, width, height);
if (((Dialog)target).isUndecorated()) {
super.reshape(newBounds.x, newBounds.y, newBounds.width, newBounds.height);
super.reshape(x, y, width, height);
} else {
reshapeFrame(newBounds.x, newBounds.y, newBounds.width, newBounds.height);
reshapeFrame(x, y, width, height);
}
}
......
......@@ -67,12 +67,6 @@ public class WEmbeddedFramePeer extends WFramePeer {
public native void synthesizeWmActivate(boolean doActivate);
@Override
Rectangle constrainBounds(int x, int y, int width, int height) {
// We don't constrain the bounds of the EmbeddedFrames
return new Rectangle(x, y, width, height);
}
@Override
public boolean isAccelCapable() {
// REMIND: Temp workaround for issues with using HW acceleration
......
......@@ -89,12 +89,10 @@ class WFramePeer extends WWindowPeer implements FramePeer {
}
public void reshape(int x, int y, int width, int height) {
Rectangle newBounds = constrainBounds(x, y, width, height);
if (((Frame)target).isUndecorated()) {
super.reshape(newBounds.x, newBounds.y, newBounds.width, newBounds.height);
super.reshape(x, y, width, height);
} else {
reshapeFrame(newBounds.x, newBounds.y, newBounds.width, newBounds.height);
reshapeFrame(x, y, width, height);
}
}
......
......@@ -99,45 +99,4 @@ class WPanelPeer extends WCanvasPeer implements PanelPeer {
public Insets insets() {
return getInsets();
}
private native void pRestack(Object[] peers);
private void restack(Container cont, Vector peers) {
for (int i = 0; i < cont.getComponentCount(); i++) {
Component comp = cont.getComponent(i);
if (!comp.isLightweight()) {
ComponentPeer peer = comp.getPeer();
if (peer != null && (peer instanceof WComponentPeer))
{
peers.add(peer);
} else {
if (log.isLoggable(Level.FINE)) {
log.log(Level.FINE,
"peer of a {0} is null or not a WComponentPeer: {1}.",
new Object[]{comp, peer});
}
}
}
if (comp.isLightweight() && comp instanceof Container) {
restack((Container)comp, peers);
}
}
}
/**
* @see java.awt.peer.ContainerPeer#restack
*/
public void restack() {
Vector peers = new Vector();
peers.add(this);
Container cont = (Container)target;
restack(cont, peers);
pRestack(peers.toArray());
}
/**
* @see java.awt.peer.ContainerPeer#isRestackSupported
*/
public boolean isRestackSupported() {
return true;
}
}
......@@ -335,16 +335,14 @@ public class WWindowPeer extends WPanelPeer implements WindowPeer,
}
private void updateShape() {
// Shape shape = ((Window)target).getShape();
Shape shape = AWTAccessor.getWindowAccessor().getShape((Window)target);
Shape shape = ((Window)target).getShape();
if (shape != null) {
applyShape(Region.getInstance(shape, null));
}
}
private void updateOpacity() {
// float opacity = ((Window)target).getOpacity();
float opacity = AWTAccessor.getWindowAccessor().getOpacity((Window)target);
float opacity = ((Window)target).getOpacity();
if (opacity < 1.0f) {
setOpacity(opacity);
}
......@@ -546,81 +544,16 @@ public class WWindowPeer extends WPanelPeer implements WindowPeer,
private volatile int sysW = 0;
private volatile int sysH = 0;
Rectangle constrainBounds(int x, int y, int width, int height) {
GraphicsConfiguration gc = this.winGraphicsConfig;
// We don't restrict the setBounds() operation if the code is trusted.
if (!hasWarningWindow() || gc == null) {
return new Rectangle(x, y, width, height);
}
int newX = x;
int newY = y;
int newW = width;
int newH = height;
Rectangle sB = gc.getBounds();
Insets sIn = Toolkit.getDefaultToolkit().getScreenInsets(gc);
int screenW = sB.width - sIn.left - sIn.right;
int screenH = sB.height - sIn.top - sIn.bottom;
// If it's undecorated or is not currently visible
if (!AWTAccessor.getComponentAccessor().isVisible_NoClientCode(
(Component)target) || isTargetUndecorated())
{
// Now check each point is within the visible part of the screen
int screenX = sB.x + sIn.left;
int screenY = sB.y + sIn.top;
// First make sure the size is within the visible part of the screen
if (newW > screenW) {
newW = screenW;
}
if (newH > screenH) {
newH = screenH;
}
// Tweak the location if needed
if (newX < screenX) {
newX = screenX;
} else if (newX + newW > screenX + screenW) {
newX = screenX + screenW - newW;
}
if (newY < screenY) {
newY = screenY;
} else if (newY + newH > screenY + screenH) {
newY = screenY + screenH - newH;
}
} else {
int maxW = Math.max(screenW, sysW);
int maxH = Math.max(screenH, sysH);
// Make sure the size is withing the visible part of the screen
// OR less that the current size of the window.
if (newW > maxW) {
newW = maxW;
}
if (newH > maxH) {
newH = maxH;
}
}
return new Rectangle(newX, newY, newW, newH);
}
public native void repositionSecurityWarning();
@Override
public void setBounds(int x, int y, int width, int height, int op) {
Rectangle newBounds = constrainBounds(x, y, width, height);
sysX = x;
sysY = y;
sysW = width;
sysH = height;
sysX = newBounds.x;
sysY = newBounds.y;
sysW = newBounds.width;
sysH = newBounds.height;
super.setBounds(newBounds.x, newBounds.y, newBounds.width, newBounds.height, op);
super.setBounds(x, y, width, height, op);
}
@Override
......@@ -675,11 +608,13 @@ public class WWindowPeer extends WPanelPeer implements WindowPeer,
public void setOpaque(boolean isOpaque) {
Window target = (Window)getTarget();
SunToolkit sunToolkit = (SunToolkit)target.getToolkit();
if (!sunToolkit.isWindowTranslucencySupported() ||
!sunToolkit.isTranslucencyCapable(target.getGraphicsConfiguration()))
{
return;
if (!isOpaque) {
SunToolkit sunToolkit = (SunToolkit)target.getToolkit();
if (!sunToolkit.isWindowTranslucencySupported() ||
!sunToolkit.isTranslucencyCapable(target.getGraphicsConfiguration()))
{
return;
}
}
boolean opaqueChanged = this.isOpaque != isOpaque;
......@@ -713,9 +648,9 @@ public class WWindowPeer extends WPanelPeer implements WindowPeer,
// its shape only. To restore the correct visual appearance
// of the window (i.e. w/ the correct shape) we have to reset
// the shape.
Shape shape = AWTAccessor.getWindowAccessor().getShape(target);
Shape shape = ((Window)target).getShape();
if (shape != null) {
AWTAccessor.getWindowAccessor().setShape(target, shape);
((Window)target).setShape(shape);
}
}
......@@ -729,6 +664,11 @@ public class WWindowPeer extends WPanelPeer implements WindowPeer,
return;
}
Component target = (Component)this.target;
if (target.getWidth() <= 0 || target.getHeight() <= 0) {
return;
}
TranslucentWindowPainter currentPainter = painter;
if (currentPainter != null) {
currentPainter.updateWindow(backBuffer);
......
......@@ -1843,8 +1843,13 @@ LRESULT AwtComponent::WindowProc(UINT message, WPARAM wParam, LPARAM lParam)
case WM_AWT_SETALWAYSONTOP: {
AwtWindow* w = (AwtWindow*)lParam;
BOOL value = (BOOL)wParam;
UINT flags = SWP_NOMOVE | SWP_NOSIZE;
// transient windows shouldn't change the owner window's position in the z-order
if (w->IsRetainingHierarchyZOrder()) {
flags |= SWP_NOOWNERZORDER;
}
::SetWindowPos(w->GetHWnd(), (value != 0 ? HWND_TOPMOST : HWND_NOTOPMOST),
0,0,0,0, SWP_NOMOVE|SWP_NOSIZE);
0,0,0,0, flags);
break;
}
......
......@@ -165,7 +165,6 @@ jmethodID AwtWindow::calculateSecurityWarningPositionMID;
int AwtWindow::ms_instanceCounter = 0;
HHOOK AwtWindow::ms_hCBTFilter;
AwtWindow * AwtWindow::m_grabbedWindow = NULL;
HWND AwtWindow::sm_retainingHierarchyZOrderInShow = NULL;
BOOL AwtWindow::sm_resizing = FALSE;
UINT AwtWindow::untrustedWindowsCounter = 0;
......@@ -341,23 +340,6 @@ MsgRouting AwtWindow::WmNcMouseDown(WPARAM hitTest, int x, int y, int button) {
}
MsgRouting AwtWindow::WmWindowPosChanging(LPARAM windowPos) {
/*
* See 6178004.
* Some windows shouldn't trigger a change in z-order of
* any window from the hierarchy.
*/
if (IsRetainingHierarchyZOrder()) {
if (((WINDOWPOS *)windowPos)->flags & SWP_SHOWWINDOW) {
sm_retainingHierarchyZOrderInShow = GetHWnd();
}
} else if (sm_retainingHierarchyZOrderInShow != NULL) {
HWND ancestor = ::GetAncestor(sm_retainingHierarchyZOrderInShow, GA_ROOTOWNER);
HWND windowAncestor = ::GetAncestor(GetHWnd(), GA_ROOTOWNER);
if (windowAncestor == ancestor) {
((WINDOWPOS *)windowPos)->flags |= SWP_NOZORDER;
}
}
return mrDoDefault;
}
......@@ -369,19 +351,14 @@ void AwtWindow::RepositionSecurityWarning(JNIEnv *env)
::SetWindowPos(warningWindow, HWND_NOTOPMOST,
rect.left, rect.top,
rect.right - rect.left, rect.bottom - rect.top,
SWP_ASYNCWINDOWPOS | SWP_NOACTIVATE | SWP_NOZORDER
SWP_ASYNCWINDOWPOS | SWP_NOACTIVATE | SWP_NOZORDER |
SWP_NOOWNERZORDER
);
}
MsgRouting AwtWindow::WmWindowPosChanged(LPARAM windowPos) {
WINDOWPOS * wp = (WINDOWPOS *)windowPos;
if (IsRetainingHierarchyZOrder() && wp->flags & SWP_SHOWWINDOW) {
// By this time all the windows from the hierarchy are already notified about z-order change.
// Thus we may and we should reset the trigger in order not to affect other changes.
sm_retainingHierarchyZOrderInShow = NULL;
}
// Reposition the warning window
if (IsUntrusted() && warningWindow != NULL) {
if (wp->flags & SWP_HIDEWINDOW) {
......@@ -854,7 +831,7 @@ void AwtWindow::StartSecurityAnimation(AnimationKind kind)
if (securityAnimationKind == akShow) {
::SetWindowPos(warningWindow, HWND_NOTOPMOST, 0, 0, 0, 0,
SWP_NOACTIVATE | SWP_NOSIZE | SWP_NOMOVE |
SWP_SHOWWINDOW);
SWP_SHOWWINDOW | SWP_NOOWNERZORDER);
::SetLayeredWindowAttributes(warningWindow, RGB(0, 0, 0),
0xFF, LWA_ALPHA);
......@@ -880,7 +857,7 @@ void AwtWindow::StopSecurityAnimation()
case akPreHide:
::SetWindowPos(warningWindow, HWND_NOTOPMOST, 0, 0, 0, 0,
SWP_NOACTIVATE | SWP_NOSIZE | SWP_NOMOVE |
SWP_HIDEWINDOW);
SWP_HIDEWINDOW | SWP_NOOWNERZORDER);
break;
case akShow:
RepaintWarningWindow();
......@@ -1250,7 +1227,16 @@ void AwtWindow::Show()
}
}
if (!done) {
::ShowWindow(GetHWnd(), nCmdShow);
// transient windows shouldn't change the owner window's position in the z-order
if (IsRetainingHierarchyZOrder()){
UINT flags = SWP_NOSIZE | SWP_NOMOVE | SWP_SHOWWINDOW | SWP_NOOWNERZORDER;
if (nCmdShow == SW_SHOWNA) {
flags |= SWP_NOACTIVATE;
}
::SetWindowPos(GetHWnd(), HWND_TOPMOST, 0, 0, 0, 0, flags);
} else {
::ShowWindow(GetHWnd(), nCmdShow);
}
}
env->DeleteLocalRef(target);
}
......
......@@ -248,7 +248,6 @@ private:
static int ms_instanceCounter;
static HHOOK ms_hCBTFilter;
static LRESULT CALLBACK CBTFilter(int nCode, WPARAM wParam, LPARAM lParam);
static HWND sm_retainingHierarchyZOrderInShow; // a referred window in the process of show
static BOOL sm_resizing; /* in the middle of a resizing operation */
RECT m_insets; /* a cache of the insets being used */
......
/*
* Copyright 2009 Sun Microsystems, Inc. All Rights Reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
* CA 95054 USA or visit www.sun.com if you need additional information or
* have any questions.
*/
/*
@test %W% %E%
@bug 6829858
@summary Mixing should work inside heavyweight containers
@author anthony.petrov@sun.com: area=awt.mixing
@library ../regtesthelpers
@build Util
@run main MixingInHwPanel
*/
/**
* MixingInHwPanel.java
*
* summary: Mixing should work inside heavyweight containers
*/
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import test.java.awt.regtesthelpers.Util;
public class MixingInHwPanel
{
static volatile boolean failed = true;
private static void init()
{
//*** Create instructions for the user here ***
String[] instructions =
{
"This is an AUTOMATIC test, simply wait until it is done.",
"The result (passed or failed) will be shown in the",
"message window below."
};
Sysout.createDialog( );
Sysout.printInstructions( instructions );
// Create the components: frame -> hwPanel -> JDesktopPane ->
// -> JInternalFrame -> hwButton
Frame frame = new Frame("Mixing in a heavyweight Panel");
frame.setBounds(100, 100, 640, 480);
Panel hwPanel = new Panel(new BorderLayout());
frame.add(hwPanel);
JDesktopPane desktop = new JDesktopPane();
hwPanel.add(desktop);
JInternalFrame iFrame = new JInternalFrame("one",
true, true, true, true);
iFrame.setPreferredSize(new Dimension(150, 55));
iFrame.setBounds(600, 100, 150, 55);
iFrame.setVisible(true);
desktop.add(iFrame);
Button button = new Button("HW Button");
button.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
failed = false;
}
});
iFrame.add(button);
// Show the frame with the hwButton slightly hidden initially
frame.setVisible(true);
Robot robot = Util.createRobot();
robot.setAutoDelay(20);
Util.waitForIdle(robot);
// Now resize the frame so that the button is fully visible
frame.setBounds(100, 100, 800, 480);
frame.validate();
Util.waitForIdle(robot);
// And click the part of the button that has been previously hidden
Point bLoc = button.getLocationOnScreen();
robot.mouseMove(bLoc.x + button.getWidth() - 6, bLoc.y + button.getHeight() / 2);
Util.waitForIdle(robot);
robot.mousePress(InputEvent.BUTTON1_MASK);
robot.mouseRelease(InputEvent.BUTTON1_MASK);
Util.waitForIdle(robot);
// If the click happens (the shape is reapplied), the button's action
// listener will make failed == false.
if (failed) {
MixingInHwPanel.fail("The HW button did not receive the click.");
} else {
MixingInHwPanel.pass();
}
}//End init()
/*****************************************************
* Standard Test Machinery Section
* DO NOT modify anything in this section -- it's a
* standard chunk of code which has all of the
* synchronisation necessary for the test harness.
* By keeping it the same in all tests, it is easier
* to read and understand someone else's test, as
* well as insuring that all tests behave correctly
* with the test harness.
* There is a section following this for test-
* classes
******************************************************/
private static boolean theTestPassed = false;
private static boolean testGeneratedInterrupt = false;
private static String failureMessage = "";
private static Thread mainThread = null;
private static int sleepTime = 300000;
// Not sure about what happens if multiple of this test are
// instantiated in the same VM. Being static (and using
// static vars), it aint gonna work. Not worrying about
// it for now.
public static void main( String args[] ) throws InterruptedException
{
mainThread = Thread.currentThread();
try
{
init();
}
catch( TestPassedException e )
{
//The test passed, so just return from main and harness will
// interepret this return as a pass
return;
}
//At this point, neither test pass nor test fail has been
// called -- either would have thrown an exception and ended the
// test, so we know we have multiple threads.
//Test involves other threads, so sleep and wait for them to
// called pass() or fail()
try
{
Thread.sleep( sleepTime );
//Timed out, so fail the test
throw new RuntimeException( "Timed out after " + sleepTime/1000 + " seconds" );
}
catch (InterruptedException e)
{
//The test harness may have interrupted the test. If so, rethrow the exception
// so that the harness gets it and deals with it.
if( ! testGeneratedInterrupt ) throw e;
//reset flag in case hit this code more than once for some reason (just safety)
testGeneratedInterrupt = false;
if ( theTestPassed == false )
{
throw new RuntimeException( failureMessage );
}
}
}//main
public static synchronized void setTimeoutTo( int seconds )
{
sleepTime = seconds * 1000;
}
public static synchronized void pass()
{
Sysout.println( "The test passed." );
Sysout.println( "The test is over, hit Ctl-C to stop Java VM" );
//first check if this is executing in main thread
if ( mainThread == Thread.currentThread() )
{
//Still in the main thread, so set the flag just for kicks,
// and throw a test passed exception which will be caught
// and end the test.
theTestPassed = true;
throw new TestPassedException();
}
theTestPassed = true;
testGeneratedInterrupt = true;
mainThread.interrupt();
}//pass()
public static synchronized void fail()
{
//test writer didn't specify why test failed, so give generic
fail( "it just plain failed! :-)" );
}
public static synchronized void fail( String whyFailed )
{
Sysout.println( "The test failed: " + whyFailed );
Sysout.println( "The test is over, hit Ctl-C to stop Java VM" );
//check if this called from main thread
if ( mainThread == Thread.currentThread() )
{
//If main thread, fail now 'cause not sleeping
throw new RuntimeException( whyFailed );
}
theTestPassed = false;
testGeneratedInterrupt = true;
failureMessage = whyFailed;
mainThread.interrupt();
}//fail()
}// class MixingInHwPanel
//This exception is used to exit from any level of call nesting
// when it's determined that the test has passed, and immediately
// end the test.
class TestPassedException extends RuntimeException
{
}
//*********** End Standard Test Machinery Section **********
//************ Begin classes defined for the test ****************
// if want to make listeners, here is the recommended place for them, then instantiate
// them in init()
/* Example of a class which may be written as part of a test
class NewClass implements anInterface
{
static int newVar = 0;
public void eventDispatched(AWTEvent e)
{
//Counting events to see if we get enough
eventCount++;
if( eventCount == 20 )
{
//got enough events, so pass
MixingInHwPanel.pass();
}
else if( tries == 20 )
{
//tried too many times without getting enough events so fail
MixingInHwPanel.fail();
}
}// eventDispatched()
}// NewClass class
*/
//************** End classes defined for the test *******************
/****************************************************
Standard Test Machinery
DO NOT modify anything below -- it's a standard
chunk of code whose purpose is to make user
interaction uniform, and thereby make it simpler
to read and understand someone else's test.
****************************************************/
/**
This is part of the standard test machinery.
It creates a dialog (with the instructions), and is the interface
for sending text messages to the user.
To print the instructions, send an array of strings to Sysout.createDialog
WithInstructions method. Put one line of instructions per array entry.
To display a message for the tester to see, simply call Sysout.println
with the string to be displayed.
This mimics System.out.println but works within the test harness as well
as standalone.
*/
class Sysout
{
private static TestDialog dialog;
public static void createDialogWithInstructions( String[] instructions )
{
dialog = new TestDialog( new Frame(), "Instructions" );
dialog.printInstructions( instructions );
dialog.setVisible(true);
println( "Any messages for the tester will display here." );
}
public static void createDialog( )
{
dialog = new TestDialog( new Frame(), "Instructions" );
String[] defInstr = { "Instructions will appear here. ", "" } ;
dialog.printInstructions( defInstr );
dialog.setVisible(true);
println( "Any messages for the tester will display here." );
}
public static void printInstructions( String[] instructions )
{
dialog.printInstructions( instructions );
}
public static void println( String messageIn )
{
dialog.displayMessage( messageIn );
System.out.println(messageIn);
}
}// Sysout class
/**
This is part of the standard test machinery. It provides a place for the
test instructions to be displayed, and a place for interactive messages
to the user to be displayed.
To have the test instructions displayed, see Sysout.
To have a message to the user be displayed, see Sysout.
Do not call anything in this dialog directly.
*/
class TestDialog extends Dialog
{
TextArea instructionsText;
TextArea messageText;
int maxStringLength = 80;
//DO NOT call this directly, go through Sysout
public TestDialog( Frame frame, String name )
{
super( frame, name );
int scrollBoth = TextArea.SCROLLBARS_BOTH;
instructionsText = new TextArea( "", 15, maxStringLength, scrollBoth );
add( "North", instructionsText );
messageText = new TextArea( "", 5, maxStringLength, scrollBoth );
add("Center", messageText);
pack();
setVisible(true);
}// TestDialog()
//DO NOT call this directly, go through Sysout
public void printInstructions( String[] instructions )
{
//Clear out any current instructions
instructionsText.setText( "" );
//Go down array of instruction strings
String printStr, remainingStr;
for( int i=0; i < instructions.length; i++ )
{
//chop up each into pieces maxSringLength long
remainingStr = instructions[ i ];
while( remainingStr.length() > 0 )
{
//if longer than max then chop off first max chars to print
if( remainingStr.length() >= maxStringLength )
{
//Try to chop on a word boundary
int posOfSpace = remainingStr.
lastIndexOf( ' ', maxStringLength - 1 );
if( posOfSpace <= 0 ) posOfSpace = maxStringLength - 1;
printStr = remainingStr.substring( 0, posOfSpace + 1 );
remainingStr = remainingStr.substring( posOfSpace + 1 );
}
//else just print
else
{
printStr = remainingStr;
remainingStr = "";
}
instructionsText.append( printStr + "\n" );
}// while
}// for
}//printInstructions()
//DO NOT call this directly, go through Sysout
public void displayMessage( String messageIn )
{
messageText.append( messageIn + "\n" );
System.out.println(messageIn);
}
}// TestDialog class
......@@ -56,7 +56,7 @@ public class TranslucentJAppletTest {
frame.add(applet);
frame.setBounds(100, 100, 200, 200);
frame.setUndecorated(true);
com.sun.awt.AWTUtilities.setWindowOpaque(frame, false);
frame.setBackground(new Color(0, 0, 0, 0));
frame.setVisible(true);
}
......
......@@ -23,14 +23,14 @@
* have any questions.
*/
import com.sun.awt.AWTUtilities;
import static com.sun.awt.AWTUtilities.Translucency.*;
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Frame;
import java.awt.Graphics;
import java.awt.GraphicsConfiguration;
import java.awt.GraphicsDevice;
import java.awt.GraphicsDevice.WindowTranslucency;
import java.awt.GraphicsEnvironment;
import java.awt.RenderingHints;
import java.awt.event.MouseAdapter;
......@@ -93,8 +93,8 @@ public class TSFrame {
}
}
private static class NonOpaqueJFrame extends JFrame {
NonOpaqueJFrame(GraphicsConfiguration gc) {
super("NonOpaque Swing JFrame", gc);
NonOpaqueJFrame() {
super("NonOpaque Swing JFrame");
JPanel p = new JPanel() {
public void paintComponent(Graphics g) {
super.paintComponent(g);
......@@ -111,8 +111,8 @@ public class TSFrame {
}
private static class NonOpaqueJAppletFrame extends JFrame {
JPanel p;
NonOpaqueJAppletFrame(GraphicsConfiguration gc) {
super("NonOpaque Swing JAppletFrame", gc);
NonOpaqueJAppletFrame() {
super("NonOpaque Swing JAppletFrame");
JApplet ja = new JApplet() {
public void paint(Graphics g) {
super.paint(g);
......@@ -135,8 +135,8 @@ public class TSFrame {
}
}
private static class NonOpaqueFrame extends Frame {
NonOpaqueFrame(GraphicsConfiguration gc) {
super("NonOpaque AWT Frame", gc);
NonOpaqueFrame() {
super("NonOpaque AWT Frame");
// uncomment to test with hw child
// setLayout(null);
// Component c = new Panel() {
......@@ -166,7 +166,7 @@ public class TSFrame {
}
}
public static Frame createGui(GraphicsConfiguration gc,
public static Frame createGui(
final boolean useSwing,
final boolean useShape,
final boolean useTransl,
......@@ -176,21 +176,16 @@ public class TSFrame {
Frame frame;
done = false;
if (gc == null) {
gc = GraphicsEnvironment.getLocalGraphicsEnvironment().
getDefaultScreenDevice().getDefaultConfiguration();
}
if (useNonOpaque) {
if (useSwing) {
frame = new NonOpaqueJFrame(gc);
frame = new NonOpaqueJFrame();
// frame = new NonOpaqueJAppletFrame(gc);
} else {
frame = new NonOpaqueFrame(gc);
frame = new NonOpaqueFrame();
}
animateComponent(frame);
} else if (useSwing) {
frame = new JFrame("Swing Frame", gc);
frame = new JFrame("Swing Frame");
JComponent p = new JButton("Swing!");
p.setPreferredSize(new Dimension(200, 100));
frame.add("North", p);
......@@ -198,7 +193,7 @@ public class TSFrame {
animateComponent(p);
frame.add("Center", p);
} else {
frame = new Frame("AWT Frame", gc) {
frame = new Frame("AWT Frame") {
public void paint(Graphics g) {
g.setColor(Color.red);
g.fillRect(0, 0, 100, 100);
......@@ -239,32 +234,30 @@ public class TSFrame {
frame.setLocation(450, 10);
frame.pack();
GraphicsDevice gd = frame.getGraphicsConfiguration().getDevice();
if (useShape) {
if (AWTUtilities.isTranslucencySupported(PERPIXEL_TRANSPARENT)) {
if (gd.isWindowTranslucencySupported(WindowTranslucency.PERPIXEL_TRANSPARENT)) {
System.out.println("applying PERPIXEL_TRANSPARENT");
AWTUtilities.setWindowShape(frame,
new Ellipse2D.Double(0, 0, frame.getWidth(),
frame.getHeight()/3));
frame.setShape(new Ellipse2D.Double(0, 0, frame.getWidth(),
frame.getHeight()/3));
frame.setTitle("PERPIXEL_TRANSPARENT");
} else {
System.out.println("Passed: PERPIXEL_TRANSPARENT unsupported");
}
}
if (useTransl) {
if (AWTUtilities.isTranslucencySupported(TRANSLUCENT)) {
if (gd.isWindowTranslucencySupported(WindowTranslucency.TRANSLUCENT)) {
System.out.println("applying TRANSLUCENT");
AWTUtilities.setWindowOpacity(frame, factor);
frame.setOpacity(factor);
frame.setTitle("TRANSLUCENT");
} else {
System.out.println("Passed: TRANSLUCENT unsupported");
}
}
if (useNonOpaque) {
if (AWTUtilities.isTranslucencySupported(PERPIXEL_TRANSLUCENT) &&
AWTUtilities.isTranslucencyCapable(gc))
{
if (gd.isWindowTranslucencySupported(WindowTranslucency.PERPIXEL_TRANSLUCENT)) {
System.out.println("applying PERPIXEL_TRANSLUCENT");
AWTUtilities.setWindowOpaque(frame, false);
frame.setBackground(new Color(0, 0, 0, 0));
frame.setTitle("PERPIXEL_TRANSLUCENT");
} else {
System.out.println("Passed: PERPIXEL_TRANSLUCENT unsupported");
......@@ -295,7 +288,7 @@ public class TSFrame {
public static void main(String[] args) throws Exception {
SwingUtilities.invokeLater(new Runnable() {
public void run() {
TSFrame.createGui(null, useSwing,
TSFrame.createGui(useSwing,
useShape,
useTransl,
useNonOpaque,
......
......@@ -34,11 +34,11 @@
* @run main/manual/othervm -Dsun.java2d.noddraw=true TranslucentShapedFrameTest
* @run main/manual/othervm -Dsun.java2d.opengl=True TranslucentShapedFrameTest
*/
import com.sun.awt.AWTUtilities;
import static com.sun.awt.AWTUtilities.Translucency.*;
import java.awt.Color;
import java.awt.Frame;
import java.awt.GraphicsConfiguration;
import java.awt.GraphicsDevice;
import java.awt.GraphicsDevice.WindowTranslucency;
import java.awt.GraphicsEnvironment;
import java.awt.Shape;
import java.awt.geom.Ellipse2D;
......@@ -130,7 +130,7 @@ public class TranslucentShapedFrameTest extends javax.swing.JFrame {
jLabel2.setText("Instructions:");
passedBtn.setBackground(new java.awt.Color(129, 255, 100));
passedBtn.setBackground(new Color(129, 255, 100));
passedBtn.setText("Passed");
passedBtn.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
......@@ -138,7 +138,7 @@ public class TranslucentShapedFrameTest extends javax.swing.JFrame {
}
});
failedBtn.setBackground(java.awt.Color.red);
failedBtn.setBackground(Color.red);
failedBtn.setText("Failed");
failedBtn.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
......@@ -234,7 +234,7 @@ public class TranslucentShapedFrameTest extends javax.swing.JFrame {
private void nonOpaqueChbActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_nonOpaqueChbActionPerformed
if (testFrame != null) {
// REMIND: this path in the test doesn't work well (test bug)
// AWTUtilities.setWindowOpaque(testFrame, !nonOpaqueChb.isSelected());
testFrame.setBackground(new Color(0, 0, 0, nonOpaqueChb.isSelected() ? 0 : 255));
}
}//GEN-LAST:event_nonOpaqueChbActionPerformed
......@@ -246,7 +246,7 @@ public class TranslucentShapedFrameTest extends javax.swing.JFrame {
testFrame.getWidth(),
testFrame.getHeight());
}
AWTUtilities.setWindowShape(testFrame, s);
testFrame.setShape(s);
}
}//GEN-LAST:event_shapedCbActionPerformed
......@@ -254,7 +254,7 @@ public class TranslucentShapedFrameTest extends javax.swing.JFrame {
JSlider source = (JSlider)evt.getSource();
int transl = transparencySld.getValue();
if (testFrame != null) {
AWTUtilities.setWindowOpacity(testFrame, (float)transl/100f);
testFrame.setOpacity((float)transl/100f);
}
}//GEN-LAST:event_transparencySldStateChanged
......@@ -276,7 +276,7 @@ public class TranslucentShapedFrameTest extends javax.swing.JFrame {
private void createFrameBtnActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_createFrameBtnActionPerformed
disposeFrameBtnActionPerformed(evt);
int transl = transparencySld.getValue();
testFrame = TSFrame.createGui(gcToUse,
testFrame = TSFrame.createGui(
useSwingCb.isSelected(), shapedCb.isSelected(),
(transl < 100), nonOpaqueChb.isSelected(),
(float)transl/100f);
......@@ -308,36 +308,16 @@ public class TranslucentShapedFrameTest extends javax.swing.JFrame {
}
private void checkEffects() {
if (!AWTUtilities.isTranslucencySupported(PERPIXEL_TRANSPARENT)) {
GraphicsDevice gd = getGraphicsConfiguration().getDevice();
if (!gd.isWindowTranslucencySupported(WindowTranslucency.PERPIXEL_TRANSPARENT)) {
shapedCb.setEnabled(false);
}
if (!AWTUtilities.isTranslucencySupported(TRANSLUCENT)) {
if (!gd.isWindowTranslucencySupported(WindowTranslucency.TRANSLUCENT)) {
transparencySld.setEnabled(false);
}
GraphicsConfiguration gc = null;
if (AWTUtilities.isTranslucencySupported(PERPIXEL_TRANSLUCENT)) {
gc = findGraphicsConfig();
if (gc == null) {
nonOpaqueChb.setEnabled(false);
}
}
gcToUse = gc;
}
private GraphicsConfiguration findGraphicsConfig() {
GraphicsDevice gd =
GraphicsEnvironment.getLocalGraphicsEnvironment().
getDefaultScreenDevice();
GraphicsConfiguration gcs[] = gd.getConfigurations();
for (GraphicsConfiguration gc : gcs) {
if (AWTUtilities.isTranslucencyCapable(gc)) {
return gc;
}
if (!gd.isWindowTranslucencySupported(WindowTranslucency.PERPIXEL_TRANSLUCENT)) {
nonOpaqueChb.setEnabled(false);
}
return null;
}
// Variables declaration - do not modify//GEN-BEGIN:variables
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册