Add support for BrowserView autoresizing
This commit is contained in:
parent
638eae1080
commit
06fcf2c19d
9 changed files with 121 additions and 4 deletions
|
@ -7,7 +7,7 @@
|
|||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include "atom/browser/native_browser_view.h"
|
||||
#include "atom/browser/native_browser_view_views.h"
|
||||
#include "atom/browser/ui/views/menu_bar.h"
|
||||
#include "atom/browser/window_list.h"
|
||||
#include "atom/common/color_util.h"
|
||||
|
@ -895,7 +895,8 @@ void NativeWindowViews::SetMenu(AtomMenuModel* menu_model) {
|
|||
|
||||
void NativeWindowViews::SetBrowserView(NativeBrowserView* browser_view) {
|
||||
if (browser_view_) {
|
||||
RemoveChildView(browser_view_->GetInspectableWebContentsView()->GetView());
|
||||
web_view_->RemoveChildView(
|
||||
browser_view_->GetInspectableWebContentsView()->GetView());
|
||||
browser_view_ = nullptr;
|
||||
}
|
||||
|
||||
|
@ -903,8 +904,11 @@ void NativeWindowViews::SetBrowserView(NativeBrowserView* browser_view) {
|
|||
return;
|
||||
}
|
||||
|
||||
// Add as child of the main web view to avoid (0, 0) origin from overlapping
|
||||
// with menu bar.
|
||||
browser_view_ = browser_view;
|
||||
AddChildView(browser_view->GetInspectableWebContentsView()->GetView());
|
||||
web_view_->AddChildView(
|
||||
browser_view->GetInspectableWebContentsView()->GetView());
|
||||
}
|
||||
|
||||
void NativeWindowViews::SetParentWindow(NativeWindow* parent) {
|
||||
|
@ -1292,11 +1296,32 @@ 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<NativeBrowserViewViews*>(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() {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue