Chromium Code Reviews| 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> |
| (...skipping 13 matching lines...) Expand all Loading... | |
| 24 #include "ui/aura/mus/surface_id_handler.h" | 24 #include "ui/aura/mus/surface_id_handler.h" |
| 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/display/display.h" | |
| 35 #include "ui/display/screen.h" | |
| 34 #include "ui/events/event.h" | 36 #include "ui/events/event.h" |
| 35 #include "ui/gfx/geometry/insets.h" | 37 #include "ui/gfx/geometry/insets.h" |
| 36 #include "ui/gfx/geometry/size.h" | 38 #include "ui/gfx/geometry/size.h" |
| 37 | 39 |
| 38 #if defined(HiWord) | 40 #if defined(HiWord) |
| 39 #undef HiWord | 41 #undef HiWord |
| 40 #endif | 42 #endif |
| 41 #if defined(LoWord) | 43 #if defined(LoWord) |
| 42 #undef LoWord | 44 #undef LoWord |
| 43 #endif | 45 #endif |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 108 } | 110 } |
| 109 } | 111 } |
| 110 | 112 |
| 111 private: | 113 private: |
| 112 std::unique_ptr<EventResultCallback> ack_callback_; | 114 std::unique_ptr<EventResultCallback> ack_callback_; |
| 113 bool handled_ = false; | 115 bool handled_ = false; |
| 114 | 116 |
| 115 DISALLOW_COPY_AND_ASSIGN(EventAckHandler); | 117 DISALLOW_COPY_AND_ASSIGN(EventAckHandler); |
| 116 }; | 118 }; |
| 117 | 119 |
| 120 WindowTreeHostMus* GetWindowTreeHostMus(Window* window) { | |
| 121 return static_cast<WindowTreeHostMus*>(window->GetRootWindow()->GetHost()); | |
| 122 } | |
| 123 | |
| 124 WindowTreeHostMus* GetWindowTreeHostMus(WindowMus* window) { | |
| 125 return GetWindowTreeHostMus(window->GetWindow()); | |
| 126 } | |
| 127 | |
| 118 } // namespace | 128 } // namespace |
| 119 | 129 |
| 120 struct WindowTreeClient::CurrentDragState { | 130 struct WindowTreeClient::CurrentDragState { |
| 121 // The current change id of the current drag an drop ipc. | 131 // The current change id of the current drag an drop ipc. |
| 122 uint32_t change_id; | 132 uint32_t change_id; |
| 123 | 133 |
| 124 // The effect to return when we send our finish signal. | 134 // The effect to return when we send our finish signal. |
| 125 uint32_t completed_action; | 135 uint32_t completed_action; |
| 126 | 136 |
| 127 // Callback executed when a drag initiated by PerformDragDrop() is completed. | 137 // Callback executed when a drag initiated by PerformDragDrop() is completed. |
| (...skipping 291 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 419 if (pair.second.is_null()) { | 429 if (pair.second.is_null()) { |
| 420 window->SetPropertyFromServer(pair.first, nullptr); | 430 window->SetPropertyFromServer(pair.first, nullptr); |
| 421 } else { | 431 } else { |
| 422 std::vector<uint8_t> stl_value = pair.second.To<std::vector<uint8_t>>(); | 432 std::vector<uint8_t> stl_value = pair.second.To<std::vector<uint8_t>>(); |
| 423 window->SetPropertyFromServer(pair.first, &stl_value); | 433 window->SetPropertyFromServer(pair.first, &stl_value); |
| 424 } | 434 } |
| 425 } | 435 } |
| 426 } | 436 } |
| 427 | 437 |
| 428 Window* WindowTreeClient::CreateWindowTreeHost( | 438 Window* WindowTreeClient::CreateWindowTreeHost( |
| 429 WindowTreeHostType type, | 439 RootWindowType type, |
| 430 const ui::mojom::WindowDataPtr& window_data, | 440 const ui::mojom::WindowDataPtr& window_data, |
| 441 int64_t display_id, | |
| 431 Window* content_window) { | 442 Window* content_window) { |
| 432 Window* user_window = nullptr; | 443 Window* user_window = nullptr; |
| 433 switch (type) { | 444 switch (type) { |
| 434 case WindowTreeHostType::DISPLAY: { | 445 case RootWindowType::DISPLAY: { |
| 435 DCHECK(!content_window); | 446 DCHECK(!content_window); |
| 436 WindowTreeHost* window_tree_host = | 447 // See WindowTreeHostMus for details on ownership. |
| 437 new WindowTreeHostMus(CreateWindowPortMus(window_data)); | 448 WindowTreeHost* window_tree_host = new WindowTreeHostMus( |
| 449 CreateWindowPortMus(window_data), this, type, display_id); | |
| 438 user_window = window_tree_host->window(); | 450 user_window = window_tree_host->window(); |
| 439 break; | 451 break; |
| 440 } | 452 } |
| 441 case WindowTreeHostType::EMBED: { | 453 case RootWindowType::EMBED: { |
| 442 DCHECK(!content_window); | 454 DCHECK(!content_window); |
| 443 user_window = new Window(nullptr, CreateWindowPortMus(window_data)); | 455 user_window = new Window(nullptr, CreateWindowPortMus(window_data)); |
| 444 user_window->Init(ui::LAYER_TEXTURED); | 456 user_window->Init(ui::LAYER_TEXTURED); |
| 445 new WindowTreeHostMus(nullptr, user_window); | 457 // See WindowTreeHostMus for details on ownership. |
| 458 new WindowTreeHostMus(nullptr, this, type, display_id, user_window); | |
| 446 break; | 459 break; |
| 447 } | 460 } |
| 448 case WindowTreeHostType::TOP_LEVEL: { | 461 case RootWindowType::TOP_LEVEL: { |
| 449 DCHECK(content_window); | 462 DCHECK(content_window); |
| 450 user_window = content_window; | 463 user_window = content_window; |
| 451 new WindowTreeHostMus(nullptr, user_window); | 464 // See WindowTreeHostMus for details on ownership. |
| 465 new WindowTreeHostMus(nullptr, this, type, display_id, user_window); | |
| 452 break; | 466 break; |
| 453 } | 467 } |
| 454 } | 468 } |
| 455 WindowMus* user_window_mus = WindowMus::Get(user_window); | 469 WindowMus* user_window_mus = WindowMus::Get(user_window); |
| 456 roots_.insert(user_window_mus); | 470 roots_.insert(user_window_mus); |
| 457 if (!window_data.is_null()) | 471 if (!window_data.is_null()) |
| 458 SetLocalPropertiesFromServerProperties(user_window_mus, window_data); | 472 SetLocalPropertiesFromServerProperties(user_window_mus, window_data); |
| 459 return user_window; | 473 return user_window; |
| 460 } | 474 } |
| 461 | 475 |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 503 ui::mojom::WindowDataPtr root_data, | 517 ui::mojom::WindowDataPtr root_data, |
| 504 int64_t display_id, | 518 int64_t display_id, |
| 505 Id focused_window_id, | 519 Id focused_window_id, |
| 506 bool drawn) { | 520 bool drawn) { |
| 507 // WARNING: this is only called if WindowTreeClient was created as the | 521 // WARNING: this is only called if WindowTreeClient was created as the |
| 508 // result of an embedding. | 522 // result of an embedding. |
| 509 tree_ = window_tree; | 523 tree_ = window_tree; |
| 510 client_id_ = client_id; | 524 client_id_ = client_id; |
| 511 | 525 |
| 512 DCHECK(roots_.empty()); | 526 DCHECK(roots_.empty()); |
| 513 Window* root = | 527 Window* root = CreateWindowTreeHost(RootWindowType::EMBED, root_data, |
| 514 CreateWindowTreeHost(WindowTreeHostType::EMBED, root_data, nullptr); | 528 display_id, nullptr); |
| 515 // TODO: needs to deal with drawn and display_id. | 529 // TODO: needs to deal with drawn and display_id. |
| 516 | 530 |
| 517 SetFocusFromServer(GetWindowByServerId(focused_window_id)); | 531 SetFocusFromServer(GetWindowByServerId(focused_window_id)); |
| 518 | 532 |
| 519 delegate_->OnEmbed(root); | 533 delegate_->OnEmbed(root); |
| 520 } | 534 } |
| 521 | 535 |
| 522 WindowTreeHost* WindowTreeClient::WmNewDisplayAddedImpl( | 536 WindowTreeHost* WindowTreeClient::WmNewDisplayAddedImpl( |
| 523 const display::Display& display, | 537 const display::Display& display, |
| 524 ui::mojom::WindowDataPtr root_data, | 538 ui::mojom::WindowDataPtr root_data, |
| 525 bool parent_drawn) { | 539 bool parent_drawn) { |
| 526 DCHECK(window_manager_delegate_); | 540 DCHECK(window_manager_delegate_); |
| 527 | 541 |
| 528 // TODO: need to deal with display_id and drawn. | 542 // TODO: need to deal with display_id and drawn. |
| 529 Window* root = | 543 Window* root = CreateWindowTreeHost(RootWindowType::DISPLAY, root_data, |
| 530 CreateWindowTreeHost(WindowTreeHostType::DISPLAY, root_data, nullptr); | 544 display.id(), nullptr); |
| 531 // WindowPrivate(root).LocalSetDisplay(display.id()); | 545 // WindowPrivate(root).LocalSetDisplay(display.id()); |
| 532 // WindowPrivate(root).LocalSetParentDrawn(parent_drawn); | 546 // WindowPrivate(root).LocalSetParentDrawn(parent_drawn); |
| 533 | 547 |
| 534 window_manager_delegate_->OnWmNewDisplay(root, display); | 548 window_manager_delegate_->OnWmNewDisplay(root, display); |
| 535 return root->GetHost(); | 549 return root->GetHost(); |
| 536 } | 550 } |
| 537 | 551 |
| 538 std::unique_ptr<EventResultCallback> | 552 std::unique_ptr<EventResultCallback> |
| 539 WindowTreeClient::CreateEventResultCallback(int32_t event_id) { | 553 WindowTreeClient::CreateEventResultCallback(int32_t event_id) { |
| 540 return base::MakeUnique<EventResultCallback>( | 554 return base::MakeUnique<EventResultCallback>( |
| 541 base::Bind(&ui::mojom::WindowTree::OnWindowInputEventAck, | 555 base::Bind(&ui::mojom::WindowTree::OnWindowInputEventAck, |
| 542 base::Unretained(tree_), event_id)); | 556 base::Unretained(tree_), event_id)); |
| 543 } | 557 } |
| 544 | 558 |
| 545 void WindowTreeClient::OnReceivedCursorLocationMemory( | 559 void WindowTreeClient::OnReceivedCursorLocationMemory( |
| 546 mojo::ScopedSharedBufferHandle handle) { | 560 mojo::ScopedSharedBufferHandle handle) { |
| 547 cursor_location_mapping_ = handle->Map(sizeof(base::subtle::Atomic32)); | 561 cursor_location_mapping_ = handle->Map(sizeof(base::subtle::Atomic32)); |
| 548 DCHECK(cursor_location_mapping_); | 562 DCHECK(cursor_location_mapping_); |
| 549 } | 563 } |
| 550 | 564 |
| 565 void WindowTreeClient::SetWindowBoundsFromServer( | |
| 566 WindowMus* window, | |
| 567 const gfx::Rect& revert_bounds) { | |
| 568 if (!IsRoot(window)) { | |
| 569 window->SetBoundsFromServer(revert_bounds); | |
| 570 return; | |
| 571 } | |
| 572 | |
| 573 const gfx::Rect window_tree_host_bounds(gfx::Rect(revert_bounds.size())); | |
| 574 std::unique_ptr<WindowMusChangeData> data = | |
| 575 window->PrepareForServerBoundsChange(window_tree_host_bounds); | |
|
sadrul
2016/10/27 20:26:17
This is really complex!
sky
2016/10/27 22:15:04
Indeed. If you have better ideas I'm all for it.
| |
| 576 // We need the root window to always have an origin of 0x0 locally. | |
| 577 WindowTreeHostMus* window_tree_host = GetWindowTreeHostMus(window); | |
| 578 window_tree_host->set_origin_offset(revert_bounds.OffsetFromOrigin()); | |
| 579 window_tree_host->SetBoundsFromServer(window_tree_host_bounds); | |
| 580 } | |
| 581 | |
| 582 void WindowTreeClient::SetWindowVisibleFromServer(WindowMus* window, | |
| 583 bool visible) { | |
| 584 if (!IsRoot(window)) { | |
| 585 window->SetVisibleFromServer(visible); | |
| 586 return; | |
| 587 } | |
| 588 | |
| 589 WindowTreeHostMus* window_tree_host = GetWindowTreeHostMus(window); | |
| 590 if (visible) | |
| 591 window_tree_host->Show(); | |
| 592 else | |
| 593 window_tree_host->Hide(); | |
| 594 } | |
| 595 | |
| 551 std::unique_ptr<WindowPortInitData> WindowTreeClient::OnWindowMusCreated( | 596 std::unique_ptr<WindowPortInitData> WindowTreeClient::OnWindowMusCreated( |
| 552 WindowMus* window) { | 597 WindowMus* window) { |
| 553 if (window->server_id() != 0) { | 598 if (window->server_id() != 0) { |
| 554 // This window was created by us and has an associated server window. | 599 // This window was created by us and has an associated server window. |
| 555 return nullptr; | 600 return nullptr; |
| 556 } | 601 } |
| 557 | 602 |
| 558 window->set_server_id(MakeTransportId(client_id_, next_window_id_++)); | 603 window->set_server_id(MakeTransportId(client_id_, next_window_id_++)); |
| 559 RegisterWindowMus(window); | 604 RegisterWindowMus(window); |
| 560 | 605 |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 599 | 644 |
| 600 void WindowTreeClient::OnWindowMusInitDone( | 645 void WindowTreeClient::OnWindowMusInitDone( |
| 601 WindowMus* window, | 646 WindowMus* window, |
| 602 std::unique_ptr<WindowPortInitData> init_data) { | 647 std::unique_ptr<WindowPortInitData> init_data) { |
| 603 if (!init_data) | 648 if (!init_data) |
| 604 return; | 649 return; |
| 605 | 650 |
| 606 // Delay creating the WindowTreeHost until after Init(), otherwise we trigger | 651 // Delay creating the WindowTreeHost until after Init(), otherwise we trigger |
| 607 // crashes in code that expects window parenting to happen after | 652 // crashes in code that expects window parenting to happen after |
| 608 // Env::NotifyWindowInitialized() is called. | 653 // Env::NotifyWindowInitialized() is called. |
| 609 CreateWindowTreeHost(WindowTreeHostType::TOP_LEVEL, nullptr, | 654 // |
| 655 // Use the primary display. We'll get the real display when created. | |
| 656 CreateWindowTreeHost(RootWindowType::TOP_LEVEL, nullptr, | |
| 657 display::Screen::GetScreen()->GetPrimaryDisplay().id(), | |
| 610 window->GetWindow()); | 658 window->GetWindow()); |
| 611 } | 659 } |
| 612 | 660 |
| 613 void WindowTreeClient::OnWindowMusDestroyed(WindowMus* window) { | 661 void WindowTreeClient::OnWindowMusDestroyed(WindowMus* window) { |
| 614 if (focused_window_ == window) | 662 if (focused_window_ == window) |
| 615 focused_window_ = nullptr; | 663 focused_window_ = nullptr; |
| 616 | 664 |
| 617 // TODO: decide how to deal with windows not owned by this client. | 665 // TODO: decide how to deal with windows not owned by this client. |
| 618 if (WasCreatedByThisClient(window) || IsRoot(window)) { | 666 if (WasCreatedByThisClient(window) || IsRoot(window)) { |
| 619 const uint32_t change_id = | 667 const uint32_t change_id = |
| (...skipping 23 matching lines...) Expand all Loading... | |
| 643 | 691 |
| 644 const bool was_root = roots_.erase(window) > 0; | 692 const bool was_root = roots_.erase(window) > 0; |
| 645 if (!in_destructor_ && was_root && roots_.empty() && is_from_embed_) | 693 if (!in_destructor_ && was_root && roots_.empty() && is_from_embed_) |
| 646 delegate_->OnEmbedRootDestroyed(window->GetWindow()); | 694 delegate_->OnEmbedRootDestroyed(window->GetWindow()); |
| 647 } | 695 } |
| 648 | 696 |
| 649 void WindowTreeClient::OnWindowMusBoundsChanged(WindowMus* window, | 697 void WindowTreeClient::OnWindowMusBoundsChanged(WindowMus* window, |
| 650 const gfx::Rect& old_bounds, | 698 const gfx::Rect& old_bounds, |
| 651 const gfx::Rect& new_bounds) { | 699 const gfx::Rect& new_bounds) { |
| 652 const uint32_t change_id = ScheduleInFlightChange( | 700 const uint32_t change_id = ScheduleInFlightChange( |
| 653 base::MakeUnique<InFlightBoundsChange>(window, old_bounds)); | 701 base::MakeUnique<InFlightBoundsChange>(this, window, old_bounds)); |
| 654 tree_->SetWindowBounds(change_id, window->server_id(), new_bounds); | 702 gfx::Point origin(new_bounds.origin()); |
| 703 if (IsRoot(window)) { | |
| 704 // WindowTreeHostMus stores the true origin of root windows. | |
| 705 WindowTreeHostMus* window_tree_host = GetWindowTreeHostMus(window); | |
| 706 origin += window_tree_host->origin_offset(); | |
| 707 } | |
| 708 tree_->SetWindowBounds(change_id, window->server_id(), | |
| 709 gfx::Rect(origin, new_bounds.size())); | |
| 655 } | 710 } |
| 656 | 711 |
| 657 void WindowTreeClient::OnWindowMusAddChild(WindowMus* parent, | 712 void WindowTreeClient::OnWindowMusAddChild(WindowMus* parent, |
| 658 WindowMus* child) { | 713 WindowMus* child) { |
| 659 // TODO: add checks to ensure this can work. | 714 // TODO: add checks to ensure this can work. |
| 660 const uint32_t change_id = ScheduleInFlightChange( | 715 const uint32_t change_id = ScheduleInFlightChange( |
| 661 base::MakeUnique<CrashInFlightChange>(parent, ChangeType::ADD_CHILD)); | 716 base::MakeUnique<CrashInFlightChange>(parent, ChangeType::ADD_CHILD)); |
| 662 tree_->AddWindow(change_id, parent->server_id(), child->server_id()); | 717 tree_->AddWindow(change_id, parent->server_id(), child->server_id()); |
| 663 } | 718 } |
| 664 | 719 |
| (...skipping 25 matching lines...) Expand all Loading... | |
| 690 direction = ui::mojom::OrderDirection::ABOVE; | 745 direction = ui::mojom::OrderDirection::ABOVE; |
| 691 } | 746 } |
| 692 tree_->ReorderWindow(change_id, window->server_id(), | 747 tree_->ReorderWindow(change_id, window->server_id(), |
| 693 relative_window->server_id(), direction); | 748 relative_window->server_id(), direction); |
| 694 } | 749 } |
| 695 | 750 |
| 696 void WindowTreeClient::OnWindowMusSetVisible(WindowMus* window, bool visible) { | 751 void WindowTreeClient::OnWindowMusSetVisible(WindowMus* window, bool visible) { |
| 697 // TODO: add checks to ensure this can work. | 752 // TODO: add checks to ensure this can work. |
| 698 DCHECK(tree_); | 753 DCHECK(tree_); |
| 699 const uint32_t change_id = ScheduleInFlightChange( | 754 const uint32_t change_id = ScheduleInFlightChange( |
| 700 base::MakeUnique<InFlightVisibleChange>(window, !visible)); | 755 base::MakeUnique<InFlightVisibleChange>(this, window, !visible)); |
| 701 tree_->SetWindowVisibility(change_id, window->server_id(), visible); | 756 tree_->SetWindowVisibility(change_id, window->server_id(), visible); |
| 702 } | 757 } |
| 703 | 758 |
| 704 std::unique_ptr<WindowPortPropertyData> | 759 std::unique_ptr<WindowPortPropertyData> |
| 705 WindowTreeClient::OnWindowMusWillChangeProperty(WindowMus* window, | 760 WindowTreeClient::OnWindowMusWillChangeProperty(WindowMus* window, |
| 706 const void* key) { | 761 const void* key) { |
| 707 std::unique_ptr<WindowPortPropertyDataMus> data( | 762 std::unique_ptr<WindowPortPropertyDataMus> data( |
| 708 base::MakeUnique<WindowPortPropertyDataMus>()); | 763 base::MakeUnique<WindowPortPropertyDataMus>()); |
| 709 if (!delegate_->GetPropertyConverter()->ConvertPropertyForTransport( | 764 if (!delegate_->GetPropertyConverter()->ConvertPropertyForTransport( |
| 710 window->GetWindow(), key, &data->transport_name, | 765 window->GetWindow(), key, &data->transport_name, |
| (...skipping 233 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 944 // The window may have been destroyed locally before the server could finish | 999 // The window may have been destroyed locally before the server could finish |
| 945 // creating the window, and before the server received the notification that | 1000 // creating the window, and before the server received the notification that |
| 946 // the window has been destroyed. | 1001 // the window has been destroyed. |
| 947 return; | 1002 return; |
| 948 } | 1003 } |
| 949 std::unique_ptr<InFlightChange> change(std::move(in_flight_map_[change_id])); | 1004 std::unique_ptr<InFlightChange> change(std::move(in_flight_map_[change_id])); |
| 950 in_flight_map_.erase(change_id); | 1005 in_flight_map_.erase(change_id); |
| 951 | 1006 |
| 952 WindowMus* window = change->window(); | 1007 WindowMus* window = change->window(); |
| 953 | 1008 |
| 954 // TODO: parent drawn and display_id need to route to WindowTreeHost. | |
| 955 // Drawn state and display-id always come from the server (they can't be | 1009 // Drawn state and display-id always come from the server (they can't be |
| 956 // modified locally). | 1010 // modified locally). |
| 1011 GetWindowTreeHostMus(window)->set_display_id(display_id); | |
| 957 | 1012 |
| 958 // The default visibilty is false, we only need update visibility if it | 1013 // The default visibilty is false, we only need update visibility if it |
| 959 // differs from that. | 1014 // differs from that. |
| 960 if (data->visible) { | 1015 if (data->visible) { |
| 961 InFlightVisibleChange visible_change(window, data->visible); | 1016 InFlightVisibleChange visible_change(this, window, data->visible); |
| 962 InFlightChange* current_change = | 1017 InFlightChange* current_change = |
| 963 GetOldestInFlightChangeMatching(visible_change); | 1018 GetOldestInFlightChangeMatching(visible_change); |
| 964 if (current_change) | 1019 if (current_change) |
| 965 current_change->SetRevertValueFrom(visible_change); | 1020 current_change->SetRevertValueFrom(visible_change); |
| 966 else | 1021 else |
| 967 window->SetVisibleFromServer(true); | 1022 SetWindowVisibleFromServer(window, true); |
| 968 } | 1023 } |
| 969 | 1024 |
| 970 const gfx::Rect bounds(data->bounds); | 1025 const gfx::Rect bounds(data->bounds); |
| 971 { | 1026 { |
| 972 InFlightBoundsChange bounds_change(window, bounds); | 1027 InFlightBoundsChange bounds_change(this, window, bounds); |
| 973 InFlightChange* current_change = | 1028 InFlightChange* current_change = |
| 974 GetOldestInFlightChangeMatching(bounds_change); | 1029 GetOldestInFlightChangeMatching(bounds_change); |
| 975 if (current_change) | 1030 if (current_change) |
| 976 current_change->SetRevertValueFrom(bounds_change); | 1031 current_change->SetRevertValueFrom(bounds_change); |
| 977 else if (window->GetWindow()->bounds() != bounds) | 1032 else if (window->GetWindow()->bounds() != bounds) |
| 978 window->SetBoundsFromServer(bounds); | 1033 SetWindowBoundsFromServer(window, bounds); |
| 979 } | 1034 } |
| 980 | 1035 |
| 981 // There is currently no API to bulk set properties, so we iterate over each | 1036 // There is currently no API to bulk set properties, so we iterate over each |
| 982 // property individually. | 1037 // property individually. |
| 983 std::map<std::string, std::vector<uint8_t>> properties = | 1038 std::map<std::string, std::vector<uint8_t>> properties = |
| 984 data->properties.To<std::map<std::string, std::vector<uint8_t>>>(); | 1039 data->properties.To<std::map<std::string, std::vector<uint8_t>>>(); |
| 985 for (const auto& pair : properties) { | 1040 for (const auto& pair : properties) { |
| 986 std::unique_ptr<std::vector<uint8_t>> revert_value( | 1041 std::unique_ptr<std::vector<uint8_t>> revert_value( |
| 987 base::MakeUnique<std::vector<uint8_t>>(pair.second)); | 1042 base::MakeUnique<std::vector<uint8_t>>(pair.second)); |
| 988 InFlightPropertyChange property_change(window, pair.first, | 1043 InFlightPropertyChange property_change(window, pair.first, |
| (...skipping 11 matching lines...) Expand all Loading... | |
| 1000 DCHECK_EQ(0u, data->parent_id); | 1055 DCHECK_EQ(0u, data->parent_id); |
| 1001 } | 1056 } |
| 1002 | 1057 |
| 1003 void WindowTreeClient::OnWindowBoundsChanged(Id window_id, | 1058 void WindowTreeClient::OnWindowBoundsChanged(Id window_id, |
| 1004 const gfx::Rect& old_bounds, | 1059 const gfx::Rect& old_bounds, |
| 1005 const gfx::Rect& new_bounds) { | 1060 const gfx::Rect& new_bounds) { |
| 1006 WindowMus* window = GetWindowByServerId(window_id); | 1061 WindowMus* window = GetWindowByServerId(window_id); |
| 1007 if (!window) | 1062 if (!window) |
| 1008 return; | 1063 return; |
| 1009 | 1064 |
| 1010 InFlightBoundsChange new_change(window, new_bounds); | 1065 InFlightBoundsChange new_change(this, window, new_bounds); |
| 1011 if (ApplyServerChangeToExistingInFlightChange(new_change)) | 1066 if (ApplyServerChangeToExistingInFlightChange(new_change)) |
| 1012 return; | 1067 return; |
| 1013 | 1068 |
| 1014 window->SetBoundsFromServer(new_bounds); | 1069 SetWindowBoundsFromServer(window, new_bounds); |
| 1015 } | 1070 } |
| 1016 | 1071 |
| 1017 void WindowTreeClient::OnClientAreaChanged( | 1072 void WindowTreeClient::OnClientAreaChanged( |
| 1018 uint32_t window_id, | 1073 uint32_t window_id, |
| 1019 const gfx::Insets& new_client_area, | 1074 const gfx::Insets& new_client_area, |
| 1020 mojo::Array<gfx::Rect> new_additional_client_areas) { | 1075 mojo::Array<gfx::Rect> new_additional_client_areas) { |
| 1021 // TODO: client area. | 1076 // TODO: client area. |
| 1022 /* | 1077 /* |
| 1023 Window* window = GetWindowByServerId(window_id); | 1078 Window* window = GetWindowByServerId(window_id); |
| 1024 if (window) { | 1079 if (window) { |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1099 | 1154 |
| 1100 Window* WindowTreeClient::GetCaptureWindow() { | 1155 Window* WindowTreeClient::GetCaptureWindow() { |
| 1101 return capture_window_ ? capture_window_->GetWindow() : nullptr; | 1156 return capture_window_ ? capture_window_->GetWindow() : nullptr; |
| 1102 } | 1157 } |
| 1103 | 1158 |
| 1104 void WindowTreeClient::OnWindowVisibilityChanged(Id window_id, bool visible) { | 1159 void WindowTreeClient::OnWindowVisibilityChanged(Id window_id, bool visible) { |
| 1105 WindowMus* window = GetWindowByServerId(window_id); | 1160 WindowMus* window = GetWindowByServerId(window_id); |
| 1106 if (!window) | 1161 if (!window) |
| 1107 return; | 1162 return; |
| 1108 | 1163 |
| 1109 InFlightVisibleChange new_change(window, visible); | 1164 InFlightVisibleChange new_change(this, window, visible); |
| 1110 if (ApplyServerChangeToExistingInFlightChange(new_change)) | 1165 if (ApplyServerChangeToExistingInFlightChange(new_change)) |
| 1111 return; | 1166 return; |
| 1112 | 1167 |
| 1113 window->SetVisibleFromServer(visible); | 1168 SetWindowVisibleFromServer(window, visible); |
| 1114 } | 1169 } |
| 1115 | 1170 |
| 1116 void WindowTreeClient::OnWindowOpacityChanged(Id window_id, | 1171 void WindowTreeClient::OnWindowOpacityChanged(Id window_id, |
| 1117 float old_opacity, | 1172 float old_opacity, |
| 1118 float new_opacity) { | 1173 float new_opacity) { |
| 1119 WindowMus* window = GetWindowByServerId(window_id); | 1174 WindowMus* window = GetWindowByServerId(window_id); |
| 1120 if (!window) | 1175 if (!window) |
| 1121 return; | 1176 return; |
| 1122 | 1177 |
| 1123 InFlightOpacityChange new_change(window, new_opacity); | 1178 InFlightOpacityChange new_change(window, new_opacity); |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1168 DCHECK(event); | 1223 DCHECK(event); |
| 1169 | 1224 |
| 1170 WindowMus* window = GetWindowByServerId(window_id); // May be null. | 1225 WindowMus* window = GetWindowByServerId(window_id); // May be null. |
| 1171 | 1226 |
| 1172 if (event->IsKeyEvent()) { | 1227 if (event->IsKeyEvent()) { |
| 1173 DCHECK(!matches_pointer_watcher); // PointerWatcher isn't for key events. | 1228 DCHECK(!matches_pointer_watcher); // PointerWatcher isn't for key events. |
| 1174 if (!window || !window->GetWindow()->GetHost()) { | 1229 if (!window || !window->GetWindow()->GetHost()) { |
| 1175 tree_->OnWindowInputEventAck(event_id, ui::mojom::EventResult::UNHANDLED); | 1230 tree_->OnWindowInputEventAck(event_id, ui::mojom::EventResult::UNHANDLED); |
| 1176 return; | 1231 return; |
| 1177 } | 1232 } |
| 1178 InputMethodMus* input_method = | 1233 InputMethodMus* input_method = GetWindowTreeHostMus(window)->input_method(); |
| 1179 static_cast<WindowTreeHostMus*>(window->GetWindow()->GetHost()) | |
| 1180 ->input_method(); | |
| 1181 input_method->DispatchKeyEvent(event->AsKeyEvent(), | 1234 input_method->DispatchKeyEvent(event->AsKeyEvent(), |
| 1182 CreateEventResultCallback(event_id)); | 1235 CreateEventResultCallback(event_id)); |
| 1183 return; | 1236 return; |
| 1184 } | 1237 } |
| 1185 | 1238 |
| 1186 if (matches_pointer_watcher && has_pointer_watcher_) { | 1239 if (matches_pointer_watcher && has_pointer_watcher_) { |
| 1187 DCHECK(event->IsPointerEvent()); | 1240 DCHECK(event->IsPointerEvent()); |
| 1188 delegate_->OnPointerEventObserved(*event->AsPointerEvent(), | 1241 delegate_->OnPointerEventObserved(*event->AsPointerEvent(), |
| 1189 window ? window->GetWindow() : nullptr); | 1242 window ? window->GetWindow() : nullptr); |
| 1190 } | 1243 } |
| 1191 | 1244 |
| 1192 // TODO: deal with no window or host here. This could happen if during | 1245 // TODO: deal with no window or host here. This could happen if during |
| 1193 // dispatch a window is deleted or moved. In either case we still need to | 1246 // dispatch a window is deleted or moved. In either case we still need to |
| 1194 // dispatch. Most likely need the display id. | 1247 // dispatch. Most likely need the display id. |
| 1195 if (!window || !window->GetWindow()->GetHost()) { | 1248 if (!window || !window->GetWindow()->GetHost()) { |
| 1196 tree_->OnWindowInputEventAck(event_id, ui::mojom::EventResult::UNHANDLED); | 1249 tree_->OnWindowInputEventAck(event_id, ui::mojom::EventResult::UNHANDLED); |
| 1197 return; | 1250 return; |
| 1198 } | 1251 } |
| 1199 | 1252 |
| 1200 EventAckHandler ack_handler(CreateEventResultCallback(event_id)); | 1253 EventAckHandler ack_handler(CreateEventResultCallback(event_id)); |
| 1201 WindowTreeHostMus* host = | 1254 WindowTreeHostMus* host = GetWindowTreeHostMus(window); |
| 1202 static_cast<WindowTreeHostMus*>(window->GetWindow()->GetHost()); | |
| 1203 // TODO(moshayedi): crbug.com/617222. No need to convert to ui::MouseEvent or | 1255 // TODO(moshayedi): crbug.com/617222. No need to convert to ui::MouseEvent or |
| 1204 // ui::TouchEvent once we have proper support for pointer events. | 1256 // ui::TouchEvent once we have proper support for pointer events. |
| 1205 if (event->IsMousePointerEvent()) { | 1257 if (event->IsMousePointerEvent()) { |
| 1206 if (event->type() == ui::ET_POINTER_WHEEL_CHANGED) { | 1258 if (event->type() == ui::ET_POINTER_WHEEL_CHANGED) { |
| 1207 ui::MouseWheelEvent mapped_event(*event->AsPointerEvent()); | 1259 ui::MouseWheelEvent mapped_event(*event->AsPointerEvent()); |
| 1208 host->SendEventToProcessor(&mapped_event); | 1260 host->SendEventToProcessor(&mapped_event); |
| 1209 } else { | 1261 } else { |
| 1210 ui::MouseEvent mapped_event(*event->AsPointerEvent()); | 1262 ui::MouseEvent mapped_event(*event->AsPointerEvent()); |
| 1211 host->SendEventToProcessor(&mapped_event); | 1263 host->SendEventToProcessor(&mapped_event); |
| 1212 } | 1264 } |
| (...skipping 437 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1650 const uint32_t change_id = ScheduleInFlightChange( | 1702 const uint32_t change_id = ScheduleInFlightChange( |
| 1651 base::MakeUnique<InFlightCaptureChange>(this, capture_window_)); | 1703 base::MakeUnique<InFlightCaptureChange>(this, capture_window_)); |
| 1652 WindowMus* old_capture_window = capture_window_; | 1704 WindowMus* old_capture_window = capture_window_; |
| 1653 capture_window_ = gained_capture_mus; | 1705 capture_window_ = gained_capture_mus; |
| 1654 if (capture_window_) | 1706 if (capture_window_) |
| 1655 tree_->SetCapture(change_id, capture_window_->server_id()); | 1707 tree_->SetCapture(change_id, capture_window_->server_id()); |
| 1656 else | 1708 else |
| 1657 tree_->ReleaseCapture(change_id, old_capture_window->server_id()); | 1709 tree_->ReleaseCapture(change_id, old_capture_window->server_id()); |
| 1658 } | 1710 } |
| 1659 | 1711 |
| 1712 void WindowTreeClient::SetRootWindowBounds(Window* window, gfx::Rect* bounds) { | |
| 1713 WindowTreeHostMus* window_tree_host = GetWindowTreeHostMus(window); | |
| 1714 switch (window_tree_host->root_window_type()) { | |
| 1715 case RootWindowType::EMBED: | |
| 1716 NOTREACHED(); | |
| 1717 return; | |
| 1718 case RootWindowType::TOP_LEVEL: | |
| 1719 // Top level requests are always in display coordinates. | |
| 1720 break; | |
| 1721 case RootWindowType::DISPLAY: { | |
| 1722 gfx::Point display_relative_origin(bounds->origin()); | |
| 1723 display_relative_origin -= | |
| 1724 window_tree_host->GetDisplay().bounds().OffsetFromOrigin(); | |
| 1725 bounds->set_origin(display_relative_origin); | |
| 1726 break; | |
| 1727 } | |
| 1728 } | |
| 1729 // We need the root window to always have an origin of 0x0 locally. | |
| 1730 window_tree_host->set_origin_offset(bounds->OffsetFromOrigin()); | |
| 1731 bounds->set_origin(gfx::Point()); | |
| 1732 } | |
| 1733 | |
| 1660 } // namespace aura | 1734 } // namespace aura |
| OLD | NEW |