15821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Copyright (c) 2012 The Chromium Authors. All rights reserved.
25821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Use of this source code is governed by a BSD-style license that can be
35821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// found in the LICENSE file.
45821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
55821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "ash/wm/window_util.h"
65821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
75821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include <vector>
85821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
95821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "ash/ash_constants.h"
105d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)#include "ash/screen_util.h"
115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "ash/shell.h"
125f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)#include "ash/snap_to_pixel_layout_manager.h"
135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "ash/wm/window_properties.h"
14f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)#include "ash/wm/window_state.h"
1523730a6e56a168d1879203e4b3819bb36e3d8f1fTorne (Richard Coles)#include "ash/wm/wm_event.h"
165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "ui/aura/client/aura_constants.h"
175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "ui/aura/window.h"
18a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)#include "ui/aura/window_delegate.h"
19a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)#include "ui/aura/window_event_dispatcher.h"
205f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)#include "ui/compositor/dip_util.h"
215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "ui/gfx/display.h"
225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "ui/gfx/rect.h"
235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "ui/gfx/screen.h"
245d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)#include "ui/gfx/size.h"
25c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)#include "ui/views/view.h"
26c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)#include "ui/views/widget/widget.h"
27a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)#include "ui/wm/core/window_util.h"
28effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch#include "ui/wm/public/activation_client.h"
295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
305821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)namespace ash {
315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)namespace wm {
325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
33a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)namespace {
34a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)
35a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)// Returns the default width of a snapped window.
36a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)int GetDefaultSnappedWindowWidth(aura::Window* window) {
37a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  const float kSnappedWidthWorkspaceRatio = 0.5f;
38a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)
39a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  int work_area_width =
40a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)      ScreenUtil::GetDisplayWorkAreaBoundsInParent(window).width();
41a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  int min_width = window->delegate() ?
42a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)      window->delegate()->GetMinimumSize().width() : 0;
43a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  int ideal_width =
44a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)      static_cast<int>(work_area_width * kSnappedWidthWorkspaceRatio);
45a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  return std::min(work_area_width, std::max(ideal_width, min_width));
46a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)}
47a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)
48a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)}  // namespace
49a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)
502a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)// TODO(beng): replace many of these functions with the corewm versions.
515821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)void ActivateWindow(aura::Window* window) {
52a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  ::wm::ActivateWindow(window);
535821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
545821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
555821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)void DeactivateWindow(aura::Window* window) {
56a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  ::wm::DeactivateWindow(window);
575821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
585821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
595821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)bool IsActiveWindow(aura::Window* window) {
60a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  return ::wm::IsActiveWindow(window);
615821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
625821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
635821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)aura::Window* GetActiveWindow() {
645821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  return aura::client::GetActivationClient(Shell::GetPrimaryRootWindow())->
655821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      GetActiveWindow();
665821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
675821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
685821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)aura::Window* GetActivatableWindow(aura::Window* window) {
69a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  return ::wm::GetActivatableWindow(window);
705821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
715821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
725821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)bool CanActivateWindow(aura::Window* window) {
73a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  return ::wm::CanActivateWindow(window);
745821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
755821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
7668043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles)bool IsWindowMinimized(aura::Window* window) {
775d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  return ash::wm::GetWindowState(window)->IsMinimized();
785821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
795821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
805821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)void CenterWindow(aura::Window* window) {
8123730a6e56a168d1879203e4b3819bb36e3d8f1fTorne (Richard Coles)  wm::WMEvent event(wm::WM_EVENT_CENTER);
8223730a6e56a168d1879203e4b3819bb36e3d8f1fTorne (Richard Coles)  wm::GetWindowState(window)->OnWMEvent(&event);
835821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
845821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
85a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)gfx::Rect GetDefaultLeftSnappedWindowBoundsInParent(aura::Window* window) {
86a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  gfx::Rect work_area_in_parent(ScreenUtil::GetDisplayWorkAreaBoundsInParent(
87a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)      window));
88a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  return gfx::Rect(work_area_in_parent.x(),
89a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)                   work_area_in_parent.y(),
90a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)                   GetDefaultSnappedWindowWidth(window),
91a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)                   work_area_in_parent.height());
92a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)}
93a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)
94a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)gfx::Rect GetDefaultRightSnappedWindowBoundsInParent(aura::Window* window) {
95a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  gfx::Rect work_area_in_parent(ScreenUtil::GetDisplayWorkAreaBoundsInParent(
96a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)      window));
97a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  int width = GetDefaultSnappedWindowWidth(window);
98a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  return gfx::Rect(work_area_in_parent.right() - width,
99a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)                   work_area_in_parent.y(),
100a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)                   width,
101a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)                   work_area_in_parent.height());
102a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)}
103a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)
1045d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)void AdjustBoundsSmallerThan(const gfx::Size& max_size, gfx::Rect* bounds) {
1055d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  bounds->set_width(std::min(bounds->width(), max_size.width()));
1065d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  bounds->set_height(std::min(bounds->height(), max_size.height()));
1075d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)}
1085d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
1093551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)void AdjustBoundsToEnsureMinimumWindowVisibility(const gfx::Rect& visible_area,
1102a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)                                                 gfx::Rect* bounds) {
1112a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  AdjustBoundsToEnsureWindowVisibility(
1123551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)      visible_area, kMinimumOnScreenArea, kMinimumOnScreenArea, bounds);
1132a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)}
1142a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
1153551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)void AdjustBoundsToEnsureWindowVisibility(const gfx::Rect& visible_area,
1162a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)                                          int min_width,
1172a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)                                          int min_height,
1182a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)                                          gfx::Rect* bounds) {
1195d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  AdjustBoundsSmallerThan(visible_area.size(), bounds);
120bb1529ce867d8845a77ec7cdf3e3003ef1771a40Ben Murdoch
1213551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)  min_width = std::min(min_width, visible_area.width());
1223551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)  min_height = std::min(min_height, visible_area.height());
123bb1529ce867d8845a77ec7cdf3e3003ef1771a40Ben Murdoch
1245d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  if (bounds->right() < visible_area.x() + min_width) {
1255d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    bounds->set_x(visible_area.x() + min_width - bounds->width());
1265d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  } else if (bounds->x() > visible_area.right() - min_width) {
1273551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)    bounds->set_x(visible_area.right() - min_width);
128bb1529ce867d8845a77ec7cdf3e3003ef1771a40Ben Murdoch  }
1295d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  if (bounds->bottom() < visible_area.y() + min_height) {
1305d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    bounds->set_y(visible_area.y() + min_height - bounds->height());
1315d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  } else if (bounds->y() > visible_area.bottom() - min_height) {
1323551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)    bounds->set_y(visible_area.bottom() - min_height);
1335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  }
1345d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  if (bounds->y() < visible_area.y())
1355d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    bounds->set_y(visible_area.y());
1365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
1375821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
138c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)bool MoveWindowToEventRoot(aura::Window* window, const ui::Event& event) {
139c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  views::View* target = static_cast<views::View*>(event.target());
140c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  if (!target)
141c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)    return false;
1421e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  aura::Window* target_root =
143c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)      target->GetWidget()->GetNativeView()->GetRootWindow();
144c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  if (!target_root || target_root == window->GetRootWindow())
145c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)    return false;
146c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  aura::Window* window_container =
147c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)      ash::Shell::GetContainer(target_root, window->parent()->id());
148c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  // Move the window to the target launcher.
149c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  window_container->AddChild(window);
150c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  return true;
151c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)}
152c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)
153a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)void ReparentChildWithTransientChildren(aura::Window* child,
154a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)                                        aura::Window* old_parent,
155a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)                                        aura::Window* new_parent) {
156a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  if (child->parent() == old_parent)
157a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)    new_parent->AddChild(child);
158a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  ReparentTransientChildrenOfChild(child, old_parent, new_parent);
1594e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)}
1604e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)
161a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)void ReparentTransientChildrenOfChild(aura::Window* child,
162a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)                                      aura::Window* old_parent,
163a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)                                      aura::Window* new_parent) {
1645d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  for (size_t i = 0;
165a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)       i < ::wm::GetTransientChildren(child).size();
1665d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)       ++i) {
1675d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    ReparentChildWithTransientChildren(
168a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)        ::wm::GetTransientChildren(child)[i],
1695d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)        old_parent,
1705d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)        new_parent);
171a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  }
1724e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)}
1734e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)
1745f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)void SnapWindowToPixelBoundary(aura::Window* window) {
1755f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)  aura::Window* snapped_ancestor = window->parent();
1765f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)  while (snapped_ancestor) {
1775f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)    if (snapped_ancestor->GetProperty(kSnapChildrenToPixelBoundary)) {
1785f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)      ui::SnapLayerToPhysicalPixelBoundary(snapped_ancestor->layer(),
1795f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)                                           window->layer());
1805f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)      return;
1815f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)    }
1825f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)    snapped_ancestor = snapped_ancestor->parent();
1835f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)  }
1845f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)}
1855f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)
1865f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)void SetSnapsChildrenToPhysicalPixelBoundary(aura::Window* container) {
1875f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)  DCHECK(!container->GetProperty(kSnapChildrenToPixelBoundary))
1885f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)      << container->name();
1895f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)  container->SetProperty(kSnapChildrenToPixelBoundary, true);
1905f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)}
1915f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)
1925f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)void InstallSnapLayoutManagerToContainers(aura::Window* parent) {
1935f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)  aura::Window::Windows children = parent->children();
1945f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)  for (aura::Window::Windows::iterator iter = children.begin();
1955f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)       iter != children.end();
1965f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)       ++iter) {
1975f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)    aura::Window* container = *iter;
1985f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)    if (container->id() < 0)  // not a container
1995f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)      continue;
2005f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)    if (container->GetProperty(kSnapChildrenToPixelBoundary)) {
2015f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)      if (!container->layout_manager())
2025f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)        container->SetLayoutManager(new SnapToPixelLayoutManager(container));
2035f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)    } else {
2045f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)      InstallSnapLayoutManagerToContainers(container);
2055f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)    }
2065f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)  }
2075f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)}
2085f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)
2095821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}  // namespace wm
2105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}  // namespace ash
211