1 /* 2 * Copyright (C) 2001 Peter Kelly (pmk (at) post.com) 3 * Copyright (C) 2001 Tobias Anton (anton (at) stud.fbi.fh-darmstadt.de) 4 * Copyright (C) 2006 Samuel Weinig (sam.weinig (at) 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 "MouseRelatedEvent.h" 29 30 namespace WebCore { 31 32 class EventDispatcher; 33 class PlatformMouseEvent; 34 35 // Introduced in DOM Level 2 36 class MouseEvent : public MouseRelatedEvent { 37 public: 38 static PassRefPtr<MouseEvent> create() 39 { 40 return adoptRef(new MouseEvent); 41 } 42 static PassRefPtr<MouseEvent> create(const AtomicString& type, bool canBubble, bool cancelable, PassRefPtr<AbstractView> view, 43 int detail, int screenX, int screenY, int pageX, int pageY, 44 bool ctrlKey, bool altKey, bool shiftKey, bool metaKey, unsigned short button, 45 PassRefPtr<EventTarget> relatedTarget, PassRefPtr<Clipboard> clipboard = 0, bool isSimulated = false) 46 { 47 return adoptRef(new MouseEvent(type, canBubble, cancelable, view, detail, screenX, screenY, pageX, pageY, 48 ctrlKey, altKey, shiftKey, metaKey, button, relatedTarget, clipboard, isSimulated)); 49 } 50 static PassRefPtr<MouseEvent> create(const AtomicString& eventType, PassRefPtr<AbstractView>, const PlatformMouseEvent&, int detail, PassRefPtr<Node> relatedTarget); 51 52 virtual ~MouseEvent(); 53 54 void initMouseEvent(const AtomicString& type, bool canBubble, bool cancelable, PassRefPtr<AbstractView>, 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<EventTarget> relatedTarget); 58 59 // WinIE uses 1,4,2 for left/middle/right but not for click (just for mousedown/up, maybe others), 60 // but we will match the standard DOM. 61 unsigned short button() const { return m_button; } 62 bool buttonDown() const { return m_buttonDown; } 63 EventTarget* relatedTarget() const { return m_relatedTarget.get(); } 64 void setRelatedTarget(PassRefPtr<EventTarget> relatedTarget) { m_relatedTarget = relatedTarget; } 65 66 Clipboard* clipboard() const { return m_clipboard.get(); } 67 68 Node* toElement() const; 69 Node* fromElement() const; 70 71 Clipboard* dataTransfer() const { return isDragEvent() ? m_clipboard.get() : 0; } 72 73 virtual bool isMouseEvent() const; 74 virtual bool isDragEvent() const; 75 virtual int which() const; 76 77 protected: 78 MouseEvent(const AtomicString& type, bool canBubble, bool cancelable, PassRefPtr<AbstractView>, 79 int detail, int screenX, int screenY, int pageX, int pageY, 80 bool ctrlKey, bool altKey, bool shiftKey, bool metaKey, unsigned short button, 81 PassRefPtr<EventTarget> relatedTarget, PassRefPtr<Clipboard> clipboard, bool isSimulated); 82 83 private: 84 MouseEvent(); 85 86 unsigned short m_button; 87 bool m_buttonDown; 88 RefPtr<EventTarget> m_relatedTarget; 89 RefPtr<Clipboard> m_clipboard; 90 }; 91 92 class SimulatedMouseEvent : public MouseEvent { 93 public: 94 static PassRefPtr<SimulatedMouseEvent> create(const AtomicString& eventType, PassRefPtr<AbstractView>, PassRefPtr<Event> underlyingEvent); 95 virtual ~SimulatedMouseEvent(); 96 97 private: 98 SimulatedMouseEvent(const AtomicString& eventType, PassRefPtr<AbstractView>, PassRefPtr<Event> underlyingEvent); 99 }; 100 101 class MouseEventDispatchMediator : public EventDispatchMediator { 102 public: 103 explicit MouseEventDispatchMediator(PassRefPtr<MouseEvent>); 104 105 private: 106 MouseEvent* event() const; 107 108 virtual bool dispatchEvent(EventDispatcher*) const; 109 }; 110 111 } // namespace WebCore 112 113 #endif // MouseEvent_h 114