| 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 "services/ui/public/cpp/window_tree_client.h" | 5 #include "services/ui/public/cpp/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 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 59 Window* parent, | 59 Window* parent, |
| 60 const mojom::WindowDataPtr& window_data) { | 60 const mojom::WindowDataPtr& window_data) { |
| 61 // We don't use the ctor that takes a WindowTreeClient here, since it will | 61 // We don't use the ctor that takes a WindowTreeClient here, since it will |
| 62 // call back to the service and attempt to create a new window. | 62 // call back to the service and attempt to create a new window. |
| 63 Window* window = WindowPrivate::LocalCreate(); | 63 Window* window = WindowPrivate::LocalCreate(); |
| 64 WindowPrivate private_window(window); | 64 WindowPrivate private_window(window); |
| 65 private_window.set_client(client); | 65 private_window.set_client(client); |
| 66 private_window.set_server_id(window_data->window_id); | 66 private_window.set_server_id(window_data->window_id); |
| 67 private_window.set_visible(window_data->visible); | 67 private_window.set_visible(window_data->visible); |
| 68 private_window.set_properties( | 68 private_window.set_properties( |
| 69 window_data->properties | 69 mojo::UnorderedMapToMap(window_data->properties)); |
| 70 .To<std::map<std::string, std::vector<uint8_t>>>()); | |
| 71 client->AddWindow(window); | 70 client->AddWindow(window); |
| 72 private_window.LocalSetBounds( | 71 private_window.LocalSetBounds( |
| 73 gfx::Rect(), | 72 gfx::Rect(), |
| 74 gfx::ConvertRectToDIP(ScaleFactorForDisplay(window->display_id()), | 73 gfx::ConvertRectToDIP(ScaleFactorForDisplay(window->display_id()), |
| 75 window_data->bounds)); | 74 window_data->bounds)); |
| 76 if (parent) | 75 if (parent) |
| 77 WindowPrivate(parent).LocalAddChild(window); | 76 WindowPrivate(parent).LocalAddChild(window); |
| 78 return window; | 77 return window; |
| 79 } | 78 } |
| 80 | 79 |
| (...skipping 257 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 338 tree_->SetWindowVisibility(change_id, server_id(window), visible); | 337 tree_->SetWindowVisibility(change_id, server_id(window), visible); |
| 339 } | 338 } |
| 340 | 339 |
| 341 void WindowTreeClient::SetOpacity(Window* window, float opacity) { | 340 void WindowTreeClient::SetOpacity(Window* window, float opacity) { |
| 342 DCHECK(tree_); | 341 DCHECK(tree_); |
| 343 const uint32_t change_id = ScheduleInFlightChange( | 342 const uint32_t change_id = ScheduleInFlightChange( |
| 344 base::MakeUnique<InFlightOpacityChange>(window, window->opacity())); | 343 base::MakeUnique<InFlightOpacityChange>(window, window->opacity())); |
| 345 tree_->SetWindowOpacity(change_id, server_id(window), opacity); | 344 tree_->SetWindowOpacity(change_id, server_id(window), opacity); |
| 346 } | 345 } |
| 347 | 346 |
| 348 void WindowTreeClient::SetProperty(Window* window, | 347 void WindowTreeClient::SetProperty( |
| 349 const std::string& name, | 348 Window* window, |
| 350 mojo::Array<uint8_t> data) { | 349 const std::string& name, |
| 350 const base::Optional<std::vector<uint8_t>>& data) { |
| 351 DCHECK(tree_); | 351 DCHECK(tree_); |
| 352 | 352 |
| 353 mojo::Array<uint8_t> old_value(nullptr); | 353 base::Optional<std::vector<uint8_t>> old_value; |
| 354 if (window->HasSharedProperty(name)) | 354 if (window->HasSharedProperty(name)) |
| 355 old_value = mojo::Array<uint8_t>::From(window->properties_[name]); | 355 old_value.emplace(window->properties_[name]); |
| 356 | 356 |
| 357 const uint32_t change_id = ScheduleInFlightChange( | 357 const uint32_t change_id = |
| 358 base::MakeUnique<InFlightPropertyChange>(window, name, old_value)); | 358 ScheduleInFlightChange(base::MakeUnique<InFlightPropertyChange>( |
| 359 tree_->SetWindowProperty(change_id, server_id(window), mojo::String(name), | 359 window, name, std::move(old_value))); |
| 360 std::move(data)); | 360 tree_->SetWindowProperty(change_id, server_id(window), name, data); |
| 361 } | 361 } |
| 362 | 362 |
| 363 void WindowTreeClient::SetWindowTextInputState( | 363 void WindowTreeClient::SetWindowTextInputState( |
| 364 Id window_id, | 364 Id window_id, |
| 365 mojo::TextInputStatePtr state) { | 365 mojo::TextInputStatePtr state) { |
| 366 DCHECK(tree_); | 366 DCHECK(tree_); |
| 367 tree_->SetWindowTextInputState(window_id, std::move(state)); | 367 tree_->SetWindowTextInputState(window_id, std::move(state)); |
| 368 } | 368 } |
| 369 | 369 |
| 370 void WindowTreeClient::SetImeVisibility(Id window_id, | 370 void WindowTreeClient::SetImeVisibility(Id window_id, |
| (...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 498 const InFlightChange& change) { | 498 const InFlightChange& change) { |
| 499 InFlightChange* existing_change = GetOldestInFlightChangeMatching(change); | 499 InFlightChange* existing_change = GetOldestInFlightChangeMatching(change); |
| 500 if (!existing_change) | 500 if (!existing_change) |
| 501 return false; | 501 return false; |
| 502 | 502 |
| 503 existing_change->SetRevertValueFrom(change); | 503 existing_change->SetRevertValueFrom(change); |
| 504 return true; | 504 return true; |
| 505 } | 505 } |
| 506 | 506 |
| 507 void WindowTreeClient::BuildWindowTree( | 507 void WindowTreeClient::BuildWindowTree( |
| 508 const mojo::Array<mojom::WindowDataPtr>& windows, | 508 const std::vector<mojom::WindowDataPtr>& windows, |
| 509 Window* initial_parent) { | 509 Window* initial_parent) { |
| 510 for (const auto& window_data : windows) { | 510 for (const auto& window_data : windows) { |
| 511 Window* parent = window_data->parent_id == 0 | 511 Window* parent = window_data->parent_id == 0 |
| 512 ? nullptr | 512 ? nullptr |
| 513 : GetWindowByServerId(window_data->parent_id); | 513 : GetWindowByServerId(window_data->parent_id); |
| 514 Window* existing_window = GetWindowByServerId(window_data->window_id); | 514 Window* existing_window = GetWindowByServerId(window_data->window_id); |
| 515 if (!existing_window) | 515 if (!existing_window) |
| 516 AddWindowToClient(this, parent, window_data); | 516 AddWindowToClient(this, parent, window_data); |
| 517 else if (parent) | 517 else if (parent) |
| 518 WindowPrivate(parent).LocalAddChild(existing_window); | 518 WindowPrivate(parent).LocalAddChild(existing_window); |
| 519 } | 519 } |
| 520 } | 520 } |
| 521 | 521 |
| 522 Window* WindowTreeClient::NewWindowImpl( | 522 Window* WindowTreeClient::NewWindowImpl( |
| 523 NewWindowType type, | 523 NewWindowType type, |
| 524 const Window::SharedProperties* properties) { | 524 const Window::SharedProperties* properties) { |
| 525 DCHECK(tree_); | 525 DCHECK(tree_); |
| 526 Window* window = | 526 Window* window = |
| 527 new Window(this, MakeTransportId(client_id_, next_window_id_++)); | 527 new Window(this, MakeTransportId(client_id_, next_window_id_++)); |
| 528 if (properties) | 528 if (properties) |
| 529 window->properties_ = *properties; | 529 window->properties_ = *properties; |
| 530 AddWindow(window); | 530 AddWindow(window); |
| 531 | 531 |
| 532 const uint32_t change_id = | 532 const uint32_t change_id = |
| 533 ScheduleInFlightChange(base::MakeUnique<CrashInFlightChange>( | 533 ScheduleInFlightChange(base::MakeUnique<CrashInFlightChange>( |
| 534 window, type == NewWindowType::CHILD | 534 window, type == NewWindowType::CHILD |
| 535 ? ChangeType::NEW_WINDOW | 535 ? ChangeType::NEW_WINDOW |
| 536 : ChangeType::NEW_TOP_LEVEL_WINDOW)); | 536 : ChangeType::NEW_TOP_LEVEL_WINDOW)); |
| 537 mojo::Map<mojo::String, mojo::Array<uint8_t>> transport_properties; | 537 std::unordered_map<std::string, std::vector<uint8_t>> transport_properties; |
| 538 if (properties) { | 538 if (properties) |
| 539 transport_properties = | 539 transport_properties = mojo::MapToUnorderedMap(*properties); |
| 540 mojo::Map<mojo::String, mojo::Array<uint8_t>>::From(*properties); | 540 |
| 541 } | |
| 542 if (type == NewWindowType::CHILD) { | 541 if (type == NewWindowType::CHILD) { |
| 543 tree_->NewWindow(change_id, server_id(window), | 542 tree_->NewWindow(change_id, server_id(window), |
| 544 std::move(transport_properties)); | 543 std::move(transport_properties)); |
| 545 } else { | 544 } else { |
| 546 roots_.insert(window); | 545 roots_.insert(window); |
| 547 tree_->NewTopLevelWindow(change_id, server_id(window), | 546 tree_->NewTopLevelWindow(change_id, server_id(window), |
| 548 std::move(transport_properties)); | 547 transport_properties); |
| 549 } | 548 } |
| 550 return window; | 549 return window; |
| 551 } | 550 } |
| 552 | 551 |
| 553 void WindowTreeClient::SetWindowTree(mojom::WindowTreePtr window_tree_ptr) { | 552 void WindowTreeClient::SetWindowTree(mojom::WindowTreePtr window_tree_ptr) { |
| 554 tree_ptr_ = std::move(window_tree_ptr); | 553 tree_ptr_ = std::move(window_tree_ptr); |
| 555 tree_ = tree_ptr_.get(); | 554 tree_ = tree_ptr_.get(); |
| 556 | 555 |
| 557 tree_ptr_->GetCursorLocationMemory( | 556 tree_ptr_->GetCursorLocationMemory( |
| 558 base::Bind(&WindowTreeClient::OnReceivedCursorLocationMemory, | 557 base::Bind(&WindowTreeClient::OnReceivedCursorLocationMemory, |
| (...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 676 const std::map<std::string, std::vector<uint8_t>>& drag_data, | 675 const std::map<std::string, std::vector<uint8_t>>& drag_data, |
| 677 int drag_operation, | 676 int drag_operation, |
| 678 const gfx::Point& cursor_location, | 677 const gfx::Point& cursor_location, |
| 679 const SkBitmap& bitmap, | 678 const SkBitmap& bitmap, |
| 680 const base::Callback<void(bool, uint32_t)>& callback) { | 679 const base::Callback<void(bool, uint32_t)>& callback) { |
| 681 DCHECK(!current_drag_state_); | 680 DCHECK(!current_drag_state_); |
| 682 | 681 |
| 683 // TODO(erg): Pass |cursor_location| and |bitmap| in PerformDragDrop() when | 682 // TODO(erg): Pass |cursor_location| and |bitmap| in PerformDragDrop() when |
| 684 // we start showing an image representation of the drag under the cursor. | 683 // we start showing an image representation of the drag under the cursor. |
| 685 | 684 |
| 685 auto unordered_drag_data = mojo::MapToUnorderedMap(drag_data); |
| 686 |
| 686 if (window->drop_target()) { | 687 if (window->drop_target()) { |
| 687 // To minimize the number of round trips, copy the drag drop data to our | 688 // To minimize the number of round trips, copy the drag drop data to our |
| 688 // handler here, instead of forcing mus to send this same data back. | 689 // handler here, instead of forcing mus to send this same data back. |
| 689 OnDragDropStart( | 690 OnDragDropStart(unordered_drag_data); |
| 690 mojo::Map<mojo::String, mojo::Array<uint8_t>>::From(drag_data)); | |
| 691 } | 691 } |
| 692 | 692 |
| 693 uint32_t current_drag_change = ScheduleInFlightChange( | 693 uint32_t current_drag_change = ScheduleInFlightChange( |
| 694 base::MakeUnique<InFlightDragChange>(window, ChangeType::DRAG_LOOP)); | 694 base::MakeUnique<InFlightDragChange>(window, ChangeType::DRAG_LOOP)); |
| 695 current_drag_state_.reset(new CurrentDragState{ | 695 current_drag_state_.reset(new CurrentDragState{ |
| 696 current_drag_change, ui::mojom::kDropEffectNone, callback}); | 696 current_drag_change, ui::mojom::kDropEffectNone, callback}); |
| 697 | 697 |
| 698 tree_->PerformDragDrop( | 698 tree_->PerformDragDrop(current_drag_change, window->server_id(), |
| 699 current_drag_change, window->server_id(), | 699 unordered_drag_data, drag_operation); |
| 700 mojo::Map<mojo::String, mojo::Array<uint8_t>>::From(drag_data), | |
| 701 drag_operation); | |
| 702 } | 700 } |
| 703 | 701 |
| 704 void WindowTreeClient::CancelDragDrop(Window* window) { | 702 void WindowTreeClient::CancelDragDrop(Window* window) { |
| 705 // Server will clean up drag and fail the in-flight change. | 703 // Server will clean up drag and fail the in-flight change. |
| 706 tree_->CancelDragDrop(window->server_id()); | 704 tree_->CancelDragDrop(window->server_id()); |
| 707 } | 705 } |
| 708 | 706 |
| 709 void WindowTreeClient::PerformWindowMove( | 707 void WindowTreeClient::PerformWindowMove( |
| 710 Window* window, | 708 Window* window, |
| 711 ui::mojom::MoveLoopSource source, | 709 ui::mojom::MoveLoopSource source, |
| (...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 880 GetOldestInFlightChangeMatching(bounds_change); | 878 GetOldestInFlightChangeMatching(bounds_change); |
| 881 if (current_change) | 879 if (current_change) |
| 882 current_change->SetRevertValueFrom(bounds_change); | 880 current_change->SetRevertValueFrom(bounds_change); |
| 883 else if (window->bounds() != bounds) | 881 else if (window->bounds() != bounds) |
| 884 window_private.LocalSetBounds(window->bounds(), bounds); | 882 window_private.LocalSetBounds(window->bounds(), bounds); |
| 885 } | 883 } |
| 886 | 884 |
| 887 // There is currently no API to bulk set properties, so we iterate over each | 885 // There is currently no API to bulk set properties, so we iterate over each |
| 888 // property individually. | 886 // property individually. |
| 889 Window::SharedProperties properties = | 887 Window::SharedProperties properties = |
| 890 data->properties.To<std::map<std::string, std::vector<uint8_t>>>(); | 888 mojo::UnorderedMapToMap(data->properties); |
| 891 for (const auto& pair : properties) { | 889 for (const auto& pair : properties) { |
| 892 InFlightPropertyChange property_change( | 890 InFlightPropertyChange property_change(window, pair.first, pair.second); |
| 893 window, pair.first, mojo::Array<uint8_t>::From(pair.second)); | |
| 894 InFlightChange* current_change = | 891 InFlightChange* current_change = |
| 895 GetOldestInFlightChangeMatching(property_change); | 892 GetOldestInFlightChangeMatching(property_change); |
| 896 if (current_change) | 893 if (current_change) |
| 897 current_change->SetRevertValueFrom(property_change); | 894 current_change->SetRevertValueFrom(property_change); |
| 898 else | 895 else |
| 899 window_private.LocalSetSharedProperty(pair.first, &(pair.second)); | 896 window_private.LocalSetSharedProperty(pair.first, &(pair.second)); |
| 900 } | 897 } |
| 901 | 898 |
| 902 // Top level windows should not have a parent. | 899 // Top level windows should not have a parent. |
| 903 DCHECK_EQ(0u, data->parent_id); | 900 DCHECK_EQ(0u, data->parent_id); |
| (...skipping 14 matching lines...) Expand all Loading... |
| 918 | 915 |
| 919 InFlightBoundsChange new_change(window, new_bounds_in_dip); | 916 InFlightBoundsChange new_change(window, new_bounds_in_dip); |
| 920 if (ApplyServerChangeToExistingInFlightChange(new_change)) | 917 if (ApplyServerChangeToExistingInFlightChange(new_change)) |
| 921 return; | 918 return; |
| 922 WindowPrivate(window).LocalSetBounds(old_bounds_in_dip, new_bounds_in_dip); | 919 WindowPrivate(window).LocalSetBounds(old_bounds_in_dip, new_bounds_in_dip); |
| 923 } | 920 } |
| 924 | 921 |
| 925 void WindowTreeClient::OnClientAreaChanged( | 922 void WindowTreeClient::OnClientAreaChanged( |
| 926 uint32_t window_id, | 923 uint32_t window_id, |
| 927 const gfx::Insets& new_client_area, | 924 const gfx::Insets& new_client_area, |
| 928 mojo::Array<gfx::Rect> new_additional_client_areas) { | 925 const std::vector<gfx::Rect>& new_additional_client_areas) { |
| 929 Window* window = GetWindowByServerId(window_id); | 926 Window* window = GetWindowByServerId(window_id); |
| 930 if (window) { | 927 if (window) { |
| 931 float device_scale_factor = ScaleFactorForDisplay(window->display_id()); | 928 float device_scale_factor = ScaleFactorForDisplay(window->display_id()); |
| 932 std::vector<gfx::Rect> new_additional_client_areas_in_dip; | 929 std::vector<gfx::Rect> new_additional_client_areas_in_dip; |
| 933 for (const gfx::Rect& area : new_additional_client_areas) { | 930 for (const gfx::Rect& area : new_additional_client_areas) { |
| 934 new_additional_client_areas_in_dip.push_back( | 931 new_additional_client_areas_in_dip.push_back( |
| 935 gfx::ConvertRectToDIP(device_scale_factor, area)); | 932 gfx::ConvertRectToDIP(device_scale_factor, area)); |
| 936 } | 933 } |
| 937 WindowPrivate(window).LocalSetClientArea( | 934 WindowPrivate(window).LocalSetClientArea( |
| 938 gfx::ConvertInsetsToDIP(device_scale_factor, new_client_area), | 935 gfx::ConvertInsetsToDIP(device_scale_factor, new_client_area), |
| (...skipping 20 matching lines...) Expand all Loading... |
| 959 // window or transient_window or both may be null if a local delete occurs | 956 // window or transient_window or both may be null if a local delete occurs |
| 960 // with an in flight delete from the server. | 957 // with an in flight delete from the server. |
| 961 if (window && transient_window) | 958 if (window && transient_window) |
| 962 WindowPrivate(window).LocalRemoveTransientWindow(transient_window); | 959 WindowPrivate(window).LocalRemoveTransientWindow(transient_window); |
| 963 } | 960 } |
| 964 | 961 |
| 965 void WindowTreeClient::OnWindowHierarchyChanged( | 962 void WindowTreeClient::OnWindowHierarchyChanged( |
| 966 Id window_id, | 963 Id window_id, |
| 967 Id old_parent_id, | 964 Id old_parent_id, |
| 968 Id new_parent_id, | 965 Id new_parent_id, |
| 969 mojo::Array<mojom::WindowDataPtr> windows) { | 966 std::vector<mojom::WindowDataPtr> windows) { |
| 970 Window* initial_parent = | 967 Window* initial_parent = |
| 971 windows.size() ? GetWindowByServerId(windows[0]->parent_id) : NULL; | 968 windows.size() ? GetWindowByServerId(windows[0]->parent_id) : NULL; |
| 972 | 969 |
| 973 const bool was_window_known = GetWindowByServerId(window_id) != nullptr; | 970 const bool was_window_known = GetWindowByServerId(window_id) != nullptr; |
| 974 | 971 |
| 975 BuildWindowTree(windows, initial_parent); | 972 BuildWindowTree(windows, initial_parent); |
| 976 | 973 |
| 977 // If the window was not known, then BuildWindowTree() will have created it | 974 // If the window was not known, then BuildWindowTree() will have created it |
| 978 // and parented the window. | 975 // and parented the window. |
| 979 if (!was_window_known) | 976 if (!was_window_known) |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1036 | 1033 |
| 1037 void WindowTreeClient::OnWindowParentDrawnStateChanged(Id window_id, | 1034 void WindowTreeClient::OnWindowParentDrawnStateChanged(Id window_id, |
| 1038 bool drawn) { | 1035 bool drawn) { |
| 1039 Window* window = GetWindowByServerId(window_id); | 1036 Window* window = GetWindowByServerId(window_id); |
| 1040 if (window) | 1037 if (window) |
| 1041 WindowPrivate(window).LocalSetParentDrawn(drawn); | 1038 WindowPrivate(window).LocalSetParentDrawn(drawn); |
| 1042 } | 1039 } |
| 1043 | 1040 |
| 1044 void WindowTreeClient::OnWindowSharedPropertyChanged( | 1041 void WindowTreeClient::OnWindowSharedPropertyChanged( |
| 1045 Id window_id, | 1042 Id window_id, |
| 1046 const mojo::String& name, | 1043 const std::string& name, |
| 1047 mojo::Array<uint8_t> new_data) { | 1044 const base::Optional<std::vector<uint8_t>>& new_data) { |
| 1048 Window* window = GetWindowByServerId(window_id); | 1045 Window* window = GetWindowByServerId(window_id); |
| 1049 if (!window) | 1046 if (!window) |
| 1050 return; | 1047 return; |
| 1051 | 1048 |
| 1052 InFlightPropertyChange new_change(window, name, new_data); | 1049 InFlightPropertyChange new_change(window, name, new_data); |
| 1053 if (ApplyServerChangeToExistingInFlightChange(new_change)) | 1050 if (ApplyServerChangeToExistingInFlightChange(new_change)) |
| 1054 return; | 1051 return; |
| 1055 | 1052 |
| 1056 WindowPrivate(window).LocalSetSharedProperty(name, std::move(new_data)); | 1053 WindowPrivate(window).LocalSetSharedProperty(name, new_data); |
| 1057 } | 1054 } |
| 1058 | 1055 |
| 1059 void WindowTreeClient::OnWindowInputEvent(uint32_t event_id, | 1056 void WindowTreeClient::OnWindowInputEvent(uint32_t event_id, |
| 1060 Id window_id, | 1057 Id window_id, |
| 1061 std::unique_ptr<ui::Event> event, | 1058 std::unique_ptr<ui::Event> event, |
| 1062 bool matches_pointer_watcher) { | 1059 bool matches_pointer_watcher) { |
| 1063 DCHECK(event); | 1060 DCHECK(event); |
| 1064 Window* window = GetWindowByServerId(window_id); // May be null. | 1061 Window* window = GetWindowByServerId(window_id); // May be null. |
| 1065 | 1062 |
| 1066 if (matches_pointer_watcher && has_pointer_watcher_) { | 1063 if (matches_pointer_watcher && has_pointer_watcher_) { |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1144 if (!window) | 1141 if (!window) |
| 1145 return; | 1142 return; |
| 1146 std::unique_ptr<SurfaceInfo> surface_info(base::MakeUnique<SurfaceInfo>()); | 1143 std::unique_ptr<SurfaceInfo> surface_info(base::MakeUnique<SurfaceInfo>()); |
| 1147 surface_info->surface_id = surface_id; | 1144 surface_info->surface_id = surface_id; |
| 1148 surface_info->frame_size = frame_size; | 1145 surface_info->frame_size = frame_size; |
| 1149 surface_info->device_scale_factor = device_scale_factor; | 1146 surface_info->device_scale_factor = device_scale_factor; |
| 1150 WindowPrivate(window).LocalSetSurfaceId(std::move(surface_info)); | 1147 WindowPrivate(window).LocalSetSurfaceId(std::move(surface_info)); |
| 1151 } | 1148 } |
| 1152 | 1149 |
| 1153 void WindowTreeClient::OnDragDropStart( | 1150 void WindowTreeClient::OnDragDropStart( |
| 1154 mojo::Map<mojo::String, mojo::Array<uint8_t>> mime_data) { | 1151 const std::unordered_map<std::string, std::vector<uint8_t>>& mime_data) { |
| 1155 mime_drag_data_ = std::move(mime_data); | 1152 mime_drag_data_ = mojo::UnorderedMapToMap(mime_data); |
| 1156 } | 1153 } |
| 1157 | 1154 |
| 1158 void WindowTreeClient::OnDragEnter(Id window_id, | 1155 void WindowTreeClient::OnDragEnter(Id window_id, |
| 1159 uint32_t key_state, | 1156 uint32_t key_state, |
| 1160 const gfx::Point& position, | 1157 const gfx::Point& position, |
| 1161 uint32_t effect_bitmask, | 1158 uint32_t effect_bitmask, |
| 1162 const OnDragEnterCallback& callback) { | 1159 const OnDragEnterCallback& callback) { |
| 1163 Window* window = GetWindowByServerId(window_id); | 1160 Window* window = GetWindowByServerId(window_id); |
| 1164 if (!window || !window->drop_target()) { | 1161 if (!window || !window->drop_target()) { |
| 1165 callback.Run(mojom::kDropEffectNone); | 1162 callback.Run(mojom::kDropEffectNone); |
| 1166 return; | 1163 return; |
| 1167 } | 1164 } |
| 1168 | 1165 |
| 1169 if (!base::ContainsKey(drag_entered_windows_, window_id)) { | 1166 if (!base::ContainsKey(drag_entered_windows_, window_id)) { |
| 1170 window->drop_target()->OnDragDropStart( | 1167 window->drop_target()->OnDragDropStart(mime_drag_data_); |
| 1171 mime_drag_data_.To<std::map<std::string, std::vector<uint8_t>>>()); | |
| 1172 drag_entered_windows_.insert(window_id); | 1168 drag_entered_windows_.insert(window_id); |
| 1173 } | 1169 } |
| 1174 | 1170 |
| 1175 uint32_t ret = | 1171 uint32_t ret = |
| 1176 window->drop_target()->OnDragEnter(key_state, position, effect_bitmask); | 1172 window->drop_target()->OnDragEnter(key_state, position, effect_bitmask); |
| 1177 callback.Run(ret); | 1173 callback.Run(ret); |
| 1178 } | 1174 } |
| 1179 | 1175 |
| 1180 void WindowTreeClient::OnDragOver(Id window_id, | 1176 void WindowTreeClient::OnDragOver(Id window_id, |
| 1181 uint32_t key_state, | 1177 uint32_t key_state, |
| (...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1325 // If the resulting bounds differ return false. Returning false ensures | 1321 // If the resulting bounds differ return false. Returning false ensures |
| 1326 // the client applies the bounds we set below. | 1322 // the client applies the bounds we set below. |
| 1327 result = bounds == transit_bounds_in_dip; | 1323 result = bounds == transit_bounds_in_dip; |
| 1328 window->SetBounds(bounds); | 1324 window->SetBounds(bounds); |
| 1329 } | 1325 } |
| 1330 } | 1326 } |
| 1331 if (window_manager_internal_client_) | 1327 if (window_manager_internal_client_) |
| 1332 window_manager_internal_client_->WmResponse(change_id, result); | 1328 window_manager_internal_client_->WmResponse(change_id, result); |
| 1333 } | 1329 } |
| 1334 | 1330 |
| 1335 void WindowTreeClient::WmSetProperty(uint32_t change_id, | 1331 void WindowTreeClient::WmSetProperty( |
| 1336 Id window_id, | 1332 uint32_t change_id, |
| 1337 const mojo::String& name, | 1333 Id window_id, |
| 1338 mojo::Array<uint8_t> transit_data) { | 1334 const std::string& name, |
| 1335 const base::Optional<std::vector<uint8_t>>& transit_data) { |
| 1339 Window* window = GetWindowByServerId(window_id); | 1336 Window* window = GetWindowByServerId(window_id); |
| 1340 bool result = false; | 1337 bool result = false; |
| 1341 if (window) { | 1338 if (window) { |
| 1342 DCHECK(window_manager_delegate_); | 1339 DCHECK(window_manager_delegate_); |
| 1343 std::unique_ptr<std::vector<uint8_t>> data; | 1340 std::unique_ptr<std::vector<uint8_t>> data; |
| 1344 if (!transit_data.is_null()) { | 1341 if (transit_data.has_value()) |
| 1345 data.reset( | 1342 data.reset(new std::vector<uint8_t>(transit_data.value())); |
| 1346 new std::vector<uint8_t>(transit_data.To<std::vector<uint8_t>>())); | 1343 |
| 1347 } | |
| 1348 result = window_manager_delegate_->OnWmSetProperty(window, name, &data); | 1344 result = window_manager_delegate_->OnWmSetProperty(window, name, &data); |
| 1349 if (result) { | 1345 if (result) { |
| 1350 // If the resulting bounds differ return false. Returning false ensures | 1346 // If the resulting bounds differ return false. Returning false ensures |
| 1351 // the client applies the bounds we set below. | 1347 // the client applies the bounds we set below. |
| 1352 window->SetSharedPropertyInternal(name, data.get()); | 1348 window->SetSharedPropertyInternal(name, data.get()); |
| 1353 } | 1349 } |
| 1354 } | 1350 } |
| 1355 if (window_manager_internal_client_) | 1351 if (window_manager_internal_client_) |
| 1356 window_manager_internal_client_->WmResponse(change_id, result); | 1352 window_manager_internal_client_->WmResponse(change_id, result); |
| 1357 } | 1353 } |
| 1358 | 1354 |
| 1359 void WindowTreeClient::WmCreateTopLevelWindow( | 1355 void WindowTreeClient::WmCreateTopLevelWindow( |
| 1360 uint32_t change_id, | 1356 uint32_t change_id, |
| 1361 ClientSpecificId requesting_client_id, | 1357 ClientSpecificId requesting_client_id, |
| 1362 mojo::Map<mojo::String, mojo::Array<uint8_t>> transport_properties) { | 1358 const std::unordered_map<std::string, std::vector<uint8_t>>& |
| 1359 transport_properties) { |
| 1363 std::map<std::string, std::vector<uint8_t>> properties = | 1360 std::map<std::string, std::vector<uint8_t>> properties = |
| 1364 transport_properties.To<std::map<std::string, std::vector<uint8_t>>>(); | 1361 mojo::UnorderedMapToMap(transport_properties); |
| 1365 Window* window = | 1362 Window* window = |
| 1366 window_manager_delegate_->OnWmCreateTopLevelWindow(&properties); | 1363 window_manager_delegate_->OnWmCreateTopLevelWindow(&properties); |
| 1367 embedded_windows_[requesting_client_id].insert(window); | 1364 embedded_windows_[requesting_client_id].insert(window); |
| 1368 if (window_manager_internal_client_) { | 1365 if (window_manager_internal_client_) { |
| 1369 window_manager_internal_client_->OnWmCreatedTopLevelWindow( | 1366 window_manager_internal_client_->OnWmCreatedTopLevelWindow( |
| 1370 change_id, server_id(window)); | 1367 change_id, server_id(window)); |
| 1371 } | 1368 } |
| 1372 } | 1369 } |
| 1373 | 1370 |
| 1374 void WindowTreeClient::WmClientJankinessChanged(ClientSpecificId client_id, | 1371 void WindowTreeClient::WmClientJankinessChanged(ClientSpecificId client_id, |
| (...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1475 // TODO(riajiang): Figure out if |offset| needs to be converted. | 1472 // TODO(riajiang): Figure out if |offset| needs to be converted. |
| 1476 // (http://crbugs.com/646932) | 1473 // (http://crbugs.com/646932) |
| 1477 window_manager_internal_client_->SetUnderlaySurfaceOffsetAndExtendedHitArea( | 1474 window_manager_internal_client_->SetUnderlaySurfaceOffsetAndExtendedHitArea( |
| 1478 server_id(window), offset.x(), offset.y(), | 1475 server_id(window), offset.x(), offset.y(), |
| 1479 gfx::ConvertInsetsToDIP(ScaleFactorForDisplay(window->display_id()), | 1476 gfx::ConvertInsetsToDIP(ScaleFactorForDisplay(window->display_id()), |
| 1480 hit_area)); | 1477 hit_area)); |
| 1481 } | 1478 } |
| 1482 } | 1479 } |
| 1483 | 1480 |
| 1484 } // namespace ui | 1481 } // namespace ui |
| OLD | NEW |