Remove MenuLayout in favor of NativeWindowViews::Layout

This commit is contained in:
Birunthan Mohanathas 2017-04-12 14:00:00 +03:00
parent 8b9f7e5b00
commit 638eae1080
5 changed files with 40 additions and 133 deletions

View file

@ -9,7 +9,6 @@
#include "atom/browser/native_browser_view.h"
#include "atom/browser/ui/views/menu_bar.h"
#include "atom/browser/ui/views/menu_layout.h"
#include "atom/browser/window_list.h"
#include "atom/common/color_util.h"
#include "atom/common/draggable_region.h"
@ -71,6 +70,20 @@ const int kMenuBarHeight = 25;
#endif
#if defined(OS_WIN)
gfx::Rect SubtractBorderSize(gfx::Rect bounds) {
gfx::Point borderSize = gfx::Point(
GetSystemMetrics(SM_CXSIZEFRAME) - 1, // width
GetSystemMetrics(SM_CYSIZEFRAME) - 1); // height
gfx::Point dpiAdjustedSize =
display::win::ScreenWin::ScreenToDIPPoint(borderSize);
bounds.set_x(bounds.x() + dpiAdjustedSize.x());
bounds.set_y(bounds.y() + dpiAdjustedSize.y());
bounds.set_width(bounds.width() - 2 * dpiAdjustedSize.x());
bounds.set_height(bounds.height() - 2 * dpiAdjustedSize.y());
return bounds;
}
void FlipWindowStyle(HWND handle, bool on, DWORD flag) {
DWORD style = ::GetWindowLong(handle, GWL_STYLE);
if (on)
@ -276,9 +289,6 @@ NativeWindowViews::NativeWindowViews(
SetWindowType(GetAcceleratedWidget(), window_type);
#endif
// Add web view.
SetLayoutManager(new MenuLayout(this, kMenuBarHeight));
AddChildView(web_view_);
#if defined(OS_WIN)
@ -1264,6 +1274,31 @@ void NativeWindowViews::HandleKeyboardEvent(
}
}
void NativeWindowViews::Layout() {
#if defined(OS_WIN)
// Reserve border space for maximized frameless window so we won't have the
// content go outside of screen.
if (!has_frame() && IsMaximized()) {
gfx::Rect bounds = SubtractBorderSize(GetContentsBounds());
web_view_->SetBoundsRect(bounds);
return;
}
#endif
const auto size = GetContentsBounds().size();
const auto menu_bar_bounds =
menu_bar_ ? gfx::Rect(0, 0, size.width(), kMenuBarHeight) : gfx::Rect();
if (menu_bar_) {
menu_bar_->SetBoundsRect(menu_bar_bounds);
}
if (web_view_) {
web_view_->SetBoundsRect(
gfx::Rect(0, menu_bar_bounds.height(), size.width(),
size.height() - menu_bar_bounds.height()));
}
}
gfx::Size NativeWindowViews::GetMinimumSize() {
return NativeWindow::GetMinimumSize();
}