Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix for issues seen on frameless window (Windows) when at 200% resolution #7416

Merged
merged 1 commit into from
Oct 3, 2016
Merged

Fix for issues seen on frameless window (Windows) when at 200% resolution #7416

merged 1 commit into from
Oct 3, 2016

Conversation

bsclifton
Copy link
Contributor

@bsclifton bsclifton commented Sep 29, 2016

First round of DPI issues we saw on Windows with BrowserWindow => frame:false were reported with #7347 and fixed with #7362

While creating a new release and testing our project with that fix, we ended up seeing more weird behavior on high DPI screens. After more investigation, we realized that the NativeWindowViews class was not calling DIPToScreenRect/ScreenToDIPSize for Frameless windows, which caused several issues (for screenshots / animated gifs, check out brave/browser-laptop#4365)

The symptoms for the original issue were ONLY noticeable / easily reproducible (to my knowledge) by using Windows 10 with the anniversary update (I'm not sure if arch or home vs pro matters- but the issue does not happen unless you have the anniversary update).

Special thanks to @bridiver for finding the issue and @bbondy / @jonathansampson for testing the fix

@zcbenz
Copy link
Contributor

zcbenz commented Oct 3, 2016

👍

@zcbenz zcbenz merged commit bee3abe into electron:master Oct 3, 2016
@zcbenz
Copy link
Contributor

zcbenz commented Oct 3, 2016

When testing this change, I realized this would cause other side effects and I'm now reverting it.

The whole purpose of the DIPToScreenRect/ScreenToDIPSize calls is to calculate the window frame: win32 APIs like AdjustWindowRectEx take pixel size instead of DIP size, so we have to convert the DIP size to pixel size before calling it, and then convert the size back from pixel to DIP after the call. That's why ContentBoundsToWindowBounds and WindowBoundsToContentBounds do nothing for frameless window, because there is no window frame.

The problem with this change is, it calls AdjustWindowRectEx for frameless window, which adds the size of window frame for frameless window, and results in failing tests of content size. I tried to avoid calling AdjustWindowRectEx for frameless window, but it then results in code like this:

gfx::Rect NativeWindowViews::WindowBoundsToContentBounds(const gfx::Rect& bounds) {
  gfx::Rect content_bounds(bounds);
  content_bounds.set_size(
      display::win::ScreenWin::DIPToScreenSize(hwnd, content_bounds.size()));
  content_bounds.set_size(
      display::win::ScreenWin::ScreenToDIPSize(hwnd, content_bounds.size()));
  return content_bounds;
}

which is basically the same with:

gfx::Rect NativeWindowViews::WindowBoundsToContentBounds(const gfx::Rect& bounds) {
  return bounds
}

I don't know the reason of your problem on Windows 10 AU, but this change is fixing it by passing wrong sizes.

@bsclifton
Copy link
Contributor Author

@zcbenz thanks for the info 😄 I'll have to look into this some more. Can you point me at the failing test? I'd like to dig into this some more

cc: @bridiver

@zcbenz
Copy link
Contributor

zcbenz commented Oct 4, 2016

@bsclifton You run ./script/test.py to see the failing tests:

not ok 58 browser-window module BrowserWindow.setContentSize(width, height) works for a frameless window
  AssertionError: 416 == 400
      at Context.<anonymous> (C:\projects\electron\spec\api-browser-window-spec.js:345:14)
      at callFn (C:\projects\electron\spec\node_modules\mocha\lib\runnable.js:251:21)
      at Test.Runnable.run (C:\projects\electron\spec\node_modules\mocha\lib\runnable.js:244:7)
      at Runner.runTest (C:\projects\electron\spec\node_modules\mocha\lib\runner.js:374:10)
      at C:\projects\electron\spec\node_modules\mocha\lib\runner.js:452:12
      at next (C:\projects\electron\spec\node_modules\mocha\lib\runner.js:299:14)
      at C:\projects\electron\spec\node_modules\mocha\lib\runner.js:309:7
      at next (C:\projects\electron\spec\node_modules\mocha\lib\runner.js:248:23)
      at Immediate.<anonymous> (C:\projects\electron\spec\node_modules\mocha\lib\runner.js:276:5)
      at runCallback (timers.js:574:20)
not ok 60 browser-window module BrowserWindow.setContentBounds(bounds) works for a frameless window
  AssertionError: { x: 2, y: -21, width: 266, height: 289 } deepEqual { x: 10, y: 10, width: 250, height: 250 }
      at C:\projects\electron\spec\api-browser-window-spec.js:370:16
      at CallbacksRegistry.apply (C:\projects\electron\out\D\resources\electron.asar\common\api\callbacks-registry.js:54:39)
      at EventEmitter.<anonymous> (C:\projects\electron\out\D\resources\electron.asar\renderer\api\remote.js:282:21)
      at emitThree (events.js:116:13)
      at EventEmitter.emit (events.js:194:7)

@bridiver
Copy link
Contributor

bridiver commented Oct 4, 2016

I believe this was also a problem on surface devices
cc @jonathansampson

@jonathansampson
Copy link

jonathansampson commented Oct 4, 2016

@bridiver It was impacting Surface Books (coincidentally those with the Anniversary Update of Windows?) as they have high-DPI screens, and therefore scale the display up (200% in my case, though 150% and 175% for others) to makeup for the increase in on-screen pixels.

@bsclifton bsclifton deleted the fix-windows-draggable-high-dpi branch October 12, 2016 23:55
@bsclifton
Copy link
Contributor Author

@zcbenz we did find the root cause for this (and other) issues, which @bridiver addressed here brave/browser-laptop@e8bf42e

More details about the issue can be found here:
https://bugs.chromium.org/p/chromium/issues/detail?id=613414

Besides breaking draggability and hit testing, it caused issues for us with regards to scrolling (inside of a guest view though, so regular electron use-cases may not be affected)

bsclifton added a commit to brave/muon that referenced this pull request Jan 12, 2017
- don't process non-client calcsize/paint
- do proper DPI calculations when DPI > 100%

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
bsclifton added a commit to brave/muon that referenced this pull request Jan 12, 2017
- 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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants