8182263: Search box and reset button needs to be a11y fixed.
authorbpatel
Thu, 24 Aug 2017 12:32:32 -0700
changeset 47047 91082c3c1d05
parent 46928 a85884d55ce3
child 47049 53333492bb1c
8182263: Search box and reset button needs to be a11y fixed. Reviewed-by: jjg, ksrini
langtools/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/HtmlDocletWriter.java
langtools/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/markup/HtmlAttr.java
langtools/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/markup/HtmlTag.java
langtools/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/markup/HtmlTree.java
langtools/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/resources/search.js
langtools/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/toolkit/resources/stylesheet.css
langtools/test/jdk/javadoc/doclet/testSearch/TestSearch.java
langtools/test/jdk/javadoc/doclet/testStylesheet/TestStylesheet.java
--- a/langtools/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/HtmlDocletWriter.java	Fri Aug 25 12:39:21 2017 +0200
+++ b/langtools/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/HtmlDocletWriter.java	Thu Aug 24 12:32:32 2017 -0700
@@ -624,12 +624,12 @@
             ulAllClasses.addAttr(HtmlAttr.ID, allClassesId);
             subDiv.addContent(ulAllClasses);
             if (header && configuration.createindex) {
-                HtmlTree inputText = HtmlTree.INPUT("text", "search");
-                HtmlTree inputReset = HtmlTree.INPUT("reset", "reset");
-                Content searchTxt = new ContentBuilder();
-                searchTxt.addContent(configuration.getContent("doclet.search"));
-                searchTxt.addContent(Contents.SPACE);
-                HtmlTree liInput = HtmlTree.LI(HtmlTree.SPAN(searchTxt));
+                String searchValueId = "search";
+                String reset = "reset";
+                HtmlTree inputText = HtmlTree.INPUT("text", searchValueId, searchValueId);
+                HtmlTree inputReset = HtmlTree.INPUT(reset, reset, reset);
+                Content searchTxt = configuration.getContent("doclet.search");
+                HtmlTree liInput = HtmlTree.LI(HtmlTree.LABEL(searchValueId, searchTxt));
                 liInput.addContent(inputText);
                 liInput.addContent(inputReset);
                 HtmlTree ulSearch = HtmlTree.UL(HtmlStyle.navListSearch, liInput);
--- a/langtools/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/markup/HtmlAttr.java	Fri Aug 25 12:39:21 2017 +0200
+++ b/langtools/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/markup/HtmlAttr.java	Thu Aug 24 12:32:32 2017 -0700
@@ -44,6 +44,7 @@
     COLS,
     CONTENT,
     DISABLED,
+    FOR,
     HREF,
     HTTP_EQUIV("http-equiv"),
     ID,
--- a/langtools/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/markup/HtmlTag.java	Fri Aug 25 12:39:21 2017 +0200
+++ b/langtools/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/markup/HtmlTag.java	Thu Aug 24 12:32:32 2017 -0700
@@ -67,6 +67,7 @@
     IFRAME(BlockType.OTHER, EndTag.END),
     IMG(BlockType.INLINE, EndTag.NOEND),
     INPUT(BlockType.BLOCK, EndTag.NOEND),
+    LABEL(BlockType.INLINE, EndTag.END),
     LI,
     LISTING,
     LINK(BlockType.OTHER, EndTag.NOEND),
--- a/langtools/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/markup/HtmlTree.java	Fri Aug 25 12:39:21 2017 +0200
+++ b/langtools/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/markup/HtmlTree.java	Thu Aug 24 12:32:32 2017 -0700
@@ -474,18 +474,32 @@
      *
      * @param type the type of input
      * @param id id for the tag
+     * @param value value for the tag
      * @return an HtmlTree object for the INPUT tag
      */
-    public static HtmlTree INPUT(String type, String id) {
+    public static HtmlTree INPUT(String type, String id, String value) {
         HtmlTree htmltree = new HtmlTree(HtmlTag.INPUT);
         htmltree.addAttr(HtmlAttr.TYPE, nullCheck(type));
         htmltree.addAttr(HtmlAttr.ID, nullCheck(id));
-        htmltree.addAttr(HtmlAttr.VALUE, " ");
+        htmltree.addAttr(HtmlAttr.VALUE, nullCheck(value));
         htmltree.addAttr(HtmlAttr.DISABLED, "disabled");
         return htmltree;
     }
 
     /**
+     * Generates a LABEL tag with some content.
+     *
+     * @param forLabel value of "for" attribute of the LABEL tag
+     * @param body content for the tag
+     * @return an HtmlTree object for the LABEL tag
+     */
+    public static HtmlTree LABEL(String forLabel, Content body) {
+        HtmlTree htmltree = new HtmlTree(HtmlTag.LABEL, nullCheck(body));
+        htmltree.addAttr(HtmlAttr.FOR, nullCheck(forLabel));
+        return htmltree;
+    }
+
+    /**
      * Generates a LI tag with some content.
      *
      * @param body content for the tag
--- a/langtools/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/resources/search.js	Fri Aug 25 12:39:21 2017 +0200
+++ b/langtools/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/resources/search.js	Thu Aug 24 12:32:32 2017 -0700
@@ -78,6 +78,7 @@
 }
 var watermark = 'Search';
 $(function() {
+    $("#search").val('');
     $("#search").prop("disabled", false);
     $("#reset").prop("disabled", false);
     $("#search").val(watermark).addClass('watermark');
--- a/langtools/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/toolkit/resources/stylesheet.css	Fri Aug 25 12:39:21 2017 +0200
+++ b/langtools/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/toolkit/resources/stylesheet.css	Thu Aug 24 12:32:32 2017 -0700
@@ -203,7 +203,7 @@
     padding: 5px 6px;
     text-transform:uppercase;
 }
-ul.navListSearch li span {
+ul.navListSearch li label {
     position:relative;
     right:-16px;
 }
@@ -756,18 +756,20 @@
 }
 #reset {
     background-color: rgb(255,255,255);
+    background-image:url('resources/x.png');
+    background-position:center;
+    background-repeat:no-repeat;
+    background-size:12px;
     border:0 none;
     width:16px;
     height:17px;
     position:relative;
-    left:-2px;
-    background-image:url('resources/x.png');
-    background-repeat:no-repeat;
-    background-size:12px;
-    background-position:center;
+    left:-4px;
+    top:-4px;
+    font-size:0px;
 }
 .watermark {
-    color:#888;
+    color:#545454;
 }
 .searchTagDescResult {
     font-style:italic;
@@ -871,4 +873,3 @@
 table.striped > tbody > tr > th {
     font-weight: normal;
 }
-
--- a/langtools/test/jdk/javadoc/doclet/testSearch/TestSearch.java	Fri Aug 25 12:39:21 2017 +0200
+++ b/langtools/test/jdk/javadoc/doclet/testSearch/TestSearch.java	Thu Aug 24 12:32:32 2017 -0700
@@ -23,7 +23,7 @@
 
 /*
  * @test
- * @bug 8141492 8071982 8141636 8147890 8166175 8168965 8176794 8175218 8147881 8181622
+ * @bug 8141492 8071982 8141636 8147890 8166175 8168965 8176794 8175218 8147881 8181622 8182263
  * @summary Test the search feature of javadoc.
  * @author bpatel
  * @library ../lib
@@ -273,9 +273,9 @@
                 "<script type=\"text/javascript\" src=\"jquery/jquery-ui.js\"></script>",
                 "var pathtoroot = \"./\";loadScripts(document, 'script');",
                 "<ul class=\"navListSearch\">\n",
-                "<li><span>SEARCH:&nbsp;</span>\n",
-                "<input type=\"text\" id=\"search\" value=\" \" disabled=\"disabled\">\n",
-                "<input type=\"reset\" id=\"reset\" value=\" \" disabled=\"disabled\">\n");
+                "<li><label for=\"search\">SEARCH:</label>\n"
+                + "<input type=\"text\" id=\"search\" value=\"search\" disabled=\"disabled\">\n"
+                + "<input type=\"reset\" id=\"reset\" value=\"reset\" disabled=\"disabled\">\n");
         checkOutput(fileName, true,
                 "<div class=\"fixedNav\">");
     }
--- a/langtools/test/jdk/javadoc/doclet/testStylesheet/TestStylesheet.java	Fri Aug 25 12:39:21 2017 +0200
+++ b/langtools/test/jdk/javadoc/doclet/testStylesheet/TestStylesheet.java	Thu Aug 24 12:32:32 2017 -0700
@@ -24,7 +24,7 @@
 /*
  * @test
  * @bug      4494033 7028815 7052425 8007338 8023608 8008164 8016549 8072461 8154261 8162363 8160196 8151743 8177417
- *           8175218 8176452 8181215
+ *           8175218 8176452 8181215 8182263
  * @summary  Run tests on doclet stylesheet.
  * @author   jamieh
  * @library  ../lib
@@ -185,6 +185,23 @@
                 + "th.colConstructorName a:link, th.colConstructorName a:visited,\n"
                 + ".constantValuesContainer td a:link, .constantValuesContainer td a:visited {\n"
                 + "    font-weight:bold;\n"
+                + "}",
+                "#reset {\n"
+                + "    background-color: rgb(255,255,255);\n"
+                + "    background-image:url('resources/x.png');\n"
+                + "    background-position:center;\n"
+                + "    background-repeat:no-repeat;\n"
+                + "    background-size:12px;\n"
+                + "    border:0 none;\n"
+                + "    width:16px;\n"
+                + "    height:17px;\n"
+                + "    position:relative;\n"
+                + "    left:-4px;\n"
+                + "    top:-4px;\n"
+                + "    font-size:0px;\n"
+                + "}",
+                ".watermark {\n"
+                + "    color:#545454;\n"
                 + "}");
 
         checkOutput("pkg/A.html", true,