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/wm/public/window_manager.h" |
| 6 |
| 7 #include "athena/screen/public/screen_manager.h" |
| 8 #include "base/logging.h" |
| 9 #include "ui/aura/layout_manager.h" |
| 10 #include "ui/aura/window.h" |
| 11 |
| 12 namespace athena { |
| 13 namespace { |
| 14 |
| 15 class WindowManagerImpl : public WindowManager { |
| 16 public: |
| 17 WindowManagerImpl(); |
| 18 virtual ~WindowManagerImpl(); |
| 19 |
| 20 void Layout(); |
| 21 |
| 22 private: |
| 23 aura::Window* container_; |
| 24 |
| 25 DISALLOW_COPY_AND_ASSIGN(WindowManagerImpl); |
| 26 }; |
| 27 |
| 28 class WindowManagerImpl* instance = NULL; |
| 29 |
| 30 class AthenaContainerLayoutManager : public aura::LayoutManager { |
| 31 public: |
| 32 AthenaContainerLayoutManager() {} |
| 33 virtual ~AthenaContainerLayoutManager() {} |
| 34 |
| 35 private: |
| 36 // aura::LayoutManager: |
| 37 virtual void OnWindowResized() OVERRIDE { instance->Layout(); } |
| 38 virtual void OnWindowAddedToLayout(aura::Window* child) OVERRIDE { |
| 39 instance->Layout(); |
| 40 } |
| 41 virtual void OnWillRemoveWindowFromLayout(aura::Window* child) OVERRIDE {} |
| 42 virtual void OnWindowRemovedFromLayout(aura::Window* child) OVERRIDE { |
| 43 instance->Layout(); |
| 44 } |
| 45 virtual void OnChildWindowVisibilityChanged(aura::Window* child, |
| 46 bool visible) OVERRIDE { |
| 47 instance->Layout(); |
| 48 } |
| 49 virtual void SetChildBounds(aura::Window* child, |
| 50 const gfx::Rect& requested_bounds) OVERRIDE { |
| 51 if (!requested_bounds.IsEmpty()) |
| 52 SetChildBoundsDirect(child, requested_bounds); |
| 53 } |
| 54 |
| 55 DISALLOW_COPY_AND_ASSIGN(AthenaContainerLayoutManager); |
| 56 }; |
| 57 |
| 58 WindowManagerImpl::WindowManagerImpl() |
| 59 : container_(ScreenManager::Get()->GetContainerWindow()) { |
| 60 container_->SetLayoutManager(new AthenaContainerLayoutManager); |
| 61 instance = this; |
| 62 } |
| 63 |
| 64 WindowManagerImpl::~WindowManagerImpl() { |
| 65 instance = NULL; |
| 66 } |
| 67 |
| 68 void WindowManagerImpl::Layout() { |
| 69 gfx::Rect bounds = gfx::Rect(container_->bounds().size()); |
| 70 // Just make it small a bit so that the background is visible. |
| 71 bounds.Inset(10, 10, 10, 10); |
| 72 const aura::Window::Windows& children = container_->children(); |
| 73 for (aura::Window::Windows::const_iterator iter = children.begin(); |
| 74 iter != children.end(); |
| 75 ++iter) { |
| 76 (*iter)->SetBounds(bounds); |
| 77 } |
| 78 } |
| 79 |
| 80 } // namespace |
| 81 |
| 82 // static |
| 83 WindowManager* WindowManager::Create() { |
| 84 DCHECK(!instance); |
| 85 new WindowManagerImpl; |
| 86 DCHECK(instance); |
| 87 return instance; |
| 88 } |
| 89 |
| 90 // static |
| 91 void WindowManager::Shutdown() { |
| 92 DCHECK(instance); |
| 93 delete instance; |
| 94 DCHECK(!instance); |
| 95 } |
| 96 |
| 97 } // namespace athena |
OLD | NEW |