Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1521)

Unified Diff: Source/modules/vibration/NavigatorVibration.cpp

Issue 1042513002: Add the vibrate attribute to the Notification object (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Created 5 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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";

Powered by Google App Engine
This is Rietveld 408576698