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

Side by Side Diff: third_party/WebKit/Source/devtools/front_end/ui/GlassPane.js

Issue 2706293007: [DevTools] Fix Dialog's close button to properly close dialog. (Closed)
Patch Set: test Created 3 years, 10 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
OLDNEW
1 // Copyright 2017 The Chromium Authors. All rights reserved. 1 // Copyright 2017 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 UI.GlassPane = class extends UI.Widget { 5 UI.GlassPane = class {
6 constructor() { 6 constructor() {
7 super(true); 7 this._widget = new UI.Widget(true);
8 this.markAsRoot(); 8 this._widget.markAsRoot();
9 this.element = this._widget.element;
10 this.contentElement = this._widget.contentElement;
11
9 this.registerRequiredCSS('ui/glassPane.css'); 12 this.registerRequiredCSS('ui/glassPane.css');
10 this.element.classList.add('no-pointer-events'); 13 this.element.classList.add('no-pointer-events');
11 this._onMouseDownBound = this._onMouseDown.bind(this); 14 this._onMouseDownBound = this._onMouseDown.bind(this);
12 /** @type {?function(!Event)} */ 15 /** @type {?function(!Event)} */
13 this._onClickOutsideCallback = null; 16 this._onClickOutsideCallback = null;
14 /** @type {?UI.Size} */ 17 /** @type {?UI.Size} */
15 this._maxSize = null; 18 this._maxSize = null;
16 /** @type {?number} */ 19 /** @type {?number} */
17 this._positionX = null; 20 this._positionX = null;
18 /** @type {?number} */ 21 /** @type {?number} */
19 this._positionY = null; 22 this._positionY = null;
20 /** @type {?AnchorBox} */ 23 /** @type {?AnchorBox} */
21 this._anchorBox = null; 24 this._anchorBox = null;
22 this._anchorBehavior = UI.GlassPane.AnchorBehavior.PreferTop; 25 this._anchorBehavior = UI.GlassPane.AnchorBehavior.PreferTop;
23 this._sizeBehavior = UI.GlassPane.SizeBehavior.SetHeight; 26 this._sizeBehavior = UI.GlassPane.SizeBehavior.SetHeight;
24 } 27 }
25 28
26 /** 29 /**
30 * @return {boolean}
31 */
32 isShowing() {
33 return this._widget.isShowing();
34 }
35
36 /**
37 * @param {string} cssFile
38 */
39 registerRequiredCSS(cssFile) {
40 this._widget.registerRequiredCSS(cssFile);
41 }
42
43 /**
27 * @param {boolean} dimmed 44 * @param {boolean} dimmed
28 */ 45 */
29 setDimmed(dimmed) { 46 setDimmed(dimmed) {
30 this.element.classList.toggle('dimmed-pane', dimmed); 47 this.element.classList.toggle('dimmed-pane', dimmed);
31 } 48 }
32 49
33 /** 50 /**
34 * @param {boolean} blockPointerEvents 51 * @param {boolean} blockPointerEvents
35 */ 52 */
36 setBlockPointerEvents(blockPointerEvents) { 53 setBlockPointerEvents(blockPointerEvents) {
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
83 /** 100 /**
84 * @param {!UI.GlassPane.AnchorBehavior} behavior 101 * @param {!UI.GlassPane.AnchorBehavior} behavior
85 */ 102 */
86 setAnchorBehavior(behavior) { 103 setAnchorBehavior(behavior) {
87 this._anchorBehavior = behavior; 104 this._anchorBehavior = behavior;
88 } 105 }
89 106
90 /** 107 /**
91 * @param {!Document} document 108 * @param {!Document} document
92 */ 109 */
93 showGlassPane(document) { 110 show(document) {
94 if (this.isShowing()) 111 if (this.isShowing())
95 return; 112 return;
96 // Deliberately starts with 3000 to hide other z-indexed elements below. 113 // Deliberately starts with 3000 to hide other z-indexed elements below.
97 this.element.style.zIndex = 3000 + 1000 * UI.GlassPane._panes.size; 114 this.element.style.zIndex = 3000 + 1000 * UI.GlassPane._panes.size;
98 document.body.addEventListener('mousedown', this._onMouseDownBound, true); 115 document.body.addEventListener('mousedown', this._onMouseDownBound, true);
99 this.show(document.body); 116 this._widget.show(document.body);
100 UI.GlassPane._panes.add(this); 117 UI.GlassPane._panes.add(this);
101 this._positionContent(); 118 this._positionContent();
102 } 119 }
103 120
104 hideGlassPane() { 121 hide() {
105 if (!this.isShowing()) 122 if (!this.isShowing())
106 return; 123 return;
107 UI.GlassPane._panes.delete(this); 124 UI.GlassPane._panes.delete(this);
108 this.element.ownerDocument.body.removeEventListener('mousedown', this._onMou seDownBound, true); 125 this.element.ownerDocument.body.removeEventListener('mousedown', this._onMou seDownBound, true);
109 this.detach(); 126 this._widget.detach();
110 } 127 }
111 128
112 /** 129 /**
113 * @param {!Event} event 130 * @param {!Event} event
114 */ 131 */
115 _onMouseDown(event) { 132 _onMouseDown(event) {
116 if (!this._onClickOutsideCallback) 133 if (!this._onClickOutsideCallback)
117 return; 134 return;
118 if (this.contentElement.isSelfOrAncestor(/** @type {?Node} */ (event.deepEle mentFromPoint()))) 135 if (this.contentElement.isSelfOrAncestor(/** @type {?Node} */ (event.deepEle mentFromPoint())))
119 return; 136 return;
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
196 width = Math.min(width, containerWidth - positionX - gutterSize); 213 width = Math.min(width, containerWidth - positionX - gutterSize);
197 height = Math.min(height, containerHeight - positionY - gutterSize); 214 height = Math.min(height, containerHeight - positionY - gutterSize);
198 } 215 }
199 216
200 this.contentElement.style.width = width + 'px'; 217 this.contentElement.style.width = width + 'px';
201 if (this._sizeBehavior === UI.GlassPane.SizeBehavior.SetMaxHeight) 218 if (this._sizeBehavior === UI.GlassPane.SizeBehavior.SetMaxHeight)
202 this.contentElement.style.maxHeight = height + 'px'; 219 this.contentElement.style.maxHeight = height + 'px';
203 else 220 else
204 this.contentElement.style.height = height + 'px'; 221 this.contentElement.style.height = height + 'px';
205 this.contentElement.positionAt(positionX, positionY, container); 222 this.contentElement.positionAt(positionX, positionY, container);
223 this._widget.doResize();
206 } 224 }
207 225
208 /** 226 /**
227 * @protected
228 * @return {!UI.Widget}
229 */
230 widget() {
231 return this._widget;
232 }
233
234 /**
209 * @param {!Element} element 235 * @param {!Element} element
210 */ 236 */
211 static setContainer(element) { 237 static setContainer(element) {
212 UI.GlassPane._containers.set(/** @type {!Document} */ (element.ownerDocument ), element); 238 UI.GlassPane._containers.set(/** @type {!Document} */ (element.ownerDocument ), element);
213 UI.GlassPane.containerMoved(element); 239 UI.GlassPane.containerMoved(element);
214 } 240 }
215 241
216 /** 242 /**
217 * @param {!Document} document 243 * @param {!Document} document
218 * @return {!Element} 244 * @return {!Element}
219 */ 245 */
220 static container(document) { 246 static container(document) {
221 return UI.GlassPane._containers.get(document); 247 return UI.GlassPane._containers.get(document);
222 } 248 }
223 249
224 /** 250 /**
225 * @param {!Element} element 251 * @param {!Element} element
226 */ 252 */
227 static containerMoved(element) { 253 static containerMoved(element) {
228 for (var pane of UI.GlassPane._panes) { 254 for (var pane of UI.GlassPane._panes) {
229 if (pane.isShowing() && pane.element.ownerDocument === element.ownerDocume nt) { 255 if (pane.isShowing() && pane.element.ownerDocument === element.ownerDocume nt)
230 pane._positionContent(); 256 pane._positionContent();
231 pane.doResize();
232 }
233 } 257 }
234 } 258 }
235 }; 259 };
236 260
237 /** 261 /**
238 * @enum {symbol} 262 * @enum {symbol}
239 */ 263 */
240 UI.GlassPane.AnchorBehavior = { 264 UI.GlassPane.AnchorBehavior = {
241 PreferTop: Symbol('PreferTop'), 265 PreferTop: Symbol('PreferTop'),
242 PreferBottom: Symbol('PreferBottom'), 266 PreferBottom: Symbol('PreferBottom'),
243 PreferLeft: Symbol('PreferLeft'), 267 PreferLeft: Symbol('PreferLeft'),
244 PreferRight: Symbol('PreferRight'), 268 PreferRight: Symbol('PreferRight'),
245 }; 269 };
246 270
247 /** 271 /**
248 * @enum {symbol} 272 * @enum {symbol}
249 */ 273 */
250 UI.GlassPane.SizeBehavior = { 274 UI.GlassPane.SizeBehavior = {
251 SetHeight: Symbol('SetHeight'), 275 SetHeight: Symbol('SetHeight'),
252 SetMaxHeight: Symbol('SetMaxHeight'), 276 SetMaxHeight: Symbol('SetMaxHeight'),
253 MeasureContent: Symbol('MeasureContent') 277 MeasureContent: Symbol('MeasureContent')
254 }; 278 };
255 279
256 /** @type {!Map<!Document, !Element>} */ 280 /** @type {!Map<!Document, !Element>} */
257 UI.GlassPane._containers = new Map(); 281 UI.GlassPane._containers = new Map();
258 /** @type {!Set<!UI.GlassPane>} */ 282 /** @type {!Set<!UI.GlassPane>} */
259 UI.GlassPane._panes = new Set(); 283 UI.GlassPane._panes = new Set();
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698