Commit 1ca79d4a authored by oshima@chromium.org's avatar oshima@chromium.org

Snap widgets to pixel boundary on ash

Introduced SnapToPixelLayoutManager and used where it makes sense.
WorkspaceLayoutManager uses WindowState, so it's the property is manually set there.


This depends on the following CL:
https://codereview.chromium.org/375693006/

BUG=391822

Review URL: https://codereview.chromium.org/357063002

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@284119 0039d316-1c4b-4281-b951-d872f2087c98
parent 388f6742
......@@ -249,6 +249,8 @@
'shell_init_params.cc',
'shell_init_params.h',
'shell_window_ids.h',
'snap_to_pixel_layout_manager.cc',
'snap_to_pixel_layout_manager.h',
'sticky_keys/sticky_keys_state.h',
'sticky_keys/sticky_keys_controller.cc',
'sticky_keys/sticky_keys_controller.h',
......
......@@ -856,6 +856,10 @@ void RootWindowController::InitLayoutManagers() {
new DockedWindowLayoutManager(docked_container, workspace_controller());
docked_container->SetLayoutManager(docked_layout_manager_);
// Installs SnapLayoutManager to containers who set the
// |kSnapsChildrenToPhysicalPixelBoundary| property.
wm::InstallSnapLayoutManagerToContainers(root_window);
// Create Panel layout manager
aura::Window* panel_container = GetContainer(kShellWindowId_PanelContainer);
panel_layout_manager_ = new PanelLayoutManager(panel_container);
......@@ -955,6 +959,7 @@ void RootWindowController::CreateContainersInRootWindow(
"DefaultContainer",
non_lock_screen_containers);
::wm::SetChildWindowVisibilityChangesAnimated(default_container);
wm::SetSnapsChildrenToPhysicalPixelBoundary(default_container);
SetUsesScreenCoordinates(default_container);
SetUsesEasyResizeTargeter(default_container);
......@@ -963,6 +968,7 @@ void RootWindowController::CreateContainersInRootWindow(
"AlwaysOnTopContainer",
non_lock_screen_containers);
::wm::SetChildWindowVisibilityChangesAnimated(always_on_top_container);
wm::SetSnapsChildrenToPhysicalPixelBoundary(always_on_top_container);
SetUsesScreenCoordinates(always_on_top_container);
aura::Window* docked_container = CreateContainer(
......@@ -970,6 +976,7 @@ void RootWindowController::CreateContainersInRootWindow(
"DockedContainer",
non_lock_screen_containers);
::wm::SetChildWindowVisibilityChangesAnimated(docked_container);
wm::SetSnapsChildrenToPhysicalPixelBoundary(docked_container);
SetUsesScreenCoordinates(docked_container);
SetUsesEasyResizeTargeter(docked_container);
......@@ -977,6 +984,7 @@ void RootWindowController::CreateContainersInRootWindow(
CreateContainer(kShellWindowId_ShelfContainer,
"ShelfContainer",
non_lock_screen_containers);
wm::SetSnapsChildrenToPhysicalPixelBoundary(shelf_container);
SetUsesScreenCoordinates(shelf_container);
DescendantShouldStayInSameRootWindow(shelf_container);
......@@ -984,12 +992,14 @@ void RootWindowController::CreateContainersInRootWindow(
kShellWindowId_PanelContainer,
"PanelContainer",
non_lock_screen_containers);
wm::SetSnapsChildrenToPhysicalPixelBoundary(panel_container);
SetUsesScreenCoordinates(panel_container);
aura::Window* shelf_bubble_container =
CreateContainer(kShellWindowId_ShelfBubbleContainer,
"ShelfBubbleContainer",
non_lock_screen_containers);
wm::SetSnapsChildrenToPhysicalPixelBoundary(shelf_bubble_container);
SetUsesScreenCoordinates(shelf_bubble_container);
DescendantShouldStayInSameRootWindow(shelf_bubble_container);
......@@ -997,12 +1007,14 @@ void RootWindowController::CreateContainersInRootWindow(
CreateContainer(kShellWindowId_AppListContainer,
"AppListContainer",
non_lock_screen_containers);
wm::SetSnapsChildrenToPhysicalPixelBoundary(app_list_container);
SetUsesScreenCoordinates(app_list_container);
aura::Window* modal_container = CreateContainer(
kShellWindowId_SystemModalContainer,
"SystemModalContainer",
non_lock_screen_containers);
wm::SetSnapsChildrenToPhysicalPixelBoundary(modal_container);
modal_container->SetLayoutManager(
new SystemModalContainerLayoutManager(modal_container));
::wm::SetChildWindowVisibilityChangesAnimated(modal_container);
......@@ -1015,6 +1027,7 @@ void RootWindowController::CreateContainersInRootWindow(
kShellWindowId_LockScreenContainer,
"LockScreenContainer",
lock_screen_containers);
wm::SetSnapsChildrenToPhysicalPixelBoundary(lock_container);
if (CommandLine::ForCurrentProcess()->HasSwitch(
switches::kAshDisableLockLayoutManager)) {
lock_container->SetLayoutManager(
......@@ -1029,6 +1042,7 @@ void RootWindowController::CreateContainersInRootWindow(
kShellWindowId_LockSystemModalContainer,
"LockSystemModalContainer",
lock_screen_containers);
wm::SetSnapsChildrenToPhysicalPixelBoundary(lock_modal_container);
lock_modal_container->SetLayoutManager(
new SystemModalContainerLayoutManager(lock_modal_container));
::wm::SetChildWindowVisibilityChangesAnimated(lock_modal_container);
......@@ -1039,6 +1053,7 @@ void RootWindowController::CreateContainersInRootWindow(
CreateContainer(kShellWindowId_StatusContainer,
"StatusContainer",
lock_screen_related_containers);
wm::SetSnapsChildrenToPhysicalPixelBoundary(status_container);
SetUsesScreenCoordinates(status_container);
DescendantShouldStayInSameRootWindow(status_container);
......@@ -1047,6 +1062,7 @@ void RootWindowController::CreateContainersInRootWindow(
"SettingBubbleContainer",
lock_screen_related_containers);
::wm::SetChildWindowVisibilityChangesAnimated(settings_bubble_container);
wm::SetSnapsChildrenToPhysicalPixelBoundary(settings_bubble_container);
SetUsesScreenCoordinates(settings_bubble_container);
DescendantShouldStayInSameRootWindow(settings_bubble_container);
......@@ -1055,6 +1071,7 @@ void RootWindowController::CreateContainersInRootWindow(
"MenuContainer",
lock_screen_related_containers);
::wm::SetChildWindowVisibilityChangesAnimated(menu_container);
wm::SetSnapsChildrenToPhysicalPixelBoundary(menu_container);
SetUsesScreenCoordinates(menu_container);
aura::Window* drag_drop_container = CreateContainer(
......@@ -1062,18 +1079,22 @@ void RootWindowController::CreateContainersInRootWindow(
"DragImageAndTooltipContainer",
lock_screen_related_containers);
::wm::SetChildWindowVisibilityChangesAnimated(drag_drop_container);
wm::SetSnapsChildrenToPhysicalPixelBoundary(drag_drop_container);
SetUsesScreenCoordinates(drag_drop_container);
aura::Window* overlay_container = CreateContainer(
kShellWindowId_OverlayContainer,
"OverlayContainer",
lock_screen_related_containers);
wm::SetSnapsChildrenToPhysicalPixelBoundary(overlay_container);
SetUsesScreenCoordinates(overlay_container);
aura::Window* virtual_keyboard_parent_container = CreateContainer(
kShellWindowId_VirtualKeyboardParentContainer,
"VirtualKeyboardParentContainer",
root_window);
wm::SetSnapsChildrenToPhysicalPixelBoundary(
virtual_keyboard_parent_container);
SetUsesScreenCoordinates(virtual_keyboard_parent_container);
#if defined(OS_CHROMEOS)
......
......@@ -187,7 +187,8 @@ class ShelfLayoutManager::UpdateShelfObserver
// ShelfLayoutManager ----------------------------------------------------------
ShelfLayoutManager::ShelfLayoutManager(ShelfWidget* shelf)
: root_window_(shelf->GetNativeView()->GetRootWindow()),
: SnapToPixelLayoutManager(shelf->GetNativeView()->parent()),
root_window_(shelf->GetNativeView()->GetRootWindow()),
updating_bounds_(false),
auto_hide_behavior_(SHELF_AUTO_HIDE_BEHAVIOR_NEVER),
alignment_(SHELF_ALIGNMENT_BOTTOM),
......@@ -515,22 +516,9 @@ void ShelfLayoutManager::OnWindowResized() {
LayoutShelf();
}
void ShelfLayoutManager::OnWindowAddedToLayout(aura::Window* child) {
}
void ShelfLayoutManager::OnWillRemoveWindowFromLayout(aura::Window* child) {
}
void ShelfLayoutManager::OnWindowRemovedFromLayout(aura::Window* child) {
}
void ShelfLayoutManager::OnChildWindowVisibilityChanged(aura::Window* child,
bool visible) {
}
void ShelfLayoutManager::SetChildBounds(aura::Window* child,
const gfx::Rect& requested_bounds) {
SetChildBoundsDirect(child, requested_bounds);
SnapToPixelLayoutManager::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_ &&
......
......@@ -13,6 +13,7 @@
#include "ash/shelf/shelf.h"
#include "ash/shelf/shelf_types.h"
#include "ash/shell_observer.h"
#include "ash/snap_to_pixel_layout_manager.h"
#include "ash/system/status_area_widget.h"
#include "ash/wm/dock/docked_window_layout_manager_observer.h"
#include "ash/wm/lock_state_observer.h"
......@@ -22,7 +23,6 @@
#include "base/logging.h"
#include "base/observer_list.h"
#include "base/timer/timer.h"
#include "ui/aura/layout_manager.h"
#include "ui/gfx/insets.h"
#include "ui/gfx/rect.h"
#include "ui/keyboard/keyboard_controller.h"
......@@ -56,14 +56,14 @@ FORWARD_DECLARE_TEST(WebNotificationTrayTest, PopupAndFullscreen);
// layout to the status area.
// To respond to bounds changes in the status area StatusAreaLayoutManager works
// closely with ShelfLayoutManager.
class ASH_EXPORT ShelfLayoutManager :
public aura::LayoutManager,
public ash::ShellObserver,
public aura::client::ActivationChangeObserver,
public DockedWindowLayoutManagerObserver,
public keyboard::KeyboardControllerObserver,
public LockStateObserver,
public SessionStateObserver {
class ASH_EXPORT ShelfLayoutManager
: public ash::ShellObserver,
public aura::client::ActivationChangeObserver,
public DockedWindowLayoutManagerObserver,
public keyboard::KeyboardControllerObserver,
public LockStateObserver,
public SnapToPixelLayoutManager,
public SessionStateObserver {
public:
// We reserve a small area on the edge of the workspace area to ensure that
......@@ -164,13 +164,8 @@ class ASH_EXPORT ShelfLayoutManager :
// shelf. Specifying 0 leads to use the default.
void SetAnimationDurationOverride(int duration_override_in_ms);
// Overridden from aura::LayoutManager:
// Overridden from SnapLayoutManager:
virtual void OnWindowResized() OVERRIDE;
virtual void OnWindowAddedToLayout(aura::Window* child) OVERRIDE;
virtual void OnWillRemoveWindowFromLayout(aura::Window* child) OVERRIDE;
virtual void OnWindowRemovedFromLayout(aura::Window* child) OVERRIDE;
virtual void OnChildWindowVisibilityChanged(aura::Window* child,
bool visible) OVERRIDE;
virtual void SetChildBounds(aura::Window* child,
const gfx::Rect& requested_bounds) OVERRIDE;
......
......@@ -630,7 +630,8 @@ ShelfWidget::ShelfWidget(aura::Window* shelf_container,
shelf_layout_manager_->set_workspace_controller(workspace_controller);
workspace_controller->SetShelf(shelf_layout_manager_);
status_container->SetLayoutManager(new StatusAreaLayoutManager(this));
status_container->SetLayoutManager(
new StatusAreaLayoutManager(status_container, this));
shelf_container->SetEventTargeter(scoped_ptr<ui::EventTargeter>(new
ShelfWindowTargeter(shelf_container, shelf_layout_manager_)));
......
// Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "ash/snap_to_pixel_layout_manager.h"
#include "ash/wm/window_properties.h"
#include "ash/wm/window_util.h"
#include "ui/aura/window.h"
namespace ash {
SnapToPixelLayoutManager::SnapToPixelLayoutManager(aura::Window* container) {
DCHECK(container->GetProperty(kSnapChildrenToPixelBoundary));
}
SnapToPixelLayoutManager::~SnapToPixelLayoutManager() {
}
void SnapToPixelLayoutManager::OnWindowResized() {
}
void SnapToPixelLayoutManager::OnWindowAddedToLayout(aura::Window* child) {
}
void SnapToPixelLayoutManager::OnWillRemoveWindowFromLayout(
aura::Window* child) {
}
void SnapToPixelLayoutManager::OnWindowRemovedFromLayout(aura::Window* child) {
}
void SnapToPixelLayoutManager::OnChildWindowVisibilityChanged(
aura::Window* child,
bool visibile) {
}
void SnapToPixelLayoutManager::SetChildBounds(
aura::Window* child,
const gfx::Rect& requested_bounds) {
SetChildBoundsDirect(child, requested_bounds);
wm::SnapWindowToPixelBoundary(child);
}
} // namespace ash
// Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef ASH_WM_SNAP_TO_PIXEL_LAYOUT_MANAGER_H_
#define ASH_WM_SNAP_TO_PIXEL_LAYOUT_MANAGER_H_
#include "ash/ash_export.h"
#include "base/macros.h"
#include "ui/aura/layout_manager.h"
namespace ash {
// A layout manager that places children's layer at the physical pixel
// boundaries.
class ASH_EXPORT SnapToPixelLayoutManager : public aura::LayoutManager {
public:
explicit SnapToPixelLayoutManager(aura::Window* container);
virtual ~SnapToPixelLayoutManager();
protected:
// Overridden from aura::LayoutManager:
virtual void OnWindowResized() OVERRIDE;
virtual void OnWindowAddedToLayout(aura::Window* child) OVERRIDE;
virtual void OnWillRemoveWindowFromLayout(aura::Window* child) OVERRIDE;
virtual void OnWindowRemovedFromLayout(aura::Window* child) OVERRIDE;
virtual void OnChildWindowVisibilityChanged(aura::Window* child,
bool visibile) OVERRIDE;
virtual void SetChildBounds(aura::Window* child,
const gfx::Rect& requested_bounds) OVERRIDE;
private:
DISALLOW_COPY_AND_ASSIGN(SnapToPixelLayoutManager);
};
} // namespace ash
#endif // ASH_WM_SNAP_TO_PIXEL_LAYOUT_MANAGER_H_
......@@ -402,8 +402,10 @@ class DockedWindowLayoutManager::ShelfWindowObserver : public WindowObserver {
////////////////////////////////////////////////////////////////////////////////
// DockedWindowLayoutManager public implementation:
DockedWindowLayoutManager::DockedWindowLayoutManager(
aura::Window* dock_container, WorkspaceController* workspace_controller)
: dock_container_(dock_container),
aura::Window* dock_container,
WorkspaceController* workspace_controller)
: SnapToPixelLayoutManager(dock_container),
dock_container_(dock_container),
in_layout_(false),
dragged_window_(NULL),
is_dragged_window_docked_(false),
......@@ -411,7 +413,7 @@ DockedWindowLayoutManager::DockedWindowLayoutManager(
shelf_(NULL),
workspace_controller_(workspace_controller),
in_fullscreen_(workspace_controller_->GetWindowState() ==
WORKSPACE_WINDOW_STATE_FULL_SCREEN),
WORKSPACE_WINDOW_STATE_FULL_SCREEN),
docked_width_(0),
alignment_(DOCKED_ALIGNMENT_NONE),
last_active_window_(NULL),
......@@ -716,10 +718,10 @@ void DockedWindowLayoutManager::SetChildBounds(
actual_new_bounds.set_height(
std::max(min_size.height(), actual_new_bounds.height()));
}
// Whenever one of our windows is moved or resized enforce layout.
SetChildBoundsDirect(child, actual_new_bounds);
SnapToPixelLayoutManager::SetChildBounds(child, actual_new_bounds);
if (IsPopupOrTransient(child))
return;
// Whenever one of our windows is moved or resized enforce layout.
ShelfLayoutManager* shelf_layout =
ShelfLayoutManager::ForShelf(dock_container_);
if (shelf_layout)
......
......@@ -8,6 +8,7 @@
#include "ash/ash_export.h"
#include "ash/shelf/shelf_layout_manager_observer.h"
#include "ash/shell_observer.h"
#include "ash/snap_to_pixel_layout_manager.h"
#include "ash/wm/dock/dock_types.h"
#include "ash/wm/dock/docked_window_layout_manager_observer.h"
#include "ash/wm/window_state_observer.h"
......@@ -17,7 +18,6 @@
#include "base/memory/scoped_ptr.h"
#include "base/observer_list.h"
#include "base/time/time.h"
#include "ui/aura/layout_manager.h"
#include "ui/aura/window.h"
#include "ui/aura/window_observer.h"
#include "ui/gfx/rect.h"
......@@ -67,7 +67,7 @@ struct WindowWithHeight {
// TODO(varkha): extend BaseLayoutManager instead of LayoutManager to inherit
// common functionality.
class ASH_EXPORT DockedWindowLayoutManager
: public aura::LayoutManager,
: public SnapToPixelLayoutManager,
public ash::ShellObserver,
public aura::WindowObserver,
public aura::client::ActivationChangeObserver,
......@@ -134,7 +134,7 @@ class ASH_EXPORT DockedWindowLayoutManager
// Updates docked layout when shelf bounds change.
void OnShelfBoundsChanged();
// aura::LayoutManager:
// SnapLayoutManager:
virtual void OnWindowResized() OVERRIDE;
virtual void OnWindowAddedToLayout(aura::Window* child) OVERRIDE;
virtual void OnWillRemoveWindowFromLayout(aura::Window* child) OVERRIDE {}
......
......@@ -18,7 +18,8 @@
namespace ash {
LockLayoutManager::LockLayoutManager(aura::Window* window)
: window_(window),
: SnapToPixelLayoutManager(window),
window_(window),
root_window_(window->GetRootWindow()),
is_observing_keyboard_(false) {
Shell::GetInstance()->delegate()->AddVirtualKeyboardStateObserver(this);
......
......@@ -7,6 +7,7 @@
#include "ash/ash_export.h"
#include "ash/shell_delegate.h"
#include "ash/snap_to_pixel_layout_manager.h"
#include "ash/wm/wm_types.h"
#include "base/basictypes.h"
#include "base/compiler_specific.h"
......@@ -44,7 +45,7 @@ class WMEvent;
// For all windows in LockScreenContainer default wm::WindowState is replaced
// with LockWindowState.
class ASH_EXPORT LockLayoutManager
: public aura::LayoutManager,
: public SnapToPixelLayoutManager,
public aura::WindowObserver,
public VirtualKeyboardStateObserver,
public keyboard::KeyboardControllerObserver {
......
......@@ -16,9 +16,9 @@ namespace ash {
////////////////////////////////////////////////////////////////////////////////
// StatusAreaLayoutManager, public:
StatusAreaLayoutManager::StatusAreaLayoutManager(ShelfWidget* shelf)
: in_layout_(false),
shelf_(shelf) {
StatusAreaLayoutManager::StatusAreaLayoutManager(aura::Window* container,
ShelfWidget* shelf)
: SnapToPixelLayoutManager(container), in_layout_(false), shelf_(shelf) {
}
StatusAreaLayoutManager::~StatusAreaLayoutManager() {
......@@ -31,27 +31,13 @@ void StatusAreaLayoutManager::OnWindowResized() {
LayoutStatusArea();
}
void StatusAreaLayoutManager::OnWindowAddedToLayout(aura::Window* child) {
}
void StatusAreaLayoutManager::OnWillRemoveWindowFromLayout(
aura::Window* child) {
}
void StatusAreaLayoutManager::OnWindowRemovedFromLayout(aura::Window* child) {
}
void StatusAreaLayoutManager::OnChildWindowVisibilityChanged(
aura::Window* child, bool visible) {
}
void StatusAreaLayoutManager::SetChildBounds(
aura::Window* child,
const gfx::Rect& requested_bounds) {
// Only need to have the shelf do a layout if the child changing is the status
// area and the shelf isn't in the process of doing a layout.
if (child != shelf_->status_area_widget()->GetNativeView() || in_layout_) {
SetChildBoundsDirect(child, requested_bounds);
SnapToPixelLayoutManager::SetChildBounds(child, requested_bounds);
return;
}
......@@ -60,7 +46,7 @@ void StatusAreaLayoutManager::SetChildBounds(
if (requested_bounds == child->GetTargetBounds())
return;
SetChildBoundsDirect(child, requested_bounds);
SnapToPixelLayoutManager::SetChildBounds(child, requested_bounds);
LayoutStatusArea();
}
......
......@@ -5,6 +5,7 @@
#ifndef ASH_WM_STATUS_AREA_LAYOUT_MANAGER_H_
#define ASH_WM_STATUS_AREA_LAYOUT_MANAGER_H_
#include "ash/snap_to_pixel_layout_manager.h"
#include "base/basictypes.h"
#include "base/compiler_specific.h"
#include "ui/aura/layout_manager.h"
......@@ -15,18 +16,13 @@ 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 aura::LayoutManager {
class StatusAreaLayoutManager : public SnapToPixelLayoutManager {
public:
explicit StatusAreaLayoutManager(ShelfWidget* shelf);
StatusAreaLayoutManager(aura::Window* container, ShelfWidget* shelf);
virtual ~StatusAreaLayoutManager();
// Overridden from aura::LayoutManager:
virtual void OnWindowResized() OVERRIDE;
virtual void OnWindowAddedToLayout(aura::Window* child) OVERRIDE;
virtual void OnWillRemoveWindowFromLayout(aura::Window* child) OVERRIDE;
virtual void OnWindowRemovedFromLayout(aura::Window* child) OVERRIDE;
virtual void OnChildWindowVisibilityChanged(aura::Window* child,
bool visible) OVERRIDE;
virtual void SetChildBounds(aura::Window* child,
const gfx::Rect& requested_bounds) OVERRIDE;
......
......@@ -46,7 +46,8 @@ const int kCenterPixelDelta = 32;
SystemModalContainerLayoutManager::SystemModalContainerLayoutManager(
aura::Window* container)
: container_(container),
: SnapToPixelLayoutManager(container),
container_(container),
modal_background_(NULL) {
}
......@@ -86,19 +87,10 @@ void SystemModalContainerLayoutManager::OnWillRemoveWindowFromLayout(
RemoveModalWindow(child);
}
void SystemModalContainerLayoutManager::OnWindowRemovedFromLayout(
aura::Window* child) {
}
void SystemModalContainerLayoutManager::OnChildWindowVisibilityChanged(
aura::Window* child,
bool visible) {
}
void SystemModalContainerLayoutManager::SetChildBounds(
aura::Window* child,
const gfx::Rect& requested_bounds) {
SetChildBoundsDirect(child, requested_bounds);
SnapToPixelLayoutManager::SetChildBounds(child, requested_bounds);
child->SetProperty(kCenteredKey, DialogIsCentered(requested_bounds));
}
......
......@@ -8,10 +8,10 @@
#include <vector>
#include "ash/ash_export.h"
#include "ash/snap_to_pixel_layout_manager.h"
#include "base/basictypes.h"
#include "base/compiler_specific.h"
#include "base/memory/scoped_ptr.h"
#include "ui/aura/layout_manager.h"
#include "ui/aura/window_observer.h"
#include "ui/keyboard/keyboard_controller_observer.h"
......@@ -32,7 +32,7 @@ namespace ash {
// System modal windows which are centered on the screen will be kept centered
// when the container size changes.
class ASH_EXPORT SystemModalContainerLayoutManager
: public aura::LayoutManager,
: public SnapToPixelLayoutManager,
public aura::WindowObserver,
public keyboard::KeyboardControllerObserver {
public:
......@@ -41,13 +41,10 @@ class ASH_EXPORT SystemModalContainerLayoutManager
bool has_modal_background() const { return modal_background_ != NULL; }
// Overridden from aura::LayoutManager:
// Overridden from SnapToPixelLayoutManager:
virtual void OnWindowResized() OVERRIDE;
virtual void OnWindowAddedToLayout(aura::Window* child) OVERRIDE;
virtual void OnWillRemoveWindowFromLayout(aura::Window* child) OVERRIDE;
virtual void OnWindowRemovedFromLayout(aura::Window* child) OVERRIDE;
virtual void OnChildWindowVisibilityChanged(aura::Window* child,
bool visibile) OVERRIDE;
virtual void SetChildBounds(aura::Window* child,
const gfx::Rect& requested_bounds) OVERRIDE;
......
......@@ -21,8 +21,12 @@ DEFINE_WINDOW_PROPERTY_KEY(ui::WindowShowState,
kRestoreShowStateOverrideKey,
ui::SHOW_STATE_DEFAULT);
DEFINE_WINDOW_PROPERTY_KEY(bool, kSnapChildrenToPixelBoundary, false);
DEFINE_WINDOW_PROPERTY_KEY(bool, kStayInSameRootWindowKey, false);
DEFINE_WINDOW_PROPERTY_KEY(bool, kUsesScreenCoordinatesKey, false);
DEFINE_OWNED_WINDOW_PROPERTY_KEY(wm::WindowState,
kWindowStateKey, NULL);
......
......@@ -37,6 +37,10 @@ ASH_EXPORT extern const aura::WindowProperty<gfx::Rect*>* const
ASH_EXPORT extern const aura::WindowProperty<ui::WindowShowState>* const
kRestoreShowStateOverrideKey;
// Containers with this property (true) are aligned with physical pixel
// boundary.
extern const aura::WindowProperty<bool>* const kSnapChildrenToPixelBoundary;
// If this is set to true, the window stays in the same root window
// even if the bounds outside of its root window is set.
// This is exported as it's used in the tests.
......
......@@ -378,6 +378,7 @@ void WindowState::SetBoundsDirect(const gfx::Rect& bounds) {
std::max(min_size.height(), actual_new_bounds.height()));
}
BoundsSetter().SetBounds(window_, actual_new_bounds);
SnapWindowToPixelBoundary(window_);
}
void WindowState::SetBoundsConstrained(const gfx::Rect& bounds) {
......
......@@ -330,7 +330,7 @@ class ASH_EXPORT WindowState : public aura::WindowObserver {
void NotifyPreStateTypeChange(WindowStateType old_window_state_type);
void NotifyPostStateTypeChange(WindowStateType old_window_state_type);
// Sets |bounds| as is.
// Sets |bounds| as is and ensure the layer is aligned with pixel boundary.
void SetBoundsDirect(const gfx::Rect& bounds);
// Sets the window's |bounds| with constraint where the size of the
......
......@@ -9,6 +9,7 @@
#include "ash/ash_constants.h"
#include "ash/screen_util.h"
#include "ash/shell.h"
#include "ash/snap_to_pixel_layout_manager.h"
#include "ash/wm/window_properties.h"
#include "ash/wm/window_state.h"
#include "ash/wm/wm_event.h"
......@@ -16,6 +17,7 @@
#include "ui/aura/window.h"
#include "ui/aura/window_delegate.h"
#include "ui/aura/window_event_dispatcher.h"
#include "ui/compositor/dip_util.h"
#include "ui/gfx/display.h"
#include "ui/gfx/rect.h"
#include "ui/gfx/screen.h"
......@@ -169,5 +171,40 @@ void ReparentTransientChildrenOfChild(aura::Window* child,
}
}
void SnapWindowToPixelBoundary(aura::Window* window) {
aura::Window* snapped_ancestor = window->parent();
while (snapped_ancestor) {
if (snapped_ancestor->GetProperty(kSnapChildrenToPixelBoundary)) {
ui::SnapLayerToPhysicalPixelBoundary(snapped_ancestor->layer(),
window->layer());
return;
}
snapped_ancestor = snapped_ancestor->parent();
}
}
void SetSnapsChildrenToPhysicalPixelBoundary(aura::Window* container) {
DCHECK(!container->GetProperty(kSnapChildrenToPixelBoundary))
<< container->name();
container->SetProperty(kSnapChildrenToPixelBoundary, true);
}
void InstallSnapLayoutManagerToContainers(aura::Window* parent) {
aura::Window::Windows children = parent->children();
for (aura::Window::Windows::iterator iter = children.begin();
iter != children.end();
++iter) {
aura::Window* container = *iter;
if (container->id() < 0) // not a container
continue;
if (container->GetProperty(kSnapChildrenToPixelBoundary)) {
if (!container->layout_manager())
container->SetLayoutManager(new SnapToPixelLayoutManager(container));
} else {
InstallSnapLayoutManagerToContainers(container);
}
}
}
} // namespace wm
} // namespace ash
......@@ -14,6 +14,7 @@ class Window;
}
namespace gfx {
class Point;
class Rect;
class Size;
}
......@@ -96,6 +97,17 @@ void ReparentTransientChildrenOfChild(aura::Window* child,
aura::Window* old_parent,
aura::Window* new_parent);
// Snap the window's layer to physical pixel boundary.
void SnapWindowToPixelBoundary(aura::Window* window);
// Mark the container window so that InstallSnapLayoutManagerToContainers
// installs the SnapToPixelLayoutManager.
ASH_EXPORT void SetSnapsChildrenToPhysicalPixelBoundary(
aura::Window* container);
// Traverse the |container| tree and installs SnapToPixelLayoutManager.
void InstallSnapLayoutManagerToContainers(aura::Window* container);
} // namespace wm
} // namespace ash
......
......@@ -49,6 +49,7 @@ WorkspaceLayoutManager::WorkspaceLayoutManager(aura::Window* window)
Shell::GetInstance()->activation_client()->AddObserver(this);
Shell::GetInstance()->AddShellObserver(this);
root_window_->AddObserver(this);
DCHECK(window->GetProperty(kSnapChildrenToPixelBoundary));
}
WorkspaceLayoutManager::~WorkspaceLayoutManager() {
......
......@@ -523,8 +523,7 @@ TEST_F(WorkspaceLayoutManagerTest, NotifyFullscreenChanges) {
EXPECT_FALSE(observer.is_fullscreen());
}
// Following tests were originally written for BaseLayoutManager.
// Following "Solo" tests were originally written for BaseLayoutManager.
namespace {
class WorkspaceLayoutManagerSoloTest : public test::AshTestBase {
......@@ -532,15 +531,6 @@ class WorkspaceLayoutManagerSoloTest : public test::AshTestBase {
WorkspaceLayoutManagerSoloTest() {}
virtual ~WorkspaceLayoutManagerSoloTest() {}
virtual void SetUp() OVERRIDE {
test::AshTestBase::SetUp();
UpdateDisplay("800x600");
aura::Window* default_container = Shell::GetContainer(
Shell::GetPrimaryRootWindow(), kShellWindowId_DefaultContainer);
default_container->SetLayoutManager(
new WorkspaceLayoutManager(Shell::GetPrimaryRootWindow()));
}
aura::Window* CreateTestWindow(const gfx::Rect& bounds) {
return CreateTestWindowInShellWithBounds(bounds);
}
......@@ -993,8 +983,8 @@ class WorkspaceLayoutManagerKeyboardTest : public test::AshTestBase {
UpdateDisplay("800x600");
aura::Window* default_container = Shell::GetContainer(
Shell::GetPrimaryRootWindow(), kShellWindowId_DefaultContainer);
layout_manager_ = new WorkspaceLayoutManager(Shell::GetPrimaryRootWindow());
default_container->SetLayoutManager(layout_manager_);
layout_manager_ = static_cast<WorkspaceLayoutManager*>(
default_container->layout_manager());
}
aura::Window* CreateTestWindow(const gfx::Rect& bounds) {
......
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