| 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 |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 51 size_t length = sanitized.size(); | 51 size_t length = sanitized.size(); |
| 52 | 52 |
| 53 // If the pattern is too long then truncate it. | 53 // If the pattern is too long then truncate it. |
| 54 if (length > kVibrationPatternLengthMax) { | 54 if (length > kVibrationPatternLengthMax) { |
| 55 sanitized.shrink(kVibrationPatternLengthMax); | 55 sanitized.shrink(kVibrationPatternLengthMax); |
| 56 length = kVibrationPatternLengthMax; | 56 length = kVibrationPatternLengthMax; |
| 57 } | 57 } |
| 58 | 58 |
| 59 // If any pattern entry is too long then truncate it. | 59 // If any pattern entry is too long then truncate it. |
| 60 for (size_t i = 0; i < length; ++i) { | 60 for (size_t i = 0; i < length; ++i) { |
| 61 if (sanitized[i] > blink::kVibrationDurationMax) | 61 if (sanitized[i] > kVibrationDurationMax) |
| 62 sanitized[i] = blink::kVibrationDurationMax; | 62 sanitized[i] = kVibrationDurationMax; |
| 63 } | 63 } |
| 64 | 64 |
| 65 // If the last item in the pattern is a pause then discard it. | 65 // If the last item in the pattern is a pause then discard it. |
| 66 if (length && !(length % 2)) | 66 if (length && !(length % 2)) |
| 67 sanitized.removeLast(); | 67 sanitized.removeLast(); |
| 68 | 68 |
| 69 // Cancelling clears the stored pattern so do it before setting the new one. | 69 // Cancelling clears the stored pattern so do it before setting the new one. |
| 70 if (m_isVibrating) | 70 if (m_isVibrating) |
| 71 cancelVibration(); | 71 cancelVibration(); |
| 72 | 72 |
| (...skipping 12 matching lines...) Expand all Loading... |
| 85 | 85 |
| 86 m_timerStart.startOneShot(0, FROM_HERE); | 86 m_timerStart.startOneShot(0, FROM_HERE); |
| 87 m_isVibrating = true; | 87 m_isVibrating = true; |
| 88 return true; | 88 return true; |
| 89 } | 89 } |
| 90 | 90 |
| 91 void NavigatorVibration::cancelVibration() | 91 void NavigatorVibration::cancelVibration() |
| 92 { | 92 { |
| 93 m_pattern.clear(); | 93 m_pattern.clear(); |
| 94 if (m_isVibrating) { | 94 if (m_isVibrating) { |
| 95 blink::Platform::current()->cancelVibration(); | 95 Platform::current()->cancelVibration(); |
| 96 m_isVibrating = false; | 96 m_isVibrating = false; |
| 97 m_timerStop.stop(); | 97 m_timerStop.stop(); |
| 98 } | 98 } |
| 99 } | 99 } |
| 100 | 100 |
| 101 void NavigatorVibration::timerStartFired(Timer<NavigatorVibration>* timer) | 101 void NavigatorVibration::timerStartFired(Timer<NavigatorVibration>* timer) |
| 102 { | 102 { |
| 103 ASSERT_UNUSED(timer, timer == &m_timerStart); | 103 ASSERT_UNUSED(timer, timer == &m_timerStart); |
| 104 | 104 |
| 105 if (m_pattern.size()) { | 105 if (m_pattern.size()) { |
| 106 m_isVibrating = true; | 106 m_isVibrating = true; |
| 107 blink::Platform::current()->vibrate(m_pattern[0]); | 107 Platform::current()->vibrate(m_pattern[0]); |
| 108 m_timerStop.startOneShot(m_pattern[0] / 1000.0, FROM_HERE); | 108 m_timerStop.startOneShot(m_pattern[0] / 1000.0, FROM_HERE); |
| 109 m_pattern.remove(0); | 109 m_pattern.remove(0); |
| 110 } | 110 } |
| 111 } | 111 } |
| 112 | 112 |
| 113 void NavigatorVibration::timerStopFired(Timer<NavigatorVibration>* timer) | 113 void NavigatorVibration::timerStopFired(Timer<NavigatorVibration>* timer) |
| 114 { | 114 { |
| 115 ASSERT_UNUSED(timer, timer == &m_timerStop); | 115 ASSERT_UNUSED(timer, timer == &m_timerStop); |
| 116 | 116 |
| 117 if (m_pattern.isEmpty()) | 117 if (m_pattern.isEmpty()) |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 167 } | 167 } |
| 168 return *navigatorVibration; | 168 return *navigatorVibration; |
| 169 } | 169 } |
| 170 | 170 |
| 171 const char* NavigatorVibration::supplementName() | 171 const char* NavigatorVibration::supplementName() |
| 172 { | 172 { |
| 173 return "NavigatorVibration"; | 173 return "NavigatorVibration"; |
| 174 } | 174 } |
| 175 | 175 |
| 176 } // namespace blink | 176 } // namespace blink |
| OLD | NEW |