OLD | NEW |
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/focus_synchronizer.h" | 5 #include "ui/aura/mus/focus_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/aura_constants.h" | 9 #include "ui/aura/client/aura_constants.h" |
10 #include "ui/aura/client/focus_client.h" | 10 #include "ui/aura/client/focus_client.h" |
(...skipping 24 matching lines...) Expand all Loading... |
35 return; | 35 return; |
36 | 36 |
37 DCHECK(!setting_focus_); | 37 DCHECK(!setting_focus_); |
38 base::AutoReset<bool> focus_reset(&setting_focus_, true); | 38 base::AutoReset<bool> focus_reset(&setting_focus_, true); |
39 base::AutoReset<WindowMus*> window_setting_focus_to_reset( | 39 base::AutoReset<WindowMus*> window_setting_focus_to_reset( |
40 &window_setting_focus_to_, window); | 40 &window_setting_focus_to_, window); |
41 if (window) { | 41 if (window) { |
42 Window* root = window->GetWindow()->GetRootWindow(); | 42 Window* root = window->GetWindow()->GetRootWindow(); |
43 // The client should provide a focus client for all roots. | 43 // The client should provide a focus client for all roots. |
44 DCHECK(client::GetFocusClient(root)); | 44 DCHECK(client::GetFocusClient(root)); |
45 if (active_focus_client_root_ != root) | 45 if (is_singleton_focus_client_) |
| 46 DCHECK_EQ(active_focus_client_, client::GetFocusClient(root)); |
| 47 else if (active_focus_client_root_ != root) |
46 SetActiveFocusClient(client::GetFocusClient(root), root); | 48 SetActiveFocusClient(client::GetFocusClient(root), root); |
47 window->GetWindow()->Focus(); | 49 window->GetWindow()->Focus(); |
48 } else if (active_focus_client_) { | 50 } else if (active_focus_client_) { |
49 active_focus_client_->FocusWindow(nullptr); | 51 active_focus_client_->FocusWindow(nullptr); |
50 } | 52 } |
51 } | 53 } |
52 | 54 |
53 void FocusSynchronizer::OnFocusedWindowDestroyed() { | 55 void FocusSynchronizer::OnFocusedWindowDestroyed() { |
54 focused_window_ = nullptr; | 56 focused_window_ = nullptr; |
55 } | 57 } |
56 | 58 |
| 59 void FocusSynchronizer::SetSingletonFocusClient( |
| 60 client::FocusClient* focus_client) { |
| 61 SetActiveFocusClient(focus_client, nullptr); |
| 62 if (focus_client) |
| 63 is_singleton_focus_client_ = true; |
| 64 } |
| 65 |
57 void FocusSynchronizer::SetActiveFocusClient(client::FocusClient* focus_client, | 66 void FocusSynchronizer::SetActiveFocusClient(client::FocusClient* focus_client, |
58 Window* focus_client_root) { | 67 Window* focus_client_root) { |
59 if (focus_client_root == active_focus_client_root_) { | 68 if (focus_client == active_focus_client_ && |
60 DCHECK_EQ(focus_client, active_focus_client_); | 69 focus_client_root == active_focus_client_root_) { |
61 return; | 70 return; |
62 } | 71 } |
63 | 72 |
| 73 is_singleton_focus_client_ = false; |
| 74 |
64 if (active_focus_client_root_) | 75 if (active_focus_client_root_) |
65 active_focus_client_root_->RemoveObserver(this); | 76 active_focus_client_root_->RemoveObserver(this); |
66 active_focus_client_root_ = focus_client_root; | 77 active_focus_client_root_ = focus_client_root; |
67 if (active_focus_client_root_) | 78 if (active_focus_client_root_) |
68 active_focus_client_root_->AddObserver(this); | 79 active_focus_client_root_->AddObserver(this); |
69 | 80 |
| 81 if (focus_client == active_focus_client_) |
| 82 return; |
| 83 |
70 OnActiveFocusClientChanged(focus_client, focus_client_root); | 84 OnActiveFocusClientChanged(focus_client, focus_client_root); |
71 for (FocusSynchronizerObserver& observer : observers_) | 85 for (FocusSynchronizerObserver& observer : observers_) |
72 observer.OnActiveFocusClientChanged(focus_client, focus_client_root); | 86 observer.OnActiveFocusClientChanged(focus_client, focus_client_root); |
73 } | 87 } |
74 | 88 |
75 void FocusSynchronizer::SetActiveFocusClientInternal( | 89 void FocusSynchronizer::SetActiveFocusClientInternal( |
76 client::FocusClient* focus_client) { | 90 client::FocusClient* focus_client) { |
77 if (focus_client == active_focus_client_) | 91 if (focus_client == active_focus_client_) |
78 return; | 92 return; |
79 | 93 |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
111 Window* lost_focus) { | 125 Window* lost_focus) { |
112 WindowMus* gained_focus_mus = WindowMus::Get(gained_focus); | 126 WindowMus* gained_focus_mus = WindowMus::Get(gained_focus); |
113 if (setting_focus_ && gained_focus_mus == window_setting_focus_to_) { | 127 if (setting_focus_ && gained_focus_mus == window_setting_focus_to_) { |
114 focused_window_ = gained_focus_mus; | 128 focused_window_ = gained_focus_mus; |
115 return; | 129 return; |
116 } | 130 } |
117 SetFocusedWindow(gained_focus_mus); | 131 SetFocusedWindow(gained_focus_mus); |
118 } | 132 } |
119 | 133 |
120 void FocusSynchronizer::OnWindowDestroying(Window* window) { | 134 void FocusSynchronizer::OnWindowDestroying(Window* window) { |
| 135 DCHECK(!is_singleton_focus_client_); |
121 SetActiveFocusClient(nullptr, nullptr); | 136 SetActiveFocusClient(nullptr, nullptr); |
122 } | 137 } |
123 | 138 |
124 void FocusSynchronizer::OnWindowPropertyChanged(Window* window, | 139 void FocusSynchronizer::OnWindowPropertyChanged(Window* window, |
125 const void* key, | 140 const void* key, |
126 intptr_t old) { | 141 intptr_t old) { |
| 142 DCHECK(!is_singleton_focus_client_); |
127 if (key != client::kFocusClientKey) | 143 if (key != client::kFocusClientKey) |
128 return; | 144 return; |
129 | 145 |
130 // Assume if the focus client changes the window is being destroyed. | 146 // Assume if the focus client changes the window is being destroyed. |
131 SetActiveFocusClient(nullptr, nullptr); | 147 SetActiveFocusClient(nullptr, nullptr); |
132 } | 148 } |
133 | 149 |
134 } // namespace aura | 150 } // namespace aura |
OLD | NEW |