Bug 1676529 [wpt PR 26467] - [LayoutNG] Find sibling spanners using the child iterato...
[gecko.git] / widget / IconLoader.h
blobbee8ffc4807231c43c5c8782a850c3aefe9a7a90
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 #ifndef mozilla_widget_IconLoader_h_
7 #define mozilla_widget_IconLoader_h_
9 #include "imgINotificationObserver.h"
10 #include "mozilla/RefPtr.h"
11 #include "nsCOMPtr.h"
12 #include "nsIContentPolicy.h"
13 #include "nsISupports.h"
15 class nsIURI;
16 class nsINode;
17 class imgRequestProxy;
18 class imgIContainer;
20 namespace mozilla::widget {
22 /**
23 * IconLoader is a utility for loading icons from either the disk or over
24 * the network, and then using them in native OS widgetry like the macOS
25 * global menu bar or the Windows notification area.
28 class IconLoader : public imgINotificationObserver {
29 public:
30 /**
31 * IconLoader itself is cross-platform, but each platform needs to supply
32 * it with a Helper that does the platform-specific conversion work. The
33 * Helper needs to implement the OnComplete method in order to handle the
34 * imgIContainer of the loaded icon.
36 class Helper : public nsISupports {
37 public:
38 // Helper needs to implement nsISupports in order for its subclasses to
39 // participate in cycle collection
40 virtual nsresult OnComplete(imgIContainer* aContainer,
41 const nsIntRect& aRect) = 0;
43 protected:
44 virtual ~Helper() = default;
47 IconLoader(Helper* aHelper, nsINode* aContent,
48 const nsIntRect& aImageRegionRect);
50 public:
51 NS_DECL_CYCLE_COLLECTING_ISUPPORTS
52 NS_DECL_IMGINOTIFICATIONOBSERVER
53 NS_DECL_CYCLE_COLLECTION_CLASS(IconLoader)
55 // LoadIcon will start a load request for the icon.
56 // The request may not complete until after LoadIcon returns.
57 // If aIsInternalIcon is true, the document and principal will not be
58 // used when loading.
59 nsresult LoadIcon(nsIURI* aIconURI, bool aIsInternalIcon = false);
61 void ReleaseJSObjects() { mContent = nullptr; }
63 void Destroy();
65 protected:
66 virtual ~IconLoader();
68 private:
69 nsresult OnFrameComplete(imgIRequest* aRequest);
71 nsCOMPtr<nsINode> mContent;
72 nsContentPolicyType mContentType;
73 RefPtr<imgRequestProxy> mIconRequest;
74 nsIntRect mImageRegionRect;
75 bool mLoadedIcon;
76 RefPtr<Helper> mHelper;
79 } // namespace mozilla::widget
80 #endif // mozilla_widget_IconLoader_h_