Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 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 | |
| 3 // BSD-style license that can be found in the LICENSE file. | |
| 4 | |
| 5 part of html_common; | |
|
blois
2013/08/22 20:42:23
Not sure I understand this move- is this moving in
Emily Fortuna
2013/08/22 22:10:10
Only needed if this file calls _createEvent(eventT
blois
2013/08/23 15:55:06
It's not called too often and I'd like to keep thi
| |
| 6 | |
| 7 /** | |
| 8 * Utils for device detection. | |
| 9 */ | |
| 10 class Device { | |
| 11 static bool _isOpera; | |
| 12 static bool _isIE; | |
| 13 static bool _isFirefox; | |
| 14 static bool _isWebKit; | |
| 15 static String _cachedCssPrefix; | |
| 16 static String _cachedPropertyPrefix; | |
| 17 | |
| 18 /** | |
| 19 * Gets the browser's user agent. Using this function allows tests to inject | |
| 20 * the user agent. | |
| 21 * Returns the user agent. | |
| 22 */ | |
| 23 static String get userAgent => window.navigator.userAgent; | |
| 24 | |
| 25 /** | |
| 26 * Determines if the current device is running Opera. | |
| 27 */ | |
| 28 static bool get isOpera { | |
| 29 if (_isOpera == null) { | |
| 30 _isOpera = userAgent.contains("Opera", 0); | |
| 31 } | |
| 32 return _isOpera; | |
| 33 } | |
| 34 | |
| 35 /** | |
| 36 * Determines if the current device is running Internet Explorer. | |
| 37 */ | |
| 38 static bool get isIE { | |
| 39 if (_isIE == null) { | |
| 40 _isIE = !isOpera && userAgent.contains("MSIE", 0); | |
| 41 } | |
| 42 return _isIE; | |
| 43 } | |
| 44 | |
| 45 /** | |
| 46 * Determines if the current device is running Firefox. | |
| 47 */ | |
| 48 static bool get isFirefox { | |
| 49 if (_isFirefox == null) { | |
| 50 _isFirefox = userAgent.contains("Firefox", 0); | |
| 51 } | |
| 52 return _isFirefox; | |
| 53 } | |
| 54 | |
| 55 /** | |
| 56 * Determines if the current device is running WebKit. | |
| 57 */ | |
| 58 static bool get isWebKit { | |
| 59 if (_isWebKit == null) { | |
| 60 _isWebKit = !isOpera && userAgent.contains("WebKit", 0); | |
| 61 } | |
| 62 return _isWebKit; | |
| 63 } | |
| 64 | |
| 65 /** | |
| 66 * Gets the CSS property prefix for the current platform. | |
| 67 */ | |
| 68 static String get cssPrefix { | |
| 69 if (_cachedCssPrefix == null) { | |
| 70 if (isFirefox) { | |
| 71 _cachedCssPrefix = '-moz-'; | |
| 72 } else if (isIE) { | |
| 73 _cachedCssPrefix = '-ms-'; | |
| 74 } else if (isOpera) { | |
| 75 _cachedCssPrefix = '-o-'; | |
| 76 } else { | |
| 77 _cachedCssPrefix = '-webkit-'; | |
| 78 } | |
| 79 } | |
| 80 return _cachedCssPrefix; | |
| 81 } | |
| 82 | |
| 83 /** | |
| 84 * Prefix as used for JS property names. | |
| 85 */ | |
| 86 static String get propertyPrefix { | |
| 87 if (_cachedPropertyPrefix == null) { | |
| 88 if (isFirefox) { | |
| 89 _cachedPropertyPrefix = 'moz'; | |
| 90 } else if (isIE) { | |
| 91 _cachedPropertyPrefix = 'ms'; | |
| 92 } else if (isOpera) { | |
| 93 _cachedPropertyPrefix = 'o'; | |
| 94 } else { | |
| 95 _cachedPropertyPrefix = 'webkit'; | |
| 96 } | |
| 97 } | |
| 98 return _cachedPropertyPrefix; | |
| 99 } | |
| 100 | |
| 101 /** | |
| 102 * Checks to see if the event class is supported by the current platform. | |
| 103 */ | |
| 104 static bool isEventTypeSupported(String eventType) { | |
| 105 // Browsers throw for unsupported event names. | |
| 106 try { | |
| 107 var e = document.$dom_createEvent(eventType); | |
|
blois
2013/08/22 20:42:23
Should be able to replace with new Event.eventType
| |
| 108 return e is Event; | |
| 109 } catch (_) { } | |
| 110 return false; | |
| 111 } | |
| 112 } | |
| OLD | NEW |