| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2011, 2012 Google Inc. All rights reserved. | 2 * Copyright (C) 2011, 2012 Google Inc. All rights reserved. |
| 3 * | 3 * |
| 4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
| 5 * modification, are permitted provided that the following conditions are | 5 * modification, are permitted provided that the following conditions are |
| 6 * met: | 6 * met: |
| 7 * | 7 * |
| 8 * * Redistributions of source code must retain the above copyright | 8 * * Redistributions of source code must retain the above copyright |
| 9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
| 10 * * Redistributions in binary form must reproduce the above | 10 * * Redistributions in binary form must reproduce the above |
| (...skipping 591 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 602 if (!event.hasPreciseScrollingDeltas) | 602 if (!event.hasPreciseScrollingDeltas) |
| 603 endActiveFlingAnimation(); | 603 endActiveFlingAnimation(); |
| 604 | 604 |
| 605 hidePopups(); | 605 hidePopups(); |
| 606 return PageWidgetEventHandler::handleMouseWheel(mainFrame, event); | 606 return PageWidgetEventHandler::handleMouseWheel(mainFrame, event); |
| 607 } | 607 } |
| 608 | 608 |
| 609 WebGestureEvent WebViewImpl::createGestureScrollEventFromFling( | 609 WebGestureEvent WebViewImpl::createGestureScrollEventFromFling( |
| 610 WebInputEvent::Type type, | 610 WebInputEvent::Type type, |
| 611 WebGestureDevice sourceDevice) const { | 611 WebGestureDevice sourceDevice) const { |
| 612 WebGestureEvent gestureEvent; | 612 WebGestureEvent gestureEvent(type, m_flingModifier, |
| 613 gestureEvent.type = type; | 613 WTF::monotonicallyIncreasingTime()); |
| 614 gestureEvent.sourceDevice = sourceDevice; | 614 gestureEvent.sourceDevice = sourceDevice; |
| 615 gestureEvent.timeStampSeconds = WTF::monotonicallyIncreasingTime(); | |
| 616 gestureEvent.x = m_positionOnFlingStart.x; | 615 gestureEvent.x = m_positionOnFlingStart.x; |
| 617 gestureEvent.y = m_positionOnFlingStart.y; | 616 gestureEvent.y = m_positionOnFlingStart.y; |
| 618 gestureEvent.globalX = m_globalPositionOnFlingStart.x; | 617 gestureEvent.globalX = m_globalPositionOnFlingStart.x; |
| 619 gestureEvent.globalY = m_globalPositionOnFlingStart.y; | 618 gestureEvent.globalY = m_globalPositionOnFlingStart.y; |
| 620 gestureEvent.modifiers = m_flingModifier; | |
| 621 return gestureEvent; | 619 return gestureEvent; |
| 622 } | 620 } |
| 623 | 621 |
| 624 bool WebViewImpl::scrollBy(const WebFloatSize& delta, | 622 bool WebViewImpl::scrollBy(const WebFloatSize& delta, |
| 625 const WebFloatSize& velocity) { | 623 const WebFloatSize& velocity) { |
| 626 DCHECK_NE(m_flingSourceDevice, WebGestureDeviceUninitialized); | 624 DCHECK_NE(m_flingSourceDevice, WebGestureDeviceUninitialized); |
| 627 if (!m_page || !m_page->mainFrame() || !m_page->mainFrame()->isLocalFrame() || | 625 if (!m_page || !m_page->mainFrame() || !m_page->mainFrame()->isLocalFrame() || |
| 628 !m_page->deprecatedLocalMainFrame()->view()) | 626 !m_page->deprecatedLocalMainFrame()->view()) |
| 629 return false; | 627 return false; |
| 630 | 628 |
| 631 if (m_flingSourceDevice == WebGestureDeviceTouchpad) { | 629 if (m_flingSourceDevice == WebGestureDeviceTouchpad) { |
| 632 WebMouseWheelEvent syntheticWheel; | 630 WebMouseWheelEvent syntheticWheel(WebInputEvent::MouseWheel, |
| 631 m_flingModifier, |
| 632 WTF::monotonicallyIncreasingTime()); |
| 633 const float tickDivisor = WheelEvent::TickMultiplier; | 633 const float tickDivisor = WheelEvent::TickMultiplier; |
| 634 | 634 |
| 635 syntheticWheel.type = WebInputEvent::MouseWheel; | |
| 636 syntheticWheel.timeStampSeconds = WTF::monotonicallyIncreasingTime(); | |
| 637 syntheticWheel.deltaX = delta.width; | 635 syntheticWheel.deltaX = delta.width; |
| 638 syntheticWheel.deltaY = delta.height; | 636 syntheticWheel.deltaY = delta.height; |
| 639 syntheticWheel.wheelTicksX = delta.width / tickDivisor; | 637 syntheticWheel.wheelTicksX = delta.width / tickDivisor; |
| 640 syntheticWheel.wheelTicksY = delta.height / tickDivisor; | 638 syntheticWheel.wheelTicksY = delta.height / tickDivisor; |
| 641 syntheticWheel.hasPreciseScrollingDeltas = true; | 639 syntheticWheel.hasPreciseScrollingDeltas = true; |
| 642 syntheticWheel.x = m_positionOnFlingStart.x; | 640 syntheticWheel.x = m_positionOnFlingStart.x; |
| 643 syntheticWheel.y = m_positionOnFlingStart.y; | 641 syntheticWheel.y = m_positionOnFlingStart.y; |
| 644 syntheticWheel.globalX = m_globalPositionOnFlingStart.x; | 642 syntheticWheel.globalX = m_globalPositionOnFlingStart.x; |
| 645 syntheticWheel.globalY = m_globalPositionOnFlingStart.y; | 643 syntheticWheel.globalY = m_globalPositionOnFlingStart.y; |
| 646 syntheticWheel.modifiers = m_flingModifier; | |
| 647 | 644 |
| 648 if (handleMouseWheel(*m_page->deprecatedLocalMainFrame(), syntheticWheel) != | 645 if (handleMouseWheel(*m_page->deprecatedLocalMainFrame(), syntheticWheel) != |
| 649 WebInputEventResult::NotHandled) | 646 WebInputEventResult::NotHandled) |
| 650 return true; | 647 return true; |
| 651 | 648 |
| 652 // TODO(dtapuska): Remove these GSB/GSE sequences when trackpad latching is | 649 // TODO(dtapuska): Remove these GSB/GSE sequences when trackpad latching is |
| 653 // implemented; see crbug.com/526463. | 650 // implemented; see crbug.com/526463. |
| 654 WebGestureEvent syntheticScrollBegin = createGestureScrollEventFromFling( | 651 WebGestureEvent syntheticScrollBegin = createGestureScrollEventFromFling( |
| 655 WebInputEvent::GestureScrollBegin, WebGestureDeviceTouchpad); | 652 WebInputEvent::GestureScrollBegin, WebGestureDeviceTouchpad); |
| 656 syntheticScrollBegin.data.scrollBegin.deltaXHint = delta.width; | 653 syntheticScrollBegin.data.scrollBegin.deltaXHint = delta.width; |
| (...skipping 274 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 931 } | 928 } |
| 932 | 929 |
| 933 WebInputEventResult WebViewImpl::handleSyntheticWheelFromTouchpadPinchEvent( | 930 WebInputEventResult WebViewImpl::handleSyntheticWheelFromTouchpadPinchEvent( |
| 934 const WebGestureEvent& pinchEvent) { | 931 const WebGestureEvent& pinchEvent) { |
| 935 DCHECK_EQ(pinchEvent.type, WebInputEvent::GesturePinchUpdate); | 932 DCHECK_EQ(pinchEvent.type, WebInputEvent::GesturePinchUpdate); |
| 936 | 933 |
| 937 // For pinch gesture events, match typical trackpad behavior on Windows by | 934 // For pinch gesture events, match typical trackpad behavior on Windows by |
| 938 // sending fake wheel events with the ctrl modifier set when we see trackpad | 935 // sending fake wheel events with the ctrl modifier set when we see trackpad |
| 939 // pinch gestures. Ideally we'd someday get a platform 'pinch' event and | 936 // pinch gestures. Ideally we'd someday get a platform 'pinch' event and |
| 940 // send that instead. | 937 // send that instead. |
| 941 WebMouseWheelEvent wheelEvent; | 938 WebMouseWheelEvent wheelEvent( |
| 942 wheelEvent.type = WebInputEvent::MouseWheel; | 939 WebInputEvent::MouseWheel, |
| 943 wheelEvent.timeStampSeconds = pinchEvent.timeStampSeconds; | 940 pinchEvent.modifiers | WebInputEvent::ControlKey, |
| 941 pinchEvent.timeStampSeconds); |
| 944 wheelEvent.windowX = wheelEvent.x = pinchEvent.x; | 942 wheelEvent.windowX = wheelEvent.x = pinchEvent.x; |
| 945 wheelEvent.windowY = wheelEvent.y = pinchEvent.y; | 943 wheelEvent.windowY = wheelEvent.y = pinchEvent.y; |
| 946 wheelEvent.globalX = pinchEvent.globalX; | 944 wheelEvent.globalX = pinchEvent.globalX; |
| 947 wheelEvent.globalY = pinchEvent.globalY; | 945 wheelEvent.globalY = pinchEvent.globalY; |
| 948 wheelEvent.modifiers = pinchEvent.modifiers | WebInputEvent::ControlKey; | |
| 949 wheelEvent.deltaX = 0; | 946 wheelEvent.deltaX = 0; |
| 950 | 947 |
| 951 // The function to convert scales to deltaY values is designed to be | 948 // The function to convert scales to deltaY values is designed to be |
| 952 // compatible with websites existing use of wheel events, and with existing | 949 // compatible with websites existing use of wheel events, and with existing |
| 953 // Windows trackpad behavior. In particular, we want: | 950 // Windows trackpad behavior. In particular, we want: |
| 954 // - deltas should accumulate via addition: f(s1*s2)==f(s1)+f(s2) | 951 // - deltas should accumulate via addition: f(s1*s2)==f(s1)+f(s2) |
| 955 // - deltas should invert via negation: f(1/s) == -f(s) | 952 // - deltas should invert via negation: f(1/s) == -f(s) |
| 956 // - zoom in should be positive: f(s) > 0 iff s > 1 | 953 // - zoom in should be positive: f(s) > 0 iff s > 1 |
| 957 // - magnitude roughly matches wheels: f(2) > 25 && f(2) < 100 | 954 // - magnitude roughly matches wheels: f(2) > 25 && f(2) < 100 |
| 958 // - a formula that's relatively easy to use from JavaScript | 955 // - a formula that's relatively easy to use from JavaScript |
| (...skipping 2818 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3777 result.setToShadowHostIfInUserAgentShadowRoot(); | 3774 result.setToShadowHostIfInUserAgentShadowRoot(); |
| 3778 return result; | 3775 return result; |
| 3779 } | 3776 } |
| 3780 | 3777 |
| 3781 WebHitTestResult WebViewImpl::hitTestResultForTap( | 3778 WebHitTestResult WebViewImpl::hitTestResultForTap( |
| 3782 const WebPoint& tapPointWindowPos, | 3779 const WebPoint& tapPointWindowPos, |
| 3783 const WebSize& tapArea) { | 3780 const WebSize& tapArea) { |
| 3784 if (!m_page->mainFrame()->isLocalFrame()) | 3781 if (!m_page->mainFrame()->isLocalFrame()) |
| 3785 return HitTestResult(); | 3782 return HitTestResult(); |
| 3786 | 3783 |
| 3787 WebGestureEvent tapEvent; | 3784 WebGestureEvent tapEvent(WebInputEvent::GestureTap, |
| 3785 WebInputEvent::NoModifiers, |
| 3786 WTF::monotonicallyIncreasingTime()); |
| 3788 tapEvent.x = tapPointWindowPos.x; | 3787 tapEvent.x = tapPointWindowPos.x; |
| 3789 tapEvent.y = tapPointWindowPos.y; | 3788 tapEvent.y = tapPointWindowPos.y; |
| 3790 tapEvent.type = WebInputEvent::GestureTap; | |
| 3791 // GestureTap is only ever from a touchscreen. | 3789 // GestureTap is only ever from a touchscreen. |
| 3792 tapEvent.sourceDevice = WebGestureDeviceTouchscreen; | 3790 tapEvent.sourceDevice = WebGestureDeviceTouchscreen; |
| 3793 tapEvent.data.tap.tapCount = 1; | 3791 tapEvent.data.tap.tapCount = 1; |
| 3794 tapEvent.data.tap.width = tapArea.width; | 3792 tapEvent.data.tap.width = tapArea.width; |
| 3795 tapEvent.data.tap.height = tapArea.height; | 3793 tapEvent.data.tap.height = tapArea.height; |
| 3796 | 3794 |
| 3797 WebGestureEvent scaledEvent = | 3795 WebGestureEvent scaledEvent = |
| 3798 TransformWebGestureEvent(mainFrameImpl()->frameView(), tapEvent); | 3796 TransformWebGestureEvent(mainFrameImpl()->frameView(), tapEvent); |
| 3799 | 3797 |
| 3800 HitTestResult result = | 3798 HitTestResult result = |
| (...skipping 401 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4202 if (focusedFrame->localFrameRoot() != mainFrameImpl()->frame()) | 4200 if (focusedFrame->localFrameRoot() != mainFrameImpl()->frame()) |
| 4203 return nullptr; | 4201 return nullptr; |
| 4204 return focusedFrame; | 4202 return focusedFrame; |
| 4205 } | 4203 } |
| 4206 | 4204 |
| 4207 LocalFrame* WebViewImpl::focusedLocalFrameAvailableForIme() const { | 4205 LocalFrame* WebViewImpl::focusedLocalFrameAvailableForIme() const { |
| 4208 return m_imeAcceptEvents ? focusedLocalFrameInWidget() : nullptr; | 4206 return m_imeAcceptEvents ? focusedLocalFrameInWidget() : nullptr; |
| 4209 } | 4207 } |
| 4210 | 4208 |
| 4211 } // namespace blink | 4209 } // namespace blink |
| OLD | NEW |