Bug 443437 - cdoc index.html does not have the left-pane tree navigation thingie when using Chrome
cdoc now generates toc.html (no more xslt!)
diff --git a/src/packages/xdc/tools/cdoc/Big.xs b/src/packages/xdc/tools/cdoc/Big.xs
index 31ec617..bf6baca 100644
--- a/src/packages/xdc/tools/cdoc/Big.xs
+++ b/src/packages/xdc/tools/cdoc/Big.xs
@@ -4,10 +4,10 @@
  *  are made available under the terms of the Eclipse Public License v1.0
  *  which accompanies this distribution, and is available at
  *  http://www.eclipse.org/legal/epl-v10.html
- * 
+ *
  *  Contributors:
  *      Texas Instruments - initial implementation
- * 
+ *
  * --/COPYRIGHT--*/
 /*
  *  ======== Big.xs ========
@@ -37,7 +37,7 @@
     _genPageSuf();
     Gbl.outstr().close();
 
-    Gbl.outstr(new Out.Stream(outdir + '/toc-big.xml'));
+    Gbl.outstr(new Out.Stream(outdir + '/toc-big.html'));
     _genToc();
     Gbl.outstr().close();
 
@@ -56,7 +56,7 @@
 
     fin.read(barr);
     fin.close();
-    
+
     return String(new java.lang.String(barr));
 }
 
@@ -125,7 +125,7 @@
 function _genPageSuf()
 {
     var d = new Date;
-    
+
     PL('<div id="xdocDate">generated on ' + d.toUTCString() + '</div>');
     PL('</div></div></body>');
     PL('</html>');
@@ -164,9 +164,9 @@
         m0 = m0.replace('href="', 'href="body-big.html');
         return m0;
     };
-    
-    var page = _fileText(Gbl.outdir() + '/toc.xml');
-    page = page.replace(/<topic .*?>/g, fxn);
+
+    var page = _fileText(Gbl.outdir() + '/toc.html');
+    page = page.replace(/<li .*?\.html" onclick=/g, fxn);
 
     PL(page);
 }
@@ -250,3 +250,4 @@
 
     return Gbl.sprintf('href="#$1"', m1);
 }
+
diff --git a/src/packages/xdc/tools/cdoc/Index.xs b/src/packages/xdc/tools/cdoc/Index.xs
index 8920d3c..5a164a5 100644
--- a/src/packages/xdc/tools/cdoc/Index.xs
+++ b/src/packages/xdc/tools/cdoc/Index.xs
@@ -4,10 +4,10 @@
  *  are made available under the terms of the Eclipse Public License v1.0
  *  which accompanies this distribution, and is available at
  *  http://www.eclipse.org/legal/epl-v10.html
- * 
+ *
  *  Contributors:
  *      Texas Instruments - initial implementation
- * 
+ *
  * --/COPYRIGHT--*/
 
 var Gbl     = xdc.loadCapsule('Gbl.xs');
@@ -59,10 +59,10 @@
 
     PL('<FRAMESET cols=20%,*>');
     if (big) {
-        PL('<FRAME name="tree" scrolling="yes" src="toc-big.xml">');
+        PL('<FRAME name="tree" scrolling="yes" src="toc-big.html">');
     }
     else {
-        PL('<FRAME name="tree" scrolling="yes" src="toc.xml">');
+        PL('<FRAME name="tree" scrolling="yes" src="toc.html">');
     }
     PL('<FRAMESET name="main" border="0" rows="*">');
     PL('<FRAME name="body" scrolling="yes" src="' + bodyPage + '">');
@@ -74,6 +74,3 @@
     _out.close();
 }
 
-
-
-
diff --git a/src/packages/xdc/tools/cdoc/Toc.xs b/src/packages/xdc/tools/cdoc/Toc.xs
index c6e1813..38058af 100644
--- a/src/packages/xdc/tools/cdoc/Toc.xs
+++ b/src/packages/xdc/tools/cdoc/Toc.xs
@@ -4,10 +4,10 @@
  *  are made available under the terms of the Eclipse Public License v1.0
  *  which accompanies this distribution, and is available at
  *  http://www.eclipse.org/legal/epl-v10.html
- * 
+ *
  *  Contributors:
  *      Texas Instruments - initial implementation
- * 
+ *
  * --/COPYRIGHT--*/
 
 /*
@@ -24,7 +24,7 @@
 function PL( s ) { Gbl.outstr().println(s); }
 
 /*
- *  ======== genToc ======== 
+ *  ======== genToc ========
  */
 function genToc(outdir)
 {
@@ -35,7 +35,7 @@
 
     _getTocPkgs(pkgdirs);
 
-    /* our toc */
+    /* our xml toc */
     Gbl.outstr(new Out.Stream(outdir + '/toc.xml'));
     _genPageTop();
     var gtree = _bldGroups();
@@ -45,6 +45,9 @@
     _genPageSuf();
     Gbl.outstr().close();
 
+    /* our html toc */
+    _htmlToc(outdir);
+
     /* eclipse toc */
     Gbl.outstr(new Out.Stream(outdir + '/eclipse_toc.xml'));
     _genPageTop();
@@ -65,6 +68,234 @@
 }
 
 /*
+ *  ======== _htmlToc ========
+ */
+function _htmlToc(outdir)
+{
+    var gtree = _bldGroups();
+    Gbl.outstr(new Out.Stream(outdir + '/toc.html'));
+
+    /* page top */
+    PL('<html>');
+    PL('<head><meta content="text/html; charset=UTF-8" http-equiv="Content-Type">');
+    PL('<title>XDC Packages</title>');
+    PL('<link href="toc.css" type="text/css" rel="stylesheet">');
+    PL('<script src="toc.js" type="text/javascript" language="javascript"></script>');
+    PL('</head>');
+    PL('<body onmousedown="return false;">');
+    PL('<ul class="open">');
+
+    _htmlAllPackages();
+    _htmlAllModules();
+    _htmlGenGroups(gtree, "");
+
+    /* suffix */
+    PL('</ul></body></html>');
+    Gbl.outstr().close();
+}
+
+/*
+ *  ======== _htmlAllModules ========
+ */
+function _htmlAllModules()
+{
+    /* Get all units and sort by name */
+    var units = [];
+    for each (var pName in tocPkgNames) {
+        var pkg = tocPkgs[pName];
+        for (var i = 0; i < pkg.units.length; i++) {
+            pkg.units[i].qual = pName;
+            units.push(pkg.units[i]);
+        }
+    }
+    units.sort(_objNameCompare);
+
+    /* output the units one by one */
+    PL('<li onclick="toggle(this)" class="closed"><span onclick="cancel(event)" class="noclick">all modules</span><ul onclick="cancel(event)">');
+
+    var srcImg;
+    var i = 0;
+    while (i < units.length - 1) {
+
+        if (units[i + 1].name == units[i].name) {
+            var j = i + 1;
+            var uSame = [units[i], units[j]];
+            while (j < units.length - 1) {
+                if (units[j + 1].name == units[j].name) {
+                    uSame.push(units[++j]);
+                }
+                else {
+                    ++j;
+                    break;
+                }
+            }
+
+            /* find shortest pkg name */
+            var minIndex = 0;
+            for (var k = 1; k < uSame.length; k++) {
+                if (uSame[k].qual.length < uSame[k - 1].qual.length) {
+                    minIndex = k;
+                }
+            }
+            uSame.sort(_objQualCompare);
+
+            PL('<li onclick="toggle(this)" class="closed"><img class="toc-img" src="modules.gif"><span onclick="cancel(event)" class="noclick">' + units[i].name +
+               '</span><ul onclick="cancel(event)">');
+            for (k = 0; k < uSame.length; k++) {
+                srcImg = _srcImg(uSame[k].title);
+                PL('<li class="leaf"><img class="toc-img" src="' + srcImg + '"><a title="' + uSame[k].title +
+                   '" target="body" href="' + uSame[k].href + '" onclick="cancel(event)"><span class="toc-id">' + uSame[k].qual + '</span></a></li>');
+            }
+            PL('</ul></li>');
+            i = j;
+            continue;
+        }
+        else {
+            srcImg = _srcImg(units[i].title);
+            PL('<li class="leaf"><img class="toc-img" src="' + srcImg + '"><a title="' + units[i].title +
+               '" target="body" href="' + units[i].href + '" onclick="cancel(event)"><span class="toc-id">' + units[i].name + '</span></a></li>');
+        }
+        ++i;
+    }
+    if (i == units.length - 1) {
+        srcImg = _srcImg(units[i].title);
+        PL('<li class="leaf"><img class="toc-img" src="' + srcImg + '"><a title="' + units[i].title +
+           '" target="body" href="' + units[i].href + '" onclick="cancel(event)"><span class="toc-id">' + units[i].name + '</span></a></li>');
+    }
+    PL('</ul></li>');
+}
+
+/*
+ *  ======== _htmlAllPackages ========
+ */
+function _htmlAllPackages()
+{
+    PL('<li onclick="toggle(this)" class="closed"><a title="" target="body" href="all-packages.html" onclick="cancel(event)"><span class="toc-pkgs">all packages</span></a>');
+    PL('<ul onclick="cancel(event)">');
+
+    for each (var pName in tocPkgNames) {
+        var pre = pName.replace(/\./g, '/') + '/';
+        var href = pre + 'package.html';
+        var title = 'package ' + pName;
+
+        if (tocPkgs[pName].units.length > 0) {
+            PL('<li onclick="toggle(this)" class="closed"><img class="toc-img" src="package.gif"><a title="' + title +
+               '" target="body" href="' + href + '" onclick="cancel(event)"><span class="toc-id">' + pName + '</span></a><ul onclick="cancel(event)">');
+            _htmlGenUnits(tocPkgs[pName]);
+            PL('</ul></li>');
+        }
+        else {
+            PL('<li class="leaf"><img class="toc-img" src="package.gif"><a title="' + title +
+               '" target="body" href="' + href + '" onclick="cancel(event)"><span class="toc-id">' + pName + '</span></a></li>');
+       }
+    }
+    PL('</ul></li>');
+}
+
+/*
+ *  ======== _htmlGenGroups ========
+ */
+function _htmlGenGroups(gtree, pre)
+{
+    if (gtree.length) {
+        gtree.sort();
+        for (var i = 0; i < gtree.length; i++) {
+	    var elem = gtree[i];
+	    if (elem in gtree) {
+                var qelem = pre ? (pre + '.' + elem) : elem;
+                var isPkg = tocPkgs[qelem] ? true : false;
+                var closeTags = true;
+                if (isPkg) {
+                    var pkgPre = qelem.replace(/\./g, '/') + '/';
+                    var title = 'package ' + qelem;
+                    var href = pkgPre + 'package.html';
+                    if (tocPkgs[qelem].units.length > 0 || _hasSubPkgs(qelem)) {
+                        PL('<li onclick="toggle(this)" class="closed"><img class="toc-img" src="package.gif"><a title="' + title +
+                           '" target="body" href="' + href + '" onclick="cancel(event)"><span class="toc-id">' + elem + '</span></a><ul onclick="cancel(event)">');
+                    }
+                    else {
+                        PL('<li class="leaf"><img class="toc-img" src="package.gif"><a title="' + title +
+                           '" target="body" href="' + href + '" onclick="cancel(event)"><span class="toc-id">' + elem + '</span></a></li>');
+                        closeTags = false;
+                    }
+                }
+                else {
+                    PL('<li onclick="toggle(this)" class="closed"><img class="toc-img" src="packages.gif"><span onclick="cancel(event)" class="noclick">' +
+                       elem + '</span><ul onclick="cancel(event)">');
+                }
+	        _htmlGenGroups(gtree[elem], qelem);
+                if (isPkg) {
+                    _htmlGenPkg(qelem);
+                }
+                if (closeTags) {
+                    PL('</ul></li>');
+                }
+	    }
+        }
+    }
+}
+
+/*
+ *  ======== _htmlGenPkg ========
+ */
+function _htmlGenPkg(pname)
+{
+    var pkg = tocPkgs[pname];
+    if (pkg.units.length) {
+        _htmlGenUnits(pkg);
+    }
+}
+
+/*
+ *  ======== _htmlGenUnits ========
+ */
+function _htmlGenUnits(pkg)
+{
+    for (var i = 0; i < pkg.units.length; i++) {
+	var unit = pkg.units[i];
+        var srcImg = _srcImg(unit.title);
+        PL('<li class="leaf"><img class="toc-img" src="' + srcImg + '"><a title="' + unit.title +
+           '" target="body" href="' + unit.href + '" onclick="cancel(event)"><span class="toc-id">' + unit.name + '</span></a></li>');
+    }
+}
+
+/*
+ *  ======== _hasSubPkgs ========
+ */
+function _hasSubPkgs(pname)
+{
+    var found = false;
+    for (var i = 0; i < tocPkgNames.length; i++) {
+        if (tocPkgNames[i].indexOf(pname + '.') == 0) {
+            found = true;
+            break;
+        }
+    }
+    return (found);
+}
+
+/*
+ *  ======== _srcImg ========
+ */
+function _srcImg(title)
+{
+    var srcImg = '';
+    if (title.search('metaonly module') != -1) {
+        srcImg = 'mod-red.gif';
+    }
+    else if (title.search('module') != -1) {
+        srcImg = 'mod-blue.gif';
+    }
+    else if (title.search('metaonly interface') != -1) {
+        srcImg = 'int-red.gif';
+    }
+    else if (title.search('interface') != -1) {
+        srcImg = 'int-blue.gif';
+    }
+    return (srcImg);
+}
+
+/*
  *  ======== _bldGroups ========
  */
 function _bldGroups()
@@ -272,7 +503,7 @@
 }
 
 /*
- *  ======== _genPkg ======== 
+ *  ======== _genPkg ========
  */
 function _genPkg(pname)
 {
@@ -283,11 +514,11 @@
 }
 
 /*
- *  ======== _genPkgTopic ======== 
+ *  ======== _genPkgTopic ========
  */
 function _genPkgTopic(pname, label)
 {
-    var pre = pname.replace(/\./g, '/') + '/';    
+    var pre = pname.replace(/\./g, '/') + '/';
     PL('<topic class="toc-id" label="' + label + '" href="' + pre + 'package.html" title="package ' + pname + '">');
 }
 
@@ -301,7 +532,7 @@
 	var unit = pkg.units[i];
 
         PL('<topic class="toc-id" label="' + unit.name + '" href="' + unit.href + '" title="' + unit.title + '">');
-/*        
+/*
         if (unit.decls.length) {
             _genDecls(unit);
         }
@@ -366,7 +597,7 @@
                 var decl = {};
                 decl.name = '' + dNode.@name;
                 decl.href = pre + uNode.@name + '.html#' +
-                            dNode.@anchor; 
+                            dNode.@anchor;
                 decl.title = _mkTitle(dNode, uNode);
                 unit.decls.push(decl);
             }
@@ -476,6 +707,4 @@
     else {
         return ('');
     }
-}
-
-
+}
\ No newline at end of file
diff --git a/src/packages/xdc/tools/cdoc/files/index.js b/src/packages/xdc/tools/cdoc/files/index.js
index 2445730..849ee08 100644
--- a/src/packages/xdc/tools/cdoc/files/index.js
+++ b/src/packages/xdc/tools/cdoc/files/index.js
@@ -14,13 +14,8 @@
     urlbase = urlbase.substring(0, urlbase.indexOf("#"));
 }
 urlbase = urlbase.substring(0, urlbase.lastIndexOf("/"));
-var isChrome = navigator.userAgent.toLowerCase().indexOf('chrome') > -1;
 
 function onLoad() {
-    if (isChrome) {
-        window.location.href = urlbase + "/indexChrome.html";
-        return;
-    }
     if (!location.hash) {
         return;
     }
diff --git a/src/packages/xdc/tools/cdoc/files/indexChrome.html b/src/packages/xdc/tools/cdoc/files/indexChrome.html
deleted file mode 100644
index 9654037..0000000
--- a/src/packages/xdc/tools/cdoc/files/indexChrome.html
+++ /dev/null
@@ -1,13 +0,0 @@
-<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Frameset//EN"  "http://www.w3.org/TR/html4/frameset.dtd"><HTML>

-<HEAD>

-<TITLE>RTSC Package Documentation</TITLE>

-<META name="googlebot" content="noindex,nofollow">

-<SCRIPT language="javascript" type="text/javascript" src="indexChrome.js"></SCRIPT>

-</HEAD>

-<FRAMESET cols=20%,*>

-<FRAME name="tree" scrolling="no" src="tocChrome.html">

-<FRAMESET name="main" border="0" rows="*">

-<FRAME name="body" scrolling="yes" src="all-packages.html">

-</FRAMESET>

-</FRAMESET>

-</HTML>

diff --git a/src/packages/xdc/tools/cdoc/files/indexChrome.js b/src/packages/xdc/tools/cdoc/files/indexChrome.js
deleted file mode 100644
index 849ee08..0000000
--- a/src/packages/xdc/tools/cdoc/files/indexChrome.js
+++ /dev/null
@@ -1,67 +0,0 @@
-/* --COPYRIGHT--,EPL
- *  Copyright (c) 2008 Texas Instruments and others.
- *  All rights reserved. This program and the accompanying materials
- *  are made available under the terms of the Eclipse Public License v1.0
- *  which accompanies this distribution, and is available at
- *  http://www.eclipse.org/legal/epl-v10.html
- * 
- *  Contributors:
- *      Texas Instruments - initial implementation
- * 
- * --/COPYRIGHT--*/
-var urlbase = location.href;
-if (location.hash) {
-    urlbase = urlbase.substring(0, urlbase.indexOf("#"));
-}
-urlbase = urlbase.substring(0, urlbase.lastIndexOf("/"));
-
-function onLoad() {
-    if (!location.hash) {
-        return;
-    }
-
-    var href;
-    var dname;
-    var wasxml = false;
-
-    var m = location.hash.match(/^#([^#:]*\.html)([#:](.*))?$/);
-    if (m) {
-        href = m[1];
-        dname = m[3];
-    }
-    else {
-        m = location.hash.match(/^#([^#:]*\.xml)([#:](.*))?$/);
-        if (m) {
-            href = m[1].replace(/\.xml/, '.html');
-            dname = m[3];
-            wasxml = true;
-        }
-    }
-
-    m = location.hash.match(/^#([^:]*)\.html(:([^\.]*))?$/);
-    if (m) {
-        href = m[1] + ".html";
-        dname = m[3] && m[3].replace(/([A-Z])/g, '.$1');
-        dname = dname && dname.replace(/\//g, '');
-    }
-
-    if (dname) {
-        href += "#" + dname;
-    }
-
-    if (href) {
-        top.frames.body.location.replace(urlbase + "/" + href);
-        if (wasxml) {
-  	    var indexbase = location.href;
-	    indexbase = indexbase.substring(0, indexbase.indexOf("#"));
-	    if (indexbase.match(/index\.html$/)) {
-	        location.href = indexbase + "#" + href;
-	    }
-            else {
-                location.href = urlbase + "/" + href;
-            }
-        }
-    }
-}
-
-window.onload = onLoad;
diff --git a/src/packages/xdc/tools/cdoc/files/tocChrome.html b/src/packages/xdc/tools/cdoc/files/tocChrome.html
deleted file mode 100644
index eaeb950..0000000
--- a/src/packages/xdc/tools/cdoc/files/tocChrome.html
+++ /dev/null
@@ -1,15 +0,0 @@
-<!DOCTYPE html>
-<html><head>
-<meta charset="utf-8"/>
-<title>Chrome Message</title>
-</head>
-<body>
-
-    <p style="font-size: 10pt; font-family: Verdana,sans-serif;"> The table of contents cannot be displayed
-    correctly in the Chrome browser. Please use a different browser or refer to
-    <a href="http://stackoverflow.com/questions/3828898/can-chrome-be-made-to-perform-an-xsl-transform-on-a-local-file" target="_blank">this link</a>
-    for a description of the issue and a workaround.
-    </p>
-
-</body>
-</html>