| 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/focus_client.h" | 9 #include "ui/aura/client/focus_client.h" |
| 10 #include "ui/aura/env.h" | 10 #include "ui/aura/env.h" |
| 11 #include "ui/aura/mus/focus_synchronizer_delegate.h" | 11 #include "ui/aura/mus/focus_synchronizer_delegate.h" |
| 12 #include "ui/aura/mus/window_mus.h" | 12 #include "ui/aura/mus/window_mus.h" |
| 13 #include "ui/aura/window.h" | 13 #include "ui/aura/window.h" |
| 14 | 14 |
| 15 namespace aura { | 15 namespace aura { |
| 16 | 16 |
| 17 FocusSynchronizer::FocusSynchronizer(FocusSynchronizerDelegate* delegate, | 17 FocusSynchronizer::FocusSynchronizer(FocusSynchronizerDelegate* delegate, |
| 18 ui::mojom::WindowTree* window_tree) | 18 ui::mojom::WindowTree* window_tree) |
| 19 : delegate_(delegate), window_tree_(window_tree), env_(Env::GetInstance()) { | 19 : delegate_(delegate), window_tree_(window_tree) { |
| 20 DCHECK(env_); | 20 Env::GetInstance()->AddObserver(this); |
| 21 env_->AddObserver(this); | |
| 22 } | 21 } |
| 23 | 22 |
| 24 FocusSynchronizer::~FocusSynchronizer() { | 23 FocusSynchronizer::~FocusSynchronizer() { |
| 25 if (env_) { | 24 SetActiveFocusClient(nullptr); |
| 26 SetActiveFocusClient(nullptr); | 25 Env::GetInstance()->RemoveObserver(this); |
| 27 env_->RemoveObserver(this); | |
| 28 } | |
| 29 } | 26 } |
| 30 | 27 |
| 31 void FocusSynchronizer::SetFocusFromServer(WindowMus* window) { | 28 void FocusSynchronizer::SetFocusFromServer(WindowMus* window) { |
| 32 if (focused_window_ == window) | 29 if (focused_window_ == window) |
| 33 return; | 30 return; |
| 34 | 31 |
| 35 DCHECK(!setting_focus_); | 32 DCHECK(!setting_focus_); |
| 36 base::AutoReset<bool> focus_reset(&setting_focus_, true); | 33 base::AutoReset<bool> focus_reset(&setting_focus_, true); |
| 37 base::AutoReset<WindowMus*> window_setting_focus_to_reset( | 34 base::AutoReset<WindowMus*> window_setting_focus_to_reset( |
| 38 &window_setting_focus_to_, window); | 35 &window_setting_focus_to_, window); |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 77 WindowMus* gained_focus_mus = WindowMus::Get(gained_focus); | 74 WindowMus* gained_focus_mus = WindowMus::Get(gained_focus); |
| 78 if (setting_focus_ && gained_focus_mus == window_setting_focus_to_) { | 75 if (setting_focus_ && gained_focus_mus == window_setting_focus_to_) { |
| 79 focused_window_ = gained_focus_mus; | 76 focused_window_ = gained_focus_mus; |
| 80 return; | 77 return; |
| 81 } | 78 } |
| 82 SetFocusedWindow(gained_focus_mus); | 79 SetFocusedWindow(gained_focus_mus); |
| 83 } | 80 } |
| 84 | 81 |
| 85 void FocusSynchronizer::OnWindowInitialized(Window* window) {} | 82 void FocusSynchronizer::OnWindowInitialized(Window* window) {} |
| 86 | 83 |
| 87 void FocusSynchronizer::OnWillDestroyEnv() { | |
| 88 // TODO(sky): this override should not be necessary. http://crbug.com/674803. | |
| 89 SetActiveFocusClient(nullptr); | |
| 90 env_->RemoveObserver(this); | |
| 91 env_ = nullptr; | |
| 92 } | |
| 93 | |
| 94 void FocusSynchronizer::OnActiveFocusClientChanged( | 84 void FocusSynchronizer::OnActiveFocusClientChanged( |
| 95 client::FocusClient* focus_client, | 85 client::FocusClient* focus_client, |
| 96 Window* window) { | 86 Window* window) { |
| 97 SetActiveFocusClient(focus_client); | 87 SetActiveFocusClient(focus_client); |
| 98 if (setting_focus_) | 88 if (setting_focus_) |
| 99 return; | 89 return; |
| 100 | 90 |
| 101 if (focus_client) { | 91 if (focus_client) { |
| 102 Window* focused_window = focus_client->GetFocusedWindow(); | 92 Window* focused_window = focus_client->GetFocusedWindow(); |
| 103 SetFocusedWindow(focused_window ? WindowMus::Get(focused_window) | 93 SetFocusedWindow(focused_window ? WindowMus::Get(focused_window) |
| 104 : WindowMus::Get(window)); | 94 : WindowMus::Get(window)); |
| 105 } else { | 95 } else { |
| 106 SetFocusedWindow(nullptr); | 96 SetFocusedWindow(nullptr); |
| 107 } | 97 } |
| 108 } | 98 } |
| 109 | 99 |
| 110 } // namespace aura | 100 } // namespace aura |
| OLD | NEW |