|
7 | 7 | #include <string> |
8 | 8 | #include <vector> |
9 | 9 |
|
10 | | -#include "atom/browser/native_browser_view.h" |
| 10 | +#include "atom/browser/native_browser_view_views.h" |
11 | 11 | #include "atom/browser/ui/views/menu_bar.h" |
12 | 12 | #include "atom/browser/window_list.h" |
13 | 13 | #include "atom/common/color_util.h" |
@@ -895,16 +895,20 @@ void NativeWindowViews::SetMenu(AtomMenuModel* menu_model) { |
895 | 895 |
|
896 | 896 | void NativeWindowViews::SetBrowserView(NativeBrowserView* browser_view) { |
897 | 897 | if (browser_view_) { |
898 | | - RemoveChildView(browser_view_->GetInspectableWebContentsView()->GetView()); |
| 898 | + web_view_->RemoveChildView( |
| 899 | + browser_view_->GetInspectableWebContentsView()->GetView()); |
899 | 900 | browser_view_ = nullptr; |
900 | 901 | } |
901 | 902 |
|
902 | 903 | if (!browser_view) { |
903 | 904 | return; |
904 | 905 | } |
905 | 906 |
|
| 907 | + // Add as child of the main web view to avoid (0, 0) origin from overlapping |
| 908 | + // with menu bar. |
906 | 909 | browser_view_ = browser_view; |
907 | | - AddChildView(browser_view->GetInspectableWebContentsView()->GetView()); |
| 910 | + web_view_->AddChildView( |
| 911 | + browser_view->GetInspectableWebContentsView()->GetView()); |
908 | 912 | } |
909 | 913 |
|
910 | 914 | void NativeWindowViews::SetParentWindow(NativeWindow* parent) { |
@@ -1292,11 +1296,32 @@ void NativeWindowViews::Layout() { |
1292 | 1296 | menu_bar_->SetBoundsRect(menu_bar_bounds); |
1293 | 1297 | } |
1294 | 1298 |
|
| 1299 | + const auto old_web_view_size = web_view_ ? web_view_->size() : gfx::Size(); |
1295 | 1300 | if (web_view_) { |
1296 | 1301 | web_view_->SetBoundsRect( |
1297 | 1302 | gfx::Rect(0, menu_bar_bounds.height(), size.width(), |
1298 | 1303 | size.height() - menu_bar_bounds.height())); |
1299 | 1304 | } |
| 1305 | + const auto new_web_view_size = web_view_ ? web_view_->size() : gfx::Size(); |
| 1306 | + |
| 1307 | + if (browser_view_) { |
| 1308 | + const auto flags = static_cast<NativeBrowserViewViews*>(browser_view_) |
| 1309 | + ->GetAutoResizeFlags(); |
| 1310 | + int width_delta = 0; |
| 1311 | + int height_delta = 0; |
| 1312 | + if (flags & kAutoResizeWidth) { |
| 1313 | + width_delta = new_web_view_size.width() - old_web_view_size.width(); |
| 1314 | + } |
| 1315 | + if (flags & kAutoResizeHeight) { |
| 1316 | + height_delta = new_web_view_size.height() - old_web_view_size.height(); |
| 1317 | + } |
| 1318 | + |
| 1319 | + auto* view = browser_view_->GetInspectableWebContentsView()->GetView(); |
| 1320 | + auto new_view_size = view->size(); |
| 1321 | + new_view_size.set_width(new_view_size.width() + width_delta); |
| 1322 | + new_view_size.set_height(new_view_size.height() + height_delta); |
| 1323 | + view->SetSize(new_view_size); |
| 1324 | + } |
1300 | 1325 | } |
1301 | 1326 |
|
1302 | 1327 | gfx::Size NativeWindowViews::GetMinimumSize() { |
|
0 commit comments