Backed out changeset 2450366cf7ca (bug 1891629) for causing win msix mochitest failures
[gecko.git] / widget / cocoa / nsMenuItemIconX.h
blobe60e920f9d3274284f1e57c7dad3821a39aeedbe
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/. */
6 /*
7 * Retrieves and displays icons in native menu items on Mac OS X.
8 */
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;
19 class nsIURI;
20 class nsIContent;
21 class nsIPrincipal;
22 class imgRequestProxy;
23 class nsMenuParentX;
24 class nsPresContext;
26 namespace mozilla {
27 class ComputedStyle;
30 class nsMenuItemIconX final : public mozilla::widget::IconLoader::Listener {
31 public:
32 class Listener {
33 public:
34 virtual void IconUpdated() = 0;
37 explicit nsMenuItemIconX(Listener* aListener);
38 ~nsMenuItemIconX();
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
53 // return nil.
54 NSImage* GetIconImage() const { return mIconImage; }
56 protected:
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_