JSDeviceOrientationEventCustom.cpp [plain text]
#include "config.h"
#include "JSDeviceOrientationEvent.h"
#if ENABLE(DEVICE_ORIENTATION)
#include "DeviceOrientation.h"
#include "DeviceOrientationEvent.h"
using namespace JSC;
namespace WebCore {
JSValue JSDeviceOrientationEvent::alpha(ExecState*) const
{
DeviceOrientationEvent* imp = static_cast<DeviceOrientationEvent*>(impl());
if (!imp->orientation()->canProvideAlpha())
return jsNull();
return jsNumber(imp->orientation()->alpha());
}
JSValue JSDeviceOrientationEvent::beta(ExecState*) const
{
DeviceOrientationEvent* imp = static_cast<DeviceOrientationEvent*>(impl());
if (!imp->orientation()->canProvideBeta())
return jsNull();
return jsNumber(imp->orientation()->beta());
}
JSValue JSDeviceOrientationEvent::gamma(ExecState*) const
{
DeviceOrientationEvent* imp = static_cast<DeviceOrientationEvent*>(impl());
if (!imp->orientation()->canProvideGamma())
return jsNull();
return jsNumber(imp->orientation()->gamma());
}
JSValue JSDeviceOrientationEvent::initDeviceOrientationEvent(ExecState* exec)
{
const String& type = ustringToString(exec->argument(0).toString(exec));
bool bubbles = exec->argument(1).toBoolean(exec);
bool cancelable = exec->argument(2).toBoolean(exec);
bool alphaProvided = !exec->argument(3).isUndefinedOrNull();
double alpha = exec->argument(3).toNumber(exec);
bool betaProvided = !exec->argument(4).isUndefinedOrNull();
double beta = exec->argument(4).toNumber(exec);
bool gammaProvided = !exec->argument(5).isUndefinedOrNull();
double gamma = exec->argument(5).toNumber(exec);
RefPtr<DeviceOrientation> orientation = DeviceOrientation::create(alphaProvided, alpha, betaProvided, beta, gammaProvided, gamma);
DeviceOrientationEvent* imp = static_cast<DeviceOrientationEvent*>(impl());
imp->initDeviceOrientationEvent(type, bubbles, cancelable, orientation.get());
return jsUndefined();
}
}
#endif // ENABLE(DEVICE_ORIENTATION)