Chromium Code Reviews| 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/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 DoesGrabInput(aura::Window* container) { | |
|
oshima
2014/07/24 18:12:48
Or GrabsInput (whichever you like).
Jun Mukai
2014/07/24 18:57:25
Done.
| |
| 34 ScreenManager::ContainerParams* params = | |
| 35 container->GetProperty(kContainerParamsKey); | |
| 36 return params && params->grab_inputs; | |
| 37 } | |
| 38 | |
| 32 class AthenaFocusRules : public wm::BaseFocusRules { | 39 class AthenaFocusRules : public wm::BaseFocusRules { |
| 33 public: | 40 public: |
| 34 AthenaFocusRules() {} | 41 AthenaFocusRules() {} |
| 35 virtual ~AthenaFocusRules() {} | 42 virtual ~AthenaFocusRules() {} |
| 36 | 43 |
| 37 // wm::BaseFocusRules: | 44 // wm::BaseFocusRules: |
| 38 virtual bool SupportsChildActivation(aura::Window* window) const OVERRIDE { | 45 virtual bool SupportsChildActivation(aura::Window* window) const OVERRIDE { |
| 39 ScreenManager::ContainerParams* params = | 46 ScreenManager::ContainerParams* params = |
| 40 window->GetProperty(kContainerParamsKey); | 47 window->GetProperty(kContainerParamsKey); |
| 41 return params && params->can_activate_children; | 48 return params && params->can_activate_children; |
| 42 } | 49 } |
| 50 virtual bool CanActivateWindow(aura::Window* window) const OVERRIDE { | |
| 51 // Check if other containers have 'grab_inputs' fields. | |
| 52 bool other_has_grab = false; | |
| 53 if (window) { | |
| 54 const aura::Window::Windows& containers = | |
| 55 window->GetRootWindow()->children(); | |
| 56 for (size_t i = 0; i < containers.size(); ++i) { | |
| 57 ScreenManager::ContainerParams* params = | |
| 58 containers[i]->GetProperty(kContainerParamsKey); | |
| 59 if (!containers[i]->Contains(window) && params && params->grab_inputs) { | |
| 60 other_has_grab = true; | |
| 61 break; | |
| 62 } | |
|
oshima
2014/07/24 18:12:48
I wonder if we need to allow a window in higher z-
Jun Mukai
2014/07/24 18:57:26
Done.
| |
| 63 } | |
| 64 } | |
| 65 return !other_has_grab && BaseFocusRules::CanActivateWindow(window); | |
| 66 } | |
| 43 | 67 |
| 44 private: | 68 private: |
| 45 DISALLOW_COPY_AND_ASSIGN(AthenaFocusRules); | 69 DISALLOW_COPY_AND_ASSIGN(AthenaFocusRules); |
| 46 }; | 70 }; |
| 47 | 71 |
| 48 class AthenaWindowTreeClient : public aura::client::WindowTreeClient { | 72 class AthenaWindowTreeClient : public aura::client::WindowTreeClient { |
| 49 public: | 73 public: |
| 50 explicit AthenaWindowTreeClient(aura::Window* container) | 74 explicit AthenaWindowTreeClient(aura::Window* container) |
| 51 : container_(container) {} | 75 : container_(container) {} |
| 52 | 76 |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 94 | 118 |
| 95 virtual void SetBounds(aura::Window* window, | 119 virtual void SetBounds(aura::Window* window, |
| 96 const gfx::Rect& bounds, | 120 const gfx::Rect& bounds, |
| 97 const gfx::Display& display) OVERRIDE { | 121 const gfx::Display& display) OVERRIDE { |
| 98 window->SetBounds(bounds); | 122 window->SetBounds(bounds); |
| 99 } | 123 } |
| 100 | 124 |
| 101 DISALLOW_COPY_AND_ASSIGN(AthenaScreenPositionClient); | 125 DISALLOW_COPY_AND_ASSIGN(AthenaScreenPositionClient); |
| 102 }; | 126 }; |
| 103 | 127 |
| 128 class AthenaEventTargeter : public aura::WindowTargeter, | |
| 129 public aura::WindowObserver { | |
| 130 public: | |
| 131 AthenaEventTargeter(aura::Window* container) | |
|
oshima
2014/07/24 18:12:48
nit: explicit
Jun Mukai
2014/07/24 18:57:26
Done.
| |
| 132 : container_(container) { | |
| 133 container_->AddObserver(this); | |
| 134 } | |
| 135 | |
| 136 virtual ~AthenaEventTargeter() { | |
| 137 // Removed before the container is removed. | |
| 138 if (container_) | |
| 139 container_->RemoveObserver(this); | |
| 140 } | |
| 141 | |
| 142 private: | |
| 143 // aura::WindowTargeter: | |
| 144 virtual bool SubtreeCanAcceptEvent( | |
| 145 ui::EventTarget* target, | |
| 146 const ui::LocatedEvent& event) const OVERRIDE { | |
| 147 aura::Window* window = static_cast<aura::Window*>(target); | |
| 148 const aura::Window::Windows& containers = | |
| 149 container_->GetRootWindow()->children(); | |
| 150 aura::Window::Windows::const_iterator iter = | |
| 151 std::find(containers.begin(), containers.end(), container_); | |
| 152 DCHECK(iter != containers.end()); | |
| 153 for (; iter != containers.end(); ++iter) { | |
| 154 if ((*iter)->Contains(window)) | |
| 155 return true; | |
| 156 } | |
| 157 return false; | |
| 158 } | |
| 159 | |
| 160 // aura::WindowObserver: | |
| 161 virtual void OnWindowDestroying(aura::Window* window) OVERRIDE { | |
| 162 aura::Window* root_window = container_->GetRootWindow(); | |
| 163 DCHECK_EQ(window, container_); | |
| 164 DCHECK_EQ( | |
| 165 this, static_cast<ui::EventTarget*>(root_window)->GetEventTargeter()); | |
| 166 | |
| 167 container_->RemoveObserver(this); | |
| 168 container_ = NULL; | |
| 169 | |
| 170 // This will remove myself. | |
| 171 root_window->SetEventTargeter(scoped_ptr<ui::EventTargeter>()); | |
| 172 } | |
| 173 | |
| 174 aura::Window* container_; | |
| 175 | |
| 176 DISALLOW_COPY_AND_ASSIGN(AthenaEventTargeter); | |
| 177 }; | |
| 178 | |
| 104 class ScreenManagerImpl : public ScreenManager { | 179 class ScreenManagerImpl : public ScreenManager { |
| 105 public: | 180 public: |
| 106 explicit ScreenManagerImpl(aura::Window* root_window); | 181 explicit ScreenManagerImpl(aura::Window* root_window); |
| 107 virtual ~ScreenManagerImpl(); | 182 virtual ~ScreenManagerImpl(); |
| 108 | 183 |
| 109 void Init(); | 184 void Init(); |
| 110 | 185 |
| 111 private: | 186 private: |
| 112 // ScreenManager: | 187 // ScreenManager: |
| 113 virtual aura::Window* CreateDefaultContainer( | 188 virtual aura::Window* CreateDefaultContainer( |
| (...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 201 #if !defined(NDEBUG) | 276 #if !defined(NDEBUG) |
| 202 DCHECK(std::find_if(children.begin(), | 277 DCHECK(std::find_if(children.begin(), |
| 203 children.end(), | 278 children.end(), |
| 204 PriorityMatcher(params.z_order_priority)) | 279 PriorityMatcher(params.z_order_priority)) |
| 205 == children.end()) | 280 == children.end()) |
| 206 << "The container with the priority " | 281 << "The container with the priority " |
| 207 << params.z_order_priority << " already exists."; | 282 << params.z_order_priority << " already exists."; |
| 208 #endif | 283 #endif |
| 209 | 284 |
| 210 container->SetProperty(kContainerParamsKey, new ContainerParams(params)); | 285 container->SetProperty(kContainerParamsKey, new ContainerParams(params)); |
| 286 | |
| 287 // If another container is already grabbing the input, SetEventTargeter | |
| 288 // implicitly release the grabbing and remove the EventTargeter instance. | |
| 289 // TODO(mukai|oshima): think about the ideal behavior of multiple grabbing | |
| 290 // and implement it. | |
| 291 if (params.grab_inputs) { | |
| 292 DCHECK(std::find_if(children.begin(), children.end(), &DoesGrabInput) | |
| 293 == children.end()); | |
|
oshima
2014/07/24 18:12:48
add message << "input has already been grabbed by
Jun Mukai
2014/07/24 18:57:26
Done.
| |
| 294 root_window_->SetEventTargeter( | |
| 295 scoped_ptr<ui::EventTargeter>(new AthenaEventTargeter(container))); | |
| 296 } | |
| 297 | |
| 211 root_window_->AddChild(container); | 298 root_window_->AddChild(container); |
| 212 | 299 |
| 213 aura::Window::Windows::const_iterator iter = | 300 aura::Window::Windows::const_iterator iter = |
| 214 std::find_if(children.begin(), | 301 std::find_if(children.begin(), |
| 215 children.end(), | 302 children.end(), |
| 216 HigherPriorityFinder(params.z_order_priority)); | 303 HigherPriorityFinder(params.z_order_priority)); |
| 217 if (iter != children.end()) | 304 if (iter != children.end()) |
| 218 root_window_->StackChildBelow(container, *iter); | 305 root_window_->StackChildBelow(container, *iter); |
| 219 | 306 |
| 220 container->Show(); | 307 container->Show(); |
| 221 return container; | 308 return container; |
| 222 } | 309 } |
| 223 | 310 |
| 224 void ScreenManagerImpl::SetBackgroundImage(const gfx::ImageSkia& image) { | 311 void ScreenManagerImpl::SetBackgroundImage(const gfx::ImageSkia& image) { |
| 225 background_controller_->SetImage(image); | 312 background_controller_->SetImage(image); |
| 226 } | 313 } |
| 227 | 314 |
| 228 } // namespace | 315 } // namespace |
| 229 | 316 |
| 230 ScreenManager::ContainerParams::ContainerParams(const std::string& n, | 317 ScreenManager::ContainerParams::ContainerParams(const std::string& n, |
| 231 int priority) | 318 int priority) |
| 232 : name(n), can_activate_children(false), z_order_priority(priority) { | 319 : name(n), |
| 320 can_activate_children(false), | |
| 321 grab_inputs(false), | |
| 322 z_order_priority(priority) { | |
| 233 } | 323 } |
| 234 | 324 |
| 235 // static | 325 // static |
| 236 ScreenManager* ScreenManager::Create(aura::Window* root_window) { | 326 ScreenManager* ScreenManager::Create(aura::Window* root_window) { |
| 237 (new ScreenManagerImpl(root_window))->Init(); | 327 (new ScreenManagerImpl(root_window))->Init(); |
| 238 DCHECK(instance); | 328 DCHECK(instance); |
| 239 return instance; | 329 return instance; |
| 240 } | 330 } |
| 241 | 331 |
| 242 // static | 332 // static |
| 243 ScreenManager* ScreenManager::Get() { | 333 ScreenManager* ScreenManager::Get() { |
| 244 DCHECK(instance); | 334 DCHECK(instance); |
| 245 return instance; | 335 return instance; |
| 246 } | 336 } |
| 247 | 337 |
| 248 // static | 338 // static |
| 249 void ScreenManager::Shutdown() { | 339 void ScreenManager::Shutdown() { |
| 250 DCHECK(instance); | 340 DCHECK(instance); |
| 251 delete instance; | 341 delete instance; |
| 252 DCHECK(!instance); | 342 DCHECK(!instance); |
| 253 } | 343 } |
| 254 | 344 |
| 255 // static | 345 // static |
| 256 wm::FocusRules* ScreenManager::CreateFocusRules() { | 346 wm::FocusRules* ScreenManager::CreateFocusRules() { |
| 257 return new AthenaFocusRules(); | 347 return new AthenaFocusRules(); |
| 258 } | 348 } |
| 259 | 349 |
| 260 } // namespace athena | 350 } // namespace athena |
| OLD | NEW |