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"
11 // This is to avoid creating type definitoin for kAlwaysFillWindowKey.
12 DECLARE_EXPORTED_WINDOW_PROPERTY_TYPE(ATHENA_EXPORT
, bool);
17 DEFINE_LOCAL_WINDOW_PROPERTY_KEY(bool, kAlwaysFillWindowKey
, false);
19 // TODO(oshima): Implement real window/layout manager. crbug.com/388362.
20 bool ShouldFill(aura::Window
* window
) {
21 return window
->GetProperty(kAlwaysFillWindowKey
) ||
22 (window
->type() != ui::wm::WINDOW_TYPE_MENU
&&
23 window
->type() != ui::wm::WINDOW_TYPE_TOOLTIP
&&
24 window
->type() != ui::wm::WINDOW_TYPE_POPUP
);
30 void FillLayoutManager::SetAlwaysFill(aura::Window
* window
) {
31 window
->SetProperty(kAlwaysFillWindowKey
, true);
34 FillLayoutManager::FillLayoutManager(aura::Window
* container
)
35 : container_(container
) {
39 FillLayoutManager::~FillLayoutManager() {
42 void FillLayoutManager::OnWindowResized() {
43 gfx::Rect full_bounds
= gfx::Rect(container_
->bounds().size());
44 for (aura::Window::Windows::const_iterator iter
=
45 container_
->children().begin();
46 iter
!= container_
->children().end();
48 if (ShouldFill(*iter
))
49 SetChildBoundsDirect(*iter
, full_bounds
);
53 void FillLayoutManager::OnWindowAddedToLayout(aura::Window
* child
) {
54 if (ShouldFill(child
))
55 SetChildBoundsDirect(child
, gfx::Rect(container_
->bounds().size()));
58 void FillLayoutManager::OnWillRemoveWindowFromLayout(aura::Window
* child
) {
61 void FillLayoutManager::OnWindowRemovedFromLayout(aura::Window
* child
) {
64 void FillLayoutManager::OnChildWindowVisibilityChanged(aura::Window
* child
,
66 if (visible
&& ShouldFill(child
))
67 SetChildBoundsDirect(child
, gfx::Rect(container_
->bounds().size()));
70 void FillLayoutManager::SetChildBounds(aura::Window
* child
,
71 const gfx::Rect
& requested_bounds
) {
72 if (!ShouldFill(child
))
73 SetChildBoundsDirect(child
, requested_bounds
);