Home | History | Annotate | Download | only in WebCoreSupport
      1 /*
      2  * Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies)
      3  *
      4  * This library is free software; you can redistribute it and/or
      5  * modify it under the terms of the GNU Library General Public
      6  * License as published by the Free Software Foundation; either
      7  * version 2 of the License, or (at your option) any later version.
      8  *
      9  * This library is distributed in the hope that it will be useful,
     10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
     11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
     12  * Library General Public License for more details.
     13  *
     14  * You should have received a copy of the GNU Library General Public License
     15  * along with this library; see the file COPYING.LIB.  If not, write to
     16  * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
     17  * Boston, MA 02110-1301, USA.
     18  *
     19  */
     20 #include "config.h"
     21 #include "DeviceMotionProviderQt.h"
     22 
     23 #include "DeviceOrientationProviderQt.h"
     24 
     25 namespace WebCore {
     26 
     27 DeviceMotionProviderQt::DeviceMotionProviderQt()
     28 {
     29     m_acceleration.addFilter(this);
     30     m_motion = DeviceMotionData::create();
     31     m_deviceOrientation = new DeviceOrientationProviderQt();
     32 }
     33 
     34 DeviceMotionProviderQt::~DeviceMotionProviderQt()
     35 {
     36     delete m_deviceOrientation;
     37 }
     38 
     39 void DeviceMotionProviderQt::start()
     40 {
     41     m_acceleration.start();
     42     m_deviceOrientation->start();
     43 }
     44 
     45 void DeviceMotionProviderQt::stop()
     46 {
     47     m_acceleration.stop();
     48     m_deviceOrientation->stop();
     49 }
     50 
     51 bool DeviceMotionProviderQt::filter(QAccelerometerReading* reading)
     52 {
     53     RefPtr<DeviceMotionData::Acceleration> accel = DeviceMotionData::Acceleration::create(
     54             /* x available */ true, reading->x(),
     55             /* y available */ true, reading->y(),
     56             /* z available */ true, reading->z());
     57 
     58     RefPtr<DeviceMotionData::RotationRate> rotation = DeviceMotionData::RotationRate::create(
     59             m_deviceOrientation->hasAlpha(), m_deviceOrientation->orientation()->alpha(),
     60             /* beta available */ true, m_deviceOrientation->orientation()->beta(),
     61             /* gamma available */ true, m_deviceOrientation->orientation()->gamma());
     62 
     63     m_motion = DeviceMotionData::create(accel,
     64             accel, /* FIXME: Needs to provide acceleration include gravity. */
     65             rotation,
     66             false, 0 /* The interval is treated internally by Qt mobility */);
     67 
     68     emit deviceMotionChanged();
     69 
     70     return false;
     71 }
     72 
     73 } // namespace WebCore
     74 
     75 #include "moc_DeviceMotionProviderQt.cpp"
     76