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 "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 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 124 : connection_id_(0), | 124 : connection_id_(0), |
| 125 next_window_id_(1), | 125 next_window_id_(1), |
| 126 next_change_id_(1), | 126 next_change_id_(1), |
| 127 delegate_(delegate), | 127 delegate_(delegate), |
| 128 window_manager_delegate_(window_manager_delegate), | 128 window_manager_delegate_(window_manager_delegate), |
| 129 capture_window_(nullptr), | 129 capture_window_(nullptr), |
| 130 focused_window_(nullptr), | 130 focused_window_(nullptr), |
| 131 binding_(this), | 131 binding_(this), |
| 132 tree_(nullptr), | 132 tree_(nullptr), |
| 133 delete_on_no_roots_(true), | 133 delete_on_no_roots_(true), |
| 134 in_destructor_(false) { | 134 in_destructor_(false), |
| 135 cursor_location_memory_(nullptr), | |
| 136 weak_factory_(this) { | |
| 135 // Allow for a null request in tests. | 137 // Allow for a null request in tests. |
| 136 if (request.is_pending()) | 138 if (request.is_pending()) |
| 137 binding_.Bind(std::move(request)); | 139 binding_.Bind(std::move(request)); |
| 138 if (window_manager_delegate) | 140 if (window_manager_delegate) |
| 139 window_manager_delegate->SetWindowManagerClient(this); | 141 window_manager_delegate->SetWindowManagerClient(this); |
| 140 } | 142 } |
| 141 | 143 |
| 142 WindowTreeClientImpl::~WindowTreeClientImpl() { | 144 WindowTreeClientImpl::~WindowTreeClientImpl() { |
| 143 in_destructor_ = true; | 145 in_destructor_ = true; |
| 144 | 146 |
| (...skipping 25 matching lines...) Expand all Loading... | |
| 170 delete_on_no_roots_ = false; | 172 delete_on_no_roots_ = false; |
| 171 | 173 |
| 172 // The connection id doesn't really matter, we use 101 purely for debugging. | 174 // The connection id doesn't really matter, we use 101 purely for debugging. |
| 173 connection_id_ = 101; | 175 connection_id_ = 101; |
| 174 | 176 |
| 175 mojom::WindowTreeFactoryPtr factory; | 177 mojom::WindowTreeFactoryPtr factory; |
| 176 connector->ConnectToInterface("mojo:mus", &factory); | 178 connector->ConnectToInterface("mojo:mus", &factory); |
| 177 factory->CreateWindowTree(GetProxy(&tree_ptr_), | 179 factory->CreateWindowTree(GetProxy(&tree_ptr_), |
| 178 binding_.CreateInterfacePtrAndBind()); | 180 binding_.CreateInterfacePtrAndBind()); |
| 179 tree_ = tree_ptr_.get(); | 181 tree_ = tree_ptr_.get(); |
| 182 | |
| 183 tree_ptr_->GetCursorLocationMemory( | |
| 184 base::Bind(&WindowTreeClientImpl::OnReceivedCursorLocationMemory, | |
| 185 weak_factory_.GetWeakPtr())); | |
| 180 } | 186 } |
| 181 | 187 |
| 182 void WindowTreeClientImpl::WaitForEmbed() { | 188 void WindowTreeClientImpl::WaitForEmbed() { |
| 183 DCHECK(roots_.empty()); | 189 DCHECK(roots_.empty()); |
| 184 // OnEmbed() is the first function called. | 190 // OnEmbed() is the first function called. |
| 185 binding_.WaitForIncomingMethodCall(); | 191 binding_.WaitForIncomingMethodCall(); |
| 186 // TODO(sky): deal with pipe being closed before we get OnEmbed(). | 192 // TODO(sky): deal with pipe being closed before we get OnEmbed(). |
| 187 } | 193 } |
| 188 | 194 |
| 189 void WindowTreeClientImpl::DestroyWindow(Window* window) { | 195 void WindowTreeClientImpl::DestroyWindow(Window* window) { |
| (...skipping 332 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 522 WindowPrivate(root).LocalSetParentDrawn(drawn); | 528 WindowPrivate(root).LocalSetParentDrawn(drawn); |
| 523 | 529 |
| 524 delegate_->OnEmbed(root); | 530 delegate_->OnEmbed(root); |
| 525 | 531 |
| 526 if (focused_window_) { | 532 if (focused_window_) { |
| 527 FOR_EACH_OBSERVER(WindowTreeConnectionObserver, observers_, | 533 FOR_EACH_OBSERVER(WindowTreeConnectionObserver, observers_, |
| 528 OnWindowTreeFocusChanged(focused_window_, nullptr)); | 534 OnWindowTreeFocusChanged(focused_window_, nullptr)); |
| 529 } | 535 } |
| 530 } | 536 } |
| 531 | 537 |
| 538 void WindowTreeClientImpl::OnReceivedCursorLocationMemory( | |
| 539 mojo::ScopedSharedBufferHandle handle) { | |
| 540 cursor_location_handle_ = std::move(handle); | |
| 541 MojoResult result = mojo::MapBuffer( | |
| 542 cursor_location_handle_.get(), 0, | |
| 543 sizeof(base::subtle::Atomic32), | |
| 544 reinterpret_cast<void**>(&cursor_location_memory_), | |
| 545 MOJO_MAP_BUFFER_FLAG_NONE); | |
| 546 if (result != MOJO_RESULT_OK) { | |
| 547 NOTREACHED(); | |
| 548 return; | |
| 549 } | |
| 550 DCHECK(cursor_location_memory_); | |
| 551 } | |
| 552 | |
| 532 //////////////////////////////////////////////////////////////////////////////// | 553 //////////////////////////////////////////////////////////////////////////////// |
| 533 // WindowTreeClientImpl, WindowTreeConnection implementation: | 554 // WindowTreeClientImpl, WindowTreeConnection implementation: |
| 534 | 555 |
| 535 void WindowTreeClientImpl::SetDeleteOnNoRoots(bool value) { | 556 void WindowTreeClientImpl::SetDeleteOnNoRoots(bool value) { |
| 536 delete_on_no_roots_ = value; | 557 delete_on_no_roots_ = value; |
| 537 } | 558 } |
| 538 | 559 |
| 539 const std::set<Window*>& WindowTreeClientImpl::GetRoots() { | 560 const std::set<Window*>& WindowTreeClientImpl::GetRoots() { |
| 540 return roots_; | 561 return roots_; |
| 541 } | 562 } |
| 542 | 563 |
| 543 Window* WindowTreeClientImpl::GetFocusedWindow() { | 564 Window* WindowTreeClientImpl::GetFocusedWindow() { |
| 544 return focused_window_; | 565 return focused_window_; |
| 545 } | 566 } |
| 546 | 567 |
| 547 void WindowTreeClientImpl::ClearFocus() { | 568 void WindowTreeClientImpl::ClearFocus() { |
| 548 if (!focused_window_) | 569 if (!focused_window_) |
| 549 return; | 570 return; |
| 550 | 571 |
| 551 SetFocus(nullptr); | 572 SetFocus(nullptr); |
| 552 } | 573 } |
| 553 | 574 |
| 575 gfx::Point WindowTreeClientImpl::GetCursorScreenPoint() { | |
| 576 // We raced initialization. Return (0, 0). | |
| 577 if (!cursor_location_memory_) | |
| 578 return gfx::Point(); | |
| 579 | |
| 580 base::subtle::Atomic32 location = | |
| 581 base::subtle::NoBarrier_Load(cursor_location_memory_); | |
| 582 return gfx::Point(location >> 16, | |
|
sky
2016/04/27 23:55:57
Is the sign bit preserved here? I would expect you
Elliot Glaysher
2016/04/28 00:14:01
I manually tested this and the sign bit is preserv
| |
| 583 static_cast<int16_t>(location & 0xFFFF)); | |
| 584 } | |
| 585 | |
| 554 Window* WindowTreeClientImpl::NewWindow( | 586 Window* WindowTreeClientImpl::NewWindow( |
| 555 const Window::SharedProperties* properties) { | 587 const Window::SharedProperties* properties) { |
| 556 return NewWindowImpl(NewWindowType::CHILD, properties); | 588 return NewWindowImpl(NewWindowType::CHILD, properties); |
| 557 } | 589 } |
| 558 | 590 |
| 559 Window* WindowTreeClientImpl::NewTopLevelWindow( | 591 Window* WindowTreeClientImpl::NewTopLevelWindow( |
| 560 const Window::SharedProperties* properties) { | 592 const Window::SharedProperties* properties) { |
| 561 Window* window = NewWindowImpl(NewWindowType::TOP_LEVEL, properties); | 593 Window* window = NewWindowImpl(NewWindowType::TOP_LEVEL, properties); |
| 562 // Assume newly created top level windows are drawn by default, otherwise | 594 // Assume newly created top level windows are drawn by default, otherwise |
| 563 // requests to focus will fail. We will get the real value in | 595 // requests to focus will fail. We will get the real value in |
| (...skipping 477 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1041 | 1073 |
| 1042 void WindowTreeClientImpl::SetUnderlaySurfaceOffsetAndExtendedHitArea( | 1074 void WindowTreeClientImpl::SetUnderlaySurfaceOffsetAndExtendedHitArea( |
| 1043 Window* window, | 1075 Window* window, |
| 1044 const gfx::Vector2d& offset, | 1076 const gfx::Vector2d& offset, |
| 1045 const gfx::Insets& hit_area) { | 1077 const gfx::Insets& hit_area) { |
| 1046 window_manager_internal_client_->SetUnderlaySurfaceOffsetAndExtendedHitArea( | 1078 window_manager_internal_client_->SetUnderlaySurfaceOffsetAndExtendedHitArea( |
| 1047 server_id(window), offset.x(), offset.y(), mojo::Insets::From(hit_area)); | 1079 server_id(window), offset.x(), offset.y(), mojo::Insets::From(hit_area)); |
| 1048 } | 1080 } |
| 1049 | 1081 |
| 1050 } // namespace mus | 1082 } // namespace mus |
| OLD | NEW |