• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2004, 2005, 2006, 2009 Apple Inc. All rights reserved.
3  *
4  * Redistribution and use in source and binary forms, with or without
5  * modification, are permitted provided that the following conditions
6  * are met:
7  * 1. Redistributions of source code must retain the above copyright
8  *    notice, this list of conditions and the following disclaimer.
9  * 2. Redistributions in binary form must reproduce the above copyright
10  *    notice, this list of conditions and the following disclaimer in the
11  *    documentation and/or other materials provided with the distribution.
12  *
13  * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
14  * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL APPLE COMPUTER, INC. OR
17  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
18  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
19  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
20  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
21  * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
23  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
24  */
25 
26 #ifndef PlatformMouseEvent_h
27 #define PlatformMouseEvent_h
28 
29 #include "platform/PlatformEvent.h"
30 #include "platform/geometry/IntPoint.h"
31 
32 namespace WebCore {
33 
34 // These button numbers match the ones used in the DOM API, 0 through 2, except for NoButton which isn't specified.
35 enum MouseButton { NoButton = -1, LeftButton, MiddleButton, RightButton };
36 
37 class PlatformMouseEvent : public PlatformEvent {
38 public:
39     enum SyntheticEventType {
40         NotFromTouch,
41         FromTouch,
42     };
43 
PlatformMouseEvent()44     PlatformMouseEvent()
45         : PlatformEvent(PlatformEvent::MouseMoved)
46         , m_button(NoButton)
47         , m_clickCount(0)
48         , m_synthesized(NotFromTouch)
49         , m_modifierFlags(0)
50     {
51     }
52 
PlatformMouseEvent(const IntPoint & position,const IntPoint & globalPosition,MouseButton button,PlatformEvent::Type type,int clickCount,Modifiers modifiers,double timestamp)53     PlatformMouseEvent(const IntPoint& position, const IntPoint& globalPosition, MouseButton button, PlatformEvent::Type type, int clickCount, Modifiers modifiers, double timestamp)
54         : PlatformEvent(type, modifiers, timestamp)
55         , m_position(position)
56         , m_globalPosition(globalPosition)
57         , m_button(button)
58         , m_clickCount(clickCount)
59         , m_synthesized(NotFromTouch)
60         , m_modifierFlags(0)
61     {
62     }
63 
PlatformMouseEvent(const IntPoint & position,const IntPoint & globalPosition,MouseButton button,PlatformEvent::Type type,int clickCount,Modifiers modifiers,SyntheticEventType synthesized,double timestamp)64     PlatformMouseEvent(const IntPoint& position, const IntPoint& globalPosition, MouseButton button, PlatformEvent::Type type, int clickCount, Modifiers modifiers, SyntheticEventType synthesized, double timestamp)
65         : PlatformEvent(type, modifiers, timestamp)
66         , m_position(position)
67         , m_globalPosition(globalPosition)
68         , m_button(button)
69         , m_clickCount(clickCount)
70         , m_synthesized(synthesized)
71         , m_modifierFlags(0)
72     {
73     }
74 
PlatformMouseEvent(const IntPoint & position,const IntPoint & globalPosition,MouseButton button,PlatformEvent::Type type,int clickCount,bool shiftKey,bool ctrlKey,bool altKey,bool metaKey,double timestamp)75     PlatformMouseEvent(const IntPoint& position, const IntPoint& globalPosition, MouseButton button, PlatformEvent::Type type, int clickCount, bool shiftKey, bool ctrlKey, bool altKey, bool metaKey, double timestamp)
76         : PlatformEvent(type, shiftKey, ctrlKey, altKey, metaKey, timestamp)
77         , m_position(position)
78         , m_globalPosition(globalPosition)
79         , m_button(button)
80         , m_clickCount(clickCount)
81         , m_synthesized(NotFromTouch)
82         , m_modifierFlags(0)
83     {
84     }
85 
position()86     const IntPoint& position() const { return m_position; }
globalPosition()87     const IntPoint& globalPosition() const { return m_globalPosition; }
movementDelta()88     const IntPoint& movementDelta() const { return m_movementDelta; }
89 
button()90     MouseButton button() const { return m_button; }
clickCount()91     int clickCount() const { return m_clickCount; }
modifierFlags()92     unsigned modifierFlags() const { return m_modifierFlags; }
fromTouch()93     bool fromTouch() const { return m_synthesized == FromTouch; }
94 
95 protected:
96     IntPoint m_position;
97     IntPoint m_globalPosition;
98     IntPoint m_movementDelta;
99     MouseButton m_button;
100     int m_clickCount;
101     SyntheticEventType m_synthesized;
102     unsigned m_modifierFlags;
103 };
104 
105 } // namespace WebCore
106 
107 #endif // PlatformMouseEvent_h
108