Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(308)

Side by Side Diff: Source/devtools/front_end/documentation/DocumentationView.js

Issue 525363003: DevTools: [Documentation] Add signature section for renderer (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@iliia-patch
Patch Set: Rebased on current patch Created 6 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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
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");
171 dataTypeValue.classList.add("documentation-box"); 195 dataTypeValue.classList.add("documentation-box");
172 dataTypeValue.textContent = parameters[i].dataType; 196 dataTypeValue.textContent = parameters[i].dataType;
173 if (parameters[i].optional) { 197 if (parameters[i].optional) {
174 var optional = header.createChild("span", "documentation-paramet er-optional"); 198 var optional = header.createChild("span", "documentation-paramet er-optional");
175 optional.classList.add("documentation-box"); 199 optional.classList.add("documentation-box");
176 optional.textContent = WebInspector.UIString("Optional"); 200 optional.textContent = WebInspector.UIString("Optional");
177 } 201 }
178 parameter.appendChild(this._renderBlock(parameters[i].description)); 202 parameter.appendChild(this._renderBlock(parameters[i].description));
179 } 203 }
180 }, 204 },
181 205
182 /** 206 /**
183 * @param {?WebInspector.JSArticle.Method} method 207 * @param {?WebInspector.JSArticle.Method} method
184 */ 208 */
185 _createReturnValueSection: function(method) 209 _createReturnValueSection: function(method)
186 { 210 {
187 if (!method) 211 if (!method)
188 return; 212 return;
189
190 var section = this._element.createChild("div", "documentation-section"); 213 var section = this._element.createChild("div", "documentation-section");
191 var title = section.createChild("div", "documentation-section-title"); 214 var title = section.createChild("div", "documentation-section-title");
192 title.textContent = "Return Value"; 215 title.textContent = "Return Value";
193 var returnValueName = section.createChild("div", "documentation-return-v alue"); 216 var returnValueName = section.createChild("div", "documentation-section- content documentation-return-value");
194 returnValueName.textContent = WebInspector.UIString("Returns an object o f type " + method.returnValueName + "."); 217 returnValueName.textContent = WebInspector.UIString("Returns an object o f type " + method.returnValueName + ".");
195 var returnValueDescription = section.createChild("div", "documentation-r eturn-value"); 218 var returnValueDescription = section.createChild("div", "documentation-s ection-content documentation-text");
196 returnValueDescription.textContent = WebInspector.UIString(method.return ValueDescription); 219 returnValueDescription.textContent = WebInspector.UIString(method.return ValueDescription);
197 }, 220 },
198 221
199 /** 222 /**
200 * @param {!Array.<!WebInspector.JSArticle.Example>} examples 223 * @param {!Array.<!WebInspector.JSArticle.Example>} examples
201 */ 224 */
202 _createExamplesSection: function(examples) 225 _createExamplesSection: function(examples)
203 { 226 {
204 if (!examples.length) 227 if (!examples.length)
205 return; 228 return;
206 229
207 var section = this._element.createChild("div", "documentation-section"); 230 var section = this._element.createChild("div", "documentation-section");
208 var title = section.createChild("div", "documentation-section-title"); 231 var title = section.createChild("div", "documentation-section-title");
209 title.textContent = "Examples"; 232 title.textContent = "Examples";
210 233
211 for (var i = 0; i < examples.length; ++i) { 234 for (var i = 0; i < examples.length; ++i) {
212 var example = section.createChild("div", "documentation-example"); 235 var example = section.createChild("div", "documentation-example docu mentation-section-content");
213 var exampleDescription = example.createChild("div", "documentation-e xample-description-section"); 236 var exampleDescription = example.createChild("div", "documentation-e xample-description-section");
214 if (examples[i].liveUrl) { 237 if (examples[i].liveUrl) {
215 var liveUrl = exampleDescription.createChild("a", "documentation -example-link"); 238 var liveUrl = exampleDescription.createChild("a", "documentation -example-link");
216 liveUrl.classList.add("documentation-box"); 239 liveUrl.classList.add("documentation-box");
217 liveUrl.href = examples[i].liveUrl; 240 liveUrl.href = examples[i].liveUrl;
218 liveUrl.textContent = WebInspector.UIString("Example"); 241 liveUrl.textContent = WebInspector.UIString("Example");
219 } 242 }
220 if (examples[i].description) 243 if (examples[i].description) {
221 exampleDescription.appendChild(this._renderBlock(examples[i].des cription)); 244 var description = this._renderBlock(examples[i].description);
222 var code = example.createChild("div", "documentation-code"); 245 description.classList.add("documentation-text");
223 code.classList.add("source-code"); 246 exampleDescription.appendChild(description);
247 }
248 var code = example.createChild("div", "documentation-code source-cod e");
224 code.textContent = examples[i].code; 249 code.textContent = examples[i].code;
225 if (!examples[i].language) 250 if (!examples[i].language)
226 continue; 251 continue;
227 var syntaxHighlighter = new WebInspector.DOMSyntaxHighlighter(WebIns pector.DocumentationView._languageToMimeType[examples[i].language.toLowerCase()] , true); 252 var syntaxHighlighter = new WebInspector.DOMSyntaxHighlighter(WebIns pector.DocumentationView._languageToMimeType[examples[i].language.toLowerCase()] , true);
228 syntaxHighlighter.syntaxHighlightNode(code); 253 syntaxHighlighter.syntaxHighlightNode(code);
229 } 254 }
230 }, 255 },
231 256
232 /** 257 /**
233 * @param {!WebInspector.WikiParser.ArticleElement} article 258 * @param {!WebInspector.WikiParser.ArticleElement} article
(...skipping 11 matching lines...) Expand all
245 case elementTypes.Link: 270 case elementTypes.Link:
246 element = document.createElementWithClass("a", "documentation-link") ; 271 element = document.createElementWithClass("a", "documentation-link") ;
247 element.href = article.url(); 272 element.href = article.url();
248 if (!article.children().length) 273 if (!article.children().length)
249 element.textContent = article.url(); 274 element.textContent = article.url();
250 break; 275 break;
251 case elementTypes.Code: 276 case elementTypes.Code:
252 element = document.createElementWithClass("span", "documentation-cod e-tag"); 277 element = document.createElementWithClass("span", "documentation-cod e-tag");
253 break; 278 break;
254 case elementTypes.CodeBlock: 279 case elementTypes.CodeBlock:
255 element = document.createElementWithClass("pre", "documentation-code "); 280 element = document.createElementWithClass("pre", "documentation-code source-code");
256 element.classList.add("source-code");
257 element.textContent = article.code(); 281 element.textContent = article.code();
258 break; 282 break;
259 case elementTypes.PlainText: 283 case elementTypes.PlainText:
260 element = document.createElement("span"); 284 element = document.createElement("span");
261 element.textContent = article.text(); 285 element.textContent = article.text();
262 if (article.isHighlighted()) 286 if (article.isHighlighted())
263 element.classList.add("documentation-highlighted-text"); 287 element.classList.add("documentation-highlighted-text");
264 break; 288 break;
265 default: 289 default:
266 console.error("Unknown ArticleElement type " + article.type()); 290 console.error("Unknown ArticleElement type " + article.type());
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
298 appendApplicableItems: function(event, contextMenu, target) 322 appendApplicableItems: function(event, contextMenu, target)
299 { 323 {
300 if (!(target instanceof WebInspector.CodeMirrorTextEditor)) 324 if (!(target instanceof WebInspector.CodeMirrorTextEditor))
301 return; 325 return;
302 var textEditor = /** @type {!WebInspector.CodeMirrorTextEditor} */ (targ et); 326 var textEditor = /** @type {!WebInspector.CodeMirrorTextEditor} */ (targ et);
303 var descriptors = this._determineDescriptors(textEditor); 327 var descriptors = this._determineDescriptors(textEditor);
304 if (!descriptors.length) 328 if (!descriptors.length)
305 return; 329 return;
306 if (descriptors.length === 1) { 330 if (descriptors.length === 1) {
307 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";
308 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));
309 return; 334 return;
310 } 335 }
311 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..."));
312 for (var i = 0; i < descriptors.length; ++i) 337 for (var i = 0; i < descriptors.length; ++i) {
313 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 }
314 }, 341 },
315 342
316 /** 343 /**
317 * @param {!WebInspector.CodeMirrorTextEditor} textEditor 344 * @param {!WebInspector.CodeMirrorTextEditor} textEditor
318 * @return {!Array.<!WebInspector.DocumentationURLProvider.ItemDescriptor>} 345 * @return {!Array.<!WebInspector.DocumentationURLProvider.ItemDescriptor>}
319 */ 346 */
320 _determineDescriptors: function(textEditor) 347 _determineDescriptors: function(textEditor)
321 { 348 {
322 var urlProvider = WebInspector.DocumentationURLProvider.instance(); 349 var urlProvider = WebInspector.DocumentationURLProvider.instance();
323 var textSelection = textEditor.selection().normalize(); 350 var textSelection = textEditor.selection().normalize();
(...skipping 17 matching lines...) Expand all
341 function computeDescriptors(column) 368 function computeDescriptors(column)
342 { 369 {
343 var token = textEditor.tokenAtTextPosition(textSelection.startLine, column); 370 var token = textEditor.tokenAtTextPosition(textSelection.startLine, column);
344 if (!token) 371 if (!token)
345 return []; 372 return [];
346 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);
347 return urlProvider.itemDescriptors(tokenText); 374 return urlProvider.itemDescriptors(tokenText);
348 } 375 }
349 } 376 }
350 } 377 }
OLDNEW
« no previous file with comments | « Source/devtools/front_end/documentation/DocumentationURLProvider.js ('k') | Source/devtools/front_end/documentationView.css » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698