• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2010 Google Inc. All rights reserved.
3  *
4  * Redistribution and use in source and binary forms, with or without
5  * modification, are permitted provided that the following conditions are
6  * met:
7  *
8  *     * Redistributions of source code must retain the above copyright
9  * notice, this list of conditions and the following disclaimer.
10  *     * Redistributions in binary form must reproduce the above
11  * copyright notice, this list of conditions and the following disclaimer
12  * in the documentation and/or other materials provided with the
13  * distribution.
14  *     * Neither the name of Google Inc. nor the names of its
15  * contributors may be used to endorse or promote products derived from
16  * this software without specific prior written permission.
17  *
18  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29  */
30 
31 #ifndef WebDOMEvent_h
32 #define WebDOMEvent_h
33 
34 #include "WebCommon.h"
35 #include "WebNode.h"
36 #include "WebString.h"
37 
38 namespace WebCore { class Event; }
39 #if WEBKIT_IMPLEMENTATION
40 namespace WTF { template <typename T> class PassRefPtr; }
41 #endif
42 
43 namespace WebKit {
44 
45 class WebDOMEvent {
46 public:
47     enum PhaseType {
48         CapturingPhase     = 1,
49         AtTarget           = 2,
50         BubblingPhase      = 3
51     };
52 
~WebDOMEvent()53     ~WebDOMEvent() { reset(); }
54 
WebDOMEvent()55     WebDOMEvent() : m_private(0) { }
WebDOMEvent(const WebDOMEvent & e)56     WebDOMEvent(const WebDOMEvent& e) : m_private(0) { assign(e); }
57     WebDOMEvent& operator=(const WebDOMEvent& e)
58     {
59         assign(e);
60         return *this;
61     }
62 
63     WEBKIT_API void reset();
64     WEBKIT_API void assign(const WebDOMEvent&);
65 
isNull()66     bool isNull() const { return !m_private; }
67 
68     WEBKIT_API WebString type() const;
69     WEBKIT_API WebNode target() const;
70     WEBKIT_API WebNode currentTarget() const;
71 
72     WEBKIT_API PhaseType eventPhase() const;
73     WEBKIT_API bool bubbles() const;
74     WEBKIT_API bool cancelable() const;
75 
76     WEBKIT_API bool isUIEvent() const;
77     WEBKIT_API bool isMouseEvent() const;
78     WEBKIT_API bool isMutationEvent() const;
79     WEBKIT_API bool isKeyboardEvent() const;
80     WEBKIT_API bool isTextEvent() const;
81     WEBKIT_API bool isCompositionEvent() const;
82     WEBKIT_API bool isDragEvent() const;
83     WEBKIT_API bool isClipboardEvent() const;
84     WEBKIT_API bool isMessageEvent() const;
85     WEBKIT_API bool isWheelEvent() const;
86     WEBKIT_API bool isBeforeTextInsertedEvent() const;
87     WEBKIT_API bool isOverflowEvent() const;
88     WEBKIT_API bool isPageTransitionEvent() const;
89     WEBKIT_API bool isPopStateEvent() const;
90     WEBKIT_API bool isProgressEvent() const;
91     WEBKIT_API bool isXMLHttpRequestProgressEvent() const;
92     WEBKIT_API bool isWebKitAnimationEvent() const;
93     WEBKIT_API bool isWebKitTransitionEvent() const;
94     WEBKIT_API bool isBeforeLoadEvent() const;
95 
96 #if WEBKIT_IMPLEMENTATION
97     WebDOMEvent(const WTF::PassRefPtr<WebCore::Event>&);
98 #endif
99 
to()100     template<typename T> T to()
101     {
102         T res;
103         res.WebDOMEvent::assign(*this);
104         return res;
105     }
106 
toConst()107     template<typename T> const T toConst() const
108     {
109         T res;
110         res.WebDOMEvent::assign(*this);
111         return res;
112     }
113 
114 protected:
115     typedef WebCore::Event WebDOMEventPrivate;
116     void assign(WebDOMEventPrivate*);
117     WebDOMEventPrivate* m_private;
118 
unwrap()119     template<typename T> T* unwrap()
120     {
121         return static_cast<T*>(m_private);
122     }
123 
constUnwrap()124     template<typename T> const T* constUnwrap() const
125     {
126         return static_cast<const T*>(m_private);
127     }
128 };
129 
130 } // namespace WebKit
131 
132 #endif
133