Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1927)

Unified Diff: chrome/android/java/src/org/chromium/chrome/browser/compositor/bottombar/contextualsearch/ContextualSearchPanelBase.java

Issue 1237913002: [Contextual Search] Adds basic support for narrow Search Panel. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/android/java/src/org/chromium/chrome/browser/compositor/bottombar/contextualsearch/ContextualSearchPanelBase.java
diff --git a/chrome/android/java/src/org/chromium/chrome/browser/compositor/bottombar/contextualsearch/ContextualSearchPanelBase.java b/chrome/android/java/src/org/chromium/chrome/browser/compositor/bottombar/contextualsearch/ContextualSearchPanelBase.java
index ffa11e8ee6a47cfa9392076d4e03825c5971ac01..4e66f182912daee62118da67b01c849c26094f4d 100644
--- a/chrome/android/java/src/org/chromium/chrome/browser/compositor/bottombar/contextualsearch/ContextualSearchPanelBase.java
+++ b/chrome/android/java/src/org/chromium/chrome/browser/compositor/bottombar/contextualsearch/ContextualSearchPanelBase.java
@@ -44,12 +44,21 @@ abstract class ContextualSearchPanelBase extends ContextualSearchPanelStateHandl
private static final float SEARCH_BAR_BORDER_HEIGHT_DP = 1.f;
/**
- * The height of the expanded Contextual Search Panel relative to the height
- * of the screen.
+ * The height of the expanded Search Panel relative to the height of the screen.
*/
private static final float EXPANDED_PANEL_HEIGHT_PERCENTAGE = .7f;
/**
+ * The width of the small version of the Search Panel in dps.
+ */
+ private static final float SMALL_PANEL_WIDTH_DP = 600.f;
+
+ /**
+ * The minimum width a screen should have in order to trigger the small version of the Panel.
+ */
+ private static final float SMALL_PANEL_WIDTH_THRESHOLD_DP = 620.f;
+
+ /**
* The height of the Contextual Search Panel's Shadow in dps.
*/
private static final float PANEL_SHADOW_HEIGHT_DP = 16.f;
@@ -277,6 +286,9 @@ abstract class ContextualSearchPanelBase extends ContextualSearchPanelStateHandl
private float mLayoutHeight;
private boolean mIsToolbarShowing;
+ private float mMaximumWidth;
+ private float mMaximumHeight;
+
/**
* Called when the size of the view has changed.
*
@@ -288,19 +300,41 @@ abstract class ContextualSearchPanelBase extends ContextualSearchPanelStateHandl
mLayoutWidth = width;
mLayoutHeight = height;
mIsToolbarShowing = isToolbarShowing;
+
+ mMaximumWidth = calculateSearchPanelWidth();
+ mMaximumHeight = getPanelHeightFromState(PanelState.MAXIMIZED);
+ }
+
+ /**
+ * @return Whether the Panel is in fullscreen size.
+ */
+ protected boolean isFullscreenSizePanel() {
+ return getFullscreenWidth() <= SMALL_PANEL_WIDTH_THRESHOLD_DP;
+ }
+
+ /**
+ * @return The current X-position of the Contextual Search Panel.
+ */
+ protected float calculateSearchPanelX() {
+ return isFullscreenSizePanel() ? 0.f :
+ Math.round((getFullscreenWidth() - calculateSearchPanelWidth()) / 2.f);
}
/**
- * Returns the Y position of the Contextual Search Panel.
- * Layouts supporting Contextual Search should override this method.
- *
* @return The current Y-position of the Contextual Search Panel.
*/
- public float getContextualSearchPanelY() {
+ protected float calculateSearchPanelY() {
return getFullscreenHeight() - mHeight;
}
/**
+ * @return The current width of the Contextual Search Panel.
+ */
+ protected float calculateSearchPanelWidth() {
+ return isFullscreenSizePanel() ? getFullscreenWidth() : SMALL_PANEL_WIDTH_DP;
+ }
+
+ /**
* @return The height of the Chrome toolbar in dp.
*/
public float getToolbarHeight() {
@@ -354,6 +388,20 @@ abstract class ContextualSearchPanelBase extends ContextualSearchPanelStateHandl
return height;
}
+ /**
+ * @return The maximum width of the Contextual Search Panel in pixels.
+ */
+ public int getMaximumWidthPx() {
+ return Math.round(mMaximumWidth / mPxToDp);
+ }
+
+ /**
+ * @return The maximum height of the Contextual Search Panel in pixels.
+ */
+ public int getMaximumHeightPx() {
+ return Math.round(mMaximumHeight / mPxToDp);
+ }
+
// ============================================================================================
// UI States
// ============================================================================================
@@ -401,30 +449,37 @@ abstract class ContextualSearchPanelBase extends ContextualSearchPanelStateHandl
// Contextual Search Panel states
// --------------------------------------------------------------------------------------------
+ private float mOffsetX;
private float mOffsetY;
private float mHeight;
- private float mWidth;
private boolean mIsMaximized;
/**
* @return The vertical offset of the Contextual Search Panel.
*/
+ public float getOffsetX() {
+ return mOffsetX;
+ }
+
+ /**
+ * @return The vertical offset of the Contextual Search Panel.
+ */
public float getOffsetY() {
return mOffsetY;
}
/**
- * @return The height of the Contextual Search Panel.
+ * @return The width of the Contextual Search Panel in dps.
*/
- public float getHeight() {
- return mHeight;
+ public float getWidth() {
+ return mMaximumWidth;
}
/**
- * @return The width of the Contextual Search Panel.
+ * @return The height of the Contextual Search Panel in dps.
*/
- public float getWidth() {
- return mWidth;
+ public float getHeight() {
+ return mHeight;
}
/**
@@ -449,7 +504,6 @@ abstract class ContextualSearchPanelBase extends ContextualSearchPanelStateHandl
private boolean mSearchBarShadowVisible = false;
private float mSearchBarShadowOpacity = 0.f;
- private boolean mSearchProviderIconVisible;
private float mSearchProviderIconOpacity;
private float mSearchIconOpacity;
@@ -898,9 +952,9 @@ abstract class ContextualSearchPanelBase extends ContextualSearchPanelStateHandl
* @param percentage The completion percentage of the transition.
*/
private void updatePanelSize(float height, PanelState endState, float percentage) {
- mWidth = getFullscreenWidth();
+ mOffsetX = calculateSearchPanelX();
+ mOffsetY = calculateSearchPanelY();
mHeight = height;
- mOffsetY = getContextualSearchPanelY();
mIsMaximized = height == getPanelHeightFromState(PanelState.MAXIMIZED);
}
@@ -1216,6 +1270,10 @@ abstract class ContextualSearchPanelBase extends ContextualSearchPanelStateHandl
* @return The target offset Y.
*/
private float calculateBasePageTargetY(PanelState expandedState) {
+ // Only a fullscreen wide Panel should offset the base page. A small panel should
+ // always return zero to ensure the Base Page remains in the same position.
+ if (!isFullscreenSizePanel()) return 0.f;
+
// Convert from px to dp.
final float selectionY = mBasePageSelectionYPx * mPxToDp;
@@ -1305,6 +1363,13 @@ abstract class ContextualSearchPanelBase extends ContextualSearchPanelStateHandl
LayoutInflater.from(mContext).inflate(R.layout.contextual_search_view, mContainerView);
mControl = (ContextualSearchControl)
mContainerView.findViewById(R.id.contextual_search_view);
+
+ // Adjust size for small Panel.
+ if (!isFullscreenSizePanel()) {
+ mControl.getLayoutParams().width = getMaximumWidthPx();
+ mControl.requestLayout();
+ }
+
if (mResourceLoader != null) {
mResourceLoader.registerResource(R.id.contextual_search_view,
mControl.getResourceAdapter());
@@ -1387,13 +1452,22 @@ abstract class ContextualSearchPanelBase extends ContextualSearchPanelStateHandl
R.layout.contextual_search_opt_out_promo, mContainerView);
mPromoView = (ContextualSearchOptOutPromo)
mContainerView.findViewById(R.id.contextual_search_opt_out_promo);
+
+ final int maximumWidth = getMaximumWidthPx();
+
+ // Adjust size for small Panel.
+ if (!isFullscreenSizePanel()) {
+ mPromoView.getLayoutParams().width = maximumWidth;
+ mPromoView.requestLayout();
+ }
+
if (mResourceLoader != null) {
mResourceLoader.registerResource(R.id.contextual_search_opt_out_promo,
mPromoView.getResourceAdapter());
}
mPromoView.setPromoHost(this);
- setPromoContentHeightPx(mPromoView.getHeightForGivenWidth(mContainerView.getWidth()));
+ setPromoContentHeightPx(mPromoView.getHeightForGivenWidth(maximumWidth));
}
assert mPromoView != null;
@@ -1422,6 +1496,7 @@ abstract class ContextualSearchPanelBase extends ContextualSearchPanelStateHandl
public void showPromoViewAtYPosition(float y) {
if (mPromoView == null || !isPromoAvailable()) return;
+ mPromoView.setTranslationX(getOffsetX() / mPxToDp);
mPromoView.setTranslationY(y);
mPromoView.setVisibility(View.VISIBLE);

Powered by Google App Engine
This is Rietveld 408576698