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.h" | 5 #include "mash/wm/shelf_layout.h" |
6 | 6 |
7 #include "components/mus/public/cpp/property_type_converters.h" | 7 #include "components/mus/public/cpp/property_type_converters.h" |
8 #include "components/mus/public/cpp/window.h" | 8 #include "components/mus/public/cpp/window.h" |
9 #include "components/mus/public/cpp/window_property.h" | 9 #include "components/mus/public/cpp/window_property.h" |
10 #include "mash/wm/property_util.h" | 10 #include "mash/wm/property_util.h" |
11 #include "mash/wm/public/interfaces/ash_window_type.mojom.h" | 11 #include "mash/wm/public/interfaces/ash_window_type.mojom.h" |
12 #include "ui/gfx/geometry/rect.h" | 12 #include "ui/gfx/geometry/rect.h" |
13 | 13 |
14 namespace mash { | 14 namespace mash { |
15 namespace wm { | 15 namespace wm { |
16 | 16 |
17 namespace { | 17 namespace { |
18 | 18 |
19 mojom::AshWindowType GetAshWindowType(const mus::Window* window) { | 19 mojom::AshWindowType GetAshWindowType(const mus::Window* window) { |
20 if (!window->HasSharedProperty(mojom::kAshWindowType_Property)) | 20 if (!window->HasSharedProperty(mojom::kAshWindowType_Property)) |
21 return mojom::AshWindowType::COUNT; | 21 return mojom::AshWindowType::COUNT; |
22 | 22 |
23 return static_cast<mojom::AshWindowType>( | 23 return static_cast<mojom::AshWindowType>( |
24 window->GetSharedProperty<int32_t>(mojom::kAshWindowType_Property)); | 24 window->GetSharedProperty<int32_t>(mojom::kAshWindowType_Property)); |
25 } | 25 } |
26 | 26 |
27 } // namespace | 27 } // namespace |
28 | 28 |
29 ShelfLayout::ShelfLayout(mus::Window* owner) : LayoutManager(owner) { | 29 ShelfLayout::ShelfLayout(mus::Window* owner) |
| 30 : LayoutManager(owner), |
| 31 alignment_(mojom::ShelfAlignment::SHELF_ALIGNMENT_BOTTOM), |
| 32 auto_hide_(mojom::ShelfAutoHideBehavior::SHELF_AUTO_HIDE_BEHAVIOR_NEVER) { |
30 AddLayoutProperty(mus::mojom::WindowManager::kPreferredSize_Property); | 33 AddLayoutProperty(mus::mojom::WindowManager::kPreferredSize_Property); |
31 } | 34 } |
32 | 35 |
33 ShelfLayout::~ShelfLayout() {} | 36 ShelfLayout::~ShelfLayout() {} |
34 | 37 |
35 // We explicitly don't make assertions about the number of children in this | 38 // We explicitly don't make assertions about the number of children in this |
36 // layout as the number of children can vary when the application providing the | 39 // layout as the number of children can vary when the application providing the |
37 // shelf restarts. | 40 // shelf restarts. |
38 | 41 |
39 void ShelfLayout::LayoutWindow(mus::Window* window) { | 42 void ShelfLayout::LayoutWindow(mus::Window* window) { |
40 // TODO(msw): Support additional shelf alignments and RTL UI. | 43 // TODO(msw): Support additional shelf alignments and RTL UI. |
| 44 const mojom::AshWindowType ash_window_type = GetAshWindowType(window); |
41 gfx::Size size = GetWindowPreferredSize(window); | 45 gfx::Size size = GetWindowPreferredSize(window); |
42 const int y = owner()->bounds().height() - size.height(); | 46 |
43 const mojom::AshWindowType ash_window_type = GetAshWindowType(window); | 47 if (alignment_ == mojom::ShelfAlignment::SHELF_ALIGNMENT_BOTTOM) { |
44 if (ash_window_type == mojom::AshWindowType::SHELF) { | 48 const int y = owner()->bounds().height() - size.height(); |
45 size.set_width(owner()->bounds().width()); | 49 if (ash_window_type == mojom::AshWindowType::SHELF) { |
46 window->SetBounds(gfx::Rect(0, y, size.width(), size.height())); | 50 size.set_width(owner()->bounds().width()); |
47 } else if (ash_window_type == mojom::AshWindowType::STATUS_AREA) { | 51 window->SetBounds(gfx::Rect(0, y, size.width(), size.height())); |
48 window->SetBounds(gfx::Rect(owner()->bounds().width() - size.width(), y, | 52 LOG(ERROR) << "MSW Layout Shelf Bottom " << window->bounds().ToString(); |
49 size.width(), size.height())); | 53 } else if (ash_window_type == mojom::AshWindowType::STATUS_AREA) { |
| 54 window->SetBounds(gfx::Rect(owner()->bounds().width() - size.width(), y, |
| 55 size.width(), size.height())); |
| 56 LOG(ERROR) << "MSW Layout Status Bottom " << window->bounds().ToString(); |
| 57 } else { |
| 58 NOTREACHED() << "Unknown window in USER_SHELF container."; |
| 59 } |
50 } else { | 60 } else { |
51 NOTREACHED() << "Unknown window in USER_SHELF container."; | 61 |
| 62 // TODO(msw): Use actual preferred sizes (need to update)... |
| 63 size = gfx::Size(47, 150); |
| 64 |
| 65 // TODO(msw): Why does the status area sometimes fail to align left? |
| 66 const int x = (alignment_ == mojom::ShelfAlignment::SHELF_ALIGNMENT_LEFT) ? |
| 67 0 : (owner()->bounds().width() - size.width()); |
| 68 if (ash_window_type == mojom::AshWindowType::SHELF) { |
| 69 size.set_height(owner()->bounds().height()); |
| 70 window->SetBounds(gfx::Rect(x, 0, size.width(), size.height())); |
| 71 LOG(ERROR) << "MSW Layout Shelf Side " << window->bounds().ToString(); |
| 72 } else if (ash_window_type == mojom::AshWindowType::STATUS_AREA) { |
| 73 window->SetBounds(gfx::Rect(x, owner()->bounds().height() - size.height(), |
| 74 size.width(), size.height())); |
| 75 LOG(ERROR) << "MSW Layout Status Side " << window->bounds().ToString(); |
| 76 } else { |
| 77 NOTREACHED() << "Unknown window in USER_SHELF container."; |
| 78 } |
52 } | 79 } |
53 } | 80 } |
54 | 81 |
| 82 void ShelfLayout::SetAlignment(mojom::ShelfAlignment alignment) { |
| 83 LOG(ERROR) << "MSW ShelfLayout::SetAlignment"; |
| 84 if (alignment_ == alignment) |
| 85 return; |
| 86 |
| 87 // TODO(msw): Check against SHELF_ALIGNMENT_TOP if it's included in the enum. |
| 88 // if (mojom::SHELF_ALIGNMENT_TOP == alignment) |
| 89 // NOTREACHED() << "Unknown window in USER_SHELF container."; |
| 90 |
| 91 alignment_ = alignment; |
| 92 for (auto window : owner()->children()) |
| 93 LayoutWindow(window); |
| 94 } |
| 95 |
| 96 void ShelfLayout::SetAutoHideBehavior(mojom::ShelfAutoHideBehavior auto_hide) { |
| 97 LOG(ERROR) << "MSW ShelfLayout::SetAutoHideBehavior"; |
| 98 if (auto_hide_ == auto_hide) |
| 99 return; |
| 100 |
| 101 auto_hide_ = auto_hide; |
| 102 // TODO(msw|jamescook): Implement... |
| 103 } |
| 104 |
55 } // namespace wm | 105 } // namespace wm |
56 } // namespace mash | 106 } // namespace mash |
OLD | NEW |