Browse Source

b=476531, r=mfinkle, Need a way to minimize to tray programmatically

matthew@allpeers.com 15 years ago
parent
commit
3b02da3098

+ 5 - 0
runtime/components/public/nsIApplicationIcon.idl

@@ -91,6 +91,11 @@ interface nsIApplicationIcon : nsISupports
    */
   void hide();
   
+  /**
+   * Minimize the window to the notification area.
+   */
+  void minimize();
+  
   /**
    * Display a popup over the icon. Displays a normal alert (using nsIAlertsService) on
    * platforms that don't support balloon tips.

+ 5 - 0
runtime/components/src/mac/nsDockTile.mm

@@ -228,6 +228,11 @@ NS_IMETHODIMP nsDockTile::Hide()
   return NS_OK;
 }
 
+NS_IMETHODIMP nsDockTile::Minimize()
+{
+  return NS_OK;
+}
+
 NS_IMETHODIMP nsDockTile::SetBehavior(PRUint32 aBehavior)
 {
   // Ignored on OS X

+ 1 - 0
runtime/components/src/windows/Makefile.in

@@ -60,6 +60,7 @@ REQUIRES	= \
     widget \
     dom \
     caps \
+    content \
     prism_win \
     $(NULL)
 

+ 25 - 4
runtime/components/src/windows/nsNotificationArea.cpp

@@ -58,6 +58,7 @@
 #include "nsIInterfaceRequestor.h"
 #include "nsINativeIcon.h"
 #include "nsIIOService.h"
+#include "nsIPrivateDOMEvent.h"
 #include "nsIURI.h"
 #include "nsIXULWindow.h"
 #include "nsServiceManagerUtils.h"
@@ -444,6 +445,18 @@ nsNotificationArea::SetBehavior(PRUint32 aBehavior)
   return NS_OK;
 }
 
+NS_IMETHODIMP
+nsNotificationArea::Minimize()
+{
+  NS_ENSURE_STATE(mWindow);
+  
+  nsresult rv;
+  rv = DispatchEvent(mWindow, nsnull, NS_LITERAL_STRING("minimizing"), PR_TRUE, nsnull);
+  NS_ENSURE_SUCCESS(rv, rv);
+
+  return NS_OK;
+}
+
 NS_IMETHODIMP
 nsNotificationArea::ShowNotification(const nsAString& aTitle,
                                    const nsAString& aText,
@@ -563,6 +576,7 @@ nsNotificationArea::DispatchEvent(
   nsIDOMWindow* aDOMWindow,
   nsIDOMEventTarget* aEventTarget,
   const nsAString& aType,
+  PRBool canBubble,
   PRBool* aPreventDefault)
 {
   NS_ENSURE_ARG(aDOMWindow);
@@ -588,7 +602,14 @@ nsNotificationArea::DispatchEvent(
   rv = documentEvent->CreateEvent(NS_LITERAL_STRING("Events"), getter_AddRefs(event));
   NS_ENSURE_SUCCESS(rv, rv);
 
-  rv = event->InitEvent(aType, PR_TRUE, PR_TRUE);
+  rv = event->InitEvent(aType, canBubble, PR_TRUE);
+  NS_ENSURE_SUCCESS(rv, rv);
+  
+  // Need to make event trusted so content can cause it to be dispatched (e.g. minimizing the window via the API)
+  nsCOMPtr<nsIPrivateDOMEvent> privateEvent(do_QueryInterface(event, &rv));
+  NS_ENSURE_SUCCESS(rv, rv);
+  
+  rv = privateEvent->SetTrusted(PR_TRUE);
   NS_ENSURE_SUCCESS(rv, rv);
 
   PRBool ret;
@@ -682,7 +703,7 @@ nsNotificationArea::ListenerWindowProc(HWND hwnd,
         nsCOMPtr<nsIDOMElement> element = (nsIDOMElement *) itemInfo.dwItemData;
         nsCOMPtr<nsIDOMEventTarget> eventTarget(do_QueryInterface(element));
         
-        DispatchEvent(notificationArea->mWindow, eventTarget, NS_LITERAL_STRING("DOMActivate"), nsnull);
+        DispatchEvent(notificationArea->mWindow, eventTarget, NS_LITERAL_STRING("DOMActivate"), PR_FALSE, nsnull);
       }
       return FALSE;
     default:
@@ -696,7 +717,7 @@ nsNotificationArea::ListenerWindowProc(HWND hwnd,
       }
       break;
     case WM_LBUTTONDOWN:
-      DispatchEvent(notificationArea->mWindow, nsnull, NS_LITERAL_STRING("DOMActivate"), nsnull);
+      DispatchEvent(notificationArea->mWindow, nsnull, NS_LITERAL_STRING("DOMActivate"), PR_TRUE, nsnull);
       break;
   }
 
@@ -765,7 +786,7 @@ nsNotificationArea::WindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lPara
     // dispatch the event
     PRBool preventDefault;
     nsresult rv;
-    rv = DispatchEvent(domWindow, nsnull, typeArg, &preventDefault);
+    rv = DispatchEvent(domWindow, nsnull, typeArg, PR_TRUE, &preventDefault);
     NS_ENSURE_SUCCESS(rv, rv);
 
     if (preventDefault)

+ 1 - 1
runtime/components/src/windows/nsNotificationArea.h

@@ -85,7 +85,7 @@ protected:
   nsresult CreateMenu(nsIDOMElement* aElement, HMENU& subMenu);
   
   static nsresult DispatchEvent(nsIDOMWindow* aDOMWindow, nsIDOMEventTarget* aEventTarget, const nsAString& aType,
-    PRBool* aPreventDefault);
+    PRBool canBubble, PRBool* aPreventDefault);
   static void ShowPopupMenu(HWND hwnd, HMENU hmenu);
 
   static LRESULT CALLBACK ListenerWindowProc(