| 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/shelf_layout_manager.h" | 5 #include "mash/wm/shelf_layout_manager.h" |
| 6 | 6 |
| 7 #include "components/mus/public/cpp/window.h" | 7 #include "components/mus/public/cpp/window.h" |
| 8 #include "mash/wm/property_util.h" | 8 #include "mash/wm/property_util.h" |
| 9 #include "mash/wm/public/interfaces/ash_window_type.mojom.h" | 9 #include "mash/wm/public/interfaces/ash_window_type.mojom.h" |
| 10 #include "mash/wm/shelf_layout_manager_delegate.h" |
| 10 #include "ui/gfx/geometry/rect.h" | 11 #include "ui/gfx/geometry/rect.h" |
| 11 | 12 |
| 12 namespace mash { | 13 namespace mash { |
| 13 namespace wm { | 14 namespace wm { |
| 14 | 15 |
| 15 ShelfLayoutManager::ShelfLayoutManager(mus::Window* owner) | 16 ShelfLayoutManager::ShelfLayoutManager(mus::Window* owner, |
| 17 ShelfLayoutManagerDelegate* delegate) |
| 16 : LayoutManager(owner), | 18 : LayoutManager(owner), |
| 19 delegate_(delegate), |
| 17 alignment_(shelf::mojom::Alignment::BOTTOM), | 20 alignment_(shelf::mojom::Alignment::BOTTOM), |
| 18 auto_hide_behavior_(shelf::mojom::AutoHideBehavior::NEVER) { | 21 auto_hide_behavior_(shelf::mojom::AutoHideBehavior::NEVER) { |
| 19 AddLayoutProperty(mus::mojom::WindowManager::kPreferredSize_Property); | 22 AddLayoutProperty(mus::mojom::WindowManager::kPreferredSize_Property); |
| 20 } | 23 } |
| 21 | 24 |
| 22 ShelfLayoutManager::~ShelfLayoutManager() {} | 25 ShelfLayoutManager::~ShelfLayoutManager() {} |
| 23 | 26 |
| 24 mus::Window* ShelfLayoutManager::GetShelfWindow() { | 27 mus::Window* ShelfLayoutManager::GetShelfWindow() { |
| 25 for (mus::Window* child : owner()->children()) { | 28 for (mus::Window* child : owner()->children()) { |
| 26 if (GetAshWindowType(child) == mojom::AshWindowType::SHELF) | 29 if (GetAshWindowType(child) == mojom::AshWindowType::SHELF) |
| 27 return child; | 30 return child; |
| 28 } | 31 } |
| 29 return nullptr; | 32 return nullptr; |
| 30 } | 33 } |
| 31 | 34 |
| 35 void ShelfLayoutManager::SetAlignment(shelf::mojom::Alignment alignment) { |
| 36 if (alignment_ == alignment) |
| 37 return; |
| 38 |
| 39 alignment_ = alignment; |
| 40 for (mus::Window* window : owner()->children()) |
| 41 LayoutWindow(window); |
| 42 } |
| 43 |
| 44 void ShelfLayoutManager::SetAutoHideBehavior( |
| 45 shelf::mojom::AutoHideBehavior auto_hide) { |
| 46 if (auto_hide_behavior_ == auto_hide) |
| 47 return; |
| 48 |
| 49 auto_hide_behavior_ = auto_hide; |
| 50 NOTIMPLEMENTED(); |
| 51 } |
| 52 |
| 32 // We explicitly don't make assertions about the number of children in this | 53 // We explicitly don't make assertions about the number of children in this |
| 33 // layout as the number of children can vary when the application providing the | 54 // layout as the number of children can vary when the application providing the |
| 34 // shelf restarts. | 55 // shelf restarts. |
| 35 | 56 |
| 36 void ShelfLayoutManager::LayoutWindow(mus::Window* window) { | 57 void ShelfLayoutManager::LayoutWindow(mus::Window* window) { |
| 37 if (GetAshWindowType(window) != mojom::AshWindowType::SHELF) { | 58 if (GetAshWindowType(window) != mojom::AshWindowType::SHELF) { |
| 38 // Phantom windows end up in this container, ignore them. | 59 // Phantom windows end up in this container, ignore them. |
| 39 return; | 60 return; |
| 40 } | 61 } |
| 41 gfx::Size size = GetWindowPreferredSize(window); | 62 gfx::Size size = GetWindowPreferredSize(window); |
| 42 | 63 |
| 43 if (alignment_ == shelf::mojom::Alignment::BOTTOM) { | 64 if (alignment_ == shelf::mojom::Alignment::BOTTOM) { |
| 44 const int y = owner()->bounds().height() - size.height(); | 65 const int y = owner()->bounds().height() - size.height(); |
| 45 size.set_width(owner()->bounds().width()); | 66 size.set_width(owner()->bounds().width()); |
| 46 window->SetBounds(gfx::Rect(0, y, size.width(), size.height())); | 67 window->SetBounds(gfx::Rect(0, y, size.width(), size.height())); |
| 47 } else { | 68 } else { |
| 48 const int x = (alignment_ == shelf::mojom::Alignment::LEFT) | 69 const int x = (alignment_ == shelf::mojom::Alignment::LEFT) |
| 49 ? 0 | 70 ? 0 |
| 50 : (owner()->bounds().width() - size.width()); | 71 : (owner()->bounds().width() - size.width()); |
| 51 size.set_height(owner()->bounds().height()); | 72 size.set_height(owner()->bounds().height()); |
| 52 window->SetBounds(gfx::Rect(x, 0, size.width(), size.height())); | 73 window->SetBounds(gfx::Rect(x, 0, size.width(), size.height())); |
| 53 } | 74 } |
| 54 } | 75 } |
| 55 | 76 |
| 56 void ShelfLayoutManager::SetAlignment(shelf::mojom::Alignment alignment) { | 77 void ShelfLayoutManager::WindowAdded(mus::Window* window) { |
| 57 if (alignment_ == alignment) | 78 if (GetAshWindowType(window) == mojom::AshWindowType::SHELF) |
| 58 return; | 79 delegate_->OnShelfWindowAvailable(); |
| 59 | |
| 60 alignment_ = alignment; | |
| 61 for (mus::Window* window : owner()->children()) | |
| 62 LayoutWindow(window); | |
| 63 } | |
| 64 | |
| 65 void ShelfLayoutManager::SetAutoHideBehavior( | |
| 66 shelf::mojom::AutoHideBehavior auto_hide) { | |
| 67 if (auto_hide_behavior_ == auto_hide) | |
| 68 return; | |
| 69 | |
| 70 auto_hide_behavior_ = auto_hide; | |
| 71 NOTIMPLEMENTED(); | |
| 72 } | 80 } |
| 73 | 81 |
| 74 } // namespace wm | 82 } // namespace wm |
| 75 } // namespace mash | 83 } // namespace mash |
| OLD | NEW |