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

Side by Side Diff: ui/aura/mus/capture_synchronizer.cc

Issue 2626013005: Change CaptureSynchronizer and PointerWatcherEventRouter to support multiple CaptureClients. (Closed)
Patch Set: comments; sequence; test 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 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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 "ui/aura/mus/capture_synchronizer.h" 5 #include "ui/aura/mus/capture_synchronizer.h"
6 6
7 #include "base/auto_reset.h" 7 #include "base/auto_reset.h"
8 #include "services/ui/public/interfaces/window_tree.mojom.h" 8 #include "services/ui/public/interfaces/window_tree.mojom.h"
9 #include "ui/aura/client/capture_client.h" 9 #include "ui/aura/client/capture_client.h"
10 #include "ui/aura/mus/capture_synchronizer_delegate.h" 10 #include "ui/aura/mus/capture_synchronizer_delegate.h"
11 #include "ui/aura/mus/window_mus.h" 11 #include "ui/aura/mus/window_mus.h"
12 #include "ui/aura/window.h" 12 #include "ui/aura/window.h"
13 13
14 namespace aura { 14 namespace aura {
15 15
16 CaptureSynchronizer::CaptureSynchronizer(CaptureSynchronizerDelegate* delegate, 16 CaptureSynchronizer::CaptureSynchronizer(CaptureSynchronizerDelegate* delegate,
17 ui::mojom::WindowTree* window_tree, 17 ui::mojom::WindowTree* window_tree)
18 client::CaptureClient* capture_client) 18 : delegate_(delegate), window_tree_(window_tree) {}
19 : delegate_(delegate),
20 window_tree_(window_tree),
21 capture_client_(capture_client) {
22 capture_client_->AddObserver(this);
23 }
24 19
25 CaptureSynchronizer::~CaptureSynchronizer() { 20 CaptureSynchronizer::~CaptureSynchronizer() {}
26 SetCaptureWindow(nullptr);
27 capture_client_->RemoveObserver(this);
28 }
29 21
30 void CaptureSynchronizer::SetCaptureFromServer(WindowMus* window) { 22 void CaptureSynchronizer::SetCaptureFromServer(WindowMus* window) {
31 if (window == capture_window_) 23 if (window == capture_window_)
32 return; 24 return;
33 25
34 DCHECK(!setting_capture_); 26 DCHECK(!setting_capture_);
35 // Don't immediately set |capture_client_|. It's possible the change will be 27 // Don't immediately set capture client. It's possible the change will be
sadrul 2017/01/30 19:37:58 We do not set the capture client anymore (since we
riajiang 2017/01/30 20:24:09 Done.
36 // rejected. 28 // rejected.
37 base::AutoReset<bool> capture_reset(&setting_capture_, true); 29 base::AutoReset<bool> capture_reset(&setting_capture_, true);
38 base::AutoReset<WindowMus*> window_setting_capture_to_reset( 30 base::AutoReset<WindowMus*> window_setting_capture_to_reset(
39 &window_setting_capture_to_, window); 31 &window_setting_capture_to_, window);
40 capture_client_->SetCapture(window ? window->GetWindow() : nullptr); 32 client::CaptureClient* capture_client =
33 window ? client::GetCaptureClient(window->GetWindow()->GetRootWindow())
34 : client::GetCaptureClient(
35 capture_window_->GetWindow()->GetRootWindow());
36 capture_client->SetCapture(window ? window->GetWindow() : nullptr);
37 }
38
39 void CaptureSynchronizer::AttachToCaptureClient(
40 client::CaptureClient* capture_client) {
41 capture_client->AddObserver(this);
42 }
43
44 void CaptureSynchronizer::DetachFromCaptureClient(
45 client::CaptureClient* capture_client) {
46 SetCaptureWindow(nullptr);
47 capture_client->RemoveObserver(this);
41 } 48 }
42 49
43 void CaptureSynchronizer::SetCaptureWindow(WindowMus* window) { 50 void CaptureSynchronizer::SetCaptureWindow(WindowMus* window) {
44 if (capture_window_) 51 if (capture_window_)
45 capture_window_->GetWindow()->RemoveObserver(this); 52 capture_window_->GetWindow()->RemoveObserver(this);
46 capture_window_ = window; 53 capture_window_ = window;
47 if (capture_window_) 54 if (capture_window_)
48 capture_window_->GetWindow()->AddObserver(this); 55 capture_window_->GetWindow()->AddObserver(this);
49 } 56 }
50 57
51 void CaptureSynchronizer::OnWindowDestroying(Window* window) { 58 void CaptureSynchronizer::OnWindowDestroying(Window* window) {
52 // The CaptureClient implementation handles resetting capture when a window 59 // The CaptureClient implementation handles resetting capture when a window
53 // is destroyed, but because of observer ordering this may be called first. 60 // is destroyed, but because of observer ordering this may be called first.
54 DCHECK_EQ(window, capture_window_->GetWindow()); 61 DCHECK_EQ(window, capture_window_->GetWindow());
55 SetCaptureWindow(nullptr); 62 SetCaptureWindow(nullptr);
56 // The server will release capture when a window is destroyed, so no need 63 // The server will release capture when a window is destroyed, so no need
57 // explicitly schedule a change. 64 // explicitly schedule a change.
58 } 65 }
59 66
60 void CaptureSynchronizer::OnCaptureChanged(Window* lost_capture, 67 void CaptureSynchronizer::OnCaptureChanged(Window* lost_capture,
61 Window* gained_capture) { 68 Window* gained_capture) {
62 if (!gained_capture && !capture_window_) 69 if (!gained_capture && !capture_window_)
63 return; // Happens if the window is deleted during notification. 70 return; // Happens if the window is deleted during notification.
64 71
72 // Happens if the window that just lost capture is not the most updated window
73 // that has capture to avoid setting the current capture_window_ to null by
74 // accident.
sadrul 2017/01/30 19:37:58 This probably needs some farther explanation, e.g.
riajiang 2017/01/30 20:24:09 Updated the comment. WDYT?
75 if (!gained_capture && lost_capture != capture_window_->GetWindow())
76 return;
77
65 WindowMus* gained_capture_mus = WindowMus::Get(gained_capture); 78 WindowMus* gained_capture_mus = WindowMus::Get(gained_capture);
66 if (setting_capture_ && gained_capture_mus == window_setting_capture_to_) { 79 if (setting_capture_ && gained_capture_mus == window_setting_capture_to_) {
67 SetCaptureWindow(gained_capture_mus); 80 SetCaptureWindow(gained_capture_mus);
68 return; 81 return;
69 } 82 }
70 83
71 const uint32_t change_id = 84 const uint32_t change_id =
72 delegate_->CreateChangeIdForCapture(capture_window_); 85 delegate_->CreateChangeIdForCapture(capture_window_);
73 WindowMus* old_capture_window = capture_window_; 86 WindowMus* old_capture_window = capture_window_;
74 SetCaptureWindow(gained_capture_mus); 87 SetCaptureWindow(gained_capture_mus);
75 if (capture_window_) 88 if (capture_window_)
76 window_tree_->SetCapture(change_id, capture_window_->server_id()); 89 window_tree_->SetCapture(change_id, capture_window_->server_id());
77 else 90 else
78 window_tree_->ReleaseCapture(change_id, old_capture_window->server_id()); 91 window_tree_->ReleaseCapture(change_id, old_capture_window->server_id());
79 } 92 }
80 93
81 } // namespace aura 94 } // namespace aura
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698