| 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 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 91 } | 91 } |
| 92 | 92 |
| 93 /** | 93 /** |
| 94 * @constructor | 94 * @constructor |
| 95 * @param {!WebInspector.JSArticle} article | 95 * @param {!WebInspector.JSArticle} article |
| 96 * @param {string} searchItem | 96 * @param {string} searchItem |
| 97 */ | 97 */ |
| 98 WebInspector.DocumentationView.Renderer = function(article, searchItem) | 98 WebInspector.DocumentationView.Renderer = function(article, searchItem) |
| 99 { | 99 { |
| 100 this._searchItem = searchItem; | 100 this._searchItem = searchItem; |
| 101 this._element = document.createElement("div"); | 101 this._element = createElement("div"); |
| 102 this._article = article; | 102 this._article = article; |
| 103 } | 103 } |
| 104 | 104 |
| 105 WebInspector.DocumentationView.Renderer.prototype = { | 105 WebInspector.DocumentationView.Renderer.prototype = { |
| 106 /** | 106 /** |
| 107 * @return {!Element} | 107 * @return {!Element} |
| 108 */ | 108 */ |
| 109 renderJSArticle: function() | 109 renderJSArticle: function() |
| 110 { | 110 { |
| 111 this._element.appendChild(this._createPageTitle(this._article.pageTitle,
this._searchItem)); | 111 this._element.appendChild(this._createPageTitle(this._article.pageTitle,
this._searchItem)); |
| (...skipping 27 matching lines...) Expand all Loading... |
| 139 return this._element; | 139 return this._element; |
| 140 }, | 140 }, |
| 141 | 141 |
| 142 /** | 142 /** |
| 143 * @param {string} titleText | 143 * @param {string} titleText |
| 144 * @param {string} searchItem | 144 * @param {string} searchItem |
| 145 * @return {!Element} | 145 * @return {!Element} |
| 146 */ | 146 */ |
| 147 _createPageTitle: function(titleText, searchItem) | 147 _createPageTitle: function(titleText, searchItem) |
| 148 { | 148 { |
| 149 var pageTitle = document.createElementWithClass("div", "documentation-pa
ge-title"); | 149 var pageTitle = createElementWithClass("div", "documentation-page-title"
); |
| 150 if (titleText) | 150 if (titleText) |
| 151 pageTitle.textContent = titleText; | 151 pageTitle.textContent = titleText; |
| 152 else if (searchItem) | 152 else if (searchItem) |
| 153 pageTitle.textContent = searchItem; | 153 pageTitle.textContent = searchItem; |
| 154 return pageTitle; | 154 return pageTitle; |
| 155 }, | 155 }, |
| 156 | 156 |
| 157 /** | 157 /** |
| 158 * @param {!Array.<!WebInspector.JSArticle.Parameter>} parameters | 158 * @param {!Array.<!WebInspector.JSArticle.Parameter>} parameters |
| 159 * @param {?WebInspector.JSArticle.Method} method | 159 * @param {?WebInspector.JSArticle.Method} method |
| 160 * @return {?Element} | 160 * @return {?Element} |
| 161 */ | 161 */ |
| 162 _createSignatureSection: function(parameters, method) | 162 _createSignatureSection: function(parameters, method) |
| 163 { | 163 { |
| 164 if (!parameters.length && !method) | 164 if (!parameters.length && !method) |
| 165 return null; | 165 return null; |
| 166 var signature = document.createElementWithClass("div", "documentation-me
thod-signature monospace"); | 166 var signature = createElementWithClass("div", "documentation-method-sign
ature monospace"); |
| 167 if (method && method.returnValueName) { | 167 if (method && method.returnValueName) { |
| 168 var returnTypeElement = signature.createChild("span", "documentation
-parameter-data-type-value"); | 168 var returnTypeElement = signature.createChild("span", "documentation
-parameter-data-type-value"); |
| 169 returnTypeElement.textContent = method.returnValueName; | 169 returnTypeElement.textContent = method.returnValueName; |
| 170 } | 170 } |
| 171 var methodName = signature.createChild("span", "documentation-method-nam
e"); | 171 var methodName = signature.createChild("span", "documentation-method-nam
e"); |
| 172 methodName.textContent = this._searchItem.split(".").peekLast() + "("; | 172 methodName.textContent = this._searchItem.split(".").peekLast() + "("; |
| 173 for (var i = 0; i < parameters.length; ++i) { | 173 for (var i = 0; i < parameters.length; ++i) { |
| 174 if (i > 0) | 174 if (i > 0) |
| 175 signature.createTextChild(",") | 175 signature.createTextChild(",") |
| 176 var parameterType = signature.createChild("span", "documentation-par
ameter-data-type-value"); | 176 var parameterType = signature.createChild("span", "documentation-par
ameter-data-type-value"); |
| 177 parameterType.textContent = parameters[i].dataType; | 177 parameterType.textContent = parameters[i].dataType; |
| 178 var parameterName = signature.createChild("span", "documentation-par
ameter-name"); | 178 var parameterName = signature.createChild("span", "documentation-par
ameter-name"); |
| 179 parameterName.textContent = parameters[i].name; | 179 parameterName.textContent = parameters[i].name; |
| 180 } | 180 } |
| 181 | 181 |
| 182 signature.createTextChild(")"); | 182 signature.createTextChild(")"); |
| 183 return signature; | 183 return signature; |
| 184 }, | 184 }, |
| 185 | 185 |
| 186 /** | 186 /** |
| 187 * @param {!Array.<!WebInspector.JSArticle.Parameter>} parameters | 187 * @param {!Array.<!WebInspector.JSArticle.Parameter>} parameters |
| 188 * @return {?Element} | 188 * @return {?Element} |
| 189 */ | 189 */ |
| 190 _createParametersSection: function(parameters) | 190 _createParametersSection: function(parameters) |
| 191 { | 191 { |
| 192 if (!parameters.length) | 192 if (!parameters.length) |
| 193 return null; | 193 return null; |
| 194 var table = document.createElementWithClass("table", "documentation-tabl
e"); | 194 var table = createElementWithClass("table", "documentation-table"); |
| 195 var tableBody = table.createChild("tbody"); | 195 var tableBody = table.createChild("tbody"); |
| 196 var headerRow = tableBody.createChild("tr", "documentation-table-row"); | 196 var headerRow = tableBody.createChild("tr", "documentation-table-row"); |
| 197 var tableHeader = headerRow.createChild("th", "documentation-table-heade
r"); | 197 var tableHeader = headerRow.createChild("th", "documentation-table-heade
r"); |
| 198 tableHeader.textContent = WebInspector.UIString("Parameters"); | 198 tableHeader.textContent = WebInspector.UIString("Parameters"); |
| 199 tableHeader.colSpan = 3; | 199 tableHeader.colSpan = 3; |
| 200 for (var i = 0; i < parameters.length; ++i) { | 200 for (var i = 0; i < parameters.length; ++i) { |
| 201 var tableRow = tableBody.createChild("tr", "documentation-table-row"
); | 201 var tableRow = tableBody.createChild("tr", "documentation-table-row"
); |
| 202 var type = tableRow.createChild("td", "documentation-table-cell"); | 202 var type = tableRow.createChild("td", "documentation-table-cell"); |
| 203 type.textContent = parameters[i].dataType; | 203 type.textContent = parameters[i].dataType; |
| 204 var name = tableRow.createChild("td", "documentation-table-cell"); | 204 var name = tableRow.createChild("td", "documentation-table-cell"); |
| 205 name.textContent = parameters[i].optional ? WebInspector.UIString("(
optional)\n") : ""; | 205 name.textContent = parameters[i].optional ? WebInspector.UIString("(
optional)\n") : ""; |
| 206 name.textContent += parameters[i].name; | 206 name.textContent += parameters[i].name; |
| 207 var description = tableRow.createChild("td", "documentation-table-ce
ll"); | 207 var description = tableRow.createChild("td", "documentation-table-ce
ll"); |
| 208 if (parameters[i].description) | 208 if (parameters[i].description) |
| 209 description.appendChild(this._renderBlock(/** @type {!WebInspect
or.WikiParser.Block} */(parameters[i].description))); | 209 description.appendChild(this._renderBlock(/** @type {!WebInspect
or.WikiParser.Block} */(parameters[i].description))); |
| 210 } | 210 } |
| 211 return table; | 211 return table; |
| 212 }, | 212 }, |
| 213 | 213 |
| 214 /** | 214 /** |
| 215 * @param {!Array.<!WebInspector.JSArticle.Example>} examples | 215 * @param {!Array.<!WebInspector.JSArticle.Example>} examples |
| 216 */ | 216 */ |
| 217 _createExamplesSection: function(examples) | 217 _createExamplesSection: function(examples) |
| 218 { | 218 { |
| 219 if (!examples.length) | 219 if (!examples.length) |
| 220 return; | 220 return; |
| 221 | 221 |
| 222 var section = document.createElementWithClass("div", "documentation-sect
ion"); | 222 var section = createElementWithClass("div", "documentation-section"); |
| 223 | 223 |
| 224 for (var i = 0; i < examples.length; ++i) { | 224 for (var i = 0; i < examples.length; ++i) { |
| 225 var example = section.createChild("div", "documentation-example"); | 225 var example = section.createChild("div", "documentation-example"); |
| 226 var exampleDescription = example.createChild("div", "documentation-e
xample-description-section"); | 226 var exampleDescription = example.createChild("div", "documentation-e
xample-description-section"); |
| 227 if (examples[i].description) { | 227 if (examples[i].description) { |
| 228 var description = this._renderBlock(/** @type {!WebInspector.Wik
iParser.Block} */(examples[i].description)); | 228 var description = this._renderBlock(/** @type {!WebInspector.Wik
iParser.Block} */(examples[i].description)); |
| 229 description.classList.add("documentation-text"); | 229 description.classList.add("documentation-text"); |
| 230 exampleDescription.appendChild(description); | 230 exampleDescription.appendChild(description); |
| 231 } | 231 } |
| 232 var code = example.createChild("div", "documentation-code source-cod
e"); | 232 var code = example.createChild("div", "documentation-code source-cod
e"); |
| (...skipping 10 matching lines...) Expand all Loading... |
| 243 * @param {!WebInspector.WikiParser.ArticleElement} article | 243 * @param {!WebInspector.WikiParser.ArticleElement} article |
| 244 * @return {!Element} | 244 * @return {!Element} |
| 245 */ | 245 */ |
| 246 _renderBlock: function(article) | 246 _renderBlock: function(article) |
| 247 { | 247 { |
| 248 var element; | 248 var element; |
| 249 var elementTypes = WebInspector.WikiParser.ArticleElement.Type; | 249 var elementTypes = WebInspector.WikiParser.ArticleElement.Type; |
| 250 | 250 |
| 251 switch (article.type()) { | 251 switch (article.type()) { |
| 252 case elementTypes.Inline: | 252 case elementTypes.Inline: |
| 253 element = document.createElement("span"); | 253 element = createElement("span"); |
| 254 break; | 254 break; |
| 255 case elementTypes.Link: | 255 case elementTypes.Link: |
| 256 element = document.createElementWithClass("a", "documentation-link")
; | 256 element = createElementWithClass("a", "documentation-link"); |
| 257 element.href = article.url(); | 257 element.href = article.url(); |
| 258 if (!article.children().length) | 258 if (!article.children().length) |
| 259 element.textContent = article.url(); | 259 element.textContent = article.url(); |
| 260 break; | 260 break; |
| 261 case elementTypes.Code: | 261 case elementTypes.Code: |
| 262 element = document.createElementWithClass("span", "documentation-cod
e-tag"); | 262 element = createElementWithClass("span", "documentation-code-tag"); |
| 263 break; | 263 break; |
| 264 case elementTypes.CodeBlock: | 264 case elementTypes.CodeBlock: |
| 265 element = document.createElementWithClass("pre", "documentation-code
source-code"); | 265 element = createElementWithClass("pre", "documentation-code source-c
ode"); |
| 266 element.textContent = article.code(); | 266 element.textContent = article.code(); |
| 267 break; | 267 break; |
| 268 case elementTypes.PlainText: | 268 case elementTypes.PlainText: |
| 269 element = document.createElement("span"); | 269 element = createElement("span"); |
| 270 element.textContent = article.text(); | 270 element.textContent = article.text(); |
| 271 if (article.isHighlighted()) | 271 if (article.isHighlighted()) |
| 272 element.classList.add("documentation-highlighted-text"); | 272 element.classList.add("documentation-highlighted-text"); |
| 273 break; | 273 break; |
| 274 case elementTypes.Block: | 274 case elementTypes.Block: |
| 275 element = document.createElement(article.hasBullet() ? "li" : "div")
; | 275 element = createElement(article.hasBullet() ? "li" : "div"); |
| 276 if (!article.hasBullet()) | 276 if (!article.hasBullet()) |
| 277 element.classList.add("documentation-paragraph"); | 277 element.classList.add("documentation-paragraph"); |
| 278 break; | 278 break; |
| 279 case elementTypes.Table: | 279 case elementTypes.Table: |
| 280 return this._renderTable(/** @type {!WebInspector.WikiParser.Table}
*/(article)); | 280 return this._renderTable(/** @type {!WebInspector.WikiParser.Table}
*/(article)); |
| 281 default: | 281 default: |
| 282 throw new Error("Unknown ArticleElement type " + article.type()); | 282 throw new Error("Unknown ArticleElement type " + article.type()); |
| 283 } | 283 } |
| 284 | 284 |
| 285 if (article.type() === WebInspector.WikiParser.ArticleElement.Type.Block | 285 if (article.type() === WebInspector.WikiParser.ArticleElement.Type.Block |
| 286 || article.type() === WebInspector.WikiParser.ArticleElement.Type.Co
de | 286 || article.type() === WebInspector.WikiParser.ArticleElement.Type.Co
de |
| 287 || article.type() === WebInspector.WikiParser.ArticleElement.Type.In
line) { | 287 || article.type() === WebInspector.WikiParser.ArticleElement.Type.In
line) { |
| 288 for (var i = 0; i < article.children().length; ++i) { | 288 for (var i = 0; i < article.children().length; ++i) { |
| 289 var child = this._renderBlock(article.children()[i]); | 289 var child = this._renderBlock(article.children()[i]); |
| 290 if (child) | 290 if (child) |
| 291 element.appendChild(child); | 291 element.appendChild(child); |
| 292 } | 292 } |
| 293 } | 293 } |
| 294 | 294 |
| 295 return element; | 295 return element; |
| 296 }, | 296 }, |
| 297 | 297 |
| 298 /** | 298 /** |
| 299 * @param {!WebInspector.WikiParser.Table} table | 299 * @param {!WebInspector.WikiParser.Table} table |
| 300 * @return {!Element} | 300 * @return {!Element} |
| 301 */ | 301 */ |
| 302 _renderTable: function(table) | 302 _renderTable: function(table) |
| 303 { | 303 { |
| 304 var tableElement = document.createElementWithClass("table", "documentati
on-table"); | 304 var tableElement = createElementWithClass("table", "documentation-table"
); |
| 305 var tableBody = tableElement.createChild("tbody"); | 305 var tableBody = tableElement.createChild("tbody"); |
| 306 var headerRow = tableBody.createChild("tr", "documentation-table-row"); | 306 var headerRow = tableBody.createChild("tr", "documentation-table-row"); |
| 307 for (var i = 0; i < table.columnNames().length; ++i) { | 307 for (var i = 0; i < table.columnNames().length; ++i) { |
| 308 var tableHeader = headerRow.createChild("th", "documentation-table-h
eader"); | 308 var tableHeader = headerRow.createChild("th", "documentation-table-h
eader"); |
| 309 tableHeader.appendChild(this._renderBlock(table.columnNames()[i])); | 309 tableHeader.appendChild(this._renderBlock(table.columnNames()[i])); |
| 310 } | 310 } |
| 311 for (var i = 0; i < table.rows().length; ++i) { | 311 for (var i = 0; i < table.rows().length; ++i) { |
| 312 var tableRow = tableBody.createChild("tr", "documentation-table-row"
); | 312 var tableRow = tableBody.createChild("tr", "documentation-table-row"
); |
| 313 var row = table.rows()[i]; | 313 var row = table.rows()[i]; |
| 314 for (var j = 0; j < row.length; ++j) { | 314 for (var j = 0; j < row.length; ++j) { |
| (...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 420 function findPreviousToken(textRange) | 420 function findPreviousToken(textRange) |
| 421 { | 421 { |
| 422 var line = textEditor.line(textRange.startLine); | 422 var line = textEditor.line(textRange.startLine); |
| 423 if (textRange.startColumn < 3 || line[textRange.startColumn - 1] !==
".") | 423 if (textRange.startColumn < 3 || line[textRange.startColumn - 1] !==
".") |
| 424 return null; | 424 return null; |
| 425 var token = textEditor.tokenAtTextPosition(textRange.startLine, text
Range.startColumn - 2); | 425 var token = textEditor.tokenAtTextPosition(textRange.startLine, text
Range.startColumn - 2); |
| 426 return token ? line.substring(token.startColumn, token.endColumn) :
null; | 426 return token ? line.substring(token.startColumn, token.endColumn) :
null; |
| 427 } | 427 } |
| 428 } | 428 } |
| 429 } | 429 } |
| OLD | NEW |