Skip to content

Commit

Permalink
Revert of [Contextual Search] Remove opt-in code. (patchset crosswalk…
Browse files Browse the repository at this point in the history
…-project#6 id:100001 of https://codereview.chromium.org/1103163004/)

Reason for revert:
It broke Clank bots.

Original issue's description:
> [Contextual Search] Remove opt-in code.
>
> This CL requires a downstream change:
> https://chrome-internal-review.googlesource.com/#/c/214963/
>
> BUG=482618
> [email protected], [email protected], [email protected]
>
> Committed: https://chromium.googlesource.com/chromium/src/+/277f043bb56fb1e4bb93d9d17fc3de4ada0eb81b

[email protected],[email protected],[email protected],[email protected]
NOPRESUBMIT=true
NOTREECHECKS=true
NOTRY=true
BUG=482618

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

Cr-Commit-Position: refs/heads/master@{#330248}

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

Cr-Commit-Position: refs/branch-heads/2403@{crosswalk-project#9}
Cr-Branched-From: f54b809-refs/heads/master@{#330231}
  • Loading branch information
liutikas committed May 18, 2015
1 parent 5b4e0b4 commit 93c2ea2
Show file tree
Hide file tree
Showing 18 changed files with 856 additions and 41 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,10 @@ public abstract class ChromeSwitches {
/** Enable Contextual Search. */
public static final String ENABLE_CONTEXTUAL_SEARCH = "enable-contextual-search";

/** Disable Contextual Search first-run flow, for testing. Not exposed to user. */
public static final String DISABLE_CONTEXTUAL_SEARCH_PROMO_FOR_TESTING =
"disable-contextual-search-promo-for-testing";

/** Enable Contextual Search for instrumentation testing. Not exposed to user. */
public static final String ENABLE_CONTEXTUAL_SEARCH_FOR_TESTING =
"enable-contextual-search-for-testing";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,23 @@ public ViewParent invalidateChildInParent(int[] location, Rect dirty) {
return parent;
}

/**
* Sets the text to display on top of the first-run promo.
* @param selection The portion of the text that represents the user's selection.
*/
public void setFirstRunText(String selection) {
// TODO(pedrosimonetti): confirm that is okay to remove the experimental text
// String firstRunText = ContextualSearchFieldTrial.getEnglishExperimentFirstRunText(
// selection);
// if (firstRunText == null) {
// firstRunText =
// getContext().getString(R.string.contextual_search_action_bar, selection);
// }
String firstRunText =
getContext().getString(R.string.contextual_search_action_bar, selection);
setCentralText(firstRunText);
}

/**
* Sets the search context to display in the control.
* @param selection The portion of the context that represents the user's selection.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ public static enum PanelState {
UNDEFINED,
CLOSED,
PEEKED,
PROMO,
EXPANDED,
MAXIMIZED;
}
Expand Down Expand Up @@ -145,15 +146,14 @@ public void setPreferenceState(boolean enabled) {
}

@Override
protected boolean isPromoAvailable() {
protected boolean isPanelPromoAvailable() {
return mManagementDelegate != null && mManagementDelegate.isOptOutPromoAvailable();
}

@Override
public void onPromoButtonClick(boolean accepted) {
super.onPromoButtonClick(accepted);
mManagementDelegate.logPromoOutcome();
setIsPromoActive(false);
}

@Override
Expand Down Expand Up @@ -236,7 +236,19 @@ public void handleClick(long time, float x, float y) {
if (mManagementDelegate.isRunningInCompatibilityMode()) {
mManagementDelegate.openResolvedSearchUrlInNewTab();
} else {
expandPanel(StateChangeReason.SEARCH_BAR_TAP);
// NOTE(pedrosimonetti): If the promo is active and getPromoContentHeight()
// returns -1 that means that the promo page hasn't finished loading, and
// therefore it wasn't possible to calculate the height of the promo contents.
// This will only happen if the user taps on a word that will trigger the
// promo, and then quickly taps on the peeking bar, before the promo page
// (which is local) finishes loading.
//
// TODO(pedrosimonetti): For now, we're simply ignoring the tap action in
// that case. Consider implementing a better approach, where the Panel
// would auto-expand once the height is calculated.
if (!getIsPromoActive() || getPromoContentHeight() != -1) {
expandPanel(StateChangeReason.SEARCH_BAR_TAP);
}
}
} else if (isExpanded()) {
peekPanel(StateChangeReason.SEARCH_BAR_TAP);
Expand Down Expand Up @@ -385,6 +397,24 @@ public void updateBasePageSelectionYPx(float y) {
super.updateBasePageSelectionYPx(y);
}

@Override
public void setPromoContentHeight(float height) {
// NOTE(pedrosimonetti): exposing superclass method to the interface.
super.setPromoContentHeight(height);
}

@Override
public void setShouldHidePromoHeader(boolean shouldHidePromoHeader) {
// NOTE(pedrosimonetti): exposing superclass method to the interface.
super.setShouldHidePromoHeader(shouldHidePromoHeader);
}

@Override
public void animateAfterFirstRunSuccess() {
// NOTE(pedrosimonetti): exposing superclass method to the interface.
super.animateAfterFirstRunSuccess();
}

@Override
public void onLoadStarted() {
setProgressBarCompletion(0);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ abstract class ContextualSearchPanelAnimation extends ContextualSearchPanelBase
*/
protected enum Property {
PANEL_HEIGHT,
PROMO_VISIBILITY
PROMO_VISIBILITY,
FIRST_RUN_PANEL_HEIGHT,
}

/**
Expand Down Expand Up @@ -109,7 +110,7 @@ protected void maximizePanel(StateChangeReason reason) {
* @param reason The reason for the change of panel state.
*/
protected void expandPanel(StateChangeReason reason) {
animatePanelToState(PanelState.EXPANDED, reason);
animatePanelToState(getIntermediaryState(), reason);
}

/**
Expand Down Expand Up @@ -192,6 +193,19 @@ protected void animatePromoAcceptance() {
animateProperty(Property.PROMO_VISIBILITY, 1.f, 0.f, BASE_ANIMATION_DURATION_MS);
}

/**
* Animates the Contextual Search panel after first-run success.
*/
protected void animateAfterFirstRunSuccess() {
final PanelState desiredState = PanelState.EXPANDED;
mAnimatingState = desiredState;
mAnimatingStateReason = StateChangeReason.OPTIN;

final float desiredHeight = getPanelHeightFromState(desiredState);
animateProperty(Property.FIRST_RUN_PANEL_HEIGHT, getHeight(), desiredHeight,
BASE_ANIMATION_DURATION_MS);
}

/**
* Animates the Panel to its nearest state.
*/
Expand Down Expand Up @@ -225,7 +239,7 @@ protected void animateToProjectedState(float velocity) {
// the EXPANDED state is the only one that will show the Promo.
if (projectedState == PanelState.MAXIMIZED
&& getPanelState() == PanelState.PEEKED
&& isPromoAvailable()) {
&& isPanelPromoAvailable()) {
projectedState = PanelState.EXPANDED;
}

Expand Down Expand Up @@ -341,6 +355,8 @@ public void setProperty(Property prop, float value) {
setPanelHeight(value);
} else if (prop == Property.PROMO_VISIBILITY) {
setPromoVisibilityForOptInAnimation(value);
} else if (prop == Property.FIRST_RUN_PANEL_HEIGHT) {
setPanelHeightForPromoOptInAnimation(value);
}
}

Expand Down
Loading

0 comments on commit 93c2ea2

Please sign in to comment.