Commit f02cbd18 authored by Theresa's avatar Theresa Committed by Commit Bot

Account for margin in native page snapshot

Use the native page's margin to translate the canvas used to capture the
bitmap used in the tab switcher.

Without explicitly considering margin, the snapshot is actually shorter
than the tab content, causing the content to "jump" when entering and
exiting the tab switcher.

BUG=832588

Change-Id: Ifdd871369341877c80214fbe767a602ee1f80d23
Reviewed-on: https://chromium-review.googlesource.com/1013132Reviewed-by: default avatarChangwan Ryu <changwan@chromium.org>
Commit-Queue: Theresa <twellington@chromium.org>
Cr-Commit-Position: refs/heads/master@{#551043}
parent 82a61bb9
......@@ -8,6 +8,7 @@ import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.view.View;
import android.view.ViewGroup.MarginLayoutParams;
import org.chromium.base.CommandLine;
import org.chromium.base.annotations.CalledByNative;
......@@ -173,10 +174,19 @@ public class TabContentManager {
float overlayTranslateY = mContentOffsetProvider.getOverlayTranslateY();
float leftMargin = 0.f;
float topMargin = 0.f;
if (viewToDraw.getLayoutParams() instanceof MarginLayoutParams) {
MarginLayoutParams params = (MarginLayoutParams) viewToDraw.getLayoutParams();
leftMargin = params.leftMargin;
topMargin = params.topMargin;
}
try {
bitmap = Bitmap.createBitmap(
(int) (viewToDraw.getWidth() * mThumbnailScale),
(int) ((viewToDraw.getHeight() - overlayTranslateY) * mThumbnailScale),
(int) (viewToDraw.getWidth() + leftMargin * mThumbnailScale),
(int) ((viewToDraw.getHeight() + topMargin - overlayTranslateY)
* mThumbnailScale),
Bitmap.Config.ARGB_8888);
} catch (OutOfMemoryError ex) {
return null;
......@@ -184,7 +194,7 @@ public class TabContentManager {
Canvas c = new Canvas(bitmap);
c.scale(scale, scale);
c.translate(0.f, -overlayTranslateY);
c.translate(leftMargin, -overlayTranslateY + topMargin);
if (page instanceof InvalidationAwareThumbnailProvider) {
((InvalidationAwareThumbnailProvider) page).captureThumbnail(c);
} else {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment