Repository navigation
Expand file tree
/
Copy pathvariable.dart
More file actions
56 lines (48 loc) · 1.65 KB
/
Copy pathvariable.dart
File metadata and controls
56 lines (48 loc) · 1.65 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
/*
* Copyright (C) 2019-2022 The Kraken authors. All rights reserved.
* Copyright (C) 2022-present The WebF authors. All rights reserved.
*/
import 'dart:collection';
import 'render_style.dart';
mixin CSSVariableMixin on RenderStyle {
Map<String, String>? _storage;
final Map<String, List<String>> _propertyDependencies = {};
void _addDependency(String identifier, String propertyName) {
List<String>? dep = _propertyDependencies[identifier];
if (dep == null) {
_propertyDependencies[identifier] = [propertyName];
} else if (!dep.contains(propertyName)) {
dep.add(propertyName);
}
}
@override
String? getCSSVariable(String identifier, String propertyName) {
Map<String, String>? storage = _storage;
_addDependency(identifier, propertyName);
if (storage != null && storage.containsKey(identifier)) {
return storage[identifier];
} else {
// Inherits from renderStyle tree.
return parent?.getCSSVariable(identifier, propertyName);
}
}
// --x: red
// key: --x
// value: red
@override
void setCSSVariable(String identifier, String value) {
_storage ??= HashMap<String, String>();
_storage![identifier] = value;
if (_propertyDependencies.containsKey(identifier)) {
_notifyCSSVariableChanged(_propertyDependencies[identifier]!, value);
}
}
void _notifyCSSVariableChanged(List<String> propertyNames, String value) {
propertyNames.forEach((String propertyName) {
target.setRenderStyle(propertyName, value);
visitChildren((CSSRenderStyle childRenderStyle) {
childRenderStyle._notifyCSSVariableChanged(propertyNames, value);
});
});
}
}