Bug 1338870 - Don't call [super respondsToSelector:] because it doesn't do what you might think. r?spohl
From https://developer.apple.com/reference/objectivec/1418956-nsobject/1418583-respondstoselector :
> You cannot test whether an object inherits a method from its superclass by
> sending respondsToSelector: to the object using the super keyword. This method
> will still be testing the object as a whole, not just the superclass’s
> implementation. Therefore, sending respondsToSelector: to super is equivalent
> to sending it to self. Instead, you must invoke the NSObject class method
> instancesRespondToSelector: directly on the object’s superclass.
MozReview-Commit-ID: 8wTexCQWUPw
--- a/widget/cocoa/nsCocoaWindow.mm
+++ b/widget/cocoa/nsCocoaWindow.mm
@@ -3183,17 +3183,19 @@ static const NSString* kStateCollectionB
return [super contentRectForFrameRect:aRect];
}
- (NSRect)contentRectForFrameRect:(NSRect)aRect styleMask:(NSUInteger)aMask
{
if ([self drawsContentsIntoWindowFrame]) {
return aRect;
}
- if ([super respondsToSelector:@selector(contentRectForFrameRect:styleMask:)]) {
+ // Call the instance method on super, if it exists (it's undocumented so we
+ // shouldn't rely on it), or fall back to the (documented) class method.
+ if ([NSWindow instancesRespondToSelector:@selector(contentRectForFrameRect:styleMask:)]) {
return [super contentRectForFrameRect:aRect styleMask:aMask];
} else {
return [NSWindow contentRectForFrameRect:aRect styleMask:aMask];
}
}
- (NSRect)frameRectForContentRect:(NSRect)aRect
{
@@ -3203,17 +3205,19 @@ static const NSString* kStateCollectionB
return [super frameRectForContentRect:aRect];
}
- (NSRect)frameRectForContentRect:(NSRect)aRect styleMask:(NSUInteger)aMask
{
if ([self drawsContentsIntoWindowFrame]) {
return aRect;
}
- if ([super respondsToSelector:@selector(frameRectForContentRect:styleMask:)]) {
+ // Call the instance method on super, if it exists (it's undocumented so we
+ // shouldn't rely on it), or fall back to the (documented) class method.
+ if ([NSWindow instancesRespondToSelector:@selector(frameRectForContentRect:styleMask:)]) {
return [super frameRectForContentRect:aRect styleMask:aMask];
} else {
return [NSWindow frameRectForContentRect:aRect styleMask:aMask];
}
}
- (void)setContentView:(NSView*)aView
{