Bug 1425363 - use JS instead of the windowds data source for the mac window menu, r?bgrins,spohl draft
authorGijs Kruitbosch <gijskruitbosch@gmail.com>
Thu, 14 Dec 2017 21:35:53 -0600
changeset 712825 6142539ab1b17e5398a998f839a0932e3514149e
parent 712645 5572465c08a9ce0671dcd01c721f9356fcd53a65
child 712826 bbe7413bfedd7a0833f7caf016bcefaf5d847ede
push id93451
push usergijskruitbosch@gmail.com
push dateMon, 18 Dec 2017 21:48:39 +0000
reviewersbgrins, spohl
bugs1425363
milestone59.0a1
Bug 1425363 - use JS instead of the windowds data source for the mac window menu, r?bgrins,spohl MozReview-Commit-ID: 2qcRkFLjOeu
toolkit/content/macWindowMenu.inc
toolkit/content/macWindowMenu.js
--- a/toolkit/content/macWindowMenu.inc
+++ b/toolkit/content/macWindowMenu.inc
@@ -10,30 +10,19 @@
     <keyset id="baseMenuKeyset">
         <key id="key_minimizeWindow"
              command="minimizeWindow"
              key="&minimizeWindow.key;"
              modifiers="accel"/>
     </keyset>
     <menu id="windowMenu"
           label="&windowMenu.label;"
-          datasources="rdf:window-mediator" ref="NC:WindowMediatorRoot"
           onpopupshowing="macWindowMenuDidShow();"
-          hidden="false">
-        <template>
-        <rule>
-            <menupopup>
-                <menuitem uri="rdf:*"
-                          label="rdf:http://home.netscape.com/NC-rdf#Name"
-                          type="radio"
-                          name="windowList"
-                          oncommand="ShowWindowFromResource(event.target)"/>
-            </menupopup>
-        </rule>
-        </template>
+          onpopuphidden="macWindowMenuDidHide();"
+          >
         <menupopup id="windowPopup">
             <menuitem command="minimizeWindow" key="key_minimizeWindow"/>
             <menuitem command="zoomWindow"/>
             <!-- decomment when "BringAllToFront" is implemented
                 <menuseparator/>
                 <menuitem label="&bringAllToFront.label;" disabled="true"/> -->
             <menuseparator id="sep-window-list"/>
         </menupopup>
--- a/toolkit/content/macWindowMenu.js
+++ b/toolkit/content/macWindowMenu.js
@@ -1,47 +1,44 @@
 // -*- indent-tabs-mode: nil; js-indent-level: 2 -*-
 
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 function macWindowMenuDidShow() {
-  var windowManagerDS =
-    Components.classes["@mozilla.org/rdf/datasource;1?name=window-mediator"]
-              .getService(Components.interfaces.nsIWindowDataSource);
-  var sep = document.getElementById("sep-window-list");
-  // Using double parens to avoid warning
-  while ((sep = sep.nextSibling)) {
-    var url = sep.getAttribute("id");
-    var win = windowManagerDS.getWindowForResource(url);
-    if (win.document.documentElement.getAttribute("inwindowmenu") == "false")
-      sep.hidden = true;
-    else if (win == window)
-      sep.setAttribute("checked", "true");
+  let windows = Services.wm.getEnumerator("");
+  let frag = document.createDocumentFragment();
+  while (windows.hasMoreElements()) {
+    let win = windows.getNext();
+    if (win.document.documentElement.getAttribute("inwindowmenu") == "false") {
+      continue;
+    }
+    let item = document.createElement("menuitem");
+    item.setAttribute("label", win.document.title);
+    if (win == window) {
+      item.setAttribute("checked", "true");
+    }
+    item.addEventListener("command", () => {
+      if (win.windowState == window.STATE_MINIMIZED) {
+        win.restore();
+      }
+      win.document.commandDispatcher.focusedWindow.focus();
+    });
+    frag.appendChild(item);
   }
+  document.getElementById("windowPopup").appendChild(frag);
 }
 
-function toOpenWindow( aWindow ) {
-  // deminiaturize the window, if it's in the Dock
-  if (aWindow.windowState == window.STATE_MINIMIZED)
-    aWindow.restore();
-  aWindow.document.commandDispatcher.focusedWindow.focus();
-}
-
-function ShowWindowFromResource( node ) {
-  var windowManagerDS =
-    Components.classes["@mozilla.org/rdf/datasource;1?name=window-mediator"]
-              .getService(Components.interfaces.nsIWindowDataSource);
-
-  var desiredWindow = null;
-  var url = node.getAttribute("id");
-  desiredWindow = windowManagerDS.getWindowForResource( url );
-  if (desiredWindow)
-    toOpenWindow(desiredWindow);
+function macWindowMenuDidHide() {
+  let sep = document.getElementById("sep-window-list");
+  // Clear old items
+  while (sep.nextElementSibling) {
+    sep.nextElementSibling.remove();
+  }
 }
 
 function zoomWindow() {
   if (window.windowState == window.STATE_NORMAL)
     window.maximize();
   else
     window.restore();
 }