OLD | NEW |
---|---|
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "athena/wm/window_manager_impl.h" | 5 #include "athena/wm/window_manager_impl.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 | 8 |
9 #include "athena/screen/public/screen_manager.h" | 9 #include "athena/screen/public/screen_manager.h" |
10 #include "athena/util/container_priorities.h" | 10 #include "athena/util/container_priorities.h" |
11 #include "athena/wm/bezel_controller.h" | 11 #include "athena/wm/bezel_controller.h" |
12 #include "athena/wm/public/window_manager_observer.h" | 12 #include "athena/wm/public/window_manager_observer.h" |
13 #include "athena/wm/split_view_controller.h" | 13 #include "athena/wm/split_view_controller.h" |
14 #include "athena/wm/title_drag_controller.h" | 14 #include "athena/wm/title_drag_controller.h" |
15 #include "athena/wm/window_list_provider_impl.h" | 15 #include "athena/wm/window_list_provider_impl.h" |
16 #include "athena/wm/window_overview_mode.h" | 16 #include "athena/wm/window_overview_mode.h" |
17 #include "base/bind.h" | 17 #include "base/bind.h" |
18 #include "base/logging.h" | 18 #include "base/logging.h" |
19 #include "ui/aura/client/aura_constants.h" | |
19 #include "ui/aura/layout_manager.h" | 20 #include "ui/aura/layout_manager.h" |
20 #include "ui/aura/window.h" | 21 #include "ui/aura/window.h" |
22 #include "ui/aura/window_delegate.h" | |
21 #include "ui/compositor/closure_animation_observer.h" | 23 #include "ui/compositor/closure_animation_observer.h" |
22 #include "ui/compositor/scoped_layer_animation_settings.h" | 24 #include "ui/compositor/scoped_layer_animation_settings.h" |
23 #include "ui/gfx/display.h" | 25 #include "ui/gfx/display.h" |
24 #include "ui/gfx/screen.h" | 26 #include "ui/gfx/screen.h" |
25 #include "ui/wm/core/shadow_controller.h" | 27 #include "ui/wm/core/shadow_controller.h" |
26 #include "ui/wm/core/transient_window_manager.h" | 28 #include "ui/wm/core/transient_window_manager.h" |
27 #include "ui/wm/core/window_util.h" | 29 #include "ui/wm/core/window_util.h" |
28 #include "ui/wm/core/wm_state.h" | 30 #include "ui/wm/core/wm_state.h" |
29 #include "ui/wm/public/activation_client.h" | 31 #include "ui/wm/public/activation_client.h" |
30 #include "ui/wm/public/window_types.h" | 32 #include "ui/wm/public/window_types.h" |
31 | 33 |
32 namespace athena { | 34 namespace athena { |
33 namespace { | 35 namespace { |
34 class WindowManagerImpl* instance = NULL; | 36 class WindowManagerImpl* instance = NULL; |
35 | 37 |
36 void SetWindowState(aura::Window* window, | 38 void SetWindowState(aura::Window* window, |
37 const gfx::Rect& bounds, | 39 const gfx::Rect& bounds, |
38 const gfx::Transform& transform) { | 40 const gfx::Transform& transform) { |
39 window->SetBounds(bounds); | 41 window->SetBounds(bounds); |
40 window->SetTransform(transform); | 42 window->SetTransform(transform); |
41 } | 43 } |
42 | 44 |
45 // Tests whether the given window can be maximized | |
46 bool CanWindowMaximize(const aura::Window* const window) { | |
47 const aura::WindowDelegate* delegate = window->delegate(); | |
48 const bool no_max_size = | |
49 !delegate || delegate->GetMaximumSize().IsEmpty(); | |
50 return (no_max_size && | |
51 window->GetProperty(aura::client::kCanMaximizeKey) && | |
52 window->GetProperty(aura::client::kCanResizeKey)); | |
oshima
2014/10/24 18:39:55
nit: we don't use outmost () unless it's complicat
afakhry
2014/10/25 00:35:08
Done.
| |
53 } | |
54 | |
43 } // namespace | 55 } // namespace |
44 | 56 |
45 class AthenaContainerLayoutManager : public aura::LayoutManager { | 57 class AthenaContainerLayoutManager : public aura::LayoutManager { |
46 public: | 58 public: |
47 AthenaContainerLayoutManager(); | 59 AthenaContainerLayoutManager(); |
48 virtual ~AthenaContainerLayoutManager(); | 60 virtual ~AthenaContainerLayoutManager(); |
49 | 61 |
50 private: | 62 private: |
51 // aura::LayoutManager: | 63 // aura::LayoutManager: |
52 virtual void OnWindowResized() override; | 64 virtual void OnWindowResized() override; |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
84 for (aura::Window::Windows::const_iterator iter = list.begin(); | 96 for (aura::Window::Windows::const_iterator iter = list.begin(); |
85 iter != list.end(); | 97 iter != list.end(); |
86 ++iter) { | 98 ++iter) { |
87 aura::Window* window = *iter; | 99 aura::Window* window = *iter; |
88 if (is_splitview) { | 100 if (is_splitview) { |
89 if (window == instance->split_view_controller_->left_window()) | 101 if (window == instance->split_view_controller_->left_window()) |
90 window->SetBounds(gfx::Rect(split_size)); | 102 window->SetBounds(gfx::Rect(split_size)); |
91 else if (window == instance->split_view_controller_->right_window()) | 103 else if (window == instance->split_view_controller_->right_window()) |
92 window->SetBounds( | 104 window->SetBounds( |
93 gfx::Rect(gfx::Point(split_size.width(), 0), split_size)); | 105 gfx::Rect(gfx::Point(split_size.width(), 0), split_size)); |
94 else | 106 else { |
107 if (CanWindowMaximize(window)) | |
oshima
2014/10/24 18:39:56
else if
afakhry
2014/10/25 00:35:08
Done.
| |
108 window->SetBounds(gfx::Rect(work_area)); | |
109 } | |
110 } else { | |
111 if (CanWindowMaximize(window)) | |
oshima
2014/10/24 18:39:56
ditto
afakhry
2014/10/25 00:35:08
Done.
| |
95 window->SetBounds(gfx::Rect(work_area)); | 112 window->SetBounds(gfx::Rect(work_area)); |
96 } else { | |
97 window->SetBounds(gfx::Rect(work_area)); | |
98 } | 113 } |
99 } | 114 } |
100 } | 115 } |
101 | 116 |
102 void AthenaContainerLayoutManager::OnWindowAddedToLayout(aura::Window* child) { | 117 void AthenaContainerLayoutManager::OnWindowAddedToLayout(aura::Window* child) { |
103 // TODO(oshima): Split view modes needs to take the transient window into | 118 // TODO(oshima): Split view modes needs to take the transient window into |
104 // account. | 119 // account. |
105 if (wm::GetTransientParent(child)) { | 120 if (wm::GetTransientParent(child)) { |
106 wm::TransientWindowManager::Get(child) | 121 wm::TransientWindowManager::Get(child) |
107 ->set_parent_controls_visibility(true); | 122 ->set_parent_controls_visibility(true); |
(...skipping 23 matching lines...) Expand all Loading... | |
131 aura::Window* child) { | 146 aura::Window* child) { |
132 } | 147 } |
133 | 148 |
134 void AthenaContainerLayoutManager::OnWindowRemovedFromLayout( | 149 void AthenaContainerLayoutManager::OnWindowRemovedFromLayout( |
135 aura::Window* child) { | 150 aura::Window* child) { |
136 } | 151 } |
137 | 152 |
138 void AthenaContainerLayoutManager::OnChildWindowVisibilityChanged( | 153 void AthenaContainerLayoutManager::OnChildWindowVisibilityChanged( |
139 aura::Window* child, | 154 aura::Window* child, |
140 bool visible) { | 155 bool visible) { |
156 if (visible && CanWindowMaximize(child)) { | |
157 // Make sure we're resizing a window that actually exists in the window list | |
158 // to avoid resizing the divider in the split mode. | |
159 const aura::Window::Windows& list = instance->window_list_provider_ | |
160 ->GetWindowList(); | |
161 aura::Window::Windows::const_iterator itr = std::find(list.cbegin(), | |
162 list.cend(), child); | |
163 | |
164 if (itr != list.end()) { | |
165 child->SetBounds( | |
166 gfx::Screen::GetNativeScreen()->GetPrimaryDisplay().work_area()); | |
167 } | |
oshima
2014/10/24 18:39:56
Can you add
// TODO(oshima): Fix WindowListProvid
oshima
2014/10/24 21:37:28
Actually, you should be able to just use InWnidowI
afakhry
2014/10/25 00:35:08
Done.
| |
168 } | |
141 } | 169 } |
142 | 170 |
143 void AthenaContainerLayoutManager::SetChildBounds( | 171 void AthenaContainerLayoutManager::SetChildBounds( |
144 aura::Window* child, | 172 aura::Window* child, |
145 const gfx::Rect& requested_bounds) { | 173 const gfx::Rect& requested_bounds) { |
146 if (!requested_bounds.IsEmpty()) | 174 if (!requested_bounds.IsEmpty()) |
147 SetChildBoundsDirect(child, requested_bounds); | 175 SetChildBoundsDirect(child, requested_bounds); |
148 } | 176 } |
149 | 177 |
150 WindowManagerImpl::WindowManagerImpl() { | 178 WindowManagerImpl::WindowManagerImpl() { |
(...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
297 wm::ActivateWindow(window); | 325 wm::ActivateWindow(window); |
298 | 326 |
299 if (split_view_controller_->IsSplitViewModeActive()) { | 327 if (split_view_controller_->IsSplitViewModeActive()) { |
300 split_view_controller_->DeactivateSplitMode(); | 328 split_view_controller_->DeactivateSplitMode(); |
301 FOR_EACH_OBSERVER(WindowManagerObserver, observers_, OnSplitViewModeExit()); | 329 FOR_EACH_OBSERVER(WindowManagerObserver, observers_, OnSplitViewModeExit()); |
302 } | 330 } |
303 // If |window| does not have the size of the work-area, then make sure it is | 331 // If |window| does not have the size of the work-area, then make sure it is |
304 // resized. | 332 // resized. |
305 const gfx::Size work_area = | 333 const gfx::Size work_area = |
306 gfx::Screen::GetNativeScreen()->GetPrimaryDisplay().work_area().size(); | 334 gfx::Screen::GetNativeScreen()->GetPrimaryDisplay().work_area().size(); |
307 if (window->GetTargetBounds().size() != work_area) { | 335 |
336 // Resize to the screen bounds only if the window is maximize-able, and | |
337 // is not already maximized | |
338 if (window->GetTargetBounds().size() != work_area && | |
339 CanWindowMaximize(window)) { | |
308 const gfx::Rect& window_bounds = window->bounds(); | 340 const gfx::Rect& window_bounds = window->bounds(); |
309 const gfx::Rect desired_bounds(work_area); | 341 const gfx::Rect desired_bounds(work_area); |
310 gfx::Transform transform; | 342 gfx::Transform transform; |
311 transform.Translate(desired_bounds.x() - window_bounds.x(), | 343 transform.Translate(desired_bounds.x() - window_bounds.x(), |
312 desired_bounds.y() - window_bounds.y()); | 344 desired_bounds.y() - window_bounds.y()); |
313 transform.Scale(desired_bounds.width() / window_bounds.width(), | 345 transform.Scale(desired_bounds.width() / window_bounds.width(), |
314 desired_bounds.height() / window_bounds.height()); | 346 desired_bounds.height() / window_bounds.height()); |
315 ui::ScopedLayerAnimationSettings settings(window->layer()->GetAnimator()); | 347 ui::ScopedLayerAnimationSettings settings(window->layer()->GetAnimator()); |
316 settings.SetPreemptionStrategy( | 348 settings.SetPreemptionStrategy( |
317 ui::LayerAnimator::IMMEDIATELY_ANIMATE_TO_NEW_TARGET); | 349 ui::LayerAnimator::IMMEDIATELY_ANIMATE_TO_NEW_TARGET); |
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
453 DCHECK(!instance); | 485 DCHECK(!instance); |
454 } | 486 } |
455 | 487 |
456 // static | 488 // static |
457 WindowManager* WindowManager::Get() { | 489 WindowManager* WindowManager::Get() { |
458 DCHECK(instance); | 490 DCHECK(instance); |
459 return instance; | 491 return instance; |
460 } | 492 } |
461 | 493 |
462 } // namespace athena | 494 } // namespace athena |
OLD | NEW |