Update To 11.40.268.0
[platform/framework/web/crosswalk.git] / src / third_party / WebKit / Source / core / page / EventHandler.h
index 7f025b2..5b54c15 100644 (file)
 #include "core/editing/TextGranularity.h"
 #include "core/events/TextEventInputType.h"
 #include "core/page/DragActions.h"
+#include "core/page/EventWithHitTestResults.h"
 #include "core/page/FocusType.h"
 #include "core/rendering/HitTestRequest.h"
 #include "core/rendering/style/RenderStyleConstants.h"
-#include "heap/Handle.h"
 #include "platform/Cursor.h"
 #include "platform/PlatformMouseEvent.h"
 #include "platform/Timer.h"
 #include "platform/UserGestureIndicator.h"
 #include "platform/geometry/LayoutPoint.h"
+#include "platform/heap/Handle.h"
 #include "platform/scroll/ScrollTypes.h"
 #include "wtf/Forward.h"
 #include "wtf/HashMap.h"
+#include "wtf/HashTraits.h"
 #include "wtf/RefPtr.h"
 
-namespace WebCore {
+namespace blink {
 
 class AutoscrollController;
-class Clipboard;
+class DataTransfer;
 class Document;
+class DragState;
 class Element;
 class Event;
 class EventTarget;
+template <typename EventType>
+class EventWithHitTestResults;
 class FloatPoint;
 class FloatQuad;
-class FullscreenElementStack;
-class LocalFrame;
+class Fullscreen;
 class HTMLFrameSetElement;
 class HitTestRequest;
 class HitTestResult;
 class KeyboardEvent;
-class MouseEventWithHitTestResults;
+class LocalFrame;
 class Node;
 class OptionalCursor;
 class PlatformGestureEvent;
@@ -69,26 +73,22 @@ class PlatformWheelEvent;
 class RenderLayer;
 class RenderLayerScrollableArea;
 class RenderObject;
-class RenderWidget;
-class SVGElementInstance;
 class ScrollableArea;
 class Scrollbar;
 class TextEvent;
-class TouchEvent;
 class VisibleSelection;
 class WheelEvent;
 class Widget;
 
-class DragState;
-
 enum AppendTrailingWhitespace { ShouldAppendTrailingWhitespace, DontAppendTrailingWhitespace };
 enum CheckDragHysteresis { ShouldCheckDragHysteresis, DontCheckDragHysteresis };
 
-class EventHandler {
+class EventHandler : public NoBaseWillBeGarbageCollectedFinalized<EventHandler> {
     WTF_MAKE_NONCOPYABLE(EventHandler);
 public:
     explicit EventHandler(LocalFrame*);
     ~EventHandler();
+    void trace(Visitor*);
 
     void clear();
     void nodeWillBeRemoved(Node&);
@@ -113,11 +113,11 @@ public:
     bool mousePressed() const { return m_mousePressed; }
     void setMousePressed(bool pressed) { m_mousePressed = pressed; }
 
-    void setCapturingMouseEventsNode(PassRefPtr<Node>); // A caller is responsible for resetting capturing node to 0.
+    void setCapturingMouseEventsNode(PassRefPtrWillBeRawPtr<Node>); // A caller is responsible for resetting capturing node to 0.
 
-    bool updateDragAndDrop(const PlatformMouseEvent&, Clipboard*);
-    void cancelDragAndDrop(const PlatformMouseEvent&, Clipboard*);
-    bool performDragAndDrop(const PlatformMouseEvent&, Clipboard*);
+    bool updateDragAndDrop(const PlatformMouseEvent&, DataTransfer*);
+    void cancelDragAndDrop(const PlatformMouseEvent&, DataTransfer*);
+    bool performDragAndDrop(const PlatformMouseEvent&, DataTransfer*);
     void updateDragStateAfterEditDragIfNeeded(Element* rootEditableElement);
 
     void scheduleHoverStateUpdate();
@@ -132,7 +132,7 @@ public:
 
     // Attempts to scroll the DOM tree. If that fails, scrolls the view.
     // If the view can't be scrolled either, recursively bubble to the parent frame.
-    bool bubblingScroll(ScrollDirection, ScrollGranularity, Node* startingNode = 0);
+    bool bubblingScroll(ScrollDirection, ScrollGranularity, Node* startingNode = nullptr);
 
     bool handleMouseMoveEvent(const PlatformMouseEvent&);
     void handleMouseLeaveEvent(const PlatformMouseEvent&);
@@ -142,19 +142,33 @@ public:
     bool handleWheelEvent(const PlatformWheelEvent&);
     void defaultWheelEventHandler(Node*, WheelEvent*);
 
+    // Called on the local root frame exactly once per gesture event.
     bool handleGestureEvent(const PlatformGestureEvent&);
+    bool handleGestureEvent(const GestureEventWithHitTestResults&);
+
+    // Hit-test the provided (non-scroll) gesture event, applying touch-adjustment and updating
+    // hover/active state across all frames if necessary. This should be called at most once
+    // per gesture event, and called on the local root frame.
+    // Note: This is similar to (the less clearly named) prepareMouseEvent.
+    // FIXME: Remove readOnly param when there is only ever a single call to this.
+    GestureEventWithHitTestResults targetGestureEvent(const PlatformGestureEvent&, bool readOnly = false);
+
+    // Handle the provided non-scroll gesture event. Should be called only on the inner frame.
+    bool handleGestureEventInFrame(const GestureEventWithHitTestResults&);
+
+    // Handle the provided scroll gesture event, propagating down to child frames as necessary.
+    bool handleGestureScrollEvent(const PlatformGestureEvent&);
     bool handleGestureScrollEnd(const PlatformGestureEvent&);
     bool isScrollbarHandlingGestures() const;
 
-    bool bestClickableNodeForTouchPoint(const IntPoint& touchCenter, const IntSize& touchRadius, IntPoint& targetPoint, Node*& targetNode);
-    bool bestContextMenuNodeForTouchPoint(const IntPoint& touchCenter, const IntSize& touchRadius, IntPoint& targetPoint, Node*& targetNode);
+    bool bestClickableNodeForHitTestResult(const HitTestResult&, IntPoint& targetPoint, Node*& targetNode);
+    bool bestContextMenuNodeForHitTestResult(const HitTestResult&, IntPoint& targetPoint, Node*& targetNode);
+    // FIXME: This doesn't appear to be used outside tests anymore, what path are we using now and is it tested?
     bool bestZoomableAreaForTouchPoint(const IntPoint& touchCenter, const IntSize& touchRadius, IntRect& targetArea, Node*& targetNode);
 
-    void adjustGesturePosition(const PlatformGestureEvent&, IntPoint& adjustedPoint);
-
     bool sendContextMenuEvent(const PlatformMouseEvent&);
     bool sendContextMenuEventForKey();
-    bool sendContextMenuEventForGesture(const PlatformGestureEvent&);
+    bool sendContextMenuEventForGesture(const GestureEventWithHitTestResults&);
 
     void setMouseDownMayStartAutoscroll() { m_mouseDownMayStartAutoscroll = true; }
 
@@ -163,7 +177,7 @@ public:
     bool keyEvent(const PlatformKeyboardEvent&);
     void defaultKeyboardEventHandler(KeyboardEvent*);
 
-    bool handleTextInputEvent(const String& text, Event* underlyingEvent = 0, TextEventInputType = TextEventInputKeyboard);
+    bool handleTextInputEvent(const String& text, Event* underlyingEvent = nullptr, TextEventInputType = TextEventInputKeyboard);
     void defaultTextInputEventHandler(TextEvent*);
 
     void dragSourceEndedAt(const PlatformMouseEvent&, DragOperation);
@@ -174,14 +188,20 @@ public:
 
     bool handleTouchEvent(const PlatformTouchEvent&);
 
-    bool useHandCursor(Node*, bool isOverLink, bool shiftKey);
+    bool useHandCursor(Node*, bool isOverLink);
 
     void notifyElementActivated();
+    void notifySelectionChanged();
+
+    PassRefPtr<UserGestureToken> takeLastMouseDownGestureToken() { return m_lastMouseDownUserGestureToken.release(); }
+
+    int clickCount() { return m_clickCount; }
+    bool mouseDownWasSingleClickInSelection() { return m_mouseDownWasSingleClickInSelection; }
 
 private:
     static DragState& dragState();
 
-    PassRefPtrWillBeRawPtr<Clipboard> createDraggingClipboard() const;
+    PassRefPtrWillBeRawPtr<DataTransfer> createDraggingDataTransfer() const;
 
     bool updateSelectionForMouseDownDispatchingSelectStart(Node*, const VisibleSelection&, TextGranularity);
     void selectClosestWordFromHitTestResult(const HitTestResult&, AppendTrailingWhitespace);
@@ -190,34 +210,35 @@ private:
     void selectClosestMisspellingFromMouseEvent(const MouseEventWithHitTestResults&);
     void selectClosestWordOrLinkFromMouseEvent(const MouseEventWithHitTestResults&);
 
-    bool handleMouseMoveOrLeaveEvent(const PlatformMouseEvent&, HitTestResult* hoveredNode = 0, bool onlyUpdateScrollbars = false);
+    bool handleMouseMoveOrLeaveEvent(const PlatformMouseEvent&, HitTestResult* hoveredNode = nullptr, bool onlyUpdateScrollbars = false);
     bool handleMousePressEvent(const MouseEventWithHitTestResults&);
     bool handleMousePressEventSingleClick(const MouseEventWithHitTestResults&);
     bool handleMousePressEventDoubleClick(const MouseEventWithHitTestResults&);
     bool handleMousePressEventTripleClick(const MouseEventWithHitTestResults&);
+    bool handleMouseFocus(const MouseEventWithHitTestResults&);
     bool handleMouseDraggedEvent(const MouseEventWithHitTestResults&);
     bool handleMouseReleaseEvent(const MouseEventWithHitTestResults&);
 
     bool handlePasteGlobalSelection(const PlatformMouseEvent&);
 
-    bool handleGestureTap(const PlatformGestureEvent&, const IntPoint& adjustedPoint);
-    bool handleGestureLongPress(const PlatformGestureEvent&, const IntPoint& adjustedPoint);
-    bool handleGestureLongTap(const PlatformGestureEvent&, const IntPoint& adjustedPoint);
-    bool handleGestureTwoFingerTap(const PlatformGestureEvent&, const IntPoint& adjustedPoint);
+    HitTestRequest::HitTestRequestType getHitTypeForGestureType(PlatformEvent::Type);
+    void applyTouchAdjustment(PlatformGestureEvent*, HitTestResult*);
+    bool handleGestureTap(const GestureEventWithHitTestResults&);
+    bool handleGestureLongPress(const GestureEventWithHitTestResults&);
+    bool handleGestureLongTap(const GestureEventWithHitTestResults&);
     bool handleGestureScrollUpdate(const PlatformGestureEvent&);
     bool handleGestureScrollBegin(const PlatformGestureEvent&);
     void clearGestureScrollNodes();
 
     bool shouldApplyTouchAdjustment(const PlatformGestureEvent&) const;
 
-    OptionalCursor selectCursor(const HitTestResult&, bool shiftKey);
-    OptionalCursor selectAutoCursor(const HitTestResult&, Node*, const Cursor& iBeam, bool shiftKey);
+    OptionalCursor selectCursor(const HitTestResult&);
+    OptionalCursor selectAutoCursor(const HitTestResult&, Node*, const Cursor& iBeam);
 
     void hoverTimerFired(Timer<EventHandler>*);
     void cursorUpdateTimerFired(Timer<EventHandler>*);
     void activeIntervalTimerFired(Timer<EventHandler>*);
 
-    bool shouldTurnVerticalTicksIntoHorizontal(const HitTestResult&, const PlatformWheelEvent&) const;
     bool mouseDownMayStartSelect() const { return m_mouseDownMayStartSelect; }
 
     void fakeMouseMoveEventTimerFired(Timer<EventHandler>*);
@@ -225,8 +246,6 @@ private:
     bool isCursorVisible() const;
     void updateCursor();
 
-    bool isInsideScrollbar(const IntPoint&) const;
-
     ScrollableArea* associatedScrollableArea(const RenderLayer*) const;
 
     // Scrolls the elements of the DOM tree. Returns true if a node was scrolled.
@@ -240,29 +259,23 @@ private:
     //            On output, if provided and a node was scrolled stopNode will point to that node.
     // delta - The delta to scroll by, in the units of the granularity parameter. (e.g. pixels, lines, pages, etc.)
     // absolutePoint - For wheel scrolls - the location, in absolute coordinates, where the event occured.
-    bool scroll(ScrollDirection, ScrollGranularity, Node* startNode = 0, Node** stopNode = 0, float delta = 1.0f, IntPoint absolutePoint = IntPoint());
-
-    bool dispatchSyntheticTouchEventIfEnabled(const PlatformMouseEvent&);
+    bool scroll(ScrollDirection, ScrollGranularity, Node* startNode = nullptr, Node** stopNode = nullptr, float delta = 1.0f, IntPoint absolutePoint = IntPoint());
 
     TouchAction intersectTouchAction(const TouchAction, const TouchAction);
-    TouchAction computeEffectiveTouchAction(const LayoutPoint&);
+    TouchAction computeEffectiveTouchAction(const Node&);
 
-    bool handleMouseEventAsEmulatedGesture(const PlatformMouseEvent&);
-    bool handleWheelEventAsEmulatedGesture(const PlatformWheelEvent&);
-    HitTestResult hitTestResultInFrame(LocalFrame*, const LayoutPoint&, HitTestRequest::HitTestRequestType hitType = HitTestRequest::ReadOnly | HitTestRequest::Active | HitTestRequest::ConfusingAndOftenMisusedDisallowShadowContent);
+    HitTestResult hitTestResultInFrame(LocalFrame*, const LayoutPoint&, HitTestRequest::HitTestRequestType hitType = HitTestRequest::ReadOnly | HitTestRequest::Active);
 
     void invalidateClick();
 
-    Node* nodeUnderMouse() const;
-
     void updateMouseEventTargetNode(Node*, const PlatformMouseEvent&, bool fireMouseOverOut);
 
     MouseEventWithHitTestResults prepareMouseEvent(const HitTestRequest&, const PlatformMouseEvent&);
 
-    bool dispatchMouseEvent(const AtomicString& eventType, Node* target, bool cancelable, int clickCount, const PlatformMouseEvent&, bool setUnder);
-    bool dispatchDragEvent(const AtomicString& eventType, Node* target, const PlatformMouseEvent&, Clipboard*);
+    bool dispatchMouseEvent(const AtomicString& eventType, Node* target, int clickCount, const PlatformMouseEvent&, bool setUnder);
+    bool dispatchDragEvent(const AtomicString& eventType, Node* target, const PlatformMouseEvent&, DataTransfer*);
 
-    void freeClipboard();
+    void clearDragDataTransfer();
 
     bool handleDrag(const MouseEventWithHitTestResults&, CheckDragHysteresis);
     bool tryStartDrag(const MouseEventWithHitTestResults&);
@@ -274,15 +287,14 @@ private:
     bool dragHysteresisExceeded(const IntPoint&) const;
 
     bool passMousePressEventToSubframe(MouseEventWithHitTestResults&, LocalFrame* subframe);
-    bool passMouseMoveEventToSubframe(MouseEventWithHitTestResults&, LocalFrame* subframe, HitTestResult* hoveredNode = 0);
+    bool passMouseMoveEventToSubframe(MouseEventWithHitTestResults&, LocalFrame* subframe, HitTestResult* hoveredNode = nullptr);
     bool passMouseReleaseEventToSubframe(MouseEventWithHitTestResults&, LocalFrame* subframe);
 
-    bool passMousePressEventToScrollbar(MouseEventWithHitTestResults&, Scrollbar*);
+    bool passMousePressEventToScrollbar(MouseEventWithHitTestResults&);
 
     bool passWidgetMouseDownEventToWidget(const MouseEventWithHitTestResults&);
 
     bool passWheelEventToWidget(const PlatformWheelEvent&, Widget*);
-
     void defaultSpaceEventHandler(KeyboardEvent*);
     void defaultBackspaceEventHandler(KeyboardEvent*);
     void defaultTabEventHandler(KeyboardEvent*);
@@ -297,16 +309,14 @@ private:
 
     bool capturesDragging() const { return m_capturesDragging; }
 
-    bool isKeyEventAllowedInFullScreen(FullscreenElementStack*, const PlatformKeyboardEvent&) const;
+    bool isKeyEventAllowedInFullScreen(Fullscreen*, const PlatformKeyboardEvent&) const;
 
     bool handleGestureShowPress();
 
     bool handleScrollGestureOnResizer(Node*, const PlatformGestureEvent&);
 
-    bool passGestureEventToWidget(const PlatformGestureEvent&, Widget*);
-    bool passGestureEventToWidgetIfPossible(const PlatformGestureEvent&, RenderObject*);
+    bool passScrollGestureEventToWidget(const PlatformGestureEvent&, RenderObject*);
     bool sendScrollEventToView(const PlatformGestureEvent&, const FloatSize&);
-    LocalFrame* getSubFrameForGestureEvent(const IntPoint& touchAdjustedPoint, const PlatformGestureEvent&);
 
     AutoscrollController* autoscrollController() const;
     bool panScrollInProgress() const;
@@ -316,7 +326,7 @@ private:
 
     bool m_mousePressed;
     bool m_capturesDragging;
-    RefPtr<Node> m_mousePressNode;
+    RefPtrWillBeMember<Node> m_mousePressNode;
 
     bool m_mouseDownMayStartSelect;
     bool m_mouseDownMayStartDrag;
@@ -330,32 +340,29 @@ private:
     Timer<EventHandler> m_cursorUpdateTimer;
 
     bool m_mouseDownMayStartAutoscroll;
-    bool m_mouseDownWasInSubframe;
 
     Timer<EventHandler> m_fakeMouseMoveEventTimer;
 
     bool m_svgPan;
-    RefPtr<SVGElementInstance> m_instanceUnderMouse;
-    RefPtr<SVGElementInstance> m_lastInstanceUnderMouse;
 
     RenderLayerScrollableArea* m_resizeScrollableArea;
 
-    RefPtr<Node> m_capturingMouseEventsNode;
+    RefPtrWillBeMember<Node> m_capturingMouseEventsNode;
     bool m_eventHandlerWillResetCapturingMouseEventsNode;
 
-    RefPtr<Node> m_nodeUnderMouse;
-    RefPtr<Node> m_lastNodeUnderMouse;
-    RefPtr<LocalFrame> m_lastMouseMoveEventSubframe;
-    RefPtr<Scrollbar> m_lastScrollbarUnderMouse;
+    RefPtrWillBeMember<Node> m_nodeUnderMouse;
+    RefPtrWillBeMember<Node> m_lastNodeUnderMouse;
+    RefPtrWillBeMember<LocalFrame> m_lastMouseMoveEventSubframe;
+    RefPtrWillBeMember<Scrollbar> m_lastScrollbarUnderMouse;
     Cursor m_currentMouseCursor;
 
     int m_clickCount;
-    RefPtr<Node> m_clickNode;
+    RefPtrWillBeMember<Node> m_clickNode;
 
-    RefPtr<Node> m_dragTarget;
+    RefPtrWillBeMember<Node> m_dragTarget;
     bool m_shouldOnlyFireDragOverEvent;
 
-    RefPtr<HTMLFrameSetElement> m_frameSetBeingResized;
+    RefPtrWillBeMember<HTMLFrameSetElement> m_frameSetBeingResized;
 
     LayoutSize m_offsetFromResizeCorner; // In the coords of m_resizeScrollableArea.
 
@@ -367,37 +374,36 @@ private:
     PlatformMouseEvent m_mouseDown;
     RefPtr<UserGestureToken> m_lastMouseDownUserGestureToken;
 
-    RefPtr<Node> m_latchedWheelEventNode;
+    RefPtrWillBeMember<Node> m_latchedWheelEventNode;
     bool m_widgetIsLatched;
 
-    RefPtr<Node> m_previousWheelScrolledNode;
+    RefPtrWillBeMember<Node> m_previousWheelScrolledNode;
+
+    // The target of each active touch point indexed by the touch ID.
+    using TouchTargetMap = WillBeHeapHashMap<unsigned, RefPtrWillBeMember<EventTarget>, DefaultHash<unsigned>::Hash, WTF::UnsignedWithZeroKeyHashTraits<unsigned>>;
+    TouchTargetMap m_targetForTouchID;
+
+    // If set, the document of the active touch sequence. Unset if no touch sequence active.
+    RefPtrWillBeMember<Document> m_touchSequenceDocument;
+    RefPtr<UserGestureToken> m_touchSequenceUserGestureToken;
 
-    typedef HashMap<int, RefPtr<EventTarget> > TouchTargetMap;
-    TouchTargetMap m_originatingTouchPointTargets;
-    RefPtr<Document> m_originatingTouchPointDocument;
-    unsigned m_originatingTouchPointTargetKey;
     bool m_touchPressed;
 
-    RefPtr<Node> m_scrollGestureHandlingNode;
-    bool m_lastHitTestResultOverWidget;
-    RefPtr<Node> m_previousGestureScrolledNode;
-    RefPtr<Scrollbar> m_scrollbarHandlingScrollGesture;
+    RefPtrWillBeMember<Node> m_scrollGestureHandlingNode;
+    bool m_lastGestureScrollOverWidget;
+    RefPtrWillBeMember<Node> m_previousGestureScrolledNode;
+    RefPtrWillBeMember<Scrollbar> m_scrollbarHandlingScrollGesture;
 
     double m_maxMouseMovedDuration;
-    PlatformEvent::Type m_baseEventType;
     bool m_didStartDrag;
 
     bool m_longTapShouldInvokeContextMenu;
-    OwnPtr<IntPoint> m_lastSyntheticPinchAnchorCss;
-    OwnPtr<IntPoint> m_lastSyntheticPinchAnchorDip;
-    OwnPtr<IntPoint> m_lastSyntheticPanLocation;
-    float m_syntheticPageScaleFactor;
 
     Timer<EventHandler> m_activeIntervalTimer;
     double m_lastShowPressTimestamp;
-    RefPtr<Element> m_lastDeferredTapElement;
+    RefPtrWillBeMember<Element> m_lastDeferredTapElement;
 };
 
-} // namespace WebCore
+} // namespace blink
 
 #endif // EventHandler_h