OLD | NEW |
1 | 1 |
2 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file | 2 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file |
3 // for details. All rights reserved. Use of this source code is governed by a | 3 // for details. All rights reserved. Use of this source code is governed by a |
4 // BSD-style license that can be found in the LICENSE file. | 4 // BSD-style license that can be found in the LICENSE file. |
5 | 5 |
6 // WARNING: DO NOT EDIT THIS TEMPLATE FILE. | 6 // WARNING: DO NOT EDIT THIS TEMPLATE FILE. |
7 // The template file was generated by scripts/css_code_generator.py | 7 // The template file was generated by scripts/css_code_generator.py |
8 | 8 |
9 // Source of CSS properties: | 9 // Source of CSS properties: |
10 // CSSPropertyNames.in | 10 // CSSPropertyNames.in |
(...skipping 10 matching lines...) Expand all Loading... |
21 return style; | 21 return style; |
22 } | 22 } |
23 | 23 |
24 /// Returns the value of the property if the provided *CSS* property | 24 /// Returns the value of the property if the provided *CSS* property |
25 /// name is supported on this element and if the value is set. Otherwise | 25 /// name is supported on this element and if the value is set. Otherwise |
26 /// returns an empty string. | 26 /// returns an empty string. |
27 /// | 27 /// |
28 /// Please note the property name uses camelCase, not-hyphens. | 28 /// Please note the property name uses camelCase, not-hyphens. |
29 String getPropertyValue(String propertyName) { | 29 String getPropertyValue(String propertyName) { |
30 var propValue = _getPropertyValueHelper(propertyName); | 30 var propValue = _getPropertyValueHelper(propertyName); |
31 return propValue != null ? propValue : ''; | 31 return propValue ?? ''; |
32 } | 32 } |
33 | 33 |
34 String _getPropertyValueHelper(String propertyName) { | 34 String _getPropertyValueHelper(String propertyName) { |
35 if (_supportsProperty(_camelCase(propertyName))) { | 35 return _getPropertyValue(_browserPropertyName(propertyName)); |
36 return _getPropertyValue(propertyName); | |
37 } else { | |
38 return _getPropertyValue(Device.cssPrefix + propertyName); | |
39 } | |
40 } | 36 } |
41 | 37 |
42 /** | 38 /** |
43 * Returns true if the provided *CSS* property name is supported on this | 39 * Returns true if the provided *CSS* property name is supported on this |
44 * element. | 40 * element. |
45 * | 41 * |
46 * Please note the property name camelCase, not-hyphens. This | 42 * Please note the property name camelCase, not-hyphens. This |
47 * method returns true if the property is accessible via an unprefixed _or_ | 43 * method returns true if the property is accessible via an unprefixed _or_ |
48 * prefixed property. | 44 * prefixed property. |
49 */ | 45 */ |
50 bool supportsProperty(String propertyName) { | 46 bool supportsProperty(String propertyName) { |
51 return _supportsProperty(propertyName) || | 47 return _supportsProperty(propertyName) || |
52 _supportsProperty(_camelCase(Device.cssPrefix + propertyName)); | 48 _supportsProperty(_camelCase("${Device.cssPrefix}$propertyName")); |
53 } | 49 } |
54 | 50 |
55 bool _supportsProperty(String propertyName) { | 51 bool _supportsProperty(String propertyName) { |
56 $if DART2JS | 52 $if DART2JS |
57 return JS('bool', '# in #', propertyName, this); | 53 return JS('bool', '# in #', propertyName, this); |
58 $else | 54 $else |
59 // You can't just check the value of a property, because there is no way | 55 // You can't just check the value of a property, because there is no way |
60 // to distinguish between property not being present in the browser and | 56 // to distinguish between property not being present in the browser and |
61 // not having a value at all. (Ultimately we'll want the native method to | 57 // not having a value at all. (Ultimately we'll want the native method to |
62 // return null if the property doesn't exist and empty string if it's | 58 // return null if the property doesn't exist and empty string if it's |
63 // defined but just doesn't have a value. | 59 // defined but just doesn't have a value. |
64 return _hasProperty(propertyName); | 60 return _hasProperty(propertyName); |
65 $endif | 61 $endif |
66 } | 62 } |
67 | 63 |
68 $if DARTIUM | 64 $if DARTIUM |
69 bool _hasProperty(String propertyName) => | 65 bool _hasProperty(String propertyName) => |
70 _blink.BlinkCSSStyleDeclaration.instance.$__get___propertyIsEnumerable_Cal
lback_1_(this, propertyName); | 66 _blink.BlinkCSSStyleDeclaration.instance.$__get___propertyIsEnumerable_Cal
lback_1_(this, propertyName); |
71 $endif | 67 $endif |
72 | 68 |
73 @DomName('CSSStyleDeclaration.setProperty') | 69 @DomName('CSSStyleDeclaration.setProperty') |
74 void setProperty(String propertyName, String value, [String priority]) { | 70 void setProperty(String propertyName, String value, [String priority]) { |
75 return _setPropertyHelper(_browserPropertyName(propertyName), | 71 return _setPropertyHelper(_browserPropertyName(propertyName), |
76 value, priority); | 72 value, priority); |
77 } | 73 } |
78 | 74 |
79 String _browserPropertyName(String propertyName) { | 75 String _browserPropertyName(String propertyName) { |
80 String name = _readCache(propertyName); | 76 String name = _readCache(propertyName); |
81 if (name is String) return name; | 77 if (name is String) return name; |
82 if (_supportsProperty(_camelCase(propertyName))) { | 78 name = _supportedBrowserPropertyName(propertyName); |
83 name = propertyName; | |
84 } else { | |
85 name = Device.cssPrefix + propertyName; | |
86 } | |
87 _writeCache(propertyName, name); | 79 _writeCache(propertyName, name); |
88 return name; | 80 return name; |
89 } | 81 } |
90 | 82 |
| 83 String _supportedBrowserPropertyName(String propertyName) { |
| 84 if (_supportsProperty(_camelCase(propertyName))) { |
| 85 return propertyName; |
| 86 } |
| 87 var prefixed = "${Device.cssPrefix}$propertyName"; |
| 88 if (_supportsProperty(prefixed)) { |
| 89 return prefixed; |
| 90 } |
| 91 // May be a CSS variable, just use it as provided. |
| 92 return propertyName; |
| 93 } |
| 94 |
91 $if DART2JS | 95 $if DART2JS |
92 static final _propertyCache = JS('', '{}'); | 96 static final _propertyCache = JS('', '{}'); |
93 static String _readCache(String key) => | 97 static String _readCache(String key) => |
94 JS('String|Null', '#[#]', _propertyCache, key); | 98 JS('String|Null', '#[#]', _propertyCache, key); |
95 static void _writeCache(String key, String value) { | 99 static void _writeCache(String key, String value) { |
96 JS('void', '#[#] = #', _propertyCache, key, value); | 100 JS('void', '#[#] = #', _propertyCache, key, value); |
97 } | 101 } |
98 $else | 102 $else |
99 static String _readCache(String key) => null; | 103 static String _readCache(String key) => null; |
100 static void _writeCache(String key, value) {} | 104 static void _writeCache(String key, value) {} |
(...skipping 4618 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4719 | 4723 |
4720 /** Gets the value of "zoom" */ | 4724 /** Gets the value of "zoom" */ |
4721 String get zoom => | 4725 String get zoom => |
4722 getPropertyValue('zoom'); | 4726 getPropertyValue('zoom'); |
4723 | 4727 |
4724 /** Sets the value of "zoom" */ | 4728 /** Sets the value of "zoom" */ |
4725 set zoom(String value) { | 4729 set zoom(String value) { |
4726 setProperty('zoom', value, ''); | 4730 setProperty('zoom', value, ''); |
4727 } | 4731 } |
4728 } | 4732 } |
OLD | NEW |