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

Unified 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 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..5502e77f2e0f7c736ddd5d4472a669466dbd8571 100644
--- a/ui/aura/mus/focus_synchronizer.h
+++ b/ui/aura/mus/focus_synchronizer.h
@@ -6,8 +6,12 @@
#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/mus/window_mus.h"
+#include "ui/aura/window_observer.h"
namespace ui {
namespace mojom {
@@ -16,9 +20,7 @@ class WindowTree;
}
namespace aura {
-
class FocusSynchronizerDelegate;
-class WindowMus;
namespace client {
class FocusClient;
@@ -26,42 +28,70 @@ 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 WindowObserver,
+ public client::FocusChangeObserver {
public:
FocusSynchronizer(FocusSynchronizerDelegate* delegate,
ui::mojom::WindowTree* window_tree);
~FocusSynchronizer() override;
+ client::FocusClient* active_focus_client() { return active_focus_client_; }
+ Window* focused_window() {
+ return focused_window_ ? focused_window_->GetWindow() : nullptr;
+ }
+
+ // Add and remove observers to the FocusSynchronizer to get notified when the
+ // |active_focus_client_| and the |focused_window_| 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_; }
+ // Set 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.
+ void AttachToFocusClient(client::FocusClient* focus_client,
+ Window* focus_client_root);
+
+ // Called when |focus_client| will be unset.
+ void DetachFromFocusClient(client::FocusClient* focus_client);
private:
void SetActiveFocusClient(client::FocusClient* focus_client);
+ void UpdateFocusedWindowObserver(Window* window);
+
// Called internally to set |focused_window_| and update the server.
void SetFocusedWindow(WindowMus* window);
- // Overriden from client::FocusChangeObserver:
- void OnWindowFocused(Window* gained_focus, Window* lost_focus) override;
-
- // Overrided from EnvObserver:
- void OnWindowInitialized(Window* window) override;
+ // Called internally to set |active_focus_client_| and |focused_window_| and
+ // notify observers.
void OnActiveFocusClientChanged(client::FocusClient* focus_client,
- Window* window) override;
+ Window* window);
+
+ // WindowObserver:
+ void OnWindowDestroying(Window* window) override;
+ void OnWindowPropertyChanged(Window* window,
+ const void* key,
+ intptr_t old) override;
+
+ // client::FocusChangeObserver:
+ void OnWindowFocused(Window* gained_focus, Window* lost_focus) 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;
WindowMus* focused_window_ = nullptr;
DISALLOW_COPY_AND_ASSIGN(FocusSynchronizer);

Powered by Google App Engine
This is Rietveld 408576698