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/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 Loading... | |
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 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
208 (event->action == mojom::EVENT_TYPE_POINTER_MOVE && | 211 (event->action == mojom::EVENT_TYPE_POINTER_MOVE && |
209 pointer_targets_.count(pointer_id) == 0)) { | 212 pointer_targets_.count(pointer_id) == 0)) { |
210 PointerTarget pointer_target; | 213 PointerTarget pointer_target; |
211 if (pointer_targets_.count(pointer_id) != 0) { | 214 if (pointer_targets_.count(pointer_id) != 0) { |
212 pointer_target = pointer_targets_[pointer_id]; | 215 pointer_target = pointer_targets_[pointer_id]; |
213 } else { | 216 } else { |
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 } |
221 if (!mouse_button_down_) | |
222 mouse_cursor_source_window_ = pointer_target.window; | |
218 DispatchToPointerTarget(pointer_target, event.Pass()); | 223 DispatchToPointerTarget(pointer_target, event.Pass()); |
219 return; | 224 return; |
220 } | 225 } |
221 | 226 |
222 // Pointer down implicitly captures. | 227 // Pointer down implicitly captures. |
223 if (pointer_targets_.count(pointer_id) == 0) { | 228 if (pointer_targets_.count(pointer_id) == 0) { |
224 DCHECK(event->action == mojom::EVENT_TYPE_POINTER_DOWN); | 229 DCHECK(event->action == mojom::EVENT_TYPE_POINTER_DOWN); |
225 const bool is_first_pointer_down = pointer_targets_.empty(); | 230 const bool is_first_pointer_down = pointer_targets_.empty(); |
226 gfx::Point location(EventLocationToPoint(*event)); | 231 gfx::Point location(EventLocationToPoint(*event)); |
227 ServerWindow* target = | 232 ServerWindow* target = |
228 FindDeepestVisibleWindowForEvents(root_, surface_id_, &location); | 233 FindDeepestVisibleWindowForEvents(root_, surface_id_, &location); |
229 DCHECK(target); | 234 DCHECK(target); |
230 if (!IsObservingWindow(target)) | 235 if (!IsObservingWindow(target)) |
231 target->AddObserver(this); | 236 target->AddObserver(this); |
232 | 237 |
238 mouse_button_down_ = true; | |
sky
2015/12/03 22:01:10
This path is hit for both touch and mouse. Don't y
Elliot Glaysher
2015/12/03 22:32:00
Is it? In a previous comment you said this was onl
| |
239 mouse_cursor_source_window_ = target; | |
240 | |
233 pointer_targets_[pointer_id].window = target; | 241 pointer_targets_[pointer_id].window = target; |
234 pointer_targets_[pointer_id].in_nonclient_area = | 242 pointer_targets_[pointer_id].in_nonclient_area = |
235 IsLocationInNonclientArea(target, location); | 243 IsLocationInNonclientArea(target, location); |
236 | 244 |
237 if (is_first_pointer_down) | 245 if (is_first_pointer_down) |
238 delegate_->SetFocusedWindowFromEventDispatcher(target); | 246 delegate_->SetFocusedWindowFromEventDispatcher(target); |
239 } | 247 } |
240 | 248 |
241 // Release capture on pointer up. For mouse we only release if there are | 249 // Release capture on pointer up. For mouse we only release if there are |
242 // no buttons down. | 250 // no buttons down. |
243 const bool should_reset_target = | 251 const bool should_reset_target = |
244 (event->action == mojom::EVENT_TYPE_POINTER_UP || | 252 (event->action == mojom::EVENT_TYPE_POINTER_UP || |
245 event->action == mojom::EVENT_TYPE_POINTER_CANCEL) && | 253 event->action == mojom::EVENT_TYPE_POINTER_CANCEL) && |
246 (event->pointer_data->kind != mojom::POINTER_KIND_MOUSE || | 254 (event->pointer_data->kind != mojom::POINTER_KIND_MOUSE || |
247 IsOnlyOneMouseButtonDown(event->flags)); | 255 IsOnlyOneMouseButtonDown(event->flags)); |
248 | 256 |
257 if (should_reset_target && | |
258 event->pointer_data && | |
259 event->pointer_data->kind == mojom::PointerKind::POINTER_KIND_MOUSE) { | |
260 // When we release the mouse button, we want the cursor to be sourced from | |
261 // the window under the mouse pointer, even though we're sending the button | |
262 // up event to the window that had implicit capture. We have to set this | |
263 // before we perform dispatch because the Delegate is going to read this | |
264 // information from us. | |
265 mouse_button_down_ = false; | |
266 gfx::Point location(EventLocationToPoint(*event)); | |
267 mouse_cursor_source_window_ = | |
268 FindDeepestVisibleWindowForEvents(root_, surface_id_, &location); | |
269 } | |
270 | |
249 DispatchToPointerTarget(pointer_targets_[pointer_id], event.Pass()); | 271 DispatchToPointerTarget(pointer_targets_[pointer_id], event.Pass()); |
250 | 272 |
251 if (should_reset_target) { | 273 if (should_reset_target) { |
252 ServerWindow* target = pointer_targets_[pointer_id].window; | 274 ServerWindow* target = pointer_targets_[pointer_id].window; |
253 pointer_targets_.erase(pointer_id); | 275 pointer_targets_.erase(pointer_id); |
254 if (target && !IsObservingWindow(target)) | 276 if (target && !IsObservingWindow(target)) |
255 target->RemoveObserver(this); | 277 target->RemoveObserver(this); |
256 } | 278 } |
257 } | 279 } |
258 | 280 |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
304 ServerWindow* old_parent) { | 326 ServerWindow* old_parent) { |
305 CancelPointerEventsToTarget(window); | 327 CancelPointerEventsToTarget(window); |
306 } | 328 } |
307 | 329 |
308 void EventDispatcher::OnWindowVisibilityChanged(ServerWindow* window) { | 330 void EventDispatcher::OnWindowVisibilityChanged(ServerWindow* window) { |
309 CancelPointerEventsToTarget(window); | 331 CancelPointerEventsToTarget(window); |
310 } | 332 } |
311 | 333 |
312 void EventDispatcher::OnWindowDestroyed(ServerWindow* window) { | 334 void EventDispatcher::OnWindowDestroyed(ServerWindow* window) { |
313 CancelPointerEventsToTarget(window); | 335 CancelPointerEventsToTarget(window); |
336 | |
337 if (mouse_cursor_source_window_ == window) | |
338 mouse_cursor_source_window_ = nullptr; | |
314 } | 339 } |
315 | 340 |
316 } // namespace ws | 341 } // namespace ws |
317 } // namespace mus | 342 } // namespace mus |
OLD | NEW |