1 | /* |
2 | * Copyright (C) 2010 Apple Inc. All rights reserved. |
3 | * |
4 | * This library is free software; you can redistribute it and/or |
5 | * modify it under the terms of the GNU Library General Public |
6 | * License as published by the Free Software Foundation; either |
7 | * version 2 of the License, or (at your option) any later version. |
8 | * |
9 | * This library is distributed in the hope that it will be useful, |
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
12 | * Library General Public License for more details. |
13 | * |
14 | * You should have received a copy of the GNU Library General Public License |
15 | * along with this library; see the file COPYING.LIB. If not, write to |
16 | * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, |
17 | * Boston, MA 02110-1301, USA. |
18 | * |
19 | */ |
20 | |
21 | #pragma once |
22 | |
23 | #include "Event.h" |
24 | #include "EventNames.h" |
25 | |
26 | namespace WebCore { |
27 | |
28 | class HashChangeEvent final : public Event { |
29 | public: |
30 | static Ref<HashChangeEvent> create(const String& oldURL, const String& newURL) |
31 | { |
32 | return adoptRef(*new HashChangeEvent(oldURL, newURL)); |
33 | } |
34 | |
35 | static Ref<HashChangeEvent> createForBindings() |
36 | { |
37 | return adoptRef(*new HashChangeEvent); |
38 | } |
39 | |
40 | struct Init : EventInit { |
41 | String oldURL; |
42 | String newURL; |
43 | }; |
44 | |
45 | static Ref<HashChangeEvent> create(const AtomicString& type, const Init& initializer, IsTrusted isTrusted = IsTrusted::No) |
46 | { |
47 | return adoptRef(*new HashChangeEvent(type, initializer, isTrusted)); |
48 | } |
49 | |
50 | void initHashChangeEvent(const AtomicString& eventType, bool canBubble, bool cancelable, const String& oldURL, const String& newURL) |
51 | { |
52 | if (isBeingDispatched()) |
53 | return; |
54 | |
55 | initEvent(eventType, canBubble, cancelable); |
56 | |
57 | m_oldURL = oldURL; |
58 | m_newURL = newURL; |
59 | } |
60 | |
61 | const String& oldURL() const { return m_oldURL; } |
62 | const String& newURL() const { return m_newURL; } |
63 | |
64 | EventInterface eventInterface() const override { return HashChangeEventInterfaceType; } |
65 | |
66 | private: |
67 | HashChangeEvent() |
68 | { |
69 | } |
70 | |
71 | HashChangeEvent(const String& oldURL, const String& newURL) |
72 | : Event(eventNames().hashchangeEvent, CanBubble::No, IsCancelable::No) |
73 | , m_oldURL(oldURL) |
74 | , m_newURL(newURL) |
75 | { |
76 | } |
77 | |
78 | HashChangeEvent(const AtomicString& type, const Init& initializer, IsTrusted isTrusted) |
79 | : Event(type, initializer, isTrusted) |
80 | , m_oldURL(initializer.oldURL) |
81 | , m_newURL(initializer.newURL) |
82 | { |
83 | } |
84 | |
85 | String m_oldURL; |
86 | String m_newURL; |
87 | }; |
88 | |
89 | } // namespace WebCore |
90 | |