From f3f6bedf8ec01331ac0c1432a5d8da1ebbd9c852 Mon Sep 17 00:00:00 2001 From: Birunthan Mohanathas Date: Mon, 17 Jul 2017 21:46:31 +0300 Subject: [PATCH 1/2] Make BrowserView auto-resize relative to window size on Windows/Linux Previously it was relative to the window web contents size, which was not consistent with macOS. --- atom/browser/native_window_views.cc | 40 ++++++++++++++--------------- 1 file changed, 19 insertions(+), 21 deletions(-) diff --git a/atom/browser/native_window_views.cc b/atom/browser/native_window_views.cc index 3b633ab96355..3452323546c4 100644 --- a/atom/browser/native_window_views.cc +++ b/atom/browser/native_window_views.cc @@ -1122,6 +1122,25 @@ void NativeWindowViews::OnWidgetBoundsChanged( return; if (widget_size_ != bounds.size()) { + if (browser_view_) { + const auto flags = static_cast(browser_view_) + ->GetAutoResizeFlags(); + int width_delta = 0; + int height_delta = 0; + if (flags & kAutoResizeWidth) { + width_delta = bounds.width() - widget_size_.width(); + } + if (flags & kAutoResizeHeight) { + height_delta = bounds.height() - widget_size_.height(); + } + + auto* view = browser_view_->GetInspectableWebContentsView()->GetView(); + auto new_view_size = view->size(); + new_view_size.set_width(new_view_size.width() + width_delta); + new_view_size.set_height(new_view_size.height() + height_delta); + view->SetSize(new_view_size); + } + NotifyWindowResize(); widget_size_ = bounds.size(); } @@ -1342,32 +1361,11 @@ void NativeWindowViews::Layout() { menu_bar_->SetBoundsRect(menu_bar_bounds); } - const auto old_web_view_size = web_view_ ? web_view_->size() : gfx::Size(); if (web_view_) { web_view_->SetBoundsRect( gfx::Rect(0, menu_bar_bounds.height(), size.width(), size.height() - menu_bar_bounds.height())); } - const auto new_web_view_size = web_view_ ? web_view_->size() : gfx::Size(); - - if (browser_view_) { - const auto flags = static_cast(browser_view_) - ->GetAutoResizeFlags(); - int width_delta = 0; - int height_delta = 0; - if (flags & kAutoResizeWidth) { - width_delta = new_web_view_size.width() - old_web_view_size.width(); - } - if (flags & kAutoResizeHeight) { - height_delta = new_web_view_size.height() - old_web_view_size.height(); - } - - auto* view = browser_view_->GetInspectableWebContentsView()->GetView(); - auto new_view_size = view->size(); - new_view_size.set_width(new_view_size.width() + width_delta); - new_view_size.set_height(new_view_size.height() + height_delta); - view->SetSize(new_view_size); - } } gfx::Size NativeWindowViews::GetMinimumSize() const { From e1ddd3bdbc28d945d39d30840b34cf329f5eaff5 Mon Sep 17 00:00:00 2001 From: Birunthan Mohanathas Date: Mon, 17 Jul 2017 23:51:42 +0300 Subject: [PATCH 2/2] Stop sending resize event for minimized windows on Windows This makes it consistent with macOS. This also fixes BrowserView auto-resize on Windows when minimizing and restoring the window. Previously it would incorrectly grow too in some cases. --- atom/browser/native_window_views.cc | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/atom/browser/native_window_views.cc b/atom/browser/native_window_views.cc index 3452323546c4..a00943f5549f 100644 --- a/atom/browser/native_window_views.cc +++ b/atom/browser/native_window_views.cc @@ -1121,17 +1121,20 @@ void NativeWindowViews::OnWidgetBoundsChanged( if (widget != window_.get()) return; - if (widget_size_ != bounds.size()) { + // Note: We intentionally use `GetBounds()` instead of `bounds` to properly + // handle minimized windows on Windows. + const auto new_bounds = GetBounds(); + if (widget_size_ != new_bounds.size()) { if (browser_view_) { const auto flags = static_cast(browser_view_) ->GetAutoResizeFlags(); int width_delta = 0; int height_delta = 0; if (flags & kAutoResizeWidth) { - width_delta = bounds.width() - widget_size_.width(); + width_delta = new_bounds.width() - widget_size_.width(); } if (flags & kAutoResizeHeight) { - height_delta = bounds.height() - widget_size_.height(); + height_delta = new_bounds.height() - widget_size_.height(); } auto* view = browser_view_->GetInspectableWebContentsView()->GetView(); @@ -1142,7 +1145,7 @@ void NativeWindowViews::OnWidgetBoundsChanged( } NotifyWindowResize(); - widget_size_ = bounds.size(); + widget_size_ = new_bounds.size(); } }