Merge
authorpsadhukhan
Wed, 27 Feb 2019 14:45:17 +0530
changeset 53940 f8b2179a55d0
parent 53939 7f715085caac (diff)
parent 53932 33839b74e47c (current diff)
child 53941 f9302cf718c9
child 54229 6673d2b7e084
Merge
--- a/src/java.desktop/macosx/native/libawt_lwawt/awt/AWTWindow.h	Wed Feb 27 10:03:22 2019 +0100
+++ b/src/java.desktop/macosx/native/libawt_lwawt/awt/AWTWindow.h	Wed Feb 27 14:45:17 2019 +0530
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2011, 2015, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2011, 2018, Oracle and/or its affiliates. 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
@@ -47,6 +47,7 @@
     jint preFullScreenLevel;
     NSRect standardFrame;
     BOOL isMinimizing;
+    BOOL keyNotificationRecd;
 }
 
 // An instance of either AWTWindow_Normal or AWTWindow_Panel
@@ -62,6 +63,7 @@
 @property (nonatomic) jint preFullScreenLevel;
 @property (nonatomic) NSRect standardFrame;
 @property (nonatomic) BOOL isMinimizing;
+@property (nonatomic) BOOL keyNotificationRecd;
 
 - (id) initWithPlatformWindow:(JNFWeakJObjectWrapper *)javaPlatformWindow
                   ownerWindow:owner
--- a/src/java.desktop/macosx/native/libawt_lwawt/awt/AWTWindow.m	Wed Feb 27 10:03:22 2019 +0100
+++ b/src/java.desktop/macosx/native/libawt_lwawt/awt/AWTWindow.m	Wed Feb 27 14:45:17 2019 +0530
@@ -186,6 +186,7 @@
 @synthesize preFullScreenLevel;
 @synthesize standardFrame;
 @synthesize isMinimizing;
+@synthesize keyNotificationRecd;
 
 - (void) updateMinMaxSize:(BOOL)resizable {
     if (resizable) {
@@ -319,6 +320,7 @@
     if (self.nsWindow == nil) return nil; // no hope either
     [self.nsWindow release]; // the property retains the object already
 
+    self.keyNotificationRecd = NO;
     self.isEnabled = YES;
     self.isMinimizing = NO;
     self.javaPlatformWindow = platformWindow;
@@ -747,9 +749,16 @@
 AWT_ASSERT_APPKIT_THREAD;
     [AWTToolkit eventCountPlusPlus];
 #ifdef DEBUG
-    NSLog(@"became main: %d %@ %@", [self.nsWindow isKeyWindow], [self.nsWindow title], [self menuBarForWindow]);
+    NSLog(@"became main: %d %@ %@ %d", [self.nsWindow isKeyWindow], [self.nsWindow title], [self menuBarForWindow], self.keyNotificationRecd);
 #endif
 
+    // if for some reason, no KEY notification is received but this main window is also a key window
+    // then we need to execute the KEY notification functionality.
+    if(self.keyNotificationRecd != YES && [self.nsWindow isKeyWindow]) {
+        [self doWindowDidBecomeKey];
+    }
+    self.keyNotificationRecd = NO;
+
     if (![self.nsWindow isKeyWindow]) {
         [self activateWindowMenuBar];
     }
@@ -769,6 +778,12 @@
 #ifdef DEBUG
     NSLog(@"became key: %d %@ %@", [self.nsWindow isMainWindow], [self.nsWindow title], [self menuBarForWindow]);
 #endif
+    [self doWindowDidBecomeKey];
+    self.keyNotificationRecd = YES;
+}
+
+- (void) doWindowDidBecomeKey {
+AWT_ASSERT_APPKIT_THREAD;
     AWTWindow *opposite = [AWTWindow lastKeyWindow];
 
     if (![self.nsWindow isMainWindow]) {
--- a/src/java.desktop/share/classes/javax/swing/text/html/CSS.java	Wed Feb 27 10:03:22 2019 +0100
+++ b/src/java.desktop/share/classes/javax/swing/text/html/CSS.java	Wed Feb 27 14:45:17 2019 +0530
@@ -1362,6 +1362,19 @@
         } else {
             digits = value;
         }
+        // Some webpage passes 3 digit color code as in #fff which is
+        // decoded as #000FFF resulting in blue background.
+        // As per https://www.w3.org/TR/CSS1/#color-units,
+        // The three-digit RGB notation (#rgb) is converted into six-digit form
+        // (#rrggbb) by replicating digits, not by adding zeros.
+        // This makes sure that white (#ffffff) can be specified with the short notation
+        // (#fff) and removes any dependencies on the color depth of the display.
+        if (digits.length() == 3) {
+            final String r = digits.substring(0, 1);
+            final String g = digits.substring(1, 2);
+            final String b = digits.substring(2, 3);
+            digits = String.format("%s%s%s%s%s%s", r, r, g, g, b, b);
+        }
         String hstr = "0x" + digits;
         Color c;
         try {
--- a/src/java.desktop/share/classes/javax/swing/text/rtf/RTFReader.java	Wed Feb 27 10:03:22 2019 +0100
+++ b/src/java.desktop/share/classes/javax/swing/text/rtf/RTFReader.java	Wed Feb 27 14:45:17 2019 +0530
@@ -1185,6 +1185,10 @@
             parserState.put(keyword, Integer.valueOf(parameter));
             return true;
         }
+        if (keyword.equals("cb")) {
+            parserState.put(keyword, Integer.valueOf(parameter));
+            return true;
+        }
 
         {
             RTFAttribute attr = straightforwardAttributes.get(keyword);
--- a/src/java.desktop/windows/classes/sun/print/PrintServiceLookupProvider.java	Wed Feb 27 10:03:22 2019 +0100
+++ b/src/java.desktop/windows/classes/sun/print/PrintServiceLookupProvider.java	Wed Feb 27 14:45:17 2019 +0530
@@ -403,18 +403,36 @@
        list.
     */
     class RemotePrinterChangeListener implements Runnable {
-        private String[] prevRemotePrinters;
+        private String[] prevRemotePrinters = null;
 
         RemotePrinterChangeListener() {
             prevRemotePrinters = getRemotePrintersNames();
         }
 
         boolean doCompare(String[] str1, String[] str2) {
+            if (str1 == null && str2 == null) {
+                return false;
+            } else if (str1 == null || str2 == null) {
+                return true;
+            }
+
             if (str1.length != str2.length) {
                 return true;
             } else {
                 for (int i = 0;i < str1.length;i++) {
                     for (int j = 0;j < str2.length;j++) {
+                        // skip if both are nulls
+                        if (str1[i] == null && str2[j] == null) {
+                            continue;
+                        }
+
+                        // return true if there is a 'difference' but
+                        // no need to access the individual string
+                        if (str1[i] == null || str2[j] == null) {
+                            return true;
+                        }
+
+                        // do comparison only if they are non-nulls
                         if (!str1[i].equals(str2[j])) {
                             return true;
                         }
@@ -428,15 +446,19 @@
         @Override
         public void run() {
             while (true) {
-                String[] currentRemotePrinters = getRemotePrintersNames();
-                if (doCompare(prevRemotePrinters, currentRemotePrinters)) {
+                if (prevRemotePrinters != null && prevRemotePrinters.length > 0) {
+                    String[] currentRemotePrinters = getRemotePrintersNames();
+                    if (doCompare(prevRemotePrinters, currentRemotePrinters)) {
 
-                    // updated the printers data
-                    // printers list now contains both local and network printer data
-                    refreshServices();
+                        // updated the printers data
+                        // printers list now contains both local and network printer data
+                        refreshServices();
 
-                    // store the current data for next comparison
-                    prevRemotePrinters = currentRemotePrinters;
+                        // store the current data for next comparison
+                        prevRemotePrinters = currentRemotePrinters;
+                    }
+                } else {
+                    prevRemotePrinters = getRemotePrintersNames();
                 }
 
                 try {
--- a/src/java.desktop/windows/native/libawt/windows/WPrinterJob.cpp	Wed Feb 27 10:03:22 2019 +0100
+++ b/src/java.desktop/windows/native/libawt/windows/WPrinterJob.cpp	Wed Feb 27 14:45:17 2019 +0530
@@ -249,7 +249,7 @@
     if (clazz == NULL) {
         return NULL;
     }
-    jobjectArray nameArray;
+    jobjectArray nameArray = NULL;
 
     try {
         ::EnumPrinters(PRINTER_ENUM_LOCAL | PRINTER_ENUM_CONNECTIONS,
@@ -270,13 +270,14 @@
                 }
             }
 
-            // Allocate space only for the network type printers
-            nameArray = env->NewObjectArray(remotePrintersCount, clazz, NULL);
-            if (nameArray == NULL) {
-                throw std::bad_alloc();
+            // return remote printers only if the list contains it.
+            if (remotePrintersCount > 0) {
+                // Allocate space only for the network type printers
+                nameArray = env->NewObjectArray(remotePrintersCount, clazz, NULL);
+                if (nameArray == NULL) {
+                    throw std::bad_alloc();
+                }
             }
-        } else {
-            nameArray = NULL;
         }
 
         // Loop thro' network printers list only
@@ -298,7 +299,12 @@
 
     delete [] pPrinterEnum;
     delete [] pNetworkPrinterLoc;
-    return nameArray;
+
+    if (nameArray != NULL) {
+      return nameArray;
+    } else {
+      return env->NewObjectArray(0, clazz, NULL);
+    }
 
     CATCH_BAD_ALLOC_RET(NULL);
 }
--- a/src/jdk.accessibility/windows/native/jaccessinspector/jaccessinspectorWindow.rc	Wed Feb 27 10:03:22 2019 +0100
+++ b/src/jdk.accessibility/windows/native/jaccessinspector/jaccessinspectorWindow.rc	Wed Feb 27 14:45:17 2019 +0530
@@ -202,7 +202,7 @@
             VALUE "CompanyName",      XSTR(JDK_COMPANY)       "\0"
             VALUE "FileDescription",  XSTR(JDK_COMPONENT)     "\0"
             VALUE "FileVersion",      XSTR(JDK_VER)           "\0"
-            VALUE "Full Version",     XSTR(JDK_BUILD_ID)      "\0"
+            VALUE "Full Version",     XSTR(JDK_VERSION_STRING) "\0"
             VALUE "InternalName",     XSTR(JDK_INTERNAL_NAME) "\0"
             VALUE "LegalCopyright",   XSTR(JDK_COPYRIGHT)     "\0"
             VALUE "OriginalFilename", XSTR(JDK_FNAME)         "\0"
--- a/src/jdk.accessibility/windows/native/jaccesswalker/jaccesswalkerWindow.rc	Wed Feb 27 10:03:22 2019 +0100
+++ b/src/jdk.accessibility/windows/native/jaccesswalker/jaccesswalkerWindow.rc	Wed Feb 27 14:45:17 2019 +0530
@@ -167,7 +167,7 @@
             VALUE "CompanyName",      XSTR(JDK_COMPANY)       "\0"
             VALUE "FileDescription",  XSTR(JDK_COMPONENT)     "\0"
             VALUE "FileVersion",      XSTR(JDK_VER)           "\0"
-            VALUE "Full Version",     XSTR(JDK_BUILD_ID)      "\0"
+            VALUE "Full Version",     XSTR(JDK_VERSION_STRING) "\0"
             VALUE "InternalName",     XSTR(JDK_INTERNAL_NAME) "\0"
             VALUE "LegalCopyright",   XSTR(JDK_COPYRIGHT)     "\0"
             VALUE "OriginalFilename", XSTR(JDK_FNAME)         "\0"
--- a/test/jdk/java/awt/print/RemotePrinterStatusRefresh/RemotePrinterStatusRefresh.java	Wed Feb 27 10:03:22 2019 +0100
+++ b/test/jdk/java/awt/print/RemotePrinterStatusRefresh/RemotePrinterStatusRefresh.java	Wed Feb 27 14:45:17 2019 +0530
@@ -23,7 +23,7 @@
 
 /**
  * @test
- * @bug 8153732
+ * @bug 8153732 8212202
  * @requires (os.family == "Windows")
  * @summary Windows remote printer changes do not reflect in lookupPrintServices()
  * @ignore Requires a new network printer installation\removal
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/jdk/javax/swing/JEditorPane/TestBrowserBGColor.java	Wed Feb 27 14:45:17 2019 +0530
@@ -0,0 +1,116 @@
+/*
+ * Copyright (c) 2019, Oracle and/or its affiliates. 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 Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+/*
+ * @test
+ * @key headful
+ * @bug 8213781
+ * @summary Verify webpage background color renders correctly in JEditorPane
+ */
+
+import java.awt.Toolkit;
+import java.awt.event.WindowAdapter;
+import java.awt.event.WindowEvent;
+import java.io.IOException;
+import java.net.MalformedURLException;
+import javax.swing.JDialog;
+import javax.swing.JEditorPane;
+import javax.swing.JFrame;
+import javax.swing.JScrollPane;
+import javax.swing.SwingUtilities;
+import javax.swing.event.HyperlinkEvent;
+import javax.swing.event.HyperlinkListener;
+import javax.swing.text.html.HTMLFrameHyperlinkEvent;
+import javax.swing.text.html.HTMLDocument;
+import java.awt.Color;
+import java.awt.Insets;
+import java.awt.Point;
+import java.awt.Robot;
+
+public class TestBrowserBGColor extends JFrame implements HyperlinkListener {
+
+    private static TestBrowserBGColor b;
+    private static JEditorPane browser;
+
+    public static void main(final String[] args) throws Exception {
+        Robot r = new Robot();
+        SwingUtilities.invokeAndWait(() -> {
+            try {
+                b = new TestBrowserBGColor();
+            } catch (Exception e) {
+                throw new RuntimeException(e);
+            }
+            b.setSize(Toolkit.getDefaultToolkit().getScreenSize());
+            b.setVisible(true);
+            b.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
+            b.addWindowListener(new WindowAdapter() {
+                public void windowClosing(WindowEvent e) {
+                    b.dispose();
+                    b = null;
+                }
+            });
+        });
+
+        r.waitForIdle();
+        r.delay(500);
+
+        SwingUtilities.invokeAndWait(() -> {
+            Insets insets = browser.getInsets();
+            Point loc = browser.getLocationOnScreen();
+            Color c = r.getPixelColor( loc.x + insets.left+100,
+                                  loc.y + insets.top + 100);
+            b.dispose();
+            if (!c.equals(Color.WHITE)) {
+                throw new RuntimeException("webpage background color wrong");
+            }
+        });
+    }
+
+
+    String htmlDoc = " <!DOCTYPE html> <html><style> body { background: #FFF; } </style> <head> <title>Title</title> </head> <body> </body> </html>";
+
+    public TestBrowserBGColor() throws IOException, MalformedURLException {
+        browser = new JEditorPane("text/html", htmlDoc);
+        browser.setEditable(false);
+        browser.addHyperlinkListener(this);
+        JScrollPane scroll = new JScrollPane(browser);
+        getContentPane().add(scroll);
+    }
+
+    public void hyperlinkUpdate(final HyperlinkEvent e) {
+        if (e.getEventType() == HyperlinkEvent.EventType.ACTIVATED) {
+            JEditorPane pane = (JEditorPane) e.getSource();
+            if (e instanceof HTMLFrameHyperlinkEvent) {
+                HTMLFrameHyperlinkEvent evt = (HTMLFrameHyperlinkEvent) e;
+                HTMLDocument doc = (HTMLDocument) pane.getDocument();
+                doc.processHTMLFrameHyperlinkEvent(evt);
+            } else {
+                try {
+                    pane.setPage(e.getURL());
+                } catch (Throwable t) {
+                    t.printStackTrace();
+                }
+            }
+        }
+    }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/jdk/javax/swing/text/rtf/RTFReadBGColorTest.java	Wed Feb 27 14:45:17 2019 +0530
@@ -0,0 +1,100 @@
+/*
+ * Copyright (c) 2019, Oracle and/or its affiliates. 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 Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+/*
+ * @test
+ * @key headful
+ * @bug 8219156
+ * @summary Verify RTFEditorKit does not read background color
+ */
+
+import java.awt.Color;
+import java.awt.image.BufferedImage;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.nio.file.Files;
+import java.nio.file.Paths;
+import java.util.Enumeration;
+
+import javax.swing.JTextPane;
+import javax.swing.SwingUtilities;
+import javax.swing.JFrame;
+import javax.swing.text.MutableAttributeSet;
+import javax.swing.text.StyleConstants;
+import javax.swing.text.SimpleAttributeSet;
+import javax.swing.text.StyledDocument;
+import javax.swing.text.AttributeSet;
+import javax.swing.text.rtf.RTFEditorKit;
+
+public class RTFReadBGColorTest {
+    static JTextPane text;
+    static String BGTEXT = "yellow_background\n";
+
+    public static void main(String[] a) throws Exception {
+        SwingUtilities.invokeAndWait(() -> {
+            JFrame f = new JFrame();
+            f.setBounds(200, 600, 400, 300);
+            f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
+            text = new JTextPane();
+            text.setEditorKit(new RTFEditorKit());
+
+            MutableAttributeSet attrBackground = new SimpleAttributeSet();
+            StyleConstants.setBackground(attrBackground, Color.YELLOW);
+
+            try {
+                text.getDocument().insertString(0, BGTEXT, attrBackground);
+            } catch (Exception e) {
+                throw new RuntimeException(e);
+            }
+            write();
+            read();
+
+            f.getContentPane().add(text);
+            f.setVisible(true);
+            text.setCaretPosition(BGTEXT.length()+6);
+            StyledDocument style = text.getStyledDocument();
+            AttributeSet oldSet = style.getCharacterElement(BGTEXT.length()+6).getAttributes();
+            f.dispose();
+            if (!style.getBackground(oldSet).equals(Color.YELLOW)) {
+                throw new RuntimeException("RTFEditorKit does not read background color");
+            }
+        });
+    }
+
+    static void write() {
+        try (OutputStream o = Files.newOutputStream(Paths.get("test.rtf"))) {
+            text.getEditorKit().write(o, text.getDocument(), 0, 0);
+        } catch (Exception e2) {
+            throw new RuntimeException(e2);
+        }
+    }
+
+    static void read() {
+        try (InputStream in = Files.newInputStream(Paths.get("test.rtf"))) {
+            text.getEditorKit().read(in, text.getDocument(), 0);
+        } catch (Exception e2) {
+            throw new RuntimeException(e2);
+        }
+    }
+}
+