Commit bf36900f authored by pedrosimonetti's avatar pedrosimonetti Committed by Commit bot

[Contextual Search] Adds offscreen View rendering capability.

BUG=535373

Review URL: https://codereview.chromium.org/1361153004

Cr-Commit-Position: refs/heads/master@{#351147}
parent 475d0979
// Copyright 2015 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
package org.chromium.chrome.browser.compositor.bottombar.contextualsearch;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.ViewGroup;
import android.view.ViewTreeObserver.OnDrawListener;
import android.widget.TextView;
import org.chromium.chrome.R;
import org.chromium.ui.resources.dynamics.ViewResourceAdapter;
/**
* Root ControlContainer for the Contextual Search panel.
* Handles user interaction with the bottom bar text.
* Based on ToolbarControlContainer.
*/
public class BottomBarTextControl {
/**
* Object Replacement Character that is used in place of HTML objects that cannot be represented
* as text (e.g. images). Contextual search panel should not be displaying such characters as
* they get shown as [obj] character.
*/
private static final String OBJ_CHARACTER = "\uFFFC";
private Context mContext;
private ViewGroup mContainer;
private ViewGroup mSearchContextView;
private TextView mSelectedText;
private TextView mStartText;
private TextView mEndText;
private ViewResourceAdapter mSearchContextResourceAdapter;
private boolean mIsSearchContextDirty;
private ViewGroup mSearchTermView;
private TextView mSearchTermText;
private ViewResourceAdapter mSearchTermResourceAdapter;
private boolean mIsSearchTermDirty;
/**
* Constructs a new bottom bar control container by inflating views from XML.
*
* @param context The context used to build this view.
* @param container The parent view for the bottom bar views.
*/
public BottomBarTextControl(Context context, ViewGroup container) {
mContext = context;
mContainer = container;
// TODO(pedrosimonetti): For now, we're still relying on a Android View
// to render the text that appears in the Search Bar. The View will be
// invisible and will not capture events. Consider rendering the text
// in the Compositor and get rid of the View entirely.
// TODO(twellington): Make this class more generic so that it can be reused by ReaderMode.
LayoutInflater.from(mContext).inflate(R.layout.contextual_search_term_view, container);
mSearchTermView = (ViewGroup) container.findViewById(R.id.contextual_search_term_view);
mSearchTermText = (TextView) container.findViewById(R.id.contextual_search_term);
mSearchTermResourceAdapter = new ViewResourceAdapter(mSearchTermView);
// mSearchTermResourceAdapter needs to be invalidated in OnDraw after it has been measured.
// Without this OnDrawListener, the search text view wasn't always appearing on the panel
// for RTL text.
mSearchTermView.getViewTreeObserver().addOnDrawListener(new OnDrawListener() {
@Override
public void onDraw() {
if (mIsSearchTermDirty) {
mSearchTermResourceAdapter.invalidate(null);
mIsSearchTermDirty = false;
}
}
});
LayoutInflater.from(mContext).inflate(R.layout.contextual_search_context_view, container);
mSearchContextView = (ViewGroup) container.findViewById(
R.id.contextual_search_context_view);
mSelectedText = (TextView) mSearchContextView.findViewById(R.id.selected_text);
mStartText = (TextView) mSearchContextView.findViewById(R.id.surrounding_text_start);
mEndText = (TextView) mSearchContextView.findViewById(R.id.surrounding_text_end);
mSearchContextResourceAdapter = new ViewResourceAdapter(mSearchContextView);
// mSearchContextResourceAdapter needs to be invalidated in OnDraw after it has been
// measured. Without this OnDrawListener, the selected text view was occasionally getting
// ellipsized.
mSearchContextView.getViewTreeObserver().addOnDrawListener(new OnDrawListener() {
@Override
public void onDraw() {
if (mIsSearchContextDirty) {
mSearchContextResourceAdapter.invalidate(null);
mIsSearchContextDirty = false;
}
}
});
}
/**
* @return The {@link ViewResourceAdapter} that exposes the search context view as a CC
* resource.
*/
public ViewResourceAdapter getSearchContextResourceAdapter() {
return mSearchContextResourceAdapter;
}
/**
* @return The {@link ViewResourceAdapter} that exposes the search term view as a CC resource.
*/
public ViewResourceAdapter getSearchTermResourceAdapter() {
return mSearchTermResourceAdapter;
}
/**
* @param width The width of the container.
*/
public void setWidth(int width) {
mSearchContextView.getLayoutParams().width = width;
mSearchContextView.requestLayout();
mSearchTermView.getLayoutParams().width = width;
mSearchTermView.requestLayout();
}
/**
* Removes the bottom bar views from the parent container.
*/
public void removeFromContainer() {
mContainer.removeView(mSearchTermView);
mContainer.removeView(mSearchContextView);
}
/**
* Sets the search context to display in the control.
* @param selection The portion of the context that represents the user's selection.
* @param start The portion of the context from its start to the selection.
* @param end The portion of the context the selection to its end.
*/
public void setSearchContext(String selection, String start, String end) {
mSelectedText.setText(sanitizeText(selection));
mStartText.setText(sanitizeText(start));
mEndText.setText(sanitizeText(end));
mIsSearchContextDirty = true;
}
/**
* Sets the search term to display in the control.
* @param searchTerm The string that represents the search term.
*/
public void setSearchTerm(String searchTerm) {
mSearchTermText.setText(searchTerm);
mIsSearchTermDirty = true;
}
private String sanitizeText(String text) {
if (text == null) return null;
return text.replace(OBJ_CHARACTER, " ");
}
}
// Copyright 2015 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
package org.chromium.chrome.browser.compositor.bottombar.contextualsearch;
import android.content.Context;
import android.view.ViewGroup;
import org.chromium.ui.resources.dynamics.DynamicResourceLoader;
/**
* Controls the Search Bar in the Contextual Search Panel.
*/
public class ContextualSearchBarControl {
/**
* The {@link ContextualSearchContextControl} used to control the Search Context View.
*/
private final ContextualSearchContextControl mContextControl;
/**
* The {@link ContextualSearchTermControl} used to control the Search Term View.
*/
private final ContextualSearchTermControl mSearchTermControl;
/**
* Constructs a new bottom bar control container by inflating views from XML.
*
* @param panel The panel delegate.
* @param context The context used to build this view.
* @param container The parent view for the bottom bar views.
* @param loader The resource loader that will handle the snapshot capturing.
*/
public ContextualSearchBarControl(ContextualSearchPanelDelegate panel, Context context,
ViewGroup container, DynamicResourceLoader loader) {
mContextControl = new ContextualSearchContextControl(panel, context, container, loader);
mSearchTermControl = new ContextualSearchTermControl(panel, context, container, loader);
}
/**
* Removes the bottom bar views from the parent container.
*/
public void destroy() {
mContextControl.destroy();
mSearchTermControl.destroy();
}
/**
* Sets the search context to display in the control.
* @param selection The portion of the context that represents the user's selection.
* @param start The portion of the context before the selection.
* @param end The portion of the context after the selection.
*/
public void setSearchContext(String selection, String start, String end) {
mContextControl.setSearchContext(selection, start, end);
}
/**
* Sets the search term to display in the control.
* @param searchTerm The string that represents the search term.
*/
public void setSearchTerm(String searchTerm) {
mSearchTermControl.setSearchTerm(searchTerm);
}
/**
* @return The Id of the Search Context View.
*/
public int getSearchContextViewId() {
return mContextControl.getViewId();
}
/**
* @return The Id of the Search Term View.
*/
public int getSearchTermViewId() {
return mSearchTermControl.getViewId();
}
}
// Copyright 2015 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
package org.chromium.chrome.browser.compositor.bottombar.contextualsearch;
import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;
import org.chromium.chrome.R;
import org.chromium.ui.resources.dynamics.DynamicResourceLoader;
/**
* Controls the Search Context View that is used as a dynamic resource.
*/
public class ContextualSearchContextControl extends ContextualSearchInflater {
/**
* The selected text View.
*/
private TextView mSelectedText;
/**
* The start of the surrounding text View.
*/
private TextView mStartText;
/**
* The end of the surrounding text View.
*/
private TextView mEndText;
/**
* @param panel The panel delegate.
* @param context The Android Context used to inflate the View.
* @param container The container View used to inflate the View.
* @param resourceLoader The resource loader that will handle the snapshot capturing.
*/
public ContextualSearchContextControl(ContextualSearchPanelDelegate panel,
Context context,
ViewGroup container,
DynamicResourceLoader resourceLoader) {
super(panel, R.layout.contextual_search_context_view, R.id.contextual_search_context_view,
context, container, resourceLoader);
}
/**
* Sets the search context to display in the control.
* @param selection The portion of the context that represents the user's selection.
* @param start The portion of the context before the selection.
* @param end The portion of the context after the selection.
*/
public void setSearchContext(String selection, String start, String end) {
inflate();
mStartText.setText(sanitizeText(start));
mSelectedText.setText(sanitizeText(selection));
mEndText.setText(sanitizeText(end));
invalidate();
}
@Override
protected void onFinishInflate() {
super.onFinishInflate();
View view = getView();
mSelectedText = (TextView) view.findViewById(R.id.selected_text);
mStartText = (TextView) view.findViewById(R.id.surrounding_text_start);
mEndText = (TextView) view.findViewById(R.id.surrounding_text_end);
}
}
// Copyright 2015 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
package org.chromium.chrome.browser.compositor.bottombar.contextualsearch;
import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import org.chromium.ui.resources.dynamics.DynamicResourceLoader;
import org.chromium.ui.resources.dynamics.ViewResourceInflater;
/**
* A helper class for inflating Contextual Search Views.
*/
abstract class ContextualSearchInflater extends ViewResourceInflater {
/**
* The panel delegate used to get information about the panel layout.
*/
private ContextualSearchPanelDelegate mSearchPanelDelegate;
/**
* Object Replacement Character that is used in place of HTML objects that cannot be represented
* as text (e.g. images). Contextual search panel should not be displaying such characters as
* they get shown as [obj] character.
*/
private static final String OBJ_CHARACTER = "\uFFFC";
/**
* @param panelDelegate The panel delegate.
* @param layoutId The XML Layout that declares the View.
* @param viewId The id of the root View of the Layout.
* @param context The Android Context used to inflate the View.
* @param container The container View used to inflate the View.
* @param resourceLoader The resource loader that will handle the snapshot capturing.
*/
public ContextualSearchInflater(ContextualSearchPanelDelegate panelDelegate,
int layoutId,
int viewId,
Context context,
ViewGroup container,
DynamicResourceLoader resourceLoader) {
super(layoutId, viewId, context, container, resourceLoader);
mSearchPanelDelegate = panelDelegate;
}
@Override
public void destroy() {
super.destroy();
mSearchPanelDelegate = null;
}
@Override
protected void onFinishInflate() {
if (!mSearchPanelDelegate.isFullscreenSizePanel()) {
setWidth(mSearchPanelDelegate.getMaximumWidthPx());
}
}
@Override
protected int getWidthMeasureSpec() {
return View.MeasureSpec.makeMeasureSpec(
mSearchPanelDelegate.getMaximumWidthPx(), View.MeasureSpec.EXACTLY);
}
/**
* @param width The width of the view to be inforced.
*/
private void setWidth(int width) {
// When the view is attached, we need to force the layout to have a specific width
// because the container is "full-width" (as wide as a tab). When not attached,
// ViewResourceInflater#layout() will properly resize the view offscreen.
if (shouldAttachView()) {
View view = getView();
if (view != null) {
view.getLayoutParams().width = width;
view.requestLayout();
}
}
}
/**
* Sanitizes a string to be displayed on the Contextual Search Bar.
* @param text The text to be sanitized.
* @return The sanitized text.
*/
public static String sanitizeText(String text) {
if (text == null) return null;
return text.replace(OBJ_CHARACTER, " ").trim();
}
}
...@@ -215,6 +215,7 @@ public class ContextualSearchPanel extends ContextualSearchPanelAnimation ...@@ -215,6 +215,7 @@ public class ContextualSearchPanel extends ContextualSearchPanelAnimation
@Override @Override
protected void onClose(StateChangeReason reason) { protected void onClose(StateChangeReason reason) {
destroySearchBarControl();
if (mOverlayPanelContent != null) { if (mOverlayPanelContent != null) {
mOverlayPanelContent.destroyContentView(); mOverlayPanelContent.destroyContentView();
} }
...@@ -571,12 +572,6 @@ public class ContextualSearchPanel extends ContextualSearchPanelAnimation ...@@ -571,12 +572,6 @@ public class ContextualSearchPanel extends ContextualSearchPanelAnimation
super.onSearchResultsLoaded(wasPrefetch); super.onSearchResultsLoaded(wasPrefetch);
} }
@Override
public BottomBarTextControl getBottomBarTextControl() {
// NOTE(pedrosimonetti): exposing superclass method to the interface.
return super.getBottomBarTextControl();
}
@Override @Override
public boolean shouldAnimatePanelCloseOnPromoteToTab() { public boolean shouldAnimatePanelCloseOnPromoteToTab() {
return mSearchPanelFeatures.shouldAnimatePanelCloseOnPromoteToTab(); return mSearchPanelFeatures.shouldAnimatePanelCloseOnPromoteToTab();
...@@ -585,20 +580,20 @@ public class ContextualSearchPanel extends ContextualSearchPanelAnimation ...@@ -585,20 +580,20 @@ public class ContextualSearchPanel extends ContextualSearchPanelAnimation
@Override @Override
public void displaySearchTerm(String searchTerm) { public void displaySearchTerm(String searchTerm) {
cancelSearchTermResolutionAnimation(); cancelSearchTermResolutionAnimation();
getBottomBarTextControl().setSearchTerm(searchTerm); getSearchBarControl().setSearchTerm(searchTerm);
resetBottomBarSearchTermVisibility(); resetSearchBarTermOpacity();
} }
@Override @Override
public void displaySearchContext(String selection, String start, String end) { public void displaySearchContext(String selection, String start, String end) {
cancelSearchTermResolutionAnimation(); cancelSearchTermResolutionAnimation();
getBottomBarTextControl().setSearchContext(selection, start, end); getSearchBarControl().setSearchContext(selection, start, end);
resetBottomBarSearchContextVisibility(); resetSearchBarContextOpacity();
} }
@Override @Override
public void onSearchTermResolutionResponse(String searchTerm) { public void onSearchTermResolutionResponse(String searchTerm) {
getBottomBarTextControl().setSearchTerm(searchTerm); getSearchBarControl().setSearchTerm(searchTerm);
animateSearchTermResolution(); animateSearchTermResolution();
} }
...@@ -617,6 +612,11 @@ public class ContextualSearchPanel extends ContextualSearchPanelAnimation ...@@ -617,6 +612,11 @@ public class ContextualSearchPanel extends ContextualSearchPanelAnimation
getOverlayPanelContent().loadUrl(url); getOverlayPanelContent().loadUrl(url);
} }
@Override
public boolean didLoadAnyUrl() {
return mOverlayPanelContent != null && mOverlayPanelContent.didLoadAnyUrl();
}
@Override @Override
public void updateTopControlState() { public void updateTopControlState() {
if (mOverlayPanelContent == null) return; if (mOverlayPanelContent == null) return;
...@@ -635,11 +635,106 @@ public class ContextualSearchPanel extends ContextualSearchPanelAnimation ...@@ -635,11 +635,106 @@ public class ContextualSearchPanel extends ContextualSearchPanelAnimation
} }
} }
// ============================================================================================
// ContextualSearchBarControl
// ============================================================================================
private ContextualSearchBarControl mContextualSearchBarControl;
private float mSearchBarContextOpacity = 1.f;
private float mSearchBarTermOpacity = 1.f;
/**
* @return The opacity of the SearchBar's search context.
*/
public float getSearchBarContextOpacity() {
return mSearchBarContextOpacity;
}
/**
* @return The opacity of the SearchBar's search term.
*/
public float getSearchBarTermOpacity() {
return mSearchBarTermOpacity;
}
/**
* @return The Id of the Search Context View.
*/
public int getSearchContextViewId() {
return getSearchBarControl().getSearchContextViewId();
}
/**
* @return The Id of the Search Term View.
*/
public int getSearchTermViewId() {
return getSearchBarControl().getSearchTermViewId();
}
/**
* Creates the ContextualSearchBarControl, if needed. The Views are set to INVISIBLE, because
* they won't actually be displayed on the screen (their snapshots will be displayed instead).
*/
protected ContextualSearchBarControl getSearchBarControl() {
assert mContainerView != null;
assert mResourceLoader != null;
if (mContextualSearchBarControl == null) {
mContextualSearchBarControl =
new ContextualSearchBarControl(this, mContext, mContainerView, mResourceLoader);
}
assert mContextualSearchBarControl != null;
return mContextualSearchBarControl;
}
/**
* Destroys the ContextualSearchBarControl.
*/
protected void destroySearchBarControl() {
if (mContextualSearchBarControl != null) {
mContextualSearchBarControl.destroy();
mContextualSearchBarControl = null;
}
}
@Override @Override
public boolean didLoadAnyUrl() { protected void updateSearchBarTextOpacity(float percentage) {
return mOverlayPanelContent != null && mOverlayPanelContent.didLoadAnyUrl(); // The search context will start fading out before the search term starts fading in.
// They will both be partially visible for overlapPercentage of the animation duration.
float overlapPercentage = .75f;
float fadingOutPercentage = Math.max(1 - (percentage / overlapPercentage), 0.f);
float fadingInPercentage =
Math.max(percentage - (1 - overlapPercentage), 0.f) / overlapPercentage;
mSearchBarContextOpacity = fadingOutPercentage;
mSearchBarTermOpacity = fadingInPercentage;
}
/**
* Resets the SearchBar text opacity when a new search context is set. The search
* context is made visible and the search term invisible.
*/
private void resetSearchBarContextOpacity() {
mSearchBarContextOpacity = 1.f;
mSearchBarTermOpacity = 0.f;
}
/**
* Resets the SearchBar text opacity when a new search term is set. The search
* term is made visible and the search context invisible.
*/
private void resetSearchBarTermOpacity() {
mSearchBarContextOpacity = 0.f;
mSearchBarTermOpacity = 1.f;
} }
// ============================================================================================
// Panel Content
// ============================================================================================
// TODO(pedrosimonetti): move content code to its own section.
@Override @Override
public ContentViewCore getContentViewCore() { public ContentViewCore getContentViewCore() {
// Expose OverlayPanelContent method. // Expose OverlayPanelContent method.
......
...@@ -96,6 +96,18 @@ public abstract class ContextualSearchPanelAnimation extends ContextualSearchPan ...@@ -96,6 +96,18 @@ public abstract class ContextualSearchPanelAnimation extends ContextualSearchPan
mUpdateHost = updateHost; mUpdateHost = updateHost;
} }
// ============================================================================================
// Custom Animations
// ============================================================================================
/**
* Updates the UI state for the SearchBar text. The search context view will fade out
* while the search term fades in.
*
* @param percentage The visibility percentage of the search term view.
*/
protected abstract void updateSearchBarTextOpacity(float percentage);
// ============================================================================================ // ============================================================================================
// Animation API // Animation API
// ============================================================================================ // ============================================================================================
...@@ -366,7 +378,7 @@ public abstract class ContextualSearchPanelAnimation extends ContextualSearchPan ...@@ -366,7 +378,7 @@ public abstract class ContextualSearchPanelAnimation extends ContextualSearchPan
} else if (prop == Property.PROMO_VISIBILITY) { } else if (prop == Property.PROMO_VISIBILITY) {
setPromoVisibilityForOptInAnimation(value); setPromoVisibilityForOptInAnimation(value);
} else if (prop == Property.BOTTOM_BAR_TEXT_VISIBILITY) { } else if (prop == Property.BOTTOM_BAR_TEXT_VISIBILITY) {
updateBottomBarTextVisibility(value); updateSearchBarTextOpacity(value);
} }
} }
......
...@@ -189,7 +189,7 @@ abstract class ContextualSearchPanelBase extends ContextualSearchPanelStateHandl ...@@ -189,7 +189,7 @@ abstract class ContextualSearchPanelBase extends ContextualSearchPanelStateHandl
/** /**
* The current context. * The current context.
*/ */
private final Context mContext; protected final Context mContext;
/** /**
* The object for handling global Contextual Search management duties * The object for handling global Contextual Search management duties
...@@ -242,8 +242,7 @@ abstract class ContextualSearchPanelBase extends ContextualSearchPanelStateHandl ...@@ -242,8 +242,7 @@ abstract class ContextualSearchPanelBase extends ContextualSearchPanelStateHandl
protected abstract void animatePromoAcceptance(); protected abstract void animatePromoAcceptance();
/** /**
* Animates the BottomBar text visibility. The BottomBar context text fades out while the * Animates the search term resolution.
* BottomBar search text fades in.
*/ */
protected abstract void animateSearchTermResolution(); protected abstract void animateSearchTermResolution();
...@@ -539,8 +538,6 @@ abstract class ContextualSearchPanelBase extends ContextualSearchPanelStateHandl ...@@ -539,8 +538,6 @@ abstract class ContextualSearchPanelBase extends ContextualSearchPanelStateHandl
// -------------------------------------------------------------------------------------------- // --------------------------------------------------------------------------------------------
private float mSearchBarMarginSide; private float mSearchBarMarginSide;
private float mSearchBarHeight; private float mSearchBarHeight;
private float mBottomBarSearchContextOpacity = 1.f;
private float mBottomBarSearchTermOpacity = 1.f;
private boolean mIsSearchBarBorderVisible; private boolean mIsSearchBarBorderVisible;
private float mSearchBarBorderY; private float mSearchBarBorderY;
private float mSearchBarBorderHeight; private float mSearchBarBorderHeight;
...@@ -567,20 +564,6 @@ abstract class ContextualSearchPanelBase extends ContextualSearchPanelStateHandl ...@@ -567,20 +564,6 @@ abstract class ContextualSearchPanelBase extends ContextualSearchPanelStateHandl
return mSearchBarHeight; return mSearchBarHeight;
} }
/**
* @return The opacity of the BottomBar search context view.
*/
public float getBottomBarSearchContextOpacity() {
return mBottomBarSearchContextOpacity;
}
/**
* @return The opacity of the BottomBar search term view.
*/
public float getBottomBarSearchTermOpacity() {
return mBottomBarSearchTermOpacity;
}
/** /**
* @return Whether the Search Bar border is visible. * @return Whether the Search Bar border is visible.
*/ */
...@@ -917,7 +900,6 @@ abstract class ContextualSearchPanelBase extends ContextualSearchPanelStateHandl ...@@ -917,7 +900,6 @@ abstract class ContextualSearchPanelBase extends ContextualSearchPanelStateHandl
if (state == PanelState.CLOSED) { if (state == PanelState.CLOSED) {
mIsShowing = false; mIsShowing = false;
destroyPromoView(); destroyPromoView();
destroyBottomBarTextControl();
onClose(reason); onClose(reason);
} else if (state == PanelState.EXPANDED && isFullscreenSizePanel() } else if (state == PanelState.EXPANDED && isFullscreenSizePanel()
|| (state == PanelState.MAXIMIZED && !isFullscreenSizePanel())) { || (state == PanelState.MAXIMIZED && !isFullscreenSizePanel())) {
...@@ -1309,8 +1291,8 @@ abstract class ContextualSearchPanelBase extends ContextualSearchPanelStateHandl ...@@ -1309,8 +1291,8 @@ abstract class ContextualSearchPanelBase extends ContextualSearchPanelStateHandl
// Resource Loader // Resource Loader
// ============================================================================================ // ============================================================================================
private ViewGroup mContainerView; protected ViewGroup mContainerView;
private DynamicResourceLoader mResourceLoader; protected DynamicResourceLoader mResourceLoader;
/** /**
* @param resourceLoader The {@link DynamicResourceLoader} to register and unregister the view. * @param resourceLoader The {@link DynamicResourceLoader} to register and unregister the view.
...@@ -1318,13 +1300,6 @@ abstract class ContextualSearchPanelBase extends ContextualSearchPanelStateHandl ...@@ -1318,13 +1300,6 @@ abstract class ContextualSearchPanelBase extends ContextualSearchPanelStateHandl
public void setDynamicResourceLoader(DynamicResourceLoader resourceLoader) { public void setDynamicResourceLoader(DynamicResourceLoader resourceLoader) {
mResourceLoader = resourceLoader; mResourceLoader = resourceLoader;
if (mBottomBarTextControl != null) {
mResourceLoader.registerResource(R.id.contextual_search_context_view,
mBottomBarTextControl.getSearchContextResourceAdapter());
mResourceLoader.registerResource(R.id.contextual_search_term_view,
mBottomBarTextControl.getSearchTermResourceAdapter());
}
if (mPromoView != null) { if (mPromoView != null) {
mResourceLoader.registerResource(R.id.contextual_search_opt_out_promo, mResourceLoader.registerResource(R.id.contextual_search_opt_out_promo,
mPromoView.getResourceAdapter()); mPromoView.getResourceAdapter());
...@@ -1340,86 +1315,6 @@ abstract class ContextualSearchPanelBase extends ContextualSearchPanelStateHandl ...@@ -1340,86 +1315,6 @@ abstract class ContextualSearchPanelBase extends ContextualSearchPanelStateHandl
mContainerView = container; mContainerView = container;
} }
// ============================================================================================
// BottomBarTextControl
// ============================================================================================
private BottomBarTextControl mBottomBarTextControl;
/**
* Creates the BottomBarTextControl, if needed. The Views are set to INVISIBLE, because they
* won't actually be displayed on the screen (their snapshots will be displayed instead).
*/
protected BottomBarTextControl getBottomBarTextControl() {
assert mContainerView != null;
if (mBottomBarTextControl == null) {
mBottomBarTextControl = new BottomBarTextControl(mContext, mContainerView);
// Adjust size for small Panel.
if (!isFullscreenSizePanel()) {
mBottomBarTextControl.setWidth(getMaximumWidthPx());
}
if (mResourceLoader != null) {
mResourceLoader.registerResource(R.id.contextual_search_context_view,
mBottomBarTextControl.getSearchContextResourceAdapter());
mResourceLoader.registerResource(R.id.contextual_search_term_view,
mBottomBarTextControl.getSearchTermResourceAdapter());
}
}
assert mBottomBarTextControl != null;
return mBottomBarTextControl;
}
protected void destroyBottomBarTextControl() {
if (mBottomBarTextControl != null) {
mBottomBarTextControl.removeFromContainer();
mBottomBarTextControl = null;
if (mResourceLoader != null) {
mResourceLoader.unregisterResource(R.id.contextual_search_context_view);
mResourceLoader.unregisterResource(R.id.contextual_search_term_view);
}
}
}
/**
* Updates the UI state for the BottomBar text. The BottomBar search context view will fade out
* while the search term fades in.
*
* @param percentage The visibility percentage of the BottomBar search term view.
*/
protected void updateBottomBarTextVisibility(float percentage) {
// The search context will start fading out before the search term starts fading in.
// They will both be partially visible for overlapPercentage of the animation duration.
float overlapPercentage = .75f;
float fadingOutPercentage = Math.max(1 - (percentage / overlapPercentage), 0.f);
float fadingInPercentage =
Math.max(percentage - (1 - overlapPercentage), 0.f) / overlapPercentage;
mBottomBarSearchContextOpacity = fadingOutPercentage;
mBottomBarSearchTermOpacity = fadingInPercentage;
}
/**
* Resets the BottomBar text visibility when a new search context is set. The BottomBar search
* context is made visible and the BottomBar search text invisible.
*/
protected void resetBottomBarSearchContextVisibility() {
mBottomBarSearchContextOpacity = 1.f;
mBottomBarSearchTermOpacity = 0.f;
}
/**
* Resets the BottomBar text visibility when a new search term is set. The BottomBar search
* term is made visible and the BottomBar search context invisible.
*/
protected void resetBottomBarSearchTermVisibility() {
mBottomBarSearchContextOpacity = 0.f;
mBottomBarSearchTermOpacity = 1.f;
}
// ============================================================================================ // ============================================================================================
// Promo Host // Promo Host
// ============================================================================================ // ============================================================================================
...@@ -1473,6 +1368,7 @@ abstract class ContextualSearchPanelBase extends ContextualSearchPanelStateHandl ...@@ -1473,6 +1368,7 @@ abstract class ContextualSearchPanelBase extends ContextualSearchPanelStateHandl
assert mContainerView != null; assert mContainerView != null;
if (mPromoView == null) { if (mPromoView == null) {
// TODO(pedrosimonetti): Refactor promo code to use ViewResourceInflater.
LayoutInflater.from(mContext).inflate( LayoutInflater.from(mContext).inflate(
R.layout.contextual_search_opt_out_promo, mContainerView); R.layout.contextual_search_opt_out_promo, mContainerView);
mPromoView = (ContextualSearchOptOutPromo) mPromoView = (ContextualSearchOptOutPromo)
......
...@@ -130,14 +130,14 @@ public interface ContextualSearchPanelDelegate { ...@@ -130,14 +130,14 @@ public interface ContextualSearchPanelDelegate {
void removeLastHistoryEntry(String historyUrl, long urlTimeMs); void removeLastHistoryEntry(String historyUrl, long urlTimeMs);
/** /**
* Shows the search term in the BottomBar. This should be called when the search term is set * Shows the search term in the SearchBar. This should be called when the search term is set
* without resolving a search context. * without search term resolution.
* @param searchTerm The string that represents the search term. * @param searchTerm The string that represents the search term.
*/ */
void displaySearchTerm(String searchTerm); void displaySearchTerm(String searchTerm);
/** /**
* Shows the search context in the BottomBar. * Shows the search context in the SearchBar.
* @param selection The portion of the context that represents the user's selection. * @param selection The portion of the context that represents the user's selection.
* @param start The portion of the context from its start to the selection. * @param start The portion of the context from its start to the selection.
* @param end The portion of the context the selection to its end. * @param end The portion of the context the selection to its end.
...@@ -145,7 +145,7 @@ public interface ContextualSearchPanelDelegate { ...@@ -145,7 +145,7 @@ public interface ContextualSearchPanelDelegate {
void displaySearchContext(String selection, String start, String end); void displaySearchContext(String selection, String start, String end);
/** /**
* Handles showing the resolved search term in the BottomBarTextControl. * Handles showing the resolved search term in the SearchBar.
* @param searchTerm The string that represents the search term. * @param searchTerm The string that represents the search term.
*/ */
void onSearchTermResolutionResponse(String searchTerm); void onSearchTermResolutionResponse(String searchTerm);
......
// Copyright 2015 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
package org.chromium.chrome.browser.compositor.bottombar.contextualsearch;
import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;
import org.chromium.chrome.R;
import org.chromium.ui.resources.dynamics.DynamicResourceLoader;
/**
* Controls the Search Term View that is used as a dynamic resource.
*/
public class ContextualSearchTermControl extends ContextualSearchInflater {
/**
* The search term View.
*/
private TextView mSearchTerm;
/**
* @param panel The panel delegate.
* @param context The Android Context used to inflate the View.
* @param container The container View used to inflate the View.
* @param resourceLoader The resource loader that will handle the snapshot capturing.
*/
public ContextualSearchTermControl(ContextualSearchPanelDelegate panel,
Context context,
ViewGroup container,
DynamicResourceLoader resourceLoader) {
super(panel, R.layout.contextual_search_term_view, R.id.contextual_search_term_view,
context, container, resourceLoader);
}
/**
* Sets the search term to display in the control.
* @param searchTerm The string that represents the search term.
*/
public void setSearchTerm(String searchTerm) {
inflate();
mSearchTerm.setText(sanitizeText(searchTerm));
invalidate();
}
@Override
protected void onFinishInflate() {
super.onFinishInflate();
View view = getView();
mSearchTerm = (TextView) view.findViewById(R.id.contextual_search_term);
}
}
...@@ -36,6 +36,9 @@ public class ContextualSearchSceneLayer extends SceneLayer { ...@@ -36,6 +36,9 @@ public class ContextualSearchSceneLayer extends SceneLayer {
* @param resourceManager * @param resourceManager
*/ */
public void update(@Nullable ContentViewCore contentViewCore, ResourceManager resourceManager) { public void update(@Nullable ContentViewCore contentViewCore, ResourceManager resourceManager) {
int searchContextViewId = mSearchPanel.getSearchContextViewId();
int searchTermViewId = mSearchPanel.getSearchTermViewId();
boolean searchPromoVisible = mSearchPanel.getPromoVisible(); boolean searchPromoVisible = mSearchPanel.getPromoVisible();
float searchPromoHeightPx = mSearchPanel.getPromoHeightPx(); float searchPromoHeightPx = mSearchPanel.getPromoHeightPx();
float searchPromoOpacity = mSearchPanel.getPromoOpacity(); float searchPromoOpacity = mSearchPanel.getPromoOpacity();
...@@ -47,8 +50,8 @@ public class ContextualSearchSceneLayer extends SceneLayer { ...@@ -47,8 +50,8 @@ public class ContextualSearchSceneLayer extends SceneLayer {
float searchBarMarginSide = mSearchPanel.getSearchBarMarginSide(); float searchBarMarginSide = mSearchPanel.getSearchBarMarginSide();
float searchBarHeight = mSearchPanel.getSearchBarHeight(); float searchBarHeight = mSearchPanel.getSearchBarHeight();
float searchContextOpacity = mSearchPanel.getBottomBarSearchContextOpacity(); float searchContextOpacity = mSearchPanel.getSearchBarContextOpacity();
float searchTermOpacity = mSearchPanel.getBottomBarSearchTermOpacity(); float searchTermOpacity = mSearchPanel.getSearchBarTermOpacity();
boolean searchBarBorderVisible = mSearchPanel.isSearchBarBorderVisible(); boolean searchBarBorderVisible = mSearchPanel.isSearchBarBorderVisible();
float searchBarBorderY = mSearchPanel.getSearchBarBorderY(); float searchBarBorderY = mSearchPanel.getSearchBarBorderY();
...@@ -70,8 +73,8 @@ public class ContextualSearchSceneLayer extends SceneLayer { ...@@ -70,8 +73,8 @@ public class ContextualSearchSceneLayer extends SceneLayer {
nativeUpdateContextualSearchLayer(mNativePtr, nativeUpdateContextualSearchLayer(mNativePtr,
R.drawable.contextual_search_bar_background, R.drawable.contextual_search_bar_background,
R.id.contextual_search_context_view, searchContextViewId,
R.id.contextual_search_term_view, searchTermViewId,
R.drawable.contextual_search_bar_shadow, R.drawable.contextual_search_bar_shadow,
R.drawable.google_icon, R.drawable.google_icon,
R.drawable.breadcrumb_arrow, R.drawable.breadcrumb_arrow,
......
...@@ -19,7 +19,7 @@ import org.chromium.ui.resources.dynamics.ViewResourceAdapter; ...@@ -19,7 +19,7 @@ import org.chromium.ui.resources.dynamics.ViewResourceAdapter;
/** /**
* Root ControlContainer for the Reader Mode panel. * Root ControlContainer for the Reader Mode panel.
* Handles user interaction with the Reader Mode control. * Handles user interaction with the Reader Mode control.
* See {@link BottomBarTextControl} for inspiration, based on ToolbarControlContainer. * See {@link ContextualSearchBarControl} for inspiration, based on ToolbarControlContainer.
*/ */
public class ReaderModeControl extends LinearLayout { public class ReaderModeControl extends LinearLayout {
private ViewResourceAdapter mResourceAdapter; private ViewResourceAdapter mResourceAdapter;
......
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