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.
5 #include "athena/util/fill_layout_manager.h"
7 #include "base/logging.h"
8 #include "ui/aura/window.h"
9 #include "ui/aura/window_property.h"
14 DEFINE_LOCAL_WINDOW_PROPERTY_KEY(bool, kAlwaysFillWindowKey
, false);
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
);
27 void FillLayoutManager::SetAlwaysFill(aura::Window
* window
) {
28 window
->SetProperty(kAlwaysFillWindowKey
, true);
31 FillLayoutManager::FillLayoutManager(aura::Window
* container
)
32 : container_(container
) {
36 FillLayoutManager::~FillLayoutManager() {
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();
45 if (ShouldFill(*iter
))
46 SetChildBoundsDirect(*iter
, full_bounds
);
50 void FillLayoutManager::OnWindowAddedToLayout(aura::Window
* child
) {
51 if (ShouldFill(child
))
52 SetChildBoundsDirect(child
, gfx::Rect(container_
->bounds().size()));
55 void FillLayoutManager::OnWillRemoveWindowFromLayout(aura::Window
* child
) {
58 void FillLayoutManager::OnWindowRemovedFromLayout(aura::Window
* child
) {
61 void FillLayoutManager::OnChildWindowVisibilityChanged(aura::Window
* child
,
63 if (visible
&& ShouldFill(child
))
64 SetChildBoundsDirect(child
, gfx::Rect(container_
->bounds().size()));
67 void FillLayoutManager::SetChildBounds(aura::Window
* child
,
68 const gfx::Rect
& requested_bounds
) {
69 if (!ShouldFill(child
))
70 SetChildBoundsDirect(child
, requested_bounds
);