diff --git a/Meta/Lagom/Contrib/MacPDF/MacPDFView.mm b/Meta/Lagom/Contrib/MacPDF/MacPDFView.mm index 42111fd19c..9b9fcc6088 100644 --- a/Meta/Lagom/Contrib/MacPDF/MacPDFView.mm +++ b/Meta/Lagom/Contrib/MacPDF/MacPDFView.mm @@ -66,9 +66,27 @@ static NSBitmapImageRep* ns_from_gfx(NonnullRefPtr bitmap_p) _doc = move(doc); _page_index = 0; + [self addObserver:self + forKeyPath:@"safeAreaRect" + options:NSKeyValueObservingOptionNew + context:nil]; + [self invalidateCachedBitmap]; } +- (void)observeValueForKeyPath:(NSString*)keyPath + ofObject:(id)object + change:(NSDictionary*)change + context:(void*)context +{ + // AppKit by default doesn't invalidate a view if safeAreaRect changes but the view's bounds don't change. + // This happens for example when toggling the visibility of the toolbar with a full-size content view. + // We do want a repaint in this case. + VERIFY([keyPath isEqualToString:@"safeAreaRect"]); + VERIFY(object == self); + [self setNeedsDisplay:YES]; +} + - (void)goToPage:(int)page { if (!_doc) @@ -107,7 +125,7 @@ static NSBitmapImageRep* ns_from_gfx(NonnullRefPtr bitmap_p) if (!_doc || _doc->get_page_count() == 0) return; - NSSize pixel_size = [self convertSizeToBacking:self.bounds.size]; + NSSize pixel_size = [self convertSizeToBacking:self.safeAreaRect.size]; if (NSEqualSizes([_cachedBitmap size], pixel_size)) return; @@ -118,7 +136,7 @@ static NSBitmapImageRep* ns_from_gfx(NonnullRefPtr bitmap_p) - (void)drawRect:(NSRect)rect { [self ensureCachedBitmapIsUpToDate]; - [_cachedBitmap drawInRect:self.bounds]; + [_cachedBitmap drawInRect:self.safeAreaRect]; } #pragma mark - Keyboard handling diff --git a/Meta/Lagom/Contrib/MacPDF/MacPDFWindowController.mm b/Meta/Lagom/Contrib/MacPDF/MacPDFWindowController.mm index 6e54bbed40..1812d17ae4 100644 --- a/Meta/Lagom/Contrib/MacPDF/MacPDFWindowController.mm +++ b/Meta/Lagom/Contrib/MacPDF/MacPDFWindowController.mm @@ -19,7 +19,7 @@ - (instancetype)initWithDocument:(MacPDFDocument*)document { - auto const style_mask = NSWindowStyleMaskTitled | NSWindowStyleMaskClosable | NSWindowStyleMaskMiniaturizable | NSWindowStyleMaskResizable; + auto const style_mask = NSWindowStyleMaskTitled | NSWindowStyleMaskClosable | NSWindowStyleMaskMiniaturizable | NSWindowStyleMaskResizable | NSWindowStyleMaskFullSizeContentView; NSWindow* window = [[NSWindow alloc] initWithContentRect:NSMakeRect(0, 0, 600, 800) styleMask:style_mask backing:NSBackingStoreBuffered @@ -123,7 +123,10 @@ { // NSToolbarToggleSidebarItemIdentifier sends toggleSidebar: along the responder chain, // which NSSplitViewController conveniently implements. - return @[ NSToolbarToggleSidebarItemIdentifier ]; + return @[ + NSToolbarToggleSidebarItemIdentifier, + NSToolbarSidebarTrackingSeparatorItemIdentifier, + ]; } - (NSToolbarItem*)toolbar:(NSToolbar*)toolbar