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

Side by Side 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 unified diff | Download patch
« components/exo/pointer.cc ('K') | « components/exo/wm_helper_mus.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "components/exo/wm_helper_mus.h" 5 #include "components/exo/wm_helper_mus.h"
6 6
7 #include "ash/common/display/display_info.h" 7 #include "ash/common/display/display_info.h"
8 #include "services/ui/public/cpp/window_tree_client.h" 8 #include "services/ui/public/cpp/window_tree_client.h"
9 #include "ui/aura/client/focus_client.h" 9 #include "ui/aura/client/focus_client.h"
10 #include "ui/aura/env.h"
11 #include "ui/aura/window.h"
10 #include "ui/views/mus/native_widget_mus.h" 12 #include "ui/views/mus/native_widget_mus.h"
11 #include "ui/views/mus/window_manager_connection.h" 13 #include "ui/views/mus/window_manager_connection.h"
12 #include "ui/views/widget/widget.h" 14 #include "ui/views/widget/widget.h"
13 15
14 namespace exo { 16 namespace exo {
15 namespace { 17 namespace {
16 18
17 aura::Window* GetToplevelAuraWindow(ui::Window* window) { 19 aura::Window* GetToplevelAuraWindow(ui::Window* window) {
18 if (!window) 20 if (!window)
19 return nullptr; 21 return nullptr;
20 // We never create child ui::Window, so window->parent() should be null. 22 // We never create child ui::Window, so window->parent() should be null.
21 DCHECK(!window->parent()); 23 DCHECK(!window->parent());
22 auto* widget = views::NativeWidgetMus::GetWidgetForWindow(window); 24 auto* widget = views::NativeWidgetMus::GetWidgetForWindow(window);
23 if (!widget) 25 if (!widget)
24 return nullptr; 26 return nullptr;
25 return widget->GetNativeWindow(); 27 return widget->GetNativeWindow();
26 } 28 }
27 } 29 }
28 30
29 //////////////////////////////////////////////////////////////////////////////// 31 ////////////////////////////////////////////////////////////////////////////////
32 // WMHelperMus::EventForwarder:
33
34 class WMHelperMus::EventForwarder : public ui::EventHandler {
35 public:
36 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.
37 : helper_(helper), is_post_(is_post) {}
38 ~EventForwarder() override {}
39
40 // Overriden from ui::EventHandler:
41 void OnEvent(ui::Event* event) override {
42 helper_->ForwardEvent(event, is_post_);
43 }
44
45 private:
46 WMHelperMus* helper_;
47 const bool is_post_;
48
49 DISALLOW_COPY_AND_ASSIGN(EventForwarder);
50 };
51
52 ////////////////////////////////////////////////////////////////////////////////
30 // WMHelperMus, public: 53 // WMHelperMus, public:
31 54
32 WMHelperMus::WMHelperMus() 55 WMHelperMus::WMHelperMus()
33 : active_window_(GetActiveWindow()), focused_window_(GetFocusedWindow()) { 56 : pre_target_event_forwarder_(new EventForwarder(this, false)),
57 post_target_event_forwarder_(new EventForwarder(this, true)),
58 active_window_(GetActiveWindow()),
59 focused_window_(GetFocusedWindow()) {
34 views::WindowManagerConnection::Get()->window_tree_client()->AddObserver( 60 views::WindowManagerConnection::Get()->window_tree_client()->AddObserver(
35 this); 61 this);
62 aura::Env::GetInstance()->AddObserver(this);
36 } 63 }
37 64
38 WMHelperMus::~WMHelperMus() { 65 WMHelperMus::~WMHelperMus() {
66 auto* env = aura::Env::GetInstance();
67 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.
68 env->RemoveObserver(this);
39 auto* connection = views::WindowManagerConnection::Get(); 69 auto* connection = views::WindowManagerConnection::Get();
40 if (connection) 70 if (connection)
41 connection->window_tree_client()->RemoveObserver(this); 71 connection->window_tree_client()->RemoveObserver(this);
42 } 72 }
43 73
44 //////////////////////////////////////////////////////////////////////////////// 74 ////////////////////////////////////////////////////////////////////////////////
45 // WMHelperMus, private: 75 // WMHelperMus, private:
46 76
47 const ash::DisplayInfo WMHelperMus::GetDisplayInfo(int64_t display_id) const { 77 const ash::DisplayInfo WMHelperMus::GetDisplayInfo(int64_t display_id) const {
48 NOTIMPLEMENTED(); 78 // TODO(penghuang): Return real display info when it is supported in mus.
49 return ash::DisplayInfo(); 79 return ash::DisplayInfo(display_id, "", false);
50 } 80 }
51 81
52 aura::Window* WMHelperMus::GetContainer(int container_id) { 82 aura::Window* WMHelperMus::GetContainer(int container_id) {
53 NOTIMPLEMENTED(); 83 NOTIMPLEMENTED();
54 return nullptr; 84 return nullptr;
55 } 85 }
56 86
57 aura::Window* WMHelperMus::GetActiveWindow() const { 87 aura::Window* WMHelperMus::GetActiveWindow() const {
58 ui::Window* window = views::WindowManagerConnection::Get() 88 ui::Window* window = views::WindowManagerConnection::Get()
59 ->window_tree_client() 89 ->window_tree_client()
60 ->GetFocusedWindow(); 90 ->GetFocusedWindow();
61 return GetToplevelAuraWindow(window); 91 return GetToplevelAuraWindow(window);
62 } 92 }
63 93
64 aura::Window* WMHelperMus::GetFocusedWindow() const { 94 aura::Window* WMHelperMus::GetFocusedWindow() const {
65 auto* active_window = GetActiveWindow(); 95 auto* active_window = GetActiveWindow();
66 if (!active_window) 96 if (!active_window)
67 return nullptr; 97 return nullptr;
68 auto* focus_client = aura::client::GetFocusClient(active_window); 98 auto* focus_client = aura::client::GetFocusClient(active_window);
69 return focus_client->GetFocusedWindow(); 99 return focus_client->GetFocusedWindow();
70 } 100 }
71 101
72 ui::CursorSetType WMHelperMus::GetCursorSet() const { 102 ui::CursorSetType WMHelperMus::GetCursorSet() const {
73 NOTIMPLEMENTED(); 103 NOTIMPLEMENTED();
74 return ui::CursorSetType::CURSOR_SET_NORMAL; 104 return ui::CursorSetType::CURSOR_SET_NORMAL;
75 } 105 }
76 106
77 void WMHelperMus::AddPreTargetHandler(ui::EventHandler* handler) { 107 void WMHelperMus::AddPreTargetHandler(ui::EventHandler* handler) {
78 NOTIMPLEMENTED(); 108 pre_target_list_.push_back(handler);
79 } 109 }
80 110
81 void WMHelperMus::PrependPreTargetHandler(ui::EventHandler* handler) { 111 void WMHelperMus::PrependPreTargetHandler(ui::EventHandler* handler) {
82 NOTIMPLEMENTED(); 112 pre_target_list_.insert(pre_target_list_.begin(), handler);
83 } 113 }
84 114
85 void WMHelperMus::RemovePreTargetHandler(ui::EventHandler* handler) { 115 void WMHelperMus::RemovePreTargetHandler(ui::EventHandler* handler) {
86 NOTIMPLEMENTED(); 116 auto it =
117 std::find(pre_target_list_.begin(), pre_target_list_.end(), handler);
118 if (it != pre_target_list_.end())
119 pre_target_list_.erase(it);
87 } 120 }
88 121
89 void WMHelperMus::AddPostTargetHandler(ui::EventHandler* handler) { 122 void WMHelperMus::AddPostTargetHandler(ui::EventHandler* handler) {
90 NOTIMPLEMENTED(); 123 post_target_list_.push_back(handler);
91 } 124 }
92 125
93 void WMHelperMus::RemovePostTargetHandler(ui::EventHandler* handler) { 126 void WMHelperMus::RemovePostTargetHandler(ui::EventHandler* handler) {
94 NOTIMPLEMENTED(); 127 auto it =
128 std::find(post_target_list_.begin(), post_target_list_.end(), handler);
129 if (it != post_target_list_.end())
130 post_target_list_.erase(it);
95 } 131 }
96 132
97 bool WMHelperMus::IsMaximizeModeWindowManagerEnabled() const { 133 bool WMHelperMus::IsMaximizeModeWindowManagerEnabled() const {
98 NOTIMPLEMENTED(); 134 NOTIMPLEMENTED();
99 return false; 135 return false;
100 } 136 }
101 137
138 void WMHelperMus::OnHostInitialized(aura::WindowTreeHost* host) {
139 auto* root_window = host->window();
140 root_window->AddPreTargetHandler(pre_target_event_forwarder_.get());
141 root_window->AddPostTargetHandler(post_target_event_forwarder_.get());
142 }
143
102 void WMHelperMus::OnWindowTreeFocusChanged(ui::Window* gained_focus, 144 void WMHelperMus::OnWindowTreeFocusChanged(ui::Window* gained_focus,
103 ui::Window* lost_focus) { 145 ui::Window* lost_focus) {
104 aura::Window* gained_active = GetToplevelAuraWindow(gained_focus); 146 aura::Window* gained_active = GetToplevelAuraWindow(gained_focus);
105 aura::Window* lost_active = GetToplevelAuraWindow(lost_focus); 147 aura::Window* lost_active = GetToplevelAuraWindow(lost_focus);
106 148
107 OnWindowFocused(nullptr, focused_window_); 149 OnWindowFocused(nullptr, focused_window_);
108 150
109 // Because NativeWidgetMus uses separate FocusClient for every toplevel 151 // Because NativeWidgetMus uses separate FocusClient for every toplevel
110 // window, we have to stop observering the FocusClient of the |lost_active| 152 // window, we have to stop observering the FocusClient of the |lost_active|
111 // and start observering the FocusClient of the |gained_active|. 153 // and start observering the FocusClient of the |gained_active|.
(...skipping 13 matching lines...) Expand all
125 } 167 }
126 168
127 void WMHelperMus::OnWindowFocused(aura::Window* gained_focus, 169 void WMHelperMus::OnWindowFocused(aura::Window* gained_focus,
128 aura::Window* lost_focus) { 170 aura::Window* lost_focus) {
129 if (focused_window_ != gained_focus) { 171 if (focused_window_ != gained_focus) {
130 focused_window_ = gained_focus; 172 focused_window_ = gained_focus;
131 NotifyWindowFocused(gained_focus, lost_focus); 173 NotifyWindowFocused(gained_focus, lost_focus);
132 } 174 }
133 } 175 }
134 176
177 void WMHelperMus::ForwardEvent(ui::Event* event, bool is_post) {
178 auto it = is_post ? post_target_list_.begin() : pre_target_list_.begin();
179 auto end = is_post ? post_target_list_.end() : pre_target_list_.end();
180 for (; it != end; ++it) {
181 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
182 break;
183 (*it)->OnEvent(event);
184 }
185 }
186
135 } // namespace exo 187 } // namespace exo
OLDNEW
« 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