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

Side by Side Diff: components/mus/ws/window_tree_host_impl.cc

Issue 1465803003: mus: Let clients set the cursor of their window. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Sync pass the nacl breakage Created 5 years 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 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
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
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())
sky 2015/12/01 21:48:01 Doesn't this need to be more sophisticated? What i
Elliot Glaysher 2015/12/02 20:01:32 So I might just be wrong about this, but in event_
sky 2015/12/02 21:19:41 You are correct. We currently only have implicit c
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 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
204 } 211 }
205 212
206 void WindowTreeHostImpl::DispatchNextEventFromQueue() { 213 void WindowTreeHostImpl::DispatchNextEventFromQueue() {
207 if (event_queue_.empty()) 214 if (event_queue_.empty())
208 return; 215 return;
209 mojom::EventPtr next_event = event_queue_.front().Pass(); 216 mojom::EventPtr next_event = event_queue_.front().Pass();
210 event_queue_.pop(); 217 event_queue_.pop();
211 event_dispatcher_.OnEvent(next_event.Pass()); 218 event_dispatcher_.OnEvent(next_event.Pass());
212 } 219 }
213 220
221 void WindowTreeHostImpl::UpdateNativeCursor(int32_t cursor_id) {
222 if (cursor_id != last_cursor_) {
223 display_manager_->SetCursorById(cursor_id);
224 last_cursor_ = cursor_id;
225 }
226 }
227
214 ServerWindow* WindowTreeHostImpl::GetRootWindow() { 228 ServerWindow* WindowTreeHostImpl::GetRootWindow() {
215 return root_.get(); 229 return root_.get();
216 } 230 }
217 231
218 void WindowTreeHostImpl::OnEvent(mojom::EventPtr event) { 232 void WindowTreeHostImpl::OnEvent(mojom::EventPtr event) {
219 // If this is still waiting for an ack from a previously sent event, then 233 // If this is still waiting for an ack from a previously sent event, then
220 // queue up the event to be dispatched once the ack is received. 234 // queue up the event to be dispatched once the ack is received.
221 if (event_ack_timer_.IsRunning()) { 235 if (event_ack_timer_.IsRunning()) {
222 // TODO(sad): Coalesce if possible. 236 // TODO(sad): Coalesce if possible.
223 event_queue_.push(event.Pass()); 237 event_queue_.push(event.Pass());
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after
353 } 367 }
354 368
355 ServerWindow* WindowTreeHostImpl::GetFocusedWindowForEventDispatcher() { 369 ServerWindow* WindowTreeHostImpl::GetFocusedWindowForEventDispatcher() {
356 return GetFocusedWindow(); 370 return GetFocusedWindow();
357 } 371 }
358 372
359 void WindowTreeHostImpl::DispatchInputEventToWindow(ServerWindow* target, 373 void WindowTreeHostImpl::DispatchInputEventToWindow(ServerWindow* target,
360 bool in_nonclient_area, 374 bool in_nonclient_area,
361 mojom::EventPtr event) { 375 mojom::EventPtr event) {
362 DCHECK(!event_ack_timer_.IsRunning()); 376 DCHECK(!event_ack_timer_.IsRunning());
377 if (event->action == mojom::EventType::EVENT_TYPE_POINTER_CANCEL ||
378 event->action == mojom::EventType::EVENT_TYPE_POINTER_DOWN ||
379 event->action == mojom::EventType::EVENT_TYPE_POINTER_MOVE ||
380 event->action == mojom::EventType::EVENT_TYPE_POINTER_UP) {
381 UpdateNativeCursor(target->cursor());
382 }
383
363 // If the event is in the non-client area the event goes to the owner of 384 // If the event is in the non-client area the event goes to the owner of
364 // the window. Otherwise if the window is an embed root, forward to the 385 // the window. Otherwise if the window is an embed root, forward to the
365 // embedded window. 386 // embedded window.
366 WindowTreeImpl* connection = 387 WindowTreeImpl* connection =
367 in_nonclient_area 388 in_nonclient_area
368 ? connection_manager_->GetConnection(target->id().connection_id) 389 ? connection_manager_->GetConnection(target->id().connection_id)
369 : connection_manager_->GetConnectionWithRoot(target->id()); 390 : connection_manager_->GetConnectionWithRoot(target->id());
370 if (!connection) { 391 if (!connection) {
371 DCHECK(!in_nonclient_area); 392 DCHECK(!in_nonclient_area);
372 connection = connection_manager_->GetConnection(target->id().connection_id); 393 connection = connection_manager_->GetConnection(target->id().connection_id);
373 } 394 }
374 tree_awaiting_input_ack_ = connection; 395 tree_awaiting_input_ack_ = connection;
375 connection->DispatchInputEvent(target, event.Pass()); 396 connection->DispatchInputEvent(target, event.Pass());
376 397
377 // TOOD(sad): Adjust this delay, possibly make this dynamic. 398 // TOOD(sad): Adjust this delay, possibly make this dynamic.
378 const base::TimeDelta max_delay = base::debug::BeingDebugged() 399 const base::TimeDelta max_delay = base::debug::BeingDebugged()
379 ? base::TimeDelta::FromDays(1) 400 ? base::TimeDelta::FromDays(1)
380 : GetDefaultAckTimerDelay(); 401 : GetDefaultAckTimerDelay();
381 event_ack_timer_.Start(FROM_HERE, max_delay, this, 402 event_ack_timer_.Start(FROM_HERE, max_delay, this,
382 &WindowTreeHostImpl::OnEventAckTimeout); 403 &WindowTreeHostImpl::OnEventAckTimeout);
383 } 404 }
384 405
385 void WindowTreeHostImpl::OnWindowDestroyed(ServerWindow* window) { 406 void WindowTreeHostImpl::OnWindowDestroyed(ServerWindow* window) {
386 windows_needing_frame_destruction_.erase(window); 407 windows_needing_frame_destruction_.erase(window);
387 window->RemoveObserver(this); 408 window->RemoveObserver(this);
388 } 409 }
389 410
390 } // namespace ws 411 } // namespace ws
391 } // namespace mus 412 } // namespace mus
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698