OLD | NEW |
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 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
48 this._insertionPoint = this._contentElement.createChild('content'); | 48 this._insertionPoint = this._contentElement.createChild('content'); |
49 } | 49 } |
50 | 50 |
51 /** | 51 /** |
52 * @param {!WebInspector.Action} action | 52 * @param {!WebInspector.Action} action |
53 * @param {!Array<!WebInspector.ToolbarButton>=} toggledOptions | 53 * @param {!Array<!WebInspector.ToolbarButton>=} toggledOptions |
54 * @param {!Array<!WebInspector.ToolbarButton>=} untoggledOptions | 54 * @param {!Array<!WebInspector.ToolbarButton>=} untoggledOptions |
55 * @return {!WebInspector.ToolbarItem} | 55 * @return {!WebInspector.ToolbarItem} |
56 */ | 56 */ |
57 static createActionButton(action, toggledOptions, untoggledOptions) { | 57 static createActionButton(action, toggledOptions, untoggledOptions) { |
58 var button = new WebInspector.ToolbarToggle(action.title(), action.icon()); | 58 var button = new WebInspector.ToolbarToggle(action.title(), action.icon(), a
ction.toggledIcon()); |
| 59 button.setToggleWithRedColor(action.toggleWithRedColor()); |
59 button.addEventListener('click', action.execute, action); | 60 button.addEventListener('click', action.execute, action); |
60 action.addEventListener(WebInspector.Action.Events.Enabled, enabledChanged); | 61 action.addEventListener(WebInspector.Action.Events.Enabled, enabledChanged); |
61 action.addEventListener(WebInspector.Action.Events.Toggled, toggled); | 62 action.addEventListener(WebInspector.Action.Events.Toggled, toggled); |
62 /** @type {?WebInspector.LongClickController} */ | 63 /** @type {?WebInspector.LongClickController} */ |
63 var longClickController = null; | 64 var longClickController = null; |
64 /** @type {?Array<!WebInspector.ToolbarButton>} */ | 65 /** @type {?Array<!WebInspector.ToolbarButton>} */ |
65 var longClickButtons = null; | 66 var longClickButtons = null; |
66 /** @type {?Element} */ | 67 /** @type {?Element} */ |
67 var longClickGlyph = null; | 68 var longClickGlyph = null; |
68 toggled(); | 69 toggled(); |
(...skipping 28 matching lines...) Expand all Loading... |
97 longClickController = null; | 98 longClickController = null; |
98 longClickGlyph.remove(); | 99 longClickGlyph.remove(); |
99 longClickGlyph = null; | 100 longClickGlyph = null; |
100 longClickButtons = null; | 101 longClickButtons = null; |
101 } | 102 } |
102 } | 103 } |
103 } | 104 } |
104 | 105 |
105 function showOptions() { | 106 function showOptions() { |
106 var buttons = longClickButtons.slice(); | 107 var buttons = longClickButtons.slice(); |
107 var mainButtonClone = new WebInspector.ToolbarToggle(action.title(), actio
n.icon()); | 108 var mainButtonClone = new WebInspector.ToolbarToggle(action.title(), actio
n.icon(), action.toggledIcon()); |
108 mainButtonClone.addEventListener('click', clicked); | 109 mainButtonClone.addEventListener('click', clicked); |
109 | 110 |
110 /** | 111 /** |
111 * @param {!WebInspector.Event} event | 112 * @param {!WebInspector.Event} event |
112 */ | 113 */ |
113 function clicked(event) { | 114 function clicked(event) { |
114 button._clicked(/** @type {!Event} */ (event.data)); | 115 button._clicked(/** @type {!Event} */ (event.data)); |
115 } | 116 } |
116 | 117 |
117 mainButtonClone.setToggled(action.toggled()); | 118 mainButtonClone.setToggled(action.toggled()); |
(...skipping 335 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
453 this.element.addEventListener('mousedown', this._mouseDown.bind(this), false
); | 454 this.element.addEventListener('mousedown', this._mouseDown.bind(this), false
); |
454 this.element.addEventListener('mouseup', this._mouseUp.bind(this), false); | 455 this.element.addEventListener('mouseup', this._mouseUp.bind(this), false); |
455 | 456 |
456 this._glyphElement = this.element.createChild('div', 'toolbar-glyph hidden')
; | 457 this._glyphElement = this.element.createChild('div', 'toolbar-glyph hidden')
; |
457 this._textElement = this.element.createChild('div', 'toolbar-text hidden'); | 458 this._textElement = this.element.createChild('div', 'toolbar-text hidden'); |
458 | 459 |
459 this.setTitle(title); | 460 this.setTitle(title); |
460 if (glyph) | 461 if (glyph) |
461 this.setGlyph(glyph); | 462 this.setGlyph(glyph); |
462 this.setText(text || ''); | 463 this.setText(text || ''); |
463 this._state = ''; | |
464 this._title = ''; | 464 this._title = ''; |
465 } | 465 } |
466 | 466 |
467 /** | 467 /** |
468 * @param {string} text | 468 * @param {string} text |
469 */ | 469 */ |
470 setText(text) { | 470 setText(text) { |
471 if (this._text === text) | 471 if (this._text === text) |
472 return; | 472 return; |
473 this._textElement.textContent = text; | 473 this._textElement.textContent = text; |
(...skipping 17 matching lines...) Expand all Loading... |
491 } | 491 } |
492 | 492 |
493 /** | 493 /** |
494 * @param {string} iconURL | 494 * @param {string} iconURL |
495 */ | 495 */ |
496 setBackgroundImage(iconURL) { | 496 setBackgroundImage(iconURL) { |
497 this.element.style.backgroundImage = 'url(' + iconURL + ')'; | 497 this.element.style.backgroundImage = 'url(' + iconURL + ')'; |
498 } | 498 } |
499 | 499 |
500 /** | 500 /** |
501 * @return {string} | |
502 */ | |
503 state() { | |
504 return this._state; | |
505 } | |
506 | |
507 /** | |
508 * @param {string} state | |
509 */ | |
510 setState(state) { | |
511 if (this._state === state) | |
512 return; | |
513 this.element.classList.remove('toolbar-state-' + this._state); | |
514 this.element.classList.add('toolbar-state-' + state); | |
515 this._state = state; | |
516 } | |
517 | |
518 /** | |
519 * @param {number=} width | 501 * @param {number=} width |
520 */ | 502 */ |
521 turnIntoSelect(width) { | 503 turnIntoSelect(width) { |
522 this.element.classList.add('toolbar-has-dropdown'); | 504 this.element.classList.add('toolbar-has-dropdown'); |
523 this.element.createChild('div', 'toolbar-dropdown-arrow'); | 505 this.element.createChild('div', 'toolbar-dropdown-arrow'); |
524 if (width) | 506 if (width) |
525 this.element.style.width = width + 'px'; | 507 this.element.style.width = width + 'px'; |
526 } | 508 } |
527 | 509 |
528 /** | 510 /** |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
590 TextChanged: 'TextChanged' | 572 TextChanged: 'TextChanged' |
591 }; | 573 }; |
592 | 574 |
593 /** | 575 /** |
594 * @unrestricted | 576 * @unrestricted |
595 */ | 577 */ |
596 WebInspector.ToolbarToggle = class extends WebInspector.ToolbarButton { | 578 WebInspector.ToolbarToggle = class extends WebInspector.ToolbarButton { |
597 /** | 579 /** |
598 * @param {string} title | 580 * @param {string} title |
599 * @param {string=} glyph | 581 * @param {string=} glyph |
600 * @param {string=} text | 582 * @param {string=} toggledGlyph |
601 */ | 583 */ |
602 constructor(title, glyph, text) { | 584 constructor(title, glyph, toggledGlyph) { |
603 super(title, glyph, text); | 585 super(title, glyph, ''); |
604 this._toggled = false; | 586 this._toggled = false; |
605 this.setState('off'); | 587 this._untoggledGlyph = glyph; |
| 588 this._toggledGlyph = toggledGlyph; |
| 589 this.element.classList.add('toolbar-state-off'); |
606 } | 590 } |
607 | 591 |
608 /** | 592 /** |
609 * @return {boolean} | 593 * @return {boolean} |
610 */ | 594 */ |
611 toggled() { | 595 toggled() { |
612 return this._toggled; | 596 return this._toggled; |
613 } | 597 } |
614 | 598 |
615 /** | 599 /** |
616 * @param {boolean} toggled | 600 * @param {boolean} toggled |
617 */ | 601 */ |
618 setToggled(toggled) { | 602 setToggled(toggled) { |
619 if (this._toggled === toggled) | 603 if (this._toggled === toggled) |
620 return; | 604 return; |
621 this._toggled = toggled; | 605 this._toggled = toggled; |
622 this.setState(toggled ? 'on' : 'off'); | 606 this.element.classList.toggle('toolbar-state-on', toggled); |
| 607 this.element.classList.toggle('toolbar-state-off', !toggled); |
| 608 if (this._toggledGlyph && this._untoggledGlyph) |
| 609 this.setGlyph(toggled ? this._toggledGlyph : this._untoggledGlyph); |
| 610 } |
| 611 |
| 612 /** |
| 613 * @param {boolean} toggleWithRedColor |
| 614 */ |
| 615 setToggleWithRedColor(toggleWithRedColor) { |
| 616 this.element.classList.toggle('toolbar-toggle-with-red-color', toggleWithRed
Color); |
623 } | 617 } |
624 }; | 618 }; |
625 | 619 |
626 | 620 |
627 /** | 621 /** |
628 * @unrestricted | 622 * @unrestricted |
629 */ | 623 */ |
630 WebInspector.ToolbarMenuButton = class extends WebInspector.ToolbarButton { | 624 WebInspector.ToolbarMenuButton = class extends WebInspector.ToolbarButton { |
631 /** | 625 /** |
632 * @param {function(!WebInspector.ContextMenu)} contextMenuHandler | 626 * @param {function(!WebInspector.ContextMenu)} contextMenuHandler |
(...skipping 268 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
901 return this.inputElement.checked; | 895 return this.inputElement.checked; |
902 } | 896 } |
903 | 897 |
904 /** | 898 /** |
905 * @param {boolean} value | 899 * @param {boolean} value |
906 */ | 900 */ |
907 setChecked(value) { | 901 setChecked(value) { |
908 this.inputElement.checked = value; | 902 this.inputElement.checked = value; |
909 } | 903 } |
910 }; | 904 }; |
OLD | NEW |