Convert ui/ to ESM
- ViewManager has been extracted from View
- Action has been extracted from ActionRegistry
- ContextFlavorListener has been extracted from Context
Bug: 1006759
Change-Id: Iff41f3a7db4dcbd6da90fd5752923e32af03bac8
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1827294
Commit-Queue: Tim Van der Lippe <[email protected]>
Reviewed-by: Yang Guo <[email protected]>
Cr-Original-Commit-Position: refs/heads/master@{#702390}
Cr-Mirrored-From: https://chromium.googlesource.com/chromium/src
Cr-Mirrored-Commit: 0ffd51ccac853da7c8ec3d91ae868bc61626b29b
diff --git a/front_end/ui/Widget.js b/front_end/ui/Widget.js
index 5ae52180..522e90f 100644
--- a/front_end/ui/Widget.js
+++ b/front_end/ui/Widget.js
@@ -27,7 +27,7 @@
/**
* @unrestricted
*/
-UI.Widget = class extends Common.Object {
+export default class Widget extends Common.Object {
/**
* @param {boolean=} isWebComponent
* @param {boolean=} delegatesFocus
@@ -106,26 +106,26 @@
}
markAsRoot() {
- UI.Widget.__assert(!this.element.parentElement, 'Attempt to mark as root attached node');
+ Widget.__assert(!this.element.parentElement, 'Attempt to mark as root attached node');
this._isRoot = true;
}
/**
- * @return {?UI.Widget}
+ * @return {?Widget}
*/
parentWidget() {
return this._parentWidget;
}
/**
- * @return {!Array.<!UI.Widget>}
+ * @return {!Array.<!Widget>}
*/
children() {
return this._children;
}
/**
- * @param {!UI.Widget} widget
+ * @param {!Widget} widget
* @protected
*/
childWasDetached(widget) {
@@ -175,7 +175,7 @@
}
/**
- * @param {function(this:UI.Widget)} method
+ * @param {function(this:Widget)} method
*/
_callOnVisibleChildren(method) {
const copy = this._children.slice();
@@ -227,7 +227,7 @@
}
/**
- * @param {function(this:UI.Widget)} notification
+ * @param {function(this:Widget)} notification
*/
_notify(notification) {
++this._notificationDepth;
@@ -258,7 +258,7 @@
* @param {?Node=} insertBefore
*/
show(parentElement, insertBefore) {
- UI.Widget.__assert(parentElement, 'Attempt to attach widget with no parent element');
+ Widget.__assert(parentElement, 'Attempt to attach widget with no parent element');
if (!this._isRoot) {
// Update widget hierarchy.
@@ -266,7 +266,7 @@
while (currentParent && !currentParent.__widget) {
currentParent = currentParent.parentElementOrShadowHost();
}
- UI.Widget.__assert(currentParent, 'Attempt to attach widget to orphan node');
+ Widget.__assert(currentParent, 'Attempt to attach widget to orphan node');
this._attach(currentParent.__widget);
}
@@ -274,7 +274,7 @@
}
/**
- * @param {!UI.Widget} parentWidget
+ * @param {!Widget} parentWidget
*/
_attach(parentWidget) {
if (parentWidget === this._parentWidget) {
@@ -292,7 +292,7 @@
if (this._visible) {
return;
}
- UI.Widget.__assert(this.element.parentElement, 'Attempt to show widget that is not hidden using hideWidget().');
+ Widget.__assert(this.element.parentElement, 'Attempt to show widget that is not hidden using hideWidget().');
this._showWidget(/** @type {!Element} */ (this.element.parentElement), this.element.nextSibling);
}
@@ -307,9 +307,9 @@
}
if (this._isRoot) {
- UI.Widget.__assert(!currentParent, 'Attempt to show root widget under another widget');
+ Widget.__assert(!currentParent, 'Attempt to show root widget under another widget');
} else {
- UI.Widget.__assert(
+ Widget.__assert(
currentParent && currentParent.__widget === this._parentWidget,
'Attempt to show under node belonging to alien widget');
}
@@ -330,12 +330,12 @@
// Reparent
if (this.element.parentElement !== parentElement) {
if (!this._externallyManaged) {
- UI.Widget._incrementWidgetCounter(parentElement, this.element);
+ Widget._incrementWidgetCounter(parentElement, this.element);
}
if (insertBefore) {
- UI.Widget._originalInsertBefore.call(parentElement, this.element, insertBefore);
+ Widget._originalInsertBefore.call(parentElement, this.element, insertBefore);
} else {
- UI.Widget._originalAppendChild.call(parentElement, this.element);
+ Widget._originalAppendChild.call(parentElement, this.element);
}
}
@@ -370,8 +370,8 @@
if (removeFromDOM) {
// Force legal removal
- UI.Widget._decrementWidgetCounter(parentElement, this.element);
- UI.Widget._originalRemoveChild.call(parentElement, this.element);
+ Widget._decrementWidgetCounter(parentElement, this.element);
+ Widget._originalRemoveChild.call(parentElement, this.element);
} else {
this.element.classList.add('hidden');
}
@@ -403,14 +403,14 @@
} else if (removeFromDOM && this.element.parentElement) {
const parentElement = this.element.parentElement;
// Force kick out from DOM.
- UI.Widget._decrementWidgetCounter(parentElement, this.element);
- UI.Widget._originalRemoveChild.call(parentElement, this.element);
+ Widget._decrementWidgetCounter(parentElement, this.element);
+ Widget._originalRemoveChild.call(parentElement, this.element);
}
// Update widget hierarchy.
if (this._parentWidget) {
const childIndex = this._parentWidget._children.indexOf(this);
- UI.Widget.__assert(childIndex >= 0, 'Attempt to remove non-child widget');
+ Widget.__assert(childIndex >= 0, 'Attempt to remove non-child widget');
this._parentWidget._children.splice(childIndex, 1);
if (this._parentWidget._defaultFocusedChild === this) {
this._parentWidget._defaultFocusedChild = null;
@@ -418,7 +418,7 @@
this._parentWidget.childWasDetached(this);
this._parentWidget = null;
} else {
- UI.Widget.__assert(this._isRoot, 'Removing non-root widget from DOM');
+ Widget.__assert(this._isRoot, 'Removing non-root widget from DOM');
}
}
@@ -509,10 +509,10 @@
}
/**
- * @param {!UI.Widget} child
+ * @param {!Widget} child
*/
setDefaultFocusedChild(child) {
- UI.Widget.__assert(child._parentWidget === this, 'Attempt to set non-child widget as default focused.');
+ Widget.__assert(child._parentWidget === this, 'Attempt to set non-child widget as default focused.');
this._defaultFocusedChild = child;
}
@@ -642,21 +642,21 @@
// Also note that this must be called before the widget is shown so that
// so that its ancestor's __widgetCounter is not incremented.
markAsExternallyManaged() {
- UI.Widget.__assert(!this._parentWidget, 'Attempt to mark widget as externally managed after insertion to the DOM');
+ Widget.__assert(!this._parentWidget, 'Attempt to mark widget as externally managed after insertion to the DOM');
this._externallyManaged = true;
}
-};
+}
-UI.Widget._originalAppendChild = Element.prototype.appendChild;
-UI.Widget._originalInsertBefore = Element.prototype.insertBefore;
-UI.Widget._originalRemoveChild = Element.prototype.removeChild;
-UI.Widget._originalRemoveChildren = Element.prototype.removeChildren;
+export const _originalAppendChild = Element.prototype.appendChild;
+export const _originalInsertBefore = Element.prototype.insertBefore;
+export const _originalRemoveChild = Element.prototype.removeChild;
+export const _originalRemoveChildren = Element.prototype.removeChildren;
/**
* @unrestricted
*/
-UI.VBox = class extends UI.Widget {
+export class VBox extends Widget {
/**
* @param {boolean=} isWebComponent
* @param {boolean=} delegatesFocus
@@ -674,7 +674,7 @@
let constraints = new UI.Constraints();
/**
- * @this {!UI.Widget}
+ * @this {!Widget}
* @suppressReceiverCheck
*/
function updateForChild() {
@@ -686,12 +686,12 @@
this._callOnVisibleChildren(updateForChild);
return constraints;
}
-};
+}
/**
* @unrestricted
*/
-UI.HBox = class extends UI.Widget {
+export class HBox extends Widget {
/**
* @param {boolean=} isWebComponent
*/
@@ -708,7 +708,7 @@
let constraints = new UI.Constraints();
/**
- * @this {!UI.Widget}
+ * @this {!Widget}
* @suppressReceiverCheck
*/
function updateForChild() {
@@ -720,12 +720,12 @@
this._callOnVisibleChildren(updateForChild);
return constraints;
}
-};
+}
/**
* @unrestricted
*/
-UI.VBoxWithResizeCallback = class extends UI.VBox {
+export class VBoxWithResizeCallback extends VBox {
/**
* @param {function()} resizeCallback
*/
@@ -740,14 +740,14 @@
onResize() {
this._resizeCallback();
}
-};
+}
/**
* @unrestricted
*/
-UI.WidgetFocusRestorer = class {
+export class WidgetFocusRestorer {
/**
- * @param {!UI.Widget} widget
+ * @param {!Widget} widget
*/
constructor(widget) {
this._widget = widget;
@@ -765,7 +765,7 @@
this._previous = null;
this._widget = null;
}
-};
+}
/**
* @override
@@ -774,9 +774,8 @@
* @suppress {duplicate}
*/
Element.prototype.appendChild = function(child) {
- UI.Widget.__assert(
- !child.__widget || child.parentElement === this, 'Attempt to add widget via regular DOM operation.');
- return UI.Widget._originalAppendChild.call(this, child);
+ Widget.__assert(!child.__widget || child.parentElement === this, 'Attempt to add widget via regular DOM operation.');
+ return Widget._originalAppendChild.call(this, child);
};
/**
@@ -787,9 +786,8 @@
* @suppress {duplicate}
*/
Element.prototype.insertBefore = function(child, anchor) {
- UI.Widget.__assert(
- !child.__widget || child.parentElement === this, 'Attempt to add widget via regular DOM operation.');
- return UI.Widget._originalInsertBefore.call(this, child, anchor);
+ Widget.__assert(!child.__widget || child.parentElement === this, 'Attempt to add widget via regular DOM operation.');
+ return Widget._originalInsertBefore.call(this, child, anchor);
};
/**
@@ -799,13 +797,39 @@
* @suppress {duplicate}
*/
Element.prototype.removeChild = function(child) {
- UI.Widget.__assert(
+ Widget.__assert(
!child.__widgetCounter && !child.__widget,
'Attempt to remove element containing widget via regular DOM operation');
- return UI.Widget._originalRemoveChild.call(this, child);
+ return Widget._originalRemoveChild.call(this, child);
};
Element.prototype.removeChildren = function() {
- UI.Widget.__assert(!this.__widgetCounter, 'Attempt to remove element containing widget via regular DOM operation');
- UI.Widget._originalRemoveChildren.call(this);
+ Widget.__assert(!this.__widgetCounter, 'Attempt to remove element containing widget via regular DOM operation');
+ Widget._originalRemoveChildren.call(this);
};
+
+/* Legacy exported object*/
+self.UI = self.UI || {};
+
+/* Legacy exported object*/
+UI = UI || {};
+
+/** @constructor */
+UI.Widget = Widget;
+
+Widget._originalAppendChild = _originalAppendChild;
+Widget._originalInsertBefore = _originalInsertBefore;
+Widget._originalRemoveChild = _originalRemoveChild;
+Widget._originalRemoveChildren = _originalRemoveChildren;
+
+/** @constructor */
+UI.HBox = HBox;
+
+/** @constructor */
+UI.VBox = VBox;
+
+/** @constructor */
+UI.WidgetFocusRestorer = WidgetFocusRestorer;
+
+/** @constructor */
+UI.VBoxWithResizeCallback = VBoxWithResizeCallback;