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 #ifndef UI_AURA_MUS_FOCUS_SYNCHRONIZER_H_ | 5 #ifndef UI_AURA_MUS_FOCUS_SYNCHRONIZER_H_ |
| 6 #define UI_AURA_MUS_FOCUS_SYNCHRONIZER_H_ | 6 #define UI_AURA_MUS_FOCUS_SYNCHRONIZER_H_ |
| 7 | 7 |
| 8 #include "base/macros.h" | 8 #include "base/macros.h" |
| 9 #include "base/observer_list.h" | |
| 10 #include "ui/aura/aura_export.h" | |
| 9 #include "ui/aura/client/focus_change_observer.h" | 11 #include "ui/aura/client/focus_change_observer.h" |
| 10 #include "ui/aura/env_observer.h" | 12 #include "ui/aura/mus/focus_synchronizer_observer.h" |
| 13 #include "ui/aura/window_observer.h" | |
| 11 | 14 |
| 12 namespace ui { | 15 namespace ui { |
| 13 namespace mojom { | 16 namespace mojom { |
| 14 class WindowTree; | 17 class WindowTree; |
| 15 } | 18 } |
| 16 } | 19 } |
| 17 | 20 |
| 18 namespace aura { | 21 namespace aura { |
| 19 | 22 |
| 20 class FocusSynchronizerDelegate; | 23 class FocusSynchronizerDelegate; |
| 21 class WindowMus; | 24 class WindowMus; |
| 22 | 25 |
| 23 namespace client { | 26 namespace client { |
| 24 class FocusClient; | 27 class FocusClient; |
| 25 } | 28 } |
| 26 | 29 |
| 27 // FocusSynchronizer is resonsible for keeping focus in sync between aura | 30 // FocusSynchronizer is resonsible for keeping focus in sync between aura |
| 28 // and the mus server. | 31 // and the mus server. |
| 29 class FocusSynchronizer : public client::FocusChangeObserver, | 32 class AURA_EXPORT FocusSynchronizer : public client::FocusChangeObserver, |
| 30 public EnvObserver { | 33 public WindowObserver { |
| 31 public: | 34 public: |
| 32 FocusSynchronizer(FocusSynchronizerDelegate* delegate, | 35 FocusSynchronizer(FocusSynchronizerDelegate* delegate, |
| 33 ui::mojom::WindowTree* window_tree); | 36 ui::mojom::WindowTree* window_tree); |
| 34 ~FocusSynchronizer() override; | 37 ~FocusSynchronizer() override; |
| 35 | 38 |
| 39 client::FocusClient* active_focus_client() { return active_focus_client_; } | |
| 40 Window* active_focus_client_root() { return active_focus_client_root_; } | |
| 41 WindowMus* focused_window() { return focused_window_; } | |
|
sadrul
2017/03/28 15:03:23
Doesn't look like this is actually ever used by an
riajiang
2017/03/28 22:07:27
It is used by WindowTreeClient::OnWindowMusDestroy
| |
| 42 | |
| 43 // Add and remove observers to the FocusSynchronizer to get notified when the | |
| 44 // |active_focus_client_| and the |active_focus_client_root_| change. | |
| 45 void AddObserver(FocusSynchronizerObserver* observer); | |
| 46 void RemoveObserver(FocusSynchronizerObserver* observer); | |
| 47 | |
| 36 // Called when the server side wants to change focus to |window|. | 48 // Called when the server side wants to change focus to |window|. |
| 37 void SetFocusFromServer(WindowMus* window); | 49 void SetFocusFromServer(WindowMus* window); |
| 38 | 50 |
| 39 // Called when the focused window is destroyed. | 51 // Called when the focused window is destroyed. |
| 40 void OnFocusedWindowDestroyed(); | 52 void OnFocusedWindowDestroyed(); |
| 41 | 53 |
| 42 WindowMus* focused_window() { return focused_window_; } | 54 // Sets the active FocusClient and the window the FocusClient is associated |
| 55 // with. |focus_client_root| is not necessarily the window that actually has | |
| 56 // focus. |focus_client_root| may be null, which indicates all windows share | |
| 57 // a FocusClient. | |
|
sadrul
2017/03/28 15:03:23
Why would a null |focus_client_root| imply all win
riajiang
2017/03/28 22:07:27
I copied this comment from aura::Env::SetActiveFoc
| |
| 58 void SetActiveFocusClient(client::FocusClient* focus_client, | |
| 59 Window* focus_client_root); | |
| 43 | 60 |
| 44 private: | 61 private: |
| 45 void SetActiveFocusClient(client::FocusClient* focus_client); | 62 // Called internally to set |active_focus_client_| and update observer. |
| 63 void SetActiveFocusClientInternal(client::FocusClient* focus_client); | |
| 46 | 64 |
| 47 // Called internally to set |focused_window_| and update the server. | 65 // Called internally to set |focused_window_| and update the server. |
| 48 void SetFocusedWindow(WindowMus* window); | 66 void SetFocusedWindow(WindowMus* window); |
| 49 | 67 |
| 50 // Overriden from client::FocusChangeObserver: | 68 // Called internally when notified that |active_focus_client_| and |
| 69 // |active_focus_client_root_| have been changed. | |
| 70 void OnActiveFocusClientChanged(client::FocusClient* focus_client, | |
| 71 Window* focus_client_root); | |
| 72 | |
| 73 // client::FocusChangeObserver: | |
| 51 void OnWindowFocused(Window* gained_focus, Window* lost_focus) override; | 74 void OnWindowFocused(Window* gained_focus, Window* lost_focus) override; |
| 52 | 75 |
| 53 // Overrided from EnvObserver: | 76 // WindowObserver: |
| 54 void OnWindowInitialized(Window* window) override; | 77 void OnWindowDestroying(Window* window) override; |
| 55 void OnActiveFocusClientChanged(client::FocusClient* focus_client, | 78 void OnWindowPropertyChanged(Window* window, |
| 56 Window* window) override; | 79 const void* key, |
| 80 intptr_t old) override; | |
| 57 | 81 |
| 58 FocusSynchronizerDelegate* delegate_; | 82 FocusSynchronizerDelegate* delegate_; |
| 59 ui::mojom::WindowTree* window_tree_; | 83 ui::mojom::WindowTree* window_tree_; |
| 60 | 84 |
| 61 client::FocusClient* active_focus_client_ = nullptr; | 85 base::ObserverList<FocusSynchronizerObserver> observers_; |
| 62 | 86 |
| 63 bool setting_focus_ = false; | 87 bool setting_focus_ = false; |
| 64 WindowMus* window_setting_focus_to_ = nullptr; | 88 WindowMus* window_setting_focus_to_ = nullptr; |
| 89 | |
| 90 client::FocusClient* active_focus_client_ = nullptr; | |
| 91 // The window that |active_focus_client_| is associated with. | |
| 92 Window* active_focus_client_root_ = nullptr; | |
| 93 // The window that actually has focus. | |
| 65 WindowMus* focused_window_ = nullptr; | 94 WindowMus* focused_window_ = nullptr; |
| 66 | 95 |
| 67 DISALLOW_COPY_AND_ASSIGN(FocusSynchronizer); | 96 DISALLOW_COPY_AND_ASSIGN(FocusSynchronizer); |
| 68 }; | 97 }; |
| 69 | 98 |
| 70 } // namespace aura | 99 } // namespace aura |
| 71 | 100 |
| 72 #endif // UI_AURA_MUS_FOCUS_SYNCHRONIZER_H_ | 101 #endif // UI_AURA_MUS_FOCUS_SYNCHRONIZER_H_ |
| OLD | NEW |