From d913b53fea1acfa0bce97c06ed101e19f2163da8 Mon Sep 17 00:00:00 2001 From: Felix Rieseberg Date: Thu, 10 Aug 2017 07:58:39 -0700 Subject: [PATCH] :wrench: Handle offset BrowserView --- atom/browser/native_browser_view_mac.mm | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/atom/browser/native_browser_view_mac.mm b/atom/browser/native_browser_view_mac.mm index 589278dbce..9ce98b7233 100644 --- a/atom/browser/native_browser_view_mac.mm +++ b/atom/browser/native_browser_view_mac.mm @@ -144,8 +144,21 @@ void NativeBrowserViewMac::SetBackgroundColor(SkColor color) { void NativeBrowserViewMac::UpdateDraggableRegions( std::vector system_drag_exclude_areas) { NSView* webView = GetInspectableWebContentsView()->GetNativeView(); + + NSInteger superViewHeight = NSHeight([webView.superview bounds]); NSInteger webViewHeight = NSHeight([webView bounds]); NSInteger webViewWidth = NSWidth([webView bounds]); + NSInteger webViewX = NSMinX([webView frame]); + NSInteger webViewY = 0; + + // Apple's NSViews have their coordinate system originate at the bottom left, + // meaning that we need to be a bit smarter when it comes to calculating our + // current top offset + if (webViewHeight > superViewHeight) { + webViewY = std::abs(webViewHeight - superViewHeight - (std::abs(NSMinY([webView frame])))); + } else { + webViewY = superViewHeight - NSMaxY([webView frame]); + } // Remove all DraggableRegionViews that are added last time. // Note that [webView subviews] returns the view's mutable internal array and @@ -171,8 +184,8 @@ void NativeBrowserViewMac::UpdateDraggableRegions( ++iter) { base::scoped_nsobject controlRegion( [[ExcludeDragRegionView alloc] initWithFrame:NSZeroRect]); - [controlRegion setFrame:NSMakeRect(iter->x(), - webViewHeight - iter->bottom(), + [controlRegion setFrame:NSMakeRect(iter->x() - webViewX, + webViewHeight - iter->bottom() + webViewY, iter->width(), iter->height())]; [dragRegion addSubview:controlRegion];