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

Side by Side Diff: third_party/WebKit/Source/core/input/EventHandler.cpp

Issue 1463823003: Return a enumeration of the state of handling of InputEvents. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix drag layout test 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 /* 1 /*
2 * Copyright (C) 2006, 2007, 2008, 2009, 2010, 2011 Apple Inc. All rights reserv ed. 2 * Copyright (C) 2006, 2007, 2008, 2009, 2010, 2011 Apple Inc. All rights reserv ed.
3 * Copyright (C) 2006 Alexey Proskuryakov (ap@webkit.org) 3 * Copyright (C) 2006 Alexey Proskuryakov (ap@webkit.org)
4 * Copyright (C) 2012 Digia Plc. and/or its subsidiary(-ies) 4 * Copyright (C) 2012 Digia Plc. and/or its subsidiary(-ies)
5 * 5 *
6 * Redistribution and use in source and binary forms, with or without 6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions 7 * modification, are permitted provided that the following conditions
8 * are met: 8 * are met:
9 * 1. Redistributions of source code must retain the above copyright 9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer. 10 * notice, this list of conditions and the following disclaimer.
(...skipping 24 matching lines...) Expand all
35 #include "core/clipboard/DataTransfer.h" 35 #include "core/clipboard/DataTransfer.h"
36 #include "core/dom/Document.h" 36 #include "core/dom/Document.h"
37 #include "core/dom/TouchList.h" 37 #include "core/dom/TouchList.h"
38 #include "core/dom/shadow/ComposedTreeTraversal.h" 38 #include "core/dom/shadow/ComposedTreeTraversal.h"
39 #include "core/dom/shadow/ShadowRoot.h" 39 #include "core/dom/shadow/ShadowRoot.h"
40 #include "core/editing/Editor.h" 40 #include "core/editing/Editor.h"
41 #include "core/editing/FrameSelection.h" 41 #include "core/editing/FrameSelection.h"
42 #include "core/editing/SelectionController.h" 42 #include "core/editing/SelectionController.h"
43 #include "core/events/DragEvent.h" 43 #include "core/events/DragEvent.h"
44 #include "core/events/EventPath.h" 44 #include "core/events/EventPath.h"
45 #include "core/events/GestureEvent.h"
45 #include "core/events/KeyboardEvent.h" 46 #include "core/events/KeyboardEvent.h"
46 #include "core/events/MouseEvent.h" 47 #include "core/events/MouseEvent.h"
47 #include "core/events/PointerEvent.h" 48 #include "core/events/PointerEvent.h"
48 #include "core/events/TextEvent.h" 49 #include "core/events/TextEvent.h"
49 #include "core/events/TouchEvent.h" 50 #include "core/events/TouchEvent.h"
50 #include "core/events/WheelEvent.h" 51 #include "core/events/WheelEvent.h"
51 #include "core/fetch/ImageResource.h" 52 #include "core/fetch/ImageResource.h"
52 #include "core/frame/EventHandlerRegistry.h" 53 #include "core/frame/EventHandlerRegistry.h"
53 #include "core/frame/FrameHost.h" 54 #include "core/frame/FrameHost.h"
54 #include "core/frame/FrameView.h" 55 #include "core/frame/FrameView.h"
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
96 #include "platform/scroll/Scrollbar.h" 97 #include "platform/scroll/Scrollbar.h"
97 #include "wtf/Assertions.h" 98 #include "wtf/Assertions.h"
98 #include "wtf/CurrentTime.h" 99 #include "wtf/CurrentTime.h"
99 #include "wtf/StdLibExtras.h" 100 #include "wtf/StdLibExtras.h"
100 #include "wtf/TemporaryChange.h" 101 #include "wtf/TemporaryChange.h"
101 102
102 namespace blink { 103 namespace blink {
103 104
104 namespace { 105 namespace {
105 106
107 WebInputEventResult mergeEventResult(WebInputEventResult responseA, WebInputEven tResult responseB)
Rick Byers 2015/11/27 21:31:53 This deserves a comment I think (and probably a wa
dtapuska 2015/11/30 16:15:43 done; and static asserts added
108 {
109 return static_cast<WebInputEventResult>(max(static_cast<int>(responseA), sta tic_cast<int>(responseB)));
110 }
111
112 WebInputEventResult eventToEventResult(PassRefPtrWillBeRawPtr<Event> event, bool res)
113 {
114 if (event->defaultPrevented())
115 return WebInputEventResult::HandledApplication;
116 if (event->defaultHandled())
117 return WebInputEventResult::HandledSystem;
118
119 // TODO(dtapuska): There are cases in the code where dispatchEvent
120 // returns false (indicated handled) but event is not marked
121 // as default handled or default prevented. crbug.com/560355
122 if (!res)
123 return WebInputEventResult::HandledSuppressed;
124 return WebInputEventResult::NotHandled;
125 }
126
106 bool isNodeInDocument(Node* n) 127 bool isNodeInDocument(Node* n)
107 { 128 {
108 return n && n->inDocument(); 129 return n && n->inDocument();
109 } 130 }
110 131
111 const AtomicString& touchEventNameForTouchPointState(PlatformTouchPoint::State s tate) 132 const AtomicString& touchEventNameForTouchPointState(PlatformTouchPoint::State s tate)
112 { 133 {
113 switch (state) { 134 switch (state) {
114 case PlatformTouchPoint::TouchReleased: 135 case PlatformTouchPoint::TouchReleased:
115 return EventTypeNames::touchend; 136 return EventTypeNames::touchend;
(...skipping 277 matching lines...) Expand 10 before | Expand all | Expand 10 after
393 414
394 void EventHandler::nodeWillBeRemoved(Node& nodeToBeRemoved) 415 void EventHandler::nodeWillBeRemoved(Node& nodeToBeRemoved)
395 { 416 {
396 if (nodeToBeRemoved.containsIncludingShadowDOM(m_clickNode.get())) { 417 if (nodeToBeRemoved.containsIncludingShadowDOM(m_clickNode.get())) {
397 // We don't dispatch click events if the mousedown node is removed 418 // We don't dispatch click events if the mousedown node is removed
398 // before a mouseup event. It is compatible with IE and Firefox. 419 // before a mouseup event. It is compatible with IE and Firefox.
399 m_clickNode = nullptr; 420 m_clickNode = nullptr;
400 } 421 }
401 } 422 }
402 423
403 bool EventHandler::handleMousePressEvent(const MouseEventWithHitTestResults& eve nt) 424 WebInputEventResult EventHandler::handleMousePressEvent(const MouseEventWithHitT estResults& event)
404 { 425 {
405 TRACE_EVENT0("blink", "EventHandler::handleMousePressEvent"); 426 TRACE_EVENT0("blink", "EventHandler::handleMousePressEvent");
406 427
407 // Reset drag state. 428 // Reset drag state.
408 dragState().m_dragSrc = nullptr; 429 dragState().m_dragSrc = nullptr;
409 430
410 cancelFakeMouseMoveEvent(); 431 cancelFakeMouseMoveEvent();
411 432
412 m_frame->document()->updateLayoutIgnorePendingStylesheets(); 433 m_frame->document()->updateLayoutIgnorePendingStylesheets();
413 434
414 if (FrameView* frameView = m_frame->view()) { 435 if (FrameView* frameView = m_frame->view()) {
415 if (frameView->isPointInScrollbarCorner(event.event().position())) 436 if (frameView->isPointInScrollbarCorner(event.event().position()))
416 return false; 437 return WebInputEventResult::NotHandled;
417 } 438 }
418 439
419 bool singleClick = event.event().clickCount() <= 1; 440 bool singleClick = event.event().clickCount() <= 1;
420 441
421 m_mouseDownMayStartDrag = singleClick; 442 m_mouseDownMayStartDrag = singleClick;
422 443
423 selectionController().handleMousePressEvent(event); 444 selectionController().handleMousePressEvent(event);
424 445
425 m_mouseDown = event.event(); 446 m_mouseDown = event.event();
426 447
427 if (m_frame->document()->isSVGDocument() && m_frame->document()->accessSVGEx tensions().zoomAndPanEnabled()) { 448 if (m_frame->document()->isSVGDocument() && m_frame->document()->accessSVGEx tensions().zoomAndPanEnabled()) {
428 if (event.event().shiftKey() && singleClick) { 449 if (event.event().shiftKey() && singleClick) {
429 m_svgPan = true; 450 m_svgPan = true;
430 m_frame->document()->accessSVGExtensions().startPan(m_frame->view()- >rootFrameToContents(event.event().position())); 451 m_frame->document()->accessSVGExtensions().startPan(m_frame->view()- >rootFrameToContents(event.event().position()));
431 return true; 452 return WebInputEventResult::HandledSystem;
432 } 453 }
433 } 454 }
434 455
435 // We don't do this at the start of mouse down handling, 456 // We don't do this at the start of mouse down handling,
436 // because we don't want to do it until we know we didn't hit a widget. 457 // because we don't want to do it until we know we didn't hit a widget.
437 if (singleClick) 458 if (singleClick)
438 focusDocumentView(); 459 focusDocumentView();
439 460
440 Node* innerNode = event.innerNode(); 461 Node* innerNode = event.innerNode();
441 462
442 m_mousePressNode = innerNode; 463 m_mousePressNode = innerNode;
443 m_dragStartPos = event.event().position(); 464 m_dragStartPos = event.event().position();
444 465
445 bool swallowEvent = false; 466 bool swallowEvent = false;
446 m_mousePressed = true; 467 m_mousePressed = true;
447 468
448 if (event.event().clickCount() == 2) 469 if (event.event().clickCount() == 2)
449 swallowEvent = selectionController().handleMousePressEventDoubleClick(ev ent); 470 swallowEvent = selectionController().handleMousePressEventDoubleClick(ev ent);
450 else if (event.event().clickCount() >= 3) 471 else if (event.event().clickCount() >= 3)
451 swallowEvent = selectionController().handleMousePressEventTripleClick(ev ent); 472 swallowEvent = selectionController().handleMousePressEventTripleClick(ev ent);
452 else 473 else
453 swallowEvent = selectionController().handleMousePressEventSingleClick(ev ent); 474 swallowEvent = selectionController().handleMousePressEventSingleClick(ev ent);
454 475
455 m_mouseDownMayStartAutoscroll = selectionController().mouseDownMayStartSelec t() 476 m_mouseDownMayStartAutoscroll = selectionController().mouseDownMayStartSelec t()
456 || (m_mousePressNode && m_mousePressNode->layoutBox() && m_mousePressNod e->layoutBox()->canBeProgramaticallyScrolled()); 477 || (m_mousePressNode && m_mousePressNode->layoutBox() && m_mousePressNod e->layoutBox()->canBeProgramaticallyScrolled());
457 478
458 return swallowEvent; 479 return swallowEvent ? WebInputEventResult::HandledSystem : WebInputEventResu lt::NotHandled;
459 } 480 }
460 481
461 bool EventHandler::handleMouseDraggedEvent(const MouseEventWithHitTestResults& e vent) 482 WebInputEventResult EventHandler::handleMouseDraggedEvent(const MouseEventWithHi tTestResults& event)
462 { 483 {
463 TRACE_EVENT0("blink", "EventHandler::handleMouseDraggedEvent"); 484 TRACE_EVENT0("blink", "EventHandler::handleMouseDraggedEvent");
464 485
465 // While resetting m_mousePressed here may seem out of place, it turns out 486 // While resetting m_mousePressed here may seem out of place, it turns out
466 // to be needed to handle some bugs^Wfeatures in Blink mouse event handling: 487 // to be needed to handle some bugs^Wfeatures in Blink mouse event handling:
467 // 1. Certain elements, such as <embed>, capture mouse events. They do not 488 // 1. Certain elements, such as <embed>, capture mouse events. They do not
468 // bubble back up. One way for a <embed> to start capturing mouse events 489 // bubble back up. One way for a <embed> to start capturing mouse events
469 // is on a mouse press. The problem is the <embed> node only starts 490 // is on a mouse press. The problem is the <embed> node only starts
470 // capturing mouse events *after* m_mousePressed for the containing frame 491 // capturing mouse events *after* m_mousePressed for the containing frame
471 // has already been set to true. As a result, the frame's EventHandler 492 // has already been set to true. As a result, the frame's EventHandler
472 // never sees the mouse release event, which is supposed to reset 493 // never sees the mouse release event, which is supposed to reset
473 // m_mousePressed... so m_mousePressed ends up remaining true until the 494 // m_mousePressed... so m_mousePressed ends up remaining true until the
474 // event handler finally gets another mouse released event. Oops. 495 // event handler finally gets another mouse released event. Oops.
475 // 2. Dragging doesn't start until after a mouse press event, but a drag 496 // 2. Dragging doesn't start until after a mouse press event, but a drag
476 // that ends as a result of a mouse release does not send a mouse release 497 // that ends as a result of a mouse release does not send a mouse release
477 // event. As a result, m_mousePressed also ends up remaining true until 498 // event. As a result, m_mousePressed also ends up remaining true until
478 // the next mouse release event seen by the EventHandler. 499 // the next mouse release event seen by the EventHandler.
479 if (event.event().button() != LeftButton) 500 if (event.event().button() != LeftButton)
480 m_mousePressed = false; 501 m_mousePressed = false;
481 502
482 if (!m_mousePressed) 503 if (!m_mousePressed)
483 return false; 504 return WebInputEventResult::NotHandled;
484 505
485 if (handleDrag(event, DragInitiator::Mouse)) 506 if (handleDrag(event, DragInitiator::Mouse))
486 return true; 507 return WebInputEventResult::HandledSystem;
487 508
488 Node* targetNode = event.innerNode(); 509 Node* targetNode = event.innerNode();
489 if (!targetNode) 510 if (!targetNode)
490 return false; 511 return WebInputEventResult::NotHandled;
491 512
492 LayoutObject* layoutObject = targetNode->layoutObject(); 513 LayoutObject* layoutObject = targetNode->layoutObject();
493 if (!layoutObject) { 514 if (!layoutObject) {
494 Node* parent = ComposedTreeTraversal::parent(*targetNode); 515 Node* parent = ComposedTreeTraversal::parent(*targetNode);
495 if (!parent) 516 if (!parent)
496 return false; 517 return WebInputEventResult::NotHandled;
497 518
498 layoutObject = parent->layoutObject(); 519 layoutObject = parent->layoutObject();
499 if (!layoutObject || !layoutObject->isListBox()) 520 if (!layoutObject || !layoutObject->isListBox())
500 return false; 521 return WebInputEventResult::NotHandled;
501 } 522 }
502 523
503 m_mouseDownMayStartDrag = false; 524 m_mouseDownMayStartDrag = false;
504 525
505 if (m_mouseDownMayStartAutoscroll && !panScrollInProgress()) { 526 if (m_mouseDownMayStartAutoscroll && !panScrollInProgress()) {
506 if (AutoscrollController* controller = autoscrollController()) { 527 if (AutoscrollController* controller = autoscrollController()) {
507 controller->startAutoscrollForSelection(layoutObject); 528 controller->startAutoscrollForSelection(layoutObject);
508 m_mouseDownMayStartAutoscroll = false; 529 m_mouseDownMayStartAutoscroll = false;
509 } 530 }
510 } 531 }
511 532
512 selectionController().handleMouseDraggedEvent(event, m_mouseDownPos, m_dragS tartPos, m_mousePressNode.get(), m_lastKnownMousePosition); 533 selectionController().handleMouseDraggedEvent(event, m_mouseDownPos, m_dragS tartPos, m_mousePressNode.get(), m_lastKnownMousePosition);
513 return true; 534 return WebInputEventResult::HandledSystem;
514 } 535 }
515 536
516 void EventHandler::updateSelectionForMouseDrag() 537 void EventHandler::updateSelectionForMouseDrag()
517 { 538 {
518 selectionController().updateSelectionForMouseDrag(m_mousePressNode.get(), m_ dragStartPos, m_lastKnownMousePosition); 539 selectionController().updateSelectionForMouseDrag(m_mousePressNode.get(), m_ dragStartPos, m_lastKnownMousePosition);
519 } 540 }
520 541
521 bool EventHandler::handleMouseReleaseEvent(const MouseEventWithHitTestResults& e vent) 542 WebInputEventResult EventHandler::handleMouseReleaseEvent(const MouseEventWithHi tTestResults& event)
522 { 543 {
523 AutoscrollController* controller = autoscrollController(); 544 AutoscrollController* controller = autoscrollController();
524 if (controller && controller->autoscrollInProgress()) 545 if (controller && controller->autoscrollInProgress())
525 stopAutoscroll(); 546 stopAutoscroll();
526 547
527 // Used to prevent mouseMoveEvent from initiating a drag before 548 // Used to prevent mouseMoveEvent from initiating a drag before
528 // the mouse is pressed again. 549 // the mouse is pressed again.
529 m_mousePressed = false; 550 m_mousePressed = false;
530 m_capturesDragging = false; 551 m_capturesDragging = false;
531 m_mouseDownMayStartDrag = false; 552 m_mouseDownMayStartDrag = false;
532 m_mouseDownMayStartAutoscroll = false; 553 m_mouseDownMayStartAutoscroll = false;
533 554
534 return selectionController().handleMouseReleaseEvent(event, m_dragStartPos); 555 return selectionController().handleMouseReleaseEvent(event, m_dragStartPos) ? WebInputEventResult::HandledSystem : WebInputEventResult::NotHandled;
535 } 556 }
536 557
537 #if OS(WIN) 558 #if OS(WIN)
538 559
539 void EventHandler::startPanScrolling(LayoutObject* layoutObject) 560 void EventHandler::startPanScrolling(LayoutObject* layoutObject)
540 { 561 {
541 if (!layoutObject->isBox()) 562 if (!layoutObject->isBox())
542 return; 563 return;
543 AutoscrollController* controller = autoscrollController(); 564 AutoscrollController* controller = autoscrollController();
544 if (!controller) 565 if (!controller)
(...skipping 396 matching lines...) Expand 10 before | Expand all | Expand 10 after
941 } 962 }
942 963
943 static LayoutPoint contentPointFromRootFrame(LocalFrame* frame, const IntPoint& pointInRootFrame) 964 static LayoutPoint contentPointFromRootFrame(LocalFrame* frame, const IntPoint& pointInRootFrame)
944 { 965 {
945 FrameView* view = frame->view(); 966 FrameView* view = frame->view();
946 // FIXME: Is it really OK to use the wrong coordinates here when view is 0? 967 // FIXME: Is it really OK to use the wrong coordinates here when view is 0?
947 // Historically the code would just crash; this is clearly no worse than tha t. 968 // Historically the code would just crash; this is clearly no worse than tha t.
948 return view ? view->rootFrameToContents(pointInRootFrame) : pointInRootFrame ; 969 return view ? view->rootFrameToContents(pointInRootFrame) : pointInRootFrame ;
949 } 970 }
950 971
951 bool EventHandler::handleMousePressEvent(const PlatformMouseEvent& mouseEvent) 972 WebInputEventResult EventHandler::handleMousePressEvent(const PlatformMouseEvent & mouseEvent)
952 { 973 {
953 TRACE_EVENT0("blink", "EventHandler::handleMousePressEvent"); 974 TRACE_EVENT0("blink", "EventHandler::handleMousePressEvent");
954 975
955 RefPtrWillBeRawPtr<FrameView> protector(m_frame->view()); 976 RefPtrWillBeRawPtr<FrameView> protector(m_frame->view());
956 977
957 UserGestureIndicator gestureIndicator(DefinitelyProcessingUserGesture); 978 UserGestureIndicator gestureIndicator(DefinitelyProcessingUserGesture);
958 m_frame->localFrameRoot()->eventHandler().m_lastMouseDownUserGestureToken = gestureIndicator.currentToken(); 979 m_frame->localFrameRoot()->eventHandler().m_lastMouseDownUserGestureToken = gestureIndicator.currentToken();
959 980
960 cancelFakeMouseMoveEvent(); 981 cancelFakeMouseMoveEvent();
961 if (m_eventHandlerWillResetCapturingMouseEventsNode) 982 if (m_eventHandlerWillResetCapturingMouseEventsNode)
962 m_capturingMouseEventsNode = nullptr; 983 m_capturingMouseEventsNode = nullptr;
963 m_mousePressed = true; 984 m_mousePressed = true;
964 m_capturesDragging = true; 985 m_capturesDragging = true;
965 setLastKnownMousePosition(mouseEvent); 986 setLastKnownMousePosition(mouseEvent);
966 m_mouseDownTimestamp = mouseEvent.timestamp(); 987 m_mouseDownTimestamp = mouseEvent.timestamp();
967 m_mouseDownMayStartDrag = false; 988 m_mouseDownMayStartDrag = false;
968 selectionController().setMouseDownMayStartSelect(false); 989 selectionController().setMouseDownMayStartSelect(false);
969 m_mouseDownMayStartAutoscroll = false; 990 m_mouseDownMayStartAutoscroll = false;
970 if (FrameView* view = m_frame->view()) { 991 if (FrameView* view = m_frame->view()) {
971 m_mouseDownPos = view->rootFrameToContents(mouseEvent.position()); 992 m_mouseDownPos = view->rootFrameToContents(mouseEvent.position());
972 } else { 993 } else {
973 invalidateClick(); 994 invalidateClick();
974 return false; 995 return WebInputEventResult::NotHandled;
975 } 996 }
976 997
977 HitTestRequest request(HitTestRequest::Active); 998 HitTestRequest request(HitTestRequest::Active);
978 // Save the document point we generate in case the window coordinate is inva lidated by what happens 999 // Save the document point we generate in case the window coordinate is inva lidated by what happens
979 // when we dispatch the event. 1000 // when we dispatch the event.
980 LayoutPoint documentPoint = contentPointFromRootFrame(m_frame, mouseEvent.po sition()); 1001 LayoutPoint documentPoint = contentPointFromRootFrame(m_frame, mouseEvent.po sition());
981 MouseEventWithHitTestResults mev = m_frame->document()->prepareMouseEvent(re quest, documentPoint, mouseEvent); 1002 MouseEventWithHitTestResults mev = m_frame->document()->prepareMouseEvent(re quest, documentPoint, mouseEvent);
982 1003
983 if (!mev.innerNode()) { 1004 if (!mev.innerNode()) {
984 invalidateClick(); 1005 invalidateClick();
985 return false; 1006 return WebInputEventResult::NotHandled;
986 } 1007 }
987 1008
988 m_mousePressNode = mev.innerNode(); 1009 m_mousePressNode = mev.innerNode();
989 1010
990 RefPtrWillBeRawPtr<LocalFrame> subframe = subframeForHitTestResult(mev); 1011 RefPtrWillBeRawPtr<LocalFrame> subframe = subframeForHitTestResult(mev);
991 if (subframe && passMousePressEventToSubframe(mev, subframe.get())) { 1012 if (subframe) {
1013 WebInputEventResult result = passMousePressEventToSubframe(mev, subframe .get());
Rick Byers 2015/11/27 21:31:53 this capturing logic needs to be done only when th
dtapuska 2015/11/30 16:15:43 Done.
Rick Byers 2015/12/02 14:52:10 You're still missing the test. Previously we'd go
992 // Start capturing future events for this frame. We only do this if we didn't clear 1014 // Start capturing future events for this frame. We only do this if we didn't clear
993 // the m_mousePressed flag, which may happen if an AppKit widget entered a modal event loop. 1015 // the m_mousePressed flag, which may happen if an AppKit widget entered a modal event loop.
994 m_capturesDragging = subframe->eventHandler().capturesDragging(); 1016 m_capturesDragging = subframe->eventHandler().capturesDragging();
995 if (m_mousePressed && m_capturesDragging) { 1017 if (m_mousePressed && m_capturesDragging) {
996 m_capturingMouseEventsNode = mev.innerNode(); 1018 m_capturingMouseEventsNode = mev.innerNode();
997 m_eventHandlerWillResetCapturingMouseEventsNode = true; 1019 m_eventHandlerWillResetCapturingMouseEventsNode = true;
998 } 1020 }
999 invalidateClick(); 1021 invalidateClick();
1000 return true; 1022 return result;
1001 } 1023 }
1002 1024
1003 #if OS(WIN) 1025 #if OS(WIN)
1004 // We store whether pan scrolling is in progress before calling stopAutoscro ll() 1026 // We store whether pan scrolling is in progress before calling stopAutoscro ll()
1005 // because it will set m_autoscrollType to NoAutoscroll on return. 1027 // because it will set m_autoscrollType to NoAutoscroll on return.
1006 bool isPanScrollInProgress = panScrollInProgress(); 1028 bool isPanScrollInProgress = panScrollInProgress();
1007 stopAutoscroll(); 1029 stopAutoscroll();
1008 if (isPanScrollInProgress) { 1030 if (isPanScrollInProgress) {
1009 // We invalidate the click when exiting pan scrolling so that we don't i nadvertently navigate 1031 // We invalidate the click when exiting pan scrolling so that we don't i nadvertently navigate
1010 // away from the current page (e.g. the click was on a hyperlink). See < rdar://problem/6095023>. 1032 // away from the current page (e.g. the click was on a hyperlink). See < rdar://problem/6095023>.
1011 invalidateClick(); 1033 invalidateClick();
1012 return true; 1034 return WebInputEventResult::HandledSuppressed;
1013 } 1035 }
1014 #endif 1036 #endif
1015 1037
1016 m_clickCount = mouseEvent.clickCount(); 1038 m_clickCount = mouseEvent.clickCount();
1017 m_clickNode = mev.innerNode()->isTextNode() ? ComposedTreeTraversal::parent (*mev.innerNode()) : mev.innerNode(); 1039 m_clickNode = mev.innerNode()->isTextNode() ? ComposedTreeTraversal::parent (*mev.innerNode()) : mev.innerNode();
1018 1040
1019 if (FrameView* view = m_frame->view()) { 1041 if (FrameView* view = m_frame->view()) {
1020 PaintLayer* layer = mev.innerNode()->layoutObject() ? mev.innerNode()->l ayoutObject()->enclosingLayer() : nullptr; 1042 PaintLayer* layer = mev.innerNode()->layoutObject() ? mev.innerNode()->l ayoutObject()->enclosingLayer() : nullptr;
1021 IntPoint p = view->rootFrameToContents(mouseEvent.position()); 1043 IntPoint p = view->rootFrameToContents(mouseEvent.position());
1022 if (layer && layer->scrollableArea() && layer->scrollableArea()->isPoint InResizeControl(p, ResizerForPointer)) { 1044 if (layer && layer->scrollableArea() && layer->scrollableArea()->isPoint InResizeControl(p, ResizerForPointer)) {
1023 m_resizeScrollableArea = layer->scrollableArea(); 1045 m_resizeScrollableArea = layer->scrollableArea();
1024 m_resizeScrollableArea->setInResizeMode(true); 1046 m_resizeScrollableArea->setInResizeMode(true);
1025 m_offsetFromResizeCorner = LayoutSize(m_resizeScrollableArea->offset FromResizeCorner(p)); 1047 m_offsetFromResizeCorner = LayoutSize(m_resizeScrollableArea->offset FromResizeCorner(p));
1026 invalidateClick(); 1048 invalidateClick();
1027 return true; 1049 return WebInputEventResult::HandledSuppressed;
1028 } 1050 }
1029 } 1051 }
1030 1052
1031 m_frame->selection().setCaretBlinkingSuspended(true); 1053 m_frame->selection().setCaretBlinkingSuspended(true);
1032 1054
1033 bool swallowEvent = updatePointerTargetAndDispatchEvents(EventTypeNames::mou sedown, mev.innerNode(), m_clickCount, mouseEvent); 1055 WebInputEventResult eventResult = updatePointerTargetAndDispatchEvents(Event TypeNames::mousedown, mev.innerNode(), m_clickCount, mouseEvent);
1034 1056
1035 // m_selectionInitiationState is initialized after dispatching mousedown 1057 // m_selectionInitiationState is initialized after dispatching mousedown
1036 // event in order not to keep the selection by DOM APIs Because we can't 1058 // event in order not to keep the selection by DOM APIs Because we can't
1037 // give the user the chance to handle the selection by user action like 1059 // give the user the chance to handle the selection by user action like
1038 // dragging if we keep the selection in case of mousedown. FireFox also has 1060 // dragging if we keep the selection in case of mousedown. FireFox also has
1039 // the same behavior and it's more compatible with other browsers. 1061 // the same behavior and it's more compatible with other browsers.
1040 selectionController().initializeSelectionState(); 1062 selectionController().initializeSelectionState();
1041 HitTestResult hitTestResult = hitTestResultInFrame(m_frame, documentPoint, H itTestRequest::ReadOnly); 1063 HitTestResult hitTestResult = hitTestResultInFrame(m_frame, documentPoint, H itTestRequest::ReadOnly);
1042 InputDeviceCapabilities* sourceCapabilities = mouseEvent.syntheticEventType( ) == PlatformMouseEvent::FromTouch ? InputDeviceCapabilities::firesTouchEventsSo urceCapabilities() : 1064 InputDeviceCapabilities* sourceCapabilities = mouseEvent.syntheticEventType( ) == PlatformMouseEvent::FromTouch ? InputDeviceCapabilities::firesTouchEventsSo urceCapabilities() :
1043 InputDeviceCapabilities::doesntFireTouchEventsSourceCapabilities(); 1065 InputDeviceCapabilities::doesntFireTouchEventsSourceCapabilities();
1044 swallowEvent = swallowEvent || handleMouseFocus(MouseEventWithHitTestResults (mouseEvent, hitTestResult), sourceCapabilities); 1066 if (eventResult == WebInputEventResult::NotHandled)
1045 m_capturesDragging = !swallowEvent || mev.scrollbar(); 1067 eventResult = handleMouseFocus(MouseEventWithHitTestResults(mouseEvent, hitTestResult), sourceCapabilities);
1068 m_capturesDragging = eventResult == WebInputEventResult::NotHandled || mev.s crollbar();
1046 1069
1047 // If the hit testing originally determined the event was in a scrollbar, re fetch the MouseEventWithHitTestResults 1070 // If the hit testing originally determined the event was in a scrollbar, re fetch the MouseEventWithHitTestResults
1048 // in case the scrollbar widget was destroyed when the mouse event was handl ed. 1071 // in case the scrollbar widget was destroyed when the mouse event was handl ed.
1049 if (mev.scrollbar()) { 1072 if (mev.scrollbar()) {
1050 const bool wasLastScrollBar = mev.scrollbar() == m_lastScrollbarUnderMou se.get(); 1073 const bool wasLastScrollBar = mev.scrollbar() == m_lastScrollbarUnderMou se.get();
1051 HitTestRequest request(HitTestRequest::ReadOnly | HitTestRequest::Active ); 1074 HitTestRequest request(HitTestRequest::ReadOnly | HitTestRequest::Active );
1052 mev = m_frame->document()->prepareMouseEvent(request, documentPoint, mou seEvent); 1075 mev = m_frame->document()->prepareMouseEvent(request, documentPoint, mou seEvent);
1053 if (wasLastScrollBar && mev.scrollbar() != m_lastScrollbarUnderMouse.get ()) 1076 if (wasLastScrollBar && mev.scrollbar() != m_lastScrollbarUnderMouse.get ())
1054 m_lastScrollbarUnderMouse = nullptr; 1077 m_lastScrollbarUnderMouse = nullptr;
1055 } 1078 }
1056 1079
1057 if (swallowEvent) { 1080 if (eventResult != WebInputEventResult::NotHandled) {
1058 // scrollbars should get events anyway, even disabled controls might be scrollable 1081 // scrollbars should get events anyway, even disabled controls might be scrollable
1059 passMousePressEventToScrollbar(mev); 1082 passMousePressEventToScrollbar(mev);
1060 } else { 1083 } else {
1061 if (shouldRefetchEventTarget(mev)) { 1084 if (shouldRefetchEventTarget(mev)) {
1062 HitTestRequest request(HitTestRequest::ReadOnly | HitTestRequest::Ac tive); 1085 HitTestRequest request(HitTestRequest::ReadOnly | HitTestRequest::Ac tive);
1063 mev = m_frame->document()->prepareMouseEvent(request, documentPoint, mouseEvent); 1086 mev = m_frame->document()->prepareMouseEvent(request, documentPoint, mouseEvent);
1064 } 1087 }
1065 1088
1066 if (passMousePressEventToScrollbar(mev)) 1089 if (passMousePressEventToScrollbar(mev))
1067 swallowEvent = true; 1090 eventResult = WebInputEventResult::HandledSystem;
1068 else 1091 else
1069 swallowEvent = handleMousePressEvent(mev); 1092 eventResult = handleMousePressEvent(mev);
1070 } 1093 }
1071 1094
1072 if (mev.hitTestResult().innerNode() && mouseEvent.button() == LeftButton) { 1095 if (mev.hitTestResult().innerNode() && mouseEvent.button() == LeftButton) {
1073 ASSERT(mouseEvent.type() == PlatformEvent::MousePressed); 1096 ASSERT(mouseEvent.type() == PlatformEvent::MousePressed);
1074 HitTestResult result = mev.hitTestResult(); 1097 HitTestResult result = mev.hitTestResult();
1075 result.setToShadowHostIfInUserAgentShadowRoot(); 1098 result.setToShadowHostIfInUserAgentShadowRoot();
1076 m_frame->chromeClient().onMouseDown(result.innerNode()); 1099 m_frame->chromeClient().onMouseDown(result.innerNode());
1077 } 1100 }
1078 1101
1079 return swallowEvent; 1102 return eventResult;
1080 } 1103 }
1081 1104
1082 static PaintLayer* layerForNode(Node* node) 1105 static PaintLayer* layerForNode(Node* node)
1083 { 1106 {
1084 if (!node) 1107 if (!node)
1085 return nullptr; 1108 return nullptr;
1086 1109
1087 LayoutObject* layoutObject = node->layoutObject(); 1110 LayoutObject* layoutObject = node->layoutObject();
1088 if (!layoutObject) 1111 if (!layoutObject)
1089 return nullptr; 1112 return nullptr;
1090 1113
1091 PaintLayer* layer = layoutObject->enclosingLayer(); 1114 PaintLayer* layer = layoutObject->enclosingLayer();
1092 if (!layer) 1115 if (!layer)
1093 return nullptr; 1116 return nullptr;
1094 1117
1095 return layer; 1118 return layer;
1096 } 1119 }
1097 1120
1098 ScrollableArea* EventHandler::associatedScrollableArea(const PaintLayer* layer) const 1121 ScrollableArea* EventHandler::associatedScrollableArea(const PaintLayer* layer) const
1099 { 1122 {
1100 if (PaintLayerScrollableArea* scrollableArea = layer->scrollableArea()) { 1123 if (PaintLayerScrollableArea* scrollableArea = layer->scrollableArea()) {
1101 if (scrollableArea->scrollsOverflow()) 1124 if (scrollableArea->scrollsOverflow())
1102 return scrollableArea; 1125 return scrollableArea;
1103 } 1126 }
1104 1127
1105 return nullptr; 1128 return nullptr;
1106 } 1129 }
1107 1130
1108 bool EventHandler::handleMouseMoveEvent(const PlatformMouseEvent& event) 1131 WebInputEventResult EventHandler::handleMouseMoveEvent(const PlatformMouseEvent& event)
1109 { 1132 {
1110 TRACE_EVENT0("blink", "EventHandler::handleMouseMoveEvent"); 1133 TRACE_EVENT0("blink", "EventHandler::handleMouseMoveEvent");
1111 1134
1112 conditionallyEnableMouseEventForPointerTypeMouse(event); 1135 conditionallyEnableMouseEventForPointerTypeMouse(event);
1113 1136
1114 RefPtrWillBeRawPtr<FrameView> protector(m_frame->view()); 1137 RefPtrWillBeRawPtr<FrameView> protector(m_frame->view());
1115 1138
1116 HitTestResult hoveredNode = HitTestResult(); 1139 HitTestResult hoveredNode = HitTestResult();
1117 bool result = handleMouseMoveOrLeaveEvent(event, &hoveredNode); 1140 WebInputEventResult result = handleMouseMoveOrLeaveEvent(event, &hoveredNode );
1118 1141
1119 Page* page = m_frame->page(); 1142 Page* page = m_frame->page();
1120 if (!page) 1143 if (!page)
1121 return result; 1144 return result;
1122 1145
1123 if (PaintLayer* layer = layerForNode(hoveredNode.innerNode())) { 1146 if (PaintLayer* layer = layerForNode(hoveredNode.innerNode())) {
1124 if (ScrollableArea* layerScrollableArea = associatedScrollableArea(layer )) 1147 if (ScrollableArea* layerScrollableArea = associatedScrollableArea(layer ))
1125 layerScrollableArea->mouseMovedInContentArea(); 1148 layerScrollableArea->mouseMovedInContentArea();
1126 } 1149 }
1127 1150
1128 if (FrameView* frameView = m_frame->view()) 1151 if (FrameView* frameView = m_frame->view())
1129 frameView->mouseMovedInContentArea(); 1152 frameView->mouseMovedInContentArea();
1130 1153
1131 hoveredNode.setToShadowHostIfInUserAgentShadowRoot(); 1154 hoveredNode.setToShadowHostIfInUserAgentShadowRoot();
1132 page->chromeClient().mouseDidMoveOverElement(hoveredNode); 1155 page->chromeClient().mouseDidMoveOverElement(hoveredNode);
1133 1156
1134 return result; 1157 return result;
1135 } 1158 }
1136 1159
1137 void EventHandler::handleMouseLeaveEvent(const PlatformMouseEvent& event) 1160 void EventHandler::handleMouseLeaveEvent(const PlatformMouseEvent& event)
1138 { 1161 {
1139 TRACE_EVENT0("blink", "EventHandler::handleMouseLeaveEvent"); 1162 TRACE_EVENT0("blink", "EventHandler::handleMouseLeaveEvent");
1140 1163
1141 conditionallyEnableMouseEventForPointerTypeMouse(event); 1164 conditionallyEnableMouseEventForPointerTypeMouse(event);
1142 1165
1143 RefPtrWillBeRawPtr<FrameView> protector(m_frame->view()); 1166 RefPtrWillBeRawPtr<FrameView> protector(m_frame->view());
1144 handleMouseMoveOrLeaveEvent(event, 0, false, true); 1167 handleMouseMoveOrLeaveEvent(event, 0, false, true);
1145 } 1168 }
1146 1169
1147 bool EventHandler::handleMouseMoveOrLeaveEvent(const PlatformMouseEvent& mouseEv ent, HitTestResult* hoveredNode, bool onlyUpdateScrollbars, bool forceLeave) 1170 WebInputEventResult EventHandler::handleMouseMoveOrLeaveEvent(const PlatformMous eEvent& mouseEvent, HitTestResult* hoveredNode, bool onlyUpdateScrollbars, bool forceLeave)
1148 { 1171 {
1149 ASSERT(m_frame); 1172 ASSERT(m_frame);
1150 ASSERT(m_frame->view()); 1173 ASSERT(m_frame->view());
1151 1174
1152 setLastKnownMousePosition(mouseEvent); 1175 setLastKnownMousePosition(mouseEvent);
1153 1176
1154 if (m_hoverTimer.isActive()) 1177 if (m_hoverTimer.isActive())
1155 m_hoverTimer.stop(); 1178 m_hoverTimer.stop();
1156 1179
1157 m_cursorUpdateTimer.stop(); 1180 m_cursorUpdateTimer.stop();
1158 1181
1159 cancelFakeMouseMoveEvent(); 1182 cancelFakeMouseMoveEvent();
1160 1183
1161 if (m_svgPan) { 1184 if (m_svgPan) {
1162 m_frame->document()->accessSVGExtensions().updatePan(m_frame->view()->ro otFrameToContents(m_lastKnownMousePosition)); 1185 m_frame->document()->accessSVGExtensions().updatePan(m_frame->view()->ro otFrameToContents(m_lastKnownMousePosition));
1163 return true; 1186 return WebInputEventResult::HandledSuppressed;
1164 } 1187 }
1165 1188
1166 if (m_frameSetBeingResized) 1189 if (m_frameSetBeingResized)
1167 return updatePointerTargetAndDispatchEvents(EventTypeNames::mousemove, m _frameSetBeingResized.get(), 0, mouseEvent); 1190 return updatePointerTargetAndDispatchEvents(EventTypeNames::mousemove, m _frameSetBeingResized.get(), 0, mouseEvent);
1168 1191
1169 // Send events right to a scrollbar if the mouse is pressed. 1192 // Send events right to a scrollbar if the mouse is pressed.
1170 if (m_lastScrollbarUnderMouse && m_mousePressed) { 1193 if (m_lastScrollbarUnderMouse && m_mousePressed) {
1171 m_lastScrollbarUnderMouse->mouseMoved(mouseEvent); 1194 m_lastScrollbarUnderMouse->mouseMoved(mouseEvent);
1172 return true; 1195 return WebInputEventResult::HandledSystem;
1173 } 1196 }
1174 1197
1175 // Mouse events simulated from touch should not hit-test again. 1198 // Mouse events simulated from touch should not hit-test again.
1176 ASSERT(!mouseEvent.fromTouch()); 1199 ASSERT(!mouseEvent.fromTouch());
1177 1200
1178 HitTestRequest::HitTestRequestType hitType = HitTestRequest::Move; 1201 HitTestRequest::HitTestRequestType hitType = HitTestRequest::Move;
1179 if (m_mousePressed) { 1202 if (m_mousePressed) {
1180 hitType |= HitTestRequest::Active; 1203 hitType |= HitTestRequest::Active;
1181 } else if (onlyUpdateScrollbars) { 1204 } else if (onlyUpdateScrollbars) {
1182 // Mouse events should be treated as "read-only" if we're updating only scrollbars. This 1205 // Mouse events should be treated as "read-only" if we're updating only scrollbars. This
(...skipping 22 matching lines...) Expand all
1205 Scrollbar* scrollbar = nullptr; 1228 Scrollbar* scrollbar = nullptr;
1206 1229
1207 if (m_resizeScrollableArea && m_resizeScrollableArea->inResizeMode()) { 1230 if (m_resizeScrollableArea && m_resizeScrollableArea->inResizeMode()) {
1208 m_resizeScrollableArea->resize(mouseEvent, m_offsetFromResizeCorner); 1231 m_resizeScrollableArea->resize(mouseEvent, m_offsetFromResizeCorner);
1209 } else { 1232 } else {
1210 if (!scrollbar) 1233 if (!scrollbar)
1211 scrollbar = mev.scrollbar(); 1234 scrollbar = mev.scrollbar();
1212 1235
1213 updateLastScrollbarUnderMouse(scrollbar, !m_mousePressed); 1236 updateLastScrollbarUnderMouse(scrollbar, !m_mousePressed);
1214 if (onlyUpdateScrollbars) 1237 if (onlyUpdateScrollbars)
1215 return true; 1238 return WebInputEventResult::HandledSuppressed;
1216 } 1239 }
1217 1240
1218 bool swallowEvent = false; 1241 WebInputEventResult eventResult = WebInputEventResult::NotHandled;
1219 RefPtrWillBeRawPtr<LocalFrame> newSubframe = m_capturingMouseEventsNode.get( ) ? subframeForTargetNode(m_capturingMouseEventsNode.get()) : subframeForHitTest Result(mev); 1242 RefPtrWillBeRawPtr<LocalFrame> newSubframe = m_capturingMouseEventsNode.get( ) ? subframeForTargetNode(m_capturingMouseEventsNode.get()) : subframeForHitTest Result(mev);
1220 1243
1221 // We want mouseouts to happen first, from the inside out. First send a mov e event to the last subframe so that it will fire mouseouts. 1244 // We want mouseouts to happen first, from the inside out. First send a mov e event to the last subframe so that it will fire mouseouts.
1222 if (m_lastMouseMoveEventSubframe && m_lastMouseMoveEventSubframe->tree().isD escendantOf(m_frame) && m_lastMouseMoveEventSubframe != newSubframe) 1245 if (m_lastMouseMoveEventSubframe && m_lastMouseMoveEventSubframe->tree().isD escendantOf(m_frame) && m_lastMouseMoveEventSubframe != newSubframe)
1223 m_lastMouseMoveEventSubframe->eventHandler().handleMouseLeaveEvent(mouse Event); 1246 m_lastMouseMoveEventSubframe->eventHandler().handleMouseLeaveEvent(mouse Event);
1224 1247
1225 if (newSubframe) { 1248 if (newSubframe) {
1226 // Update over/out state before passing the event to the subframe. 1249 // Update over/out state before passing the event to the subframe.
1227 updateMouseEventTargetNode(mev.innerNode(), mouseEvent); 1250 updateMouseEventTargetNode(mev.innerNode(), mouseEvent);
1228 1251
1229 // Event dispatch in updateMouseEventTargetNode may have caused the subf rame of the target 1252 // Event dispatch in updateMouseEventTargetNode may have caused the subf rame of the target
1230 // node to be detached from its FrameView, in which case the event shoul d not be passed. 1253 // node to be detached from its FrameView, in which case the event shoul d not be passed.
1231 if (newSubframe->view()) 1254 if (newSubframe->view())
1232 swallowEvent |= passMouseMoveEventToSubframe(mev, newSubframe.get(), hoveredNode); 1255 eventResult = passMouseMoveEventToSubframe(mev, newSubframe.get(), h overedNode);
1233 } else { 1256 } else {
1234 if (scrollbar && !m_mousePressed) 1257 if (scrollbar && !m_mousePressed)
1235 scrollbar->mouseMoved(mouseEvent); // Handle hover effects on platfo rms that support visual feedback on scrollbar hovering. 1258 scrollbar->mouseMoved(mouseEvent); // Handle hover effects on platfo rms that support visual feedback on scrollbar hovering.
1236 if (FrameView* view = m_frame->view()) { 1259 if (FrameView* view = m_frame->view()) {
1237 OptionalCursor optionalCursor = selectCursor(mev.hitTestResult()); 1260 OptionalCursor optionalCursor = selectCursor(mev.hitTestResult());
1238 if (optionalCursor.isCursorChange()) { 1261 if (optionalCursor.isCursorChange()) {
1239 view->setCursor(optionalCursor.cursor()); 1262 view->setCursor(optionalCursor.cursor());
1240 } 1263 }
1241 } 1264 }
1242 } 1265 }
1243 1266
1244 m_lastMouseMoveEventSubframe = newSubframe; 1267 m_lastMouseMoveEventSubframe = newSubframe;
1245 1268
1246 if (swallowEvent) 1269 if (eventResult != WebInputEventResult::NotHandled)
1247 return true; 1270 return eventResult;
1248 1271
1249 swallowEvent = updatePointerTargetAndDispatchEvents(EventTypeNames::mousemov e, mev.innerNode(), 0, mouseEvent); 1272 eventResult = updatePointerTargetAndDispatchEvents(EventTypeNames::mousemove , mev.innerNode(), 0, mouseEvent);
1273 if (eventResult != WebInputEventResult::NotHandled)
1274 return eventResult;
1250 1275
1251 if (!swallowEvent) 1276 return handleMouseDraggedEvent(mev);
1252 swallowEvent = handleMouseDraggedEvent(mev);
1253
1254 return swallowEvent;
1255 } 1277 }
1256 1278
1257 void EventHandler::invalidateClick() 1279 void EventHandler::invalidateClick()
1258 { 1280 {
1259 m_clickCount = 0; 1281 m_clickCount = 0;
1260 m_clickNode = nullptr; 1282 m_clickNode = nullptr;
1261 } 1283 }
1262 1284
1263 static ContainerNode* parentForClickEvent(const Node& node) 1285 static ContainerNode* parentForClickEvent(const Node& node)
1264 { 1286 {
1265 // IE doesn't dispatch click events for mousedown/mouseup events across form 1287 // IE doesn't dispatch click events for mousedown/mouseup events across form
1266 // controls. 1288 // controls.
1267 if (node.isHTMLElement() && toHTMLElement(node).isInteractiveContent()) 1289 if (node.isHTMLElement() && toHTMLElement(node).isInteractiveContent())
1268 return nullptr; 1290 return nullptr;
1269 1291
1270 return ComposedTreeTraversal::parent(node); 1292 return ComposedTreeTraversal::parent(node);
1271 } 1293 }
1272 1294
1273 bool EventHandler::handleMouseReleaseEvent(const PlatformMouseEvent& mouseEvent) 1295 WebInputEventResult EventHandler::handleMouseReleaseEvent(const PlatformMouseEve nt& mouseEvent)
1274 { 1296 {
1275 TRACE_EVENT0("blink", "EventHandler::handleMouseReleaseEvent"); 1297 TRACE_EVENT0("blink", "EventHandler::handleMouseReleaseEvent");
1276 1298
1277 RefPtrWillBeRawPtr<FrameView> protector(m_frame->view()); 1299 RefPtrWillBeRawPtr<FrameView> protector(m_frame->view());
1278 1300
1279 m_frame->selection().setCaretBlinkingSuspended(false); 1301 m_frame->selection().setCaretBlinkingSuspended(false);
1280 1302
1281 OwnPtr<UserGestureIndicator> gestureIndicator; 1303 OwnPtr<UserGestureIndicator> gestureIndicator;
1282 1304
1283 if (m_frame->localFrameRoot()->eventHandler().m_lastMouseDownUserGestureToke n) 1305 if (m_frame->localFrameRoot()->eventHandler().m_lastMouseDownUserGestureToke n)
1284 gestureIndicator = adoptPtr(new UserGestureIndicator(m_frame->localFrame Root()->eventHandler().m_lastMouseDownUserGestureToken.release())); 1306 gestureIndicator = adoptPtr(new UserGestureIndicator(m_frame->localFrame Root()->eventHandler().m_lastMouseDownUserGestureToken.release()));
1285 else 1307 else
1286 gestureIndicator = adoptPtr(new UserGestureIndicator(DefinitelyProcessin gUserGesture)); 1308 gestureIndicator = adoptPtr(new UserGestureIndicator(DefinitelyProcessin gUserGesture));
1287 1309
1288 #if OS(WIN) 1310 #if OS(WIN)
1289 if (Page* page = m_frame->page()) 1311 if (Page* page = m_frame->page())
1290 page->autoscrollController().handleMouseReleaseForPanScrolling(m_frame, mouseEvent); 1312 page->autoscrollController().handleMouseReleaseForPanScrolling(m_frame, mouseEvent);
1291 #endif 1313 #endif
1292 1314
1293 m_mousePressed = false; 1315 m_mousePressed = false;
1294 setLastKnownMousePosition(mouseEvent); 1316 setLastKnownMousePosition(mouseEvent);
1295 1317
1296 if (m_svgPan) { 1318 if (m_svgPan) {
1297 m_svgPan = false; 1319 m_svgPan = false;
1298 m_frame->document()->accessSVGExtensions().updatePan(m_frame->view()->ro otFrameToContents(m_lastKnownMousePosition)); 1320 m_frame->document()->accessSVGExtensions().updatePan(m_frame->view()->ro otFrameToContents(m_lastKnownMousePosition));
1299 return true; 1321 return WebInputEventResult::HandledSuppressed;
1300 } 1322 }
1301 1323
1302 if (m_frameSetBeingResized) 1324 if (m_frameSetBeingResized)
1303 return dispatchMouseEvent(EventTypeNames::mouseup, m_frameSetBeingResize d.get(), m_clickCount, mouseEvent); 1325 return dispatchMouseEvent(EventTypeNames::mouseup, m_frameSetBeingResize d.get(), m_clickCount, mouseEvent);
1304 1326
1305 if (m_lastScrollbarUnderMouse) { 1327 if (m_lastScrollbarUnderMouse) {
1306 invalidateClick(); 1328 invalidateClick();
1307 m_lastScrollbarUnderMouse->mouseUp(mouseEvent); 1329 m_lastScrollbarUnderMouse->mouseUp(mouseEvent);
1308 return dispatchMouseEvent(EventTypeNames::mouseup, m_nodeUnderMouse.get( ), m_clickCount, mouseEvent); 1330 return dispatchMouseEvent(EventTypeNames::mouseup, m_nodeUnderMouse.get( ), m_clickCount, mouseEvent);
1309 } 1331 }
1310 1332
1311 // Mouse events simulated from touch should not hit-test again. 1333 // Mouse events simulated from touch should not hit-test again.
1312 ASSERT(!mouseEvent.fromTouch()); 1334 ASSERT(!mouseEvent.fromTouch());
1313 1335
1314 HitTestRequest::HitTestRequestType hitType = HitTestRequest::Release; 1336 HitTestRequest::HitTestRequestType hitType = HitTestRequest::Release;
1315 HitTestRequest request(hitType); 1337 HitTestRequest request(hitType);
1316 MouseEventWithHitTestResults mev = prepareMouseEvent(request, mouseEvent); 1338 MouseEventWithHitTestResults mev = prepareMouseEvent(request, mouseEvent);
1317 LocalFrame* subframe = m_capturingMouseEventsNode.get() ? subframeForTargetN ode(m_capturingMouseEventsNode.get()) : subframeForHitTestResult(mev); 1339 LocalFrame* subframe = m_capturingMouseEventsNode.get() ? subframeForTargetN ode(m_capturingMouseEventsNode.get()) : subframeForHitTestResult(mev);
1318 if (m_eventHandlerWillResetCapturingMouseEventsNode) 1340 if (m_eventHandlerWillResetCapturingMouseEventsNode)
1319 m_capturingMouseEventsNode = nullptr; 1341 m_capturingMouseEventsNode = nullptr;
1320 if (subframe && passMouseReleaseEventToSubframe(mev, subframe)) 1342 if (subframe)
1321 return true; 1343 return passMouseReleaseEventToSubframe(mev, subframe);
1322 1344
1323 bool swallowUpEvent = updatePointerTargetAndDispatchEvents(EventTypeNames::m ouseup, mev.innerNode(), m_clickCount, mouseEvent); 1345 WebInputEventResult eventResult = updatePointerTargetAndDispatchEvents(Event TypeNames::mouseup, mev.innerNode(), m_clickCount, mouseEvent);
1324 1346
1325 // TODO(crbug/545647): This state should reset with pointercancel too. 1347 // TODO(crbug/545647): This state should reset with pointercancel too.
1326 m_preventMouseEventForPointerTypeMouse = false; 1348 m_preventMouseEventForPointerTypeMouse = false;
1327 1349
1328 bool contextMenuEvent = mouseEvent.button() == RightButton; 1350 bool contextMenuEvent = mouseEvent.button() == RightButton;
1329 #if OS(MACOSX) 1351 #if OS(MACOSX)
1330 // FIXME: The Mac port achieves the same behavior by checking whether the co ntext menu is currently open in WebPage::mouseEvent(). Consider merging the impl ementations. 1352 // FIXME: The Mac port achieves the same behavior by checking whether the co ntext menu is currently open in WebPage::mouseEvent(). Consider merging the impl ementations.
1331 if (mouseEvent.button() == LeftButton && mouseEvent.modifiers() & PlatformEv ent::CtrlKey) 1353 if (mouseEvent.button() == LeftButton && mouseEvent.modifiers() & PlatformEv ent::CtrlKey)
1332 contextMenuEvent = true; 1354 contextMenuEvent = true;
1333 #endif 1355 #endif
1334 1356
1335 bool swallowClickEvent = false;
1336 if (m_clickCount > 0 && !contextMenuEvent && mev.innerNode() && m_clickNode && mev.innerNode()->canParticipateInComposedTree() && m_clickNode->canParticipat eInComposedTree()) { 1357 if (m_clickCount > 0 && !contextMenuEvent && mev.innerNode() && m_clickNode && mev.innerNode()->canParticipateInComposedTree() && m_clickNode->canParticipat eInComposedTree()) {
1337 // Updates distribution because a 'mouseup' event listener can make the 1358 // Updates distribution because a 'mouseup' event listener can make the
1338 // tree dirty at dispatchMouseEvent() invocation above. 1359 // tree dirty at dispatchMouseEvent() invocation above.
1339 // Unless distribution is updated, commonAncestor would hit ASSERT. 1360 // Unless distribution is updated, commonAncestor would hit ASSERT.
1340 // Both m_clickNode and mev.innerNode() don't need to be updated 1361 // Both m_clickNode and mev.innerNode() don't need to be updated
1341 // because commonAncestor() will exit early if their documents are diffe rent. 1362 // because commonAncestor() will exit early if their documents are diffe rent.
1342 m_clickNode->updateDistribution(); 1363 m_clickNode->updateDistribution();
1343 if (Node* clickTargetNode = mev.innerNode()->commonAncestor( 1364 if (Node* clickTargetNode = mev.innerNode()->commonAncestor(
1344 *m_clickNode, parentForClickEvent)) { 1365 *m_clickNode, parentForClickEvent)) {
1345 1366
1346 // Dispatch mouseup directly w/o calling updateMouseEventTargetNode 1367 // Dispatch mouseup directly w/o calling updateMouseEventTargetNode
1347 // because the mouseup dispatch above has already updated it 1368 // because the mouseup dispatch above has already updated it
1348 // correctly. Moreover, clickTargetNode is different from 1369 // correctly. Moreover, clickTargetNode is different from
1349 // mev.innerNode at drag-release. 1370 // mev.innerNode at drag-release.
1350 clickTargetNode->dispatchMouseEvent(mouseEvent, 1371 clickTargetNode->dispatchMouseEvent(mouseEvent,
Rick Byers 2015/11/27 21:31:53 oh weird - looks like we forgot (or lost) the code
mustaq 2015/11/30 16:02:50 Yes, swallowClickEvent should have been there, and
dtapuska 2015/11/30 16:15:43 I've fixed it; although I return HandledApplicatio
1351 EventTypeNames::click, m_clickCount); 1372 EventTypeNames::click, m_clickCount);
1352 } 1373 }
1353 } 1374 }
1354 1375
1355 if (m_resizeScrollableArea) { 1376 if (m_resizeScrollableArea) {
1356 m_resizeScrollableArea->setInResizeMode(false); 1377 m_resizeScrollableArea->setInResizeMode(false);
1357 m_resizeScrollableArea = nullptr; 1378 m_resizeScrollableArea = nullptr;
1358 } 1379 }
1359 1380
1360 bool swallowMouseReleaseEvent = false; 1381 if (eventResult == WebInputEventResult::NotHandled)
1361 if (!swallowUpEvent) 1382 eventResult = handleMouseReleaseEvent(mev);
1362 swallowMouseReleaseEvent = handleMouseReleaseEvent(mev);
1363 1383
1364 invalidateClick(); 1384 invalidateClick();
1365 1385
1366 return swallowUpEvent || swallowClickEvent || swallowMouseReleaseEvent; 1386 return eventResult;
1367 } 1387 }
1368 1388
1369 bool EventHandler::dispatchDragEvent(const AtomicString& eventType, Node* dragTa rget, const PlatformMouseEvent& event, DataTransfer* dataTransfer) 1389 WebInputEventResult EventHandler::dispatchDragEvent(const AtomicString& eventTyp e, Node* dragTarget, const PlatformMouseEvent& event, DataTransfer* dataTransfer )
1370 { 1390 {
1371 FrameView* view = m_frame->view(); 1391 FrameView* view = m_frame->view();
1372 1392
1373 // FIXME: We might want to dispatch a dragleave even if the view is gone. 1393 // FIXME: We might want to dispatch a dragleave even if the view is gone.
1374 if (!view) 1394 if (!view)
1375 return false; 1395 return WebInputEventResult::NotHandled;
1376 1396
1377 RefPtrWillBeRawPtr<DragEvent> me = DragEvent::create(eventType, 1397 RefPtrWillBeRawPtr<DragEvent> me = DragEvent::create(eventType,
1378 true, true, m_frame->document()->domWindow(), 1398 true, true, m_frame->document()->domWindow(),
1379 0, event.globalPosition().x(), event.globalPosition().y(), event.positio n().x(), event.position().y(), 1399 0, event.globalPosition().x(), event.globalPosition().y(), event.positio n().x(), event.position().y(),
1380 event.movementDelta().x(), event.movementDelta().y(), 1400 event.movementDelta().x(), event.movementDelta().y(),
1381 event.modifiers(), 1401 event.modifiers(),
1382 0, MouseEvent::platformModifiersToButtons(event.modifiers()), nullptr, d ataTransfer, event.syntheticEventType(), event.timestamp()); 1402 0, MouseEvent::platformModifiersToButtons(event.modifiers()), nullptr, d ataTransfer, event.syntheticEventType(), event.timestamp());
1383 1403
1384 dragTarget->dispatchEvent(me.get()); 1404 bool dispatchResult = dragTarget->dispatchEvent(me.get());
1385 return me->defaultPrevented(); 1405 return eventToEventResult(me, dispatchResult);
1386 } 1406 }
1387 1407
1388 static bool targetIsFrame(Node* target, LocalFrame*& frame) 1408 static bool targetIsFrame(Node* target, LocalFrame*& frame)
1389 { 1409 {
1390 if (!isHTMLFrameElementBase(target)) 1410 if (!isHTMLFrameElementBase(target))
1391 return false; 1411 return false;
1392 1412
1393 // Cross-process drag and drop is not yet supported. 1413 // Cross-process drag and drop is not yet supported.
1394 if (toHTMLFrameElementBase(target)->contentFrame() && !toHTMLFrameElementBas e(target)->contentFrame()->isLocalFrame()) 1414 if (toHTMLFrameElementBase(target)->contentFrame() && !toHTMLFrameElementBas e(target)->contentFrame()->isLocalFrame())
1395 return false; 1415 return false;
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
1430 break; 1450 break;
1431 } 1451 }
1432 if (matched) { 1452 if (matched) {
1433 dataTransfer->setDropEffect(convertDragOperationToDropZoneOperation( dragOperation)); 1453 dataTransfer->setDropEffect(convertDragOperationToDropZoneOperation( dragOperation));
1434 return true; 1454 return true;
1435 } 1455 }
1436 } 1456 }
1437 return false; 1457 return false;
1438 } 1458 }
1439 1459
1440 bool EventHandler::updateDragAndDrop(const PlatformMouseEvent& event, DataTransf er* dataTransfer) 1460 WebInputEventResult EventHandler::updateDragAndDrop(const PlatformMouseEvent& ev ent, DataTransfer* dataTransfer)
1441 { 1461 {
1442 bool accept = false; 1462 WebInputEventResult eventResult = WebInputEventResult::NotHandled;
1443 1463
1444 if (!m_frame->view()) 1464 if (!m_frame->view())
1445 return false; 1465 return eventResult;
1446 1466
1447 HitTestRequest request(HitTestRequest::ReadOnly); 1467 HitTestRequest request(HitTestRequest::ReadOnly);
1448 MouseEventWithHitTestResults mev = prepareMouseEvent(request, event); 1468 MouseEventWithHitTestResults mev = prepareMouseEvent(request, event);
1449 1469
1450 // Drag events should never go to text nodes (following IE, and proper mouse over/out dispatch) 1470 // Drag events should never go to text nodes (following IE, and proper mouse over/out dispatch)
1451 RefPtrWillBeRawPtr<Node> newTarget = mev.innerNode(); 1471 RefPtrWillBeRawPtr<Node> newTarget = mev.innerNode();
1452 if (newTarget && newTarget->isTextNode()) 1472 if (newTarget && newTarget->isTextNode())
1453 newTarget = ComposedTreeTraversal::parent(*newTarget); 1473 newTarget = ComposedTreeTraversal::parent(*newTarget);
1454 1474
1455 if (AutoscrollController* controller = autoscrollController()) 1475 if (AutoscrollController* controller = autoscrollController())
1456 controller->updateDragAndDrop(newTarget.get(), event.position(), event.t imestamp()); 1476 controller->updateDragAndDrop(newTarget.get(), event.position(), event.t imestamp());
1457 1477
1458 if (m_dragTarget != newTarget) { 1478 if (m_dragTarget != newTarget) {
1459 // FIXME: this ordering was explicitly chosen to match WinIE. However, 1479 // FIXME: this ordering was explicitly chosen to match WinIE. However,
1460 // it is sometimes incorrect when dragging within subframes, as seen wit h 1480 // it is sometimes incorrect when dragging within subframes, as seen wit h
1461 // LayoutTests/fast/events/drag-in-frames.html. 1481 // LayoutTests/fast/events/drag-in-frames.html.
1462 // 1482 //
1463 // Moreover, this ordering conforms to section 7.9.4 of the HTML 5 spec. <http://dev.w3.org/html5/spec/Overview.html#drag-and-drop-processing-model>. 1483 // Moreover, this ordering conforms to section 7.9.4 of the HTML 5 spec. <http://dev.w3.org/html5/spec/Overview.html#drag-and-drop-processing-model>.
1464 LocalFrame* targetFrame; 1484 LocalFrame* targetFrame;
1465 if (targetIsFrame(newTarget.get(), targetFrame)) { 1485 if (targetIsFrame(newTarget.get(), targetFrame)) {
1466 if (targetFrame) 1486 if (targetFrame)
1467 accept = targetFrame->eventHandler().updateDragAndDrop(event, da taTransfer); 1487 eventResult = targetFrame->eventHandler().updateDragAndDrop(even t, dataTransfer);
1468 } else if (newTarget) { 1488 } else if (newTarget) {
1469 // As per section 7.9.4 of the HTML 5 spec., we must always fire a d rag event before firing a dragenter, dragleave, or dragover event. 1489 // As per section 7.9.4 of the HTML 5 spec., we must always fire a d rag event before firing a dragenter, dragleave, or dragover event.
1470 if (dragState().m_dragSrc) { 1490 if (dragState().m_dragSrc) {
1471 // for now we don't care if event handler cancels default behavi or, since there is none 1491 // for now we don't care if event handler cancels default behavi or, since there is none
1472 dispatchDragSrcEvent(EventTypeNames::drag, event); 1492 dispatchDragSrcEvent(EventTypeNames::drag, event);
1473 } 1493 }
1474 accept = dispatchDragEvent(EventTypeNames::dragenter, newTarget.get( ), event, dataTransfer); 1494 eventResult = dispatchDragEvent(EventTypeNames::dragenter, newTarget .get(), event, dataTransfer);
1475 if (!accept) 1495 if (eventResult == WebInputEventResult::NotHandled && findDropZone(n ewTarget.get(), dataTransfer))
1476 accept = findDropZone(newTarget.get(), dataTransfer); 1496 eventResult = WebInputEventResult::HandledSystem;
1477 } 1497 }
1478 1498
1479 if (targetIsFrame(m_dragTarget.get(), targetFrame)) { 1499 if (targetIsFrame(m_dragTarget.get(), targetFrame)) {
1480 if (targetFrame) 1500 if (targetFrame)
1481 accept = targetFrame->eventHandler().updateDragAndDrop(event, da taTransfer); 1501 eventResult = targetFrame->eventHandler().updateDragAndDrop(even t, dataTransfer);
1482 } else if (m_dragTarget) { 1502 } else if (m_dragTarget) {
1483 dispatchDragEvent(EventTypeNames::dragleave, m_dragTarget.get(), eve nt, dataTransfer); 1503 dispatchDragEvent(EventTypeNames::dragleave, m_dragTarget.get(), eve nt, dataTransfer);
1484 } 1504 }
1485 1505
1486 if (newTarget) { 1506 if (newTarget) {
1487 // We do not explicitly call dispatchDragEvent here because it could ultimately result in the appearance that 1507 // We do not explicitly call dispatchDragEvent here because it could ultimately result in the appearance that
1488 // two dragover events fired. So, we mark that we should only fire a dragover event on the next call to this function. 1508 // two dragover events fired. So, we mark that we should only fire a dragover event on the next call to this function.
1489 m_shouldOnlyFireDragOverEvent = true; 1509 m_shouldOnlyFireDragOverEvent = true;
1490 } 1510 }
1491 } else { 1511 } else {
1492 LocalFrame* targetFrame; 1512 LocalFrame* targetFrame;
1493 if (targetIsFrame(newTarget.get(), targetFrame)) { 1513 if (targetIsFrame(newTarget.get(), targetFrame)) {
1494 if (targetFrame) 1514 if (targetFrame)
1495 accept = targetFrame->eventHandler().updateDragAndDrop(event, da taTransfer); 1515 eventResult = targetFrame->eventHandler().updateDragAndDrop(even t, dataTransfer);
1496 } else if (newTarget) { 1516 } else if (newTarget) {
1497 // Note, when dealing with sub-frames, we may need to fire only a dr agover event as a drag event may have been fired earlier. 1517 // Note, when dealing with sub-frames, we may need to fire only a dr agover event as a drag event may have been fired earlier.
1498 if (!m_shouldOnlyFireDragOverEvent && dragState().m_dragSrc) { 1518 if (!m_shouldOnlyFireDragOverEvent && dragState().m_dragSrc) {
1499 // for now we don't care if event handler cancels default behavi or, since there is none 1519 // for now we don't care if event handler cancels default behavi or, since there is none
1500 dispatchDragSrcEvent(EventTypeNames::drag, event); 1520 dispatchDragSrcEvent(EventTypeNames::drag, event);
1501 } 1521 }
1502 accept = dispatchDragEvent(EventTypeNames::dragover, newTarget.get() , event, dataTransfer); 1522 eventResult = dispatchDragEvent(EventTypeNames::dragover, newTarget. get(), event, dataTransfer);
1503 if (!accept) 1523 if (eventResult == WebInputEventResult::NotHandled && findDropZone(n ewTarget.get(), dataTransfer))
1504 accept = findDropZone(newTarget.get(), dataTransfer); 1524 eventResult = WebInputEventResult::HandledSystem;
1505 m_shouldOnlyFireDragOverEvent = false; 1525 m_shouldOnlyFireDragOverEvent = false;
1506 } 1526 }
1507 } 1527 }
1508 m_dragTarget = newTarget; 1528 m_dragTarget = newTarget;
1509 1529
1510 return accept; 1530 return eventResult;
1511 } 1531 }
1512 1532
1513 void EventHandler::cancelDragAndDrop(const PlatformMouseEvent& event, DataTransf er* dataTransfer) 1533 void EventHandler::cancelDragAndDrop(const PlatformMouseEvent& event, DataTransf er* dataTransfer)
1514 { 1534 {
1515 LocalFrame* targetFrame; 1535 LocalFrame* targetFrame;
1516 if (targetIsFrame(m_dragTarget.get(), targetFrame)) { 1536 if (targetIsFrame(m_dragTarget.get(), targetFrame)) {
1517 if (targetFrame) 1537 if (targetFrame)
1518 targetFrame->eventHandler().cancelDragAndDrop(event, dataTransfer); 1538 targetFrame->eventHandler().cancelDragAndDrop(event, dataTransfer);
1519 } else if (m_dragTarget.get()) { 1539 } else if (m_dragTarget.get()) {
1520 if (dragState().m_dragSrc) 1540 if (dragState().m_dragSrc)
1521 dispatchDragSrcEvent(EventTypeNames::drag, event); 1541 dispatchDragSrcEvent(EventTypeNames::drag, event);
1522 dispatchDragEvent(EventTypeNames::dragleave, m_dragTarget.get(), event, dataTransfer); 1542 dispatchDragEvent(EventTypeNames::dragleave, m_dragTarget.get(), event, dataTransfer);
1523 } 1543 }
1524 clearDragState(); 1544 clearDragState();
1525 } 1545 }
1526 1546
1527 bool EventHandler::performDragAndDrop(const PlatformMouseEvent& event, DataTrans fer* dataTransfer) 1547 WebInputEventResult EventHandler::performDragAndDrop(const PlatformMouseEvent& e vent, DataTransfer* dataTransfer)
1528 { 1548 {
1529 LocalFrame* targetFrame; 1549 LocalFrame* targetFrame;
1530 bool preventedDefault = false; 1550 WebInputEventResult result = WebInputEventResult::NotHandled;
1531 if (targetIsFrame(m_dragTarget.get(), targetFrame)) { 1551 if (targetIsFrame(m_dragTarget.get(), targetFrame)) {
1532 if (targetFrame) 1552 if (targetFrame)
1533 preventedDefault = targetFrame->eventHandler().performDragAndDrop(ev ent, dataTransfer); 1553 result = targetFrame->eventHandler().performDragAndDrop(event, dataT ransfer);
1534 } else if (m_dragTarget.get()) { 1554 } else if (m_dragTarget.get()) {
1535 preventedDefault = dispatchDragEvent(EventTypeNames::drop, m_dragTarget. get(), event, dataTransfer); 1555 result = dispatchDragEvent(EventTypeNames::drop, m_dragTarget.get(), eve nt, dataTransfer);
1536 } 1556 }
1537 clearDragState(); 1557 clearDragState();
1538 return preventedDefault; 1558 return result;
1539 } 1559 }
1540 1560
1541 void EventHandler::clearDragState() 1561 void EventHandler::clearDragState()
1542 { 1562 {
1543 stopAutoscroll(); 1563 stopAutoscroll();
1544 m_dragTarget = nullptr; 1564 m_dragTarget = nullptr;
1545 m_capturingMouseEventsNode = nullptr; 1565 m_capturingMouseEventsNode = nullptr;
1546 m_shouldOnlyFireDragOverEvent = false; 1566 m_shouldOnlyFireDragOverEvent = false;
1547 } 1567 }
1548 1568
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
1605 1625
1606 if (lastNodeUnderMouse && lastNodeUnderMouse->document() != m_frame->documen t()) { 1626 if (lastNodeUnderMouse && lastNodeUnderMouse->document() != m_frame->documen t()) {
1607 lastNodeUnderMouse = nullptr; 1627 lastNodeUnderMouse = nullptr;
1608 m_lastScrollbarUnderMouse = nullptr; 1628 m_lastScrollbarUnderMouse = nullptr;
1609 } 1629 }
1610 1630
1611 if (lastNodeUnderMouse != m_nodeUnderMouse) 1631 if (lastNodeUnderMouse != m_nodeUnderMouse)
1612 sendMouseEventsForNodeTransition(lastNodeUnderMouse.get(), m_nodeUnderMo use.get(), mouseEvent); 1632 sendMouseEventsForNodeTransition(lastNodeUnderMouse.get(), m_nodeUnderMo use.get(), mouseEvent);
1613 } 1633 }
1614 1634
1615 bool EventHandler::dispatchPointerEvent(Node* target, const AtomicString& eventT ype, 1635 WebInputEventResult EventHandler::dispatchPointerEvent(Node* target, const Atomi cString& eventType,
1616 const PlatformMouseEvent& mouseEvent, Node* relatedTarget) 1636 const PlatformMouseEvent& mouseEvent, Node* relatedTarget)
1617 { 1637 {
1618 if (!RuntimeEnabledFeatures::pointerEventEnabled()) 1638 if (!RuntimeEnabledFeatures::pointerEventEnabled())
1619 return false; 1639 return WebInputEventResult::NotHandled;
1620 1640
1621 RefPtrWillBeRawPtr<PointerEvent> pointerEvent = PointerEvent::create(eventTy pe, true, 1641 RefPtrWillBeRawPtr<PointerEvent> pointerEvent = PointerEvent::create(eventTy pe, true,
1622 mouseEvent, relatedTarget, m_frame->document()->domWindow()); 1642 mouseEvent, relatedTarget, m_frame->document()->domWindow());
1623 target->dispatchEvent(pointerEvent.get()); 1643
1624 return pointerEvent->defaultPrevented() || pointerEvent->defaultHandled(); 1644 bool dispatchResult = target->dispatchEvent(pointerEvent.get());
1645 return eventToEventResult(pointerEvent, dispatchResult);
1625 } 1646 }
1626 1647
1627 void EventHandler::sendMouseEventsForNodeTransition(Node* exitedNode, Node* ente redNode, 1648 void EventHandler::sendMouseEventsForNodeTransition(Node* exitedNode, Node* ente redNode,
1628 const PlatformMouseEvent& mouseEvent) 1649 const PlatformMouseEvent& mouseEvent)
1629 { 1650 {
1630 ASSERT(exitedNode != enteredNode); 1651 ASSERT(exitedNode != enteredNode);
1631 1652
1632 // Dispatch pointerout/mouseout events 1653 // Dispatch pointerout/mouseout events
1633 if (isNodeInDocument(exitedNode)) { 1654 if (isNodeInDocument(exitedNode)) {
1634 dispatchPointerEvent(exitedNode, EventTypeNames::pointerout, mouseEvent, enteredNode); 1655 dispatchPointerEvent(exitedNode, EventTypeNames::pointerout, mouseEvent, enteredNode);
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
1720 for (size_t i = enteredAncestorIndex; i > 0; i--) { 1741 for (size_t i = enteredAncestorIndex; i > 0; i--) {
1721 if (enteredNodeHasCapturingAncestor || enteredAncestors[i-1]->hasEventLi steners(EventTypeNames::pointerenter)) { 1742 if (enteredNodeHasCapturingAncestor || enteredAncestors[i-1]->hasEventLi steners(EventTypeNames::pointerenter)) {
1722 dispatchPointerEvent(enteredAncestors[i-1].get(), EventTypeNames::po interenter, mouseEvent, 1743 dispatchPointerEvent(enteredAncestors[i-1].get(), EventTypeNames::po interenter, mouseEvent,
1723 exitedNode); 1744 exitedNode);
1724 } 1745 }
1725 if (enteredNodeHasCapturingAncestor || enteredAncestors[i-1]->hasEventLi steners(EventTypeNames::mouseenter)) 1746 if (enteredNodeHasCapturingAncestor || enteredAncestors[i-1]->hasEventLi steners(EventTypeNames::mouseenter))
1726 enteredAncestors[i-1]->dispatchMouseEvent(mouseEvent, EventTypeNames ::mouseenter, 0, exitedNode); 1747 enteredAncestors[i-1]->dispatchMouseEvent(mouseEvent, EventTypeNames ::mouseenter, 0, exitedNode);
1727 } 1748 }
1728 } 1749 }
1729 1750
1730 bool EventHandler::dispatchMouseEvent(const AtomicString& eventType, Node* targe tNode, int clickCount, const PlatformMouseEvent& mouseEvent) 1751 WebInputEventResult EventHandler::dispatchMouseEvent(const AtomicString& eventTy pe, Node* targetNode, int clickCount, const PlatformMouseEvent& mouseEvent)
1731 { 1752 {
1732 updateMouseEventTargetNode(targetNode, mouseEvent); 1753 updateMouseEventTargetNode(targetNode, mouseEvent);
1733 return m_nodeUnderMouse && !m_nodeUnderMouse->dispatchMouseEvent(mouseEvent, eventType, clickCount); 1754 if (!m_nodeUnderMouse)
1755 return WebInputEventResult::NotHandled;
1756
1757 RefPtrWillBeRawPtr<MouseEvent> event = MouseEvent::create(eventType, m_nodeU nderMouse->document().domWindow(), mouseEvent, clickCount, nullptr);
1758 bool dispatchResult = m_nodeUnderMouse->dispatchEvent(event);
1759 return eventToEventResult(event, dispatchResult);
1734 } 1760 }
1735 1761
1736 // TODO(mustaq): Make PE drive ME dispatch & bookkeeping in EventHandler. 1762 // TODO(mustaq): Make PE drive ME dispatch & bookkeeping in EventHandler.
1737 bool EventHandler::updatePointerTargetAndDispatchEvents(const AtomicString& mous eEventType, Node* targetNode, int clickCount, const PlatformMouseEvent& mouseEve nt) 1763 WebInputEventResult EventHandler::updatePointerTargetAndDispatchEvents(const Ato micString& mouseEventType, Node* targetNode, int clickCount, const PlatformMouse Event& mouseEvent)
1738 { 1764 {
1739 ASSERT(mouseEventType == EventTypeNames::mousedown 1765 ASSERT(mouseEventType == EventTypeNames::mousedown
1740 || mouseEventType == EventTypeNames::mousemove 1766 || mouseEventType == EventTypeNames::mousemove
1741 || mouseEventType == EventTypeNames::mouseup); 1767 || mouseEventType == EventTypeNames::mouseup);
1742 1768
1743 updateMouseEventTargetNode(targetNode, mouseEvent); 1769 updateMouseEventTargetNode(targetNode, mouseEvent);
1744 if (!m_nodeUnderMouse) 1770 if (!m_nodeUnderMouse)
1745 return false; 1771 return WebInputEventResult::NotHandled;
1746 1772
1747 bool swallowEvent = dispatchPointerEvent(m_nodeUnderMouse.get(), 1773 WebInputEventResult result = dispatchPointerEvent(m_nodeUnderMouse.get(),
1748 pointerEventNameForMouseEventName(mouseEventType), 1774 pointerEventNameForMouseEventName(mouseEventType),
1749 mouseEvent); 1775 mouseEvent);
1750 1776
1751 if (swallowEvent && mouseEventType == EventTypeNames::mousedown) { 1777 if (result != WebInputEventResult::NotHandled && mouseEventType == EventType Names::mousedown) {
1752 m_preventMouseEventForPointerTypeMouse = true; 1778 m_preventMouseEventForPointerTypeMouse = true;
1753 } 1779 }
1754 1780
1755 if (!m_preventMouseEventForPointerTypeMouse) { 1781 if (!m_preventMouseEventForPointerTypeMouse) {
1756 swallowEvent |= !m_nodeUnderMouse->dispatchMouseEvent(mouseEvent, mouseE ventType, clickCount); 1782 RefPtrWillBeRawPtr<MouseEvent> event = MouseEvent::create(mouseEventType , m_nodeUnderMouse->document().domWindow(), mouseEvent, clickCount, nullptr);
1783 bool dispatchResult = m_nodeUnderMouse->dispatchEvent(event);
1784 result = mergeEventResult(result, eventToEventResult(event, dispatchResu lt));
1757 } 1785 }
1758 1786
1759 return swallowEvent; 1787 return result;
1760 } 1788 }
1761 1789
1762 bool EventHandler::handleMouseFocus(const MouseEventWithHitTestResults& targeted Event, InputDeviceCapabilities* sourceCapabilities) 1790 WebInputEventResult EventHandler::handleMouseFocus(const MouseEventWithHitTestRe sults& targetedEvent, InputDeviceCapabilities* sourceCapabilities)
1763 { 1791 {
1764 // If clicking on a frame scrollbar, do not mess up with content focus. 1792 // If clicking on a frame scrollbar, do not mess up with content focus.
1765 if (targetedEvent.hitTestResult().scrollbar() && m_frame->contentLayoutObjec t()) { 1793 if (targetedEvent.hitTestResult().scrollbar() && m_frame->contentLayoutObjec t()) {
1766 if (targetedEvent.hitTestResult().scrollbar()->scrollableArea() == m_fra me->contentLayoutObject()->scrollableArea()) 1794 if (targetedEvent.hitTestResult().scrollbar()->scrollableArea() == m_fra me->contentLayoutObject()->scrollableArea())
1767 return false; 1795 return WebInputEventResult::NotHandled;
1768 } 1796 }
1769 1797
1770 // The layout needs to be up to date to determine if an element is focusable . 1798 // The layout needs to be up to date to determine if an element is focusable .
1771 m_frame->document()->updateLayoutIgnorePendingStylesheets(); 1799 m_frame->document()->updateLayoutIgnorePendingStylesheets();
1772 1800
1773 Element* element = nullptr; 1801 Element* element = nullptr;
1774 if (m_nodeUnderMouse) 1802 if (m_nodeUnderMouse)
1775 element = m_nodeUnderMouse->isElementNode() ? toElement(m_nodeUnderMouse ) : m_nodeUnderMouse->parentOrShadowHostElement(); 1803 element = m_nodeUnderMouse->isElementNode() ? toElement(m_nodeUnderMouse ) : m_nodeUnderMouse->parentOrShadowHostElement();
1776 for (; element; element = element->parentOrShadowHostElement()) { 1804 for (; element; element = element->parentOrShadowHostElement()) {
1777 if (element->isFocusable() && element->isFocusedElementInDocument()) 1805 if (element->isFocusable() && element->isFocusedElementInDocument())
1778 return false; 1806 return WebInputEventResult::NotHandled;
1779 if (element->isMouseFocusable()) 1807 if (element->isMouseFocusable())
1780 break; 1808 break;
1781 } 1809 }
1782 ASSERT(!element || element->isMouseFocusable()); 1810 ASSERT(!element || element->isMouseFocusable());
1783 1811
1784 // To fix <rdar://problem/4895428> Can't drag selected ToDo, we don't focus 1812 // To fix <rdar://problem/4895428> Can't drag selected ToDo, we don't focus
1785 // a node on mouse down if it's selected and inside a focused node. It will 1813 // a node on mouse down if it's selected and inside a focused node. It will
1786 // be focused if the user does a mouseup over it, however, because the 1814 // be focused if the user does a mouseup over it, however, because the
1787 // mouseup will set a selection inside it, which will call 1815 // mouseup will set a selection inside it, which will call
1788 // FrameSelection::setFocusedNodeIfNeeded. 1816 // FrameSelection::setFocusedNodeIfNeeded.
1789 if (element && m_frame->selection().isRange()) { 1817 if (element && m_frame->selection().isRange()) {
1790 // TODO(yosin) We should not create |Range| object for calling 1818 // TODO(yosin) We should not create |Range| object for calling
1791 // |isNodeFullyContained()|. 1819 // |isNodeFullyContained()|.
1792 if (createRange(m_frame->selection().selection().toNormalizedEphemeralRa nge())->isNodeFullyContained(*element) 1820 if (createRange(m_frame->selection().selection().toNormalizedEphemeralRa nge())->isNodeFullyContained(*element)
1793 && element->isDescendantOf(m_frame->document()->focusedElement())) 1821 && element->isDescendantOf(m_frame->document()->focusedElement()))
1794 return false; 1822 return WebInputEventResult::NotHandled;
1795 } 1823 }
1796 1824
1797 1825
1798 // Only change the focus when clicking scrollbars if it can transfered to a 1826 // Only change the focus when clicking scrollbars if it can transfered to a
1799 // mouse focusable node. 1827 // mouse focusable node.
1800 if (!element && targetedEvent.hitTestResult().scrollbar()) 1828 if (!element && targetedEvent.hitTestResult().scrollbar())
1801 return true; 1829 return WebInputEventResult::HandledSystem;
1802 1830
1803 if (Page* page = m_frame->page()) { 1831 if (Page* page = m_frame->page()) {
1804 // If focus shift is blocked, we eat the event. Note we should never 1832 // If focus shift is blocked, we eat the event. Note we should never
1805 // clear swallowEvent if the page already set it (e.g., by canceling 1833 // clear swallowEvent if the page already set it (e.g., by canceling
1806 // default behavior). 1834 // default behavior).
1807 if (element) { 1835 if (element) {
1808 if (slideFocusOnShadowHostIfNecessary(*element)) 1836 if (slideFocusOnShadowHostIfNecessary(*element))
1809 return true; 1837 return WebInputEventResult::HandledSystem;
1810 if (!page->focusController().setFocusedElement(element, m_frame, Foc usParams(SelectionBehaviorOnFocus::None, WebFocusTypeMouse, sourceCapabilities)) ) 1838 if (!page->focusController().setFocusedElement(element, m_frame, Foc usParams(SelectionBehaviorOnFocus::None, WebFocusTypeMouse, sourceCapabilities)) )
1811 return true; 1839 return WebInputEventResult::HandledSystem;
1812 } else { 1840 } else {
1813 // We call setFocusedElement even with !element in order to blur 1841 // We call setFocusedElement even with !element in order to blur
1814 // current focus element when a link is clicked; this is expected by 1842 // current focus element when a link is clicked; this is expected by
1815 // some sites that rely on onChange handlers running from form 1843 // some sites that rely on onChange handlers running from form
1816 // fields before the button click is processed. 1844 // fields before the button click is processed.
1817 if (!page->focusController().setFocusedElement(nullptr, m_frame, Foc usParams(SelectionBehaviorOnFocus::None, WebFocusTypeNone, sourceCapabilities))) 1845 if (!page->focusController().setFocusedElement(nullptr, m_frame, Foc usParams(SelectionBehaviorOnFocus::None, WebFocusTypeNone, sourceCapabilities)))
1818 return true; 1846 return WebInputEventResult::HandledSystem;
1819 } 1847 }
1820 } 1848 }
1821 1849
1822 return false; 1850 return WebInputEventResult::NotHandled;
1823 } 1851 }
1824 1852
1825 bool EventHandler::slideFocusOnShadowHostIfNecessary(const Element& element) 1853 bool EventHandler::slideFocusOnShadowHostIfNecessary(const Element& element)
1826 { 1854 {
1827 if (element.authorShadowRoot() && element.authorShadowRoot()->delegatesFocus ()) { 1855 if (element.authorShadowRoot() && element.authorShadowRoot()->delegatesFocus ()) {
1828 Document* doc = m_frame->document(); 1856 Document* doc = m_frame->document();
1829 if (element.containsIncludingShadowDOM(doc->focusedElement())) { 1857 if (element.containsIncludingShadowDOM(doc->focusedElement())) {
1830 // If the inner element is already focused, do nothing. 1858 // If the inner element is already focused, do nothing.
1831 return true; 1859 return true;
1832 } 1860 }
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
1873 ScrollResult result; 1901 ScrollResult result;
1874 result.didScrollY = resultY.didScroll; 1902 result.didScrollY = resultY.didScroll;
1875 result.didScrollX = resultX.didScroll; 1903 result.didScrollX = resultX.didScroll;
1876 result.unusedScrollDeltaY = resultY.unusedScrollDelta; 1904 result.unusedScrollDeltaY = resultY.unusedScrollDelta;
1877 result.unusedScrollDeltaX = resultX.unusedScrollDelta; 1905 result.unusedScrollDeltaX = resultX.unusedScrollDelta;
1878 return result; 1906 return result;
1879 } 1907 }
1880 1908
1881 } // namespace 1909 } // namespace
1882 1910
1883 bool EventHandler::handleWheelEvent(const PlatformWheelEvent& event) 1911 WebInputEventResult EventHandler::handleWheelEvent(const PlatformWheelEvent& eve nt)
1884 { 1912 {
1885 #define RETURN_WHEEL_EVENT_HANDLED() \
1886 { \
1887 setFrameWasScrolledByUser(); \
1888 return true; \
1889 }
1890
1891 Document* doc = m_frame->document(); 1913 Document* doc = m_frame->document();
1892 1914
1893 if (!doc->layoutView()) 1915 if (!doc->layoutView())
1894 return false; 1916 return WebInputEventResult::NotHandled;
1895 1917
1896 RefPtrWillBeRawPtr<FrameView> protector(m_frame->view()); 1918 RefPtrWillBeRawPtr<FrameView> protector(m_frame->view());
1897 1919
1898 FrameView* view = m_frame->view(); 1920 FrameView* view = m_frame->view();
1899 if (!view) 1921 if (!view)
1900 return false; 1922 return WebInputEventResult::NotHandled;
1901 1923
1902 LayoutPoint vPoint = view->rootFrameToContents(event.position()); 1924 LayoutPoint vPoint = view->rootFrameToContents(event.position());
1903 1925
1904 HitTestRequest request(HitTestRequest::ReadOnly); 1926 HitTestRequest request(HitTestRequest::ReadOnly);
1905 HitTestResult result(request, vPoint); 1927 HitTestResult result(request, vPoint);
1906 doc->layoutView()->hitTest(result); 1928 doc->layoutView()->hitTest(result);
1907 1929
1908 Node* node = result.innerNode(); 1930 Node* node = result.innerNode();
1909 // Wheel events should not dispatch to text nodes. 1931 // Wheel events should not dispatch to text nodes.
1910 if (node && node->isTextNode()) 1932 if (node && node->isTextNode())
1911 node = ComposedTreeTraversal::parent(*node); 1933 node = ComposedTreeTraversal::parent(*node);
1912 1934
1913 if (m_previousWheelScrolledNode) 1935 if (m_previousWheelScrolledNode)
1914 m_previousWheelScrolledNode = nullptr; 1936 m_previousWheelScrolledNode = nullptr;
1915 1937
1916 bool isOverWidget = result.isOverWidget(); 1938 bool isOverWidget = result.isOverWidget();
1917 1939
1918 if (node) { 1940 if (node) {
1919 // Figure out which view to send the event to. 1941 // Figure out which view to send the event to.
1920 LayoutObject* target = node->layoutObject(); 1942 LayoutObject* target = node->layoutObject();
1921 1943
1922 if (isOverWidget && target && target->isLayoutPart()) { 1944 if (isOverWidget && target && target->isLayoutPart()) {
1923 Widget* widget = toLayoutPart(target)->widget(); 1945 if (Widget* widget = toLayoutPart(target)->widget()) {
1924 if (widget && passWheelEventToWidget(event, *widget)) 1946 WebInputEventResult result = passWheelEventToWidget(event, *widg et);
1925 RETURN_WHEEL_EVENT_HANDLED(); 1947 if (result != WebInputEventResult::NotHandled) {
1948 setFrameWasScrolledByUser();
1949 return result;
1950 }
1951 }
1926 } 1952 }
1927 1953
1928 if (node && !node->dispatchWheelEvent(event)) 1954 RefPtrWillBeRawPtr<Event> domEvent = WheelEvent::create(event, node->doc ument().domWindow());
1929 RETURN_WHEEL_EVENT_HANDLED(); 1955 if (!node->dispatchEvent(domEvent)) {
1956 setFrameWasScrolledByUser();
1957 return eventToEventResult(domEvent, false);
1958 }
1930 } 1959 }
1931 1960
1932 // We do another check on the frame view because the event handler can run 1961 // We do another check on the frame view because the event handler can run
1933 // JS which results in the frame getting destroyed. 1962 // JS which results in the frame getting destroyed.
1934 view = m_frame->view(); 1963 view = m_frame->view();
1935 if (!view) 1964 if (!view)
1936 return false; 1965 return WebInputEventResult::NotHandled;
1937 1966
1938 // Wheel events which do not scroll are used to trigger zooming. 1967 // Wheel events which do not scroll are used to trigger zooming.
1939 if (!event.canScroll()) 1968 if (!event.canScroll())
1940 return false; 1969 return WebInputEventResult::NotHandled;
1941 1970
1942 ScrollResult scrollResult = scrollAreaWithWheelEvent(event, *view->scrollabl eArea()); 1971 ScrollResult scrollResult = scrollAreaWithWheelEvent(event, *view->scrollabl eArea());
1943 if (m_frame->settings() && m_frame->settings()->reportWheelOverscroll()) 1972 if (m_frame->settings() && m_frame->settings()->reportWheelOverscroll())
1944 handleOverscroll(scrollResult); 1973 handleOverscroll(scrollResult);
1945 if (scrollResult.didScroll()) 1974 if (scrollResult.didScroll()) {
1946 RETURN_WHEEL_EVENT_HANDLED(); 1975 setFrameWasScrolledByUser();
1976 return WebInputEventResult::HandledSystem;
1977 }
1947 1978
1948 return false; 1979 return WebInputEventResult::NotHandled;
1949 #undef RETURN_WHEEL_EVENT_HANDLED
1950 } 1980 }
1951 1981
1952 void EventHandler::defaultWheelEventHandler(Node* startNode, WheelEvent* wheelEv ent) 1982 void EventHandler::defaultWheelEventHandler(Node* startNode, WheelEvent* wheelEv ent)
1953 { 1983 {
1954 if (!startNode || !wheelEvent) 1984 if (!startNode || !wheelEvent)
1955 return; 1985 return;
1956 1986
1957 // When the wheelEvent do not scroll, we trigger zoom in/out instead. 1987 // When the wheelEvent do not scroll, we trigger zoom in/out instead.
1958 if (!wheelEvent->canScroll()) 1988 if (!wheelEvent->canScroll())
1959 return; 1989 return;
(...skipping 10 matching lines...) Expand all
1970 && scroll(ScrollRightIgnoringWritingMode, granularity, startNode, &stopN ode, wheelEvent->deltaX(), absolutePosition).didScroll) 2000 && scroll(ScrollRightIgnoringWritingMode, granularity, startNode, &stopN ode, wheelEvent->deltaX(), absolutePosition).didScroll)
1971 wheelEvent->setDefaultHandled(); 2001 wheelEvent->setDefaultHandled();
1972 2002
1973 if (wheelEvent->railsMode() != Event::RailsModeHorizontal 2003 if (wheelEvent->railsMode() != Event::RailsModeHorizontal
1974 && scroll(ScrollDownIgnoringWritingMode, granularity, startNode, &stopNo de, wheelEvent->deltaY(), absolutePosition).didScroll) 2004 && scroll(ScrollDownIgnoringWritingMode, granularity, startNode, &stopNo de, wheelEvent->deltaY(), absolutePosition).didScroll)
1975 wheelEvent->setDefaultHandled(); 2005 wheelEvent->setDefaultHandled();
1976 2006
1977 m_previousWheelScrolledNode = stopNode; 2007 m_previousWheelScrolledNode = stopNode;
1978 } 2008 }
1979 2009
1980 bool EventHandler::handleGestureShowPress() 2010 WebInputEventResult EventHandler::handleGestureShowPress()
1981 { 2011 {
1982 m_lastShowPressTimestamp = WTF::currentTime(); 2012 m_lastShowPressTimestamp = WTF::currentTime();
1983 2013
1984 FrameView* view = m_frame->view(); 2014 FrameView* view = m_frame->view();
1985 if (!view) 2015 if (!view)
1986 return false; 2016 return WebInputEventResult::NotHandled;
1987 if (ScrollAnimatorBase* scrollAnimator = view->existingScrollAnimator()) 2017 if (ScrollAnimatorBase* scrollAnimator = view->existingScrollAnimator())
1988 scrollAnimator->cancelAnimations(); 2018 scrollAnimator->cancelAnimations();
1989 const FrameView::ScrollableAreaSet* areas = view->scrollableAreas(); 2019 const FrameView::ScrollableAreaSet* areas = view->scrollableAreas();
1990 if (!areas) 2020 if (!areas)
1991 return false; 2021 return WebInputEventResult::NotHandled;
1992 for (const ScrollableArea* scrollableArea : *areas) { 2022 for (const ScrollableArea* scrollableArea : *areas) {
1993 ScrollAnimatorBase* animator = scrollableArea->existingScrollAnimator(); 2023 ScrollAnimatorBase* animator = scrollableArea->existingScrollAnimator();
1994 if (animator) 2024 if (animator)
1995 animator->cancelAnimations(); 2025 animator->cancelAnimations();
1996 } 2026 }
1997 return false; 2027 return WebInputEventResult::NotHandled;
1998 } 2028 }
1999 2029
2000 bool EventHandler::handleGestureEvent(const PlatformGestureEvent& gestureEvent) 2030 WebInputEventResult EventHandler::handleGestureEvent(const PlatformGestureEvent& gestureEvent)
2001 { 2031 {
2002 // Propagation to inner frames is handled below this function. 2032 // Propagation to inner frames is handled below this function.
2003 ASSERT(m_frame == m_frame->localFrameRoot()); 2033 ASSERT(m_frame == m_frame->localFrameRoot());
2004 2034
2005 // Scrolling-related gesture events invoke EventHandler recursively for each frame down 2035 // Scrolling-related gesture events invoke EventHandler recursively for each frame down
2006 // the chain, doing a single-frame hit-test per frame. This matches handleWh eelEvent. 2036 // the chain, doing a single-frame hit-test per frame. This matches handleWh eelEvent.
2007 // FIXME: Add a test that traverses this path, e.g. for devtools overlay. 2037 // FIXME: Add a test that traverses this path, e.g. for devtools overlay.
2008 if (gestureEvent.isScrollEvent()) 2038 if (gestureEvent.isScrollEvent())
2009 return handleGestureScrollEvent(gestureEvent); 2039 return handleGestureScrollEvent(gestureEvent);
2010 2040
2011 // Hit test across all frames and do touch adjustment as necessary for the e vent type. 2041 // Hit test across all frames and do touch adjustment as necessary for the e vent type.
2012 GestureEventWithHitTestResults targetedEvent = targetGestureEvent(gestureEve nt); 2042 GestureEventWithHitTestResults targetedEvent = targetGestureEvent(gestureEve nt);
2013 2043
2014 return handleGestureEvent(targetedEvent); 2044 return handleGestureEvent(targetedEvent);
2015 } 2045 }
2016 2046
2017 bool EventHandler::handleGestureEvent(const GestureEventWithHitTestResults& targ etedEvent) 2047 WebInputEventResult EventHandler::handleGestureEvent(const GestureEventWithHitTe stResults& targetedEvent)
2018 { 2048 {
2019 TRACE_EVENT0("input", "EventHandler::handleGestureEvent"); 2049 TRACE_EVENT0("input", "EventHandler::handleGestureEvent");
2020 2050
2021 // Propagation to inner frames is handled below this function. 2051 // Propagation to inner frames is handled below this function.
2022 ASSERT(m_frame == m_frame->localFrameRoot()); 2052 ASSERT(m_frame == m_frame->localFrameRoot());
2023 2053
2024 // Non-scrolling related gesture events do a single cross-frame hit-test and jump 2054 // Non-scrolling related gesture events do a single cross-frame hit-test and jump
2025 // directly to the inner most frame. This matches handleMousePressEvent etc. 2055 // directly to the inner most frame. This matches handleMousePressEvent etc.
2026 ASSERT(!targetedEvent.event().isScrollEvent()); 2056 ASSERT(!targetedEvent.event().isScrollEvent());
2027 2057
2028 // update mouseout/leave/over/enter events before jumping directly to the in ner most frame 2058 // update mouseout/leave/over/enter events before jumping directly to the in ner most frame
2029 if (targetedEvent.event().type() == PlatformEvent::GestureTap) 2059 if (targetedEvent.event().type() == PlatformEvent::GestureTap)
2030 updateGestureTargetNodeForMouseEvent(targetedEvent); 2060 updateGestureTargetNodeForMouseEvent(targetedEvent);
2031 2061
2032 // Route to the correct frame. 2062 // Route to the correct frame.
2033 if (LocalFrame* innerFrame = targetedEvent.hitTestResult().innerNodeFrame()) 2063 if (LocalFrame* innerFrame = targetedEvent.hitTestResult().innerNodeFrame())
2034 return innerFrame->eventHandler().handleGestureEventInFrame(targetedEven t); 2064 return innerFrame->eventHandler().handleGestureEventInFrame(targetedEven t);
2035 2065
2036 // No hit test result, handle in root instance. Perhaps we should just retur n false instead? 2066 // No hit test result, handle in root instance. Perhaps we should just retur n false instead?
2037 return handleGestureEventInFrame(targetedEvent); 2067 return handleGestureEventInFrame(targetedEvent);
2038 } 2068 }
2039 2069
2040 bool EventHandler::handleGestureEventInFrame(const GestureEventWithHitTestResult s& targetedEvent) 2070 WebInputEventResult EventHandler::handleGestureEventInFrame(const GestureEventWi thHitTestResults& targetedEvent)
2041 { 2071 {
2042 ASSERT(!targetedEvent.event().isScrollEvent()); 2072 ASSERT(!targetedEvent.event().isScrollEvent());
2043 2073
2044 RefPtrWillBeRawPtr<Node> eventTarget = targetedEvent.hitTestResult().innerNo de(); 2074 RefPtrWillBeRawPtr<Node> eventTarget = targetedEvent.hitTestResult().innerNo de();
2045 RefPtrWillBeRawPtr<Scrollbar> scrollbar = targetedEvent.hitTestResult().scro llbar(); 2075 RefPtrWillBeRawPtr<Scrollbar> scrollbar = targetedEvent.hitTestResult().scro llbar();
2046 const PlatformGestureEvent& gestureEvent = targetedEvent.event(); 2076 const PlatformGestureEvent& gestureEvent = targetedEvent.event();
2047 2077
2048 if (scrollbar) { 2078 if (scrollbar) {
2049 bool eventSwallowed = scrollbar->gestureEvent(gestureEvent); 2079 bool eventSwallowed = scrollbar->gestureEvent(gestureEvent);
2050 if (gestureEvent.type() == PlatformEvent::GestureTapDown && eventSwallow ed) 2080 if (gestureEvent.type() == PlatformEvent::GestureTapDown && eventSwallow ed)
2051 m_scrollbarHandlingScrollGesture = scrollbar; 2081 m_scrollbarHandlingScrollGesture = scrollbar;
2052 if (eventSwallowed) 2082 if (eventSwallowed)
2053 return true; 2083 return WebInputEventResult::HandledSuppressed;
2054 } 2084 }
2055 2085
2056 if (eventTarget && eventTarget->dispatchGestureEvent(gestureEvent)) 2086 if (eventTarget) {
2057 return true; 2087 RefPtrWillBeRawPtr<GestureEvent> gestureDomEvent = GestureEvent::create( eventTarget->document().domWindow(), gestureEvent);
2088 // TODO(dtapuska): dispatchEvent is inverted for Gesture Events
2089 // crbug.com/560357
2090 if (gestureDomEvent.get() && eventTarget->dispatchEvent(gestureDomEvent) )
2091 return eventToEventResult(gestureDomEvent, false);
2092 }
2058 2093
2059 switch (gestureEvent.type()) { 2094 switch (gestureEvent.type()) {
2060 case PlatformEvent::GestureTap: 2095 case PlatformEvent::GestureTap:
2061 return handleGestureTap(targetedEvent); 2096 return handleGestureTap(targetedEvent);
2062 case PlatformEvent::GestureShowPress: 2097 case PlatformEvent::GestureShowPress:
2063 return handleGestureShowPress(); 2098 return handleGestureShowPress();
2064 case PlatformEvent::GestureLongPress: 2099 case PlatformEvent::GestureLongPress:
2065 return handleGestureLongPress(targetedEvent); 2100 return handleGestureLongPress(targetedEvent);
2066 case PlatformEvent::GestureLongTap: 2101 case PlatformEvent::GestureLongTap:
2067 return handleGestureLongTap(targetedEvent); 2102 return handleGestureLongTap(targetedEvent);
2068 case PlatformEvent::GestureTwoFingerTap: 2103 case PlatformEvent::GestureTwoFingerTap:
2069 return sendContextMenuEventForGesture(targetedEvent); 2104 return sendContextMenuEventForGesture(targetedEvent);
2070 case PlatformEvent::GestureTapDown: 2105 case PlatformEvent::GestureTapDown:
2071 case PlatformEvent::GesturePinchBegin: 2106 case PlatformEvent::GesturePinchBegin:
2072 case PlatformEvent::GesturePinchEnd: 2107 case PlatformEvent::GesturePinchEnd:
2073 case PlatformEvent::GesturePinchUpdate: 2108 case PlatformEvent::GesturePinchUpdate:
2074 case PlatformEvent::GestureTapDownCancel: 2109 case PlatformEvent::GestureTapDownCancel:
2075 case PlatformEvent::GestureTapUnconfirmed: 2110 case PlatformEvent::GestureTapUnconfirmed:
2076 break; 2111 break;
2077 default: 2112 default:
2078 ASSERT_NOT_REACHED(); 2113 ASSERT_NOT_REACHED();
2079 } 2114 }
2080 2115
2081 return false; 2116 return WebInputEventResult::NotHandled;
2082 } 2117 }
2083 2118
2084 bool EventHandler::handleGestureScrollEvent(const PlatformGestureEvent& gestureE vent) 2119 WebInputEventResult EventHandler::handleGestureScrollEvent(const PlatformGesture Event& gestureEvent)
2085 { 2120 {
2086 TRACE_EVENT0("input", "EventHandler::handleGestureScrollEvent"); 2121 TRACE_EVENT0("input", "EventHandler::handleGestureScrollEvent");
2087 2122
2088 RefPtrWillBeRawPtr<Node> eventTarget = nullptr; 2123 RefPtrWillBeRawPtr<Node> eventTarget = nullptr;
2089 RefPtrWillBeRawPtr<Scrollbar> scrollbar = nullptr; 2124 RefPtrWillBeRawPtr<Scrollbar> scrollbar = nullptr;
2090 if (gestureEvent.type() != PlatformEvent::GestureScrollBegin) { 2125 if (gestureEvent.type() != PlatformEvent::GestureScrollBegin) {
2091 scrollbar = m_scrollbarHandlingScrollGesture.get(); 2126 scrollbar = m_scrollbarHandlingScrollGesture.get();
2092 eventTarget = m_scrollGestureHandlingNode.get(); 2127 eventTarget = m_scrollGestureHandlingNode.get();
2093 } 2128 }
2094 2129
2095 if (!eventTarget) { 2130 if (!eventTarget) {
2096 Document* document = m_frame->document(); 2131 Document* document = m_frame->document();
2097 if (!document->layoutView()) 2132 if (!document->layoutView())
2098 return false; 2133 return WebInputEventResult::NotHandled;
2099 2134
2100 FrameView* view = m_frame->view(); 2135 FrameView* view = m_frame->view();
2101 LayoutPoint viewPoint = view->rootFrameToContents(gestureEvent.position( )); 2136 LayoutPoint viewPoint = view->rootFrameToContents(gestureEvent.position( ));
2102 HitTestRequest request(HitTestRequest::ReadOnly); 2137 HitTestRequest request(HitTestRequest::ReadOnly);
2103 HitTestResult result(request, viewPoint); 2138 HitTestResult result(request, viewPoint);
2104 document->layoutView()->hitTest(result); 2139 document->layoutView()->hitTest(result);
2105 2140
2106 eventTarget = result.innerNode(); 2141 eventTarget = result.innerNode();
2107 2142
2108 m_lastGestureScrollOverWidget = result.isOverWidget(); 2143 m_lastGestureScrollOverWidget = result.isOverWidget();
2109 m_scrollGestureHandlingNode = eventTarget; 2144 m_scrollGestureHandlingNode = eventTarget;
2110 m_previousGestureScrolledNode = nullptr; 2145 m_previousGestureScrolledNode = nullptr;
2111 2146
2112 if (!scrollbar) 2147 if (!scrollbar)
2113 scrollbar = result.scrollbar(); 2148 scrollbar = result.scrollbar();
2114 } 2149 }
2115 2150
2116 if (scrollbar) { 2151 if (scrollbar) {
2117 bool eventSwallowed = scrollbar->gestureEvent(gestureEvent); 2152 bool eventSwallowed = scrollbar->gestureEvent(gestureEvent);
2118 if (gestureEvent.type() == PlatformEvent::GestureScrollEnd 2153 if (gestureEvent.type() == PlatformEvent::GestureScrollEnd
2119 || gestureEvent.type() == PlatformEvent::GestureFlingStart 2154 || gestureEvent.type() == PlatformEvent::GestureFlingStart
2120 || !eventSwallowed) { 2155 || !eventSwallowed) {
2121 m_scrollbarHandlingScrollGesture = nullptr; 2156 m_scrollbarHandlingScrollGesture = nullptr;
2122 } 2157 }
2123 if (eventSwallowed) 2158 if (eventSwallowed)
2124 return true; 2159 return WebInputEventResult::HandledSuppressed;
2125 } 2160 }
2126 2161
2127 if (eventTarget) { 2162 if (eventTarget) {
2128 bool eventSwallowed = handleScrollGestureOnResizer(eventTarget.get(), ge stureEvent); 2163 if (handleScrollGestureOnResizer(eventTarget.get(), gestureEvent))
2129 if (!eventSwallowed) 2164 return WebInputEventResult::HandledSuppressed;
2130 eventSwallowed = eventTarget->dispatchGestureEvent(gestureEvent); 2165
2131 if (eventSwallowed) 2166 RefPtrWillBeRawPtr<GestureEvent> gestureDomEvent = GestureEvent::create( eventTarget->document().domWindow(), gestureEvent);
2132 return true; 2167 // TODO(dtapuska): dispatchEvent is inverted for Gesture Events
2168 // crbug.com/560357
2169 if (gestureDomEvent.get() && eventTarget->dispatchEvent(gestureDomEvent) )
2170 return eventToEventResult(gestureDomEvent, false);
2133 } 2171 }
2134 2172
2135 switch (gestureEvent.type()) { 2173 switch (gestureEvent.type()) {
2136 case PlatformEvent::GestureScrollBegin: 2174 case PlatformEvent::GestureScrollBegin:
2137 return handleGestureScrollBegin(gestureEvent); 2175 return handleGestureScrollBegin(gestureEvent);
2138 case PlatformEvent::GestureScrollUpdate: 2176 case PlatformEvent::GestureScrollUpdate:
2139 return handleGestureScrollUpdate(gestureEvent); 2177 return handleGestureScrollUpdate(gestureEvent);
2140 case PlatformEvent::GestureScrollEnd: 2178 case PlatformEvent::GestureScrollEnd:
2141 return handleGestureScrollEnd(gestureEvent); 2179 return handleGestureScrollEnd(gestureEvent);
2142 case PlatformEvent::GestureFlingStart: 2180 case PlatformEvent::GestureFlingStart:
2143 case PlatformEvent::GesturePinchBegin: 2181 case PlatformEvent::GesturePinchBegin:
2144 case PlatformEvent::GesturePinchEnd: 2182 case PlatformEvent::GesturePinchEnd:
2145 case PlatformEvent::GesturePinchUpdate: 2183 case PlatformEvent::GesturePinchUpdate:
2146 return false; 2184 return WebInputEventResult::NotHandled;
2147 default: 2185 default:
2148 ASSERT_NOT_REACHED(); 2186 ASSERT_NOT_REACHED();
2149 return false; 2187 return WebInputEventResult::NotHandled;
2150 } 2188 }
2151 } 2189 }
2152 2190
2153 bool EventHandler::handleGestureTap(const GestureEventWithHitTestResults& target edEvent) 2191 WebInputEventResult EventHandler::handleGestureTap(const GestureEventWithHitTest Results& targetedEvent)
2154 { 2192 {
2155 RefPtrWillBeRawPtr<FrameView> frameView(m_frame->view()); 2193 RefPtrWillBeRawPtr<FrameView> frameView(m_frame->view());
2156 const PlatformGestureEvent& gestureEvent = targetedEvent.event(); 2194 const PlatformGestureEvent& gestureEvent = targetedEvent.event();
2157 HitTestRequest::HitTestRequestType hitType = getHitTypeForGestureType(gestur eEvent.type()); 2195 HitTestRequest::HitTestRequestType hitType = getHitTypeForGestureType(gestur eEvent.type());
2158 uint64_t preDispatchDomTreeVersion = m_frame->document()->domTreeVersion(); 2196 uint64_t preDispatchDomTreeVersion = m_frame->document()->domTreeVersion();
2159 uint64_t preDispatchStyleVersion = m_frame->document()->styleVersion(); 2197 uint64_t preDispatchStyleVersion = m_frame->document()->styleVersion();
2160 2198
2161 UserGestureIndicator gestureIndicator(DefinitelyProcessingUserGesture); 2199 UserGestureIndicator gestureIndicator(DefinitelyProcessingUserGesture);
2162 2200
2163 HitTestResult currentHitTest = targetedEvent.hitTestResult(); 2201 HitTestResult currentHitTest = targetedEvent.hitTestResult();
(...skipping 29 matching lines...) Expand all
2193 RefPtrWillBeRawPtr<Node> tappedNode = m_clickNode; 2231 RefPtrWillBeRawPtr<Node> tappedNode = m_clickNode;
2194 IntPoint tappedPosition = gestureEvent.position(); 2232 IntPoint tappedPosition = gestureEvent.position();
2195 2233
2196 if (m_clickNode && m_clickNode->isTextNode()) 2234 if (m_clickNode && m_clickNode->isTextNode())
2197 m_clickNode = ComposedTreeTraversal::parent(*m_clickNode); 2235 m_clickNode = ComposedTreeTraversal::parent(*m_clickNode);
2198 2236
2199 PlatformMouseEvent fakeMouseDown(gestureEvent.position(), gestureEvent.globa lPosition(), 2237 PlatformMouseEvent fakeMouseDown(gestureEvent.position(), gestureEvent.globa lPosition(),
2200 LeftButton, PlatformEvent::MousePressed, gestureEvent.tapCount(), 2238 LeftButton, PlatformEvent::MousePressed, gestureEvent.tapCount(),
2201 static_cast<PlatformEvent::Modifiers>(modifiers | PlatformEvent::LeftBut tonDown), 2239 static_cast<PlatformEvent::Modifiers>(modifiers | PlatformEvent::LeftBut tonDown),
2202 PlatformMouseEvent::FromTouch, gestureEvent.timestamp()); 2240 PlatformMouseEvent::FromTouch, gestureEvent.timestamp());
2203 bool swallowMouseDownEvent = dispatchMouseEvent(EventTypeNames::mousedown, c urrentHitTest.innerNode(), gestureEvent.tapCount(), fakeMouseDown); 2241 WebInputEventResult mouseDownEventResult = dispatchMouseEvent(EventTypeNames ::mousedown, currentHitTest.innerNode(), gestureEvent.tapCount(), fakeMouseDown) ;
2204 selectionController().initializeSelectionState(); 2242 selectionController().initializeSelectionState();
2205 if (!swallowMouseDownEvent) 2243 if (mouseDownEventResult == WebInputEventResult::NotHandled)
2206 swallowMouseDownEvent = handleMouseFocus(MouseEventWithHitTestResults(fa keMouseDown, currentHitTest), InputDeviceCapabilities::firesTouchEventsSourceCap abilities()); 2244 mouseDownEventResult = handleMouseFocus(MouseEventWithHitTestResults(fak eMouseDown, currentHitTest), InputDeviceCapabilities::firesTouchEventsSourceCapa bilities());
2207 if (!swallowMouseDownEvent) 2245 if (mouseDownEventResult == WebInputEventResult::NotHandled)
2208 swallowMouseDownEvent = handleMousePressEvent(MouseEventWithHitTestResul ts(fakeMouseDown, currentHitTest)); 2246 mouseDownEventResult = handleMousePressEvent(MouseEventWithHitTestResult s(fakeMouseDown, currentHitTest));
2209 2247
2210 if (currentHitTest.innerNode()) { 2248 if (currentHitTest.innerNode()) {
2211 ASSERT(gestureEvent.type() == PlatformEvent::GestureTap); 2249 ASSERT(gestureEvent.type() == PlatformEvent::GestureTap);
2212 HitTestResult result = currentHitTest; 2250 HitTestResult result = currentHitTest;
2213 result.setToShadowHostIfInUserAgentShadowRoot(); 2251 result.setToShadowHostIfInUserAgentShadowRoot();
2214 m_frame->chromeClient().onMouseDown(result.innerNode()); 2252 m_frame->chromeClient().onMouseDown(result.innerNode());
2215 } 2253 }
2216 2254
2217 // FIXME: Use a hit-test cache to avoid unnecessary hit tests. http://crbug. com/398920 2255 // FIXME: Use a hit-test cache to avoid unnecessary hit tests. http://crbug. com/398920
2218 if (currentHitTest.innerNode()) { 2256 if (currentHitTest.innerNode()) {
2219 LocalFrame* mainFrame = m_frame->localFrameRoot(); 2257 LocalFrame* mainFrame = m_frame->localFrameRoot();
2220 if (mainFrame && mainFrame->view()) 2258 if (mainFrame && mainFrame->view())
2221 mainFrame->view()->updateAllLifecyclePhases(); 2259 mainFrame->view()->updateAllLifecyclePhases();
2222 adjustedPoint = frameView->rootFrameToContents(gestureEvent.position()); 2260 adjustedPoint = frameView->rootFrameToContents(gestureEvent.position());
2223 currentHitTest = hitTestResultInFrame(m_frame, adjustedPoint, hitType); 2261 currentHitTest = hitTestResultInFrame(m_frame, adjustedPoint, hitType);
2224 } 2262 }
2225 PlatformMouseEvent fakeMouseUp(gestureEvent.position(), gestureEvent.globalP osition(), 2263 PlatformMouseEvent fakeMouseUp(gestureEvent.position(), gestureEvent.globalP osition(),
2226 LeftButton, PlatformEvent::MouseReleased, gestureEvent.tapCount(), 2264 LeftButton, PlatformEvent::MouseReleased, gestureEvent.tapCount(),
2227 static_cast<PlatformEvent::Modifiers>(modifiers), 2265 static_cast<PlatformEvent::Modifiers>(modifiers),
2228 PlatformMouseEvent::FromTouch, gestureEvent.timestamp()); 2266 PlatformMouseEvent::FromTouch, gestureEvent.timestamp());
2229 bool swallowMouseUpEvent = dispatchMouseEvent(EventTypeNames::mouseup, curre ntHitTest.innerNode(), gestureEvent.tapCount(), fakeMouseUp); 2267 WebInputEventResult mouseUpEventResult = dispatchMouseEvent(EventTypeNames:: mouseup, currentHitTest.innerNode(), gestureEvent.tapCount(), fakeMouseUp);
2230 2268
2231 bool swallowClickEvent = false; 2269 WebInputEventResult clickEventResult = WebInputEventResult::NotHandled;
2232 if (m_clickNode) { 2270 if (m_clickNode) {
2233 if (currentHitTest.innerNode()) { 2271 if (currentHitTest.innerNode()) {
2234 // Updates distribution because a mouseup (or mousedown) event liste ner can make the 2272 // Updates distribution because a mouseup (or mousedown) event liste ner can make the
2235 // tree dirty at dispatchMouseEvent() invocation above. 2273 // tree dirty at dispatchMouseEvent() invocation above.
2236 // Unless distribution is updated, commonAncestor would hit ASSERT. 2274 // Unless distribution is updated, commonAncestor would hit ASSERT.
2237 // Both m_clickNode and currentHitTest.innerNode()) don't need to be updated 2275 // Both m_clickNode and currentHitTest.innerNode()) don't need to be updated
2238 // because commonAncestor() will exit early if their documents are d ifferent. 2276 // because commonAncestor() will exit early if their documents are d ifferent.
2239 m_clickNode->updateDistribution(); 2277 m_clickNode->updateDistribution();
2240 Node* clickTargetNode = currentHitTest.innerNode()->commonAncestor(* m_clickNode, parentForClickEvent); 2278 Node* clickTargetNode = currentHitTest.innerNode()->commonAncestor(* m_clickNode, parentForClickEvent);
2241 swallowClickEvent = dispatchMouseEvent(EventTypeNames::click, clickT argetNode, gestureEvent.tapCount(), fakeMouseUp); 2279 clickEventResult = dispatchMouseEvent(EventTypeNames::click, clickTa rgetNode, gestureEvent.tapCount(), fakeMouseUp);
2242 } 2280 }
2243 m_clickNode = nullptr; 2281 m_clickNode = nullptr;
2244 } 2282 }
2245 2283
2246 if (!swallowMouseUpEvent) 2284 if (mouseUpEventResult == WebInputEventResult::NotHandled)
2247 swallowMouseUpEvent = handleMouseReleaseEvent(MouseEventWithHitTestResul ts(fakeMouseUp, currentHitTest)); 2285 mouseUpEventResult = handleMouseReleaseEvent(MouseEventWithHitTestResult s(fakeMouseUp, currentHitTest));
2248 2286
2249 bool swallowed = swallowMouseDownEvent | swallowMouseUpEvent | swallowClickE vent; 2287 WebInputEventResult eventResult = mergeEventResult(mergeEventResult(mouseDow nEventResult, mouseUpEventResult), clickEventResult);
2250 if (!swallowed && tappedNode && m_frame->page()) { 2288 if (eventResult == WebInputEventResult::NotHandled && tappedNode && m_frame- >page()) {
2251 bool domTreeChanged = preDispatchDomTreeVersion != m_frame->document()-> domTreeVersion(); 2289 bool domTreeChanged = preDispatchDomTreeVersion != m_frame->document()-> domTreeVersion();
2252 bool styleChanged = preDispatchStyleVersion != m_frame->document()->styl eVersion(); 2290 bool styleChanged = preDispatchStyleVersion != m_frame->document()->styl eVersion();
2253 2291
2254 IntPoint tappedPositionInViewport = m_frame->page()->frameHost().visualV iewport().rootFrameToViewport(tappedPosition); 2292 IntPoint tappedPositionInViewport = m_frame->page()->frameHost().visualV iewport().rootFrameToViewport(tappedPosition);
2255 m_frame->chromeClient().showUnhandledTapUIIfNeeded(tappedPositionInViewp ort, tappedNode.get(), domTreeChanged || styleChanged); 2293 m_frame->chromeClient().showUnhandledTapUIIfNeeded(tappedPositionInViewp ort, tappedNode.get(), domTreeChanged || styleChanged);
2256 } 2294 }
2257 return swallowed; 2295 return eventResult;
2258 } 2296 }
2259 2297
2260 bool EventHandler::handleGestureLongPress(const GestureEventWithHitTestResults& targetedEvent) 2298 WebInputEventResult EventHandler::handleGestureLongPress(const GestureEventWithH itTestResults& targetedEvent)
2261 { 2299 {
2262 const PlatformGestureEvent& gestureEvent = targetedEvent.event(); 2300 const PlatformGestureEvent& gestureEvent = targetedEvent.event();
2263 IntPoint adjustedPoint = gestureEvent.position(); 2301 IntPoint adjustedPoint = gestureEvent.position();
2264 2302
2265 unsigned modifiers = gestureEvent.modifiers(); 2303 unsigned modifiers = gestureEvent.modifiers();
2266 2304
2267 // FIXME: Ideally we should try to remove the extra mouse-specific hit-tests here (re-using the 2305 // FIXME: Ideally we should try to remove the extra mouse-specific hit-tests here (re-using the
2268 // supplied HitTestResult), but that will require some overhaul of the touch drag-and-drop code 2306 // supplied HitTestResult), but that will require some overhaul of the touch drag-and-drop code
2269 // and LongPress is such a special scenario that it's unlikely to matter muc h in practice. 2307 // and LongPress is such a special scenario that it's unlikely to matter muc h in practice.
2270 2308
2271 m_longTapShouldInvokeContextMenu = false; 2309 m_longTapShouldInvokeContextMenu = false;
2272 if (m_frame->settings() && m_frame->settings()->touchDragDropEnabled() && m_ frame->view()) { 2310 if (m_frame->settings() && m_frame->settings()->touchDragDropEnabled() && m_ frame->view()) {
2273 PlatformMouseEvent mouseDownEvent(adjustedPoint, gestureEvent.globalPosi tion(), LeftButton, PlatformEvent::MousePressed, 1, 2311 PlatformMouseEvent mouseDownEvent(adjustedPoint, gestureEvent.globalPosi tion(), LeftButton, PlatformEvent::MousePressed, 1,
2274 static_cast<PlatformEvent::Modifiers>(modifiers | PlatformEvent::Lef tButtonDown), 2312 static_cast<PlatformEvent::Modifiers>(modifiers | PlatformEvent::Lef tButtonDown),
2275 PlatformMouseEvent::FromTouch, WTF::currentTime()); 2313 PlatformMouseEvent::FromTouch, WTF::currentTime());
2276 m_mouseDown = mouseDownEvent; 2314 m_mouseDown = mouseDownEvent;
2277 2315
2278 PlatformMouseEvent mouseDragEvent(adjustedPoint, gestureEvent.globalPosi tion(), LeftButton, PlatformEvent::MouseMoved, 1, 2316 PlatformMouseEvent mouseDragEvent(adjustedPoint, gestureEvent.globalPosi tion(), LeftButton, PlatformEvent::MouseMoved, 1,
2279 static_cast<PlatformEvent::Modifiers>(modifiers | PlatformEvent::Lef tButtonDown), 2317 static_cast<PlatformEvent::Modifiers>(modifiers | PlatformEvent::Lef tButtonDown),
2280 PlatformMouseEvent::FromTouch, WTF::currentTime()); 2318 PlatformMouseEvent::FromTouch, WTF::currentTime());
2281 HitTestRequest request(HitTestRequest::ReadOnly); 2319 HitTestRequest request(HitTestRequest::ReadOnly);
2282 MouseEventWithHitTestResults mev = prepareMouseEvent(request, mouseDragE vent); 2320 MouseEventWithHitTestResults mev = prepareMouseEvent(request, mouseDragE vent);
2283 m_mouseDownMayStartDrag = true; 2321 m_mouseDownMayStartDrag = true;
2284 dragState().m_dragSrc = nullptr; 2322 dragState().m_dragSrc = nullptr;
2285 m_mouseDownPos = m_frame->view()->rootFrameToContents(mouseDragEvent.pos ition()); 2323 m_mouseDownPos = m_frame->view()->rootFrameToContents(mouseDragEvent.pos ition());
2286 RefPtrWillBeRawPtr<FrameView> protector(m_frame->view()); 2324 RefPtrWillBeRawPtr<FrameView> protector(m_frame->view());
2287 if (handleDrag(mev, DragInitiator::Touch)) { 2325 if (handleDrag(mev, DragInitiator::Touch)) {
2288 m_longTapShouldInvokeContextMenu = true; 2326 m_longTapShouldInvokeContextMenu = true;
2289 return true; 2327 return WebInputEventResult::HandledSystem;
2290 } 2328 }
2291 } 2329 }
2292 2330
2293 IntPoint hitTestPoint = m_frame->view()->rootFrameToContents(gestureEvent.po sition()); 2331 IntPoint hitTestPoint = m_frame->view()->rootFrameToContents(gestureEvent.po sition());
2294 HitTestResult result = hitTestResultAtPoint(hitTestPoint); 2332 HitTestResult result = hitTestResultAtPoint(hitTestPoint);
2295 RefPtrWillBeRawPtr<FrameView> protector(m_frame->view()); 2333 RefPtrWillBeRawPtr<FrameView> protector(m_frame->view());
2296 if (selectionController().handleGestureLongPress(gestureEvent, result)) { 2334 if (selectionController().handleGestureLongPress(gestureEvent, result)) {
2297 focusDocumentView(); 2335 focusDocumentView();
2298 return true; 2336 return WebInputEventResult::HandledSystem;
2299 } 2337 }
2300 2338
2301 return sendContextMenuEventForGesture(targetedEvent); 2339 return sendContextMenuEventForGesture(targetedEvent);
2302 } 2340 }
2303 2341
2304 bool EventHandler::handleGestureLongTap(const GestureEventWithHitTestResults& ta rgetedEvent) 2342 WebInputEventResult EventHandler::handleGestureLongTap(const GestureEventWithHit TestResults& targetedEvent)
2305 { 2343 {
2306 #if !OS(ANDROID) 2344 #if !OS(ANDROID)
2307 if (m_longTapShouldInvokeContextMenu) { 2345 if (m_longTapShouldInvokeContextMenu) {
2308 m_longTapShouldInvokeContextMenu = false; 2346 m_longTapShouldInvokeContextMenu = false;
2309 return sendContextMenuEventForGesture(targetedEvent); 2347 return sendContextMenuEventForGesture(targetedEvent);
2310 } 2348 }
2311 #endif 2349 #endif
2312 return false; 2350 return WebInputEventResult::NotHandled;
2313 } 2351 }
2314 2352
2315 bool EventHandler::handleScrollGestureOnResizer(Node* eventTarget, const Platfor mGestureEvent& gestureEvent) 2353 bool EventHandler::handleScrollGestureOnResizer(Node* eventTarget, const Platfor mGestureEvent& gestureEvent)
2316 { 2354 {
2317 if (gestureEvent.type() == PlatformEvent::GestureScrollBegin) { 2355 if (gestureEvent.type() == PlatformEvent::GestureScrollBegin) {
2318 PaintLayer* layer = eventTarget->layoutObject() ? eventTarget->layoutObj ect()->enclosingLayer() : nullptr; 2356 PaintLayer* layer = eventTarget->layoutObject() ? eventTarget->layoutObj ect()->enclosingLayer() : nullptr;
2319 IntPoint p = m_frame->view()->rootFrameToContents(gestureEvent.position( )); 2357 IntPoint p = m_frame->view()->rootFrameToContents(gestureEvent.position( ));
2320 if (layer && layer->scrollableArea() && layer->scrollableArea()->isPoint InResizeControl(p, ResizerForTouch)) { 2358 if (layer && layer->scrollableArea() && layer->scrollableArea()->isPoint InResizeControl(p, ResizerForTouch)) {
2321 m_resizeScrollableArea = layer->scrollableArea(); 2359 m_resizeScrollableArea = layer->scrollableArea();
2322 m_resizeScrollableArea->setInResizeMode(true); 2360 m_resizeScrollableArea->setInResizeMode(true);
2323 m_offsetFromResizeCorner = LayoutSize(m_resizeScrollableArea->offset FromResizeCorner(p)); 2361 m_offsetFromResizeCorner = LayoutSize(m_resizeScrollableArea->offset FromResizeCorner(p));
2324 return true; 2362 return true;
2325 } 2363 }
2326 } else if (gestureEvent.type() == PlatformEvent::GestureScrollUpdate) { 2364 } else if (gestureEvent.type() == PlatformEvent::GestureScrollUpdate) {
2327 if (m_resizeScrollableArea && m_resizeScrollableArea->inResizeMode()) { 2365 if (m_resizeScrollableArea && m_resizeScrollableArea->inResizeMode()) {
2328 m_resizeScrollableArea->resize(gestureEvent, m_offsetFromResizeCorne r); 2366 m_resizeScrollableArea->resize(gestureEvent, m_offsetFromResizeCorne r);
2329 return true; 2367 return true;
2330 } 2368 }
2331 } else if (gestureEvent.type() == PlatformEvent::GestureScrollEnd) { 2369 } else if (gestureEvent.type() == PlatformEvent::GestureScrollEnd) {
2332 if (m_resizeScrollableArea && m_resizeScrollableArea->inResizeMode()) { 2370 if (m_resizeScrollableArea && m_resizeScrollableArea->inResizeMode()) {
2333 m_resizeScrollableArea->setInResizeMode(false); 2371 m_resizeScrollableArea->setInResizeMode(false);
2334 m_resizeScrollableArea = nullptr; 2372 m_resizeScrollableArea = nullptr;
2335 return false; 2373 return false;
2336 } 2374 }
2337 } 2375 }
2338 2376
2339 return false; 2377 return false;
2340 } 2378 }
2341 2379
2342 bool EventHandler::passScrollGestureEventToWidget(const PlatformGestureEvent& ge stureEvent, LayoutObject* layoutObject) 2380 WebInputEventResult EventHandler::passScrollGestureEventToWidget(const PlatformG estureEvent& gestureEvent, LayoutObject* layoutObject)
2343 { 2381 {
2344 ASSERT(gestureEvent.isScrollEvent()); 2382 ASSERT(gestureEvent.isScrollEvent());
2345 2383
2346 if (!m_lastGestureScrollOverWidget) 2384 if (!m_lastGestureScrollOverWidget || !layoutObject || !layoutObject->isLayo utPart())
2347 return false; 2385 return WebInputEventResult::NotHandled;
2348
2349 if (!layoutObject || !layoutObject->isLayoutPart())
2350 return false;
2351 2386
2352 Widget* widget = toLayoutPart(layoutObject)->widget(); 2387 Widget* widget = toLayoutPart(layoutObject)->widget();
2353 2388
2354 if (!widget || !widget->isFrameView()) 2389 if (!widget || !widget->isFrameView())
2355 return false; 2390 return WebInputEventResult::NotHandled;
2356 2391
2357 return toFrameView(widget)->frame().eventHandler().handleGestureScrollEvent( gestureEvent); 2392 return toFrameView(widget)->frame().eventHandler().handleGestureScrollEvent( gestureEvent);
2358 } 2393 }
2359 2394
2360 bool EventHandler::handleGestureScrollEnd(const PlatformGestureEvent& gestureEve nt) 2395 WebInputEventResult EventHandler::handleGestureScrollEnd(const PlatformGestureEv ent& gestureEvent)
2361 { 2396 {
2362 RefPtrWillBeRawPtr<Node> node = m_scrollGestureHandlingNode; 2397 RefPtrWillBeRawPtr<Node> node = m_scrollGestureHandlingNode;
2363 2398
2364 if (node) { 2399 if (node) {
2365 passScrollGestureEventToWidget(gestureEvent, node->layoutObject()); 2400 passScrollGestureEventToWidget(gestureEvent, node->layoutObject());
2366 if (RuntimeEnabledFeatures::scrollCustomizationEnabled()) { 2401 if (RuntimeEnabledFeatures::scrollCustomizationEnabled()) {
2367 RefPtrWillBeRawPtr<ScrollState> scrollState = ScrollState::create( 2402 RefPtrWillBeRawPtr<ScrollState> scrollState = ScrollState::create(
2368 0, 0, 0, 0, 0, gestureEvent.inertial(), /* isBeginning */ 2403 0, 0, 0, 0, 0, gestureEvent.inertial(), /* isBeginning */
2369 false, /* isEnding */ true, /* fromUserInput */ true); 2404 false, /* isEnding */ true, /* fromUserInput */ true);
2370 customizedScroll(*node.get(), *scrollState); 2405 customizedScroll(*node.get(), *scrollState);
2371 } 2406 }
2372 } 2407 }
2373 2408
2374 clearGestureScrollState(); 2409 clearGestureScrollState();
2375 return false; 2410 return WebInputEventResult::NotHandled;
2376 } 2411 }
2377 2412
2378 bool EventHandler::handleGestureScrollBegin(const PlatformGestureEvent& gestureE vent) 2413 WebInputEventResult EventHandler::handleGestureScrollBegin(const PlatformGesture Event& gestureEvent)
2379 { 2414 {
2380 Document* document = m_frame->document(); 2415 Document* document = m_frame->document();
2381 if (!document->layoutView()) 2416 if (!document->layoutView())
2382 return false; 2417 return WebInputEventResult::NotHandled;
2383 2418
2384 FrameView* view = m_frame->view(); 2419 FrameView* view = m_frame->view();
2385 if (!view) 2420 if (!view)
2386 return false; 2421 return WebInputEventResult::NotHandled;
2387 2422
2388 // If there's no layoutObject on the node, send the event to the nearest anc estor with a layoutObject. 2423 // If there's no layoutObject on the node, send the event to the nearest anc estor with a layoutObject.
2389 // Needed for <option> and <optgroup> elements so we can touch scroll <selec t>s 2424 // Needed for <option> and <optgroup> elements so we can touch scroll <selec t>s
2390 while (m_scrollGestureHandlingNode && !m_scrollGestureHandlingNode->layoutOb ject()) 2425 while (m_scrollGestureHandlingNode && !m_scrollGestureHandlingNode->layoutOb ject())
2391 m_scrollGestureHandlingNode = m_scrollGestureHandlingNode->parentOrShado wHostNode(); 2426 m_scrollGestureHandlingNode = m_scrollGestureHandlingNode->parentOrShado wHostNode();
2392 2427
2393 if (!m_scrollGestureHandlingNode) { 2428 if (!m_scrollGestureHandlingNode) {
2394 if (RuntimeEnabledFeatures::scrollCustomizationEnabled()) 2429 if (RuntimeEnabledFeatures::scrollCustomizationEnabled())
2395 m_scrollGestureHandlingNode = m_frame->document()->documentElement() ; 2430 m_scrollGestureHandlingNode = m_frame->document()->documentElement() ;
2396 else 2431 else
2397 return false; 2432 return WebInputEventResult::NotHandled;
2398 } 2433 }
2399 ASSERT(m_scrollGestureHandlingNode); 2434 ASSERT(m_scrollGestureHandlingNode);
2400 2435
2401 passScrollGestureEventToWidget(gestureEvent, m_scrollGestureHandlingNode->la youtObject()); 2436 passScrollGestureEventToWidget(gestureEvent, m_scrollGestureHandlingNode->la youtObject());
2402 if (RuntimeEnabledFeatures::scrollCustomizationEnabled()) { 2437 if (RuntimeEnabledFeatures::scrollCustomizationEnabled()) {
2403 m_currentScrollChain.clear(); 2438 m_currentScrollChain.clear();
2404 RefPtrWillBeRawPtr<ScrollState> scrollState = ScrollState::create( 2439 RefPtrWillBeRawPtr<ScrollState> scrollState = ScrollState::create(
2405 0, 0, 0, 0, 0, /* inInertialPhase */ false, /* isBeginning */ 2440 0, 0, 0, 0, 0, /* inInertialPhase */ false, /* isBeginning */
2406 true, /* isEnding */ false, /* fromUserInput */ true); 2441 true, /* isEnding */ false, /* fromUserInput */ true);
2407 customizedScroll(*m_scrollGestureHandlingNode.get(), *scrollState); 2442 customizedScroll(*m_scrollGestureHandlingNode.get(), *scrollState);
2408 } else { 2443 } else {
2409 if (m_frame->isMainFrame()) 2444 if (m_frame->isMainFrame())
2410 m_frame->host()->topControls().scrollBegin(); 2445 m_frame->host()->topControls().scrollBegin();
2411 } 2446 }
2412 return true; 2447 return WebInputEventResult::HandledSystem;
2413 } 2448 }
2414 2449
2415 void EventHandler::resetOverscroll(bool didScrollX, bool didScrollY) 2450 void EventHandler::resetOverscroll(bool didScrollX, bool didScrollY)
2416 { 2451 {
2417 if (didScrollX) 2452 if (didScrollX)
2418 m_accumulatedRootOverscroll.setWidth(0); 2453 m_accumulatedRootOverscroll.setWidth(0);
2419 if (didScrollY) 2454 if (didScrollY)
2420 m_accumulatedRootOverscroll.setHeight(0); 2455 m_accumulatedRootOverscroll.setHeight(0);
2421 } 2456 }
2422 2457
(...skipping 11 matching lines...) Expand all
2434 { 2469 {
2435 FloatSize unusedDelta(scrollResult.unusedScrollDeltaX, scrollResult.unusedSc rollDeltaY); 2470 FloatSize unusedDelta(scrollResult.unusedScrollDeltaX, scrollResult.unusedSc rollDeltaY);
2436 unusedDelta = adjustOverscoll(unusedDelta); 2471 unusedDelta = adjustOverscoll(unusedDelta);
2437 resetOverscroll(scrollResult.didScrollX, scrollResult.didScrollY); 2472 resetOverscroll(scrollResult.didScrollX, scrollResult.didScrollY);
2438 if (unusedDelta != FloatSize()) { 2473 if (unusedDelta != FloatSize()) {
2439 m_accumulatedRootOverscroll += unusedDelta; 2474 m_accumulatedRootOverscroll += unusedDelta;
2440 m_frame->chromeClient().didOverscroll(unusedDelta, m_accumulatedRootOver scroll, position, velocity); 2475 m_frame->chromeClient().didOverscroll(unusedDelta, m_accumulatedRootOver scroll, position, velocity);
2441 } 2476 }
2442 } 2477 }
2443 2478
2444 bool EventHandler::handleGestureScrollUpdate(const PlatformGestureEvent& gesture Event) 2479 WebInputEventResult EventHandler::handleGestureScrollUpdate(const PlatformGestur eEvent& gestureEvent)
2445 { 2480 {
2446 ASSERT(gestureEvent.type() == PlatformEvent::GestureScrollUpdate); 2481 ASSERT(gestureEvent.type() == PlatformEvent::GestureScrollUpdate);
2447 2482
2448 FloatSize delta(gestureEvent.deltaX(), gestureEvent.deltaY()); 2483 FloatSize delta(gestureEvent.deltaX(), gestureEvent.deltaY());
2449 if (delta.isZero()) 2484 if (delta.isZero())
2450 return false; 2485 return WebInputEventResult::NotHandled;
2451 2486
2452 Node* node = m_scrollGestureHandlingNode.get(); 2487 Node* node = m_scrollGestureHandlingNode.get();
2453 if (node) { 2488 if (node) {
2454 LayoutObject* layoutObject = node->layoutObject(); 2489 LayoutObject* layoutObject = node->layoutObject();
2455 if (!layoutObject) 2490 if (!layoutObject)
2456 return false; 2491 return WebInputEventResult::NotHandled;
2457 2492
2458 RefPtrWillBeRawPtr<FrameView> protector(m_frame->view()); 2493 RefPtrWillBeRawPtr<FrameView> protector(m_frame->view());
2459 2494
2460 Node* stopNode = nullptr; 2495 Node* stopNode = nullptr;
2461 2496
2462 // Try to send the event to the correct view. 2497 // Try to send the event to the correct view.
2463 if (passScrollGestureEventToWidget(gestureEvent, layoutObject)) { 2498 WebInputEventResult result = passScrollGestureEventToWidget(gestureEvent , layoutObject);
2499 if (result != WebInputEventResult::NotHandled) {
2464 if (gestureEvent.preventPropagation() 2500 if (gestureEvent.preventPropagation()
2465 && !RuntimeEnabledFeatures::scrollCustomizationEnabled()) { 2501 && !RuntimeEnabledFeatures::scrollCustomizationEnabled()) {
2466 // This is an optimization which doesn't apply with 2502 // This is an optimization which doesn't apply with
2467 // scroll customization enabled. 2503 // scroll customization enabled.
2468 m_previousGestureScrolledNode = m_scrollGestureHandlingNode; 2504 m_previousGestureScrolledNode = m_scrollGestureHandlingNode;
2469 } 2505 }
2470 // FIXME: we should allow simultaneous scrolling of nested 2506 // FIXME: we should allow simultaneous scrolling of nested
2471 // iframes along perpendicular axes. See crbug.com/466991. 2507 // iframes along perpendicular axes. See crbug.com/466991.
2472 m_deltaConsumedForScrollSequence = true; 2508 m_deltaConsumedForScrollSequence = true;
2473 return true; 2509 return result;
2474 } 2510 }
2475 2511
2476 bool scrolled = false; 2512 bool scrolled = false;
2477 if (RuntimeEnabledFeatures::scrollCustomizationEnabled()) { 2513 if (RuntimeEnabledFeatures::scrollCustomizationEnabled()) {
2478 RefPtrWillBeRawPtr<ScrollState> scrollState = ScrollState::create( 2514 RefPtrWillBeRawPtr<ScrollState> scrollState = ScrollState::create(
2479 gestureEvent.deltaX(), gestureEvent.deltaY(), 2515 gestureEvent.deltaX(), gestureEvent.deltaY(),
2480 0, gestureEvent.velocityX(), gestureEvent.velocityY(), 2516 0, gestureEvent.velocityX(), gestureEvent.velocityY(),
2481 gestureEvent.inertial(), /* isBeginning */ 2517 gestureEvent.inertial(), /* isBeginning */
2482 false, /* isEnding */ false, /* fromUserInput */ true, 2518 false, /* isEnding */ false, /* fromUserInput */ true,
2483 !gestureEvent.preventPropagation(), m_deltaConsumedForScrollSequ ence); 2519 !gestureEvent.preventPropagation(), m_deltaConsumedForScrollSequ ence);
(...skipping 24 matching lines...) Expand all
2508 bool verticalScroll = result.didScroll; 2544 bool verticalScroll = result.didScroll;
2509 scrolled = horizontalScroll || verticalScroll; 2545 scrolled = horizontalScroll || verticalScroll;
2510 2546
2511 if (gestureEvent.preventPropagation()) 2547 if (gestureEvent.preventPropagation())
2512 m_previousGestureScrolledNode = stopNode; 2548 m_previousGestureScrolledNode = stopNode;
2513 2549
2514 resetOverscroll(horizontalScroll, verticalScroll); 2550 resetOverscroll(horizontalScroll, verticalScroll);
2515 } 2551 }
2516 if (scrolled) { 2552 if (scrolled) {
2517 setFrameWasScrolledByUser(); 2553 setFrameWasScrolledByUser();
2518 return true; 2554 return WebInputEventResult::HandledSystem;
2519 } 2555 }
2520 } 2556 }
2521 2557
2522 if (RuntimeEnabledFeatures::scrollCustomizationEnabled()) 2558 if (RuntimeEnabledFeatures::scrollCustomizationEnabled())
2523 return false; 2559 return WebInputEventResult::NotHandled;
2524 2560
2525 // Try to scroll the frame view. 2561 // Try to scroll the frame view.
2526 ScrollResult scrollResult = m_frame->applyScrollDelta(delta, false); 2562 ScrollResult scrollResult = m_frame->applyScrollDelta(delta, false);
2527 FloatPoint position = FloatPoint(gestureEvent.position().x(), gestureEvent.p osition().y()); 2563 FloatPoint position = FloatPoint(gestureEvent.position().x(), gestureEvent.p osition().y());
2528 FloatSize velocity = FloatSize(gestureEvent.velocityX(), gestureEvent.veloci tyY()); 2564 FloatSize velocity = FloatSize(gestureEvent.velocityX(), gestureEvent.veloci tyY());
2529 handleOverscroll(scrollResult, position, velocity); 2565 handleOverscroll(scrollResult, position, velocity);
2530 if (scrollResult.didScroll()) { 2566 if (scrollResult.didScroll()) {
2531 setFrameWasScrolledByUser(); 2567 setFrameWasScrolledByUser();
2532 return true; 2568 return WebInputEventResult::HandledSystem;
2533 } 2569 }
2534 2570
2535 return false; 2571 return WebInputEventResult::NotHandled;
2536 } 2572 }
2537 2573
2538 void EventHandler::clearGestureScrollState() 2574 void EventHandler::clearGestureScrollState()
2539 { 2575 {
2540 m_scrollGestureHandlingNode = nullptr; 2576 m_scrollGestureHandlingNode = nullptr;
2541 m_previousGestureScrolledNode = nullptr; 2577 m_previousGestureScrolledNode = nullptr;
2542 m_deltaConsumedForScrollSequence = false; 2578 m_deltaConsumedForScrollSequence = false;
2543 m_currentScrollChain.clear(); 2579 m_currentScrollChain.clear();
2544 m_accumulatedRootOverscroll = FloatSize(); 2580 m_accumulatedRootOverscroll = FloatSize();
2545 } 2581 }
(...skipping 317 matching lines...) Expand 10 before | Expand all | Expand 10 after
2863 } 2899 }
2864 2900
2865 // Update the hit-test result to be a point-based result instead of a rect-b ased result. 2901 // Update the hit-test result to be a point-based result instead of a rect-b ased result.
2866 // FIXME: We should do this even when no candidate matches the node filter. crbug.com/398914 2902 // FIXME: We should do this even when no candidate matches the node filter. crbug.com/398914
2867 if (adjusted) { 2903 if (adjusted) {
2868 hitTestResult->resolveRectBasedTest(adjustedNode, m_frame->view()->rootF rameToContents(adjustedPoint)); 2904 hitTestResult->resolveRectBasedTest(adjustedNode, m_frame->view()->rootF rameToContents(adjustedPoint));
2869 gestureEvent->applyTouchAdjustment(adjustedPoint); 2905 gestureEvent->applyTouchAdjustment(adjustedPoint);
2870 } 2906 }
2871 } 2907 }
2872 2908
2873 bool EventHandler::sendContextMenuEvent(const PlatformMouseEvent& event, Node* o verrideTargetNode) 2909 WebInputEventResult EventHandler::sendContextMenuEvent(const PlatformMouseEvent& event, Node* overrideTargetNode)
2874 { 2910 {
2875 FrameView* v = m_frame->view(); 2911 FrameView* v = m_frame->view();
2876 if (!v) 2912 if (!v)
2877 return false; 2913 return WebInputEventResult::NotHandled;
2878 2914
2879 // Clear mouse press state to avoid initiating a drag while context menu is up. 2915 // Clear mouse press state to avoid initiating a drag while context menu is up.
2880 m_mousePressed = false; 2916 m_mousePressed = false;
2881 LayoutPoint positionInContents = v->rootFrameToContents(event.position()); 2917 LayoutPoint positionInContents = v->rootFrameToContents(event.position());
2882 HitTestRequest request(HitTestRequest::Active); 2918 HitTestRequest request(HitTestRequest::Active);
2883 MouseEventWithHitTestResults mev = m_frame->document()->prepareMouseEvent(re quest, positionInContents, event); 2919 MouseEventWithHitTestResults mev = m_frame->document()->prepareMouseEvent(re quest, positionInContents, event);
2884 2920
2885 selectionController().sendContextMenuEvent(mev, positionInContents); 2921 selectionController().sendContextMenuEvent(mev, positionInContents);
2886 2922
2887 Node* targetNode = overrideTargetNode ? overrideTargetNode : mev.innerNode() ; 2923 Node* targetNode = overrideTargetNode ? overrideTargetNode : mev.innerNode() ;
2888 return dispatchMouseEvent(EventTypeNames::contextmenu, targetNode, 0, event) ; 2924 return dispatchMouseEvent(EventTypeNames::contextmenu, targetNode, 0, event) ;
2889 } 2925 }
2890 2926
2891 bool EventHandler::sendContextMenuEventForKey(Element* overrideTargetElement) 2927 WebInputEventResult EventHandler::sendContextMenuEventForKey(Element* overrideTa rgetElement)
2892 { 2928 {
2893 FrameView* view = m_frame->view(); 2929 FrameView* view = m_frame->view();
2894 if (!view) 2930 if (!view)
2895 return false; 2931 return WebInputEventResult::NotHandled;
2896 2932
2897 Document* doc = m_frame->document(); 2933 Document* doc = m_frame->document();
2898 if (!doc) 2934 if (!doc)
2899 return false; 2935 return WebInputEventResult::NotHandled;
2900 2936
2901 // Clear mouse press state to avoid initiating a drag while context menu is up. 2937 // Clear mouse press state to avoid initiating a drag while context menu is up.
2902 m_mousePressed = false; 2938 m_mousePressed = false;
2903 2939
2904 static const int kContextMenuMargin = 1; 2940 static const int kContextMenuMargin = 1;
2905 2941
2906 #if OS(WIN) 2942 #if OS(WIN)
2907 int rightAligned = ::GetSystemMetrics(SM_MENUDROPALIGNMENT); 2943 int rightAligned = ::GetSystemMetrics(SM_MENUDROPALIGNMENT);
2908 #else 2944 #else
2909 int rightAligned = 0; 2945 int rightAligned = 0;
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
2953 // This is required for web compatibility. 2989 // This is required for web compatibility.
2954 PlatformEvent::Type eventType = PlatformEvent::MousePressed; 2990 PlatformEvent::Type eventType = PlatformEvent::MousePressed;
2955 if (m_frame->settings() && m_frame->settings()->showContextMenuOnMouseUp()) 2991 if (m_frame->settings() && m_frame->settings()->showContextMenuOnMouseUp())
2956 eventType = PlatformEvent::MouseReleased; 2992 eventType = PlatformEvent::MouseReleased;
2957 2993
2958 PlatformMouseEvent mouseEvent(locationInRootFrame, globalPosition, RightButt on, eventType, 1, PlatformEvent::NoModifiers, PlatformMouseEvent::RealOrIndistin guishable, WTF::currentTime()); 2994 PlatformMouseEvent mouseEvent(locationInRootFrame, globalPosition, RightButt on, eventType, 1, PlatformEvent::NoModifiers, PlatformMouseEvent::RealOrIndistin guishable, WTF::currentTime());
2959 2995
2960 return sendContextMenuEvent(mouseEvent, overrideTargetElement); 2996 return sendContextMenuEvent(mouseEvent, overrideTargetElement);
2961 } 2997 }
2962 2998
2963 bool EventHandler::sendContextMenuEventForGesture(const GestureEventWithHitTestR esults& targetedEvent) 2999 WebInputEventResult EventHandler::sendContextMenuEventForGesture(const GestureEv entWithHitTestResults& targetedEvent)
2964 { 3000 {
2965 const PlatformGestureEvent& gestureEvent = targetedEvent.event(); 3001 const PlatformGestureEvent& gestureEvent = targetedEvent.event();
2966 unsigned modifiers = gestureEvent.modifiers(); 3002 unsigned modifiers = gestureEvent.modifiers();
2967 3003
2968 // Send MouseMoved event prior to handling (https://crbug.com/485290). 3004 // Send MouseMoved event prior to handling (https://crbug.com/485290).
2969 PlatformMouseEvent fakeMouseMove(gestureEvent.position(), gestureEvent.globa lPosition(), 3005 PlatformMouseEvent fakeMouseMove(gestureEvent.position(), gestureEvent.globa lPosition(),
2970 NoButton, PlatformEvent::MouseMoved, /* clickCount */ 0, 3006 NoButton, PlatformEvent::MouseMoved, /* clickCount */ 0,
2971 static_cast<PlatformEvent::Modifiers>(modifiers), 3007 static_cast<PlatformEvent::Modifiers>(modifiers),
2972 PlatformMouseEvent::FromTouch, gestureEvent.timestamp()); 3008 PlatformMouseEvent::FromTouch, gestureEvent.timestamp());
2973 dispatchMouseEvent(EventTypeNames::mousemove, targetedEvent.hitTestResult(). innerNode(), 0, fakeMouseMove); 3009 dispatchMouseEvent(EventTypeNames::mousemove, targetedEvent.hitTestResult(). innerNode(), 0, fakeMouseMove);
(...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after
3141 if ((evt.modifiers() & (PlatformEvent::KeyModifiers & ~PlatformEvent::ShiftK ey)) != accessKeyModifiers()) 3177 if ((evt.modifiers() & (PlatformEvent::KeyModifiers & ~PlatformEvent::ShiftK ey)) != accessKeyModifiers())
3142 return false; 3178 return false;
3143 String key = evt.unmodifiedText(); 3179 String key = evt.unmodifiedText();
3144 Element* elem = m_frame->document()->getElementByAccessKey(key.lower()); 3180 Element* elem = m_frame->document()->getElementByAccessKey(key.lower());
3145 if (!elem) 3181 if (!elem)
3146 return false; 3182 return false;
3147 elem->accessKeyAction(false); 3183 elem->accessKeyAction(false);
3148 return true; 3184 return true;
3149 } 3185 }
3150 3186
3151 bool EventHandler::keyEvent(const PlatformKeyboardEvent& initialKeyEvent) 3187 WebInputEventResult EventHandler::keyEvent(const PlatformKeyboardEvent& initialK eyEvent)
3152 { 3188 {
3153 RefPtrWillBeRawPtr<FrameView> protector(m_frame->view()); 3189 RefPtrWillBeRawPtr<FrameView> protector(m_frame->view());
3154 m_frame->chromeClient().setToolTip(String(), LTR); 3190 m_frame->chromeClient().setToolTip(String(), LTR);
3155 3191
3156 if (initialKeyEvent.windowsVirtualKeyCode() == VK_CAPITAL) 3192 if (initialKeyEvent.windowsVirtualKeyCode() == VK_CAPITAL)
3157 capsLockStateMayHaveChanged(); 3193 capsLockStateMayHaveChanged();
3158 3194
3159 #if OS(WIN) 3195 #if OS(WIN)
3160 if (panScrollInProgress()) { 3196 if (panScrollInProgress()) {
3161 // If a key is pressed while the panScroll is in progress then we want t o stop 3197 // If a key is pressed while the panScroll is in progress then we want t o stop
3162 if (initialKeyEvent.type() == PlatformEvent::KeyDown || initialKeyEvent. type() == PlatformEvent::RawKeyDown) 3198 if (initialKeyEvent.type() == PlatformEvent::KeyDown || initialKeyEvent. type() == PlatformEvent::RawKeyDown)
3163 stopAutoscroll(); 3199 stopAutoscroll();
3164 3200
3165 // If we were in panscroll mode, we swallow the key event 3201 // If we were in panscroll mode, we swallow the key event
3166 return true; 3202 return WebInputEventResult::HandledSuppressed;
3167 } 3203 }
3168 #endif 3204 #endif
3169 3205
3170 // Check for cases where we are too early for events -- possible unmatched k ey up 3206 // Check for cases where we are too early for events -- possible unmatched k ey up
3171 // from pressing return in the location bar. 3207 // from pressing return in the location bar.
3172 RefPtrWillBeRawPtr<Node> node = eventTargetNodeForDocument(m_frame->document ()); 3208 RefPtrWillBeRawPtr<Node> node = eventTargetNodeForDocument(m_frame->document ());
3173 if (!node) 3209 if (!node)
3174 return false; 3210 return WebInputEventResult::NotHandled;
3175 3211
3176 UserGestureIndicator gestureIndicator(DefinitelyProcessingUserGesture); 3212 UserGestureIndicator gestureIndicator(DefinitelyProcessingUserGesture);
3177 3213
3178 // In IE, access keys are special, they are handled after default keydown pr ocessing, but cannot be canceled - this is hard to match. 3214 // In IE, access keys are special, they are handled after default keydown pr ocessing, but cannot be canceled - this is hard to match.
3179 // On Mac OS X, we process them before dispatching keydown, as the default k eydown handler implements Emacs key bindings, which may conflict 3215 // On Mac OS X, we process them before dispatching keydown, as the default k eydown handler implements Emacs key bindings, which may conflict
3180 // with access keys. Then we dispatch keydown, but suppress its default hand ling. 3216 // with access keys. Then we dispatch keydown, but suppress its default hand ling.
3181 // On Windows, WebKit explicitly calls handleAccessKey() instead of dispatch ing a keypress event for WM_SYSCHAR messages. 3217 // On Windows, WebKit explicitly calls handleAccessKey() instead of dispatch ing a keypress event for WM_SYSCHAR messages.
3182 // Other platforms currently match either Mac or Windows behavior, depending on whether they send combined KeyDown events. 3218 // Other platforms currently match either Mac or Windows behavior, depending on whether they send combined KeyDown events.
3183 bool matchedAnAccessKey = false; 3219 bool matchedAnAccessKey = false;
3184 if (initialKeyEvent.type() == PlatformEvent::KeyDown) 3220 if (initialKeyEvent.type() == PlatformEvent::KeyDown)
3185 matchedAnAccessKey = handleAccessKey(initialKeyEvent); 3221 matchedAnAccessKey = handleAccessKey(initialKeyEvent);
3186 3222
3187 // FIXME: it would be fair to let an input method handle KeyUp events before DOM dispatch. 3223 // FIXME: it would be fair to let an input method handle KeyUp events before DOM dispatch.
3188 if (initialKeyEvent.type() == PlatformEvent::KeyUp || initialKeyEvent.type() == PlatformEvent::Char) 3224 if (initialKeyEvent.type() == PlatformEvent::KeyUp || initialKeyEvent.type() == PlatformEvent::Char) {
3189 return !node->dispatchKeyEvent(initialKeyEvent); 3225 RefPtrWillBeRawPtr<KeyboardEvent> domEvent = KeyboardEvent::create(initi alKeyEvent, m_frame->document()->domWindow());
3226
3227 bool dispatchResult = node->dispatchEvent(domEvent);
3228 return eventToEventResult(domEvent, dispatchResult);
3229 }
3190 3230
3191 PlatformKeyboardEvent keyDownEvent = initialKeyEvent; 3231 PlatformKeyboardEvent keyDownEvent = initialKeyEvent;
3192 if (keyDownEvent.type() != PlatformEvent::RawKeyDown) 3232 if (keyDownEvent.type() != PlatformEvent::RawKeyDown)
3193 keyDownEvent.disambiguateKeyDownEvent(PlatformEvent::RawKeyDown); 3233 keyDownEvent.disambiguateKeyDownEvent(PlatformEvent::RawKeyDown);
3194 RefPtrWillBeRawPtr<KeyboardEvent> keydown = KeyboardEvent::create(keyDownEve nt, m_frame->document()->domWindow()); 3234 RefPtrWillBeRawPtr<KeyboardEvent> keydown = KeyboardEvent::create(keyDownEve nt, m_frame->document()->domWindow());
3195 if (matchedAnAccessKey) 3235 if (matchedAnAccessKey)
3196 keydown->setDefaultPrevented(true); 3236 keydown->setDefaultPrevented(true);
3197 keydown->setTarget(node); 3237 keydown->setTarget(node);
3198 3238
3199 if (initialKeyEvent.type() == PlatformEvent::RawKeyDown) { 3239 if (initialKeyEvent.type() == PlatformEvent::RawKeyDown) {
3200 node->dispatchEvent(keydown); 3240 if (!node->dispatchEvent(keydown))
3241 return eventToEventResult(keydown, false);
3201 // If frame changed as a result of keydown dispatch, then return true to avoid sending a subsequent keypress message to the new frame. 3242 // If frame changed as a result of keydown dispatch, then return true to avoid sending a subsequent keypress message to the new frame.
3202 bool changedFocusedFrame = m_frame->page() && m_frame != m_frame->page() ->focusController().focusedOrMainFrame(); 3243 bool changedFocusedFrame = m_frame->page() && m_frame != m_frame->page() ->focusController().focusedOrMainFrame();
3203 return keydown->defaultHandled() || keydown->defaultPrevented() || chang edFocusedFrame; 3244 if (changedFocusedFrame)
3245 return WebInputEventResult::HandledSystem;
3246 return WebInputEventResult::NotHandled;
3204 } 3247 }
3205 3248
3206 node->dispatchEvent(keydown); 3249 if (!node->dispatchEvent(keydown))
3250 return eventToEventResult(keydown, false);
3207 // If frame changed as a result of keydown dispatch, then return early to av oid sending a subsequent keypress message to the new frame. 3251 // If frame changed as a result of keydown dispatch, then return early to av oid sending a subsequent keypress message to the new frame.
3208 bool changedFocusedFrame = m_frame->page() && m_frame != m_frame->page()->fo cusController().focusedOrMainFrame(); 3252 bool changedFocusedFrame = m_frame->page() && m_frame != m_frame->page()->fo cusController().focusedOrMainFrame();
3209 bool keydownResult = keydown->defaultHandled() || keydown->defaultPrevented( ) || changedFocusedFrame; 3253 if (changedFocusedFrame)
3210 if (keydownResult) 3254 return WebInputEventResult::HandledSystem;
3211 return keydownResult;
3212 3255
3213 // Focus may have changed during keydown handling, so refetch node. 3256 // Focus may have changed during keydown handling, so refetch node.
3214 // But if we are dispatching a fake backward compatibility keypress, then we pretend that the keypress happened on the original node. 3257 // But if we are dispatching a fake backward compatibility keypress, then we pretend that the keypress happened on the original node.
3215 node = eventTargetNodeForDocument(m_frame->document()); 3258 node = eventTargetNodeForDocument(m_frame->document());
3216 if (!node) 3259 if (!node)
3217 return false; 3260 return WebInputEventResult::NotHandled;
3218 3261
3219 PlatformKeyboardEvent keyPressEvent = initialKeyEvent; 3262 PlatformKeyboardEvent keyPressEvent = initialKeyEvent;
3220 keyPressEvent.disambiguateKeyDownEvent(PlatformEvent::Char); 3263 keyPressEvent.disambiguateKeyDownEvent(PlatformEvent::Char);
3221 if (keyPressEvent.text().isEmpty()) 3264 if (keyPressEvent.text().isEmpty())
3222 return keydownResult; 3265 return WebInputEventResult::NotHandled;
3223 RefPtrWillBeRawPtr<KeyboardEvent> keypress = KeyboardEvent::create(keyPressE vent, m_frame->document()->domWindow()); 3266 RefPtrWillBeRawPtr<KeyboardEvent> keypress = KeyboardEvent::create(keyPressE vent, m_frame->document()->domWindow());
3224 keypress->setTarget(node); 3267 keypress->setTarget(node);
3225 if (keydownResult) 3268 bool dispatchResult = node->dispatchEvent(keypress);
3226 keypress->setDefaultPrevented(true); 3269 return eventToEventResult(keypress, dispatchResult);
3227 node->dispatchEvent(keypress);
3228
3229 return keydownResult || keypress->defaultPrevented() || keypress->defaultHan dled();
3230 } 3270 }
3231 3271
3232 static WebFocusType focusDirectionForKey(const AtomicString& keyIdentifier) 3272 static WebFocusType focusDirectionForKey(const AtomicString& keyIdentifier)
3233 { 3273 {
3234 DEFINE_STATIC_LOCAL(AtomicString, Down, ("Down", AtomicString::ConstructFrom Literal)); 3274 DEFINE_STATIC_LOCAL(AtomicString, Down, ("Down", AtomicString::ConstructFrom Literal));
3235 DEFINE_STATIC_LOCAL(AtomicString, Up, ("Up", AtomicString::ConstructFromLite ral)); 3275 DEFINE_STATIC_LOCAL(AtomicString, Up, ("Up", AtomicString::ConstructFromLite ral));
3236 DEFINE_STATIC_LOCAL(AtomicString, Left, ("Left", AtomicString::ConstructFrom Literal)); 3276 DEFINE_STATIC_LOCAL(AtomicString, Left, ("Left", AtomicString::ConstructFrom Literal));
3237 DEFINE_STATIC_LOCAL(AtomicString, Right, ("Right", AtomicString::ConstructFr omLiteral)); 3277 DEFINE_STATIC_LOCAL(AtomicString, Right, ("Right", AtomicString::ConstructFr omLiteral));
3238 3278
3239 WebFocusType retVal = WebFocusTypeNone; 3279 WebFocusType retVal = WebFocusTypeNone;
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after
3337 } 3377 }
3338 3378
3339 void EventHandler::updateDragStateAfterEditDragIfNeeded(Element* rootEditableEle ment) 3379 void EventHandler::updateDragStateAfterEditDragIfNeeded(Element* rootEditableEle ment)
3340 { 3380 {
3341 // If inserting the dragged contents removed the drag source, we still want to fire dragend at the root editble element. 3381 // If inserting the dragged contents removed the drag source, we still want to fire dragend at the root editble element.
3342 if (dragState().m_dragSrc && !dragState().m_dragSrc->inDocument()) 3382 if (dragState().m_dragSrc && !dragState().m_dragSrc->inDocument())
3343 dragState().m_dragSrc = rootEditableElement; 3383 dragState().m_dragSrc = rootEditableElement;
3344 } 3384 }
3345 3385
3346 // returns if we should continue "default processing", i.e., whether eventhandle r canceled 3386 // returns if we should continue "default processing", i.e., whether eventhandle r canceled
3347 bool EventHandler::dispatchDragSrcEvent(const AtomicString& eventType, const Pla tformMouseEvent& event) 3387 WebInputEventResult EventHandler::dispatchDragSrcEvent(const AtomicString& event Type, const PlatformMouseEvent& event)
3348 { 3388 {
3349 return dispatchDragEvent(eventType, dragState().m_dragSrc.get(), event, drag State().m_dragDataTransfer.get()); 3389 return dispatchDragEvent(eventType, dragState().m_dragSrc.get(), event, drag State().m_dragDataTransfer.get());
3350 } 3390 }
3351 3391
3352 bool EventHandler::handleDrag(const MouseEventWithHitTestResults& event, DragIni tiator initiator) 3392 bool EventHandler::handleDrag(const MouseEventWithHitTestResults& event, DragIni tiator initiator)
3353 { 3393 {
3354 ASSERT(event.event().type() == PlatformEvent::MouseMoved); 3394 ASSERT(event.event().type() == PlatformEvent::MouseMoved);
3355 // Callers must protect the reference to FrameView, since this function may dispatch DOM 3395 // Callers must protect the reference to FrameView, since this function may dispatch DOM
3356 // events, causing page/FrameView to go away. 3396 // events, causing page/FrameView to go away.
3357 ASSERT(m_frame); 3397 ASSERT(m_frame);
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
3426 DragController& dragController = m_frame->page()->dragController(); 3466 DragController& dragController = m_frame->page()->dragController();
3427 if (!dragController.populateDragDataTransfer(m_frame, dragState(), m_mouseDo wnPos)) 3467 if (!dragController.populateDragDataTransfer(m_frame, dragState(), m_mouseDo wnPos))
3428 return false; 3468 return false;
3429 3469
3430 // If dispatching dragstart brings about another mouse down -- one way 3470 // If dispatching dragstart brings about another mouse down -- one way
3431 // this will happen is if a DevTools user breaks within a dragstart 3471 // this will happen is if a DevTools user breaks within a dragstart
3432 // handler and then clicks on the suspended page -- the drag state is 3472 // handler and then clicks on the suspended page -- the drag state is
3433 // reset. Hence, need to check if this particular drag operation can 3473 // reset. Hence, need to check if this particular drag operation can
3434 // continue even if dispatchEvent() indicates no (direct) cancellation. 3474 // continue even if dispatchEvent() indicates no (direct) cancellation.
3435 // Do that by checking if m_dragSrc is still set. 3475 // Do that by checking if m_dragSrc is still set.
3436 m_mouseDownMayStartDrag = !dispatchDragSrcEvent(EventTypeNames::dragstart, m _mouseDown) 3476 m_mouseDownMayStartDrag = dispatchDragSrcEvent(EventTypeNames::dragstart, m_ mouseDown) == WebInputEventResult::NotHandled
3437 && !m_frame->selection().isInPasswordField() && dragState().m_dragSrc; 3477 && !m_frame->selection().isInPasswordField() && dragState().m_dragSrc;
3438 3478
3439 // Invalidate clipboard here against anymore pasteboard writing for security . The drag 3479 // Invalidate clipboard here against anymore pasteboard writing for security . The drag
3440 // image can still be changed as we drag, but not the pasteboard data. 3480 // image can still be changed as we drag, but not the pasteboard data.
3441 dragState().m_dragDataTransfer->setAccessPolicy(DataTransferImageWritable); 3481 dragState().m_dragDataTransfer->setAccessPolicy(DataTransferImageWritable);
3442 3482
3443 if (m_mouseDownMayStartDrag) { 3483 if (m_mouseDownMayStartDrag) {
3444 // Dispatching the event could cause Page to go away. Make sure it's sti ll valid before trying to use DragController. 3484 // Dispatching the event could cause Page to go away. Make sure it's sti ll valid before trying to use DragController.
3445 if (m_frame->page() && dragController.startDrag(m_frame, dragState(), ev ent.event(), m_mouseDownPos)) 3485 if (m_frame->page() && dragController.startDrag(m_frame, dragState(), ev ent.event(), m_mouseDownPos))
3446 return true; 3486 return true;
(...skipping 280 matching lines...) Expand 10 before | Expand all | Expand 10 after
3727 // instance represents. 3767 // instance represents.
3728 RefPtrWillBeMember<TouchList> m_touches; 3768 RefPtrWillBeMember<TouchList> m_touches;
3729 3769
3730 using EventTargetSet = WillBeHeapHashSet<RefPtrWillBeMember<EventTarget>>; 3770 using EventTargetSet = WillBeHeapHashSet<RefPtrWillBeMember<EventTarget>>;
3731 // Set of targets involved in m_touches. 3771 // Set of targets involved in m_touches.
3732 EventTargetSet m_targets; 3772 EventTargetSet m_targets;
3733 }; 3773 };
3734 3774
3735 } // namespace 3775 } // namespace
3736 3776
3737 bool EventHandler::dispatchTouchEvents(const PlatformTouchEvent& event, 3777 WebInputEventResult EventHandler::dispatchTouchEvents(const PlatformTouchEvent& event,
3738 WillBeHeapVector<TouchInfo>& touchInfos, bool freshTouchEvents, bool allTouc hReleased) 3778 WillBeHeapVector<TouchInfo>& touchInfos, bool freshTouchEvents, bool allTouc hReleased)
3739 { 3779 {
3740 // Build up the lists to use for the 'touches', 'targetTouches' and 3780 // Build up the lists to use for the 'touches', 'targetTouches' and
3741 // 'changedTouches' attributes in the JS event. See 3781 // 'changedTouches' attributes in the JS event. See
3742 // http://www.w3.org/TR/touch-events/#touchevent-interface for how these 3782 // http://www.w3.org/TR/touch-events/#touchevent-interface for how these
3743 // lists fit together. 3783 // lists fit together.
3744 3784
3745 // Holds the complete set of touches on the screen. 3785 // Holds the complete set of touches on the screen.
3746 RefPtrWillBeRawPtr<TouchList> touches = TouchList::create(); 3786 RefPtrWillBeRawPtr<TouchList> touches = TouchList::create();
3747 3787
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
3799 changedTouches[pointState].m_touches = TouchList::create(); 3839 changedTouches[pointState].m_touches = TouchList::create();
3800 changedTouches[pointState].m_touches->append(touch); 3840 changedTouches[pointState].m_touches->append(touch);
3801 changedTouches[pointState].m_targets.add(touchInfo.touchTarget); 3841 changedTouches[pointState].m_targets.add(touchInfo.touchTarget);
3802 } 3842 }
3803 } 3843 }
3804 if (allTouchReleased) { 3844 if (allTouchReleased) {
3805 m_touchSequenceDocument.clear(); 3845 m_touchSequenceDocument.clear();
3806 m_touchSequenceUserGestureToken.clear(); 3846 m_touchSequenceUserGestureToken.clear();
3807 } 3847 }
3808 3848
3809 bool swallowedEvent = false; 3849 WebInputEventResult eventResult = WebInputEventResult::NotHandled;
3810 3850
3811 // Now iterate through the changedTouches list and m_targets within it, send ing 3851 // Now iterate through the changedTouches list and m_targets within it, send ing
3812 // TouchEvents to the targets as required. 3852 // TouchEvents to the targets as required.
3813 for (unsigned state = 0; state != PlatformTouchPoint::TouchStateEnd; ++state ) { 3853 for (unsigned state = 0; state != PlatformTouchPoint::TouchStateEnd; ++state ) {
3814 if (!changedTouches[state].m_touches) 3854 if (!changedTouches[state].m_touches)
3815 continue; 3855 continue;
3816 3856
3817 const AtomicString& eventName(touchEventNameForTouchPointState(static_ca st<PlatformTouchPoint::State>(state))); 3857 const AtomicString& eventName(touchEventNameForTouchPointState(static_ca st<PlatformTouchPoint::State>(state)));
3818 for (const auto& eventTarget : changedTouches[state].m_targets) { 3858 for (const auto& eventTarget : changedTouches[state].m_targets) {
3819 EventTarget* touchEventTarget = eventTarget.get(); 3859 EventTarget* touchEventTarget = eventTarget.get();
3820 RefPtrWillBeRawPtr<TouchEvent> touchEvent = TouchEvent::create( 3860 RefPtrWillBeRawPtr<TouchEvent> touchEvent = TouchEvent::create(
3821 touches.get(), touchesByTarget.get(touchEventTarget), changedTou ches[state].m_touches.get(), 3861 touches.get(), touchesByTarget.get(touchEventTarget), changedTou ches[state].m_touches.get(),
3822 eventName, touchEventTarget->toNode()->document().domWindow(), 3862 eventName, touchEventTarget->toNode()->document().domWindow(),
3823 event.modifiers(), event.cancelable(), event.causesScrollingIfUn canceled(), event.timestamp()); 3863 event.modifiers(), event.cancelable(), event.causesScrollingIfUn canceled(), event.timestamp());
3824 3864
3825 touchEventTarget->dispatchEvent(touchEvent.get()); 3865 bool dispatchResult = touchEventTarget->dispatchEvent(touchEvent.get ());
3826 swallowedEvent = swallowedEvent || touchEvent->defaultPrevented() || touchEvent->defaultHandled(); 3866 eventResult = mergeEventResult(eventResult, eventToEventResult(touch Event, dispatchResult));
3827 } 3867 }
3828 } 3868 }
3829 3869
3830 return swallowedEvent; 3870 return eventResult;
3831 } 3871 }
3832 3872
3833 bool EventHandler::handleTouchEvent(const PlatformTouchEvent& event) 3873 WebInputEventResult EventHandler::handleTouchEvent(const PlatformTouchEvent& eve nt)
3834 { 3874 {
3835 TRACE_EVENT0("blink", "EventHandler::handleTouchEvent"); 3875 TRACE_EVENT0("blink", "EventHandler::handleTouchEvent");
3836 3876
3837 const Vector<PlatformTouchPoint>& points = event.touchPoints(); 3877 const Vector<PlatformTouchPoint>& points = event.touchPoints();
3838 3878
3839 bool freshTouchEvents = true; 3879 bool freshTouchEvents = true;
3840 bool allTouchReleased = true; 3880 bool allTouchReleased = true;
3841 for (unsigned i = 0; i < points.size(); ++i) { 3881 for (unsigned i = 0; i < points.size(); ++i) {
3842 const PlatformTouchPoint& point = points[i]; 3882 const PlatformTouchPoint& point = points[i];
3843 3883
(...skipping 18 matching lines...) Expand all
3862 gestureIndicator = adoptPtr(new UserGestureIndicator(m_touchSequenceUser GestureToken.release())); 3902 gestureIndicator = adoptPtr(new UserGestureIndicator(m_touchSequenceUser GestureToken.release()));
3863 else 3903 else
3864 gestureIndicator = adoptPtr(new UserGestureIndicator(DefinitelyProcessin gUserGesture)); 3904 gestureIndicator = adoptPtr(new UserGestureIndicator(DefinitelyProcessin gUserGesture));
3865 3905
3866 m_touchSequenceUserGestureToken = gestureIndicator->currentToken(); 3906 m_touchSequenceUserGestureToken = gestureIndicator->currentToken();
3867 3907
3868 ASSERT(m_frame->view()); 3908 ASSERT(m_frame->view());
3869 if (m_touchSequenceDocument && (!m_touchSequenceDocument->frame() || !m_touc hSequenceDocument->frame()->view())) { 3909 if (m_touchSequenceDocument && (!m_touchSequenceDocument->frame() || !m_touc hSequenceDocument->frame()->view())) {
3870 // If the active touch document has no frame or view, it's probably bein g destroyed 3910 // If the active touch document has no frame or view, it's probably bein g destroyed
3871 // so we can't dispatch events. 3911 // so we can't dispatch events.
3872 return false; 3912 return WebInputEventResult::NotHandled;
3873 } 3913 }
3874 3914
3875 // First do hit tests for any new touch points. 3915 // First do hit tests for any new touch points.
3876 for (unsigned i = 0; i < points.size(); ++i) { 3916 for (unsigned i = 0; i < points.size(); ++i) {
3877 const PlatformTouchPoint& point = points[i]; 3917 const PlatformTouchPoint& point = points[i];
3878 3918
3879 // Touch events implicitly capture to the touched node, and don't change 3919 // Touch events implicitly capture to the touched node, and don't change
3880 // active/hover states themselves (Gesture events do). So we only need 3920 // active/hover states themselves (Gesture events do). So we only need
3881 // to hit-test on touchstart, and it can be read-only. 3921 // to hit-test on touchstart, and it can be read-only.
3882 if (point.state() == PlatformTouchPoint::TouchPressed) { 3922 if (point.state() == PlatformTouchPoint::TouchPressed) {
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
3925 m_touchPressed = !allTouchReleased; 3965 m_touchPressed = !allTouchReleased;
3926 3966
3927 // If there's no document receiving touch events, or no handlers on the 3967 // If there's no document receiving touch events, or no handlers on the
3928 // document set to receive the events, then we can skip all the rest of 3968 // document set to receive the events, then we can skip all the rest of
3929 // this work. 3969 // this work.
3930 if (!m_touchSequenceDocument || !m_touchSequenceDocument->frameHost() || !m_ touchSequenceDocument->frameHost()->eventHandlerRegistry().hasEventHandlers(Even tHandlerRegistry::TouchEvent) || !m_touchSequenceDocument->frame()) { 3970 if (!m_touchSequenceDocument || !m_touchSequenceDocument->frameHost() || !m_ touchSequenceDocument->frameHost()->eventHandlerRegistry().hasEventHandlers(Even tHandlerRegistry::TouchEvent) || !m_touchSequenceDocument->frame()) {
3931 if (allTouchReleased) { 3971 if (allTouchReleased) {
3932 m_touchSequenceDocument.clear(); 3972 m_touchSequenceDocument.clear();
3933 m_touchSequenceUserGestureToken.clear(); 3973 m_touchSequenceUserGestureToken.clear();
3934 } 3974 }
3935 return false; 3975 return WebInputEventResult::NotHandled;
3936 } 3976 }
3937 3977
3938 // Compute and store the common info used by both PointerEvent and TouchEven t. 3978 // Compute and store the common info used by both PointerEvent and TouchEven t.
3939 WillBeHeapVector<TouchInfo> touchInfos(points.size()); 3979 WillBeHeapVector<TouchInfo> touchInfos(points.size());
3940 3980
3941 for (unsigned i = 0; i < points.size(); ++i) { 3981 for (unsigned i = 0; i < points.size(); ++i) {
3942 const PlatformTouchPoint& point = points[i]; 3982 const PlatformTouchPoint& point = points[i];
3943 PlatformTouchPoint::State pointState = point.state(); 3983 PlatformTouchPoint::State pointState = point.state();
3944 RefPtrWillBeRawPtr<EventTarget> touchTarget = nullptr; 3984 RefPtrWillBeRawPtr<EventTarget> touchTarget = nullptr;
3945 3985
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
4004 // Note that the disposition of any pointer events affects only the gene ration of touch 4044 // Note that the disposition of any pointer events affects only the gene ration of touch
4005 // events. If all pointer events were handled (and hence no touch events were fired), that 4045 // events. If all pointer events were handled (and hence no touch events were fired), that
4006 // is still equivalent to the touch events going unhandled because point er event handler 4046 // is still equivalent to the touch events going unhandled because point er event handler
4007 // don't block scroll gesture generation. 4047 // don't block scroll gesture generation.
4008 } 4048 }
4009 4049
4010 // TODO(crbug.com/507408): If PE handlers always call preventDefault, we won 't see TEs until after 4050 // TODO(crbug.com/507408): If PE handlers always call preventDefault, we won 't see TEs until after
4011 // scrolling starts because the scrolling would suppress upcoming PEs. This sudden "break" in TE 4051 // scrolling starts because the scrolling would suppress upcoming PEs. This sudden "break" in TE
4012 // suppression can make the visible TEs inconsistent (e.g. touchmove without a touchstart). 4052 // suppression can make the visible TEs inconsistent (e.g. touchmove without a touchstart).
4013 4053
4014 bool swallowedTouchEvent = dispatchTouchEvents(event, touchInfos, freshTouch Events, 4054 WebInputEventResult eventResult = dispatchTouchEvents(event, touchInfos, fre shTouchEvents,
4015 allTouchReleased); 4055 allTouchReleased);
4016 4056
4017 if (!m_inPointerCanceledState) { 4057 if (!m_inPointerCanceledState) {
4018 // Check if we need to stop firing pointer events because of a touch act ion. 4058 // Check if we need to stop firing pointer events because of a touch act ion.
4019 // See: www.w3.org/TR/pointerevents/#declaring-candidate-regions-for-def ault-touch-behaviors 4059 // See: www.w3.org/TR/pointerevents/#declaring-candidate-regions-for-def ault-touch-behaviors
4020 if (event.causesScrollingIfUncanceled() && !swallowedTouchEvent) { 4060 if (event.causesScrollingIfUncanceled() && eventResult == WebInputEventR esult::NotHandled) {
4021 m_inPointerCanceledState = true; 4061 m_inPointerCanceledState = true;
4022 sendPointerCancels(touchInfos); 4062 sendPointerCancels(touchInfos);
4023 } 4063 }
4024 } else if (allTouchReleased) { 4064 } else if (allTouchReleased) {
4025 m_inPointerCanceledState = false; 4065 m_inPointerCanceledState = false;
4026 } 4066 }
4027 4067
4028 return swallowedTouchEvent; 4068 return eventResult;
4029 } 4069 }
4030 4070
4031 void EventHandler::setLastKnownMousePosition(const PlatformMouseEvent& event) 4071 void EventHandler::setLastKnownMousePosition(const PlatformMouseEvent& event)
4032 { 4072 {
4033 m_mousePositionIsUnknown = false; 4073 m_mousePositionIsUnknown = false;
4034 m_lastKnownMousePosition = event.position(); 4074 m_lastKnownMousePosition = event.position();
4035 m_lastKnownMouseGlobalPosition = event.globalPosition(); 4075 m_lastKnownMouseGlobalPosition = event.globalPosition();
4036 } 4076 }
4037 4077
4038 void EventHandler::conditionallyEnableMouseEventForPointerTypeMouse(const Platfo rmMouseEvent& event) 4078 void EventHandler::conditionallyEnableMouseEventForPointerTypeMouse(const Platfo rmMouseEvent& event)
4039 { 4079 {
4040 if (event.button() == NoButton) 4080 if (event.button() == NoButton)
4041 m_preventMouseEventForPointerTypeMouse = false; 4081 m_preventMouseEventForPointerTypeMouse = false;
4042 } 4082 }
4043 4083
4044 bool EventHandler::passMousePressEventToSubframe(MouseEventWithHitTestResults& m ev, LocalFrame* subframe) 4084 WebInputEventResult EventHandler::passMousePressEventToSubframe(MouseEventWithHi tTestResults& mev, LocalFrame* subframe)
4045 { 4085 {
4046 selectionController().passMousePressEventToSubframe(mev); 4086 selectionController().passMousePressEventToSubframe(mev);
4047 subframe->eventHandler().handleMousePressEvent(mev.event()); 4087 WebInputEventResult result = subframe->eventHandler().handleMousePressEvent( mev.event());
4048 return true; 4088 if (result != WebInputEventResult::NotHandled)
4089 return result;
4090 return WebInputEventResult::HandledSystem;
4049 } 4091 }
4050 4092
4051 bool EventHandler::passMouseMoveEventToSubframe(MouseEventWithHitTestResults& me v, LocalFrame* subframe, HitTestResult* hoveredNode) 4093 WebInputEventResult EventHandler::passMouseMoveEventToSubframe(MouseEventWithHit TestResults& mev, LocalFrame* subframe, HitTestResult* hoveredNode)
4052 { 4094 {
4053 if (m_mouseDownMayStartDrag) 4095 if (m_mouseDownMayStartDrag)
4054 return false; 4096 return WebInputEventResult::NotHandled;
4055 subframe->eventHandler().handleMouseMoveOrLeaveEvent(mev.event(), hoveredNod e); 4097 WebInputEventResult result = subframe->eventHandler().handleMouseMoveOrLeave Event(mev.event(), hoveredNode);
4056 return true; 4098 if (result != WebInputEventResult::NotHandled)
4099 return result;
4100 return WebInputEventResult::HandledSystem;
4057 } 4101 }
4058 4102
4059 bool EventHandler::passMouseReleaseEventToSubframe(MouseEventWithHitTestResults& mev, LocalFrame* subframe) 4103 WebInputEventResult EventHandler::passMouseReleaseEventToSubframe(MouseEventWith HitTestResults& mev, LocalFrame* subframe)
4060 { 4104 {
4061 subframe->eventHandler().handleMouseReleaseEvent(mev.event()); 4105 WebInputEventResult result = subframe->eventHandler().handleMouseReleaseEven t(mev.event());
4062 return true; 4106 if (result != WebInputEventResult::NotHandled)
4107 return result;
4108 return WebInputEventResult::HandledSystem;
4063 } 4109 }
4064 4110
4065 bool EventHandler::passWheelEventToWidget(const PlatformWheelEvent& wheelEvent, Widget& widget) 4111 WebInputEventResult EventHandler::passWheelEventToWidget(const PlatformWheelEven t& wheelEvent, Widget& widget)
4066 { 4112 {
4067 // If not a FrameView, then probably a plugin widget. Those will receive 4113 // If not a FrameView, then probably a plugin widget. Those will receive
4068 // the event via an EventTargetNode dispatch when this returns false. 4114 // the event via an EventTargetNode dispatch when this returns false.
4069 if (!widget.isFrameView()) 4115 if (!widget.isFrameView())
4070 return false; 4116 return WebInputEventResult::NotHandled;
4071 4117
4072 return toFrameView(&widget)->frame().eventHandler().handleWheelEvent(wheelEv ent); 4118 return toFrameView(&widget)->frame().eventHandler().handleWheelEvent(wheelEv ent);
4073 } 4119 }
4074 4120
4075 DataTransfer* EventHandler::createDraggingDataTransfer() const 4121 DataTransfer* EventHandler::createDraggingDataTransfer() const
4076 { 4122 {
4077 return DataTransfer::create(DataTransfer::DragAndDrop, DataTransferWritable, DataObject::create()); 4123 return DataTransfer::create(DataTransfer::DragAndDrop, DataTransferWritable, DataObject::create());
4078 } 4124 }
4079 4125
4080 void EventHandler::focusDocumentView() 4126 void EventHandler::focusDocumentView()
4081 { 4127 {
4082 Page* page = m_frame->page(); 4128 Page* page = m_frame->page();
4083 if (!page) 4129 if (!page)
4084 return; 4130 return;
4085 page->focusController().focusDocumentView(m_frame); 4131 page->focusController().focusDocumentView(m_frame);
4086 } 4132 }
4087 4133
4088 PlatformEvent::Modifiers EventHandler::accessKeyModifiers() 4134 PlatformEvent::Modifiers EventHandler::accessKeyModifiers()
4089 { 4135 {
4090 #if OS(MACOSX) 4136 #if OS(MACOSX)
4091 return static_cast<PlatformEvent::Modifiers>(PlatformEvent::CtrlKey | Platfo rmEvent::AltKey); 4137 return static_cast<PlatformEvent::Modifiers>(PlatformEvent::CtrlKey | Platfo rmEvent::AltKey);
4092 #else 4138 #else
4093 return PlatformEvent::AltKey; 4139 return PlatformEvent::AltKey;
4094 #endif 4140 #endif
4095 } 4141 }
4096 4142
4097 } // namespace blink 4143 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698