1/*
2 * Copyright (C) 2013 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
6 * are met:
7 * 1. Redistributions of source code must retain the above copyright
8 *    notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright
10 *    notice, this list of conditions and the following disclaimer in the
11 *    documentation and/or other materials provided with the distribution.
12 *
13 * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
14 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
15 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
17 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
18 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
19 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
20 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
21 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
22 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
23 * THE POSSIBILITY OF SUCH DAMAGE.
24 */
25
26#include "config.h"
27#include "FocusEvent.h"
28
29#include "Event.h"
30#include "EventDispatcher.h"
31#include "EventNames.h"
32#include "EventRetargeter.h"
33#include "Node.h"
34
35namespace WebCore {
36
37FocusEventInit::FocusEventInit()
38    : relatedTarget(0)
39{
40}
41
42const AtomicString& FocusEvent::interfaceName() const
43{
44    return eventNames().interfaceForFocusEvent;
45}
46
47bool FocusEvent::isFocusEvent() const
48{
49    return true;
50}
51
52FocusEvent::FocusEvent()
53{
54}
55
56FocusEvent::FocusEvent(const AtomicString& type, bool canBubble, bool cancelable, PassRefPtr<AbstractView> view, int detail, PassRefPtr<EventTarget> relatedTarget)
57    : UIEvent(type, canBubble, cancelable, view, detail)
58    , m_relatedTarget(relatedTarget)
59{
60}
61
62FocusEvent::FocusEvent(const AtomicString& type, const FocusEventInit& initializer)
63    : UIEvent(type, initializer)
64    , m_relatedTarget(initializer.relatedTarget)
65{
66}
67
68PassRefPtr<FocusEventDispatchMediator> FocusEventDispatchMediator::create(PassRefPtr<FocusEvent> focusEvent)
69{
70    return adoptRef(new FocusEventDispatchMediator(focusEvent));
71}
72
73FocusEventDispatchMediator::FocusEventDispatchMediator(PassRefPtr<FocusEvent> focusEvent)
74    : EventDispatchMediator(focusEvent)
75{
76}
77
78bool FocusEventDispatchMediator::dispatchEvent(EventDispatcher* dispatcher) const
79{
80    EventRetargeter::adjustForFocusEvent(dispatcher->node(), *event(), dispatcher->eventPath());
81    return EventDispatchMediator::dispatchEvent(dispatcher);
82}
83
84PassRefPtr<BlurEventDispatchMediator> BlurEventDispatchMediator::create(PassRefPtr<FocusEvent> focusEvent)
85{
86    return adoptRef(new BlurEventDispatchMediator(focusEvent));
87}
88
89BlurEventDispatchMediator::BlurEventDispatchMediator(PassRefPtr<FocusEvent> focusEvent)
90    : EventDispatchMediator(focusEvent)
91{
92}
93
94bool BlurEventDispatchMediator::dispatchEvent(EventDispatcher* dispatcher) const
95{
96    EventRetargeter::adjustForFocusEvent(dispatcher->node(), *event(), dispatcher->eventPath());
97    return EventDispatchMediator::dispatchEvent(dispatcher);
98}
99
100PassRefPtr<FocusInEventDispatchMediator> FocusInEventDispatchMediator::create(PassRefPtr<FocusEvent> focusEvent)
101{
102    return adoptRef(new FocusInEventDispatchMediator(focusEvent));
103}
104
105FocusInEventDispatchMediator::FocusInEventDispatchMediator(PassRefPtr<FocusEvent> focusEvent)
106    : EventDispatchMediator(focusEvent)
107{
108}
109
110bool FocusInEventDispatchMediator::dispatchEvent(EventDispatcher* dispatcher) const
111{
112    EventRetargeter::adjustForFocusEvent(dispatcher->node(), *event(), dispatcher->eventPath());
113    return EventDispatchMediator::dispatchEvent(dispatcher);
114}
115
116PassRefPtr<FocusOutEventDispatchMediator> FocusOutEventDispatchMediator::create(PassRefPtr<FocusEvent> focusEvent)
117{
118    return adoptRef(new FocusOutEventDispatchMediator(focusEvent));
119}
120
121FocusOutEventDispatchMediator::FocusOutEventDispatchMediator(PassRefPtr<FocusEvent> focusEvent)
122    : EventDispatchMediator(focusEvent)
123{
124}
125
126bool FocusOutEventDispatchMediator::dispatchEvent(EventDispatcher* dispatcher) const
127{
128    EventRetargeter::adjustForFocusEvent(dispatcher->node(), *event(), dispatcher->eventPath());
129    return EventDispatchMediator::dispatchEvent(dispatcher);
130}
131
132} // namespace WebCore
133