OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 package org.chromium.chrome.browser.contextualsearch; | 5 package org.chromium.chrome.browser.contextualsearch; |
6 | 6 |
7 import android.app.Activity; | 7 import android.app.Activity; |
8 import android.view.View; | 8 import android.view.View; |
9 import android.view.ViewGroup; | 9 import android.view.ViewGroup; |
10 import android.view.ViewTreeObserver; | 10 import android.view.ViewTreeObserver; |
(...skipping 492 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
503 // Although the surroundings are extracted, they will not be sent to
the server as | 503 // Although the surroundings are extracted, they will not be sent to
the server as |
504 // part of search term resolution, just sent to Icing which keeps th
em local until | 504 // part of search term resolution, just sent to Icing which keeps th
em local until |
505 // the user activates a Voice Search. | 505 // the user activates a Voice Search. |
506 nativeGatherSurroundingText(mNativeContextualSearchManagerPtr, | 506 nativeGatherSurroundingText(mNativeContextualSearchManagerPtr, |
507 mSelectionController.getSelectedText(), NEVER_USE_RESOLVED_S
EARCH_TERM, | 507 mSelectionController.getSelectedText(), NEVER_USE_RESOLVED_S
EARCH_TERM, |
508 getBaseContentView(), mPolicy.maySendBasePageUrl()); | 508 getBaseContentView(), mPolicy.maySendBasePageUrl()); |
509 } | 509 } |
510 | 510 |
511 mWereSearchResultsSeen = false; | 511 mWereSearchResultsSeen = false; |
512 | 512 |
| 513 // Show the Peek Promo only when the Panel wasn't previously visible, pr
ovided |
| 514 // the policy allows it. |
| 515 if (!mSearchPanelDelegate.isShowing()) { |
| 516 boolean isPeekPromoAvailable = mPolicy.isPeekPromoAvailable(mSelecti
onController); |
| 517 if (isPeekPromoAvailable) { |
| 518 mSearchPanelDelegate.showPeekPromo(); |
| 519 mPolicy.registerPeekPromoSeen(); |
| 520 } |
| 521 } |
| 522 |
513 // TODO(donnd): although we are showing the bar here, we have not yet se
t the text! | 523 // TODO(donnd): although we are showing the bar here, we have not yet se
t the text! |
514 // Refactor to show the bar and set the text at the same time! | 524 // Refactor to show the bar and set the text at the same time! |
515 // TODO(donnd): If there was a previously ongoing contextual search, we
should ensure | 525 // TODO(donnd): If there was a previously ongoing contextual search, we
should ensure |
516 // it's registered as closed. | 526 // it's registered as closed. |
517 mSearchPanelDelegate.peekPanel(stateChangeReason); | 527 mSearchPanelDelegate.peekPanel(stateChangeReason); |
518 | 528 |
519 // Note: now that the contextual search has properly started, set the pr
omo involvement. | 529 // Note: now that the contextual search has properly started, set the pr
omo involvement. |
520 if (mPolicy.isPromoAvailable()) { | 530 if (mPolicy.isPromoAvailable()) { |
521 mIsShowingPromo = true; | 531 mIsShowingPromo = true; |
522 mDidLogPromoOutcome = false; | 532 mDidLogPromoOutcome = false; |
(...skipping 558 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1081 ? entry.getUrl() : searchContentViewCore.getWebContents().getUrl
(); | 1091 ? entry.getUrl() : searchContentViewCore.getWebContents().getUrl
(); |
1082 return url; | 1092 return url; |
1083 } | 1093 } |
1084 | 1094 |
1085 @Override | 1095 @Override |
1086 public float getSearchContentViewVerticalScroll() { | 1096 public float getSearchContentViewVerticalScroll() { |
1087 return mSearchPanelDelegate.getContentViewCore() != null | 1097 return mSearchPanelDelegate.getContentViewCore() != null |
1088 ? mSearchPanelDelegate.getContentViewCore().computeVerticalScrol
lOffset() : -1.f; | 1098 ? mSearchPanelDelegate.getContentViewCore().computeVerticalScrol
lOffset() : -1.f; |
1089 } | 1099 } |
1090 | 1100 |
1091 /** | |
1092 * This is called when the search panel is shown or is hidden. | |
1093 * @param isVisible True if the panel is now visible. | |
1094 */ | |
1095 public void onContentViewVisibilityChanged(boolean isVisible) { | |
1096 if (isVisible) { | |
1097 mWereSearchResultsSeen = true; | |
1098 // If there's no current request, then either a search term resoluti
on | |
1099 // is in progress or we should do a verbatim search now. | |
1100 if (mSearchRequest == null | |
1101 && mPolicy.shouldCreateVerbatimRequest(mSelectionController, | |
1102 mNetworkCommunicator.getBasePageUrl())) { | |
1103 mSearchRequest = new ContextualSearchRequest( | |
1104 mSelectionController.getSelectedText()); | |
1105 mDidStartLoadingResolvedSearchRequest = false; | |
1106 } | |
1107 if ((mSearchRequest != null && !mDidStartLoadingResolvedSearchReques
t) | |
1108 || mShouldLoadDelayedSearch) { | |
1109 // mShouldLoadDelayedSearch is used in the long-press case to lo
ad content. Since | |
1110 // content is now created and destroyed for each request, was im
possible to know if | |
1111 // content was already loaded or recently needed to be; this is
for the case where | |
1112 // it needed to be. | |
1113 mSearchRequest.setNormalPriority(); | |
1114 loadSearchUrl(); | |
1115 } | |
1116 mShouldLoadDelayedSearch = true; | |
1117 mPolicy.updateCountersForOpen(); | |
1118 } | |
1119 } | |
1120 | |
1121 @Override | 1101 @Override |
1122 public void preserveBasePageSelectionOnNextLossOfFocus() { | 1102 public void preserveBasePageSelectionOnNextLossOfFocus() { |
1123 ContentViewCore basePageContentView = getBaseContentView(); | 1103 ContentViewCore basePageContentView = getBaseContentView(); |
1124 if (basePageContentView != null) { | 1104 if (basePageContentView != null) { |
1125 basePageContentView.preserveSelectionOnNextLossOfFocus(); | 1105 basePageContentView.preserveSelectionOnNextLossOfFocus(); |
1126 } | 1106 } |
1127 } | 1107 } |
1128 | 1108 |
1129 @Override | 1109 @Override |
1130 public void dismissContextualSearchBar() { | 1110 public void dismissContextualSearchBar() { |
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1242 | 1222 |
1243 private native long nativeInit(); | 1223 private native long nativeInit(); |
1244 private native void nativeDestroy(long nativeContextualSearchManager); | 1224 private native void nativeDestroy(long nativeContextualSearchManager); |
1245 private native void nativeStartSearchTermResolutionRequest(long nativeContex
tualSearchManager, | 1225 private native void nativeStartSearchTermResolutionRequest(long nativeContex
tualSearchManager, |
1246 String selection, boolean useResolvedSearchTerm, ContentViewCore bas
eContentViewCore, | 1226 String selection, boolean useResolvedSearchTerm, ContentViewCore bas
eContentViewCore, |
1247 boolean maySendBasePageUrl); | 1227 boolean maySendBasePageUrl); |
1248 private native void nativeGatherSurroundingText(long nativeContextualSearchM
anager, | 1228 private native void nativeGatherSurroundingText(long nativeContextualSearchM
anager, |
1249 String selection, boolean useResolvedSearchTerm, ContentViewCore bas
eContentViewCore, | 1229 String selection, boolean useResolvedSearchTerm, ContentViewCore bas
eContentViewCore, |
1250 boolean maySendBasePageUrl); | 1230 boolean maySendBasePageUrl); |
1251 } | 1231 } |
OLD | NEW |