2
* Copyright (C) 2012 Samsung Electronics
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.
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.
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.
21
#include "Vibration.h"
25
#include "VibrationClient.h"
29
Vibration::Vibration(VibrationClient* client)
30
: m_vibrationClient(client)
31
, m_timerStart(this, &Vibration::timerStartFired)
32
, m_timerStop(this, &Vibration::timerStopFired)
33
, m_isVibrating(false)
37
Vibration::~Vibration()
39
m_vibrationClient->vibrationDestroyed();
42
PassOwnPtr<Vibration> Vibration::create(VibrationClient* client)
44
return adoptPtr(new Vibration(client));
47
void Vibration::vibrate(const unsigned long& time)
53
m_pattern.append(time);
54
m_timerStart.startOneShot(0);
57
void Vibration::vibrate(const VibrationPattern& pattern)
59
int length = pattern.size();
61
// Cancel the pre-existing instance of vibration patterns, if the pattern is 0 or an empty list.
62
if (!length || (length == 1 && !pattern[0])) {
70
if (m_timerStart.isActive())
74
m_timerStart.startOneShot(0);
77
void Vibration::cancelVibration()
81
m_vibrationClient->cancelVibration();
82
m_isVibrating = false;
87
void Vibration::suspendVibration()
92
m_pattern.insert(0, m_timerStop.nextFireInterval());
97
void Vibration::resumeVibration()
99
m_timerStart.startOneShot(0);
102
void Vibration::timerStartFired(Timer<Vibration>* timer)
104
ASSERT_UNUSED(timer, timer == &m_timerStart);
108
if (m_pattern.size()) {
109
m_isVibrating = true;
110
m_vibrationClient->vibrate(m_pattern[0]);
111
m_timerStop.startOneShot(m_pattern[0] / 1000.0);
116
void Vibration::timerStopFired(Timer<Vibration>* timer)
118
ASSERT_UNUSED(timer, timer == &m_timerStop);
121
m_isVibrating = false;
123
if (m_pattern.size()) {
124
m_timerStart.startOneShot(m_pattern[0] / 1000.0);
129
const AtomicString& Vibration::supplementName()
131
DEFINE_STATIC_LOCAL(AtomicString, name, ("Vibration", AtomicString::ConstructFromLiteral));
135
bool Vibration::isActive(Page* page)
137
return static_cast<bool>(Vibration::from(page));
140
void provideVibrationTo(Page* page, VibrationClient* client)
142
Vibration::provideTo(page, Vibration::supplementName(), Vibration::create(client));
145
} // namespace WebCore
147
#endif // ENABLE(VIBRATION)