Chromium Code Reviews| Index: chromecast/graphics/cast_window_manager_aura.cc |
| diff --git a/chromecast/graphics/cast_window_manager_aura.cc b/chromecast/graphics/cast_window_manager_aura.cc |
| index b4d9dbcd0896f1180c237be5c1cfcbb851fe8dae..d575d4e4556360f0a80c9962e06c827dce655a6a 100644 |
| --- a/chromecast/graphics/cast_window_manager_aura.cc |
| +++ b/chromecast/graphics/cast_window_manager_aura.cc |
| @@ -5,7 +5,9 @@ |
| #include "chromecast/graphics/cast_window_manager_aura.h" |
| #include "base/memory/ptr_util.h" |
| +#include "chromecast/graphics/cast_focus_client_aura.h" |
| #include "ui/aura/client/default_capture_client.h" |
| +#include "ui/aura/client/focus_change_observer.h" |
| #include "ui/aura/env.h" |
| #include "ui/aura/layout_manager.h" |
| #include "ui/aura/window.h" |
| @@ -17,6 +19,31 @@ |
| namespace chromecast { |
| +// An ui::EventTarget that ignores events. |
| +class CastEventIgnorer : public ui::EventTargeter { |
| + public: |
| + ~CastEventIgnorer() override; |
| + |
| + // ui::EventTargeter implementation: |
| + ui::EventTarget* FindTargetForEvent(ui::EventTarget* root, |
| + ui::Event* event) override; |
| + ui::EventTarget* FindNextBestTarget(ui::EventTarget* previous_target, |
| + ui::Event* event) override; |
| +}; |
| + |
| +CastEventIgnorer::~CastEventIgnorer() {} |
| + |
| +ui::EventTarget* CastEventIgnorer::FindTargetForEvent(ui::EventTarget* root, |
| + ui::Event* event) { |
| + return nullptr; |
| +} |
| + |
| +ui::EventTarget* CastEventIgnorer::FindNextBestTarget( |
| + ui::EventTarget* previous_target, |
| + ui::Event* event) { |
| + return nullptr; |
| +} |
| + |
| // An aura::WindowTreeHost that correctly converts input events. |
| class CastWindowTreeHost : public aura::WindowTreeHostPlatform { |
| public: |
| @@ -34,7 +61,12 @@ class CastWindowTreeHost : public aura::WindowTreeHostPlatform { |
| CastWindowTreeHost::CastWindowTreeHost(bool enable_input, |
| const gfx::Rect& bounds) |
| - : WindowTreeHostPlatform(bounds), enable_input_(enable_input) {} |
| + : WindowTreeHostPlatform(bounds), enable_input_(enable_input) { |
| + if (!enable_input) { |
| + window()->SetEventTargeter( |
| + std::unique_ptr<ui::EventTargeter>(new CastEventIgnorer)); |
| + } |
| +} |
| CastWindowTreeHost::~CastWindowTreeHost() {} |
| @@ -136,6 +168,9 @@ void CastWindowManagerAura::Setup() { |
| window_tree_host_->compositor()->SetHostHasTransparentBackground(true); |
| window_tree_host_->compositor()->SetBackgroundColor(SK_ColorTRANSPARENT); |
| + focus_client_.reset(new CastFocusClientAura()); |
| + aura::client::SetFocusClient(window_tree_host_->window(), |
| + focus_client_.get()); |
| capture_client_.reset( |
| new aura::client::DefaultCaptureClient(window_tree_host_->window())); |
| @@ -152,6 +187,8 @@ void CastWindowManagerAura::TearDown() { |
| } |
| CastVSyncSettings::GetInstance()->RemoveObserver(this); |
| capture_client_.reset(); |
| + aura::client::SetFocusClient(window_tree_host_->window(), nullptr); |
| + focus_client_.reset(); |
| window_tree_host_.reset(); |
| } |
| @@ -165,7 +202,30 @@ void CastWindowManagerAura::AddWindow(gfx::NativeView child) { |
| parent->AddChild(child); |
| } |
| - parent->StackChildAtTop(child); |
| + // Determine z-order relative to existing windows. |
| + aura::Window::Windows windows = parent->children(); |
| + aura::Window* above = nullptr; |
| + aura::Window* below = nullptr; |
| + for (auto&& other : windows) { |
|
sadrul
2017/01/26 01:50:10
auto* other : windows
Joshua LeVasseur
2017/01/26 02:51:01
Done.
|
| + if (other == child) { |
| + continue; |
| + } |
| + if ((other->id() < child->id()) && (!below || other->id() > below->id())) { |
| + below = other; |
| + } else if ((other->id() > child->id()) && |
| + (!above || other->id() < above->id())) { |
|
sadrul
2017/01/26 01:50:10
Where in the code do you assign the window ids? I
Joshua LeVasseur
2017/01/26 02:51:01
Some future code changes, which will bring in addi
|
| + above = other; |
| + } |
| + } |
| + |
| + // Adjust the z-order of the new child window. |
| + if (above) { |
| + parent->StackChildBelow(child, above); |
| + } else if (below) { |
| + parent->StackChildAbove(child, below); |
| + } else { |
| + parent->StackChildAtBottom(child); |
| + } |
| child->SetBounds(window_tree_host_->window()->bounds()); |
| } |