| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "ash/wm/window_util.h" | 5 #include "ash/wm/window_util.h" |
| 6 | 6 |
| 7 #include <vector> | 7 #include <vector> |
| 8 | 8 |
| 9 #include "ash/ash_constants.h" | 9 #include "ash/ash_constants.h" |
| 10 #include "ash/screen_util.h" | 10 #include "ash/screen_util.h" |
| (...skipping 16 matching lines...) Expand all Loading... |
| 27 #include "ui/gfx/geometry/size.h" | 27 #include "ui/gfx/geometry/size.h" |
| 28 #include "ui/gfx/screen.h" | 28 #include "ui/gfx/screen.h" |
| 29 #include "ui/views/view.h" | 29 #include "ui/views/view.h" |
| 30 #include "ui/views/widget/widget.h" | 30 #include "ui/views/widget/widget.h" |
| 31 #include "ui/wm/core/window_util.h" | 31 #include "ui/wm/core/window_util.h" |
| 32 #include "ui/wm/public/activation_client.h" | 32 #include "ui/wm/public/activation_client.h" |
| 33 | 33 |
| 34 namespace ash { | 34 namespace ash { |
| 35 namespace wm { | 35 namespace wm { |
| 36 | 36 |
| 37 namespace { | |
| 38 | |
| 39 // Returns the default width of a snapped window. | |
| 40 int GetDefaultSnappedWindowWidth(wm::WmWindow* window) { | |
| 41 const float kSnappedWidthWorkspaceRatio = 0.5f; | |
| 42 | |
| 43 int work_area_width = GetDisplayWorkAreaBoundsInParent(window).width(); | |
| 44 int min_width = window->GetMinimumSize().width(); | |
| 45 int ideal_width = | |
| 46 static_cast<int>(work_area_width * kSnappedWidthWorkspaceRatio); | |
| 47 return std::min(work_area_width, std::max(ideal_width, min_width)); | |
| 48 } | |
| 49 | |
| 50 int GetDefaultSnappedWindowWidth(aura::Window* window) { | |
| 51 return GetDefaultSnappedWindowWidth(WmWindowAura::Get(window)); | |
| 52 } | |
| 53 | |
| 54 } // namespace | |
| 55 | |
| 56 // TODO(beng): replace many of these functions with the corewm versions. | 37 // TODO(beng): replace many of these functions with the corewm versions. |
| 57 void ActivateWindow(aura::Window* window) { | 38 void ActivateWindow(aura::Window* window) { |
| 58 ::wm::ActivateWindow(window); | 39 ::wm::ActivateWindow(window); |
| 59 } | 40 } |
| 60 | 41 |
| 61 void DeactivateWindow(aura::Window* window) { | 42 void DeactivateWindow(aura::Window* window) { |
| 62 ::wm::DeactivateWindow(window); | 43 ::wm::DeactivateWindow(window); |
| 63 } | 44 } |
| 64 | 45 |
| 65 bool IsActiveWindow(aura::Window* window) { | 46 bool IsActiveWindow(aura::Window* window) { |
| (...skipping 19 matching lines...) Expand all Loading... |
| 85 | 66 |
| 86 bool IsWindowUserPositionable(aura::Window* window) { | 67 bool IsWindowUserPositionable(aura::Window* window) { |
| 87 return GetWindowState(window)->IsUserPositionable(); | 68 return GetWindowState(window)->IsUserPositionable(); |
| 88 } | 69 } |
| 89 | 70 |
| 90 void CenterWindow(aura::Window* window) { | 71 void CenterWindow(aura::Window* window) { |
| 91 wm::WMEvent event(wm::WM_EVENT_CENTER); | 72 wm::WMEvent event(wm::WM_EVENT_CENTER); |
| 92 wm::GetWindowState(window)->OnWMEvent(&event); | 73 wm::GetWindowState(window)->OnWMEvent(&event); |
| 93 } | 74 } |
| 94 | 75 |
| 95 gfx::Rect GetDefaultLeftSnappedWindowBoundsInParent(wm::WmWindow* window) { | |
| 96 gfx::Rect work_area_in_parent(GetDisplayWorkAreaBoundsInParent(window)); | |
| 97 return gfx::Rect(work_area_in_parent.x(), work_area_in_parent.y(), | |
| 98 GetDefaultSnappedWindowWidth(window), | |
| 99 work_area_in_parent.height()); | |
| 100 } | |
| 101 | |
| 102 gfx::Rect GetDefaultRightSnappedWindowBoundsInParent(wm::WmWindow* window) { | |
| 103 gfx::Rect work_area_in_parent(GetDisplayWorkAreaBoundsInParent(window)); | |
| 104 int width = GetDefaultSnappedWindowWidth(window); | |
| 105 return gfx::Rect(work_area_in_parent.right() - width, work_area_in_parent.y(), | |
| 106 width, work_area_in_parent.height()); | |
| 107 } | |
| 108 | |
| 109 gfx::Rect GetDefaultLeftSnappedWindowBoundsInParent(aura::Window* window) { | |
| 110 gfx::Rect work_area_in_parent(ScreenUtil::GetDisplayWorkAreaBoundsInParent( | |
| 111 window)); | |
| 112 return gfx::Rect(work_area_in_parent.x(), | |
| 113 work_area_in_parent.y(), | |
| 114 GetDefaultSnappedWindowWidth(window), | |
| 115 work_area_in_parent.height()); | |
| 116 } | |
| 117 | |
| 118 gfx::Rect GetDefaultRightSnappedWindowBoundsInParent(aura::Window* window) { | |
| 119 gfx::Rect work_area_in_parent(ScreenUtil::GetDisplayWorkAreaBoundsInParent( | |
| 120 window)); | |
| 121 int width = GetDefaultSnappedWindowWidth(window); | |
| 122 return gfx::Rect(work_area_in_parent.right() - width, | |
| 123 work_area_in_parent.y(), | |
| 124 width, | |
| 125 work_area_in_parent.height()); | |
| 126 } | |
| 127 | |
| 128 bool MoveWindowToEventRoot(aura::Window* window, const ui::Event& event) { | 76 bool MoveWindowToEventRoot(aura::Window* window, const ui::Event& event) { |
| 129 views::View* target = static_cast<views::View*>(event.target()); | 77 views::View* target = static_cast<views::View*>(event.target()); |
| 130 if (!target) | 78 if (!target) |
| 131 return false; | 79 return false; |
| 132 aura::Window* target_root = | 80 aura::Window* target_root = |
| 133 target->GetWidget()->GetNativeView()->GetRootWindow(); | 81 target->GetWidget()->GetNativeView()->GetRootWindow(); |
| 134 if (!target_root || target_root == window->GetRootWindow()) | 82 if (!target_root || target_root == window->GetRootWindow()) |
| 135 return false; | 83 return false; |
| 136 aura::Window* window_container = | 84 aura::Window* window_container = |
| 137 ash::Shell::GetContainer(target_root, window->parent()->id()); | 85 ash::Shell::GetContainer(target_root, window->parent()->id()); |
| 138 // Move the window to the target launcher. | 86 // Move the window to the target launcher. |
| 139 window_container->AddChild(window); | 87 window_container->AddChild(window); |
| 140 return true; | 88 return true; |
| 141 } | 89 } |
| 142 | 90 |
| 143 void ReparentChildWithTransientChildren(aura::Window* child, | |
| 144 aura::Window* old_parent, | |
| 145 aura::Window* new_parent) { | |
| 146 if (child->parent() == old_parent) | |
| 147 new_parent->AddChild(child); | |
| 148 ReparentTransientChildrenOfChild(child, old_parent, new_parent); | |
| 149 } | |
| 150 | |
| 151 void ReparentTransientChildrenOfChild(aura::Window* child, | |
| 152 aura::Window* old_parent, | |
| 153 aura::Window* new_parent) { | |
| 154 for (size_t i = 0; | |
| 155 i < ::wm::GetTransientChildren(child).size(); | |
| 156 ++i) { | |
| 157 ReparentChildWithTransientChildren( | |
| 158 ::wm::GetTransientChildren(child)[i], | |
| 159 old_parent, | |
| 160 new_parent); | |
| 161 } | |
| 162 } | |
| 163 | |
| 164 void SnapWindowToPixelBoundary(aura::Window* window) { | 91 void SnapWindowToPixelBoundary(aura::Window* window) { |
| 165 aura::Window* snapped_ancestor = window->parent(); | 92 aura::Window* snapped_ancestor = window->parent(); |
| 166 while (snapped_ancestor) { | 93 while (snapped_ancestor) { |
| 167 if (snapped_ancestor->GetProperty(kSnapChildrenToPixelBoundary)) { | 94 if (snapped_ancestor->GetProperty(kSnapChildrenToPixelBoundary)) { |
| 168 ui::SnapLayerToPhysicalPixelBoundary(snapped_ancestor->layer(), | 95 ui::SnapLayerToPhysicalPixelBoundary(snapped_ancestor->layer(), |
| 169 window->layer()); | 96 window->layer()); |
| 170 return; | 97 return; |
| 171 } | 98 } |
| 172 snapped_ancestor = snapped_ancestor->parent(); | 99 snapped_ancestor = snapped_ancestor->parent(); |
| 173 } | 100 } |
| (...skipping 17 matching lines...) Expand all Loading... |
| 191 if (!container->layout_manager()) | 118 if (!container->layout_manager()) |
| 192 container->SetLayoutManager(new SnapToPixelLayoutManager(container)); | 119 container->SetLayoutManager(new SnapToPixelLayoutManager(container)); |
| 193 } else { | 120 } else { |
| 194 InstallSnapLayoutManagerToContainers(container); | 121 InstallSnapLayoutManagerToContainers(container); |
| 195 } | 122 } |
| 196 } | 123 } |
| 197 } | 124 } |
| 198 | 125 |
| 199 } // namespace wm | 126 } // namespace wm |
| 200 } // namespace ash | 127 } // namespace ash |
| OLD | NEW |