summaryrefslogtreecommitdiffstats
path: root/widget/cocoa/nsCocoaUtils.mm
diff options
context:
space:
mode:
Diffstat (limited to 'widget/cocoa/nsCocoaUtils.mm')
-rw-r--r--widget/cocoa/nsCocoaUtils.mm84
1 files changed, 30 insertions, 54 deletions
diff --git a/widget/cocoa/nsCocoaUtils.mm b/widget/cocoa/nsCocoaUtils.mm
index f3a7604762..769eb05a85 100644
--- a/widget/cocoa/nsCocoaUtils.mm
+++ b/widget/cocoa/nsCocoaUtils.mm
@@ -515,11 +515,27 @@ nsresult nsCocoaUtils::CreateNSImageFromCGImage(CGImageRef aInputImage,
nsresult nsCocoaUtils::CreateNSImageFromImageContainer(
imgIContainer* aImage, uint32_t aWhichFrame,
const nsPresContext* aPresContext, const ComputedStyle* aComputedStyle,
- NSImage** aResult, CGFloat scaleFactor, bool* aIsEntirelyBlack) {
+ const NSSize& aPreferredSize, NSImage** aResult, CGFloat scaleFactor,
+ bool* aIsEntirelyBlack) {
RefPtr<SourceSurface> surface;
- int32_t width = 0, height = 0;
- aImage->GetWidth(&width);
- aImage->GetHeight(&height);
+ int32_t width = 0;
+ int32_t height = 0;
+ {
+ const bool gotWidth = NS_SUCCEEDED(aImage->GetWidth(&width));
+ const bool gotHeight = NS_SUCCEEDED(aImage->GetHeight(&height));
+ if (auto ratio = aImage->GetIntrinsicRatio()) {
+ if (gotWidth != gotHeight) {
+ if (gotWidth) {
+ height = ratio->Inverted().ApplyTo(width);
+ } else {
+ width = ratio->ApplyTo(height);
+ }
+ } else if (!gotWidth) {
+ height = std::ceil(aPreferredSize.height);
+ width = ratio->ApplyTo(height);
+ }
+ }
+ }
// Render a vector image at the correct resolution on a retina display
if (aImage->GetType() == imgIContainer::TYPE_VECTOR) {
@@ -582,31 +598,28 @@ nsresult nsCocoaUtils::CreateNSImageFromImageContainer(
nsresult nsCocoaUtils::CreateDualRepresentationNSImageFromImageContainer(
imgIContainer* aImage, uint32_t aWhichFrame,
const nsPresContext* aPresContext, const ComputedStyle* aComputedStyle,
- NSImage** aResult, bool* aIsEntirelyBlack) {
- int32_t width = 0, height = 0;
- aImage->GetWidth(&width);
- aImage->GetHeight(&height);
- NSSize size = NSMakeSize(width, height);
- *aResult = [[NSImage alloc] init];
- [*aResult setSize:size];
-
+ const NSSize& aPreferredSize, NSImage** aResult, bool* aIsEntirelyBlack) {
NSImage* newRepresentation = nil;
nsresult rv = CreateNSImageFromImageContainer(
- aImage, aWhichFrame, aPresContext, aComputedStyle, &newRepresentation,
- 1.0f, aIsEntirelyBlack);
+ aImage, aWhichFrame, aPresContext, aComputedStyle, aPreferredSize,
+ &newRepresentation, 1.0f, aIsEntirelyBlack);
if (NS_FAILED(rv) || !newRepresentation) {
return NS_ERROR_FAILURE;
}
+ NSSize size = newRepresentation.size;
+ *aResult = [[NSImage alloc] init];
+ [*aResult setSize:size];
+
[[[newRepresentation representations] objectAtIndex:0] setSize:size];
[*aResult
addRepresentation:[[newRepresentation representations] objectAtIndex:0]];
[newRepresentation release];
newRepresentation = nil;
- rv = CreateNSImageFromImageContainer(aImage, aWhichFrame, aPresContext,
- aComputedStyle, &newRepresentation, 2.0f,
- aIsEntirelyBlack);
+ rv = CreateNSImageFromImageContainer(
+ aImage, aWhichFrame, aPresContext, aComputedStyle, aPreferredSize,
+ &newRepresentation, 2.0f, aIsEntirelyBlack);
if (NS_FAILED(rv) || !newRepresentation) {
return NS_ERROR_FAILURE;
}
@@ -619,43 +632,6 @@ nsresult nsCocoaUtils::CreateDualRepresentationNSImageFromImageContainer(
}
// static
-void nsCocoaUtils::GetStringForNSString(const NSString* aSrc,
- nsAString& aDist) {
- NS_OBJC_BEGIN_TRY_IGNORE_BLOCK;
-
- if (!aSrc) {
- aDist.Truncate();
- return;
- }
-
- aDist.SetLength([aSrc length]);
- [aSrc getCharacters:reinterpret_cast<unichar*>(aDist.BeginWriting())
- range:NSMakeRange(0, [aSrc length])];
-
- NS_OBJC_END_TRY_IGNORE_BLOCK;
-}
-
-// static
-NSString* nsCocoaUtils::ToNSString(const nsAString& aString) {
- if (aString.IsEmpty()) {
- return [NSString string];
- }
- return [NSString stringWithCharacters:reinterpret_cast<const unichar*>(
- aString.BeginReading())
- length:aString.Length()];
-}
-
-// static
-NSString* nsCocoaUtils::ToNSString(const nsACString& aCString) {
- if (aCString.IsEmpty()) {
- return [NSString string];
- }
- return [[[NSString alloc] initWithBytes:aCString.BeginReading()
- length:aCString.Length()
- encoding:NSUTF8StringEncoding] autorelease];
-}
-
-// static
NSURL* nsCocoaUtils::ToNSURL(const nsAString& aURLString) {
nsAutoCString encodedURLString;
nsresult rv = NS_GetSpecWithNSURLEncoding(encodedURLString,