| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2008 Apple Inc. All Rights Reserved. | 2 * Copyright (C) 2008 Apple Inc. All Rights Reserved. |
| 3 * Copyright (C) 2011 Google Inc. All Rights Reserved. | 3 * Copyright (C) 2011 Google Inc. All Rights Reserved. |
| 4 * | 4 * |
| 5 * Redistribution and use in source and binary forms, with or without | 5 * Redistribution and use in source and binary forms, with or without |
| 6 * modification, are permitted provided that the following conditions | 6 * modification, are permitted provided that the following conditions |
| 7 * are met: | 7 * are met: |
| 8 * 1. Redistributions of source code must retain the above copyright | 8 * 1. 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 * 2. Redistributions in binary form must reproduce the above copyright | 10 * 2. Redistributions in binary form must reproduce the above copyright |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 42 this._isWebComponent = isWebComponent; | 42 this._isWebComponent = isWebComponent; |
| 43 this.element.__widget = this; | 43 this.element.__widget = this; |
| 44 this._visible = false; | 44 this._visible = false; |
| 45 this._isRoot = false; | 45 this._isRoot = false; |
| 46 this._isShowing = false; | 46 this._isShowing = false; |
| 47 this._children = []; | 47 this._children = []; |
| 48 this._hideOnDetach = false; | 48 this._hideOnDetach = false; |
| 49 this._notificationDepth = 0; | 49 this._notificationDepth = 0; |
| 50 this._invalidationsSuspended = 0; | 50 this._invalidationsSuspended = 0; |
| 51 this._defaultFocusedChild = null; | 51 this._defaultFocusedChild = null; |
| 52 } | 52 }; |
| 53 | 53 |
| 54 WebInspector.Widget.prototype = { | 54 WebInspector.Widget.prototype = { |
| 55 markAsRoot: function() | 55 markAsRoot: function() |
| 56 { | 56 { |
| 57 WebInspector.Widget.__assert(!this.element.parentElement, "Attempt to ma
rk as root attached node"); | 57 WebInspector.Widget.__assert(!this.element.parentElement, "Attempt to ma
rk as root attached node"); |
| 58 this._isRoot = true; | 58 this._isRoot = true; |
| 59 }, | 59 }, |
| 60 | 60 |
| 61 /** | 61 /** |
| 62 * @return {?WebInspector.Widget} | 62 * @return {?WebInspector.Widget} |
| (...skipping 523 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 586 this.doLayout(); | 586 this.doLayout(); |
| 587 }, | 587 }, |
| 588 | 588 |
| 589 invalidateSize: function() | 589 invalidateSize: function() |
| 590 { | 590 { |
| 591 if (this._parentWidget) | 591 if (this._parentWidget) |
| 592 this._parentWidget.doLayout(); | 592 this._parentWidget.doLayout(); |
| 593 }, | 593 }, |
| 594 | 594 |
| 595 __proto__: WebInspector.Object.prototype | 595 __proto__: WebInspector.Object.prototype |
| 596 } | 596 }; |
| 597 | 597 |
| 598 WebInspector.Widget._originalAppendChild = Element.prototype.appendChild; | 598 WebInspector.Widget._originalAppendChild = Element.prototype.appendChild; |
| 599 WebInspector.Widget._originalInsertBefore = Element.prototype.insertBefore; | 599 WebInspector.Widget._originalInsertBefore = Element.prototype.insertBefore; |
| 600 WebInspector.Widget._originalRemoveChild = Element.prototype.removeChild; | 600 WebInspector.Widget._originalRemoveChild = Element.prototype.removeChild; |
| 601 WebInspector.Widget._originalRemoveChildren = Element.prototype.removeChildren; | 601 WebInspector.Widget._originalRemoveChildren = Element.prototype.removeChildren; |
| 602 | 602 |
| 603 WebInspector.Widget._incrementWidgetCounter = function(parentElement, childEleme
nt) | 603 WebInspector.Widget._incrementWidgetCounter = function(parentElement, childEleme
nt) |
| 604 { | 604 { |
| 605 var count = (childElement.__widgetCounter || 0) + (childElement.__widget ? 1
: 0); | 605 var count = (childElement.__widgetCounter || 0) + (childElement.__widget ? 1
: 0); |
| 606 if (!count) | 606 if (!count) |
| 607 return; | 607 return; |
| 608 | 608 |
| 609 while (parentElement) { | 609 while (parentElement) { |
| 610 parentElement.__widgetCounter = (parentElement.__widgetCounter || 0) + c
ount; | 610 parentElement.__widgetCounter = (parentElement.__widgetCounter || 0) + c
ount; |
| 611 parentElement = parentElement.parentElementOrShadowHost(); | 611 parentElement = parentElement.parentElementOrShadowHost(); |
| 612 } | 612 } |
| 613 } | 613 }; |
| 614 | 614 |
| 615 WebInspector.Widget._decrementWidgetCounter = function(parentElement, childEleme
nt) | 615 WebInspector.Widget._decrementWidgetCounter = function(parentElement, childEleme
nt) |
| 616 { | 616 { |
| 617 var count = (childElement.__widgetCounter || 0) + (childElement.__widget ? 1
: 0); | 617 var count = (childElement.__widgetCounter || 0) + (childElement.__widget ? 1
: 0); |
| 618 if (!count) | 618 if (!count) |
| 619 return; | 619 return; |
| 620 | 620 |
| 621 while (parentElement) { | 621 while (parentElement) { |
| 622 parentElement.__widgetCounter -= count; | 622 parentElement.__widgetCounter -= count; |
| 623 parentElement = parentElement.parentElementOrShadowHost(); | 623 parentElement = parentElement.parentElementOrShadowHost(); |
| 624 } | 624 } |
| 625 } | 625 }; |
| 626 | 626 |
| 627 WebInspector.Widget.__assert = function(condition, message) | 627 WebInspector.Widget.__assert = function(condition, message) |
| 628 { | 628 { |
| 629 if (!condition) { | 629 if (!condition) { |
| 630 console.trace(); | 630 console.trace(); |
| 631 throw new Error(message); | 631 throw new Error(message); |
| 632 } | 632 } |
| 633 } | 633 }; |
| 634 | 634 |
| 635 /** | 635 /** |
| 636 * @param {?Node} node | 636 * @param {?Node} node |
| 637 */ | 637 */ |
| 638 WebInspector.Widget.focusWidgetForNode = function(node) | 638 WebInspector.Widget.focusWidgetForNode = function(node) |
| 639 { | 639 { |
| 640 while (node) { | 640 while (node) { |
| 641 if (node.__widget) | 641 if (node.__widget) |
| 642 break; | 642 break; |
| 643 node = node.parentNodeOrShadowHost(); | 643 node = node.parentNodeOrShadowHost(); |
| 644 } | 644 } |
| 645 if (!node) | 645 if (!node) |
| 646 return; | 646 return; |
| 647 | 647 |
| 648 var widget = node.__widget; | 648 var widget = node.__widget; |
| 649 while (widget._parentWidget) { | 649 while (widget._parentWidget) { |
| 650 widget._parentWidget._defaultFocusedChild = widget; | 650 widget._parentWidget._defaultFocusedChild = widget; |
| 651 widget = widget._parentWidget; | 651 widget = widget._parentWidget; |
| 652 } | 652 } |
| 653 } | 653 }; |
| 654 | 654 |
| 655 /** | 655 /** |
| 656 * @constructor | 656 * @constructor |
| 657 * @extends {WebInspector.Widget} | 657 * @extends {WebInspector.Widget} |
| 658 * @param {boolean=} isWebComponent | 658 * @param {boolean=} isWebComponent |
| 659 */ | 659 */ |
| 660 WebInspector.VBox = function(isWebComponent) | 660 WebInspector.VBox = function(isWebComponent) |
| 661 { | 661 { |
| 662 WebInspector.Widget.call(this, isWebComponent); | 662 WebInspector.Widget.call(this, isWebComponent); |
| 663 this.contentElement.classList.add("vbox"); | 663 this.contentElement.classList.add("vbox"); |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 730 | 730 |
| 731 /** | 731 /** |
| 732 * @constructor | 732 * @constructor |
| 733 * @extends {WebInspector.VBox} | 733 * @extends {WebInspector.VBox} |
| 734 * @param {function()} resizeCallback | 734 * @param {function()} resizeCallback |
| 735 */ | 735 */ |
| 736 WebInspector.VBoxWithResizeCallback = function(resizeCallback) | 736 WebInspector.VBoxWithResizeCallback = function(resizeCallback) |
| 737 { | 737 { |
| 738 WebInspector.VBox.call(this); | 738 WebInspector.VBox.call(this); |
| 739 this._resizeCallback = resizeCallback; | 739 this._resizeCallback = resizeCallback; |
| 740 } | 740 }; |
| 741 | 741 |
| 742 WebInspector.VBoxWithResizeCallback.prototype = { | 742 WebInspector.VBoxWithResizeCallback.prototype = { |
| 743 onResize: function() | 743 onResize: function() |
| 744 { | 744 { |
| 745 this._resizeCallback(); | 745 this._resizeCallback(); |
| 746 }, | 746 }, |
| 747 | 747 |
| 748 __proto__: WebInspector.VBox.prototype | 748 __proto__: WebInspector.VBox.prototype |
| 749 } | 749 }; |
| 750 | 750 |
| 751 /** | 751 /** |
| 752 * @param {!WebInspector.Widget} widget | 752 * @param {!WebInspector.Widget} widget |
| 753 * @constructor | 753 * @constructor |
| 754 */ | 754 */ |
| 755 WebInspector.WidgetFocusRestorer = function(widget) | 755 WebInspector.WidgetFocusRestorer = function(widget) |
| 756 { | 756 { |
| 757 this._widget = widget; | 757 this._widget = widget; |
| 758 this._previous = widget.element.ownerDocument.deepActiveElement(); | 758 this._previous = widget.element.ownerDocument.deepActiveElement(); |
| 759 widget.focus(); | 759 widget.focus(); |
| 760 } | 760 }; |
| 761 | 761 |
| 762 WebInspector.WidgetFocusRestorer.prototype = { | 762 WebInspector.WidgetFocusRestorer.prototype = { |
| 763 restore: function() | 763 restore: function() |
| 764 { | 764 { |
| 765 if (!this._widget) | 765 if (!this._widget) |
| 766 return; | 766 return; |
| 767 if (this._widget.hasFocus() && this._previous) | 767 if (this._widget.hasFocus() && this._previous) |
| 768 this._previous.focus(); | 768 this._previous.focus(); |
| 769 this._previous = null; | 769 this._previous = null; |
| 770 this._widget = null; | 770 this._widget = null; |
| 771 } | 771 } |
| 772 } | 772 }; |
| 773 | 773 |
| 774 /** | 774 /** |
| 775 * @override | 775 * @override |
| 776 * @param {?Node} child | 776 * @param {?Node} child |
| 777 * @return {?Node} | 777 * @return {?Node} |
| 778 * @suppress {duplicate} | 778 * @suppress {duplicate} |
| 779 */ | 779 */ |
| 780 Element.prototype.appendChild = function(child) | 780 Element.prototype.appendChild = function(child) |
| 781 { | 781 { |
| 782 WebInspector.Widget.__assert(!child.__widget || child.parentElement === this
, "Attempt to add widget via regular DOM operation."); | 782 WebInspector.Widget.__assert(!child.__widget || child.parentElement === this
, "Attempt to add widget via regular DOM operation."); |
| 783 return WebInspector.Widget._originalAppendChild.call(this, child); | 783 return WebInspector.Widget._originalAppendChild.call(this, child); |
| 784 } | 784 }; |
| 785 | 785 |
| 786 /** | 786 /** |
| 787 * @override | 787 * @override |
| 788 * @param {?Node} child | 788 * @param {?Node} child |
| 789 * @param {?Node} anchor | 789 * @param {?Node} anchor |
| 790 * @return {!Node} | 790 * @return {!Node} |
| 791 * @suppress {duplicate} | 791 * @suppress {duplicate} |
| 792 */ | 792 */ |
| 793 Element.prototype.insertBefore = function(child, anchor) | 793 Element.prototype.insertBefore = function(child, anchor) |
| 794 { | 794 { |
| 795 WebInspector.Widget.__assert(!child.__widget || child.parentElement === this
, "Attempt to add widget via regular DOM operation."); | 795 WebInspector.Widget.__assert(!child.__widget || child.parentElement === this
, "Attempt to add widget via regular DOM operation."); |
| 796 return WebInspector.Widget._originalInsertBefore.call(this, child, anchor); | 796 return WebInspector.Widget._originalInsertBefore.call(this, child, anchor); |
| 797 } | 797 }; |
| 798 | 798 |
| 799 /** | 799 /** |
| 800 * @override | 800 * @override |
| 801 * @param {?Node} child | 801 * @param {?Node} child |
| 802 * @return {!Node} | 802 * @return {!Node} |
| 803 * @suppress {duplicate} | 803 * @suppress {duplicate} |
| 804 */ | 804 */ |
| 805 Element.prototype.removeChild = function(child) | 805 Element.prototype.removeChild = function(child) |
| 806 { | 806 { |
| 807 WebInspector.Widget.__assert(!child.__widgetCounter && !child.__widget, "Att
empt to remove element containing widget via regular DOM operation"); | 807 WebInspector.Widget.__assert(!child.__widgetCounter && !child.__widget, "Att
empt to remove element containing widget via regular DOM operation"); |
| 808 return WebInspector.Widget._originalRemoveChild.call(this, child); | 808 return WebInspector.Widget._originalRemoveChild.call(this, child); |
| 809 } | 809 }; |
| 810 | 810 |
| 811 Element.prototype.removeChildren = function() | 811 Element.prototype.removeChildren = function() |
| 812 { | 812 { |
| 813 WebInspector.Widget.__assert(!this.__widgetCounter, "Attempt to remove eleme
nt containing widget via regular DOM operation"); | 813 WebInspector.Widget.__assert(!this.__widgetCounter, "Attempt to remove eleme
nt containing widget via regular DOM operation"); |
| 814 WebInspector.Widget._originalRemoveChildren.call(this); | 814 WebInspector.Widget._originalRemoveChildren.call(this); |
| 815 } | 815 }; |
| OLD | NEW |