OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "athena/wm/public/window_manager.h" | 5 #include "athena/wm/public/window_manager.h" |
6 | 6 |
| 7 #include "athena/input/public/accelerator_manager.h" |
7 #include "athena/screen/public/screen_manager.h" | 8 #include "athena/screen/public/screen_manager.h" |
8 #include "athena/wm/window_overview_mode.h" | 9 #include "athena/wm/window_overview_mode.h" |
9 #include "base/logging.h" | 10 #include "base/logging.h" |
10 #include "ui/aura/layout_manager.h" | 11 #include "ui/aura/layout_manager.h" |
11 #include "ui/aura/window.h" | 12 #include "ui/aura/window.h" |
12 #include "ui/wm/public/window_types.h" | 13 #include "ui/wm/public/window_types.h" |
13 | 14 |
14 namespace athena { | 15 namespace athena { |
15 namespace { | 16 namespace { |
16 | 17 |
17 class WindowManagerImpl : public WindowManager, | 18 class WindowManagerImpl : public WindowManager, |
18 public WindowOverviewModeDelegate, | 19 public WindowOverviewModeDelegate, |
19 public aura::WindowObserver { | 20 public aura::WindowObserver, |
| 21 public AcceleratorHandler { |
20 public: | 22 public: |
21 WindowManagerImpl(); | 23 WindowManagerImpl(); |
22 virtual ~WindowManagerImpl(); | 24 virtual ~WindowManagerImpl(); |
23 | 25 |
| 26 void Init() { InstallAccelerators(); } |
| 27 |
24 void Layout(); | 28 void Layout(); |
25 | 29 |
26 // WindowManager: | 30 // WindowManager: |
27 virtual void ToggleOverview() OVERRIDE { | 31 virtual void ToggleOverview() OVERRIDE { |
28 if (overview_) | 32 if (overview_) |
29 overview_.reset(); | 33 overview_.reset(); |
30 else | 34 else |
31 overview_ = WindowOverviewMode::Create(container_.get(), this); | 35 overview_ = WindowOverviewMode::Create(container_.get(), this); |
32 } | 36 } |
33 | 37 |
34 private: | 38 private: |
| 39 enum Command { |
| 40 COMMAND_TOGGLE_OVERVIEW, |
| 41 }; |
| 42 |
| 43 void InstallAccelerators() { |
| 44 const AcceleratorData accelerator_data[] = { |
| 45 {TRIGGER_ON_PRESS, ui::VKEY_6, ui::EF_NONE, COMMAND_TOGGLE_OVERVIEW, |
| 46 AF_NONE}, |
| 47 }; |
| 48 AcceleratorManager::Get()->RegisterAccelerators( |
| 49 accelerator_data, arraysize(accelerator_data), this); |
| 50 } |
| 51 |
35 // WindowOverviewModeDelegate: | 52 // WindowOverviewModeDelegate: |
36 virtual void OnSelectWindow(aura::Window* window) OVERRIDE { | 53 virtual void OnSelectWindow(aura::Window* window) OVERRIDE { |
37 CHECK_EQ(container_.get(), window->parent()); | 54 CHECK_EQ(container_.get(), window->parent()); |
38 container_->StackChildAtTop(window); | 55 container_->StackChildAtTop(window); |
39 overview_.reset(); | 56 overview_.reset(); |
40 } | 57 } |
41 | 58 |
42 // aura::WindowObserver | 59 // aura::WindowObserver |
43 virtual void OnWindowDestroying(aura::Window* window) OVERRIDE { | 60 virtual void OnWindowDestroying(aura::Window* window) OVERRIDE { |
44 if (window == container_) | 61 if (window == container_) |
45 container_.reset(); | 62 container_.reset(); |
46 } | 63 } |
47 | 64 |
| 65 // AcceleratorHandler: |
| 66 virtual bool IsCommandEnabled(int command_id) const OVERRIDE { return true; } |
| 67 virtual bool OnAcceleratorFired(int command_id, |
| 68 const ui::Accelerator& accelerator) OVERRIDE { |
| 69 switch (command_id) { |
| 70 case COMMAND_TOGGLE_OVERVIEW: |
| 71 ToggleOverview(); |
| 72 break; |
| 73 } |
| 74 return true; |
| 75 } |
| 76 |
48 scoped_ptr<aura::Window> container_; | 77 scoped_ptr<aura::Window> container_; |
49 scoped_ptr<ui::EventHandler> temp_handler_; | |
50 scoped_ptr<WindowOverviewMode> overview_; | 78 scoped_ptr<WindowOverviewMode> overview_; |
51 | 79 |
52 DISALLOW_COPY_AND_ASSIGN(WindowManagerImpl); | 80 DISALLOW_COPY_AND_ASSIGN(WindowManagerImpl); |
53 }; | 81 }; |
54 | 82 |
55 class WindowManagerImpl* instance = NULL; | 83 class WindowManagerImpl* instance = NULL; |
56 | 84 |
57 class AthenaContainerLayoutManager : public aura::LayoutManager { | 85 class AthenaContainerLayoutManager : public aura::LayoutManager { |
58 public: | 86 public: |
59 AthenaContainerLayoutManager() {} | 87 AthenaContainerLayoutManager() {} |
(...skipping 15 matching lines...) Expand all Loading... |
75 } | 103 } |
76 virtual void SetChildBounds(aura::Window* child, | 104 virtual void SetChildBounds(aura::Window* child, |
77 const gfx::Rect& requested_bounds) OVERRIDE { | 105 const gfx::Rect& requested_bounds) OVERRIDE { |
78 if (!requested_bounds.IsEmpty()) | 106 if (!requested_bounds.IsEmpty()) |
79 SetChildBoundsDirect(child, requested_bounds); | 107 SetChildBoundsDirect(child, requested_bounds); |
80 } | 108 } |
81 | 109 |
82 DISALLOW_COPY_AND_ASSIGN(AthenaContainerLayoutManager); | 110 DISALLOW_COPY_AND_ASSIGN(AthenaContainerLayoutManager); |
83 }; | 111 }; |
84 | 112 |
85 class TempEventHandler : public ui::EventHandler { | |
86 public: | |
87 TempEventHandler() {} | |
88 virtual ~TempEventHandler() {} | |
89 | |
90 private: | |
91 // ui::EventHandler: | |
92 virtual void OnKeyEvent(ui::KeyEvent* event) OVERRIDE { | |
93 if (event->type() == ui::ET_KEY_PRESSED && | |
94 event->key_code() == ui::VKEY_F6) { | |
95 instance->ToggleOverview(); | |
96 } | |
97 } | |
98 | |
99 DISALLOW_COPY_AND_ASSIGN(TempEventHandler); | |
100 }; | |
101 | |
102 WindowManagerImpl::WindowManagerImpl() | 113 WindowManagerImpl::WindowManagerImpl() |
103 : container_(ScreenManager::Get()->CreateDefaultContainer("MainContainer")), | 114 : container_( |
104 temp_handler_(new TempEventHandler()) { | 115 ScreenManager::Get()->CreateDefaultContainer("MainContainer")) { |
105 container_->SetLayoutManager(new AthenaContainerLayoutManager); | 116 container_->SetLayoutManager(new AthenaContainerLayoutManager); |
106 container_->AddObserver(this); | 117 container_->AddObserver(this); |
107 container_->AddPreTargetHandler(temp_handler_.get()); | |
108 instance = this; | 118 instance = this; |
109 } | 119 } |
110 | 120 |
111 WindowManagerImpl::~WindowManagerImpl() { | 121 WindowManagerImpl::~WindowManagerImpl() { |
112 if (container_) { | 122 if (container_) |
113 container_->RemovePreTargetHandler(temp_handler_.get()); | |
114 container_->RemoveObserver(this); | 123 container_->RemoveObserver(this); |
115 } | |
116 container_.reset(); | 124 container_.reset(); |
117 instance = NULL; | 125 instance = NULL; |
118 } | 126 } |
119 | 127 |
120 void WindowManagerImpl::Layout() { | 128 void WindowManagerImpl::Layout() { |
121 if (!container_) | 129 if (!container_) |
122 return; | 130 return; |
123 gfx::Rect bounds = gfx::Rect(container_->bounds().size()); | 131 gfx::Rect bounds = gfx::Rect(container_->bounds().size()); |
124 const aura::Window::Windows& children = container_->children(); | 132 const aura::Window::Windows& children = container_->children(); |
125 for (aura::Window::Windows::const_iterator iter = children.begin(); | 133 for (aura::Window::Windows::const_iterator iter = children.begin(); |
(...skipping 16 matching lines...) Expand all Loading... |
142 } | 150 } |
143 | 151 |
144 // static | 152 // static |
145 void WindowManager::Shutdown() { | 153 void WindowManager::Shutdown() { |
146 DCHECK(instance); | 154 DCHECK(instance); |
147 delete instance; | 155 delete instance; |
148 DCHECK(!instance); | 156 DCHECK(!instance); |
149 } | 157 } |
150 | 158 |
151 } // namespace athena | 159 } // namespace athena |
OLD | NEW |