| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2012 Samsung Electronics | 2 * Copyright (C) 2012 Samsung Electronics |
| 3 * | 3 * |
| 4 * This library is free software; you can redistribute it and/or | 4 * This library is free software; you can redistribute it and/or |
| 5 * modify it under the terms of the GNU Library General Public | 5 * modify it under the terms of the GNU Library General Public |
| 6 * License as published by the Free Software Foundation; either | 6 * License as published by the Free Software Foundation; either |
| 7 * version 2 of the License, or (at your option) any later version. | 7 * version 2 of the License, or (at your option) any later version. |
| 8 * | 8 * |
| 9 * This library is distributed in the hope that it will be useful, | 9 * This library is distributed in the hope that it will be useful, |
| 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of | 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 12 * Library General Public License for more details. | 12 * Library General Public License for more details. |
| 13 * | 13 * |
| 14 * You should have received a copy of the GNU Library General Public License | 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 | 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, | 16 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, |
| 17 * Boston, MA 02110-1301, USA. | 17 * Boston, MA 02110-1301, USA. |
| 18 */ | 18 */ |
| 19 | 19 |
| 20 #include "config.h" | 20 #include "config.h" |
| 21 #include "modules/vibration/Vibration.h" | 21 #include "modules/vibration/Vibration.h" |
| 22 | 22 |
| 23 #if ENABLE(VIBRATION) | 23 #include "public/platform/Platform.h" |
| 24 | |
| 25 #include "modules/vibration/VibrationClient.h" | |
| 26 | 24 |
| 27 namespace WebCore { | 25 namespace WebCore { |
| 28 | 26 |
| 29 Vibration::Vibration(VibrationClient* client) | 27 Vibration::Vibration() |
| 30 : m_vibrationClient(client) | 28 : m_timerStart(this, &Vibration::timerStartFired) |
| 31 , m_timerStart(this, &Vibration::timerStartFired) | |
| 32 , m_timerStop(this, &Vibration::timerStopFired) | 29 , m_timerStop(this, &Vibration::timerStopFired) |
| 33 , m_isVibrating(false) | 30 , m_isVibrating(false) |
| 34 { | 31 { |
| 35 } | 32 } |
| 36 | 33 |
| 37 Vibration::~Vibration() | 34 Vibration::~Vibration() |
| 38 { | 35 { |
| 39 m_vibrationClient->vibrationDestroyed(); | 36 if (m_isVibrating) |
| 40 } | 37 cancelVibration(); |
| 41 | |
| 42 PassOwnPtr<Vibration> Vibration::create(VibrationClient* client) | |
| 43 { | |
| 44 return adoptPtr(new Vibration(client)); | |
| 45 } | 38 } |
| 46 | 39 |
| 47 void Vibration::vibrate(const unsigned& time) | 40 void Vibration::vibrate(const unsigned& time) |
| 48 { | 41 { |
| 49 if (!time) { | 42 if (!time) { |
| 50 cancelVibration(); | 43 cancelVibration(); |
| 51 return; | 44 return; |
| 52 } | 45 } |
| 53 m_pattern.append(time); | 46 m_pattern.append(time); |
| 54 m_timerStart.startOneShot(0); | 47 m_timerStart.startOneShot(0); |
| (...skipping 16 matching lines...) Expand all Loading... |
| 71 m_timerStart.stop(); | 64 m_timerStart.stop(); |
| 72 | 65 |
| 73 m_pattern = pattern; | 66 m_pattern = pattern; |
| 74 m_timerStart.startOneShot(0); | 67 m_timerStart.startOneShot(0); |
| 75 } | 68 } |
| 76 | 69 |
| 77 void Vibration::cancelVibration() | 70 void Vibration::cancelVibration() |
| 78 { | 71 { |
| 79 m_pattern.clear(); | 72 m_pattern.clear(); |
| 80 if (m_isVibrating) { | 73 if (m_isVibrating) { |
| 81 m_vibrationClient->cancelVibration(); | 74 WebKit::Platform::current()->cancelVibration(); |
| 82 m_isVibrating = false; | 75 m_isVibrating = false; |
| 83 m_timerStop.stop(); | 76 m_timerStop.stop(); |
| 84 } | 77 } |
| 85 } | 78 } |
| 86 | 79 |
| 87 void Vibration::suspendVibration() | 80 void Vibration::suspendVibration() |
| 88 { | 81 { |
| 89 if (!m_isVibrating) | 82 if (!m_isVibrating) |
| 90 return; | 83 return; |
| 91 | 84 |
| 92 m_pattern.insert(0, m_timerStop.nextFireInterval()); | 85 m_pattern.insert(0, m_timerStop.nextFireInterval()); |
| 93 m_timerStop.stop(); | 86 m_timerStop.stop(); |
| 94 cancelVibration(); | 87 cancelVibration(); |
| 95 } | 88 } |
| 96 | 89 |
| 97 void Vibration::resumeVibration() | 90 void Vibration::resumeVibration() |
| 98 { | 91 { |
| 99 m_timerStart.startOneShot(0); | 92 m_timerStart.startOneShot(0); |
| 100 } | 93 } |
| 101 | 94 |
| 102 void Vibration::timerStartFired(Timer<Vibration>* timer) | 95 void Vibration::timerStartFired(Timer<Vibration>* timer) |
| 103 { | 96 { |
| 104 ASSERT_UNUSED(timer, timer == &m_timerStart); | 97 ASSERT_UNUSED(timer, timer == &m_timerStart); |
| 105 | 98 |
| 106 m_timerStart.stop(); | 99 m_timerStart.stop(); |
| 107 | 100 |
| 108 if (m_pattern.size()) { | 101 if (m_pattern.size()) { |
| 109 m_isVibrating = true; | 102 m_isVibrating = true; |
| 110 m_vibrationClient->vibrate(m_pattern[0]); | 103 WebKit::Platform::current()->vibrate(m_pattern[0]); |
| 111 m_timerStop.startOneShot(m_pattern[0] / 1000.0); | 104 m_timerStop.startOneShot(m_pattern[0] / 1000.0); |
| 112 m_pattern.remove(0); | 105 m_pattern.remove(0); |
| 113 } | 106 } |
| 114 } | 107 } |
| 115 | 108 |
| 116 void Vibration::timerStopFired(Timer<Vibration>* timer) | 109 void Vibration::timerStopFired(Timer<Vibration>* timer) |
| 117 { | 110 { |
| 118 ASSERT_UNUSED(timer, timer == &m_timerStop); | 111 ASSERT_UNUSED(timer, timer == &m_timerStop); |
| 119 | 112 |
| 120 m_timerStop.stop(); | 113 m_timerStop.stop(); |
| 121 m_isVibrating = false; | 114 m_isVibrating = false; |
| 122 | 115 |
| 123 if (m_pattern.size()) { | 116 if (m_pattern.size()) { |
| 124 m_timerStart.startOneShot(m_pattern[0] / 1000.0); | 117 m_timerStart.startOneShot(m_pattern[0] / 1000.0); |
| 125 m_pattern.remove(0); | 118 m_pattern.remove(0); |
| 126 } | 119 } |
| 127 } | 120 } |
| 128 | 121 |
| 129 const char* Vibration::supplementName() | 122 const char* Vibration::supplementName() |
| 130 { | 123 { |
| 131 return "Vibration"; | 124 return "Vibration"; |
| 132 } | 125 } |
| 133 | 126 |
| 134 bool Vibration::isActive(Page* page) | 127 Vibration* Vibration::from(Page* page) |
| 135 { | 128 { |
| 136 return static_cast<bool>(Vibration::from(page)); | 129 if (!Supplement<Page>::from(page, supplementName())) |
| 137 } | 130 Supplement<Page>::provideTo(page, supplementName(), adoptPtr(new Vibrati
on())); |
| 138 | 131 return static_cast<Vibration*>(Supplement<Page>::from(page, supplementName()
)); |
| 139 void provideVibrationTo(Page* page, VibrationClient* client) | |
| 140 { | |
| 141 Vibration::provideTo(page, Vibration::supplementName(), Vibration::create(cl
ient)); | |
| 142 } | 132 } |
| 143 | 133 |
| 144 } // namespace WebCore | 134 } // namespace WebCore |
| 145 | |
| 146 #endif // ENABLE(VIBRATION) | |
| 147 | |
| OLD | NEW |