OLD | NEW |
---|---|
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" | 10 #include "ui/aura/env.h" |
(...skipping 11 matching lines...) Expand all Loading... | |
22 DCHECK(!window->parent()); | 22 DCHECK(!window->parent()); |
23 views::Widget* widget = views::NativeWidgetMus::GetWidgetForWindow(window); | 23 views::Widget* widget = views::NativeWidgetMus::GetWidgetForWindow(window); |
24 if (!widget) | 24 if (!widget) |
25 return nullptr; | 25 return nullptr; |
26 return widget->GetNativeWindow(); | 26 return widget->GetNativeWindow(); |
27 } | 27 } |
28 | 28 |
29 } // namespace | 29 } // namespace |
30 | 30 |
31 //////////////////////////////////////////////////////////////////////////////// | 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 //////////////////////////////////////////////////////////////////////////////// | |
57 // WMHelperMus, public: | 32 // WMHelperMus, public: |
58 | 33 |
59 WMHelperMus::WMHelperMus() | 34 WMHelperMus::WMHelperMus() |
60 : pre_target_event_forwarder_(new EventForwarder(&pre_target_list_)), | 35 : active_window_(WMHelperMus::GetActiveWindow()), |
61 post_target_event_forwarder_(new EventForwarder(&post_target_list_)), | |
62 active_window_(WMHelperMus::GetActiveWindow()), | |
63 focused_window_(WMHelperMus::GetFocusedWindow()) { | 36 focused_window_(WMHelperMus::GetFocusedWindow()) { |
64 views::WindowManagerConnection::Get()->client()->AddObserver(this); | 37 views::WindowManagerConnection::Get()->client()->AddObserver(this); |
65 aura::Env::GetInstance()->AddObserver(this); | |
66 } | 38 } |
67 | 39 |
68 WMHelperMus::~WMHelperMus() { | 40 WMHelperMus::~WMHelperMus() { |
69 views::WindowManagerConnection::Get()->client()->RemoveObserver(this); | 41 views::WindowManagerConnection::Get()->client()->RemoveObserver(this); |
70 aura::Env::GetInstance()->RemoveObserver(this); | |
71 } | 42 } |
72 | 43 |
73 //////////////////////////////////////////////////////////////////////////////// | 44 //////////////////////////////////////////////////////////////////////////////// |
74 // WMHelperMus, private: | 45 // WMHelperMus, private: |
75 | 46 |
76 const ash::DisplayInfo WMHelperMus::GetDisplayInfo(int64_t display_id) const { | 47 const ash::DisplayInfo WMHelperMus::GetDisplayInfo(int64_t display_id) const { |
77 // TODO(penghuang): Return real display info when it is supported in mus. | 48 // TODO(penghuang): Return real display info when it is supported in mus. |
78 return ash::DisplayInfo(display_id, "", false); | 49 return ash::DisplayInfo(display_id, "", false); |
79 } | 50 } |
80 | 51 |
(...skipping 16 matching lines...) Expand all Loading... | |
97 aura::client::GetFocusClient(active_window); | 68 aura::client::GetFocusClient(active_window); |
98 return focus_client->GetFocusedWindow(); | 69 return focus_client->GetFocusedWindow(); |
99 } | 70 } |
100 | 71 |
101 ui::CursorSetType WMHelperMus::GetCursorSet() const { | 72 ui::CursorSetType WMHelperMus::GetCursorSet() const { |
102 NOTIMPLEMENTED(); | 73 NOTIMPLEMENTED(); |
103 return ui::CursorSetType::CURSOR_SET_NORMAL; | 74 return ui::CursorSetType::CURSOR_SET_NORMAL; |
104 } | 75 } |
105 | 76 |
106 void WMHelperMus::AddPreTargetHandler(ui::EventHandler* handler) { | 77 void WMHelperMus::AddPreTargetHandler(ui::EventHandler* handler) { |
107 pre_target_list_.push_back(handler); | 78 aura::Env::GetInstance()->AddPreTargetHandler(handler); |
reveman
2016/08/25 20:14:45
could we use the same for Ash impl and just remove
| |
108 } | 79 } |
109 | 80 |
110 void WMHelperMus::PrependPreTargetHandler(ui::EventHandler* handler) { | 81 void WMHelperMus::PrependPreTargetHandler(ui::EventHandler* handler) { |
111 pre_target_list_.insert(pre_target_list_.begin(), handler); | 82 aura::Env::GetInstance()->PrependPreTargetHandler(handler); |
112 } | 83 } |
113 | 84 |
114 void WMHelperMus::RemovePreTargetHandler(ui::EventHandler* handler) { | 85 void WMHelperMus::RemovePreTargetHandler(ui::EventHandler* handler) { |
115 auto it = | 86 aura::Env::GetInstance()->RemovePreTargetHandler(handler); |
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); | |
119 } | 87 } |
120 | 88 |
121 void WMHelperMus::AddPostTargetHandler(ui::EventHandler* handler) { | 89 void WMHelperMus::AddPostTargetHandler(ui::EventHandler* handler) { |
122 post_target_list_.push_back(handler); | 90 aura::Env::GetInstance()->AddPostTargetHandler(handler); |
123 } | 91 } |
124 | 92 |
125 void WMHelperMus::RemovePostTargetHandler(ui::EventHandler* handler) { | 93 void WMHelperMus::RemovePostTargetHandler(ui::EventHandler* handler) { |
126 auto it = | 94 aura::Env::GetInstance()->RemovePostTargetHandler(handler); |
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); | |
130 } | 95 } |
131 | 96 |
132 bool WMHelperMus::IsMaximizeModeWindowManagerEnabled() const { | 97 bool WMHelperMus::IsMaximizeModeWindowManagerEnabled() const { |
133 NOTIMPLEMENTED(); | 98 NOTIMPLEMENTED(); |
134 return false; | 99 return false; |
135 } | 100 } |
136 | 101 |
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 | |
143 void WMHelperMus::OnWindowTreeFocusChanged(ui::Window* gained_focus, | 102 void WMHelperMus::OnWindowTreeFocusChanged(ui::Window* gained_focus, |
144 ui::Window* lost_focus) { | 103 ui::Window* lost_focus) { |
145 aura::Window* gained_active = | 104 aura::Window* gained_active = |
146 gained_focus ? GetToplevelAuraWindow(gained_focus) : nullptr; | 105 gained_focus ? GetToplevelAuraWindow(gained_focus) : nullptr; |
147 aura::Window* lost_active = | 106 aura::Window* lost_active = |
148 lost_focus ? GetToplevelAuraWindow(lost_focus) : nullptr; | 107 lost_focus ? GetToplevelAuraWindow(lost_focus) : nullptr; |
149 | 108 |
150 // Because NativeWidgetMus uses separate FocusClient for every toplevel | 109 // Because NativeWidgetMus uses separate FocusClient for every toplevel |
151 // window, we have to stop observering the FocusClient of the |lost_active| | 110 // window, we have to stop observering the FocusClient of the |lost_active| |
152 // and start observering the FocusClient of the |gained_active|. | 111 // and start observering the FocusClient of the |gained_active|. |
(...skipping 20 matching lines...) Expand all Loading... | |
173 | 132 |
174 void WMHelperMus::OnWindowFocused(aura::Window* gained_focus, | 133 void WMHelperMus::OnWindowFocused(aura::Window* gained_focus, |
175 aura::Window* lost_focus) { | 134 aura::Window* lost_focus) { |
176 if (focused_window_ != gained_focus) { | 135 if (focused_window_ != gained_focus) { |
177 focused_window_ = gained_focus; | 136 focused_window_ = gained_focus; |
178 NotifyWindowFocused(gained_focus, lost_focus); | 137 NotifyWindowFocused(gained_focus, lost_focus); |
179 } | 138 } |
180 } | 139 } |
181 | 140 |
182 } // namespace exo | 141 } // namespace exo |
OLD | NEW |