Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(7)

Side by Side Diff: athena/wm/window_manager_impl.cc

Issue 287163009: [Athena] minimum impl to add screen/background and test windows (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« athena/main/main_util.cc ('K') | « athena/wm/public/window_manager.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(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/client/window_tree_client.h"
10 #include "ui/aura/layout_manager.h"
11 #include "ui/aura/window.h"
12
13 namespace athena {
14 namespace {
15
16 class WindowManagerImpl : public WindowManager {
17 public:
18 WindowManagerImpl();
19 virtual ~WindowManagerImpl();
20
21 void OnWindowAdded(aura::Window* window);
22 void OnWindowRemoved(aura::Window* window);
23 void Layout();
24
25 private:
26 aura::Window* container_;
27 scoped_ptr<aura::client::WindowTreeClient> window_tree_client_;
28
29 DISALLOW_COPY_AND_ASSIGN(WindowManagerImpl);
30 };
31
32 class WindowManagerImpl* instance = NULL;
33
34 class AthenaContainerLayoutManager : public aura::LayoutManager {
35 public:
36 AthenaContainerLayoutManager() {}
37
38 // aura::LayoutManager:
39 virtual void OnWindowResized() OVERRIDE { instance->Layout(); }
40 virtual void OnWindowAddedToLayout(aura::Window* child) OVERRIDE {
41 instance->OnWindowAdded(child);
42 }
43 virtual void OnWillRemoveWindowFromLayout(aura::Window* child) OVERRIDE {}
44 virtual void OnWindowRemovedFromLayout(aura::Window* child) OVERRIDE {
45 instance->OnWindowRemoved(child);
46 }
47 virtual void OnChildWindowVisibilityChanged(aura::Window* child,
48 bool visible) OVERRIDE {
49 instance->Layout();
50 }
51 virtual void SetChildBounds(aura::Window* child,
52 const gfx::Rect& requested_bounds) OVERRIDE {
53 if (!requested_bounds.IsEmpty())
54 SetChildBoundsDirect(child, requested_bounds);
55 }
56
57 private:
58 WindowManager* window_manager_;
59
60 DISALLOW_COPY_AND_ASSIGN(AthenaContainerLayoutManager);
61 };
62
63 class AthenaWindowTreeClient : public aura::client::WindowTreeClient {
64 public:
65 AthenaWindowTreeClient(aura::Window* container) : container_(container) {
66 container_->SetLayoutManager(new AthenaContainerLayoutManager);
67 }
68
69 private:
70 virtual ~AthenaWindowTreeClient() {}
71
72 // aura::client::WindowTreeClient:
73 virtual aura::Window* GetDefaultParent(aura::Window* context,
74 aura::Window* window,
75 const gfx::Rect& bounds) OVERRIDE {
76 return container_;
77 }
78
79 aura::Window* container_;
80
81 DISALLOW_COPY_AND_ASSIGN(AthenaWindowTreeClient);
82 };
83
84 WindowManagerImpl::WindowManagerImpl()
85 : container_(ScreenManager::Get()->GetContainerWindow()),
86 window_tree_client_(new AthenaWindowTreeClient(container_)) {
87 instance = this;
88 aura::client::SetWindowTreeClient(
89 ScreenManager::Get()->GetContainerWindow(), window_tree_client_.get());
90 }
91
92 WindowManagerImpl::~WindowManagerImpl() {
93 instance = NULL;
94 aura::client::SetWindowTreeClient(
95 ScreenManager::Get()->GetContainerWindow(), NULL);
96 }
97
98 void WindowManagerImpl::Layout() {
99 gfx::Rect bounds = gfx::Rect(container_->bounds().size());
100 bounds.Inset(10, 10, 10, 10);
101 const aura::Window::Windows& children = container_->children();
102 for (aura::Window::Windows::const_iterator iter = children.begin();
103 iter != children.end();
104 ++iter) {
105 (*iter)->SetBounds(bounds);
106 }
107 }
108
109 void WindowManagerImpl::OnWindowAdded(aura::Window* child) {
110 }
111
112 void WindowManagerImpl::OnWindowRemoved(aura::Window* child) {
113 }
114
115 } // namespace
116
117 // static
118 WindowManager* WindowManager::Create() {
119 DCHECK(!instance);
120 new WindowManagerImpl;
121 DCHECK(instance);
122 return instance;
123 }
124
125 // static
126 void WindowManager::Shutdown() {
127 DCHECK(instance);
128 delete instance;
129 DCHECK(!instance);
130 }
131
132 } // namespace athena
OLDNEW
« athena/main/main_util.cc ('K') | « athena/wm/public/window_manager.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698