Skip to content

Commit

Permalink
feat: optimize recalculate style.
Browse files Browse the repository at this point in the history
  • Loading branch information
andycall committed Apr 7, 2024
1 parent 2f5c881 commit fd64918
Show file tree
Hide file tree
Showing 3 changed files with 1 addition and 33 deletions.
11 changes: 0 additions & 11 deletions webf/lib/src/bridge/ui_command.dart
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,6 @@ List<UICommand> nativeUICommandToDart(List<int> rawMemory, int commandLength, do

void execUICommands(WebFViewController view, List<UICommand> commands) {
Map<int, bool> pendingStylePropertiesTargets = {};
Set<int> pendingRecalculateTargets = {};

for(UICommand command in commands) {
UICommandType commandType = command.type;
Expand Down Expand Up @@ -268,7 +267,6 @@ void execUICommands(WebFViewController view, List<UICommand> commands) {
String key = nativeStringToString(nativeKey);
freeNativeString(nativeKey);
view.setAttribute(nativePtr.cast<NativeBindingObject>(), key, command.args);
pendingRecalculateTargets.add(nativePtr.address);
if (enableWebFProfileTracking) {
WebFProfiler.instance.finishTrackUICommandStep();
}
Expand Down Expand Up @@ -343,15 +341,6 @@ void execUICommands(WebFViewController view, List<UICommand> commands) {
WebFProfiler.instance.startTrackUICommandStep('FlushUICommand.recalculateStyle');
}

for (var address in pendingRecalculateTargets) {
try {
view.recalculateStyle(address);
} catch (e, stack) {
print('$e\n$stack');
}
}
pendingRecalculateTargets.clear();

if (enableWebFProfileTracking) {
WebFProfiler.instance.finishTrackUICommandStep();
}
Expand Down
11 changes: 1 addition & 10 deletions webf/lib/src/dom/element.dart
Original file line number Diff line number Diff line change
Expand Up @@ -207,8 +207,6 @@ abstract class Element extends ContainerNode with ElementBase, ElementEventMixin
updateRenderBoxModel();
}

bool _needRecalculateStyle = false;

final ElementRuleCollector _elementRuleCollector = ElementRuleCollector();

Element(BindingContext? context) : super(NodeType.ELEMENT_NODE, context) {
Expand Down Expand Up @@ -1361,13 +1359,11 @@ abstract class Element extends ContainerNode with ElementBase, ElementEventMixin

@mustCallSuper
void setAttribute(String qualifiedName, String value) {
internalSetAttribute(qualifiedName, value);
ElementAttributeProperty? propertyHandler = _attributeProperties[qualifiedName];
if (propertyHandler != null && propertyHandler.setter != null) {
propertyHandler.setter!(value);
}
final isNeedRecalculate = _checkRecalculateStyle([qualifiedName]);
_needRecalculateStyle = _needRecalculateStyle || isNeedRecalculate;
internalSetAttribute(qualifiedName, value);
}

void internalSetAttribute(String qualifiedName, String value) {
Expand Down Expand Up @@ -1713,11 +1709,6 @@ abstract class Element extends ContainerNode with ElementBase, ElementEventMixin
// But it's necessary for SVG.
}

void tryRecalculateStyle({bool rebuildNested = false}) {
recalculateStyle(forceRecalculate: _needRecalculateStyle);
_needRecalculateStyle = false;
}

void recalculateStyle({bool rebuildNested = false, bool forceRecalculate = false}) {
if (renderBoxModel != null || forceRecalculate || renderStyle.display == CSSDisplay.none) {
if (enableWebFProfileTracking) {
Expand Down
12 changes: 0 additions & 12 deletions webf/lib/src/launcher/controller.dart
Original file line number Diff line number Diff line change
Expand Up @@ -656,18 +656,6 @@ class WebFViewController implements WidgetsBindingObserver {
}
}

void recalculateStyle(int address) {
if (!hasBindingObject(Pointer.fromAddress(address))) return;
Node? target = getBindingObject<Node>(Pointer.fromAddress(address));
if (target == null) return;

if (target is Element) {
target.tryRecalculateStyle();
} else {
debugPrint('Only element has style, try recalculateStyle from Node(#${Pointer.fromAddress(address)}).');
}
}

// Hooks for DevTools.
VoidCallback? debugDOMTreeChanged;

Expand Down

0 comments on commit fd64918

Please sign in to comment.