Chromium Code Reviews| 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(), ' ', action.toggledIcon()); |
| 59 button.addEventListener('click', action.execute, action); | 59 button.addEventListener('click', action.execute, action); |
| 60 action.addEventListener(WebInspector.Action.Events.Enabled, enabledChanged); | 60 action.addEventListener(WebInspector.Action.Events.Enabled, enabledChanged); |
| 61 action.addEventListener(WebInspector.Action.Events.Toggled, toggled); | 61 action.addEventListener(WebInspector.Action.Events.Toggled, toggled); |
| 62 /** @type {?WebInspector.LongClickController} */ | 62 /** @type {?WebInspector.LongClickController} */ |
| 63 var longClickController = null; | 63 var longClickController = null; |
| 64 /** @type {?Array<!WebInspector.ToolbarButton>} */ | 64 /** @type {?Array<!WebInspector.ToolbarButton>} */ |
| 65 var longClickButtons = null; | 65 var longClickButtons = null; |
| 66 /** @type {?Element} */ | 66 /** @type {?Element} */ |
| 67 var longClickGlyph = null; | 67 var longClickGlyph = null; |
| 68 toggled(); | 68 toggled(); |
| (...skipping 28 matching lines...) Expand all Loading... | |
| 97 longClickController = null; | 97 longClickController = null; |
| 98 longClickGlyph.remove(); | 98 longClickGlyph.remove(); |
| 99 longClickGlyph = null; | 99 longClickGlyph = null; |
| 100 longClickButtons = null; | 100 longClickButtons = null; |
| 101 } | 101 } |
| 102 } | 102 } |
| 103 } | 103 } |
| 104 | 104 |
| 105 function showOptions() { | 105 function showOptions() { |
| 106 var buttons = longClickButtons.slice(); | 106 var buttons = longClickButtons.slice(); |
| 107 var mainButtonClone = new WebInspector.ToolbarToggle(action.title(), actio n.icon()); | 107 var mainButtonClone = new WebInspector.ToolbarToggle(action.title(), actio n.icon(), undefined, action.toggledIcon()); |
| 108 mainButtonClone.addEventListener('click', clicked); | 108 mainButtonClone.addEventListener('click', clicked); |
| 109 | 109 |
| 110 /** | 110 /** |
| 111 * @param {!WebInspector.Event} event | 111 * @param {!WebInspector.Event} event |
| 112 */ | 112 */ |
| 113 function clicked(event) { | 113 function clicked(event) { |
| 114 button._clicked(/** @type {!Event} */ (event.data)); | 114 button._clicked(/** @type {!Event} */ (event.data)); |
| 115 } | 115 } |
| 116 | 116 |
| 117 mainButtonClone.setToggled(action.toggled()); | 117 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 ); | 453 this.element.addEventListener('mousedown', this._mouseDown.bind(this), false ); |
| 454 this.element.addEventListener('mouseup', this._mouseUp.bind(this), false); | 454 this.element.addEventListener('mouseup', this._mouseUp.bind(this), false); |
| 455 | 455 |
| 456 this._glyphElement = this.element.createChild('div', 'toolbar-glyph hidden') ; | 456 this._glyphElement = this.element.createChild('div', 'toolbar-glyph hidden') ; |
| 457 this._textElement = this.element.createChild('div', 'toolbar-text hidden'); | 457 this._textElement = this.element.createChild('div', 'toolbar-text hidden'); |
| 458 | 458 |
| 459 this.setTitle(title); | 459 this.setTitle(title); |
| 460 if (glyph) | 460 if (glyph) |
| 461 this.setGlyph(glyph); | 461 this.setGlyph(glyph); |
| 462 this.setText(text || ''); | 462 this.setText(text || ''); |
| 463 this._state = ''; | |
| 464 this._title = ''; | 463 this._title = ''; |
| 465 } | 464 } |
| 466 | 465 |
| 467 /** | 466 /** |
| 468 * @param {string} text | 467 * @param {string} text |
| 469 */ | 468 */ |
| 470 setText(text) { | 469 setText(text) { |
| 471 if (this._text === text) | 470 if (this._text === text) |
| 472 return; | 471 return; |
| 473 this._textElement.textContent = text; | 472 this._textElement.textContent = text; |
| (...skipping 17 matching lines...) Expand all Loading... | |
| 491 } | 490 } |
| 492 | 491 |
| 493 /** | 492 /** |
| 494 * @param {string} iconURL | 493 * @param {string} iconURL |
| 495 */ | 494 */ |
| 496 setBackgroundImage(iconURL) { | 495 setBackgroundImage(iconURL) { |
| 497 this.element.style.backgroundImage = 'url(' + iconURL + ')'; | 496 this.element.style.backgroundImage = 'url(' + iconURL + ')'; |
| 498 } | 497 } |
| 499 | 498 |
| 500 /** | 499 /** |
| 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 | 500 * @param {number=} width |
| 520 */ | 501 */ |
| 521 turnIntoSelect(width) { | 502 turnIntoSelect(width) { |
| 522 this.element.classList.add('toolbar-has-dropdown'); | 503 this.element.classList.add('toolbar-has-dropdown'); |
| 523 this.element.createChild('div', 'toolbar-dropdown-arrow'); | 504 this.element.createChild('div', 'toolbar-dropdown-arrow'); |
| 524 if (width) | 505 if (width) |
| 525 this.element.style.width = width + 'px'; | 506 this.element.style.width = width + 'px'; |
| 526 } | 507 } |
| 527 | 508 |
| 528 /** | 509 /** |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 591 }; | 572 }; |
| 592 | 573 |
| 593 /** | 574 /** |
| 594 * @unrestricted | 575 * @unrestricted |
| 595 */ | 576 */ |
| 596 WebInspector.ToolbarToggle = class extends WebInspector.ToolbarButton { | 577 WebInspector.ToolbarToggle = class extends WebInspector.ToolbarButton { |
| 597 /** | 578 /** |
| 598 * @param {string} title | 579 * @param {string} title |
| 599 * @param {string=} glyph | 580 * @param {string=} glyph |
| 600 * @param {string=} text | 581 * @param {string=} text |
| 582 * @param {string=} toggledGlyph | |
| 601 */ | 583 */ |
| 602 constructor(title, glyph, text) { | 584 constructor(title, glyph, text, toggledGlyph) { |
|
dgozman
2016/11/07 18:32:45
Does it make sense to pass toggledTitle as well?
lushnikov
2016/11/08 01:44:45
Tooltips are done in a various of techniques - som
| |
| 603 super(title, glyph, text); | 585 super(title, glyph, text); |
| 604 this._toggled = false; | 586 this._toggled = false; |
| 605 this.setState('off'); | 587 this._untoggledGlyph = glyph; |
| 588 this._toggledGlyph = toggledGlyph; | |
| 589 this._state = ''; | |
|
dgozman
2016/11/07 18:32:45
Unused.
lushnikov
2016/11/08 01:44:45
Done.
| |
| 590 this.element.classList.add('toolbar-state-off'); | |
| 606 } | 591 } |
| 607 | 592 |
| 608 /** | 593 /** |
| 609 * @return {boolean} | 594 * @return {boolean} |
| 610 */ | 595 */ |
| 611 toggled() { | 596 toggled() { |
| 612 return this._toggled; | 597 return this._toggled; |
| 613 } | 598 } |
| 614 | 599 |
| 615 /** | 600 /** |
| 616 * @param {boolean} toggled | 601 * @param {boolean} toggled |
| 617 */ | 602 */ |
| 618 setToggled(toggled) { | 603 setToggled(toggled) { |
| 619 if (this._toggled === toggled) | 604 if (this._toggled === toggled) |
| 620 return; | 605 return; |
| 621 this._toggled = toggled; | 606 this._toggled = toggled; |
| 622 this.setState(toggled ? 'on' : 'off'); | 607 this.element.classList.toggle('toolbar-state-on', toggled); |
| 608 this.element.classList.toggle('toolbar-state-off', !toggled); | |
| 609 if (this._toggledGlyph && this._untoggledGlyph) | |
| 610 this.setGlyph(toggled ? this._toggledGlyph : this._untoggledGlyph); | |
| 611 } | |
| 612 | |
| 613 /** | |
| 614 * @param {boolean} active | |
| 615 */ | |
| 616 setActive(active) { | |
| 617 this.element.classList.toggle('toolbar-state-active', active); | |
| 623 } | 618 } |
| 624 }; | 619 }; |
| 625 | 620 |
| 626 | 621 |
| 627 /** | 622 /** |
| 628 * @unrestricted | 623 * @unrestricted |
| 629 */ | 624 */ |
| 630 WebInspector.ToolbarMenuButton = class extends WebInspector.ToolbarButton { | 625 WebInspector.ToolbarMenuButton = class extends WebInspector.ToolbarButton { |
| 631 /** | 626 /** |
| 632 * @param {function(!WebInspector.ContextMenu)} contextMenuHandler | 627 * @param {function(!WebInspector.ContextMenu)} contextMenuHandler |
| (...skipping 268 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 901 return this.inputElement.checked; | 896 return this.inputElement.checked; |
| 902 } | 897 } |
| 903 | 898 |
| 904 /** | 899 /** |
| 905 * @param {boolean} value | 900 * @param {boolean} value |
| 906 */ | 901 */ |
| 907 setChecked(value) { | 902 setChecked(value) { |
| 908 this.inputElement.checked = value; | 903 this.inputElement.checked = value; |
| 909 } | 904 } |
| 910 }; | 905 }; |
| OLD | NEW |