]> khamidou — GitHub mirrors - electron.git/commitdiff
Fix calculating min/max size in frameless views
authorEran Tiktin <eran.t@mce-sys.com>
Sat, 3 Oct 2015 19:09:57 +0000 (22:09 +0300)
committerEran Tiktin <eran.t@mce-sys.com>
Sat, 3 Oct 2015 19:09:57 +0000 (22:09 +0300)
The minimum and maximum size that frameless windows had used, was
incorrect. It included the border, so when it was called it actually
added that to the size, so window increased in size. The fix makes sure
that the view will use the frameless size.

This fixes #2945 and partially fixes #1806 (it also refers to some other
issues with hidpi which might still exist).

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

index e9db97e195d15ab43ece6c56347f180ee7a2ef1d..40d702e35aa428304691e54de83bdfa8d8090af6 100644 (file)
@@ -818,9 +818,7 @@ bool NativeWindowViews::ExecuteWindowsCommand(int command_id) {
   NotifyWindowExecuteWindowsCommand(command);
   return false;
 }
-#endif
 
-#if defined(OS_WIN)
 bool NativeWindowViews::PreHandleMSG(
     UINT message, WPARAM w_param, LPARAM l_param, LRESULT* result) {
   switch (message) {
@@ -874,6 +872,33 @@ void NativeWindowViews::HandleSizeEvent(WPARAM w_param, LPARAM l_param) {
 }
 #endif
 
+gfx::Size NativeWindowViews::WindowSizeToFramelessSize(
+    const gfx::Size& size) {
+  if (size.width() == 0 && size.height() == 0)
+    return size;
+
+  gfx::Rect window_bounds = gfx::Rect(size);
+  if (use_content_size_) {
+    if (menu_bar_ && menu_bar_visible_) {
+      window_bounds.set_height(window_bounds.height() + kMenuBarHeight);
+    }
+  } else if (has_frame()) {
+#if defined(OS_WIN)
+  gfx::Size frame_size = gfx::win::ScreenToDIPRect(
+      window_->non_client_view()->GetWindowBoundsForClientBounds(
+          gfx::Rect())).size();
+#else
+  gfx::Size frame_size =
+      window_->non_client_view()->GetWindowBoundsForClientBounds(
+          gfx::Rect()).size();
+#endif
+    window_bounds.set_height(window_bounds.height() - frame_size.height());
+    window_bounds.set_width(window_bounds.width() - frame_size.width());
+  }
+
+  return window_bounds.size();
+}
+
 void NativeWindowViews::HandleKeyboardEvent(
     content::WebContents*,
     const content::NativeWebKeyboardEvent& event) {
index 71e122d3814f10c04913f26e67d424839309aaee..790e532f84a02aa91a7e3314ef86d8ecaf798ecc 100644 (file)
@@ -94,6 +94,8 @@ class NativeWindowViews : public NativeWindow,
 
   gfx::AcceleratedWidget GetAcceleratedWidget();
 
+  gfx::Size WindowSizeToFramelessSize(const gfx::Size& size);
+
   views::Widget* widget() const { return window_.get(); }
 
 #if defined(OS_WIN)
index 03a31e0828742b9bd0f76dfe34344c616c10a714..e8d351ec82815a2428cca70ac37091efb9c3f836 100644 (file)
@@ -104,11 +104,15 @@ gfx::Size FramelessView::GetPreferredSize() const {
 }
 
 gfx::Size FramelessView::GetMinimumSize() const {
-  return window_->GetMinimumSize();
+  gfx::Size size = window_->WindowSizeToFramelessSize(
+      window_->GetMinimumSize());
+  return size;
 }
 
 gfx::Size FramelessView::GetMaximumSize() const {
-  return window_->GetMaximumSize();
+  gfx::Size size = window_->WindowSizeToFramelessSize(
+      window_->GetMaximumSize());
+  return size;
 }
 
 const char* FramelessView::GetClassName() const {