Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(914)

Side by Side Diff: ui/webui/resources/cr_elements/cr_dialog/cr_dialog.js

Issue 2815623005: MD Settings: in cr_dialog, prevent intersectionObserver from firing early. (Closed)
Patch Set: updates based on comments Created 3 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « chrome/test/data/webui/cr_elements/cr_dialog_test.js ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 /** 5 /**
6 * @fileoverview 'cr-dialog' is a component for showing a modal dialog. If the 6 * @fileoverview 'cr-dialog' is a component for showing a modal dialog. If the
7 * dialog is closed via close(), a 'close' event is fired. If the dialog is 7 * dialog is closed via close(), a 'close' event is fired. If the dialog is
8 * canceled via cancel(), a 'cancel' event is fired followed by a 'close' event. 8 * canceled via cancel(), a 'cancel' event is fired followed by a 'close' event.
9 * Additionally clients can inspect the dialog's |returnValue| property inside 9 * Additionally clients can inspect the dialog's |returnValue| property inside
10 * the 'close' event listener to determine whether it was canceled or just 10 * the 'close' event listener to determine whether it was canceled or just
(...skipping 30 matching lines...) Expand all
41 showScrollBorders: { 41 showScrollBorders: {
42 type: Boolean, 42 type: Boolean,
43 value: false, 43 value: false,
44 reflectToAttribute: true, 44 reflectToAttribute: true,
45 }, 45 },
46 }, 46 },
47 47
48 /** @private {?IntersectionObserver} */ 48 /** @private {?IntersectionObserver} */
49 intersectionObserver_: null, 49 intersectionObserver_: null,
50 50
51 /** @private {?MutationObserver} */
52 mutationObserver_: null,
53
51 /** @override */ 54 /** @override */
52 ready: function() { 55 ready: function() {
53 // If the active history entry changes (i.e. user clicks back button), 56 // If the active history entry changes (i.e. user clicks back button),
54 // all open dialogs should be cancelled. 57 // all open dialogs should be cancelled.
55 window.addEventListener('popstate', function() { 58 window.addEventListener('popstate', function() {
56 if (!this.ignorePopstate && this.open) 59 if (!this.ignorePopstate && this.open)
57 this.cancel(); 60 this.cancel();
58 }.bind(this)); 61 }.bind(this));
59 62
60 if (!this.ignoreEnterKey) 63 if (!this.ignoreEnterKey)
61 this.addEventListener('keypress', this.onKeypress_.bind(this)); 64 this.addEventListener('keypress', this.onKeypress_.bind(this));
62 }, 65 },
63 66
64 /** @override */ 67 /** @override */
65 attached: function() { 68 attached: function() {
66 if (this.showScrollBorders) { 69 if (this.showScrollBorders) {
70 this.mutationObserver_ = new MutationObserver(function() {
71 if (this.open) {
72 this.addIntersectionObserver_();
73 } else {
74 this.removeIntersectionObserver_();
75 }
76 }.bind(this));
77
78 this.mutationObserver_.observe(this, {
79 attributes: true,
80 attributeFilter: ['open'],
81 });
82 }
83 },
84
85 /** @override */
86 detached: function() {
87 this.removeIntersectionObserver_();
88 if (this.mutationObserver_) {
89 this.mutationObserver_.disconnect();
90 this.mutationObserver_ = null;
91 }
92 },
93
94 /** @private */
95 addIntersectionObserver_: function() {
dpapad 2017/04/13 22:02:03 Nit: You can reduce indentation throughout this me
scottchen 2017/04/13 22:33:29 Done.
96 if (!this.intersectionObserver_) {
67 var bodyContainer = this.$$('.body-container'); 97 var bodyContainer = this.$$('.body-container');
68 98
69 var bottomMarker = this.$.bodyBottomMarker; 99 var bottomMarker = this.$.bodyBottomMarker;
70 var topMarker = this.$.bodyTopMarker; 100 var topMarker = this.$.bodyTopMarker;
71 101
72 var callback = function(entries) { 102 var callback = function(entries) {
73 assert(entries.length <= 2); 103 assert(entries.length <= 2);
74 for (var i = 0; i < entries.length; i++) { 104 for (var i = 0; i < entries.length; i++) {
75 var target = entries[i].target; 105 var target = entries[i].target;
76 assert(target == bottomMarker || target == topMarker); 106 assert(target == bottomMarker || target == topMarker);
(...skipping 10 matching lines...) Expand all
87 callback, 117 callback,
88 /** @type {IntersectionObserverInit} */ ({ 118 /** @type {IntersectionObserverInit} */ ({
89 root: bodyContainer, 119 root: bodyContainer,
90 threshold: 0, 120 threshold: 0,
91 })); 121 }));
92 this.intersectionObserver_.observe(bottomMarker); 122 this.intersectionObserver_.observe(bottomMarker);
93 this.intersectionObserver_.observe(topMarker); 123 this.intersectionObserver_.observe(topMarker);
94 } 124 }
95 }, 125 },
96 126
97 /** @override */ 127 /** @private */
98 detached: function() { 128 removeIntersectionObserver_: function() {
99 if (this.intersectionObserver_) { 129 if (this.intersectionObserver_) {
100 this.intersectionObserver_.disconnect(); 130 this.intersectionObserver_.disconnect();
101 this.intersectionObserver_ = null; 131 this.intersectionObserver_ = null;
102 } 132 }
103 }, 133 },
104 134
105 cancel: function() { 135 cancel: function() {
106 this.fire('cancel'); 136 this.fire('cancel');
107 HTMLDialogElement.prototype.close.call(this, ''); 137 HTMLDialogElement.prototype.close.call(this, '');
108 }, 138 },
(...skipping 24 matching lines...) Expand all
133 return; 163 return;
134 164
135 var actionButton = 165 var actionButton =
136 this.querySelector('.action-button:not([disabled]):not([hidden])'); 166 this.querySelector('.action-button:not([disabled]):not([hidden])');
137 if (actionButton) { 167 if (actionButton) {
138 actionButton.click(); 168 actionButton.click();
139 e.preventDefault(); 169 e.preventDefault();
140 } 170 }
141 }, 171 },
142 }); 172 });
OLDNEW
« no previous file with comments | « chrome/test/data/webui/cr_elements/cr_dialog_test.js ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698