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

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: Remove changes in pointer.cc Created 4 years, 3 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
« no previous file with comments | « 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 DCHECK(window); 20 DCHECK(window);
19 // We never create child ui::Window, so window->parent() should be null. 21 // We never create child ui::Window, so window->parent() should be null.
20 DCHECK(!window->parent()); 22 DCHECK(!window->parent());
21 views::Widget* widget = views::NativeWidgetMus::GetWidgetForWindow(window); 23 views::Widget* widget = views::NativeWidgetMus::GetWidgetForWindow(window);
22 if (!widget) 24 if (!widget)
23 return nullptr; 25 return nullptr;
24 return widget->GetNativeWindow(); 26 return widget->GetNativeWindow();
25 } 27 }
26 28
27 } // namespace 29 } // namespace
28 30
29 //////////////////////////////////////////////////////////////////////////////// 31 ////////////////////////////////////////////////////////////////////////////////
32 // WMHelperMus::EventForwarder:
33
34 class WMHelperMus::EventForwarder : public ui::EventHandler {
35 public:
36 explicit EventForwarder(ui::EventHandlerList* event_handlers)
37 : event_handlers_(event_handlers) {}
38 ~EventForwarder() override {}
39
40 // Overriden from ui::EventHandler:
41 void OnEvent(ui::Event* event) override;
42
43 private:
44 const ui::EventHandlerList* event_handlers_;
45
46 DISALLOW_COPY_AND_ASSIGN(EventForwarder);
47 };
48
49 void WMHelperMus::EventForwarder::OnEvent(ui::Event* event) {
50 for (ui::EventHandler* handler : *event_handlers_) {
51 if (event->stopped_propagation())
52 break;
53 handler->OnEvent(event);
54 }
55 }
56 ////////////////////////////////////////////////////////////////////////////////
30 // WMHelperMus, public: 57 // WMHelperMus, public:
31 58
32 WMHelperMus::WMHelperMus() 59 WMHelperMus::WMHelperMus()
33 : active_window_(WMHelperMus::GetActiveWindow()), 60 : pre_target_event_forwarder_(new EventForwarder(&pre_target_list_)),
61 post_target_event_forwarder_(new EventForwarder(&post_target_list_)),
62 active_window_(WMHelperMus::GetActiveWindow()),
34 focused_window_(WMHelperMus::GetFocusedWindow()) { 63 focused_window_(WMHelperMus::GetFocusedWindow()) {
35 views::WindowManagerConnection::Get()->client()->AddObserver(this); 64 views::WindowManagerConnection::Get()->client()->AddObserver(this);
65 aura::Env::GetInstance()->AddObserver(this);
36 } 66 }
37 67
38 WMHelperMus::~WMHelperMus() { 68 WMHelperMus::~WMHelperMus() {
39 views::WindowManagerConnection::Get()->client()->RemoveObserver(this); 69 views::WindowManagerConnection::Get()->client()->RemoveObserver(this);
70 aura::Env::GetInstance()->RemoveObserver(this);
40 } 71 }
41 72
42 //////////////////////////////////////////////////////////////////////////////// 73 ////////////////////////////////////////////////////////////////////////////////
43 // WMHelperMus, private: 74 // WMHelperMus, private:
44 75
45 const ash::DisplayInfo WMHelperMus::GetDisplayInfo(int64_t display_id) const { 76 const ash::DisplayInfo WMHelperMus::GetDisplayInfo(int64_t display_id) const {
46 NOTIMPLEMENTED(); 77 // TODO(penghuang): Return real display info when it is supported in mus.
47 return ash::DisplayInfo(); 78 return ash::DisplayInfo(display_id, "", false);
48 } 79 }
49 80
50 aura::Window* WMHelperMus::GetContainer(int container_id) { 81 aura::Window* WMHelperMus::GetContainer(int container_id) {
51 NOTIMPLEMENTED(); 82 NOTIMPLEMENTED();
52 return nullptr; 83 return nullptr;
53 } 84 }
54 85
55 aura::Window* WMHelperMus::GetActiveWindow() const { 86 aura::Window* WMHelperMus::GetActiveWindow() const {
56 ui::Window* window = 87 ui::Window* window =
57 views::WindowManagerConnection::Get()->client()->GetFocusedWindow(); 88 views::WindowManagerConnection::Get()->client()->GetFocusedWindow();
58 return window ? GetToplevelAuraWindow(window) : nullptr; 89 return window ? GetToplevelAuraWindow(window) : nullptr;
59 } 90 }
60 91
61 aura::Window* WMHelperMus::GetFocusedWindow() const { 92 aura::Window* WMHelperMus::GetFocusedWindow() const {
62 aura::Window* active_window = GetActiveWindow(); 93 aura::Window* active_window = GetActiveWindow();
63 if (!active_window) 94 if (!active_window)
64 return nullptr; 95 return nullptr;
65 aura::client::FocusClient* focus_client = 96 aura::client::FocusClient* focus_client =
66 aura::client::GetFocusClient(active_window); 97 aura::client::GetFocusClient(active_window);
67 return focus_client->GetFocusedWindow(); 98 return focus_client->GetFocusedWindow();
68 } 99 }
69 100
70 ui::CursorSetType WMHelperMus::GetCursorSet() const { 101 ui::CursorSetType WMHelperMus::GetCursorSet() const {
71 NOTIMPLEMENTED(); 102 NOTIMPLEMENTED();
72 return ui::CursorSetType::CURSOR_SET_NORMAL; 103 return ui::CursorSetType::CURSOR_SET_NORMAL;
73 } 104 }
74 105
75 void WMHelperMus::AddPreTargetHandler(ui::EventHandler* handler) { 106 void WMHelperMus::AddPreTargetHandler(ui::EventHandler* handler) {
76 NOTIMPLEMENTED(); 107 pre_target_list_.push_back(handler);
77 } 108 }
78 109
79 void WMHelperMus::PrependPreTargetHandler(ui::EventHandler* handler) { 110 void WMHelperMus::PrependPreTargetHandler(ui::EventHandler* handler) {
80 NOTIMPLEMENTED(); 111 pre_target_list_.insert(pre_target_list_.begin(), handler);
81 } 112 }
82 113
83 void WMHelperMus::RemovePreTargetHandler(ui::EventHandler* handler) { 114 void WMHelperMus::RemovePreTargetHandler(ui::EventHandler* handler) {
84 NOTIMPLEMENTED(); 115 auto it =
116 std::find(pre_target_list_.begin(), pre_target_list_.end(), handler);
117 if (it != pre_target_list_.end())
118 pre_target_list_.erase(it);
85 } 119 }
86 120
87 void WMHelperMus::AddPostTargetHandler(ui::EventHandler* handler) { 121 void WMHelperMus::AddPostTargetHandler(ui::EventHandler* handler) {
88 NOTIMPLEMENTED(); 122 post_target_list_.push_back(handler);
89 } 123 }
90 124
91 void WMHelperMus::RemovePostTargetHandler(ui::EventHandler* handler) { 125 void WMHelperMus::RemovePostTargetHandler(ui::EventHandler* handler) {
92 NOTIMPLEMENTED(); 126 auto it =
127 std::find(post_target_list_.begin(), post_target_list_.end(), handler);
128 if (it != post_target_list_.end())
129 post_target_list_.erase(it);
93 } 130 }
94 131
95 bool WMHelperMus::IsMaximizeModeWindowManagerEnabled() const { 132 bool WMHelperMus::IsMaximizeModeWindowManagerEnabled() const {
96 NOTIMPLEMENTED(); 133 NOTIMPLEMENTED();
97 return false; 134 return false;
98 } 135 }
99 136
137 void WMHelperMus::OnHostInitialized(aura::WindowTreeHost* host) {
138 aura::Window* root_window = host->window();
139 root_window->AddPreTargetHandler(pre_target_event_forwarder_.get());
140 root_window->AddPostTargetHandler(post_target_event_forwarder_.get());
141 }
142
100 void WMHelperMus::OnWindowTreeFocusChanged(ui::Window* gained_focus, 143 void WMHelperMus::OnWindowTreeFocusChanged(ui::Window* gained_focus,
101 ui::Window* lost_focus) { 144 ui::Window* lost_focus) {
102 aura::Window* gained_active = 145 aura::Window* gained_active =
103 gained_focus ? GetToplevelAuraWindow(gained_focus) : nullptr; 146 gained_focus ? GetToplevelAuraWindow(gained_focus) : nullptr;
104 aura::Window* lost_active = 147 aura::Window* lost_active =
105 lost_focus ? GetToplevelAuraWindow(lost_focus) : nullptr; 148 lost_focus ? GetToplevelAuraWindow(lost_focus) : nullptr;
106 149
107 // Because NativeWidgetMus uses separate FocusClient for every toplevel 150 // Because NativeWidgetMus uses separate FocusClient for every toplevel
108 // window, we have to stop observering the FocusClient of the |lost_active| 151 // window, we have to stop observering the FocusClient of the |lost_active|
109 // and start observering the FocusClient of the |gained_active|. 152 // and start observering the FocusClient of the |gained_active|.
(...skipping 20 matching lines...) Expand all
130 173
131 void WMHelperMus::OnWindowFocused(aura::Window* gained_focus, 174 void WMHelperMus::OnWindowFocused(aura::Window* gained_focus,
132 aura::Window* lost_focus) { 175 aura::Window* lost_focus) {
133 if (focused_window_ != gained_focus) { 176 if (focused_window_ != gained_focus) {
134 focused_window_ = gained_focus; 177 focused_window_ = gained_focus;
135 NotifyWindowFocused(gained_focus, lost_focus); 178 NotifyWindowFocused(gained_focus, lost_focus);
136 } 179 }
137 } 180 }
138 181
139 } // namespace exo 182 } // namespace exo
OLDNEW
« no previous file with comments | « components/exo/wm_helper_mus.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698