| 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_; } |
| 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. |
| 57 void SetActiveFocusClient(client::FocusClient* focus_client, |
| 58 Window* focus_client_root); |
| 43 | 59 |
| 44 private: | 60 private: |
| 45 void SetActiveFocusClient(client::FocusClient* focus_client); | 61 // Called internally to set |active_focus_client_| and update observer. |
| 62 void SetActiveFocusClientInternal(client::FocusClient* focus_client); |
| 46 | 63 |
| 47 // Called internally to set |focused_window_| and update the server. | 64 // Called internally to set |focused_window_| and update the server. |
| 48 void SetFocusedWindow(WindowMus* window); | 65 void SetFocusedWindow(WindowMus* window); |
| 49 | 66 |
| 50 // Overriden from client::FocusChangeObserver: | 67 // Called internally when notified that |active_focus_client_| and |
| 68 // |active_focus_client_root_| have been changed. |
| 69 void OnActiveFocusClientChanged(client::FocusClient* focus_client, |
| 70 Window* focus_client_root); |
| 71 |
| 72 // client::FocusChangeObserver: |
| 51 void OnWindowFocused(Window* gained_focus, Window* lost_focus) override; | 73 void OnWindowFocused(Window* gained_focus, Window* lost_focus) override; |
| 52 | 74 |
| 53 // Overrided from EnvObserver: | 75 // WindowObserver: |
| 54 void OnWindowInitialized(Window* window) override; | 76 void OnWindowDestroying(Window* window) override; |
| 55 void OnActiveFocusClientChanged(client::FocusClient* focus_client, | 77 void OnWindowPropertyChanged(Window* window, |
| 56 Window* window) override; | 78 const void* key, |
| 79 intptr_t old) override; |
| 57 | 80 |
| 58 FocusSynchronizerDelegate* delegate_; | 81 FocusSynchronizerDelegate* delegate_; |
| 59 ui::mojom::WindowTree* window_tree_; | 82 ui::mojom::WindowTree* window_tree_; |
| 60 | 83 |
| 61 client::FocusClient* active_focus_client_ = nullptr; | 84 base::ObserverList<FocusSynchronizerObserver> observers_; |
| 62 | 85 |
| 63 bool setting_focus_ = false; | 86 bool setting_focus_ = false; |
| 64 WindowMus* window_setting_focus_to_ = nullptr; | 87 WindowMus* window_setting_focus_to_ = nullptr; |
| 88 |
| 89 client::FocusClient* active_focus_client_ = nullptr; |
| 90 // The window that |active_focus_client_| is associated with. |
| 91 Window* active_focus_client_root_ = nullptr; |
| 92 // The window that actually has focus. |
| 65 WindowMus* focused_window_ = nullptr; | 93 WindowMus* focused_window_ = nullptr; |
| 66 | 94 |
| 67 DISALLOW_COPY_AND_ASSIGN(FocusSynchronizer); | 95 DISALLOW_COPY_AND_ASSIGN(FocusSynchronizer); |
| 68 }; | 96 }; |
| 69 | 97 |
| 70 } // namespace aura | 98 } // namespace aura |
| 71 | 99 |
| 72 #endif // UI_AURA_MUS_FOCUS_SYNCHRONIZER_H_ | 100 #endif // UI_AURA_MUS_FOCUS_SYNCHRONIZER_H_ |
| OLD | NEW |