OLD | NEW |
| (Empty) |
1 // Copyright 2014 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 "athena/util/fill_layout_manager.h" | |
6 | |
7 #include "base/logging.h" | |
8 #include "ui/aura/window.h" | |
9 #include "ui/aura/window_property.h" | |
10 | |
11 namespace athena { | |
12 namespace { | |
13 | |
14 DEFINE_LOCAL_WINDOW_PROPERTY_KEY(bool, kAlwaysFillWindowKey, false); | |
15 | |
16 // TODO(oshima): Implement real window/layout manager. crbug.com/388362. | |
17 bool ShouldFill(aura::Window* window) { | |
18 return window->GetProperty(kAlwaysFillWindowKey) || | |
19 (window->type() != ui::wm::WINDOW_TYPE_MENU && | |
20 window->type() != ui::wm::WINDOW_TYPE_TOOLTIP && | |
21 window->type() != ui::wm::WINDOW_TYPE_POPUP); | |
22 } | |
23 | |
24 } // namespace | |
25 | |
26 // static | |
27 void FillLayoutManager::SetAlwaysFill(aura::Window* window) { | |
28 window->SetProperty(kAlwaysFillWindowKey, true); | |
29 } | |
30 | |
31 FillLayoutManager::FillLayoutManager(aura::Window* container) | |
32 : container_(container) { | |
33 DCHECK(container_); | |
34 } | |
35 | |
36 FillLayoutManager::~FillLayoutManager() { | |
37 } | |
38 | |
39 void FillLayoutManager::OnWindowResized() { | |
40 gfx::Rect full_bounds = gfx::Rect(container_->bounds().size()); | |
41 for (aura::Window::Windows::const_iterator iter = | |
42 container_->children().begin(); | |
43 iter != container_->children().end(); | |
44 ++iter) { | |
45 if (ShouldFill(*iter)) | |
46 SetChildBoundsDirect(*iter, full_bounds); | |
47 } | |
48 } | |
49 | |
50 void FillLayoutManager::OnWindowAddedToLayout(aura::Window* child) { | |
51 if (ShouldFill(child)) | |
52 SetChildBoundsDirect(child, gfx::Rect(container_->bounds().size())); | |
53 } | |
54 | |
55 void FillLayoutManager::OnWillRemoveWindowFromLayout(aura::Window* child) { | |
56 } | |
57 | |
58 void FillLayoutManager::OnWindowRemovedFromLayout(aura::Window* child) { | |
59 } | |
60 | |
61 void FillLayoutManager::OnChildWindowVisibilityChanged(aura::Window* child, | |
62 bool visible) { | |
63 if (visible && ShouldFill(child)) | |
64 SetChildBoundsDirect(child, gfx::Rect(container_->bounds().size())); | |
65 } | |
66 | |
67 void FillLayoutManager::SetChildBounds(aura::Window* child, | |
68 const gfx::Rect& requested_bounds) { | |
69 if (!ShouldFill(child)) | |
70 SetChildBoundsDirect(child, requested_bounds); | |
71 } | |
72 | |
73 } // namespace athena | |
OLD | NEW |