diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 17:32:43 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 17:32:43 +0000 |
commit | 6bf0a5cb5034a7e684dcc3500e841785237ce2dd (patch) | |
tree | a68f146d7fa01f0134297619fbe7e33db084e0aa /widget/IconLoader.h | |
parent | Initial commit. (diff) | |
download | thunderbird-6bf0a5cb5034a7e684dcc3500e841785237ce2dd.tar.xz thunderbird-6bf0a5cb5034a7e684dcc3500e841785237ce2dd.zip |
Adding upstream version 1:115.7.0.upstream/1%115.7.0upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'widget/IconLoader.h')
-rw-r--r-- | widget/IconLoader.h | 69 |
1 files changed, 69 insertions, 0 deletions
diff --git a/widget/IconLoader.h b/widget/IconLoader.h new file mode 100644 index 0000000000..f665df6fc5 --- /dev/null +++ b/widget/IconLoader.h @@ -0,0 +1,69 @@ +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +#ifndef mozilla_widget_IconLoader_h_ +#define mozilla_widget_IconLoader_h_ + +#include "imgINotificationObserver.h" +#include "mozilla/RefPtr.h" +#include "nsCOMPtr.h" +#include "nsISupports.h" + +class nsIURI; +class nsINode; +class imgRequestProxy; +class imgIContainer; + +namespace mozilla::widget { + +/** + * IconLoader is a utility for loading icons from either the disk or over + * the network, and then using them in native OS widgetry like the macOS + * global menu bar or the Windows notification area. + */ + +class IconLoader : public imgINotificationObserver { + public: + // This is the interface that our listeners need to implement so that they can + // be notified when the icon is loaded. + class Listener { + public: + virtual nsresult OnComplete(imgIContainer* aContainer) = 0; + }; + + // Create the loader. + // aListener will be notified when the load is complete. + // The loader does not keep an owning reference to the listener. Call Destroy + // before the listener goes away. + explicit IconLoader(Listener* aListener); + + public: + NS_DECL_ISUPPORTS + NS_DECL_IMGINOTIFICATIONOBSERVER + + // LoadIcon will start a load request for the icon. + // The request may not complete until after LoadIcon returns. + // If aIsInternalIcon is true, the document and principal will not be + // used when loading. + nsresult LoadIcon(nsIURI* aIconURI, nsINode* aNode, + bool aIsInternalIcon = false); + + void Destroy(); + + protected: + virtual ~IconLoader(); + + private: + RefPtr<imgRequestProxy> mIconRequest; + + // The listener, which is notified when loading completes. + // Can be null, after a call to Destroy. + // This is a non-owning reference and needs to be cleared with a call to + // Destroy before the listener goes away. + Listener* mListener; +}; + +} // namespace mozilla::widget +#endif // mozilla_widget_IconLoader_h_ |