blob: 6becaa7ba1043853f600c3f15ae9f7ffd67fb9a4 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
|
/* -*- 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_IconLoaderHelperCocoa_h
#define mozilla_widget_IconLoaderHelperCocoa_h
#import <Cocoa/Cocoa.h>
#include "mozilla/widget/IconLoader.h"
namespace mozilla::widget {
/**
* Classes that want to hear about when icons load should subclass
* IconLoaderListenerCocoa, and implement the OnComplete() method,
* which will be called once the load of the icon has completed.
*/
class IconLoaderListenerCocoa {
public:
IconLoaderListenerCocoa() = default;
NS_INLINE_DECL_REFCOUNTING(mozilla::widget::IconLoaderListenerCocoa)
virtual nsresult OnComplete() = 0;
protected:
virtual ~IconLoaderListenerCocoa() = default;
};
/**
* This is a Helper used with mozilla::widget::IconLoader that implements the
* macOS-specific functionality for converting a loaded icon into an NSImage*.
*/
class IconLoaderHelperCocoa final : public mozilla::widget::IconLoader::Helper {
public:
IconLoaderHelperCocoa(mozilla::widget::IconLoaderListenerCocoa* aLoadListener,
uint32_t aIconHeight, uint32_t aIconWidth, CGFloat aScaleFactor = 0.0f);
NS_DECL_ISUPPORTS
nsresult OnComplete(imgIContainer* aImage, const nsIntRect& aRect) override;
/**
* IconLoaderHelperCocoa will default the NSImage* returned by
* GetNativeIconImage to an empty icon. Once the load of the icon
* by IconLoader has completed, GetNativeIconImage will return the
* loaded icon.
*
* Note that IconLoaderHelperCocoa owns this NSImage. If you don't
* need it to hold onto the NSImage anymore, call Destroy on it to
* deallocate. The IconLoaderHelperCocoa destructor will also deallocate
* the NSImage if necessary.
*/
NSImage* GetNativeIconImage(); // Owned by IconLoaderHelperCocoa
void Destroy();
protected:
~IconLoaderHelperCocoa();
private:
RefPtr<mozilla::widget::IconLoaderListenerCocoa> mLoadListener;
uint32_t mIconHeight;
uint32_t mIconWidth;
CGFloat mScaleFactor;
NSImage* mNativeIconImage;
};
} // namespace mozilla::widget
#endif // mozilla_widget_IconLoaderHelperCocoa_h
|