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

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

Issue 2456623002: Fixes to WindowTreeHostMus (Closed)
Patch Set: merge 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_unittest.cc » ('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>
(...skipping 14 matching lines...) Expand all
25 #include "ui/aura/mus/window_manager_delegate.h" 25 #include "ui/aura/mus/window_manager_delegate.h"
26 #include "ui/aura/mus/window_mus.h" 26 #include "ui/aura/mus/window_mus.h"
27 #include "ui/aura/mus/window_port_mus.h" 27 #include "ui/aura/mus/window_port_mus.h"
28 #include "ui/aura/mus/window_tree_client_delegate.h" 28 #include "ui/aura/mus/window_tree_client_delegate.h"
29 #include "ui/aura/mus/window_tree_client_observer.h" 29 #include "ui/aura/mus/window_tree_client_observer.h"
30 #include "ui/aura/mus/window_tree_host_mus.h" 30 #include "ui/aura/mus/window_tree_host_mus.h"
31 #include "ui/aura/window.h" 31 #include "ui/aura/window.h"
32 #include "ui/aura/window_delegate.h" 32 #include "ui/aura/window_delegate.h"
33 #include "ui/aura/window_tracker.h" 33 #include "ui/aura/window_tracker.h"
34 #include "ui/base/ui_base_types.h" 34 #include "ui/base/ui_base_types.h"
35 #include "ui/display/display.h"
36 #include "ui/display/screen.h"
35 #include "ui/events/event.h" 37 #include "ui/events/event.h"
36 #include "ui/gfx/geometry/insets.h" 38 #include "ui/gfx/geometry/insets.h"
37 #include "ui/gfx/geometry/size.h" 39 #include "ui/gfx/geometry/size.h"
38 40
39 #if defined(HiWord) 41 #if defined(HiWord)
40 #undef HiWord 42 #undef HiWord
41 #endif 43 #endif
42 #if defined(LoWord) 44 #if defined(LoWord)
43 #undef LoWord 45 #undef LoWord
44 #endif 46 #endif
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
109 } 111 }
110 } 112 }
111 113
112 private: 114 private:
113 std::unique_ptr<EventResultCallback> ack_callback_; 115 std::unique_ptr<EventResultCallback> ack_callback_;
114 bool handled_ = false; 116 bool handled_ = false;
115 117
116 DISALLOW_COPY_AND_ASSIGN(EventAckHandler); 118 DISALLOW_COPY_AND_ASSIGN(EventAckHandler);
117 }; 119 };
118 120
121 WindowTreeHostMus* GetWindowTreeHostMus(Window* window) {
122 return static_cast<WindowTreeHostMus*>(window->GetRootWindow()->GetHost());
123 }
124
125 WindowTreeHostMus* GetWindowTreeHostMus(WindowMus* window) {
126 return GetWindowTreeHostMus(window->GetWindow());
127 }
128
119 bool IsInternalProperty(const void* key) { 129 bool IsInternalProperty(const void* key) {
120 return key == client::kModalKey; 130 return key == client::kModalKey;
121 } 131 }
122 132
123 } // namespace 133 } // namespace
124 134
125 struct WindowTreeClient::CurrentDragState { 135 struct WindowTreeClient::CurrentDragState {
126 // The current change id of the current drag an drop ipc. 136 // The current change id of the current drag an drop ipc.
127 uint32_t change_id; 137 uint32_t change_id;
128 138
(...skipping 295 matching lines...) Expand 10 before | Expand all | Expand 10 after
424 if (pair.second.is_null()) { 434 if (pair.second.is_null()) {
425 window->SetPropertyFromServer(pair.first, nullptr); 435 window->SetPropertyFromServer(pair.first, nullptr);
426 } else { 436 } else {
427 std::vector<uint8_t> stl_value = pair.second.To<std::vector<uint8_t>>(); 437 std::vector<uint8_t> stl_value = pair.second.To<std::vector<uint8_t>>();
428 window->SetPropertyFromServer(pair.first, &stl_value); 438 window->SetPropertyFromServer(pair.first, &stl_value);
429 } 439 }
430 } 440 }
431 } 441 }
432 442
433 Window* WindowTreeClient::CreateWindowTreeHost( 443 Window* WindowTreeClient::CreateWindowTreeHost(
434 WindowTreeHostType type, 444 RootWindowType type,
435 const ui::mojom::WindowDataPtr& window_data, 445 const ui::mojom::WindowDataPtr& window_data,
446 int64_t display_id,
436 Window* content_window) { 447 Window* content_window) {
437 Window* user_window = nullptr; 448 Window* user_window = nullptr;
438 switch (type) { 449 switch (type) {
439 case WindowTreeHostType::DISPLAY: { 450 case RootWindowType::DISPLAY: {
440 DCHECK(!content_window); 451 DCHECK(!content_window);
441 WindowTreeHost* window_tree_host = 452 // See WindowTreeHostMus for details on ownership.
442 new WindowTreeHostMus(CreateWindowPortMus(window_data)); 453 WindowTreeHost* window_tree_host = new WindowTreeHostMus(
454 CreateWindowPortMus(window_data), this, type, display_id);
443 user_window = window_tree_host->window(); 455 user_window = window_tree_host->window();
444 break; 456 break;
445 } 457 }
446 case WindowTreeHostType::EMBED: { 458 case RootWindowType::EMBED: {
447 DCHECK(!content_window); 459 DCHECK(!content_window);
448 user_window = new Window(nullptr, CreateWindowPortMus(window_data)); 460 user_window = new Window(nullptr, CreateWindowPortMus(window_data));
449 user_window->Init(ui::LAYER_TEXTURED); 461 user_window->Init(ui::LAYER_TEXTURED);
450 new WindowTreeHostMus(nullptr, user_window); 462 // See WindowTreeHostMus for details on ownership.
463 new WindowTreeHostMus(base::MakeUnique<WindowPortMus>(this, false), this,
464 type, display_id, user_window);
451 break; 465 break;
452 } 466 }
453 case WindowTreeHostType::TOP_LEVEL: { 467 case RootWindowType::TOP_LEVEL: {
454 DCHECK(content_window); 468 DCHECK(content_window);
455 user_window = content_window; 469 user_window = content_window;
456 new WindowTreeHostMus(nullptr, user_window); 470 // See WindowTreeHostMus for details on ownership.
471 new WindowTreeHostMus(base::MakeUnique<WindowPortMus>(this, false), this,
472 type, display_id, user_window);
457 break; 473 break;
458 } 474 }
459 } 475 }
460 WindowMus* user_window_mus = WindowMus::Get(user_window); 476 WindowMus* user_window_mus = WindowMus::Get(user_window);
461 roots_.insert(user_window_mus); 477 roots_.insert(user_window_mus);
462 if (!window_data.is_null()) 478 if (!window_data.is_null())
463 SetLocalPropertiesFromServerProperties(user_window_mus, window_data); 479 SetLocalPropertiesFromServerProperties(user_window_mus, window_data);
464 return user_window; 480 return user_window;
465 } 481 }
466 482
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
528 ui::mojom::WindowDataPtr root_data, 544 ui::mojom::WindowDataPtr root_data,
529 int64_t display_id, 545 int64_t display_id,
530 Id focused_window_id, 546 Id focused_window_id,
531 bool drawn) { 547 bool drawn) {
532 // WARNING: this is only called if WindowTreeClient was created as the 548 // WARNING: this is only called if WindowTreeClient was created as the
533 // result of an embedding. 549 // result of an embedding.
534 tree_ = window_tree; 550 tree_ = window_tree;
535 client_id_ = client_id; 551 client_id_ = client_id;
536 552
537 DCHECK(roots_.empty()); 553 DCHECK(roots_.empty());
538 Window* root = 554 Window* root = CreateWindowTreeHost(RootWindowType::EMBED, root_data,
539 CreateWindowTreeHost(WindowTreeHostType::EMBED, root_data, nullptr); 555 display_id, nullptr);
540 // TODO: needs to deal with drawn and display_id. 556 // TODO: needs to deal with drawn and display_id.
541 557
542 SetFocusFromServer(GetWindowByServerId(focused_window_id)); 558 SetFocusFromServer(GetWindowByServerId(focused_window_id));
543 559
544 delegate_->OnEmbed(root); 560 delegate_->OnEmbed(root);
545 } 561 }
546 562
547 WindowTreeHost* WindowTreeClient::WmNewDisplayAddedImpl( 563 WindowTreeHost* WindowTreeClient::WmNewDisplayAddedImpl(
548 const display::Display& display, 564 const display::Display& display,
549 ui::mojom::WindowDataPtr root_data, 565 ui::mojom::WindowDataPtr root_data,
550 bool parent_drawn) { 566 bool parent_drawn) {
551 DCHECK(window_manager_delegate_); 567 DCHECK(window_manager_delegate_);
552 568
553 // TODO: need to deal with display_id and drawn. 569 // TODO: need to deal with display_id and drawn.
554 Window* root = 570 Window* root = CreateWindowTreeHost(RootWindowType::DISPLAY, root_data,
555 CreateWindowTreeHost(WindowTreeHostType::DISPLAY, root_data, nullptr); 571 display.id(), nullptr);
556 // WindowPrivate(root).LocalSetDisplay(display.id()); 572 // WindowPrivate(root).LocalSetDisplay(display.id());
557 // WindowPrivate(root).LocalSetParentDrawn(parent_drawn); 573 // WindowPrivate(root).LocalSetParentDrawn(parent_drawn);
558 574
559 window_manager_delegate_->OnWmNewDisplay(root, display); 575 window_manager_delegate_->OnWmNewDisplay(root, display);
560 return root->GetHost(); 576 return root->GetHost();
561 } 577 }
562 578
563 std::unique_ptr<EventResultCallback> 579 std::unique_ptr<EventResultCallback>
564 WindowTreeClient::CreateEventResultCallback(int32_t event_id) { 580 WindowTreeClient::CreateEventResultCallback(int32_t event_id) {
565 return base::MakeUnique<EventResultCallback>( 581 return base::MakeUnique<EventResultCallback>(
566 base::Bind(&ui::mojom::WindowTree::OnWindowInputEventAck, 582 base::Bind(&ui::mojom::WindowTree::OnWindowInputEventAck,
567 base::Unretained(tree_), event_id)); 583 base::Unretained(tree_), event_id));
568 } 584 }
569 585
570 void WindowTreeClient::OnReceivedCursorLocationMemory( 586 void WindowTreeClient::OnReceivedCursorLocationMemory(
571 mojo::ScopedSharedBufferHandle handle) { 587 mojo::ScopedSharedBufferHandle handle) {
572 cursor_location_mapping_ = handle->Map(sizeof(base::subtle::Atomic32)); 588 cursor_location_mapping_ = handle->Map(sizeof(base::subtle::Atomic32));
573 DCHECK(cursor_location_mapping_); 589 DCHECK(cursor_location_mapping_);
574 } 590 }
575 591
592 void WindowTreeClient::SetWindowBoundsFromServer(
593 WindowMus* window,
594 const gfx::Rect& revert_bounds) {
595 if (!IsRoot(window)) {
596 window->SetBoundsFromServer(revert_bounds);
597 return;
598 }
599
600 const gfx::Rect window_tree_host_bounds(gfx::Rect(revert_bounds.size()));
601 std::unique_ptr<WindowMusChangeData> data =
602 window->PrepareForServerBoundsChange(window_tree_host_bounds);
603 // We need the root window to always have an origin of 0x0 locally.
604 WindowTreeHostMus* window_tree_host = GetWindowTreeHostMus(window);
605 window_tree_host->set_origin_offset(revert_bounds.OffsetFromOrigin());
606 window_tree_host->SetBoundsFromServer(window_tree_host_bounds);
607 }
608
609 void WindowTreeClient::SetWindowVisibleFromServer(WindowMus* window,
610 bool visible) {
611 if (!IsRoot(window)) {
612 window->SetVisibleFromServer(visible);
613 return;
614 }
615
616 std::unique_ptr<WindowMusChangeData> data1 =
617 window->PrepareForServerVisibilityChange(visible);
618 WindowTreeHostMus* window_tree_host = GetWindowTreeHostMus(window);
619 if (visible)
620 window_tree_host->Show();
621 else
622 window_tree_host->Hide();
623 }
624
576 std::unique_ptr<WindowPortInitData> WindowTreeClient::OnWindowMusCreated( 625 std::unique_ptr<WindowPortInitData> WindowTreeClient::OnWindowMusCreated(
577 WindowMus* window) { 626 WindowMus* window) {
578 if (window->server_id() != 0) { 627 if (window->server_id() != 0 || !window->create_remote_window()) {
579 // This window was created by us and has an associated server window. 628 // This window was created by us, or should not have a window created on
629 // the server.
580 return nullptr; 630 return nullptr;
581 } 631 }
582 632
583 window->set_server_id(MakeTransportId(client_id_, next_window_id_++)); 633 window->set_server_id(MakeTransportId(client_id_, next_window_id_++));
584 RegisterWindowMus(window); 634 RegisterWindowMus(window);
585 635
586 const bool create_top_level = 636 const bool create_top_level =
587 !window_manager_delegate_ && 637 !window_manager_delegate_ &&
588 ShouldCreateTopLevel(window->GetWindow()->type()); 638 ShouldCreateTopLevel(window->GetWindow()->type());
589 639
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
624 674
625 void WindowTreeClient::OnWindowMusInitDone( 675 void WindowTreeClient::OnWindowMusInitDone(
626 WindowMus* window, 676 WindowMus* window,
627 std::unique_ptr<WindowPortInitData> init_data) { 677 std::unique_ptr<WindowPortInitData> init_data) {
628 if (!init_data) 678 if (!init_data)
629 return; 679 return;
630 680
631 // Delay creating the WindowTreeHost until after Init(), otherwise we trigger 681 // Delay creating the WindowTreeHost until after Init(), otherwise we trigger
632 // crashes in code that expects window parenting to happen after 682 // crashes in code that expects window parenting to happen after
633 // Env::NotifyWindowInitialized() is called. 683 // Env::NotifyWindowInitialized() is called.
634 CreateWindowTreeHost(WindowTreeHostType::TOP_LEVEL, nullptr, 684 //
685 // Use the primary display. We'll get the real display when created.
686 CreateWindowTreeHost(RootWindowType::TOP_LEVEL, nullptr,
687 display::Screen::GetScreen()->GetPrimaryDisplay().id(),
635 window->GetWindow()); 688 window->GetWindow());
636 } 689 }
637 690
638 void WindowTreeClient::OnWindowMusDestroyed(WindowMus* window) { 691 void WindowTreeClient::OnWindowMusDestroyed(WindowMus* window) {
639 if (focused_window_ == window) 692 if (focused_window_ == window)
640 focused_window_ = nullptr; 693 focused_window_ = nullptr;
641 694
642 // TODO: decide how to deal with windows not owned by this client. 695 // TODO: decide how to deal with windows not owned by this client.
643 if (WasCreatedByThisClient(window) || IsRoot(window)) { 696 if (WasCreatedByThisClient(window) || IsRoot(window)) {
644 const uint32_t change_id = 697 const uint32_t change_id =
(...skipping 23 matching lines...) Expand all
668 721
669 const bool was_root = roots_.erase(window) > 0; 722 const bool was_root = roots_.erase(window) > 0;
670 if (!in_destructor_ && was_root && roots_.empty() && is_from_embed_) 723 if (!in_destructor_ && was_root && roots_.empty() && is_from_embed_)
671 delegate_->OnEmbedRootDestroyed(window->GetWindow()); 724 delegate_->OnEmbedRootDestroyed(window->GetWindow());
672 } 725 }
673 726
674 void WindowTreeClient::OnWindowMusBoundsChanged(WindowMus* window, 727 void WindowTreeClient::OnWindowMusBoundsChanged(WindowMus* window,
675 const gfx::Rect& old_bounds, 728 const gfx::Rect& old_bounds,
676 const gfx::Rect& new_bounds) { 729 const gfx::Rect& new_bounds) {
677 const uint32_t change_id = ScheduleInFlightChange( 730 const uint32_t change_id = ScheduleInFlightChange(
678 base::MakeUnique<InFlightBoundsChange>(window, old_bounds)); 731 base::MakeUnique<InFlightBoundsChange>(this, window, old_bounds));
679 tree_->SetWindowBounds(change_id, window->server_id(), new_bounds); 732 gfx::Point origin(new_bounds.origin());
733 if (IsRoot(window)) {
734 // WindowTreeHostMus stores the true origin of root windows.
735 WindowTreeHostMus* window_tree_host = GetWindowTreeHostMus(window);
736 origin += window_tree_host->origin_offset();
737 }
738 tree_->SetWindowBounds(change_id, window->server_id(),
739 gfx::Rect(origin, new_bounds.size()));
680 } 740 }
681 741
682 void WindowTreeClient::OnWindowMusAddChild(WindowMus* parent, 742 void WindowTreeClient::OnWindowMusAddChild(WindowMus* parent,
683 WindowMus* child) { 743 WindowMus* child) {
684 // TODO: add checks to ensure this can work. 744 // TODO: add checks to ensure this can work.
685 const uint32_t change_id = ScheduleInFlightChange( 745 const uint32_t change_id = ScheduleInFlightChange(
686 base::MakeUnique<CrashInFlightChange>(parent, ChangeType::ADD_CHILD)); 746 base::MakeUnique<CrashInFlightChange>(parent, ChangeType::ADD_CHILD));
687 tree_->AddWindow(change_id, parent->server_id(), child->server_id()); 747 tree_->AddWindow(change_id, parent->server_id(), child->server_id());
688 } 748 }
689 749
(...skipping 25 matching lines...) Expand all
715 direction = ui::mojom::OrderDirection::ABOVE; 775 direction = ui::mojom::OrderDirection::ABOVE;
716 } 776 }
717 tree_->ReorderWindow(change_id, window->server_id(), 777 tree_->ReorderWindow(change_id, window->server_id(),
718 relative_window->server_id(), direction); 778 relative_window->server_id(), direction);
719 } 779 }
720 780
721 void WindowTreeClient::OnWindowMusSetVisible(WindowMus* window, bool visible) { 781 void WindowTreeClient::OnWindowMusSetVisible(WindowMus* window, bool visible) {
722 // TODO: add checks to ensure this can work. 782 // TODO: add checks to ensure this can work.
723 DCHECK(tree_); 783 DCHECK(tree_);
724 const uint32_t change_id = ScheduleInFlightChange( 784 const uint32_t change_id = ScheduleInFlightChange(
725 base::MakeUnique<InFlightVisibleChange>(window, !visible)); 785 base::MakeUnique<InFlightVisibleChange>(this, window, !visible));
726 tree_->SetWindowVisibility(change_id, window->server_id(), visible); 786 tree_->SetWindowVisibility(change_id, window->server_id(), visible);
727 } 787 }
728 788
729 std::unique_ptr<WindowPortPropertyData> 789 std::unique_ptr<WindowPortPropertyData>
730 WindowTreeClient::OnWindowMusWillChangeProperty(WindowMus* window, 790 WindowTreeClient::OnWindowMusWillChangeProperty(WindowMus* window,
731 const void* key) { 791 const void* key) {
732 if (IsInternalProperty(key)) 792 if (IsInternalProperty(key))
733 return nullptr; 793 return nullptr;
734 794
735 std::unique_ptr<WindowPortPropertyDataMus> data( 795 std::unique_ptr<WindowPortPropertyDataMus> data(
(...skipping 237 matching lines...) Expand 10 before | Expand all | Expand 10 after
973 // The window may have been destroyed locally before the server could finish 1033 // The window may have been destroyed locally before the server could finish
974 // creating the window, and before the server received the notification that 1034 // creating the window, and before the server received the notification that
975 // the window has been destroyed. 1035 // the window has been destroyed.
976 return; 1036 return;
977 } 1037 }
978 std::unique_ptr<InFlightChange> change(std::move(in_flight_map_[change_id])); 1038 std::unique_ptr<InFlightChange> change(std::move(in_flight_map_[change_id]));
979 in_flight_map_.erase(change_id); 1039 in_flight_map_.erase(change_id);
980 1040
981 WindowMus* window = change->window(); 1041 WindowMus* window = change->window();
982 1042
983 // TODO: parent drawn and display_id need to route to WindowTreeHost.
984 // Drawn state and display-id always come from the server (they can't be 1043 // Drawn state and display-id always come from the server (they can't be
985 // modified locally). 1044 // modified locally).
1045 GetWindowTreeHostMus(window)->set_display_id(display_id);
986 1046
987 // The default visibilty is false, we only need update visibility if it 1047 // The default visibilty is false, we only need update visibility if it
988 // differs from that. 1048 // differs from that.
989 if (data->visible) { 1049 if (data->visible) {
990 InFlightVisibleChange visible_change(window, data->visible); 1050 InFlightVisibleChange visible_change(this, window, data->visible);
991 InFlightChange* current_change = 1051 InFlightChange* current_change =
992 GetOldestInFlightChangeMatching(visible_change); 1052 GetOldestInFlightChangeMatching(visible_change);
993 if (current_change) 1053 if (current_change)
994 current_change->SetRevertValueFrom(visible_change); 1054 current_change->SetRevertValueFrom(visible_change);
995 else 1055 else
996 window->SetVisibleFromServer(true); 1056 SetWindowVisibleFromServer(window, true);
997 } 1057 }
998 1058
999 const gfx::Rect bounds(data->bounds); 1059 const gfx::Rect bounds(data->bounds);
1000 { 1060 {
1001 InFlightBoundsChange bounds_change(window, bounds); 1061 InFlightBoundsChange bounds_change(this, window, bounds);
1002 InFlightChange* current_change = 1062 InFlightChange* current_change =
1003 GetOldestInFlightChangeMatching(bounds_change); 1063 GetOldestInFlightChangeMatching(bounds_change);
1004 if (current_change) 1064 if (current_change)
1005 current_change->SetRevertValueFrom(bounds_change); 1065 current_change->SetRevertValueFrom(bounds_change);
1006 else if (window->GetWindow()->bounds() != bounds) 1066 else if (window->GetWindow()->bounds() != bounds)
1007 window->SetBoundsFromServer(bounds); 1067 SetWindowBoundsFromServer(window, bounds);
1008 } 1068 }
1009 1069
1010 // There is currently no API to bulk set properties, so we iterate over each 1070 // There is currently no API to bulk set properties, so we iterate over each
1011 // property individually. 1071 // property individually.
1012 std::map<std::string, std::vector<uint8_t>> properties = 1072 std::map<std::string, std::vector<uint8_t>> properties =
1013 data->properties.To<std::map<std::string, std::vector<uint8_t>>>(); 1073 data->properties.To<std::map<std::string, std::vector<uint8_t>>>();
1014 for (const auto& pair : properties) { 1074 for (const auto& pair : properties) {
1015 std::unique_ptr<std::vector<uint8_t>> revert_value( 1075 std::unique_ptr<std::vector<uint8_t>> revert_value(
1016 base::MakeUnique<std::vector<uint8_t>>(pair.second)); 1076 base::MakeUnique<std::vector<uint8_t>>(pair.second));
1017 InFlightPropertyChange property_change(window, pair.first, 1077 InFlightPropertyChange property_change(window, pair.first,
(...skipping 11 matching lines...) Expand all
1029 DCHECK_EQ(0u, data->parent_id); 1089 DCHECK_EQ(0u, data->parent_id);
1030 } 1090 }
1031 1091
1032 void WindowTreeClient::OnWindowBoundsChanged(Id window_id, 1092 void WindowTreeClient::OnWindowBoundsChanged(Id window_id,
1033 const gfx::Rect& old_bounds, 1093 const gfx::Rect& old_bounds,
1034 const gfx::Rect& new_bounds) { 1094 const gfx::Rect& new_bounds) {
1035 WindowMus* window = GetWindowByServerId(window_id); 1095 WindowMus* window = GetWindowByServerId(window_id);
1036 if (!window) 1096 if (!window)
1037 return; 1097 return;
1038 1098
1039 InFlightBoundsChange new_change(window, new_bounds); 1099 InFlightBoundsChange new_change(this, window, new_bounds);
1040 if (ApplyServerChangeToExistingInFlightChange(new_change)) 1100 if (ApplyServerChangeToExistingInFlightChange(new_change))
1041 return; 1101 return;
1042 1102
1043 window->SetBoundsFromServer(new_bounds); 1103 SetWindowBoundsFromServer(window, new_bounds);
1044 } 1104 }
1045 1105
1046 void WindowTreeClient::OnClientAreaChanged( 1106 void WindowTreeClient::OnClientAreaChanged(
1047 uint32_t window_id, 1107 uint32_t window_id,
1048 const gfx::Insets& new_client_area, 1108 const gfx::Insets& new_client_area,
1049 mojo::Array<gfx::Rect> new_additional_client_areas) { 1109 mojo::Array<gfx::Rect> new_additional_client_areas) {
1050 // TODO: client area. 1110 // TODO: client area.
1051 /* 1111 /*
1052 Window* window = GetWindowByServerId(window_id); 1112 Window* window = GetWindowByServerId(window_id);
1053 if (window) { 1113 if (window) {
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
1128 1188
1129 Window* WindowTreeClient::GetCaptureWindow() { 1189 Window* WindowTreeClient::GetCaptureWindow() {
1130 return capture_window_ ? capture_window_->GetWindow() : nullptr; 1190 return capture_window_ ? capture_window_->GetWindow() : nullptr;
1131 } 1191 }
1132 1192
1133 void WindowTreeClient::OnWindowVisibilityChanged(Id window_id, bool visible) { 1193 void WindowTreeClient::OnWindowVisibilityChanged(Id window_id, bool visible) {
1134 WindowMus* window = GetWindowByServerId(window_id); 1194 WindowMus* window = GetWindowByServerId(window_id);
1135 if (!window) 1195 if (!window)
1136 return; 1196 return;
1137 1197
1138 InFlightVisibleChange new_change(window, visible); 1198 InFlightVisibleChange new_change(this, window, visible);
1139 if (ApplyServerChangeToExistingInFlightChange(new_change)) 1199 if (ApplyServerChangeToExistingInFlightChange(new_change))
1140 return; 1200 return;
1141 1201
1142 window->SetVisibleFromServer(visible); 1202 SetWindowVisibleFromServer(window, visible);
1143 } 1203 }
1144 1204
1145 void WindowTreeClient::OnWindowOpacityChanged(Id window_id, 1205 void WindowTreeClient::OnWindowOpacityChanged(Id window_id,
1146 float old_opacity, 1206 float old_opacity,
1147 float new_opacity) { 1207 float new_opacity) {
1148 WindowMus* window = GetWindowByServerId(window_id); 1208 WindowMus* window = GetWindowByServerId(window_id);
1149 if (!window) 1209 if (!window)
1150 return; 1210 return;
1151 1211
1152 InFlightOpacityChange new_change(window, new_opacity); 1212 InFlightOpacityChange new_change(window, new_opacity);
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
1197 DCHECK(event); 1257 DCHECK(event);
1198 1258
1199 WindowMus* window = GetWindowByServerId(window_id); // May be null. 1259 WindowMus* window = GetWindowByServerId(window_id); // May be null.
1200 1260
1201 if (event->IsKeyEvent()) { 1261 if (event->IsKeyEvent()) {
1202 DCHECK(!matches_pointer_watcher); // PointerWatcher isn't for key events. 1262 DCHECK(!matches_pointer_watcher); // PointerWatcher isn't for key events.
1203 if (!window || !window->GetWindow()->GetHost()) { 1263 if (!window || !window->GetWindow()->GetHost()) {
1204 tree_->OnWindowInputEventAck(event_id, ui::mojom::EventResult::UNHANDLED); 1264 tree_->OnWindowInputEventAck(event_id, ui::mojom::EventResult::UNHANDLED);
1205 return; 1265 return;
1206 } 1266 }
1207 InputMethodMus* input_method = 1267 InputMethodMus* input_method = GetWindowTreeHostMus(window)->input_method();
1208 static_cast<WindowTreeHostMus*>(window->GetWindow()->GetHost())
1209 ->input_method();
1210 input_method->DispatchKeyEvent(event->AsKeyEvent(), 1268 input_method->DispatchKeyEvent(event->AsKeyEvent(),
1211 CreateEventResultCallback(event_id)); 1269 CreateEventResultCallback(event_id));
1212 return; 1270 return;
1213 } 1271 }
1214 1272
1215 if (matches_pointer_watcher && has_pointer_watcher_) { 1273 if (matches_pointer_watcher && has_pointer_watcher_) {
1216 DCHECK(event->IsPointerEvent()); 1274 DCHECK(event->IsPointerEvent());
1217 delegate_->OnPointerEventObserved(*event->AsPointerEvent(), 1275 delegate_->OnPointerEventObserved(*event->AsPointerEvent(),
1218 window ? window->GetWindow() : nullptr); 1276 window ? window->GetWindow() : nullptr);
1219 } 1277 }
1220 1278
1221 // TODO: deal with no window or host here. This could happen if during 1279 // TODO: deal with no window or host here. This could happen if during
1222 // dispatch a window is deleted or moved. In either case we still need to 1280 // dispatch a window is deleted or moved. In either case we still need to
1223 // dispatch. Most likely need the display id. 1281 // dispatch. Most likely need the display id.
1224 if (!window || !window->GetWindow()->GetHost()) { 1282 if (!window || !window->GetWindow()->GetHost()) {
1225 tree_->OnWindowInputEventAck(event_id, ui::mojom::EventResult::UNHANDLED); 1283 tree_->OnWindowInputEventAck(event_id, ui::mojom::EventResult::UNHANDLED);
1226 return; 1284 return;
1227 } 1285 }
1228 1286
1229 EventAckHandler ack_handler(CreateEventResultCallback(event_id)); 1287 EventAckHandler ack_handler(CreateEventResultCallback(event_id));
1230 WindowTreeHostMus* host = 1288 WindowTreeHostMus* host = GetWindowTreeHostMus(window);
1231 static_cast<WindowTreeHostMus*>(window->GetWindow()->GetHost());
1232 // TODO(moshayedi): crbug.com/617222. No need to convert to ui::MouseEvent or 1289 // TODO(moshayedi): crbug.com/617222. No need to convert to ui::MouseEvent or
1233 // ui::TouchEvent once we have proper support for pointer events. 1290 // ui::TouchEvent once we have proper support for pointer events.
1234 if (event->IsMousePointerEvent()) { 1291 if (event->IsMousePointerEvent()) {
1235 if (event->type() == ui::ET_POINTER_WHEEL_CHANGED) { 1292 if (event->type() == ui::ET_POINTER_WHEEL_CHANGED) {
1236 ui::MouseWheelEvent mapped_event(*event->AsPointerEvent()); 1293 ui::MouseWheelEvent mapped_event(*event->AsPointerEvent());
1237 host->SendEventToProcessor(&mapped_event); 1294 host->SendEventToProcessor(&mapped_event);
1238 } else { 1295 } else {
1239 ui::MouseEvent mapped_event(*event->AsPointerEvent()); 1296 ui::MouseEvent mapped_event(*event->AsPointerEvent());
1240 host->SendEventToProcessor(&mapped_event); 1297 host->SendEventToProcessor(&mapped_event);
1241 } 1298 }
(...skipping 437 matching lines...) Expand 10 before | Expand all | Expand 10 after
1679 const uint32_t change_id = ScheduleInFlightChange( 1736 const uint32_t change_id = ScheduleInFlightChange(
1680 base::MakeUnique<InFlightCaptureChange>(this, capture_window_)); 1737 base::MakeUnique<InFlightCaptureChange>(this, capture_window_));
1681 WindowMus* old_capture_window = capture_window_; 1738 WindowMus* old_capture_window = capture_window_;
1682 capture_window_ = gained_capture_mus; 1739 capture_window_ = gained_capture_mus;
1683 if (capture_window_) 1740 if (capture_window_)
1684 tree_->SetCapture(change_id, capture_window_->server_id()); 1741 tree_->SetCapture(change_id, capture_window_->server_id());
1685 else 1742 else
1686 tree_->ReleaseCapture(change_id, old_capture_window->server_id()); 1743 tree_->ReleaseCapture(change_id, old_capture_window->server_id());
1687 } 1744 }
1688 1745
1746 void WindowTreeClient::SetRootWindowBounds(Window* window, gfx::Rect* bounds) {
1747 WindowTreeHostMus* window_tree_host = GetWindowTreeHostMus(window);
1748 switch (window_tree_host->root_window_type()) {
1749 case RootWindowType::EMBED:
1750 NOTREACHED();
1751 return;
1752 case RootWindowType::TOP_LEVEL:
1753 // Top level requests are always in display coordinates.
1754 break;
1755 case RootWindowType::DISPLAY: {
1756 gfx::Point display_relative_origin(bounds->origin());
1757 display_relative_origin -=
1758 window_tree_host->GetDisplay().bounds().OffsetFromOrigin();
1759 bounds->set_origin(display_relative_origin);
1760 break;
1761 }
1762 }
1763 // We need the root window to always have an origin of 0x0 locally.
1764 window_tree_host->set_origin_offset(bounds->OffsetFromOrigin());
1765 bounds->set_origin(gfx::Point());
1766 }
1767
1689 } // namespace aura 1768 } // namespace aura
OLDNEW
« no previous file with comments | « ui/aura/mus/window_tree_client.h ('k') | ui/aura/mus/window_tree_client_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698