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

Commit 70b34a1e authored by Gilles Debunne's avatar Gilles Debunne
Browse files

Scroll performance improved in multiline TextEdit

Measuring line widths, glyph by glyph slows down the scrolling
process for long text (for some reason, width measure efficiency
is affectedi by text length, maybe because the whole text has to
be passed to JNI layers).

This optimization avoids this computation in the case where there
is no possible horizontal scroll.

This is a cherry pick of 145957 into ICS-MR1

Change-Id: I2082e3d0eedace1a86122a03e4b21f90f3bc8522
parent 9b518d93
Loading
Loading
Loading
Loading
+28 −12
Original line number Original line Diff line number Diff line
@@ -35,22 +35,30 @@ public class Touch {
     * Y position.
     * Y position.
     */
     */
    public static void scrollTo(TextView widget, Layout layout, int x, int y) {
    public static void scrollTo(TextView widget, Layout layout, int x, int y) {
        final int verticalPadding = widget.getTotalPaddingTop() + widget.getTotalPaddingBottom();
        final int horizontalPadding = widget.getTotalPaddingLeft() + widget.getTotalPaddingRight();
        final int top = layout.getLineForVertical(y);
        final int availableWidth = widget.getWidth() - horizontalPadding;
        final int bottom = layout.getLineForVertical(y + widget.getHeight() - verticalPadding);


        int left = Integer.MAX_VALUE;
        final int top = layout.getLineForVertical(y);
        int right = 0;
        Alignment a = layout.getParagraphAlignment(top);
        Alignment a = layout.getParagraphAlignment(top);
        boolean ltr = layout.getParagraphDirection(top) > 0;
        boolean ltr = layout.getParagraphDirection(top) > 0;


        int left, right;
        if (widget.getHorizontallyScrolling()) {
            final int verticalPadding = widget.getTotalPaddingTop() + widget.getTotalPaddingBottom();
            final int bottom = layout.getLineForVertical(y + widget.getHeight() - verticalPadding);

            left = Integer.MAX_VALUE;
            right = 0;

            for (int i = top; i <= bottom; i++) {
            for (int i = top; i <= bottom; i++) {
                left = (int) Math.min(left, layout.getLineLeft(i));
                left = (int) Math.min(left, layout.getLineLeft(i));
                right = (int) Math.max(right, layout.getLineRight(i));
                right = (int) Math.max(right, layout.getLineRight(i));
            }
            }
        } else {
            left = 0;
            right = availableWidth;
        }


        final int hoizontalPadding = widget.getTotalPaddingLeft() + widget.getTotalPaddingRight();
        final int availableWidth = widget.getWidth() - hoizontalPadding;
        final int actualWidth = right - left;
        final int actualWidth = right - left;


        if (actualWidth < availableWidth) {
        if (actualWidth < availableWidth) {
@@ -166,11 +174,19 @@ public class Touch {
        return false;
        return false;
    }
    }


    /**
     * @param widget The text view.
     * @param buffer The text buffer.
     */
    public static int getInitialScrollX(TextView widget, Spannable buffer) {
    public static int getInitialScrollX(TextView widget, Spannable buffer) {
        DragState[] ds = buffer.getSpans(0, buffer.length(), DragState.class);
        DragState[] ds = buffer.getSpans(0, buffer.length(), DragState.class);
        return ds.length > 0 ? ds[0].mScrollX : -1;
        return ds.length > 0 ? ds[0].mScrollX : -1;
    }
    }


    /**
     * @param widget The text view.
     * @param buffer The text buffer.
     */
    public static int getInitialScrollY(TextView widget, Spannable buffer) {
    public static int getInitialScrollY(TextView widget, Spannable buffer) {
        DragState[] ds = buffer.getSpans(0, buffer.length(), DragState.class);
        DragState[] ds = buffer.getSpans(0, buffer.length(), DragState.class);
        return ds.length > 0 ? ds[0].mScrollY : -1;
        return ds.length > 0 ? ds[0].mScrollY : -1;
+11 −0
Original line number Original line Diff line number Diff line
@@ -2580,6 +2580,17 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener
        }
        }
    }
    }


    /**
     * Returns whether the text is allowed to be wider than the View is.
     * If false, the text will be wrapped to the width of the View.
     *
     * @attr ref android.R.styleable#TextView_scrollHorizontally
     * @hide
     */
    public boolean getHorizontallyScrolling() {
        return mHorizontallyScrolling;
    }

    /**
    /**
     * Makes the TextView at least this many lines tall.
     * Makes the TextView at least this many lines tall.
     *
     *