]> khamidou — GitHub mirrors - electron.git/commitdiff
win: Reserve border space for maximized frameless window
authorCheng Zhao <zcbenz@gmail.com>
Tue, 16 Dec 2014 00:00:16 +0000 (16:00 -0800)
committerCheng Zhao <zcbenz@gmail.com>
Tue, 16 Dec 2014 00:01:11 +0000 (16:01 -0800)
Fixes #732.

atom/browser/native_window_views.cc
atom/browser/ui/views/menu_layout.cc
atom/browser/ui/views/menu_layout.h

index 69ca71325cba60413ce76bd00cdebe36e874eb9c..2d52cd0838526931886a443ffe003a91915ad361 100644 (file)
@@ -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_);
 
index ba27e141cd064976306cb64c82cf7a22c996102f..8f8e636472ca663d49de51fcf922777fc6308fd5 100644 (file)
@@ -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;
index def28214ea99761ffc03f6d6d5320889e5d496dd..0a8464a1d44a321d85c6a655214381881ee89ea7 100644 (file)
@@ -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);