updateActiveStyleSheets method

bool updateActiveStyleSheets({
  1. bool rebuild = false,
})

Implementation

bool updateActiveStyleSheets({bool rebuild = false}) {
  List<CSSStyleSheet> newSheets = _collectActiveStyleSheets();
  if (DebugFlags.enableCssMultiStyleTrace) {
    cssLogger.info('[trace][multi-style][update] pending=${_pendingStyleSheets.length} candidates=${_styleSheetCandidateNodes.length} rebuild=$rebuild');
  }
  newSheets = newSheets.where((element) => element.cssRules.isNotEmpty).toList();
  if (rebuild == false) {
    RuleSet changedRuleSet = analyzeStyleSheetChangeRuleSet(document.styleSheets, newSheets);
    final bool shouldForceHtml = !changedRuleSet.tagRules.containsKey('HTML') && _sheetsContainTagDifference(document.styleSheets, newSheets, 'HTML');
    final bool shouldForceBody = !changedRuleSet.tagRules.containsKey('BODY') && _sheetsContainTagDifference(document.styleSheets, newSheets, 'BODY');
    if (changedRuleSet.isEmpty) {
      _pendingStyleSheets.clear();
      _isStyleSheetCandidateNodeChanged = false;
      return false;
    }
    invalidateElementStyle(changedRuleSet);
    if (shouldForceHtml) {
      final HTMLElement? root = document.documentElement;
      if (root != null) {
        document.markElementStyleDirty(root, reason: 'tag-detect:HTML');
      }
    }
    if (shouldForceBody) {
      final BodyElement? body = document.bodyElement;
      if (body != null) {
        document.markElementStyleDirty(body, reason: 'tag-detect:BODY');
      }
    }
  } else {
    final root = document.documentElement;
    if (root != null) {
      document.markElementStyleDirty(root);
    }
  }
  document.handleStyleSheets(newSheets);
  _pendingStyleSheets.clear();
  _isStyleSheetCandidateNodeChanged = false;
  return true;
}