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

Unified Diff: components/exo/wm_helper_mus.cc

Issue 2578893003: Converts chrome to aura-mus (Closed)
Patch Set: merge 2 trunk 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
Index: components/exo/wm_helper_mus.cc
diff --git a/components/exo/wm_helper_mus.cc b/components/exo/wm_helper_mus.cc
index 4a2d37253fee7370a21eab5415b76b355c8a47d8..07a60cfdce72879f5ee56a4801bd15992107325b 100644
--- a/components/exo/wm_helper_mus.cc
+++ b/components/exo/wm_helper_mus.cc
@@ -4,41 +4,27 @@
#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/views/mus/native_widget_mus.h"
-#include "ui/views/mus/window_manager_connection.h"
-#include "ui/views/widget/widget.h"
-
+#include "ui/wm/public/activation_client.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()
- : active_window_(WMHelperMus::GetActiveWindow()),
- focused_window_(WMHelperMus::GetFocusedWindow()) {
- views::WindowManagerConnection::Get()->client()->AddObserver(this);
+WMHelperMus::WMHelperMus() {
+ aura::Env* env = aura::Env::GetInstance();
+ SetActiveFocusClient(env->active_focus_client(),
+ env->active_focus_client_root());
+ env->AddObserver(this);
}
WMHelperMus::~WMHelperMus() {
- views::WindowManagerConnection::Get()->client()->RemoveObserver(this);
+ if (active_focus_client_)
+ active_focus_client_->RemoveObserver(this);
+ aura::Env::GetInstance()->RemoveObserver(this);
}
////////////////////////////////////////////////////////////////////////////////
@@ -56,18 +42,11 @@ aura::Window* WMHelperMus::GetContainer(int container_id) {
}
aura::Window* WMHelperMus::GetActiveWindow() const {
- ui::Window* window =
- views::WindowManagerConnection::Get()->client()->GetFocusedWindow();
- return window ? GetToplevelAuraWindow(window) : nullptr;
+ return active_window_;
}
aura::Window* WMHelperMus::GetFocusedWindow() const {
- aura::Window* active_window = GetActiveWindow();
- if (!active_window)
- return nullptr;
- aura::client::FocusClient* focus_client =
- aura::client::GetFocusClient(active_window);
- return focus_client->GetFocusedWindow();
+ return focused_window_;
}
ui::CursorSetType WMHelperMus::GetCursorSet() const {
@@ -109,47 +88,65 @@ void WMHelperMus::PlayEarcon(int sound_key) const {
NOTIMPLEMENTED();
}
-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;
-
- // 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);
+void WMHelperMus::OnWindowInitialized(aura::Window* window) {}
- 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::OnActiveFocusClientChanged(
+ aura::client::FocusClient* focus_client,
+ aura::Window* window) {
+ SetActiveFocusClient(focus_client, window);
}
void WMHelperMus::OnWindowFocused(aura::Window* gained_focus,
aura::Window* lost_focus) {
- if (focused_window_ != gained_focus) {
- focused_window_ = gained_focus;
- NotifyWindowFocused(gained_focus, lost_focus);
- }
+ if (focused_window_ == gained_focus)
+ return;
+
+ SetActiveWindow(GetActivationClient()->GetActiveWindow());
+ SetFocusedWindow(gained_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

Powered by Google App Engine
This is Rietveld 408576698