From 7842d19989a852aa50948dac55c0892ca6aec01e Mon Sep 17 00:00:00 2001 From: Shelley Vohr Date: Thu, 6 Jul 2023 09:50:08 +0200 Subject: [PATCH] revert: compensate for title bar height when setting bounds on `BrowserView` (#38981) This reverts commit 75f9573e53338e15af7c7ccd07a529332847ea2c. --- shell/browser/native_browser_view_mac.mm | 39 +++++------------------- spec/api-browser-view-spec.ts | 9 +----- 2 files changed, 9 insertions(+), 39 deletions(-) diff --git a/shell/browser/native_browser_view_mac.mm b/shell/browser/native_browser_view_mac.mm index 63cc06463f327..14cc582d90db9 100644 --- a/shell/browser/native_browser_view_mac.mm +++ b/shell/browser/native_browser_view_mac.mm @@ -58,21 +58,9 @@ auto* view = iwc_view->GetNativeView().GetNativeNSView(); auto* superview = view.superview; const auto superview_height = superview ? superview.frame.size.height : 0; - - // We need to use the content rect to calculate the titlebar height if the - // superview is an framed NSWindow, otherwise it will be offset incorrectly by - // the height of the titlebar. - auto titlebar_height = 0; - if (auto* win = [superview window]) { - const auto content_rect_height = - [win contentRectForFrameRect:superview.frame].size.height; - titlebar_height = superview_height - content_rect_height; - } - - auto new_height = - superview_height - bounds.y() - bounds.height() + titlebar_height; view.frame = - NSMakeRect(bounds.x(), new_height, bounds.width(), bounds.height()); + NSMakeRect(bounds.x(), superview_height - bounds.y() - bounds.height(), + bounds.width(), bounds.height()); } gfx::Rect NativeBrowserViewMac::GetBounds() { @@ -80,23 +68,12 @@ if (!iwc_view) return gfx::Rect(); NSView* view = iwc_view->GetNativeView().GetNativeNSView(); - auto* superview = view.superview; - const int superview_height = superview ? superview.frame.size.height : 0; - - // We need to use the content rect to calculate the titlebar height if the - // superview is an framed NSWindow, otherwise it will be offset incorrectly by - // the height of the titlebar. - auto titlebar_height = 0; - if (auto* win = [superview window]) { - const auto content_rect_height = - [win contentRectForFrameRect:superview.frame].size.height; - titlebar_height = superview_height - content_rect_height; - } - - auto new_height = superview_height - view.frame.origin.y - - view.frame.size.height + titlebar_height; - return gfx::Rect(view.frame.origin.x, new_height, view.frame.size.width, - view.frame.size.height); + const int superview_height = + (view.superview) ? view.superview.frame.size.height : 0; + return gfx::Rect( + view.frame.origin.x, + superview_height - view.frame.origin.y - view.frame.size.height, + view.frame.size.width, view.frame.size.height); } void NativeBrowserViewMac::SetBackgroundColor(SkColor color) { diff --git a/spec/api-browser-view-spec.ts b/spec/api-browser-view-spec.ts index 80bb56478d419..80e26e21d7307 100644 --- a/spec/api-browser-view-spec.ts +++ b/spec/api-browser-view-spec.ts @@ -146,14 +146,7 @@ describe('BrowserView module', () => { }); describe('BrowserView.getBounds()', () => { - it('returns correct bounds on a framed window', () => { - view = new BrowserView(); - const bounds = { x: 10, y: 20, width: 30, height: 40 }; - view.setBounds(bounds); - expect(view.getBounds()).to.deep.equal(bounds); - }); - - it('returns correct bounds on a frameless window', () => { + it('returns the current bounds', () => { view = new BrowserView(); const bounds = { x: 10, y: 20, width: 30, height: 40 }; view.setBounds(bounds);