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._defaultFocusedChild = 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._defaultFocusedChild) | |
|
dgozman
2016/09/12 18:24:54
I think we can now remove this one, as we iterate
einbinder
2016/09/12 18:37:12
Done.
| |
| 243 this._parentWidget._defaultFocusedChild = 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._defaultFocusedChild === this) | |
| 339 this._parentWidget._defaultFocusedChild = this._parentWidget._ch ildren[0] || null; | |
|
dgozman
2016/09/12 18:24:54
Just set to null here?
einbinder
2016/09/12 18:37:12
Done.
| |
| 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 /** | |
| 437 * @param {!WebInspector.Widget} child | |
| 438 */ | |
| 439 setDefaultFocusedChild: function(child) | |
| 440 { | |
| 441 WebInspector.Widget.__assert(child._parentWidget === this, "Attempt to s et non-child widget as default focused."); | |
| 442 this._defaultFocusedChild = child; | |
| 443 }, | |
| 444 | |
| 431 focus: function() | 445 focus: function() |
| 432 { | 446 { |
| 433 var element = this._defaultFocusedElement; | 447 var element = this._defaultFocusedElement; |
| 434 if (element && !element.isAncestor(this.element.ownerDocument.activeElem ent)) { | 448 if (element && !element.isAncestor(this.element.ownerDocument.activeElem ent)) { |
| 435 WebInspector.setCurrentFocusElement(element); | 449 WebInspector.setCurrentFocusElement(element); |
| 436 return; | 450 return; |
| 437 } | 451 } |
| 438 | 452 |
| 439 if (this._children.length) | 453 if (this._defaultFocusedChild && this._defaultFocusedChild._visible) { |
| 440 this._children[0].focus(); | 454 this._defaultFocusedChild.focus(); |
| 455 } | |
| 456 else { | |
|
dgozman
2016/09/12 18:24:54
style: else on the same line as }
einbinder
2016/09/12 18:37:12
Done.
| |
| 457 for (var child of this._children) { | |
| 458 if (child._visible) { | |
| 459 child.focus(); | |
| 460 break; | |
| 461 } | |
| 462 } | |
| 463 } | |
| 464 | |
| 441 }, | 465 }, |
| 442 | 466 |
| 443 /** | 467 /** |
| 444 * @return {boolean} | 468 * @return {boolean} |
| 445 */ | 469 */ |
| 446 hasFocus: function() | 470 hasFocus: function() |
| 447 { | 471 { |
| 448 var activeElement = this.element.ownerDocument.activeElement; | 472 var activeElement = this.element.ownerDocument.activeElement; |
| 449 return activeElement && activeElement.isSelfOrDescendant(this.element); | 473 return activeElement && activeElement.isSelfOrDescendant(this.element); |
| 450 }, | 474 }, |
| (...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 589 | 613 |
| 590 WebInspector.Widget.__assert = function(condition, message) | 614 WebInspector.Widget.__assert = function(condition, message) |
| 591 { | 615 { |
| 592 if (!condition) { | 616 if (!condition) { |
| 593 console.trace(); | 617 console.trace(); |
| 594 throw new Error(message); | 618 throw new Error(message); |
| 595 } | 619 } |
| 596 } | 620 } |
| 597 | 621 |
| 598 /** | 622 /** |
| 623 * @param {?Node} node | |
| 624 */ | |
| 625 WebInspector.Widget.focusWidgetForNode = function(node) | |
| 626 { | |
| 627 while (node) { | |
|
dgozman
2016/09/12 18:24:54
nit: I'd split this into two loops:
while (node &
einbinder
2016/09/12 18:37:12
Done.
| |
| 628 if (node.__widget) { | |
| 629 var widget = node.__widget; | |
| 630 while (widget._parentWidget) { | |
| 631 widget._parentWidget._defaultFocusedChild = widget; | |
| 632 widget = widget._parentWidget; | |
| 633 } | |
| 634 return; | |
| 635 } | |
| 636 node = node.parentNodeOrShadowHost(); | |
| 637 } | |
| 638 } | |
| 639 | |
| 640 /** | |
| 599 * @constructor | 641 * @constructor |
| 600 * @extends {WebInspector.Widget} | 642 * @extends {WebInspector.Widget} |
| 601 * @param {boolean=} isWebComponent | 643 * @param {boolean=} isWebComponent |
| 602 */ | 644 */ |
| 603 WebInspector.VBox = function(isWebComponent) | 645 WebInspector.VBox = function(isWebComponent) |
| 604 { | 646 { |
| 605 WebInspector.Widget.call(this, isWebComponent); | 647 WebInspector.Widget.call(this, isWebComponent); |
| 606 this.contentElement.classList.add("vbox"); | 648 this.contentElement.classList.add("vbox"); |
| 607 }; | 649 }; |
| 608 | 650 |
| (...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 726 { | 768 { |
| 727 WebInspector.Widget.__assert(!child.__widgetCounter && !child.__widget, "Att empt to remove element containing widget via regular DOM operation"); | 769 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); | 770 return WebInspector.Widget._originalRemoveChild.call(this, child); |
| 729 } | 771 } |
| 730 | 772 |
| 731 Element.prototype.removeChildren = function() | 773 Element.prototype.removeChildren = function() |
| 732 { | 774 { |
| 733 WebInspector.Widget.__assert(!this.__widgetCounter, "Attempt to remove eleme nt containing widget via regular DOM operation"); | 775 WebInspector.Widget.__assert(!this.__widgetCounter, "Attempt to remove eleme nt containing widget via regular DOM operation"); |
| 734 WebInspector.Widget._originalRemoveChildren.call(this); | 776 WebInspector.Widget._originalRemoveChildren.call(this); |
| 735 } | 777 } |
| OLD | NEW |