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..d6d6bc797a7c709f25618fa723c1eee364747802 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,12 @@ 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._onClickBound = this._onGlassPaneClick.bind(this); |
+ this._overlay = new UI.ModalOverlay(); |
+ this._overlay.setBlockPointerEvents(true); |
this._wrapsContent = false; |
- this._dimmed = false; |
+ this._maxSize = null; |
+ |
/** @type {!Map<!HTMLElement, number>} */ |
this._tabIndexMap = new Map(); |
} |
@@ -56,27 +59,6 @@ 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 |
*/ |
show() { |
@@ -84,16 +66,15 @@ UI.Dialog = class extends UI.Widget { |
UI.Dialog._instance.detach(); |
UI.Dialog._instance = this; |
- var document = /** @type {!Document} */ (UI.Dialog._modalHostView.element.ownerDocument); |
- this._disableTabIndexOnElements(document); |
+ this._disableTabIndexOnElements(this._overlay.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); |
+ super.show(this._overlay.element); |
+ this._overlay.show(); |
+ this._overlay.addGlassPaneEventListener('click', this._onClickBound, false); |
+ this._overlay.document().body.addEventListener('keydown', this._keyDownBound, false); |
caseq
2017/01/31 21:27:19
I wonder if we can make it simpler by focusing to
dgozman
2017/01/31 23:39:49
Done.
|
+ this._overlay.setMaxSize(this._effectiveMaxSize()); |
+ this._overlay.position(); |
- super.show(this._glassPane.element); |
- |
- this._position(); |
this._focusRestorer = new UI.WidgetFocusRestorer(this); |
} |
@@ -103,11 +84,10 @@ UI.Dialog = class extends UI.Widget { |
detach() { |
this._focusRestorer.restore(); |
- this.element.ownerDocument.body.removeEventListener('keydown', this._keyDownBound, false); |
+ this._overlay.document().body.removeEventListener('keydown', this._keyDownBound, false); |
+ this._overlay.removeGlassPaneEventListener('click', this._onClickBound, false); |
super.detach(); |
- |
- this._glassPane.dispose(); |
- delete this._glassPane; |
+ this._overlay.hide(); |
this._restoreTabIndexOnElements(); |
@@ -121,12 +101,13 @@ 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._overlay.setPosition(positionX, positionY); |
+ if (this._overlay.visible()) |
caseq
2017/01/31 21:27:20
remove?
dgozman
2017/01/31 23:39:49
Done.
|
+ this._overlay.position(); |
} |
/** |
@@ -134,26 +115,47 @@ UI.Dialog = class extends UI.Widget { |
*/ |
setMaxSize(size) { |
this._maxSize = size; |
+ this._overlay.setMaxSize(this._effectiveMaxSize()); |
+ if (this._overlay.visible()) |
caseq
2017/01/31 21:27:20
ditto
|
+ this._overlay.position(); |
+ } |
+ |
+ /** |
+ * @return {?UI.Size} |
+ */ |
+ _effectiveMaxSize() { |
+ if (!this._wrapsContent) |
+ return this._maxSize; |
+ |
+ var size = new UI.Size(this.contentElement.offsetWidth, this.contentElement.offsetHeight); |
+ size.sizeToMin(this._maxSize); |
+ return size; |
} |
/** |
* @param {boolean} wraps |
*/ |
setWrapsContent(wraps) { |
- this.element.classList.toggle('wraps-content', wraps); |
this._wrapsContent = wraps; |
+ this.element.classList.toggle('wraps-content', wraps); |
+ this._overlay.setMaxSize(this._effectiveMaxSize()); |
+ if (this._overlay.visible()) |
caseq
2017/01/31 21:27:19
ditto.
|
+ this._overlay.position(); |
} |
/** |
* @param {boolean} dimmed |
*/ |
setDimmed(dimmed) { |
- this._dimmed = dimmed; |
+ this._overlay.setDimmed(dimmed); |
} |
contentResized() { |
- if (this._wrapsContent) |
- this._position(); |
+ if (!this._wrapsContent) |
+ return; |
+ this._overlay.setMaxSize(this._effectiveMaxSize()); |
+ if (this._overlay.visible()) |
caseq
2017/01/31 21:27:19
ditto.
|
+ this._overlay.position(); |
} |
/** |
@@ -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; |