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

Side by Side Diff: third_party/WebKit/Source/devtools/front_end/ui/Toolbar.js

Issue 1574213006: DevTools: beautified styles sidebar toolbar. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: review comments addressed. Created 4 years, 11 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 /* 1 /*
2 * Copyright (C) 2009 Google Inc. All rights reserved. 2 * Copyright (C) 2009 Google Inc. All rights reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are 5 * modification, are permitted provided that the following conditions are
6 * met: 6 * met:
7 * 7 *
8 * * Redistributions of source code must retain the above copyright 8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer. 9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above 10 * * Redistributions in binary form must reproduce the above
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after
99 appendSeparator: function() 99 appendSeparator: function()
100 { 100 {
101 this.appendToolbarItem(new WebInspector.ToolbarSeparator()); 101 this.appendToolbarItem(new WebInspector.ToolbarSeparator());
102 }, 102 },
103 103
104 /** 104 /**
105 * @param {string} text 105 * @param {string} text
106 */ 106 */
107 appendText: function(text) 107 appendText: function(text)
108 { 108 {
109 this.appendToolbarItem(new WebInspector.ToolbarLabel(text)); 109 this.appendToolbarItem(new WebInspector.ToolbarText(text));
110 }, 110 },
111 111
112 removeToolbarItems: function() 112 removeToolbarItems: function()
113 { 113 {
114 for (var item of this._items) 114 for (var item of this._items)
115 delete item._toolbar; 115 delete item._toolbar;
116 this._items = []; 116 this._items = [];
117 this._contentElement.removeChildren(); 117 this._contentElement.removeChildren();
118 this._insertionPoint = this._contentElement.createChild("content"); 118 this._insertionPoint = this._contentElement.createChild("content");
119 }, 119 },
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
175 { 175 {
176 this.element = element; 176 this.element = element;
177 this.element.classList.add("toolbar-item"); 177 this.element.classList.add("toolbar-item");
178 this._visible = true; 178 this._visible = true;
179 this._enabled = true; 179 this._enabled = true;
180 this.element.addEventListener("mouseenter", this._mouseEnter.bind(this), fal se); 180 this.element.addEventListener("mouseenter", this._mouseEnter.bind(this), fal se);
181 this.element.addEventListener("mouseleave", this._mouseLeave.bind(this), fal se); 181 this.element.addEventListener("mouseleave", this._mouseLeave.bind(this), fal se);
182 } 182 }
183 183
184 WebInspector.ToolbarItem.prototype = { 184 WebInspector.ToolbarItem.prototype = {
185 /**
186 * @param {string} title
187 */
188 setTitle: function(title)
189 {
190 if (this._title === title)
191 return;
192 this._title = title;
193 WebInspector.Tooltip.install(this.element, title);
194 },
195
185 _mouseEnter: function() 196 _mouseEnter: function()
186 { 197 {
187 this.element.classList.add("hover"); 198 this.element.classList.add("hover");
188 }, 199 },
189 200
190 _mouseLeave: function() 201 _mouseLeave: function()
191 { 202 {
192 this.element.classList.remove("hover"); 203 this.element.classList.remove("hover");
193 }, 204 },
194 205
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
229 this._toolbar._hideSeparatorDupes(); 240 this._toolbar._hideSeparatorDupes();
230 }, 241 },
231 242
232 __proto__: WebInspector.Object.prototype 243 __proto__: WebInspector.Object.prototype
233 } 244 }
234 245
235 /** 246 /**
236 * @constructor 247 * @constructor
237 * @extends {WebInspector.ToolbarItem} 248 * @extends {WebInspector.ToolbarItem}
238 * @param {string=} text 249 * @param {string=} text
250 */
251 WebInspector.ToolbarText = function(text)
252 {
253 WebInspector.ToolbarItem.call(this, createElementWithClass("div", "toolbar-t ext"));
254 this.element.classList.add("toolbar-text");
255 this.setText(text || "");
256 }
257
258 WebInspector.ToolbarText.prototype = {
259 /**
260 * @param {string} text
261 */
262 setText: function(text)
263 {
264 this.element.textContent = text;
265 },
266
267 __proto__: WebInspector.ToolbarItem.prototype
268 }
269
270 /**
271 * @constructor
272 * @extends {WebInspector.ToolbarItem}
273 * @param {string} title
239 * @param {string=} glyph 274 * @param {string=} glyph
275 * @param {string=} text
240 */ 276 */
241 WebInspector.ToolbarLabel = function(text, glyph) 277 WebInspector.ToolbarButton = function(title, glyph, text)
242 { 278 {
243 WebInspector.ToolbarItem.call(this, createElementWithClass("button", "toolba r-text-glyph")); 279 WebInspector.ToolbarItem.call(this, createElementWithClass("button", "toolba r-button"));
280 this.element.addEventListener("click", this._clicked.bind(this), false);
281 this.element.addEventListener("mousedown", this._mouseDown.bind(this), false );
282 this.element.addEventListener("mouseup", this._mouseUp.bind(this), false);
283
244 this._glyphElement = this.element.createChild("div", "toolbar-glyph hidden") ; 284 this._glyphElement = this.element.createChild("div", "toolbar-glyph hidden") ;
245 this._textElement = this.element.createChild("div", "toolbar-text hidden"); 285 this._textElement = this.element.createChild("div", "toolbar-text hidden");
246 this.setText(text || ""); 286
287 this.setTitle(title);
247 if (glyph) 288 if (glyph)
248 this.setGlyph(glyph); 289 this.setGlyph(glyph);
290 this.setText(text || "");
249 this._state = ""; 291 this._state = "";
250 this._title = ""; 292 this._title = "";
251 } 293 }
252 294
253 WebInspector.ToolbarLabel.prototype = { 295 WebInspector.ToolbarButton.prototype = {
254 /** 296 /**
255 * @param {string} text 297 * @param {string} text
256 */ 298 */
257 setText: function(text) 299 setText: function(text)
258 { 300 {
259 if (this._text === text) 301 if (this._text === text)
260 return; 302 return;
261 this._textElement.textContent = text; 303 this._textElement.textContent = text;
262 this._textElement.classList.toggle("hidden", !text); 304 this._textElement.classList.toggle("hidden", !text);
263 this._text = text; 305 this._text = text;
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
301 setState: function(state) 343 setState: function(state)
302 { 344 {
303 if (this._state === state) 345 if (this._state === state)
304 return; 346 return;
305 this.element.classList.remove("toolbar-state-" + this._state); 347 this.element.classList.remove("toolbar-state-" + this._state);
306 this.element.classList.add("toolbar-state-" + state); 348 this.element.classList.add("toolbar-state-" + state);
307 this._state = state; 349 this._state = state;
308 }, 350 },
309 351
310 /** 352 /**
311 * @param {string} title
312 */
313 setTitle: function(title)
314 {
315 if (this._title === title)
316 return;
317 this._title = title;
318 WebInspector.Tooltip.install(this.element, title);
319 },
320
321 /**
322 * @param {boolean} bold
323 */
324 setBold: function(bold)
325 {
326 this.element.classList.toggle("toolbar-bold", bold);
327 },
328
329 /**
330 * @param {boolean} dimmed 353 * @param {boolean} dimmed
331 */ 354 */
332 setDimmed: function(dimmed) 355 setDimmed: function(dimmed)
333 { 356 {
334 this.element.classList.toggle("toolbar-dimmed", dimmed); 357 this.element.classList.toggle("toolbar-dimmed", dimmed);
335 }, 358 },
336 359
337 addDropDownArrow: function() 360 addDropDownArrow: function()
338 { 361 {
339 this.element.classList.add("toolbar-has-dropdown"); 362 this.element.classList.add("toolbar-has-dropdown");
340 this.element.createChild("div", "toolbar-dropdown-arrow"); 363 this.element.createChild("div", "toolbar-dropdown-arrow");
341 }, 364 },
342 365
343 __proto__: WebInspector.ToolbarItem.prototype
344 }
345
346 /**
347 * @constructor
348 * @extends {WebInspector.ToolbarLabel}
349 * @param {string} title
350 * @param {string} glyph
351 */
352 WebInspector.ToolbarButton = function(title, glyph)
353 {
354 WebInspector.ToolbarLabel.call(this);
355 this.element.classList.add("toolbar-button");
356 this.element.addEventListener("click", this._clicked.bind(this), false);
357 this.element.addEventListener("mousedown", this._mouseDown.bind(this), false );
358 this.element.addEventListener("mouseup", this._mouseUp.bind(this), false);
359 this.setBold(true);
360 this.setTitle(title);
361 this.setGlyph(glyph);
362 }
363
364 WebInspector.ToolbarButton.prototype = {
365 /** 366 /**
366 * @param {!Event} event 367 * @param {!Event} event
367 */ 368 */
368 _clicked: function(event) 369 _clicked: function(event)
369 { 370 {
370 var defaultPrevented = this.dispatchEventToListeners("click", event); 371 var defaultPrevented = this.dispatchEventToListeners("click", event);
371 event.consume(defaultPrevented); 372 event.consume(defaultPrevented);
372 }, 373 },
373 374
374 /** 375 /**
375 * @param {!Event} event 376 * @param {!Event} event
376 */ 377 */
377 _mouseDown: function(event) 378 _mouseDown: function(event)
378 { 379 {
379 this.dispatchEventToListeners("mousedown", event); 380 this.dispatchEventToListeners("mousedown", event);
380 }, 381 },
381 382
382 /** 383 /**
383 * @param {!Event} event 384 * @param {!Event} event
384 */ 385 */
385 _mouseUp: function(event) 386 _mouseUp: function(event)
386 { 387 {
387 this.dispatchEventToListeners("mouseup", event); 388 this.dispatchEventToListeners("mouseup", event);
388 }, 389 },
389 390
390 __proto__: WebInspector.ToolbarLabel.prototype 391 __proto__: WebInspector.ToolbarItem.prototype
391 } 392 }
392 393
393 /** 394 /**
394 * @constructor 395 * @constructor
395 * @extends {WebInspector.ToolbarItem} 396 * @extends {WebInspector.ToolbarItem}
396 * @param {string=} placeholder 397 * @param {string=} placeholder
397 * @param {number=} growFactor 398 * @param {number=} growFactor
398 */ 399 */
399 WebInspector.ToolbarInput = function(placeholder, growFactor) 400 WebInspector.ToolbarInput = function(placeholder, growFactor)
400 { 401 {
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
433 { 434 {
434 this.dispatchEventToListeners(WebInspector.ToolbarInput.Event.TextChange d, this.element.value); 435 this.dispatchEventToListeners(WebInspector.ToolbarInput.Event.TextChange d, this.element.value);
435 }, 436 },
436 437
437 __proto__: WebInspector.ToolbarItem.prototype 438 __proto__: WebInspector.ToolbarItem.prototype
438 } 439 }
439 440
440 /** 441 /**
441 * @constructor 442 * @constructor
442 * @extends {WebInspector.ToolbarButton} 443 * @extends {WebInspector.ToolbarButton}
444 * @param {string} title
445 * @param {string=} glyph
446 * @param {string=} text
443 */ 447 */
444 WebInspector.ToolbarToggle = function(title, glyph) 448 WebInspector.ToolbarToggle = function(title, glyph, text)
445 { 449 {
446 WebInspector.ToolbarButton.call(this, title, glyph); 450 WebInspector.ToolbarButton.call(this, title, glyph, text);
447 this._toggled = false; 451 this._toggled = false;
448 this.setState("off"); 452 this.setState("off");
449 } 453 }
450 454
451 WebInspector.ToolbarToggle.prototype = { 455 WebInspector.ToolbarToggle.prototype = {
452 /** 456 /**
453 * @return {boolean} 457 * @return {boolean}
454 */ 458 */
455 toggled: function() 459 toggled: function()
456 { 460 {
(...skipping 439 matching lines...) Expand 10 before | Expand all | Expand 10 after
896 * @param {string} location 900 * @param {string} location
897 */ 901 */
898 _loadItems: function(location) 902 _loadItems: function(location)
899 { 903 {
900 var extensions = self.runtime.extensions(WebInspector.ToolbarItem.Provid er); 904 var extensions = self.runtime.extensions(WebInspector.ToolbarItem.Provid er);
901 var promises = []; 905 var promises = [];
902 for (var i = 0; i < extensions.length; ++i) { 906 for (var i = 0; i < extensions.length; ++i) {
903 if (extensions[i].descriptor()["location"] === location) 907 if (extensions[i].descriptor()["location"] === location)
904 promises.push(resolveItem(extensions[i])); 908 promises.push(resolveItem(extensions[i]));
905 } 909 }
906 Promise.all(promises).then(appendItemsInOrder.bind(this)); 910 this._promise = Promise.all(promises).then(appendItemsInOrder.bind(this) );
907 911
908 /** 912 /**
909 * @param {!Runtime.Extension} extension 913 * @param {!Runtime.Extension} extension
910 * @return {!Promise.<?WebInspector.ToolbarItem>} 914 * @return {!Promise.<?WebInspector.ToolbarItem>}
911 */ 915 */
912 function resolveItem(extension) 916 function resolveItem(extension)
913 { 917 {
914 var descriptor = extension.descriptor(); 918 var descriptor = extension.descriptor();
915 if (descriptor["separator"]) 919 if (descriptor["separator"])
916 return Promise.resolve(/** @type {?WebInspector.ToolbarItem} */( new WebInspector.ToolbarSeparator())); 920 return Promise.resolve(/** @type {?WebInspector.ToolbarItem} */( new WebInspector.ToolbarSeparator()));
(...skipping 17 matching lines...) Expand all
934 function appendItemsInOrder(items) 938 function appendItemsInOrder(items)
935 { 939 {
936 for (var i = 0; i < items.length; ++i) { 940 for (var i = 0; i < items.length; ++i) {
937 var item = items[i]; 941 var item = items[i];
938 if (item) 942 if (item)
939 this.appendToolbarItem(item); 943 this.appendToolbarItem(item);
940 } 944 }
941 } 945 }
942 }, 946 },
943 947
948 /**
949 * @return {!Promise}
950 */
951 onLoad: function()
952 {
953 return this._promise;
954 },
955
944 __proto__: WebInspector.Toolbar.prototype 956 __proto__: WebInspector.Toolbar.prototype
945 } 957 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698