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 = nullptr; | 36 class WindowManagerImpl* instance = nullptr; |
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); |
| 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 ~AthenaContainerLayoutManager() override; | 60 ~AthenaContainerLayoutManager() override; |
49 | 61 |
50 private: | 62 private: |
51 // aura::LayoutManager: | 63 // aura::LayoutManager: |
52 void OnWindowResized() override; | 64 void OnWindowResized() override; |
(...skipping 28 matching lines...) Expand all Loading... |
81 instance->split_view_controller_->left_window()->bounds().size(); | 93 instance->split_view_controller_->left_window()->bounds().size(); |
82 } | 94 } |
83 | 95 |
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 if (CanWindowMaximize(window)) |
95 window->SetBounds(gfx::Rect(work_area)); | 107 window->SetBounds(gfx::Rect(work_area)); |
96 } else { | 108 } else if (CanWindowMaximize(window)) { |
97 window->SetBounds(gfx::Rect(work_area)); | 109 window->SetBounds(gfx::Rect(work_area)); |
98 } | 110 } |
99 } | 111 } |
100 } | 112 } |
101 | 113 |
102 void AthenaContainerLayoutManager::OnWindowAddedToLayout(aura::Window* child) { | 114 void AthenaContainerLayoutManager::OnWindowAddedToLayout(aura::Window* child) { |
103 // TODO(oshima): Split view modes needs to take the transient window into | 115 // TODO(oshima): Split view modes needs to take the transient window into |
104 // account. | 116 // account. |
105 if (wm::GetTransientParent(child)) { | 117 if (wm::GetTransientParent(child)) { |
106 wm::TransientWindowManager::Get(child) | 118 wm::TransientWindowManager::Get(child) |
107 ->set_parent_controls_visibility(true); | 119 ->set_parent_controls_visibility(true); |
108 } | 120 } |
109 } | 121 } |
110 | 122 |
111 void AthenaContainerLayoutManager::OnWillRemoveWindowFromLayout( | 123 void AthenaContainerLayoutManager::OnWillRemoveWindowFromLayout( |
112 aura::Window* child) { | 124 aura::Window* child) { |
113 } | 125 } |
114 | 126 |
115 void AthenaContainerLayoutManager::OnWindowRemovedFromLayout( | 127 void AthenaContainerLayoutManager::OnWindowRemovedFromLayout( |
116 aura::Window* child) { | 128 aura::Window* child) { |
117 } | 129 } |
118 | 130 |
119 void AthenaContainerLayoutManager::OnChildWindowVisibilityChanged( | 131 void AthenaContainerLayoutManager::OnChildWindowVisibilityChanged( |
120 aura::Window* child, | 132 aura::Window* child, |
121 bool visible) { | 133 bool visible) { |
| 134 if (visible && CanWindowMaximize(child)) { |
| 135 // Make sure we're resizing a window that actually exists in the window list |
| 136 // to avoid resizing the divider in the split mode. |
| 137 if(instance->window_list_provider_->IsWindowInList(child)) { |
| 138 child->SetBounds( |
| 139 gfx::Screen::GetNativeScreen()->GetPrimaryDisplay().work_area()); |
| 140 } |
| 141 } |
122 } | 142 } |
123 | 143 |
124 void AthenaContainerLayoutManager::SetChildBounds( | 144 void AthenaContainerLayoutManager::SetChildBounds( |
125 aura::Window* child, | 145 aura::Window* child, |
126 const gfx::Rect& requested_bounds) { | 146 const gfx::Rect& requested_bounds) { |
127 if (!requested_bounds.IsEmpty()) | 147 if (!requested_bounds.IsEmpty()) |
128 SetChildBoundsDirect(child, requested_bounds); | 148 SetChildBoundsDirect(child, requested_bounds); |
129 } | 149 } |
130 | 150 |
131 WindowManagerImpl::WindowManagerImpl() { | 151 WindowManagerImpl::WindowManagerImpl() { |
(...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
284 wm::ActivateWindow(window); | 304 wm::ActivateWindow(window); |
285 | 305 |
286 if (split_view_controller_->IsSplitViewModeActive()) { | 306 if (split_view_controller_->IsSplitViewModeActive()) { |
287 split_view_controller_->DeactivateSplitMode(); | 307 split_view_controller_->DeactivateSplitMode(); |
288 FOR_EACH_OBSERVER(WindowManagerObserver, observers_, OnSplitViewModeExit()); | 308 FOR_EACH_OBSERVER(WindowManagerObserver, observers_, OnSplitViewModeExit()); |
289 } | 309 } |
290 // If |window| does not have the size of the work-area, then make sure it is | 310 // If |window| does not have the size of the work-area, then make sure it is |
291 // resized. | 311 // resized. |
292 const gfx::Size work_area = | 312 const gfx::Size work_area = |
293 gfx::Screen::GetNativeScreen()->GetPrimaryDisplay().work_area().size(); | 313 gfx::Screen::GetNativeScreen()->GetPrimaryDisplay().work_area().size(); |
294 if (window->GetTargetBounds().size() != work_area) { | 314 |
| 315 // Resize to the screen bounds only if the window is maximize-able, and |
| 316 // is not already maximized |
| 317 if (window->GetTargetBounds().size() != work_area && |
| 318 CanWindowMaximize(window)) { |
295 const gfx::Rect& window_bounds = window->bounds(); | 319 const gfx::Rect& window_bounds = window->bounds(); |
296 const gfx::Rect desired_bounds(work_area); | 320 const gfx::Rect desired_bounds(work_area); |
297 gfx::Transform transform; | 321 gfx::Transform transform; |
298 transform.Translate(desired_bounds.x() - window_bounds.x(), | 322 transform.Translate(desired_bounds.x() - window_bounds.x(), |
299 desired_bounds.y() - window_bounds.y()); | 323 desired_bounds.y() - window_bounds.y()); |
300 transform.Scale(desired_bounds.width() / window_bounds.width(), | 324 transform.Scale(desired_bounds.width() / window_bounds.width(), |
301 desired_bounds.height() / window_bounds.height()); | 325 desired_bounds.height() / window_bounds.height()); |
302 ui::ScopedLayerAnimationSettings settings(window->layer()->GetAnimator()); | 326 ui::ScopedLayerAnimationSettings settings(window->layer()->GetAnimator()); |
303 settings.SetPreemptionStrategy( | 327 settings.SetPreemptionStrategy( |
304 ui::LayerAnimator::IMMEDIATELY_ANIMATE_TO_NEW_TARGET); | 328 ui::LayerAnimator::IMMEDIATELY_ANIMATE_TO_NEW_TARGET); |
(...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
465 DCHECK(!instance); | 489 DCHECK(!instance); |
466 } | 490 } |
467 | 491 |
468 // static | 492 // static |
469 WindowManager* WindowManager::Get() { | 493 WindowManager* WindowManager::Get() { |
470 DCHECK(instance); | 494 DCHECK(instance); |
471 return instance; | 495 return instance; |
472 } | 496 } |
473 | 497 |
474 } // namespace athena | 498 } // namespace athena |
OLD | NEW |