Commit 4157336f authored by Mitsuru Oshima's avatar Mitsuru Oshima Committed by Commit Bot

Make sure that workspace on android side is within chrome's work area.

Bug: 901538
Test: manually tested with squid.
Change-Id: I06cf91e0bbcc5281f2f4caf65dc84b0f1833087c
Reviewed-on: https://chromium-review.googlesource.com/c/1328161Reviewed-by: default avatarDominik Laskowski <domlaskowski@chromium.org>
Commit-Queue: Mitsuru Oshima <oshima@chromium.org>
Cr-Commit-Position: refs/heads/master@{#606756}
parent bcc307a6
...@@ -204,6 +204,50 @@ double GetDefaultDeviceScaleFactor() { ...@@ -204,6 +204,50 @@ double GetDefaultDeviceScaleFactor() {
return WMHelper::GetInstance()->GetDefaultDeviceScaleFactor(); return WMHelper::GetInstance()->GetDefaultDeviceScaleFactor();
} }
// Scale the |child_bounds| in such a way that if it should fill the
// |parent_size|'s width/height, it returns the |parent_size_in_pixel|'s
// width/height.
gfx::Rect ScaleBoundsToPixelSnappedToParent(
const gfx::Size& parent_size_in_pixel,
const gfx::Size& parent_size,
float device_scale_factor,
const gfx::Rect& child_bounds) {
int right = child_bounds.right();
int bottom = child_bounds.bottom();
int new_x = std::round(child_bounds.x() * device_scale_factor);
int new_y = std::round(child_bounds.y() * device_scale_factor);
int new_right = right == parent_size.width()
? parent_size_in_pixel.width()
: std::round(right * device_scale_factor);
int new_bottom = bottom == parent_size.height()
? parent_size_in_pixel.height()
: std::round(bottom * device_scale_factor);
return gfx::Rect(new_x, new_y, new_right - new_x, new_bottom - new_y);
}
// Create the insets make sure that work area will be within the chrome's
// work area when converted to the pixel on client side.
// TODO(oshima): We should send these information in pixel so that
// client do not have to convert it back.
gfx::Insets GetAdjustedInsets(const display::Display& display) {
float scale = display.device_scale_factor();
gfx::Size size_in_pixel = display.GetSizeInPixel();
gfx::Rect work_area_in_display = display.work_area();
work_area_in_display.Offset(-display.bounds().x(), -display.bounds().y());
gfx::Rect work_area_in_pixel = ScaleBoundsToPixelSnappedToParent(
size_in_pixel, display.bounds().size(), scale, work_area_in_display);
gfx::Insets insets_in_pixel =
gfx::Rect(size_in_pixel).InsetsFrom(work_area_in_pixel);
return gfx::Insets(std::ceil(insets_in_pixel.top() / scale),
std::ceil(insets_in_pixel.left() / scale),
std::ceil(insets_in_pixel.bottom() / scale),
std::ceil(insets_in_pixel.right() / scale));
}
// Convert a timestamp to a time value that can be used when interfacing // Convert a timestamp to a time value that can be used when interfacing
// with wayland. Note that we cast a int64_t value to uint32_t which can // with wayland. Note that we cast a int64_t value to uint32_t which can
// potentially overflow. // potentially overflow.
...@@ -2683,7 +2727,7 @@ class WaylandRemoteShell : public ash::TabletModeObserver, ...@@ -2683,7 +2727,7 @@ class WaylandRemoteShell : public ash::TabletModeObserver,
for (const auto& display : screen->GetAllDisplays()) { for (const auto& display : screen->GetAllDisplays()) {
const gfx::Rect& bounds = display.bounds(); const gfx::Rect& bounds = display.bounds();
const gfx::Insets& insets = display.GetWorkAreaInsets(); const gfx::Insets& insets = GetAdjustedInsets(display);
double device_scale_factor = display.device_scale_factor(); double device_scale_factor = display.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