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

Side by Side Diff: components/mus/ws/event_dispatcher.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: 3rd merge conflict today. 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
« no previous file with comments | « components/mus/ws/event_dispatcher.h ('k') | components/mus/ws/operation.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/event_dispatcher.h" 5 #include "components/mus/ws/event_dispatcher.h"
6 6
7 #include <set> 7 #include <set>
8 8
9 #include "cc/surfaces/surface_hittest.h" 9 #include "cc/surfaces/surface_hittest.h"
10 #include "components/mus/surfaces/surfaces_state.h" 10 #include "components/mus/surfaces/surfaces_state.h"
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after
132 mojom::EventType event_type_; 132 mojom::EventType event_type_;
133 mojom::EventFlags event_flags_; 133 mojom::EventFlags event_flags_;
134 mojom::KeyboardCode keyboard_code_; 134 mojom::KeyboardCode keyboard_code_;
135 mojom::PointerKind pointer_kind_; 135 mojom::PointerKind pointer_kind_;
136 gfx::RectF pointer_region_; 136 gfx::RectF pointer_region_;
137 }; 137 };
138 138
139 //////////////////////////////////////////////////////////////////////////////// 139 ////////////////////////////////////////////////////////////////////////////////
140 140
141 EventDispatcher::EventDispatcher(EventDispatcherDelegate* delegate) 141 EventDispatcher::EventDispatcher(EventDispatcherDelegate* delegate)
142 : delegate_(delegate), root_(nullptr) {} 142 : delegate_(delegate),
143 root_(nullptr),
144 mouse_button_down_(false),
145 mouse_cursor_source_window_(nullptr) {}
143 146
144 EventDispatcher::~EventDispatcher() { 147 EventDispatcher::~EventDispatcher() {
145 std::set<ServerWindow*> pointer_targets; 148 std::set<ServerWindow*> pointer_targets;
146 for (const auto& pair : pointer_targets_) { 149 for (const auto& pair : pointer_targets_) {
147 if (pair.second.window && 150 if (pair.second.window &&
148 pointer_targets.insert(pair.second.window).second) { 151 pointer_targets.insert(pair.second.window).second) {
149 pair.second.window->RemoveObserver(this); 152 pair.second.window->RemoveObserver(this);
150 } 153 }
151 } 154 }
152 } 155 }
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
214 gfx::Point location(EventLocationToPoint(*event)); 217 gfx::Point location(EventLocationToPoint(*event));
215 pointer_target.window = 218 pointer_target.window =
216 FindDeepestVisibleWindowForEvents(root_, surface_id_, &location); 219 FindDeepestVisibleWindowForEvents(root_, surface_id_, &location);
217 } 220 }
218 DispatchToPointerTarget(pointer_target, event.Pass()); 221 DispatchToPointerTarget(pointer_target, event.Pass());
219 return; 222 return;
220 } 223 }
221 224
222 // Pointer down implicitly captures. 225 // Pointer down implicitly captures.
223 if (pointer_targets_.count(pointer_id) == 0) { 226 if (pointer_targets_.count(pointer_id) == 0) {
224 DCHECK(event->action == mojom::EVENT_TYPE_POINTER_DOWN); 227 DCHECK(event->action == mojom::EVENT_TYPE_POINTER_DOWN);
sky 2015/12/03 03:23:18 This should be the place you add the logic for the
225 const bool is_first_pointer_down = pointer_targets_.empty(); 228 const bool is_first_pointer_down = pointer_targets_.empty();
226 gfx::Point location(EventLocationToPoint(*event)); 229 gfx::Point location(EventLocationToPoint(*event));
227 ServerWindow* target = 230 ServerWindow* target =
228 FindDeepestVisibleWindowForEvents(root_, surface_id_, &location); 231 FindDeepestVisibleWindowForEvents(root_, surface_id_, &location);
229 DCHECK(target); 232 DCHECK(target);
230 if (!IsObservingWindow(target)) 233 if (!IsObservingWindow(target))
231 target->AddObserver(this); 234 target->AddObserver(this);
232 235
233 pointer_targets_[pointer_id].window = target; 236 pointer_targets_[pointer_id].window = target;
234 pointer_targets_[pointer_id].in_nonclient_area = 237 pointer_targets_[pointer_id].in_nonclient_area =
235 IsLocationInNonclientArea(target, location); 238 IsLocationInNonclientArea(target, location);
236 239
237 if (is_first_pointer_down) 240 if (is_first_pointer_down)
238 delegate_->SetFocusedWindowFromEventDispatcher(target); 241 delegate_->SetFocusedWindowFromEventDispatcher(target);
239 } 242 }
240 243
241 // Release capture on pointer up. For mouse we only release if there are 244 // Release capture on pointer up. For mouse we only release if there are
242 // no buttons down. 245 // no buttons down.
243 const bool should_reset_target = 246 const bool should_reset_target =
244 (event->action == mojom::EVENT_TYPE_POINTER_UP || 247 (event->action == mojom::EVENT_TYPE_POINTER_UP ||
245 event->action == mojom::EVENT_TYPE_POINTER_CANCEL) && 248 event->action == mojom::EVENT_TYPE_POINTER_CANCEL) &&
246 (event->pointer_data->kind != mojom::POINTER_KIND_MOUSE || 249 (event->pointer_data->kind != mojom::POINTER_KIND_MOUSE ||
247 IsOnlyOneMouseButtonDown(event->flags)); 250 IsOnlyOneMouseButtonDown(event->flags));
248 251
249 DispatchToPointerTarget(pointer_targets_[pointer_id], event.Pass()); 252 DispatchToPointerTarget(pointer_targets_[pointer_id], event.Pass());
250 253
251 if (should_reset_target) { 254 if (should_reset_target) {
252 ServerWindow* target = pointer_targets_[pointer_id].window; 255 ServerWindow* target = pointer_targets_[pointer_id].window;
sky 2015/12/03 03:23:18 And this should be the place you add logic for the
253 pointer_targets_.erase(pointer_id); 256 pointer_targets_.erase(pointer_id);
254 if (target && !IsObservingWindow(target)) 257 if (target && !IsObservingWindow(target))
255 target->RemoveObserver(this); 258 target->RemoveObserver(this);
256 } 259 }
257 } 260 }
258 261
259 void EventDispatcher::DispatchToPointerTarget(const PointerTarget& target, 262 void EventDispatcher::DispatchToPointerTarget(const PointerTarget& target,
260 mojom::EventPtr event) { 263 mojom::EventPtr event) {
261 if (!target.window) 264 if (!target.window)
262 return; 265 return;
263 266
267 if (event->pointer_data->kind == mojom::PointerKind::POINTER_KIND_MOUSE) {
268 if (event->action == mojom::EventType::EVENT_TYPE_POINTER_MOVE) {
269 // Only change the last targeted window when we are moving without
270 // dragging.
271 if (!mouse_button_down_)
272 mouse_cursor_source_window_ = target.window;
273 } else if (event->action == mojom::EventType::EVENT_TYPE_POINTER_UP ||
274 event->action == mojom::EventType::EVENT_TYPE_POINTER_CANCEL) {
275 mouse_button_down_ = false;
276
277 // When we release the mouse button, we want the cursor to be sourced
278 // from the window under the mouse pointer, even though we're sending the
279 // button up event to the window that had implicit capture.
280 gfx::Point location(EventLocationToPoint(*event));
281 mouse_cursor_source_window_ =
282 FindDeepestVisibleWindowForEvents(root_, surface_id_, &location);
283 } else if (event->action == mojom::EventType::EVENT_TYPE_POINTER_DOWN) {
284 mouse_button_down_ = true;
285 mouse_cursor_source_window_ = target.window;
286 }
287 }
288
264 gfx::Point location(EventLocationToPoint(*event)); 289 gfx::Point location(EventLocationToPoint(*event));
265 gfx::Transform transform(GetTransformToWindow(surface_id_, target.window)); 290 gfx::Transform transform(GetTransformToWindow(surface_id_, target.window));
266 transform.TransformPoint(&location); 291 transform.TransformPoint(&location);
267 event->pointer_data->location->x = location.x(); 292 event->pointer_data->location->x = location.x();
268 event->pointer_data->location->y = location.y(); 293 event->pointer_data->location->y = location.y();
269 delegate_->DispatchInputEventToWindow(target.window, target.in_nonclient_area, 294 delegate_->DispatchInputEventToWindow(target.window, target.in_nonclient_area,
270 event.Pass()); 295 event.Pass());
271 } 296 }
272 297
273 void EventDispatcher::CancelPointerEventsToTarget(ServerWindow* window) { 298 void EventDispatcher::CancelPointerEventsToTarget(ServerWindow* window) {
(...skipping 30 matching lines...) Expand all
304 ServerWindow* old_parent) { 329 ServerWindow* old_parent) {
305 CancelPointerEventsToTarget(window); 330 CancelPointerEventsToTarget(window);
306 } 331 }
307 332
308 void EventDispatcher::OnWindowVisibilityChanged(ServerWindow* window) { 333 void EventDispatcher::OnWindowVisibilityChanged(ServerWindow* window) {
309 CancelPointerEventsToTarget(window); 334 CancelPointerEventsToTarget(window);
310 } 335 }
311 336
312 void EventDispatcher::OnWindowDestroyed(ServerWindow* window) { 337 void EventDispatcher::OnWindowDestroyed(ServerWindow* window) {
313 CancelPointerEventsToTarget(window); 338 CancelPointerEventsToTarget(window);
339
340 if (mouse_cursor_source_window_ == window)
341 mouse_cursor_source_window_ = nullptr;
314 } 342 }
315 343
316 } // namespace ws 344 } // namespace ws
317 } // namespace mus 345 } // namespace mus
OLDNEW
« no previous file with comments | « components/mus/ws/event_dispatcher.h ('k') | components/mus/ws/operation.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698