| 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/NavigatorVibration.h" | 21 #include "modules/vibration/NavigatorVibration.h" |
| 22 | 22 |
| 23 #include "core/page/Frame.h" | 23 #include "core/page/Frame.h" |
| 24 #include "core/page/Page.h" | 24 #include "core/page/Page.h" |
| 25 #include "public/platform/Platform.h" | 25 #include "public/platform/Platform.h" |
| 26 #include "public/platform/WebVibration.h" |
| 26 | 27 |
| 27 namespace WebCore { | 28 namespace WebCore { |
| 28 | 29 |
| 29 // Maximum duration of a vibration is 10 seconds. | |
| 30 const unsigned kVibrationDurationMax = 10000; | |
| 31 | |
| 32 // Maximum number of entries in a vibration pattern. | 30 // Maximum number of entries in a vibration pattern. |
| 33 const unsigned kVibrationPatternLengthMax = 99; | 31 const unsigned kVibrationPatternLengthMax = 99; |
| 34 | 32 |
| 35 NavigatorVibration::NavigatorVibration() | 33 NavigatorVibration::NavigatorVibration() |
| 36 : m_timerStart(this, &NavigatorVibration::timerStartFired) | 34 : m_timerStart(this, &NavigatorVibration::timerStartFired) |
| 37 , m_timerStop(this, &NavigatorVibration::timerStopFired) | 35 , m_timerStop(this, &NavigatorVibration::timerStopFired) |
| 38 , m_isVibrating(false) | 36 , m_isVibrating(false) |
| 39 { | 37 { |
| 40 } | 38 } |
| 41 | 39 |
| 42 NavigatorVibration::~NavigatorVibration() | 40 NavigatorVibration::~NavigatorVibration() |
| 43 { | 41 { |
| 44 if (m_isVibrating) | 42 if (m_isVibrating) |
| 45 cancelVibration(); | 43 cancelVibration(); |
| 46 } | 44 } |
| 47 | 45 |
| 48 bool NavigatorVibration::vibrate(const VibrationPattern& pattern) | 46 bool NavigatorVibration::vibrate(const VibrationPattern& pattern) |
| 49 { | 47 { |
| 50 size_t length = pattern.size(); | 48 size_t length = pattern.size(); |
| 51 | 49 |
| 52 // If the pattern is too long then abort. | 50 // If the pattern is too long then abort. |
| 53 if (length > kVibrationPatternLengthMax) | 51 if (length > kVibrationPatternLengthMax) |
| 54 return false; | 52 return false; |
| 55 | 53 |
| 56 // If any pattern entry is too long then abort. | 54 // If any pattern entry is too long then abort. |
| 57 for (size_t i = 0; i < length; ++i) { | 55 for (size_t i = 0; i < length; ++i) { |
| 58 if (pattern[i] > kVibrationDurationMax) | 56 if (pattern[i] > WebKit::kVibrationDurationMax) |
| 59 return false; | 57 return false; |
| 60 } | 58 } |
| 61 | 59 |
| 62 // Cancelling clears the pattern so do this before setting the new pattern. | 60 // Cancelling clears the pattern so do this before setting the new pattern. |
| 63 if (m_isVibrating) | 61 if (m_isVibrating) |
| 64 cancelVibration(); | 62 cancelVibration(); |
| 65 | 63 |
| 66 // If the last item in the pattern is a pause then discard it. | 64 // If the last item in the pattern is a pause then discard it. |
| 67 if (length && !(length % 2)) { | 65 if (length && !(length % 2)) { |
| 68 VibrationPattern tempPattern = pattern; | 66 VibrationPattern tempPattern = pattern; |
| (...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 165 } | 163 } |
| 166 return navigatorVibration; | 164 return navigatorVibration; |
| 167 } | 165 } |
| 168 | 166 |
| 169 const char* NavigatorVibration::supplementName() | 167 const char* NavigatorVibration::supplementName() |
| 170 { | 168 { |
| 171 return "NavigatorVibration"; | 169 return "NavigatorVibration"; |
| 172 } | 170 } |
| 173 | 171 |
| 174 } // namespace WebCore | 172 } // namespace WebCore |
| OLD | NEW |