8173707: Javadoc generated pages should default to no-frames view

Reviewed-by: jjg, ksrini
This commit is contained in:
Bhavesh Patel 2017-02-02 14:55:23 -08:00
parent 02431ac603
commit 0c3069371e
3 changed files with 42 additions and 7 deletions

View File

@ -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.HtmlAttr;
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 @@ public class FrameOutputWriter extends HtmlDocletWriter {
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);

View File

@ -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 @@ public class TestFramesNoFrames extends JavadocTester {
}
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

View File

@ -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 @@ public class TestHtmlVersion extends JavadocTester {
"<!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 @@ public class TestHtmlVersion extends JavadocTester {
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 @@ public class TestHtmlVersion extends JavadocTester {
"<!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 @@ public class TestHtmlVersion extends JavadocTester {
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");
}