| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 /** | 5 /** |
| 6 * @constructor | 6 * @constructor |
| 7 * @extends {WebInspector.View} | 7 * @extends {WebInspector.View} |
| 8 */ | 8 */ |
| 9 WebInspector.DocumentationView = function() | 9 WebInspector.DocumentationView = function() |
| 10 { | 10 { |
| (...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 95 } | 95 } |
| 96 | 96 |
| 97 WebInspector.DocumentationView.Renderer.prototype = { | 97 WebInspector.DocumentationView.Renderer.prototype = { |
| 98 /** | 98 /** |
| 99 * @return {!Element} | 99 * @return {!Element} |
| 100 */ | 100 */ |
| 101 renderJSArticle: function() | 101 renderJSArticle: function() |
| 102 { | 102 { |
| 103 this._createPageTitle(this._article.pageTitle, this._searchItem); | 103 this._createPageTitle(this._article.pageTitle, this._searchItem); |
| 104 this._createStandardizationStatus(this._article.standardizationStatus); | 104 this._createStandardizationStatus(this._article.standardizationStatus); |
| 105 this._createSignatureSection(this._article.parameters, this._article.met
hods); |
| 105 this._createTextSectionWithTitle("Summary", this._article.summary); | 106 this._createTextSectionWithTitle("Summary", this._article.summary); |
| 106 this._createSignatureSection(this._article.parameters, this._article.met
hods); | 107 this._createParametersSection(this._article.parameters); |
| 107 this._createReturnValueSection(this._article.methods); | 108 this._createReturnValueSection(this._article.methods); |
| 108 this._createExamplesSection(this._article.examples); | 109 this._createExamplesSection(this._article.examples); |
| 109 this._createTextSectionWithTitle("Remarks", this._article.remarks); | 110 this._createTextSectionWithTitle("Remarks", this._article.remarks); |
| 110 | 111 |
| 111 return this._element; | 112 return this._element; |
| 112 }, | 113 }, |
| 113 | 114 |
| 114 /** | 115 /** |
| 115 * @param {string} titleText | 116 * @param {string} titleText |
| 116 * @param {string} searchItem | 117 * @param {string} searchItem |
| (...skipping 24 matching lines...) Expand all Loading... |
| 141 */ | 142 */ |
| 142 _createTextSectionWithTitle: function(titleText, article) | 143 _createTextSectionWithTitle: function(titleText, article) |
| 143 { | 144 { |
| 144 if (!article) | 145 if (!article) |
| 145 return; | 146 return; |
| 146 var section = this._element.createChild("div", "documentation-section"); | 147 var section = this._element.createChild("div", "documentation-section"); |
| 147 var title = section.createChild("div", "documentation-section-title"); | 148 var title = section.createChild("div", "documentation-section-title"); |
| 148 title.textContent = titleText; | 149 title.textContent = titleText; |
| 149 var text = this._renderBlock(article); | 150 var text = this._renderBlock(article); |
| 150 text.classList.add("documentation-text"); | 151 text.classList.add("documentation-text"); |
| 152 text.classList.add("documentation-section-content"); |
| 151 section.appendChild(text); | 153 section.appendChild(text); |
| 152 }, | 154 }, |
| 153 | 155 |
| 154 /** | 156 /** |
| 155 * @param {!Array.<!WebInspector.JSArticle.Parameter>} parameters | 157 * @param {!Array.<!WebInspector.JSArticle.Parameter>} parameters |
| 156 * @param {?WebInspector.JSArticle.Method} method | 158 * @param {?WebInspector.JSArticle.Method} method |
| 157 */ | 159 */ |
| 158 _createSignatureSection: function(parameters, method) | 160 _createSignatureSection: function(parameters, method) |
| 159 { | 161 { |
| 162 if (!method) |
| 163 return; |
| 164 var section = this._element.createChild("p", "documentation-section"); |
| 165 var signature = section.createChild("span", "documentation-method-signat
ure documentation-section-content monospace"); |
| 166 var methodName = signature.createChild("span", "documentation-method-nam
e"); |
| 167 methodName.textContent = this._searchItem.split(".").peekLast() + "("; |
| 168 for (var i = 0; i < parameters.length; ++i) { |
| 169 if (i > 0) |
| 170 signature.createTextChild(", ") |
| 171 var parameterType = signature.createChild("span", "documentation-par
ameter-data-type-value"); |
| 172 parameterType.textContent = parameters[i].dataType + (parameters[i].
optional ? "=" : "");; |
| 173 } |
| 174 signature.createTextChild("): "); |
| 175 var returnTypeElement = signature.createChild("span", "documentation-par
ameter-data-type-value"); |
| 176 returnTypeElement.textContent = method.returnValueName; |
| 177 }, |
| 178 |
| 179 /** |
| 180 * @param {!Array.<!WebInspector.JSArticle.Parameter>} parameters |
| 181 */ |
| 182 _createParametersSection: function(parameters) |
| 183 { |
| 160 if (!parameters.length) | 184 if (!parameters.length) |
| 161 return; | 185 return; |
| 162 var section = this._element.createChild("div", "documentation-section"); | 186 var section = this._element.createChild("div", "documentation-section"); |
| 163 var title = section.createChild("div", "documentation-section-title"); | 187 var title = section.createChild("div", "documentation-section-title"); |
| 164 title.textContent = "Parameters"; | 188 title.textContent = "Parameters"; |
| 165 for (var i = 0; i < parameters.length; ++i) { | 189 for (var i = 0; i < parameters.length; ++i) { |
| 166 var parameter = section.createChild("div", "documentation-parameter"
); | 190 var parameter = section.createChild("div", "documentation-parameter
documentation-section-content"); |
| 167 var header = parameter.createChild("div", "documentation-parameter-h
eader"); | 191 var header = parameter.createChild("div", "documentation-parameter-h
eader"); |
| 168 var name = header.createChild("span", "documentation-parameter-name"
); | 192 var name = header.createChild("span", "documentation-parameter-name"
); |
| 169 name.textContent = parameters[i].name; | 193 name.textContent = parameters[i].name; |
| 170 var dataTypeValue = header.createChild("span", "documentation-parame
ter-data-type-value"); | 194 var dataTypeValue = header.createChild("span", "documentation-parame
ter-data-type-value documentation-parameter-margin"); |
| 171 dataTypeValue.textContent = parameters[i].dataType; | 195 dataTypeValue.textContent = parameters[i].dataType; |
| 172 if (parameters[i].optional) { | 196 if (parameters[i].optional) { |
| 173 var optional = header.createChild("span", "documentation-paramet
er-optional"); | 197 var optional = header.createChild("span", "documentation-paramet
er-optional documentation-parameter-margin"); |
| 174 optional.textContent = WebInspector.UIString("Optional"); | 198 optional.textContent = WebInspector.UIString("Optional"); |
| 175 } | 199 } |
| 176 parameter.appendChild(this._renderBlock(parameters[i].description)); | 200 parameter.appendChild(this._renderBlock(parameters[i].description)); |
| 177 } | 201 } |
| 178 }, | 202 }, |
| 179 | 203 |
| 180 /** | 204 /** |
| 181 * @param {?WebInspector.JSArticle.Method} method | 205 * @param {?WebInspector.JSArticle.Method} method |
| 182 */ | 206 */ |
| 183 _createReturnValueSection: function(method) | 207 _createReturnValueSection: function(method) |
| 184 { | 208 { |
| 185 if (!method) | 209 if (!method) |
| 186 return; | 210 return; |
| 187 | |
| 188 var section = this._element.createChild("div", "documentation-section"); | 211 var section = this._element.createChild("div", "documentation-section"); |
| 189 var title = section.createChild("div", "documentation-section-title"); | 212 var title = section.createChild("div", "documentation-section-title"); |
| 190 title.textContent = "Return Value"; | 213 title.textContent = "Return Value"; |
| 191 var returnValueName = section.createChild("div", "documentation-return-v
alue"); | 214 var returnValueName = section.createChild("div", "documentation-section-
content documentation-return-value"); |
| 192 returnValueName.textContent = WebInspector.UIString("Returns an object o
f type " + method.returnValueName + "."); | 215 returnValueName.textContent = WebInspector.UIString("Returns an object o
f type " + method.returnValueName + "."); |
| 193 var returnValueDescription = section.createChild("div", "documentation-r
eturn-value"); | 216 var returnValueDescription = section.createChild("div", "documentation-s
ection-content documentation-text"); |
| 194 returnValueDescription.textContent = WebInspector.UIString(method.return
ValueDescription); | 217 returnValueDescription.textContent = WebInspector.UIString(method.return
ValueDescription); |
| 195 }, | 218 }, |
| 196 | 219 |
| 197 /** | 220 /** |
| 198 * @param {!Array.<!WebInspector.JSArticle.Example>} examples | 221 * @param {!Array.<!WebInspector.JSArticle.Example>} examples |
| 199 */ | 222 */ |
| 200 _createExamplesSection: function(examples) | 223 _createExamplesSection: function(examples) |
| 201 { | 224 { |
| 202 if (!examples.length) | 225 if (!examples.length) |
| 203 return; | 226 return; |
| 204 | 227 |
| 205 var section = this._element.createChild("div", "documentation-section"); | 228 var section = this._element.createChild("div", "documentation-section"); |
| 206 var title = section.createChild("div", "documentation-section-title"); | 229 var title = section.createChild("div", "documentation-section-title"); |
| 207 title.textContent = "Examples"; | 230 title.textContent = "Examples"; |
| 208 | 231 |
| 209 for (var i = 0; i < examples.length; ++i) { | 232 for (var i = 0; i < examples.length; ++i) { |
| 210 var example = section.createChild("div", "documentation-example"); | 233 var example = section.createChild("div", "documentation-example docu
mentation-section-content"); |
| 211 var exampleDescription = example.createChild("div", "documentation-e
xample-description-section"); | 234 var exampleDescription = example.createChild("div", "documentation-e
xample-description-section"); |
| 212 if (examples[i].liveUrl) { | 235 if (examples[i].liveUrl) { |
| 213 var liveUrl = exampleDescription.createChild("a", "documentation
-example-link"); | 236 var liveUrl = exampleDescription.createChild("a", "documentation
-example-link"); |
| 214 liveUrl.href = examples[i].liveUrl; | 237 liveUrl.href = examples[i].liveUrl; |
| 215 liveUrl.textContent = WebInspector.UIString("Example"); | 238 liveUrl.textContent = WebInspector.UIString("Example"); |
| 216 } | 239 } |
| 217 exampleDescription.appendChild(this._renderBlock(examples[i].descrip
tion)); | 240 var description = this._renderBlock(examples[i].description); |
| 218 var code = example.createChild("div", "documentation-example-code"); | 241 description.classList.add("documentation-text"); |
| 219 code.classList.add("source-code"); | 242 exampleDescription.appendChild(description); |
| 243 var code = example.createChild("div", "documentation-example-code so
urce-code"); |
| 220 code.textContent = examples[i].code; | 244 code.textContent = examples[i].code; |
| 221 if (!examples[i].language) | 245 if (!examples[i].language) |
| 222 continue; | 246 continue; |
| 223 var syntaxHighlighter = new WebInspector.DOMSyntaxHighlighter(WebIns
pector.DocumentationView._languageToMimeType[examples[i].language.toLowerCase()]
, true); | 247 var syntaxHighlighter = new WebInspector.DOMSyntaxHighlighter(WebIns
pector.DocumentationView._languageToMimeType[examples[i].language.toLowerCase()]
, true); |
| 224 syntaxHighlighter.syntaxHighlightNode(code); | 248 syntaxHighlighter.syntaxHighlightNode(code); |
| 225 } | 249 } |
| 226 }, | 250 }, |
| 227 | 251 |
| 228 /** | 252 /** |
| 229 * @param {!WebInspector.WikiParser.ArticleElement} article | 253 * @param {!WebInspector.WikiParser.ArticleElement} article |
| (...skipping 11 matching lines...) Expand all Loading... |
| 241 case elementTypes.Link: | 265 case elementTypes.Link: |
| 242 element = document.createElementWithClass("a", "documentation-link")
; | 266 element = document.createElementWithClass("a", "documentation-link")
; |
| 243 element.href = article.url(); | 267 element.href = article.url(); |
| 244 if (!article.children().length) | 268 if (!article.children().length) |
| 245 element.textContent = article.url(); | 269 element.textContent = article.url(); |
| 246 break; | 270 break; |
| 247 case elementTypes.Code: | 271 case elementTypes.Code: |
| 248 element = document.createElementWithClass("span", "documentation-cod
e-tag"); | 272 element = document.createElementWithClass("span", "documentation-cod
e-tag"); |
| 249 break; | 273 break; |
| 250 case elementTypes.CodeBlock: | 274 case elementTypes.CodeBlock: |
| 251 element = document.createElementWithClass("pre", "documentation-code
"); | 275 element = document.createElementWithClass("pre", "documentation-code
source-code"); |
| 252 element.classList.add("source-code"); | |
| 253 element.textContent = article.code(); | 276 element.textContent = article.code(); |
| 254 break; | 277 break; |
| 255 case elementTypes.PlainText: | 278 case elementTypes.PlainText: |
| 256 element = document.createElement("span"); | 279 element = document.createElement("span"); |
| 257 element.textContent = article.text(); | 280 element.textContent = article.text(); |
| 258 if (article.isHighlighted()) | 281 if (article.isHighlighted()) |
| 259 element.classList.add("documentation-highlighted-text"); | 282 element.classList.add("documentation-highlighted-text"); |
| 260 break; | 283 break; |
| 261 default: | 284 default: |
| 262 console.error("Unknown ArticleElement type " + article.type()); | 285 console.error("Unknown ArticleElement type " + article.type()); |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 294 appendApplicableItems: function(event, contextMenu, target) | 317 appendApplicableItems: function(event, contextMenu, target) |
| 295 { | 318 { |
| 296 if (!(target instanceof WebInspector.CodeMirrorTextEditor)) | 319 if (!(target instanceof WebInspector.CodeMirrorTextEditor)) |
| 297 return; | 320 return; |
| 298 var textEditor = /** @type {!WebInspector.CodeMirrorTextEditor} */ (targ
et); | 321 var textEditor = /** @type {!WebInspector.CodeMirrorTextEditor} */ (targ
et); |
| 299 var descriptors = this._determineDescriptors(textEditor); | 322 var descriptors = this._determineDescriptors(textEditor); |
| 300 if (!descriptors.length) | 323 if (!descriptors.length) |
| 301 return; | 324 return; |
| 302 if (descriptors.length === 1) { | 325 if (descriptors.length === 1) { |
| 303 var formatString = WebInspector.useLowerCaseMenuTitles() ? "Show doc
umentation for %s.%s" : "Show Documentation for %s.%s"; | 326 var formatString = WebInspector.useLowerCaseMenuTitles() ? "Show doc
umentation for %s.%s" : "Show Documentation for %s.%s"; |
| 304 contextMenu.appendItem(WebInspector.UIString(formatString, descripto
rs[0].name(), descriptors[0].searchItem()), WebInspector.DocumentationView.showD
ocumentationURL.bind(null, descriptors[0].url(), descriptors[0].searchItem())); | 327 var methodName = String.sprintf("%s.%s", descriptors[0].name(), desc
riptors[0].searchItem()); |
| 328 contextMenu.appendItem(WebInspector.UIString(formatString, descripto
rs[0].name(), descriptors[0].searchItem()), WebInspector.DocumentationView.showD
ocumentationURL.bind(null, descriptors[0].url(), methodName)); |
| 305 return; | 329 return; |
| 306 } | 330 } |
| 307 var subMenuItem = contextMenu.appendSubMenuItem(WebInspector.UIString(We
bInspector.useLowerCaseMenuTitles() ? "Show documentation for..." : "Show Docume
ntation for...")); | 331 var subMenuItem = contextMenu.appendSubMenuItem(WebInspector.UIString(We
bInspector.useLowerCaseMenuTitles() ? "Show documentation for..." : "Show Docume
ntation for...")); |
| 308 for (var i = 0; i < descriptors.length; ++i) | 332 for (var i = 0; i < descriptors.length; ++i) { |
| 309 subMenuItem.appendItem(String.sprintf("%s.%s", descriptors[i].name()
, descriptors[i].searchItem()), WebInspector.DocumentationView.showDocumentation
URL.bind(null, descriptors[i].url(), descriptors[i].searchItem())); | 333 var methodName = String.sprintf("%s.%s", descriptors[i].name(), desc
riptors[i].searchItem()); |
| 334 subMenuItem.appendItem(methodName, WebInspector.DocumentationView.sh
owDocumentationURL.bind(null, descriptors[i].url(), methodName)); |
| 335 } |
| 310 }, | 336 }, |
| 311 | 337 |
| 312 /** | 338 /** |
| 313 * @param {!WebInspector.CodeMirrorTextEditor} textEditor | 339 * @param {!WebInspector.CodeMirrorTextEditor} textEditor |
| 314 * @return {!Array.<!WebInspector.DocumentationURLProvider.ItemDescriptor>} | 340 * @return {!Array.<!WebInspector.DocumentationURLProvider.ItemDescriptor>} |
| 315 */ | 341 */ |
| 316 _determineDescriptors: function(textEditor) | 342 _determineDescriptors: function(textEditor) |
| 317 { | 343 { |
| 318 var urlProvider = WebInspector.DocumentationURLProvider.instance(); | 344 var urlProvider = WebInspector.DocumentationURLProvider.instance(); |
| 319 var textSelection = textEditor.selection().normalize(); | 345 var textSelection = textEditor.selection().normalize(); |
| (...skipping 17 matching lines...) Expand all Loading... |
| 337 function computeDescriptors(column) | 363 function computeDescriptors(column) |
| 338 { | 364 { |
| 339 var token = textEditor.tokenAtTextPosition(textSelection.startLine,
column); | 365 var token = textEditor.tokenAtTextPosition(textSelection.startLine,
column); |
| 340 if (!token) | 366 if (!token) |
| 341 return []; | 367 return []; |
| 342 var tokenText = textEditor.line(textSelection.startLine).substring(t
oken.startColumn, token.endColumn); | 368 var tokenText = textEditor.line(textSelection.startLine).substring(t
oken.startColumn, token.endColumn); |
| 343 return urlProvider.itemDescriptors(tokenText); | 369 return urlProvider.itemDescriptors(tokenText); |
| 344 } | 370 } |
| 345 } | 371 } |
| 346 } | 372 } |
| OLD | NEW |