Bug 1700051: part 28) Refactor `WordSplitState<T>::GetDOMWordSeparatorOffset` to...
[gecko.git] / widget / cocoa / nsMenuItemIconX.h
blobdca07a8fd4814e665aec5316f96d9b7fae6b4f68
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"
17 class nsIconLoaderService;
18 class nsIURI;
19 class nsIContent;
20 class nsIPrincipal;
21 class imgRequestProxy;
22 class nsMenuParentX;
24 namespace mozilla {
25 class ComputedStyle;
28 class nsMenuItemIconX final : public mozilla::widget::IconLoader::Listener {
29 public:
30 class Listener {
31 public:
32 virtual void IconUpdated() = 0;
35 explicit nsMenuItemIconX(Listener* aListener);
36 ~nsMenuItemIconX();
38 // SetupIcon starts the icon load. Once the icon has loaded,
39 // nsMenuParentX::IconUpdated will be called. The icon image needs to be
40 // retrieved from GetIconImage(). If aContent is an icon-less menuitem,
41 // GetIconImage() will return nil. If it does have an icon, GetIconImage()
42 // will return a transparent placeholder icon during the load and the actual
43 // icon when the load is completed.
44 void SetupIcon(nsIContent* aContent);
46 // Implements this method for mozilla::widget::IconLoader::Listener.
47 // Called once the icon load is complete.
48 nsresult OnComplete(imgIContainer* aImage) override;
50 // Returns a weak reference to the icon image that is owned by this class. Can
51 // return nil.
52 NSImage* GetIconImage() const { return mIconImage; }
54 protected:
55 // Returns whether there should be an icon.
56 bool StartIconLoad(nsIContent* aContent);
58 // GetIconURI returns null if the item should not have any icon.
59 already_AddRefed<nsIURI> GetIconURI(nsIContent* aContent);
61 nsCOMPtr<nsIContent> mContent; // always non-null
62 Listener* mListener; // [weak]
63 nsIntRect mImageRegionRect;
64 RefPtr<mozilla::ComputedStyle> mComputedStyle;
65 NSImage* mIconImage = nil; // [strong]
66 RefPtr<mozilla::widget::IconLoader> mIconLoader;
69 #endif // nsMenuItemIconX_h_