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 { |
11 WebInspector.View.call(this); | 11 WebInspector.View.call(this); |
12 this.element.classList.add("documentation-view"); | 12 this.element.classList.add("documentation-view"); |
13 this.registerRequiredCSS("documentationView.css"); | 13 this.registerRequiredCSS("documentationView.css"); |
14 } | 14 } |
15 | 15 |
16 /** | 16 /** |
17 * @param {string} url | 17 * @param {string} url |
18 * @param {string} searchItem | 18 * @param {string} searchItem |
19 */ | 19 */ |
20 WebInspector.DocumentationView.showDocumentationURL = function(url, searchItem) | 20 WebInspector.DocumentationView.showDocumentationURL = function(url, searchItem) |
21 { | 21 { |
22 if (!WebInspector.DocumentationView._view) | 22 if (!WebInspector.DocumentationView._view) |
23 WebInspector.DocumentationView._view = new WebInspector.DocumentationVie w(); | 23 WebInspector.DocumentationView._view = new WebInspector.DocumentationVie w(); |
24 var view = WebInspector.DocumentationView._view; | 24 var view = WebInspector.DocumentationView._view; |
25 view.element.removeChildren(); | |
25 WebInspector.inspectorView.showCloseableViewInDrawer("documentation", WebIns pector.UIString("Documentation"), view); | 26 WebInspector.inspectorView.showCloseableViewInDrawer("documentation", WebIns pector.UIString("Documentation"), view); |
26 view.showDocumentation(url, searchItem); | 27 view.showDocumentation(url, searchItem); |
27 } | 28 } |
28 | 29 |
29 WebInspector.DocumentationView.prototype = { | 30 WebInspector.DocumentationView.prototype = { |
30 /** | 31 /** |
31 * @param {string} url | 32 * @param {string} url |
32 * @param {string} searchItem | 33 * @param {string} searchItem |
33 */ | 34 */ |
34 showDocumentation: function(url, searchItem) | 35 showDocumentation: function(url, searchItem) |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
92 WebInspector.DocumentationView.Renderer.prototype = { | 93 WebInspector.DocumentationView.Renderer.prototype = { |
93 /** | 94 /** |
94 * @return {!Element} | 95 * @return {!Element} |
95 */ | 96 */ |
96 renderJSArticle: function() | 97 renderJSArticle: function() |
97 { | 98 { |
98 this._createPageTitle(this._article.pageTitle, this._searchItem); | 99 this._createPageTitle(this._article.pageTitle, this._searchItem); |
99 this._createStandardizationStatus(this._article.standardizationStatus); | 100 this._createStandardizationStatus(this._article.standardizationStatus); |
100 this._createTextSectionWithTitle("Summary", this._article.summary); | 101 this._createTextSectionWithTitle("Summary", this._article.summary); |
101 this._createSignatureSection(this._article.parameters, this._article.met hods); | 102 this._createSignatureSection(this._article.parameters, this._article.met hods); |
103 this._createParametresSection(this._article.parameters); | |
apavlov
2014/09/05 11:32:14
Parameters
semeny
2014/09/05 13:30:20
Done.
| |
102 this._createReturnValueSection(this._article.methods); | 104 this._createReturnValueSection(this._article.methods); |
103 this._createExamplesSection(this._article.examples); | 105 this._createExamplesSection(this._article.examples); |
104 this._createTextSectionWithTitle("Remarks", this._article.remarks); | 106 this._createTextSectionWithTitle("Remarks", this._article.remarks); |
105 | 107 |
106 return this._element; | 108 return this._element; |
107 }, | 109 }, |
108 | 110 |
109 /** | 111 /** |
110 * @param {string} titleText | 112 * @param {string} titleText |
111 * @param {string} searchItem | 113 * @param {string} searchItem |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
145 text.classList.add("documentation-text"); | 147 text.classList.add("documentation-text"); |
146 section.appendChild(text); | 148 section.appendChild(text); |
147 }, | 149 }, |
148 | 150 |
149 /** | 151 /** |
150 * @param {!Array.<!WebInspector.JSArticle.Parameter>} parameters | 152 * @param {!Array.<!WebInspector.JSArticle.Parameter>} parameters |
151 * @param {?WebInspector.JSArticle.Method} method | 153 * @param {?WebInspector.JSArticle.Method} method |
152 */ | 154 */ |
153 _createSignatureSection: function(parameters, method) | 155 _createSignatureSection: function(parameters, method) |
154 { | 156 { |
157 if (!method) | |
158 return; | |
159 var section = this._element.createChild("div", "documentation-section"); | |
160 var title = section.createChild("div", "documentation-section-title"); | |
161 title.textContent = "Signature"; | |
162 var signature = section.createChild("p", "documentation-method-signature "); | |
163 var methodName = signature.createChild("span", "documentation-method-nam e"); | |
164 methodName.textContent = this._searchItem.split(".").pop() + "("; | |
apavlov
2014/09/05 11:32:14
pop() > peekLast() to avoid extraneous temporary a
semeny
2014/09/05 13:30:19
Done.
| |
165 for (var i = 0; i < parameters.length; ++i) { | |
166 if (i > 0) { | |
167 var separator = signature.createChild("span"); | |
apavlov
2014/09/05 11:32:14
Inline
semeny
2014/09/05 13:30:20
Done.
| |
168 separator.textContent = ", "; | |
169 } | |
170 var parameterType = signature.createChild("span", "documentation-par ameter-data-type-value"); | |
171 var optional = ""; | |
172 if (parameters[i].optional) { | |
173 parameterType.className = "documentation-parameter-optional"; | |
174 optional = "="; | |
175 } | |
176 parameterType.textContent = optional + parameters[i].dataType; | |
177 } | |
178 var separator = signature.createChild("span"); | |
apavlov
2014/09/05 11:32:14
Inline
semeny
2014/09/05 13:30:19
Done.
| |
179 separator.textContent = ") : "; | |
180 var returnTypeElement = signature.createChild("span", "documentation-ret urn-type"); | |
181 returnTypeElement.textContent = method.returnValueName; | |
182 }, | |
183 | |
184 /** | |
185 * @param {!Array.<!WebInspector.JSArticle.Parameter>} parameters | |
186 */ | |
187 _createParametresSection: function(parameters) | |
188 { | |
155 if (!parameters.length) | 189 if (!parameters.length) |
156 return; | 190 return; |
157 var section = this._element.createChild("div", "documentation-section"); | 191 var section = this._element.createChild("div", "documentation-section"); |
158 var title = section.createChild("div", "documentation-section-title"); | 192 var title = section.createChild("div", "documentation-section-title"); |
159 title.textContent = "Parameters"; | 193 title.textContent = "Parameters"; |
160 for (var i = 0; i < parameters.length; ++i) { | 194 for (var i = 0; i < parameters.length; ++i) { |
161 var parameter = section.createChild("div", "documentation-parameter" ); | 195 var parameter = section.createChild("div", "documentation-parameter" ); |
162 var header = parameter.createChild("div", "documentation-parameter-h eader"); | 196 var header = parameter.createChild("div", "documentation-parameter-h eader"); |
163 var name = header.createChild("span", "documentation-parameter-name" ); | 197 var name = header.createChild("span", "documentation-parameter-name" ); |
164 name.textContent = parameters[i].name; | 198 name.textContent = parameters[i].name; |
165 var dataTypeValue = header.createChild("span", "documentation-parame ter-data-type-value"); | 199 var dataTypeValue = header.createChild("span", "documentation-parame ter-data-type-value"); |
200 dataTypeValue.classList.add("documentation-parameter-margin"); | |
166 dataTypeValue.textContent = parameters[i].dataType; | 201 dataTypeValue.textContent = parameters[i].dataType; |
167 if (parameters[i].optional) { | 202 if (parameters[i].optional) { |
168 var optional = header.createChild("span", "documentation-paramet er-optional"); | 203 var optional = header.createChild("span", "documentation-paramet er-optional"); |
204 optional.classList.add("documentation-parameter-margin"); | |
169 optional.textContent = WebInspector.UIString("Optional"); | 205 optional.textContent = WebInspector.UIString("Optional"); |
170 } | 206 } |
171 parameter.appendChild(this._renderBlock(parameters[i].description)); | 207 parameter.appendChild(this._renderBlock(parameters[i].description)); |
172 } | 208 } |
209 | |
173 }, | 210 }, |
174 | 211 |
175 /** | 212 /** |
176 * @param {?WebInspector.JSArticle.Method} method | 213 * @param {?WebInspector.JSArticle.Method} method |
177 */ | 214 */ |
178 _createReturnValueSection: function(method) | 215 _createReturnValueSection: function(method) |
179 { | 216 { |
180 if (!method) | 217 if (!method) |
181 return; | 218 return; |
182 | 219 |
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
285 appendApplicableItems: function(event, contextMenu, target) | 322 appendApplicableItems: function(event, contextMenu, target) |
286 { | 323 { |
287 if (!(target instanceof WebInspector.CodeMirrorTextEditor)) | 324 if (!(target instanceof WebInspector.CodeMirrorTextEditor)) |
288 return; | 325 return; |
289 var textEditor = /** @type {!WebInspector.CodeMirrorTextEditor} */ (targ et); | 326 var textEditor = /** @type {!WebInspector.CodeMirrorTextEditor} */ (targ et); |
290 var descriptors = this._determineDescriptors(textEditor); | 327 var descriptors = this._determineDescriptors(textEditor); |
291 if (!descriptors.length) | 328 if (!descriptors.length) |
292 return; | 329 return; |
293 if (descriptors.length === 1) { | 330 if (descriptors.length === 1) { |
294 var formatString = WebInspector.useLowerCaseMenuTitles() ? "Show doc umentation for %s.%s" : "Show Documentation for %s.%s"; | 331 var formatString = WebInspector.useLowerCaseMenuTitles() ? "Show doc umentation for %s.%s" : "Show Documentation for %s.%s"; |
295 contextMenu.appendItem(WebInspector.UIString(formatString, descripto rs[0].name(), descriptors[0].searchItem()), WebInspector.DocumentationView.showD ocumentationURL.bind(null, descriptors[0].url(), descriptors[0].searchItem())); | 332 var methodName = String.sprintf("%s.%s", descriptors[0].name(), desc riptors[0].searchItem()); |
333 contextMenu.appendItem(WebInspector.UIString(formatString, descripto rs[0].name(), descriptors[0].searchItem()), WebInspector.DocumentationView.showD ocumentationURL.bind(null, descriptors[0].url(), methodName)); | |
296 return; | 334 return; |
297 } | 335 } |
298 var subMenuItem = contextMenu.appendSubMenuItem(WebInspector.UIString(We bInspector.useLowerCaseMenuTitles() ? "Show documentation for..." : "Show Docume ntation for...")); | 336 var subMenuItem = contextMenu.appendSubMenuItem(WebInspector.UIString(We bInspector.useLowerCaseMenuTitles() ? "Show documentation for..." : "Show Docume ntation for...")); |
299 for (var i = 0; i < descriptors.length; ++i) | 337 for (var i = 0; i < descriptors.length; ++i) { |
300 subMenuItem.appendItem(String.sprintf("%s.%s", descriptors[i].name() , descriptors[i].searchItem()), WebInspector.DocumentationView.showDocumentation URL.bind(null, descriptors[i].url(), descriptors[i].searchItem())); | 338 var methodName = String.sprintf("%s.%s", descriptors[i].name(), desc riptors[i].searchItem()); |
339 subMenuItem.appendItem(methodName, WebInspector.DocumentationView.sh owDocumentationURL.bind(null, descriptors[i].url(), methodName)); | |
340 } | |
301 }, | 341 }, |
302 | 342 |
303 /** | 343 /** |
304 * @param {!WebInspector.CodeMirrorTextEditor} textEditor | 344 * @param {!WebInspector.CodeMirrorTextEditor} textEditor |
305 * @return {!Array.<!WebInspector.DocumentationURLProvider.ItemDescriptor>} | 345 * @return {!Array.<!WebInspector.DocumentationURLProvider.ItemDescriptor>} |
306 */ | 346 */ |
307 _determineDescriptors: function(textEditor) | 347 _determineDescriptors: function(textEditor) |
308 { | 348 { |
309 var urlProvider = WebInspector.DocumentationURLProvider.instance(); | 349 var urlProvider = WebInspector.DocumentationURLProvider.instance(); |
310 var textSelection = textEditor.selection().normalize(); | 350 var textSelection = textEditor.selection().normalize(); |
(...skipping 17 matching lines...) Expand all Loading... | |
328 function computeDescriptors(column) | 368 function computeDescriptors(column) |
329 { | 369 { |
330 var token = textEditor.tokenAtTextPosition(textSelection.startLine, column); | 370 var token = textEditor.tokenAtTextPosition(textSelection.startLine, column); |
331 if (!token) | 371 if (!token) |
332 return []; | 372 return []; |
333 var tokenText = textEditor.line(textSelection.startLine).substring(t oken.startColumn, token.endColumn); | 373 var tokenText = textEditor.line(textSelection.startLine).substring(t oken.startColumn, token.endColumn); |
334 return urlProvider.itemDescriptors(tokenText); | 374 return urlProvider.itemDescriptors(tokenText); |
335 } | 375 } |
336 } | 376 } |
337 } | 377 } |
OLD | NEW |