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