Commit e0f9b7e9 authored by Mike Wasserman's avatar Mike Wasserman Committed by Commit Bot

ws: Refine WindowTreeHost::device_scale_factor_ init and add a test

Attempt to init the display device scale factor in WindowTreeHost's ctor.
WindowTreeHost subclasses/users may use the cached scale before InitHost.
See http://crbug.com/899084 and https://crrev.com/c/1311080 (PS7)

This may incorrectly use the primary display's scale for new windows on extended displays.
Still, a best effort attempt to initialize the cached value here may be worthwhile.
It's unclear if this solves any practical defects similar to crbug.com/899084.

Bug: None
Test: Automated
Change-Id: Ia776d870d8a51c5ac381b2a023c7a2a579dca97a
Reviewed-on: https://chromium-review.googlesource.com/c/1318693Reviewed-by: default avatarScott Violet <sky@chromium.org>
Commit-Queue: Michael Wasserman <msw@chromium.org>
Cr-Commit-Position: refs/heads/master@{#605770}
parent 3ac539c8
......@@ -2412,6 +2412,20 @@ TEST_F(WindowTreeClientTestHighDPI, NewTopLevelWindowBounds) {
top_level->GetHost()->GetBoundsInPixels());
}
TEST_F(WindowTreeClientTestHighDPI, HostCtorInitializesDisplayScale) {
// WindowTreeHost's ctor attempts to initialize the display scale factor.
WindowTreeHostMus window_tree_host(
CreateInitParamsForTopLevel(window_tree_client_impl()));
EXPECT_EQ(2.0f, window_tree_host.device_scale_factor());
// This test sets pixel bounds before calling WindowTreeHost::InitHost() to
// simulate circumstances similar to <http://crbug.com/899084>. Pixel bounds
// should still be scaled to DIP bounds for the window tree before InitHost.
gfx::Rect bounds(2, 4, 60, 80);
gfx::Rect pixel_bounds = gfx::ConvertRectToPixel(2.0f, bounds);
window_tree_host.SetBoundsInPixels(pixel_bounds);
EXPECT_EQ(bounds, window_tree()->last_set_window_bounds());
}
TEST_F(WindowTreeClientTestHighDPI, ObservedInputEventsInDip) {
display::Screen* screen = display::Screen::GetScreen();
const display::Display primary_display = screen->GetPrimaryDisplay();
......
......@@ -348,6 +348,8 @@ WindowTreeHost::WindowTreeHost(std::unique_ptr<Window> window)
if (!window_)
window_ = new Window(nullptr);
display::Screen::GetScreen()->AddObserver(this);
auto display = display::Screen::GetScreen()->GetDisplayNearestWindow(window_);
device_scale_factor_ = display.device_scale_factor();
}
void WindowTreeHost::IntializeDeviceScaleFactor(float device_scale_factor) {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment