Index: components/mus/public/cpp/lib/window_tree_client.cc |
diff --git a/components/mus/public/cpp/lib/window_tree_client.cc b/components/mus/public/cpp/lib/window_tree_client.cc |
index 3a7e71dbcb9a8cf5fb213b702df2627165e113b6..9ae24816e4ab3e9cd3a2b3b9e7817d287f5d413d 100644 |
--- a/components/mus/public/cpp/lib/window_tree_client.cc |
+++ b/components/mus/public/cpp/lib/window_tree_client.cc |
@@ -12,6 +12,8 @@ |
#include "base/bind.h" |
#include "base/memory/ptr_util.h" |
+#include "base/message_loop/message_loop.h" |
+#include "base/run_loop.h" |
#include "components/mus/common/util.h" |
#include "components/mus/public/cpp/input_event_handler.h" |
#include "components/mus/public/cpp/lib/in_flight_change.h" |
@@ -232,8 +234,8 @@ bool WindowTreeClient::OwnsWindow(Window* window) const { |
} |
void WindowTreeClient::SetBounds(Window* window, |
- const gfx::Rect& old_bounds, |
- const gfx::Rect& bounds) { |
+ const gfx::Rect& old_bounds, |
+ const gfx::Rect& bounds) { |
DCHECK(tree_); |
const uint32_t change_id = ScheduleInFlightChange( |
base::WrapUnique(new InFlightBoundsChange(window, old_bounds))); |
@@ -624,6 +626,37 @@ void WindowTreeClient::SetEventObserver(mojom::EventMatcherPtr matcher) { |
} |
} |
+bool WindowTreeClient::PerformWindowMove(Window* window, |
+ const gfx::Point& cursor_location) { |
+ base::MessageLoopForUI* loop = base::MessageLoopForUI::current(); |
+ base::MessageLoop::ScopedNestableTaskAllower allow_nested(loop); |
sky
2016/06/22 23:47:56
mus::Window shouldn't run a nested message loop. C
|
+ base::RunLoop run_loop; |
+ |
+ const uint32_t change_id = ScheduleInFlightChange( |
+ base::WrapUnique(new InFlightMoveLoopChange(window, window->bounds()))); |
+ |
+ current_move_succeeded_ = false; |
+ on_current_move_finished_ = run_loop.QuitClosure(); |
+ |
+ // Tell the window manager to take over moving us. |
+ tree_->PerformWindowMove(change_id, window->server_id(), cursor_location); |
+ |
+ // PerformWindowMove is deliberately not a sync call. We want to process |
+ // other messages while we're otherwise blocking on RunMoveLoop(); everything |
+ // in views makes this assumption. |
+ // |
+ // TODO(erg): Once mus is the only target for views, go through the chrome |
+ // code base and try making this properly asynchronous instead of building up |
+ // a nested RunLoop, as we always have in this situation. |
+ run_loop.Run(); |
+ |
+ return current_move_succeeded_; |
+} |
+ |
+void WindowTreeClient::CancelWindowMove(Window* window) { |
+ tree_->CancelWindowMove(window->server_id()); |
+} |
+ |
Window* WindowTreeClient::NewWindow( |
const Window::SharedProperties* properties) { |
return NewWindowImpl(NewWindowType::CHILD, properties); |
@@ -1021,6 +1054,16 @@ void WindowTreeClient::OnChangeCompleted(uint32_t change_id, bool success) { |
} |
} |
+void WindowTreeClient::OnMoveLoopCompleted(uint32_t change_id, bool success) { |
+ std::unique_ptr<InFlightChange> change(std::move(in_flight_map_[change_id])); |
+ in_flight_map_.erase(change_id); |
+ if (!change) |
+ return; |
+ |
+ current_move_succeeded_ = success; |
+ on_current_move_finished_.Run(); |
+} |
+ |
void WindowTreeClient::GetWindowManager( |
mojo::AssociatedInterfaceRequest<WindowManager> internal) { |
window_manager_internal_.reset( |
@@ -1069,9 +1112,9 @@ void WindowTreeClient::WmSetBounds(uint32_t change_id, |
} |
void WindowTreeClient::WmSetProperty(uint32_t change_id, |
- Id window_id, |
- const mojo::String& name, |
- mojo::Array<uint8_t> transit_data) { |
+ Id window_id, |
+ const mojo::String& name, |
+ mojo::Array<uint8_t> transit_data) { |
Window* window = GetWindowByServerId(window_id); |
bool result = false; |
if (window) { |
@@ -1108,7 +1151,7 @@ void WindowTreeClient::WmCreateTopLevelWindow( |
} |
void WindowTreeClient::WmClientJankinessChanged(ClientSpecificId client_id, |
- bool janky) { |
+ bool janky) { |
if (window_manager_delegate_) { |
auto it = embedded_windows_.find(client_id); |
CHECK(it != embedded_windows_.end()); |
@@ -1117,6 +1160,19 @@ void WindowTreeClient::WmClientJankinessChanged(ClientSpecificId client_id, |
} |
} |
+void WindowTreeClient::WmPerformMoveLoop(uint32_t change_id, |
+ Id window_id, |
+ const gfx::Point& cursor_location) { |
+ if (window_manager_delegate_) |
+ window_manager_delegate_->OnWmPerformMoveLoop(change_id, window_id, |
+ cursor_location); |
+} |
+ |
+void WindowTreeClient::WmCancelMoveLoop(uint32_t window_id) { |
+ if (window_manager_delegate_) |
+ window_manager_delegate_->OnWmCancelMoveLoop(window_id); |
+} |
+ |
void WindowTreeClient::OnAccelerator(uint32_t id, |
std::unique_ptr<ui::Event> event) { |
DCHECK(event); |
@@ -1132,7 +1188,7 @@ void WindowTreeClient::SetFrameDecorationValues( |
} |
void WindowTreeClient::SetNonClientCursor(Window* window, |
- mus::mojom::Cursor cursor_id) { |
+ mus::mojom::Cursor cursor_id) { |
window_manager_internal_client_->WmSetNonClientCursor(server_id(window), |
cursor_id); |
} |
@@ -1178,4 +1234,13 @@ void WindowTreeClient::SetUnderlaySurfaceOffsetAndExtendedHitArea( |
} |
} |
+void WindowTreeClient::OnWmMoveLoopCompleted(uint32_t change_id, |
+ uint32_t window_id, |
+ bool completed) { |
+ if (window_manager_internal_client_) { |
+ window_manager_internal_client_->OnWmMoveLoopCompleted(change_id, window_id, |
+ completed); |
+ } |
+} |
+ |
} // namespace mus |