Commit fd6fd0c8 authored by Malay Keshav's avatar Malay Keshav Committed by Commit Bot

Adjust shelf bounds to cover display edges

This patch adjusts the shelf width such that in pixel space there is no
gap left between the shelf and the edge of the display. The adjustment
is done via a utility method which can be used to adjust any bounds to
ensure that they cover the edge of the display or screen.

Bug: 843354
Change-Id: Ica9adfe6e21e7ae71ef8206e20507a372317c105
Component: Screen util, shelf
Reviewed-on: https://chromium-review.googlesource.com/1154040
Commit-Queue: Malay Keshav <malaykeshav@chromium.org>
Reviewed-by: default avatarMitsuru Oshima <oshima@chromium.org>
Cr-Commit-Position: refs/heads/master@{#579590}
parent b8054333
......@@ -9,6 +9,7 @@
#include "base/logging.h"
#include "ui/aura/client/screen_position_client.h"
#include "ui/aura/window_event_dispatcher.h"
#include "ui/aura/window_tree_host.h"
#include "ui/display/display.h"
#include "ui/display/manager/display_manager.h"
#include "ui/display/screen.h"
......@@ -76,6 +77,40 @@ gfx::Rect GetDisplayBoundsWithShelf(aura::Window* window) {
return gfx::Rect(gfx::ToCeiledSize(size));
}
gfx::Rect SnapBoundsToDisplayEdge(const gfx::Rect& bounds,
const aura::Window* window) {
const aura::WindowTreeHost* host = window->GetHost();
if (!host)
return bounds;
const float dsf = host->device_scale_factor();
const gfx::Rect display_bounds_in_pixel = host->GetBoundsInPixels();
const gfx::Rect display_bounds_in_dip = window->GetRootWindow()->bounds();
const gfx::Rect bounds_in_pixel = gfx::ScaleToEnclosedRect(bounds, dsf);
// Adjusts |bounds| such that the scaled enclosed bounds are atleast as big as
// the scaled enclosing unadjusted bounds.
gfx::Rect snapped_bounds = bounds;
if ((display_bounds_in_dip.width() == bounds.width() &&
bounds_in_pixel.width() != display_bounds_in_pixel.width()) ||
(bounds.right() == display_bounds_in_dip.width() &&
bounds_in_pixel.right() != display_bounds_in_pixel.width())) {
snapped_bounds.Inset(0, 0, -1, 0);
DCHECK_GE(gfx::ScaleToEnclosedRect(snapped_bounds, dsf).right(),
gfx::ScaleToEnclosingRect(bounds, dsf).right());
}
if ((display_bounds_in_dip.height() == bounds.height() &&
bounds_in_pixel.height() != display_bounds_in_pixel.height()) ||
(bounds.bottom() == display_bounds_in_dip.height() &&
bounds_in_pixel.bottom() != display_bounds_in_pixel.height())) {
snapped_bounds.Inset(0, 0, 0, -1);
DCHECK_GE(gfx::ScaleToEnclosedRect(snapped_bounds, dsf).bottom(),
gfx::ScaleToEnclosingRect(bounds, dsf).bottom());
}
return snapped_bounds;
}
} // namespace screen_util
} // namespace ash
......@@ -47,6 +47,15 @@ ASH_EXPORT gfx::Rect GetDisplayWorkAreaBoundsInParentForLockScreen(
// root windows, and only use logical display in display management code.
ASH_EXPORT gfx::Rect GetDisplayBoundsWithShelf(aura::Window* window);
// Returns an adjusted bounds for the given |bounds| by false snapping it to the
// edge of the display in pixel space. It will snap the bounds to the display
// that contains |window|. This will prevent any 1px gaps that you might see at
// the edges of the display. We achieve this by increasing the height and/or the
// width of |bounds| so that in pixel space, they cover the edge of the dispaly.
// |bounds| should be in screen space.
ASH_EXPORT gfx::Rect SnapBoundsToDisplayEdge(const gfx::Rect& bounds,
const aura::Window* window);
} // namespace screen_util
} // namespace ash
......
......@@ -166,4 +166,27 @@ TEST_F(ScreenUtilTest, ShelfDisplayBoundsInUnifiedDesktopGrid) {
screen_util::GetDisplayBoundsWithShelf(window));
}
TEST_F(ScreenUtilTest, SnapBoundsToDisplayEdge) {
UpdateDisplay("2400x1600*1.5");
gfx::Rect bounds(1555, 0, 45, 1066);
views::Widget* widget = views::Widget::CreateWindowWithContextAndBounds(
NULL, CurrentContext(), bounds);
aura::Window* window = widget->GetNativeWindow();
gfx::Rect snapped_bounds =
screen_util::SnapBoundsToDisplayEdge(bounds, window);
EXPECT_EQ(snapped_bounds, gfx::Rect(1555, 0, 45, 1067));
bounds = gfx::Rect(5, 1000, 1595, 66);
snapped_bounds = screen_util::SnapBoundsToDisplayEdge(bounds, window);
EXPECT_EQ(snapped_bounds, gfx::Rect(5, 1000, 1595, 67));
UpdateDisplay("800x600");
bounds = gfx::Rect(0, 552, 800, 48);
snapped_bounds = screen_util::SnapBoundsToDisplayEdge(bounds, window);
EXPECT_EQ(snapped_bounds, gfx::Rect(0, 552, 800, 48));
}
} // namespace ash
......@@ -754,8 +754,10 @@ void ShelfLayoutManager::CalculateTargetBounds(const State& state,
gfx::Point(available_bounds.x(), bottom_shelf_vertical_offset),
gfx::Point(available_bounds.x(), available_bounds.y()),
gfx::Point(available_bounds.right() - shelf_width, available_bounds.y()));
target_bounds->shelf_bounds_in_root =
gfx::Rect(shelf_origin.x(), shelf_origin.y(), shelf_width, shelf_height);
target_bounds->shelf_bounds_in_root = screen_util::SnapBoundsToDisplayEdge(
gfx::Rect(shelf_origin.x(), shelf_origin.y(), shelf_width, shelf_height),
shelf_widget_->GetNativeWindow());
gfx::Size status_size(
shelf_widget_->status_area_widget()->GetWindowBoundsInScreen().size());
......
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