OLD | NEW |
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 385 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
396 m_latchedWheelEventNode = 0; | 396 m_latchedWheelEventNode = 0; |
397 m_previousWheelScrolledNode = 0; | 397 m_previousWheelScrolledNode = 0; |
398 #if ENABLE(TOUCH_EVENTS) | 398 #if ENABLE(TOUCH_EVENTS) |
399 m_originatingTouchPointTargets.clear(); | 399 m_originatingTouchPointTargets.clear(); |
400 m_originatingTouchPointDocument.clear(); | 400 m_originatingTouchPointDocument.clear(); |
401 m_originatingTouchPointTargetKey = 0; | 401 m_originatingTouchPointTargetKey = 0; |
402 #endif | 402 #endif |
403 #if ENABLE(GESTURE_EVENTS) | 403 #if ENABLE(GESTURE_EVENTS) |
404 m_scrollGestureHandlingNode = 0; | 404 m_scrollGestureHandlingNode = 0; |
405 m_lastHitTestResultOverWidget = false; | 405 m_lastHitTestResultOverWidget = false; |
| 406 m_previousGestureScrolledNode = 0; |
406 m_scrollbarHandlingScrollGesture = 0; | 407 m_scrollbarHandlingScrollGesture = 0; |
407 #endif | 408 #endif |
408 m_maxMouseMovedDuration = 0; | 409 m_maxMouseMovedDuration = 0; |
409 m_baseEventType = PlatformEvent::NoType; | 410 m_baseEventType = PlatformEvent::NoType; |
410 m_didStartDrag = false; | 411 m_didStartDrag = false; |
411 m_didLongPressInvokeContextMenu = false; | 412 m_didLongPressInvokeContextMenu = false; |
412 } | 413 } |
413 | 414 |
414 void EventHandler::nodeWillBeRemoved(Node* nodeToBeRemoved) | 415 void EventHandler::nodeWillBeRemoved(Node* nodeToBeRemoved) |
415 { | 416 { |
(...skipping 2075 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2491 // FIXME: A more general scroll system (https://bugs.webkit.org/show_bug.cgi
?id=80596) will | 2492 // FIXME: A more general scroll system (https://bugs.webkit.org/show_bug.cgi
?id=80596) will |
2492 // eliminate the need for this. | 2493 // eliminate the need for this. |
2493 TemporaryChange<PlatformEvent::Type> baseEventType(m_baseEventType, gestureE
vent.type()); | 2494 TemporaryChange<PlatformEvent::Type> baseEventType(m_baseEventType, gestureE
vent.type()); |
2494 | 2495 |
2495 switch (gestureEvent.type()) { | 2496 switch (gestureEvent.type()) { |
2496 case PlatformEvent::GestureScrollBegin: | 2497 case PlatformEvent::GestureScrollBegin: |
2497 return handleGestureScrollBegin(gestureEvent); | 2498 return handleGestureScrollBegin(gestureEvent); |
2498 case PlatformEvent::GestureScrollUpdate: | 2499 case PlatformEvent::GestureScrollUpdate: |
2499 case PlatformEvent::GestureScrollUpdateWithoutPropagation: | 2500 case PlatformEvent::GestureScrollUpdateWithoutPropagation: |
2500 return handleGestureScrollUpdate(gestureEvent); | 2501 return handleGestureScrollUpdate(gestureEvent); |
| 2502 case PlatformEvent::GestureScrollEnd: |
| 2503 clearGestureScrollNodes(); |
| 2504 return true; |
2501 case PlatformEvent::GestureTap: | 2505 case PlatformEvent::GestureTap: |
2502 return handleGestureTap(gestureEvent); | 2506 return handleGestureTap(gestureEvent); |
2503 case PlatformEvent::GestureTapDown: | 2507 case PlatformEvent::GestureTapDown: |
2504 return handleGestureTapDown(); | 2508 return handleGestureTapDown(); |
2505 case PlatformEvent::GestureLongPress: | 2509 case PlatformEvent::GestureLongPress: |
2506 return handleGestureLongPress(gestureEvent); | 2510 return handleGestureLongPress(gestureEvent); |
2507 case PlatformEvent::GestureLongTap: | 2511 case PlatformEvent::GestureLongTap: |
2508 return handleGestureLongTap(gestureEvent); | 2512 return handleGestureLongTap(gestureEvent); |
2509 case PlatformEvent::GestureTwoFingerTap: | 2513 case PlatformEvent::GestureTwoFingerTap: |
2510 return handleGestureTwoFingerTap(gestureEvent); | 2514 return handleGestureTwoFingerTap(gestureEvent); |
2511 case PlatformEvent::GestureScrollEnd: | |
2512 case PlatformEvent::GestureDoubleTap: | 2515 case PlatformEvent::GestureDoubleTap: |
2513 case PlatformEvent::GesturePinchBegin: | 2516 case PlatformEvent::GesturePinchBegin: |
2514 case PlatformEvent::GesturePinchEnd: | 2517 case PlatformEvent::GesturePinchEnd: |
2515 case PlatformEvent::GesturePinchUpdate: | 2518 case PlatformEvent::GesturePinchUpdate: |
2516 case PlatformEvent::GestureTapDownCancel: | 2519 case PlatformEvent::GestureTapDownCancel: |
2517 break; | 2520 break; |
2518 default: | 2521 default: |
2519 ASSERT_NOT_REACHED(); | 2522 ASSERT_NOT_REACHED(); |
2520 } | 2523 } |
2521 | 2524 |
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2629 | 2632 |
2630 bool EventHandler::passGestureEventToWidgetIfPossible(const PlatformGestureEvent
& gestureEvent, RenderObject* renderer) | 2633 bool EventHandler::passGestureEventToWidgetIfPossible(const PlatformGestureEvent
& gestureEvent, RenderObject* renderer) |
2631 { | 2634 { |
2632 if (m_lastHitTestResultOverWidget && renderer && renderer->isWidget()) { | 2635 if (m_lastHitTestResultOverWidget && renderer && renderer->isWidget()) { |
2633 Widget* widget = toRenderWidget(renderer)->widget(); | 2636 Widget* widget = toRenderWidget(renderer)->widget(); |
2634 return widget && passGestureEventToWidget(gestureEvent, widget); | 2637 return widget && passGestureEventToWidget(gestureEvent, widget); |
2635 } | 2638 } |
2636 return false; | 2639 return false; |
2637 } | 2640 } |
2638 | 2641 |
2639 static const Node* closestScrollableNodeCandidate(const Node* node) | |
2640 { | |
2641 for (const Node* scrollableNode = node; scrollableNode; scrollableNode = scr
ollableNode->parentNode()) { | |
2642 if (scrollableNode->isDocumentNode()) | |
2643 return scrollableNode; | |
2644 RenderObject* renderer = scrollableNode->renderer(); | |
2645 if (renderer && renderer->isBox() && toRenderBox(renderer)->canBeScrolle
dAndHasScrollableArea()) | |
2646 return scrollableNode; | |
2647 } | |
2648 return node; | |
2649 } | |
2650 | |
2651 bool EventHandler::handleGestureScrollBegin(const PlatformGestureEvent& gestureE
vent) | 2642 bool EventHandler::handleGestureScrollBegin(const PlatformGestureEvent& gestureE
vent) |
2652 { | 2643 { |
2653 Document* document = m_frame->document(); | 2644 Document* document = m_frame->document(); |
2654 RenderObject* documentRenderer = document->renderer(); | 2645 RenderObject* documentRenderer = document->renderer(); |
2655 if (!documentRenderer) | 2646 if (!documentRenderer) |
2656 return false; | 2647 return false; |
2657 | 2648 |
2658 FrameView* view = m_frame->view(); | 2649 FrameView* view = m_frame->view(); |
2659 if (!view) | 2650 if (!view) |
2660 return false; | 2651 return false; |
2661 | 2652 |
2662 LayoutPoint viewPoint = view->windowToContents(gestureEvent.position()); | 2653 LayoutPoint viewPoint = view->windowToContents(gestureEvent.position()); |
2663 HitTestRequest request(HitTestRequest::ReadOnly); | 2654 HitTestRequest request(HitTestRequest::ReadOnly); |
2664 HitTestResult result(viewPoint); | 2655 HitTestResult result(viewPoint); |
2665 document->renderView()->hitTest(request, result); | 2656 document->renderView()->hitTest(request, result); |
2666 | 2657 |
2667 m_lastHitTestResultOverWidget = result.isOverWidget(); | 2658 m_lastHitTestResultOverWidget = result.isOverWidget(); |
2668 m_scrollGestureHandlingNode = result.innerNode(); | 2659 m_scrollGestureHandlingNode = result.innerNode(); |
| 2660 m_previousGestureScrolledNode = 0; |
2669 | 2661 |
2670 Node* node = m_scrollGestureHandlingNode.get(); | 2662 Node* node = m_scrollGestureHandlingNode.get(); |
2671 if (node) | 2663 if (node) |
2672 passGestureEventToWidgetIfPossible(gestureEvent, node->renderer()); | 2664 passGestureEventToWidgetIfPossible(gestureEvent, node->renderer()); |
2673 | 2665 |
2674 return node && node->renderer(); | 2666 return node && node->renderer(); |
2675 } | 2667 } |
2676 | 2668 |
2677 bool EventHandler::handleGestureScrollUpdate(const PlatformGestureEvent& gesture
Event) | 2669 bool EventHandler::handleGestureScrollUpdate(const PlatformGestureEvent& gesture
Event) |
2678 { | 2670 { |
2679 // Ignore this event if we don't already have a targeted node with a valid r
enderer. | 2671 FloatSize delta(gestureEvent.deltaX(), gestureEvent.deltaY()); |
2680 const Node* node = m_scrollGestureHandlingNode.get(); | 2672 if (delta.isZero()) |
2681 if (!node) | |
2682 return false; | 2673 return false; |
2683 | 2674 |
2684 RenderObject* latchedRenderer = node->renderer(); | 2675 const float scaleFactor = m_frame->pageZoomFactor() * m_frame->frameScaleFac
tor(); |
2685 if (!latchedRenderer) | 2676 delta.scale(1 / scaleFactor, 1 / scaleFactor); |
2686 return false; | |
2687 | 2677 |
2688 IntSize delta(-gestureEvent.deltaX(), -gestureEvent.deltaY()); | 2678 Node* node = m_scrollGestureHandlingNode.get(); |
2689 if (delta.isZero()) | 2679 if (!node) |
| 2680 return sendScrollEventToView(gestureEvent, delta); |
| 2681 |
| 2682 // Ignore this event if the targeted node does not have a valid renderer. |
| 2683 RenderObject* renderer = node->renderer(); |
| 2684 if (!renderer) |
2690 return false; | 2685 return false; |
2691 | 2686 |
2692 RefPtr<FrameView> protector(m_frame->view()); | 2687 RefPtr<FrameView> protector(m_frame->view()); |
2693 | 2688 |
2694 // Try to send the event to the correct view. | 2689 // Try to send the event to the correct view. |
2695 if (passGestureEventToWidgetIfPossible(gestureEvent, latchedRenderer)) | 2690 if (passGestureEventToWidgetIfPossible(gestureEvent, renderer)) |
2696 return true; | 2691 return true; |
2697 | 2692 |
2698 // Otherwise if this is the correct view for the event, find the closest scr
ollable | 2693 Node* stopNode = 0; |
2699 // ancestor of the targeted node and scroll the layer that contains this nod
e's renderer. | 2694 bool scrollShouldNotPropagate = gestureEvent.type() == PlatformEvent::Gestur
eScrollUpdateWithoutPropagation; |
2700 node = closestScrollableNodeCandidate(node); | 2695 if (scrollShouldNotPropagate) |
2701 if (!node) | 2696 stopNode = m_previousGestureScrolledNode.get(); |
| 2697 |
| 2698 // First try to scroll the closest scrollable RenderBox ancestor of |node|. |
| 2699 ScrollGranularity granularity = ScrollByPixel; |
| 2700 bool horizontalScroll = scrollNode(delta.width(), granularity, ScrollLeft, S
crollRight, node, &stopNode); |
| 2701 bool verticalScroll = scrollNode(delta.height(), granularity, ScrollUp, Scro
llDown, node, &stopNode); |
| 2702 |
| 2703 if (scrollShouldNotPropagate) |
| 2704 m_previousGestureScrolledNode = stopNode; |
| 2705 |
| 2706 if (horizontalScroll || verticalScroll) { |
| 2707 setFrameWasScrolledByUser(); |
| 2708 return true; |
| 2709 } |
| 2710 |
| 2711 // Otherwise try to scroll the view. |
| 2712 return sendScrollEventToView(gestureEvent, delta); |
| 2713 } |
| 2714 |
| 2715 bool EventHandler::sendScrollEventToView(const PlatformGestureEvent& gestureEven
t, const FloatSize& scaledDelta) |
| 2716 { |
| 2717 FrameView* view = m_frame->view(); |
| 2718 if (!view) |
2702 return false; | 2719 return false; |
2703 | 2720 |
2704 latchedRenderer = node->renderer(); | 2721 const float tickDivisor = static_cast<float>(WheelEvent::TickMultiplier); |
2705 if (!latchedRenderer) | 2722 IntPoint point(gestureEvent.position().x(), gestureEvent.position().y()); |
2706 return false; | 2723 IntPoint globalPoint(gestureEvent.globalPosition().x(), gestureEvent.globalP
osition().y()); |
| 2724 PlatformWheelEvent syntheticWheelEvent(point, globalPoint, |
| 2725 scaledDelta.width(), scaledDelta.height(), |
| 2726 scaledDelta.width() / tickDivisor, scaledDelta.height() / tickDivisor, |
| 2727 ScrollByPixelWheelEvent, |
| 2728 gestureEvent.shiftKey(), gestureEvent.ctrlKey(), gestureEvent.altKey(),
gestureEvent.metaKey()); |
| 2729 #if PLATFORM(MAC) || PLATFORM(CHROMIUM) |
| 2730 syntheticWheelEvent.setHasPreciseScrollingDeltas(true); |
| 2731 #endif |
2707 | 2732 |
2708 RenderLayer::ScrollPropagation shouldPropagate = RenderLayer::ShouldPropagat
eScroll; | 2733 bool scrolledFrame = view->wheelEvent(syntheticWheelEvent); |
2709 if (gestureEvent.type() == PlatformEvent::GestureScrollUpdateWithoutPropagat
ion) | 2734 if (scrolledFrame) |
2710 shouldPropagate = RenderLayer::DontPropagateScroll; | |
2711 | |
2712 const float scaleFactor = m_frame->pageZoomFactor() * m_frame->frameScaleFac
tor(); | |
2713 delta.scale(1 / scaleFactor, 1 / scaleFactor); | |
2714 | |
2715 bool result = latchedRenderer->enclosingLayer()->scrollBy(delta, RenderLayer
::ScrollOffsetClamped, shouldPropagate); | |
2716 | |
2717 if (result) | |
2718 setFrameWasScrolledByUser(); | 2735 setFrameWasScrolledByUser(); |
2719 | 2736 |
2720 return result; | 2737 return scrolledFrame; |
| 2738 } |
| 2739 |
| 2740 void EventHandler::clearGestureScrollNodes() |
| 2741 { |
| 2742 m_scrollGestureHandlingNode = 0; |
| 2743 m_previousGestureScrolledNode = 0; |
2721 } | 2744 } |
2722 | 2745 |
2723 bool EventHandler::isScrollbarHandlingGestures() const | 2746 bool EventHandler::isScrollbarHandlingGestures() const |
2724 { | 2747 { |
2725 return m_scrollbarHandlingScrollGesture.get(); | 2748 return m_scrollbarHandlingScrollGesture.get(); |
2726 } | 2749 } |
2727 #endif // ENABLE(GESTURE_EVENTS) | 2750 #endif // ENABLE(GESTURE_EVENTS) |
2728 | 2751 |
2729 #if ENABLE(TOUCH_ADJUSTMENT) | 2752 #if ENABLE(TOUCH_ADJUSTMENT) |
2730 bool EventHandler::shouldApplyTouchAdjustment(const PlatformGestureEvent& event)
const | 2753 bool EventHandler::shouldApplyTouchAdjustment(const PlatformGestureEvent& event)
const |
(...skipping 1292 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4023 #endif | 4046 #endif |
4024 | 4047 |
4025 void EventHandler::setLastKnownMousePosition(const PlatformMouseEvent& event) | 4048 void EventHandler::setLastKnownMousePosition(const PlatformMouseEvent& event) |
4026 { | 4049 { |
4027 m_mousePositionIsUnknown = false; | 4050 m_mousePositionIsUnknown = false; |
4028 m_lastKnownMousePosition = event.position(); | 4051 m_lastKnownMousePosition = event.position(); |
4029 m_lastKnownMouseGlobalPosition = event.globalPosition(); | 4052 m_lastKnownMouseGlobalPosition = event.globalPosition(); |
4030 } | 4053 } |
4031 | 4054 |
4032 } // namespace WebCore | 4055 } // namespace WebCore |
OLD | NEW |