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 "services/ui/public/cpp/window_tree_client.h" |
7 #include "ui/aura/client/focus_client.h" | 8 #include "ui/aura/client/focus_client.h" |
8 #include "ui/aura/env.h" | 9 #include "ui/aura/env.h" |
9 #include "ui/aura/window.h" | 10 #include "ui/aura/window.h" |
10 #include "ui/display/manager/managed_display_info.h" | 11 #include "ui/display/manager/managed_display_info.h" |
11 #include "ui/wm/public/activation_client.h" | 12 #include "ui/views/mus/native_widget_mus.h" |
| 13 #include "ui/views/mus/window_manager_connection.h" |
| 14 #include "ui/views/widget/widget.h" |
| 15 |
12 namespace exo { | 16 namespace exo { |
| 17 namespace { |
| 18 |
| 19 aura::Window* GetToplevelAuraWindow(ui::Window* window) { |
| 20 DCHECK(window); |
| 21 // We never create child ui::Window, so window->parent() should be null. |
| 22 DCHECK(!window->parent()); |
| 23 views::Widget* widget = views::NativeWidgetMus::GetWidgetForWindow(window); |
| 24 if (!widget) |
| 25 return nullptr; |
| 26 return widget->GetNativeWindow(); |
| 27 } |
| 28 |
| 29 } // namespace |
13 | 30 |
14 //////////////////////////////////////////////////////////////////////////////// | 31 //////////////////////////////////////////////////////////////////////////////// |
15 // WMHelperMus, public: | 32 // WMHelperMus, public: |
16 | 33 |
17 WMHelperMus::WMHelperMus() { | 34 WMHelperMus::WMHelperMus() |
18 aura::Env* env = aura::Env::GetInstance(); | 35 : active_window_(WMHelperMus::GetActiveWindow()), |
19 SetActiveFocusClient(env->active_focus_client(), | 36 focused_window_(WMHelperMus::GetFocusedWindow()) { |
20 env->active_focus_client_root()); | 37 views::WindowManagerConnection::Get()->client()->AddObserver(this); |
21 env->AddObserver(this); | |
22 } | 38 } |
23 | 39 |
24 WMHelperMus::~WMHelperMus() { | 40 WMHelperMus::~WMHelperMus() { |
25 if (active_focus_client_) | 41 views::WindowManagerConnection::Get()->client()->RemoveObserver(this); |
26 active_focus_client_->RemoveObserver(this); | |
27 aura::Env::GetInstance()->RemoveObserver(this); | |
28 } | 42 } |
29 | 43 |
30 //////////////////////////////////////////////////////////////////////////////// | 44 //////////////////////////////////////////////////////////////////////////////// |
31 // WMHelperMus, private: | 45 // WMHelperMus, private: |
32 | 46 |
33 const display::ManagedDisplayInfo WMHelperMus::GetDisplayInfo( | 47 const display::ManagedDisplayInfo WMHelperMus::GetDisplayInfo( |
34 int64_t display_id) const { | 48 int64_t display_id) const { |
35 // TODO(penghuang): Return real display info when it is supported in mus. | 49 // TODO(penghuang): Return real display info when it is supported in mus. |
36 return display::ManagedDisplayInfo(display_id, "", false); | 50 return display::ManagedDisplayInfo(display_id, "", false); |
37 } | 51 } |
38 | 52 |
39 aura::Window* WMHelperMus::GetContainer(int container_id) { | 53 aura::Window* WMHelperMus::GetContainer(int container_id) { |
40 NOTIMPLEMENTED(); | 54 NOTIMPLEMENTED(); |
41 return nullptr; | 55 return nullptr; |
42 } | 56 } |
43 | 57 |
44 aura::Window* WMHelperMus::GetActiveWindow() const { | 58 aura::Window* WMHelperMus::GetActiveWindow() const { |
45 return active_window_; | 59 ui::Window* window = |
| 60 views::WindowManagerConnection::Get()->client()->GetFocusedWindow(); |
| 61 return window ? GetToplevelAuraWindow(window) : nullptr; |
46 } | 62 } |
47 | 63 |
48 aura::Window* WMHelperMus::GetFocusedWindow() const { | 64 aura::Window* WMHelperMus::GetFocusedWindow() const { |
49 return focused_window_; | 65 aura::Window* active_window = GetActiveWindow(); |
| 66 if (!active_window) |
| 67 return nullptr; |
| 68 aura::client::FocusClient* focus_client = |
| 69 aura::client::GetFocusClient(active_window); |
| 70 return focus_client->GetFocusedWindow(); |
50 } | 71 } |
51 | 72 |
52 ui::CursorSetType WMHelperMus::GetCursorSet() const { | 73 ui::CursorSetType WMHelperMus::GetCursorSet() const { |
53 NOTIMPLEMENTED(); | 74 NOTIMPLEMENTED(); |
54 return ui::CursorSetType::CURSOR_SET_NORMAL; | 75 return ui::CursorSetType::CURSOR_SET_NORMAL; |
55 } | 76 } |
56 | 77 |
57 void WMHelperMus::AddPreTargetHandler(ui::EventHandler* handler) { | 78 void WMHelperMus::AddPreTargetHandler(ui::EventHandler* handler) { |
58 aura::Env::GetInstance()->AddPreTargetHandler(handler); | 79 aura::Env::GetInstance()->AddPreTargetHandler(handler); |
59 } | 80 } |
(...skipping 21 matching lines...) Expand all Loading... |
81 | 102 |
82 bool WMHelperMus::IsSpokenFeedbackEnabled() const { | 103 bool WMHelperMus::IsSpokenFeedbackEnabled() const { |
83 NOTIMPLEMENTED(); | 104 NOTIMPLEMENTED(); |
84 return false; | 105 return false; |
85 } | 106 } |
86 | 107 |
87 void WMHelperMus::PlayEarcon(int sound_key) const { | 108 void WMHelperMus::PlayEarcon(int sound_key) const { |
88 NOTIMPLEMENTED(); | 109 NOTIMPLEMENTED(); |
89 } | 110 } |
90 | 111 |
91 void WMHelperMus::OnWindowInitialized(aura::Window* window) {} | 112 void WMHelperMus::OnWindowTreeFocusChanged(ui::Window* gained_focus, |
| 113 ui::Window* lost_focus) { |
| 114 aura::Window* gained_active = |
| 115 gained_focus ? GetToplevelAuraWindow(gained_focus) : nullptr; |
| 116 aura::Window* lost_active = |
| 117 lost_focus ? GetToplevelAuraWindow(lost_focus) : nullptr; |
92 | 118 |
93 void WMHelperMus::OnActiveFocusClientChanged( | 119 // Because NativeWidgetMus uses separate FocusClient for every toplevel |
94 aura::client::FocusClient* focus_client, | 120 // window, we have to stop observering the FocusClient of the |lost_active| |
95 aura::Window* window) { | 121 // and start observering the FocusClient of the |gained_active|. |
96 SetActiveFocusClient(focus_client, window); | 122 if (active_window_) { |
| 123 aura::client::FocusClient* focus_client = |
| 124 aura::client::GetFocusClient(active_window_); |
| 125 focus_client->RemoveObserver(this); |
| 126 } |
| 127 |
| 128 active_window_ = gained_active; |
| 129 NotifyWindowActivated(gained_active, lost_active); |
| 130 |
| 131 aura::Window* focused_window = nullptr; |
| 132 if (active_window_) { |
| 133 aura::client::FocusClient* focus_client = |
| 134 aura::client::GetFocusClient(active_window_); |
| 135 focus_client->AddObserver(this); |
| 136 focused_window = focus_client->GetFocusedWindow(); |
| 137 } |
| 138 |
| 139 // OnWindowFocused() will update |focused_window_|. |
| 140 OnWindowFocused(focused_window, focused_window_); |
97 } | 141 } |
98 | 142 |
99 void WMHelperMus::OnWindowFocused(aura::Window* gained_focus, | 143 void WMHelperMus::OnWindowFocused(aura::Window* gained_focus, |
100 aura::Window* lost_focus) { | 144 aura::Window* lost_focus) { |
101 if (focused_window_ == gained_focus) | 145 if (focused_window_ != gained_focus) { |
102 return; | 146 focused_window_ = gained_focus; |
103 | 147 NotifyWindowFocused(gained_focus, lost_focus); |
104 SetActiveWindow(GetActivationClient()->GetActiveWindow()); | 148 } |
105 SetFocusedWindow(gained_focus); | |
106 } | 149 } |
107 | 150 |
108 void WMHelperMus::OnKeyboardDeviceConfigurationChanged() { | 151 void WMHelperMus::OnKeyboardDeviceConfigurationChanged() { |
109 NotifyKeyboardDeviceConfigurationChanged(); | 152 NotifyKeyboardDeviceConfigurationChanged(); |
110 } | 153 } |
111 | 154 |
112 void WMHelperMus::SetActiveFocusClient(aura::client::FocusClient* focus_client, | |
113 aura::Window* window) { | |
114 if (active_focus_client_) | |
115 active_focus_client_->RemoveObserver(this); | |
116 active_focus_client_ = focus_client; | |
117 root_with_active_focus_client_ = window; | |
118 if (active_focus_client_) { | |
119 active_focus_client_->AddObserver(this); | |
120 SetActiveWindow(GetActivationClient()->GetActiveWindow()); | |
121 SetFocusedWindow(active_focus_client_->GetFocusedWindow()); | |
122 } else { | |
123 SetActiveWindow(nullptr); | |
124 SetFocusedWindow(nullptr); | |
125 } | |
126 } | |
127 | |
128 void WMHelperMus::SetActiveWindow(aura::Window* window) { | |
129 if (active_window_ == window) | |
130 return; | |
131 | |
132 aura::Window* lost_active = active_window_; | |
133 active_window_ = window; | |
134 NotifyWindowActivated(active_window_, lost_active); | |
135 } | |
136 | |
137 void WMHelperMus::SetFocusedWindow(aura::Window* window) { | |
138 if (focused_window_ == window) | |
139 return; | |
140 | |
141 aura::Window* lost_focus = focused_window_; | |
142 focused_window_ = window; | |
143 NotifyWindowFocused(focused_window_, lost_focus); | |
144 } | |
145 | |
146 aura::client::ActivationClient* WMHelperMus::GetActivationClient() { | |
147 return root_with_active_focus_client_ | |
148 ? aura::client::GetActivationClient(root_with_active_focus_client_) | |
149 : nullptr; | |
150 } | |
151 | |
152 } // namespace exo | 155 } // namespace exo |
OLD | NEW |