1967717af5423377c967781471ee106e2bb4e11c8Ben Murdoch/* 2967717af5423377c967781471ee106e2bb4e11c8Ben Murdoch * Copyright (C) 2010 Google Inc. All rights reserved. 3967717af5423377c967781471ee106e2bb4e11c8Ben Murdoch * 4967717af5423377c967781471ee106e2bb4e11c8Ben Murdoch * Redistribution and use in source and binary forms, with or without 5967717af5423377c967781471ee106e2bb4e11c8Ben Murdoch * modification, are permitted provided that the following conditions 6967717af5423377c967781471ee106e2bb4e11c8Ben Murdoch * are met: 7967717af5423377c967781471ee106e2bb4e11c8Ben Murdoch * * Redistributions of source code must retain the above copyright 8967717af5423377c967781471ee106e2bb4e11c8Ben Murdoch * notice, this list of conditions and the following disclaimer. 9967717af5423377c967781471ee106e2bb4e11c8Ben Murdoch * * Redistributions in binary form must reproduce the above copyright 10967717af5423377c967781471ee106e2bb4e11c8Ben Murdoch * notice, this list of conditions and the following disclaimer in the 11967717af5423377c967781471ee106e2bb4e11c8Ben Murdoch * documentation and/or other materials provided with the distribution. 12967717af5423377c967781471ee106e2bb4e11c8Ben Murdoch * 13967717af5423377c967781471ee106e2bb4e11c8Ben Murdoch * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS'' AND ANY 14967717af5423377c967781471ee106e2bb4e11c8Ben Murdoch * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 15967717af5423377c967781471ee106e2bb4e11c8Ben Murdoch * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 16967717af5423377c967781471ee106e2bb4e11c8Ben Murdoch * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR 17967717af5423377c967781471ee106e2bb4e11c8Ben Murdoch * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 18967717af5423377c967781471ee106e2bb4e11c8Ben Murdoch * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 19967717af5423377c967781471ee106e2bb4e11c8Ben Murdoch * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 20967717af5423377c967781471ee106e2bb4e11c8Ben Murdoch * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY 21967717af5423377c967781471ee106e2bb4e11c8Ben Murdoch * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 22967717af5423377c967781471ee106e2bb4e11c8Ben Murdoch * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 23967717af5423377c967781471ee106e2bb4e11c8Ben Murdoch * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 24967717af5423377c967781471ee106e2bb4e11c8Ben Murdoch */ 25967717af5423377c967781471ee106e2bb4e11c8Ben Murdoch 26967717af5423377c967781471ee106e2bb4e11c8Ben Murdoch#include "config.h" 27967717af5423377c967781471ee106e2bb4e11c8Ben Murdoch#include "JSDeviceOrientationEvent.h" 28967717af5423377c967781471ee106e2bb4e11c8Ben Murdoch 29967717af5423377c967781471ee106e2bb4e11c8Ben Murdoch#if ENABLE(DEVICE_ORIENTATION) 30967717af5423377c967781471ee106e2bb4e11c8Ben Murdoch 31967717af5423377c967781471ee106e2bb4e11c8Ben Murdoch#include "DeviceOrientation.h" 32967717af5423377c967781471ee106e2bb4e11c8Ben Murdoch#include "DeviceOrientationEvent.h" 33967717af5423377c967781471ee106e2bb4e11c8Ben Murdoch 34967717af5423377c967781471ee106e2bb4e11c8Ben Murdochusing namespace JSC; 35967717af5423377c967781471ee106e2bb4e11c8Ben Murdoch 36967717af5423377c967781471ee106e2bb4e11c8Ben Murdochnamespace WebCore { 37967717af5423377c967781471ee106e2bb4e11c8Ben Murdoch 386b70adc33054f8aee8c54d0f460458a9df11b8a5Russell BrennerJSValue JSDeviceOrientationEvent::alpha(ExecState*) const 39967717af5423377c967781471ee106e2bb4e11c8Ben Murdoch{ 40967717af5423377c967781471ee106e2bb4e11c8Ben Murdoch DeviceOrientationEvent* imp = static_cast<DeviceOrientationEvent*>(impl()); 41967717af5423377c967781471ee106e2bb4e11c8Ben Murdoch if (!imp->orientation()->canProvideAlpha()) 42967717af5423377c967781471ee106e2bb4e11c8Ben Murdoch return jsNull(); 43e14391e94c850b8bd03680c23b38978db68687a8John Reck return jsNumber(imp->orientation()->alpha()); 44967717af5423377c967781471ee106e2bb4e11c8Ben Murdoch} 45967717af5423377c967781471ee106e2bb4e11c8Ben Murdoch 466b70adc33054f8aee8c54d0f460458a9df11b8a5Russell BrennerJSValue JSDeviceOrientationEvent::beta(ExecState*) const 47967717af5423377c967781471ee106e2bb4e11c8Ben Murdoch{ 48967717af5423377c967781471ee106e2bb4e11c8Ben Murdoch DeviceOrientationEvent* imp = static_cast<DeviceOrientationEvent*>(impl()); 49967717af5423377c967781471ee106e2bb4e11c8Ben Murdoch if (!imp->orientation()->canProvideBeta()) 50967717af5423377c967781471ee106e2bb4e11c8Ben Murdoch return jsNull(); 51e14391e94c850b8bd03680c23b38978db68687a8John Reck return jsNumber(imp->orientation()->beta()); 52967717af5423377c967781471ee106e2bb4e11c8Ben Murdoch} 53967717af5423377c967781471ee106e2bb4e11c8Ben Murdoch 546b70adc33054f8aee8c54d0f460458a9df11b8a5Russell BrennerJSValue JSDeviceOrientationEvent::gamma(ExecState*) const 55967717af5423377c967781471ee106e2bb4e11c8Ben Murdoch{ 56967717af5423377c967781471ee106e2bb4e11c8Ben Murdoch DeviceOrientationEvent* imp = static_cast<DeviceOrientationEvent*>(impl()); 57967717af5423377c967781471ee106e2bb4e11c8Ben Murdoch if (!imp->orientation()->canProvideGamma()) 58967717af5423377c967781471ee106e2bb4e11c8Ben Murdoch return jsNull(); 59e14391e94c850b8bd03680c23b38978db68687a8John Reck return jsNumber(imp->orientation()->gamma()); 60967717af5423377c967781471ee106e2bb4e11c8Ben Murdoch} 61967717af5423377c967781471ee106e2bb4e11c8Ben Murdoch 62967717af5423377c967781471ee106e2bb4e11c8Ben MurdochJSValue JSDeviceOrientationEvent::initDeviceOrientationEvent(ExecState* exec) 63967717af5423377c967781471ee106e2bb4e11c8Ben Murdoch{ 64967717af5423377c967781471ee106e2bb4e11c8Ben Murdoch const String& type = ustringToString(exec->argument(0).toString(exec)); 65967717af5423377c967781471ee106e2bb4e11c8Ben Murdoch bool bubbles = exec->argument(1).toBoolean(exec); 66967717af5423377c967781471ee106e2bb4e11c8Ben Murdoch bool cancelable = exec->argument(2).toBoolean(exec); 67967717af5423377c967781471ee106e2bb4e11c8Ben Murdoch // If alpha, beta or gamma are null or undefined, mark them as not provided. 68967717af5423377c967781471ee106e2bb4e11c8Ben Murdoch // Otherwise, use the standard JavaScript conversion. 69967717af5423377c967781471ee106e2bb4e11c8Ben Murdoch bool alphaProvided = !exec->argument(3).isUndefinedOrNull(); 70967717af5423377c967781471ee106e2bb4e11c8Ben Murdoch double alpha = exec->argument(3).toNumber(exec); 71967717af5423377c967781471ee106e2bb4e11c8Ben Murdoch bool betaProvided = !exec->argument(4).isUndefinedOrNull(); 72967717af5423377c967781471ee106e2bb4e11c8Ben Murdoch double beta = exec->argument(4).toNumber(exec); 73967717af5423377c967781471ee106e2bb4e11c8Ben Murdoch bool gammaProvided = !exec->argument(5).isUndefinedOrNull(); 74967717af5423377c967781471ee106e2bb4e11c8Ben Murdoch double gamma = exec->argument(5).toNumber(exec); 75967717af5423377c967781471ee106e2bb4e11c8Ben Murdoch RefPtr<DeviceOrientation> orientation = DeviceOrientation::create(alphaProvided, alpha, betaProvided, beta, gammaProvided, gamma); 76967717af5423377c967781471ee106e2bb4e11c8Ben Murdoch DeviceOrientationEvent* imp = static_cast<DeviceOrientationEvent*>(impl()); 77967717af5423377c967781471ee106e2bb4e11c8Ben Murdoch imp->initDeviceOrientationEvent(type, bubbles, cancelable, orientation.get()); 78967717af5423377c967781471ee106e2bb4e11c8Ben Murdoch return jsUndefined(); 79967717af5423377c967781471ee106e2bb4e11c8Ben Murdoch} 80967717af5423377c967781471ee106e2bb4e11c8Ben Murdoch 81967717af5423377c967781471ee106e2bb4e11c8Ben Murdoch} // namespace WebCore 82967717af5423377c967781471ee106e2bb4e11c8Ben Murdoch 83967717af5423377c967781471ee106e2bb4e11c8Ben Murdoch#endif // ENABLE(DEVICE_ORIENTATION) 84