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

Unified Diff: components/exo/wm_helper_mus.cc

Issue 2264503003: exo: WMHelperMus: Hook up event handlers for mus+ash (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 4 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
« components/exo/pointer.cc ('K') | « components/exo/wm_helper_mus.h ('k') | no next file » | 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 4f204cdc76383f7eea6d9e7a899d4efaab14ddcf..59da6e2d4d2f1418f8280e583962468c195e6ca6 100644
--- a/components/exo/wm_helper_mus.cc
+++ b/components/exo/wm_helper_mus.cc
@@ -7,6 +7,8 @@
#include "ash/common/display/display_info.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/views/mus/native_widget_mus.h"
#include "ui/views/mus/window_manager_connection.h"
#include "ui/views/widget/widget.h"
@@ -27,15 +29,43 @@ aura::Window* GetToplevelAuraWindow(ui::Window* window) {
}
////////////////////////////////////////////////////////////////////////////////
+// WMHelperMus::EventForwarder:
+
+class WMHelperMus::EventForwarder : public ui::EventHandler {
+ public:
+ EventForwarder(WMHelperMus* helper, bool is_post)
reveman 2016/08/22 13:41:42 Can we pass a ui::EventHandlerList reference to th
Peng 2016/08/22 14:32:40 Done.
+ : helper_(helper), is_post_(is_post) {}
+ ~EventForwarder() override {}
+
+ // Overriden from ui::EventHandler:
+ void OnEvent(ui::Event* event) override {
+ helper_->ForwardEvent(event, is_post_);
+ }
+
+ private:
+ WMHelperMus* helper_;
+ const bool is_post_;
+
+ DISALLOW_COPY_AND_ASSIGN(EventForwarder);
+};
+
+////////////////////////////////////////////////////////////////////////////////
// WMHelperMus, public:
WMHelperMus::WMHelperMus()
- : active_window_(GetActiveWindow()), focused_window_(GetFocusedWindow()) {
+ : pre_target_event_forwarder_(new EventForwarder(this, false)),
+ post_target_event_forwarder_(new EventForwarder(this, true)),
+ active_window_(GetActiveWindow()),
+ focused_window_(GetFocusedWindow()) {
views::WindowManagerConnection::Get()->window_tree_client()->AddObserver(
this);
+ aura::Env::GetInstance()->AddObserver(this);
}
WMHelperMus::~WMHelperMus() {
+ auto* env = aura::Env::GetInstance();
+ if (env)
reveman 2016/08/22 13:41:42 Why this conditional necessary? Would be nice if w
Peng 2016/08/22 14:32:40 Done.
+ env->RemoveObserver(this);
auto* connection = views::WindowManagerConnection::Get();
if (connection)
connection->window_tree_client()->RemoveObserver(this);
@@ -45,8 +75,8 @@ WMHelperMus::~WMHelperMus() {
// WMHelperMus, private:
const ash::DisplayInfo WMHelperMus::GetDisplayInfo(int64_t display_id) const {
- NOTIMPLEMENTED();
- return ash::DisplayInfo();
+ // TODO(penghuang): Return real display info when it is supported in mus.
+ return ash::DisplayInfo(display_id, "", false);
}
aura::Window* WMHelperMus::GetContainer(int container_id) {
@@ -75,23 +105,29 @@ ui::CursorSetType WMHelperMus::GetCursorSet() const {
}
void WMHelperMus::AddPreTargetHandler(ui::EventHandler* handler) {
- NOTIMPLEMENTED();
+ pre_target_list_.push_back(handler);
}
void WMHelperMus::PrependPreTargetHandler(ui::EventHandler* handler) {
- NOTIMPLEMENTED();
+ pre_target_list_.insert(pre_target_list_.begin(), handler);
}
void WMHelperMus::RemovePreTargetHandler(ui::EventHandler* handler) {
- NOTIMPLEMENTED();
+ auto it =
+ std::find(pre_target_list_.begin(), pre_target_list_.end(), handler);
+ if (it != pre_target_list_.end())
+ pre_target_list_.erase(it);
}
void WMHelperMus::AddPostTargetHandler(ui::EventHandler* handler) {
- NOTIMPLEMENTED();
+ post_target_list_.push_back(handler);
}
void WMHelperMus::RemovePostTargetHandler(ui::EventHandler* handler) {
- NOTIMPLEMENTED();
+ auto it =
+ std::find(post_target_list_.begin(), post_target_list_.end(), handler);
+ if (it != post_target_list_.end())
+ post_target_list_.erase(it);
}
bool WMHelperMus::IsMaximizeModeWindowManagerEnabled() const {
@@ -99,6 +135,12 @@ bool WMHelperMus::IsMaximizeModeWindowManagerEnabled() const {
return false;
}
+void WMHelperMus::OnHostInitialized(aura::WindowTreeHost* host) {
+ auto* root_window = host->window();
+ root_window->AddPreTargetHandler(pre_target_event_forwarder_.get());
+ root_window->AddPostTargetHandler(post_target_event_forwarder_.get());
+}
+
void WMHelperMus::OnWindowTreeFocusChanged(ui::Window* gained_focus,
ui::Window* lost_focus) {
aura::Window* gained_active = GetToplevelAuraWindow(gained_focus);
@@ -132,4 +174,14 @@ void WMHelperMus::OnWindowFocused(aura::Window* gained_focus,
}
}
+void WMHelperMus::ForwardEvent(ui::Event* event, bool is_post) {
+ auto it = is_post ? post_target_list_.begin() : pre_target_list_.begin();
+ auto end = is_post ? post_target_list_.end() : pre_target_list_.end();
+ for (; it != end; ++it) {
+ if (!is_post && event->stopped_propagation())
reveman 2016/08/22 13:41:42 why is stopped_propagation() only respected in the
Peng 2016/08/22 14:32:40 I thought we should always dispatch event to post
+ break;
+ (*it)->OnEvent(event);
+ }
+}
+
} // namespace exo
« components/exo/pointer.cc ('K') | « components/exo/wm_helper_mus.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698