Chromium Code Reviews| 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_ && active_focus_client_root_ != root) |
|
msw
2017/04/26 23:01:08
If |is_singleton_focus_client_| is true, should th
sky
2017/04/26 23:30:28
Done.
| |
| 46 SetActiveFocusClient(client::GetFocusClient(root), root); | 46 SetActiveFocusClient(client::GetFocusClient(root), root); |
| 47 window->GetWindow()->Focus(); | 47 window->GetWindow()->Focus(); |
| 48 } else if (active_focus_client_) { | 48 } else if (active_focus_client_) { |
| 49 active_focus_client_->FocusWindow(nullptr); | 49 active_focus_client_->FocusWindow(nullptr); |
| 50 } | 50 } |
| 51 } | 51 } |
| 52 | 52 |
| 53 void FocusSynchronizer::OnFocusedWindowDestroyed() { | 53 void FocusSynchronizer::OnFocusedWindowDestroyed() { |
| 54 focused_window_ = nullptr; | 54 focused_window_ = nullptr; |
| 55 } | 55 } |
| 56 | 56 |
| 57 void FocusSynchronizer::SetSingletonFocusClient( | |
| 58 client::FocusClient* focus_client) { | |
| 59 SetActiveFocusClient(focus_client, nullptr); | |
| 60 if (focus_client) | |
| 61 is_singleton_focus_client_ = true; | |
| 62 } | |
| 63 | |
| 57 void FocusSynchronizer::SetActiveFocusClient(client::FocusClient* focus_client, | 64 void FocusSynchronizer::SetActiveFocusClient(client::FocusClient* focus_client, |
| 58 Window* focus_client_root) { | 65 Window* focus_client_root) { |
| 59 if (focus_client_root == active_focus_client_root_) { | 66 if (focus_client == active_focus_client_ && |
| 60 DCHECK_EQ(focus_client, active_focus_client_); | 67 focus_client_root == active_focus_client_root_) { |
| 61 return; | 68 return; |
| 62 } | 69 } |
| 63 | 70 |
| 71 is_singleton_focus_client_ = false; | |
| 72 | |
| 64 if (active_focus_client_root_) | 73 if (active_focus_client_root_) |
| 65 active_focus_client_root_->RemoveObserver(this); | 74 active_focus_client_root_->RemoveObserver(this); |
| 66 active_focus_client_root_ = focus_client_root; | 75 active_focus_client_root_ = focus_client_root; |
| 67 if (active_focus_client_root_) | 76 if (active_focus_client_root_) |
| 68 active_focus_client_root_->AddObserver(this); | 77 active_focus_client_root_->AddObserver(this); |
| 69 | 78 |
| 79 if (focus_client == active_focus_client_) | |
| 80 return; | |
| 81 | |
| 70 OnActiveFocusClientChanged(focus_client, focus_client_root); | 82 OnActiveFocusClientChanged(focus_client, focus_client_root); |
| 71 for (FocusSynchronizerObserver& observer : observers_) | 83 for (FocusSynchronizerObserver& observer : observers_) |
| 72 observer.OnActiveFocusClientChanged(focus_client, focus_client_root); | 84 observer.OnActiveFocusClientChanged(focus_client, focus_client_root); |
| 73 } | 85 } |
| 74 | 86 |
| 75 void FocusSynchronizer::SetActiveFocusClientInternal( | 87 void FocusSynchronizer::SetActiveFocusClientInternal( |
| 76 client::FocusClient* focus_client) { | 88 client::FocusClient* focus_client) { |
| 77 if (focus_client == active_focus_client_) | 89 if (focus_client == active_focus_client_) |
| 78 return; | 90 return; |
| 79 | 91 |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 111 Window* lost_focus) { | 123 Window* lost_focus) { |
| 112 WindowMus* gained_focus_mus = WindowMus::Get(gained_focus); | 124 WindowMus* gained_focus_mus = WindowMus::Get(gained_focus); |
| 113 if (setting_focus_ && gained_focus_mus == window_setting_focus_to_) { | 125 if (setting_focus_ && gained_focus_mus == window_setting_focus_to_) { |
| 114 focused_window_ = gained_focus_mus; | 126 focused_window_ = gained_focus_mus; |
| 115 return; | 127 return; |
| 116 } | 128 } |
| 117 SetFocusedWindow(gained_focus_mus); | 129 SetFocusedWindow(gained_focus_mus); |
| 118 } | 130 } |
| 119 | 131 |
| 120 void FocusSynchronizer::OnWindowDestroying(Window* window) { | 132 void FocusSynchronizer::OnWindowDestroying(Window* window) { |
| 133 DCHECK(!is_singleton_focus_client_); | |
| 121 SetActiveFocusClient(nullptr, nullptr); | 134 SetActiveFocusClient(nullptr, nullptr); |
| 122 } | 135 } |
| 123 | 136 |
| 124 void FocusSynchronizer::OnWindowPropertyChanged(Window* window, | 137 void FocusSynchronizer::OnWindowPropertyChanged(Window* window, |
| 125 const void* key, | 138 const void* key, |
| 126 intptr_t old) { | 139 intptr_t old) { |
| 140 DCHECK(!is_singleton_focus_client_); | |
| 127 if (key != client::kFocusClientKey) | 141 if (key != client::kFocusClientKey) |
| 128 return; | 142 return; |
| 129 | 143 |
| 130 // Assume if the focus client changes the window is being destroyed. | 144 // Assume if the focus client changes the window is being destroyed. |
| 131 SetActiveFocusClient(nullptr, nullptr); | 145 SetActiveFocusClient(nullptr, nullptr); |
| 132 } | 146 } |
| 133 | 147 |
| 134 } // namespace aura | 148 } // namespace aura |
| OLD | NEW |