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, 2005, 2006, 2008 Apple Inc. All rights reserved.
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.
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.
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.
24 #include "MouseEvent.h"
27 #include "FrameView.h"
28 #include "EventNames.h"
29 #include "PlatformMouseEvent.h"
33 PassRefPtr<MouseEvent> MouseEvent::create(const AtomicString& eventType, PassRefPtr<AbstractView> view, const PlatformMouseEvent& event, const IntPoint& position, int detail, PassRefPtr<Node> relatedTarget)
35 bool isCancelable = eventType != eventNames().mousemoveEvent;
37 return MouseEvent::create(eventType, true, isCancelable, view,
38 detail, event.globalX(), event.globalY(), position.x(), position.y(),
39 event.ctrlKey(), event.altKey(), event.shiftKey(), event.metaKey(), event.button(),
40 relatedTarget, 0, false);
43 MouseEvent::MouseEvent()
49 MouseEvent::MouseEvent(const AtomicString& eventType, bool canBubble, bool cancelable, PassRefPtr<AbstractView> view,
50 int detail, int screenX, int screenY, int pageX, int pageY,
51 bool ctrlKey, bool altKey, bool shiftKey, bool metaKey,
52 unsigned short button, PassRefPtr<EventTarget> relatedTarget,
53 PassRefPtr<Clipboard> clipboard, bool isSimulated)
54 : MouseRelatedEvent(eventType, canBubble, cancelable, view, detail, screenX, screenY,
55 pageX, pageY, ctrlKey, altKey, shiftKey, metaKey, isSimulated)
56 , m_button(button == (unsigned short)-1 ? 0 : button)
57 , m_buttonDown(button != (unsigned short)-1)
58 , m_relatedTarget(relatedTarget)
59 , m_clipboard(clipboard)
63 MouseEvent::~MouseEvent()
67 void MouseEvent::initMouseEvent(const AtomicString& type, bool canBubble, bool cancelable, PassRefPtr<AbstractView> view,
68 int detail, int screenX, int screenY, int clientX, int clientY,
69 bool ctrlKey, bool altKey, bool shiftKey, bool metaKey,
70 unsigned short button, PassRefPtr<EventTarget> relatedTarget)
75 initUIEvent(type, canBubble, cancelable, view, detail);
81 m_shiftKey = shiftKey;
83 m_button = button == (unsigned short)-1 ? 0 : button;
84 m_buttonDown = button != (unsigned short)-1;
85 m_relatedTarget = relatedTarget;
87 initCoordinates(clientX, clientY);
89 // FIXME: m_isSimulated is not set to false here.
90 // FIXME: m_clipboard is not set to 0 here.
93 bool MouseEvent::isMouseEvent() const
98 bool MouseEvent::isDragEvent() const
100 const AtomicString& t = type();
101 return t == eventNames().dragenterEvent || t == eventNames().dragoverEvent || t == eventNames().dragleaveEvent || t == eventNames().dropEvent
102 || t == eventNames().dragstartEvent|| t == eventNames().dragEvent || t == eventNames().dragendEvent;
105 int MouseEvent::which() const
107 // For the DOM, the return values for left, middle and right mouse buttons are 0, 1, 2, respectively.
108 // For the Netscape "which" property, the return values for left, middle and right mouse buttons are 1, 2, 3, respectively.
113 Node* MouseEvent::toElement() const
115 // MSIE extension - "the object toward which the user is moving the mouse pointer"
116 if (type() == eventNames().mouseoutEvent)
117 return relatedTarget() ? relatedTarget()->toNode() : 0;
119 return target() ? target()->toNode() : 0;
122 Node* MouseEvent::fromElement() const
124 // MSIE extension - "object from which activation or the mouse pointer is exiting during the event" (huh?)
125 if (type() != eventNames().mouseoutEvent)
126 return relatedTarget() ? relatedTarget()->toNode() : 0;
128 return target() ? target()->toNode() : 0;
131 PassRefPtr<SimulatedMouseEvent> SimulatedMouseEvent::create(const AtomicString& eventType, PassRefPtr<AbstractView> view, PassRefPtr<Event> underlyingEvent)
133 return adoptRef(new SimulatedMouseEvent(eventType, view, underlyingEvent));
136 SimulatedMouseEvent::~SimulatedMouseEvent()
140 SimulatedMouseEvent::SimulatedMouseEvent(const AtomicString& eventType, PassRefPtr<AbstractView> view, PassRefPtr<Event> underlyingEvent)
141 : MouseEvent(eventType, true, true, view, 0, 0, 0, 0, 0, false, false, false, false, 0, 0, 0, true)
143 if (UIEventWithKeyState* keyStateEvent = findEventWithKeyState(underlyingEvent.get())) {
144 m_ctrlKey = keyStateEvent->ctrlKey();
145 m_altKey = keyStateEvent->altKey();
146 m_shiftKey = keyStateEvent->shiftKey();
147 m_metaKey = keyStateEvent->metaKey();
149 setUnderlyingEvent(underlyingEvent);
152 } // namespace WebCore