Commit 18fe962c authored by Gang Wu's avatar Gang Wu Committed by Commit Bot

[Omnibox] Resize the thumbnail if it is larger than expected

Bug: 1090164
Change-Id: I5ce8101b3d14ec0aea02478eee919fa92c1f3261
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2226081
Commit-Queue: Gang Wu <gangwu@chromium.org>
Reviewed-by: default avatarTed Choc <tedchoc@chromium.org>
Cr-Commit-Position: refs/heads/master@{#774873}
parent fdc4a56f
...@@ -54,6 +54,13 @@ public abstract class BaseSuggestionViewProcessor implements SuggestionProcessor ...@@ -54,6 +54,13 @@ public abstract class BaseSuggestionViewProcessor implements SuggestionProcessor
R.dimen.omnibox_suggestion_comfortable_height); R.dimen.omnibox_suggestion_comfortable_height);
} }
/**
* @return The desired size of Omnibox suggestion favicon.
*/
protected int getDesiredFaviconSize() {
return mDesiredFaviconWidthPx;
}
@Override @Override
public void onNativeInitialized() { public void onNativeInitialized() {
if (ChromeFeatureList.isEnabled(ChromeFeatureList.OMNIBOX_COMPACT_SUGGESTIONS)) { if (ChromeFeatureList.isEnabled(ChromeFeatureList.OMNIBOX_COMPACT_SUGGESTIONS)) {
......
...@@ -73,6 +73,18 @@ public class ClipboardSuggestionProcessor extends BaseSuggestionViewProcessor { ...@@ -73,6 +73,18 @@ public class ClipboardSuggestionProcessor extends BaseSuggestionViewProcessor {
if (imageData != null && imageData.length > 0) { if (imageData != null && imageData.length > 0) {
Bitmap bitmap = BitmapFactory.decodeByteArray(imageData, 0, imageData.length); Bitmap bitmap = BitmapFactory.decodeByteArray(imageData, 0, imageData.length);
if (bitmap != null) { if (bitmap != null) {
// TODO(crbug.com/1090919): This is short term solution, resize need to be
// handled somewhere else.
if (bitmap.getWidth() > 0 && bitmap.getHeight() > 0
&& (bitmap.getWidth() > getDesiredFaviconSize()
|| bitmap.getHeight() > getDesiredFaviconSize())) {
float max = Math.max(bitmap.getWidth(), bitmap.getHeight());
float scale = (float) getDesiredFaviconSize() / max;
float width = bitmap.getWidth();
float height = bitmap.getHeight();
bitmap = Bitmap.createScaledBitmap(bitmap, (int) Math.round(scale * width),
(int) Math.round(scale * height), true);
}
setSuggestionDrawableState(model, setSuggestionDrawableState(model,
SuggestionDrawableState.Builder.forBitmap(getContext(), bitmap) SuggestionDrawableState.Builder.forBitmap(getContext(), bitmap)
.build()); .build());
......
...@@ -197,4 +197,22 @@ public class ClipboardSuggestionProcessorTest { ...@@ -197,4 +197,22 @@ public class ClipboardSuggestionProcessorTest {
Assert.assertEquals( Assert.assertEquals(
mBitmap.getHeight(), ((BitmapDrawable) icon.drawable).getBitmap().getHeight()); mBitmap.getHeight(), ((BitmapDrawable) icon.drawable).getBitmap().getHeight());
} }
@CalledByNativeJavaTest
public void clipboardSuggestion_thumbnailShouldResizeIfTooLarge() {
int size = ContextUtils.getApplicationContext().getResources().getDimensionPixelSize(
R.dimen.omnibox_suggestion_favicon_size);
Bitmap largeBitmap = Bitmap.createBitmap(size * 2, size * 2, Config.ARGB_8888);
ByteArrayOutputStream baos = new ByteArrayOutputStream();
Assert.assertTrue(largeBitmap.compress(Bitmap.CompressFormat.PNG, 100, baos));
byte[] bitmapData = baos.toByteArray();
createClipboardSuggestion(
OmniboxSuggestionType.CLIPBOARD_IMAGE, GURL.emptyGURL(), bitmapData);
SuggestionDrawableState icon = mModel.get(BaseSuggestionViewProperties.ICON);
Assert.assertNotNull(icon);
Assert.assertEquals(size, ((BitmapDrawable) icon.drawable).getBitmap().getWidth());
Assert.assertEquals(size, ((BitmapDrawable) icon.drawable).getBitmap().getHeight());
}
} }
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