| 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 229 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 240 } | 240 } |
| 241 | 241 |
| 242 onResize() { | 242 onResize() { |
| 243 } | 243 } |
| 244 | 244 |
| 245 onLayout() { | 245 onLayout() { |
| 246 } | 246 } |
| 247 | 247 |
| 248 /** | 248 /** |
| 249 * @param {!Element} parentElement | 249 * @param {!Element} parentElement |
| 250 * @param {?Node=} insertBefore | 250 * @param {?Element=} insertBefore |
| 251 */ | 251 */ |
| 252 show(parentElement, insertBefore) { | 252 show(parentElement, insertBefore) { |
| 253 UI.Widget.__assert(parentElement, 'Attempt to attach widget with no parent e
lement'); | 253 UI.Widget.__assert(parentElement, 'Attempt to attach widget with no parent e
lement'); |
| 254 | 254 |
| 255 if (!this._isRoot) { | 255 if (!this._isRoot) { |
| 256 // Update widget hierarchy. | 256 // Update widget hierarchy. |
| 257 var currentParent = parentElement; | 257 var currentParent = parentElement; |
| 258 while (currentParent && !currentParent.__widget) | 258 while (currentParent && !currentParent.__widget) |
| 259 currentParent = currentParent.parentElementOrShadowHost(); | 259 currentParent = currentParent.parentElementOrShadowHost(); |
| 260 UI.Widget.__assert(currentParent, 'Attempt to attach widget to orphan node
'); | 260 UI.Widget.__assert(currentParent, 'Attempt to attach widget to orphan node
'); |
| 261 this.attach(currentParent.__widget, parentElement, insertBefore); | 261 this.attach(currentParent.__widget); |
| 262 } else { | |
| 263 this._attachedToParentElement = parentElement; | |
| 264 this._attachedBeforeNode = insertBefore; | |
| 265 } | 262 } |
| 266 | 263 |
| 267 this.showWidget(); | 264 this.showWidget(parentElement, insertBefore); |
| 268 } | 265 } |
| 269 | 266 |
| 270 /** | 267 /** |
| 271 * @param {!UI.Widget} parentWidget | 268 * @param {!UI.Widget} parentWidget |
| 272 * @param {!Element=} parentElement | |
| 273 * @param {?Node=} insertBefore | |
| 274 */ | 269 */ |
| 275 attach(parentWidget, parentElement, insertBefore) { | 270 attach(parentWidget) { |
| 276 parentElement = parentElement || parentWidget.element; | 271 if (parentWidget === this._parentWidget) |
| 277 if (parentWidget === this._parentWidget) { | |
| 278 this._attachedToParentElement = parentElement; | |
| 279 this._attachedBeforeNode = insertBefore; | |
| 280 if (this._visible) | |
| 281 this.showWidget(); | |
| 282 return; | 272 return; |
| 283 } | |
| 284 if (this._parentWidget) | 273 if (this._parentWidget) |
| 285 this.detach(); | 274 this.detach(); |
| 286 this._parentWidget = parentWidget; | 275 this._parentWidget = parentWidget; |
| 287 this._parentWidget._children.push(this); | 276 this._parentWidget._children.push(this); |
| 288 this._attachedToParentElement = parentElement; | |
| 289 this._attachedBeforeNode = insertBefore; | |
| 290 this._isRoot = false; | 277 this._isRoot = false; |
| 291 } | 278 } |
| 292 | 279 |
| 293 showWidget() { | 280 /** |
| 294 UI.Widget.__assert(this._parentWidget || this._isRoot, 'Attempt to show widg
et that has not been attached'); | 281 * @param {!Element} parentElement |
| 295 var parentElement = this._attachedToParentElement; | 282 * @param {?Element=} insertBefore |
| 296 var insertBefore = this._attachedBeforeNode; | 283 */ |
| 297 | 284 showWidget(parentElement, insertBefore) { |
| 298 var currentParent = parentElement; | 285 var currentParent = parentElement; |
| 299 while (currentParent && !currentParent.__widget) | 286 while (currentParent && !currentParent.__widget) |
| 300 currentParent = currentParent.parentElementOrShadowHost(); | 287 currentParent = currentParent.parentElementOrShadowHost(); |
| 301 | 288 |
| 302 if (this._isRoot) { | 289 if (this._isRoot) { |
| 303 UI.Widget.__assert(!currentParent, 'Attempt to show root widget under anot
her widget'); | 290 UI.Widget.__assert(!currentParent, 'Attempt to show root widget under anot
her widget'); |
| 304 } else { | 291 } else { |
| 305 UI.Widget.__assert( | 292 UI.Widget.__assert( |
| 306 currentParent && currentParent.__widget === this._parentWidget, | 293 currentParent && currentParent.__widget === this._parentWidget, |
| 307 'Attempt to show under node belonging to alien widget'); | 294 'Attempt to show under node belonging to alien widget'); |
| (...skipping 22 matching lines...) Expand all Loading... |
| 330 if (!wasVisible && this._parentIsShowing()) | 317 if (!wasVisible && this._parentIsShowing()) |
| 331 this._processWasShown(); | 318 this._processWasShown(); |
| 332 | 319 |
| 333 if (this._parentWidget && this._hasNonZeroConstraints()) | 320 if (this._parentWidget && this._hasNonZeroConstraints()) |
| 334 this._parentWidget.invalidateConstraints(); | 321 this._parentWidget.invalidateConstraints(); |
| 335 else | 322 else |
| 336 this._processOnResize(); | 323 this._processOnResize(); |
| 337 } | 324 } |
| 338 | 325 |
| 339 hideWidget() { | 326 hideWidget() { |
| 340 UI.Widget.__assert(this._parentWidget || this._isRoot, 'Attempt to hide widg
et that has not been attached'); | 327 if (!this._parentWidget) |
| 328 return; |
| 341 this._hideWidget(); | 329 this._hideWidget(); |
| 342 } | 330 } |
| 343 | 331 |
| 344 /** | 332 /** |
| 345 * @param {boolean=} overrideHideOnDetach | 333 * @param {boolean=} overrideHideOnDetach |
| 346 */ | 334 */ |
| 347 _hideWidget(overrideHideOnDetach) { | 335 _hideWidget(overrideHideOnDetach) { |
| 348 if (!this._visible) | 336 if (!this._visible) |
| 349 return; | 337 return; |
| 350 this._visible = false; | 338 this._visible = false; |
| 351 var parentElement = this.element.parentElement; | 339 var parentElement = this.element.parentElement; |
| 352 this._attachedToParentElement = parentElement; | |
| 353 this._attachedBeforeNode = this.element.nextSibling; | |
| 354 | 340 |
| 355 if (this._parentIsShowing()) | 341 if (this._parentIsShowing()) |
| 356 this._processWillHide(); | 342 this._processWillHide(); |
| 357 | 343 |
| 358 if (!overrideHideOnDetach && this.shouldHideOnDetach()) { | 344 if (!overrideHideOnDetach && this.shouldHideOnDetach()) { |
| 359 this.element.classList.add('hidden'); | 345 this.element.classList.add('hidden'); |
| 360 } else { | 346 } else { |
| 361 // Force legal removal | 347 // Force legal removal |
| 362 UI.Widget._decrementWidgetCounter(parentElement, this.element); | 348 UI.Widget._decrementWidgetCounter(parentElement, this.element); |
| 363 UI.Widget._originalRemoveChild.call(parentElement, this.element); | 349 UI.Widget._originalRemoveChild.call(parentElement, this.element); |
| (...skipping 18 matching lines...) Expand all Loading... |
| 382 UI.Widget.__assert(childIndex >= 0, 'Attempt to remove non-child widget'); | 368 UI.Widget.__assert(childIndex >= 0, 'Attempt to remove non-child widget'); |
| 383 this._parentWidget._children.splice(childIndex, 1); | 369 this._parentWidget._children.splice(childIndex, 1); |
| 384 if (this._parentWidget._defaultFocusedChild === this) | 370 if (this._parentWidget._defaultFocusedChild === this) |
| 385 this._parentWidget._defaultFocusedChild = null; | 371 this._parentWidget._defaultFocusedChild = null; |
| 386 this._parentWidget.childWasDetached(this); | 372 this._parentWidget.childWasDetached(this); |
| 387 this._parentWidget = null; | 373 this._parentWidget = null; |
| 388 this._processWasDetachedFromHierarchy(); | 374 this._processWasDetachedFromHierarchy(); |
| 389 } else { | 375 } else { |
| 390 UI.Widget.__assert(this._isRoot, 'Removing non-root widget from DOM'); | 376 UI.Widget.__assert(this._isRoot, 'Removing non-root widget from DOM'); |
| 391 } | 377 } |
| 392 | |
| 393 this._attachedToParentElement = null; | |
| 394 this._attachedBeforeNode = null; | |
| 395 } | 378 } |
| 396 | 379 |
| 397 detachChildWidgets() { | 380 detachChildWidgets() { |
| 398 var children = this._children.slice(); | 381 var children = this._children.slice(); |
| 399 for (var i = 0; i < children.length; ++i) | 382 for (var i = 0; i < children.length; ++i) |
| 400 children[i].detach(); | 383 children[i].detach(); |
| 401 } | 384 } |
| 402 | 385 |
| 403 /** | 386 /** |
| 404 * @return {!Array.<!Element>} | 387 * @return {!Array.<!Element>} |
| (...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 595 } | 578 } |
| 596 this._invalidationsRequested = false; | 579 this._invalidationsRequested = false; |
| 597 var cached = this._cachedConstraints; | 580 var cached = this._cachedConstraints; |
| 598 delete this._cachedConstraints; | 581 delete this._cachedConstraints; |
| 599 var actual = this.constraints(); | 582 var actual = this.constraints(); |
| 600 if (!actual.isEqual(cached) && this._parentWidget) | 583 if (!actual.isEqual(cached) && this._parentWidget) |
| 601 this._parentWidget.invalidateConstraints(); | 584 this._parentWidget.invalidateConstraints(); |
| 602 else | 585 else |
| 603 this.doLayout(); | 586 this.doLayout(); |
| 604 } | 587 } |
| 588 |
| 589 invalidateSize() { |
| 590 if (this._parentWidget) |
| 591 this._parentWidget.doLayout(); |
| 592 } |
| 605 }; | 593 }; |
| 606 | 594 |
| 607 UI.Widget._originalAppendChild = Element.prototype.appendChild; | 595 UI.Widget._originalAppendChild = Element.prototype.appendChild; |
| 608 UI.Widget._originalInsertBefore = Element.prototype.insertBefore; | 596 UI.Widget._originalInsertBefore = Element.prototype.insertBefore; |
| 609 UI.Widget._originalRemoveChild = Element.prototype.removeChild; | 597 UI.Widget._originalRemoveChild = Element.prototype.removeChild; |
| 610 UI.Widget._originalRemoveChildren = Element.prototype.removeChildren; | 598 UI.Widget._originalRemoveChildren = Element.prototype.removeChildren; |
| 611 | 599 |
| 612 | 600 |
| 613 /** | 601 /** |
| 614 * @unrestricted | 602 * @unrestricted |
| (...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 756 UI.Widget.__assert( | 744 UI.Widget.__assert( |
| 757 !child.__widgetCounter && !child.__widget, | 745 !child.__widgetCounter && !child.__widget, |
| 758 'Attempt to remove element containing widget via regular DOM operation'); | 746 'Attempt to remove element containing widget via regular DOM operation'); |
| 759 return UI.Widget._originalRemoveChild.call(this, child); | 747 return UI.Widget._originalRemoveChild.call(this, child); |
| 760 }; | 748 }; |
| 761 | 749 |
| 762 Element.prototype.removeChildren = function() { | 750 Element.prototype.removeChildren = function() { |
| 763 UI.Widget.__assert(!this.__widgetCounter, 'Attempt to remove element containin
g widget via regular DOM operation'); | 751 UI.Widget.__assert(!this.__widgetCounter, 'Attempt to remove element containin
g widget via regular DOM operation'); |
| 764 UI.Widget._originalRemoveChildren.call(this); | 752 UI.Widget._originalRemoveChildren.call(this); |
| 765 }; | 753 }; |
| OLD | NEW |