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#ifndef HashChangeEvent_h
22#define HashChangeEvent_h
23
24#include "core/events/Event.h"
25
26namespace blink {
27
28struct HashChangeEventInit : public EventInit {
29    HashChangeEventInit() { }
30
31    String oldURL;
32    String newURL;
33};
34
35class HashChangeEvent FINAL : public Event {
36    DEFINE_WRAPPERTYPEINFO();
37public:
38    static PassRefPtrWillBeRawPtr<HashChangeEvent> create()
39    {
40        return adoptRefWillBeNoop(new HashChangeEvent);
41    }
42
43    static PassRefPtrWillBeRawPtr<HashChangeEvent> create(const String& oldURL, const String& newURL)
44    {
45        return adoptRefWillBeNoop(new HashChangeEvent(oldURL, newURL));
46    }
47
48    static PassRefPtrWillBeRawPtr<HashChangeEvent> create(const AtomicString& type, const HashChangeEventInit& initializer)
49    {
50        return adoptRefWillBeNoop(new HashChangeEvent(type, initializer));
51    }
52
53    void initHashChangeEvent(const AtomicString& eventType, bool canBubble, bool cancelable, const String& oldURL, const String& newURL)
54    {
55        if (dispatched())
56            return;
57
58        initEvent(eventType, canBubble, cancelable);
59
60        m_oldURL = oldURL;
61        m_newURL = newURL;
62    }
63
64    const String& oldURL() const { return m_oldURL; }
65    const String& newURL() const { return m_newURL; }
66
67    virtual const AtomicString& interfaceName() const OVERRIDE { return EventNames::HashChangeEvent; }
68
69    virtual void trace(Visitor* visitor) OVERRIDE { Event::trace(visitor); }
70
71private:
72    HashChangeEvent() { }
73
74    HashChangeEvent(const String& oldURL, const String& newURL)
75        : Event(EventTypeNames::hashchange, false, false)
76        , m_oldURL(oldURL)
77        , m_newURL(newURL) { }
78
79    HashChangeEvent(const AtomicString& type, const HashChangeEventInit& initializer)
80        : Event(type, initializer)
81        , m_oldURL(initializer.oldURL)
82        , m_newURL(initializer.newURL) { }
83
84    String m_oldURL;
85    String m_newURL;
86};
87
88} // namespace blink
89
90#endif // HashChangeEvent_h
91