src/3rdparty/webkit/WebCore/page/EventHandler.h
changeset 30 5dc02b23752f
parent 0 1918ee327afb
child 33 3e2da88830cd
equal deleted inserted replaced
29:b72c6db6890b 30:5dc02b23752f
     1 /*
     1 /*
     2  * Copyright (C) 2006, 2007, 2009 Apple Inc. All rights reserved.
     2  * Copyright (C) 2006, 2007, 2009, 2010 Apple 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
     5  * modification, are permitted provided that the following conditions
     6  * are met:
     6  * are met:
     7  * 1. Redistributions of source code must retain the above copyright
     7  * 1. Redistributions of source code must retain the above copyright
    25 
    25 
    26 #ifndef EventHandler_h
    26 #ifndef EventHandler_h
    27 #define EventHandler_h
    27 #define EventHandler_h
    28 
    28 
    29 #include "DragActions.h"
    29 #include "DragActions.h"
       
    30 #include "FocusDirection.h"
    30 #include "PlatformMouseEvent.h"
    31 #include "PlatformMouseEvent.h"
    31 #include "ScrollTypes.h"
    32 #include "ScrollTypes.h"
    32 #include "Timer.h"
    33 #include "Timer.h"
    33 #include <wtf/Forward.h>
    34 #include <wtf/Forward.h>
    34 #include <wtf/RefPtr.h>
    35 #include <wtf/RefPtr.h>
    35 
    36 
    36 #if PLATFORM(MAC) && !defined(__OBJC__)
    37 #if PLATFORM(MAC) && !defined(__OBJC__)
    37 class NSView;
    38 class NSView;
    38 #endif
    39 #endif
    39 
    40 
       
    41 #if ENABLE(TOUCH_EVENTS)
       
    42 #include <wtf/HashMap.h>
       
    43 #endif
       
    44 
    40 namespace WebCore {
    45 namespace WebCore {
    41 
    46 
    42 class AtomicString;
    47 class AtomicString;
    43 class Clipboard;
    48 class Clipboard;
    44 class Cursor;
    49 class Cursor;
    45 class Event;
    50 class Event;
       
    51 class EventTarget;
    46 class FloatPoint;
    52 class FloatPoint;
       
    53 class FloatQuad;
    47 class Frame;
    54 class Frame;
    48 class HitTestRequest;
    55 class HitTestRequest;
    49 class HitTestResult;
    56 class HitTestResult;
    50 class HTMLFrameSetElement;
    57 class HTMLFrameSetElement;
    51 class KeyboardEvent;
    58 class KeyboardEvent;
    52 class MouseEventWithHitTestResults;
    59 class MouseEventWithHitTestResults;
    53 class Node;
    60 class Node;
    54 class PlatformKeyboardEvent;
    61 class PlatformKeyboardEvent;
       
    62 class PlatformTouchEvent;
    55 class PlatformWheelEvent;
    63 class PlatformWheelEvent;
    56 class RenderLayer;
    64 class RenderLayer;
    57 class RenderObject;
    65 class RenderObject;
    58 class RenderWidget;
    66 class RenderWidget;
    59 class Scrollbar;
    67 class Scrollbar;
    60 class String;
    68 class String;
    61 class SVGElementInstance;
    69 class SVGElementInstance;
    62 class TextEvent;
    70 class TextEvent;
       
    71 class TouchEvent;
       
    72 class WheelEvent;
    63 class Widget;
    73 class Widget;
    64     
    74     
    65 #if ENABLE(DRAG_SUPPORT)
    75 #if ENABLE(DRAG_SUPPORT)
    66 extern const int LinkDragHysteresis;
    76 extern const int LinkDragHysteresis;
    67 extern const int ImageDragHysteresis;
    77 extern const int ImageDragHysteresis;
    83 #endif
    93 #endif
    84 
    94 
    85     Node* mousePressNode() const;
    95     Node* mousePressNode() const;
    86     void setMousePressNode(PassRefPtr<Node>);
    96     void setMousePressNode(PassRefPtr<Node>);
    87 
    97 
       
    98     void startPanScrolling(RenderObject*);
    88     bool panScrollInProgress() { return m_panScrollInProgress; }
    99     bool panScrollInProgress() { return m_panScrollInProgress; }
    89     void setPanScrollInProgress(bool inProgress) { m_panScrollInProgress = inProgress; }
   100     void setPanScrollInProgress(bool inProgress) { m_panScrollInProgress = inProgress; }
    90 
   101 
    91     void stopAutoscrollTimer(bool rendererIsBeingDestroyed = false);
   102     void stopAutoscrollTimer(bool rendererIsBeingDestroyed = false);
    92     RenderObject* autoscrollRenderer() const;
   103     RenderObject* autoscrollRenderer() const;
    93     void updateAutoscrollRenderer();
   104     void updateAutoscrollRenderer();
       
   105 
       
   106     void dispatchFakeMouseMoveEventSoonInQuad(const FloatQuad&);
    94 
   107 
    95     HitTestResult hitTestResultAtPoint(const IntPoint&, bool allowShadowContent, bool ignoreClipping = false, HitTestScrollbars scrollbars = DontHitTestScrollbars);
   108     HitTestResult hitTestResultAtPoint(const IntPoint&, bool allowShadowContent, bool ignoreClipping = false, HitTestScrollbars scrollbars = DontHitTestScrollbars);
    96 
   109 
    97     bool mousePressed() const { return m_mousePressed; }
   110     bool mousePressed() const { return m_mousePressed; }
    98     void setMousePressed(bool pressed) { m_mousePressed = pressed; }
   111     void setMousePressed(bool pressed) { m_mousePressed = pressed; }
   136 
   149 
   137     bool handleMousePressEvent(const PlatformMouseEvent&);
   150     bool handleMousePressEvent(const PlatformMouseEvent&);
   138     bool handleMouseMoveEvent(const PlatformMouseEvent&, HitTestResult* hoveredNode = 0);
   151     bool handleMouseMoveEvent(const PlatformMouseEvent&, HitTestResult* hoveredNode = 0);
   139     bool handleMouseReleaseEvent(const PlatformMouseEvent&);
   152     bool handleMouseReleaseEvent(const PlatformMouseEvent&);
   140     bool handleWheelEvent(PlatformWheelEvent&);
   153     bool handleWheelEvent(PlatformWheelEvent&);
       
   154     void defaultWheelEventHandler(Node*, WheelEvent*);
   141 
   155 
   142 #if ENABLE(CONTEXT_MENUS)
   156 #if ENABLE(CONTEXT_MENUS)
   143     bool sendContextMenuEvent(const PlatformMouseEvent&);
   157     bool sendContextMenuEvent(const PlatformMouseEvent&);
   144 #endif
   158 #endif
   145 
   159 
   157     void defaultTextInputEventHandler(TextEvent*);
   171     void defaultTextInputEventHandler(TextEvent*);
   158 
   172 
   159 #if ENABLE(DRAG_SUPPORT)
   173 #if ENABLE(DRAG_SUPPORT)
   160     bool eventMayStartDrag(const PlatformMouseEvent&) const;
   174     bool eventMayStartDrag(const PlatformMouseEvent&) const;
   161     
   175     
   162     void dragSourceMovedTo(const PlatformMouseEvent&);
       
   163     void dragSourceEndedAt(const PlatformMouseEvent&, DragOperation);
   176     void dragSourceEndedAt(const PlatformMouseEvent&, DragOperation);
   164 #endif
   177 #endif
   165 
   178 
   166     void focusDocumentView();
   179     void focusDocumentView();
   167 
   180 
   190     void setActivationEventNumber(int num) { m_activationEventNumber = num; }
   203     void setActivationEventNumber(int num) { m_activationEventNumber = num; }
   191 
   204 
   192     static NSEvent *currentNSEvent();
   205     static NSEvent *currentNSEvent();
   193 #endif
   206 #endif
   194 
   207 
       
   208 #if ENABLE(TOUCH_EVENTS)
       
   209     bool handleTouchEvent(const PlatformTouchEvent&);
       
   210 #endif
       
   211 
   195 private:
   212 private:
   196 #if ENABLE(DRAG_SUPPORT)
   213 #if ENABLE(DRAG_SUPPORT)
   197     struct EventHandlerDragState {
   214     enum DragAndDropHandleType {
       
   215         UpdateDragAndDrop,
       
   216         CancelDragAndDrop,
       
   217         PerformDragAndDrop
       
   218     };
       
   219 
       
   220     struct EventHandlerDragState : Noncopyable {
   198         RefPtr<Node> m_dragSrc; // element that may be a drag source, for the current mouse gesture
   221         RefPtr<Node> m_dragSrc; // element that may be a drag source, for the current mouse gesture
   199         bool m_dragSrcIsLink;
   222         bool m_dragSrcIsLink;
   200         bool m_dragSrcIsImage;
   223         bool m_dragSrcIsImage;
   201         bool m_dragSrcInSelection;
   224         bool m_dragSrcInSelection;
   202         bool m_dragSrcMayBeDHTML;
   225         bool m_dragSrcMayBeDHTML;
   204         bool m_dragSrcIsDHTML;
   227         bool m_dragSrcIsDHTML;
   205         RefPtr<Clipboard> m_dragClipboard; // used on only the source side of dragging
   228         RefPtr<Clipboard> m_dragClipboard; // used on only the source side of dragging
   206     };
   229     };
   207     static EventHandlerDragState& dragState();
   230     static EventHandlerDragState& dragState();
   208     static const double TextDragDelay;
   231     static const double TextDragDelay;
       
   232 
       
   233     bool canHandleDragAndDropForTarget(DragAndDropHandleType, Node* target, const PlatformMouseEvent&, Clipboard*, bool* accepted = 0);
   209     
   234     
   210     PassRefPtr<Clipboard> createDraggingClipboard() const;
   235     PassRefPtr<Clipboard> createDraggingClipboard() const;
   211 #endif // ENABLE(DRAG_SUPPORT)
   236 #endif // ENABLE(DRAG_SUPPORT)
   212     
   237     
   213     bool eventActivatedView(const PlatformMouseEvent&) const;
   238     bool eventActivatedView(const PlatformMouseEvent&) const;
   242     void handleAutoscroll(RenderObject*);
   267     void handleAutoscroll(RenderObject*);
   243     void startAutoscrollTimer();
   268     void startAutoscrollTimer();
   244     void setAutoscrollRenderer(RenderObject*);
   269     void setAutoscrollRenderer(RenderObject*);
   245     void autoscrollTimerFired(Timer<EventHandler>*);
   270     void autoscrollTimerFired(Timer<EventHandler>*);
   246 
   271 
       
   272     void fakeMouseMoveEventTimerFired(Timer<EventHandler>*);
       
   273     void cancelFakeMouseMoveEvent();
       
   274 
   247     void invalidateClick();
   275     void invalidateClick();
   248 
   276 
   249     Node* nodeUnderMouse() const;
   277     Node* nodeUnderMouse() const;
   250     
   278     
   251     void updateMouseEventTargetNode(Node*, const PlatformMouseEvent&, bool fireMouseOverOut);
   279     void updateMouseEventTargetNode(Node*, const PlatformMouseEvent&, bool fireMouseOverOut);
   285     bool passMouseDownEventToWidget(Widget*);
   313     bool passMouseDownEventToWidget(Widget*);
   286     bool passWheelEventToWidget(PlatformWheelEvent&, Widget*);
   314     bool passWheelEventToWidget(PlatformWheelEvent&, Widget*);
   287 
   315 
   288     void defaultSpaceEventHandler(KeyboardEvent*);
   316     void defaultSpaceEventHandler(KeyboardEvent*);
   289     void defaultTabEventHandler(KeyboardEvent*);
   317     void defaultTabEventHandler(KeyboardEvent*);
       
   318     void defaultArrowEventHandler(FocusDirection, KeyboardEvent*);
   290 
   319 
   291 #if ENABLE(DRAG_SUPPORT)
   320 #if ENABLE(DRAG_SUPPORT)
   292     void allowDHTMLDrag(bool& flagDHTML, bool& flagUA) const;
   321     void allowDHTMLDrag(bool& flagDHTML, bool& flagUA) const;
   293 #endif
   322 #endif
   294 
   323 
   307 
   336 
   308     void updateLastScrollbarUnderMouse(Scrollbar*, bool);
   337     void updateLastScrollbarUnderMouse(Scrollbar*, bool);
   309     
   338     
   310     void setFrameWasScrolledByUser();
   339     void setFrameWasScrolledByUser();
   311 
   340 
       
   341     FocusDirection focusDirectionForKey(const AtomicString&) const;
       
   342 
   312     bool capturesDragging() const { return m_capturesDragging; }
   343     bool capturesDragging() const { return m_capturesDragging; }
   313 
   344 
   314 #if PLATFORM(MAC) && defined(__OBJC__)
   345 #if PLATFORM(MAC) && defined(__OBJC__) && !ENABLE(EXPERIMENTAL_SINGLE_VIEW_MODE)
   315     NSView *mouseDownViewIfStillGood();
   346     NSView *mouseDownViewIfStillGood();
   316 
   347 
   317     PlatformMouseEvent currentPlatformMouseEvent() const;
   348     PlatformMouseEvent currentPlatformMouseEvent() const;
   318 #endif
   349 #endif
   319 
   350 
   346     RenderObject* m_autoscrollRenderer;
   377     RenderObject* m_autoscrollRenderer;
   347     bool m_autoscrollInProgress;
   378     bool m_autoscrollInProgress;
   348     bool m_mouseDownMayStartAutoscroll;
   379     bool m_mouseDownMayStartAutoscroll;
   349     bool m_mouseDownWasInSubframe;
   380     bool m_mouseDownWasInSubframe;
   350 
   381 
       
   382     Timer<EventHandler> m_fakeMouseMoveEventTimer;
       
   383 
   351 #if ENABLE(SVG)
   384 #if ENABLE(SVG)
   352     bool m_svgPan;
   385     bool m_svgPan;
   353     RefPtr<SVGElementInstance> m_instanceUnderMouse;
   386     RefPtr<SVGElementInstance> m_instanceUnderMouse;
   354     RefPtr<SVGElementInstance> m_lastInstanceUnderMouse;
   387     RefPtr<SVGElementInstance> m_lastInstanceUnderMouse;
   355 #endif
   388 #endif
   366     int m_clickCount;
   399     int m_clickCount;
   367     RefPtr<Node> m_clickNode;
   400     RefPtr<Node> m_clickNode;
   368 
   401 
   369 #if ENABLE(DRAG_SUPPORT)
   402 #if ENABLE(DRAG_SUPPORT)
   370     RefPtr<Node> m_dragTarget;
   403     RefPtr<Node> m_dragTarget;
       
   404     bool m_shouldOnlyFireDragOverEvent;
   371 #endif
   405 #endif
   372     
   406     
   373     RefPtr<HTMLFrameSetElement> m_frameSetBeingResized;
   407     RefPtr<HTMLFrameSetElement> m_frameSetBeingResized;
   374 
   408 
   375     IntSize m_offsetFromResizeCorner;   // in the coords of m_resizeLayer
   409     IntSize m_offsetFromResizeCorner;   // in the coords of m_resizeLayer
   384     bool m_widgetIsLatched;
   418     bool m_widgetIsLatched;
   385 
   419 
   386     RefPtr<Node> m_previousWheelScrolledNode;
   420     RefPtr<Node> m_previousWheelScrolledNode;
   387 
   421 
   388 #if PLATFORM(MAC)
   422 #if PLATFORM(MAC)
       
   423 #if !ENABLE(EXPERIMENTAL_SINGLE_VIEW_MODE)
   389     NSView *m_mouseDownView;
   424     NSView *m_mouseDownView;
   390     bool m_sendingEventToSubview;
   425     bool m_sendingEventToSubview;
       
   426 #endif
   391     int m_activationEventNumber;
   427     int m_activationEventNumber;
   392 #endif
   428 #endif
       
   429 #if ENABLE(TOUCH_EVENTS)
       
   430     typedef HashMap<int, RefPtr<EventTarget> > TouchTargetMap;
       
   431     TouchTargetMap m_originatingTouchPointTargets;
       
   432 #endif
   393 };
   433 };
   394 
   434 
   395 } // namespace WebCore
   435 } // namespace WebCore
   396 
   436 
   397 #endif // EventHandler_h
   437 #endif // EventHandler_h