Search in sources :

Example 6 with PanelState

use of org.chromium.chrome.browser.compositor.bottombar.OverlayPanel.PanelState in project AndroidChromium by JackyAndroid.

the class ContextualSearchManager method showContextualSearch.

/**
     * Shows the Contextual Search UX.
     * Calls back into onGetContextualSearchQueryResponse.
     * @param stateChangeReason The reason explaining the change of state.
     */
private void showContextualSearch(StateChangeReason stateChangeReason) {
    if (mFindToolbarManager != null) {
        mFindToolbarManager.hideToolbar(false);
    }
    // Dismiss the undo SnackBar if present by committing all tab closures.
    mActivity.getTabModelSelector().commitAllTabClosures();
    if (!mSearchPanel.isShowing()) {
        // If visible, hide the infobar container before showing the Contextual Search panel.
        InfoBarContainer container = getInfoBarContainer();
        if (container != null && container.getVisibility() == View.VISIBLE) {
            mWereInfoBarsHidden = true;
            container.setIsObscuredByOtherView(true);
        }
    }
    // If the user is jumping from one unseen search to another search, remove the last search
    // from history.
    PanelState state = mSearchPanel.getPanelState();
    if (!mWereSearchResultsSeen && mLoadedSearchUrlTimeMs != 0L && state != PanelState.UNDEFINED && state != PanelState.CLOSED) {
        removeLastSearchVisit();
    }
    // TODO(pedrosimonetti): Fix for M47. Replace this with a better delayed load approach.
    mSearchPanel.destroyContent();
    boolean isTap = mSelectionController.getSelectionType() == SelectionType.TAP;
    boolean didRequestSurroundings = false;
    if (isTap) {
        // If the user action was not a long-press, immediately start loading content.
        mShouldLoadDelayedSearch = false;
    }
    if (isTap && mPolicy.shouldPreviousTapResolve()) {
        mNetworkCommunicator.startSearchTermResolutionRequest(mSelectionController.getSelectedText());
        didRequestSurroundings = true;
        // Cache the native translate data, so JNI calls won't be made when time-critical.
        mTranslateController.cacheNativeTranslateData();
    } else {
        boolean shouldPrefetch = mPolicy.shouldPrefetchSearchResult();
        mSearchRequest = createContextualSearchRequest(mSelectionController.getSelectedText(), null, null, shouldPrefetch);
        mTranslateController.forceAutoDetectTranslateUnlessDisabled(mSearchRequest);
        mDidStartLoadingResolvedSearchRequest = false;
        mSearchPanel.setSearchTerm(mSelectionController.getSelectedText());
        if (shouldPrefetch)
            loadSearchUrl();
        // TODO(donnd): remove this section once metrics have been analyzed.
        if (mSelectionController.getSelectionType() == SelectionType.LONG_PRESS && mSearchPanel.isPeeking()) {
            boolean isSingleWord = !CONTAINS_WHITESPACE_PATTERN.matcher(mSelectionController.getSelectedText().trim()).find();
            RecordUserAction.record(isSingleWord ? "ContextualSearch.ManualRefineSingleWord" : "ContextualSearch.ManualRefineMultiWord");
        }
    }
    if (!didRequestSurroundings) {
        // Gather surrounding text for Icing integration, which will make the selection and
        // a shorter version of the surroundings available for Conversational Search.
        // Although the surroundings are extracted, they will not be sent to the server as
        // part of search term resolution, just sent to Icing which keeps them local until
        // the user activates a Voice Search.
        nativeGatherSurroundingText(mNativeContextualSearchManagerPtr, mSelectionController.getSelectedText(), NEVER_USE_RESOLVED_SEARCH_TERM, getBaseContentView().getWebContents(), mPolicy.maySendBasePageUrl());
    }
    mWereSearchResultsSeen = false;
    // the policy allows it.
    if (!mSearchPanel.isShowing()) {
        mWouldShowPeekPromo = mPolicy.isPeekPromoConditionSatisfied();
        mIsShowingPeekPromo = mPolicy.isPeekPromoAvailable();
        if (mIsShowingPeekPromo) {
            mSearchPanel.showPeekPromo();
            mPolicy.registerPeekPromoSeen();
        }
    }
    // Note: whether the sprite should be animated or not needs to be set before the call to
    // peekPanel(). If the sprite should be animated, the animation will begin after the panel
    // finishes peeking. If it should not be animated, the icon will be drawn right away.
    mSearchPanel.getImageControl().setShouldAnimateIconSprite(mPolicy.shouldAnimateSearchProviderIcon());
    // Note: now that the contextual search has properly started, set the promo involvement.
    if (mPolicy.isPromoAvailable()) {
        mIsShowingPromo = true;
        mIsMandatoryPromo = mPolicy.isMandatoryPromoAvailable();
        mDidLogPromoOutcome = false;
        mSearchPanel.setIsPromoActive(true, mIsMandatoryPromo);
        mSearchPanel.setDidSearchInvolvePromo();
    }
    // TODO(donnd): although we are showing the bar here, we have not yet set the text!
    // Refactor to show the bar and set the text at the same time!
    // TODO(donnd): If there was a previously ongoing contextual search, we should ensure
    // it's registered as closed.
    mSearchPanel.requestPanelShow(stateChangeReason);
    assert mSelectionController.getSelectionType() != SelectionType.UNDETERMINED;
    mWasActivatedByTap = mSelectionController.getSelectionType() == SelectionType.TAP;
}
Also used : InfoBarContainer(org.chromium.chrome.browser.infobar.InfoBarContainer) PanelState(org.chromium.chrome.browser.compositor.bottombar.OverlayPanel.PanelState)

Aggregations

PanelState (org.chromium.chrome.browser.compositor.bottombar.OverlayPanel.PanelState)6 InfoBarContainer (org.chromium.chrome.browser.infobar.InfoBarContainer)1