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/. */
7 * Retrieves and displays icons in native menu items on Mac OS X.
10 #ifndef nsMenuItemIconX_h_
11 #define nsMenuItemIconX_h_
13 #import <Cocoa/Cocoa.h>
15 #include "mozilla/widget/IconLoader.h"
16 #include "mozilla/WeakPtr.h"
18 class nsIconLoaderService
;
22 class imgRequestProxy
;
30 class nsMenuItemIconX final
: public mozilla::widget::IconLoader::Listener
{
34 virtual void IconUpdated() = 0;
37 explicit nsMenuItemIconX(Listener
* aListener
);
40 // SetupIcon starts the icon load. Once the icon has loaded,
41 // nsMenuParentX::IconUpdated will be called. The icon image needs to be
42 // retrieved from GetIconImage(). If aContent is an icon-less menuitem,
43 // GetIconImage() will return nil. If it does have an icon, GetIconImage()
44 // will return a transparent placeholder icon during the load and the actual
45 // icon when the load is completed.
46 void SetupIcon(nsIContent
* aContent
);
48 // Implements this method for mozilla::widget::IconLoader::Listener.
49 // Called once the icon load is complete.
50 nsresult
OnComplete(imgIContainer
* aImage
) override
;
52 // Returns a weak reference to the icon image that is owned by this class. Can
54 NSImage
* GetIconImage() const { return mIconImage
; }
57 // Returns whether there should be an icon.
58 bool StartIconLoad(nsIContent
* aContent
);
60 // GetIconURI returns null if the item should not have any icon.
61 already_AddRefed
<nsIURI
> GetIconURI(nsIContent
* aContent
);
63 Listener
* mListener
; // [weak]
64 RefPtr
<const mozilla::ComputedStyle
> mComputedStyle
;
65 mozilla::WeakPtr
<nsPresContext
> mPresContext
;
66 NSImage
* mIconImage
= nil
; // [strong]
67 RefPtr
<mozilla::widget::IconLoader
> mIconLoader
;
70 #endif // nsMenuItemIconX_h_