Skip to content

Commit

Permalink
8210047: some pages contain content outside of landmark region
Browse files Browse the repository at this point in the history
Reviewed-by: clanger
Backport-of: a17816f
  • Loading branch information
psoujany authored and RealCLanger committed Sep 22, 2022
1 parent bcdcc9f commit 7957658
Show file tree
Hide file tree
Showing 12 changed files with 411 additions and 224 deletions.
Expand Up @@ -33,6 +33,7 @@
import javax.lang.model.element.ModuleElement;
import javax.lang.model.element.PackageElement;

import jdk.javadoc.internal.doclets.formats.html.markup.ContentBuilder;
import jdk.javadoc.internal.doclets.formats.html.markup.HtmlConstants;
import jdk.javadoc.internal.doclets.formats.html.markup.HtmlStyle;
import jdk.javadoc.internal.doclets.formats.html.markup.HtmlTag;
Expand Down Expand Up @@ -81,42 +82,42 @@ public AbstractModuleIndexWriter(HtmlConfiguration configuration,
/**
* Adds the navigation bar header to the documentation tree.
*
* @param body the document tree to which the navigation bar header will be added
* @param header the document tree to which the navigation bar header will be added
*/
protected abstract void addNavigationBarHeader(Content body);
protected abstract void addNavigationBarHeader(Content header);

/**
* Adds the navigation bar footer to the documentation tree.
*
* @param body the document tree to which the navigation bar footer will be added
* @param footer the document tree to which the navigation bar footer will be added
*/
protected abstract void addNavigationBarFooter(Content body);
protected abstract void addNavigationBarFooter(Content footer);

/**
* Adds the overview header to the documentation tree.
*
* @param body the document tree to which the overview header will be added
* @param main the document tree to which the overview header will be added
*/
protected abstract void addOverviewHeader(Content body);
protected abstract void addOverviewHeader(Content main);

/**
* Adds the modules list to the documentation tree.
*
* @param body the document tree to which the modules list will be added
* @param main the document tree to which the modules list will be added
*/
protected abstract void addModulesList(Content body);
protected abstract void addModulesList(Content main);

/**
* Adds the module packages list to the documentation tree.
*
* @param modules the set of modules
* @param text caption for the table
* @param tableSummary summary for the table
* @param body the document tree to which the modules list will be added
* @param main the document tree to which the modules list will be added
* @param mdle the module being documented
*/
protected abstract void addModulePackagesList(Map<ModuleElement, Set<PackageElement>> modules, String text,
String tableSummary, Content body, ModuleElement mdle);
String tableSummary, Content main, ModuleElement mdle);

/**
* Generate and prints the contents in the module index file. Call appropriate
Expand All @@ -130,11 +131,17 @@ protected abstract void addModulePackagesList(Map<ModuleElement, Set<PackageElem
protected void buildModuleIndexFile(String title, boolean includeScript) throws DocFileIOException {
String windowOverview = configuration.getText(title);
Content body = getBody(includeScript, getWindowTitle(windowOverview));
addNavigationBarHeader(body);
addOverviewHeader(body);
addIndex(body);
addOverview(body);
addNavigationBarFooter(body);
Content header = createTagIfAllowed(HtmlTag.HEADER, HtmlTree::HEADER, ContentBuilder::new);
addNavigationBarHeader(header);
Content main = createTagIfAllowed(HtmlTag.MAIN, HtmlTree::MAIN, ContentBuilder::new);
addOverviewHeader(main);
addIndex(header, main);
addOverview(main);
Content footer = createTagIfAllowed(HtmlTag.FOOTER, HtmlTree::FOOTER, ContentBuilder::new);
addNavigationBarFooter(footer);
body.addContent(header);
body.addContent(main);
body.addContent(footer);
printHtmlDocument(configuration.metakeywords.getOverviewMetaKeywords(title,
configuration.doctitle), includeScript, body);
}
Expand All @@ -153,45 +160,53 @@ protected void buildModulePackagesIndexFile(String title,
boolean includeScript, ModuleElement mdle) throws DocFileIOException {
String windowOverview = configuration.getText(title);
Content body = getBody(includeScript, getWindowTitle(windowOverview));
addNavigationBarHeader(body);
addOverviewHeader(body);
addModulePackagesIndex(body, mdle);
addOverview(body);
addNavigationBarFooter(body);
Content header = createTagIfAllowed(HtmlTag.HEADER, HtmlTree::HEADER, ContentBuilder::new);
addNavigationBarHeader(header);
Content main = createTagIfAllowed(HtmlTag.MAIN, HtmlTree::MAIN, ContentBuilder::new);
addOverviewHeader(main);
addModulePackagesIndex(header, main, mdle);
addOverview(main);
Content footer = createTagIfAllowed(HtmlTag.FOOTER, HtmlTree::FOOTER, ContentBuilder::new);
addNavigationBarFooter(footer);
body.addContent(header);
body.addContent(main);
body.addContent(footer);
printHtmlDocument(configuration.metakeywords.getOverviewMetaKeywords(title,
configuration.doctitle), includeScript, body);
}

/**
* Default to no overview, override to add overview.
*
* @param body the document tree to which the overview will be added
* @param main the document tree to which the overview will be added
*/
protected void addOverview(Content body) { }
protected void addOverview(Content main) { }

/**
* Adds the frame or non-frame module index to the documentation tree.
*
* @param body the document tree to which the index will be added
* @param header the document tree to which the navigational links will be added
* @param main the document tree to which the modules list will be added
*/
protected void addIndex(Content body) {
protected void addIndex(Content header, Content main) {
addIndexContents(configuration.modules, "doclet.Module_Summary",
configuration.getText("doclet.Member_Table_Summary",
configuration.getText("doclet.Module_Summary"),
configuration.getText("doclet.modules")), body);
configuration.getText("doclet.modules")), header, main);
}

/**
* Adds the frame or non-frame module packages index to the documentation tree.
*
* @param body the document tree to which the index will be added
* @param header the document tree to which the navigational links will be added
* @param main the document tree to which the module packages list will be added
* @param mdle the module being documented
*/
protected void addModulePackagesIndex(Content body, ModuleElement mdle) {
protected void addModulePackagesIndex(Content header, Content main, ModuleElement mdle) {
addModulePackagesIndexContents("doclet.Module_Summary",
configuration.getText("doclet.Member_Table_Summary",
configuration.getText("doclet.Module_Summary"),
configuration.getText("doclet.modules")), body, mdle);
configuration.getText("doclet.modules")), header, main, mdle);
}

/**
Expand All @@ -201,20 +216,19 @@ protected void addModulePackagesIndex(Content body, ModuleElement mdle) {
* @param modules the modules to be documented
* @param text string which will be used as the heading
* @param tableSummary summary for the table
* @param body the document tree to which the index contents will be added
* @param header the document tree to which the navgational links will be added
* @param main the document tree to which the modules list will be added
*/
protected void addIndexContents(Collection<ModuleElement> modules, String text,
String tableSummary, Content body) {
HtmlTree htmlTree = (configuration.allowTag(HtmlTag.NAV))
? HtmlTree.NAV()
: new HtmlTree(HtmlTag.DIV);
String tableSummary, Content header, Content main) {
HtmlTree htmlTree = (HtmlTree)createTagIfAllowed(HtmlTag.NAV, HtmlTree::NAV, () -> new HtmlTree(HtmlTag.DIV));
htmlTree.setStyle(HtmlStyle.indexNav);
HtmlTree ul = new HtmlTree(HtmlTag.UL);
addAllClassesLink(ul);
addAllPackagesLink(ul);
htmlTree.addContent(ul);
body.addContent(htmlTree);
addModulesList(body);
header.addContent(htmlTree);
addModulesList(main);
}

/**
Expand All @@ -223,22 +237,21 @@ protected void addIndexContents(Collection<ModuleElement> modules, String text,
*
* @param text string which will be used as the heading
* @param tableSummary summary for the table
* @param body the document tree to which the index contents will be added
* @param header the document tree to which the navigational links will be added
* @param main the document tree to which the module packages list will be added
* @param mdle the module being documented
*/
protected void addModulePackagesIndexContents(String text,
String tableSummary, Content body, ModuleElement mdle) {
HtmlTree htmlTree = (configuration.allowTag(HtmlTag.NAV))
? HtmlTree.NAV()
: new HtmlTree(HtmlTag.DIV);
String tableSummary, Content header, Content main, ModuleElement mdle) {
HtmlTree htmlTree = (HtmlTree)createTagIfAllowed(HtmlTag.NAV, HtmlTree::NAV, () -> new HtmlTree(HtmlTag.DIV));
htmlTree.setStyle(HtmlStyle.indexNav);
HtmlTree ul = new HtmlTree(HtmlTag.UL);
addAllClassesLink(ul);
addAllPackagesLink(ul);
addAllModulesLink(ul);
htmlTree.addContent(ul);
body.addContent(htmlTree);
addModulePackagesList(modules, text, tableSummary, body, mdle);
header.addContent(htmlTree);
addModulePackagesList(modules, text, tableSummary, main, mdle);
}

/**
Expand Down
Expand Up @@ -29,6 +29,7 @@

import javax.lang.model.element.PackageElement;

import jdk.javadoc.internal.doclets.formats.html.markup.ContentBuilder;
import jdk.javadoc.internal.doclets.formats.html.markup.HtmlConstants;
import jdk.javadoc.internal.doclets.formats.html.markup.HtmlStyle;
import jdk.javadoc.internal.doclets.formats.html.markup.HtmlTag;
Expand Down Expand Up @@ -78,9 +79,9 @@ public AbstractPackageIndexWriter(HtmlConfiguration configuration,
/**
* Adds the navigation bar header to the documentation tree.
*
* @param body the document tree to which the navigation bar header will be added
* @param header the document tree to which the navigation bar header will be added
*/
protected abstract void addNavigationBarHeader(Content body);
protected abstract void addNavigationBarHeader(Content header);

/**
* Adds the navigation bar footer to the documentation tree.
Expand All @@ -92,16 +93,16 @@ public AbstractPackageIndexWriter(HtmlConfiguration configuration,
/**
* Adds the overview header to the documentation tree.
*
* @param body the document tree to which the overview header will be added
* @param footer the document tree to which the overview header will be added
*/
protected abstract void addOverviewHeader(Content body);
protected abstract void addOverviewHeader(Content footer);

/**
* Adds the packages list to the documentation tree.
*
* @param body the document tree to which the packages list will be added
* @param main the document tree to which the packages list will be added
*/
protected abstract void addPackagesList(Content body);
protected abstract void addPackagesList(Content main);

/**
* Generate and prints the contents in the package index file. Call appropriate
Expand All @@ -115,51 +116,57 @@ public AbstractPackageIndexWriter(HtmlConfiguration configuration,
protected void buildPackageIndexFile(String title, boolean includeScript) throws DocFileIOException {
String windowOverview = configuration.getText(title);
Content body = getBody(includeScript, getWindowTitle(windowOverview));
addNavigationBarHeader(body);
addOverviewHeader(body);
addIndex(body);
addOverview(body);
addNavigationBarFooter(body);
Content header = createTagIfAllowed(HtmlTag.HEADER, HtmlTree::HEADER, ContentBuilder::new);
addNavigationBarHeader(header);
Content main = createTagIfAllowed(HtmlTag.MAIN, HtmlTree::MAIN, ContentBuilder::new);
addOverviewHeader(main);
addIndex(header, main);
addOverview(main);
Content footer = createTagIfAllowed(HtmlTag.FOOTER, HtmlTree::FOOTER, ContentBuilder::new);
addNavigationBarFooter(footer);
body.addContent(header);
body.addContent(main);
body.addContent(footer);
printHtmlDocument(configuration.metakeywords.getOverviewMetaKeywords(title,
configuration.doctitle), includeScript, body);
}

/**
* Default to no overview, override to add overview.
*
* @param body the document tree to which the overview will be added
* @param main the document tree to which the overview will be added
*/
protected void addOverview(Content body) { }
protected void addOverview(Content main) { }

/**
* Adds the frame or non-frame package index to the documentation tree.
*
* @param body the document tree to which the index will be added
* @param header the document tree to which the navigation links will be added
* @param main the document tree to which the packages list will be added
*/
protected void addIndex(Content body) {
addIndexContents(body);
protected void addIndex(Content header, Content main) {
addIndexContents(header, main);
}

/**
* Adds package index contents. Call appropriate methods from
* the sub-classes. Adds it to the body HtmlTree
*
* @param body the document tree to which the index contents will be added
* @param header the document tree to which navigation links will be added
* @param main the document tree to which the packages list will be added
*/
protected void addIndexContents(Content body) {
protected void addIndexContents(Content header, Content main) {
if (!packages.isEmpty()) {
HtmlTree htmlTree = (configuration.allowTag(HtmlTag.NAV))
? HtmlTree.NAV()
: new HtmlTree(HtmlTag.DIV);
HtmlTree htmlTree = (HtmlTree)createTagIfAllowed(HtmlTag.NAV, HtmlTree::NAV, () -> new HtmlTree(HtmlTag.DIV));
htmlTree.setStyle(HtmlStyle.indexNav);
HtmlTree ul = new HtmlTree(HtmlTag.UL);
addAllClassesLink(ul);
if (configuration.showModules && configuration.modules.size() > 1) {
addAllModulesLink(ul);
}
htmlTree.addContent(ul);
body.addContent(htmlTree);
addPackagesList(body);
header.addContent(htmlTree);
addPackagesList(main);
}
}

Expand Down
Expand Up @@ -29,6 +29,7 @@
import javax.lang.model.element.Element;
import javax.lang.model.element.TypeElement;

import jdk.javadoc.internal.doclets.formats.html.markup.ContentBuilder;
import jdk.javadoc.internal.doclets.formats.html.markup.HtmlConstants;
import jdk.javadoc.internal.doclets.formats.html.markup.HtmlStyle;
import jdk.javadoc.internal.doclets.formats.html.markup.HtmlTag;
Expand Down Expand Up @@ -114,15 +115,15 @@ private static void generate(HtmlConfiguration configuration, IndexBuilder index
protected void buildAllClassesFile(boolean wantFrames) throws DocFileIOException {
String label = configuration.getText("doclet.All_Classes");
Content body = getBody(false, getWindowTitle(label));
Content htmlTree = createTagIfAllowed(HtmlTag.MAIN, HtmlTree::MAIN, ContentBuilder::new);
Content heading = HtmlTree.HEADING(HtmlConstants.TITLE_HEADING,
HtmlStyle.bar, contents.allClassesLabel);
body.addContent(heading);
htmlTree.addContent(heading);
Content ul = new HtmlTree(HtmlTag.UL);
// Generate the class links and add it to the tdFont tree.
addAllClasses(ul, wantFrames);
HtmlTree htmlTree = (configuration.allowTag(HtmlTag.MAIN))
? HtmlTree.MAIN(HtmlStyle.indexContainer, ul)
: HtmlTree.DIV(HtmlStyle.indexContainer, ul);
HtmlTree div = HtmlTree.DIV(HtmlStyle.indexContainer, ul);
htmlTree.addContent(div);
body.addContent(htmlTree);
printHtmlDocument(null, false, body);
}
Expand Down
Expand Up @@ -29,6 +29,7 @@
import jdk.javadoc.internal.doclets.formats.html.markup.TableHeader;

import java.util.*;
import java.util.function.Supplier;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

Expand Down Expand Up @@ -2093,4 +2094,20 @@ public HtmlTree getBody(boolean includeScript, String title) {
Script getMainBodyScript() {
return mainBodyScript;
}

/**
* Creates the HTML tag if the tag is supported by this specific HTML version
* otherwise return the Content instance provided by Supplier ifNotSupported.
* @param tag the HTML tag
* @param ifSupported create this instance if HTML tag is supported
* @param ifNotSupported create this instance if HTML tag is not supported
* @return
*/
protected Content createTagIfAllowed(HtmlTag tag, Supplier<Content> ifSupported, Supplier<Content> ifNotSupported) {
if (configuration.allowTag(tag)) {
return ifSupported.get();
} else {
return ifNotSupported.get();
}
}
}

1 comment on commit 7957658

@openjdk-notifier
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.