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

Unified Diff: components/exo/wm_helper_mus.cc

Issue 2577963006: Revert of Converts chrome to aura-mus (Closed)
Patch Set: Created 4 years 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
« no previous file with comments | « components/exo/wm_helper_mus.h ('k') | services/ui/ws/window_tree.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: components/exo/wm_helper_mus.cc
diff --git a/components/exo/wm_helper_mus.cc b/components/exo/wm_helper_mus.cc
index 07a60cfdce72879f5ee56a4801bd15992107325b..4a2d37253fee7370a21eab5415b76b355c8a47d8 100644
--- a/components/exo/wm_helper_mus.cc
+++ b/components/exo/wm_helper_mus.cc
@@ -4,27 +4,41 @@
#include "components/exo/wm_helper_mus.h"
+#include "services/ui/public/cpp/window_tree_client.h"
#include "ui/aura/client/focus_client.h"
#include "ui/aura/env.h"
#include "ui/aura/window.h"
#include "ui/display/manager/managed_display_info.h"
-#include "ui/wm/public/activation_client.h"
+#include "ui/views/mus/native_widget_mus.h"
+#include "ui/views/mus/window_manager_connection.h"
+#include "ui/views/widget/widget.h"
+
namespace exo {
+namespace {
+
+aura::Window* GetToplevelAuraWindow(ui::Window* window) {
+ DCHECK(window);
+ // We never create child ui::Window, so window->parent() should be null.
+ DCHECK(!window->parent());
+ views::Widget* widget = views::NativeWidgetMus::GetWidgetForWindow(window);
+ if (!widget)
+ return nullptr;
+ return widget->GetNativeWindow();
+}
+
+} // namespace
////////////////////////////////////////////////////////////////////////////////
// WMHelperMus, public:
-WMHelperMus::WMHelperMus() {
- aura::Env* env = aura::Env::GetInstance();
- SetActiveFocusClient(env->active_focus_client(),
- env->active_focus_client_root());
- env->AddObserver(this);
+WMHelperMus::WMHelperMus()
+ : active_window_(WMHelperMus::GetActiveWindow()),
+ focused_window_(WMHelperMus::GetFocusedWindow()) {
+ views::WindowManagerConnection::Get()->client()->AddObserver(this);
}
WMHelperMus::~WMHelperMus() {
- if (active_focus_client_)
- active_focus_client_->RemoveObserver(this);
- aura::Env::GetInstance()->RemoveObserver(this);
+ views::WindowManagerConnection::Get()->client()->RemoveObserver(this);
}
////////////////////////////////////////////////////////////////////////////////
@@ -42,11 +56,18 @@
}
aura::Window* WMHelperMus::GetActiveWindow() const {
- return active_window_;
+ ui::Window* window =
+ views::WindowManagerConnection::Get()->client()->GetFocusedWindow();
+ return window ? GetToplevelAuraWindow(window) : nullptr;
}
aura::Window* WMHelperMus::GetFocusedWindow() const {
- return focused_window_;
+ aura::Window* active_window = GetActiveWindow();
+ if (!active_window)
+ return nullptr;
+ aura::client::FocusClient* focus_client =
+ aura::client::GetFocusClient(active_window);
+ return focus_client->GetFocusedWindow();
}
ui::CursorSetType WMHelperMus::GetCursorSet() const {
@@ -88,65 +109,47 @@
NOTIMPLEMENTED();
}
-void WMHelperMus::OnWindowInitialized(aura::Window* window) {}
+void WMHelperMus::OnWindowTreeFocusChanged(ui::Window* gained_focus,
+ ui::Window* lost_focus) {
+ aura::Window* gained_active =
+ gained_focus ? GetToplevelAuraWindow(gained_focus) : nullptr;
+ aura::Window* lost_active =
+ lost_focus ? GetToplevelAuraWindow(lost_focus) : nullptr;
-void WMHelperMus::OnActiveFocusClientChanged(
- aura::client::FocusClient* focus_client,
- aura::Window* window) {
- SetActiveFocusClient(focus_client, window);
+ // Because NativeWidgetMus uses separate FocusClient for every toplevel
+ // window, we have to stop observering the FocusClient of the |lost_active|
+ // and start observering the FocusClient of the |gained_active|.
+ if (active_window_) {
+ aura::client::FocusClient* focus_client =
+ aura::client::GetFocusClient(active_window_);
+ focus_client->RemoveObserver(this);
+ }
+
+ active_window_ = gained_active;
+ NotifyWindowActivated(gained_active, lost_active);
+
+ aura::Window* focused_window = nullptr;
+ if (active_window_) {
+ aura::client::FocusClient* focus_client =
+ aura::client::GetFocusClient(active_window_);
+ focus_client->AddObserver(this);
+ focused_window = focus_client->GetFocusedWindow();
+ }
+
+ // OnWindowFocused() will update |focused_window_|.
+ OnWindowFocused(focused_window, focused_window_);
}
void WMHelperMus::OnWindowFocused(aura::Window* gained_focus,
aura::Window* lost_focus) {
- if (focused_window_ == gained_focus)
- return;
-
- SetActiveWindow(GetActivationClient()->GetActiveWindow());
- SetFocusedWindow(gained_focus);
+ if (focused_window_ != gained_focus) {
+ focused_window_ = gained_focus;
+ NotifyWindowFocused(gained_focus, lost_focus);
+ }
}
void WMHelperMus::OnKeyboardDeviceConfigurationChanged() {
NotifyKeyboardDeviceConfigurationChanged();
}
-void WMHelperMus::SetActiveFocusClient(aura::client::FocusClient* focus_client,
- aura::Window* window) {
- if (active_focus_client_)
- active_focus_client_->RemoveObserver(this);
- active_focus_client_ = focus_client;
- root_with_active_focus_client_ = window;
- if (active_focus_client_) {
- active_focus_client_->AddObserver(this);
- SetActiveWindow(GetActivationClient()->GetActiveWindow());
- SetFocusedWindow(active_focus_client_->GetFocusedWindow());
- } else {
- SetActiveWindow(nullptr);
- SetFocusedWindow(nullptr);
- }
-}
-
-void WMHelperMus::SetActiveWindow(aura::Window* window) {
- if (active_window_ == window)
- return;
-
- aura::Window* lost_active = active_window_;
- active_window_ = window;
- NotifyWindowActivated(active_window_, lost_active);
-}
-
-void WMHelperMus::SetFocusedWindow(aura::Window* window) {
- if (focused_window_ == window)
- return;
-
- aura::Window* lost_focus = focused_window_;
- focused_window_ = window;
- NotifyWindowFocused(focused_window_, lost_focus);
-}
-
-aura::client::ActivationClient* WMHelperMus::GetActivationClient() {
- return root_with_active_focus_client_
- ? aura::client::GetActivationClient(root_with_active_focus_client_)
- : nullptr;
-}
-
} // namespace exo
« no previous file with comments | « components/exo/wm_helper_mus.h ('k') | services/ui/ws/window_tree.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698