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/status_layout_manager.h" |
6 | 6 |
7 #include "components/mus/public/cpp/property_type_converters.h" | |
8 #include "components/mus/public/cpp/window.h" | 7 #include "components/mus/public/cpp/window.h" |
9 #include "components/mus/public/cpp/window_property.h" | |
10 #include "mash/wm/property_util.h" | 8 #include "mash/wm/property_util.h" |
11 #include "mash/wm/public/interfaces/ash_window_type.mojom.h" | 9 #include "mash/wm/public/interfaces/ash_window_type.mojom.h" |
12 #include "ui/gfx/geometry/rect.h" | 10 #include "ui/gfx/geometry/rect.h" |
13 | 11 |
14 namespace mash { | 12 namespace mash { |
15 namespace wm { | 13 namespace wm { |
16 | 14 |
17 namespace { | 15 StatusLayoutManager::StatusLayoutManager(mus::Window* owner) |
18 | |
19 mojom::AshWindowType GetAshWindowType(const mus::Window* window) { | |
20 if (!window->HasSharedProperty(mojom::kAshWindowType_Property)) | |
21 return mojom::AshWindowType::COUNT; | |
22 | |
23 return static_cast<mojom::AshWindowType>( | |
24 window->GetSharedProperty<int32_t>(mojom::kAshWindowType_Property)); | |
25 } | |
26 | |
27 } // namespace | |
28 | |
29 ShelfLayout::ShelfLayout(mus::Window* owner) | |
30 : LayoutManager(owner), | 16 : LayoutManager(owner), |
31 alignment_(mash::shelf::mojom::Alignment::BOTTOM), | 17 alignment_(mash::shelf::mojom::Alignment::BOTTOM), |
32 auto_hide_behavior_(mash::shelf::mojom::AutoHideBehavior::NEVER) { | 18 auto_hide_behavior_(mash::shelf::mojom::AutoHideBehavior::NEVER) { |
33 AddLayoutProperty(mus::mojom::WindowManager::kPreferredSize_Property); | 19 AddLayoutProperty(mus::mojom::WindowManager::kPreferredSize_Property); |
34 } | 20 } |
35 | 21 |
36 ShelfLayout::~ShelfLayout() {} | 22 StatusLayoutManager::~StatusLayoutManager() {} |
37 | 23 |
38 // 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 |
39 // 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 |
40 // shelf restarts. | 26 // status area restarts. |
41 | 27 |
42 void ShelfLayout::LayoutWindow(mus::Window* window) { | 28 void StatusLayoutManager::LayoutWindow(mus::Window* window) { |
43 const mojom::AshWindowType ash_window_type = GetAshWindowType(window); | 29 const mojom::AshWindowType ash_window_type = GetAshWindowType(window); |
msw
2016/05/05 21:20:26
nit: inline this in the conditional below.
James Cook
2016/05/05 22:09:09
Done.
| |
44 gfx::Size size = GetWindowPreferredSize(window); | 30 gfx::Size size = GetWindowPreferredSize(window); |
msw
2016/05/05 21:20:26
nit: move this after the early return.
James Cook
2016/05/05 22:09:09
Done.
| |
45 | 31 |
32 if (ash_window_type != mojom::AshWindowType::STATUS_AREA) { | |
33 // TODO(jamescook): Layout for notifications and other windows. | |
34 NOTIMPLEMENTED() << "Non-status-area window needs layout."; | |
35 return; | |
36 } | |
46 if (alignment_ == mash::shelf::mojom::Alignment::BOTTOM) { | 37 if (alignment_ == mash::shelf::mojom::Alignment::BOTTOM) { |
47 const int y = owner()->bounds().height() - size.height(); | 38 const int y = owner()->bounds().height() - size.height(); |
48 if (ash_window_type == mojom::AshWindowType::SHELF) { | 39 // TODO(msw): Place the status area widget on the left for RTL UIs. |
49 size.set_width(owner()->bounds().width()); | 40 window->SetBounds(gfx::Rect(owner()->bounds().width() - size.width(), y, |
50 window->SetBounds(gfx::Rect(0, y, size.width(), size.height())); | 41 size.width(), size.height())); |
51 } else if (ash_window_type == mojom::AshWindowType::STATUS_AREA) { | |
52 // TODO(msw): Place the status area on the left for RTL UIs. | |
53 window->SetBounds(gfx::Rect(owner()->bounds().width() - size.width(), y, | |
54 size.width(), size.height())); | |
55 } else { | |
56 NOTREACHED() << "Unknown window in USER_SHELF container."; | |
57 } | |
58 } else { | 42 } else { |
59 const int x = (alignment_ == mash::shelf::mojom::Alignment::LEFT) | 43 const int x = (alignment_ == mash::shelf::mojom::Alignment::LEFT) |
60 ? 0 | 44 ? 0 |
61 : (owner()->bounds().width() - size.width()); | 45 : (owner()->bounds().width() - size.width()); |
62 if (ash_window_type == mojom::AshWindowType::SHELF) { | 46 window->SetBounds(gfx::Rect(x, owner()->bounds().height() - size.height(), |
63 size.set_height(owner()->bounds().height()); | 47 size.width(), size.height())); |
64 window->SetBounds(gfx::Rect(x, 0, size.width(), size.height())); | |
65 } else if (ash_window_type == mojom::AshWindowType::STATUS_AREA) { | |
66 window->SetBounds(gfx::Rect(x, owner()->bounds().height() - size.height(), | |
67 size.width(), size.height())); | |
68 } else { | |
69 NOTREACHED() << "Unknown window in USER_SHELF container."; | |
70 } | |
71 } | 48 } |
72 } | 49 } |
73 | 50 |
74 void ShelfLayout::SetAlignment(mash::shelf::mojom::Alignment alignment) { | 51 void StatusLayoutManager::SetAlignment( |
52 mash::shelf::mojom::Alignment alignment) { | |
75 if (alignment_ == alignment) | 53 if (alignment_ == alignment) |
76 return; | 54 return; |
77 | 55 |
78 alignment_ = alignment; | 56 alignment_ = alignment; |
79 for (mus::Window* window : owner()->children()) | 57 for (mus::Window* window : owner()->children()) |
80 LayoutWindow(window); | 58 LayoutWindow(window); |
81 } | 59 } |
82 | 60 |
83 void ShelfLayout::SetAutoHideBehavior( | 61 void StatusLayoutManager::SetAutoHideBehavior( |
84 mash::shelf::mojom::AutoHideBehavior auto_hide) { | 62 mash::shelf::mojom::AutoHideBehavior auto_hide) { |
85 if (auto_hide_behavior_ == auto_hide) | 63 if (auto_hide_behavior_ == auto_hide) |
86 return; | 64 return; |
87 | 65 |
88 auto_hide_behavior_ = auto_hide; | 66 auto_hide_behavior_ = auto_hide; |
89 NOTIMPLEMENTED(); | 67 NOTIMPLEMENTED(); |
90 } | 68 } |
91 | 69 |
92 } // namespace wm | 70 } // namespace wm |
93 } // namespace mash | 71 } // namespace mash |
OLD | NEW |