getContentInfoFromDocument static method

ContentInfo getContentInfoFromDocument(
  1. Document document
)

Gets detailed content information from a document

Implementation

static ContentInfo getContentInfoFromDocument(Document document) {
  final info = ContentInfo._();

  info.hasVisibleContent = hasVisibleContentInDocument(document);
  info.totalVisibleArea = getTotalVisibleContentArea(document);

  // Count different types of visible content
  void countContent(RenderObject renderObject) {
    if (!_isVisibleContent(renderObject)) {
      renderObject.visitChildren(countContent);
      return;
    }

    info.totalElements++;

    if (renderObject is RenderParagraph) {
      info.textElements++;
    } else if (renderObject is RenderImage) {
      info.imageElements++;
    } else if (renderObject is RenderBoxModel || renderObject is RenderDecoratedBox) {
      info.decoratedElements++;
    } else if (renderObject is RenderWidget) {
      info.widgetElements++;
    } else if (renderObject is RenderCustomPaint) {
      info.customPaintElements++;
    }

    renderObject.visitChildren(countContent);
  }

  final viewport = document.viewport;
  if (viewport != null) {
    countContent(viewport);
  }

  return info;
}