Commit 3f8166d2 authored by Tim Zheng's avatar Tim Zheng Committed by Commit Bot

Try resize window in proportion to display size.

When moving Crostini app window between displays, try to resize the
window in proportion to the relative size of the displays.

BUG=chromium:843001
TEST=Manual test on an eve device.

Change-Id: Ic72ae35dcc6b1e07da3877aba51d225f96a4fa4d
Reviewed-on: https://chromium-review.googlesource.com/1103609Reviewed-by: default avatarStefan Kuhne <skuhne@chromium.org>
Commit-Queue: Tim Zheng <timzheng@chromium.org>
Cr-Commit-Position: refs/heads/master@{#568990}
parent e0d3e9a7
...@@ -140,15 +140,31 @@ void CrostiniAppWindowShelfController::OnWindowPropertyChanged( ...@@ -140,15 +140,31 @@ void CrostiniAppWindowShelfController::OnWindowPropertyChanged(
crostini_app_display_.GetDisplayIdForStartupId(*startup_id); crostini_app_display_.GetDisplayIdForStartupId(*startup_id);
if (display_id == display::kInvalidDisplayId) if (display_id == display::kInvalidDisplayId)
return; return;
display::Display display;
display::Display new_display;
if (!display::Screen::GetScreen()->GetDisplayWithDisplayId(display_id, if (!display::Screen::GetScreen()->GetDisplayWithDisplayId(display_id,
&display)) &new_display))
return; return;
gfx::Rect bounds = window->bounds(); display::Display old_display =
gfx::Point origin = display.bounds().origin(); display::Screen::GetScreen()->GetDisplayNearestWindow(window);
origin.Offset(bounds.x(), bounds.y());
bounds.set_origin(origin); // Adjust the window size and origin in proportion to the relative size of the
window->SetBoundsInScreen(bounds, display); // display.
int old_width = old_display.bounds().width();
int new_width = new_display.bounds().width();
int old_height = old_display.bounds().height();
int new_height = new_display.bounds().height();
gfx::Rect old_bounds = window->bounds();
gfx::Rect new_bounds(old_bounds.x() * new_width / old_width,
old_bounds.y() * new_height / old_height,
old_bounds.width() * new_width / old_width,
old_bounds.height() * new_height / old_height);
// Transform the bounds in display to that in screen.
gfx::Point new_origin = new_display.bounds().origin();
new_origin.Offset(new_bounds.x(), new_bounds.y());
new_bounds.set_origin(new_origin);
window->SetBoundsInScreen(new_bounds, new_display);
} }
void CrostiniAppWindowShelfController::OnWindowVisibilityChanged( void CrostiniAppWindowShelfController::OnWindowVisibilityChanged(
......
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