| 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/status_layout_manager.h" | 5 #include "ash/mus/status_layout_manager.h" |
| 6 | 6 |
| 7 #include "ash/mus/property_util.h" | 7 #include "ash/mus/property_util.h" |
| 8 #include "ash/public/interfaces/ash_window_type.mojom.h" | 8 #include "ash/public/interfaces/ash_window_type.mojom.h" |
| 9 #include "services/ui/public/cpp/window.h" | 9 #include "services/ui/public/cpp/window.h" |
| 10 #include "ui/gfx/geometry/rect.h" | 10 #include "ui/gfx/geometry/rect.h" |
| 11 | 11 |
| 12 namespace ash { | 12 namespace ash { |
| 13 namespace mus { | 13 namespace mus { |
| 14 | 14 |
| 15 StatusLayoutManager::StatusLayoutManager(::ui::Window* owner) | 15 StatusLayoutManager::StatusLayoutManager(ui::Window* owner) |
| 16 : LayoutManager(owner), | 16 : LayoutManager(owner), |
| 17 alignment_(mash::shelf::mojom::Alignment::BOTTOM), | 17 alignment_(mash::shelf::mojom::Alignment::BOTTOM), |
| 18 auto_hide_behavior_(mash::shelf::mojom::AutoHideBehavior::NEVER) { | 18 auto_hide_behavior_(mash::shelf::mojom::AutoHideBehavior::NEVER) { |
| 19 AddLayoutProperty(::ui::mojom::WindowManager::kPreferredSize_Property); | 19 AddLayoutProperty(ui::mojom::WindowManager::kPreferredSize_Property); |
| 20 } | 20 } |
| 21 | 21 |
| 22 StatusLayoutManager::~StatusLayoutManager() {} | 22 StatusLayoutManager::~StatusLayoutManager() {} |
| 23 | 23 |
| 24 // We explicitly don't make assertions about the number of children in this | 24 // 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 | 25 // layout as the number of children can vary when the application providing the |
| 26 // status area restarts. | 26 // status area restarts. |
| 27 | 27 |
| 28 void StatusLayoutManager::LayoutWindow(::ui::Window* window) { | 28 void StatusLayoutManager::LayoutWindow(ui::Window* window) { |
| 29 if (GetAshWindowType(window) != mojom::AshWindowType::STATUS_AREA) { | 29 if (GetAshWindowType(window) != mojom::AshWindowType::STATUS_AREA) { |
| 30 // TODO(jamescook): Layout for notifications and other windows. | 30 // TODO(jamescook): Layout for notifications and other windows. |
| 31 NOTIMPLEMENTED() << "Non-status-area window needs layout."; | 31 NOTIMPLEMENTED() << "Non-status-area window needs layout."; |
| 32 return; | 32 return; |
| 33 } | 33 } |
| 34 gfx::Size size = GetWindowPreferredSize(window); | 34 gfx::Size size = GetWindowPreferredSize(window); |
| 35 if (alignment_ == mash::shelf::mojom::Alignment::BOTTOM) { | 35 if (alignment_ == mash::shelf::mojom::Alignment::BOTTOM) { |
| 36 const int y = owner()->bounds().height() - size.height(); | 36 const int y = owner()->bounds().height() - size.height(); |
| 37 // TODO(msw): Place the status area widget on the left for RTL UIs. | 37 // TODO(msw): Place the status area widget on the left for RTL UIs. |
| 38 window->SetBounds(gfx::Rect(owner()->bounds().width() - size.width(), y, | 38 window->SetBounds(gfx::Rect(owner()->bounds().width() - size.width(), y, |
| 39 size.width(), size.height())); | 39 size.width(), size.height())); |
| 40 } else { | 40 } else { |
| 41 const int x = (alignment_ == mash::shelf::mojom::Alignment::LEFT) | 41 const int x = (alignment_ == mash::shelf::mojom::Alignment::LEFT) |
| 42 ? 0 | 42 ? 0 |
| 43 : (owner()->bounds().width() - size.width()); | 43 : (owner()->bounds().width() - size.width()); |
| 44 window->SetBounds(gfx::Rect(x, owner()->bounds().height() - size.height(), | 44 window->SetBounds(gfx::Rect(x, owner()->bounds().height() - size.height(), |
| 45 size.width(), size.height())); | 45 size.width(), size.height())); |
| 46 } | 46 } |
| 47 } | 47 } |
| 48 | 48 |
| 49 void StatusLayoutManager::SetAlignment( | 49 void StatusLayoutManager::SetAlignment( |
| 50 mash::shelf::mojom::Alignment alignment) { | 50 mash::shelf::mojom::Alignment alignment) { |
| 51 if (alignment_ == alignment) | 51 if (alignment_ == alignment) |
| 52 return; | 52 return; |
| 53 | 53 |
| 54 alignment_ = alignment; | 54 alignment_ = alignment; |
| 55 for (::ui::Window* window : owner()->children()) | 55 for (ui::Window* window : owner()->children()) |
| 56 LayoutWindow(window); | 56 LayoutWindow(window); |
| 57 } | 57 } |
| 58 | 58 |
| 59 void StatusLayoutManager::SetAutoHideBehavior( | 59 void StatusLayoutManager::SetAutoHideBehavior( |
| 60 mash::shelf::mojom::AutoHideBehavior auto_hide) { | 60 mash::shelf::mojom::AutoHideBehavior auto_hide) { |
| 61 if (auto_hide_behavior_ == auto_hide) | 61 if (auto_hide_behavior_ == auto_hide) |
| 62 return; | 62 return; |
| 63 | 63 |
| 64 auto_hide_behavior_ = auto_hide; | 64 auto_hide_behavior_ = auto_hide; |
| 65 NOTIMPLEMENTED(); | 65 NOTIMPLEMENTED(); |
| 66 } | 66 } |
| 67 | 67 |
| 68 } // namespace mus | 68 } // namespace mus |
| 69 } // namespace ash | 69 } // namespace ash |
| OLD | NEW |