Backed out changeset 2450366cf7ca (bug 1891629) for causing win msix mochitest failures
[gecko.git] / widget / cocoa / nsTouchBarInputIcon.h
blobd018afb756ef339085573a530764cca5d9988b88
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 on the macOS Touch Bar.
8 */
10 #ifndef nsTouchBarInputIcon_h_
11 #define nsTouchBarInputIcon_h_
13 #import <Cocoa/Cocoa.h>
15 #include "mozilla/widget/IconLoader.h"
16 #include "nsTouchBarInput.h"
18 using namespace mozilla::dom;
20 class nsIURI;
21 class nsIPrincipal;
22 class imgRequestProxy;
24 namespace mozilla::dom {
25 class Document;
28 class nsTouchBarInputIcon : public mozilla::widget::IconLoader::Listener {
29 public:
30 explicit nsTouchBarInputIcon(RefPtr<Document> aDocument,
31 TouchBarInput* aInput, NSTouchBarItem* aItem);
33 NS_INLINE_DECL_REFCOUNTING(nsTouchBarInputIcon)
35 private:
36 virtual ~nsTouchBarInputIcon();
38 public:
39 // SetupIcon succeeds if it was able to set up the icon, or if there should
40 // be no icon, in which case it clears any existing icon but still succeeds.
41 nsresult SetupIcon(nsCOMPtr<nsIURI> aIconURI);
43 // Implements this method for mozilla::widget::IconLoader::Listener.
44 // Called once the icon load is complete.
45 nsresult OnComplete(imgIContainer* aImage) override;
47 // Unless we take precautions, we may outlive the object that created us
48 // (mTouchBar, which owns our native menu item (mTouchBarInput)).
49 // Destroy() should be called from mTouchBar's destructor to prevent
50 // this from happening.
51 void Destroy();
53 void ReleaseJSObjects();
55 protected:
56 RefPtr<Document> mDocument;
57 bool mSetIcon;
58 NSButton* mButton;
59 // We accept a mShareScrubber only as a special case since
60 // NSSharingServicePickerTouchBarItem does not expose an NSButton* on which we
61 // can set the `image` property.
62 NSSharingServicePickerTouchBarItem* mShareScrubber;
63 // We accept a popover only as a special case.
64 NSPopoverTouchBarItem* mPopoverItem;
65 // The icon loader object should never outlive its creating
66 // nsTouchBarInputIcon object.
67 RefPtr<mozilla::widget::IconLoader> mIconLoader;
70 #endif // nsTouchBarInputIcon_h_