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

Side by Side Diff: Source/modules/vibration/NavigatorVibration.cpp

Issue 1127713005: Change kVibrationDurationMax to be file-local to NavigatorVibration. (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: commenst Created 5 years, 7 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | public/platform/WebVibration.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Library General Public License for more details. 12 * Library General Public License for more details.
13 * 13 *
14 * You should have received a copy of the GNU Library General Public License 14 * You should have received a copy of the GNU Library General Public License
15 * along with this library; see the file COPYING.LIB. If not, write to 15 * along with this library; see the file COPYING.LIB. If not, write to
16 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 16 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17 * Boston, MA 02110-1301, USA. 17 * Boston, MA 02110-1301, USA.
18 */ 18 */
19 19
20 #include "config.h" 20 #include "config.h"
21 #include "modules/vibration/NavigatorVibration.h" 21 #include "modules/vibration/NavigatorVibration.h"
22 22
23 #include "bindings/modules/v8/UnionTypesModules.h" 23 #include "bindings/modules/v8/UnionTypesModules.h"
24 #include "core/frame/LocalFrame.h" 24 #include "core/frame/LocalFrame.h"
25 #include "core/frame/Navigator.h" 25 #include "core/frame/Navigator.h"
26 #include "core/page/PageVisibilityState.h" 26 #include "core/page/PageVisibilityState.h"
27 #include "public/platform/Platform.h" 27 #include "public/platform/Platform.h"
28 #include "public/platform/WebVibration.h"
29 28
30 // Maximum number of entries in a vibration pattern. 29 // Maximum number of entries in a vibration pattern.
31 const unsigned kVibrationPatternLengthMax = 99; 30 const unsigned kVibrationPatternLengthMax = 99;
32 31
32 // Maximum duration of a vibration is 10 seconds.
33 const unsigned kVibrationDurationMsMax = 10000;
34
33 blink::NavigatorVibration::VibrationPattern sanitizeVibrationPatternInternal(con st blink::NavigatorVibration::VibrationPattern& pattern) 35 blink::NavigatorVibration::VibrationPattern sanitizeVibrationPatternInternal(con st blink::NavigatorVibration::VibrationPattern& pattern)
34 { 36 {
35 blink::NavigatorVibration::VibrationPattern sanitized = pattern; 37 blink::NavigatorVibration::VibrationPattern sanitized = pattern;
36 size_t length = sanitized.size(); 38 size_t length = sanitized.size();
37 39
38 // If the pattern is too long then truncate it. 40 // If the pattern is too long then truncate it.
39 if (length > kVibrationPatternLengthMax) { 41 if (length > kVibrationPatternLengthMax) {
40 sanitized.shrink(kVibrationPatternLengthMax); 42 sanitized.shrink(kVibrationPatternLengthMax);
41 length = kVibrationPatternLengthMax; 43 length = kVibrationPatternLengthMax;
42 } 44 }
43 45
44 // If any pattern entry is too long then truncate it. 46 // If any pattern entry is too long then truncate it.
45 for (size_t i = 0; i < length; ++i) { 47 for (size_t i = 0; i < length; ++i) {
46 if (sanitized[i] > blink::kVibrationDurationMax) 48 if (sanitized[i] > kVibrationDurationMsMax)
47 sanitized[i] = blink::kVibrationDurationMax; 49 sanitized[i] = kVibrationDurationMsMax;
48 } 50 }
49 51
50 // If the last item in the pattern is a pause then discard it. 52 // If the last item in the pattern is a pause then discard it.
51 if (length && !(length % 2)) 53 if (length && !(length % 2))
52 sanitized.removeLast(); 54 sanitized.removeLast();
53 55
54 return sanitized; 56 return sanitized;
55 } 57 }
56 58
57 namespace blink { 59 namespace blink {
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after
191 return "NavigatorVibration"; 193 return "NavigatorVibration";
192 } 194 }
193 195
194 DEFINE_TRACE(NavigatorVibration) 196 DEFINE_TRACE(NavigatorVibration)
195 { 197 {
196 WillBeHeapSupplement<Page>::trace(visitor); 198 WillBeHeapSupplement<Page>::trace(visitor);
197 PageLifecycleObserver::trace(visitor); 199 PageLifecycleObserver::trace(visitor);
198 } 200 }
199 201
200 } // namespace blink 202 } // namespace blink
OLDNEW
« no previous file with comments | « no previous file | public/platform/WebVibration.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698