Bug 83056 Add support for windows sounds to Menus r=enndeakin, sr=roc, ui=jboriss
authorMasayuki Nakano <masayuki@d-toybox.com>
Thu, 11 Dec 2008 02:23:20 +0900
changeset 22575 8602d55fe61f
parent 22574 5ce74cb333cc
child 22576 1eae54a0f48c
push id4082
push usermasayuki@d-toybox.com
push dateWed, 10 Dec 2008 17:26:55 +0000
treeherdermozilla-central@1eae54a0f48c [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersenndeakin, roc
bugs83056
milestone1.9.2a1pre
Bug 83056 Add support for windows sounds to Menus r=enndeakin, sr=roc, ui=jboriss
layout/xul/base/src/nsMenuFrame.cpp
layout/xul/base/src/nsMenuPopupFrame.cpp
widget/public/nsISound.idl
widget/src/windows/nsSound.cpp
--- a/layout/xul/base/src/nsMenuFrame.cpp
+++ b/layout/xul/base/src/nsMenuFrame.cpp
@@ -77,16 +77,17 @@
 #include "nsXPIDLString.h"
 #include "nsReadableUtils.h"
 #include "nsUnicharUtils.h"
 #include "nsIStringBundle.h"
 #include "nsGUIEvent.h"
 #include "nsContentUtils.h"
 #include "nsDisplayList.h"
 #include "nsIReflowCallback.h"
+#include "nsISound.h"
 
 #define NS_MENU_POPUP_LIST_INDEX 0
 
 #if defined(XP_WIN) || defined(XP_OS2)
 #define NSCONTEXTMENUISMOUSEUP 1
 #endif
 
 static PRInt32 gEatMouseMove = PR_FALSE;
@@ -1167,16 +1168,20 @@ nsMenuFrame::Execute(nsGUIEvent *aEvent)
       else {
         mContent->SetAttr(kNameSpaceID_None, nsGkAtoms::checked, NS_LITERAL_STRING("true"),
                           PR_TRUE);
         ENSURE_TRUE(weakFrame.IsAlive());
       }
     }
   }
 
+  nsCOMPtr<nsISound> sound(do_CreateInstance("@mozilla.org/sound;1"));
+  if (sound)
+    sound->PlaySystemSound(NS_SYSSOUND_MENU_EXECUTE);
+
   nsXULPopupManager* pm = nsXULPopupManager::GetInstance();
   if (pm && mMenuParent)
     pm->ExecuteMenu(mContent, aEvent);
 }
 
 NS_IMETHODIMP
 nsMenuFrame::RemoveFrame(nsIAtom*        aListName,
                          nsIFrame*       aOldFrame)
--- a/layout/xul/base/src/nsMenuPopupFrame.cpp
+++ b/layout/xul/base/src/nsMenuPopupFrame.cpp
@@ -78,19 +78,17 @@
 #include "nsCSSFrameConstructor.h"
 #include "nsIEventStateManager.h"
 #include "nsIBoxLayout.h"
 #include "nsIPopupBoxObject.h"
 #include "nsIReflowCallback.h"
 #include "nsBindingManager.h"
 #include "nsIDocShellTreeOwner.h"
 #include "nsIBaseWindow.h"
-#ifdef XP_WIN
 #include "nsISound.h"
-#endif
 
 const PRInt32 kMaxZ = 0x7fffffff; //XXX: Shouldn't there be a define somewhere for MaxInt for PRInt32
 
 PRInt8 nsMenuPopupFrame::sDefaultLevelParent = -1;
 
 // NS_NewMenuPopupFrame
 //
 // Wrapper for creating a new menu popup container
@@ -620,16 +618,21 @@ nsMenuPopupFrame::ShowPopup(PRBool aIsCo
         AddLazyChildren(mContent, LazyGeneratePopupDone, NS_INT32_TO_PTR(aSelectFirstItem));
     }
     else {
       hasChildren = PR_TRUE;
       PresContext()->PresShell()->
         FrameNeedsReflow(this, nsIPresShell::eTreeChange,
                          NS_FRAME_HAS_DIRTY_CHILDREN);
     }
+    if (mPopupType == ePopupTypeMenu) {
+      nsCOMPtr<nsISound> sound(do_CreateInstance("@mozilla.org/sound;1"));
+      if (sound)
+        sound->PlaySystemSound(NS_SYSSOUND_MENU_POPUP);
+    }
   }
 
   mShouldAutoPosition = PR_TRUE;
   return hasChildren;
 }
 
 void
 nsMenuPopupFrame::HidePopup(PRBool aDeselectMenu, nsPopupState aNewState)
--- a/widget/public/nsISound.idl
+++ b/widget/public/nsISound.idl
@@ -61,13 +61,15 @@ interface nsISound : nsISupports
 %{C++
 
 #define NS_SYSSOUND_PREFIX          NS_LITERAL_STRING("_moz_")
 #define NS_SYSSOUND_MAIL_BEEP       NS_LITERAL_STRING("_moz_mailbeep")
 #define NS_SYSSOUND_ALERT_DIALOG    NS_LITERAL_STRING("_moz_alertdialog")
 #define NS_SYSSOUND_CONFIRM_DIALOG  NS_LITERAL_STRING("_moz_confirmdialog")
 #define NS_SYSSOUND_PROMPT_DIALOG   NS_LITERAL_STRING("_moz_promptdialog")
 #define NS_SYSSOUND_SELECT_DIALOG   NS_LITERAL_STRING("_moz_selectdialog")
+#define NS_SYSSOUND_MENU_EXECUTE    NS_LITERAL_STRING("_moz_menucommand")
+#define NS_SYSSOUND_MENU_POPUP      NS_LITERAL_STRING("_moz_menupopup")
 
 #define NS_IsMozAliasSound(aSoundAlias) \
           StringBeginsWith(aSoundAlias, NS_SYSSOUND_PREFIX)
 
 %}
--- a/widget/src/windows/nsSound.cpp
+++ b/widget/src/windows/nsSound.cpp
@@ -174,15 +174,19 @@ NS_IMETHODIMP nsSound::PlaySystemSound(c
   // NS_SYSSOUND_SELECT_DIALOG.
   const wchar_t *sound = nsnull;
   if (aSoundAlias.Equals(NS_SYSSOUND_MAIL_BEEP))
     sound = L"MailBeep";
   else if (aSoundAlias.Equals(NS_SYSSOUND_CONFIRM_DIALOG))
     sound = L"SystemQuestion";
   else if (aSoundAlias.Equals(NS_SYSSOUND_ALERT_DIALOG))
     sound = L"SystemExclamation";
+  else if (aSoundAlias.Equals(NS_SYSSOUND_MENU_EXECUTE))
+    sound = L"MenuCommand";
+  else if (aSoundAlias.Equals(NS_SYSSOUND_MENU_POPUP))
+    sound = L"MenuPopup";
 
   if (sound)
     ::PlaySoundW(sound, nsnull, SND_NODEFAULT | SND_ALIAS | SND_ASYNC);
 
   return NS_OK;
 }