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 if (!window) | |
|
reveman
2016/08/22 19:28:38
nit: I prefer if this check was moved to the calle
Peng
2016/08/22 20:25:50
Done.
| |
| 19 return nullptr; | |
| 20 // We never create child ui::Window, so window->parent() should be null. | |
| 21 DCHECK(!window->parent()); | |
| 22 auto* widget = views::NativeWidgetMus::GetWidgetForWindow(window); | |
|
reveman
2016/08/22 19:28:38
nit: I prefer to avoid "auto" unless iterator type
Peng
2016/08/22 20:25:50
Done.
| |
| 23 if (!widget) | |
| 24 return nullptr; | |
| 25 return widget->GetNativeWindow(); | |
| 26 } | |
| 27 } | |
| 10 | 28 |
| 11 //////////////////////////////////////////////////////////////////////////////// | 29 //////////////////////////////////////////////////////////////////////////////// |
| 12 // WMHelperMus, public: | 30 // WMHelperMus, public: |
| 13 | 31 |
| 14 WMHelperMus::WMHelperMus() {} | 32 WMHelperMus::WMHelperMus() |
| 33 : active_window_(GetActiveWindow()), focused_window_(GetFocusedWindow()) { | |
|
reveman
2016/08/22 19:28:38
hm, can we avoid calling virtual functions in the
Peng
2016/08/22 20:25:50
Done.
| |
| 34 views::WindowManagerConnection::Get()->client()->AddObserver(this); | |
| 35 } | |
| 15 | 36 |
| 16 WMHelperMus::~WMHelperMus() {} | 37 WMHelperMus::~WMHelperMus() { |
| 38 auto* connection = views::WindowManagerConnection::Get(); | |
|
reveman
2016/08/22 19:28:38
nit: I prefer not using auto here
Peng
2016/08/22 20:25:50
Done.
| |
| 39 if (connection) | |
|
reveman
2016/08/22 19:28:38
do we need this check?
Peng
2016/08/22 20:25:50
Removed it. Done
| |
| 40 connection->client()->RemoveObserver(this); | |
| 41 } | |
| 17 | 42 |
| 18 //////////////////////////////////////////////////////////////////////////////// | 43 //////////////////////////////////////////////////////////////////////////////// |
| 19 // WMHelperMus, private: | 44 // WMHelperMus, private: |
| 20 | 45 |
| 21 const ash::DisplayInfo WMHelperMus::GetDisplayInfo(int64_t display_id) const { | 46 const ash::DisplayInfo WMHelperMus::GetDisplayInfo(int64_t display_id) const { |
| 22 NOTIMPLEMENTED(); | 47 NOTIMPLEMENTED(); |
| 23 return ash::DisplayInfo(); | 48 return ash::DisplayInfo(); |
| 24 } | 49 } |
| 25 | 50 |
| 26 aura::Window* WMHelperMus::GetContainer(int container_id) { | 51 aura::Window* WMHelperMus::GetContainer(int container_id) { |
| 27 NOTIMPLEMENTED(); | 52 NOTIMPLEMENTED(); |
| 28 return nullptr; | 53 return nullptr; |
| 29 } | 54 } |
| 30 | 55 |
| 31 aura::Window* WMHelperMus::GetActiveWindow() const { | 56 aura::Window* WMHelperMus::GetActiveWindow() const { |
| 32 NOTIMPLEMENTED(); | 57 ui::Window* window = |
| 33 return nullptr; | 58 views::WindowManagerConnection::Get()->client()->GetFocusedWindow(); |
| 59 return GetToplevelAuraWindow(window); | |
| 34 } | 60 } |
| 35 | 61 |
| 36 aura::Window* WMHelperMus::GetFocusedWindow() const { | 62 aura::Window* WMHelperMus::GetFocusedWindow() const { |
| 37 NOTIMPLEMENTED(); | 63 auto* active_window = GetActiveWindow(); |
|
reveman
2016/08/22 19:28:38
nit: I prefer not using auto here
Peng
2016/08/22 20:25:50
Done.
| |
| 38 return nullptr; | 64 if (!active_window) |
| 65 return nullptr; | |
| 66 auto* focus_client = aura::client::GetFocusClient(active_window); | |
|
reveman
2016/08/22 19:28:38
nit: I prefer not using auto here
Peng
2016/08/22 20:25:50
Done.
| |
| 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 Loading... | |
| 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 = GetToplevelAuraWindow(gained_focus); | |
| 103 aura::Window* lost_active = GetToplevelAuraWindow(lost_focus); | |
| 104 | |
| 105 OnWindowFocused(nullptr, focused_window_); | |
|
reveman
2016/08/22 19:28:38
why is this called twice with null as temporarily
Peng
2016/08/22 20:25:50
Done.
| |
| 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 auto* focus_client = aura::client::GetFocusClient(active_window_); | |
|
reveman
2016/08/22 19:28:38
nit: I prefer not using auto here
Peng
2016/08/22 20:25:50
Done.
| |
| 112 focus_client->RemoveObserver(this); | |
| 113 } | |
| 114 | |
| 115 active_window_ = gained_active; | |
| 116 NotifyWindowActivated(gained_active, lost_active); | |
| 117 | |
| 118 if (active_window_) { | |
| 119 auto* focus_client = aura::client::GetFocusClient(active_window_); | |
|
reveman
2016/08/22 19:28:38
nit: I prefer not using auto here
Peng
2016/08/22 20:25:50
Done.
| |
| 120 focus_client->AddObserver(this); | |
| 121 OnWindowFocused(focus_client->GetFocusedWindow(), nullptr); | |
| 122 } | |
| 123 } | |
| 124 | |
| 125 void WMHelperMus::OnWindowFocused(aura::Window* gained_focus, | |
| 126 aura::Window* lost_focus) { | |
| 127 if (focused_window_ != gained_focus) { | |
| 128 focused_window_ = gained_focus; | |
| 129 NotifyWindowFocused(gained_focus, lost_focus); | |
| 130 } | |
| 131 } | |
| 132 | |
| 71 } // namespace exo | 133 } // namespace exo |
| OLD | NEW |