OLD | NEW |
---|---|
1 // Copyright 2017 The Chromium Authors. All rights reserved. | 1 // Copyright 2017 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 "chromecast/graphics/cast_window_manager_aura.h" | 5 #include "chromecast/graphics/cast_window_manager_aura.h" |
6 | 6 |
7 #include "base/memory/ptr_util.h" | 7 #include "base/memory/ptr_util.h" |
8 #include "ui/aura/client/default_capture_client.h" | 8 #include "ui/aura/client/default_capture_client.h" |
9 #include "ui/aura/client/focus_change_observer.h" | |
9 #include "ui/aura/env.h" | 10 #include "ui/aura/env.h" |
10 #include "ui/aura/layout_manager.h" | 11 #include "ui/aura/layout_manager.h" |
11 #include "ui/aura/window.h" | 12 #include "ui/aura/window.h" |
12 #include "ui/aura/window_tree_host_platform.h" | 13 #include "ui/aura/window_tree_host_platform.h" |
13 #include "ui/base/ime/input_method.h" | 14 #include "ui/base/ime/input_method.h" |
14 #include "ui/base/ime/input_method_factory.h" | 15 #include "ui/base/ime/input_method_factory.h" |
15 #include "ui/display/display.h" | 16 #include "ui/display/display.h" |
16 #include "ui/display/screen.h" | 17 #include "ui/display/screen.h" |
17 | 18 |
18 namespace chromecast { | 19 namespace chromecast { |
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
129 CHECK(aura::Env::GetInstance()); | 130 CHECK(aura::Env::GetInstance()); |
130 window_tree_host_.reset( | 131 window_tree_host_.reset( |
131 new CastWindowTreeHost(enable_input_, gfx::Rect(display_size))); | 132 new CastWindowTreeHost(enable_input_, gfx::Rect(display_size))); |
132 window_tree_host_->InitHost(); | 133 window_tree_host_->InitHost(); |
133 window_tree_host_->window()->SetLayoutManager(new CastLayoutManager()); | 134 window_tree_host_->window()->SetLayoutManager(new CastLayoutManager()); |
134 | 135 |
135 // Allow seeing through to the hardware video plane: | 136 // Allow seeing through to the hardware video plane: |
136 window_tree_host_->compositor()->SetHostHasTransparentBackground(true); | 137 window_tree_host_->compositor()->SetHostHasTransparentBackground(true); |
137 window_tree_host_->compositor()->SetBackgroundColor(SK_ColorTRANSPARENT); | 138 window_tree_host_->compositor()->SetBackgroundColor(SK_ColorTRANSPARENT); |
138 | 139 |
140 aura::client::SetFocusClient(window_tree_host_->window(), &focus_client_); | |
139 capture_client_.reset( | 141 capture_client_.reset( |
140 new aura::client::DefaultCaptureClient(window_tree_host_->window())); | 142 new aura::client::DefaultCaptureClient(window_tree_host_->window())); |
141 | 143 |
142 CastVSyncSettings::GetInstance()->AddObserver(this); | 144 CastVSyncSettings::GetInstance()->AddObserver(this); |
143 window_tree_host_->compositor()->SetAuthoritativeVSyncInterval( | 145 window_tree_host_->compositor()->SetAuthoritativeVSyncInterval( |
144 CastVSyncSettings::GetInstance()->GetVSyncInterval()); | 146 CastVSyncSettings::GetInstance()->GetVSyncInterval()); |
145 | 147 |
146 window_tree_host_->Show(); | 148 window_tree_host_->Show(); |
147 } | 149 } |
148 | 150 |
149 void CastWindowManagerAura::TearDown() { | 151 void CastWindowManagerAura::TearDown() { |
150 if (!window_tree_host_) { | 152 if (!window_tree_host_) { |
151 return; | 153 return; |
152 } | 154 } |
155 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
| |
153 CastVSyncSettings::GetInstance()->RemoveObserver(this); | 156 CastVSyncSettings::GetInstance()->RemoveObserver(this); |
154 capture_client_.reset(); | 157 capture_client_.reset(); |
158 aura::client::SetFocusClient(window_tree_host_->window(), nullptr); | |
155 window_tree_host_.reset(); | 159 window_tree_host_.reset(); |
156 } | 160 } |
157 | 161 |
158 void CastWindowManagerAura::AddWindow(gfx::NativeView child) { | 162 void CastWindowManagerAura::AddWindow(gfx::NativeView child) { |
159 LOG(INFO) << "Adding window: " << child->id() << ": " << child->GetName(); | 163 LOG(INFO) << "Adding window: " << child->id() << ": " << child->GetName(); |
160 Setup(); | 164 Setup(); |
161 | 165 |
162 DCHECK(child); | 166 DCHECK(child); |
163 aura::Window* parent = window_tree_host_->window(); | 167 aura::Window* parent = window_tree_host_->window(); |
164 if (!parent->Contains(child)) { | 168 if (!parent->Contains(child)) { |
165 parent->AddChild(child); | 169 parent->AddChild(child); |
166 } | 170 } |
167 | 171 |
168 parent->StackChildAtTop(child); | 172 // Determine z-order relative to existing windows. |
173 aura::Window::Windows windows = parent->children(); | |
174 aura::Window* above = nullptr; | |
175 aura::Window* below = nullptr; | |
176 for (auto&& other : windows) { | |
177 if (other == child) { | |
178 continue; | |
179 } | |
180 if ((other->id() < child->id()) && (!below || other->id() > below->id())) { | |
181 below = other; | |
182 } else if ((other->id() > child->id()) && | |
183 (!above || other->id() < above->id())) { | |
184 above = other; | |
185 } | |
186 } | |
187 | |
188 // Adjust the z-order of the new child window. | |
189 if (above) { | |
190 parent->StackChildBelow(child, above); | |
191 } else if (below) { | |
192 parent->StackChildAbove(child, below); | |
193 } else { | |
194 parent->StackChildAtBottom(child); | |
195 } | |
169 child->SetBounds(window_tree_host_->window()->bounds()); | 196 child->SetBounds(window_tree_host_->window()->bounds()); |
170 } | 197 } |
171 | 198 |
172 void CastWindowManagerAura::OnVSyncIntervalChanged(base::TimeDelta interval) { | 199 void CastWindowManagerAura::OnVSyncIntervalChanged(base::TimeDelta interval) { |
173 DCHECK(window_tree_host_.get()); | 200 DCHECK(window_tree_host_.get()); |
174 window_tree_host_->compositor()->SetAuthoritativeVSyncInterval(interval); | 201 window_tree_host_->compositor()->SetAuthoritativeVSyncInterval(interval); |
175 } | 202 } |
176 | 203 |
177 } // namespace chromecast | 204 } // namespace chromecast |
OLD | NEW |