| 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" |
| 11 #include "ash/shell.h" | 11 #include "ash/shell.h" |
| 12 #include "ash/snap_to_pixel_layout_manager.h" | 12 #include "ash/snap_to_pixel_layout_manager.h" |
| 13 #include "ash/wm/aura/wm_window_aura.h" |
| 13 #include "ash/wm/common/wm_event.h" | 14 #include "ash/wm/common/wm_event.h" |
| 15 #include "ash/wm/common/wm_screen_util.h" |
| 16 #include "ash/wm/common/wm_window.h" |
| 14 #include "ash/wm/window_properties.h" | 17 #include "ash/wm/window_properties.h" |
| 15 #include "ash/wm/window_state.h" | 18 #include "ash/wm/window_state.h" |
| 19 #include "ash/wm/window_state_aura.h" |
| 16 #include "ui/aura/client/aura_constants.h" | 20 #include "ui/aura/client/aura_constants.h" |
| 17 #include "ui/aura/window.h" | 21 #include "ui/aura/window.h" |
| 18 #include "ui/aura/window_delegate.h" | 22 #include "ui/aura/window_delegate.h" |
| 19 #include "ui/aura/window_event_dispatcher.h" | 23 #include "ui/aura/window_event_dispatcher.h" |
| 20 #include "ui/compositor/dip_util.h" | 24 #include "ui/compositor/dip_util.h" |
| 21 #include "ui/gfx/display.h" | 25 #include "ui/gfx/display.h" |
| 22 #include "ui/gfx/geometry/rect.h" | 26 #include "ui/gfx/geometry/rect.h" |
| 23 #include "ui/gfx/geometry/size.h" | 27 #include "ui/gfx/geometry/size.h" |
| 24 #include "ui/gfx/screen.h" | 28 #include "ui/gfx/screen.h" |
| 25 #include "ui/views/view.h" | 29 #include "ui/views/view.h" |
| 26 #include "ui/views/widget/widget.h" | 30 #include "ui/views/widget/widget.h" |
| 27 #include "ui/wm/core/window_util.h" | 31 #include "ui/wm/core/window_util.h" |
| 28 #include "ui/wm/public/activation_client.h" | 32 #include "ui/wm/public/activation_client.h" |
| 29 | 33 |
| 30 namespace ash { | 34 namespace ash { |
| 31 namespace wm { | 35 namespace wm { |
| 32 | 36 |
| 33 namespace { | 37 namespace { |
| 34 | 38 |
| 35 // Returns the default width of a snapped window. | 39 // Returns the default width of a snapped window. |
| 36 int GetDefaultSnappedWindowWidth(aura::Window* window) { | 40 int GetDefaultSnappedWindowWidth(wm::WmWindow* window) { |
| 37 const float kSnappedWidthWorkspaceRatio = 0.5f; | 41 const float kSnappedWidthWorkspaceRatio = 0.5f; |
| 38 | 42 |
| 39 int work_area_width = | 43 int work_area_width = GetDisplayWorkAreaBoundsInParent(window).width(); |
| 40 ScreenUtil::GetDisplayWorkAreaBoundsInParent(window).width(); | 44 int min_width = window->GetMinimumSize().width(); |
| 41 int min_width = window->delegate() ? | |
| 42 window->delegate()->GetMinimumSize().width() : 0; | |
| 43 int ideal_width = | 45 int ideal_width = |
| 44 static_cast<int>(work_area_width * kSnappedWidthWorkspaceRatio); | 46 static_cast<int>(work_area_width * kSnappedWidthWorkspaceRatio); |
| 45 return std::min(work_area_width, std::max(ideal_width, min_width)); | 47 return std::min(work_area_width, std::max(ideal_width, min_width)); |
| 46 } | 48 } |
| 47 | 49 |
| 50 int GetDefaultSnappedWindowWidth(aura::Window* window) { |
| 51 return GetDefaultSnappedWindowWidth(WmWindowAura::Get(window)); |
| 52 } |
| 53 |
| 48 } // namespace | 54 } // namespace |
| 49 | 55 |
| 50 // TODO(beng): replace many of these functions with the corewm versions. | 56 // TODO(beng): replace many of these functions with the corewm versions. |
| 51 void ActivateWindow(aura::Window* window) { | 57 void ActivateWindow(aura::Window* window) { |
| 52 ::wm::ActivateWindow(window); | 58 ::wm::ActivateWindow(window); |
| 53 } | 59 } |
| 54 | 60 |
| 55 void DeactivateWindow(aura::Window* window) { | 61 void DeactivateWindow(aura::Window* window) { |
| 56 ::wm::DeactivateWindow(window); | 62 ::wm::DeactivateWindow(window); |
| 57 } | 63 } |
| (...skipping 21 matching lines...) Expand all Loading... |
| 79 | 85 |
| 80 bool IsWindowUserPositionable(aura::Window* window) { | 86 bool IsWindowUserPositionable(aura::Window* window) { |
| 81 return GetWindowState(window)->IsUserPositionable(); | 87 return GetWindowState(window)->IsUserPositionable(); |
| 82 } | 88 } |
| 83 | 89 |
| 84 void CenterWindow(aura::Window* window) { | 90 void CenterWindow(aura::Window* window) { |
| 85 wm::WMEvent event(wm::WM_EVENT_CENTER); | 91 wm::WMEvent event(wm::WM_EVENT_CENTER); |
| 86 wm::GetWindowState(window)->OnWMEvent(&event); | 92 wm::GetWindowState(window)->OnWMEvent(&event); |
| 87 } | 93 } |
| 88 | 94 |
| 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 |
| 89 gfx::Rect GetDefaultLeftSnappedWindowBoundsInParent(aura::Window* window) { | 109 gfx::Rect GetDefaultLeftSnappedWindowBoundsInParent(aura::Window* window) { |
| 90 gfx::Rect work_area_in_parent(ScreenUtil::GetDisplayWorkAreaBoundsInParent( | 110 gfx::Rect work_area_in_parent(ScreenUtil::GetDisplayWorkAreaBoundsInParent( |
| 91 window)); | 111 window)); |
| 92 return gfx::Rect(work_area_in_parent.x(), | 112 return gfx::Rect(work_area_in_parent.x(), |
| 93 work_area_in_parent.y(), | 113 work_area_in_parent.y(), |
| 94 GetDefaultSnappedWindowWidth(window), | 114 GetDefaultSnappedWindowWidth(window), |
| 95 work_area_in_parent.height()); | 115 work_area_in_parent.height()); |
| 96 } | 116 } |
| 97 | 117 |
| 98 gfx::Rect GetDefaultRightSnappedWindowBoundsInParent(aura::Window* window) { | 118 gfx::Rect GetDefaultRightSnappedWindowBoundsInParent(aura::Window* window) { |
| (...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 205 if (!container->layout_manager()) | 225 if (!container->layout_manager()) |
| 206 container->SetLayoutManager(new SnapToPixelLayoutManager(container)); | 226 container->SetLayoutManager(new SnapToPixelLayoutManager(container)); |
| 207 } else { | 227 } else { |
| 208 InstallSnapLayoutManagerToContainers(container); | 228 InstallSnapLayoutManagerToContainers(container); |
| 209 } | 229 } |
| 210 } | 230 } |
| 211 } | 231 } |
| 212 | 232 |
| 213 } // namespace wm | 233 } // namespace wm |
| 214 } // namespace ash | 234 } // namespace ash |
| OLD | NEW |