Bug 500506: Simplify providing an nsIController implementation for tab modes; r=Standard8
authorKarsten Düsterloh <mnyromyr@tprac.de>
Fri, 04 Sep 2009 15:11:33 +0200
changeset 3515 67a4f048f57398c13529981e2101a57acec131a0
parent 3514 71b3937a084cb557883dc581f169512606553432
child 3516 11ee32afb19b3e0ae084d51f0310b3d4f3a0683c
push id2848
push usermnyromyr@tprac.de
push dateFri, 04 Sep 2009 13:12:33 +0000
treeherdercomm-central@67a4f048f573 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersStandard8
bugs500506
Bug 500506: Simplify providing an nsIController implementation for tab modes; r=Standard8
mail/base/content/mailWindowOverlay.js
mail/base/content/specialTabs.js
mail/base/content/tabmail.xml
--- a/mail/base/content/mailWindowOverlay.js
+++ b/mail/base/content/mailWindowOverlay.js
@@ -2278,31 +2278,26 @@ let mailTabType = {
         gFolderTreeView.selection.selectEventsSuppressed = false;
       }
     }
 
     // restore focus
     this.restoreFocus(aTab);
   },
 
-  supportsCommand: function(aTab, aCommand) {
-    return DefaultController.supportsCommand(aCommand);
-  },
-
-  isCommandEnabled: function(aTab, aCommand) {
-    return DefaultController.isCommandEnabled(aCommand);
-  },
-
-  doCommand: function(aTab, aCommand) {
-    DefaultController.doCommand(aCommand, aTab);
-  },
-
-  onEvent: function(aTab, aEvent) {
-    DefaultController.onEvent(aEvent);
-  }
+  //
+  // nsIController implementation
+  //
+  // We ignore the aTab parameter sent by tabmail when calling nsIController
+  // stuff and just delegate the call to a default controller by using it as
+  // our proto chain:
+  // - "DefaultController" is the default controller of messenger.xul
+  // - "MessageWindowController" is the default controller of messageWindow.xul
+  __proto__: "DefaultController" in window && window.DefaultController ||
+             "MessageWindowController" in window && window.MessageWindowController
 };
 /**
  * The glodaSearch tab mode has a UI widget outside of the mailTabType's
  *  display panel, the #glodaSearchInput textbox.  This means we need to use a
  *  tab monitor so that we can appropriately update the contents of the textbox.
  * Every time a tab is changed, we save the state of the text box and restore
  *  its previous value for the tab we are switching to, as well as whether this
  *  value is a change to the currently-used value (if it is a glodaSearch) tab.
--- a/mail/base/content/specialTabs.js
+++ b/mail/base/content/specialTabs.js
@@ -159,17 +159,17 @@ var specialTabs = {
     },
     restoreTab: function onRestoreTab(aTabmail, aPersistedState) {
       aTabmail.openTab("contentTab", { contentPage: aPersistedState.tabURI,
                                        background: true } );
     },
     onTitleChanged: function onTitleChanged(aTab) {
       aTab.title = aTab.browser.contentDocument.title;
     },
-    supportsCommand: function supportsCommand(aTab, aCommand) {
+    supportsCommand: function supportsCommand(aCommand, aTab) {
       switch (aCommand) {
         case "cmd_fullZoomReduce":
         case "cmd_fullZoomEnlarge":
         case "cmd_fullZoomReset":
         case "cmd_fullZoomToggle":
         case "cmd_find":
         case "cmd_findAgain":
         case "cmd_findPrevious":
@@ -178,17 +178,17 @@ var specialTabs = {
         case "button_print":
         // XXX print preview not currently supported - bug 497994 to implement.
         // case "cmd_printpreview":
           return true;
         default:
           return false;
       }
     },
-    isCommandEnabled: function isCommandEnabled(aTab, aCommand) {
+    isCommandEnabled: function isCommandEnabled(aCommand, aTab) {
       switch (aCommand) {
         case "cmd_fullZoomReduce":
         case "cmd_fullZoomEnlarge":
         case "cmd_fullZoomReset":
         case "cmd_fullZoomToggle":
         case "cmd_find":
         case "cmd_findAgain":
         case "cmd_findPrevious":
@@ -197,17 +197,17 @@ var specialTabs = {
         case "button_print":
         // XXX print preview not currently supported - bug 497994 to implement.
         // case "cmd_printpreview":
           return true;
         default:
           return false;
       }
     },
-    doCommand: function isCommandEnabled(aTab, aCommand) {
+    doCommand: function isCommandEnabled(aCommand, aTab) {
       switch (aCommand) {
         case "cmd_fullZoomReduce":
           ZoomManager.reduce();
           break;
         case "cmd_fullZoomEnlarge":
           ZoomManager.enlarge();
           break;
         case "cmd_fullZoomReset":
--- a/mail/base/content/tabmail.xml
+++ b/mail/base/content/tabmail.xml
@@ -200,25 +200,25 @@
     -     opened.  This may seem odd, but it should help keep your code simple
     -     while letting you do whatever you want.  Since openTab is synchronous
     -     and returns the tabInfo structure built for the tab, you can perform
     -     any additional work you need after the call to openTab.
     - * onTitleChanged(aTab): Called when someone calls tabmail.setTabTitle() to
     -     hint that the tab's title needs to be updated.  This function should
     -     update aTab.title if it can.
     - Mode definition functions to do with menu/toolbar commands:
-    - * supportsCommand(aTab, aCommand): Called when a menu or toolbar needs to
+    - * supportsCommand(aCommand, aTab): Called when a menu or toolbar needs to
     -     be updated. Return true if you support that command in
     -     isCommandEnabled and doCommand, return false otherwise.
-    - * isCommandEnabled(aTab, aCommand): Called when a menu or toolbar needs
+    - * isCommandEnabled(aCommand, aTab): Called when a menu or toolbar needs
     -     to be updated. Return true if the command can be executed at the
     -     current time, false otherwise.
-    - * doCommand(aTab, aCommand): Called when a menu or toolbar command is to
+    - * doCommand(aCommand, aTab): Called when a menu or toolbar command is to
     -     be executed. Perform the action appropriate to the command.
-    - * onEvent(aTab, aEvent): This can be used to handle different events on
+    - * onEvent(aEvent, aTab): This can be used to handle different events on
     -     the window.
     - * getBrowser(aTab): This function should return the browser element for
     -     your tab if there is one (return null or don't define this function
     -     otherwise). It is used for some toolkit functions that require a
     -     global "getBrowser" function, e.g. ZoomManager.
     -
     - Tab monitoring code is expected to be used for widgets on the screen
     -  outside of the tab box that need to update themselves as the active tab
@@ -968,17 +968,17 @@
              // This can happen if we're starting up and haven't got a tab
              // loaded yet.
              if (!tab)
                return false;
 
              let supportsCommandFunc = tab.mode.supportsCommand ||
                                        tab.mode.tabType.supportsCommand;
              if (supportsCommandFunc)
-               return supportsCommandFunc.call(tab.mode.tabType, tab, aCommand);
+               return supportsCommandFunc.call(tab.mode.tabType, aCommand, tab);
 
              return false;
            ]]>
         </body>
       </method>
       <method name="isCommandEnabled">
         <parameter name="aCommand"/>
         <body>
@@ -988,17 +988,17 @@
              // This can happen if we're starting up and haven't got a tab
              // loaded yet.
              if (!tab)
                return false;
 
              let isCommandEnabledFunc = tab.mode.isCommandEnabled ||
                                         tab.mode.tabType.isCommandEnabled;
              if (isCommandEnabledFunc)
-               return isCommandEnabledFunc.call(tab.mode.tabType, tab, aCommand);
+               return isCommandEnabledFunc.call(tab.mode.tabType, aCommand, tab);
 
              return false;
            ]]>
         </body>
       </method>
       <method name="doCommand">
         <parameter name="aCommand"/>
         <body>
@@ -1008,17 +1008,17 @@
              // This can happen if we're starting up and haven't got a tab
              // loaded yet.
              if (!tab)
                return;
 
              let doCommandFunc = tab.mode.doCommand ||
                                  tab.mode.tabType.doCommand;
              if (doCommandFunc)
-               doCommandFunc.call(tab.mode.tabType, tab, aCommand);
+               doCommandFunc.call(tab.mode.tabType, aCommand, tab);
            ]]>
         </body>
       </method>
       <method name="onEvent">
         <parameter name="aEvent"/>
         <body>
            <![CDATA[
              let tab = this.currentTabInfo;
@@ -1026,17 +1026,17 @@
              // This can happen if we're starting up and haven't got a tab
              // loaded yet.
              if (!tab)
                return;
 
              let onEventFunc = tab.mode.onEvent ||
                                tab.mode.tabType.onEvent;
              if (onEventFunc)
-               return onEventFunc.call(tab.mode.tabType, tab, aEvent);
+               return onEventFunc.call(tab.mode.tabType, aEvent, tab);
 
              return false;
            ]]>
         </body>
       </method>
       <!-- Set the document title based on the tab title -->
       <method name="setDocumentTitle">
         <parameter name="aTab"/>