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

Side by Side Diff: components/mus/public/cpp/lib/window_tree_client_impl.cc

Issue 1864113002: Fixes problems with drawn state (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: better comments Created 4 years, 8 months 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
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 "components/mus/public/cpp/lib/window_tree_client_impl.h" 5 #include "components/mus/public/cpp/lib/window_tree_client_impl.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 #include <utility> 8 #include <utility>
9 9
10 #include "base/bind.h" 10 #include "base/bind.h"
(...skipping 25 matching lines...) Expand all
36 Window* AddWindowToConnection(WindowTreeClientImpl* client, 36 Window* AddWindowToConnection(WindowTreeClientImpl* client,
37 Window* parent, 37 Window* parent,
38 const mojom::WindowDataPtr& window_data) { 38 const mojom::WindowDataPtr& window_data) {
39 // We don't use the ctor that takes a WindowTreeConnection here, since it 39 // We don't use the ctor that takes a WindowTreeConnection here, since it
40 // will call back to the service and attempt to create a new window. 40 // will call back to the service and attempt to create a new window.
41 Window* window = WindowPrivate::LocalCreate(); 41 Window* window = WindowPrivate::LocalCreate();
42 WindowPrivate private_window(window); 42 WindowPrivate private_window(window);
43 private_window.set_connection(client); 43 private_window.set_connection(client);
44 private_window.set_id(window_data->window_id); 44 private_window.set_id(window_data->window_id);
45 private_window.set_visible(window_data->visible); 45 private_window.set_visible(window_data->visible);
46 private_window.set_drawn(window_data->drawn);
47 private_window.LocalSetViewportMetrics(mojom::ViewportMetrics(), 46 private_window.LocalSetViewportMetrics(mojom::ViewportMetrics(),
48 *window_data->viewport_metrics); 47 *window_data->viewport_metrics);
49 private_window.set_properties( 48 private_window.set_properties(
50 window_data->properties 49 window_data->properties
51 .To<std::map<std::string, std::vector<uint8_t>>>()); 50 .To<std::map<std::string, std::vector<uint8_t>>>());
52 client->AddWindow(window); 51 client->AddWindow(window);
53 private_window.LocalSetBounds(gfx::Rect(), 52 private_window.LocalSetBounds(gfx::Rect(),
54 window_data->bounds.To<gfx::Rect>()); 53 window_data->bounds.To<gfx::Rect>());
55 if (parent) 54 if (parent)
56 WindowPrivate(parent).LocalAddChild(window); 55 WindowPrivate(parent).LocalAddChild(window);
(...skipping 420 matching lines...) Expand 10 before | Expand all | Expand 10 after
477 roots_.insert(window); 476 roots_.insert(window);
478 tree_->NewTopLevelWindow(change_id, window->id(), 477 tree_->NewTopLevelWindow(change_id, window->id(),
479 std::move(transport_properties)); 478 std::move(transport_properties));
480 } 479 }
481 return window; 480 return window;
482 } 481 }
483 482
484 void WindowTreeClientImpl::OnEmbedImpl(mojom::WindowTree* window_tree, 483 void WindowTreeClientImpl::OnEmbedImpl(mojom::WindowTree* window_tree,
485 ConnectionSpecificId connection_id, 484 ConnectionSpecificId connection_id,
486 mojom::WindowDataPtr root_data, 485 mojom::WindowDataPtr root_data,
487 Id focused_window_id) { 486 Id focused_window_id,
487 bool drawn) {
488 // WARNING: this is only called if WindowTreeClientImpl was created as the 488 // WARNING: this is only called if WindowTreeClientImpl was created as the
489 // result of an embedding. 489 // result of an embedding.
490 tree_ = window_tree; 490 tree_ = window_tree;
491 connection_id_ = connection_id; 491 connection_id_ = connection_id;
492 492
493 DCHECK(roots_.empty()); 493 DCHECK(roots_.empty());
494 Window* root = AddWindowToConnection(this, nullptr, root_data); 494 Window* root = AddWindowToConnection(this, nullptr, root_data);
495 roots_.insert(root); 495 roots_.insert(root);
496 496
497 focused_window_ = GetWindowById(focused_window_id); 497 focused_window_ = GetWindowById(focused_window_id);
498 498
499 WindowPrivate(root).LocalSetParentDrawn(drawn);
500
499 delegate_->OnEmbed(root); 501 delegate_->OnEmbed(root);
500 502
501 if (focused_window_) { 503 if (focused_window_) {
502 FOR_EACH_OBSERVER(WindowTreeConnectionObserver, observers_, 504 FOR_EACH_OBSERVER(WindowTreeConnectionObserver, observers_,
503 OnWindowTreeFocusChanged(focused_window_, nullptr)); 505 OnWindowTreeFocusChanged(focused_window_, nullptr));
504 } 506 }
505 } 507 }
506 508
507 //////////////////////////////////////////////////////////////////////////////// 509 ////////////////////////////////////////////////////////////////////////////////
508 // WindowTreeClientImpl, WindowTreeConnection implementation: 510 // WindowTreeClientImpl, WindowTreeConnection implementation:
(...skipping 15 matching lines...) Expand all
524 return focused_window_; 526 return focused_window_;
525 } 527 }
526 528
527 Window* WindowTreeClientImpl::NewWindow( 529 Window* WindowTreeClientImpl::NewWindow(
528 const Window::SharedProperties* properties) { 530 const Window::SharedProperties* properties) {
529 return NewWindowImpl(NewWindowType::CHILD, properties); 531 return NewWindowImpl(NewWindowType::CHILD, properties);
530 } 532 }
531 533
532 Window* WindowTreeClientImpl::NewTopLevelWindow( 534 Window* WindowTreeClientImpl::NewTopLevelWindow(
533 const Window::SharedProperties* properties) { 535 const Window::SharedProperties* properties) {
534 return NewWindowImpl(NewWindowType::TOP_LEVEL, properties); 536 Window* window = NewWindowImpl(NewWindowType::TOP_LEVEL, properties);
537 // Assume newly created top level windows are drawn by default, otherwise
538 // requests to focus will fail. We will get the real value in
539 // OnTopLevelCreated().
540 window->LocalSetParentDrawn(true);
541 return window;
535 } 542 }
536 543
537 ConnectionSpecificId WindowTreeClientImpl::GetConnectionId() { 544 ConnectionSpecificId WindowTreeClientImpl::GetConnectionId() {
538 return connection_id_; 545 return connection_id_;
539 } 546 }
540 547
541 //////////////////////////////////////////////////////////////////////////////// 548 ////////////////////////////////////////////////////////////////////////////////
542 // WindowTreeClientImpl, WindowTreeClient implementation: 549 // WindowTreeClientImpl, WindowTreeClient implementation:
543 550
544 void WindowTreeClientImpl::AddObserver(WindowTreeConnectionObserver* observer) { 551 void WindowTreeClientImpl::AddObserver(WindowTreeConnectionObserver* observer) {
545 observers_.AddObserver(observer); 552 observers_.AddObserver(observer);
546 } 553 }
547 554
548 void WindowTreeClientImpl::RemoveObserver( 555 void WindowTreeClientImpl::RemoveObserver(
549 WindowTreeConnectionObserver* observer) { 556 WindowTreeConnectionObserver* observer) {
550 observers_.RemoveObserver(observer); 557 observers_.RemoveObserver(observer);
551 } 558 }
552 559
553 void WindowTreeClientImpl::OnEmbed(ConnectionSpecificId connection_id, 560 void WindowTreeClientImpl::OnEmbed(ConnectionSpecificId connection_id,
554 mojom::WindowDataPtr root_data, 561 mojom::WindowDataPtr root_data,
555 mojom::WindowTreePtr tree, 562 mojom::WindowTreePtr tree,
556 Id focused_window_id) { 563 Id focused_window_id,
564 bool drawn) {
557 DCHECK(!tree_ptr_); 565 DCHECK(!tree_ptr_);
558 tree_ptr_ = std::move(tree); 566 tree_ptr_ = std::move(tree);
559 tree_ptr_.set_connection_error_handler([this]() { delete this; }); 567 tree_ptr_.set_connection_error_handler([this]() { delete this; });
560 568
561 if (window_manager_delegate_) { 569 if (window_manager_delegate_) {
562 tree_ptr_->GetWindowManagerClient(GetProxy(&window_manager_internal_client_, 570 tree_ptr_->GetWindowManagerClient(GetProxy(&window_manager_internal_client_,
563 tree_ptr_.associated_group())); 571 tree_ptr_.associated_group()));
564 } 572 }
565 573
566 OnEmbedImpl(tree_ptr_.get(), connection_id, std::move(root_data), 574 OnEmbedImpl(tree_ptr_.get(), connection_id, std::move(root_data),
567 focused_window_id); 575 focused_window_id, drawn);
568 } 576 }
569 577
570 void WindowTreeClientImpl::OnEmbeddedAppDisconnected(Id window_id) { 578 void WindowTreeClientImpl::OnEmbeddedAppDisconnected(Id window_id) {
571 Window* window = GetWindowById(window_id); 579 Window* window = GetWindowById(window_id);
572 if (window) { 580 if (window) {
573 FOR_EACH_OBSERVER(WindowObserver, *WindowPrivate(window).observers(), 581 FOR_EACH_OBSERVER(WindowObserver, *WindowPrivate(window).observers(),
574 OnWindowEmbeddedAppDisconnected(window)); 582 OnWindowEmbeddedAppDisconnected(window));
575 } 583 }
576 } 584 }
577 585
(...skipping 12 matching lines...) Expand all
590 return; 598 return;
591 599
592 InFlightCaptureChange reset_change(this, nullptr); 600 InFlightCaptureChange reset_change(this, nullptr);
593 if (ApplyServerChangeToExistingInFlightChange(reset_change)) 601 if (ApplyServerChangeToExistingInFlightChange(reset_change))
594 return; 602 return;
595 603
596 LocalSetCapture(nullptr); 604 LocalSetCapture(nullptr);
597 } 605 }
598 606
599 void WindowTreeClientImpl::OnTopLevelCreated(uint32_t change_id, 607 void WindowTreeClientImpl::OnTopLevelCreated(uint32_t change_id,
600 mojom::WindowDataPtr data) { 608 mojom::WindowDataPtr data,
609 bool drawn) {
601 // The server ack'd the top level window we created and supplied the state 610 // The server ack'd the top level window we created and supplied the state
602 // of the window at the time the server created it. For properties we do not 611 // of the window at the time the server created it. For properties we do not
603 // have changes in flight for we can update them immediately. For properties 612 // have changes in flight for we can update them immediately. For properties
604 // with changes in flight we set the revert value from the server. 613 // with changes in flight we set the revert value from the server.
605 614
606 if (!in_flight_map_.count(change_id)) { 615 if (!in_flight_map_.count(change_id)) {
607 // The window may have been destroyed locally before the server could finish 616 // The window may have been destroyed locally before the server could finish
608 // creating the window, and before the server received the notification that 617 // creating the window, and before the server received the notification that
609 // the window has been destroyed. 618 // the window has been destroyed.
610 return; 619 return;
611 } 620 }
612 scoped_ptr<InFlightChange> change(std::move(in_flight_map_[change_id])); 621 scoped_ptr<InFlightChange> change(std::move(in_flight_map_[change_id]));
613 in_flight_map_.erase(change_id); 622 in_flight_map_.erase(change_id);
614 623
615 Window* window = change->window(); 624 Window* window = change->window();
616 WindowPrivate window_private(window); 625 WindowPrivate window_private(window);
617 626
618 // Drawn state and ViewportMetrics always come from the server (they can't 627 // Drawn state and ViewportMetrics always come from the server (they can't
619 // be modified locally). 628 // be modified locally).
620 window_private.set_drawn(data->drawn); 629 window_private.LocalSetParentDrawn(drawn);
621 window_private.LocalSetViewportMetrics(mojom::ViewportMetrics(), 630 window_private.LocalSetViewportMetrics(mojom::ViewportMetrics(),
622 *data->viewport_metrics); 631 *data->viewport_metrics);
623 632
624 // The default visibilty is false, we only need update visibility if it 633 // The default visibilty is false, we only need update visibility if it
625 // differs from that. 634 // differs from that.
626 if (data->visible) { 635 if (data->visible) {
627 InFlightVisibleChange visible_change(window, data->visible); 636 InFlightVisibleChange visible_change(window, data->visible);
628 InFlightChange* current_change = 637 InFlightChange* current_change =
629 GetOldestInFlightChangeMatching(visible_change); 638 GetOldestInFlightChangeMatching(visible_change);
630 if (current_change) 639 if (current_change)
(...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after
786 if (!window) 795 if (!window)
787 return; 796 return;
788 797
789 InFlightVisibleChange new_change(window, visible); 798 InFlightVisibleChange new_change(window, visible);
790 if (ApplyServerChangeToExistingInFlightChange(new_change)) 799 if (ApplyServerChangeToExistingInFlightChange(new_change))
791 return; 800 return;
792 801
793 WindowPrivate(window).LocalSetVisible(visible); 802 WindowPrivate(window).LocalSetVisible(visible);
794 } 803 }
795 804
796 void WindowTreeClientImpl::OnWindowDrawnStateChanged(Id window_id, bool drawn) { 805 void WindowTreeClientImpl::OnWindowParentDrawnStateChanged(Id window_id,
806 bool drawn) {
797 Window* window = GetWindowById(window_id); 807 Window* window = GetWindowById(window_id);
798 if (window) 808 if (window)
799 WindowPrivate(window).LocalSetDrawn(drawn); 809 WindowPrivate(window).LocalSetParentDrawn(drawn);
800 } 810 }
801 811
802 void WindowTreeClientImpl::OnWindowSharedPropertyChanged( 812 void WindowTreeClientImpl::OnWindowSharedPropertyChanged(
803 Id window_id, 813 Id window_id,
804 const mojo::String& name, 814 const mojo::String& name,
805 mojo::Array<uint8_t> new_data) { 815 mojo::Array<uint8_t> new_data) {
806 Window* window = GetWindowById(window_id); 816 Window* window = GetWindowById(window_id);
807 if (!window) 817 if (!window)
808 return; 818 return;
809 819
(...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after
983 993
984 void WindowTreeClientImpl::SetUnderlaySurfaceOffsetAndExtendedHitArea( 994 void WindowTreeClientImpl::SetUnderlaySurfaceOffsetAndExtendedHitArea(
985 Window* window, 995 Window* window,
986 const gfx::Vector2d& offset, 996 const gfx::Vector2d& offset,
987 const gfx::Insets& hit_area) { 997 const gfx::Insets& hit_area) {
988 window_manager_internal_client_->SetUnderlaySurfaceOffsetAndExtendedHitArea( 998 window_manager_internal_client_->SetUnderlaySurfaceOffsetAndExtendedHitArea(
989 window->id(), offset.x(), offset.y(), mojo::Insets::From(hit_area)); 999 window->id(), offset.x(), offset.y(), mojo::Insets::From(hit_area));
990 } 1000 }
991 1001
992 } // namespace mus 1002 } // namespace mus
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698