Chromium Code Reviews| 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" | |
| 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 } | |
|
reveman
2016/08/22 21:38:33
nit: blank line after this to be consistent with h
Peng
2016/08/22 23:10:09
Done.
| |
| 26 } | |
| 10 | 27 |
| 11 //////////////////////////////////////////////////////////////////////////////// | 28 //////////////////////////////////////////////////////////////////////////////// |
| 12 // WMHelperMus, public: | 29 // WMHelperMus, public: |
| 13 | 30 |
| 14 WMHelperMus::WMHelperMus() {} | 31 WMHelperMus::WMHelperMus() |
| 32 : active_window_(WMHelperMus::GetActiveWindow()), | |
| 33 focused_window_(WMHelperMus::GetFocusedWindow()) { | |
| 34 views::WindowManagerConnection::Get()->client()->AddObserver(this); | |
| 35 } | |
| 15 | 36 |
| 16 WMHelperMus::~WMHelperMus() {} | 37 WMHelperMus::~WMHelperMus() { |
| 38 views::WindowManagerConnection::Get()->client()->RemoveObserver(this); | |
| 39 } | |
| 17 | 40 |
| 18 //////////////////////////////////////////////////////////////////////////////// | 41 //////////////////////////////////////////////////////////////////////////////// |
| 19 // WMHelperMus, private: | 42 // WMHelperMus, private: |
| 20 | 43 |
| 21 const ash::DisplayInfo WMHelperMus::GetDisplayInfo(int64_t display_id) const { | 44 const ash::DisplayInfo WMHelperMus::GetDisplayInfo(int64_t display_id) const { |
| 22 NOTIMPLEMENTED(); | 45 NOTIMPLEMENTED(); |
| 23 return ash::DisplayInfo(); | 46 return ash::DisplayInfo(); |
| 24 } | 47 } |
| 25 | 48 |
| 26 aura::Window* WMHelperMus::GetContainer(int container_id) { | 49 aura::Window* WMHelperMus::GetContainer(int container_id) { |
| 27 NOTIMPLEMENTED(); | 50 NOTIMPLEMENTED(); |
| 28 return nullptr; | 51 return nullptr; |
| 29 } | 52 } |
| 30 | 53 |
| 31 aura::Window* WMHelperMus::GetActiveWindow() const { | 54 aura::Window* WMHelperMus::GetActiveWindow() const { |
| 32 NOTIMPLEMENTED(); | 55 ui::Window* window = |
| 33 return nullptr; | 56 views::WindowManagerConnection::Get()->client()->GetFocusedWindow(); |
| 57 return window ? GetToplevelAuraWindow(window) : nullptr; | |
| 34 } | 58 } |
| 35 | 59 |
| 36 aura::Window* WMHelperMus::GetFocusedWindow() const { | 60 aura::Window* WMHelperMus::GetFocusedWindow() const { |
| 37 NOTIMPLEMENTED(); | 61 aura::Window* active_window = GetActiveWindow(); |
| 38 return nullptr; | 62 if (!active_window) |
| 63 return nullptr; | |
| 64 aura::client::FocusClient* focus_client = | |
| 65 aura::client::GetFocusClient(active_window); | |
| 66 return focus_client->GetFocusedWindow(); | |
| 39 } | 67 } |
| 40 | 68 |
| 41 ui::CursorSetType WMHelperMus::GetCursorSet() const { | 69 ui::CursorSetType WMHelperMus::GetCursorSet() const { |
| 42 NOTIMPLEMENTED(); | 70 NOTIMPLEMENTED(); |
| 43 return ui::CursorSetType::CURSOR_SET_NORMAL; | 71 return ui::CursorSetType::CURSOR_SET_NORMAL; |
| 44 } | 72 } |
| 45 | 73 |
| 46 void WMHelperMus::AddPreTargetHandler(ui::EventHandler* handler) { | 74 void WMHelperMus::AddPreTargetHandler(ui::EventHandler* handler) { |
| 47 NOTIMPLEMENTED(); | 75 NOTIMPLEMENTED(); |
| 48 } | 76 } |
| (...skipping 12 matching lines...) Expand all Loading... | |
| 61 | 89 |
| 62 void WMHelperMus::RemovePostTargetHandler(ui::EventHandler* handler) { | 90 void WMHelperMus::RemovePostTargetHandler(ui::EventHandler* handler) { |
| 63 NOTIMPLEMENTED(); | 91 NOTIMPLEMENTED(); |
| 64 } | 92 } |
| 65 | 93 |
| 66 bool WMHelperMus::IsMaximizeModeWindowManagerEnabled() const { | 94 bool WMHelperMus::IsMaximizeModeWindowManagerEnabled() const { |
| 67 NOTIMPLEMENTED(); | 95 NOTIMPLEMENTED(); |
| 68 return false; | 96 return false; |
| 69 } | 97 } |
| 70 | 98 |
| 99 void WMHelperMus::OnWindowTreeFocusChanged(ui::Window* gained_focus, | |
| 100 ui::Window* lost_focus) { | |
| 101 aura::Window* gained_active = | |
| 102 gained_focus ? GetToplevelAuraWindow(gained_focus) : nullptr; | |
| 103 aura::Window* lost_active = | |
| 104 lost_focus ? GetToplevelAuraWindow(lost_focus) : nullptr; | |
| 105 | |
| 106 // Because NativeWidgetMus uses separate FocusClient for every toplevel | |
| 107 // window, we have to stop observering the FocusClient of the |lost_active| | |
| 108 // and start observering the FocusClient of the |gained_active|. | |
| 109 if (active_window_) { | |
| 110 aura::client::FocusClient* focus_client = | |
| 111 aura::client::GetFocusClient(active_window_); | |
| 112 focus_client->RemoveObserver(this); | |
| 113 } | |
| 114 | |
| 115 active_window_ = gained_active; | |
| 116 NotifyWindowActivated(gained_active, lost_active); | |
| 117 | |
| 118 aura::Window* focused_window = nullptr; | |
| 119 if (active_window_) { | |
| 120 aura::client::FocusClient* focus_client = | |
| 121 aura::client::GetFocusClient(active_window_); | |
| 122 focus_client->AddObserver(this); | |
| 123 focused_window = focus_client->GetFocusedWindow(); | |
| 124 } | |
| 125 | |
| 126 // OnWindowFocused() will update |focused_window_|. | |
| 127 OnWindowFocused(focused_window, focused_window_); | |
| 128 } | |
| 129 | |
| 130 void WMHelperMus::OnWindowFocused(aura::Window* gained_focus, | |
| 131 aura::Window* lost_focus) { | |
| 132 if (focused_window_ != gained_focus) { | |
| 133 focused_window_ = gained_focus; | |
| 134 NotifyWindowFocused(gained_focus, lost_focus); | |
| 135 } | |
| 136 } | |
| 137 | |
| 71 } // namespace exo | 138 } // namespace exo |
| OLD | NEW |