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

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: add test 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 27 matching lines...) Expand all
38 value: false, 38 value: false,
39 }, 39 },
40 40
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 observers: ['onOpenChanged_(open)'],
dpapad 2017/04/13 01:12:12 You probably checked this already, but does this w
scottchen 2017/04/13 20:17:51 It does work, but unfortunately found out that obs
49
48 /** @private {?IntersectionObserver} */ 50 /** @private {?IntersectionObserver} */
49 intersectionObserver_: null, 51 intersectionObserver_: null,
50 52
51 /** @override */ 53 /** @override */
52 ready: function() { 54 ready: function() {
53 // If the active history entry changes (i.e. user clicks back button), 55 // If the active history entry changes (i.e. user clicks back button),
54 // all open dialogs should be cancelled. 56 // all open dialogs should be cancelled.
55 window.addEventListener('popstate', function() { 57 window.addEventListener('popstate', function() {
56 if (!this.ignorePopstate && this.open) 58 if (!this.ignorePopstate && this.open)
57 this.cancel(); 59 this.cancel();
58 }.bind(this)); 60 }.bind(this));
59 61
60 if (!this.ignoreEnterKey) 62 if (!this.ignoreEnterKey)
61 this.addEventListener('keypress', this.onKeypress_.bind(this)); 63 this.addEventListener('keypress', this.onKeypress_.bind(this));
62 }, 64 },
63 65
64 /** @override */ 66 /** @private */
65 attached: function() { 67 onOpenChanged_: function() {
66 if (this.showScrollBorders) { 68 if (!this.showScrollBorders) {
69 return;
70 }
71
72 if (this.open !== null && !this.intersectionObserver_) {
67 var bodyContainer = this.$$('.body-container'); 73 var bodyContainer = this.$$('.body-container');
68 74
69 var bottomMarker = this.$.bodyBottomMarker; 75 var bottomMarker = this.$.bodyBottomMarker;
70 var topMarker = this.$.bodyTopMarker; 76 var topMarker = this.$.bodyTopMarker;
71 77
72 var callback = function(entries) { 78 var callback = function(entries) {
73 assert(entries.length <= 2); 79 assert(entries.length <= 2);
74 for (var i = 0; i < entries.length; i++) { 80 for (var i = 0; i < entries.length; i++) {
75 var target = entries[i].target; 81 var target = entries[i].target;
76 assert(target == bottomMarker || target == topMarker); 82 assert(target == bottomMarker || target == topMarker);
77 83
78 var classToToggle = 84 var classToToggle =
79 target == bottomMarker ? 'bottom-scrollable' : 'top-scrollable'; 85 target == bottomMarker ? 'bottom-scrollable' : 'top-scrollable';
80 86
81 bodyContainer.classList.toggle( 87 bodyContainer.classList.toggle(
82 classToToggle, entries[i].intersectionRatio == 0); 88 classToToggle, entries[i].intersectionRatio == 0);
83 } 89 }
84 }; 90 };
85 91
86 this.intersectionObserver_ = new IntersectionObserver( 92 this.intersectionObserver_ = new IntersectionObserver(
87 callback, 93 callback,
88 /** @type {IntersectionObserverInit} */ ({ 94 /** @type {IntersectionObserverInit} */ ({
89 root: bodyContainer, 95 root: bodyContainer,
90 threshold: 0, 96 threshold: 0,
91 })); 97 }));
98
92 this.intersectionObserver_.observe(bottomMarker); 99 this.intersectionObserver_.observe(bottomMarker);
93 this.intersectionObserver_.observe(topMarker); 100 this.intersectionObserver_.observe(topMarker);
94 } 101 } else if (this.open === null && this.intersectionObserver_) {
95 },
96
97 /** @override */
98 detached: function() {
99 if (this.intersectionObserver_) {
100 this.intersectionObserver_.disconnect(); 102 this.intersectionObserver_.disconnect();
101 this.intersectionObserver_ = null; 103 this.intersectionObserver_ = null;
102 } 104 }
103 }, 105 },
104 106
105 cancel: function() { 107 cancel: function() {
106 this.fire('cancel'); 108 this.fire('cancel');
107 HTMLDialogElement.prototype.close.call(this, ''); 109 HTMLDialogElement.prototype.close.call(this, '');
108 }, 110 },
109 111
(...skipping 23 matching lines...) Expand all
133 return; 135 return;
134 136
135 var actionButton = 137 var actionButton =
136 this.querySelector('.action-button:not([disabled]):not([hidden])'); 138 this.querySelector('.action-button:not([disabled]):not([hidden])');
137 if (actionButton) { 139 if (actionButton) {
138 actionButton.click(); 140 actionButton.click();
139 e.preventDefault(); 141 e.preventDefault();
140 } 142 }
141 }, 143 },
142 }); 144 });
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