OLD | NEW |
1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file |
2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
4 | 4 |
5 // TODO(jacobr): cache these results. | 5 // TODO(jacobr): cache these results. |
6 // TODO(jacobr): figure out how to test this. | 6 // TODO(jacobr): figure out how to test this. |
7 /** | 7 /** |
8 * Utils for device detection. | 8 * Utils for device detection. |
9 */ | 9 */ |
10 class Device { | 10 class Device { |
(...skipping 11 matching lines...) Expand all Loading... |
22 /** | 22 /** |
23 * The regular expression for detecting an iPhone or iPod or iPad simulator. | 23 * The regular expression for detecting an iPhone or iPod or iPad simulator. |
24 */ | 24 */ |
25 static const _APPLE_SIM_REGEX = const RegExp('iP.*Simulator'); | 25 static const _APPLE_SIM_REGEX = const RegExp('iP.*Simulator'); |
26 | 26 |
27 /** | 27 /** |
28 * Gets the browser's user agent. Using this function allows tests to inject | 28 * Gets the browser's user agent. Using this function allows tests to inject |
29 * the user agent. | 29 * the user agent. |
30 * Returns the user agent. | 30 * Returns the user agent. |
31 */ | 31 */ |
32 static String get userAgent() => window.navigator.userAgent; | 32 static String get userAgent => window.navigator.userAgent; |
33 | 33 |
34 /** | 34 /** |
35 * Determines if the current device is an iPhone or iPod. | 35 * Determines if the current device is an iPhone or iPod. |
36 * Returns true if the current device is an iPhone or iPod. | 36 * Returns true if the current device is an iPhone or iPod. |
37 */ | 37 */ |
38 static bool get isIPhone() => _IPHONE_REGEX.hasMatch(userAgent); | 38 static bool get isIPhone => _IPHONE_REGEX.hasMatch(userAgent); |
39 | 39 |
40 /** | 40 /** |
41 * Determines if the current device is an iPad. | 41 * Determines if the current device is an iPad. |
42 * Returns true if the current device is an iPad. | 42 * Returns true if the current device is an iPad. |
43 */ | 43 */ |
44 static bool get isIPad() => userAgent.contains("iPad", 0); | 44 static bool get isIPad => userAgent.contains("iPad", 0); |
45 | 45 |
46 /** | 46 /** |
47 * Determines if the current device is running Firefox. | 47 * Determines if the current device is running Firefox. |
48 */ | 48 */ |
49 static bool get isFirefox() => userAgent.contains("Firefox", 0); | 49 static bool get isFirefox => userAgent.contains("Firefox", 0); |
50 | 50 |
51 /** | 51 /** |
52 * Determines if the current device is an iPhone or iPod or iPad. | 52 * Determines if the current device is an iPhone or iPod or iPad. |
53 * Returns true if the current device is an iPhone or iPod or iPad. | 53 * Returns true if the current device is an iPhone or iPod or iPad. |
54 */ | 54 */ |
55 static bool get isMobileSafari() => _MOBILE_SAFARI_REGEX.hasMatch(userAgent); | 55 static bool get isMobileSafari => _MOBILE_SAFARI_REGEX.hasMatch(userAgent); |
56 | 56 |
57 /** | 57 /** |
58 * Determines if the current device is the iP* Simulator. | 58 * Determines if the current device is the iP* Simulator. |
59 * Returns true if the current device is an iP* Simulator. | 59 * Returns true if the current device is an iP* Simulator. |
60 */ | 60 */ |
61 static bool get isAppleSimulator() => _APPLE_SIM_REGEX.hasMatch(userAgent); | 61 static bool get isAppleSimulator => _APPLE_SIM_REGEX.hasMatch(userAgent); |
62 | 62 |
63 /** | 63 /** |
64 * Determines if the current device is an Android. | 64 * Determines if the current device is an Android. |
65 * Returns true if the current device is an Android. | 65 * Returns true if the current device is an Android. |
66 */ | 66 */ |
67 static bool get isAndroid() => userAgent.contains("Android", 0); | 67 static bool get isAndroid => userAgent.contains("Android", 0); |
68 | 68 |
69 /** | 69 /** |
70 * Determines if the current device is WebOS WebKit. | 70 * Determines if the current device is WebOS WebKit. |
71 * Returns true if the current device is WebOS WebKit. | 71 * Returns true if the current device is WebOS WebKit. |
72 */ | 72 */ |
73 static bool get isWebOs() => userAgent.contains("webOS", 0); | 73 static bool get isWebOs => userAgent.contains("webOS", 0); |
74 | 74 |
75 static bool _supportsTouch; | 75 static bool _supportsTouch; |
76 static bool get supportsTouch() { | 76 static bool get supportsTouch { |
77 if (_supportsTouch == null) { | 77 if (_supportsTouch == null) { |
78 _supportsTouch = isMobileSafari || isAndroid; | 78 _supportsTouch = isMobileSafari || isAndroid; |
79 } | 79 } |
80 return _supportsTouch; | 80 return _supportsTouch; |
81 } | 81 } |
82 } | 82 } |
OLD | NEW |