]> khamidou — GitHub mirrors - electron.git/commitdiff
win: Fix calculating window bounds on high DPI display
authorCheng Zhao <zcbenz@gmail.com>
Fri, 12 Dec 2014 17:04:43 +0000 (09:04 -0800)
committerCheng Zhao <zcbenz@gmail.com>
Fri, 12 Dec 2014 17:04:43 +0000 (09:04 -0800)
atom/browser/native_window_views.cc
atom/browser/ui/views/win_frame_view.cc
atom/browser/ui/views/win_frame_view.h

index 9ee492aaa64fdea6958f7db345cdee5683700aed..8825371dc3907856e6945c7535fc73b4a22b1dc6 100644 (file)
@@ -49,6 +49,7 @@
 #include "base/win/scoped_comptr.h"
 #include "base/win/windows_version.h"
 #include "ui/base/win/shell.h"
+#include "ui/gfx/win/dpi.h"
 #include "ui/views/win/hwnd_util.h"
 #endif
 
@@ -837,8 +838,15 @@ void NativeWindowViews::RegisterAccelerators(ui::MenuModel* menu_model) {
 
 gfx::Rect NativeWindowViews::ContentBoundsToWindowBounds(
     const gfx::Rect& bounds) {
+#if defined(OS_WIN)
+  gfx::Rect dpi_bounds = gfx::win::DIPToScreenRect(bounds);
+  gfx::Rect window_bounds = gfx::win::ScreenToDIPRect(
+      window_->non_client_view()->GetWindowBoundsForClientBounds(dpi_bounds));
+#else
   gfx::Rect window_bounds =
       window_->non_client_view()->GetWindowBoundsForClientBounds(bounds);
+#endif
+
   if (menu_bar_ && menu_bar_visible_)
     window_bounds.set_height(window_bounds.height() + kMenuBarHeight);
   return window_bounds;
index e1ef9a018ed547a3321eaeded8cf23fd80092175..db74661932b7d8b8a50d19acf318c40b993e9455 100644 (file)
@@ -27,9 +27,9 @@ WinFrameView::~WinFrameView() {
 
 gfx::Rect WinFrameView::GetWindowBoundsForClientBounds(
     const gfx::Rect& client_bounds) const {
-  gfx::Size size(client_bounds.size());
-  ClientAreaSizeToWindowSize(&size);
-  return gfx::Rect(client_bounds.origin(), size);
+  return views::GetWindowBoundsForClientBounds(
+      static_cast<views::View*>(const_cast<WinFrameView*>(this)),
+      client_bounds);
 }
 
 int WinFrameView::NonClientHitTest(const gfx::Point& point) {
@@ -53,12 +53,4 @@ const char* WinFrameView::GetClassName() const {
   return kViewClassName;
 }
 
-void WinFrameView::ClientAreaSizeToWindowSize(gfx::Size* size) const {
-  // AdjustWindowRect seems to return a wrong window size.
-  gfx::Size window = frame_->GetWindowBoundsInScreen().size();
-  gfx::Size client = frame_->GetClientAreaBoundsInScreen().size();
-  size->set_width(size->width() + window.width() - client.width());
-  size->set_height(size->height() + window.height() - client.height());
-}
-
 }  // namespace atom
index 43bab2c8f430a1b18fb5bb9fb17dda8351a4812b..825677bff31018e912a063390f940c7c539938b3 100644 (file)
@@ -25,8 +25,6 @@ class WinFrameView : public FramelessView {
   const char* GetClassName() const override;
 
  private:
-  void ClientAreaSizeToWindowSize(gfx::Size* size) const;
-
   DISALLOW_COPY_AND_ASSIGN(WinFrameView);
 };