Skip to content

Commit

Permalink
Auto snapping of ui Layers to physical pixel boundaries
Browse files Browse the repository at this point in the history
This patch makes changes to ui Layers in the way they handle snapping to
physical pixel boundaries. Historically, the clients of ui Layers had to
manually snap a layer to a target layer. This patch modifies it so that
ui Layers internally snap to their parent layer's pixel boundary. Doing
so frees up the clients from performing the snap manually. The API to
set an external snap offset is still available however since some layer
delegates (like views::View) want to manage the snapping manually.

The patch also removes the snapping for transforms that are applied to
layers. To consider layer transform scale for snapping it would be better
to use cc::Layer::IsSnappedToPixelGridInTarget() rather than handling it
in ui::Layer.

Bug: 863268
TEST: Manually tested on chrome os and linux
Change-Id: Iae7727f1ee4f781b26ae78ac721976b7e5160f3e
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1674745
Reviewed-by: Scott Violet <sky@chromium.org>
Reviewed-by: Mitsuru Oshima <oshima@chromium.org>
Commit-Queue: Malay Keshav <malaykeshav@chromium.org>
Cr-Commit-Position: refs/heads/master@{#673084}
  • Loading branch information
Malay Keshav authored and Commit Bot committed Jun 27, 2019
1 parent fd3d8ca commit ebd73ca
Show file tree
Hide file tree
Showing 42 changed files with 230 additions and 478 deletions.
4 changes: 2 additions & 2 deletions ash/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -1234,11 +1234,11 @@ component("ash") {
"wm/window_transient_descendant_iterator.cc",
"wm/window_transient_descendant_iterator.h",
"wm/window_util.cc",
"wm/wm_default_layout_manager.cc",
"wm/wm_default_layout_manager.h",
"wm/wm_event.cc",
"wm/wm_shadow_controller_delegate.cc",
"wm/wm_shadow_controller_delegate.h",
"wm/wm_snap_to_pixel_layout_manager.cc",
"wm/wm_snap_to_pixel_layout_manager.h",
"wm/wm_window_animations.cc",
"wm/wm_window_animations.h",
"wm/work_area_insets.cc",
Expand Down
4 changes: 1 addition & 3 deletions ash/accelerators/debug_commands.cc
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ void PrintWindowHierarchy(const aura::Window* active_window,
if (name.empty())
name = "\"\"";
const gfx::Vector2dF& subpixel_position_offset =
window->layer()->subpixel_position_offset();
window->layer()->GetSubpixelOffset();
*out << indent_str;
*out << name << " (" << window << ")"
<< " type=" << window->type();
Expand All @@ -80,8 +80,6 @@ void PrintWindowHierarchy(const aura::Window* active_window,
? aura::Window::OcclusionStateToString(window->occlusion_state())
: "")
<< " " << window->bounds().ToString();
if (window->GetProperty(::wm::kSnapChildrenToPixelBoundary))
*out << " [snapped]";
if (!subpixel_position_offset.IsZero())
*out << " subpixel offset=" + subpixel_position_offset.ToString();
std::string* tree_id = window->GetProperty(ui::kChildAXTreeID);
Expand Down
25 changes: 1 addition & 24 deletions ash/root_window_controller.cc
Original file line number Diff line number Diff line change
Expand Up @@ -870,7 +870,7 @@ void RootWindowController::InitLayoutManagers() {
always_on_top_controller_ = std::make_unique<AlwaysOnTopController>(
always_on_top_container, pip_container);

wm::WmSnapToPixelLayoutManager::InstallOnContainers(root);
wm::WmDefaultLayoutManager::InstallOnContainers(root);

// Make it easier to resize windows that partially overlap the shelf. Must
// occur after the ShelfLayoutManager is constructed by ShelfWidget.
Expand Down Expand Up @@ -940,7 +940,6 @@ void RootWindowController::CreateContainers() {
aura::Window* app_list_tablet_mode_container =
CreateContainer(kShellWindowId_HomeScreenContainer, "HomeScreenContainer",
non_lock_screen_containers);
wm::SetSnapsChildrenToPhysicalPixelBoundary(app_list_tablet_mode_container);
app_list_tablet_mode_container->SetProperty(::wm::kUsesScreenCoordinatesKey,
true);

Expand All @@ -951,7 +950,6 @@ void RootWindowController::CreateContainers() {
aura::Window* container = CreateContainer(
id, desks_util::GetDeskContainerName(id), non_lock_screen_containers);
::wm::SetChildWindowVisibilityChangesAnimated(container);
wm::SetSnapsChildrenToPhysicalPixelBoundary(container);
container->SetProperty(::wm::kUsesScreenCoordinatesKey, true);
wm::SetChildrenUseExtendedHitRegionForWindow(container);

Expand All @@ -964,96 +962,82 @@ void RootWindowController::CreateContainers() {
CreateContainer(kShellWindowId_AlwaysOnTopContainer,
"AlwaysOnTopContainer", non_lock_screen_containers);
::wm::SetChildWindowVisibilityChangesAnimated(always_on_top_container);
wm::SetSnapsChildrenToPhysicalPixelBoundary(always_on_top_container);
always_on_top_container->SetProperty(::wm::kUsesScreenCoordinatesKey, true);

aura::Window* app_list_container =
CreateContainer(kShellWindowId_AppListContainer, "AppListContainer",
non_lock_screen_containers);
wm::SetSnapsChildrenToPhysicalPixelBoundary(app_list_container);
app_list_container->SetProperty(::wm::kUsesScreenCoordinatesKey, true);

aura::Window* pip_container = CreateContainer(
kShellWindowId_PipContainer, "PipContainer", non_lock_screen_containers);
::wm::SetChildWindowVisibilityChangesAnimated(pip_container);
wm::SetSnapsChildrenToPhysicalPixelBoundary(pip_container);
pip_container->SetProperty(::wm::kUsesScreenCoordinatesKey, true);

aura::Window* arc_ime_parent_container = CreateContainer(
kShellWindowId_ArcImeWindowParentContainer, "ArcImeWindowParentContainer",
non_lock_screen_containers);
wm::SetSnapsChildrenToPhysicalPixelBoundary(arc_ime_parent_container);
arc_ime_parent_container->SetProperty(::wm::kUsesScreenCoordinatesKey, true);
arc_ime_parent_container->SetLayoutManager(
new ArcVirtualKeyboardContainerLayoutManager(arc_ime_parent_container));
aura::Window* arc_vk_container =
CreateContainer(kShellWindowId_ArcVirtualKeyboardContainer,
"ArcVirtualKeyboardContainer", arc_ime_parent_container);
wm::SetSnapsChildrenToPhysicalPixelBoundary(arc_vk_container);
arc_vk_container->SetProperty(::wm::kUsesScreenCoordinatesKey, true);

aura::Window* shelf_container_parent = lock_screen_related_containers;
aura::Window* shelf_container = CreateContainer(
kShellWindowId_ShelfContainer, "ShelfContainer", shelf_container_parent);
wm::SetSnapsChildrenToPhysicalPixelBoundary(shelf_container);
shelf_container->SetProperty(::wm::kUsesScreenCoordinatesKey, true);
shelf_container->SetProperty(kLockedToRootKey, true);

aura::Window* shelf_bubble_container =
CreateContainer(kShellWindowId_ShelfBubbleContainer,
"ShelfBubbleContainer", non_lock_screen_containers);
wm::SetSnapsChildrenToPhysicalPixelBoundary(shelf_bubble_container);
shelf_bubble_container->SetProperty(::wm::kUsesScreenCoordinatesKey, true);
shelf_bubble_container->SetProperty(kLockedToRootKey, true);

aura::Window* modal_container =
CreateContainer(kShellWindowId_SystemModalContainer,
"SystemModalContainer", non_lock_screen_containers);
wm::SetSnapsChildrenToPhysicalPixelBoundary(modal_container);
::wm::SetChildWindowVisibilityChangesAnimated(modal_container);
modal_container->SetProperty(::wm::kUsesScreenCoordinatesKey, true);
wm::SetChildrenUseExtendedHitRegionForWindow(modal_container);

aura::Window* lock_container =
CreateContainer(kShellWindowId_LockScreenContainer, "LockScreenContainer",
lock_screen_containers);
wm::SetSnapsChildrenToPhysicalPixelBoundary(lock_container);
lock_container->SetProperty(::wm::kUsesScreenCoordinatesKey, true);

aura::Window* lock_action_handler_container =
CreateContainer(kShellWindowId_LockActionHandlerContainer,
"LockActionHandlerContainer", lock_screen_containers);
wm::SetSnapsChildrenToPhysicalPixelBoundary(lock_action_handler_container);
::wm::SetChildWindowVisibilityChangesAnimated(lock_action_handler_container);
lock_action_handler_container->SetProperty(::wm::kUsesScreenCoordinatesKey,
true);

aura::Window* lock_modal_container =
CreateContainer(kShellWindowId_LockSystemModalContainer,
"LockSystemModalContainer", lock_screen_containers);
wm::SetSnapsChildrenToPhysicalPixelBoundary(lock_modal_container);
::wm::SetChildWindowVisibilityChangesAnimated(lock_modal_container);
lock_modal_container->SetProperty(::wm::kUsesScreenCoordinatesKey, true);
wm::SetChildrenUseExtendedHitRegionForWindow(lock_modal_container);

aura::Window* status_container =
CreateContainer(kShellWindowId_StatusContainer, "StatusContainer",
lock_screen_related_containers);
wm::SetSnapsChildrenToPhysicalPixelBoundary(status_container);
status_container->SetProperty(::wm::kUsesScreenCoordinatesKey, true);
status_container->SetProperty(kLockedToRootKey, true);

aura::Window* power_menu_container =
CreateContainer(kShellWindowId_PowerMenuContainer, "PowerMenuContainer",
lock_screen_related_containers);
wm::SetSnapsChildrenToPhysicalPixelBoundary(power_menu_container);
power_menu_container->SetProperty(::wm::kUsesScreenCoordinatesKey, true);

aura::Window* settings_bubble_container =
CreateContainer(kShellWindowId_SettingBubbleContainer,
"SettingBubbleContainer", lock_screen_related_containers);
::wm::SetChildWindowVisibilityChangesAnimated(settings_bubble_container);
wm::SetSnapsChildrenToPhysicalPixelBoundary(settings_bubble_container);
settings_bubble_container->SetProperty(::wm::kUsesScreenCoordinatesKey, true);
settings_bubble_container->SetProperty(kLockedToRootKey, true);

Expand All @@ -1070,8 +1054,6 @@ void RootWindowController::CreateContainers() {
aura::Window* virtual_keyboard_parent_container = CreateContainer(
kShellWindowId_ImeWindowParentContainer, "ImeWindowParentContainer",
lock_screen_related_containers);
wm::SetSnapsChildrenToPhysicalPixelBoundary(
virtual_keyboard_parent_container);
virtual_keyboard_parent_container->SetProperty(
::wm::kUsesScreenCoordinatesKey, true);
virtual_keyboard_parent_container->SetLayoutManager(
Expand All @@ -1080,7 +1062,6 @@ void RootWindowController::CreateContainers() {
aura::Window* virtual_keyboard_container = CreateContainer(
kShellWindowId_VirtualKeyboardContainer, "VirtualKeyboardContainer",
virtual_keyboard_parent_container);
wm::SetSnapsChildrenToPhysicalPixelBoundary(virtual_keyboard_container);
virtual_keyboard_container->SetProperty(::wm::kUsesScreenCoordinatesKey,
true);
virtual_keyboard_container->SetLayoutManager(
Expand All @@ -1090,26 +1071,22 @@ void RootWindowController::CreateContainers() {
CreateContainer(kShellWindowId_MenuContainer, "MenuContainer",
lock_screen_related_containers);
::wm::SetChildWindowVisibilityChangesAnimated(menu_container);
wm::SetSnapsChildrenToPhysicalPixelBoundary(menu_container);
menu_container->SetProperty(::wm::kUsesScreenCoordinatesKey, true);

aura::Window* autoclick_container = CreateContainer(
kShellWindowId_AutoclickContainer, "AutoclickBubbleContainer",
lock_screen_related_containers);
autoclick_container->SetProperty(::wm::kUsesScreenCoordinatesKey, true);
wm::SetSnapsChildrenToPhysicalPixelBoundary(autoclick_container);

aura::Window* drag_drop_container = CreateContainer(
kShellWindowId_DragImageAndTooltipContainer,
"DragImageAndTooltipContainer", lock_screen_related_containers);
::wm::SetChildWindowVisibilityChangesAnimated(drag_drop_container);
wm::SetSnapsChildrenToPhysicalPixelBoundary(drag_drop_container);
drag_drop_container->SetProperty(::wm::kUsesScreenCoordinatesKey, true);

aura::Window* overlay_container =
CreateContainer(kShellWindowId_OverlayContainer, "OverlayContainer",
lock_screen_related_containers);
wm::SetSnapsChildrenToPhysicalPixelBoundary(overlay_container);
overlay_container->SetProperty(::wm::kUsesScreenCoordinatesKey, true);
overlay_container->SetLayoutManager(
new OverlayLayoutManager(overlay_container)); // Takes ownership.
Expand Down
2 changes: 1 addition & 1 deletion ash/shelf/shelf_layout_manager.cc
Original file line number Diff line number Diff line change
Expand Up @@ -605,7 +605,7 @@ void ShelfLayoutManager::OnWindowResized() {

void ShelfLayoutManager::SetChildBounds(aura::Window* child,
const gfx::Rect& requested_bounds) {
wm::WmSnapToPixelLayoutManager::SetChildBounds(child, requested_bounds);
wm::WmDefaultLayoutManager::SetChildBounds(child, requested_bounds);
// We may contain other widgets (such as frame maximize bubble) but they don't
// effect the layout in anyway.
if (!updating_bounds_ &&
Expand Down
6 changes: 3 additions & 3 deletions ash/shelf/shelf_layout_manager.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
#include "ash/system/locale/locale_update_controller_impl.h"
#include "ash/wm/lock_state_observer.h"
#include "ash/wm/overview/overview_observer.h"
#include "ash/wm/wm_snap_to_pixel_layout_manager.h"
#include "ash/wm/wm_default_layout_manager.h"
#include "ash/wm/workspace/workspace_types.h"
#include "base/macros.h"
#include "base/observer_list.h"
Expand Down Expand Up @@ -61,7 +61,7 @@ class ASH_EXPORT ShelfLayoutManager : public AppListControllerObserver,
public OverviewObserver,
public ::wm::ActivationChangeObserver,
public LockStateObserver,
public wm::WmSnapToPixelLayoutManager,
public wm::WmDefaultLayoutManager,
public display::DisplayObserver,
public SessionObserver,
public WallpaperControllerObserver,
Expand Down Expand Up @@ -129,7 +129,7 @@ class ASH_EXPORT ShelfLayoutManager : public AppListControllerObserver,
// Cancel the drag if the shelf is in drag progress.
void CancelDragOnShelfIfInProgress();

// wm::WmSnapToPixelLayoutManager:
// wm::WmDefaultLayoutManager:
void OnWindowResized() override;
void SetChildBounds(aura::Window* child,
const gfx::Rect& requested_bounds) override;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
#include "ash/system/message_center/arc/arc_notification_surface.h"
#include "ash/system/message_center/arc/arc_notification_view.h"
// TODO(https://crbug.com/768439): Remove nogncheck when moved to ash.
#include "ash/wm/window_util.h" // nogncheck
#include "base/auto_reset.h"
#include "base/metrics/histogram_macros.h"
#include "components/arc/metrics/arc_metrics_constants.h"
Expand Down Expand Up @@ -478,11 +477,6 @@ void ArcNotificationContentView::AttachSurface() {
UpdatePreferredSize();
surface_->Attach(this);

// The texture for this window can be placed at subpixel position
// with fractional scale factor. Force to align it at the pixel
// boundary here, and when layout is updated in Layout().
::wm::SnapWindowToPixelBoundary(surface_->GetWindow());

// Creates slide helper after this view is added to its parent.
slide_helper_.reset(new SlideHelper(this));

Expand Down Expand Up @@ -655,9 +649,6 @@ void ArcNotificationContentView::Layout() {
}

UpdateControlButtonsVisibility();

if (is_surface_visible)
::wm::SnapWindowToPixelBoundary(surface_->GetWindow());
}

void ArcNotificationContentView::OnPaint(gfx::Canvas* canvas) {
Expand Down
4 changes: 2 additions & 2 deletions ash/system/status_area_layout_manager.cc
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ void StatusAreaLayoutManager::SetChildBounds(
// area and the shelf isn't in the process of doing a layout.
if (child != shelf_widget_->status_area_widget()->GetNativeWindow() ||
in_layout_) {
wm::WmSnapToPixelLayoutManager::SetChildBounds(child, requested_bounds);
wm::WmDefaultLayoutManager::SetChildBounds(child, requested_bounds);
return;
}

Expand All @@ -49,7 +49,7 @@ void StatusAreaLayoutManager::SetChildBounds(
if (requested_bounds == child->GetTargetBounds())
return;

wm::WmSnapToPixelLayoutManager::SetChildBounds(child, requested_bounds);
wm::WmDefaultLayoutManager::SetChildBounds(child, requested_bounds);
LayoutStatusArea();
}

Expand Down
6 changes: 3 additions & 3 deletions ash/system/status_area_layout_manager.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
#ifndef ASH_SYSTEM_STATUS_AREA_LAYOUT_MANAGER_H_
#define ASH_SYSTEM_STATUS_AREA_LAYOUT_MANAGER_H_

#include "ash/wm/wm_snap_to_pixel_layout_manager.h"
#include "ash/wm/wm_default_layout_manager.h"
#include "base/macros.h"

namespace ash {
Expand All @@ -15,12 +15,12 @@ class ShelfWidget;
// StatusAreaLayoutManager is a layout manager responsible for the status area.
// In any case when status area needs relayout it redirects this call to
// ShelfLayoutManager.
class StatusAreaLayoutManager : public wm::WmSnapToPixelLayoutManager {
class StatusAreaLayoutManager : public wm::WmDefaultLayoutManager {
public:
explicit StatusAreaLayoutManager(ShelfWidget* shelf_widget);
~StatusAreaLayoutManager() override;

// Overridden from wm::WmSnapToPixelLayoutManager:
// Overridden from wm::WmDefaultLayoutManager:
void OnWindowResized() override;
void SetChildBounds(aura::Window* child,
const gfx::Rect& requested_bounds) override;
Expand Down
2 changes: 1 addition & 1 deletion ash/wm/lock_action_handler_layout_manager.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ class ASH_EXPORT LockActionHandlerLayoutManager
LockScreenActionBackgroundController* action_background_controller);
~LockActionHandlerLayoutManager() override;

// WmSnapToPixelLayoutManager:
// WmDefaultLayoutManager:
void OnWindowAddedToLayout(aura::Window* child) override;
void OnChildWindowVisibilityChanged(aura::Window* child,
bool visibile) override;
Expand Down
2 changes: 1 addition & 1 deletion ash/wm/lock_layout_manager.cc
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
namespace ash {

LockLayoutManager::LockLayoutManager(aura::Window* window, Shelf* shelf)
: wm::WmSnapToPixelLayoutManager(),
: wm::WmDefaultLayoutManager(),
window_(window),
root_window_(window->GetRootWindow()),
shelf_observer_(this) {
Expand Down
6 changes: 3 additions & 3 deletions ash/wm/lock_layout_manager.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
#include "ash/public/cpp/keyboard/keyboard_controller_observer.h"
#include "ash/shelf/shelf_observer.h"
#include "ash/shell_observer.h"
#include "ash/wm/wm_snap_to_pixel_layout_manager.h"
#include "ash/wm/wm_default_layout_manager.h"
#include "base/macros.h"
#include "base/scoped_observer.h"
#include "ui/aura/window_observer.h"
Expand All @@ -36,7 +36,7 @@ class WMEvent;
// virtual keyboard changes inner workspace of each WebContents.
// For all windows in LockScreenContainer default wm::WindowState is replaced
// with LockWindowState.
class ASH_EXPORT LockLayoutManager : public wm::WmSnapToPixelLayoutManager,
class ASH_EXPORT LockLayoutManager : public wm::WmDefaultLayoutManager,
public aura::WindowObserver,
public ShellObserver,
public ShelfObserver,
Expand All @@ -45,7 +45,7 @@ class ASH_EXPORT LockLayoutManager : public wm::WmSnapToPixelLayoutManager,
LockLayoutManager(aura::Window* window, Shelf* shelf);
~LockLayoutManager() override;

// Overridden from WmSnapToPixelLayoutManager:
// Overridden from WmDefaultLayoutManager:
void OnWindowResized() override;
void OnWindowAddedToLayout(aura::Window* child) override;
void OnWillRemoveWindowFromLayout(aura::Window* child) override;
Expand Down
4 changes: 2 additions & 2 deletions ash/wm/overlay_layout_manager.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
#define ASH_WM_OVERLAY_LAYOUT_MANAGER_H_

#include "ash/ash_export.h"
#include "ash/wm/wm_snap_to_pixel_layout_manager.h"
#include "ash/wm/wm_default_layout_manager.h"
#include "base/macros.h"
#include "ui/display/display_observer.h"

Expand All @@ -18,7 +18,7 @@ namespace ash {

// Updates the bounds of widgets in the overlay container whenever the display
// bounds change. Keeps children snapped to pixel bounds.
class ASH_EXPORT OverlayLayoutManager : public wm::WmSnapToPixelLayoutManager,
class ASH_EXPORT OverlayLayoutManager : public wm::WmDefaultLayoutManager,
public display::DisplayObserver {
public:
explicit OverlayLayoutManager(aura::Window* overlay_container);
Expand Down
2 changes: 1 addition & 1 deletion ash/wm/system_modal_container_layout_manager.cc
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ void SystemModalContainerLayoutManager::OnWillRemoveWindowFromLayout(
void SystemModalContainerLayoutManager::SetChildBounds(
aura::Window* child,
const gfx::Rect& requested_bounds) {
WmSnapToPixelLayoutManager::SetChildBounds(child, requested_bounds);
WmDefaultLayoutManager::SetChildBounds(child, requested_bounds);
if (IsBoundsCentered(requested_bounds))
windows_to_center_.insert(child);
else
Expand Down
Loading

0 comments on commit ebd73ca

Please sign in to comment.