Index: athena/screen/screen_manager_impl.cc |
diff --git a/athena/screen/screen_manager_impl.cc b/athena/screen/screen_manager_impl.cc |
index acc367bb2bfbcd451436df66166fd4acf7bf05e6..c581d0eb4c44bef6fe3d04a88e218d1bbdfb66d5 100644 |
--- a/athena/screen/screen_manager_impl.cc |
+++ b/athena/screen/screen_manager_impl.cc |
@@ -15,6 +15,7 @@ |
#include "ui/aura/layout_manager.h" |
#include "ui/aura/window.h" |
#include "ui/aura/window_property.h" |
+#include "ui/aura/window_targeter.h" |
#include "ui/aura/window_tree_host.h" |
#include "ui/wm/core/base_focus_rules.h" |
#include "ui/wm/core/capture_controller.h" |
@@ -39,6 +40,23 @@ class AthenaFocusRules : public wm::BaseFocusRules { |
window->GetProperty(kContainerParamsKey); |
return params && params->can_activate_children; |
} |
+ virtual bool CanActivateWindow(aura::Window* window) const OVERRIDE { |
+ // Check if other containers have 'grab_inputs' fields. |
+ bool other_has_grab = false; |
+ if (window) { |
+ const aura::Window::Windows& containers = |
+ window->GetRootWindow()->children(); |
+ for (size_t i = 0; i < containers.size(); ++i) { |
+ ScreenManager::ContainerParams* params = |
+ containers[i]->GetProperty(kContainerParamsKey); |
+ if (!containers[i]->Contains(window) && params && params->grab_inputs) { |
+ other_has_grab = true; |
+ break; |
+ } |
+ } |
+ } |
+ return !other_has_grab && BaseFocusRules::CanActivateWindow(window); |
+ } |
private: |
DISALLOW_COPY_AND_ASSIGN(AthenaFocusRules); |
@@ -100,6 +118,49 @@ class AthenaScreenPositionClient : public aura::client::ScreenPositionClient { |
DISALLOW_COPY_AND_ASSIGN(AthenaScreenPositionClient); |
}; |
+class AthenaEventTargeter : public aura::WindowTargeter, |
+ public aura::WindowObserver { |
+ public: |
+ AthenaEventTargeter(aura::Window* container) |
+ : container_(container) { |
+ container_->AddObserver(this); |
+ } |
+ |
+ virtual ~AthenaEventTargeter() { |
+ // Removed before the container is removed. |
+ if (container_) |
+ container_->RemoveObserver(this); |
+ } |
+ |
+ private: |
+ // aura::WindowTargeter: |
+ virtual ui::EventTarget* FindTargetForEvent(ui::EventTarget* root, |
+ ui::Event* event) OVERRIDE { |
+ ui::EventTarget* target = |
+ aura::WindowTargeter::FindTargetForEvent(root, event); |
+ 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.
|
+ target : NULL; |
+ } |
+ |
+ // aura::WindowObserver: |
+ virtual void OnWindowDestroying(aura::Window* window) OVERRIDE { |
+ aura::Window* root_window = container_->GetRootWindow(); |
+ DCHECK_EQ(window, container_); |
+ DCHECK_EQ( |
+ this, static_cast<ui::EventTarget*>(root_window)->GetEventTargeter()); |
+ |
+ container_->RemoveObserver(this); |
+ container_ = NULL; |
+ |
+ // This will remove myself. |
+ root_window->SetEventTargeter(scoped_ptr<ui::EventTargeter>()); |
+ } |
+ |
+ aura::Window* container_; |
+ |
+ DISALLOW_COPY_AND_ASSIGN(AthenaEventTargeter); |
+}; |
+ |
class ScreenManagerImpl : public ScreenManager { |
public: |
explicit ScreenManagerImpl(aura::Window* root_window); |
@@ -159,6 +220,14 @@ aura::Window* ScreenManagerImpl::CreateContainer( |
container->Init(aura::WINDOW_LAYER_NOT_DRAWN); |
container->SetName(params.name); |
root_window_->AddChild(container); |
+ // If another container is already grabbing the input, SetEventTargeter |
+ // implicitly release the grabbing and remove the EventTargeter instance. |
+ // TODO(mukai|oshima): think about the ideal behavior of multiple grabbing |
+ // 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.
|
+ if (params.grab_inputs) { |
+ root_window_->SetEventTargeter( |
+ scoped_ptr<ui::EventTargeter>(new AthenaEventTargeter(container))); |
+ } |
container->Show(); |
container->SetProperty(kContainerParamsKey, new ContainerParams(params)); |
return container; |
@@ -185,7 +254,8 @@ ScreenManagerImpl::~ScreenManagerImpl() { |
ScreenManager::ContainerParams::ContainerParams(const std::string& n) |
: name(n), |
- can_activate_children(false) { |
+ can_activate_children(false), |
+ grab_inputs(false) { |
} |
// static |