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

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: Fix rebase problems 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 {
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 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
90 } 91 }
91 92
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);
101 this._createSignatureSection(this._article.parameters, this._article.met hods);
100 this._createTextSectionWithTitle("Summary", this._article.summary); 102 this._createTextSectionWithTitle("Summary", this._article.summary);
101 this._createSignatureSection(this._article.parameters, this._article.met hods); 103 this._createParametersSection(this._article.parameters);
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 24 matching lines...) Expand all
136 */ 138 */
137 _createTextSectionWithTitle: function(titleText, article) 139 _createTextSectionWithTitle: function(titleText, article)
138 { 140 {
139 if (!article) 141 if (!article)
140 return; 142 return;
141 var section = this._element.createChild("div", "documentation-section"); 143 var section = this._element.createChild("div", "documentation-section");
142 var title = section.createChild("div", "documentation-section-title"); 144 var title = section.createChild("div", "documentation-section-title");
143 title.textContent = titleText; 145 title.textContent = titleText;
144 var text = this._renderBlock(article); 146 var text = this._renderBlock(article);
145 text.classList.add("documentation-text"); 147 text.classList.add("documentation-text");
148 text.classList.add("documentation-section-content");
146 section.appendChild(text); 149 section.appendChild(text);
147 }, 150 },
148 151
149 /** 152 /**
150 * @param {!Array.<!WebInspector.JSArticle.Parameter>} parameters 153 * @param {!Array.<!WebInspector.JSArticle.Parameter>} parameters
151 * @param {?WebInspector.JSArticle.Method} method 154 * @param {?WebInspector.JSArticle.Method} method
152 */ 155 */
153 _createSignatureSection: function(parameters, method) 156 _createSignatureSection: function(parameters, method)
154 { 157 {
158 if (!method)
159 return;
160 var section = this._element.createChild("p", "documentation-section");
161 var signature = section.createChild("div", "documentation-method-signatu re");
lushnikov 2014/09/05 15:20:44 lets use "span" here instead of "div" and get rid
semeny 2014/09/08 10:03:56 Done.
162 var methodName = signature.createChild("span", "documentation-method-nam e");
163 methodName.textContent = this._searchItem.split(".").peekLast() + "(";
164 for (var i = 0; i < parameters.length; ++i) {
165 if (i > 0) {
166 var separator = signature.createChild("inline");
lushnikov 2014/09/05 15:20:44 there's no tag "inline". You probably would like t
apavlov 2014/09/05 16:43:00 Yes, I meant that the variable should be inlined
semeny 2014/09/08 10:03:57 Done.
167 separator.textContent = ", ";
168 }
169 var parameterType = signature.createChild("span", "documentation-par ameter-data-type-value");
170 var optional = "";
171 if (parameters[i].optional) {
172 parameterType.className = "documentation-parameter-data-type-val ue";
lushnikov 2014/09/05 15:20:44 You've already set this className in element creat
semeny 2014/09/08 10:03:57 Done.
173 optional = "=";
174 }
175 parameterType.classList.add("documentation-color-box");
apavlov 2014/09/05 16:43:00 This class can be provided during the element cons
semeny 2014/09/08 10:03:56 Done.
176 parameterType.textContent = parameters[i].dataType + optional;
lushnikov 2014/09/05 15:20:44 parameterType.textContent = parameters[i].dataType
semeny 2014/09/08 10:03:56 Done.
177 }
178 var separator = signature.createChild("inline");
lushnikov 2014/09/05 15:20:44 ditto
semeny 2014/09/08 10:03:56 Done.
179 separator.textContent = ") : ";
lushnikov 2014/09/05 15:20:44 lets avoid space after ")"
semeny 2014/09/08 10:03:56 Done.
180 var returnTypeElement = signature.createChild("span", "documentation-par ameter-data-type-value");
181 returnTypeElement.classList.add("documentation-color-box");
182 returnTypeElement.textContent = method.returnValueName;
183 },
184
185 /**
186 * @param {!Array.<!WebInspector.JSArticle.Parameter>} parameters
187 */
188 _createParametersSection: function(parameters)
189 {
155 if (!parameters.length) 190 if (!parameters.length)
156 return; 191 return;
157 var section = this._element.createChild("div", "documentation-section"); 192 var section = this._element.createChild("div", "documentation-section");
158 var title = section.createChild("div", "documentation-section-title"); 193 var title = section.createChild("div", "documentation-section-title");
159 title.textContent = "Parameters"; 194 title.textContent = "Parameters";
160 for (var i = 0; i < parameters.length; ++i) { 195 for (var i = 0; i < parameters.length; ++i) {
161 var parameter = section.createChild("div", "documentation-parameter" ); 196 var parameter = section.createChild("div", "documentation-parameter" );
197 parameter.classList.add("documentation-section-content");
apavlov 2014/09/05 16:43:00 Ditto
semeny 2014/09/08 10:03:56 Done.
162 var header = parameter.createChild("div", "documentation-parameter-h eader"); 198 var header = parameter.createChild("div", "documentation-parameter-h eader");
163 var name = header.createChild("span", "documentation-parameter-name" ); 199 var name = header.createChild("span", "documentation-parameter-name" );
164 name.textContent = parameters[i].name; 200 name.textContent = parameters[i].name;
165 var dataTypeValue = header.createChild("span", "documentation-parame ter-data-type-value"); 201 var dataTypeValue = header.createChild("span", "documentation-parame ter-data-type-value");
202 dataTypeValue.classList.add("documentation-color-box");
apavlov 2014/09/05 16:43:00 Ditto for these two classes
semeny 2014/09/08 10:03:57 Done.
203 dataTypeValue.classList.add("documentation-parameter-margin");
166 dataTypeValue.textContent = parameters[i].dataType; 204 dataTypeValue.textContent = parameters[i].dataType;
167 if (parameters[i].optional) { 205 if (parameters[i].optional) {
168 var optional = header.createChild("span", "documentation-paramet er-optional"); 206 var optional = header.createChild("span", "documentation-paramet er-optional");
207 optional.classList.add("documentation-color-box");
apavlov 2014/09/05 16:43:00 Ditto for these two classes
semeny 2014/09/08 10:03:56 Done.
208 optional.classList.add("documentation-parameter-margin");
169 optional.textContent = WebInspector.UIString("Optional"); 209 optional.textContent = WebInspector.UIString("Optional");
170 } 210 }
171 parameter.appendChild(this._renderBlock(parameters[i].description)); 211 var description = this._renderBlock(parameters[i].description);
212 description.classList.add("documentation-text");
213 parameter.appendChild(description);
172 } 214 }
173 }, 215 },
174 216
175 /** 217 /**
176 * @param {?WebInspector.JSArticle.Method} method 218 * @param {?WebInspector.JSArticle.Method} method
177 */ 219 */
178 _createReturnValueSection: function(method) 220 _createReturnValueSection: function(method)
179 { 221 {
180 if (!method) 222 if (!method)
181 return; 223 return;
182 224
183 var section = this._element.createChild("div", "documentation-section"); 225 var section = this._element.createChild("div", "documentation-section");
184 var title = section.createChild("div", "documentation-section-title"); 226 var title = section.createChild("div", "documentation-section-title");
185 title.textContent = "Return Value"; 227 title.textContent = "Return Value";
186 var returnValueName = section.createChild("div", "documentation-return-v alue"); 228 var returnValueName = section.createChild("div", "documentation-section- content");
187 returnValueName.textContent = WebInspector.UIString("Returns an object o f type " + method.returnValueName + "."); 229 returnValueName.textContent = WebInspector.UIString("Returns an object o f type " + method.returnValueName + ".");
188 var returnValueDescription = section.createChild("div", "documentation-r eturn-value"); 230 var returnValueDescription = section.createChild("div", "documentation-s ection-content");
231 returnValueDescription.classList.add("documentation-text");
apavlov 2014/09/05 16:43:00 Ditto
semeny 2014/09/08 10:03:56 Done.
189 returnValueDescription.textContent = WebInspector.UIString(method.return ValueDescription); 232 returnValueDescription.textContent = WebInspector.UIString(method.return ValueDescription);
190 }, 233 },
191 234
192 /** 235 /**
193 * @param {!Array.<!WebInspector.JSArticle.Example>} examples 236 * @param {!Array.<!WebInspector.JSArticle.Example>} examples
194 */ 237 */
195 _createExamplesSection: function(examples) 238 _createExamplesSection: function(examples)
196 { 239 {
197 if (!examples.length) 240 if (!examples.length)
198 return; 241 return;
199 242
200 var section = this._element.createChild("div", "documentation-section"); 243 var section = this._element.createChild("div", "documentation-section");
201 var title = section.createChild("div", "documentation-section-title"); 244 var title = section.createChild("div", "documentation-section-title");
202 title.textContent = "Examples"; 245 title.textContent = "Examples";
203 246
204 for (var i = 0; i < examples.length; ++i) { 247 for (var i = 0; i < examples.length; ++i) {
205 var example = section.createChild("div", "documentation-example"); 248 var example = section.createChild("div", "documentation-example");
249 example.classList.add("documentation-section-content");
apavlov 2014/09/05 16:43:00 Ditto here and below
semeny 2014/09/08 10:03:56 Done.
206 var exampleDescription = example.createChild("div", "documentation-e xample-description-section"); 250 var exampleDescription = example.createChild("div", "documentation-e xample-description-section");
207 if (examples[i].liveUrl) { 251 if (examples[i].liveUrl) {
208 var liveUrl = exampleDescription.createChild("a", "documentation -example-link"); 252 var liveUrl = exampleDescription.createChild("a", "documentation -example-link");
253 liveUrl.classList.add("documentation-color-box");
209 liveUrl.href = examples[i].liveUrl; 254 liveUrl.href = examples[i].liveUrl;
210 liveUrl.textContent = WebInspector.UIString("Example"); 255 liveUrl.textContent = WebInspector.UIString("Example");
211 } 256 }
212 exampleDescription.appendChild(this._renderBlock(examples[i].descrip tion)); 257 var description = this._renderBlock(examples[i].description);
258 description.classList.add("documentation-text");
259 exampleDescription.appendChild(description);
213 var code = example.createChild("div", "documentation-example-code"); 260 var code = example.createChild("div", "documentation-example-code");
214 code.classList.add("source-code"); 261 code.classList.add("source-code");
215 code.textContent = examples[i].code; 262 code.textContent = examples[i].code;
216 } 263 }
217 }, 264 },
218 265
219 /** 266 /**
220 * @param {!WebInspector.WikiParser.ArticleElement} article 267 * @param {!WebInspector.WikiParser.ArticleElement} article
221 * @return {!Element} 268 * @return {!Element}
222 */ 269 */
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
285 appendApplicableItems: function(event, contextMenu, target) 332 appendApplicableItems: function(event, contextMenu, target)
286 { 333 {
287 if (!(target instanceof WebInspector.CodeMirrorTextEditor)) 334 if (!(target instanceof WebInspector.CodeMirrorTextEditor))
288 return; 335 return;
289 var textEditor = /** @type {!WebInspector.CodeMirrorTextEditor} */ (targ et); 336 var textEditor = /** @type {!WebInspector.CodeMirrorTextEditor} */ (targ et);
290 var descriptors = this._determineDescriptors(textEditor); 337 var descriptors = this._determineDescriptors(textEditor);
291 if (!descriptors.length) 338 if (!descriptors.length)
292 return; 339 return;
293 if (descriptors.length === 1) { 340 if (descriptors.length === 1) {
294 var formatString = WebInspector.useLowerCaseMenuTitles() ? "Show doc umentation for %s.%s" : "Show Documentation for %s.%s"; 341 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())); 342 var methodName = String.sprintf("%s.%s", descriptors[0].name(), desc riptors[0].searchItem());
343 contextMenu.appendItem(WebInspector.UIString(formatString, descripto rs[0].name(), descriptors[0].searchItem()), WebInspector.DocumentationView.showD ocumentationURL.bind(null, descriptors[0].url(), methodName));
296 return; 344 return;
297 } 345 }
298 var subMenuItem = contextMenu.appendSubMenuItem(WebInspector.UIString(We bInspector.useLowerCaseMenuTitles() ? "Show documentation for..." : "Show Docume ntation for...")); 346 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) 347 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())); 348 var methodName = String.sprintf("%s.%s", descriptors[i].name(), desc riptors[i].searchItem());
349 subMenuItem.appendItem(methodName, WebInspector.DocumentationView.sh owDocumentationURL.bind(null, descriptors[i].url(), methodName));
350 }
301 }, 351 },
302 352
303 /** 353 /**
304 * @param {!WebInspector.CodeMirrorTextEditor} textEditor 354 * @param {!WebInspector.CodeMirrorTextEditor} textEditor
305 * @return {!Array.<!WebInspector.DocumentationURLProvider.ItemDescriptor>} 355 * @return {!Array.<!WebInspector.DocumentationURLProvider.ItemDescriptor>}
306 */ 356 */
307 _determineDescriptors: function(textEditor) 357 _determineDescriptors: function(textEditor)
308 { 358 {
309 var urlProvider = WebInspector.DocumentationURLProvider.instance(); 359 var urlProvider = WebInspector.DocumentationURLProvider.instance();
310 var textSelection = textEditor.selection().normalize(); 360 var textSelection = textEditor.selection().normalize();
(...skipping 16 matching lines...) Expand all
327 */ 377 */
328 function computeDescriptors(column) 378 function computeDescriptors(column)
329 { 379 {
330 var token = textEditor.tokenAtTextPosition(textSelection.startLine, column); 380 var token = textEditor.tokenAtTextPosition(textSelection.startLine, column);
331 if (!token) 381 if (!token)
332 return []; 382 return [];
333 var tokenText = textEditor.line(textSelection.startLine).substring(t oken.startColumn, token.endColumn); 383 var tokenText = textEditor.line(textSelection.startLine).substring(t oken.startColumn, token.endColumn);
334 return urlProvider.itemDescriptors(tokenText); 384 return urlProvider.itemDescriptors(tokenText);
335 } 385 }
336 } 386 }
337 } 387 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698