readPage method
What page pageIndex of prepared holds for a host: its interaction
targets, semantic outline, text and text runs. An artifact carries
only its pages' index and size; the engine builds these when a host
first asks, the way a browser hit-tests the fragments it painted when
a pointer arrives. Hit-test a tap with RitoHitResolver over the
records of the pages it may land on.
Implementation
Future<RitoPageRecords> readPage(
RitoPreparedArtifact prepared,
int pageIndex,
) async {
_requireOpen();
final artifact = prepared.artifact;
_requireLiveArtifact(artifact);
if (!artifact.pages.any((page) => page.pageIndex == pageIndex)) {
throw ArgumentError.value(
pageIndex,
'pageIndex',
'is not a page of the artifact',
);
}
late final RitoPageRecords records;
try {
records = await gateway.readPage(
sessionId: sessionId,
artifactId: artifact.artifactId,
pageIndex: pageIndex,
);
} on RitoNativeSessionInvalidatedException catch (error, stackTrace) {
return _failClosedAfterCleanupFailure(
requestId: error.requestId,
cleanupError: error,
cleanupStackTrace: stackTrace,
);
}
_requireOpen();
if (records.artifactId != artifact.artifactId ||
records.pageIndex != pageIndex) {
throw StateError('Page records ownership does not match the artifact.');
}
return records;
}