| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 "mash/wm/window_layout.h" | 5 #include "mash/wm/window_layout.h" |
| 6 | 6 |
| 7 #include <stdint.h> | 7 #include <stdint.h> |
| 8 | 8 |
| 9 #include "components/mus/public/cpp/property_type_converters.h" | 9 #include "components/mus/public/cpp/property_type_converters.h" |
| 10 #include "components/mus/public/cpp/window.h" | 10 #include "components/mus/public/cpp/window.h" |
| (...skipping 17 matching lines...) Expand all Loading... |
| 28 // Maximized/fullscreen/presentation windows should be sized to the bounds | 28 // Maximized/fullscreen/presentation windows should be sized to the bounds |
| 29 // of the container. | 29 // of the container. |
| 30 // If a window has bounds set by the user, those should be respected as long | 30 // If a window has bounds set by the user, those should be respected as long |
| 31 // as they meet certain constraints (e.g. visible). | 31 // as they meet certain constraints (e.g. visible). |
| 32 // TODO(beng): transient windows: | 32 // TODO(beng): transient windows: |
| 33 // Top level non-transient windows with no bounds but a preferred size should | 33 // Top level non-transient windows with no bounds but a preferred size should |
| 34 // opened centered within the work area. | 34 // opened centered within the work area. |
| 35 // Transient windows should be opened centered within their parent. | 35 // Transient windows should be opened centered within their parent. |
| 36 | 36 |
| 37 switch (show_state) { | 37 switch (show_state) { |
| 38 case mus::mojom::SHOW_STATE_MAXIMIZED: | 38 case mus::mojom::ShowState::MAXIMIZED: |
| 39 case mus::mojom::SHOW_STATE_IMMERSIVE: | 39 case mus::mojom::ShowState::IMMERSIVE: |
| 40 case mus::mojom::SHOW_STATE_PRESENTATION: | 40 case mus::mojom::ShowState::PRESENTATION: |
| 41 FitToContainer(window); | 41 FitToContainer(window); |
| 42 break; | 42 break; |
| 43 case mus::mojom::SHOW_STATE_RESTORED: { | 43 case mus::mojom::ShowState::RESTORED: { |
| 44 if (!user_set_bounds.IsEmpty()) { | 44 if (!user_set_bounds.IsEmpty()) { |
| 45 // If the bounds are unchanged, this will do nothing. | 45 // If the bounds are unchanged, this will do nothing. |
| 46 window->SetBounds(user_set_bounds); | 46 window->SetBounds(user_set_bounds); |
| 47 } else if (!preferred_size.IsEmpty()) { | 47 } else if (!preferred_size.IsEmpty()) { |
| 48 CenterWindow(window, preferred_size); | 48 CenterWindow(window, preferred_size); |
| 49 } | 49 } |
| 50 } | 50 } |
| 51 case mus::mojom::SHOW_STATE_MINIMIZED: | 51 case mus::mojom::ShowState::MINIMIZED: |
| 52 break; | 52 break; |
| 53 default: | 53 default: |
| 54 NOTREACHED(); | 54 NOTREACHED(); |
| 55 break; | 55 break; |
| 56 } | 56 } |
| 57 } | 57 } |
| 58 | 58 |
| 59 void WindowLayout::OnWindowSharedPropertyChanged( | 59 void WindowLayout::OnWindowSharedPropertyChanged( |
| 60 mus::Window* window, | 60 mus::Window* window, |
| 61 const std::string& name, | 61 const std::string& name, |
| 62 const std::vector<uint8_t>* old_data, | 62 const std::vector<uint8_t>* old_data, |
| 63 const std::vector<uint8_t>* new_data) { | 63 const std::vector<uint8_t>* new_data) { |
| 64 // TODO(sky): this feels like the wrong place for this logic. Find a better | 64 // TODO(sky): this feels like the wrong place for this logic. Find a better |
| 65 // place. | 65 // place. |
| 66 if (name == mus::mojom::WindowManager::kShowState_Property && | 66 if (name == mus::mojom::WindowManager::kShowState_Property && |
| 67 GetWindowShowState(window) == mus::mojom::SHOW_STATE_MAXIMIZED) { | 67 GetWindowShowState(window) == mus::mojom::ShowState::MAXIMIZED) { |
| 68 SetRestoreBounds(window, window->bounds()); | 68 SetRestoreBounds(window, window->bounds()); |
| 69 } | 69 } |
| 70 LayoutManager::OnWindowSharedPropertyChanged(window, name, old_data, | 70 LayoutManager::OnWindowSharedPropertyChanged(window, name, old_data, |
| 71 new_data); | 71 new_data); |
| 72 } | 72 } |
| 73 | 73 |
| 74 void WindowLayout::FitToContainer(mus::Window* window) { | 74 void WindowLayout::FitToContainer(mus::Window* window) { |
| 75 window->SetBounds(gfx::Rect(owner()->bounds().size())); | 75 window->SetBounds(gfx::Rect(owner()->bounds().size())); |
| 76 } | 76 } |
| 77 | 77 |
| 78 void WindowLayout::CenterWindow(mus::Window* window, | 78 void WindowLayout::CenterWindow(mus::Window* window, |
| 79 const gfx::Size& preferred_size) { | 79 const gfx::Size& preferred_size) { |
| 80 const gfx::Rect bounds( | 80 const gfx::Rect bounds( |
| 81 (owner()->bounds().width() - preferred_size.width()) / 2, | 81 (owner()->bounds().width() - preferred_size.width()) / 2, |
| 82 (owner()->bounds().height() - preferred_size.height()) / 2, | 82 (owner()->bounds().height() - preferred_size.height()) / 2, |
| 83 preferred_size.width(), preferred_size.height()); | 83 preferred_size.width(), preferred_size.height()); |
| 84 window->SetBounds(bounds); | 84 window->SetBounds(bounds); |
| 85 } | 85 } |
| 86 | 86 |
| 87 } // namespace wm | 87 } // namespace wm |
| 88 } // namespace mash | 88 } // namespace mash |
| OLD | NEW |