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

Side by Side Diff: components/exo/wm_helper_mus.cc

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

Powered by Google App Engine
This is Rietveld 408576698