OLD | NEW |
1 // Copyright (c) 2011 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/default_container_layout_manager.h" | 5 #include "ash/wm/workspace/workspace_layout_manager.h" |
6 | 6 |
7 #include "ash/wm/property_util.h" | 7 #include "ash/wm/property_util.h" |
8 #include "ash/wm/show_state_controller.h" | 8 #include "ash/wm/show_state_controller.h" |
9 #include "ash/wm/window_util.h" | 9 #include "ash/wm/window_util.h" |
10 #include "ash/wm/workspace/workspace.h" | 10 #include "ash/wm/workspace/workspace.h" |
11 #include "ash/wm/workspace/workspace_manager.h" | 11 #include "ash/wm/workspace/workspace_manager.h" |
12 #include "ui/aura/client/aura_constants.h" | 12 #include "ui/aura/client/aura_constants.h" |
13 #include "ui/aura/event.h" | 13 #include "ui/aura/event.h" |
14 #include "ui/aura/root_window.h" | 14 #include "ui/aura/root_window.h" |
15 #include "ui/aura/screen_aura.h" | 15 #include "ui/aura/screen_aura.h" |
16 #include "ui/aura/window.h" | 16 #include "ui/aura/window.h" |
17 #include "ui/aura/window_observer.h" | 17 #include "ui/aura/window_observer.h" |
18 #include "ui/base/ui_base_types.h" | 18 #include "ui/base/ui_base_types.h" |
19 #include "ui/gfx/rect.h" | 19 #include "ui/gfx/rect.h" |
20 #include "ui/views/widget/native_widget_aura.h" | 20 #include "ui/views/widget/native_widget_aura.h" |
21 | 21 |
22 namespace ash { | 22 namespace ash { |
23 namespace internal { | 23 namespace internal { |
24 | 24 |
25 //////////////////////////////////////////////////////////////////////////////// | 25 //////////////////////////////////////////////////////////////////////////////// |
26 // DefaultContainerLayoutManager, public: | 26 // WorkspaceLayoutManager, public: |
27 | 27 |
28 DefaultContainerLayoutManager::DefaultContainerLayoutManager( | 28 WorkspaceLayoutManager::WorkspaceLayoutManager( |
29 WorkspaceManager* workspace_manager) | 29 WorkspaceManager* workspace_manager) |
30 : workspace_manager_(workspace_manager), | 30 : workspace_manager_(workspace_manager), |
31 show_state_controller_(new ShowStateController(workspace_manager)) { | 31 show_state_controller_(new ShowStateController(workspace_manager)) { |
32 } | 32 } |
33 | 33 |
34 DefaultContainerLayoutManager::~DefaultContainerLayoutManager() {} | 34 WorkspaceLayoutManager::~WorkspaceLayoutManager() {} |
35 | 35 |
36 void DefaultContainerLayoutManager::PrepareForMoveOrResize( | 36 void WorkspaceLayoutManager::PrepareForMoveOrResize( |
37 aura::Window* drag, | 37 aura::Window* drag, |
38 aura::MouseEvent* event) { | 38 aura::MouseEvent* event) { |
39 workspace_manager_->set_ignored_window(drag); | 39 workspace_manager_->set_ignored_window(drag); |
40 } | 40 } |
41 | 41 |
42 void DefaultContainerLayoutManager::CancelMoveOrResize( | 42 void WorkspaceLayoutManager::CancelMoveOrResize( |
43 aura::Window* drag, | 43 aura::Window* drag, |
44 aura::MouseEvent* event) { | 44 aura::MouseEvent* event) { |
45 workspace_manager_->set_ignored_window(NULL); | 45 workspace_manager_->set_ignored_window(NULL); |
46 } | 46 } |
47 | 47 |
48 void DefaultContainerLayoutManager::ProcessMove( | 48 void WorkspaceLayoutManager::ProcessMove( |
49 aura::Window* drag, | 49 aura::Window* drag, |
50 aura::MouseEvent* event) { | 50 aura::MouseEvent* event) { |
51 // TODO(oshima): Just zooming out may (and will) move/swap window without | 51 // TODO(oshima): Just zooming out may (and will) move/swap window without |
52 // a users's intent. We probably should scroll viewport, but that may not | 52 // a users's intent. We probably should scroll viewport, but that may not |
53 // be enough. See crbug.com/101826 for more discussion. | 53 // be enough. See crbug.com/101826 for more discussion. |
54 workspace_manager_->SetOverview(true); | 54 workspace_manager_->SetOverview(true); |
55 | 55 |
56 gfx::Point point_in_owner = event->location(); | 56 gfx::Point point_in_owner = event->location(); |
57 aura::Window::ConvertPointToWindow( | 57 aura::Window::ConvertPointToWindow( |
58 drag, | 58 drag, |
59 workspace_manager_->contents_view(), | 59 workspace_manager_->contents_view(), |
60 &point_in_owner); | 60 &point_in_owner); |
61 // TODO(oshima): We should support simply moving to another | 61 // TODO(oshima): We should support simply moving to another |
62 // workspace when the destination workspace has enough room to accomodate. | 62 // workspace when the destination workspace has enough room to accomodate. |
63 aura::Window* rotate_target = | 63 aura::Window* rotate_target = |
64 workspace_manager_->FindRotateWindowForLocation(point_in_owner); | 64 workspace_manager_->FindRotateWindowForLocation(point_in_owner); |
65 if (rotate_target) | 65 if (rotate_target) |
66 workspace_manager_->RotateWindows(drag, rotate_target); | 66 workspace_manager_->RotateWindows(drag, rotate_target); |
67 } | 67 } |
68 | 68 |
69 void DefaultContainerLayoutManager::EndMove( | 69 void WorkspaceLayoutManager::EndMove( |
70 aura::Window* drag, | 70 aura::Window* drag, |
71 aura::MouseEvent* evnet) { | 71 aura::MouseEvent* evnet) { |
72 // TODO(oshima): finish moving window between workspaces. | 72 // TODO(oshima): finish moving window between workspaces. |
73 workspace_manager_->set_ignored_window(NULL); | 73 workspace_manager_->set_ignored_window(NULL); |
74 Workspace* workspace = workspace_manager_->FindBy(drag); | 74 Workspace* workspace = workspace_manager_->FindBy(drag); |
75 workspace->Layout(NULL); | 75 workspace->Layout(NULL); |
76 workspace->Activate(); | 76 workspace->Activate(); |
77 workspace_manager_->SetOverview(false); | 77 workspace_manager_->SetOverview(false); |
78 } | 78 } |
79 | 79 |
80 void DefaultContainerLayoutManager::EndResize( | 80 void WorkspaceLayoutManager::EndResize( |
81 aura::Window* drag, | 81 aura::Window* drag, |
82 aura::MouseEvent* evnet) { | 82 aura::MouseEvent* evnet) { |
83 workspace_manager_->set_ignored_window(NULL); | 83 workspace_manager_->set_ignored_window(NULL); |
84 Workspace* workspace = workspace_manager_->GetActiveWorkspace(); | 84 Workspace* workspace = workspace_manager_->GetActiveWorkspace(); |
85 if (workspace) | 85 if (workspace) |
86 workspace->Layout(NULL); | 86 workspace->Layout(NULL); |
87 workspace_manager_->SetOverview(false); | 87 workspace_manager_->SetOverview(false); |
88 } | 88 } |
89 | 89 |
90 //////////////////////////////////////////////////////////////////////////////// | 90 //////////////////////////////////////////////////////////////////////////////// |
91 // DefaultContainerLayoutManager, aura::LayoutManager implementation: | 91 // WorkspaceLayoutManager, aura::LayoutManager implementation: |
92 | 92 |
93 void DefaultContainerLayoutManager::OnWindowResized() { | 93 void WorkspaceLayoutManager::OnWindowResized() { |
94 // Workspace is updated via RootWindowObserver::OnRootWindowResized. | 94 // Workspace is updated via RootWindowObserver::OnRootWindowResized. |
95 } | 95 } |
96 | 96 |
97 void DefaultContainerLayoutManager::OnWindowAddedToLayout(aura::Window* child) { | 97 void WorkspaceLayoutManager::OnWindowAddedToLayout(aura::Window* child) { |
98 if (child->type() != aura::client::WINDOW_TYPE_NORMAL || | 98 if (child->type() != aura::client::WINDOW_TYPE_NORMAL || |
99 child->transient_parent()) { | 99 child->transient_parent()) { |
100 return; | 100 return; |
101 } | 101 } |
102 | 102 |
103 if (!child->GetProperty(aura::client::kShowStateKey)) | 103 if (!child->GetProperty(aura::client::kShowStateKey)) |
104 child->SetIntProperty(aura::client::kShowStateKey, ui::SHOW_STATE_NORMAL); | 104 child->SetIntProperty(aura::client::kShowStateKey, ui::SHOW_STATE_NORMAL); |
105 | 105 |
106 child->AddObserver(show_state_controller_.get()); | 106 child->AddObserver(show_state_controller_.get()); |
107 | 107 |
108 Workspace* workspace = workspace_manager_->GetActiveWorkspace(); | 108 Workspace* workspace = workspace_manager_->GetActiveWorkspace(); |
109 if (workspace) { | 109 if (workspace) { |
110 aura::Window* active = ash::GetActiveWindow(); | 110 aura::Window* active = ash::GetActiveWindow(); |
111 // Active window may not be in the default container layer. | 111 // Active window may not be in the default container layer. |
112 if (!workspace->Contains(active)) | 112 if (!workspace->Contains(active)) |
113 active = NULL; | 113 active = NULL; |
114 if (workspace->AddWindowAfter(child, active)) | 114 if (workspace->AddWindowAfter(child, active)) |
115 return; | 115 return; |
116 } | 116 } |
117 // Create new workspace if new |child| doesn't fit to current workspace. | 117 // Create new workspace if new |child| doesn't fit to current workspace. |
118 Workspace* new_workspace = workspace_manager_->CreateWorkspace(); | 118 Workspace* new_workspace = workspace_manager_->CreateWorkspace(); |
119 new_workspace->AddWindowAfter(child, NULL); | 119 new_workspace->AddWindowAfter(child, NULL); |
120 new_workspace->Activate(); | 120 new_workspace->Activate(); |
121 } | 121 } |
122 | 122 |
123 void DefaultContainerLayoutManager::OnWillRemoveWindowFromLayout( | 123 void WorkspaceLayoutManager::OnWillRemoveWindowFromLayout( |
124 aura::Window* child) { | 124 aura::Window* child) { |
125 child->RemoveObserver(show_state_controller_.get()); | 125 child->RemoveObserver(show_state_controller_.get()); |
126 ClearRestoreBounds(child); | 126 ClearRestoreBounds(child); |
127 | 127 |
128 Workspace* workspace = workspace_manager_->FindBy(child); | 128 Workspace* workspace = workspace_manager_->FindBy(child); |
129 if (!workspace) | 129 if (!workspace) |
130 return; | 130 return; |
131 workspace->RemoveWindow(child); | 131 workspace->RemoveWindow(child); |
132 if (workspace->is_empty()) | 132 if (workspace->is_empty()) |
133 delete workspace; | 133 delete workspace; |
134 } | 134 } |
135 | 135 |
136 void DefaultContainerLayoutManager::OnChildWindowVisibilityChanged( | 136 void WorkspaceLayoutManager::OnChildWindowVisibilityChanged( |
137 aura::Window* child, | 137 aura::Window* child, |
138 bool visible) { | 138 bool visible) { |
139 NOTIMPLEMENTED(); | 139 NOTIMPLEMENTED(); |
140 } | 140 } |
141 | 141 |
142 void DefaultContainerLayoutManager::SetChildBounds( | 142 void WorkspaceLayoutManager::SetChildBounds( |
143 aura::Window* child, | 143 aura::Window* child, |
144 const gfx::Rect& requested_bounds) { | 144 const gfx::Rect& requested_bounds) { |
145 gfx::Rect adjusted_bounds = requested_bounds; | 145 gfx::Rect adjusted_bounds = requested_bounds; |
146 | 146 |
147 // First, calculate the adjusted bounds. | 147 // First, calculate the adjusted bounds. |
148 if (child->type() != aura::client::WINDOW_TYPE_NORMAL || | 148 if (child->type() != aura::client::WINDOW_TYPE_NORMAL || |
149 workspace_manager_->layout_in_progress() || | 149 workspace_manager_->layout_in_progress() || |
150 child->transient_parent()) { | 150 child->transient_parent()) { |
151 // Use the requested bounds as is. | 151 // Use the requested bounds as is. |
152 } else if (child == workspace_manager_->ignored_window()) { | 152 } else if (child == workspace_manager_->ignored_window()) { |
(...skipping 28 matching lines...) Expand all Loading... |
181 adjusted_bounds = workspace->bounds(); | 181 adjusted_bounds = workspace->bounds(); |
182 // Don't | 182 // Don't |
183 if (child->GetTargetBounds() == adjusted_bounds) | 183 if (child->GetTargetBounds() == adjusted_bounds) |
184 return; | 184 return; |
185 } | 185 } |
186 SetChildBoundsDirect(child, adjusted_bounds); | 186 SetChildBoundsDirect(child, adjusted_bounds); |
187 } | 187 } |
188 | 188 |
189 } // namespace internal | 189 } // namespace internal |
190 } // namespace ash | 190 } // namespace ash |
OLD | NEW |