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

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

Issue 1568263003: Changes top level window creation to include window state in callback (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fix gn Created 4 years, 11 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 18 matching lines...) Expand all
29 29
30 Id MakeTransportId(ConnectionSpecificId connection_id, 30 Id MakeTransportId(ConnectionSpecificId connection_id,
31 ConnectionSpecificId local_id) { 31 ConnectionSpecificId local_id) {
32 return (connection_id << 16) | local_id; 32 return (connection_id << 16) | local_id;
33 } 33 }
34 34
35 // Helper called to construct a local window object from transport data. 35 // Helper called to construct a local window object from transport data.
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 cto that takes a WindowTreeConnection here, since it will 39 // We don't use the ctor that takes a WindowTreeConnection here, since it
40 // 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); 46 private_window.set_drawn(window_data->drawn);
47 private_window.LocalSetViewportMetrics(mojom::ViewportMetrics(), 47 private_window.LocalSetViewportMetrics(mojom::ViewportMetrics(),
48 *window_data->viewport_metrics); 48 *window_data->viewport_metrics);
49 private_window.set_properties( 49 private_window.set_properties(
50 window_data->properties 50 window_data->properties
(...skipping 465 matching lines...) Expand 10 before | Expand all | Expand 10 after
516 516
517 void WindowTreeClientImpl::OnUnembed(Id window_id) { 517 void WindowTreeClientImpl::OnUnembed(Id window_id) {
518 Window* window = GetWindowById(window_id); 518 Window* window = GetWindowById(window_id);
519 if (!window) 519 if (!window)
520 return; 520 return;
521 521
522 delegate_->OnUnembed(window); 522 delegate_->OnUnembed(window);
523 WindowPrivate(window).LocalDestroy(); 523 WindowPrivate(window).LocalDestroy();
524 } 524 }
525 525
526 void WindowTreeClientImpl::OnTopLevelCreated(uint32_t change_id,
527 mojom::WindowDataPtr data) {
528 // The server ack'd the top level window we created and supplied the state
529 // of the window at the time the server created it. For properties we do not
530 // have changes in flight for we can update them immediately. For properties
531 // with changes in flight we set the revert value from the server.
532
533 scoped_ptr<InFlightChange> change(std::move(in_flight_map_[change_id]));
534 in_flight_map_.erase(change_id);
535 DCHECK(change);
536
537 Window* window = change->window();
538 WindowPrivate window_private(window);
539
540 // Drawn state and ViewportMetrics always come from the server (they can't
541 // be modified locally).
542 window_private.set_drawn(data->drawn);
543 window_private.LocalSetViewportMetrics(mojom::ViewportMetrics(),
544 *data->viewport_metrics);
545
546 // The default visibilty is false, we only need update visibility if it
547 // differs from that.
548 if (data->visible) {
549 InFlightVisibleChange visible_change(window, data->visible);
550 InFlightChange* current_change =
551 GetOldestInFlightChangeMatching(visible_change);
552 if (current_change)
553 current_change->SetRevertValueFrom(visible_change);
554 else
555 window_private.LocalSetVisible(true);
556 }
557
558 const gfx::Rect bounds(data->bounds.To<gfx::Rect>());
559 {
560 InFlightBoundsChange bounds_change(window, bounds);
561 InFlightChange* current_change =
562 GetOldestInFlightChangeMatching(bounds_change);
563 if (current_change)
564 current_change->SetRevertValueFrom(bounds_change);
565 else if (window->bounds() != bounds)
566 window_private.LocalSetBounds(window->bounds(), bounds);
567 }
568
569 // There is currently no API to bulk set properties, so we iterate over each
570 // property individually.
571 Window::SharedProperties properties =
572 data->properties.To<std::map<std::string, std::vector<uint8_t>>>();
573 for (const auto& pair : properties) {
574 InFlightPropertyChange property_change(
575 window, pair.first, mojo::Array<uint8_t>::From(pair.second));
576 InFlightChange* current_change =
577 GetOldestInFlightChangeMatching(property_change);
578 if (current_change)
579 current_change->SetRevertValueFrom(property_change);
580 else
581 window_private.LocalSetSharedProperty(pair.first, &(pair.second));
582 }
583
584 // Top level windows should not have a parent.
585 DCHECK_EQ(0u, data->parent_id);
586 }
587
526 void WindowTreeClientImpl::OnWindowBoundsChanged(Id window_id, 588 void WindowTreeClientImpl::OnWindowBoundsChanged(Id window_id,
527 mojo::RectPtr old_bounds, 589 mojo::RectPtr old_bounds,
528 mojo::RectPtr new_bounds) { 590 mojo::RectPtr new_bounds) {
529 Window* window = GetWindowById(window_id); 591 Window* window = GetWindowById(window_id);
530 if (!window) 592 if (!window)
531 return; 593 return;
532 594
533 InFlightBoundsChange new_change(window, new_bounds.To<gfx::Rect>()); 595 InFlightBoundsChange new_change(window, new_bounds.To<gfx::Rect>());
534 if (ApplyServerChangeToExistingInFlightChange(new_change)) 596 if (ApplyServerChangeToExistingInFlightChange(new_change))
535 return; 597 return;
(...skipping 256 matching lines...) Expand 10 before | Expand all | Expand 10 after
792 mojo::Map<mojo::String, mojo::Array<uint8_t>> transport_properties) { 854 mojo::Map<mojo::String, mojo::Array<uint8_t>> transport_properties) {
793 std::map<std::string, std::vector<uint8_t>> properties = 855 std::map<std::string, std::vector<uint8_t>> properties =
794 transport_properties.To<std::map<std::string, std::vector<uint8_t>>>(); 856 transport_properties.To<std::map<std::string, std::vector<uint8_t>>>();
795 Window* window = 857 Window* window =
796 window_manager_delegate_->OnWmCreateTopLevelWindow(&properties); 858 window_manager_delegate_->OnWmCreateTopLevelWindow(&properties);
797 window_manager_internal_client_->OnWmCreatedTopLevelWindow(change_id, 859 window_manager_internal_client_->OnWmCreatedTopLevelWindow(change_id,
798 window->id()); 860 window->id());
799 } 861 }
800 862
801 } // namespace mus 863 } // namespace mus
OLDNEW
« no previous file with comments | « components/mus/public/cpp/lib/window_tree_client_impl.h ('k') | components/mus/public/cpp/tests/BUILD.gn » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698