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