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

Side by Side Diff: sky/engine/core/page/EventHandler.cpp

Issue 774053003: Remove TouchAdjustment. (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Created 6 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
« no previous file with comments | « sky/engine/core/page/EventHandler.h ('k') | sky/engine/core/page/TouchAdjustment.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
52 #include "sky/engine/core/frame/LocalFrame.h" 52 #include "sky/engine/core/frame/LocalFrame.h"
53 #include "sky/engine/core/frame/Settings.h" 53 #include "sky/engine/core/frame/Settings.h"
54 #include "sky/engine/core/loader/FrameLoaderClient.h" 54 #include "sky/engine/core/loader/FrameLoaderClient.h"
55 #include "sky/engine/core/page/AutoscrollController.h" 55 #include "sky/engine/core/page/AutoscrollController.h"
56 #include "sky/engine/core/page/Chrome.h" 56 #include "sky/engine/core/page/Chrome.h"
57 #include "sky/engine/core/page/ChromeClient.h" 57 #include "sky/engine/core/page/ChromeClient.h"
58 #include "sky/engine/core/page/EditorClient.h" 58 #include "sky/engine/core/page/EditorClient.h"
59 #include "sky/engine/core/page/EventWithHitTestResults.h" 59 #include "sky/engine/core/page/EventWithHitTestResults.h"
60 #include "sky/engine/core/page/FocusController.h" 60 #include "sky/engine/core/page/FocusController.h"
61 #include "sky/engine/core/page/Page.h" 61 #include "sky/engine/core/page/Page.h"
62 #include "sky/engine/core/page/TouchAdjustment.h"
63 #include "sky/engine/core/rendering/HitTestRequest.h" 62 #include "sky/engine/core/rendering/HitTestRequest.h"
64 #include "sky/engine/core/rendering/HitTestResult.h" 63 #include "sky/engine/core/rendering/HitTestResult.h"
65 #include "sky/engine/core/rendering/RenderLayer.h" 64 #include "sky/engine/core/rendering/RenderLayer.h"
66 #include "sky/engine/core/rendering/RenderView.h" 65 #include "sky/engine/core/rendering/RenderView.h"
67 #include "sky/engine/core/rendering/style/RenderStyle.h" 66 #include "sky/engine/core/rendering/style/RenderStyle.h"
68 #include "sky/engine/platform/PlatformGestureEvent.h" 67 #include "sky/engine/platform/PlatformGestureEvent.h"
69 #include "sky/engine/platform/PlatformKeyboardEvent.h" 68 #include "sky/engine/platform/PlatformKeyboardEvent.h"
70 #include "sky/engine/platform/PlatformTouchEvent.h" 69 #include "sky/engine/platform/PlatformTouchEvent.h"
71 #include "sky/engine/platform/PlatformWheelEvent.h" 70 #include "sky/engine/platform/PlatformWheelEvent.h"
72 #include "sky/engine/platform/TraceEvent.h" 71 #include "sky/engine/platform/TraceEvent.h"
(...skipping 1788 matching lines...) Expand 10 before | Expand all | Expand 10 after
1861 { 1860 {
1862 m_scrollGestureHandlingNode = nullptr; 1861 m_scrollGestureHandlingNode = nullptr;
1863 m_previousGestureScrolledNode = nullptr; 1862 m_previousGestureScrolledNode = nullptr;
1864 } 1863 }
1865 1864
1866 bool EventHandler::isScrollbarHandlingGestures() const 1865 bool EventHandler::isScrollbarHandlingGestures() const
1867 { 1866 {
1868 return m_scrollbarHandlingScrollGesture.get(); 1867 return m_scrollbarHandlingScrollGesture.get();
1869 } 1868 }
1870 1869
1871 bool EventHandler::shouldApplyTouchAdjustment(const PlatformGestureEvent& event) const
1872 {
1873 if (m_frame->settings() && !m_frame->settings()->touchAdjustmentEnabled())
1874 return false;
1875 return !event.area().isEmpty();
1876 }
1877
1878 bool EventHandler::bestClickableNodeForHitTestResult(const HitTestResult& result , IntPoint& targetPoint, Node*& targetNode)
1879 {
1880 // FIXME: Unify this with the other best* functions which are very similar.
1881
1882 TRACE_EVENT0("input", "EventHandler::bestClickableNodeForHitTestResult");
1883 ASSERT(result.isRectBasedTest());
1884
1885 // If the touch is over a scrollbar, don't adjust the touch point since touc h adjustment only takes into account
1886 // DOM nodes so a touch over a scrollbar will be adjusted towards nearby nod es. This leads to things like textarea
1887 // scrollbars being untouchable.
1888 if (result.scrollbar())
1889 return false;
1890
1891 IntPoint touchCenter = m_frame->view()->contentsToWindow(result.roundedPoint InMainFrame());
1892 IntRect touchRect = m_frame->view()->contentsToWindow(result.hitTestLocation ().boundingBox());
1893
1894 Vector<RefPtr<Node>, 11> nodes;
1895 copyToVector(result.rectBasedTestResult(), nodes);
1896
1897 // FIXME: the explicit Vector conversion copies into a temporary and is wast eful.
1898 return findBestClickableCandidate(targetNode, targetPoint, touchCenter, touc hRect, Vector<RefPtr<Node> > (nodes));
1899 }
1900
1901 GestureEventWithHitTestResults EventHandler::targetGestureEvent(const PlatformGe stureEvent& gestureEvent, bool readOnly) 1870 GestureEventWithHitTestResults EventHandler::targetGestureEvent(const PlatformGe stureEvent& gestureEvent, bool readOnly)
1902 { 1871 {
1903 // Scrolling events get hit tested per frame (like wheel events do). 1872 // Scrolling events get hit tested per frame (like wheel events do).
1904 ASSERT(!gestureEvent.isScrollEvent()); 1873 ASSERT(!gestureEvent.isScrollEvent());
1905 1874
1906 HitTestRequest::HitTestRequestType hitType = getHitTypeForGestureType(gestur eEvent.type()); 1875 HitTestRequest::HitTestRequestType hitType = getHitTypeForGestureType(gestur eEvent.type());
1907 double activeInterval = 0; 1876 double activeInterval = 0;
1908 bool shouldKeepActiveForMinInterval = false; 1877 bool shouldKeepActiveForMinInterval = false;
1909 if (readOnly) { 1878 if (readOnly) {
1910 hitType |= HitTestRequest::ReadOnly; 1879 hitType |= HitTestRequest::ReadOnly;
1911 } else if (gestureEvent.type() == PlatformEvent::GestureTap) { 1880 } else if (gestureEvent.type() == PlatformEvent::GestureTap) {
1912 // If the Tap is received very shortly after ShowPress, we want to 1881 // If the Tap is received very shortly after ShowPress, we want to
1913 // delay clearing of the active state so that it's visible to the user 1882 // delay clearing of the active state so that it's visible to the user
1914 // for at least a couple of frames. 1883 // for at least a couple of frames.
1915 activeInterval = WTF::currentTime() - m_lastShowPressTimestamp; 1884 activeInterval = WTF::currentTime() - m_lastShowPressTimestamp;
1916 shouldKeepActiveForMinInterval = m_lastShowPressTimestamp && activeInter val < minimumActiveInterval; 1885 shouldKeepActiveForMinInterval = m_lastShowPressTimestamp && activeInter val < minimumActiveInterval;
1917 if (shouldKeepActiveForMinInterval) 1886 if (shouldKeepActiveForMinInterval)
1918 hitType |= HitTestRequest::ReadOnly; 1887 hitType |= HitTestRequest::ReadOnly;
1919 } 1888 }
1920 1889
1921 // Perform the rect-based hit-test. Note that we don't yet apply hover/activ e state here 1890 // Perform the rect-based hit-test. Note that we don't yet apply hover/activ e state here
1922 // because we need to resolve touch adjustment first so that we apply hover/ active it to 1891 // because we need to resolve touch adjustment first so that we apply hover/ active it to
1923 // the final adjusted node. 1892 // the final adjusted node.
1924 IntPoint hitTestPoint = gestureEvent.position(); 1893 IntPoint hitTestPoint = gestureEvent.position();
1925 IntSize touchRadius = gestureEvent.area(); 1894 IntSize touchRadius = gestureEvent.area();
1926 touchRadius.scale(1.f / 2); 1895 touchRadius.scale(1.f / 2);
1927 // FIXME: We should not do a rect-based hit-test if touch adjustment is disa bled. 1896 // FIXME: We should not do a rect-based hit-test if touch adjustment is disa bled.
1928 HitTestResult hitTestResult = hitTestResultAtPoint(hitTestPoint, hitType | H itTestRequest::ReadOnly, touchRadius); 1897 HitTestResult hitTestResult = hitTestResultAtPoint(hitTestPoint, hitType | H itTestRequest::ReadOnly, touchRadius);
1929 1898
1930 // Adjust the location of the gesture to the most likely nearby node, as app ropriate for the
1931 // type of event.
1932 PlatformGestureEvent adjustedEvent = gestureEvent;
1933 applyTouchAdjustment(&adjustedEvent, &hitTestResult);
1934
1935 // Do a new hit-test at the (adjusted) gesture co-ordinates. This is necessa ry because
1936 // rect-based hit testing and touch adjustment sometimes return a different node than
1937 // what a point-based hit test would return for the same point.
1938 // FIXME: Fix touch adjustment to avoid the need for a redundant hit test. h ttp://crbug.com/398914
1939 if (shouldApplyTouchAdjustment(gestureEvent)) {
1940 LocalFrame* hitFrame = hitTestResult.innerNodeFrame();
1941 if (!hitFrame)
1942 hitFrame = m_frame;
1943 hitTestResult = hitTestResultInFrame(hitFrame, adjustedEvent.position(), hitType | HitTestRequest::ReadOnly);
1944 }
1945
1946 // Now apply hover/active state to the final target. 1899 // Now apply hover/active state to the final target.
1947 // FIXME: This is supposed to send mouseenter/mouseleave events, but doesn't because we 1900 // FIXME: This is supposed to send mouseenter/mouseleave events, but doesn't because we
1948 // aren't passing a PlatformMouseEvent. 1901 // aren't passing a PlatformMouseEvent.
1949 HitTestRequest request(hitType | HitTestRequest::AllowChildFrameContent); 1902 HitTestRequest request(hitType | HitTestRequest::AllowChildFrameContent);
1950 if (!request.readOnly()) 1903 if (!request.readOnly())
1951 m_frame->document()->updateHoverActiveState(request, hitTestResult.inner Element()); 1904 m_frame->document()->updateHoverActiveState(request, hitTestResult.inner Element());
1952 1905
1953 if (shouldKeepActiveForMinInterval) { 1906 if (shouldKeepActiveForMinInterval) {
1954 m_lastDeferredTapElement = hitTestResult.innerElement(); 1907 m_lastDeferredTapElement = hitTestResult.innerElement();
1955 m_activeIntervalTimer.startOneShot(minimumActiveInterval - activeInterva l, FROM_HERE); 1908 m_activeIntervalTimer.startOneShot(minimumActiveInterval - activeInterva l, FROM_HERE);
1956 } 1909 }
1957 1910
1958 return GestureEventWithHitTestResults(adjustedEvent, hitTestResult); 1911 return GestureEventWithHitTestResults(gestureEvent, hitTestResult);
1959 } 1912 }
1960 1913
1961 HitTestRequest::HitTestRequestType EventHandler::getHitTypeForGestureType(Platfo rmEvent::Type type) 1914 HitTestRequest::HitTestRequestType EventHandler::getHitTypeForGestureType(Platfo rmEvent::Type type)
1962 { 1915 {
1963 HitTestRequest::HitTestRequestType hitType = HitTestRequest::TouchEvent | Hi tTestRequest::AllowFrameScrollbars; 1916 HitTestRequest::HitTestRequestType hitType = HitTestRequest::TouchEvent | Hi tTestRequest::AllowFrameScrollbars;
1964 switch (type) { 1917 switch (type) {
1965 case PlatformEvent::GestureShowPress: 1918 case PlatformEvent::GestureShowPress:
1966 case PlatformEvent::GestureTapUnconfirmed: 1919 case PlatformEvent::GestureTapUnconfirmed:
1967 return hitType | HitTestRequest::Active; 1920 return hitType | HitTestRequest::Active;
1968 case PlatformEvent::GestureTapDownCancel: 1921 case PlatformEvent::GestureTapDownCancel:
1969 // A TapDownCancel received when no element is active shouldn't really b e changing hover state. 1922 // A TapDownCancel received when no element is active shouldn't really b e changing hover state.
1970 if (!m_frame->document()->activeHoverElement()) 1923 if (!m_frame->document()->activeHoverElement())
1971 hitType |= HitTestRequest::ReadOnly; 1924 hitType |= HitTestRequest::ReadOnly;
1972 return hitType | HitTestRequest::Release; 1925 return hitType | HitTestRequest::Release;
1973 case PlatformEvent::GestureTap: 1926 case PlatformEvent::GestureTap:
1974 return hitType | HitTestRequest::Release; 1927 return hitType | HitTestRequest::Release;
1975 case PlatformEvent::GestureTapDown: 1928 case PlatformEvent::GestureTapDown:
1976 case PlatformEvent::GestureLongPress: 1929 case PlatformEvent::GestureLongPress:
1977 case PlatformEvent::GestureLongTap: 1930 case PlatformEvent::GestureLongTap:
1978 case PlatformEvent::GestureTwoFingerTap: 1931 case PlatformEvent::GestureTwoFingerTap:
1979 // FIXME: Shouldn't LongTap and TwoFingerTap clear the Active state? 1932 // FIXME: Shouldn't LongTap and TwoFingerTap clear the Active state?
1980 return hitType | HitTestRequest::Active | HitTestRequest::ReadOnly; 1933 return hitType | HitTestRequest::Active | HitTestRequest::ReadOnly;
1981 default: 1934 default:
1982 ASSERT_NOT_REACHED(); 1935 ASSERT_NOT_REACHED();
1983 return hitType | HitTestRequest::Active | HitTestRequest::ReadOnly; 1936 return hitType | HitTestRequest::Active | HitTestRequest::ReadOnly;
1984 } 1937 }
1985 } 1938 }
1986 1939
1987 void EventHandler::applyTouchAdjustment(PlatformGestureEvent* gestureEvent, HitT estResult* hitTestResult)
1988 {
1989 if (!shouldApplyTouchAdjustment(*gestureEvent))
1990 return;
1991
1992 Node* adjustedNode = 0;
1993 IntPoint adjustedPoint = gestureEvent->position();
1994 IntSize radius = gestureEvent->area();
1995 radius.scale(1.f / 2);
1996 bool adjusted = false;
1997 switch (gestureEvent->type()) {
1998 case PlatformEvent::GestureTap:
1999 case PlatformEvent::GestureTapUnconfirmed:
2000 case PlatformEvent::GestureTapDown:
2001 case PlatformEvent::GestureShowPress:
2002 case PlatformEvent::GestureLongPress:
2003 case PlatformEvent::GestureLongTap:
2004 case PlatformEvent::GestureTwoFingerTap:
2005 adjusted = bestClickableNodeForHitTestResult(*hitTestResult, adjustedPoi nt, adjustedNode);
2006 break;
2007 default:
2008 ASSERT_NOT_REACHED();
2009 }
2010
2011 // Update the hit-test result to be a point-based result instead of a rect-b ased result.
2012 // FIXME: We should do this even when no candidate matches the node filter. crbug.com/398914
2013 if (adjusted) {
2014 hitTestResult->resolveRectBasedTest(adjustedNode, adjustedPoint);
2015 gestureEvent->applyTouchAdjustment(adjustedPoint);
2016 }
2017 }
2018
2019 void EventHandler::scheduleHoverStateUpdate() 1940 void EventHandler::scheduleHoverStateUpdate()
2020 { 1941 {
2021 if (!m_hoverTimer.isActive()) 1942 if (!m_hoverTimer.isActive())
2022 m_hoverTimer.startOneShot(0, FROM_HERE); 1943 m_hoverTimer.startOneShot(0, FROM_HERE);
2023 } 1944 }
2024 1945
2025 void EventHandler::scheduleCursorUpdate() 1946 void EventHandler::scheduleCursorUpdate()
2026 { 1947 {
2027 if (!m_cursorUpdateTimer.isActive()) 1948 if (!m_cursorUpdateTimer.isActive())
2028 m_cursorUpdateTimer.startOneShot(cursorUpdateInterval, FROM_HERE); 1949 m_cursorUpdateTimer.startOneShot(cursorUpdateInterval, FROM_HERE);
(...skipping 661 matching lines...) Expand 10 before | Expand all | Expand 10 after
2690 unsigned EventHandler::accessKeyModifiers() 2611 unsigned EventHandler::accessKeyModifiers()
2691 { 2612 {
2692 #if OS(MACOSX) 2613 #if OS(MACOSX)
2693 return PlatformEvent::CtrlKey | PlatformEvent::AltKey; 2614 return PlatformEvent::CtrlKey | PlatformEvent::AltKey;
2694 #else 2615 #else
2695 return PlatformEvent::AltKey; 2616 return PlatformEvent::AltKey;
2696 #endif 2617 #endif
2697 } 2618 }
2698 2619
2699 } // namespace blink 2620 } // namespace blink
OLDNEW
« no previous file with comments | « sky/engine/core/page/EventHandler.h ('k') | sky/engine/core/page/TouchAdjustment.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698