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

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: fix 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/container_priorities.h" 7 #include "athena/common/container_priorities.h"
8 #include "athena/common/fill_layout_manager.h" 8 #include "athena/common/fill_layout_manager.h"
9 #include "athena/input/public/accelerator_manager.h" 9 #include "athena/input/public/accelerator_manager.h"
10 #include "athena/screen/background_controller.h" 10 #include "athena/screen/background_controller.h"
11 #include "athena/screen/screen_accelerator_handler.h" 11 #include "athena/screen/screen_accelerator_handler.h"
12 #include "base/logging.h" 12 #include "base/logging.h"
13 #include "base/memory/scoped_ptr.h" 13 #include "base/memory/scoped_ptr.h"
14 #include "ui/aura/client/screen_position_client.h" 14 #include "ui/aura/client/screen_position_client.h"
15 #include "ui/aura/client/window_tree_client.h" 15 #include "ui/aura/client/window_tree_client.h"
16 #include "ui/aura/layout_manager.h" 16 #include "ui/aura/layout_manager.h"
17 #include "ui/aura/window.h" 17 #include "ui/aura/window.h"
18 #include "ui/aura/window_property.h" 18 #include "ui/aura/window_property.h"
19 #include "ui/aura/window_targeter.h"
19 #include "ui/aura/window_tree_host.h" 20 #include "ui/aura/window_tree_host.h"
20 #include "ui/wm/core/base_focus_rules.h" 21 #include "ui/wm/core/base_focus_rules.h"
21 #include "ui/wm/core/capture_controller.h" 22 #include "ui/wm/core/capture_controller.h"
22 23
23 namespace athena { 24 namespace athena {
24 namespace { 25 namespace {
25 26
26 DEFINE_OWNED_WINDOW_PROPERTY_KEY(ScreenManager::ContainerParams, 27 DEFINE_OWNED_WINDOW_PROPERTY_KEY(ScreenManager::ContainerParams,
27 kContainerParamsKey, 28 kContainerParamsKey,
28 NULL); 29 NULL);
29 30
30 ScreenManager* instance = NULL; 31 ScreenManager* instance = NULL;
31 32
33 bool GrabsInput(aura::Window* container) {
34 ScreenManager::ContainerParams* params =
35 container->GetProperty(kContainerParamsKey);
36 return params && params->grab_inputs;
37 }
38
39 // Returns the container which contains |window|.
40 aura::Window* GetContainer(aura::Window* window) {
41 // No containers for NULL or the root window itself.
42 if (!window || !window->parent())
43 return NULL;
44 if (window->parent()->IsRootWindow())
45 return window;
46 return GetContainer(window->parent());
47 }
48
32 class AthenaFocusRules : public wm::BaseFocusRules { 49 class AthenaFocusRules : public wm::BaseFocusRules {
33 public: 50 public:
34 AthenaFocusRules() {} 51 AthenaFocusRules() {}
35 virtual ~AthenaFocusRules() {} 52 virtual ~AthenaFocusRules() {}
36 53
37 // wm::BaseFocusRules: 54 // wm::BaseFocusRules:
38 virtual bool SupportsChildActivation(aura::Window* window) const OVERRIDE { 55 virtual bool SupportsChildActivation(aura::Window* window) const OVERRIDE {
39 ScreenManager::ContainerParams* params = 56 ScreenManager::ContainerParams* params =
40 window->GetProperty(kContainerParamsKey); 57 window->GetProperty(kContainerParamsKey);
41 return params && params->can_activate_children; 58 return params && params->can_activate_children;
42 } 59 }
60 virtual bool CanActivateWindow(aura::Window* window) const OVERRIDE {
61 // Check if containers of higher z-order than |window| have 'grab_inputs'
62 // fields.
63 if (window) {
64 const aura::Window::Windows& containers =
65 window->GetRootWindow()->children();
66 aura::Window::Windows::const_iterator iter =
67 std::find(containers.begin(), containers.end(), GetContainer(window));
68 DCHECK(iter != containers.end());
69 for (++iter; iter != containers.end(); ++iter) {
70 if (GrabsInput(*iter))
71 return false;
72 }
73 }
74 return BaseFocusRules::CanActivateWindow(window);
75 }
43 76
44 private: 77 private:
45 DISALLOW_COPY_AND_ASSIGN(AthenaFocusRules); 78 DISALLOW_COPY_AND_ASSIGN(AthenaFocusRules);
46 }; 79 };
47 80
48 class AthenaWindowTreeClient : public aura::client::WindowTreeClient { 81 class AthenaWindowTreeClient : public aura::client::WindowTreeClient {
49 public: 82 public:
50 explicit AthenaWindowTreeClient(aura::Window* container) 83 explicit AthenaWindowTreeClient(aura::Window* container)
51 : container_(container) {} 84 : container_(container) {}
52 85
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
94 127
95 virtual void SetBounds(aura::Window* window, 128 virtual void SetBounds(aura::Window* window,
96 const gfx::Rect& bounds, 129 const gfx::Rect& bounds,
97 const gfx::Display& display) OVERRIDE { 130 const gfx::Display& display) OVERRIDE {
98 window->SetBounds(bounds); 131 window->SetBounds(bounds);
99 } 132 }
100 133
101 DISALLOW_COPY_AND_ASSIGN(AthenaScreenPositionClient); 134 DISALLOW_COPY_AND_ASSIGN(AthenaScreenPositionClient);
102 }; 135 };
103 136
137 class AthenaEventTargeter : public aura::WindowTargeter,
138 public aura::WindowObserver {
139 public:
140 explicit AthenaEventTargeter(aura::Window* container)
141 : container_(container) {
142 container_->AddObserver(this);
143 }
144
145 virtual ~AthenaEventTargeter() {
146 // Removed before the container is removed.
147 if (container_)
148 container_->RemoveObserver(this);
149 }
150
151 private:
152 // aura::WindowTargeter:
153 virtual bool SubtreeCanAcceptEvent(
154 ui::EventTarget* target,
155 const ui::LocatedEvent& event) const OVERRIDE {
156 aura::Window* window = static_cast<aura::Window*>(target);
157 const aura::Window::Windows& containers =
158 container_->GetRootWindow()->children();
159 aura::Window::Windows::const_iterator iter =
160 std::find(containers.begin(), containers.end(), container_);
161 DCHECK(iter != containers.end());
162 for (; iter != containers.end(); ++iter) {
163 if ((*iter)->Contains(window))
164 return true;
165 }
166 return false;
167 }
168
169 // aura::WindowObserver:
170 virtual void OnWindowDestroying(aura::Window* window) OVERRIDE {
171 aura::Window* root_window = container_->GetRootWindow();
172 DCHECK_EQ(window, container_);
173 DCHECK_EQ(
174 this, static_cast<ui::EventTarget*>(root_window)->GetEventTargeter());
175
176 container_->RemoveObserver(this);
177 container_ = NULL;
178
179 // This will remove myself.
180 root_window->SetEventTargeter(scoped_ptr<ui::EventTargeter>());
181 }
182
183 aura::Window* container_;
184
185 DISALLOW_COPY_AND_ASSIGN(AthenaEventTargeter);
186 };
187
104 class ScreenManagerImpl : public ScreenManager { 188 class ScreenManagerImpl : public ScreenManager {
105 public: 189 public:
106 explicit ScreenManagerImpl(aura::Window* root_window); 190 explicit ScreenManagerImpl(aura::Window* root_window);
107 virtual ~ScreenManagerImpl(); 191 virtual ~ScreenManagerImpl();
108 192
109 void Init(); 193 void Init();
110 194
111 private: 195 private:
112 // ScreenManager: 196 // ScreenManager:
113 virtual aura::Window* CreateDefaultContainer( 197 virtual aura::Window* CreateDefaultContainer(
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
201 #if !defined(NDEBUG) 285 #if !defined(NDEBUG)
202 DCHECK(std::find_if(children.begin(), 286 DCHECK(std::find_if(children.begin(),
203 children.end(), 287 children.end(),
204 PriorityMatcher(params.z_order_priority)) 288 PriorityMatcher(params.z_order_priority))
205 == children.end()) 289 == children.end())
206 << "The container with the priority " 290 << "The container with the priority "
207 << params.z_order_priority << " already exists."; 291 << params.z_order_priority << " already exists.";
208 #endif 292 #endif
209 293
210 container->SetProperty(kContainerParamsKey, new ContainerParams(params)); 294 container->SetProperty(kContainerParamsKey, new ContainerParams(params));
295
296 // If another container is already grabbing the input, SetEventTargeter
297 // implicitly release the grabbing and remove the EventTargeter instance.
298 // TODO(mukai|oshima): think about the ideal behavior of multiple grabbing
299 // and implement it.
300 if (params.grab_inputs) {
301 DCHECK(std::find_if(children.begin(), children.end(), &GrabsInput)
302 == children.end())
303 << "input has already been grabbed by another container";
304 root_window_->SetEventTargeter(
305 scoped_ptr<ui::EventTargeter>(new AthenaEventTargeter(container)));
306 }
307
211 root_window_->AddChild(container); 308 root_window_->AddChild(container);
212 309
213 aura::Window::Windows::const_iterator iter = 310 aura::Window::Windows::const_iterator iter =
214 std::find_if(children.begin(), 311 std::find_if(children.begin(),
215 children.end(), 312 children.end(),
216 HigherPriorityFinder(params.z_order_priority)); 313 HigherPriorityFinder(params.z_order_priority));
217 if (iter != children.end()) 314 if (iter != children.end())
218 root_window_->StackChildBelow(container, *iter); 315 root_window_->StackChildBelow(container, *iter);
219 316
220 container->Show(); 317 container->Show();
221 return container; 318 return container;
222 } 319 }
223 320
224 void ScreenManagerImpl::SetBackgroundImage(const gfx::ImageSkia& image) { 321 void ScreenManagerImpl::SetBackgroundImage(const gfx::ImageSkia& image) {
225 background_controller_->SetImage(image); 322 background_controller_->SetImage(image);
226 } 323 }
227 324
228 } // namespace 325 } // namespace
229 326
230 ScreenManager::ContainerParams::ContainerParams(const std::string& n, 327 ScreenManager::ContainerParams::ContainerParams(const std::string& n,
231 int priority) 328 int priority)
232 : name(n), can_activate_children(false), z_order_priority(priority) { 329 : name(n),
330 can_activate_children(false),
331 grab_inputs(false),
332 z_order_priority(priority) {
233 } 333 }
234 334
235 // static 335 // static
236 ScreenManager* ScreenManager::Create(aura::Window* root_window) { 336 ScreenManager* ScreenManager::Create(aura::Window* root_window) {
237 (new ScreenManagerImpl(root_window))->Init(); 337 (new ScreenManagerImpl(root_window))->Init();
238 DCHECK(instance); 338 DCHECK(instance);
239 return instance; 339 return instance;
240 } 340 }
241 341
242 // static 342 // static
243 ScreenManager* ScreenManager::Get() { 343 ScreenManager* ScreenManager::Get() {
244 DCHECK(instance); 344 DCHECK(instance);
245 return instance; 345 return instance;
246 } 346 }
247 347
248 // static 348 // static
249 void ScreenManager::Shutdown() { 349 void ScreenManager::Shutdown() {
250 DCHECK(instance); 350 DCHECK(instance);
251 delete instance; 351 delete instance;
252 DCHECK(!instance); 352 DCHECK(!instance);
253 } 353 }
254 354
255 // static 355 // static
256 wm::FocusRules* ScreenManager::CreateFocusRules() { 356 wm::FocusRules* ScreenManager::CreateFocusRules() {
257 return new AthenaFocusRules(); 357 return new AthenaFocusRules();
258 } 358 }
259 359
260 } // namespace athena 360 } // 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