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

Side by Side Diff: athena/screen/screen_manager_impl.cc

Issue 414903002: Introduce 'grab_inputs' property for athena container. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 5 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
« no previous file with comments | « athena/screen/public/screen_manager.h ('k') | athena/screen/screen_manager_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/screen/public/screen_manager.h" 5 #include "athena/screen/public/screen_manager.h"
6 6
7 #include "athena/common/fill_layout_manager.h" 7 #include "athena/common/fill_layout_manager.h"
8 #include "athena/input/public/accelerator_manager.h" 8 #include "athena/input/public/accelerator_manager.h"
9 #include "athena/screen/background_controller.h" 9 #include "athena/screen/background_controller.h"
10 #include "athena/screen/screen_accelerator_handler.h" 10 #include "athena/screen/screen_accelerator_handler.h"
11 #include "base/logging.h" 11 #include "base/logging.h"
12 #include "base/memory/scoped_ptr.h" 12 #include "base/memory/scoped_ptr.h"
13 #include "ui/aura/client/screen_position_client.h" 13 #include "ui/aura/client/screen_position_client.h"
14 #include "ui/aura/client/window_tree_client.h" 14 #include "ui/aura/client/window_tree_client.h"
15 #include "ui/aura/layout_manager.h" 15 #include "ui/aura/layout_manager.h"
16 #include "ui/aura/window.h" 16 #include "ui/aura/window.h"
17 #include "ui/aura/window_property.h" 17 #include "ui/aura/window_property.h"
18 #include "ui/aura/window_targeter.h"
18 #include "ui/aura/window_tree_host.h" 19 #include "ui/aura/window_tree_host.h"
19 #include "ui/wm/core/base_focus_rules.h" 20 #include "ui/wm/core/base_focus_rules.h"
20 #include "ui/wm/core/capture_controller.h" 21 #include "ui/wm/core/capture_controller.h"
21 22
22 namespace athena { 23 namespace athena {
23 namespace { 24 namespace {
24 25
25 DEFINE_OWNED_WINDOW_PROPERTY_KEY(ScreenManager::ContainerParams, 26 DEFINE_OWNED_WINDOW_PROPERTY_KEY(ScreenManager::ContainerParams,
26 kContainerParamsKey, 27 kContainerParamsKey,
27 NULL); 28 NULL);
28 29
29 ScreenManager* instance = NULL; 30 ScreenManager* instance = NULL;
30 31
31 class AthenaFocusRules : public wm::BaseFocusRules { 32 class AthenaFocusRules : public wm::BaseFocusRules {
32 public: 33 public:
33 AthenaFocusRules() {} 34 AthenaFocusRules() {}
34 virtual ~AthenaFocusRules() {} 35 virtual ~AthenaFocusRules() {}
35 36
36 // wm::BaseFocusRules: 37 // wm::BaseFocusRules:
37 virtual bool SupportsChildActivation(aura::Window* window) const OVERRIDE { 38 virtual bool SupportsChildActivation(aura::Window* window) const OVERRIDE {
38 ScreenManager::ContainerParams* params = 39 ScreenManager::ContainerParams* params =
39 window->GetProperty(kContainerParamsKey); 40 window->GetProperty(kContainerParamsKey);
40 return params && params->can_activate_children; 41 return params && params->can_activate_children;
41 } 42 }
43 virtual bool CanActivateWindow(aura::Window* window) const OVERRIDE {
44 // Check if other containers have 'grab_inputs' fields.
45 bool other_has_grab = false;
46 if (window) {
47 const aura::Window::Windows& containers =
48 window->GetRootWindow()->children();
49 for (size_t i = 0; i < containers.size(); ++i) {
50 ScreenManager::ContainerParams* params =
51 containers[i]->GetProperty(kContainerParamsKey);
52 if (!containers[i]->Contains(window) && params && params->grab_inputs) {
53 other_has_grab = true;
54 break;
55 }
56 }
57 }
58 return !other_has_grab && BaseFocusRules::CanActivateWindow(window);
59 }
42 60
43 private: 61 private:
44 DISALLOW_COPY_AND_ASSIGN(AthenaFocusRules); 62 DISALLOW_COPY_AND_ASSIGN(AthenaFocusRules);
45 }; 63 };
46 64
47 class AthenaWindowTreeClient : public aura::client::WindowTreeClient { 65 class AthenaWindowTreeClient : public aura::client::WindowTreeClient {
48 public: 66 public:
49 explicit AthenaWindowTreeClient(aura::Window* container) 67 explicit AthenaWindowTreeClient(aura::Window* container)
50 : container_(container) {} 68 : container_(container) {}
51 69
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
93 111
94 virtual void SetBounds(aura::Window* window, 112 virtual void SetBounds(aura::Window* window,
95 const gfx::Rect& bounds, 113 const gfx::Rect& bounds,
96 const gfx::Display& display) OVERRIDE { 114 const gfx::Display& display) OVERRIDE {
97 window->SetBounds(bounds); 115 window->SetBounds(bounds);
98 } 116 }
99 117
100 DISALLOW_COPY_AND_ASSIGN(AthenaScreenPositionClient); 118 DISALLOW_COPY_AND_ASSIGN(AthenaScreenPositionClient);
101 }; 119 };
102 120
121 class AthenaEventTargeter : public aura::WindowTargeter,
122 public aura::WindowObserver {
123 public:
124 AthenaEventTargeter(aura::Window* container)
125 : container_(container) {
126 container_->AddObserver(this);
127 }
128
129 virtual ~AthenaEventTargeter() {
130 // Removed before the container is removed.
131 if (container_)
132 container_->RemoveObserver(this);
133 }
134
135 private:
136 // aura::WindowTargeter:
137 virtual ui::EventTarget* FindTargetForEvent(ui::EventTarget* root,
138 ui::Event* event) OVERRIDE {
139 ui::EventTarget* target =
140 aura::WindowTargeter::FindTargetForEvent(root, event);
141 return container_->Contains(static_cast<aura::Window*>(target)) ?
oshima 2014/07/23 23:24:35 We need to allow a container that has higher z-ord
Jun Mukai 2014/07/24 17:52:02 Done. Also added some tests.
142 target : NULL;
143 }
144
145 // aura::WindowObserver:
146 virtual void OnWindowDestroying(aura::Window* window) OVERRIDE {
147 aura::Window* root_window = container_->GetRootWindow();
148 DCHECK_EQ(window, container_);
149 DCHECK_EQ(
150 this, static_cast<ui::EventTarget*>(root_window)->GetEventTargeter());
151
152 container_->RemoveObserver(this);
153 container_ = NULL;
154
155 // This will remove myself.
156 root_window->SetEventTargeter(scoped_ptr<ui::EventTargeter>());
157 }
158
159 aura::Window* container_;
160
161 DISALLOW_COPY_AND_ASSIGN(AthenaEventTargeter);
162 };
163
103 class ScreenManagerImpl : public ScreenManager { 164 class ScreenManagerImpl : public ScreenManager {
104 public: 165 public:
105 explicit ScreenManagerImpl(aura::Window* root_window); 166 explicit ScreenManagerImpl(aura::Window* root_window);
106 virtual ~ScreenManagerImpl(); 167 virtual ~ScreenManagerImpl();
107 168
108 void Init(); 169 void Init();
109 170
110 private: 171 private:
111 // ScreenManager: 172 // ScreenManager:
112 virtual aura::Window* CreateDefaultContainer( 173 virtual aura::Window* CreateDefaultContainer(
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
152 213
153 return container; 214 return container;
154 } 215 }
155 216
156 aura::Window* ScreenManagerImpl::CreateContainer( 217 aura::Window* ScreenManagerImpl::CreateContainer(
157 const ContainerParams& params) { 218 const ContainerParams& params) {
158 aura::Window* container = new aura::Window(NULL); 219 aura::Window* container = new aura::Window(NULL);
159 container->Init(aura::WINDOW_LAYER_NOT_DRAWN); 220 container->Init(aura::WINDOW_LAYER_NOT_DRAWN);
160 container->SetName(params.name); 221 container->SetName(params.name);
161 root_window_->AddChild(container); 222 root_window_->AddChild(container);
223 // If another container is already grabbing the input, SetEventTargeter
224 // implicitly release the grabbing and remove the EventTargeter instance.
225 // TODO(mukai|oshima): think about the ideal behavior of multiple grabbing
226 // and implement it.
oshima 2014/07/23 23:24:35 Can you add check to make sure no other containers
Jun Mukai 2014/07/24 17:52:02 Done.
227 if (params.grab_inputs) {
228 root_window_->SetEventTargeter(
229 scoped_ptr<ui::EventTargeter>(new AthenaEventTargeter(container)));
230 }
162 container->Show(); 231 container->Show();
163 container->SetProperty(kContainerParamsKey, new ContainerParams(params)); 232 container->SetProperty(kContainerParamsKey, new ContainerParams(params));
164 return container; 233 return container;
165 } 234 }
166 235
167 void ScreenManagerImpl::SetBackgroundImage(const gfx::ImageSkia& image) { 236 void ScreenManagerImpl::SetBackgroundImage(const gfx::ImageSkia& image) {
168 background_controller_->SetImage(image); 237 background_controller_->SetImage(image);
169 } 238 }
170 239
171 ScreenManagerImpl::ScreenManagerImpl(aura::Window* root_window) 240 ScreenManagerImpl::ScreenManagerImpl(aura::Window* root_window)
172 : root_window_(root_window) { 241 : root_window_(root_window) {
173 DCHECK(root_window_); 242 DCHECK(root_window_);
174 DCHECK(!instance); 243 DCHECK(!instance);
175 instance = this; 244 instance = this;
176 } 245 }
177 246
178 ScreenManagerImpl::~ScreenManagerImpl() { 247 ScreenManagerImpl::~ScreenManagerImpl() {
179 aura::client::SetScreenPositionClient(root_window_, NULL); 248 aura::client::SetScreenPositionClient(root_window_, NULL);
180 aura::client::SetWindowTreeClient(root_window_, NULL); 249 aura::client::SetWindowTreeClient(root_window_, NULL);
181 instance = NULL; 250 instance = NULL;
182 } 251 }
183 252
184 } // namespace 253 } // namespace
185 254
186 ScreenManager::ContainerParams::ContainerParams(const std::string& n) 255 ScreenManager::ContainerParams::ContainerParams(const std::string& n)
187 : name(n), 256 : name(n),
188 can_activate_children(false) { 257 can_activate_children(false),
258 grab_inputs(false) {
189 } 259 }
190 260
191 // static 261 // static
192 ScreenManager* ScreenManager::Create(aura::Window* root_window) { 262 ScreenManager* ScreenManager::Create(aura::Window* root_window) {
193 (new ScreenManagerImpl(root_window))->Init(); 263 (new ScreenManagerImpl(root_window))->Init();
194 DCHECK(instance); 264 DCHECK(instance);
195 return instance; 265 return instance;
196 } 266 }
197 267
198 // static 268 // static
199 ScreenManager* ScreenManager::Get() { 269 ScreenManager* ScreenManager::Get() {
200 DCHECK(instance); 270 DCHECK(instance);
201 return instance; 271 return instance;
202 } 272 }
203 273
204 // static 274 // static
205 void ScreenManager::Shutdown() { 275 void ScreenManager::Shutdown() {
206 DCHECK(instance); 276 DCHECK(instance);
207 delete instance; 277 delete instance;
208 DCHECK(!instance); 278 DCHECK(!instance);
209 } 279 }
210 280
211 // static 281 // static
212 wm::FocusRules* ScreenManager::CreateFocusRules() { 282 wm::FocusRules* ScreenManager::CreateFocusRules() {
213 return new AthenaFocusRules(); 283 return new AthenaFocusRules();
214 } 284 }
215 285
216 } // namespace athena 286 } // namespace athena
OLDNEW
« no previous file with comments | « athena/screen/public/screen_manager.h ('k') | athena/screen/screen_manager_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698