Chromium Code Reviews| Index: ui/webui/resources/cr_elements/cr_dialog/cr_dialog.js |
| diff --git a/ui/webui/resources/cr_elements/cr_dialog/cr_dialog.js b/ui/webui/resources/cr_elements/cr_dialog/cr_dialog.js |
| index c98c75ac4053eda397cdc7758103f9edb91fd87d..3879b397f77bb1cd4a9543250d52f4ea0c7e4932 100644 |
| --- a/ui/webui/resources/cr_elements/cr_dialog/cr_dialog.js |
| +++ b/ui/webui/resources/cr_elements/cr_dialog/cr_dialog.js |
| @@ -48,6 +48,9 @@ Polymer({ |
| /** @private {?IntersectionObserver} */ |
| intersectionObserver_: null, |
| + /** @private {?MutationObserver} */ |
| + mutationObserver_: null, |
| + |
| /** @override */ |
| ready: function() { |
| // If the active history entry changes (i.e. user clicks back button), |
| @@ -64,6 +67,34 @@ Polymer({ |
| /** @override */ |
| attached: function() { |
| if (this.showScrollBorders) { |
| + this.mutationObserver_ = new MutationObserver(function() { |
| + if (this.open) { |
| + this.addIntersectionObserver_(); |
| + } else { |
| + this.removeIntersectionObserver_(); |
| + } |
| + }.bind(this)); |
| + |
| + var observerConfig = { |
|
dpapad
2017/04/13 20:31:39
Nit (optional): Since this is only used once below
scottchen
2017/04/13 21:46:04
Done.
|
| + attributes: true, |
| + attributeFilter: ['open'], |
| + }; |
| + |
| + this.mutationObserver_.observe(this, observerConfig); |
| + } |
| + }, |
| + |
| + /** @override */ |
| + detached: function() { |
| + if (this.mutationObserver_) { |
| + this.mutationObserver_.disconnect(); |
| + this.mutationObserver_ = null; |
| + } |
|
dpapad
2017/04/13 20:31:39
Previous code was removing the IntersectionObserve
scottchen
2017/04/13 21:46:04
Yes, will leak. Fixed.
|
| + }, |
| + |
| + /** @private */ |
| + addIntersectionObserver_: function() { |
| + if (!this.intersectionObserver_) { |
| var bodyContainer = this.$$('.body-container'); |
| var bottomMarker = this.$.bodyBottomMarker; |
| @@ -89,13 +120,14 @@ Polymer({ |
| root: bodyContainer, |
| threshold: 0, |
| })); |
| + |
|
dpapad
2017/04/13 20:31:39
Nit (optional): Revert this?
scottchen
2017/04/13 21:46:04
Done.
|
| this.intersectionObserver_.observe(bottomMarker); |
| this.intersectionObserver_.observe(topMarker); |
| } |
| }, |
| - /** @override */ |
| - detached: function() { |
| + /** @private */ |
| + removeIntersectionObserver_: function() { |
| if (this.intersectionObserver_) { |
| this.intersectionObserver_.disconnect(); |
| this.intersectionObserver_ = null; |