Chromium Code Reviews| Index: Source/WebCore/platform/chromium/support/WebDeviceMotionEventPump.cpp |
| diff --git a/Source/WebCore/platform/chromium/support/WebDeviceMotionEventPump.cpp b/Source/WebCore/platform/chromium/support/WebDeviceMotionEventPump.cpp |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..b2f8aead14b98b12c05157af80a897a5605ac779 |
| --- /dev/null |
| +++ b/Source/WebCore/platform/chromium/support/WebDeviceMotionEventPump.cpp |
| @@ -0,0 +1,105 @@ |
| +/* |
| + * Copyright (C) 2013 Google Inc. All rights reserved. |
| + * |
| + * Redistribution and use in source and binary forms, with or without |
| + * modification, are permitted provided that the following conditions are |
| + * met: |
| + * |
| + * * Redistributions of source code must retain the above copyright |
| + * notice, this list of conditions and the following disclaimer. |
| + * * Redistributions in binary form must reproduce the above |
| + * copyright notice, this list of conditions and the following disclaimer |
| + * in the documentation and/or other materials provided with the |
| + * distribution. |
| + * * Neither the name of Google Inc. nor the names of its |
| + * contributors may be used to endorse or promote products derived from |
| + * this software without specific prior written permission. |
| + * |
| + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
| + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
| + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
| + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
| + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
| + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| + */ |
| + |
| +#include "config.h" |
| +#include "WebDeviceMotionEventPump.h" |
| + |
| +#include <public/Platform.h> |
| +#include <public/WebDeviceMotionData.h> |
| +#include <public/WebDeviceMotionReader.h> |
| + |
| + |
|
Peter Beverloo
2013/04/09 17:29:53
nit: two blank lines?
timvolodine
2013/04/10 19:06:12
Done.
|
| +namespace WebKit { |
| + |
| +WebDeviceMotionEventPump& WebDeviceMotionEventPump::shared() |
| +{ |
| + DEFINE_STATIC_LOCAL(WebDeviceMotionEventPump, webDeviceMotionEventPump, (kPumpDelaySeconds)); |
| + return webDeviceMotionEventPump; |
| +} |
| + |
| +WebDeviceMotionEventPump::WebDeviceMotionEventPump(double delay_seconds) : |
| + m_delaySeconds(delay_seconds), m_lastFireEventTimeMonotonic(0), m_stopped(true), |
|
Peter Beverloo
2013/04/09 17:29:53
nit: please have a single initializer per line.
timvolodine
2013/04/10 19:06:12
Done.
|
| + m_lastDeviceMotionData(0), m_pumpTimer(this, &WebDeviceMotionEventPump::fireEvent) |
| +{ |
| +} |
| + |
| +void WebDeviceMotionEventPump::fireEvent(Timer<WebDeviceMotionEventPump>* timer) |
|
Peter Beverloo
2013/04/09 17:29:53
The timer is not being used in this method, can we
timvolodine
2013/04/10 19:06:12
I've removed the name, but looks like it's not pos
|
| +{ |
| + if (m_stopped) |
| + return; |
| + |
| + m_lastFireEventTimeMonotonic = monotonicallyIncreasingTime(); |
| + WebDeviceMotionReader* reader = WebKit::Platform::current()->deviceMotionReader(); |
| + WebDeviceMotionData data; |
|
Peter Beverloo
2013/04/09 17:29:53
Do we need a temporary variable for the reader? We
timvolodine
2013/04/10 19:06:12
added asserts.
|
| + reader->lastDeviceMotionData(data); |
| + m_lastDeviceMotionData = PassRefPtr<WebCore::DeviceMotionData>(data); |
| + |
| + if (shouldFireEvent()) |
| + DeviceMotionController::shared().didChangeDeviceMotion(m_lastDeviceMotionData.get()); |
|
Peter Beverloo
2013/04/09 17:29:53
It's a bit odd that we update m_lastFireEventTimeM
timvolodine
2013/04/10 19:06:12
the if (shouldFireEvent()) is meant as an optimiza
|
| + |
| + scheduleFireEvent(); |
| +} |
| + |
| +void WebDeviceMotionEventPump::scheduleFireEvent() |
| +{ |
| + if (m_pumpTimer.isActive()) |
| + return; |
| + double scheduleDelay = std::max<double>(m_delaySeconds - (monotonicallyIncreasingTime() - m_lastFireEventTimeMonotonic), 0); |
|
Peter Beverloo
2013/04/09 17:29:53
nit: newline above this for readability.
Peter Beverloo
2013/04/09 17:29:53
This also assumes we'll fire at 10Hz for Device Mo
timvolodine
2013/04/10 19:06:12
Done.
timvolodine
2013/04/10 19:06:12
we can change the delay value as we want, but for
|
| + m_pumpTimer.startOneShot(scheduleDelay); |
| +} |
| + |
| +WebCore::DeviceMotionData* WebDeviceMotionEventPump::lastDeviceMotionData() |
|
Peter Beverloo
2013/04/09 17:29:53
The pointer ownership situation is a bit unclear h
timvolodine
2013/04/10 19:06:12
ok, done.
|
| +{ |
| + return m_lastDeviceMotionData.get(); |
| +} |
| + |
| +bool WebDeviceMotionEventPump::shouldFireEvent() |
| +{ |
| + // TODO(timvolodine): motion event should be fired only when values are different from the values |
|
Peter Beverloo
2013/04/09 17:29:53
nit: Blink style uses unattribute FIXMEs.
timvolodine
2013/04/10 19:06:12
Done.
|
| + // of the previously fired event. |
| + return true; |
| +} |
| + |
| +void WebDeviceMotionEventPump::start() |
| +{ |
| + WebDeviceMotionReader* reader = WebKit::Platform::current()->deviceMotionReader(); |
|
Peter Beverloo
2013/04/09 17:29:53
Needs a NULL check.
timvolodine
2013/04/10 19:06:12
Done.
|
| + reader->startUpdating(); |
| + m_stopped = false; |
| + scheduleFireEvent(); |
| +} |
| + |
| +void WebDeviceMotionEventPump::stop() |
| +{ |
| + WebDeviceMotionReader* reader = WebKit::Platform::current()->deviceMotionReader(); |
|
Peter Beverloo
2013/04/09 17:29:53
Needs a NULL check.
timvolodine
2013/04/10 19:06:12
Done.
|
| + reader->stopUpdating(); |
| + m_stopped = true; |
| +} |
| + |
| +} // namespace WebKit |