| 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 419 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 430 lines.push(prefix + "[" + this.element.className + "]" + (this._children
.length ? " {" : "")); | 430 lines.push(prefix + "[" + this.element.className + "]" + (this._children
.length ? " {" : "")); |
| 431 | 431 |
| 432 for (var i = 0; i < this._children.length; ++i) | 432 for (var i = 0; i < this._children.length; ++i) |
| 433 this._children[i]._collectWidgetHierarchy(prefix + " ", lines); | 433 this._children[i]._collectWidgetHierarchy(prefix + " ", lines); |
| 434 | 434 |
| 435 if (this._children.length) | 435 if (this._children.length) |
| 436 lines.push(prefix + "}"); | 436 lines.push(prefix + "}"); |
| 437 }, | 437 }, |
| 438 | 438 |
| 439 /** | 439 /** |
| 440 * @param {!Element} element | 440 * @param {?Element} element |
| 441 */ | 441 */ |
| 442 setDefaultFocusedElement: function(element) | 442 setDefaultFocusedElement: function(element) |
| 443 { | 443 { |
| 444 this._defaultFocusedElement = element; | 444 this._defaultFocusedElement = element; |
| 445 }, | 445 }, |
| 446 | 446 |
| 447 /** | 447 /** |
| 448 * @param {!WebInspector.Widget} child | 448 * @param {!WebInspector.Widget} child |
| 449 */ | 449 */ |
| 450 setDefaultFocusedChild: function(child) | 450 setDefaultFocusedChild: function(child) |
| 451 { | 451 { |
| 452 WebInspector.Widget.__assert(child._parentWidget === this, "Attempt to s
et non-child widget as default focused."); | 452 WebInspector.Widget.__assert(child._parentWidget === this, "Attempt to s
et non-child widget as default focused."); |
| 453 this._defaultFocusedChild = child; | 453 this._defaultFocusedChild = child; |
| 454 }, | 454 }, |
| 455 | 455 |
| 456 focus: function() | 456 focus: function() |
| 457 { | 457 { |
| 458 if (!this.isShowing()) |
| 459 return; |
| 460 |
| 458 var element = this._defaultFocusedElement; | 461 var element = this._defaultFocusedElement; |
| 459 if (element && !element.isAncestor(this.element.ownerDocument.activeElem
ent)) { | 462 if (element) { |
| 460 WebInspector.setCurrentFocusElement(element); | 463 if (!element.hasFocus()) |
| 464 element.focus(); |
| 461 return; | 465 return; |
| 462 } | 466 } |
| 463 | 467 |
| 464 if (this._defaultFocusedChild && this._defaultFocusedChild._visible) { | 468 if (this._defaultFocusedChild && this._defaultFocusedChild._visible) { |
| 465 this._defaultFocusedChild.focus(); | 469 this._defaultFocusedChild.focus(); |
| 466 } else { | 470 } else { |
| 467 for (var child of this._children) { | 471 for (var child of this._children) { |
| 468 if (child._visible) { | 472 if (child._visible) { |
| 469 child.focus(); | 473 child.focus(); |
| 470 break; | 474 break; |
| 471 } | 475 } |
| 472 } | 476 } |
| 473 } | 477 } |
| 474 | 478 |
| 475 }, | 479 }, |
| 476 | 480 |
| 477 /** | 481 /** |
| 478 * @return {boolean} | 482 * @return {boolean} |
| 479 */ | 483 */ |
| 480 hasFocus: function() | 484 hasFocus: function() |
| 481 { | 485 { |
| 482 var activeElement = this.element.ownerDocument.activeElement; | 486 return this.element.hasFocus(); |
| 483 return activeElement && activeElement.isSelfOrDescendant(this.element); | |
| 484 }, | 487 }, |
| 485 | 488 |
| 486 /** | 489 /** |
| 487 * @return {!Size} | 490 * @return {!Size} |
| 488 */ | 491 */ |
| 489 measurePreferredSize: function() | 492 measurePreferredSize: function() |
| 490 { | 493 { |
| 491 var document = this.element.ownerDocument; | 494 var document = this.element.ownerDocument; |
| 492 var oldParent = this.element.parentElement; | 495 var oldParent = this.element.parentElement; |
| 493 var oldNextSibling = this.element.nextSibling; | 496 var oldNextSibling = this.element.nextSibling; |
| (...skipping 245 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 739 WebInspector.VBoxWithResizeCallback.prototype = { | 742 WebInspector.VBoxWithResizeCallback.prototype = { |
| 740 onResize: function() | 743 onResize: function() |
| 741 { | 744 { |
| 742 this._resizeCallback(); | 745 this._resizeCallback(); |
| 743 }, | 746 }, |
| 744 | 747 |
| 745 __proto__: WebInspector.VBox.prototype | 748 __proto__: WebInspector.VBox.prototype |
| 746 } | 749 } |
| 747 | 750 |
| 748 /** | 751 /** |
| 752 * @param {!WebInspector.Widget} widget |
| 753 * @constructor |
| 754 */ |
| 755 WebInspector.WidgetFocusRestorer = function(widget) |
| 756 { |
| 757 this._widget = widget; |
| 758 this._previous = widget.element.ownerDocument.deepActiveElement(); |
| 759 widget.focus(); |
| 760 } |
| 761 |
| 762 WebInspector.WidgetFocusRestorer.prototype = { |
| 763 restore: function() |
| 764 { |
| 765 if (!this._widget) |
| 766 return; |
| 767 if (this._widget.hasFocus() && this._previous) |
| 768 this._previous.focus(); |
| 769 this._previous = null; |
| 770 this._widget = null; |
| 771 } |
| 772 } |
| 773 |
| 774 /** |
| 749 * @override | 775 * @override |
| 750 * @param {?Node} child | 776 * @param {?Node} child |
| 751 * @return {?Node} | 777 * @return {?Node} |
| 752 * @suppress {duplicate} | 778 * @suppress {duplicate} |
| 753 */ | 779 */ |
| 754 Element.prototype.appendChild = function(child) | 780 Element.prototype.appendChild = function(child) |
| 755 { | 781 { |
| 756 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."); |
| 757 return WebInspector.Widget._originalAppendChild.call(this, child); | 783 return WebInspector.Widget._originalAppendChild.call(this, child); |
| 758 } | 784 } |
| (...skipping 21 matching lines...) Expand all Loading... |
| 780 { | 806 { |
| 781 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"); |
| 782 return WebInspector.Widget._originalRemoveChild.call(this, child); | 808 return WebInspector.Widget._originalRemoveChild.call(this, child); |
| 783 } | 809 } |
| 784 | 810 |
| 785 Element.prototype.removeChildren = function() | 811 Element.prototype.removeChildren = function() |
| 786 { | 812 { |
| 787 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"); |
| 788 WebInspector.Widget._originalRemoveChildren.call(this); | 814 WebInspector.Widget._originalRemoveChildren.call(this); |
| 789 } | 815 } |
| OLD | NEW |