1 | /* |
2 | * Copyright 2010, The Android Open Source Project |
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 | * * Redistributions of source code must retain the above copyright |
8 | * notice, this list of conditions and the following disclaimer. |
9 | * * 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 THE COPYRIGHT HOLDERS ``AS IS'' AND ANY |
14 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
15 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR |
16 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR |
17 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, |
18 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, |
19 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR |
20 | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY |
21 | * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
22 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
23 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
24 | */ |
25 | |
26 | #include "config.h" |
27 | #include "DeviceOrientationEvent.h" |
28 | |
29 | #include "DeviceOrientationData.h" |
30 | |
31 | namespace WebCore { |
32 | |
33 | DeviceOrientationEvent::~DeviceOrientationEvent() = default; |
34 | |
35 | DeviceOrientationEvent::DeviceOrientationEvent() |
36 | : m_orientation(DeviceOrientationData::create()) |
37 | { |
38 | } |
39 | |
40 | DeviceOrientationEvent::DeviceOrientationEvent(const AtomicString& eventType, DeviceOrientationData* orientation) |
41 | : Event(eventType, CanBubble::No, IsCancelable::No) |
42 | , m_orientation(orientation) |
43 | { |
44 | } |
45 | |
46 | Optional<double> DeviceOrientationEvent::alpha() const |
47 | { |
48 | return m_orientation->alpha(); |
49 | } |
50 | |
51 | Optional<double> DeviceOrientationEvent::beta() const |
52 | { |
53 | return m_orientation->beta(); |
54 | } |
55 | |
56 | Optional<double> DeviceOrientationEvent::gamma() const |
57 | { |
58 | return m_orientation->gamma(); |
59 | } |
60 | |
61 | #if PLATFORM(IOS_FAMILY) |
62 | |
63 | Optional<double> DeviceOrientationEvent::compassHeading() const |
64 | { |
65 | return m_orientation->compassHeading(); |
66 | } |
67 | |
68 | Optional<double> DeviceOrientationEvent::compassAccuracy() const |
69 | { |
70 | return m_orientation->compassAccuracy(); |
71 | } |
72 | |
73 | void DeviceOrientationEvent::initDeviceOrientationEvent(const AtomicString& type, bool bubbles, bool cancelable, Optional<double> alpha, Optional<double> beta, Optional<double> gamma, Optional<double> compassHeading, Optional<double> compassAccuracy) |
74 | { |
75 | if (isBeingDispatched()) |
76 | return; |
77 | |
78 | initEvent(type, bubbles, cancelable); |
79 | m_orientation = DeviceOrientationData::create(alpha, beta, gamma, compassHeading, compassAccuracy); |
80 | } |
81 | |
82 | #else |
83 | |
84 | Optional<bool> DeviceOrientationEvent::absolute() const |
85 | { |
86 | return m_orientation->absolute(); |
87 | } |
88 | |
89 | void DeviceOrientationEvent::initDeviceOrientationEvent(const AtomicString& type, bool bubbles, bool cancelable, Optional<double> alpha, Optional<double> beta, Optional<double> gamma, Optional<bool> absolute) |
90 | { |
91 | if (isBeingDispatched()) |
92 | return; |
93 | |
94 | initEvent(type, bubbles, cancelable); |
95 | m_orientation = DeviceOrientationData::create(alpha, beta, gamma, absolute); |
96 | } |
97 | |
98 | #endif |
99 | |
100 | EventInterface DeviceOrientationEvent::eventInterface() const |
101 | { |
102 | #if ENABLE(DEVICE_ORIENTATION) |
103 | return DeviceOrientationEventInterfaceType; |
104 | #else |
105 | // FIXME: ENABLE(DEVICE_ORIENTATION) seems to be in a strange state where |
106 | // it is half-guarded by #ifdefs. DeviceOrientationEvent.idl is guarded |
107 | // but DeviceOrientationEvent.cpp itself is required by ungarded code. |
108 | return EventInterfaceType; |
109 | #endif |
110 | } |
111 | |
112 | } // namespace WebCore |
113 | |