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 "V8DeviceOrientationEvent.h"
28
29#if ENABLE(DEVICE_ORIENTATION)
30
31#include "DeviceOrientation.h"
32#include "V8Binding.h"
33#include "V8Proxy.h"
34
35#include <v8.h>
36
37namespace WebCore {
38
39v8::Handle<v8::Value> V8DeviceOrientationEvent::alphaAccessorGetter(v8::Local<v8::String> name, const v8::AccessorInfo& info)
40{
41 INC_STATS("DOM.DeviceOrientationEvent.alpha._get");
42 v8::Handle<v8::Object> holder = info.Holder();
43 DeviceOrientationEvent* imp = V8DeviceOrientationEvent::toNative(holder);
44 if (!imp->orientation()->canProvideAlpha())
45 return v8::Null();
46 return v8::Number::New(imp->orientation()->alpha());
47}
48
49v8::Handle<v8::Value> V8DeviceOrientationEvent::betaAccessorGetter(v8::Local<v8::String> name, const v8::AccessorInfo& info)
50{
51 INC_STATS("DOM.DeviceOrientationEvent.beta._get");
52 v8::Handle<v8::Object> holder = info.Holder();
53 DeviceOrientationEvent* imp = V8DeviceOrientationEvent::toNative(holder);
54 if (!imp->orientation()->canProvideBeta())
55 return v8::Null();
56 return v8::Number::New(imp->orientation()->beta());
57}
58
59v8::Handle<v8::Value> V8DeviceOrientationEvent::gammaAccessorGetter(v8::Local<v8::String> name, const v8::AccessorInfo& info)
60{
61 INC_STATS("DOM.DeviceOrientationEvent.gamma._get");
62 v8::Handle<v8::Object> holder = info.Holder();
63 DeviceOrientationEvent* imp = V8DeviceOrientationEvent::toNative(holder);
64 if (!imp->orientation()->canProvideGamma())
65 return v8::Null();
66 return v8::Number::New(imp->orientation()->gamma());
67}
68
69v8::Handle<v8::Value> V8DeviceOrientationEvent::initDeviceOrientationEventCallback(const v8::Arguments& args)
70{
71 DeviceOrientationEvent* imp = V8DeviceOrientationEvent::toNative(args.Holder());
72 V8Parameter<> type = args[0];
73 bool bubbles = args[1]->BooleanValue();
74 bool cancelable = args[2]->BooleanValue();
75 // If alpha, beta or gamma are null or undefined, mark them as not provided.
76 // Otherwise, use the standard JavaScript conversion.
77 bool alphaProvided = !isUndefinedOrNull(args[3]);
78 double alpha = static_cast<double>(args[3]->NumberValue());
79 bool betaProvided = !isUndefinedOrNull(args[4]);
80 double beta = static_cast<double>(args[4]->NumberValue());
81 bool gammaProvided = !isUndefinedOrNull(args[5]);
82 double gamma = static_cast<double>(args[5]->NumberValue());
83 RefPtr<DeviceOrientation> orientation = DeviceOrientation::create(alphaProvided, alpha, betaProvided, beta, gammaProvided, gamma);
84 imp->initDeviceOrientationEvent(type, bubbles, cancelable, orientation.get());
85 return v8::Handle<v8::Value>();
86}
87
88} // namespace WebCore
89
90#endif // ENABLE(DEVICE_ORIENTATION)