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/. */
7 * Retrieves and displays icons on the macOS Touch Bar.
10 #ifndef nsTouchBarInputIcon_h_
11 #define nsTouchBarInputIcon_h_
13 #import <Cocoa/Cocoa.h>
15 #include "mozilla/widget/IconLoader.h"
16 #include "nsTouchBarInput.h"
17 #include "nsTouchBarNativeAPIDefines.h"
19 using namespace mozilla::dom
;
23 class imgRequestProxy
;
25 namespace mozilla::dom
{
29 class nsTouchBarInputIcon
: public mozilla::widget::IconLoader::Listener
{
31 explicit nsTouchBarInputIcon(RefPtr
<Document
> aDocument
,
32 TouchBarInput
* aInput
, NSTouchBarItem
* aItem
);
34 NS_INLINE_DECL_REFCOUNTING(nsTouchBarInputIcon
)
37 virtual ~nsTouchBarInputIcon();
40 // SetupIcon succeeds if it was able to set up the icon, or if there should
41 // be no icon, in which case it clears any existing icon but still succeeds.
42 nsresult
SetupIcon(nsCOMPtr
<nsIURI
> aIconURI
);
44 // Implements this method for mozilla::widget::IconLoader::Listener.
45 // Called once the icon load is complete.
46 nsresult
OnComplete(imgIContainer
* aImage
) override
;
48 // Unless we take precautions, we may outlive the object that created us
49 // (mTouchBar, which owns our native menu item (mTouchBarInput)).
50 // Destroy() should be called from mTouchBar's destructor to prevent
51 // this from happening.
54 void ReleaseJSObjects();
57 RefPtr
<Document
> mDocument
;
58 nsIntRect mImageRegionRect
;
61 // We accept a mShareScrubber only as a special case since
62 // NSSharingServicePickerTouchBarItem does not expose an NSButton* on which we
63 // can set the `image` property.
64 NSSharingServicePickerTouchBarItem
* mShareScrubber
;
65 // We accept a popover only as a special case.
66 NSPopoverTouchBarItem
* mPopoverItem
;
67 // The icon loader object should never outlive its creating
68 // nsTouchBarInputIcon object.
69 RefPtr
<mozilla::widget::IconLoader
> mIconLoader
;
72 #endif // nsTouchBarInputIcon_h_