| Index: ui/aura/mus/focus_synchronizer.cc
|
| diff --git a/ui/aura/mus/focus_synchronizer.cc b/ui/aura/mus/focus_synchronizer.cc
|
| index b211315fc9ca0c97d991b01993559d1fe0cd4d51..6c8ba8c3951828879b2de3a24aa8dcee944cb0f1 100644
|
| --- a/ui/aura/mus/focus_synchronizer.cc
|
| +++ b/ui/aura/mus/focus_synchronizer.cc
|
| @@ -6,23 +6,27 @@
|
|
|
| #include "base/auto_reset.h"
|
| #include "services/ui/public/interfaces/window_tree.mojom.h"
|
| +#include "ui/aura/client/aura_constants.h"
|
| #include "ui/aura/client/focus_client.h"
|
| -#include "ui/aura/env.h"
|
| #include "ui/aura/mus/focus_synchronizer_delegate.h"
|
| -#include "ui/aura/mus/window_mus.h"
|
| #include "ui/aura/window.h"
|
|
|
| namespace aura {
|
|
|
| FocusSynchronizer::FocusSynchronizer(FocusSynchronizerDelegate* delegate,
|
| ui::mojom::WindowTree* window_tree)
|
| - : delegate_(delegate), window_tree_(window_tree) {
|
| - Env::GetInstance()->AddObserver(this);
|
| -}
|
| + : delegate_(delegate), window_tree_(window_tree) {}
|
|
|
| FocusSynchronizer::~FocusSynchronizer() {
|
| SetActiveFocusClient(nullptr);
|
| - Env::GetInstance()->RemoveObserver(this);
|
| +}
|
| +
|
| +void FocusSynchronizer::AddObserver(FocusSynchronizerObserver* observer) {
|
| + observers_.AddObserver(observer);
|
| +}
|
| +
|
| +void FocusSynchronizer::RemoveObserver(FocusSynchronizerObserver* observer) {
|
| + observers_.RemoveObserver(observer);
|
| }
|
|
|
| void FocusSynchronizer::SetFocusFromServer(WindowMus* window) {
|
| @@ -33,23 +37,37 @@ void FocusSynchronizer::SetFocusFromServer(WindowMus* window) {
|
| base::AutoReset<bool> focus_reset(&setting_focus_, true);
|
| base::AutoReset<WindowMus*> window_setting_focus_to_reset(
|
| &window_setting_focus_to_, window);
|
| - Env* env = Env::GetInstance();
|
| +
|
| if (window) {
|
| Window* root = window->GetWindow()->GetRootWindow();
|
| // The client should provide a focus client for all roots.
|
| DCHECK(client::GetFocusClient(root));
|
| - if (env->active_focus_client_root() != root)
|
| - env->SetActiveFocusClient(client::GetFocusClient(root), root);
|
| + if (focused_window() != root)
|
| + OnActiveFocusClientChanged(client::GetFocusClient(root), root);
|
| window->GetWindow()->Focus();
|
| - } else if (env->active_focus_client()) {
|
| - env->active_focus_client()->FocusWindow(nullptr);
|
| + } else if (active_focus_client_) {
|
| + active_focus_client_->FocusWindow(nullptr);
|
| }
|
| }
|
|
|
| void FocusSynchronizer::OnFocusedWindowDestroyed() {
|
| + UpdateFocusedWindowObserver(nullptr);
|
| focused_window_ = nullptr;
|
| }
|
|
|
| +void FocusSynchronizer::AttachToFocusClient(client::FocusClient* focus_client,
|
| + Window* focus_client_root) {
|
| + OnActiveFocusClientChanged(focus_client, focus_client_root);
|
| +}
|
| +
|
| +void FocusSynchronizer::DetachFromFocusClient(
|
| + client::FocusClient* focus_client) {
|
| + if (focus_client == active_focus_client_)
|
| + OnActiveFocusClientChanged(nullptr, nullptr);
|
| + else
|
| + focus_client->RemoveObserver(this);
|
| +}
|
| +
|
| void FocusSynchronizer::SetActiveFocusClient(
|
| client::FocusClient* focus_client) {
|
| if (focus_client == active_focus_client_)
|
| @@ -62,6 +80,13 @@ void FocusSynchronizer::SetActiveFocusClient(
|
| active_focus_client_->AddObserver(this);
|
| }
|
|
|
| +void FocusSynchronizer::UpdateFocusedWindowObserver(Window* window) {
|
| + if (focused_window())
|
| + focused_window()->RemoveObserver(this);
|
| + if (window)
|
| + window->AddObserver(this);
|
| +}
|
| +
|
| void FocusSynchronizer::SetFocusedWindow(WindowMus* window) {
|
| const uint32_t change_id = delegate_->CreateChangeIdForFocus(focused_window_);
|
| focused_window_ = window;
|
| @@ -69,32 +94,53 @@ void FocusSynchronizer::SetFocusedWindow(WindowMus* window) {
|
| window ? window->server_id() : kInvalidServerId);
|
| }
|
|
|
| -void FocusSynchronizer::OnWindowFocused(Window* gained_focus,
|
| - Window* lost_focus) {
|
| - WindowMus* gained_focus_mus = WindowMus::Get(gained_focus);
|
| - if (setting_focus_ && gained_focus_mus == window_setting_focus_to_) {
|
| - focused_window_ = gained_focus_mus;
|
| - return;
|
| - }
|
| - SetFocusedWindow(gained_focus_mus);
|
| -}
|
| -
|
| -void FocusSynchronizer::OnWindowInitialized(Window* window) {}
|
| -
|
| void FocusSynchronizer::OnActiveFocusClientChanged(
|
| client::FocusClient* focus_client,
|
| Window* window) {
|
| + if (focus_client == active_focus_client_ && window == focused_window())
|
| + return;
|
| +
|
| SetActiveFocusClient(focus_client);
|
| if (setting_focus_)
|
| return;
|
|
|
| if (focus_client) {
|
| Window* focused_window = focus_client->GetFocusedWindow();
|
| + UpdateFocusedWindowObserver(focused_window ? focused_window : window);
|
| SetFocusedWindow(focused_window ? WindowMus::Get(focused_window)
|
| : WindowMus::Get(window));
|
| } else {
|
| + UpdateFocusedWindowObserver(nullptr);
|
| SetFocusedWindow(nullptr);
|
| }
|
| +
|
| + for (FocusSynchronizerObserver& observer : observers_)
|
| + observer.OnActiveFocusClientChanged(focus_client, window);
|
| +}
|
| +
|
| +void FocusSynchronizer::OnWindowDestroying(Window* window) {
|
| + OnActiveFocusClientChanged(nullptr, nullptr);
|
| +}
|
| +
|
| +void FocusSynchronizer::OnWindowPropertyChanged(Window* window,
|
| + const void* key,
|
| + intptr_t old) {
|
| + if (key != client::kFocusClientKey)
|
| + return;
|
| +
|
| + // Assume if the focus client changes the window is being destroyed.
|
| + OnActiveFocusClientChanged(nullptr, nullptr);
|
| +}
|
| +
|
| +void FocusSynchronizer::OnWindowFocused(Window* gained_focus,
|
| + Window* lost_focus) {
|
| + WindowMus* gained_focus_mus = WindowMus::Get(gained_focus);
|
| + UpdateFocusedWindowObserver(gained_focus);
|
| + if (setting_focus_ && gained_focus_mus == window_setting_focus_to_) {
|
| + focused_window_ = gained_focus_mus;
|
| + return;
|
| + }
|
| + SetFocusedWindow(gained_focus_mus);
|
| }
|
|
|
| } // namespace aura
|
|
|