Skip to content
This repository has been archived by the owner on Aug 4, 2022. It is now read-only.

Commit

Permalink
Bug 1533562 - Always make the content view of ToolbarWindows cover th…
Browse files Browse the repository at this point in the history
…e entire window. r=spohl

Differential Revision: https://phabricator.services.mozilla.com/D22645
  • Loading branch information
mstange committed Apr 26, 2019
1 parent c19810f commit 2379bf0
Show file tree
Hide file tree
Showing 2 changed files with 67 additions and 66 deletions.
11 changes: 11 additions & 0 deletions widget/cocoa/nsCocoaWindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,16 @@ typedef struct _nsCocoaWindowList {
- (void)setDrawsContentsIntoWindowFrame:(BOOL)aState;
- (BOOL)drawsContentsIntoWindowFrame;

// These two methods are like contentRectForFrameRect and frameRectForContentRect,
// but they deal with the rect of the window's "main ChildView" instead of the
// rect of the window's content view. The two are sometimes sized differently: The
// window's content view always covers the entire window, whereas the ChildView
// only covers the full window when drawsContentsIntoWindowFrame is YES. When
// drawsContentsIntoWindowFrame is NO, there's a titlebar-sized gap above the
// ChildView within the content view.
- (NSRect)childViewRectForFrameRect:(NSRect)aFrameRect;
- (NSRect)frameRectForChildViewRect:(NSRect)aChildViewRect;

- (void)mouseEntered:(NSEvent*)aEvent;
- (void)mouseExited:(NSEvent*)aEvent;
- (void)mouseMoved:(NSEvent*)aEvent;
Expand Down Expand Up @@ -232,6 +242,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();
Expand Down
122 changes: 56 additions & 66 deletions widget/cocoa/nsCocoaWindow.mm
Original file line number Diff line number Diff line change
Expand Up @@ -458,7 +458,7 @@ static unsigned int WindowMaskForBorderStyle(nsBorderStyle aBorderStyle) {
[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];
Expand Down Expand Up @@ -1104,7 +1104,7 @@ static unsigned int WindowMaskForBorderStyle(nsBorderStyle aBorderStyle) {

// 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();

Expand Down Expand Up @@ -1484,23 +1484,22 @@ DesktopIntRect newBounds(NSToIntRound(aX), NSToIntRound(aY), NSToIntRound(width
DoResize(mBounds.x * invScale, mBounds.y * invScale, aWidth, aHeight, aRepaint, true);
}

LayoutDeviceIntRect nsCocoaWindow::GetClientBounds() {
NS_OBJC_BEGIN_TRY_ABORT_BLOCK_RETURN;

CGFloat scaleFactor = BackingScaleFactor();
// 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 nsCocoaUtils::CocoaRectToGeckoRectDevPix(NSZeroRect, scaleFactor);
return NSZeroRect;
}

NSRect r;
if ([mWindow isKindOfClass:[ToolbarWindow class]] &&
[(ToolbarWindow*)mWindow drawsContentsIntoWindowFrame]) {
r = [mWindow frame];
} else {
r = [mWindow contentRectForFrameRect:[mWindow frame]];
}
return [mWindow childViewRectForFrameRect:[mWindow frame]];
}

return nsCocoaUtils::CocoaRectToGeckoRectDevPix(r, scaleFactor);
LayoutDeviceIntRect nsCocoaWindow::GetClientBounds() {
NS_OBJC_BEGIN_TRY_ABORT_BLOCK_RETURN;

CGFloat scaleFactor = BackingScaleFactor();
return nsCocoaUtils::CocoaRectToGeckoRectDevPix(GetClientCocoaRect(), scaleFactor);

NS_OBJC_END_TRY_ABORT_BLOCK_RETURN(LayoutDeviceIntRect(0, 0, 0, 0));
}
Expand Down Expand Up @@ -1856,14 +1855,8 @@ static nsSizeMode GetWindowSizeMode(NSWindow* aWindow, bool aFullScreen) {
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));
}
Expand Down Expand Up @@ -1896,8 +1889,8 @@ static nsSizeMode GetWindowSizeMode(NSWindow* aWindow, bool aFullScreen) {
//
// 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();

Expand Down Expand Up @@ -2658,7 +2651,6 @@ - (void)setMaskImage:(NSImage*)image;
@interface BaseWindow (Private)
- (void)removeTrackingArea;
- (void)cursorUpdated:(NSEvent*)aEvent;
- (void)updateContentViewSize;
- (void)reflowTitlebarElements;
@end

Expand Down Expand Up @@ -2856,7 +2848,6 @@ - (void)setDrawsContentsIntoWindowFrame:(BOOL)aState {
bool changed = (aState != mDrawsIntoWindowFrame);
mDrawsIntoWindowFrame = aState;
if (changed) {
[self updateContentViewSize];
[self reflowTitlebarElements];
if ([self respondsToSelector:@selector(setTitlebarAppearsTransparent:)]) {
[self setTitlebarAppearsTransparent:mDrawsIntoWindowFrame];
Expand All @@ -2868,6 +2859,22 @@ - (BOOL)drawsContentsIntoWindowFrame {
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:)]) {
Expand Down Expand Up @@ -2956,11 +2963,6 @@ - (NSRect)getAndResetNativeDirtyRect {
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];
Expand All @@ -2971,43 +2973,19 @@ - (void)reflowTitlebarElements {

// 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 {
Expand Down Expand Up @@ -3135,18 +3113,30 @@ - (void)releaseJSObjects {
// background will reach the screen.
@implementation ToolbarWindow

- (id)initWithContentRect:(NSRect)aContentRect
- (id)initWithContentRect:(NSRect)aChildViewRect
styleMask:(NSUInteger)aStyle
backing:(NSBackingStoreType)aBufferingType
defer:(BOOL)aFlag {
NS_OBJC_BEGIN_TRY_ABORT_BLOCK_NIL;

if ((self = [super initWithContentRect:aContentRect
// We treat aChildViewRect as the rectangle that the window's main ChildView
// should be sized to. Get the right frameRect for the requested child view
// rect.
NSRect frameRect = [NSWindow frameRectForContentRect:aChildViewRect styleMask:aStyle];

// -[NSWindow initWithContentRect:styleMask:backing:defer:] calls
// [self frameRectForContentRect:styleMask:] to convert the supplied content
// rect to the window's frame rect. We've overridden that method to be a
// pass-through function. So, in order to get the intended frameRect, we need
// to supply frameRect itself as the "content rect".
NSRect contentRect = frameRect;

if ((self = [super initWithContentRect:contentRect
styleMask:aStyle
backing:aBufferingType
defer:aFlag])) {
mUnifiedToolbarHeight = 22.0f;
mSheetAttachmentPosition = aContentRect.size.height;
mSheetAttachmentPosition = aChildViewRect.size.height;
mWindowButtonsRect = NSZeroRect;
mFullScreenButtonRect = NSZeroRect;
}
Expand Down Expand Up @@ -3179,10 +3169,10 @@ - (CGFloat)unifiedToolbarHeight {
- (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);
}

Expand Down

0 comments on commit 2379bf0

Please sign in to comment.