tizen beta release
[framework/web/webkit-efl.git] / Source / WebCore / dom / MouseEvent.h
1 /*
2  * Copyright (C) 2001 Peter Kelly (pmk@post.com)
3  * Copyright (C) 2001 Tobias Anton (anton@stud.fbi.fh-darmstadt.de)
4  * Copyright (C) 2006 Samuel Weinig (sam.weinig@gmail.com)
5  * Copyright (C) 2003, 2004, 2005, 2006, 2008 Apple Inc. All rights reserved.
6  *
7  * This library is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU Library General Public
9  * License as published by the Free Software Foundation; either
10  * version 2 of the License, or (at your option) any later version.
11  *
12  * This library is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15  * Library General Public License for more details.
16  *
17  * You should have received a copy of the GNU Library General Public License
18  * along with this library; see the file COPYING.LIB.  If not, write to
19  * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
20  * Boston, MA 02110-1301, USA.
21  *
22  */
23
24 #ifndef MouseEvent_h
25 #define MouseEvent_h
26
27 #include "Clipboard.h"
28 #include "EventDispatchMediator.h"
29 #include "MouseRelatedEvent.h"
30
31 namespace WebCore {
32
33 class EventDispatcher;
34 class PlatformMouseEvent;
35
36     // Introduced in DOM Level 2
37     class MouseEvent : public MouseRelatedEvent {
38     public:
39         static PassRefPtr<MouseEvent> create()
40         {
41             return adoptRef(new MouseEvent);
42         }
43         static PassRefPtr<MouseEvent> create(const AtomicString& type, bool canBubble, bool cancelable, PassRefPtr<AbstractView> view,
44             int detail, int screenX, int screenY, int pageX, int pageY,
45 #if ENABLE(POINTER_LOCK)
46             int movementX, int movementY,
47 #endif
48             bool ctrlKey, bool altKey, bool shiftKey, bool metaKey, unsigned short button,
49             PassRefPtr<EventTarget> relatedTarget, PassRefPtr<Clipboard> clipboard = 0, bool isSimulated = false)
50         {
51             return adoptRef(new MouseEvent(type, canBubble, cancelable, view, detail, screenX, screenY, pageX, pageY,
52 #if ENABLE(POINTER_LOCK)
53                 movementX, movementY,
54 #endif
55                 ctrlKey, altKey, shiftKey, metaKey, button, relatedTarget, clipboard, isSimulated));
56         }
57         static PassRefPtr<MouseEvent> create(const AtomicString& eventType, PassRefPtr<AbstractView>, const PlatformMouseEvent&, int detail, PassRefPtr<Node> relatedTarget);
58
59         virtual ~MouseEvent();
60
61         void initMouseEvent(const AtomicString& type, bool canBubble, bool cancelable, PassRefPtr<AbstractView>,
62                             int detail, int screenX, int screenY, int clientX, int clientY,
63                             bool ctrlKey, bool altKey, bool shiftKey, bool metaKey,
64                             unsigned short button, PassRefPtr<EventTarget> relatedTarget);
65
66         // WinIE uses 1,4,2 for left/middle/right but not for click (just for mousedown/up, maybe others),
67         // but we will match the standard DOM.
68         unsigned short button() const { return m_button; }
69         bool buttonDown() const { return m_buttonDown; }
70         EventTarget* relatedTarget() const { return m_relatedTarget.get(); }
71         void setRelatedTarget(PassRefPtr<EventTarget> relatedTarget) { m_relatedTarget = relatedTarget; }
72
73         Clipboard* clipboard() const { return m_clipboard.get(); }
74
75         Node* toElement() const;
76         Node* fromElement() const;
77
78         Clipboard* dataTransfer() const { return isDragEvent() ? m_clipboard.get() : 0; }
79
80         virtual const AtomicString& interfaceName() const;
81
82         virtual bool isMouseEvent() const;
83         virtual bool isDragEvent() const;
84         virtual int which() const;
85
86     protected:
87         MouseEvent(const AtomicString& type, bool canBubble, bool cancelable, PassRefPtr<AbstractView>,
88                    int detail, int screenX, int screenY, int pageX, int pageY,
89 #if ENABLE(POINTER_LOCK)
90                    int movementX, int movementY,
91 #endif
92                    bool ctrlKey, bool altKey, bool shiftKey, bool metaKey, unsigned short button,
93                    PassRefPtr<EventTarget> relatedTarget, PassRefPtr<Clipboard> clipboard, bool isSimulated);
94
95     private:
96         MouseEvent();
97
98         unsigned short m_button;
99         bool m_buttonDown;
100         RefPtr<EventTarget> m_relatedTarget;
101         RefPtr<Clipboard> m_clipboard;
102     };
103
104 class SimulatedMouseEvent : public MouseEvent {
105 public:
106     static PassRefPtr<SimulatedMouseEvent> create(const AtomicString& eventType, PassRefPtr<AbstractView>, PassRefPtr<Event> underlyingEvent);
107     virtual ~SimulatedMouseEvent();
108
109 private:
110     SimulatedMouseEvent(const AtomicString& eventType, PassRefPtr<AbstractView>, PassRefPtr<Event> underlyingEvent);
111 };
112
113 class MouseEventDispatchMediator : public EventDispatchMediator {
114 public:
115     static PassRefPtr<MouseEventDispatchMediator> create(PassRefPtr<MouseEvent>);
116
117 private:
118     explicit MouseEventDispatchMediator(PassRefPtr<MouseEvent>);
119     MouseEvent* event() const;
120
121     virtual bool dispatchEvent(EventDispatcher*) const;
122 };
123
124 } // namespace WebCore
125
126 #endif // MouseEvent_h