OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "ui/aura/mus/window_tree_client.h" | 5 #include "ui/aura/mus/window_tree_client.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 | 8 |
9 #include <string> | 9 #include <string> |
10 #include <utility> | 10 #include <utility> |
11 #include <vector> | 11 #include <vector> |
12 | 12 |
13 #include "base/auto_reset.h" | 13 #include "base/auto_reset.h" |
14 #include "base/bind.h" | 14 #include "base/bind.h" |
15 #include "base/memory/ptr_util.h" | 15 #include "base/memory/ptr_util.h" |
16 #include "services/service_manager/public/cpp/connector.h" | 16 #include "services/service_manager/public/cpp/connector.h" |
17 #include "services/ui/public/interfaces/window_manager_window_tree_factory.mojom
.h" | 17 #include "services/ui/public/interfaces/window_manager_window_tree_factory.mojom
.h" |
18 #include "ui/aura/client/aura_constants.h" | 18 #include "ui/aura/client/aura_constants.h" |
19 #include "ui/aura/client/drag_drop_client.h" | 19 #include "ui/aura/client/drag_drop_client.h" |
| 20 #include "ui/aura/client/focus_client.h" |
20 #include "ui/aura/client/transient_window_client.h" | 21 #include "ui/aura/client/transient_window_client.h" |
21 #include "ui/aura/mus/capture_synchronizer.h" | 22 #include "ui/aura/mus/capture_synchronizer.h" |
22 #include "ui/aura/mus/drag_drop_controller_mus.h" | 23 #include "ui/aura/mus/drag_drop_controller_mus.h" |
23 #include "ui/aura/mus/focus_synchronizer.h" | |
24 #include "ui/aura/mus/in_flight_change.h" | 24 #include "ui/aura/mus/in_flight_change.h" |
25 #include "ui/aura/mus/input_method_mus.h" | 25 #include "ui/aura/mus/input_method_mus.h" |
26 #include "ui/aura/mus/property_converter.h" | 26 #include "ui/aura/mus/property_converter.h" |
27 #include "ui/aura/mus/surface_id_handler.h" | 27 #include "ui/aura/mus/surface_id_handler.h" |
28 #include "ui/aura/mus/window_manager_delegate.h" | 28 #include "ui/aura/mus/window_manager_delegate.h" |
29 #include "ui/aura/mus/window_mus.h" | 29 #include "ui/aura/mus/window_mus.h" |
30 #include "ui/aura/mus/window_port_mus.h" | 30 #include "ui/aura/mus/window_port_mus.h" |
31 #include "ui/aura/mus/window_tree_client_delegate.h" | 31 #include "ui/aura/mus/window_tree_client_delegate.h" |
32 #include "ui/aura/mus/window_tree_client_observer.h" | 32 #include "ui/aura/mus/window_tree_client_observer.h" |
33 #include "ui/aura/mus/window_tree_host_mus.h" | 33 #include "ui/aura/mus/window_tree_host_mus.h" |
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
128 next_change_id_(1), | 128 next_change_id_(1), |
129 delegate_(delegate), | 129 delegate_(delegate), |
130 window_manager_delegate_(window_manager_delegate), | 130 window_manager_delegate_(window_manager_delegate), |
131 binding_(this), | 131 binding_(this), |
132 tree_(nullptr), | 132 tree_(nullptr), |
133 in_destructor_(false), | 133 in_destructor_(false), |
134 weak_factory_(this) { | 134 weak_factory_(this) { |
135 // Allow for a null request in tests. | 135 // Allow for a null request in tests. |
136 if (request.is_pending()) | 136 if (request.is_pending()) |
137 binding_.Bind(std::move(request)); | 137 binding_.Bind(std::move(request)); |
| 138 delegate_->GetFocusClient()->AddObserver(this); |
138 client::GetTransientWindowClient()->AddObserver(this); | 139 client::GetTransientWindowClient()->AddObserver(this); |
139 if (window_manager_delegate) | 140 if (window_manager_delegate) |
140 window_manager_delegate->SetWindowManagerClient(this); | 141 window_manager_delegate->SetWindowManagerClient(this); |
141 } | 142 } |
142 | 143 |
143 WindowTreeClient::~WindowTreeClient() { | 144 WindowTreeClient::~WindowTreeClient() { |
144 in_destructor_ = true; | 145 in_destructor_ = true; |
145 | 146 |
146 for (WindowTreeClientObserver& observer : observers_) | 147 for (WindowTreeClientObserver& observer : observers_) |
147 observer.OnWillDestroyClient(this); | 148 observer.OnWillDestroyClient(this); |
(...skipping 17 matching lines...) Expand all Loading... |
165 // other random windows that it doesn't own. | 166 // other random windows that it doesn't own. |
166 while (!tracker.windows().empty()) | 167 while (!tracker.windows().empty()) |
167 delete tracker.windows().front(); | 168 delete tracker.windows().front(); |
168 | 169 |
169 for (WindowTreeClientObserver& observer : observers_) | 170 for (WindowTreeClientObserver& observer : observers_) |
170 observer.OnDidDestroyClient(this); | 171 observer.OnDidDestroyClient(this); |
171 | 172 |
172 capture_synchronizer_.reset(); | 173 capture_synchronizer_.reset(); |
173 | 174 |
174 client::GetTransientWindowClient()->RemoveObserver(this); | 175 client::GetTransientWindowClient()->RemoveObserver(this); |
| 176 delegate_->GetFocusClient()->RemoveObserver(this); |
175 } | 177 } |
176 | 178 |
177 void WindowTreeClient::ConnectViaWindowTreeFactory( | 179 void WindowTreeClient::ConnectViaWindowTreeFactory( |
178 service_manager::Connector* connector) { | 180 service_manager::Connector* connector) { |
179 // The client id doesn't really matter, we use 101 purely for debugging. | 181 // The client id doesn't really matter, we use 101 purely for debugging. |
180 client_id_ = 101; | 182 client_id_ = 101; |
181 | 183 |
182 ui::mojom::WindowTreeFactoryPtr factory; | 184 ui::mojom::WindowTreeFactoryPtr factory; |
183 connector->ConnectToInterface("service:ui", &factory); | 185 connector->ConnectToInterface("service:ui", &factory); |
184 ui::mojom::WindowTreePtr window_tree; | 186 ui::mojom::WindowTreePtr window_tree; |
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
283 return it != windows_.end() ? it->second : nullptr; | 285 return it != windows_.end() ? it->second : nullptr; |
284 } | 286 } |
285 | 287 |
286 bool WindowTreeClient::WasCreatedByThisClient(const WindowMus* window) const { | 288 bool WindowTreeClient::WasCreatedByThisClient(const WindowMus* window) const { |
287 // Windows created via CreateTopLevelWindow() are not owned by us, but have | 289 // Windows created via CreateTopLevelWindow() are not owned by us, but have |
288 // our client id. const_cast is required by set. | 290 // our client id. const_cast is required by set. |
289 return HiWord(window->server_id()) == client_id_ && | 291 return HiWord(window->server_id()) == client_id_ && |
290 roots_.count(const_cast<WindowMus*>(window)) == 0; | 292 roots_.count(const_cast<WindowMus*>(window)) == 0; |
291 } | 293 } |
292 | 294 |
| 295 void WindowTreeClient::SetFocusFromServer(WindowMus* window) { |
| 296 if (focused_window_ == window) |
| 297 return; |
| 298 |
| 299 if (window) { |
| 300 client::FocusClient* focus_client = |
| 301 client::GetFocusClient(window->GetWindow()); |
| 302 if (focus_client) { |
| 303 SetFocusFromServerImpl(focus_client, window); |
| 304 } else { |
| 305 SetFocusFromServerImpl( |
| 306 client::GetFocusClient(focused_window_->GetWindow()), nullptr); |
| 307 } |
| 308 } else { |
| 309 SetFocusFromServerImpl(client::GetFocusClient(focused_window_->GetWindow()), |
| 310 nullptr); |
| 311 } |
| 312 } |
| 313 |
| 314 void WindowTreeClient::SetFocusFromServerImpl(client::FocusClient* focus_client, |
| 315 WindowMus* window) { |
| 316 if (!focus_client) |
| 317 return; |
| 318 |
| 319 DCHECK(!setting_focus_); |
| 320 base::AutoReset<bool> focus_reset(&setting_focus_, true); |
| 321 base::AutoReset<WindowMus*> window_setting_focus_to_reset( |
| 322 &window_setting_focus_to_, window); |
| 323 focus_client->FocusWindow(window ? window->GetWindow() : nullptr); |
| 324 } |
| 325 |
293 InFlightChange* WindowTreeClient::GetOldestInFlightChangeMatching( | 326 InFlightChange* WindowTreeClient::GetOldestInFlightChangeMatching( |
294 const InFlightChange& change) { | 327 const InFlightChange& change) { |
295 for (const auto& pair : in_flight_map_) { | 328 for (const auto& pair : in_flight_map_) { |
296 if (pair.second->window() == change.window() && | 329 if (pair.second->window() == change.window() && |
297 pair.second->change_type() == change.change_type() && | 330 pair.second->change_type() == change.change_type() && |
298 pair.second->Matches(change)) { | 331 pair.second->Matches(change)) { |
299 return pair.second.get(); | 332 return pair.second.get(); |
300 } | 333 } |
301 } | 334 } |
302 return nullptr; | 335 return nullptr; |
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
410 } | 443 } |
411 } | 444 } |
412 | 445 |
413 void WindowTreeClient::WindowTreeConnectionEstablished( | 446 void WindowTreeClient::WindowTreeConnectionEstablished( |
414 ui::mojom::WindowTree* window_tree) { | 447 ui::mojom::WindowTree* window_tree) { |
415 tree_ = window_tree; | 448 tree_ = window_tree; |
416 | 449 |
417 drag_drop_controller_ = base::MakeUnique<DragDropControllerMus>(this, tree_); | 450 drag_drop_controller_ = base::MakeUnique<DragDropControllerMus>(this, tree_); |
418 capture_synchronizer_ = base::MakeUnique<CaptureSynchronizer>( | 451 capture_synchronizer_ = base::MakeUnique<CaptureSynchronizer>( |
419 this, tree_, delegate_->GetCaptureClient()); | 452 this, tree_, delegate_->GetCaptureClient()); |
420 focus_synchronizer_ = base::MakeUnique<FocusSynchronizer>(this, tree_); | |
421 } | 453 } |
422 | 454 |
423 void WindowTreeClient::OnConnectionLost() { | 455 void WindowTreeClient::OnConnectionLost() { |
424 delegate_->OnLostConnection(this); | 456 delegate_->OnLostConnection(this); |
425 } | 457 } |
426 | 458 |
427 bool WindowTreeClient::HandleInternalPropertyChanged(WindowMus* window, | 459 bool WindowTreeClient::HandleInternalPropertyChanged(WindowMus* window, |
428 const void* key) { | 460 const void* key) { |
429 if (key != client::kModalKey) | 461 if (key != client::kModalKey) |
430 return false; | 462 return false; |
(...skipping 21 matching lines...) Expand all Loading... |
452 bool drawn) { | 484 bool drawn) { |
453 // WARNING: this is only called if WindowTreeClient was created as the | 485 // WARNING: this is only called if WindowTreeClient was created as the |
454 // result of an embedding. | 486 // result of an embedding. |
455 client_id_ = client_id; | 487 client_id_ = client_id; |
456 WindowTreeConnectionEstablished(window_tree); | 488 WindowTreeConnectionEstablished(window_tree); |
457 | 489 |
458 DCHECK(roots_.empty()); | 490 DCHECK(roots_.empty()); |
459 std::unique_ptr<WindowTreeHostMus> window_tree_host = | 491 std::unique_ptr<WindowTreeHostMus> window_tree_host = |
460 CreateWindowTreeHost(WindowMusType::EMBED, root_data, display_id); | 492 CreateWindowTreeHost(WindowMusType::EMBED, root_data, display_id); |
461 | 493 |
462 focus_synchronizer_->SetFocusFromServer( | 494 SetFocusFromServer(GetWindowByServerId(focused_window_id)); |
463 GetWindowByServerId(focused_window_id)); | |
464 | 495 |
465 delegate_->OnEmbed(std::move(window_tree_host)); | 496 delegate_->OnEmbed(std::move(window_tree_host)); |
466 } | 497 } |
467 | 498 |
468 WindowTreeHost* WindowTreeClient::WmNewDisplayAddedImpl( | 499 WindowTreeHost* WindowTreeClient::WmNewDisplayAddedImpl( |
469 const display::Display& display, | 500 const display::Display& display, |
470 ui::mojom::WindowDataPtr root_data, | 501 ui::mojom::WindowDataPtr root_data, |
471 bool parent_drawn) { | 502 bool parent_drawn) { |
472 DCHECK(window_manager_delegate_); | 503 DCHECK(window_manager_delegate_); |
473 | 504 |
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
564 if (create_top_level) { | 595 if (create_top_level) { |
565 tree_->NewTopLevelWindow(change_id, window->server_id(), | 596 tree_->NewTopLevelWindow(change_id, window->server_id(), |
566 std::move(transport_properties)); | 597 std::move(transport_properties)); |
567 } else { | 598 } else { |
568 tree_->NewWindow(change_id, window->server_id(), | 599 tree_->NewWindow(change_id, window->server_id(), |
569 std::move(transport_properties)); | 600 std::move(transport_properties)); |
570 } | 601 } |
571 } | 602 } |
572 | 603 |
573 void WindowTreeClient::OnWindowMusDestroyed(WindowMus* window) { | 604 void WindowTreeClient::OnWindowMusDestroyed(WindowMus* window) { |
574 if (focus_synchronizer_->focused_window() == window) | 605 if (focused_window_ == window) |
575 focus_synchronizer_->OnFocusedWindowDestroyed(); | 606 focused_window_ = nullptr; |
576 | 607 |
577 // TODO: decide how to deal with windows not owned by this client. | 608 // TODO: decide how to deal with windows not owned by this client. |
578 if (WasCreatedByThisClient(window) || IsRoot(window)) { | 609 if (WasCreatedByThisClient(window) || IsRoot(window)) { |
579 const uint32_t change_id = | 610 const uint32_t change_id = |
580 ScheduleInFlightChange(base::MakeUnique<CrashInFlightChange>( | 611 ScheduleInFlightChange(base::MakeUnique<CrashInFlightChange>( |
581 window, ChangeType::DELETE_WINDOW)); | 612 window, ChangeType::DELETE_WINDOW)); |
582 tree_->DeleteWindow(change_id, window->server_id()); | 613 tree_->DeleteWindow(change_id, window->server_id()); |
583 } | 614 } |
584 | 615 |
585 windows_.erase(window->server_id()); | 616 windows_.erase(window->server_id()); |
(...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
735 //////////////////////////////////////////////////////////////////////////////// | 766 //////////////////////////////////////////////////////////////////////////////// |
736 // WindowTreeClient, WindowTreeClient implementation: | 767 // WindowTreeClient, WindowTreeClient implementation: |
737 | 768 |
738 std::set<Window*> WindowTreeClient::GetRoots() { | 769 std::set<Window*> WindowTreeClient::GetRoots() { |
739 std::set<Window*> roots; | 770 std::set<Window*> roots; |
740 for (WindowMus* window : roots_) | 771 for (WindowMus* window : roots_) |
741 roots.insert(window->GetWindow()); | 772 roots.insert(window->GetWindow()); |
742 return roots; | 773 return roots; |
743 } | 774 } |
744 | 775 |
| 776 Window* WindowTreeClient::GetFocusedWindow() { |
| 777 return focused_window_ ? focused_window_->GetWindow() : nullptr; |
| 778 } |
| 779 |
745 gfx::Point WindowTreeClient::GetCursorScreenPoint() { | 780 gfx::Point WindowTreeClient::GetCursorScreenPoint() { |
746 // We raced initialization. Return (0, 0). | 781 // We raced initialization. Return (0, 0). |
747 if (!cursor_location_memory()) | 782 if (!cursor_location_memory()) |
748 return gfx::Point(); | 783 return gfx::Point(); |
749 | 784 |
750 base::subtle::Atomic32 location = | 785 base::subtle::Atomic32 location = |
751 base::subtle::NoBarrier_Load(cursor_location_memory()); | 786 base::subtle::NoBarrier_Load(cursor_location_memory()); |
752 return gfx::Point(static_cast<int16_t>(location >> 16), | 787 return gfx::Point(static_cast<int16_t>(location >> 16), |
753 static_cast<int16_t>(location & 0xFFFF)); | 788 static_cast<int16_t>(location & 0xFFFF)); |
754 } | 789 } |
(...skipping 386 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1141 return; | 1176 return; |
1142 | 1177 |
1143 WindowMus* target_window = GetWindowByServerId(window_id); | 1178 WindowMus* target_window = GetWindowByServerId(window_id); |
1144 delegate_->OnPointerEventObserved( | 1179 delegate_->OnPointerEventObserved( |
1145 *event->AsPointerEvent(), | 1180 *event->AsPointerEvent(), |
1146 target_window ? target_window->GetWindow() : nullptr); | 1181 target_window ? target_window->GetWindow() : nullptr); |
1147 } | 1182 } |
1148 | 1183 |
1149 void WindowTreeClient::OnWindowFocused(Id focused_window_id) { | 1184 void WindowTreeClient::OnWindowFocused(Id focused_window_id) { |
1150 WindowMus* focused_window = GetWindowByServerId(focused_window_id); | 1185 WindowMus* focused_window = GetWindowByServerId(focused_window_id); |
1151 InFlightFocusChange new_change(this, focus_synchronizer_.get(), | 1186 InFlightFocusChange new_change(this, focused_window); |
1152 focused_window); | |
1153 if (ApplyServerChangeToExistingInFlightChange(new_change)) | 1187 if (ApplyServerChangeToExistingInFlightChange(new_change)) |
1154 return; | 1188 return; |
1155 | 1189 |
1156 focus_synchronizer_->SetFocusFromServer(focused_window); | 1190 SetFocusFromServer(focused_window); |
1157 } | 1191 } |
1158 | 1192 |
1159 void WindowTreeClient::OnWindowPredefinedCursorChanged( | 1193 void WindowTreeClient::OnWindowPredefinedCursorChanged( |
1160 Id window_id, | 1194 Id window_id, |
1161 ui::mojom::Cursor cursor) { | 1195 ui::mojom::Cursor cursor) { |
1162 WindowMus* window = GetWindowByServerId(window_id); | 1196 WindowMus* window = GetWindowByServerId(window_id); |
1163 if (!window) | 1197 if (!window) |
1164 return; | 1198 return; |
1165 | 1199 |
1166 InFlightPredefinedCursorChange new_change(window, cursor); | 1200 InFlightPredefinedCursorChange new_change(window, cursor); |
(...skipping 302 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1469 void WindowTreeClient::SetUnderlaySurfaceOffsetAndExtendedHitArea( | 1503 void WindowTreeClient::SetUnderlaySurfaceOffsetAndExtendedHitArea( |
1470 Window* window, | 1504 Window* window, |
1471 const gfx::Vector2d& offset, | 1505 const gfx::Vector2d& offset, |
1472 const gfx::Insets& hit_area) { | 1506 const gfx::Insets& hit_area) { |
1473 if (window_manager_internal_client_) { | 1507 if (window_manager_internal_client_) { |
1474 window_manager_internal_client_->SetUnderlaySurfaceOffsetAndExtendedHitArea( | 1508 window_manager_internal_client_->SetUnderlaySurfaceOffsetAndExtendedHitArea( |
1475 WindowMus::Get(window)->server_id(), offset.x(), offset.y(), hit_area); | 1509 WindowMus::Get(window)->server_id(), offset.x(), offset.y(), hit_area); |
1476 } | 1510 } |
1477 } | 1511 } |
1478 | 1512 |
| 1513 void WindowTreeClient::OnWindowFocused(Window* gained_focus, |
| 1514 Window* lost_focus) { |
| 1515 WindowMus* gained_focus_mus = WindowMus::Get(gained_focus); |
| 1516 if (setting_focus_ && gained_focus_mus == window_setting_focus_to_) { |
| 1517 focused_window_ = gained_focus_mus; |
| 1518 return; |
| 1519 } |
| 1520 |
| 1521 const uint32_t change_id = ScheduleInFlightChange( |
| 1522 base::MakeUnique<InFlightFocusChange>(this, focused_window_)); |
| 1523 focused_window_ = gained_focus_mus; |
| 1524 tree_->SetFocus(change_id, focused_window_ ? focused_window_->server_id() |
| 1525 : kInvalidServerId); |
| 1526 } |
| 1527 |
1479 void WindowTreeClient::OnWindowTreeHostBoundsWillChange( | 1528 void WindowTreeClient::OnWindowTreeHostBoundsWillChange( |
1480 WindowTreeHostMus* window_tree_host, | 1529 WindowTreeHostMus* window_tree_host, |
1481 const gfx::Rect& bounds) { | 1530 const gfx::Rect& bounds) { |
1482 ScheduleInFlightBoundsChange(WindowMus::Get(window_tree_host->window()), | 1531 ScheduleInFlightBoundsChange(WindowMus::Get(window_tree_host->window()), |
1483 window_tree_host->GetBounds(), bounds); | 1532 window_tree_host->GetBounds(), bounds); |
1484 } | 1533 } |
1485 | 1534 |
1486 std::unique_ptr<WindowPortMus> WindowTreeClient::CreateWindowPortForTopLevel() { | 1535 std::unique_ptr<WindowPortMus> WindowTreeClient::CreateWindowPortForTopLevel() { |
1487 std::unique_ptr<WindowPortMus> window_port = | 1536 std::unique_ptr<WindowPortMus> window_port = |
1488 base::MakeUnique<WindowPortMus>(this, WindowMusType::TOP_LEVEL); | 1537 base::MakeUnique<WindowPortMus>(this, WindowMusType::TOP_LEVEL); |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1532 uint32_t WindowTreeClient::CreateChangeIdForDrag(WindowMus* window) { | 1581 uint32_t WindowTreeClient::CreateChangeIdForDrag(WindowMus* window) { |
1533 return ScheduleInFlightChange( | 1582 return ScheduleInFlightChange( |
1534 base::MakeUnique<InFlightDragChange>(window, ChangeType::DRAG_LOOP)); | 1583 base::MakeUnique<InFlightDragChange>(window, ChangeType::DRAG_LOOP)); |
1535 } | 1584 } |
1536 | 1585 |
1537 uint32_t WindowTreeClient::CreateChangeIdForCapture(WindowMus* window) { | 1586 uint32_t WindowTreeClient::CreateChangeIdForCapture(WindowMus* window) { |
1538 return ScheduleInFlightChange(base::MakeUnique<InFlightCaptureChange>( | 1587 return ScheduleInFlightChange(base::MakeUnique<InFlightCaptureChange>( |
1539 this, capture_synchronizer_.get(), window)); | 1588 this, capture_synchronizer_.get(), window)); |
1540 } | 1589 } |
1541 | 1590 |
1542 uint32_t WindowTreeClient::CreateChangeIdForFocus(WindowMus* window) { | |
1543 return ScheduleInFlightChange(base::MakeUnique<InFlightFocusChange>( | |
1544 this, focus_synchronizer_.get(), window)); | |
1545 } | |
1546 | |
1547 } // namespace aura | 1591 } // namespace aura |
OLD | NEW |