OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 "mash/wm/user_window_controller_impl.h" | 5 #include "mash/wm/user_window_controller_impl.h" |
6 | 6 |
7 #include "components/mus/public/cpp/property_type_converters.h" | 7 #include "components/mus/public/cpp/property_type_converters.h" |
8 #include "components/mus/public/cpp/window.h" | 8 #include "components/mus/public/cpp/window.h" |
9 #include "components/mus/public/cpp/window_property.h" | 9 #include "components/mus/public/cpp/window_property.h" |
10 #include "components/mus/public/cpp/window_tree_connection.h" | 10 #include "components/mus/public/cpp/window_tree_client.h" |
11 #include "mash/wm/property_util.h" | 11 #include "mash/wm/property_util.h" |
12 #include "mash/wm/public/interfaces/container.mojom.h" | 12 #include "mash/wm/public/interfaces/container.mojom.h" |
13 #include "mash/wm/root_window_controller.h" | 13 #include "mash/wm/root_window_controller.h" |
14 #include "mojo/common/common_type_converters.h" | 14 #include "mojo/common/common_type_converters.h" |
15 #include "ui/resources/grit/ui_resources.h" | 15 #include "ui/resources/grit/ui_resources.h" |
16 | 16 |
17 MUS_DECLARE_WINDOW_PROPERTY_TYPE(uint32_t); | 17 MUS_DECLARE_WINDOW_PROPERTY_TYPE(uint32_t); |
18 | 18 |
19 namespace mash { | 19 namespace mash { |
20 namespace wm { | 20 namespace wm { |
(...skipping 12 matching lines...) Expand all Loading... |
33 | 33 |
34 // Get a UserWindow struct from a mus::Window. | 34 // Get a UserWindow struct from a mus::Window. |
35 mojom::UserWindowPtr GetUserWindow(mus::Window* window) { | 35 mojom::UserWindowPtr GetUserWindow(mus::Window* window) { |
36 mojom::UserWindowPtr user_window(mojom::UserWindow::New()); | 36 mojom::UserWindowPtr user_window(mojom::UserWindow::New()); |
37 DCHECK_NE(0u, window->GetLocalProperty(kUserWindowIdKey)); | 37 DCHECK_NE(0u, window->GetLocalProperty(kUserWindowIdKey)); |
38 user_window->window_id = window->GetLocalProperty(kUserWindowIdKey); | 38 user_window->window_id = window->GetLocalProperty(kUserWindowIdKey); |
39 user_window->window_title = mojo::String::From(GetWindowTitle(window)); | 39 user_window->window_title = mojo::String::From(GetWindowTitle(window)); |
40 user_window->window_app_icon = GetWindowAppIcon(window); | 40 user_window->window_app_icon = GetWindowAppIcon(window); |
41 user_window->window_app_id = mojo::String::From(GetAppID(window)); | 41 user_window->window_app_id = mojo::String::From(GetAppID(window)); |
42 user_window->ignored_by_shelf = GetWindowIgnoredByShelf(window); | 42 user_window->ignored_by_shelf = GetWindowIgnoredByShelf(window); |
43 mus::Window* focused = window->connection()->GetFocusedWindow(); | 43 mus::Window* focused = window->window_tree()->GetFocusedWindow(); |
44 focused = GetTopLevelWindow(focused, window->parent()); | 44 focused = GetTopLevelWindow(focused, window->parent()); |
45 user_window->window_has_focus = focused == window; | 45 user_window->window_has_focus = focused == window; |
46 return user_window; | 46 return user_window; |
47 } | 47 } |
48 | 48 |
49 } // namespace | 49 } // namespace |
50 | 50 |
51 // Observes property changes on user windows. UserWindowControllerImpl uses | 51 // Observes property changes on user windows. UserWindowControllerImpl uses |
52 // this separate observer to avoid observing duplicate tree change | 52 // this separate observer to avoid observing duplicate tree change |
53 // notifications. | 53 // notifications. |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
95 | 95 |
96 RemoveObservers(user_container); | 96 RemoveObservers(user_container); |
97 } | 97 } |
98 | 98 |
99 void UserWindowControllerImpl::Initialize( | 99 void UserWindowControllerImpl::Initialize( |
100 RootWindowController* root_controller) { | 100 RootWindowController* root_controller) { |
101 DCHECK(root_controller); | 101 DCHECK(root_controller); |
102 DCHECK(!root_controller_); | 102 DCHECK(!root_controller_); |
103 root_controller_ = root_controller; | 103 root_controller_ = root_controller; |
104 GetUserWindowContainer()->AddObserver(this); | 104 GetUserWindowContainer()->AddObserver(this); |
105 GetUserWindowContainer()->connection()->AddObserver(this); | 105 GetUserWindowContainer()->window_tree()->AddObserver(this); |
106 window_property_observer_.reset(new WindowPropertyObserver(this)); | 106 window_property_observer_.reset(new WindowPropertyObserver(this)); |
107 for (mus::Window* window : GetUserWindowContainer()->children()) { | 107 for (mus::Window* window : GetUserWindowContainer()->children()) { |
108 AssignIdIfNecessary(window); | 108 AssignIdIfNecessary(window); |
109 window->AddObserver(window_property_observer_.get()); | 109 window->AddObserver(window_property_observer_.get()); |
110 } | 110 } |
111 } | 111 } |
112 | 112 |
113 void UserWindowControllerImpl::AssignIdIfNecessary(mus::Window* window) { | 113 void UserWindowControllerImpl::AssignIdIfNecessary(mus::Window* window) { |
114 if (window->GetLocalProperty(kUserWindowIdKey) == 0u) | 114 if (window->GetLocalProperty(kUserWindowIdKey) == 0u) |
115 window->SetLocalProperty(kUserWindowIdKey, next_id_++); | 115 window->SetLocalProperty(kUserWindowIdKey, next_id_++); |
116 } | 116 } |
117 | 117 |
118 void UserWindowControllerImpl::RemoveObservers(mus::Window* user_container) { | 118 void UserWindowControllerImpl::RemoveObservers(mus::Window* user_container) { |
119 user_container->RemoveObserver(this); | 119 user_container->RemoveObserver(this); |
120 user_container->connection()->RemoveObserver(this); | 120 user_container->window_tree()->RemoveObserver(this); |
121 for (auto iter : user_container->children()) | 121 for (auto iter : user_container->children()) |
122 iter->RemoveObserver(window_property_observer_.get()); | 122 iter->RemoveObserver(window_property_observer_.get()); |
123 } | 123 } |
124 | 124 |
125 mus::Window* UserWindowControllerImpl::GetUserWindowById(uint32_t id) { | 125 mus::Window* UserWindowControllerImpl::GetUserWindowById(uint32_t id) { |
126 for (mus::Window* window : GetUserWindowContainer()->children()) { | 126 for (mus::Window* window : GetUserWindowContainer()->children()) { |
127 if (window->GetLocalProperty(kUserWindowIdKey) == id) | 127 if (window->GetLocalProperty(kUserWindowIdKey) == id) |
128 return window; | 128 return window; |
129 } | 129 } |
130 return nullptr; | 130 return nullptr; |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
191 } | 191 } |
192 | 192 |
193 void UserWindowControllerImpl::FocusUserWindow(uint32_t window_id) { | 193 void UserWindowControllerImpl::FocusUserWindow(uint32_t window_id) { |
194 mus::Window* window = GetUserWindowById(window_id); | 194 mus::Window* window = GetUserWindowById(window_id); |
195 if (window) | 195 if (window) |
196 window->SetFocus(); | 196 window->SetFocus(); |
197 } | 197 } |
198 | 198 |
199 } // namespace wm | 199 } // namespace wm |
200 } // namespace mash | 200 } // namespace mash |
OLD | NEW |