Commit 4c4cba8a authored by Henrique Nakashima's avatar Henrique Nakashima Committed by Commit Bot

Move tab thumbnail aspect ratio code to TabUiFeatureUtilities.

CachedFeatureFlags deals with caching generic flags to SharedPrefs.

Bug: 1012975
Change-Id: Ibe5912622a73e7a6b984b1dc3746dd775a0b711b
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2079341Reviewed-by: default avatarWei-Yin Chen (陳威尹) <wychen@chromium.org>
Reviewed-by: default avatarTheresa  <twellington@chromium.org>
Commit-Queue: Henrique Nakashima <hnakashima@chromium.org>
Cr-Commit-Position: refs/heads/master@{#745462}
parent 07199ff1
......@@ -33,13 +33,13 @@ import org.chromium.chrome.browser.compositor.layouts.content.TabContentManager;
import org.chromium.chrome.browser.compositor.layouts.eventfilter.EventFilter;
import org.chromium.chrome.browser.compositor.scene_layer.SceneLayer;
import org.chromium.chrome.browser.compositor.scene_layer.TabListSceneLayer;
import org.chromium.chrome.browser.flags.CachedFeatureFlags;
import org.chromium.chrome.browser.flags.ChromeFeatureList;
import org.chromium.chrome.browser.fullscreen.ChromeFullscreenManager;
import org.chromium.chrome.browser.tab.Tab;
import org.chromium.chrome.browser.tab.TabFeatureUtilities;
import org.chromium.chrome.browser.tabmodel.TabModelSelector;
import org.chromium.chrome.browser.tasks.tab_management.TabSwitcher;
import org.chromium.chrome.browser.tasks.tab_management.TabUiFeatureUtilities;
import org.chromium.components.browser_ui.widget.animation.Interpolators;
import org.chromium.ui.resources.ResourceManager;
......@@ -101,7 +101,7 @@ public class StartSurfaceLayout extends Layout implements StartSurface.OverviewM
mController = mStartSurface.getController();
mController.addOverviewModeObserver(this);
mTabListDelegate = mStartSurface.getTabListDelegate();
if (CachedFeatureFlags.isTabThumbnailAspectRatioNotOne()) {
if (TabUiFeatureUtilities.isTabThumbnailAspectRatioNotOne()) {
mThumbnailAspectRatio = (float) ChromeFeatureList.getFieldTrialParamByFeatureAsDouble(
ChromeFeatureList.TAB_GRID_LAYOUT_ANDROID, "thumbnail_aspect_ratio", 1.0);
mThumbnailAspectRatio = MathUtils.clamp(mThumbnailAspectRatio, 0.5f, 2.0f);
......@@ -310,7 +310,7 @@ public class StartSurfaceLayout extends Layout implements StartSurface.OverviewM
// down, making the "create group" visible for a while.
animationList.add(CompositorAnimator.ofFloatProperty(handler, sourceLayoutTab,
LayoutTab.MAX_CONTENT_HEIGHT, sourceLayoutTab.getUnclampedOriginalContentHeight(),
CachedFeatureFlags.isTabThumbnailAspectRatioNotOne()
TabUiFeatureUtilities.isTabThumbnailAspectRatioNotOne()
? Math.min(getWidth() / mThumbnailAspectRatio,
sourceLayoutTab.getUnclampedOriginalContentHeight())
: getWidth(),
......@@ -366,7 +366,7 @@ public class StartSurfaceLayout extends Layout implements StartSurface.OverviewM
// down, making the "create group" visible for a while.
animationList.add(CompositorAnimator.ofFloatProperty(handler, sourceLayoutTab,
LayoutTab.MAX_CONTENT_HEIGHT,
CachedFeatureFlags.isTabThumbnailAspectRatioNotOne()
TabUiFeatureUtilities.isTabThumbnailAspectRatioNotOne()
? Math.min(getWidth() / mThumbnailAspectRatio,
sourceLayoutTab.getUnclampedOriginalContentHeight())
: getWidth(),
......
......@@ -26,7 +26,6 @@ import androidx.vectordrawable.graphics.drawable.AnimatedVectorDrawableCompat;
import org.chromium.base.ApiCompatibilityUtils;
import org.chromium.base.Callback;
import org.chromium.base.MathUtils;
import org.chromium.chrome.browser.flags.CachedFeatureFlags;
import org.chromium.chrome.browser.flags.ChromeFeatureList;
import org.chromium.chrome.tab_ui.R;
import org.chromium.ui.modelutil.PropertyKey;
......@@ -288,7 +287,7 @@ class TabGridViewBinder {
}
private static void releaseThumbnail(ImageView thumbnail) {
if (CachedFeatureFlags.isTabThumbnailAspectRatioNotOne()) {
if (TabUiFeatureUtilities.isTabThumbnailAspectRatioNotOne()) {
float expectedThumbnailAspectRatio =
(float) ChromeFeatureList.getFieldTrialParamByFeatureAsDouble(
ChromeFeatureList.TAB_GRID_LAYOUT_ANDROID, "thumbnail_aspect_ratio",
......
......@@ -150,7 +150,7 @@ public class TabListCoordinator implements Destroyable {
ViewLookupCachingFrameLayout root = (ViewLookupCachingFrameLayout) holder.itemView;
ImageView thumbnail = (ImageView) root.fastFindViewById(R.id.tab_thumbnail);
if (thumbnail == null) return;
if (CachedFeatureFlags.isTabThumbnailAspectRatioNotOne()) {
if (TabUiFeatureUtilities.isTabThumbnailAspectRatioNotOne()) {
float expectedThumbnailAspectRatio =
(float) ChromeFeatureList.getFieldTrialParamByFeatureAsDouble(
ChromeFeatureList.TAB_GRID_LAYOUT_ANDROID,
......
......@@ -5,6 +5,7 @@
package org.chromium.chrome.browser.tasks.tab_management;
import androidx.annotation.Nullable;
import androidx.annotation.VisibleForTesting;
import org.chromium.base.ContextUtils;
import org.chromium.base.SysUtils;
......@@ -23,6 +24,7 @@ import java.util.List;
public class TabUiFeatureUtilities {
private static Boolean sSearchTermChipEnabledForTesting;
private static Boolean sTabManagementModuleSupportedForTesting;
private static Double sTabThumbnailAspectRatioForTesting;
/**
* Set whether the search term chip in Grid tab switcher is enabled for testing.
......@@ -124,4 +126,24 @@ public class TabUiFeatureUtilities {
return isTabGroupsAndroidEnabled()
&& ChromeFeatureList.isEnabled(ChromeFeatureList.TAB_GROUPS_CONTINUATION_ANDROID);
}
/**
* @return Whether the thumbnail_aspect_ratio field trail is set.
*/
public static boolean isTabThumbnailAspectRatioNotOne() {
double aspectRatio;
if (sTabThumbnailAspectRatioForTesting != null) {
aspectRatio = sTabThumbnailAspectRatioForTesting;
} else {
aspectRatio = ChromeFeatureList.getFieldTrialParamByFeatureAsDouble(
ChromeFeatureList.TAB_GRID_LAYOUT_ANDROID, "thumbnail_aspect_ratio", 1.0);
}
return Double.compare(1.0, aspectRatio) != 0;
}
@VisibleForTesting
public static void setTabThumbnailAspectRatioForTesting(Double value) {
sTabThumbnailAspectRatioForTesting = value;
}
}
......@@ -28,7 +28,6 @@ import org.junit.Test;
import org.junit.runner.RunWith;
import org.chromium.base.Callback;
import org.chromium.chrome.browser.flags.CachedFeatureFlags;
import org.chromium.chrome.browser.tab.Tab;
import org.chromium.chrome.tab_ui.R;
import org.chromium.chrome.test.ChromeJUnit4ClassRunner;
......@@ -120,7 +119,7 @@ public class TabListViewHolderTest extends DummyUiActivityTestCase {
@Override
public void setUpTest() throws Exception {
super.setUpTest();
CachedFeatureFlags.enableTabThumbnailAspectRatioForTesting(false);
TabUiFeatureUtilities.setTabThumbnailAspectRatioForTesting(1.0d);
TabUiFeatureUtilities.setSearchTermChipEnabledForTesting(true);
ViewGroup view = new LinearLayout(getActivity());
FrameLayout.LayoutParams params = new FrameLayout.LayoutParams(
......@@ -551,7 +550,7 @@ public class TabListViewHolderTest extends DummyUiActivityTestCase {
mStripMCP.destroy();
mGridMCP.destroy();
mSelectableMCP.destroy();
CachedFeatureFlags.enableTabThumbnailAspectRatioForTesting(null);
TabUiFeatureUtilities.setTabThumbnailAspectRatioForTesting(null);
TabUiFeatureUtilities.setSearchTermChipEnabledForTesting(null);
super.tearDownTest();
}
......
......@@ -206,7 +206,7 @@ public class TabContentManager {
mPriorityTabIds = new int[mFullResThumbnailsMaxSize];
if (CachedFeatureFlags.isTabThumbnailAspectRatioNotOne()
if (TabUiFeatureUtilities.isTabThumbnailAspectRatioNotOne()
|| CachedFeatureFlags.getValue(ALLOW_TO_REFETCH_TAB_THUMBNAIL_VARIATION)) {
mRefectchedTabIds = new HashSet<>();
mExpectedThumbnailAspectRatio =
......@@ -558,7 +558,7 @@ public class TabContentManager {
Matrix matrix = new Matrix();
matrix.setScale(downsamplingScale, downsamplingScale);
Bitmap resized = Bitmap.createBitmap(bitmap, 0, 0, bitmap.getWidth(),
CachedFeatureFlags.isTabThumbnailAspectRatioNotOne()
TabUiFeatureUtilities.isTabThumbnailAspectRatioNotOne()
? Math.min(bitmap.getHeight(),
(int) (bitmap.getWidth() * 1.0 / mExpectedThumbnailAspectRatio))
: min(bitmap.getWidth(), bitmap.getHeight()),
......
......@@ -114,7 +114,6 @@ public class CachedFeatureFlags {
private static Map<String, Boolean> sBoolValuesReturned = new HashMap<>();
private static Map<String, String> sStringValuesReturned = new HashMap<>();
private static String sReachedCodeProfilerTrialGroup;
private static Boolean sEnabledTabThumbnailApsectRatioForTesting;
/**
* Checks if a cached feature flag is enabled.
......@@ -330,23 +329,6 @@ public class CachedFeatureFlags {
return sReachedCodeProfilerTrialGroup;
}
/**
* @return Whether the thumbnail_aspect_ratio field trail is set.
*/
public static boolean isTabThumbnailAspectRatioNotOne() {
if (sEnabledTabThumbnailApsectRatioForTesting != null) {
return sEnabledTabThumbnailApsectRatioForTesting;
}
double expectedAspectRatio = ChromeFeatureList.getFieldTrialParamByFeatureAsDouble(
ChromeFeatureList.TAB_GRID_LAYOUT_ANDROID, "thumbnail_aspect_ratio", 1.0);
return Double.compare(1.0, expectedAspectRatio) != 0;
}
public static void enableTabThumbnailAspectRatioForTesting(Boolean enabled) {
sEnabledTabThumbnailApsectRatioForTesting = enabled;
}
static boolean getConsistentBooleanValue(String preferenceName, boolean defaultValue) {
Boolean flag = sBoolValuesReturned.get(preferenceName);
if (flag == null) {
......
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