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

Side by Side Diff: chromecast/graphics/cast_window_manager_aura.cc

Issue 2636303002: [Chromecast] Add support for z-order and window focus. (Closed)
Patch Set: reviewer feedback Created 3 years, 10 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 unified diff | Download patch
OLDNEW
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 "chromecast/graphics/cast_focus_client_aura.h"
8 #include "ui/aura/client/default_capture_client.h" 9 #include "ui/aura/client/default_capture_client.h"
10 #include "ui/aura/client/focus_change_observer.h"
9 #include "ui/aura/env.h" 11 #include "ui/aura/env.h"
10 #include "ui/aura/layout_manager.h" 12 #include "ui/aura/layout_manager.h"
11 #include "ui/aura/window.h" 13 #include "ui/aura/window.h"
12 #include "ui/aura/window_tree_host_platform.h" 14 #include "ui/aura/window_tree_host_platform.h"
13 #include "ui/base/ime/input_method.h" 15 #include "ui/base/ime/input_method.h"
14 #include "ui/base/ime/input_method_factory.h" 16 #include "ui/base/ime/input_method_factory.h"
15 #include "ui/display/display.h" 17 #include "ui/display/display.h"
16 #include "ui/display/screen.h" 18 #include "ui/display/screen.h"
17 19
18 namespace chromecast { 20 namespace chromecast {
19 21
22 // An ui::EventTarget that ignores events.
23 class CastEventIgnorer : public ui::EventTargeter {
24 public:
25 ~CastEventIgnorer() override;
26
27 // ui::EventTargeter implementation:
28 ui::EventTarget* FindTargetForEvent(ui::EventTarget* root,
29 ui::Event* event) override;
30 ui::EventTarget* FindNextBestTarget(ui::EventTarget* previous_target,
31 ui::Event* event) override;
32 };
33
34 CastEventIgnorer::~CastEventIgnorer() {}
35
36 ui::EventTarget* CastEventIgnorer::FindTargetForEvent(ui::EventTarget* root,
37 ui::Event* event) {
38 return nullptr;
39 }
40
41 ui::EventTarget* CastEventIgnorer::FindNextBestTarget(
42 ui::EventTarget* previous_target,
43 ui::Event* event) {
44 return nullptr;
45 }
46
20 // An aura::WindowTreeHost that correctly converts input events. 47 // An aura::WindowTreeHost that correctly converts input events.
21 class CastWindowTreeHost : public aura::WindowTreeHostPlatform { 48 class CastWindowTreeHost : public aura::WindowTreeHostPlatform {
22 public: 49 public:
23 CastWindowTreeHost(bool enable_input, const gfx::Rect& bounds); 50 CastWindowTreeHost(bool enable_input, const gfx::Rect& bounds);
24 ~CastWindowTreeHost() override; 51 ~CastWindowTreeHost() override;
25 52
26 // aura::WindowTreeHostPlatform implementation: 53 // aura::WindowTreeHostPlatform implementation:
27 void DispatchEvent(ui::Event* event) override; 54 void DispatchEvent(ui::Event* event) override;
28 55
29 private: 56 private:
30 const bool enable_input_; 57 const bool enable_input_;
31 58
32 DISALLOW_COPY_AND_ASSIGN(CastWindowTreeHost); 59 DISALLOW_COPY_AND_ASSIGN(CastWindowTreeHost);
33 }; 60 };
34 61
35 CastWindowTreeHost::CastWindowTreeHost(bool enable_input, 62 CastWindowTreeHost::CastWindowTreeHost(bool enable_input,
36 const gfx::Rect& bounds) 63 const gfx::Rect& bounds)
37 : WindowTreeHostPlatform(bounds), enable_input_(enable_input) {} 64 : WindowTreeHostPlatform(bounds), enable_input_(enable_input) {
65 if (!enable_input) {
66 window()->SetEventTargeter(
67 std::unique_ptr<ui::EventTargeter>(new CastEventIgnorer));
68 }
69 }
38 70
39 CastWindowTreeHost::~CastWindowTreeHost() {} 71 CastWindowTreeHost::~CastWindowTreeHost() {}
40 72
41 void CastWindowTreeHost::DispatchEvent(ui::Event* event) { 73 void CastWindowTreeHost::DispatchEvent(ui::Event* event) {
42 if (!enable_input_) { 74 if (!enable_input_) {
43 return; 75 return;
44 } 76 }
45 77
46 if (event->IsKeyEvent()) { 78 if (event->IsKeyEvent()) {
47 // Convert a RawKeyDown into a character insertion; otherwise 79 // Convert a RawKeyDown into a character insertion; otherwise
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
129 CHECK(aura::Env::GetInstance()); 161 CHECK(aura::Env::GetInstance());
130 window_tree_host_.reset( 162 window_tree_host_.reset(
131 new CastWindowTreeHost(enable_input_, gfx::Rect(display_size))); 163 new CastWindowTreeHost(enable_input_, gfx::Rect(display_size)));
132 window_tree_host_->InitHost(); 164 window_tree_host_->InitHost();
133 window_tree_host_->window()->SetLayoutManager(new CastLayoutManager()); 165 window_tree_host_->window()->SetLayoutManager(new CastLayoutManager());
134 166
135 // Allow seeing through to the hardware video plane: 167 // Allow seeing through to the hardware video plane:
136 window_tree_host_->compositor()->SetHostHasTransparentBackground(true); 168 window_tree_host_->compositor()->SetHostHasTransparentBackground(true);
137 window_tree_host_->compositor()->SetBackgroundColor(SK_ColorTRANSPARENT); 169 window_tree_host_->compositor()->SetBackgroundColor(SK_ColorTRANSPARENT);
138 170
171 focus_client_.reset(new CastFocusClientAura());
172 aura::client::SetFocusClient(window_tree_host_->window(),
173 focus_client_.get());
139 capture_client_.reset( 174 capture_client_.reset(
140 new aura::client::DefaultCaptureClient(window_tree_host_->window())); 175 new aura::client::DefaultCaptureClient(window_tree_host_->window()));
141 176
142 CastVSyncSettings::GetInstance()->AddObserver(this); 177 CastVSyncSettings::GetInstance()->AddObserver(this);
143 window_tree_host_->compositor()->SetAuthoritativeVSyncInterval( 178 window_tree_host_->compositor()->SetAuthoritativeVSyncInterval(
144 CastVSyncSettings::GetInstance()->GetVSyncInterval()); 179 CastVSyncSettings::GetInstance()->GetVSyncInterval());
145 180
146 window_tree_host_->Show(); 181 window_tree_host_->Show();
147 } 182 }
148 183
149 void CastWindowManagerAura::TearDown() { 184 void CastWindowManagerAura::TearDown() {
150 if (!window_tree_host_) { 185 if (!window_tree_host_) {
151 return; 186 return;
152 } 187 }
153 CastVSyncSettings::GetInstance()->RemoveObserver(this); 188 CastVSyncSettings::GetInstance()->RemoveObserver(this);
154 capture_client_.reset(); 189 capture_client_.reset();
190 aura::client::SetFocusClient(window_tree_host_->window(), nullptr);
191 focus_client_.reset();
155 window_tree_host_.reset(); 192 window_tree_host_.reset();
156 } 193 }
157 194
158 void CastWindowManagerAura::AddWindow(gfx::NativeView child) { 195 void CastWindowManagerAura::AddWindow(gfx::NativeView child) {
159 LOG(INFO) << "Adding window: " << child->id() << ": " << child->GetName(); 196 LOG(INFO) << "Adding window: " << child->id() << ": " << child->GetName();
160 Setup(); 197 Setup();
161 198
162 DCHECK(child); 199 DCHECK(child);
163 aura::Window* parent = window_tree_host_->window(); 200 aura::Window* parent = window_tree_host_->window();
164 if (!parent->Contains(child)) { 201 if (!parent->Contains(child)) {
165 parent->AddChild(child); 202 parent->AddChild(child);
166 } 203 }
167 204
168 parent->StackChildAtTop(child); 205 // Determine z-order relative to existing windows.
206 aura::Window::Windows windows = parent->children();
207 aura::Window* above = nullptr;
208 aura::Window* below = nullptr;
209 for (auto* other : windows) {
210 if (other == child) {
211 continue;
212 }
213 if ((other->id() < child->id()) && (!below || other->id() > below->id())) {
214 below = other;
215 } else if ((other->id() > child->id()) &&
216 (!above || other->id() < above->id())) {
217 above = other;
218 }
219 }
220
221 // Adjust the z-order of the new child window.
222 if (above) {
223 parent->StackChildBelow(child, above);
224 } else if (below) {
225 parent->StackChildAbove(child, below);
226 } else {
227 parent->StackChildAtBottom(child);
228 }
169 child->SetBounds(window_tree_host_->window()->bounds()); 229 child->SetBounds(window_tree_host_->window()->bounds());
170 } 230 }
171 231
172 void CastWindowManagerAura::OnVSyncIntervalChanged(base::TimeDelta interval) { 232 void CastWindowManagerAura::OnVSyncIntervalChanged(base::TimeDelta interval) {
173 DCHECK(window_tree_host_.get()); 233 DCHECK(window_tree_host_.get());
174 window_tree_host_->compositor()->SetAuthoritativeVSyncInterval(interval); 234 window_tree_host_->compositor()->SetAuthoritativeVSyncInterval(interval);
175 } 235 }
176 236
177 } // namespace chromecast 237 } // namespace chromecast
OLDNEW
« no previous file with comments | « chromecast/graphics/cast_window_manager_aura.h ('k') | chromecast/graphics/cast_window_manager_aura_test.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698