Chromium Code Reviews| 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 30 matching lines...) Expand all Loading... | |
| 41 } | 41 } |
| 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._lastFocusedChild = null; | |
| 51 } | 52 } |
| 52 | 53 |
| 53 WebInspector.Widget.prototype = { | 54 WebInspector.Widget.prototype = { |
| 54 markAsRoot: function() | 55 markAsRoot: function() |
| 55 { | 56 { |
| 56 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"); |
| 57 this._isRoot = true; | 58 this._isRoot = true; |
| 58 }, | 59 }, |
| 59 | 60 |
| 60 /** | 61 /** |
| (...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 231 * @param {!WebInspector.Widget} parentWidget | 232 * @param {!WebInspector.Widget} parentWidget |
| 232 */ | 233 */ |
| 233 attach: function(parentWidget) | 234 attach: function(parentWidget) |
| 234 { | 235 { |
| 235 if (parentWidget === this._parentWidget) | 236 if (parentWidget === this._parentWidget) |
| 236 return; | 237 return; |
| 237 if (this._parentWidget) | 238 if (this._parentWidget) |
| 238 this.detach(); | 239 this.detach(); |
| 239 this._parentWidget = parentWidget; | 240 this._parentWidget = parentWidget; |
| 240 this._parentWidget._children.push(this); | 241 this._parentWidget._children.push(this); |
| 242 if (!this._parentWidget._lastFocusedChild) | |
| 243 this._parentWidget._lastFocusedChild = this; | |
| 241 this._isRoot = false; | 244 this._isRoot = false; |
| 242 }, | 245 }, |
| 243 | 246 |
| 244 /** | 247 /** |
| 245 * @param {!Element} parentElement | 248 * @param {!Element} parentElement |
| 246 * @param {?Element=} insertBefore | 249 * @param {?Element=} insertBefore |
| 247 */ | 250 */ |
| 248 showWidget: function(parentElement, insertBefore) | 251 showWidget: function(parentElement, insertBefore) |
| 249 { | 252 { |
| 250 var currentParent = parentElement; | 253 var currentParent = parentElement; |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 325 return; | 328 return; |
| 326 | 329 |
| 327 if (this._visible) | 330 if (this._visible) |
| 328 this._hideWidget(true); | 331 this._hideWidget(true); |
| 329 | 332 |
| 330 // Update widget hierarchy. | 333 // Update widget hierarchy. |
| 331 if (this._parentWidget) { | 334 if (this._parentWidget) { |
| 332 var childIndex = this._parentWidget._children.indexOf(this); | 335 var childIndex = this._parentWidget._children.indexOf(this); |
| 333 WebInspector.Widget.__assert(childIndex >= 0, "Attempt to remove non -child widget"); | 336 WebInspector.Widget.__assert(childIndex >= 0, "Attempt to remove non -child widget"); |
| 334 this._parentWidget._children.splice(childIndex, 1); | 337 this._parentWidget._children.splice(childIndex, 1); |
| 338 if (this._parentWidget._lastFocusedChild === this) | |
| 339 this._parentWidget._lastFocusedChild = this._parentWidget._child ren[0] || null; | |
| 335 this._parentWidget.childWasDetached(this); | 340 this._parentWidget.childWasDetached(this); |
| 336 var parent = this._parentWidget; | 341 var parent = this._parentWidget; |
| 337 this._parentWidget = null; | 342 this._parentWidget = null; |
| 338 } else { | 343 } else { |
| 339 WebInspector.Widget.__assert(this._isRoot, "Removing non-root widget from DOM"); | 344 WebInspector.Widget.__assert(this._isRoot, "Removing non-root widget from DOM"); |
| 340 } | 345 } |
| 341 }, | 346 }, |
| 342 | 347 |
| 343 detachChildWidgets: function() | 348 detachChildWidgets: function() |
| 344 { | 349 { |
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 421 }, | 426 }, |
| 422 | 427 |
| 423 /** | 428 /** |
| 424 * @param {!Element} element | 429 * @param {!Element} element |
| 425 */ | 430 */ |
| 426 setDefaultFocusedElement: function(element) | 431 setDefaultFocusedElement: function(element) |
| 427 { | 432 { |
| 428 this._defaultFocusedElement = element; | 433 this._defaultFocusedElement = element; |
| 429 }, | 434 }, |
| 430 | 435 |
| 436 makeDefaultFocused: function() | |
|
pfeldman
2016/09/08 00:53:50
I'd rather have it on the parent.
| |
| 437 { | |
| 438 if (this._parentWidget) | |
| 439 this._parentWidget._lastFocusedChild = this; | |
|
pfeldman
2016/09/08 00:53:50
You should now call it defaultFocusChild...
| |
| 440 }, | |
| 441 | |
| 431 focus: function() | 442 focus: function() |
| 432 { | 443 { |
| 433 var element = this._defaultFocusedElement; | 444 var element = this._defaultFocusedElement; |
| 434 if (element && !element.isAncestor(this.element.ownerDocument.activeElem ent)) { | 445 if (element && !element.isAncestor(this.element.ownerDocument.activeElem ent)) { |
| 435 WebInspector.setCurrentFocusElement(element); | 446 WebInspector.setCurrentFocusElement(element); |
| 436 return; | 447 return; |
| 437 } | 448 } |
| 438 | 449 |
| 439 if (this._children.length) | 450 if (this._lastFocusedChild) |
| 440 this._children[0].focus(); | 451 this._lastFocusedChild.focus(); |
| 452 }, | |
| 453 | |
| 454 _wasFocused: function() | |
| 455 { | |
| 456 var widget = this; | |
| 457 while (widget._parentWidget) { | |
| 458 widget._parentWidget._lastFocusedChild = widget; | |
| 459 widget = widget._parentWidget; | |
| 460 } | |
| 441 }, | 461 }, |
| 442 | 462 |
| 443 /** | 463 /** |
| 444 * @return {boolean} | 464 * @return {boolean} |
| 445 */ | 465 */ |
| 446 hasFocus: function() | 466 hasFocus: function() |
| 447 { | 467 { |
| 448 var activeElement = this.element.ownerDocument.activeElement; | 468 var activeElement = this.element.ownerDocument.activeElement; |
| 449 return activeElement && activeElement.isSelfOrDescendant(this.element); | 469 return activeElement && activeElement.isSelfOrDescendant(this.element); |
| 450 }, | 470 }, |
| (...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 589 | 609 |
| 590 WebInspector.Widget.__assert = function(condition, message) | 610 WebInspector.Widget.__assert = function(condition, message) |
| 591 { | 611 { |
| 592 if (!condition) { | 612 if (!condition) { |
| 593 console.trace(); | 613 console.trace(); |
| 594 throw new Error(message); | 614 throw new Error(message); |
| 595 } | 615 } |
| 596 } | 616 } |
| 597 | 617 |
| 598 /** | 618 /** |
| 619 * @param {?Node} node | |
| 620 */ | |
| 621 WebInspector.Widget.focusWidgetForNode = function(node) | |
| 622 { | |
| 623 while (node) { | |
| 624 if (node.__widget) { | |
| 625 node.__widget._wasFocused(); | |
| 626 return; | |
| 627 } | |
| 628 node = node.parentNodeOrShadowHost(); | |
| 629 } | |
| 630 } | |
| 631 | |
| 632 /** | |
| 599 * @constructor | 633 * @constructor |
| 600 * @extends {WebInspector.Widget} | 634 * @extends {WebInspector.Widget} |
| 601 * @param {boolean=} isWebComponent | 635 * @param {boolean=} isWebComponent |
| 602 */ | 636 */ |
| 603 WebInspector.VBox = function(isWebComponent) | 637 WebInspector.VBox = function(isWebComponent) |
| 604 { | 638 { |
| 605 WebInspector.Widget.call(this, isWebComponent); | 639 WebInspector.Widget.call(this, isWebComponent); |
| 606 this.contentElement.classList.add("vbox"); | 640 this.contentElement.classList.add("vbox"); |
| 607 }; | 641 }; |
| 608 | 642 |
| (...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 726 { | 760 { |
| 727 WebInspector.Widget.__assert(!child.__widgetCounter && !child.__widget, "Att empt to remove element containing widget via regular DOM operation"); | 761 WebInspector.Widget.__assert(!child.__widgetCounter && !child.__widget, "Att empt to remove element containing widget via regular DOM operation"); |
| 728 return WebInspector.Widget._originalRemoveChild.call(this, child); | 762 return WebInspector.Widget._originalRemoveChild.call(this, child); |
| 729 } | 763 } |
| 730 | 764 |
| 731 Element.prototype.removeChildren = function() | 765 Element.prototype.removeChildren = function() |
| 732 { | 766 { |
| 733 WebInspector.Widget.__assert(!this.__widgetCounter, "Attempt to remove eleme nt containing widget via regular DOM operation"); | 767 WebInspector.Widget.__assert(!this.__widgetCounter, "Attempt to remove eleme nt containing widget via regular DOM operation"); |
| 734 WebInspector.Widget._originalRemoveChildren.call(this); | 768 WebInspector.Widget._originalRemoveChildren.call(this); |
| 735 } | 769 } |
| OLD | NEW |