Index: Source/modules/vibration/NavigatorVibration.cpp |
diff --git a/Source/modules/vibration/NavigatorVibration.cpp b/Source/modules/vibration/NavigatorVibration.cpp |
index b8fd026b8522b4fe913424749140cd41d38e458a..125411aef2237c7b14ffab463de473ea0cb8470a 100644 |
--- a/Source/modules/vibration/NavigatorVibration.cpp |
+++ b/Source/modules/vibration/NavigatorVibration.cpp |
@@ -47,30 +47,11 @@ NavigatorVibration::~NavigatorVibration() |
bool NavigatorVibration::vibrate(const VibrationPattern& pattern) |
{ |
- VibrationPattern sanitized = pattern; |
- size_t length = sanitized.size(); |
- |
- // If the pattern is too long then truncate it. |
- if (length > kVibrationPatternLengthMax) { |
- sanitized.shrink(kVibrationPatternLengthMax); |
- length = kVibrationPatternLengthMax; |
- } |
- |
- // If any pattern entry is too long then truncate it. |
- for (size_t i = 0; i < length; ++i) { |
- if (sanitized[i] > kVibrationDurationMax) |
- sanitized[i] = kVibrationDurationMax; |
- } |
- |
- // If the last item in the pattern is a pause then discard it. |
- if (length && !(length % 2)) |
- sanitized.removeLast(); |
- |
// Cancelling clears the stored pattern so do it before setting the new one. |
if (m_isVibrating) |
cancelVibration(); |
- m_pattern = sanitized; |
+ m_pattern = verifyVibrationPattern(pattern); |
if (m_timerStart.isActive()) |
m_timerStart.stop(); |
@@ -168,6 +149,30 @@ NavigatorVibration& NavigatorVibration::from(Page& page) |
return *navigatorVibration; |
} |
+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.
|
+{ |
+ VibrationPattern sanitized = pattern; |
+ size_t length = sanitized.size(); |
+ |
+ // If the pattern is too long then truncate it. |
+ if (length > kVibrationPatternLengthMax) { |
+ sanitized.shrink(kVibrationPatternLengthMax); |
+ length = kVibrationPatternLengthMax; |
+ } |
+ |
+ // If any pattern entry is too long then truncate it. |
+ for (size_t i = 0; i < length; ++i) { |
+ if (sanitized[i] > kVibrationDurationMax) |
+ sanitized[i] = kVibrationDurationMax; |
+ } |
+ |
+ // If the last item in the pattern is a pause then discard it. |
+ if (length && !(length % 2)) |
+ sanitized.removeLast(); |
+ |
+ return sanitized; |
+} |
+ |
const char* NavigatorVibration::supplementName() |
{ |
return "NavigatorVibration"; |