Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 5b942e49 authored by Tyler Freeman's avatar Tyler Freeman
Browse files

fix(high contrast text): fix text cursor, spellcheck, etc not visible

Since we now draw a solid background rectangle behind the text, the
background draws over the text position cursor, underline squiggles for
spelling errors, etc.

To fix this, we just draw those things on top of all the text, its
background, and selection highlights.

Bug: 186567103
Flag: ACONFIG com.android.graphics.hwui.flags.high_contrast_text_small_text_rect TEAMFOOD
Test: atest core/tests/coretests/src/android/text/LayoutTest.java
Test: manual
1. adb shell setenforce 0 && adb shell setprop persist.device_config.aconfig_flags.accessibility.com.android.graphics.hwui.flags.high_contrast_text_small_text_rect true && adb shell stop && adb shell start
2. Settings -> Accessibility -> Display Size and Text
3. Turn on High Contrast Text
4. Blinking cursor and error squiggles should be visible.

Change-Id: I367ffcbdfc3ca35f15679fac06fa8c03309facd3
parent 1176b9ba
Loading
Loading
Loading
Loading
+24 −4
Original line number Diff line number Diff line
@@ -2112,6 +2112,17 @@ public class Editor {
            }
        }

        boolean shouldDrawHighlightsOnTop = highContrastTextSmallTextRect()
                && canvas.isHighContrastTextEnabled();

        // If high contrast text is drawing background rectangles behind the text, those cover up
        // the cursor and correction highlighter etc. So just draw the text first, then draw the
        // others on top of the text. If high contrast text isn't enabled: draw text last, as usual.
        if (shouldDrawHighlightsOnTop) {
            drawLayout(canvas, layout, highlightPaths, highlightPaints, selectionHighlight,
                    selectionHighlightPaint, cursorOffsetVertical, shouldDrawHighlightsOnTop);
        }

        if (mCorrectionHighlighter != null) {
            mCorrectionHighlighter.draw(canvas, cursorOffsetVertical);
        }
@@ -2136,9 +2147,19 @@ public class Editor {
            mInsertModeController.onDraw(canvas);
        }

        if (!shouldDrawHighlightsOnTop) {
            drawLayout(canvas, layout, highlightPaths, highlightPaints, selectionHighlight,
                    selectionHighlightPaint, cursorOffsetVertical, shouldDrawHighlightsOnTop);
        }
    }

    private void drawLayout(Canvas canvas, Layout layout, List<Path> highlightPaths,
            List<Paint> highlightPaints, Path selectionHighlight, Paint selectionHighlightPaint,
            int cursorOffsetVertical, boolean shouldDrawHighlightsOnTop) {
        if (mTextView.canHaveDisplayList() && canvas.isHardwareAccelerated()) {
            drawHardwareAccelerated(canvas, layout, highlightPaths, highlightPaints,
                    selectionHighlight, selectionHighlightPaint, cursorOffsetVertical);
                    selectionHighlight, selectionHighlightPaint, cursorOffsetVertical,
                    shouldDrawHighlightsOnTop);
        } else {
            layout.draw(canvas, highlightPaths, highlightPaints, selectionHighlight,
                    selectionHighlightPaint, cursorOffsetVertical);
@@ -2147,14 +2168,13 @@ public class Editor {

    private void drawHardwareAccelerated(Canvas canvas, Layout layout,
            List<Path> highlightPaths, List<Paint> highlightPaints,
            Path selectionHighlight, Paint selectionHighlightPaint, int cursorOffsetVertical) {
            Path selectionHighlight, Paint selectionHighlightPaint, int cursorOffsetVertical,
            boolean shouldDrawHighlightsOnTop) {
        final long lineRange = layout.getLineRangeForDraw(canvas);
        int firstLine = TextUtils.unpackRangeStartFromLong(lineRange);
        int lastLine = TextUtils.unpackRangeEndFromLong(lineRange);
        if (lastLine < 0) return;

        boolean shouldDrawHighlightsOnTop = highContrastTextSmallTextRect()
                && canvas.isHighContrastTextEnabled();

        if (!shouldDrawHighlightsOnTop) {
            layout.drawWithoutText(canvas, highlightPaths, highlightPaints, selectionHighlight,