From: Cheng Zhao Date: Tue, 16 Dec 2014 00:00:16 +0000 (-0800) Subject: win: Reserve border space for maximized frameless window X-Git-Tag: v0.20.1~15 X-Git-Url: http://git.khamidou.com/?a=commitdiff_plain;h=0ab32bfe17c81a03c91f79088e71f6c58b2306fb;p=electron.git win: Reserve border space for maximized frameless window Fixes #732. --- diff --git a/atom/browser/native_window_views.cc b/atom/browser/native_window_views.cc index 69ca7132..2d52cd08 100644 --- a/atom/browser/native_window_views.cc +++ b/atom/browser/native_window_views.cc @@ -221,7 +221,7 @@ NativeWindowViews::NativeWindowViews(content::WebContents* web_contents, #endif // Add web view. - SetLayoutManager(new MenuLayout(kMenuBarHeight)); + SetLayoutManager(new MenuLayout(this, kMenuBarHeight)); set_background(views::Background::CreateStandardPanelBackground()); AddChildView(web_view_); diff --git a/atom/browser/ui/views/menu_layout.cc b/atom/browser/ui/views/menu_layout.cc index ba27e141..8f8e6364 100644 --- a/atom/browser/ui/views/menu_layout.cc +++ b/atom/browser/ui/views/menu_layout.cc @@ -4,16 +4,47 @@ #include "atom/browser/ui/views/menu_layout.h" +#if defined(OS_WIN) +#include "atom/browser/native_window_views.h" +#endif + namespace atom { -MenuLayout::MenuLayout(int menu_height) - : menu_height_(menu_height) { +namespace { + +#if defined(OS_WIN) +gfx::Rect SubstractBorderSize(gfx::Rect bounds) { + int border_width = GetSystemMetrics(SM_CXSIZEFRAME) - 1; + int border_height = GetSystemMetrics(SM_CYSIZEFRAME) - 1; + bounds.set_x(bounds.x() + border_width); + bounds.set_y(bounds.y() + border_height); + bounds.set_width(bounds.width() - 2 * border_width); + bounds.set_height(bounds.height() - 2 * border_height); + return bounds; +} +#endif + +} // namespace + +MenuLayout::MenuLayout(NativeWindowViews* window, int menu_height) + : window_(window), + menu_height_(menu_height) { } MenuLayout::~MenuLayout() { } void MenuLayout::Layout(views::View* host) { +#if defined(OS_WIN) + // Reserve border space for maximized frameless window so we won't have the + // content go outside of screen. + if (!window_->has_frame() && window_->IsMaximized()) { + gfx::Rect bounds = SubstractBorderSize(host->GetContentsBounds()); + host->child_at(0)->SetBoundsRect(bounds); + return; + } +#endif + if (!HasMenu(host)) { views::FillLayout::Layout(host); return; diff --git a/atom/browser/ui/views/menu_layout.h b/atom/browser/ui/views/menu_layout.h index def28214..0a8464a1 100644 --- a/atom/browser/ui/views/menu_layout.h +++ b/atom/browser/ui/views/menu_layout.h @@ -9,9 +9,11 @@ namespace atom { +class NativeWindowViews; + class MenuLayout : public views::FillLayout { public: - explicit MenuLayout(int menu_height); + MenuLayout(NativeWindowViews* window, int menu_height); virtual ~MenuLayout(); // views::LayoutManager: @@ -23,6 +25,7 @@ class MenuLayout : public views::FillLayout { private: bool HasMenu(const views::View* host) const; + NativeWindowViews* window_; int menu_height_; DISALLOW_COPY_AND_ASSIGN(MenuLayout);