changeset 43578:640eb9781ce5

8173707: Javadoc generated pages should default to no-frames view Reviewed-by: jjg, ksrini
author bpatel
date Thu, 02 Feb 2017 14:55:23 -0800
parents 1a1b1242f7aa
children 0d00f3ea77bc
files langtools/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/FrameOutputWriter.java langtools/test/jdk/javadoc/doclet/testFramesNoFrames/TestFramesNoFrames.java langtools/test/jdk/javadoc/doclet/testHtmlVersion/TestHtmlVersion.java
diffstat 3 files changed, 42 insertions(+), 7 deletions(-) [+]
line wrap: on
line diff
--- a/langtools/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/FrameOutputWriter.java	Thu Feb 02 14:34:21 2017 -0800
+++ b/langtools/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/FrameOutputWriter.java	Thu Feb 02 14:55:23 2017 -0800
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 1997, 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1997, 2017, 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
@@ -29,10 +29,12 @@
 import jdk.javadoc.internal.doclets.formats.html.markup.HtmlStyle;
 import jdk.javadoc.internal.doclets.formats.html.markup.HtmlTag;
 import jdk.javadoc.internal.doclets.formats.html.markup.HtmlTree;
+import jdk.javadoc.internal.doclets.formats.html.markup.RawHtml;
 import jdk.javadoc.internal.doclets.toolkit.Content;
 import jdk.javadoc.internal.doclets.toolkit.util.DocFileIOException;
 import jdk.javadoc.internal.doclets.toolkit.util.DocPath;
 import jdk.javadoc.internal.doclets.toolkit.util.DocPaths;
+import jdk.javadoc.internal.doclets.toolkit.util.DocletConstants;
 
 
 /**
@@ -92,6 +94,15 @@
         Content frame = getFrameDetails();
         HtmlTree body = new HtmlTree(HtmlTag.BODY);
         body.addAttr(HtmlAttr.ONLOAD, "loadFrames()");
+        String topFilePath = configuration.topFile.getPath();
+        String javaScriptRefresh = "\nif (targetPage == \"\" || targetPage == \"undefined\")\n" +
+                "     window.location.replace('" + topFilePath + "');\n";
+        RawHtml scriptContent = new RawHtml(javaScriptRefresh.replace("\n", DocletConstants.NL));
+        HtmlTree scriptTree = HtmlTree.SCRIPT();
+        scriptTree.addContent(scriptContent);
+        body.addContent(scriptTree);
+        Content noScript = HtmlTree.NOSCRIPT(contents.noScriptMessage);
+        body.addContent(noScript);
         if (configuration.allowTag(HtmlTag.MAIN)) {
             HtmlTree main = HtmlTree.MAIN(frame);
             body.addContent(main);
--- a/langtools/test/jdk/javadoc/doclet/testFramesNoFrames/TestFramesNoFrames.java	Thu Feb 02 14:34:21 2017 -0800
+++ b/langtools/test/jdk/javadoc/doclet/testFramesNoFrames/TestFramesNoFrames.java	Thu Feb 02 14:55:23 2017 -0800
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2016, 2017, 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
@@ -23,7 +23,7 @@
 
 /*
  * @test
- * @bug 8162353 8164747
+ * @bug 8162353 8164747 8173707
  * @summary javadoc should provide a way to disable use of frames
  * @library /tools/lib ../lib
  * @modules
@@ -323,10 +323,14 @@
         }
 
         private void checkIndex() {
-            // the index.html page only contains frames in frames mode
+            // the index.html page only contains frames and Javascript to default to no-frames view,
+            // in frames mode
             checkOutput("index.html", frames,
                     "<iframe ",
-                    "</iframe>");
+                    "</iframe>",
+                    "<body onload=\"loadFrames()\">\n"
+                    + "<script type=\"text/javascript\">\n"
+                    + "if (targetPage == \"\" || targetPage == \"undefined\")");
 
             // the index.html contains the overview if one
             // has been given, and not in frames mode
--- a/langtools/test/jdk/javadoc/doclet/testHtmlVersion/TestHtmlVersion.java	Thu Feb 02 14:34:21 2017 -0800
+++ b/langtools/test/jdk/javadoc/doclet/testHtmlVersion/TestHtmlVersion.java	Thu Feb 02 14:55:23 2017 -0800
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2015, 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2015, 2017, 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
@@ -23,7 +23,7 @@
 
 /*
  * @test
- * @bug 8072945 8081854 8141492 8148985 8150188 4649116
+ * @bug 8072945 8081854 8141492 8148985 8150188 4649116 8173707
  * @summary Test the version of HTML generated by the javadoc tool.
  * @author bpatel
  * @library ../lib
@@ -607,6 +607,11 @@
                 "<!DOCTYPE HTML>",
                 "<link rel=\"stylesheet\" type=\"text/css\" href=\"stylesheet.css\" title=\"Style\">",
                 "<body onload=\"loadFrames()\">\n"
+                + "<script type=\"text/javascript\">\n"
+                + "if (targetPage == \"\" || targetPage == \"undefined\")\n"
+                + "     window.location.replace('overview-summary.html');\n"
+                + "</script>\n"
+                + "<noscript>JavaScript is disabled on your browser.</noscript>\n"
                 + "<main role=\"main\">\n"
                 + "<div class=\"mainContainer\">\n"
                 + "<div class=\"leftContainer\">\n"
@@ -1012,6 +1017,11 @@
         checkOutput("index.html", false,
                 "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\" \"http://www.w3.org/TR/html4/loose.dtd\">",
                 "<body>\n"
+                + "<script type=\"text/javascript\">\n"
+                + "if (targetPage == \"\" || targetPage == \"undefined\")\n"
+                + "     window.location.replace('overview-summary.html');\n"
+                + "</script>\n"
+                + "<noscript>JavaScript is disabled on your browser.</noscript>\n"
                 + "<div class=\"mainContainer\">\n");
     }
 
@@ -1424,6 +1434,11 @@
                 "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\" \"http://www.w3.org/TR/html4/loose.dtd\">",
                 "<link rel=\"stylesheet\" type=\"text/css\" href=\"stylesheet.css\" title=\"Style\">",
                 "<body onload=\"loadFrames()\">\n"
+                + "<script type=\"text/javascript\">\n"
+                + "if (targetPage == \"\" || targetPage == \"undefined\")\n"
+                + "     window.location.replace('overview-summary.html');\n"
+                + "</script>\n"
+                + "<noscript>JavaScript is disabled on your browser.</noscript>\n"
                 + "<div class=\"mainContainer\">\n"
                 + "<div class=\"leftContainer\">\n"
                 + "<div class=\"leftTop\">\n"
@@ -1924,6 +1939,11 @@
         checkOutput("index.html", false,
                 "<!DOCTYPE HTML>",
                 "<body>\n"
+                + "<script type=\"text/javascript\">\n"
+                + "if (targetPage == \"\" || targetPage == \"undefined\")\n"
+                + "     window.location.replace('overview-summary.html');\n"
+                + "</script>\n"
+                + "<noscript>JavaScript is disabled on your browser.</noscript>\n"
                 + "<main role=\"main\">\n"
                 + "<div class=\"mainContainer\">\n");
     }