Chromium Code Reviews| 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 29 matching lines...) Expand all Loading... | |
| 40 } | 40 } |
| 41 | 41 |
| 42 NavigatorVibration::~NavigatorVibration() | 42 NavigatorVibration::~NavigatorVibration() |
| 43 { | 43 { |
| 44 if (m_isVibrating) | 44 if (m_isVibrating) |
| 45 cancelVibration(); | 45 cancelVibration(); |
| 46 } | 46 } |
| 47 | 47 |
| 48 bool NavigatorVibration::vibrate(const VibrationPattern& pattern) | 48 bool NavigatorVibration::vibrate(const VibrationPattern& pattern) |
| 49 { | 49 { |
| 50 VibrationPattern sanitized = pattern; | |
| 51 size_t length = sanitized.size(); | |
| 52 | |
| 53 // If the pattern is too long then truncate it. | |
| 54 if (length > kVibrationPatternLengthMax) { | |
| 55 sanitized.shrink(kVibrationPatternLengthMax); | |
| 56 length = kVibrationPatternLengthMax; | |
| 57 } | |
| 58 | |
| 59 // If any pattern entry is too long then truncate it. | |
| 60 for (size_t i = 0; i < length; ++i) { | |
| 61 if (sanitized[i] > kVibrationDurationMax) | |
| 62 sanitized[i] = kVibrationDurationMax; | |
| 63 } | |
| 64 | |
| 65 // If the last item in the pattern is a pause then discard it. | |
| 66 if (length && !(length % 2)) | |
| 67 sanitized.removeLast(); | |
| 68 | |
| 69 // Cancelling clears the stored pattern so do it before setting the new one. | 50 // Cancelling clears the stored pattern so do it before setting the new one. |
| 70 if (m_isVibrating) | 51 if (m_isVibrating) |
| 71 cancelVibration(); | 52 cancelVibration(); |
| 72 | 53 |
| 73 m_pattern = sanitized; | 54 m_pattern = verifyVibrationPattern(pattern); |
| 74 | 55 |
| 75 if (m_timerStart.isActive()) | 56 if (m_timerStart.isActive()) |
| 76 m_timerStart.stop(); | 57 m_timerStart.stop(); |
| 77 | 58 |
| 78 if (!m_pattern.size()) | 59 if (!m_pattern.size()) |
| 79 return true; | 60 return true; |
| 80 | 61 |
| 81 if (m_pattern.size() == 1 && !m_pattern[0]) { | 62 if (m_pattern.size() == 1 && !m_pattern[0]) { |
| 82 m_pattern.clear(); | 63 m_pattern.clear(); |
| 83 return true; | 64 return true; |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 161 NavigatorVibration& NavigatorVibration::from(Page& page) | 142 NavigatorVibration& NavigatorVibration::from(Page& page) |
| 162 { | 143 { |
| 163 NavigatorVibration* navigatorVibration = static_cast<NavigatorVibration*>(Wi llBeHeapSupplement<Page>::from(page, supplementName())); | 144 NavigatorVibration* navigatorVibration = static_cast<NavigatorVibration*>(Wi llBeHeapSupplement<Page>::from(page, supplementName())); |
| 164 if (!navigatorVibration) { | 145 if (!navigatorVibration) { |
| 165 navigatorVibration = new NavigatorVibration(page); | 146 navigatorVibration = new NavigatorVibration(page); |
| 166 WillBeHeapSupplement<Page>::provideTo(page, supplementName(), adoptPtrWi llBeNoop(navigatorVibration)); | 147 WillBeHeapSupplement<Page>::provideTo(page, supplementName(), adoptPtrWi llBeNoop(navigatorVibration)); |
| 167 } | 148 } |
| 168 return *navigatorVibration; | 149 return *navigatorVibration; |
| 169 } | 150 } |
| 170 | 151 |
| 152 NavigatorVibration::VibrationPattern NavigatorVibration::verifyVibrationPattern( const VibrationPattern& pattern) | |
|
Peter Beverloo
2015/04/01 14:26:29
s/verify/sanitize? I'd expect a verifyFoo method t
Sanghyun Park
2015/04/01 17:46:08
Done.
| |
| 153 { | |
| 154 VibrationPattern sanitized = pattern; | |
| 155 size_t length = sanitized.size(); | |
| 156 | |
| 157 // If the pattern is too long then truncate it. | |
| 158 if (length > kVibrationPatternLengthMax) { | |
| 159 sanitized.shrink(kVibrationPatternLengthMax); | |
| 160 length = kVibrationPatternLengthMax; | |
| 161 } | |
| 162 | |
| 163 // If any pattern entry is too long then truncate it. | |
| 164 for (size_t i = 0; i < length; ++i) { | |
| 165 if (sanitized[i] > kVibrationDurationMax) | |
| 166 sanitized[i] = kVibrationDurationMax; | |
| 167 } | |
| 168 | |
| 169 // If the last item in the pattern is a pause then discard it. | |
| 170 if (length && !(length % 2)) | |
| 171 sanitized.removeLast(); | |
| 172 | |
| 173 return sanitized; | |
| 174 } | |
| 175 | |
| 171 const char* NavigatorVibration::supplementName() | 176 const char* NavigatorVibration::supplementName() |
| 172 { | 177 { |
| 173 return "NavigatorVibration"; | 178 return "NavigatorVibration"; |
| 174 } | 179 } |
| 175 | 180 |
| 176 DEFINE_TRACE(NavigatorVibration) | 181 DEFINE_TRACE(NavigatorVibration) |
| 177 { | 182 { |
| 178 WillBeHeapSupplement<Page>::trace(visitor); | 183 WillBeHeapSupplement<Page>::trace(visitor); |
| 179 PageLifecycleObserver::trace(visitor); | 184 PageLifecycleObserver::trace(visitor); |
| 180 } | 185 } |
| 181 | 186 |
| 182 } // namespace blink | 187 } // namespace blink |
| OLD | NEW |