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

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

Issue 2466123002: DevTools: reformat front-end code to match chromium style. (Closed)
Patch Set: all done Created 4 years, 1 month 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
11 * copyright notice, this list of conditions and the following disclaimer 11 * copyright notice, this list of conditions and the following disclaimer
12 * in the documentation and/or other materials provided with the 12 * in the documentation and/or other materials provided with the
13 * distribution. 13 * distribution.
14 * * Neither the name of Google Inc. nor the names of its 14 * * Neither the name of Google Inc. nor the names of its
15 * contributors may be used to endorse or promote products derived from 15 * contributors may be used to endorse or promote products derived from
16 * this software without specific prior written permission. 16 * this software without specific prior written permission.
17 * 17 *
18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 19 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 20 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 21 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 */ 29 */
30 30 /**
31 /** 31 * @unrestricted
32 * @constructor 32 */
33 * @param {string} className 33 WebInspector.Toolbar = class {
34 * @param {!Element=} parentElement 34 /**
35 */ 35 * @param {string} className
36 WebInspector.Toolbar = function(className, parentElement) 36 * @param {!Element=} parentElement
37 { 37 */
38 constructor(className, parentElement) {
38 /** @type {!Array.<!WebInspector.ToolbarItem>} */ 39 /** @type {!Array.<!WebInspector.ToolbarItem>} */
39 this._items = []; 40 this._items = [];
40 this._reverse = false; 41 this._reverse = false;
41 this.element = parentElement ? parentElement.createChild("div") : createElem ent("div"); 42 this.element = parentElement ? parentElement.createChild('div') : createElem ent('div');
42 this.element.className = className; 43 this.element.className = className;
43 this.element.classList.add("toolbar"); 44 this.element.classList.add('toolbar');
44 this._shadowRoot = WebInspector.createShadowRootWithCoreStyles(this.element, "ui/toolbar.css"); 45 this._shadowRoot = WebInspector.createShadowRootWithCoreStyles(this.element, 'ui/toolbar.css');
45 this._contentElement = this._shadowRoot.createChild("div", "toolbar-shadow") ; 46 this._contentElement = this._shadowRoot.createChild('div', 'toolbar-shadow') ;
46 this._insertionPoint = this._contentElement.createChild("content"); 47 this._insertionPoint = this._contentElement.createChild('content');
47 }; 48 }
48 49
49 WebInspector.Toolbar.prototype = { 50 /**
50 /** 51 * @param {!WebInspector.Action} action
51 * @param {boolean=} reverse 52 * @param {!Array<!WebInspector.ToolbarButton>=} toggledOptions
52 */ 53 * @param {!Array<!WebInspector.ToolbarButton>=} untoggledOptions
53 makeWrappable: function(reverse) 54 * @return {!WebInspector.ToolbarItem}
54 { 55 */
55 this._contentElement.classList.add("wrappable"); 56 static createActionButton(action, toggledOptions, untoggledOptions) {
56 this._reverse = !!reverse;
57 if (reverse)
58 this._contentElement.classList.add("wrappable-reverse");
59 },
60
61 makeVertical: function()
62 {
63 this._contentElement.classList.add("vertical");
64 },
65
66 makeBlueOnHover: function()
67 {
68 this._contentElement.classList.add("toolbar-blue-on-hover");
69 },
70
71 makeToggledGray: function()
72 {
73 this._contentElement.classList.add("toolbar-toggled-gray");
74 },
75
76 renderAsLinks: function()
77 {
78 this._contentElement.classList.add("toolbar-render-as-links");
79 },
80
81 /**
82 * @param {boolean} enabled
83 */
84 setEnabled: function(enabled)
85 {
86 for (var item of this._items)
87 item.setEnabled(enabled);
88 },
89
90 /**
91 * @param {!WebInspector.ToolbarItem} item
92 */
93 appendToolbarItem: function(item)
94 {
95 this._items.push(item);
96 item._toolbar = this;
97 if (this._reverse)
98 this._contentElement.insertBefore(item.element, this._insertionPoint .nextSibling);
99 else
100 this._contentElement.insertBefore(item.element, this._insertionPoint );
101 this._hideSeparatorDupes();
102 },
103
104 appendSeparator: function()
105 {
106 this.appendToolbarItem(new WebInspector.ToolbarSeparator());
107 },
108
109 appendSpacer: function()
110 {
111 this.appendToolbarItem(new WebInspector.ToolbarSeparator(true));
112 },
113
114 /**
115 * @param {string} text
116 */
117 appendText: function(text)
118 {
119 this.appendToolbarItem(new WebInspector.ToolbarText(text));
120 },
121
122 removeToolbarItems: function()
123 {
124 for (var item of this._items)
125 delete item._toolbar;
126 this._items = [];
127 this._contentElement.removeChildren();
128 this._insertionPoint = this._contentElement.createChild("content");
129 },
130
131 /**
132 * @param {string} color
133 */
134 setColor: function(color)
135 {
136 var style = createElement("style");
137 style.textContent = ".toolbar-glyph { background-color: " + color + " !i mportant }";
138 this._shadowRoot.appendChild(style);
139 },
140
141 /**
142 * @param {string} color
143 */
144 setToggledColor: function(color)
145 {
146 var style = createElement("style");
147 style.textContent = ".toolbar-button.toolbar-state-on .toolbar-glyph { b ackground-color: " + color + " !important }";
148 this._shadowRoot.appendChild(style);
149 },
150
151 _hideSeparatorDupes: function()
152 {
153 if (!this._items.length)
154 return;
155 // Don't hide first and last separators if they were added explicitly.
156 var previousIsSeparator = false;
157 var lastSeparator;
158 var nonSeparatorVisible = false;
159 for (var i = 0; i < this._items.length; ++i) {
160 if (this._items[i] instanceof WebInspector.ToolbarSeparator) {
161 this._items[i].setVisible(!previousIsSeparator);
162 previousIsSeparator = true;
163 lastSeparator = this._items[i];
164 continue;
165 }
166 if (this._items[i].visible()) {
167 previousIsSeparator = false;
168 lastSeparator = null;
169 nonSeparatorVisible = true;
170 }
171 }
172 if (lastSeparator && lastSeparator !== this._items.peekLast())
173 lastSeparator.setVisible(false);
174
175 this.element.classList.toggle("hidden", !!lastSeparator && lastSeparator .visible() && !nonSeparatorVisible);
176 },
177
178 /**
179 * @param {string} location
180 */
181 appendLocationItems: function(location)
182 {
183 var extensions = self.runtime.extensions(WebInspector.ToolbarItem.Provid er);
184 var promises = [];
185 for (var i = 0; i < extensions.length; ++i) {
186 if (extensions[i].descriptor()["location"] === location)
187 promises.push(resolveItem(extensions[i]));
188 }
189 Promise.all(promises).then(appendItemsInOrder.bind(this));
190
191 /**
192 * @param {!Runtime.Extension} extension
193 * @return {!Promise.<?WebInspector.ToolbarItem>}
194 */
195 function resolveItem(extension)
196 {
197 var descriptor = extension.descriptor();
198 if (descriptor["separator"])
199 return Promise.resolve(/** @type {?WebInspector.ToolbarItem} */( new WebInspector.ToolbarSeparator()));
200 if (descriptor["actionId"])
201 return Promise.resolve(WebInspector.Toolbar.createActionButtonFo rId(descriptor["actionId"]));
202 return extension.instance().then(fetchItemFromProvider);
203
204 /**
205 * @param {!Object} provider
206 */
207 function fetchItemFromProvider(provider)
208 {
209 return /** @type {!WebInspector.ToolbarItem.Provider} */ (provid er).item();
210 }
211 }
212
213 /**
214 * @param {!Array.<?WebInspector.ToolbarItem>} items
215 * @this {WebInspector.Toolbar}
216 */
217 function appendItemsInOrder(items)
218 {
219 for (var i = 0; i < items.length; ++i) {
220 var item = items[i];
221 if (item)
222 this.appendToolbarItem(item);
223 }
224 }
225 }
226 };
227
228 /**
229 * @constructor
230 * @extends {WebInspector.Object}
231 * @param {!Element} element
232 */
233 WebInspector.ToolbarItem = function(element)
234 {
235 this.element = element;
236 this.element.classList.add("toolbar-item");
237 this._visible = true;
238 this._enabled = true;
239 this.element.addEventListener("mouseenter", this._mouseEnter.bind(this), fal se);
240 this.element.addEventListener("mouseleave", this._mouseLeave.bind(this), fal se);
241 };
242
243 WebInspector.ToolbarItem.prototype = {
244 /**
245 * @param {string} title
246 */
247 setTitle: function(title)
248 {
249 if (this._title === title)
250 return;
251 this._title = title;
252 WebInspector.Tooltip.install(this.element, title);
253 },
254
255 _mouseEnter: function()
256 {
257 this.element.classList.add("hover");
258 },
259
260 _mouseLeave: function()
261 {
262 this.element.classList.remove("hover");
263 },
264
265 /**
266 * @param {boolean} value
267 */
268 setEnabled: function(value)
269 {
270 if (this._enabled === value)
271 return;
272 this._enabled = value;
273 this._applyEnabledState();
274 },
275
276 _applyEnabledState: function()
277 {
278 this.element.disabled = !this._enabled;
279 },
280
281 /**
282 * @return {boolean} x
283 */
284 visible: function()
285 {
286 return this._visible;
287 },
288
289 /**
290 * @param {boolean} x
291 */
292 setVisible: function(x)
293 {
294 if (this._visible === x)
295 return;
296 this.element.classList.toggle("hidden", !x);
297 this._visible = x;
298 if (this._toolbar && !(this instanceof WebInspector.ToolbarSeparator))
299 this._toolbar._hideSeparatorDupes();
300 },
301
302 __proto__: WebInspector.Object.prototype
303 };
304
305 /**
306 * @constructor
307 * @extends {WebInspector.ToolbarItem}
308 * @param {string=} text
309 */
310 WebInspector.ToolbarText = function(text)
311 {
312 WebInspector.ToolbarItem.call(this, createElementWithClass("div", "toolbar-t ext"));
313 this.element.classList.add("toolbar-text");
314 this.setText(text || "");
315 };
316
317 WebInspector.ToolbarText.prototype = {
318 /**
319 * @param {string} text
320 */
321 setText: function(text)
322 {
323 this.element.textContent = text;
324 },
325
326 __proto__: WebInspector.ToolbarItem.prototype
327 };
328
329 /**
330 * @constructor
331 * @extends {WebInspector.ToolbarItem}
332 * @param {string} title
333 * @param {string=} glyph
334 * @param {string=} text
335 */
336 WebInspector.ToolbarButton = function(title, glyph, text)
337 {
338 WebInspector.ToolbarItem.call(this, createElementWithClass("button", "toolba r-button"));
339 this.element.addEventListener("click", this._clicked.bind(this), false);
340 this.element.addEventListener("mousedown", this._mouseDown.bind(this), false );
341 this.element.addEventListener("mouseup", this._mouseUp.bind(this), false);
342
343 this._glyphElement = this.element.createChild("div", "toolbar-glyph hidden") ;
344 this._textElement = this.element.createChild("div", "toolbar-text hidden");
345
346 this.setTitle(title);
347 if (glyph)
348 this.setGlyph(glyph);
349 this.setText(text || "");
350 this._state = "";
351 this._title = "";
352 };
353
354 WebInspector.ToolbarButton.prototype = {
355 /**
356 * @param {string} text
357 */
358 setText: function(text)
359 {
360 if (this._text === text)
361 return;
362 this._textElement.textContent = text;
363 this._textElement.classList.toggle("hidden", !text);
364 this._text = text;
365 },
366
367 /**
368 * @param {string} glyph
369 */
370 setGlyph: function(glyph)
371 {
372 if (this._glyph === glyph)
373 return;
374 if (this._glyph)
375 this._glyphElement.classList.remove(this._glyph);
376 if (glyph)
377 this._glyphElement.classList.add(glyph);
378 this._glyphElement.classList.toggle("hidden", !glyph);
379 this.element.classList.toggle("toolbar-has-glyph", !!glyph);
380 this._glyph = glyph;
381 },
382
383 /**
384 * @param {string} iconURL
385 */
386 setBackgroundImage: function(iconURL)
387 {
388 this.element.style.backgroundImage = "url(" + iconURL + ")";
389 },
390
391 /**
392 * @return {string}
393 */
394 state: function()
395 {
396 return this._state;
397 },
398
399 /**
400 * @param {string} state
401 */
402 setState: function(state)
403 {
404 if (this._state === state)
405 return;
406 this.element.classList.remove("toolbar-state-" + this._state);
407 this.element.classList.add("toolbar-state-" + state);
408 this._state = state;
409 },
410
411 /**
412 * @param {number=} width
413 */
414 turnIntoSelect: function(width)
415 {
416 this.element.classList.add("toolbar-has-dropdown");
417 this.element.createChild("div", "toolbar-dropdown-arrow");
418 if (width)
419 this.element.style.width = width + "px";
420 },
421
422 /**
423 * @param {!Event} event
424 */
425 _clicked: function(event)
426 {
427 var defaultPrevented = this.dispatchEventToListeners("click", event);
428 event.consume(defaultPrevented);
429 },
430
431 /**
432 * @param {!Event} event
433 */
434 _mouseDown: function(event)
435 {
436 this.dispatchEventToListeners("mousedown", event);
437 },
438
439 /**
440 * @param {!Event} event
441 */
442 _mouseUp: function(event)
443 {
444 this.dispatchEventToListeners("mouseup", event);
445 },
446
447 __proto__: WebInspector.ToolbarItem.prototype
448 };
449
450 /**
451 * @constructor
452 * @extends {WebInspector.ToolbarItem}
453 * @param {string=} placeholder
454 * @param {number=} growFactor
455 */
456 WebInspector.ToolbarInput = function(placeholder, growFactor)
457 {
458 WebInspector.ToolbarItem.call(this, createElementWithClass("input", "toolbar -item"));
459 this.element.addEventListener("input", this._onChangeCallback.bind(this), fa lse);
460 if (growFactor)
461 this.element.style.flexGrow = growFactor;
462 if (placeholder)
463 this.element.setAttribute("placeholder", placeholder);
464 this._value = "";
465 };
466
467 WebInspector.ToolbarInput.Event = {
468 TextChanged: "TextChanged"
469 };
470
471 WebInspector.ToolbarInput.prototype = {
472 /**
473 * @param {string} value
474 */
475 setValue: function(value)
476 {
477 this._value = value;
478 this.element.value = value;
479 },
480
481 /**
482 * @return {string}
483 */
484 value: function()
485 {
486 return this.element.value;
487 },
488
489 _onChangeCallback: function()
490 {
491 this.dispatchEventToListeners(WebInspector.ToolbarInput.Event.TextChange d, this.element.value);
492 },
493
494 __proto__: WebInspector.ToolbarItem.prototype
495 };
496
497 /**
498 * @constructor
499 * @extends {WebInspector.ToolbarButton}
500 * @param {string} title
501 * @param {string=} glyph
502 * @param {string=} text
503 */
504 WebInspector.ToolbarToggle = function(title, glyph, text)
505 {
506 WebInspector.ToolbarButton.call(this, title, glyph, text);
507 this._toggled = false;
508 this.setState("off");
509 };
510
511 WebInspector.ToolbarToggle.prototype = {
512 /**
513 * @return {boolean}
514 */
515 toggled: function()
516 {
517 return this._toggled;
518 },
519
520 /**
521 * @param {boolean} toggled
522 */
523 setToggled: function(toggled)
524 {
525 if (this._toggled === toggled)
526 return;
527 this._toggled = toggled;
528 this.setState(toggled ? "on" : "off");
529 },
530
531 __proto__: WebInspector.ToolbarButton.prototype
532 };
533
534 /**
535 * @param {!WebInspector.Action} action
536 * @param {!Array<!WebInspector.ToolbarButton>=} toggledOptions
537 * @param {!Array<!WebInspector.ToolbarButton>=} untoggledOptions
538 * @return {!WebInspector.ToolbarItem}
539 */
540 WebInspector.Toolbar.createActionButton = function(action, toggledOptions, untog gledOptions)
541 {
542 var button = new WebInspector.ToolbarToggle(action.title(), action.icon()); 57 var button = new WebInspector.ToolbarToggle(action.title(), action.icon());
543 button.addEventListener("click", action.execute, action); 58 button.addEventListener('click', action.execute, action);
544 action.addEventListener(WebInspector.Action.Events.Enabled, enabledChanged); 59 action.addEventListener(WebInspector.Action.Events.Enabled, enabledChanged);
545 action.addEventListener(WebInspector.Action.Events.Toggled, toggled); 60 action.addEventListener(WebInspector.Action.Events.Toggled, toggled);
546 /** @type {?WebInspector.LongClickController} */ 61 /** @type {?WebInspector.LongClickController} */
547 var longClickController = null; 62 var longClickController = null;
548 /** @type {?Array<!WebInspector.ToolbarButton>} */ 63 /** @type {?Array<!WebInspector.ToolbarButton>} */
549 var longClickButtons = null; 64 var longClickButtons = null;
550 /** @type {?Element} */ 65 /** @type {?Element} */
551 var longClickGlyph = null; 66 var longClickGlyph = null;
552 toggled(); 67 toggled();
553 return button; 68 return button;
554 69
555 /** 70 /**
556 * @param {!WebInspector.Event} event 71 * @param {!WebInspector.Event} event
557 */ 72 */
558 function enabledChanged(event) 73 function enabledChanged(event) {
559 { 74 button.setEnabled(/** @type {boolean} */ (event.data));
560 button.setEnabled(/** @type {boolean} */ (event.data));
561 } 75 }
562 76
563 function toggled() 77 function toggled() {
564 { 78 button.setToggled(action.toggled());
565 button.setToggled(action.toggled()); 79 if (action.title())
566 if (action.title()) 80 WebInspector.Tooltip.install(button.element, action.title(), action.id() );
567 WebInspector.Tooltip.install(button.element, action.title(), action. id()); 81 updateOptions();
568 updateOptions();
569 } 82 }
570 83
571 function updateOptions() 84 function updateOptions() {
572 { 85 var buttons = action.toggled() ? (toggledOptions || null) : (untoggledOpti ons || null);
573 var buttons = action.toggled() ? (toggledOptions || null) : (untoggledOp tions || null); 86
574 87 if (buttons && buttons.length) {
575 if (buttons && buttons.length) { 88 if (!longClickController) {
576 if (!longClickController) { 89 longClickController = new WebInspector.LongClickController(button.elem ent, showOptions);
577 longClickController = new WebInspector.LongClickController(butto n.element, showOptions); 90 longClickGlyph = button.element.createChild('div', 'long-click-glyph t oolbar-button-theme');
578 longClickGlyph = button.element.createChild("div", "long-click-g lyph toolbar-button-theme"); 91 longClickButtons = buttons;
579 longClickButtons = buttons;
580 }
581 } else {
582 if (longClickController) {
583 longClickController.dispose();
584 longClickController = null;
585 longClickGlyph.remove();
586 longClickGlyph = null;
587 longClickButtons = null;
588 }
589 } 92 }
93 } else {
94 if (longClickController) {
95 longClickController.dispose();
96 longClickController = null;
97 longClickGlyph.remove();
98 longClickGlyph = null;
99 longClickButtons = null;
100 }
101 }
590 } 102 }
591 103
592 function showOptions() 104 function showOptions() {
593 { 105 var buttons = longClickButtons.slice();
594 var buttons = longClickButtons.slice(); 106 var mainButtonClone = new WebInspector.ToolbarToggle(action.title(), actio n.icon());
595 var mainButtonClone = new WebInspector.ToolbarToggle(action.title(), act ion.icon()); 107 mainButtonClone.addEventListener('click', clicked);
596 mainButtonClone.addEventListener("click", clicked); 108
597 109 /**
598 /** 110 * @param {!WebInspector.Event} event
599 * @param {!WebInspector.Event} event 111 */
600 */ 112 function clicked(event) {
601 function clicked(event) 113 button._clicked(/** @type {!Event} */ (event.data));
602 { 114 }
603 button._clicked(/** @type {!Event} */ (event.data)); 115
116 mainButtonClone.setToggled(action.toggled());
117 buttons.push(mainButtonClone);
118
119 var document = button.element.ownerDocument;
120 document.documentElement.addEventListener('mouseup', mouseUp, false);
121
122 var optionsGlassPane = new WebInspector.GlassPane(document);
123 var optionsBar = new WebInspector.Toolbar('fill', optionsGlassPane.element );
124 optionsBar._contentElement.classList.add('floating');
125 const buttonHeight = 26;
126
127 var hostButtonPosition = button.element.totalOffset();
128
129 var topNotBottom = hostButtonPosition.top + buttonHeight * buttons.length < document.documentElement.offsetHeight;
130
131 if (topNotBottom)
132 buttons = buttons.reverse();
133
134 optionsBar.element.style.height = (buttonHeight * buttons.length) + 'px';
135 if (topNotBottom)
136 optionsBar.element.style.top = (hostButtonPosition.top + 1) + 'px';
137 else
138 optionsBar.element.style.top = (hostButtonPosition.top - (buttonHeight * (buttons.length - 1))) + 'px';
139 optionsBar.element.style.left = (hostButtonPosition.left + 1) + 'px';
140
141 for (var i = 0; i < buttons.length; ++i) {
142 buttons[i].element.addEventListener('mousemove', mouseOver, false);
143 buttons[i].element.addEventListener('mouseout', mouseOut, false);
144 optionsBar.appendToolbarItem(buttons[i]);
145 }
146 var hostButtonIndex = topNotBottom ? 0 : buttons.length - 1;
147 buttons[hostButtonIndex].element.classList.add('emulate-active');
148
149 function mouseOver(e) {
150 if (e.which !== 1)
151 return;
152 var buttonElement = e.target.enclosingNodeOrSelfWithClass('toolbar-item' );
153 buttonElement.classList.add('emulate-active');
154 }
155
156 function mouseOut(e) {
157 if (e.which !== 1)
158 return;
159 var buttonElement = e.target.enclosingNodeOrSelfWithClass('toolbar-item' );
160 buttonElement.classList.remove('emulate-active');
161 }
162
163 function mouseUp(e) {
164 if (e.which !== 1)
165 return;
166 optionsGlassPane.dispose();
167 document.documentElement.removeEventListener('mouseup', mouseUp, false);
168
169 for (var i = 0; i < buttons.length; ++i) {
170 if (buttons[i].element.classList.contains('emulate-active')) {
171 buttons[i].element.classList.remove('emulate-active');
172 buttons[i]._clicked(e);
173 break;
174 }
604 } 175 }
605 176 }
606 mainButtonClone.setToggled(action.toggled());
607 buttons.push(mainButtonClone);
608
609 var document = button.element.ownerDocument;
610 document.documentElement.addEventListener("mouseup", mouseUp, false);
611
612 var optionsGlassPane = new WebInspector.GlassPane(document);
613 var optionsBar = new WebInspector.Toolbar("fill", optionsGlassPane.eleme nt);
614 optionsBar._contentElement.classList.add("floating");
615 const buttonHeight = 26;
616
617 var hostButtonPosition = button.element.totalOffset();
618
619 var topNotBottom = hostButtonPosition.top + buttonHeight * buttons.lengt h < document.documentElement.offsetHeight;
620
621 if (topNotBottom)
622 buttons = buttons.reverse();
623
624 optionsBar.element.style.height = (buttonHeight * buttons.length) + "px" ;
625 if (topNotBottom)
626 optionsBar.element.style.top = (hostButtonPosition.top + 1) + "px";
627 else
628 optionsBar.element.style.top = (hostButtonPosition.top - (buttonHeig ht * (buttons.length - 1))) + "px";
629 optionsBar.element.style.left = (hostButtonPosition.left + 1) + "px";
630
631 for (var i = 0; i < buttons.length; ++i) {
632 buttons[i].element.addEventListener("mousemove", mouseOver, false);
633 buttons[i].element.addEventListener("mouseout", mouseOut, false);
634 optionsBar.appendToolbarItem(buttons[i]);
635 }
636 var hostButtonIndex = topNotBottom ? 0 : buttons.length - 1;
637 buttons[hostButtonIndex].element.classList.add("emulate-active");
638
639 function mouseOver(e)
640 {
641 if (e.which !== 1)
642 return;
643 var buttonElement = e.target.enclosingNodeOrSelfWithClass("toolbar-i tem");
644 buttonElement.classList.add("emulate-active");
645 }
646
647 function mouseOut(e)
648 {
649 if (e.which !== 1)
650 return;
651 var buttonElement = e.target.enclosingNodeOrSelfWithClass("toolbar-i tem");
652 buttonElement.classList.remove("emulate-active");
653 }
654
655 function mouseUp(e)
656 {
657 if (e.which !== 1)
658 return;
659 optionsGlassPane.dispose();
660 document.documentElement.removeEventListener("mouseup", mouseUp, fal se);
661
662 for (var i = 0; i < buttons.length; ++i) {
663 if (buttons[i].element.classList.contains("emulate-active")) {
664 buttons[i].element.classList.remove("emulate-active");
665 buttons[i]._clicked(e);
666 break;
667 }
668 }
669 }
670 } 177 }
671 }; 178 }
672 179
673 /** 180 /**
674 * @param {string} actionId 181 * @param {string} actionId
675 * @return {?WebInspector.ToolbarItem} 182 * @return {?WebInspector.ToolbarItem}
676 */ 183 */
677 WebInspector.Toolbar.createActionButtonForId = function(actionId) 184 static createActionButtonForId(actionId) {
678 {
679 var action = WebInspector.actionRegistry.action(actionId); 185 var action = WebInspector.actionRegistry.action(actionId);
680 return /** @type {?WebInspector.ToolbarItem} */(action ? WebInspector.Toolba r.createActionButton(action) : null); 186 return /** @type {?WebInspector.ToolbarItem} */ (action ? WebInspector.Toolb ar.createActionButton(action) : null);
681 }; 187 }
682 188
683 /** 189 /**
684 * @constructor 190 * @param {boolean=} reverse
685 * @extends {WebInspector.ToolbarButton} 191 */
686 * @param {function(!WebInspector.ContextMenu)} contextMenuHandler 192 makeWrappable(reverse) {
687 * @param {boolean=} useSoftMenu 193 this._contentElement.classList.add('wrappable');
688 */ 194 this._reverse = !!reverse;
689 WebInspector.ToolbarMenuButton = function(contextMenuHandler, useSoftMenu) 195 if (reverse)
690 { 196 this._contentElement.classList.add('wrappable-reverse');
691 WebInspector.ToolbarButton.call(this, "", "menu-toolbar-item"); 197 }
198
199 makeVertical() {
200 this._contentElement.classList.add('vertical');
201 }
202
203 makeBlueOnHover() {
204 this._contentElement.classList.add('toolbar-blue-on-hover');
205 }
206
207 makeToggledGray() {
208 this._contentElement.classList.add('toolbar-toggled-gray');
209 }
210
211 renderAsLinks() {
212 this._contentElement.classList.add('toolbar-render-as-links');
213 }
214
215 /**
216 * @param {boolean} enabled
217 */
218 setEnabled(enabled) {
219 for (var item of this._items)
220 item.setEnabled(enabled);
221 }
222
223 /**
224 * @param {!WebInspector.ToolbarItem} item
225 */
226 appendToolbarItem(item) {
227 this._items.push(item);
228 item._toolbar = this;
229 if (this._reverse)
230 this._contentElement.insertBefore(item.element, this._insertionPoint.nextS ibling);
231 else
232 this._contentElement.insertBefore(item.element, this._insertionPoint);
233 this._hideSeparatorDupes();
234 }
235
236 appendSeparator() {
237 this.appendToolbarItem(new WebInspector.ToolbarSeparator());
238 }
239
240 appendSpacer() {
241 this.appendToolbarItem(new WebInspector.ToolbarSeparator(true));
242 }
243
244 /**
245 * @param {string} text
246 */
247 appendText(text) {
248 this.appendToolbarItem(new WebInspector.ToolbarText(text));
249 }
250
251 removeToolbarItems() {
252 for (var item of this._items)
253 delete item._toolbar;
254 this._items = [];
255 this._contentElement.removeChildren();
256 this._insertionPoint = this._contentElement.createChild('content');
257 }
258
259 /**
260 * @param {string} color
261 */
262 setColor(color) {
263 var style = createElement('style');
264 style.textContent = '.toolbar-glyph { background-color: ' + color + ' !impor tant }';
265 this._shadowRoot.appendChild(style);
266 }
267
268 /**
269 * @param {string} color
270 */
271 setToggledColor(color) {
272 var style = createElement('style');
273 style.textContent =
274 '.toolbar-button.toolbar-state-on .toolbar-glyph { background-color: ' + color + ' !important }';
275 this._shadowRoot.appendChild(style);
276 }
277
278 _hideSeparatorDupes() {
279 if (!this._items.length)
280 return;
281 // Don't hide first and last separators if they were added explicitly.
282 var previousIsSeparator = false;
283 var lastSeparator;
284 var nonSeparatorVisible = false;
285 for (var i = 0; i < this._items.length; ++i) {
286 if (this._items[i] instanceof WebInspector.ToolbarSeparator) {
287 this._items[i].setVisible(!previousIsSeparator);
288 previousIsSeparator = true;
289 lastSeparator = this._items[i];
290 continue;
291 }
292 if (this._items[i].visible()) {
293 previousIsSeparator = false;
294 lastSeparator = null;
295 nonSeparatorVisible = true;
296 }
297 }
298 if (lastSeparator && lastSeparator !== this._items.peekLast())
299 lastSeparator.setVisible(false);
300
301 this.element.classList.toggle('hidden', !!lastSeparator && lastSeparator.vis ible() && !nonSeparatorVisible);
302 }
303
304 /**
305 * @param {string} location
306 */
307 appendLocationItems(location) {
308 var extensions = self.runtime.extensions(WebInspector.ToolbarItem.Provider);
309 var promises = [];
310 for (var i = 0; i < extensions.length; ++i) {
311 if (extensions[i].descriptor()['location'] === location)
312 promises.push(resolveItem(extensions[i]));
313 }
314 Promise.all(promises).then(appendItemsInOrder.bind(this));
315
316 /**
317 * @param {!Runtime.Extension} extension
318 * @return {!Promise.<?WebInspector.ToolbarItem>}
319 */
320 function resolveItem(extension) {
321 var descriptor = extension.descriptor();
322 if (descriptor['separator'])
323 return Promise.resolve(/** @type {?WebInspector.ToolbarItem} */ (new Web Inspector.ToolbarSeparator()));
324 if (descriptor['actionId'])
325 return Promise.resolve(WebInspector.Toolbar.createActionButtonForId(desc riptor['actionId']));
326 return extension.instance().then(fetchItemFromProvider);
327
328 /**
329 * @param {!Object} provider
330 */
331 function fetchItemFromProvider(provider) {
332 return /** @type {!WebInspector.ToolbarItem.Provider} */ (provider).item ();
333 }
334 }
335
336 /**
337 * @param {!Array.<?WebInspector.ToolbarItem>} items
338 * @this {WebInspector.Toolbar}
339 */
340 function appendItemsInOrder(items) {
341 for (var i = 0; i < items.length; ++i) {
342 var item = items[i];
343 if (item)
344 this.appendToolbarItem(item);
345 }
346 }
347 }
348 };
349
350 /**
351 * @unrestricted
352 */
353 WebInspector.ToolbarItem = class extends WebInspector.Object {
354 /**
355 * @param {!Element} element
356 */
357 constructor(element) {
358 super();
359 this.element = element;
360 this.element.classList.add('toolbar-item');
361 this._visible = true;
362 this._enabled = true;
363 this.element.addEventListener('mouseenter', this._mouseEnter.bind(this), fal se);
364 this.element.addEventListener('mouseleave', this._mouseLeave.bind(this), fal se);
365 }
366
367 /**
368 * @param {string} title
369 */
370 setTitle(title) {
371 if (this._title === title)
372 return;
373 this._title = title;
374 WebInspector.Tooltip.install(this.element, title);
375 }
376
377 _mouseEnter() {
378 this.element.classList.add('hover');
379 }
380
381 _mouseLeave() {
382 this.element.classList.remove('hover');
383 }
384
385 /**
386 * @param {boolean} value
387 */
388 setEnabled(value) {
389 if (this._enabled === value)
390 return;
391 this._enabled = value;
392 this._applyEnabledState();
393 }
394
395 _applyEnabledState() {
396 this.element.disabled = !this._enabled;
397 }
398
399 /**
400 * @return {boolean} x
401 */
402 visible() {
403 return this._visible;
404 }
405
406 /**
407 * @param {boolean} x
408 */
409 setVisible(x) {
410 if (this._visible === x)
411 return;
412 this.element.classList.toggle('hidden', !x);
413 this._visible = x;
414 if (this._toolbar && !(this instanceof WebInspector.ToolbarSeparator))
415 this._toolbar._hideSeparatorDupes();
416 }
417 };
418
419 /**
420 * @unrestricted
421 */
422 WebInspector.ToolbarText = class extends WebInspector.ToolbarItem {
423 /**
424 * @param {string=} text
425 */
426 constructor(text) {
427 super(createElementWithClass('div', 'toolbar-text'));
428 this.element.classList.add('toolbar-text');
429 this.setText(text || '');
430 }
431
432 /**
433 * @param {string} text
434 */
435 setText(text) {
436 this.element.textContent = text;
437 }
438 };
439
440 /**
441 * @unrestricted
442 */
443 WebInspector.ToolbarButton = class extends WebInspector.ToolbarItem {
444 /**
445 * @param {string} title
446 * @param {string=} glyph
447 * @param {string=} text
448 */
449 constructor(title, glyph, text) {
450 super(createElementWithClass('button', 'toolbar-button'));
451 this.element.addEventListener('click', this._clicked.bind(this), false);
452 this.element.addEventListener('mousedown', this._mouseDown.bind(this), false );
453 this.element.addEventListener('mouseup', this._mouseUp.bind(this), false);
454
455 this._glyphElement = this.element.createChild('div', 'toolbar-glyph hidden') ;
456 this._textElement = this.element.createChild('div', 'toolbar-text hidden');
457
458 this.setTitle(title);
459 if (glyph)
460 this.setGlyph(glyph);
461 this.setText(text || '');
462 this._state = '';
463 this._title = '';
464 }
465
466 /**
467 * @param {string} text
468 */
469 setText(text) {
470 if (this._text === text)
471 return;
472 this._textElement.textContent = text;
473 this._textElement.classList.toggle('hidden', !text);
474 this._text = text;
475 }
476
477 /**
478 * @param {string} glyph
479 */
480 setGlyph(glyph) {
481 if (this._glyph === glyph)
482 return;
483 if (this._glyph)
484 this._glyphElement.classList.remove(this._glyph);
485 if (glyph)
486 this._glyphElement.classList.add(glyph);
487 this._glyphElement.classList.toggle('hidden', !glyph);
488 this.element.classList.toggle('toolbar-has-glyph', !!glyph);
489 this._glyph = glyph;
490 }
491
492 /**
493 * @param {string} iconURL
494 */
495 setBackgroundImage(iconURL) {
496 this.element.style.backgroundImage = 'url(' + iconURL + ')';
497 }
498
499 /**
500 * @return {string}
501 */
502 state() {
503 return this._state;
504 }
505
506 /**
507 * @param {string} state
508 */
509 setState(state) {
510 if (this._state === state)
511 return;
512 this.element.classList.remove('toolbar-state-' + this._state);
513 this.element.classList.add('toolbar-state-' + state);
514 this._state = state;
515 }
516
517 /**
518 * @param {number=} width
519 */
520 turnIntoSelect(width) {
521 this.element.classList.add('toolbar-has-dropdown');
522 this.element.createChild('div', 'toolbar-dropdown-arrow');
523 if (width)
524 this.element.style.width = width + 'px';
525 }
526
527 /**
528 * @param {!Event} event
529 */
530 _clicked(event) {
531 var defaultPrevented = this.dispatchEventToListeners('click', event);
532 event.consume(defaultPrevented);
533 }
534
535 /**
536 * @param {!Event} event
537 */
538 _mouseDown(event) {
539 this.dispatchEventToListeners('mousedown', event);
540 }
541
542 /**
543 * @param {!Event} event
544 */
545 _mouseUp(event) {
546 this.dispatchEventToListeners('mouseup', event);
547 }
548 };
549
550 /**
551 * @unrestricted
552 */
553 WebInspector.ToolbarInput = class extends WebInspector.ToolbarItem {
554 /**
555 * @param {string=} placeholder
556 * @param {number=} growFactor
557 */
558 constructor(placeholder, growFactor) {
559 super(createElementWithClass('input', 'toolbar-item'));
560 this.element.addEventListener('input', this._onChangeCallback.bind(this), fa lse);
561 if (growFactor)
562 this.element.style.flexGrow = growFactor;
563 if (placeholder)
564 this.element.setAttribute('placeholder', placeholder);
565 this._value = '';
566 }
567
568 /**
569 * @param {string} value
570 */
571 setValue(value) {
572 this._value = value;
573 this.element.value = value;
574 }
575
576 /**
577 * @return {string}
578 */
579 value() {
580 return this.element.value;
581 }
582
583 _onChangeCallback() {
584 this.dispatchEventToListeners(WebInspector.ToolbarInput.Event.TextChanged, t his.element.value);
585 }
586 };
587
588 WebInspector.ToolbarInput.Event = {
589 TextChanged: 'TextChanged'
590 };
591
592 /**
593 * @unrestricted
594 */
595 WebInspector.ToolbarToggle = class extends WebInspector.ToolbarButton {
596 /**
597 * @param {string} title
598 * @param {string=} glyph
599 * @param {string=} text
600 */
601 constructor(title, glyph, text) {
602 super(title, glyph, text);
603 this._toggled = false;
604 this.setState('off');
605 }
606
607 /**
608 * @return {boolean}
609 */
610 toggled() {
611 return this._toggled;
612 }
613
614 /**
615 * @param {boolean} toggled
616 */
617 setToggled(toggled) {
618 if (this._toggled === toggled)
619 return;
620 this._toggled = toggled;
621 this.setState(toggled ? 'on' : 'off');
622 }
623 };
624
625
626 /**
627 * @unrestricted
628 */
629 WebInspector.ToolbarMenuButton = class extends WebInspector.ToolbarButton {
630 /**
631 * @param {function(!WebInspector.ContextMenu)} contextMenuHandler
632 * @param {boolean=} useSoftMenu
633 */
634 constructor(contextMenuHandler, useSoftMenu) {
635 super('', 'menu-toolbar-item');
692 this._contextMenuHandler = contextMenuHandler; 636 this._contextMenuHandler = contextMenuHandler;
693 this._useSoftMenu = !!useSoftMenu; 637 this._useSoftMenu = !!useSoftMenu;
694 }; 638 }
695 639
696 WebInspector.ToolbarMenuButton.prototype = { 640 /**
697 /** 641 * @override
698 * @override 642 * @param {!Event} event
699 * @param {!Event} event 643 */
700 */ 644 _mouseDown(event) {
701 _mouseDown: function(event) 645 if (event.buttons !== 1) {
702 { 646 super._mouseDown(event);
703 if (event.buttons !== 1) { 647 return;
704 WebInspector.ToolbarButton.prototype._mouseDown.call(this, event); 648 }
705 return; 649
706 } 650 if (!this._triggerTimeout)
707 651 this._triggerTimeout = setTimeout(this._trigger.bind(this, event), 200);
708 if (!this._triggerTimeout) 652 }
709 this._triggerTimeout = setTimeout(this._trigger.bind(this, event), 2 00); 653
710 }, 654 /**
711 655 * @param {!Event} event
712 /** 656 */
713 * @param {!Event} event 657 _trigger(event) {
714 */ 658 delete this._triggerTimeout;
715 _trigger: function(event) 659 var contextMenu = new WebInspector.ContextMenu(
716 { 660 event, this._useSoftMenu, this.element.totalOffsetLeft(),
717 delete this._triggerTimeout; 661 this.element.totalOffsetTop() + this.element.offsetHeight);
718 var contextMenu = new WebInspector.ContextMenu(event, 662 this._contextMenuHandler(contextMenu);
719 this._useSoftMenu, 663 contextMenu.show();
720 this.element.totalOffsetLeft(), 664 }
721 this.element.totalOffsetTop() + this.element.offsetHeight); 665
722 this._contextMenuHandler(contextMenu); 666 /**
723 contextMenu.show(); 667 * @override
724 }, 668 * @param {!Event} event
725 669 */
726 /** 670 _clicked(event) {
727 * @override 671 if (!this._triggerTimeout)
728 * @param {!Event} event 672 return;
729 */ 673 clearTimeout(this._triggerTimeout);
730 _clicked: function(event) 674 this._trigger(event);
731 { 675 }
732 if (!this._triggerTimeout) 676 };
733 return; 677
734 clearTimeout(this._triggerTimeout); 678 /**
735 this._trigger(event); 679 * @unrestricted
736 }, 680 */
737 681 WebInspector.ToolbarSettingToggle = class extends WebInspector.ToolbarToggle {
738 __proto__: WebInspector.ToolbarButton.prototype 682 /**
739 }; 683 * @param {!WebInspector.Setting} setting
740 684 * @param {string} glyph
741 /** 685 * @param {string} title
742 * @constructor 686 * @param {string=} toggledTitle
743 * @extends {WebInspector.ToolbarToggle} 687 */
744 * @param {!WebInspector.Setting} setting 688 constructor(setting, glyph, title, toggledTitle) {
745 * @param {string} glyph 689 super(title, glyph);
746 * @param {string} title
747 * @param {string=} toggledTitle
748 */
749 WebInspector.ToolbarSettingToggle = function(setting, glyph, title, toggledTitle )
750 {
751 WebInspector.ToolbarToggle.call(this, title, glyph);
752 this._defaultTitle = title; 690 this._defaultTitle = title;
753 this._toggledTitle = toggledTitle || title; 691 this._toggledTitle = toggledTitle || title;
754 this._setting = setting; 692 this._setting = setting;
755 this._settingChanged(); 693 this._settingChanged();
756 this._setting.addChangeListener(this._settingChanged, this); 694 this._setting.addChangeListener(this._settingChanged, this);
757 }; 695 }
758 696
759 WebInspector.ToolbarSettingToggle.prototype = { 697 _settingChanged() {
760 _settingChanged: function() 698 var toggled = this._setting.get();
761 { 699 this.setToggled(toggled);
762 var toggled = this._setting.get(); 700 this.setTitle(toggled ? this._toggledTitle : this._defaultTitle);
763 this.setToggled(toggled); 701 }
764 this.setTitle(toggled ? this._toggledTitle : this._defaultTitle); 702
765 }, 703 /**
766 704 * @override
767 /** 705 * @param {!Event} event
768 * @override 706 */
769 * @param {!Event} event 707 _clicked(event) {
770 */ 708 this._setting.set(!this.toggled());
771 _clicked: function(event) 709 super._clicked(event);
772 { 710 }
773 this._setting.set(!this.toggled()); 711 };
774 WebInspector.ToolbarToggle.prototype._clicked.call(this, event); 712
775 }, 713 /**
776 714 * @unrestricted
777 __proto__: WebInspector.ToolbarToggle.prototype 715 */
778 }; 716 WebInspector.ToolbarSeparator = class extends WebInspector.ToolbarItem {
779 717 /**
780 /** 718 * @param {boolean=} spacer
781 * @constructor 719 */
782 * @extends {WebInspector.ToolbarItem} 720 constructor(spacer) {
783 * @param {boolean=} spacer 721 super(createElementWithClass('div', spacer ? 'toolbar-spacer' : 'toolbar-div ider'));
784 */ 722 }
785 WebInspector.ToolbarSeparator = function(spacer)
786 {
787 WebInspector.ToolbarItem.call(this, createElementWithClass("div", spacer ? " toolbar-spacer" : "toolbar-divider"));
788 };
789
790 WebInspector.ToolbarSeparator.prototype = {
791 __proto__: WebInspector.ToolbarItem.prototype
792 }; 723 };
793 724
794 /** 725 /**
795 * @interface 726 * @interface
796 */ 727 */
797 WebInspector.ToolbarItem.Provider = function() 728 WebInspector.ToolbarItem.Provider = function() {};
798 {
799 };
800 729
801 WebInspector.ToolbarItem.Provider.prototype = { 730 WebInspector.ToolbarItem.Provider.prototype = {
802 /** 731 /**
803 * @return {?WebInspector.ToolbarItem} 732 * @return {?WebInspector.ToolbarItem}
804 */ 733 */
805 item: function() {} 734 item: function() {}
806 }; 735 };
807 736
808 /** 737 /**
809 * @interface 738 * @interface
810 */ 739 */
811 WebInspector.ToolbarItem.ItemsProvider = function() 740 WebInspector.ToolbarItem.ItemsProvider = function() {};
812 {
813 };
814 741
815 WebInspector.ToolbarItem.ItemsProvider.prototype = { 742 WebInspector.ToolbarItem.ItemsProvider.prototype = {
816 /** 743 /**
817 * @return {!Array<!WebInspector.ToolbarItem>} 744 * @return {!Array<!WebInspector.ToolbarItem>}
818 */ 745 */
819 toolbarItems: function() {} 746 toolbarItems: function() {}
820 }; 747 };
821 748
822 /** 749 /**
823 * @constructor 750 * @unrestricted
824 * @extends {WebInspector.ToolbarItem} 751 */
825 * @param {?function(!Event)} changeHandler 752 WebInspector.ToolbarComboBox = class extends WebInspector.ToolbarItem {
826 * @param {string=} className 753 /**
827 */ 754 * @param {?function(!Event)} changeHandler
828 WebInspector.ToolbarComboBox = function(changeHandler, className) 755 * @param {string=} className
829 { 756 */
830 WebInspector.ToolbarItem.call(this, createElementWithClass("span", "toolbar- select-container")); 757 constructor(changeHandler, className) {
831 758 super(createElementWithClass('span', 'toolbar-select-container'));
832 this._selectElement = this.element.createChild("select", "toolbar-item"); 759
833 this.element.createChild("div", "toolbar-dropdown-arrow"); 760 this._selectElement = this.element.createChild('select', 'toolbar-item');
761 this.element.createChild('div', 'toolbar-dropdown-arrow');
834 if (changeHandler) 762 if (changeHandler)
835 this._selectElement.addEventListener("change", changeHandler, false); 763 this._selectElement.addEventListener('change', changeHandler, false);
836 if (className) 764 if (className)
837 this._selectElement.classList.add(className); 765 this._selectElement.classList.add(className);
838 }; 766 }
839 767
840 WebInspector.ToolbarComboBox.prototype = { 768 /**
841 /** 769 * @return {!HTMLSelectElement}
842 * @return {!HTMLSelectElement} 770 */
843 */ 771 selectElement() {
844 selectElement: function() 772 return /** @type {!HTMLSelectElement} */ (this._selectElement);
845 { 773 }
846 return /** @type {!HTMLSelectElement} */ (this._selectElement); 774
847 }, 775 /**
848 776 * @return {number}
849 /** 777 */
850 * @return {number} 778 size() {
851 */ 779 return this._selectElement.childElementCount;
852 size: function() 780 }
853 { 781
854 return this._selectElement.childElementCount; 782 /**
855 }, 783 * @return {!Array.<!Element>}
856 784 */
857 /** 785 options() {
858 * @return {!Array.<!Element>} 786 return Array.prototype.slice.call(this._selectElement.children, 0);
859 */ 787 }
860 options: function() 788
861 { 789 /**
862 return Array.prototype.slice.call(this._selectElement.children, 0); 790 * @param {!Element} option
863 }, 791 */
864 792 addOption(option) {
865 /** 793 this._selectElement.appendChild(option);
866 * @param {!Element} option 794 }
867 */ 795
868 addOption: function(option) 796 /**
869 { 797 * @param {string} label
870 this._selectElement.appendChild(option); 798 * @param {string=} title
871 }, 799 * @param {string=} value
872 800 * @return {!Element}
873 /** 801 */
874 * @param {string} label 802 createOption(label, title, value) {
875 * @param {string=} title 803 var option = this._selectElement.createChild('option');
876 * @param {string=} value 804 option.text = label;
877 * @return {!Element} 805 if (title)
878 */ 806 option.title = title;
879 createOption: function(label, title, value) 807 if (typeof value !== 'undefined')
880 { 808 option.value = value;
881 var option = this._selectElement.createChild("option"); 809 return option;
882 option.text = label; 810 }
883 if (title) 811
884 option.title = title; 812 /**
885 if (typeof value !== "undefined") 813 * @override
886 option.value = value; 814 */
887 return option; 815 _applyEnabledState() {
888 }, 816 this._selectElement.disabled = !this._enabled;
889 817 }
890 /** 818
891 * @override 819 /**
892 */ 820 * @param {!Element} option
893 _applyEnabledState: function() 821 */
894 { 822 removeOption(option) {
895 this._selectElement.disabled = !this._enabled; 823 this._selectElement.removeChild(option);
896 }, 824 }
897 825
898 /** 826 removeOptions() {
899 * @param {!Element} option 827 this._selectElement.removeChildren();
900 */ 828 }
901 removeOption: function(option) 829
902 { 830 /**
903 this._selectElement.removeChild(option); 831 * @return {?Element}
904 }, 832 */
905 833 selectedOption() {
906 removeOptions: function() 834 if (this._selectElement.selectedIndex >= 0)
907 { 835 return this._selectElement[this._selectElement.selectedIndex];
908 this._selectElement.removeChildren(); 836 return null;
909 }, 837 }
910 838
911 /** 839 /**
912 * @return {?Element} 840 * @param {!Element} option
913 */ 841 */
914 selectedOption: function() 842 select(option) {
915 { 843 this._selectElement.selectedIndex = Array.prototype.indexOf.call(/** @type { ?} */ (this._selectElement), option);
916 if (this._selectElement.selectedIndex >= 0) 844 }
917 return this._selectElement[this._selectElement.selectedIndex]; 845
918 return null; 846 /**
919 }, 847 * @param {number} index
920 848 */
921 /** 849 setSelectedIndex(index) {
922 * @param {!Element} option 850 this._selectElement.selectedIndex = index;
923 */ 851 }
924 select: function(option) 852
925 { 853 /**
926 this._selectElement.selectedIndex = Array.prototype.indexOf.call(/** @ty pe {?} */ (this._selectElement), option); 854 * @return {number}
927 }, 855 */
928 856 selectedIndex() {
929 /** 857 return this._selectElement.selectedIndex;
930 * @param {number} index 858 }
931 */ 859
932 setSelectedIndex: function(index) 860 /**
933 { 861 * @param {number} width
934 this._selectElement.selectedIndex = index; 862 */
935 }, 863 setMaxWidth(width) {
936 864 this._selectElement.style.maxWidth = width + 'px';
937 /** 865 }
938 * @return {number} 866 };
939 */ 867
940 selectedIndex: function() 868 /**
941 { 869 * @unrestricted
942 return this._selectElement.selectedIndex; 870 */
943 }, 871 WebInspector.ToolbarCheckbox = class extends WebInspector.ToolbarItem {
944 872 /**
945 /** 873 * @param {string} text
946 * @param {number} width 874 * @param {string=} title
947 */ 875 * @param {!WebInspector.Setting=} setting
948 setMaxWidth: function(width) 876 * @param {function()=} listener
949 { 877 */
950 this._selectElement.style.maxWidth = width + "px"; 878 constructor(text, title, setting, listener) {
951 }, 879 super(createCheckboxLabel(text));
952 880 this.element.classList.add('checkbox');
953 __proto__: WebInspector.ToolbarItem.prototype
954 };
955
956 /**
957 * @constructor
958 * @extends {WebInspector.ToolbarItem}
959 * @param {string} text
960 * @param {string=} title
961 * @param {!WebInspector.Setting=} setting
962 * @param {function()=} listener
963 */
964 WebInspector.ToolbarCheckbox = function(text, title, setting, listener)
965 {
966 WebInspector.ToolbarItem.call(this, createCheckboxLabel(text));
967 this.element.classList.add("checkbox");
968 this.inputElement = this.element.checkboxElement; 881 this.inputElement = this.element.checkboxElement;
969 if (title) 882 if (title)
970 this.element.title = title; 883 this.element.title = title;
971 if (setting) 884 if (setting)
972 WebInspector.SettingsUI.bindCheckbox(this.inputElement, setting); 885 WebInspector.SettingsUI.bindCheckbox(this.inputElement, setting);
973 if (listener) 886 if (listener)
974 this.inputElement.addEventListener("click", listener, false); 887 this.inputElement.addEventListener('click', listener, false);
975 }; 888 }
976 889
977 WebInspector.ToolbarCheckbox.prototype = { 890 /**
978 /** 891 * @return {boolean}
979 * @return {boolean} 892 */
980 */ 893 checked() {
981 checked: function() 894 return this.inputElement.checked;
982 { 895 }
983 return this.inputElement.checked; 896
984 }, 897 /**
985 898 * @param {boolean} value
986 /** 899 */
987 * @param {boolean} value 900 setChecked(value) {
988 */ 901 this.inputElement.checked = value;
989 setChecked: function(value) 902 }
990 { 903 };
991 this.inputElement.checked = value;
992 },
993
994 __proto__: WebInspector.ToolbarItem.prototype
995 };
996
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698