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/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), env_(Env::GetInstance()) { |
| 20 DCHECK(env_); | 20 DCHECK(env_); |
| 21 env_->AddObserver(this); | 21 env_->AddObserver(this); |
| 22 } | 22 } |
| 23 | 23 |
| 24 FocusSynchronizer::~FocusSynchronizer() { | 24 FocusSynchronizer::~FocusSynchronizer() { |
| 25 if (env_) { | 25 if (env_) { |
|
msw
2016/12/21 17:56:35
optional nit: don't cache Env::GetInstance, just c
sadrul
2016/12/21 18:03:36
Nice! Done. Thanks!
| |
| 26 SetActiveFocusClient(nullptr); | 26 SetActiveFocusClient(nullptr); |
| 27 env_->RemoveObserver(this); | 27 env_->RemoveObserver(this); |
| 28 } | 28 } |
| 29 } | 29 } |
| 30 | 30 |
| 31 void FocusSynchronizer::SetFocusFromServer(WindowMus* window) { | 31 void FocusSynchronizer::SetFocusFromServer(WindowMus* window) { |
| 32 if (focused_window_ == window) | 32 if (focused_window_ == window) |
| 33 return; | 33 return; |
| 34 | 34 |
| 35 DCHECK(!setting_focus_); | 35 DCHECK(!setting_focus_); |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 77 WindowMus* gained_focus_mus = WindowMus::Get(gained_focus); | 77 WindowMus* gained_focus_mus = WindowMus::Get(gained_focus); |
| 78 if (setting_focus_ && gained_focus_mus == window_setting_focus_to_) { | 78 if (setting_focus_ && gained_focus_mus == window_setting_focus_to_) { |
| 79 focused_window_ = gained_focus_mus; | 79 focused_window_ = gained_focus_mus; |
| 80 return; | 80 return; |
| 81 } | 81 } |
| 82 SetFocusedWindow(gained_focus_mus); | 82 SetFocusedWindow(gained_focus_mus); |
| 83 } | 83 } |
| 84 | 84 |
| 85 void FocusSynchronizer::OnWindowInitialized(Window* window) {} | 85 void FocusSynchronizer::OnWindowInitialized(Window* window) {} |
| 86 | 86 |
| 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( | 87 void FocusSynchronizer::OnActiveFocusClientChanged( |
| 95 client::FocusClient* focus_client, | 88 client::FocusClient* focus_client, |
| 96 Window* window) { | 89 Window* window) { |
| 97 SetActiveFocusClient(focus_client); | 90 SetActiveFocusClient(focus_client); |
| 98 if (setting_focus_) | 91 if (setting_focus_) |
| 99 return; | 92 return; |
| 100 | 93 |
| 101 if (focus_client) { | 94 if (focus_client) { |
| 102 Window* focused_window = focus_client->GetFocusedWindow(); | 95 Window* focused_window = focus_client->GetFocusedWindow(); |
| 103 SetFocusedWindow(focused_window ? WindowMus::Get(focused_window) | 96 SetFocusedWindow(focused_window ? WindowMus::Get(focused_window) |
| 104 : WindowMus::Get(window)); | 97 : WindowMus::Get(window)); |
| 105 } else { | 98 } else { |
| 106 SetFocusedWindow(nullptr); | 99 SetFocusedWindow(nullptr); |
| 107 } | 100 } |
| 108 } | 101 } |
| 109 | 102 |
| 110 } // namespace aura | 103 } // namespace aura |
| OLD | NEW |