mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-10-19 16:25:38 +00:00
Bug 1691861 - Remove IconLoaderHelperCocoa. r=mconley
Differential Revision: https://phabricator.services.mozilla.com/D104632
This commit is contained in:
parent
2d7f24139c
commit
ebbe51a3e2
@ -1,93 +0,0 @@
|
||||
/* -*- 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"
|
||||
|
||||
@interface MOZIconHelper : NSObject
|
||||
|
||||
// Returns an autoreleased empty NSImage.
|
||||
+ (NSImage*)placeholderIconWithSize:(NSSize)aSize;
|
||||
|
||||
// Returns an autoreleased NSImage.
|
||||
+ (NSImage*)iconImageFromImageContainer:(imgIContainer*)aImage
|
||||
withSize:(NSSize)aSize
|
||||
subrect:(const nsIntRect&)aSubRect
|
||||
scaleFactor:(CGFloat)aScaleFactor;
|
||||
|
||||
@end
|
||||
|
||||
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 IconLoader::Listener {
|
||||
public:
|
||||
// Create the helper and install aLoadListener as a listener.
|
||||
// The helper does not keep a strong reference to the listener. Call Destroy
|
||||
// before the listener goes away.
|
||||
IconLoaderHelperCocoa(mozilla::widget::IconLoaderListenerCocoa* aLoadListener,
|
||||
uint32_t aIconHeight, uint32_t aIconWidth, CGFloat aScaleFactor = 0.0f);
|
||||
|
||||
NS_INLINE_DECL_REFCOUNTING(mozilla::widget::IconLoaderHelperCocoa)
|
||||
|
||||
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:
|
||||
// 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.
|
||||
IconLoaderListenerCocoa* mLoadListener;
|
||||
|
||||
uint32_t mIconHeight;
|
||||
uint32_t mIconWidth;
|
||||
CGFloat mScaleFactor;
|
||||
NSImage* mNativeIconImage;
|
||||
};
|
||||
|
||||
} // namespace mozilla::widget
|
||||
|
||||
#endif // mozilla_widget_IconLoaderHelperCocoa_h
|
28
widget/cocoa/MOZIconHelper.h
Normal file
28
widget/cocoa/MOZIconHelper.h
Normal file
@ -0,0 +1,28 @@
|
||||
/* -*- 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 MOZIconHelper_h
|
||||
#define MOZIconHelper_h
|
||||
|
||||
#import <Cocoa/Cocoa.h>
|
||||
|
||||
#include "nsRect.h"
|
||||
|
||||
class imgIContainer;
|
||||
|
||||
@interface MOZIconHelper : NSObject
|
||||
|
||||
// Returns an autoreleased empty NSImage.
|
||||
+ (NSImage*)placeholderIconWithSize:(NSSize)aSize;
|
||||
|
||||
// Returns an autoreleased NSImage.
|
||||
+ (NSImage*)iconImageFromImageContainer:(imgIContainer*)aImage
|
||||
withSize:(NSSize)aSize
|
||||
subrect:(const nsIntRect&)aSubRect
|
||||
scaleFactor:(CGFloat)aScaleFactor;
|
||||
|
||||
@end
|
||||
|
||||
#endif // MOZIconHelper_h
|
@ -4,42 +4,13 @@
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
/*
|
||||
* Retrieves and displays icons in native menu items on Mac OS X.
|
||||
* Creates icons for display in native menu items on macOS.
|
||||
*/
|
||||
|
||||
/* exception_defines.h defines 'try' to 'if (true)' which breaks objective-c
|
||||
exceptions and produces errors like: error: unexpected '@' in program'.
|
||||
If we define __EXCEPTIONS exception_defines.h will avoid doing this.
|
||||
#include "MOZIconHelper.h"
|
||||
|
||||
See bug 666609 for more information.
|
||||
|
||||
We use <limits> to get the libstdc++ version. */
|
||||
#include <limits>
|
||||
#if __GLIBCXX__ <= 20070719
|
||||
# ifndef __EXCEPTIONS
|
||||
# define __EXCEPTIONS
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#include "gfxPlatform.h"
|
||||
#include "imgIContainer.h"
|
||||
#include "imgLoader.h"
|
||||
#include "imgRequestProxy.h"
|
||||
#include "mozilla/dom/Document.h"
|
||||
#include "nsCocoaUtils.h"
|
||||
#include "nsContentUtils.h"
|
||||
#include "nsIContent.h"
|
||||
#include "nsNameSpaceManager.h"
|
||||
#include "nsNetUtil.h"
|
||||
#include "nsObjCExceptions.h"
|
||||
#include "nsThreadUtils.h"
|
||||
#include "nsToolkit.h"
|
||||
#include "IconLoaderHelperCocoa.h"
|
||||
|
||||
using namespace mozilla;
|
||||
|
||||
using mozilla::gfx::SourceSurface;
|
||||
using mozilla::widget::IconLoaderListenerCocoa;
|
||||
|
||||
@implementation MOZIconHelper
|
||||
|
||||
@ -107,57 +78,3 @@ using mozilla::widget::IconLoaderListenerCocoa;
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
namespace mozilla::widget {
|
||||
|
||||
IconLoaderHelperCocoa::IconLoaderHelperCocoa(IconLoaderListenerCocoa* aListener,
|
||||
uint32_t aIconHeight, uint32_t aIconWidth,
|
||||
CGFloat aScaleFactor)
|
||||
: mLoadListener(aListener),
|
||||
mIconHeight(aIconHeight),
|
||||
mIconWidth(aIconWidth),
|
||||
mScaleFactor(aScaleFactor) {
|
||||
// Placeholder icon, which will later be replaced.
|
||||
mNativeIconImage =
|
||||
[[MOZIconHelper placeholderIconWithSize:NSMakeSize(mIconHeight, mIconWidth)] retain];
|
||||
MOZ_ASSERT(aListener);
|
||||
}
|
||||
|
||||
IconLoaderHelperCocoa::~IconLoaderHelperCocoa() { Destroy(); }
|
||||
|
||||
nsresult IconLoaderHelperCocoa::OnComplete(imgIContainer* aImage, const nsIntRect& aRect) {
|
||||
NS_OBJC_BEGIN_TRY_ABORT_BLOCK_NSRESULT
|
||||
|
||||
NS_ENSURE_ARG_POINTER(aImage);
|
||||
|
||||
NSImage* newImage = [MOZIconHelper iconImageFromImageContainer:aImage
|
||||
withSize:NSMakeSize(mIconWidth, mIconHeight)
|
||||
subrect:aRect
|
||||
scaleFactor:mScaleFactor];
|
||||
|
||||
if (!newImage) {
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
[mNativeIconImage release];
|
||||
mNativeIconImage = [newImage retain];
|
||||
|
||||
if (mLoadListener) {
|
||||
mLoadListener->OnComplete();
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
NS_OBJC_END_TRY_ABORT_BLOCK_NSRESULT
|
||||
}
|
||||
|
||||
NSImage* IconLoaderHelperCocoa::GetNativeIconImage() { return mNativeIconImage; }
|
||||
|
||||
void IconLoaderHelperCocoa::Destroy() {
|
||||
if (mNativeIconImage) {
|
||||
[mNativeIconImage release];
|
||||
mNativeIconImage = nil;
|
||||
}
|
||||
mLoadListener = nullptr;
|
||||
}
|
||||
|
||||
} // namespace mozilla::widget
|
@ -35,7 +35,7 @@ EXPORTS.mozilla.widget += [
|
||||
|
||||
UNIFIED_SOURCES += [
|
||||
"GfxInfo.mm",
|
||||
"IconLoaderHelperCocoa.mm",
|
||||
"MOZIconHelper.mm",
|
||||
"NativeKeyBindings.mm",
|
||||
"NativeMenuSupport.mm",
|
||||
"nsAppShell.mm",
|
||||
|
@ -10,7 +10,7 @@
|
||||
#ifndef nsMenuItemIconX_h_
|
||||
#define nsMenuItemIconX_h_
|
||||
|
||||
#include "IconLoaderHelperCocoa.h"
|
||||
#include "mozilla/widget/IconLoader.h"
|
||||
|
||||
class nsIconLoaderService;
|
||||
class nsIURI;
|
||||
|
@ -21,6 +21,7 @@
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#include "MOZIconHelper.h"
|
||||
#include "mozilla/dom/Document.h"
|
||||
#include "nsCocoaUtils.h"
|
||||
#include "nsComputedDOMStyle.h"
|
||||
@ -37,7 +38,6 @@ using namespace mozilla;
|
||||
|
||||
using mozilla::dom::Element;
|
||||
using mozilla::widget::IconLoader;
|
||||
using mozilla::widget::IconLoaderHelperCocoa;
|
||||
|
||||
static const uint32_t kIconSize = 16;
|
||||
|
||||
|
@ -12,9 +12,9 @@
|
||||
|
||||
#import <Cocoa/Cocoa.h>
|
||||
|
||||
#include "mozilla/widget/IconLoader.h"
|
||||
#include "nsTouchBarInput.h"
|
||||
#include "nsTouchBarNativeAPIDefines.h"
|
||||
#include "IconLoaderHelperCocoa.h"
|
||||
|
||||
using namespace mozilla::dom;
|
||||
|
||||
|
@ -9,8 +9,8 @@
|
||||
|
||||
#include "nsTouchBarInputIcon.h"
|
||||
|
||||
#include "MOZIconHelper.h"
|
||||
#include "mozilla/dom/Document.h"
|
||||
#include "mozilla/widget/IconLoader.h"
|
||||
#include "nsCocoaUtils.h"
|
||||
#include "nsComputedDOMStyle.h"
|
||||
#include "nsContentUtils.h"
|
||||
@ -21,7 +21,6 @@
|
||||
|
||||
using namespace mozilla;
|
||||
using mozilla::widget::IconLoader;
|
||||
using mozilla::widget::IconLoaderHelperCocoa;
|
||||
|
||||
static const uint32_t kIconSize = 16;
|
||||
static const CGFloat kHiDPIScalingFactor = 2.0f;
|
||||
|
Loading…
Reference in New Issue
Block a user