| 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 416 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 427 break; | 427 break; |
| 428 } | 428 } |
| 429 } | 429 } |
| 430 } | 430 } |
| 431 }, | 431 }, |
| 432 | 432 |
| 433 __proto__: WebInspector.StatusBarItem.prototype | 433 __proto__: WebInspector.StatusBarItem.prototype |
| 434 } | 434 } |
| 435 | 435 |
| 436 /** | 436 /** |
| 437 * @interface |
| 438 */ |
| 439 WebInspector.StatusBarButton.Provider = function() |
| 440 { |
| 441 } |
| 442 |
| 443 WebInspector.StatusBarButton.Provider.prototype = { |
| 444 /** |
| 445 * @return {?WebInspector.StatusBarButton} |
| 446 */ |
| 447 button: function() {} |
| 448 } |
| 449 |
| 450 /** |
| 437 * @constructor | 451 * @constructor |
| 438 * @extends {WebInspector.StatusBarItem} | 452 * @extends {WebInspector.StatusBarItem} |
| 439 * @param {?function(!Event)} changeHandler | 453 * @param {?function(!Event)} changeHandler |
| 440 * @param {string=} className | 454 * @param {string=} className |
| 441 */ | 455 */ |
| 442 WebInspector.StatusBarComboBox = function(changeHandler, className) | 456 WebInspector.StatusBarComboBox = function(changeHandler, className) |
| 443 { | 457 { |
| 444 WebInspector.StatusBarItem.call(this, "span"); | 458 WebInspector.StatusBarItem.call(this, "span"); |
| 445 this.element.className = "status-bar-select-container"; | 459 this.element.className = "status-bar-select-container"; |
| 446 | 460 |
| (...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 577 | 591 |
| 578 __proto__: WebInspector.StatusBarItem.prototype | 592 __proto__: WebInspector.StatusBarItem.prototype |
| 579 } | 593 } |
| 580 | 594 |
| 581 /** | 595 /** |
| 582 * @constructor | 596 * @constructor |
| 583 * @extends {WebInspector.StatusBarButton} | 597 * @extends {WebInspector.StatusBarButton} |
| 584 * @param {string} className | 598 * @param {string} className |
| 585 * @param {!Array.<string>} states | 599 * @param {!Array.<string>} states |
| 586 * @param {!Array.<string>} titles | 600 * @param {!Array.<string>} titles |
| 601 * @param {string} initialState |
| 587 * @param {!WebInspector.Setting} currentStateSetting | 602 * @param {!WebInspector.Setting} currentStateSetting |
| 588 * @param {!WebInspector.Setting} lastStateSetting | 603 * @param {!WebInspector.Setting} lastStateSetting |
| 589 * @param {?function(string)} stateChangedCallback | 604 * @param {?function(string)} stateChangedCallback |
| 590 */ | 605 */ |
| 591 WebInspector.StatusBarStatesSettingButton = function(className, states, titles,
currentStateSetting, lastStateSetting, stateChangedCallback) | 606 WebInspector.StatusBarStatesSettingButton = function(className, states, titles,
initialState, currentStateSetting, lastStateSetting, stateChangedCallback) |
| 592 { | 607 { |
| 593 WebInspector.StatusBarButton.call(this, "", className, states.length); | 608 WebInspector.StatusBarButton.call(this, "", className, states.length); |
| 594 | 609 |
| 595 var onClickBound = this._onClick.bind(this); | 610 var onClickBound = this._onClick.bind(this); |
| 596 this.addEventListener("click", onClickBound, this); | 611 this.addEventListener("click", onClickBound, this); |
| 597 | 612 |
| 598 this._states = states; | 613 this._states = states; |
| 599 this._buttons = []; | 614 this._buttons = []; |
| 600 for (var index = 0; index < states.length; index++) { | 615 for (var index = 0; index < states.length; index++) { |
| 601 var button = new WebInspector.StatusBarButton(titles[index], className,
states.length); | 616 var button = new WebInspector.StatusBarButton(titles[index], className,
states.length); |
| 602 button.state = this._states[index]; | 617 button.state = this._states[index]; |
| 603 button.addEventListener("click", onClickBound, this); | 618 button.addEventListener("click", onClickBound, this); |
| 604 this._buttons.push(button); | 619 this._buttons.push(button); |
| 605 } | 620 } |
| 606 | 621 |
| 607 this._currentStateSetting = currentStateSetting; | 622 this._currentStateSetting = currentStateSetting; |
| 608 this._lastStateSetting = lastStateSetting; | 623 this._lastStateSetting = lastStateSetting; |
| 609 this._stateChangedCallback = stateChangedCallback; | 624 this._stateChangedCallback = stateChangedCallback; |
| 610 this.setLongClickOptionsEnabled(this._createOptions.bind(this)); | 625 this.setLongClickOptionsEnabled(this._createOptions.bind(this)); |
| 611 | 626 |
| 612 this._currentState = null; | 627 this._currentState = null; |
| 628 this.toggleState(initialState); |
| 613 } | 629 } |
| 614 | 630 |
| 615 WebInspector.StatusBarStatesSettingButton.prototype = { | 631 WebInspector.StatusBarStatesSettingButton.prototype = { |
| 616 /** | 632 /** |
| 617 * @param {!WebInspector.Event} e | 633 * @param {!WebInspector.Event} e |
| 618 */ | 634 */ |
| 619 _onClick: function(e) | 635 _onClick: function(e) |
| 620 { | 636 { |
| 621 this.toggleState(e.target.state); | 637 this.toggleState(e.target.state); |
| 622 }, | 638 }, |
| (...skipping 12 matching lines...) Expand all Loading... |
| 635 this._currentStateSetting.set(this._currentState); | 651 this._currentStateSetting.set(this._currentState); |
| 636 | 652 |
| 637 if (this._stateChangedCallback) | 653 if (this._stateChangedCallback) |
| 638 this._stateChangedCallback(state); | 654 this._stateChangedCallback(state); |
| 639 | 655 |
| 640 var defaultState = this._defaultState(); | 656 var defaultState = this._defaultState(); |
| 641 this.state = defaultState; | 657 this.state = defaultState; |
| 642 this.title = this._buttons[this._states.indexOf(defaultState)].title; | 658 this.title = this._buttons[this._states.indexOf(defaultState)].title; |
| 643 }, | 659 }, |
| 644 | 660 |
| 645 toggleInitialState: function() | |
| 646 { | |
| 647 if (this._currentState === null) | |
| 648 this.toggleState(this._defaultState()); | |
| 649 }, | |
| 650 | |
| 651 /** | 661 /** |
| 652 * @return {string} | 662 * @return {string} |
| 653 */ | 663 */ |
| 654 _defaultState: function() | 664 _defaultState: function() |
| 655 { | 665 { |
| 656 // Not yet initialized - load from setting. | |
| 657 if (!this._currentState) { | |
| 658 var state = this._currentStateSetting.get(); | |
| 659 return this._states.indexOf(state) >= 0 ? state : this._states[0]; | |
| 660 } | |
| 661 | |
| 662 var lastState = this._lastStateSetting.get(); | 666 var lastState = this._lastStateSetting.get(); |
| 663 if (lastState && this._states.indexOf(lastState) >= 0 && lastState != th
is._currentState) | 667 if (lastState && this._states.indexOf(lastState) >= 0 && lastState != th
is._currentState) |
| 664 return lastState; | 668 return lastState; |
| 665 if (this._states.length > 1 && this._currentState === this._states[0]) | 669 if (this._states.length > 1 && this._currentState === this._states[0]) |
| 666 return this._states[1]; | 670 return this._states[1]; |
| 667 return this._states[0]; | 671 return this._states[0]; |
| 668 }, | 672 }, |
| 669 | 673 |
| 670 /** | 674 /** |
| 671 * @return {!Array.<!WebInspector.StatusBarButton>} | 675 * @return {!Array.<!WebInspector.StatusBarButton>} |
| 672 */ | 676 */ |
| 673 _createOptions: function() | 677 _createOptions: function() |
| 674 { | 678 { |
| 675 var options = []; | 679 var options = []; |
| 676 for (var index = 0; index < this._states.length; index++) { | 680 for (var index = 0; index < this._states.length; index++) { |
| 677 if (this._states[index] !== this.state && this._states[index] !== th
is._currentState) | 681 if (this._states[index] !== this.state && this._states[index] !== th
is._currentState) |
| 678 options.push(this._buttons[index]); | 682 options.push(this._buttons[index]); |
| 679 } | 683 } |
| 680 return options; | 684 return options; |
| 681 }, | 685 }, |
| 682 | 686 |
| 683 __proto__: WebInspector.StatusBarButton.prototype | 687 __proto__: WebInspector.StatusBarButton.prototype |
| 684 } | 688 } |
| OLD | NEW |