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

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

Issue 2261473002: exo: WMHelperMus: Add focus and activation support. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix a review issue 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"
9 #include "ui/aura/client/focus_client.h"
10 #include "ui/views/mus/native_widget_mus.h"
11 #include "ui/views/mus/window_manager_connection.h"
12 #include "ui/views/widget/widget.h"
8 13
9 namespace exo { 14 namespace exo {
15 namespace {
16
17 aura::Window* GetToplevelAuraWindow(ui::Window* window) {
18 DCHECK(window);
19 // We never create child ui::Window, so window->parent() should be null.
20 DCHECK(!window->parent());
21 views::Widget* widget = views::NativeWidgetMus::GetWidgetForWindow(window);
22 if (!widget)
23 return nullptr;
24 return widget->GetNativeWindow();
25 }
26
27 } // namespace
10 28
11 //////////////////////////////////////////////////////////////////////////////// 29 ////////////////////////////////////////////////////////////////////////////////
12 // WMHelperMus, public: 30 // WMHelperMus, public:
13 31
14 WMHelperMus::WMHelperMus() {} 32 WMHelperMus::WMHelperMus()
33 : active_window_(WMHelperMus::GetActiveWindow()),
34 focused_window_(WMHelperMus::GetFocusedWindow()) {
35 views::WindowManagerConnection::Get()->client()->AddObserver(this);
36 }
15 37
16 WMHelperMus::~WMHelperMus() {} 38 WMHelperMus::~WMHelperMus() {
39 views::WindowManagerConnection::Get()->client()->RemoveObserver(this);
40 }
17 41
18 //////////////////////////////////////////////////////////////////////////////// 42 ////////////////////////////////////////////////////////////////////////////////
19 // WMHelperMus, private: 43 // WMHelperMus, private:
20 44
21 const ash::DisplayInfo WMHelperMus::GetDisplayInfo(int64_t display_id) const { 45 const ash::DisplayInfo WMHelperMus::GetDisplayInfo(int64_t display_id) const {
22 NOTIMPLEMENTED(); 46 NOTIMPLEMENTED();
23 return ash::DisplayInfo(); 47 return ash::DisplayInfo();
24 } 48 }
25 49
26 aura::Window* WMHelperMus::GetContainer(int container_id) { 50 aura::Window* WMHelperMus::GetContainer(int container_id) {
27 NOTIMPLEMENTED(); 51 NOTIMPLEMENTED();
28 return nullptr; 52 return nullptr;
29 } 53 }
30 54
31 aura::Window* WMHelperMus::GetActiveWindow() const { 55 aura::Window* WMHelperMus::GetActiveWindow() const {
32 NOTIMPLEMENTED(); 56 ui::Window* window =
33 return nullptr; 57 views::WindowManagerConnection::Get()->client()->GetFocusedWindow();
58 return window ? GetToplevelAuraWindow(window) : nullptr;
34 } 59 }
35 60
36 aura::Window* WMHelperMus::GetFocusedWindow() const { 61 aura::Window* WMHelperMus::GetFocusedWindow() const {
37 NOTIMPLEMENTED(); 62 aura::Window* active_window = GetActiveWindow();
38 return nullptr; 63 if (!active_window)
64 return nullptr;
65 aura::client::FocusClient* focus_client =
66 aura::client::GetFocusClient(active_window);
67 return focus_client->GetFocusedWindow();
39 } 68 }
40 69
41 ui::CursorSetType WMHelperMus::GetCursorSet() const { 70 ui::CursorSetType WMHelperMus::GetCursorSet() const {
42 NOTIMPLEMENTED(); 71 NOTIMPLEMENTED();
43 return ui::CursorSetType::CURSOR_SET_NORMAL; 72 return ui::CursorSetType::CURSOR_SET_NORMAL;
44 } 73 }
45 74
46 void WMHelperMus::AddPreTargetHandler(ui::EventHandler* handler) { 75 void WMHelperMus::AddPreTargetHandler(ui::EventHandler* handler) {
47 NOTIMPLEMENTED(); 76 NOTIMPLEMENTED();
48 } 77 }
(...skipping 12 matching lines...) Expand all
61 90
62 void WMHelperMus::RemovePostTargetHandler(ui::EventHandler* handler) { 91 void WMHelperMus::RemovePostTargetHandler(ui::EventHandler* handler) {
63 NOTIMPLEMENTED(); 92 NOTIMPLEMENTED();
64 } 93 }
65 94
66 bool WMHelperMus::IsMaximizeModeWindowManagerEnabled() const { 95 bool WMHelperMus::IsMaximizeModeWindowManagerEnabled() const {
67 NOTIMPLEMENTED(); 96 NOTIMPLEMENTED();
68 return false; 97 return false;
69 } 98 }
70 99
100 void WMHelperMus::OnWindowTreeFocusChanged(ui::Window* gained_focus,
101 ui::Window* lost_focus) {
102 aura::Window* gained_active =
103 gained_focus ? GetToplevelAuraWindow(gained_focus) : nullptr;
104 aura::Window* lost_active =
105 lost_focus ? GetToplevelAuraWindow(lost_focus) : nullptr;
106
107 // Because NativeWidgetMus uses separate FocusClient for every toplevel
108 // window, we have to stop observering the FocusClient of the |lost_active|
109 // and start observering the FocusClient of the |gained_active|.
110 if (active_window_) {
111 aura::client::FocusClient* focus_client =
112 aura::client::GetFocusClient(active_window_);
113 focus_client->RemoveObserver(this);
114 }
115
116 active_window_ = gained_active;
117 NotifyWindowActivated(gained_active, lost_active);
118
119 aura::Window* focused_window = nullptr;
120 if (active_window_) {
121 aura::client::FocusClient* focus_client =
122 aura::client::GetFocusClient(active_window_);
123 focus_client->AddObserver(this);
124 focused_window = focus_client->GetFocusedWindow();
125 }
126
127 // OnWindowFocused() will update |focused_window_|.
128 OnWindowFocused(focused_window, focused_window_);
129 }
130
131 void WMHelperMus::OnWindowFocused(aura::Window* gained_focus,
132 aura::Window* lost_focus) {
133 if (focused_window_ != gained_focus) {
134 focused_window_ = gained_focus;
135 NotifyWindowFocused(gained_focus, lost_focus);
136 }
137 }
138
71 } // namespace exo 139 } // 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