2008-11-04 Anders Carlsson <andersca@apple.com>
[webkit/qt.git] / WebCore / dom / MouseEvent.cpp
blob1c975228f0621de101ec86d7816cf83fb3e99fe7
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, 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.
23 #include "config.h"
24 #include "MouseEvent.h"
26 #include "EventNames.h"
28 namespace WebCore {
30 MouseEvent::MouseEvent()
31 : m_button(0)
32 , m_buttonDown(false)
36 MouseEvent::MouseEvent(const AtomicString& eventType, bool canBubble, bool cancelable, PassRefPtr<AbstractView> view,
37 int detail, int screenX, int screenY, int pageX, int pageY,
38 bool ctrlKey, bool altKey, bool shiftKey, bool metaKey,
39 unsigned short button, PassRefPtr<EventTargetNode> relatedTarget,
40 PassRefPtr<Clipboard> clipboard, bool isSimulated)
41 : MouseRelatedEvent(eventType, canBubble, cancelable, view, detail, screenX, screenY,
42 pageX, pageY, ctrlKey, altKey, shiftKey, metaKey, isSimulated)
43 , m_button(button == (unsigned short)-1 ? 0 : button)
44 , m_buttonDown(button != (unsigned short)-1)
45 , m_relatedTarget(relatedTarget)
46 , m_clipboard(clipboard)
50 MouseEvent::~MouseEvent()
54 void MouseEvent::initMouseEvent(const AtomicString& type, bool canBubble, bool cancelable, PassRefPtr<AbstractView> view,
55 int detail, int screenX, int screenY, int clientX, int clientY,
56 bool ctrlKey, bool altKey, bool shiftKey, bool metaKey,
57 unsigned short button, PassRefPtr<EventTargetNode> relatedTarget)
59 if (dispatched())
60 return;
62 initUIEvent(type, canBubble, cancelable, view, detail);
64 m_screenX = screenX;
65 m_screenY = screenY;
66 m_ctrlKey = ctrlKey;
67 m_altKey = altKey;
68 m_shiftKey = shiftKey;
69 m_metaKey = metaKey;
70 m_button = button == (unsigned short)-1 ? 0 : button;
71 m_buttonDown = button != (unsigned short)-1;
72 m_relatedTarget = relatedTarget;
74 initCoordinates(clientX, clientY);
76 // FIXME: m_isSimulated is not set to false here.
77 // FIXME: m_clipboard is not set to 0 here.
80 bool MouseEvent::isMouseEvent() const
82 return true;
85 bool MouseEvent::isDragEvent() const
87 const AtomicString& t = type();
88 return t == eventNames().dragenterEvent || t == eventNames().dragoverEvent || t == eventNames().dragleaveEvent || t == eventNames().dropEvent
89 || t == eventNames().dragstartEvent|| t == eventNames().dragEvent || t == eventNames().dragendEvent;
92 int MouseEvent::which() const
94 // For the DOM, the return values for left, middle and right mouse buttons are 0, 1, 2, respectively.
95 // For the Netscape "which" property, the return values for left, middle and right mouse buttons are 1, 2, 3, respectively.
96 // So we must add 1.
97 return m_button + 1;
100 Node* MouseEvent::toElement() const
102 // MSIE extension - "the object toward which the user is moving the mouse pointer"
103 if (type() == eventNames().mouseoutEvent)
104 return relatedTarget();
106 return target() ? target()->toNode() : 0;
109 Node* MouseEvent::fromElement() const
111 // MSIE extension - "object from which activation or the mouse pointer is exiting during the event" (huh?)
112 if (type() != eventNames().mouseoutEvent)
113 return relatedTarget();
115 return target() ? target()->toNode() : 0;
118 } // namespace WebCore