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

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

Issue 2674683002: Revert: Change CaptureSynchronizer and PointerWatcherEventRouter to support multiple CaptureClients (Closed)
Patch Set: 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
« no previous file with comments | « ui/aura/mus/capture_synchronizer.h ('k') | ui/aura/mus/window_tree_client.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 : delegate_(delegate), window_tree_(window_tree) {} 18 client::CaptureClient* capture_client)
19 : delegate_(delegate),
20 window_tree_(window_tree),
21 capture_client_(capture_client) {
22 capture_client_->AddObserver(this);
23 }
19 24
20 CaptureSynchronizer::~CaptureSynchronizer() {} 25 CaptureSynchronizer::~CaptureSynchronizer() {
26 SetCaptureWindow(nullptr);
27 capture_client_->RemoveObserver(this);
28 }
21 29
22 void CaptureSynchronizer::SetCaptureFromServer(WindowMus* window) { 30 void CaptureSynchronizer::SetCaptureFromServer(WindowMus* window) {
23 if (window == capture_window_) 31 if (window == capture_window_)
24 return; 32 return;
25 33
26 DCHECK(!setting_capture_); 34 DCHECK(!setting_capture_);
27 // Don't immediately set |capture_window_|. It's possible the change 35 // Don't immediately set |capture_client_|. It's possible the change will be
28 // will be rejected. |capture_window_| is set in OnCaptureChanged() if 36 // rejected.
29 // capture succeeds.
30 base::AutoReset<bool> capture_reset(&setting_capture_, true); 37 base::AutoReset<bool> capture_reset(&setting_capture_, true);
31 base::AutoReset<WindowMus*> window_setting_capture_to_reset( 38 base::AutoReset<WindowMus*> window_setting_capture_to_reset(
32 &window_setting_capture_to_, window); 39 &window_setting_capture_to_, window);
33 client::CaptureClient* capture_client = 40 capture_client_->SetCapture(window ? window->GetWindow() : nullptr);
34 window ? client::GetCaptureClient(window->GetWindow()->GetRootWindow())
35 : client::GetCaptureClient(
36 capture_window_->GetWindow()->GetRootWindow());
37 capture_client->SetCapture(window ? window->GetWindow() : nullptr);
38 }
39
40 void CaptureSynchronizer::AttachToCaptureClient(
41 client::CaptureClient* capture_client) {
42 capture_client->AddObserver(this);
43 }
44
45 void CaptureSynchronizer::DetachFromCaptureClient(
46 client::CaptureClient* capture_client) {
47 SetCaptureWindow(nullptr);
48 capture_client->RemoveObserver(this);
49 } 41 }
50 42
51 void CaptureSynchronizer::SetCaptureWindow(WindowMus* window) { 43 void CaptureSynchronizer::SetCaptureWindow(WindowMus* window) {
52 if (capture_window_) 44 if (capture_window_)
53 capture_window_->GetWindow()->RemoveObserver(this); 45 capture_window_->GetWindow()->RemoveObserver(this);
54 capture_window_ = window; 46 capture_window_ = window;
55 if (capture_window_) 47 if (capture_window_)
56 capture_window_->GetWindow()->AddObserver(this); 48 capture_window_->GetWindow()->AddObserver(this);
57 } 49 }
58 50
59 void CaptureSynchronizer::OnWindowDestroying(Window* window) { 51 void CaptureSynchronizer::OnWindowDestroying(Window* window) {
60 // The CaptureClient implementation handles resetting capture when a window 52 // The CaptureClient implementation handles resetting capture when a window
61 // is destroyed, but because of observer ordering this may be called first. 53 // is destroyed, but because of observer ordering this may be called first.
62 DCHECK_EQ(window, capture_window_->GetWindow()); 54 DCHECK_EQ(window, capture_window_->GetWindow());
63 SetCaptureWindow(nullptr); 55 SetCaptureWindow(nullptr);
64 // The server will release capture when a window is destroyed, so no need 56 // The server will release capture when a window is destroyed, so no need
65 // explicitly schedule a change. 57 // explicitly schedule a change.
66 } 58 }
67 59
68 void CaptureSynchronizer::OnCaptureChanged(Window* lost_capture, 60 void CaptureSynchronizer::OnCaptureChanged(Window* lost_capture,
69 Window* gained_capture) { 61 Window* gained_capture) {
70 if (!gained_capture && !capture_window_) 62 if (!gained_capture && !capture_window_)
71 return; // Happens if the window is deleted during notification. 63 return; // Happens if the window is deleted during notification.
72 64
73 // Happens if the window that just lost capture is not the most updated window
74 // that has capture to avoid setting the current |capture_window_| to null by
75 // accident. This can occur because CaptureSynchronizer can be the observer
76 // for multiple capture clients; after we set capture for one capture client
77 // and then set capture for another capture client, releasing capture on the
78 // first capture client could potentially reset the |capture_window_| to null
79 // while the correct |capture_window_| should be the capture window for the
80 // second capture client at that time.
81 if (!gained_capture && lost_capture != capture_window_->GetWindow())
82 return;
83
84 WindowMus* gained_capture_mus = WindowMus::Get(gained_capture); 65 WindowMus* gained_capture_mus = WindowMus::Get(gained_capture);
85 if (setting_capture_ && gained_capture_mus == window_setting_capture_to_) { 66 if (setting_capture_ && gained_capture_mus == window_setting_capture_to_) {
86 SetCaptureWindow(gained_capture_mus); 67 SetCaptureWindow(gained_capture_mus);
87 return; 68 return;
88 } 69 }
89 70
90 const uint32_t change_id = 71 const uint32_t change_id =
91 delegate_->CreateChangeIdForCapture(capture_window_); 72 delegate_->CreateChangeIdForCapture(capture_window_);
92 WindowMus* old_capture_window = capture_window_; 73 WindowMus* old_capture_window = capture_window_;
93 SetCaptureWindow(gained_capture_mus); 74 SetCaptureWindow(gained_capture_mus);
94 if (capture_window_) 75 if (capture_window_)
95 window_tree_->SetCapture(change_id, capture_window_->server_id()); 76 window_tree_->SetCapture(change_id, capture_window_->server_id());
96 else 77 else
97 window_tree_->ReleaseCapture(change_id, old_capture_window->server_id()); 78 window_tree_->ReleaseCapture(change_id, old_capture_window->server_id());
98 } 79 }
99 80
100 } // namespace aura 81 } // namespace aura
OLDNEW
« no previous file with comments | « ui/aura/mus/capture_synchronizer.h ('k') | ui/aura/mus/window_tree_client.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698