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

Unified Diff: chromecast/graphics/cast_window_manager_aura.cc

Issue 2636303002: [Chromecast] Add support for z-order and window focus. (Closed)
Patch Set: Simplifications and unit tests. Created 3 years, 11 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 side-by-side diff with in-line comments
Download patch
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..8c04b5a1a4a1b0c728038c543496a302044a55ff 100644
--- a/chromecast/graphics/cast_window_manager_aura.cc
+++ b/chromecast/graphics/cast_window_manager_aura.cc
@@ -6,6 +6,7 @@
#include "base/memory/ptr_util.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"
@@ -136,6 +137,7 @@ void CastWindowManagerAura::Setup() {
window_tree_host_->compositor()->SetHostHasTransparentBackground(true);
window_tree_host_->compositor()->SetBackgroundColor(SK_ColorTRANSPARENT);
+ aura::client::SetFocusClient(window_tree_host_->window(), &focus_client_);
capture_client_.reset(
new aura::client::DefaultCaptureClient(window_tree_host_->window()));
@@ -150,8 +152,10 @@ void CastWindowManagerAura::TearDown() {
if (!window_tree_host_) {
return;
}
+ focus_client_.reset();
halliwell 2017/01/24 00:54:46 Can you explain why you needed this?
Joshua LeVasseur 2017/01/24 03:39:50 I've switched to using a smart pointer, so that sh
CastVSyncSettings::GetInstance()->RemoveObserver(this);
capture_client_.reset();
+ aura::client::SetFocusClient(window_tree_host_->window(), nullptr);
window_tree_host_.reset();
}
@@ -165,7 +169,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) {
+ 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())) {
+ 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());
}

Powered by Google App Engine
This is Rietveld 408576698