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

Side by Side Diff: ui/aura/mus/window_tree_client.cc

Issue 2488723002: Reland of Improves focus/activation for aura-mus and DesktopNativeWidgetAura (Closed)
Patch Set: Created 4 years, 1 month 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 | « ui/aura/mus/window_tree_client.h ('k') | ui/aura/mus/window_tree_client_delegate.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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"
21 #include "ui/aura/client/transient_window_client.h" 20 #include "ui/aura/client/transient_window_client.h"
22 #include "ui/aura/mus/capture_synchronizer.h" 21 #include "ui/aura/mus/capture_synchronizer.h"
23 #include "ui/aura/mus/drag_drop_controller_mus.h" 22 #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
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);
139 client::GetTransientWindowClient()->AddObserver(this); 138 client::GetTransientWindowClient()->AddObserver(this);
140 if (window_manager_delegate) 139 if (window_manager_delegate)
141 window_manager_delegate->SetWindowManagerClient(this); 140 window_manager_delegate->SetWindowManagerClient(this);
142 } 141 }
143 142
144 WindowTreeClient::~WindowTreeClient() { 143 WindowTreeClient::~WindowTreeClient() {
145 in_destructor_ = true; 144 in_destructor_ = true;
146 145
147 for (WindowTreeClientObserver& observer : observers_) 146 for (WindowTreeClientObserver& observer : observers_)
148 observer.OnWillDestroyClient(this); 147 observer.OnWillDestroyClient(this);
(...skipping 17 matching lines...) Expand all
166 // other random windows that it doesn't own. 165 // other random windows that it doesn't own.
167 while (!tracker.windows().empty()) 166 while (!tracker.windows().empty())
168 delete tracker.windows().front(); 167 delete tracker.windows().front();
169 168
170 for (WindowTreeClientObserver& observer : observers_) 169 for (WindowTreeClientObserver& observer : observers_)
171 observer.OnDidDestroyClient(this); 170 observer.OnDidDestroyClient(this);
172 171
173 capture_synchronizer_.reset(); 172 capture_synchronizer_.reset();
174 173
175 client::GetTransientWindowClient()->RemoveObserver(this); 174 client::GetTransientWindowClient()->RemoveObserver(this);
176 delegate_->GetFocusClient()->RemoveObserver(this);
177 } 175 }
178 176
179 void WindowTreeClient::ConnectViaWindowTreeFactory( 177 void WindowTreeClient::ConnectViaWindowTreeFactory(
180 service_manager::Connector* connector) { 178 service_manager::Connector* connector) {
181 // The client id doesn't really matter, we use 101 purely for debugging. 179 // The client id doesn't really matter, we use 101 purely for debugging.
182 client_id_ = 101; 180 client_id_ = 101;
183 181
184 ui::mojom::WindowTreeFactoryPtr factory; 182 ui::mojom::WindowTreeFactoryPtr factory;
185 connector->ConnectToInterface("service:ui", &factory); 183 connector->ConnectToInterface("service:ui", &factory);
186 ui::mojom::WindowTreePtr window_tree; 184 ui::mojom::WindowTreePtr window_tree;
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after
285 return it != windows_.end() ? it->second : nullptr; 283 return it != windows_.end() ? it->second : nullptr;
286 } 284 }
287 285
288 bool WindowTreeClient::WasCreatedByThisClient(const WindowMus* window) const { 286 bool WindowTreeClient::WasCreatedByThisClient(const WindowMus* window) const {
289 // Windows created via CreateTopLevelWindow() are not owned by us, but have 287 // Windows created via CreateTopLevelWindow() are not owned by us, but have
290 // our client id. const_cast is required by set. 288 // our client id. const_cast is required by set.
291 return HiWord(window->server_id()) == client_id_ && 289 return HiWord(window->server_id()) == client_id_ &&
292 roots_.count(const_cast<WindowMus*>(window)) == 0; 290 roots_.count(const_cast<WindowMus*>(window)) == 0;
293 } 291 }
294 292
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
326 InFlightChange* WindowTreeClient::GetOldestInFlightChangeMatching( 293 InFlightChange* WindowTreeClient::GetOldestInFlightChangeMatching(
327 const InFlightChange& change) { 294 const InFlightChange& change) {
328 for (const auto& pair : in_flight_map_) { 295 for (const auto& pair : in_flight_map_) {
329 if (pair.second->window() == change.window() && 296 if (pair.second->window() == change.window() &&
330 pair.second->change_type() == change.change_type() && 297 pair.second->change_type() == change.change_type() &&
331 pair.second->Matches(change)) { 298 pair.second->Matches(change)) {
332 return pair.second.get(); 299 return pair.second.get();
333 } 300 }
334 } 301 }
335 return nullptr; 302 return nullptr;
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after
443 } 410 }
444 } 411 }
445 412
446 void WindowTreeClient::WindowTreeConnectionEstablished( 413 void WindowTreeClient::WindowTreeConnectionEstablished(
447 ui::mojom::WindowTree* window_tree) { 414 ui::mojom::WindowTree* window_tree) {
448 tree_ = window_tree; 415 tree_ = window_tree;
449 416
450 drag_drop_controller_ = base::MakeUnique<DragDropControllerMus>(this, tree_); 417 drag_drop_controller_ = base::MakeUnique<DragDropControllerMus>(this, tree_);
451 capture_synchronizer_ = base::MakeUnique<CaptureSynchronizer>( 418 capture_synchronizer_ = base::MakeUnique<CaptureSynchronizer>(
452 this, tree_, delegate_->GetCaptureClient()); 419 this, tree_, delegate_->GetCaptureClient());
420 focus_synchronizer_ = base::MakeUnique<FocusSynchronizer>(this, tree_);
453 } 421 }
454 422
455 void WindowTreeClient::OnConnectionLost() { 423 void WindowTreeClient::OnConnectionLost() {
456 delegate_->OnLostConnection(this); 424 delegate_->OnLostConnection(this);
457 } 425 }
458 426
459 bool WindowTreeClient::HandleInternalPropertyChanged(WindowMus* window, 427 bool WindowTreeClient::HandleInternalPropertyChanged(WindowMus* window,
460 const void* key) { 428 const void* key) {
461 if (key != client::kModalKey) 429 if (key != client::kModalKey)
462 return false; 430 return false;
(...skipping 21 matching lines...) Expand all
484 bool drawn) { 452 bool drawn) {
485 // WARNING: this is only called if WindowTreeClient was created as the 453 // WARNING: this is only called if WindowTreeClient was created as the
486 // result of an embedding. 454 // result of an embedding.
487 client_id_ = client_id; 455 client_id_ = client_id;
488 WindowTreeConnectionEstablished(window_tree); 456 WindowTreeConnectionEstablished(window_tree);
489 457
490 DCHECK(roots_.empty()); 458 DCHECK(roots_.empty());
491 std::unique_ptr<WindowTreeHostMus> window_tree_host = 459 std::unique_ptr<WindowTreeHostMus> window_tree_host =
492 CreateWindowTreeHost(WindowMusType::EMBED, root_data, display_id); 460 CreateWindowTreeHost(WindowMusType::EMBED, root_data, display_id);
493 461
494 SetFocusFromServer(GetWindowByServerId(focused_window_id)); 462 focus_synchronizer_->SetFocusFromServer(
463 GetWindowByServerId(focused_window_id));
495 464
496 delegate_->OnEmbed(std::move(window_tree_host)); 465 delegate_->OnEmbed(std::move(window_tree_host));
497 } 466 }
498 467
499 WindowTreeHost* WindowTreeClient::WmNewDisplayAddedImpl( 468 WindowTreeHost* WindowTreeClient::WmNewDisplayAddedImpl(
500 const display::Display& display, 469 const display::Display& display,
501 ui::mojom::WindowDataPtr root_data, 470 ui::mojom::WindowDataPtr root_data,
502 bool parent_drawn) { 471 bool parent_drawn) {
503 DCHECK(window_manager_delegate_); 472 DCHECK(window_manager_delegate_);
504 473
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after
595 if (create_top_level) { 564 if (create_top_level) {
596 tree_->NewTopLevelWindow(change_id, window->server_id(), 565 tree_->NewTopLevelWindow(change_id, window->server_id(),
597 std::move(transport_properties)); 566 std::move(transport_properties));
598 } else { 567 } else {
599 tree_->NewWindow(change_id, window->server_id(), 568 tree_->NewWindow(change_id, window->server_id(),
600 std::move(transport_properties)); 569 std::move(transport_properties));
601 } 570 }
602 } 571 }
603 572
604 void WindowTreeClient::OnWindowMusDestroyed(WindowMus* window) { 573 void WindowTreeClient::OnWindowMusDestroyed(WindowMus* window) {
605 if (focused_window_ == window) 574 if (focus_synchronizer_->focused_window() == window)
606 focused_window_ = nullptr; 575 focus_synchronizer_->OnFocusedWindowDestroyed();
607 576
608 // TODO: decide how to deal with windows not owned by this client. 577 // TODO: decide how to deal with windows not owned by this client.
609 if (WasCreatedByThisClient(window) || IsRoot(window)) { 578 if (WasCreatedByThisClient(window) || IsRoot(window)) {
610 const uint32_t change_id = 579 const uint32_t change_id =
611 ScheduleInFlightChange(base::MakeUnique<CrashInFlightChange>( 580 ScheduleInFlightChange(base::MakeUnique<CrashInFlightChange>(
612 window, ChangeType::DELETE_WINDOW)); 581 window, ChangeType::DELETE_WINDOW));
613 tree_->DeleteWindow(change_id, window->server_id()); 582 tree_->DeleteWindow(change_id, window->server_id());
614 } 583 }
615 584
616 windows_.erase(window->server_id()); 585 windows_.erase(window->server_id());
(...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after
766 //////////////////////////////////////////////////////////////////////////////// 735 ////////////////////////////////////////////////////////////////////////////////
767 // WindowTreeClient, WindowTreeClient implementation: 736 // WindowTreeClient, WindowTreeClient implementation:
768 737
769 std::set<Window*> WindowTreeClient::GetRoots() { 738 std::set<Window*> WindowTreeClient::GetRoots() {
770 std::set<Window*> roots; 739 std::set<Window*> roots;
771 for (WindowMus* window : roots_) 740 for (WindowMus* window : roots_)
772 roots.insert(window->GetWindow()); 741 roots.insert(window->GetWindow());
773 return roots; 742 return roots;
774 } 743 }
775 744
776 Window* WindowTreeClient::GetFocusedWindow() {
777 return focused_window_ ? focused_window_->GetWindow() : nullptr;
778 }
779
780 gfx::Point WindowTreeClient::GetCursorScreenPoint() { 745 gfx::Point WindowTreeClient::GetCursorScreenPoint() {
781 // We raced initialization. Return (0, 0). 746 // We raced initialization. Return (0, 0).
782 if (!cursor_location_memory()) 747 if (!cursor_location_memory())
783 return gfx::Point(); 748 return gfx::Point();
784 749
785 base::subtle::Atomic32 location = 750 base::subtle::Atomic32 location =
786 base::subtle::NoBarrier_Load(cursor_location_memory()); 751 base::subtle::NoBarrier_Load(cursor_location_memory());
787 return gfx::Point(static_cast<int16_t>(location >> 16), 752 return gfx::Point(static_cast<int16_t>(location >> 16),
788 static_cast<int16_t>(location & 0xFFFF)); 753 static_cast<int16_t>(location & 0xFFFF));
789 } 754 }
(...skipping 386 matching lines...) Expand 10 before | Expand all | Expand 10 after
1176 return; 1141 return;
1177 1142
1178 WindowMus* target_window = GetWindowByServerId(window_id); 1143 WindowMus* target_window = GetWindowByServerId(window_id);
1179 delegate_->OnPointerEventObserved( 1144 delegate_->OnPointerEventObserved(
1180 *event->AsPointerEvent(), 1145 *event->AsPointerEvent(),
1181 target_window ? target_window->GetWindow() : nullptr); 1146 target_window ? target_window->GetWindow() : nullptr);
1182 } 1147 }
1183 1148
1184 void WindowTreeClient::OnWindowFocused(Id focused_window_id) { 1149 void WindowTreeClient::OnWindowFocused(Id focused_window_id) {
1185 WindowMus* focused_window = GetWindowByServerId(focused_window_id); 1150 WindowMus* focused_window = GetWindowByServerId(focused_window_id);
1186 InFlightFocusChange new_change(this, focused_window); 1151 InFlightFocusChange new_change(this, focus_synchronizer_.get(),
1152 focused_window);
1187 if (ApplyServerChangeToExistingInFlightChange(new_change)) 1153 if (ApplyServerChangeToExistingInFlightChange(new_change))
1188 return; 1154 return;
1189 1155
1190 SetFocusFromServer(focused_window); 1156 focus_synchronizer_->SetFocusFromServer(focused_window);
1191 } 1157 }
1192 1158
1193 void WindowTreeClient::OnWindowPredefinedCursorChanged( 1159 void WindowTreeClient::OnWindowPredefinedCursorChanged(
1194 Id window_id, 1160 Id window_id,
1195 ui::mojom::Cursor cursor) { 1161 ui::mojom::Cursor cursor) {
1196 WindowMus* window = GetWindowByServerId(window_id); 1162 WindowMus* window = GetWindowByServerId(window_id);
1197 if (!window) 1163 if (!window)
1198 return; 1164 return;
1199 1165
1200 InFlightPredefinedCursorChange new_change(window, cursor); 1166 InFlightPredefinedCursorChange new_change(window, cursor);
(...skipping 302 matching lines...) Expand 10 before | Expand all | Expand 10 after
1503 void WindowTreeClient::SetUnderlaySurfaceOffsetAndExtendedHitArea( 1469 void WindowTreeClient::SetUnderlaySurfaceOffsetAndExtendedHitArea(
1504 Window* window, 1470 Window* window,
1505 const gfx::Vector2d& offset, 1471 const gfx::Vector2d& offset,
1506 const gfx::Insets& hit_area) { 1472 const gfx::Insets& hit_area) {
1507 if (window_manager_internal_client_) { 1473 if (window_manager_internal_client_) {
1508 window_manager_internal_client_->SetUnderlaySurfaceOffsetAndExtendedHitArea( 1474 window_manager_internal_client_->SetUnderlaySurfaceOffsetAndExtendedHitArea(
1509 WindowMus::Get(window)->server_id(), offset.x(), offset.y(), hit_area); 1475 WindowMus::Get(window)->server_id(), offset.x(), offset.y(), hit_area);
1510 } 1476 }
1511 } 1477 }
1512 1478
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
1528 void WindowTreeClient::OnWindowTreeHostBoundsWillChange( 1479 void WindowTreeClient::OnWindowTreeHostBoundsWillChange(
1529 WindowTreeHostMus* window_tree_host, 1480 WindowTreeHostMus* window_tree_host,
1530 const gfx::Rect& bounds) { 1481 const gfx::Rect& bounds) {
1531 ScheduleInFlightBoundsChange(WindowMus::Get(window_tree_host->window()), 1482 ScheduleInFlightBoundsChange(WindowMus::Get(window_tree_host->window()),
1532 window_tree_host->GetBounds(), bounds); 1483 window_tree_host->GetBounds(), bounds);
1533 } 1484 }
1534 1485
1535 std::unique_ptr<WindowPortMus> WindowTreeClient::CreateWindowPortForTopLevel() { 1486 std::unique_ptr<WindowPortMus> WindowTreeClient::CreateWindowPortForTopLevel() {
1536 std::unique_ptr<WindowPortMus> window_port = 1487 std::unique_ptr<WindowPortMus> window_port =
1537 base::MakeUnique<WindowPortMus>(this, WindowMusType::TOP_LEVEL); 1488 base::MakeUnique<WindowPortMus>(this, WindowMusType::TOP_LEVEL);
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
1581 uint32_t WindowTreeClient::CreateChangeIdForDrag(WindowMus* window) { 1532 uint32_t WindowTreeClient::CreateChangeIdForDrag(WindowMus* window) {
1582 return ScheduleInFlightChange( 1533 return ScheduleInFlightChange(
1583 base::MakeUnique<InFlightDragChange>(window, ChangeType::DRAG_LOOP)); 1534 base::MakeUnique<InFlightDragChange>(window, ChangeType::DRAG_LOOP));
1584 } 1535 }
1585 1536
1586 uint32_t WindowTreeClient::CreateChangeIdForCapture(WindowMus* window) { 1537 uint32_t WindowTreeClient::CreateChangeIdForCapture(WindowMus* window) {
1587 return ScheduleInFlightChange(base::MakeUnique<InFlightCaptureChange>( 1538 return ScheduleInFlightChange(base::MakeUnique<InFlightCaptureChange>(
1588 this, capture_synchronizer_.get(), window)); 1539 this, capture_synchronizer_.get(), window));
1589 } 1540 }
1590 1541
1542 uint32_t WindowTreeClient::CreateChangeIdForFocus(WindowMus* window) {
1543 return ScheduleInFlightChange(base::MakeUnique<InFlightFocusChange>(
1544 this, focus_synchronizer_.get(), window));
1545 }
1546
1591 } // namespace aura 1547 } // namespace aura
OLDNEW
« no previous file with comments | « ui/aura/mus/window_tree_client.h ('k') | ui/aura/mus/window_tree_client_delegate.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698