Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(191)

Side by Side Diff: ui/aura/mus/focus_synchronizer.h

Issue 2714763002: Change FocusSynchronizer to maintain active focus client and window. (Closed)
Patch Set: fix crash in aura_test_helper tear down Created 3 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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/mus/window_mus.h"
14 #include "ui/aura/window_observer.h"
11 15
12 namespace ui { 16 namespace ui {
13 namespace mojom { 17 namespace mojom {
14 class WindowTree; 18 class WindowTree;
15 } 19 }
16 } 20 }
17 21
18 namespace aura { 22 namespace aura {
19
20 class FocusSynchronizerDelegate; 23 class FocusSynchronizerDelegate;
21 class WindowMus;
22 24
23 namespace client { 25 namespace client {
24 class FocusClient; 26 class FocusClient;
25 } 27 }
26 28
27 // FocusSynchronizer is resonsible for keeping focus in sync between aura 29 // FocusSynchronizer is resonsible for keeping focus in sync between aura
28 // and the mus server. 30 // and the mus server.
29 class FocusSynchronizer : public client::FocusChangeObserver, 31 class AURA_EXPORT FocusSynchronizer : public WindowObserver,
30 public EnvObserver { 32 public client::FocusChangeObserver {
31 public: 33 public:
32 FocusSynchronizer(FocusSynchronizerDelegate* delegate, 34 FocusSynchronizer(FocusSynchronizerDelegate* delegate,
33 ui::mojom::WindowTree* window_tree); 35 ui::mojom::WindowTree* window_tree);
34 ~FocusSynchronizer() override; 36 ~FocusSynchronizer() override;
35 37
38 client::FocusClient* active_focus_client() { return active_focus_client_; }
39 Window* focused_window() {
40 return focused_window_ ? focused_window_->GetWindow() : nullptr;
41 }
42
43 // Add and remove observers to the FocusSynchronizer to get notified when the
44 // |active_focus_client_| and the |focused_window_| 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 // Set 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 a
57 // FocusClient.
58 void AttachToFocusClient(client::FocusClient* focus_client,
59 Window* focus_client_root);
60
61 // Called when |focus_client| will be unset.
62 void DetachFromFocusClient(client::FocusClient* focus_client);
43 63
44 private: 64 private:
45 void SetActiveFocusClient(client::FocusClient* focus_client); 65 void SetActiveFocusClient(client::FocusClient* focus_client);
46 66
67 void UpdateFocusedWindowObserver(Window* window);
68
47 // Called internally to set |focused_window_| and update the server. 69 // Called internally to set |focused_window_| and update the server.
48 void SetFocusedWindow(WindowMus* window); 70 void SetFocusedWindow(WindowMus* window);
49 71
50 // Overriden from client::FocusChangeObserver: 72 // Called internally to set |active_focus_client_| and |focused_window_| and
73 // notify observers.
74 void OnActiveFocusClientChanged(client::FocusClient* focus_client,
75 Window* window);
76
77 // WindowObserver:
78 void OnWindowDestroying(Window* window) override;
79 void OnWindowPropertyChanged(Window* window,
80 const void* key,
81 intptr_t old) override;
82
83 // client::FocusChangeObserver:
51 void OnWindowFocused(Window* gained_focus, Window* lost_focus) override; 84 void OnWindowFocused(Window* gained_focus, Window* lost_focus) override;
52 85
53 // Overrided from EnvObserver:
54 void OnWindowInitialized(Window* window) override;
55 void OnActiveFocusClientChanged(client::FocusClient* focus_client,
56 Window* window) override;
57
58 FocusSynchronizerDelegate* delegate_; 86 FocusSynchronizerDelegate* delegate_;
59 ui::mojom::WindowTree* window_tree_; 87 ui::mojom::WindowTree* window_tree_;
60 88
61 client::FocusClient* active_focus_client_ = nullptr; 89 base::ObserverList<FocusSynchronizerObserver> observers_;
62 90
63 bool setting_focus_ = false; 91 bool setting_focus_ = false;
64 WindowMus* window_setting_focus_to_ = nullptr; 92 WindowMus* window_setting_focus_to_ = nullptr;
93
94 client::FocusClient* active_focus_client_ = nullptr;
65 WindowMus* focused_window_ = nullptr; 95 WindowMus* focused_window_ = nullptr;
66 96
67 DISALLOW_COPY_AND_ASSIGN(FocusSynchronizer); 97 DISALLOW_COPY_AND_ASSIGN(FocusSynchronizer);
68 }; 98 };
69 99
70 } // namespace aura 100 } // namespace aura
71 101
72 #endif // UI_AURA_MUS_FOCUS_SYNCHRONIZER_H_ 102 #endif // UI_AURA_MUS_FOCUS_SYNCHRONIZER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698