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, 2004, 2005, 2006, 2008, 2009 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#pragma once
25
26#include "EventListener.h"
27#include <wtf/Ref.h>
28
29namespace WebCore {
30
31// https://dom.spec.whatwg.org/#concept-event-listener
32class RegisteredEventListener : public RefCounted<RegisteredEventListener> {
33public:
34 struct Options {
35 Options(bool capture = false, bool passive = false, bool once = false)
36 : capture(capture)
37 , passive(passive)
38 , once(once)
39 { }
40
41 bool capture;
42 bool passive;
43 bool once;
44 };
45
46 static Ref<RegisteredEventListener> create(Ref<EventListener>&& listener, const Options& options)
47 {
48 return adoptRef(*new RegisteredEventListener(WTFMove(listener), options));
49 }
50
51 EventListener& callback() const { return m_callback; }
52 bool useCapture() const { return m_useCapture; }
53 bool isPassive() const { return m_isPassive; }
54 bool isOnce() const { return m_isOnce; }
55 bool wasRemoved() const { return m_wasRemoved; }
56
57 void markAsRemoved() { m_wasRemoved = true; }
58
59private:
60 RegisteredEventListener(Ref<EventListener>&& listener, const Options& options)
61 : m_callback(WTFMove(listener))
62 , m_useCapture(options.capture)
63 , m_isPassive(options.passive)
64 , m_isOnce(options.once)
65 {
66 }
67
68 Ref<EventListener> m_callback;
69 bool m_useCapture { false };
70 bool m_isPassive { false };
71 bool m_isOnce { false };
72 bool m_wasRemoved { false };
73};
74
75} // namespace WebCore
76