diff options
| author | Gilles Debunne <debunne@google.com> | 2012-05-02 11:59:54 -0700 |
|---|---|---|
| committer | Android (Google) Code Review <android-gerrit@google.com> | 2012-05-02 11:59:54 -0700 |
| commit | 54562cfbcd97a3b9d3ac9fb74f7a0d0d4bb9b8a0 (patch) | |
| tree | 3effdafa94cc0c6c1a182136bf8631a60ab49105 /core/java/android | |
| parent | fe5984f43a5be9f95d1febb806f3aee8601c7ff4 (diff) | |
| parent | fd5bc01f70c8d9270162d38bb9f675308b5a19b0 (diff) | |
Merge "Better horizontal internal scroll handling in Text." into jb-dev
Diffstat (limited to 'core/java/android')
| -rw-r--r-- | core/java/android/widget/Editor.java | 35 |
1 files changed, 19 insertions, 16 deletions
diff --git a/core/java/android/widget/Editor.java b/core/java/android/widget/Editor.java index a18b64c41577..4b7ec9ab2c3e 100644 --- a/core/java/android/widget/Editor.java +++ b/core/java/android/widget/Editor.java @@ -1223,8 +1223,6 @@ public class Editor { private void drawHardwareAccelerated(Canvas canvas, Layout layout, Path highlight, Paint highlightPaint, int cursorOffsetVertical) { - final int width = mTextView.getWidth(); - final long lineRange = layout.getLineRangeForDraw(canvas); int firstLine = TextUtils.unpackRangeStartFromLong(lineRange); int lastLine = TextUtils.unpackRangeEndFromLong(lineRange); @@ -1243,10 +1241,6 @@ public class Editor { int[] blockIndices = dynamicLayout.getBlockIndices(); final int numberOfBlocks = dynamicLayout.getNumberOfBlocks(); - final int scrollX = mTextView.getScrollX(); - final int scrollY = mTextView.getScrollY(); - canvas.translate(scrollX, scrollY); - int endOfPreviousBlock = -1; int searchStartIndex = 0; for (int i = 0; i < numberOfBlocks; i++) { @@ -1274,34 +1268,43 @@ public class Editor { final int blockBeginLine = endOfPreviousBlock + 1; final int top = layout.getLineTop(blockBeginLine); final int bottom = layout.getLineBottom(blockEndLine); + int left = 0; + int right = mTextView.getWidth(); + if (mTextView.getHorizontallyScrolling()) { + float min = Float.MAX_VALUE; + float max = Float.MIN_VALUE; + for (int line = blockBeginLine; line <= blockEndLine; line++) { + min = Math.min(min, layout.getLineLeft(line)); + max = Math.max(max, layout.getLineRight(line)); + } + left = (int) min; + right = (int) (max + 0.5f); + } final HardwareCanvas hardwareCanvas = blockDisplayList.start(); try { - hardwareCanvas.setViewport(width, bottom - top); + // Tighten the bounds of the viewport to the actual text size + hardwareCanvas.setViewport(right - left, bottom - top); // The dirty rect should always be null for a display list hardwareCanvas.onPreDraw(null); // drawText is always relative to TextView's origin, this translation brings - // this range of text back to the top of the viewport - hardwareCanvas.translate(-scrollX, -top); + // this range of text back to the top left corner of the viewport + hardwareCanvas.translate(-left, -top); layout.drawText(hardwareCanvas, blockBeginLine, blockEndLine); - hardwareCanvas.translate(scrollX, top); + // No need to untranslate, previous context is popped after drawDisplayList } finally { hardwareCanvas.onPostDraw(); blockDisplayList.end(); - blockDisplayList.setLeftTopRightBottom(0, top, width, bottom); + blockDisplayList.setLeftTopRightBottom(left, top, right, bottom); // Same as drawDisplayList below, handled by our TextView's parent blockDisplayList.setClipChildren(false); } } - // TODO When View.USE_DISPLAY_LIST_PROPERTIES is the only code path, the - // width and height parameters should be removed and the bounds set above in - // setLeftTopRightBottom should be used instead for quick rejection. ((HardwareCanvas) canvas).drawDisplayList(blockDisplayList, null, 0 /* no child clipping, our TextView parent enforces it */); + endOfPreviousBlock = blockEndLine; - - canvas.translate(-scrollX, -scrollY); } } else { // Boring layout is used for empty and hint text |
