Bug 1533562 - Always make the content view of ToolbarWindows cover the entire window. r=spohl

Differential Revision: https://phabricator.services.mozilla.com/D22645

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Markus Stange 2019-04-22 19:26:38 +00:00
Родитель 92aa2412e5
Коммит 8f1414b86c
2 изменённых файлов: 51 добавлений и 63 удалений

Просмотреть файл

@ -59,6 +59,15 @@ typedef struct _nsCocoaWindowList {
- (void)setDrawsContentsIntoWindowFrame:(BOOL)aState;
- (BOOL)drawsContentsIntoWindowFrame;
// Two methods akin to contentRectForFrameRect and frameRectForContentRect,
// which convert between the window's frame rect and the rect that our Gecko
// ChildView would occupy. This is different because we make the window's
// content view always cover the entire window; when drawsContentsIntoWindowFrame
// is NO, the content view is larger than the ChildView because it includes the
// titlebar whereas the ChildView does not.
- (NSRect)childViewRectForFrameRect:(NSRect)aFrameRect;
- (NSRect)frameRectForChildViewRect:(NSRect)aChildViewRect;
- (void)mouseEntered:(NSEvent*)aEvent;
- (void)mouseExited:(NSEvent*)aEvent;
- (void)mouseMoved:(NSEvent*)aEvent;
@ -232,6 +241,7 @@ class nsCocoaWindow final : public nsBaseWidget, public nsPIWidgetCocoa {
virtual void Resize(double aWidth, double aHeight, bool aRepaint) override;
virtual void Resize(double aX, double aY, double aWidth, double aHeight, bool aRepaint) override;
NSRect GetClientCocoaRect();
virtual LayoutDeviceIntRect GetClientBounds() override;
virtual LayoutDeviceIntRect GetScreenBounds() override;
void ReportMoveEvent();

Просмотреть файл

@ -458,7 +458,7 @@ nsresult nsCocoaWindow::CreateNativeWindow(const NSRect& aRect, nsBorderStyle aB
[mWindow setDelegate:mDelegate];
// Make sure that the content rect we gave has been honored.
NSRect wantedFrame = [mWindow frameRectForContentRect:contentRect];
NSRect wantedFrame = [mWindow frameRectForChildViewRect:contentRect];
if (!NSEqualRects([mWindow frame], wantedFrame)) {
// This can happen when the window is not on the primary screen.
[mWindow setFrame:wantedFrame display:NO];
@ -1104,7 +1104,7 @@ void nsCocoaWindow::SetSizeConstraints(const SizeConstraints& aConstraints) {
// Popups can be smaller than (60, 60)
NSRect rect = (mWindowType == eWindowType_popup) ? NSZeroRect : NSMakeRect(0.0, 0.0, 60, 60);
rect = [mWindow frameRectForContentRect:rect];
rect = [mWindow frameRectForChildViewRect:rect];
CGFloat scaleFactor = BackingScaleFactor();
@ -1484,23 +1484,22 @@ void nsCocoaWindow::Resize(double aWidth, double aHeight, bool aRepaint) {
DoResize(mBounds.x * invScale, mBounds.y * invScale, aWidth, aHeight, aRepaint, true);
}
// Return the area that the Gecko ChildView in our window should cover, as an
// NSRect in screen coordinates (with 0,0 being the bottom left corner of the
// primary screen).
NSRect nsCocoaWindow::GetClientCocoaRect() {
if (!mWindow) {
return NSZeroRect;
}
return [mWindow childViewRectForFrameRect:[mWindow frame]];
}
LayoutDeviceIntRect nsCocoaWindow::GetClientBounds() {
NS_OBJC_BEGIN_TRY_ABORT_BLOCK_RETURN;
CGFloat scaleFactor = BackingScaleFactor();
if (!mWindow) {
return nsCocoaUtils::CocoaRectToGeckoRectDevPix(NSZeroRect, scaleFactor);
}
NSRect r;
if ([mWindow isKindOfClass:[ToolbarWindow class]] &&
[(ToolbarWindow*)mWindow drawsContentsIntoWindowFrame]) {
r = [mWindow frame];
} else {
r = [mWindow contentRectForFrameRect:[mWindow frame]];
}
return nsCocoaUtils::CocoaRectToGeckoRectDevPix(r, scaleFactor);
return nsCocoaUtils::CocoaRectToGeckoRectDevPix(GetClientCocoaRect(), scaleFactor);
NS_OBJC_END_TRY_ABORT_BLOCK_RETURN(LayoutDeviceIntRect(0, 0, 0, 0));
}
@ -1856,14 +1855,8 @@ nsresult nsCocoaWindow::SetFocus(bool aState) {
LayoutDeviceIntPoint nsCocoaWindow::WidgetToScreenOffset() {
NS_OBJC_BEGIN_TRY_ABORT_BLOCK_RETURN;
NSRect rect = NSZeroRect;
LayoutDeviceIntRect r;
if (mWindow) {
rect = [mWindow contentRectForFrameRect:[mWindow frame]];
}
r = nsCocoaUtils::CocoaRectToGeckoRectDevPix(rect, BackingScaleFactor());
return r.TopLeft();
return nsCocoaUtils::CocoaRectToGeckoRectDevPix(GetClientCocoaRect(), BackingScaleFactor())
.TopLeft();
NS_OBJC_END_TRY_ABORT_BLOCK_RETURN(LayoutDeviceIntPoint(0, 0));
}
@ -1896,8 +1889,8 @@ LayoutDeviceIntSize nsCocoaWindow::ClientToWindowSize(const LayoutDeviceIntSize&
//
// This is the same thing the windows widget does, but we probably should fix
// that, see bug 1445738.
unsigned int features = [mWindow styleMask];
NSRect inflatedRect = [NSWindow frameRectForContentRect:rect styleMask:features];
NSUInteger styleMask = [mWindow styleMask];
NSRect inflatedRect = [NSWindow frameRectForContentRect:rect styleMask:styleMask];
r = nsCocoaUtils::CocoaRectToGeckoRectDevPix(inflatedRect, backingScale);
return r.Size();
@ -2658,7 +2651,6 @@ static NSMutableSet* gSwizzledFrameViewClasses = nil;
@interface BaseWindow (Private)
- (void)removeTrackingArea;
- (void)cursorUpdated:(NSEvent*)aEvent;
- (void)updateContentViewSize;
- (void)reflowTitlebarElements;
@end
@ -2856,7 +2848,6 @@ static const NSString* kStateCollectionBehavior = @"collectionBehavior";
bool changed = (aState != mDrawsIntoWindowFrame);
mDrawsIntoWindowFrame = aState;
if (changed) {
[self updateContentViewSize];
[self reflowTitlebarElements];
if ([self respondsToSelector:@selector(setTitlebarAppearsTransparent:)]) {
[self setTitlebarAppearsTransparent:mDrawsIntoWindowFrame];
@ -2868,6 +2859,22 @@ static const NSString* kStateCollectionBehavior = @"collectionBehavior";
return mDrawsIntoWindowFrame;
}
- (NSRect)childViewRectForFrameRect:(NSRect)aFrameRect {
if (mDrawsIntoWindowFrame) {
return aFrameRect;
}
NSUInteger styleMask = [self styleMask];
return [NSWindow contentRectForFrameRect:aFrameRect styleMask:styleMask];
}
- (NSRect)frameRectForChildViewRect:(NSRect)aChildViewRect {
if (mDrawsIntoWindowFrame) {
return aChildViewRect;
}
NSUInteger styleMask = [self styleMask];
return [NSWindow frameRectForContentRect:aChildViewRect styleMask:styleMask];
}
- (void)setWantsTitleDrawn:(BOOL)aDrawTitle {
mDrawTitle = aDrawTitle;
if ([self respondsToSelector:@selector(setTitleVisibility:)]) {
@ -2956,11 +2963,6 @@ static const NSString* kStateCollectionBehavior = @"collectionBehavior";
return dirtyRect;
}
- (void)updateContentViewSize {
NSRect rect = [self contentRectForFrameRect:[self frame]];
[[self contentView] setFrameSize:rect.size];
}
// Possibly move the titlebar buttons.
- (void)reflowTitlebarElements {
NSView* frameView = [[self contentView] superview];
@ -2971,43 +2973,19 @@ static const NSString* kStateCollectionBehavior = @"collectionBehavior";
// Override methods that translate between content rect and frame rect.
- (NSRect)contentRectForFrameRect:(NSRect)aRect {
if ([self drawsContentsIntoWindowFrame]) {
return aRect;
}
return [super contentRectForFrameRect:aRect];
return aRect;
}
- (NSRect)contentRectForFrameRect:(NSRect)aRect styleMask:(NSUInteger)aMask {
if ([self drawsContentsIntoWindowFrame]) {
return aRect;
}
// 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];
}
return aRect;
}
- (NSRect)frameRectForContentRect:(NSRect)aRect {
if ([self drawsContentsIntoWindowFrame]) {
return aRect;
}
return [super frameRectForContentRect:aRect];
return aRect;
}
- (NSRect)frameRectForContentRect:(NSRect)aRect styleMask:(NSUInteger)aMask {
if ([self drawsContentsIntoWindowFrame]) {
return aRect;
}
// 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];
}
return aRect;
}
- (void)setContentView:(NSView*)aView {
@ -3179,10 +3157,10 @@ static const NSString* kStateCollectionBehavior = @"collectionBehavior";
- (CGFloat)titlebarHeight {
// We use the original content rect here, not what we return from
// [self contentRectForFrameRect:], because that would give us a
// titlebarHeight of zero in drawsContentsIntoWindowFrame mode.
// titlebarHeight of zero.
NSRect frameRect = [self frame];
NSRect originalContentRect = [NSWindow contentRectForFrameRect:frameRect
styleMask:[self styleMask]];
NSUInteger styleMask = [self styleMask];
NSRect originalContentRect = [NSWindow contentRectForFrameRect:frameRect styleMask:styleMask];
return NSMaxY(frameRect) - NSMaxY(originalContentRect);
}