|
1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ |
|
2 /* This Source Code Form is subject to the terms of the Mozilla Public |
|
3 * License, v. 2.0. If a copy of the MPL was not distributed with this |
|
4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
|
5 |
|
6 /* |
|
7 * Retrieves and displays icons in native menu items on Mac OS X. |
|
8 */ |
|
9 |
|
10 #ifndef nsMenuItemIconX_h_ |
|
11 #define nsMenuItemIconX_h_ |
|
12 |
|
13 #include "nsCOMPtr.h" |
|
14 #include "nsAutoPtr.h" |
|
15 #include "imgINotificationObserver.h" |
|
16 |
|
17 class nsIURI; |
|
18 class nsIContent; |
|
19 class imgRequestProxy; |
|
20 class nsMenuObjectX; |
|
21 |
|
22 #import <Cocoa/Cocoa.h> |
|
23 |
|
24 class nsMenuItemIconX : public imgINotificationObserver |
|
25 { |
|
26 public: |
|
27 nsMenuItemIconX(nsMenuObjectX* aMenuItem, |
|
28 nsIContent* aContent, |
|
29 NSMenuItem* aNativeMenuItem); |
|
30 private: |
|
31 virtual ~nsMenuItemIconX(); |
|
32 |
|
33 public: |
|
34 NS_DECL_ISUPPORTS |
|
35 NS_DECL_IMGINOTIFICATIONOBSERVER |
|
36 |
|
37 // SetupIcon succeeds if it was able to set up the icon, or if there should |
|
38 // be no icon, in which case it clears any existing icon but still succeeds. |
|
39 nsresult SetupIcon(); |
|
40 |
|
41 // GetIconURI fails if the item should not have any icon. |
|
42 nsresult GetIconURI(nsIURI** aIconURI); |
|
43 |
|
44 // LoadIcon will set a placeholder image and start a load request for the |
|
45 // icon. The request may not complete until after LoadIcon returns. |
|
46 nsresult LoadIcon(nsIURI* aIconURI); |
|
47 |
|
48 // Unless we take precautions, we may outlive the object that created us |
|
49 // (mMenuObject, which owns our native menu item (mNativeMenuItem)). |
|
50 // Destroy() should be called from mMenuObject's destructor to prevent |
|
51 // this from happening. See bug 499600. |
|
52 void Destroy(); |
|
53 |
|
54 protected: |
|
55 nsresult OnStopFrame(imgIRequest* aRequest); |
|
56 |
|
57 nsCOMPtr<nsIContent> mContent; |
|
58 nsRefPtr<imgRequestProxy> mIconRequest; |
|
59 nsMenuObjectX* mMenuObject; // [weak] |
|
60 nsIntRect mImageRegionRect; |
|
61 bool mLoadedIcon; |
|
62 bool mSetIcon; |
|
63 NSMenuItem* mNativeMenuItem; // [weak] |
|
64 }; |
|
65 |
|
66 #endif // nsMenuItemIconX_h_ |