OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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/ws/window_tree_host_impl.h" | 5 #include "components/mus/ws/window_tree_host_impl.h" |
6 | 6 |
7 #include "base/debug/debugger.h" | 7 #include "base/debug/debugger.h" |
8 #include "base/strings/utf_string_conversions.h" | 8 #include "base/strings/utf_string_conversions.h" |
9 #include "components/mus/common/types.h" | 9 #include "components/mus/common/types.h" |
| 10 #include "components/mus/public/interfaces/input_event_constants.mojom.h" |
10 #include "components/mus/ws/connection_manager.h" | 11 #include "components/mus/ws/connection_manager.h" |
11 #include "components/mus/ws/display_manager.h" | 12 #include "components/mus/ws/display_manager.h" |
12 #include "components/mus/ws/focus_controller.h" | 13 #include "components/mus/ws/focus_controller.h" |
13 #include "components/mus/ws/window_tree_host_delegate.h" | 14 #include "components/mus/ws/window_tree_host_delegate.h" |
14 #include "components/mus/ws/window_tree_impl.h" | 15 #include "components/mus/ws/window_tree_impl.h" |
15 #include "mojo/common/common_type_converters.h" | 16 #include "mojo/common/common_type_converters.h" |
16 #include "mojo/converters/geometry/geometry_type_converters.h" | 17 #include "mojo/converters/geometry/geometry_type_converters.h" |
17 | 18 |
18 namespace mus { | 19 namespace mus { |
19 namespace ws { | 20 namespace ws { |
(...skipping 16 matching lines...) Expand all Loading... |
36 const scoped_refptr<GpuState>& gpu_state, | 37 const scoped_refptr<GpuState>& gpu_state, |
37 const scoped_refptr<SurfacesState>& surfaces_state, | 38 const scoped_refptr<SurfacesState>& surfaces_state, |
38 mojom::WindowManagerPtr window_manager) | 39 mojom::WindowManagerPtr window_manager) |
39 : delegate_(nullptr), | 40 : delegate_(nullptr), |
40 connection_manager_(connection_manager), | 41 connection_manager_(connection_manager), |
41 client_(client.Pass()), | 42 client_(client.Pass()), |
42 event_dispatcher_(this), | 43 event_dispatcher_(this), |
43 display_manager_( | 44 display_manager_( |
44 DisplayManager::Create(app_impl, gpu_state, surfaces_state)), | 45 DisplayManager::Create(app_impl, gpu_state, surfaces_state)), |
45 window_manager_(window_manager.Pass()), | 46 window_manager_(window_manager.Pass()), |
46 tree_awaiting_input_ack_(nullptr) { | 47 tree_awaiting_input_ack_(nullptr), |
| 48 last_cursor_(0) { |
47 display_manager_->Init(this); | 49 display_manager_->Init(this); |
48 if (client_) { | 50 if (client_) { |
49 client_.set_connection_error_handler(base::Bind( | 51 client_.set_connection_error_handler(base::Bind( |
50 &WindowTreeHostImpl::OnClientClosed, base::Unretained(this))); | 52 &WindowTreeHostImpl::OnClientClosed, base::Unretained(this))); |
51 } | 53 } |
52 } | 54 } |
53 | 55 |
54 WindowTreeHostImpl::~WindowTreeHostImpl() { | 56 WindowTreeHostImpl::~WindowTreeHostImpl() { |
55 DestroyFocusController(); | 57 DestroyFocusController(); |
56 for (ServerWindow* window : windows_needing_frame_destruction_) | 58 for (ServerWindow* window : windows_needing_frame_destruction_) |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
124 display_manager_->UpdateTextInputState(state); | 126 display_manager_->UpdateTextInputState(state); |
125 } | 127 } |
126 | 128 |
127 void WindowTreeHostImpl::SetImeVisibility(ServerWindow* window, bool visible) { | 129 void WindowTreeHostImpl::SetImeVisibility(ServerWindow* window, bool visible) { |
128 // Do not need to show or hide IME for unfocused window. | 130 // Do not need to show or hide IME for unfocused window. |
129 if (focus_controller_->GetFocusedWindow() != window) | 131 if (focus_controller_->GetFocusedWindow() != window) |
130 return; | 132 return; |
131 display_manager_->SetImeVisibility(visible); | 133 display_manager_->SetImeVisibility(visible); |
132 } | 134 } |
133 | 135 |
| 136 void WindowTreeHostImpl::OnCursorUpdated(ServerWindow* window) { |
| 137 if (window == event_dispatcher_.last_targeted_window()) |
| 138 UpdateNativeCursor(window->cursor()); |
| 139 } |
| 140 |
134 void WindowTreeHostImpl::SetSize(mojo::SizePtr size) { | 141 void WindowTreeHostImpl::SetSize(mojo::SizePtr size) { |
135 display_manager_->SetViewportSize(size.To<gfx::Size>()); | 142 display_manager_->SetViewportSize(size.To<gfx::Size>()); |
136 } | 143 } |
137 | 144 |
138 void WindowTreeHostImpl::SetTitle(const mojo::String& title) { | 145 void WindowTreeHostImpl::SetTitle(const mojo::String& title) { |
139 display_manager_->SetTitle(title.To<base::string16>()); | 146 display_manager_->SetTitle(title.To<base::string16>()); |
140 } | 147 } |
141 | 148 |
142 void WindowTreeHostImpl::AddAccelerator(uint32_t id, | 149 void WindowTreeHostImpl::AddAccelerator(uint32_t id, |
143 mojom::EventMatcherPtr event_matcher) { | 150 mojom::EventMatcherPtr event_matcher) { |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
207 } | 214 } |
208 | 215 |
209 void WindowTreeHostImpl::DispatchNextEventFromQueue() { | 216 void WindowTreeHostImpl::DispatchNextEventFromQueue() { |
210 if (event_queue_.empty()) | 217 if (event_queue_.empty()) |
211 return; | 218 return; |
212 mojom::EventPtr next_event = event_queue_.front().Pass(); | 219 mojom::EventPtr next_event = event_queue_.front().Pass(); |
213 event_queue_.pop(); | 220 event_queue_.pop(); |
214 event_dispatcher_.OnEvent(next_event.Pass()); | 221 event_dispatcher_.OnEvent(next_event.Pass()); |
215 } | 222 } |
216 | 223 |
| 224 void WindowTreeHostImpl::UpdateNativeCursor(int32_t cursor_id) { |
| 225 if (cursor_id != last_cursor_) { |
| 226 display_manager_->SetCursorById(cursor_id); |
| 227 last_cursor_ = cursor_id; |
| 228 } |
| 229 } |
| 230 |
217 ServerWindow* WindowTreeHostImpl::GetRootWindow() { | 231 ServerWindow* WindowTreeHostImpl::GetRootWindow() { |
218 return root_.get(); | 232 return root_.get(); |
219 } | 233 } |
220 | 234 |
221 void WindowTreeHostImpl::OnEvent(mojom::EventPtr event) { | 235 void WindowTreeHostImpl::OnEvent(mojom::EventPtr event) { |
222 // If this is still waiting for an ack from a previously sent event, then | 236 // If this is still waiting for an ack from a previously sent event, then |
223 // queue up the event to be dispatched once the ack is received. | 237 // queue up the event to be dispatched once the ack is received. |
224 if (event_ack_timer_.IsRunning()) { | 238 if (event_ack_timer_.IsRunning()) { |
225 // TODO(sad): Coalesce if possible. | 239 // TODO(sad): Coalesce if possible. |
226 event_queue_.push(event.Pass()); | 240 event_queue_.push(event.Pass()); |
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
356 } | 370 } |
357 | 371 |
358 ServerWindow* WindowTreeHostImpl::GetFocusedWindowForEventDispatcher() { | 372 ServerWindow* WindowTreeHostImpl::GetFocusedWindowForEventDispatcher() { |
359 return GetFocusedWindow(); | 373 return GetFocusedWindow(); |
360 } | 374 } |
361 | 375 |
362 void WindowTreeHostImpl::DispatchInputEventToWindow(ServerWindow* target, | 376 void WindowTreeHostImpl::DispatchInputEventToWindow(ServerWindow* target, |
363 bool in_nonclient_area, | 377 bool in_nonclient_area, |
364 mojom::EventPtr event) { | 378 mojom::EventPtr event) { |
365 DCHECK(!event_ack_timer_.IsRunning()); | 379 DCHECK(!event_ack_timer_.IsRunning()); |
| 380 if ((event->action == mojom::EventType::EVENT_TYPE_POINTER_CANCEL || |
| 381 event->action == mojom::EventType::EVENT_TYPE_POINTER_DOWN || |
| 382 event->action == mojom::EventType::EVENT_TYPE_POINTER_MOVE || |
| 383 event->action == mojom::EventType::EVENT_TYPE_POINTER_UP) && |
| 384 (event->pointer_data && |
| 385 event->pointer_data->kind == mojom::PointerKind::POINTER_KIND_MOUSE)) { |
| 386 UpdateNativeCursor(target->cursor()); |
| 387 } |
| 388 |
366 // If the event is in the non-client area the event goes to the owner of | 389 // If the event is in the non-client area the event goes to the owner of |
367 // the window. Otherwise if the window is an embed root, forward to the | 390 // the window. Otherwise if the window is an embed root, forward to the |
368 // embedded window. | 391 // embedded window. |
369 WindowTreeImpl* connection = | 392 WindowTreeImpl* connection = |
370 in_nonclient_area | 393 in_nonclient_area |
371 ? connection_manager_->GetConnection(target->id().connection_id) | 394 ? connection_manager_->GetConnection(target->id().connection_id) |
372 : connection_manager_->GetConnectionWithRoot(target->id()); | 395 : connection_manager_->GetConnectionWithRoot(target->id()); |
373 if (!connection) { | 396 if (!connection) { |
374 DCHECK(!in_nonclient_area); | 397 DCHECK(!in_nonclient_area); |
375 connection = connection_manager_->GetConnection(target->id().connection_id); | 398 connection = connection_manager_->GetConnection(target->id().connection_id); |
376 } | 399 } |
377 tree_awaiting_input_ack_ = connection; | 400 tree_awaiting_input_ack_ = connection; |
378 connection->DispatchInputEvent(target, event.Pass()); | 401 connection->DispatchInputEvent(target, event.Pass()); |
379 | 402 |
380 // TOOD(sad): Adjust this delay, possibly make this dynamic. | 403 // TOOD(sad): Adjust this delay, possibly make this dynamic. |
381 const base::TimeDelta max_delay = base::debug::BeingDebugged() | 404 const base::TimeDelta max_delay = base::debug::BeingDebugged() |
382 ? base::TimeDelta::FromDays(1) | 405 ? base::TimeDelta::FromDays(1) |
383 : GetDefaultAckTimerDelay(); | 406 : GetDefaultAckTimerDelay(); |
384 event_ack_timer_.Start(FROM_HERE, max_delay, this, | 407 event_ack_timer_.Start(FROM_HERE, max_delay, this, |
385 &WindowTreeHostImpl::OnEventAckTimeout); | 408 &WindowTreeHostImpl::OnEventAckTimeout); |
386 } | 409 } |
387 | 410 |
388 void WindowTreeHostImpl::OnWindowDestroyed(ServerWindow* window) { | 411 void WindowTreeHostImpl::OnWindowDestroyed(ServerWindow* window) { |
389 windows_needing_frame_destruction_.erase(window); | 412 windows_needing_frame_destruction_.erase(window); |
390 window->RemoveObserver(this); | 413 window->RemoveObserver(this); |
391 } | 414 } |
392 | 415 |
393 } // namespace ws | 416 } // namespace ws |
394 } // namespace mus | 417 } // namespace mus |
OLD | NEW |