Chromium Code Reviews| Index: third_party/WebKit/Source/devtools/front_end/ui/Dialog.js |
| diff --git a/third_party/WebKit/Source/devtools/front_end/ui/Dialog.js b/third_party/WebKit/Source/devtools/front_end/ui/Dialog.js |
| index f4379fbc56657fae02acb3bb387ccb4c087536df..388af50234bdf7207b4409af08e2b009cbd712ba 100644 |
| --- a/third_party/WebKit/Source/devtools/front_end/ui/Dialog.js |
| +++ b/third_party/WebKit/Source/devtools/front_end/ui/Dialog.js |
| @@ -41,9 +41,15 @@ UI.Dialog = class extends UI.Widget { |
| this.contentElement.tabIndex = 0; |
| this.contentElement.addEventListener('focus', this._onFocus.bind(this), false); |
| this._keyDownBound = this._onKeyDown.bind(this); |
| - |
| - this._wrapsContent = false; |
| + this._onClickBound = this._onGlassPaneClick.bind(this); |
| this._dimmed = false; |
| + this._wrapsContent = false; |
| + this._maxSize = null; |
| + /** @type {?number} */ |
| + this._positionX = null; |
| + /** @type {?number} */ |
| + this._positionY = null; |
| + |
| /** @type {!Map<!HTMLElement, number>} */ |
| this._tabIndexMap = new Map(); |
| } |
| @@ -56,44 +62,29 @@ UI.Dialog = class extends UI.Widget { |
| } |
| /** |
| - * @param {!UI.Widget} view |
| - */ |
| - static setModalHostView(view) { |
| - UI.Dialog._modalHostView = view; |
| - } |
| - |
| - /** |
| - * FIXME: make utility method in Dialog, so clients use it instead of this getter. |
| - * Method should be like Dialog.showModalElement(position params, reposition callback). |
| - * @return {?UI.Widget} |
| - */ |
| - static modalHostView() { |
| - return UI.Dialog._modalHostView; |
| - } |
| - |
| - static modalHostRepositioned() { |
| - if (UI.Dialog._instance) |
| - UI.Dialog._instance._position(); |
| - } |
| - |
| - /** |
| * @override |
| + * @suppressGlobalPropertiesCheck |
| + * TODO(dgozman): pass document in constructor. |
| */ |
| show() { |
| if (UI.Dialog._instance) |
| UI.Dialog._instance.detach(); |
| UI.Dialog._instance = this; |
| - var document = /** @type {!Document} */ (UI.Dialog._modalHostView.element.ownerDocument); |
| this._disableTabIndexOnElements(document); |
| - this._glassPane = new UI.GlassPane(document, this._dimmed); |
| - this._glassPane.element.addEventListener('click', this._onGlassPaneClick.bind(this), false); |
| - this.element.ownerDocument.body.addEventListener('keydown', this._keyDownBound, false); |
| + this._glassPane = new UI.GlassPane(document, this._dimmed, true /* blockPointerEvents*/); |
| + var container = createElement('div'); |
| + this._glassPane.setContentElement(container); |
| + this._glassPane.show(); |
| + super.show(container); |
| + this._glassPane.setMaxContentSize(this._effectiveMaxSize()); |
| + this._glassPane.setContentPosition(this._positionX, this._positionY); |
|
pfeldman
2017/02/01 00:07:18
setContentPosition/setContentAnchorBox would be mu
dgozman
2017/02/01 16:19:44
Done.
|
| + this._glassPane.positionContent(); |
| - super.show(this._glassPane.element); |
| + this._glassPane.element.addEventListener('click', this._onClickBound, false); |
|
pfeldman
2017/02/01 00:07:18
this._glassPane.on('exit', () => {})
dgozman
2017/02/01 16:19:44
Reworked.
|
| + this.contentElement.addEventListener('keydown', this._keyDownBound, false); |
| - this._position(); |
| this._focusRestorer = new UI.WidgetFocusRestorer(this); |
| } |
| @@ -103,10 +94,11 @@ UI.Dialog = class extends UI.Widget { |
| detach() { |
| this._focusRestorer.restore(); |
| - this.element.ownerDocument.body.removeEventListener('keydown', this._keyDownBound, false); |
| - super.detach(); |
| + this.contentElement.removeEventListener('keydown', this._keyDownBound, false); |
| + this._glassPane.element.removeEventListener('click', this._onClickBound, false); |
| - this._glassPane.dispose(); |
| + super.detach(); |
| + this._glassPane.hide(); |
| delete this._glassPane; |
| this._restoreTabIndexOnElements(); |
| @@ -121,12 +113,12 @@ UI.Dialog = class extends UI.Widget { |
| } |
| /** |
| - * @param {number=} positionX |
| - * @param {number=} positionY |
| + * @param {?number} positionX |
| + * @param {?number} positionY |
| */ |
| setPosition(positionX, positionY) { |
| - this._defaultPositionX = positionX; |
| - this._defaultPositionY = positionY; |
| + this._positionX = positionX; |
| + this._positionY = positionY; |
| } |
| /** |
| @@ -137,11 +129,20 @@ UI.Dialog = class extends UI.Widget { |
| } |
| /** |
| + * @return {?UI.Size} |
| + */ |
| + _effectiveMaxSize() { |
| + if (!this._wrapsContent) |
| + return this._maxSize; |
| + return new UI.Size(this.contentElement.offsetWidth, this.contentElement.offsetHeight).clipTo(this._maxSize); |
| + } |
| + |
| + /** |
| * @param {boolean} wraps |
| */ |
| setWrapsContent(wraps) { |
| - this.element.classList.toggle('wraps-content', wraps); |
| this._wrapsContent = wraps; |
| + this.element.classList.toggle('wraps-content', wraps); |
| } |
| /** |
| @@ -152,8 +153,9 @@ UI.Dialog = class extends UI.Widget { |
| } |
| contentResized() { |
| - if (this._wrapsContent) |
| - this._position(); |
| + if (!this._wrapsContent || !this._glassPane) |
| + return; |
| + this._glassPane.setMaxContentSize(this._effectiveMaxSize()); |
| } |
| /** |
| @@ -194,43 +196,6 @@ UI.Dialog = class extends UI.Widget { |
| this.detach(); |
| } |
| - _position() { |
| - var container = UI.Dialog._modalHostView.element; |
| - |
| - var width = container.offsetWidth - 10; |
| - var height = container.offsetHeight - 10; |
| - |
| - if (this._wrapsContent) { |
| - width = Math.min(width, this.contentElement.offsetWidth); |
| - height = Math.min(height, this.contentElement.offsetHeight); |
| - } |
| - |
| - if (this._maxSize) { |
| - width = Math.min(width, this._maxSize.width); |
| - height = Math.min(height, this._maxSize.height); |
| - } |
| - |
| - var positionX; |
| - if (typeof this._defaultPositionX === 'number') { |
| - positionX = this._defaultPositionX; |
| - } else { |
| - positionX = (container.offsetWidth - width) / 2; |
| - positionX = Number.constrain(positionX, 0, container.offsetWidth - width); |
| - } |
| - |
| - var positionY; |
| - if (typeof this._defaultPositionY === 'number') { |
| - positionY = this._defaultPositionY; |
| - } else { |
| - positionY = (container.offsetHeight - height) / 2; |
| - positionY = Number.constrain(positionY, 0, container.offsetHeight - height); |
| - } |
| - |
| - this.element.style.width = width + 'px'; |
| - this.element.style.height = height + 'px'; |
| - this.element.positionAt(positionX, positionY, container); |
| - } |
| - |
| /** |
| * @param {!Event} event |
| */ |
| @@ -241,10 +206,3 @@ UI.Dialog = class extends UI.Widget { |
| } |
| } |
| }; |
| - |
| - |
| -/** @type {?Element} */ |
| -UI.Dialog._previousFocusedElement = null; |
| - |
| -/** @type {?UI.Widget} */ |
| -UI.Dialog._modalHostView = null; |