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

Side by Side Diff: tool/input_sdk/lib/html/html_common/device.dart

Issue 1528613004: First cut of mini dart:html. (Closed) Base URL: https://github.com/dart-lang/dev_compiler.git@master
Patch Set: Fix build_sdk Created 5 years 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
OLDNEW
(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;
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("Trident/", 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 String prefix = _cachedCssPrefix;
70 if (prefix != null) return prefix;
71 if (isFirefox) {
72 prefix = '-moz-';
73 } else if (isIE) {
74 prefix = '-ms-';
75 } else if (isOpera) {
76 prefix = '-o-';
77 } else {
78 prefix = '-webkit-';
79 }
80 return _cachedCssPrefix = prefix;
81 }
82
83 /**
84 * Prefix as used for JS property names.
85 */
86 static String get propertyPrefix {
87 String prefix = _cachedPropertyPrefix;
88 if (prefix != null) return prefix;
89 if (isFirefox) {
90 prefix = 'moz';
91 } else if (isIE) {
92 prefix = 'ms';
93 } else if (isOpera) {
94 prefix = 'o';
95 } else {
96 prefix = 'webkit';
97 }
98 return _cachedPropertyPrefix = prefix;
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 = new Event.eventType(eventType, '');
108 return e is Event;
109 } catch (_) { }
110 return false;
111 }
112 }
OLDNEW
« no previous file with comments | « tool/input_sdk/lib/html/html_common/css_class_set.dart ('k') | tool/input_sdk/lib/html/html_common/filtered_element_list.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698