Commit db7ca2b0 authored by semeny@google.com's avatar semeny@google.com

DevTools: [Documentation] Add signature section for renderer

Drive-by fixes:
1) Fix constants documentation detection
2) Fix inherited Function methods problem

BUG=391593

Review URL: https://codereview.chromium.org/525363003

git-svn-id: svn://svn.chromium.org/blink/trunk@181648 bbb929c8-8fbe-4397-9dbb-9b2b20218538
parent b898494e
...@@ -74,7 +74,7 @@ WebInspector.DocumentationURLProvider.ItemDescriptor.prototype = { ...@@ -74,7 +74,7 @@ WebInspector.DocumentationURLProvider.ItemDescriptor.prototype = {
/** /**
* @constructor * @constructor
* FIXME: source parameter is not annotated property due to crbug.com/407097 * FIXME: source parameter is not annotated properly due to crbug.com/407097
* @param {*} source * @param {*} source
* @param {string} url * @param {string} url
* @param {string} name * @param {string} name
...@@ -172,7 +172,7 @@ WebInspector.DocumentationURLProvider.prototype = { ...@@ -172,7 +172,7 @@ WebInspector.DocumentationURLProvider.prototype = {
var sources = WebInspector.DocumentationURLProvider._sources; var sources = WebInspector.DocumentationURLProvider._sources;
var propertyName = searchTerm.toUpperCase() === searchTerm ? "constants" : searchTerm; var propertyName = searchTerm.toUpperCase() === searchTerm ? "constants" : searchTerm;
for (var i = 0; i < sources.length; ++i) { for (var i = 0; i < sources.length; ++i) {
if (!sources[i].source().hasOwnProperty(propertyName)) if (!sources[i].source().hasOwnProperty(searchTerm) || this._inheritedFromFunction(sources[i].source(), searchTerm))
continue; continue;
descriptors.push(new WebInspector.DocumentationURLProvider.ItemDescriptor(sources[i], propertyName)); descriptors.push(new WebInspector.DocumentationURLProvider.ItemDescriptor(sources[i], propertyName));
} }
...@@ -233,19 +233,29 @@ WebInspector.DocumentationURLProvider.prototype = { ...@@ -233,19 +233,29 @@ WebInspector.DocumentationURLProvider.prototype = {
var lastSlashIndex = itemPath.lastIndexOf("/"); var lastSlashIndex = itemPath.lastIndexOf("/");
if (lastSlashIndex === -1) if (lastSlashIndex === -1)
return; return;
var sourceName = itemPath.substring(0, lastSlashIndex + 1);
// There are some properties which have several words in their name. // There are some properties which have several words in their name.
// In article list they are written through gap, while in URL they are written through underscore. // In article list they are written through gap, while in URL they are written through underscore.
// We are creating URL for current property, so we have to replace all the gaps with underscores. // We are creating URL for current property, so we have to replace all the gaps with underscores.
var correctedItemPath = itemPath.replace(" ", "_"); var propertyName = itemPath.substring(lastSlashIndex + 1).replace(" ", "_");
var sourceName = correctedItemPath.substring(0, lastSlashIndex + 1);
var propertyName = correctedItemPath.substring(lastSlashIndex + 1);
var sources = WebInspector.DocumentationURLProvider._sources; var sources = WebInspector.DocumentationURLProvider._sources;
for (var i = 0; i < sources.length; ++i) { for (var i = 0; i < sources.length; ++i) {
if (sources[i].url() !== sourceName || !sources[i].source().hasOwnProperty(propertyName)) if (sources[i].url() !== sourceName || !sources[i].source().hasOwnProperty(propertyName) || this._inheritedFromFunction(sources[i].source(), propertyName))
continue; continue;
var descriptors = this._articleList.get(propertyName) || []; var descriptors = this._articleList.get(propertyName) || [];
descriptors.push(new WebInspector.DocumentationURLProvider.ItemDescriptor(sources[i], propertyName)); descriptors.push(new WebInspector.DocumentationURLProvider.ItemDescriptor(sources[i], propertyName));
this._articleList.set(propertyName, descriptors); this._articleList.set(propertyName, descriptors);
} }
},
/**
* FIXME: object parameter is not annotated properly due to crbug.com/407097
* @param {*} object
* @param {string} propertyName
* @return {boolean}
*/
_inheritedFromFunction: function(object, propertyName)
{
return (object instanceof Function && object.hasOwnProperty(propertyName) && Function.hasOwnProperty(propertyName));
} }
} }
\ No newline at end of file
...@@ -102,8 +102,9 @@ WebInspector.DocumentationView.Renderer.prototype = { ...@@ -102,8 +102,9 @@ WebInspector.DocumentationView.Renderer.prototype = {
{ {
this._createPageTitle(this._article.pageTitle, this._searchItem); this._createPageTitle(this._article.pageTitle, this._searchItem);
this._createStandardizationStatus(this._article.standardizationStatus); this._createStandardizationStatus(this._article.standardizationStatus);
this._createTextSectionWithTitle("Summary", this._article.summary);
this._createSignatureSection(this._article.parameters, this._article.methods); this._createSignatureSection(this._article.parameters, this._article.methods);
this._createTextSectionWithTitle("Summary", this._article.summary);
this._createParametersSection(this._article.parameters);
this._createReturnValueSection(this._article.methods); this._createReturnValueSection(this._article.methods);
this._createExamplesSection(this._article.examples); this._createExamplesSection(this._article.examples);
this._createTextSectionWithTitle("Remarks", this._article.remarks); this._createTextSectionWithTitle("Remarks", this._article.remarks);
...@@ -148,6 +149,7 @@ WebInspector.DocumentationView.Renderer.prototype = { ...@@ -148,6 +149,7 @@ WebInspector.DocumentationView.Renderer.prototype = {
title.textContent = titleText; title.textContent = titleText;
var text = this._renderBlock(article); var text = this._renderBlock(article);
text.classList.add("documentation-text"); text.classList.add("documentation-text");
text.classList.add("documentation-section-content");
section.appendChild(text); section.appendChild(text);
}, },
...@@ -156,6 +158,28 @@ WebInspector.DocumentationView.Renderer.prototype = { ...@@ -156,6 +158,28 @@ WebInspector.DocumentationView.Renderer.prototype = {
* @param {?WebInspector.JSArticle.Method} method * @param {?WebInspector.JSArticle.Method} method
*/ */
_createSignatureSection: function(parameters, method) _createSignatureSection: function(parameters, method)
{
if (!method)
return;
var section = this._element.createChild("p", "documentation-section");
var signature = section.createChild("span", "documentation-method-signature documentation-section-content monospace");
var methodName = signature.createChild("span", "documentation-method-name");
methodName.textContent = this._searchItem.split(".").peekLast() + "(";
for (var i = 0; i < parameters.length; ++i) {
if (i > 0)
signature.createTextChild(", ")
var parameterType = signature.createChild("span", "documentation-parameter-data-type-value");
parameterType.textContent = parameters[i].dataType + (parameters[i].optional ? "=" : "");;
}
signature.createTextChild("): ");
var returnTypeElement = signature.createChild("span", "documentation-parameter-data-type-value");
returnTypeElement.textContent = method.returnValueName;
},
/**
* @param {!Array.<!WebInspector.JSArticle.Parameter>} parameters
*/
_createParametersSection: function(parameters)
{ {
if (!parameters.length) if (!parameters.length)
return; return;
...@@ -163,7 +187,7 @@ WebInspector.DocumentationView.Renderer.prototype = { ...@@ -163,7 +187,7 @@ WebInspector.DocumentationView.Renderer.prototype = {
var title = section.createChild("div", "documentation-section-title"); var title = section.createChild("div", "documentation-section-title");
title.textContent = "Parameters"; title.textContent = "Parameters";
for (var i = 0; i < parameters.length; ++i) { for (var i = 0; i < parameters.length; ++i) {
var parameter = section.createChild("div", "documentation-parameter"); var parameter = section.createChild("div", "documentation-parameter documentation-section-content");
var header = parameter.createChild("div", "documentation-parameter-header"); var header = parameter.createChild("div", "documentation-parameter-header");
var name = header.createChild("span", "documentation-parameter-name"); var name = header.createChild("span", "documentation-parameter-name");
name.textContent = parameters[i].name; name.textContent = parameters[i].name;
...@@ -186,13 +210,12 @@ WebInspector.DocumentationView.Renderer.prototype = { ...@@ -186,13 +210,12 @@ WebInspector.DocumentationView.Renderer.prototype = {
{ {
if (!method) if (!method)
return; return;
var section = this._element.createChild("div", "documentation-section"); var section = this._element.createChild("div", "documentation-section");
var title = section.createChild("div", "documentation-section-title"); var title = section.createChild("div", "documentation-section-title");
title.textContent = "Return Value"; title.textContent = "Return Value";
var returnValueName = section.createChild("div", "documentation-return-value"); var returnValueName = section.createChild("div", "documentation-section-content documentation-return-value");
returnValueName.textContent = WebInspector.UIString("Returns an object of type " + method.returnValueName + "."); returnValueName.textContent = WebInspector.UIString("Returns an object of type " + method.returnValueName + ".");
var returnValueDescription = section.createChild("div", "documentation-return-value"); var returnValueDescription = section.createChild("div", "documentation-section-content documentation-text");
returnValueDescription.textContent = WebInspector.UIString(method.returnValueDescription); returnValueDescription.textContent = WebInspector.UIString(method.returnValueDescription);
}, },
...@@ -209,7 +232,7 @@ WebInspector.DocumentationView.Renderer.prototype = { ...@@ -209,7 +232,7 @@ WebInspector.DocumentationView.Renderer.prototype = {
title.textContent = "Examples"; title.textContent = "Examples";
for (var i = 0; i < examples.length; ++i) { for (var i = 0; i < examples.length; ++i) {
var example = section.createChild("div", "documentation-example"); var example = section.createChild("div", "documentation-example documentation-section-content");
var exampleDescription = example.createChild("div", "documentation-example-description-section"); var exampleDescription = example.createChild("div", "documentation-example-description-section");
if (examples[i].liveUrl) { if (examples[i].liveUrl) {
var liveUrl = exampleDescription.createChild("a", "documentation-example-link"); var liveUrl = exampleDescription.createChild("a", "documentation-example-link");
...@@ -217,10 +240,12 @@ WebInspector.DocumentationView.Renderer.prototype = { ...@@ -217,10 +240,12 @@ WebInspector.DocumentationView.Renderer.prototype = {
liveUrl.href = examples[i].liveUrl; liveUrl.href = examples[i].liveUrl;
liveUrl.textContent = WebInspector.UIString("Example"); liveUrl.textContent = WebInspector.UIString("Example");
} }
if (examples[i].description) if (examples[i].description) {
exampleDescription.appendChild(this._renderBlock(examples[i].description)); var description = this._renderBlock(examples[i].description);
var code = example.createChild("div", "documentation-code"); description.classList.add("documentation-text");
code.classList.add("source-code"); exampleDescription.appendChild(description);
}
var code = example.createChild("div", "documentation-code source-code");
code.textContent = examples[i].code; code.textContent = examples[i].code;
if (!examples[i].language) if (!examples[i].language)
continue; continue;
...@@ -252,8 +277,7 @@ WebInspector.DocumentationView.Renderer.prototype = { ...@@ -252,8 +277,7 @@ WebInspector.DocumentationView.Renderer.prototype = {
element = document.createElementWithClass("span", "documentation-code-tag"); element = document.createElementWithClass("span", "documentation-code-tag");
break; break;
case elementTypes.CodeBlock: case elementTypes.CodeBlock:
element = document.createElementWithClass("pre", "documentation-code"); element = document.createElementWithClass("pre", "documentation-code source-code");
element.classList.add("source-code");
element.textContent = article.code(); element.textContent = article.code();
break; break;
case elementTypes.PlainText: case elementTypes.PlainText:
...@@ -305,12 +329,15 @@ WebInspector.DocumentationView.ContextMenuProvider.prototype = { ...@@ -305,12 +329,15 @@ WebInspector.DocumentationView.ContextMenuProvider.prototype = {
return; return;
if (descriptors.length === 1) { if (descriptors.length === 1) {
var formatString = WebInspector.useLowerCaseMenuTitles() ? "Show documentation for %s.%s" : "Show Documentation for %s.%s"; var formatString = WebInspector.useLowerCaseMenuTitles() ? "Show documentation for %s.%s" : "Show Documentation for %s.%s";
contextMenu.appendItem(WebInspector.UIString(formatString, descriptors[0].name(), descriptors[0].searchItem()), WebInspector.DocumentationView.showDocumentationURL.bind(null, descriptors[0].url(), descriptors[0].searchItem())); var methodName = String.sprintf("%s.%s", descriptors[0].name(), descriptors[0].searchItem());
contextMenu.appendItem(WebInspector.UIString(formatString, descriptors[0].name(), descriptors[0].searchItem()), WebInspector.DocumentationView.showDocumentationURL.bind(null, descriptors[0].url(), methodName));
return; return;
} }
var subMenuItem = contextMenu.appendSubMenuItem(WebInspector.UIString(WebInspector.useLowerCaseMenuTitles() ? "Show documentation for..." : "Show Documentation for...")); var subMenuItem = contextMenu.appendSubMenuItem(WebInspector.UIString(WebInspector.useLowerCaseMenuTitles() ? "Show documentation for..." : "Show Documentation for..."));
for (var i = 0; i < descriptors.length; ++i) for (var i = 0; i < descriptors.length; ++i) {
subMenuItem.appendItem(String.sprintf("%s.%s", descriptors[i].name(), descriptors[i].searchItem()), WebInspector.DocumentationView.showDocumentationURL.bind(null, descriptors[i].url(), descriptors[i].searchItem())); var methodName = String.sprintf("%s.%s", descriptors[i].name(), descriptors[i].searchItem());
subMenuItem.appendItem(methodName, WebInspector.DocumentationView.showDocumentationURL.bind(null, descriptors[i].url(), methodName));
}
}, },
/** /**
......
...@@ -5,7 +5,7 @@ ...@@ -5,7 +5,7 @@
*/ */
.documentation-code { .documentation-code {
border: 1px dotted black; border: 1px solid gray;
border-radius: 6px; border-radius: 6px;
padding: 10px; padding: 10px;
margin-bottom: 10px; margin-bottom: 10px;
...@@ -18,21 +18,28 @@ ...@@ -18,21 +18,28 @@
} }
.documentation-link { .documentation-link {
margin-left: 0.5em; margin-left: 5px;
} }
.documentation-highlighted-text { .documentation-highlighted-text {
font-weight: bold; font-weight: bold;
} }
.documentation-parameter { .documentation-view .documentation-method-signature.monospace {
margin-left: 5px; font-size: 120% !important;
border: 1px solid gray;
border-radius: 6px;
padding: 10px;
} }
.documentation-section { .documentation-section {
margin-bottom: 15px; margin-bottom: 15px;
} }
.documentation-section-content {
margin-left: 16px;
}
.documentation-code-tag { .documentation-code-tag {
font-weight: bold; font-weight: bold;
} }
...@@ -67,13 +74,23 @@ ...@@ -67,13 +74,23 @@
.documentation-example-link { .documentation-example-link {
float: right; float: right;
background-color: rgb(241, 246, 251); background-color: rgb(219, 234, 249);
}
.documentation-example-link:visited {
color: rgb(109, 114, 255);
}
.documentation-text {
line-height: 1.5;
} }
.documentation-box { .documentation-box {
padding: 6px; padding: 6px;
padding-left: 10px;
padding-right: 10px;
text-decoration: none; text-decoration: none;
margin-left: 10px; margin-left: 10px;
margin-top: 5px; margin-top: 5px;
border-radius: 5px; border-radius: 5px;
} }
\ No newline at end of file
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment