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/SplitWidget.js b/front_end/ui/SplitWidget.js
index bb083a5..6941202 100644
--- a/front_end/ui/SplitWidget.js
+++ b/front_end/ui/SplitWidget.js
@@ -29,7 +29,7 @@
 /**
  * @unrestricted
  */
-UI.SplitWidget = class extends UI.Widget {
+export default class SplitWidget extends UI.Widget {
   /**
    * @param {boolean} isVertical
    * @param {boolean} secondIsSidebar
@@ -92,7 +92,7 @@
     this.setSecondIsSidebar(secondIsSidebar);
 
     this._innerSetVertical(isVertical);
-    this._showMode = UI.SplitWidget.ShowMode.Both;
+    this._showMode = ShowMode.Both;
     this._savedShowMode = this._showMode;
 
     // Should be called after isVertical has the right value.
@@ -171,7 +171,7 @@
     this._mainWidget = widget;
     if (widget) {
       widget.element.slot = 'insertion-point-main';
-      if (this._showMode === UI.SplitWidget.ShowMode.OnlyMain || this._showMode === UI.SplitWidget.ShowMode.Both) {
+      if (this._showMode === ShowMode.OnlyMain || this._showMode === ShowMode.Both) {
         widget.show(this.element);
       }
     }
@@ -192,7 +192,7 @@
     this._sidebarWidget = widget;
     if (widget) {
       widget.element.slot = 'insertion-point-sidebar';
-      if (this._showMode === UI.SplitWidget.ShowMode.OnlySidebar || this._showMode === UI.SplitWidget.ShowMode.Both) {
+      if (this._showMode === ShowMode.OnlySidebar || this._showMode === ShowMode.Both) {
         widget.show(this.element);
       }
     }
@@ -279,7 +279,7 @@
    * @return {?string}
    */
   sidebarSide() {
-    if (this._showMode !== UI.SplitWidget.ShowMode.Both) {
+    if (this._showMode !== ShowMode.Both) {
       return null;
     }
     return this._isVertical ? (this._secondIsSidebar ? 'right' : 'left') : (this._secondIsSidebar ? 'bottom' : 'top');
@@ -297,7 +297,7 @@
    */
   hideMain(animate) {
     this._showOnly(this._sidebarWidget, this._mainWidget, this._sidebarElement, this._mainElement, animate);
-    this._updateShowMode(UI.SplitWidget.ShowMode.OnlySidebar);
+    this._updateShowMode(ShowMode.OnlySidebar);
   }
 
   /**
@@ -305,7 +305,7 @@
    */
   hideSidebar(animate) {
     this._showOnly(this._mainWidget, this._sidebarWidget, this._mainElement, this._sidebarElement, animate);
-    this._updateShowMode(UI.SplitWidget.ShowMode.OnlyMain);
+    this._updateShowMode(ShowMode.OnlyMain);
   }
 
   /**
@@ -334,7 +334,7 @@
     this._cancelAnimation();
 
     /**
-     * @this {UI.SplitWidget}
+     * @this {SplitWidget}
      */
     function callback() {
       if (sideToShow) {
@@ -398,7 +398,7 @@
    * @param {boolean=} animate
    */
   showBoth(animate) {
-    if (this._showMode === UI.SplitWidget.ShowMode.Both) {
+    if (this._showMode === ShowMode.Both) {
       animate = false;
     }
 
@@ -421,7 +421,7 @@
     this.setSecondIsSidebar(this._secondIsSidebar);
 
     this._sidebarSizeDIP = -1;
-    this._updateShowMode(UI.SplitWidget.ShowMode.Both);
+    this._updateShowMode(ShowMode.Both);
     this._updateLayout(animate);
   }
 
@@ -477,7 +477,7 @@
     this._showMode = showMode;
     this._saveShowModeToSettings();
     this._updateShowHideSidebarButton();
-    this.dispatchEventToListeners(UI.SplitWidget.Events.ShowModeChanged, showMode);
+    this.dispatchEventToListeners(SplitWidget.Events.ShowModeChanged, showMode);
     this.invalidateConstraints();
   }
 
@@ -487,7 +487,7 @@
    * @param {boolean=} userAction
    */
   _innerSetSidebarSizeDIP(sizeDIP, animate, userAction) {
-    if (this._showMode !== UI.SplitWidget.ShowMode.Both || !this.isShowing()) {
+    if (this._showMode !== ShowMode.Both || !this.isShowing()) {
       return;
     }
 
@@ -552,7 +552,7 @@
     } else {
       // No need to recalculate this._sidebarSizeDIP and this._totalSizeDIP again.
       this.doResize();
-      this.dispatchEventToListeners(UI.SplitWidget.Events.SidebarSizeChanged, this.sidebarSize());
+      this.dispatchEventToListeners(SplitWidget.Events.SidebarSizeChanged, this.sidebarSize());
     }
   }
 
@@ -593,7 +593,7 @@
     const boundAnimationFrame = animationFrame.bind(this);
     let startTime;
     /**
-     * @this {UI.SplitWidget}
+     * @this {SplitWidget}
      */
     function animationFrame() {
       this._animationFrameHandle = 0;
@@ -613,7 +613,7 @@
         if (this._mainWidget) {
           this._mainWidget.doResize();
         }
-        this.dispatchEventToListeners(UI.SplitWidget.Events.SidebarSizeChanged, this.sidebarSize());
+        this.dispatchEventToListeners(SplitWidget.Events.SidebarSizeChanged, this.sidebarSize());
         return;
       }
       this._animationFrameHandle = this.contentElement.window().requestAnimationFrame(boundAnimationFrame);
@@ -650,7 +650,7 @@
     let constraints = this._sidebarWidget ? this._sidebarWidget.constraints() : new UI.Constraints();
     let minSidebarSize = this.isVertical() ? constraints.minimum.width : constraints.minimum.height;
     if (!minSidebarSize) {
-      minSidebarSize = UI.SplitWidget.MinPadding;
+      minSidebarSize = MinPadding;
     }
     minSidebarSize *= zoomFactor;
     if (this._sidebarMinimized) {
@@ -659,7 +659,7 @@
 
     let preferredSidebarSize = this.isVertical() ? constraints.preferred.width : constraints.preferred.height;
     if (!preferredSidebarSize) {
-      preferredSidebarSize = UI.SplitWidget.MinPadding;
+      preferredSidebarSize = MinPadding;
     }
     preferredSidebarSize *= zoomFactor;
     // Allow sidebar to be less than preferred by explicit user action.
@@ -671,13 +671,13 @@
     constraints = this._mainWidget ? this._mainWidget.constraints() : new UI.Constraints();
     let minMainSize = this.isVertical() ? constraints.minimum.width : constraints.minimum.height;
     if (!minMainSize) {
-      minMainSize = UI.SplitWidget.MinPadding;
+      minMainSize = MinPadding;
     }
     minMainSize *= zoomFactor;
 
     let preferredMainSize = this.isVertical() ? constraints.preferred.width : constraints.preferred.height;
     if (!preferredMainSize) {
-      preferredMainSize = UI.SplitWidget.MinPadding;
+      preferredMainSize = MinPadding;
     }
     preferredMainSize *= zoomFactor;
     const savedMainSize = this.isVertical() ? this._savedVerticalMainSize : this._savedHorizontalMainSize;
@@ -740,16 +740,16 @@
    * @return {!UI.Constraints}
    */
   calculateConstraints() {
-    if (this._showMode === UI.SplitWidget.ShowMode.OnlyMain) {
+    if (this._showMode === ShowMode.OnlyMain) {
       return this._mainWidget ? this._mainWidget.constraints() : new UI.Constraints();
     }
-    if (this._showMode === UI.SplitWidget.ShowMode.OnlySidebar) {
+    if (this._showMode === ShowMode.OnlySidebar) {
       return this._sidebarWidget ? this._sidebarWidget.constraints() : new UI.Constraints();
     }
 
     let mainConstraints = this._mainWidget ? this._mainWidget.constraints() : new UI.Constraints();
     let sidebarConstraints = this._sidebarWidget ? this._sidebarWidget.constraints() : new UI.Constraints();
-    const min = UI.SplitWidget.MinPadding;
+    const min = MinPadding;
     if (this._isVertical) {
       mainConstraints = mainConstraints.widthToMax(min).addWidth(1);  // 1 for splitter
       sidebarConstraints = sidebarConstraints.widthToMax(min);
@@ -837,7 +837,7 @@
   }
 
   /**
-   * @return {?UI.SplitWidget.SettingForOrientation}
+   * @return {?SplitWidget.SettingForOrientation}
    */
   _settingForOrientation() {
     const state = this._setting ? this._setting.get() : {};
@@ -870,13 +870,13 @@
     this._showMode = this._savedShowMode;
 
     switch (this._savedShowMode) {
-      case UI.SplitWidget.ShowMode.Both:
+      case ShowMode.Both:
         this.showBoth();
         break;
-      case UI.SplitWidget.ShowMode.OnlyMain:
+      case ShowMode.OnlyMain:
         this.hideSidebar();
         break;
-      case UI.SplitWidget.ShowMode.OnlySidebar:
+      case ShowMode.OnlySidebar:
         this.hideMain();
         break;
     }
@@ -932,10 +932,10 @@
 
     /**
      * @param {!Common.Event} event
-     * @this {UI.SplitWidget}
+     * @this {SplitWidget}
      */
     function buttonClicked(event) {
-      if (this._showMode !== UI.SplitWidget.ShowMode.Both) {
+      if (this._showMode !== ShowMode.Both) {
         this.showBoth(true);
       } else {
         this.hideSidebar(true);
@@ -949,7 +949,7 @@
     if (!this._showHideSidebarButton) {
       return;
     }
-    const sidebarHidden = this._showMode === UI.SplitWidget.ShowMode.OnlyMain;
+    const sidebarHidden = this._showMode === ShowMode.OnlyMain;
     let glyph = '';
     if (sidebarHidden) {
       glyph = this.isVertical() ?
@@ -965,21 +965,36 @@
         sidebarHidden ? Common.UIString('Show %s', this._showHideSidebarButtonTitle) :
                         Common.UIString('Hide %s', this._showHideSidebarButtonTitle));
   }
-};
+}
 
-/** @typedef {{showMode: string, size: number}} */
-UI.SplitWidget.SettingForOrientation;
-
-UI.SplitWidget.ShowMode = {
+export const ShowMode = {
   Both: 'Both',
   OnlyMain: 'OnlyMain',
   OnlySidebar: 'OnlySidebar'
 };
 
 /** @enum {symbol} */
-UI.SplitWidget.Events = {
+export const Events = {
   SidebarSizeChanged: Symbol('SidebarSizeChanged'),
   ShowModeChanged: Symbol('ShowModeChanged')
 };
 
-UI.SplitWidget.MinPadding = 20;
+export const MinPadding = 20;
+
+/* Legacy exported object*/
+self.UI = self.UI || {};
+
+/* Legacy exported object*/
+UI = UI || {};
+
+/** @constructor */
+UI.SplitWidget = SplitWidget;
+
+UI.SplitWidget.ShowMode = ShowMode;
+UI.SplitWidget.MinPadding = MinPadding;
+
+/** @enum {symbol} */
+UI.SplitWidget.Events = Events;
+
+/** @typedef {{showMode: string, size: number}} */
+UI.SplitWidget.SettingForOrientation;
\ No newline at end of file