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

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, 8 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..5cfab2e00b986a280c51b99f0dde61f39167f14c 100644
--- a/Source/modules/vibration/NavigatorVibration.cpp
+++ b/Source/modules/vibration/NavigatorVibration.cpp
@@ -20,34 +20,19 @@
#include "config.h"
#include "modules/vibration/NavigatorVibration.h"
+#include "bindings/modules/v8/UnionTypesModules.h"
#include "core/frame/LocalFrame.h"
#include "core/frame/Navigator.h"
#include "core/page/PageVisibilityState.h"
#include "public/platform/Platform.h"
#include "public/platform/WebVibration.h"
-namespace blink {
-
// Maximum number of entries in a vibration pattern.
const unsigned kVibrationPatternLengthMax = 99;
-NavigatorVibration::NavigatorVibration(Page& page)
- : PageLifecycleObserver(&page)
- , m_timerStart(this, &NavigatorVibration::timerStartFired)
- , m_timerStop(this, &NavigatorVibration::timerStopFired)
- , m_isVibrating(false)
-{
-}
-
-NavigatorVibration::~NavigatorVibration()
+blink::NavigatorVibration::VibrationPattern sanitizeVibrationPatternInternal(const blink::NavigatorVibration::VibrationPattern& pattern)
{
- if (m_isVibrating)
- cancelVibration();
-}
-
-bool NavigatorVibration::vibrate(const VibrationPattern& pattern)
-{
- VibrationPattern sanitized = pattern;
+ blink::NavigatorVibration::VibrationPattern sanitized = pattern;
size_t length = sanitized.size();
// If the pattern is too long then truncate it.
@@ -58,19 +43,52 @@ bool NavigatorVibration::vibrate(const VibrationPattern& pattern)
// 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 (sanitized[i] > blink::kVibrationDurationMax)
+ sanitized[i] = blink::kVibrationDurationMax;
}
// If the last item in the pattern is a pause then discard it.
if (length && !(length % 2))
sanitized.removeLast();
+ return sanitized;
+}
+
+namespace blink {
+
+NavigatorVibration::VibrationPattern NavigatorVibration::sanitizeVibrationPattern(const UnsignedLongOrUnsignedLongSequence& pattern)
+{
+ VibrationPattern sanitized;
+
+ if (pattern.isUnsignedLong())
+ sanitized.append(pattern.getAsUnsignedLong());
+ else if (pattern.isUnsignedLongSequence())
+ sanitized = pattern.getAsUnsignedLongSequence();
+
+ return sanitizeVibrationPatternInternal(sanitized);
+}
+
+NavigatorVibration::NavigatorVibration(Page& page)
+ : PageLifecycleObserver(&page)
+ , m_timerStart(this, &NavigatorVibration::timerStartFired)
+ , m_timerStop(this, &NavigatorVibration::timerStopFired)
+ , m_isVibrating(false)
+{
+}
+
+NavigatorVibration::~NavigatorVibration()
+{
+ if (m_isVibrating)
+ cancelVibration();
+}
+
+bool NavigatorVibration::vibrate(const VibrationPattern& pattern)
+{
// Cancelling clears the stored pattern so do it before setting the new one.
if (m_isVibrating)
cancelVibration();
- m_pattern = sanitized;
+ m_pattern = sanitizeVibrationPatternInternal(pattern);
if (m_timerStart.isActive())
m_timerStart.stop();
« no previous file with comments | « Source/modules/vibration/NavigatorVibration.h ('k') | public/platform/modules/notifications/WebNotificationData.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698