Home | History | Annotate | Download | only in events
      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 "core/events/EventDispatchMediator.h"
     28 #include "core/events/MouseRelatedEvent.h"
     29 #include "platform/PlatformMouseEvent.h"
     30 
     31 namespace blink {
     32 
     33 class DataTransfer;
     34 class EventDispatcher;
     35 
     36 struct MouseEventInit : public UIEventInit {
     37     MouseEventInit();
     38 
     39     int screenX;
     40     int screenY;
     41     int clientX;
     42     int clientY;
     43     bool ctrlKey;
     44     bool altKey;
     45     bool shiftKey;
     46     bool metaKey;
     47     unsigned short button;
     48     RefPtrWillBeMember<EventTarget> relatedTarget;
     49 };
     50 
     51 class MouseEvent : public MouseRelatedEvent {
     52     DEFINE_WRAPPERTYPEINFO();
     53 public:
     54     static PassRefPtrWillBeRawPtr<MouseEvent> create()
     55     {
     56         return adoptRefWillBeNoop(new MouseEvent);
     57     }
     58 
     59     static PassRefPtrWillBeRawPtr<MouseEvent> create(const AtomicString& type, bool canBubble, bool cancelable, PassRefPtrWillBeRawPtr<AbstractView>,
     60         int detail, int screenX, int screenY, int pageX, int pageY,
     61         int movementX, int movementY,
     62         bool ctrlKey, bool altKey, bool shiftKey, bool metaKey, unsigned short button,
     63         PassRefPtrWillBeRawPtr<EventTarget> relatedTarget, PassRefPtrWillBeRawPtr<DataTransfer>,
     64         bool isSimulated = false, PlatformMouseEvent::SyntheticEventType = PlatformMouseEvent::RealOrIndistinguishable);
     65 
     66     static PassRefPtrWillBeRawPtr<MouseEvent> create(const AtomicString& eventType, PassRefPtrWillBeRawPtr<AbstractView>, const PlatformMouseEvent&, int detail, PassRefPtrWillBeRawPtr<Node> relatedTarget);
     67 
     68     static PassRefPtrWillBeRawPtr<MouseEvent> create(const AtomicString& eventType, const MouseEventInit&);
     69 
     70     virtual ~MouseEvent();
     71 
     72     void initMouseEvent(const AtomicString& type, bool canBubble, bool cancelable, PassRefPtrWillBeRawPtr<AbstractView>,
     73         int detail, int screenX, int screenY, int clientX, int clientY,
     74         bool ctrlKey, bool altKey, bool shiftKey, bool metaKey,
     75         unsigned short button, PassRefPtrWillBeRawPtr<EventTarget> relatedTarget);
     76 
     77     // WinIE uses 1,4,2 for left/middle/right but not for click (just for mousedown/up, maybe others),
     78     // but we will match the standard DOM.
     79     unsigned short button() const { return m_button; }
     80     bool buttonDown() const { return m_buttonDown; }
     81     EventTarget* relatedTarget() const { return m_relatedTarget.get(); }
     82     void setRelatedTarget(PassRefPtrWillBeRawPtr<EventTarget> relatedTarget) { m_relatedTarget = relatedTarget; }
     83 
     84     Node* toElement() const;
     85     Node* fromElement() const;
     86 
     87     DataTransfer* dataTransfer() const { return isDragEvent() ? m_dataTransfer.get() : 0; }
     88 
     89     bool fromTouch() const { return m_syntheticEventType == PlatformMouseEvent::FromTouch; }
     90 
     91     virtual const AtomicString& interfaceName() const OVERRIDE;
     92 
     93     virtual bool isMouseEvent() const OVERRIDE;
     94     virtual bool isDragEvent() const OVERRIDE FINAL;
     95     virtual int which() const OVERRIDE FINAL;
     96 
     97     virtual void trace(Visitor*) OVERRIDE;
     98 
     99 protected:
    100     MouseEvent(const AtomicString& type, bool canBubble, bool cancelable, PassRefPtrWillBeRawPtr<AbstractView>,
    101         int detail, int screenX, int screenY, int pageX, int pageY,
    102         int movementX, int movementY,
    103         bool ctrlKey, bool altKey, bool shiftKey, bool metaKey, unsigned short button,
    104         PassRefPtrWillBeRawPtr<EventTarget> relatedTarget, PassRefPtrWillBeRawPtr<DataTransfer>,
    105         bool isSimulated, PlatformMouseEvent::SyntheticEventType);
    106 
    107     MouseEvent(const AtomicString& type, const MouseEventInit&);
    108 
    109     MouseEvent();
    110 
    111 private:
    112     unsigned short m_button;
    113     bool m_buttonDown;
    114     RefPtrWillBeMember<EventTarget> m_relatedTarget;
    115     RefPtrWillBeMember<DataTransfer> m_dataTransfer;
    116     PlatformMouseEvent::SyntheticEventType m_syntheticEventType;
    117 };
    118 
    119 class SimulatedMouseEvent FINAL : public MouseEvent {
    120 public:
    121     static PassRefPtrWillBeRawPtr<SimulatedMouseEvent> create(const AtomicString& eventType, PassRefPtrWillBeRawPtr<AbstractView>, PassRefPtrWillBeRawPtr<Event> underlyingEvent);
    122     virtual ~SimulatedMouseEvent();
    123 
    124     virtual void trace(Visitor*) OVERRIDE;
    125 
    126 private:
    127     SimulatedMouseEvent(const AtomicString& eventType, PassRefPtrWillBeRawPtr<AbstractView>, PassRefPtrWillBeRawPtr<Event> underlyingEvent);
    128 };
    129 
    130 class MouseEventDispatchMediator FINAL : public EventDispatchMediator {
    131 public:
    132     enum MouseEventType { SyntheticMouseEvent, NonSyntheticMouseEvent};
    133     static PassRefPtrWillBeRawPtr<MouseEventDispatchMediator> create(PassRefPtrWillBeRawPtr<MouseEvent>, MouseEventType = NonSyntheticMouseEvent);
    134 
    135 private:
    136     explicit MouseEventDispatchMediator(PassRefPtrWillBeRawPtr<MouseEvent>, MouseEventType);
    137     MouseEvent* event() const;
    138 
    139     virtual bool dispatchEvent(EventDispatcher*) const OVERRIDE;
    140     bool isSyntheticMouseEvent() const { return m_mouseEventType == SyntheticMouseEvent; }
    141     MouseEventType m_mouseEventType;
    142 };
    143 
    144 DEFINE_EVENT_TYPE_CASTS(MouseEvent);
    145 
    146 } // namespace blink
    147 
    148 #endif // MouseEvent_h
    149