Skip to content
This repository has been archived by the owner on Jan 4, 2019. It is now read-only.

Commit

Permalink
Properly fix border issues
Browse files Browse the repository at this point in the history
- don't process non-client calcsize/paint
- do proper DPI calculations when DPI > 100%

Auditors: @bbondy, @darkdh

Fixes brave/browser-laptop#6258

Reverts 182fe6d
Which I believe incorrectly fixed the problem with Chromium 53
(see discussion at electron/electron#7416 for more info)

We need to test to confirm, but I believe this change will fix:
brave/browser-laptop#4502
brave/browser-laptop#6462
brave/browser-laptop#6468
brave/browser-laptop#6481
  • Loading branch information
bsclifton committed Jan 12, 2017
1 parent 99dff28 commit 30fd6ff
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 19 deletions.
10 changes: 8 additions & 2 deletions atom/browser/native_window_views.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1168,6 +1168,9 @@ void NativeWindowViews::OnWidgetMove() {

gfx::Rect NativeWindowViews::ContentBoundsToWindowBounds(
const gfx::Rect& bounds) {
if (!has_frame())
return bounds;

gfx::Rect window_bounds(bounds);
#if defined(OS_WIN)
HWND hwnd = GetAcceleratedWidget();
Expand All @@ -1177,7 +1180,7 @@ gfx::Rect NativeWindowViews::ContentBoundsToWindowBounds(
window_->non_client_view()->GetWindowBoundsForClientBounds(dpi_bounds));
#endif

if (has_frame() && menu_bar_ && menu_bar_visible_) {
if (menu_bar_ && menu_bar_visible_) {
window_bounds.set_y(window_bounds.y() - kMenuBarHeight);
window_bounds.set_height(window_bounds.height() + kMenuBarHeight);
}
Expand All @@ -1186,6 +1189,9 @@ gfx::Rect NativeWindowViews::ContentBoundsToWindowBounds(

gfx::Rect NativeWindowViews::WindowBoundsToContentBounds(
const gfx::Rect& bounds) {
if (!has_frame())
return bounds;

gfx::Rect content_bounds(bounds);
#if defined(OS_WIN)
HWND hwnd = GetAcceleratedWidget();
Expand All @@ -1202,7 +1208,7 @@ gfx::Rect NativeWindowViews::WindowBoundsToContentBounds(
display::win::ScreenWin::ScreenToDIPSize(hwnd, content_bounds.size()));
#endif

if (has_frame() && menu_bar_ && menu_bar_visible_) {
if (menu_bar_ && menu_bar_visible_) {
content_bounds.set_y(content_bounds.y() + kMenuBarHeight);
content_bounds.set_height(content_bounds.height() - kMenuBarHeight);
}
Expand Down
12 changes: 12 additions & 0 deletions atom/browser/native_window_views_win.cc
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,18 @@ bool NativeWindowViews::PreHandleMSG(
}
return false;
}
/** Return zero (no-op) for non-client area events when window is frameless.
* \see WM_NCPAINT - https://msdn.microsoft.com/en-us/library/windows/desktop/dd145212(v=vs.85).aspx
* \see WM_NCCALCSIZE - https://msdn.microsoft.com/en-us/library/windows/desktop/ms632634(v=vs.85).aspx
*/
case WM_NCPAINT:
case WM_NCCALCSIZE: {
if (!has_frame()) {
*result = 0;
return true;
}
return false;
}
default:
return false;
}
Expand Down
21 changes: 13 additions & 8 deletions atom/browser/ui/views/menu_layout.cc
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,25 @@

#if defined(OS_WIN)
#include "atom/browser/native_window_views.h"
#include "ui/display/win/screen_win.h"
#endif

namespace atom {

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);
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);

This comment has been minimized.

Copy link
@darkdh

darkdh Jan 13, 2017

Member

👍


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;
}
#endif
Expand All @@ -39,7 +44,7 @@ void MenuLayout::Layout(views::View* host) {
// 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());
gfx::Rect bounds = SubtractBorderSize(host->GetContentsBounds());
host->child_at(0)->SetBoundsRect(bounds);
return;
}
Expand Down
8 changes: 0 additions & 8 deletions atom/browser/ui/win/atom_desktop_window_tree_host_win.cc
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,4 @@ bool AtomDesktopWindowTreeHostWin::PreHandleMSG(
return delegate_->PreHandleMSG(message, w_param, l_param, result);
}

/** Override the client area inset
* Returning true forces a border of 0 for frameless windows
*/
bool AtomDesktopWindowTreeHostWin::GetClientAreaInsets(
gfx::Insets* insets) const {
return !HasFrame();
}

} // namespace atom
1 change: 0 additions & 1 deletion atom/browser/ui/win/atom_desktop_window_tree_host_win.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ class AtomDesktopWindowTreeHostWin : public views::DesktopWindowTreeHostWin {
protected:
bool PreHandleMSG(
UINT message, WPARAM w_param, LPARAM l_param, LRESULT* result) override;
bool GetClientAreaInsets(gfx::Insets* insets) const override;

private:
MessageHandlerDelegate* delegate_; // weak ref
Expand Down

2 comments on commit 30fd6ff

@bridiver
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

++ great job!

@darkdh
Copy link
Member

@darkdh darkdh commented on 30fd6ff Jan 13, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

++

Please sign in to comment.