package androidx.compose.foundation.text.selection; import androidx.compose.ui.geometry.Offset; import androidx.compose.ui.geometry.Rect; import androidx.compose.ui.layout.LayoutCoordinates; import androidx.compose.ui.text.AnnotatedString; import androidx.compose.ui.text.TextLayoutResult; import androidx.compose.ui.text.TextRange; import androidx.compose.ui.text.TextRangeKt; import androidx.compose.ui.unit.IntSize; import kotlin.Metadata; import kotlin.Pair; import kotlin.jvm.functions.Function0; import kotlin.jvm.internal.Intrinsics; import kotlin.ranges.RangesKt; /* compiled from: MultiWidgetSelectionDelegate.kt */ @Metadata(d1 = {"\u0000d\n\u0002\u0018\u0002\n\u0002\u0018\u0002\n\u0000\n\u0002\u0010\t\n\u0000\n\u0002\u0018\u0002\n\u0002\u0018\u0002\n\u0000\n\u0002\u0018\u0002\n\u0002\b\u0002\n\u0002\u0010\b\n\u0002\b\u0007\n\u0002\u0018\u0002\n\u0002\b\u0002\n\u0002\u0018\u0002\n\u0000\n\u0002\u0018\u0002\n\u0000\n\u0002\u0010\u000b\n\u0002\b\u0004\n\u0002\u0018\u0002\n\u0002\b\u0004\n\u0002\u0018\u0002\n\u0000\n\u0002\u0018\u0002\n\u0002\b\u0005\n\u0002\u0018\u0002\n\u0002\b\u0004\b\u0000\u0018\u00002\u00020\u0001B-\u0012\u0006\u0010\u0002\u001a\u00020\u0003\u0012\u000e\u0010\u0004\u001a\n\u0012\u0006\u0012\u0004\u0018\u00010\u00060\u0005\u0012\u000e\u0010\u0007\u001a\n\u0012\u0006\u0012\u0004\u0018\u00010\b0\u0005¢\u0006\u0002\u0010\tJ\u0010\u0010\u0012\u001a\u00020\u00132\u0006\u0010\u0014\u001a\u00020\u000bH\u0016J(\u0010\u0015\u001a\u00020\u00162\u0006\u0010\u0017\u001a\u00020\u00182\u0006\u0010\u0019\u001a\u00020\u001aH\u0016ø\u0001\u0000ø\u0001\u0001ø\u0001\u0002¢\u0006\u0004\b\u001b\u0010\u001cJ\b\u0010\u0010\u001a\u00020\u000bH\u0016J\n\u0010\u001d\u001a\u0004\u0018\u00010\u0006H\u0016J \u0010\u001e\u001a\u00020\u001f2\u0006\u0010\u0014\u001a\u00020\u000bH\u0016ø\u0001\u0000ø\u0001\u0001ø\u0001\u0002¢\u0006\u0004\b \u0010!J\n\u0010\"\u001a\u0004\u0018\u00010\u0018H\u0016J\b\u0010#\u001a\u00020$H\u0016J_\u0010%\u001a\u0010\u0012\u0006\u0012\u0004\u0018\u00010\u0018\u0012\u0004\u0012\u00020\u001a0&2\u0006\u0010'\u001a\u00020\u00162\u0006\u0010(\u001a\u00020\u00162\b\u0010)\u001a\u0004\u0018\u00010\u00162\u0006\u0010\u0019\u001a\u00020\u001a2\u0006\u0010*\u001a\u00020\u00062\u0006\u0010+\u001a\u00020,2\b\u0010-\u001a\u0004\u0018\u00010\u0018H\u0016ø\u0001\u0001ø\u0001\u0002¢\u0006\u0004\b.\u0010/R\u000e\u0010\n\u001a\u00020\u000bX\u0082\u000e¢\u0006\u0002\n\u0000R\u0010\u0010\f\u001a\u0004\u0018\u00010\bX\u0082\u000e¢\u0006\u0002\n\u0000R\u0016\u0010\u0004\u001a\n\u0012\u0006\u0012\u0004\u0018\u00010\u00060\u0005X\u0082\u0004¢\u0006\u0002\n\u0000R\u0016\u0010\u0007\u001a\n\u0012\u0006\u0012\u0004\u0018\u00010\b0\u0005X\u0082\u0004¢\u0006\u0002\n\u0000R\u0014\u0010\u0002\u001a\u00020\u0003X\u0096\u0004¢\u0006\b\n\u0000\u001a\u0004\b\r\u0010\u000eR\u0018\u0010\u000f\u001a\u00020\u000b*\u00020\b8BX\u0082\u0004¢\u0006\u0006\u001a\u0004\b\u0010\u0010\u0011\u0082\u0002\u000f\n\u0002\b!\n\u0005\b¡\u001e0\u0001\n\u0002\b\u0019¨\u00060"}, d2 = {"Landroidx/compose/foundation/text/selection/MultiWidgetSelectionDelegate;", "Landroidx/compose/foundation/text/selection/Selectable;", "selectableId", "", "coordinatesCallback", "Lkotlin/Function0;", "Landroidx/compose/ui/layout/LayoutCoordinates;", "layoutResultCallback", "Landroidx/compose/ui/text/TextLayoutResult;", "(JLkotlin/jvm/functions/Function0;Lkotlin/jvm/functions/Function0;)V", "_previousLastVisibleOffset", "", "_previousTextLayoutResult", "getSelectableId", "()J", "lastVisibleOffset", "getLastVisibleOffset", "(Landroidx/compose/ui/text/TextLayoutResult;)I", "getBoundingBox", "Landroidx/compose/ui/geometry/Rect;", "offset", "getHandlePosition", "Landroidx/compose/ui/geometry/Offset;", "selection", "Landroidx/compose/foundation/text/selection/Selection;", "isStartHandle", "", "getHandlePosition-dBAh8RU", "(Landroidx/compose/foundation/text/selection/Selection;Z)J", "getLayoutCoordinates", "getRangeOfLineContaining", "Landroidx/compose/ui/text/TextRange;", "getRangeOfLineContaining--jx7JFs", "(I)J", "getSelectAllSelection", "getText", "Landroidx/compose/ui/text/AnnotatedString;", "updateSelection", "Lkotlin/Pair;", "startHandlePosition", "endHandlePosition", "previousHandlePosition", "containerLayoutCoordinates", "adjustment", "Landroidx/compose/foundation/text/selection/SelectionAdjustment;", "previousSelection", "updateSelection-qCDeeow", "(JJLandroidx/compose/ui/geometry/Offset;ZLandroidx/compose/ui/layout/LayoutCoordinates;Landroidx/compose/foundation/text/selection/SelectionAdjustment;Landroidx/compose/foundation/text/selection/Selection;)Lkotlin/Pair;", "foundation_release"}, k = 1, mv = {1, 8, 0}, xi = 48) /* loaded from: classes.dex */ public final class MultiWidgetSelectionDelegate implements Selectable { private int _previousLastVisibleOffset; private TextLayoutResult _previousTextLayoutResult; private final Function0 coordinatesCallback; private final Function0 layoutResultCallback; private final long selectableId; @Override // androidx.compose.foundation.text.selection.Selectable public long getSelectableId() { return this.selectableId; } /* JADX WARN: Multi-variable type inference failed */ public MultiWidgetSelectionDelegate(long j, Function0 coordinatesCallback, Function0 layoutResultCallback) { Intrinsics.checkNotNullParameter(coordinatesCallback, "coordinatesCallback"); Intrinsics.checkNotNullParameter(layoutResultCallback, "layoutResultCallback"); this.selectableId = j; this.coordinatesCallback = coordinatesCallback; this.layoutResultCallback = layoutResultCallback; this._previousLastVisibleOffset = -1; } private final synchronized int getLastVisibleOffset(TextLayoutResult textLayoutResult) { int lineCount; if (this._previousTextLayoutResult != textLayoutResult) { if (textLayoutResult.getDidOverflowHeight() && !textLayoutResult.getMultiParagraph().getDidExceedMaxLines()) { lineCount = RangesKt.coerceAtMost(textLayoutResult.getLineForVerticalPosition(IntSize.m5042getHeightimpl(textLayoutResult.getSize())), textLayoutResult.getLineCount() - 1); while (textLayoutResult.getLineTop(lineCount) >= IntSize.m5042getHeightimpl(textLayoutResult.getSize())) { lineCount--; } this._previousLastVisibleOffset = textLayoutResult.getLineEnd(lineCount, true); this._previousTextLayoutResult = textLayoutResult; } lineCount = textLayoutResult.getLineCount() - 1; this._previousLastVisibleOffset = textLayoutResult.getLineEnd(lineCount, true); this._previousTextLayoutResult = textLayoutResult; } return this._previousLastVisibleOffset; } @Override // androidx.compose.foundation.text.selection.Selectable /* renamed from: updateSelection-qCDeeow, reason: not valid java name */ public Pair mo887updateSelectionqCDeeow(long startHandlePosition, long endHandlePosition, Offset previousHandlePosition, boolean isStartHandle, LayoutCoordinates containerLayoutCoordinates, SelectionAdjustment adjustment, Selection previousSelection) { TextLayoutResult invoke; Intrinsics.checkNotNullParameter(containerLayoutCoordinates, "containerLayoutCoordinates"); Intrinsics.checkNotNullParameter(adjustment, "adjustment"); if (previousSelection != null && (getSelectableId() != previousSelection.getStart().getSelectableId() || getSelectableId() != previousSelection.getEnd().getSelectableId())) { throw new IllegalArgumentException("The given previousSelection doesn't belong to this selectable.".toString()); } LayoutCoordinates layoutCoordinates = getLayoutCoordinates(); if (layoutCoordinates != null && (invoke = this.layoutResultCallback.invoke()) != null) { long mo3884localPositionOfR5De75A = containerLayoutCoordinates.mo3884localPositionOfR5De75A(layoutCoordinates, Offset.INSTANCE.m2416getZeroF1C5BW0()); return MultiWidgetSelectionDelegateKt.m891getTextSelectionInfoyM0VcXU(invoke, Offset.m2404minusMKHz9U(startHandlePosition, mo3884localPositionOfR5De75A), Offset.m2404minusMKHz9U(endHandlePosition, mo3884localPositionOfR5De75A), previousHandlePosition != null ? Offset.m2389boximpl(Offset.m2404minusMKHz9U(previousHandlePosition.getPackedValue(), mo3884localPositionOfR5De75A)) : null, getSelectableId(), adjustment, previousSelection, isStartHandle); } return new Pair<>(null, false); } @Override // androidx.compose.foundation.text.selection.Selectable public Selection getSelectAllSelection() { Selection m889getAssembledSelectionInfovJH6DeI; TextLayoutResult invoke = this.layoutResultCallback.invoke(); if (invoke == null) { return null; } m889getAssembledSelectionInfovJH6DeI = MultiWidgetSelectionDelegateKt.m889getAssembledSelectionInfovJH6DeI(TextRangeKt.TextRange(0, invoke.getLayoutInput().getText().length()), false, getSelectableId(), invoke); return m889getAssembledSelectionInfovJH6DeI; } @Override // androidx.compose.foundation.text.selection.Selectable /* renamed from: getHandlePosition-dBAh8RU, reason: not valid java name */ public long mo885getHandlePositiondBAh8RU(Selection selection, boolean isStartHandle) { TextLayoutResult invoke; Intrinsics.checkNotNullParameter(selection, "selection"); if ((isStartHandle && selection.getStart().getSelectableId() != getSelectableId()) || (!isStartHandle && selection.getEnd().getSelectableId() != getSelectableId())) { return Offset.INSTANCE.m2416getZeroF1C5BW0(); } if (getLayoutCoordinates() != null && (invoke = this.layoutResultCallback.invoke()) != null) { return TextSelectionDelegateKt.getSelectionHandleCoordinates(invoke, RangesKt.coerceIn((isStartHandle ? selection.getStart() : selection.getEnd()).getOffset(), 0, getLastVisibleOffset(invoke)), isStartHandle, selection.getHandlesCrossed()); } return Offset.INSTANCE.m2416getZeroF1C5BW0(); } @Override // androidx.compose.foundation.text.selection.Selectable public LayoutCoordinates getLayoutCoordinates() { LayoutCoordinates invoke = this.coordinatesCallback.invoke(); if (invoke == null || !invoke.isAttached()) { return null; } return invoke; } @Override // androidx.compose.foundation.text.selection.Selectable public AnnotatedString getText() { TextLayoutResult invoke = this.layoutResultCallback.invoke(); return invoke == null ? new AnnotatedString("", null, null, 6, null) : invoke.getLayoutInput().getText(); } @Override // androidx.compose.foundation.text.selection.Selectable public Rect getBoundingBox(int offset) { TextLayoutResult invoke = this.layoutResultCallback.invoke(); if (invoke == null) { return Rect.INSTANCE.getZero(); } int length = invoke.getLayoutInput().getText().length(); if (length < 1) { return Rect.INSTANCE.getZero(); } return invoke.getBoundingBox(RangesKt.coerceIn(offset, 0, length - 1)); } @Override // androidx.compose.foundation.text.selection.Selectable /* renamed from: getRangeOfLineContaining--jx7JFs, reason: not valid java name */ public long mo886getRangeOfLineContainingjx7JFs(int offset) { TextLayoutResult invoke = this.layoutResultCallback.invoke(); if (invoke == null) { return TextRange.INSTANCE.m4419getZerod9O1mEE(); } int lastVisibleOffset = getLastVisibleOffset(invoke); if (lastVisibleOffset < 1) { return TextRange.INSTANCE.m4419getZerod9O1mEE(); } int lineForOffset = invoke.getLineForOffset(RangesKt.coerceIn(offset, 0, lastVisibleOffset - 1)); return TextRangeKt.TextRange(invoke.getLineStart(lineForOffset), invoke.getLineEnd(lineForOffset, true)); } @Override // androidx.compose.foundation.text.selection.Selectable public int getLastVisibleOffset() { TextLayoutResult invoke = this.layoutResultCallback.invoke(); if (invoke == null) { return 0; } return getLastVisibleOffset(invoke); } }