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

Unified Diff: ui/aura/mus/focus_synchronizer.h

Issue 2714763002: Change FocusSynchronizer to maintain active focus client and window. (Closed)
Patch Set: switch back to use FocusSynchronizerObserver 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 side-by-side diff with in-line comments
Download patch
Index: ui/aura/mus/focus_synchronizer.h
diff --git a/ui/aura/mus/focus_synchronizer.h b/ui/aura/mus/focus_synchronizer.h
index db2556d76155f0e1cdb8000f5a0ab6af217f901a..08403bab54d18f6ad29ec48fdf0058c437dbcfb3 100644
--- a/ui/aura/mus/focus_synchronizer.h
+++ b/ui/aura/mus/focus_synchronizer.h
@@ -6,8 +6,11 @@
#define UI_AURA_MUS_FOCUS_SYNCHRONIZER_H_
#include "base/macros.h"
+#include "base/observer_list.h"
+#include "ui/aura/aura_export.h"
#include "ui/aura/client/focus_change_observer.h"
-#include "ui/aura/env_observer.h"
+#include "ui/aura/mus/focus_synchronizer_observer.h"
+#include "ui/aura/window_observer.h"
namespace ui {
namespace mojom {
@@ -26,42 +29,68 @@ class FocusClient;
// FocusSynchronizer is resonsible for keeping focus in sync between aura
// and the mus server.
-class FocusSynchronizer : public client::FocusChangeObserver,
- public EnvObserver {
+class AURA_EXPORT FocusSynchronizer : public client::FocusChangeObserver,
+ public WindowObserver {
public:
FocusSynchronizer(FocusSynchronizerDelegate* delegate,
ui::mojom::WindowTree* window_tree);
~FocusSynchronizer() override;
+ client::FocusClient* active_focus_client() { return active_focus_client_; }
+ Window* active_focus_client_root() { return active_focus_client_root_; }
+ 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
+
+ // Add and remove observers to the FocusSynchronizer to get notified when the
+ // |active_focus_client_| and the |active_focus_client_root_| change.
+ void AddObserver(FocusSynchronizerObserver* observer);
+ void RemoveObserver(FocusSynchronizerObserver* observer);
+
// Called when the server side wants to change focus to |window|.
void SetFocusFromServer(WindowMus* window);
// Called when the focused window is destroyed.
void OnFocusedWindowDestroyed();
- WindowMus* focused_window() { return focused_window_; }
+ // Sets the active FocusClient and the window the FocusClient is associated
+ // with. |focus_client_root| is not necessarily the window that actually has
+ // focus. |focus_client_root| may be null, which indicates all windows share
+ // 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
+ void SetActiveFocusClient(client::FocusClient* focus_client,
+ Window* focus_client_root);
private:
- void SetActiveFocusClient(client::FocusClient* focus_client);
+ // Called internally to set |active_focus_client_| and update observer.
+ void SetActiveFocusClientInternal(client::FocusClient* focus_client);
// Called internally to set |focused_window_| and update the server.
void SetFocusedWindow(WindowMus* window);
- // Overriden from client::FocusChangeObserver:
+ // Called internally when notified that |active_focus_client_| and
+ // |active_focus_client_root_| have been changed.
+ void OnActiveFocusClientChanged(client::FocusClient* focus_client,
+ Window* focus_client_root);
+
+ // client::FocusChangeObserver:
void OnWindowFocused(Window* gained_focus, Window* lost_focus) override;
- // Overrided from EnvObserver:
- void OnWindowInitialized(Window* window) override;
- void OnActiveFocusClientChanged(client::FocusClient* focus_client,
- Window* window) override;
+ // WindowObserver:
+ void OnWindowDestroying(Window* window) override;
+ void OnWindowPropertyChanged(Window* window,
+ const void* key,
+ intptr_t old) override;
FocusSynchronizerDelegate* delegate_;
ui::mojom::WindowTree* window_tree_;
- client::FocusClient* active_focus_client_ = nullptr;
+ base::ObserverList<FocusSynchronizerObserver> observers_;
bool setting_focus_ = false;
WindowMus* window_setting_focus_to_ = nullptr;
+
+ client::FocusClient* active_focus_client_ = nullptr;
+ // The window that |active_focus_client_| is associated with.
+ Window* active_focus_client_root_ = nullptr;
+ // The window that actually has focus.
WindowMus* focused_window_ = nullptr;
DISALLOW_COPY_AND_ASSIGN(FocusSynchronizer);

Powered by Google App Engine
This is Rietveld 408576698