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