Bug 613156 - Implement splitmenu binding. r=dolske a=blocks-blocker
authorDão Gottwald <dao@mozilla.com>
Thu, 02 Dec 2010 09:45:08 +0100
changeset 58454 405a236b58728ebf9549f48a91ed8c63e70c436f
parent 58453 baa5ae44f0ba9a8fb14197ca49fbb2ef6c754b3d
child 58455 7ea516b743f58d7a6cba51a431d4d19dab9038df
push id1
push usershaver@mozilla.com
push dateTue, 04 Jan 2011 17:58:04 +0000
reviewersdolske, blocks-blocker
bugs613156
milestone2.0b8pre
Bug 613156 - Implement splitmenu binding. r=dolske a=blocks-blocker
browser/base/content/browser-appmenu.inc
browser/base/content/browser.css
browser/base/content/urlbarBindings.xml
--- a/browser/base/content/browser-appmenu.inc
+++ b/browser/base/content/browser-appmenu.inc
@@ -41,42 +41,36 @@
 <menupopup id="appmenu-popup"
 #ifdef MOZ_SERVICES_SYNC
            onpopupshowing="updateEditUIVisibility();gSyncUI.updateUI();">
 #else
            onpopupshowing="updateEditUIVisibility();">
 #endif
   <hbox>
     <vbox id="appmenuPrimaryPane">
-      <hbox flex="1"
-            class="split-menuitem">
-        <menuitem id="appmenu_newTab"
-                  class="menuitem-tooltip split-menuitem-item"
-                  flex="1"
-                  label="&tabCmd.label;"
-                  command="cmd_newNavigatorTab"
-                  key="key_newNavigatorTab"/>
-        <menu class="split-menuitem-menu">
+      <splitmenu id="appmenu_newTab"
+                 label="&tabCmd.label;"
+                 command="cmd_newNavigatorTab"
+                 key="key_newNavigatorTab">
           <menupopup>
             <menuitem id="appmenu_newTab_popup"
                       label="&tabCmd.label;"
                       command="cmd_newNavigatorTab"
                       key="key_newNavigatorTab"/>
             <menuitem id="appmenu_newNavigator"
                       label="&newNavigatorCmd.label;"
                       command="cmd_newNavigator"
                       key="key_newNavigator"/>
             <menuseparator/>
             <menuitem id="appmenu_openFile"
                       label="&openFileCmd.label;"
                       command="Browser:OpenFile"
                       key="openFileKb"/>
           </menupopup>
-        </menu>
-      </hbox>
+      </splitmenu>
       <menuitem id="appmenu_privateBrowsing"
                 class="menuitem-iconic menuitem-iconic-tooltip"
                 label="&privateBrowsingCmd.start.label;"
                 startlabel="&privateBrowsingCmd.start.label;"
                 stoplabel="&privateBrowsingCmd.stop.label;"
                 command="Tools:PrivateBrowsing"
                 key="key_privatebrowsing"/>
       <menuitem label="&goOfflineCmd.label;"
@@ -114,40 +108,35 @@
       <menuitem id="appmenu_savePage"
                 class="menuitem-tooltip"
                 label="&savePageCmd.label;"
                 command="Browser:SavePage"
                 key="key_savePage"/>
       <menuitem id="appmenu_sendLink"
                 label="&sendPageCmd.label;"
                 command="Browser:SendLink"/>
-      <hbox flex="1"
-            class="split-menuitem">
-        <menuitem id="appmenu_print"
-                  class="menuitem-iconic menuitem-iconic-tooltip split-menuitem-item"
-                  flex="1"
-                  label="&printCmd.label;"
-                  command="cmd_print"
-                  key="printKb"/>
-        <menu class="split-menuitem-menu">
+      <splitmenu id="appmenu_print"
+                 iconic="true"
+                 label="&printCmd.label;"
+                 command="cmd_print"
+                 key="printKb">
           <menupopup>
             <menuitem id="appmenu_print_popup"
                       class="menuitem-iconic"
                       label="&printCmd.label;"
                       command="cmd_print"
                       key="printKb"/>
             <menuitem id="appmenu_printPreview"
                       label="&printPreviewCmd.label;"
                       command="cmd_printPreview"/>
             <menuitem id="appmenu_printSetup"
                       label="&printSetupCmd.label;"
                       command="cmd_pageSetup"/>
           </menupopup>
-        </menu>
-      </hbox>
+      </splitmenu>
       <menuseparator class="appmenu-menuseparator"/>
       <menu id="appmenu_webDeveloper"
             label="&appMenuWebDeveloper.label;">
         <menupopup id="appmenu_webDeveloper_popup">
           <menuitem id="appmenu_webConsole"
                     label="&webConsoleCmd.label;"
                     oncommand="HUDConsoleUI.toggleHUD();"
                     key="key_webConsole"/>
@@ -188,25 +177,21 @@
 #ifdef XP_WIN
                 label="&quitApplicationCmdWin.label;"
 #else
                 label="&quitApplicationCmd.label;"
 #endif
                 command="cmd_quitApplication"/>
     </vbox>
     <vbox id="appmenuSecondaryPane">
-      <hbox class="split-menuitem">
-        <menuitem id="appmenu_bookmarks"
-                  class="menuitem-iconic menuitem-iconic-tooltip split-menuitem-item"
-                  flex="1"
-                  label="&bookmarksMenu.label;"
-                  command="Browser:ShowAllBookmarks"
-                  key="manBookmarkKb"/>
-        <menu id="appmenu_bookmarksMenu"
-              class="split-menuitem-menu">
+      <splitmenu id="appmenu_bookmarks"
+                 iconic="true"
+                 label="&bookmarksMenu.label;"
+                 command="Browser:ShowAllBookmarks"
+                 key="manBookmarkKb">
           <menupopup id="appmenu_bookmarksPopup"
                      placespopup="true"
                      context="placesContext"
                      openInTabs="children"
                      oncommand="BookmarksEventHandler.onCommand(event);"
                      onclick="BookmarksEventHandler.onClick(event);"
                      onpopupshowing="BookmarksMenuButton.onPopupShowing(event);
                                      if (!this.parentNode._placesView)
@@ -255,27 +240,22 @@
             <!-- Bookmarks menu items -->
             <menuseparator builder="end"
                            class="hide-if-empty-places-result"/>
             <menuitem id="appmenu_unsortedBookmarks"
                       label="&appMenuUnsorted.label;"
                       oncommand="PlacesCommandHook.showPlacesOrganizer('UnfiledBookmarks');"
                       class="menuitem-iconic"/>
           </menupopup>
-        </menu>
-      </hbox>
-      <hbox class="split-menuitem">
-        <menuitem id="appmenu_history"
-                  class="menuitem-iconic menuitem-iconic-tooltip split-menuitem-item"
-                  flex="1"
-                  label="&historyMenu.label;"
-                  command="Browser:ShowAllHistory"
-                  key="showAllHistoryKb"/>
-        <menu id="appmenu_historyMenu"
-              class="split-menuitem-menu">
+      </splitmenu>
+      <splitmenu id="appmenu_history"
+                 iconic="true"
+                 label="&historyMenu.label;"
+                 command="Browser:ShowAllHistory"
+                 key="showAllHistoryKb">
           <menupopup id="appmenu_historyMenupopup"
                      placespopup="true"
                      oncommand="this.parentNode._placesView._onCommand(event);"
                      onclick="checkForMiddleClick(this, event);"
                      onpopupshowing="if (!this.parentNode._placesView)
                                        new HistoryMenu(event);"
                      tooltip="bhTooltip"
                      popupsinherittooltip="true">
@@ -305,41 +285,35 @@
                   class="recentlyClosedWindowsMenu"
                   label="&historyUndoWindowMenu.label;"
                   disabled="true">
               <menupopup id="appmenu_recentlyClosedWindowsMenupopup"
                          onpopupshowing="document.getElementById('appmenu_historyMenu')._placesView.populateUndoWindowSubmenu();"/>
             </menu>
             <menuseparator/>
           </menupopup>
-        </menu>
-      </hbox>
+      </splitmenu>
       <menuitem id="appmenu_downloads"
                 class="menuitem-tooltip"
                 label="&downloads.label;"
                 command="Tools:Downloads"
                 key="key_openDownloads"/>
       <spacer id="appmenuSecondaryPane-spacer"/>
       <menuitem id="appmenu_addons"
                 class="menuitem-iconic menuitem-iconic-tooltip"
                 label="&addons.label;"
                 command="Tools:Addons"
                 key="key_openAddons"/>
-      <hbox class="split-menuitem">
-        <menuitem id="appmenu_customize"
+      <splitmenu id="appmenu_customize"
 #ifdef XP_UNIX
-                  label="&preferencesCmdUnix.label;"
+                 label="&preferencesCmdUnix.label;"
 #else
-                  label="&preferencesCmd2.label;"
+                 label="&preferencesCmd2.label;"
 #endif
-                  class="split-menuitem-item"
-                  flex="1"
-                  oncommand="openPreferences();"/>
-        <menu class="split-menuitem-menu"
-              label="&preferencesCmd2.label;">
+                 oncommand="openPreferences();">
           <menupopup id="appmenu_customizeMenu"
                      onpopupshowing="onViewToolbarsPopupShowing(event, document.getElementById('appmenu_toggleTabsOnTop').previousSibling);">
             <menuitem id="appmenu_preferences"
 #ifdef XP_UNIX
                       label="&preferencesCmdUnix.label;"
 #else
                       label="&preferencesCmd2.label;"
 #endif
@@ -349,25 +323,20 @@
             <menuitem id="appmenu_toggleTabsOnTop"
                       label="&viewTabsOnTop.label;"
                       type="checkbox"
                       command="cmd_ToggleTabsOnTop"/>
             <menuitem id="appmenu_toolbarLayout"
                       label="&appMenuToolbarLayout.label;"
                       command="cmd_CustomizeToolbars"/>
           </menupopup>
-        </menu>
-      </hbox>
-      <hbox class="split-menuitem">
-        <menuitem id="appmenu_help"
-                  class="split-menuitem-item"
-                  flex="1"
-                  label="&helpMenu.label;"
-                  oncommand="openHelpLink('firefox-help')"/>
-        <menu class="split-menuitem-menu">
+      </splitmenu>
+      <splitmenu id="appmenu_help"
+                 label="&helpMenu.label;"
+                 oncommand="openHelpLink('firefox-help')">
           <menupopup id="appmenu_helpMenupopup">
             <menuitem id="appmenu_openHelp"
                       label="&helpMenu.label;"
                       oncommand="openHelpLink('firefox-help')"
                       onclick="checkForMiddleClick(this, event);"/>
             <menuitem id="appmenu_gettingStarted"
                       label="&appMenuGettingStarted.label;"
                       oncommand="gBrowser.loadOneTab('http://www.mozilla.com/firefox/central/', {inBackground: false});"
@@ -385,18 +354,17 @@
                       accesskey="&appMenuSafeMode.accesskey;"
                       label="&appMenuSafeMode.label;"
                       oncommand="safeModeRestart();"/>
             <menuseparator/>
             <menuitem id="appmenu_about"
                       label="&aboutProduct.label;"
                       oncommand="openAboutDialog();"/>
           </menupopup>
-        </menu>
-      </hbox>
+      </splitmenu>
 #ifdef MOZ_SERVICES_SYNC
       <spacer flex="1"/>
       <!-- only one of sync-setup or sync-syncnow will be showing at once -->
       <menuitem id="sync-setup-appmenu"
                 label="&syncSetup.label;"
                 observes="sync-setup-state"
                 oncommand="gSyncUI.openSetup()"/>
       <menuitem id="sync-syncnowitem-appmenu"
--- a/browser/base/content/browser.css
+++ b/browser/base/content/browser.css
@@ -131,16 +131,25 @@ toolbar[mode="icons"] > #reload-button[d
 }
 %endif
 
 #browser-bottombox[lwthemefooter="true"] {
   background-repeat: no-repeat;
   background-position: bottom left;
 }
 
+splitmenu {
+  -moz-binding: url("chrome://browser/content/urlbarBindings.xml#splitmenu");
+}
+
+.split-menuitem-item {
+  list-style-image: inherit;
+  -moz-image-region: inherit;
+}
+
 .split-menuitem-menu > .menu-text,
 .split-menuitem-menu > .menu-accel-container {
   display: none;
 }
 
 .menuitem-tooltip {
   -moz-binding: url("chrome://browser/content/urlbarBindings.xml#menuitem-tooltip");
 }
--- a/browser/base/content/urlbarBindings.xml
+++ b/browser/base/content/urlbarBindings.xml
@@ -1020,16 +1020,41 @@
         link.value = gNavigatorBundle.getString("geolocation.learnMore");
         
         let formatter = Cc["@mozilla.org/toolkit/URLFormatterService;1"].getService(Ci.nsIURLFormatter);
         link.href = formatter.formatURLPref("browser.geolocation.warning.infoURL");
       ]]></constructor>
     </implementation>
   </binding>
 
+  <binding id="splitmenu">
+    <content>
+      <xul:menuitem anonid="item" flex="1"
+                    class="menuitem-tooltip split-menuitem-item"
+                    xbl:inherits="label,key"/>
+      <xul:menu anonid="menu" class="split-menuitem-menu"
+                oncommand="event.stopPropagation();">
+        <children includes="menupopup"/>
+      </xul:menu>
+    </content>
+
+    <implementation>
+      <constructor><![CDATA[
+        if (this.getAttribute("iconic") == "true") {
+          this.item.classList.remove("menuitem-tooltip");
+          this.item.classList.add("menuitem-iconic-tooltip");
+          this.item.classList.add("menuitem-iconic");
+        }
+      ]]></constructor>
+      <field name="item" readonly="true">
+        document.getAnonymousElementByAttribute(this, "anonid", "item");
+      </field>
+    </implementation>
+  </binding>
+
   <binding id="menuitem-tooltip" extends="chrome://global/content/bindings/menu.xml#menuitem">
     <implementation>
       <constructor><![CDATA[
         this.setAttribute("tooltiptext", this.getAttribute("acceltext"));
         // TODO: Simplify this to this.setAttribute("acceltext", "") once bug
         // 592424 is fixed
         document.getAnonymousElementByAttribute(this, "anonid", "accel").firstChild.setAttribute("value", "");
       ]]></constructor>