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

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

Issue 1759523002: mus: Server-side implementation of modal windows (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: SetAsModal -> SetModal + Other review comments addressed Created 4 years, 9 months 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/event_dispatcher_unittest.cc » ('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 "base/time/time.h" 9 #include "base/time/time.h"
10 #include "cc/surfaces/surface_hittest.h" 10 #include "cc/surfaces/surface_hittest.h"
(...skipping 217 matching lines...) Expand 10 before | Expand all | Expand 10 after
228 mouse_button_down_ = false; 228 mouse_button_down_ = false;
229 } 229 }
230 230
231 void EventDispatcher::SetMousePointerScreenLocation( 231 void EventDispatcher::SetMousePointerScreenLocation(
232 const gfx::Point& screen_location) { 232 const gfx::Point& screen_location) {
233 DCHECK(pointer_targets_.empty()); 233 DCHECK(pointer_targets_.empty());
234 mouse_pointer_last_location_ = screen_location; 234 mouse_pointer_last_location_ = screen_location;
235 UpdateCursorProviderByLastKnownLocation(); 235 UpdateCursorProviderByLastKnownLocation();
236 } 236 }
237 237
238 void EventDispatcher::SetCaptureWindow(ServerWindow* window, 238 bool EventDispatcher::SetCaptureWindow(ServerWindow* window,
239 bool in_nonclient_area) { 239 bool in_nonclient_area) {
240 if (window == capture_window_) 240 if (window == capture_window_)
241 return; 241 return true;
242
243 // A window that is blocked by a modal window cannot gain capture.
244 if (window && window->IsBlockedByModalWindow())
245 return false;
242 246
243 if (capture_window_) { 247 if (capture_window_) {
244 // Stop observing old capture window. |pointer_targets_| are cleared on 248 // Stop observing old capture window. |pointer_targets_| are cleared on
245 // intial setting of a capture window. 249 // initial setting of a capture window.
246 delegate_->OnServerWindowCaptureLost(capture_window_); 250 delegate_->OnServerWindowCaptureLost(capture_window_);
247 capture_window_->RemoveObserver(this); 251 capture_window_->RemoveObserver(this);
248 } else { 252 } else {
249 // Cancel implicit capture to all other windows. 253 // Cancel implicit capture to all other windows.
250 std::set<ServerWindow*> unobserved_windows; 254 std::set<ServerWindow*> unobserved_windows;
251 for (const auto& pair : pointer_targets_) { 255 for (const auto& pair : pointer_targets_) {
252 ServerWindow* target = pair.second.window; 256 ServerWindow* target = pair.second.window;
253 if (!target) 257 if (!target)
254 continue; 258 continue;
255 if (unobserved_windows.insert(target).second) 259 if (unobserved_windows.insert(target).second)
256 target->RemoveObserver(this); 260 target->RemoveObserver(this);
257 if (target == window) 261 if (target == window)
258 continue; 262 continue;
259 263
260 ui::EventType event_type = pair.second.is_mouse_event 264 ui::EventType event_type = pair.second.is_mouse_event
261 ? ui::ET_POINTER_EXITED 265 ? ui::ET_POINTER_EXITED
262 : ui::ET_POINTER_CANCELLED; 266 : ui::ET_POINTER_CANCELLED;
263 ui::EventPointerType pointer_type = 267 ui::EventPointerType pointer_type =
264 pair.second.is_mouse_event ? ui::EventPointerType::POINTER_TYPE_MOUSE 268 pair.second.is_mouse_event ? ui::EventPointerType::POINTER_TYPE_MOUSE
265 : ui::EventPointerType::POINTER_TYPE_TOUCH; 269 : ui::EventPointerType::POINTER_TYPE_TOUCH;
266 // TODO(jonross): Track previous location in PointerTarget for sending 270 // TODO(jonross): Track previous location in PointerTarget for sending
267 // cancels 271 // cancels.
268 ui::PointerEvent event(event_type, pointer_type, gfx::Point(), 272 ui::PointerEvent event(event_type, pointer_type, gfx::Point(),
269 gfx::Point(), ui::EF_NONE, pair.first, 273 gfx::Point(), ui::EF_NONE, pair.first,
270 ui::EventTimeForNow()); 274 ui::EventTimeForNow());
271 DispatchToPointerTarget(pair.second, event); 275 DispatchToPointerTarget(pair.second, event);
272 } 276 }
273 pointer_targets_.clear(); 277 pointer_targets_.clear();
274 } 278 }
275 279
276 // Begin tracking the capture window if it is not yet being observed. 280 // Begin tracking the capture window if it is not yet being observed.
277 if (window) { 281 if (window) {
278 window->AddObserver(this); 282 window->AddObserver(this);
279 if (!capture_window_) 283 if (!capture_window_)
280 delegate_->SetNativeCapture(); 284 delegate_->SetNativeCapture();
281 } else { 285 } else {
282 delegate_->ReleaseNativeCapture(); 286 delegate_->ReleaseNativeCapture();
283 if (!mouse_button_down_) 287 if (!mouse_button_down_)
284 UpdateCursorProviderByLastKnownLocation(); 288 UpdateCursorProviderByLastKnownLocation();
285 } 289 }
286 290
287 capture_window_ = window; 291 capture_window_ = window;
288 capture_window_in_nonclient_area_ = in_nonclient_area; 292 capture_window_in_nonclient_area_ = in_nonclient_area;
293 return true;
289 } 294 }
290 295
291 void EventDispatcher::UpdateCursorProviderByLastKnownLocation() { 296 void EventDispatcher::UpdateCursorProviderByLastKnownLocation() {
292 if (!mouse_button_down_) { 297 if (!mouse_button_down_) {
293 gfx::Point location = mouse_pointer_last_location_; 298 gfx::Point location = mouse_pointer_last_location_;
294 mouse_cursor_source_window_ = 299 mouse_cursor_source_window_ =
295 FindDeepestVisibleWindowForEvents(root_, surface_id_, &location); 300 FindDeepestVisibleWindowForEvents(root_, surface_id_, &location);
296 } 301 }
297 } 302 }
298 303
(...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after
463 // Technically we're updating in place, but calling start then stop makes for 468 // Technically we're updating in place, but calling start then stop makes for
464 // simpler code. 469 // simpler code.
465 StopTrackingPointer(pointer_id); 470 StopTrackingPointer(pointer_id);
466 StartTrackingPointer(pointer_id, pointer_target); 471 StartTrackingPointer(pointer_id, pointer_target);
467 } 472 }
468 473
469 EventDispatcher::PointerTarget EventDispatcher::PointerTargetForEvent( 474 EventDispatcher::PointerTarget EventDispatcher::PointerTargetForEvent(
470 const ui::PointerEvent& event) const { 475 const ui::PointerEvent& event) const {
471 PointerTarget pointer_target; 476 PointerTarget pointer_target;
472 gfx::Point location(event.location()); 477 gfx::Point location(event.location());
473 pointer_target.window = 478 ServerWindow* target_window =
474 FindDeepestVisibleWindowForEvents(root_, surface_id_, &location); 479 FindDeepestVisibleWindowForEvents(root_, surface_id_, &location);
480 pointer_target.window = target_window->GetModalTarget();
475 pointer_target.is_mouse_event = event.IsMousePointerEvent(); 481 pointer_target.is_mouse_event = event.IsMousePointerEvent();
476 pointer_target.in_nonclient_area = 482 pointer_target.in_nonclient_area =
483 target_window != pointer_target.window ||
477 IsLocationInNonclientArea(pointer_target.window, location); 484 IsLocationInNonclientArea(pointer_target.window, location);
478 pointer_target.is_pointer_down = event.type() == ui::ET_POINTER_DOWN; 485 pointer_target.is_pointer_down = event.type() == ui::ET_POINTER_DOWN;
479 return pointer_target; 486 return pointer_target;
480 } 487 }
481 488
482 bool EventDispatcher::AreAnyPointersDown() const { 489 bool EventDispatcher::AreAnyPointersDown() const {
483 for (const auto& pair : pointer_targets_) { 490 for (const auto& pair : pointer_targets_) {
484 if (pair.second.is_pointer_down) 491 if (pair.second.is_pointer_down)
485 return true; 492 return true;
486 } 493 }
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
554 561
555 void EventDispatcher::OnWindowDestroyed(ServerWindow* window) { 562 void EventDispatcher::OnWindowDestroyed(ServerWindow* window) {
556 CancelPointerEventsToTarget(window); 563 CancelPointerEventsToTarget(window);
557 564
558 if (mouse_cursor_source_window_ == window) 565 if (mouse_cursor_source_window_ == window)
559 mouse_cursor_source_window_ = nullptr; 566 mouse_cursor_source_window_ = nullptr;
560 } 567 }
561 568
562 } // namespace ws 569 } // namespace ws
563 } // namespace mus 570 } // namespace mus
OLDNEW
« no previous file with comments | « components/mus/ws/event_dispatcher.h ('k') | components/mus/ws/event_dispatcher_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698