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