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.omnibox; | 5 package org.chromium.chrome.browser.omnibox; |
6 | 6 |
7 import static org.chromium.chrome.browser.toolbar.ToolbarPhone.URL_FOCUS_CHANGE_ ANIMATION_DURATION_MS; | 7 import static org.chromium.chrome.browser.toolbar.ToolbarPhone.URL_FOCUS_CHANGE_ ANIMATION_DURATION_MS; |
8 | 8 |
9 import android.Manifest; | 9 import android.Manifest; |
10 import android.animation.Animator; | 10 import android.animation.Animator; |
(...skipping 13 matching lines...) Expand all Loading... | |
24 import android.graphics.Color; | 24 import android.graphics.Color; |
25 import android.graphics.PorterDuff; | 25 import android.graphics.PorterDuff; |
26 import android.graphics.Rect; | 26 import android.graphics.Rect; |
27 import android.graphics.drawable.ColorDrawable; | 27 import android.graphics.drawable.ColorDrawable; |
28 import android.graphics.drawable.Drawable; | 28 import android.graphics.drawable.Drawable; |
29 import android.net.Uri; | 29 import android.net.Uri; |
30 import android.os.Parcelable; | 30 import android.os.Parcelable; |
31 import android.os.SystemClock; | 31 import android.os.SystemClock; |
32 import android.provider.Settings; | 32 import android.provider.Settings; |
33 import android.speech.RecognizerIntent; | 33 import android.speech.RecognizerIntent; |
34 import android.support.annotation.IntDef; | |
34 import android.text.InputType; | 35 import android.text.InputType; |
35 import android.text.TextUtils; | 36 import android.text.TextUtils; |
36 import android.util.AttributeSet; | 37 import android.util.AttributeSet; |
37 import android.util.Log; | 38 import android.util.Log; |
38 import android.util.Pair; | 39 import android.util.Pair; |
39 import android.util.SparseArray; | 40 import android.util.SparseArray; |
40 import android.view.ActionMode; | 41 import android.view.ActionMode; |
41 import android.view.KeyEvent; | 42 import android.view.KeyEvent; |
42 import android.view.LayoutInflater; | 43 import android.view.LayoutInflater; |
43 import android.view.Menu; | 44 import android.view.Menu; |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
92 import org.chromium.chrome.browser.widget.animation.CancelAwareAnimatorListener; | 93 import org.chromium.chrome.browser.widget.animation.CancelAwareAnimatorListener; |
93 import org.chromium.components.security_state.ConnectionSecurityLevel; | 94 import org.chromium.components.security_state.ConnectionSecurityLevel; |
94 import org.chromium.content_public.browser.LoadUrlParams; | 95 import org.chromium.content_public.browser.LoadUrlParams; |
95 import org.chromium.content_public.browser.WebContents; | 96 import org.chromium.content_public.browser.WebContents; |
96 import org.chromium.ui.UiUtils; | 97 import org.chromium.ui.UiUtils; |
97 import org.chromium.ui.base.DeviceFormFactor; | 98 import org.chromium.ui.base.DeviceFormFactor; |
98 import org.chromium.ui.base.PageTransition; | 99 import org.chromium.ui.base.PageTransition; |
99 import org.chromium.ui.base.WindowAndroid; | 100 import org.chromium.ui.base.WindowAndroid; |
100 import org.chromium.ui.interpolators.BakedBezierInterpolator; | 101 import org.chromium.ui.interpolators.BakedBezierInterpolator; |
101 | 102 |
103 import java.lang.annotation.Retention; | |
104 import java.lang.annotation.RetentionPolicy; | |
102 import java.util.ArrayList; | 105 import java.util.ArrayList; |
103 import java.util.HashSet; | 106 import java.util.HashSet; |
104 import java.util.List; | 107 import java.util.List; |
105 | 108 |
106 /** | 109 /** |
107 * This class represents the location bar where the user types in URLs and | 110 * This class represents the location bar where the user types in URLs and |
108 * search terms. | 111 * search terms. |
109 */ | 112 */ |
110 public class LocationBarLayout extends FrameLayout implements OnClickListener, | 113 public class LocationBarLayout extends FrameLayout implements OnClickListener, |
111 OnSuggestionsReceivedListener, LocationBar, FakeboxDelegate, | 114 OnSuggestionsReceivedListener, LocationBar, FakeboxDelegate, |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
156 private UrlFocusChangeListener mUrlFocusChangeListener; | 159 private UrlFocusChangeListener mUrlFocusChangeListener; |
157 | 160 |
158 protected boolean mNativeInitialized; | 161 protected boolean mNativeInitialized; |
159 | 162 |
160 private final List<Runnable> mDeferredNativeRunnables = new ArrayList<Runnab le>(); | 163 private final List<Runnable> mDeferredNativeRunnables = new ArrayList<Runnab le>(); |
161 | 164 |
162 // The type of the navigation button currently showing. | 165 // The type of the navigation button currently showing. |
163 private NavigationButtonType mNavigationButtonType; | 166 private NavigationButtonType mNavigationButtonType; |
164 | 167 |
165 // The type of the security icon currently active. | 168 // The type of the security icon currently active. |
166 private int mSecurityIconType; | 169 private int mSecurityIconResource; |
167 | 170 |
168 private final OmniboxResultsAdapter mSuggestionListAdapter; | 171 private final OmniboxResultsAdapter mSuggestionListAdapter; |
169 private OmniboxSuggestionsList mSuggestionList; | 172 private OmniboxSuggestionsList mSuggestionList; |
170 | 173 |
171 private final List<OmniboxResultItem> mSuggestionItems; | 174 private final List<OmniboxResultItem> mSuggestionItems; |
172 | 175 |
173 /** | 176 /** |
174 * The text shown in the URL bar (user text + inline autocomplete) after the most recent set of | 177 * The text shown in the URL bar (user text + inline autocomplete) after the most recent set of |
175 * omnibox suggestions was received. When the user presses enter in the omni box, this value is | 178 * omnibox suggestions was received. When the user presses enter in the omni box, this value is |
176 * compared to the URL bar text to determine whether the first suggestion is still valid. | 179 * compared to the URL bar text to determine whether the first suggestion is still valid. |
(...skipping 22 matching lines...) Expand all Loading... | |
199 | 202 |
200 private boolean mVoiceSearchEnabled; | 203 private boolean mVoiceSearchEnabled; |
201 | 204 |
202 // Set to true when the user has started typing new input in the omnibox, se t to false | 205 // Set to true when the user has started typing new input in the omnibox, se t to false |
203 // when the omnibox loses focus or becomes empty. | 206 // when the omnibox loses focus or becomes empty. |
204 private boolean mHasStartedNewOmniboxEditSession; | 207 private boolean mHasStartedNewOmniboxEditSession; |
205 // The timestamp (using SystemClock.elapsedRealtime()) at the point when the user started | 208 // The timestamp (using SystemClock.elapsedRealtime()) at the point when the user started |
206 // modifying the omnibox with new input. | 209 // modifying the omnibox with new input. |
207 private long mNewOmniboxEditSessionTimestamp = -1; | 210 private long mNewOmniboxEditSessionTimestamp = -1; |
208 | 211 |
209 private boolean mSecurityButtonShown; | 212 @LocationBarButtonType private int mLocationBarButtonType; |
210 | 213 |
211 private AnimatorSet mLocationBarIconActiveAnimator; | 214 private AnimatorSet mLocationBarIconActiveAnimator; |
212 private AnimatorSet mSecurityButtonShowAnimator; | 215 private AnimatorSet mSecurityButtonShowAnimator; |
213 private AnimatorSet mNavigationIconShowAnimator; | 216 private AnimatorSet mNavigationIconShowAnimator; |
214 | 217 |
215 private OmniboxPrerender mOmniboxPrerender; | 218 private OmniboxPrerender mOmniboxPrerender; |
216 | 219 |
217 private boolean mSuggestionModalShown; | 220 private boolean mSuggestionModalShown; |
218 private boolean mUseDarkColors; | 221 private boolean mUseDarkColors; |
219 private boolean mIsEmphasizingHttpsScheme; | 222 private boolean mIsEmphasizingHttpsScheme; |
(...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
392 } | 395 } |
393 } | 396 } |
394 | 397 |
395 /** | 398 /** |
396 * Specifies the types of buttons shown to signify different types of naviga tion elements. | 399 * Specifies the types of buttons shown to signify different types of naviga tion elements. |
397 */ | 400 */ |
398 protected enum NavigationButtonType { | 401 protected enum NavigationButtonType { |
399 PAGE, | 402 PAGE, |
400 MAGNIFIER, | 403 MAGNIFIER, |
401 EMPTY, | 404 EMPTY, |
402 OFFLINE, | |
403 } | 405 } |
404 | 406 |
407 /** Specifies which button should be shown in location bar, if any. */ | |
408 @Retention(RetentionPolicy.SOURCE) | |
409 @IntDef({BUTTON_TYPE_NONE, BUTTON_TYPE_SECURITY_ICON, BUTTON_TYPE_NAVIGATION _ICON}) | |
410 public @interface LocationBarButtonType {} | |
411 /** No button should be shown. */ | |
412 public static final int BUTTON_TYPE_NONE = 0; | |
413 /** Security button should be shown (includes offline icon). */ | |
414 public static final int BUTTON_TYPE_SECURITY_ICON = 1; | |
415 /** Navigation button should be shown. */ | |
416 public static final int BUTTON_TYPE_NAVIGATION_ICON = 2; | |
417 | |
405 /** | 418 /** |
406 * @param outRect Populated with a {@link Rect} that represents the {@link T ab} specific content | 419 * @param outRect Populated with a {@link Rect} that represents the {@link T ab} specific content |
407 * of this {@link LocationBar}. | 420 * of this {@link LocationBar}. |
408 */ | 421 */ |
409 public void getContentRect(Rect outRect) { | 422 public void getContentRect(Rect outRect) { |
410 outRect.set(getPaddingLeft(), getPaddingTop(), getWidth() - getPaddingRi ght(), | 423 outRect.set(getPaddingLeft(), getPaddingTop(), getWidth() - getPaddingRi ght(), |
411 getHeight() - getPaddingBottom()); | 424 getHeight() - getPaddingBottom()); |
412 } | 425 } |
413 | 426 |
414 /** | 427 /** |
(...skipping 203 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
618 } | 631 } |
619 } | 632 } |
620 } | 633 } |
621 | 634 |
622 public LocationBarLayout(Context context, AttributeSet attrs) { | 635 public LocationBarLayout(Context context, AttributeSet attrs) { |
623 super(context, attrs); | 636 super(context, attrs); |
624 | 637 |
625 LayoutInflater.from(context).inflate(R.layout.location_bar, this, true); | 638 LayoutInflater.from(context).inflate(R.layout.location_bar, this, true); |
626 mNavigationButton = (ImageView) findViewById(R.id.navigation_button); | 639 mNavigationButton = (ImageView) findViewById(R.id.navigation_button); |
627 assert mNavigationButton != null : "Missing navigation type view."; | 640 assert mNavigationButton != null : "Missing navigation type view."; |
641 | |
628 mNavigationButtonType = DeviceFormFactor.isTablet(context) | 642 mNavigationButtonType = DeviceFormFactor.isTablet(context) |
629 ? NavigationButtonType.PAGE : NavigationButtonType.EMPTY; | 643 ? NavigationButtonType.PAGE : NavigationButtonType.EMPTY; |
630 | 644 |
631 mSecurityButton = (TintedImageButton) findViewById(R.id.security_button) ; | 645 mSecurityButton = (TintedImageButton) findViewById(R.id.security_button) ; |
632 mSecurityIconType = ConnectionSecurityLevel.NONE; | 646 mSecurityIconResource = 0; |
633 | 647 |
634 mVerboseStatusTextView = (TextView) findViewById(R.id.location_bar_verbo se_status); | 648 mVerboseStatusTextView = (TextView) findViewById(R.id.location_bar_verbo se_status); |
635 | 649 |
636 mDeleteButton = (TintedImageButton) findViewById(R.id.delete_button); | 650 mDeleteButton = (TintedImageButton) findViewById(R.id.delete_button); |
637 | 651 |
638 mUrlBar = (UrlBar) findViewById(R.id.url_bar); | 652 mUrlBar = (UrlBar) findViewById(R.id.url_bar); |
639 // The HTC Sense IME will attempt to autocomplete words in the Omnibox w hen Prediction is | 653 // The HTC Sense IME will attempt to autocomplete words in the Omnibox w hen Prediction is |
640 // enabled. We want to disable this feature and rely on the Omnibox's i mplementation. | 654 // enabled. We want to disable this feature and rely on the Omnibox's i mplementation. |
641 // Their IME does not respect ~TYPE_TEXT_FLAG_AUTO_COMPLETE nor any of t he other InputType | 655 // Their IME does not respect ~TYPE_TEXT_FLAG_AUTO_COMPLETE nor any of t he other InputType |
642 // options I tried, but setting the filter variation prevents it. Sadly , it also removes | 656 // options I tried, but setting the filter variation prevents it. Sadly , it also removes |
(...skipping 11 matching lines...) Expand all Loading... | |
654 mSuggestionListAdapter = new OmniboxResultsAdapter(getContext(), this, m SuggestionItems); | 668 mSuggestionListAdapter = new OmniboxResultsAdapter(getContext(), this, m SuggestionItems); |
655 | 669 |
656 mMicButton = (TintedImageButton) findViewById(R.id.mic_button); | 670 mMicButton = (TintedImageButton) findViewById(R.id.mic_button); |
657 } | 671 } |
658 | 672 |
659 @Override | 673 @Override |
660 protected void onFinishInflate() { | 674 protected void onFinishInflate() { |
661 super.onFinishInflate(); | 675 super.onFinishInflate(); |
662 | 676 |
663 mUrlBar.setCursorVisible(false); | 677 mUrlBar.setCursorVisible(false); |
664 mNavigationButton.setVisibility(VISIBLE); | 678 |
665 mSecurityButton.setVisibility(INVISIBLE); | 679 mLocationBarButtonType = getLocationBarButtonToShow(); |
680 mNavigationButton.setVisibility( | |
681 mLocationBarButtonType == BUTTON_TYPE_NAVIGATION_ICON ? VISIBLE : INVISIBLE); | |
682 mSecurityButton.setVisibility( | |
683 mLocationBarButtonType == BUTTON_TYPE_SECURITY_ICON ? VISIBLE : INVISIBLE); | |
666 | 684 |
667 setLayoutTransition(null); | 685 setLayoutTransition(null); |
668 | 686 |
669 AnimatorListenerAdapter iconChangeAnimatorListener = new AnimatorListene rAdapter() { | 687 AnimatorListenerAdapter iconChangeAnimatorListener = new AnimatorListene rAdapter() { |
670 @Override | 688 @Override |
671 public void onAnimationEnd(Animator animation) { | 689 public void onAnimationEnd(Animator animation) { |
672 if (animation == mSecurityButtonShowAnimator) { | 690 if (animation == mSecurityButtonShowAnimator) { |
673 mNavigationButton.setVisibility(INVISIBLE); | 691 mNavigationButton.setVisibility(INVISIBLE); |
674 } else if (animation == mNavigationIconShowAnimator) { | 692 } else if (animation == mNavigationIconShowAnimator) { |
675 mSecurityButton.setVisibility(INVISIBLE); | 693 mSecurityButton.setVisibility(INVISIBLE); |
(...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
858 public void setAutocompleteProfile(Profile profile) { | 876 public void setAutocompleteProfile(Profile profile) { |
859 // This will only be called once at least one tab exists, and the tab mo del is told to | 877 // This will only be called once at least one tab exists, and the tab mo del is told to |
860 // update its state. During Chrome initialization the tab model update h appens after the | 878 // update its state. During Chrome initialization the tab model update h appens after the |
861 // call to onNativeLibraryReady, so this assert will not fire. | 879 // call to onNativeLibraryReady, so this assert will not fire. |
862 assert mNativeInitialized : | 880 assert mNativeInitialized : |
863 "Setting Autocomplete Profile before native side initialized"; | 881 "Setting Autocomplete Profile before native side initialized"; |
864 mAutocomplete.setProfile(profile); | 882 mAutocomplete.setProfile(profile); |
865 mOmniboxPrerender.initializeForProfile(profile); | 883 mOmniboxPrerender.initializeForProfile(profile); |
866 } | 884 } |
867 | 885 |
868 private void changeLocationBarIcon(boolean showSecurityButton) { | 886 @LocationBarButtonType private int getLocationBarButtonToShow() { |
887 boolean isOffline = getCurrentTab() != null && getCurrentTab().isOffline Page(); | |
888 boolean isTablet = DeviceFormFactor.isTablet(getContext()); | |
889 | |
890 if (mUrlHasFocus) { | |
891 return isTablet ? BUTTON_TYPE_NAVIGATION_ICON : BUTTON_TYPE_NONE; | |
892 } | |
893 | |
894 return getSecurityIconResource(getSecurityLevel(), !isTablet, isOffline) != 0 | |
895 ? BUTTON_TYPE_SECURITY_ICON | |
896 : BUTTON_TYPE_NONE; | |
897 } | |
898 | |
899 private void changeLocationBarIcon() { | |
869 if (mLocationBarIconActiveAnimator != null && mLocationBarIconActiveAnim ator.isRunning()) { | 900 if (mLocationBarIconActiveAnimator != null && mLocationBarIconActiveAnim ator.isRunning()) { |
870 mLocationBarIconActiveAnimator.cancel(); | 901 mLocationBarIconActiveAnimator.cancel(); |
871 } | 902 } |
872 View viewToBeShown = showSecurityButton ? mSecurityButton : mNavigationB utton; | 903 |
904 mLocationBarButtonType = getLocationBarButtonToShow(); | |
905 | |
906 View viewToBeShown = null; | |
907 switch (mLocationBarButtonType) { | |
908 case BUTTON_TYPE_SECURITY_ICON: | |
909 viewToBeShown = mSecurityButton; | |
910 mLocationBarIconActiveAnimator = mSecurityButtonShowAnimator; | |
911 break; | |
912 case BUTTON_TYPE_NAVIGATION_ICON: | |
913 viewToBeShown = mNavigationButton; | |
914 mLocationBarIconActiveAnimator = mNavigationIconShowAnimator; | |
915 break; | |
916 case BUTTON_TYPE_NONE: | |
917 mLocationBarIconActiveAnimator = null; | |
918 return; | |
919 } | |
920 | |
873 if (viewToBeShown.getVisibility() == VISIBLE && viewToBeShown.getAlpha() == 1) { | 921 if (viewToBeShown.getVisibility() == VISIBLE && viewToBeShown.getAlpha() == 1) { |
874 return; | 922 return; |
875 } | 923 } |
876 if (showSecurityButton) { | |
877 mLocationBarIconActiveAnimator = mSecurityButtonShowAnimator; | |
878 } else { | |
879 mLocationBarIconActiveAnimator = mNavigationIconShowAnimator; | |
880 } | |
881 if (shouldAnimateIconChanges()) { | 924 if (shouldAnimateIconChanges()) { |
882 mLocationBarIconActiveAnimator.setDuration(URL_FOCUS_CHANGE_ANIMATIO N_DURATION_MS); | 925 mLocationBarIconActiveAnimator.setDuration(URL_FOCUS_CHANGE_ANIMATIO N_DURATION_MS); |
883 } else { | 926 } else { |
884 mLocationBarIconActiveAnimator.setDuration(0); | 927 mLocationBarIconActiveAnimator.setDuration(0); |
885 } | 928 } |
886 mLocationBarIconActiveAnimator.start(); | 929 mLocationBarIconActiveAnimator.start(); |
887 } | 930 } |
888 | 931 |
889 @Override | 932 @Override |
890 public void setUrlBarFocus(boolean shouldBeFocused) { | 933 public void setUrlBarFocus(boolean shouldBeFocused) { |
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
968 setUrlToPageUrl(); | 1011 setUrlToPageUrl(); |
969 emphasizeUrl(); | 1012 emphasizeUrl(); |
970 } | 1013 } |
971 } | 1014 } |
972 | 1015 |
973 if (getToolbarDataProvider().isUsingBrandColor()) { | 1016 if (getToolbarDataProvider().isUsingBrandColor()) { |
974 updateVisualsForState(); | 1017 updateVisualsForState(); |
975 if (mUrlHasFocus) mUrlBar.selectAll(); | 1018 if (mUrlHasFocus) mUrlBar.selectAll(); |
976 } | 1019 } |
977 | 1020 |
978 changeLocationBarIcon( | 1021 changeLocationBarIcon(); |
979 (!DeviceFormFactor.isTablet(getContext()) || !hasFocus) && isSec urityButtonShown()); | |
980 mUrlBar.setCursorVisible(hasFocus); | 1022 mUrlBar.setCursorVisible(hasFocus); |
981 | 1023 |
982 if (!mUrlFocusedWithoutAnimations) handleUrlFocusAnimation(hasFocus); | 1024 if (!mUrlFocusedWithoutAnimations) handleUrlFocusAnimation(hasFocus); |
983 | 1025 |
984 if (hasFocus && currentTab != null && !currentTab.isIncognito()) { | 1026 if (hasFocus && currentTab != null && !currentTab.isIncognito()) { |
985 if (mNativeInitialized | 1027 if (mNativeInitialized |
986 && TemplateUrlService.getInstance().isDefaultSearchEngineGoo gle()) { | 1028 && TemplateUrlService.getInstance().isDefaultSearchEngineGoo gle()) { |
987 GeolocationHeader.primeLocationForGeoHeader(getContext()); | 1029 GeolocationHeader.primeLocationForGeoHeader(getContext()); |
988 } else { | 1030 } else { |
989 mDeferredNativeRunnables.add(new Runnable() { | 1031 mDeferredNativeRunnables.add(new Runnable() { |
(...skipping 209 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1199 } | 1241 } |
1200 | 1242 |
1201 // Updates the navigation button based on the URL string | 1243 // Updates the navigation button based on the URL string |
1202 private void updateNavigationButton() { | 1244 private void updateNavigationButton() { |
1203 boolean isTablet = DeviceFormFactor.isTablet(getContext()); | 1245 boolean isTablet = DeviceFormFactor.isTablet(getContext()); |
1204 NavigationButtonType type = NavigationButtonType.EMPTY; | 1246 NavigationButtonType type = NavigationButtonType.EMPTY; |
1205 if (isTablet && !mSuggestionItems.isEmpty()) { | 1247 if (isTablet && !mSuggestionItems.isEmpty()) { |
1206 // If there are suggestions showing, show the icon for the default s uggestion. | 1248 // If there are suggestions showing, show the icon for the default s uggestion. |
1207 type = suggestionTypeToNavigationButtonType( | 1249 type = suggestionTypeToNavigationButtonType( |
1208 mSuggestionItems.get(0).getSuggestion()); | 1250 mSuggestionItems.get(0).getSuggestion()); |
1209 } else if (!mUrlHasFocus && getCurrentTab() != null && getCurrentTab().i sOfflinePage()) { | |
1210 type = NavigationButtonType.OFFLINE; | |
1211 } else if (isTablet) { | 1251 } else if (isTablet) { |
1212 type = NavigationButtonType.PAGE; | 1252 type = NavigationButtonType.PAGE; |
1213 } | 1253 } |
1214 | 1254 |
1215 if (type != mNavigationButtonType) setNavigationButtonType(type); | 1255 if (type != mNavigationButtonType) setNavigationButtonType(type); |
1216 } | 1256 } |
1217 | 1257 |
1218 private int getSecurityLevel() { | 1258 private int getSecurityLevel() { |
1219 if (getCurrentTab() == null) return ConnectionSecurityLevel.NONE; | 1259 if (getCurrentTab() == null) return ConnectionSecurityLevel.NONE; |
1220 return getCurrentTab().getSecurityLevel(); | 1260 return getCurrentTab().getSecurityLevel(); |
1221 } | 1261 } |
1222 | 1262 |
1223 /** | 1263 /** |
1224 * Determines the icon that should be displayed for the current security lev el. | 1264 * Determines the icon that should be displayed for the current security lev el. |
1225 * @param securityLevel The security level for which the resource will be re turned. | 1265 * @param securityLevel The security level for which the resource will be re turned. |
1226 * @param isSmallDevice Whether the device form factor is small (like a phon e) or large | 1266 * @param isSmallDevice Whether the device form factor is small (like a phon e) or large |
1227 * (like a tablet). | 1267 * (like a tablet). |
1228 * @return The resource ID of the icon that should be displayed, 0 if no ico n should show. | 1268 * @return The resource ID of the icon that should be displayed, 0 if no ico n should show. |
1229 */ | 1269 */ |
1230 public static int getSecurityIconResource(int securityLevel, boolean isSmall Device) { | 1270 public static int getSecurityIconResource( |
1271 int securityLevel, boolean isSmallDevice, boolean isOfflinePage) { | |
1272 // Both conditions should be met, because isOfflinePage might take longe r to be cleared. | |
1273 if (securityLevel == ConnectionSecurityLevel.NONE && isOfflinePage) { | |
1274 return R.drawable.offline_pin; | |
1275 } | |
1231 switch (securityLevel) { | 1276 switch (securityLevel) { |
1232 case ConnectionSecurityLevel.NONE: | 1277 case ConnectionSecurityLevel.NONE: |
1233 case ConnectionSecurityLevel.HTTP_SHOW_WARNING: | 1278 case ConnectionSecurityLevel.HTTP_SHOW_WARNING: |
1234 return isSmallDevice ? 0 : R.drawable.omnibox_info; | 1279 return isSmallDevice ? 0 : R.drawable.omnibox_info; |
1235 case ConnectionSecurityLevel.SECURITY_WARNING: | 1280 case ConnectionSecurityLevel.SECURITY_WARNING: |
1236 return R.drawable.omnibox_info; | 1281 return R.drawable.omnibox_info; |
1237 case ConnectionSecurityLevel.DANGEROUS: | 1282 case ConnectionSecurityLevel.DANGEROUS: |
1238 return R.drawable.omnibox_https_invalid; | 1283 return R.drawable.omnibox_https_invalid; |
1239 case ConnectionSecurityLevel.SECURE: | 1284 case ConnectionSecurityLevel.SECURE: |
1240 case ConnectionSecurityLevel.EV_SECURE: | 1285 case ConnectionSecurityLevel.EV_SECURE: |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1279 assert list != null : "Missing ColorStateList for Security Button."; | 1324 assert list != null : "Missing ColorStateList for Security Button."; |
1280 return list; | 1325 return list; |
1281 } | 1326 } |
1282 | 1327 |
1283 /** | 1328 /** |
1284 * Updates the security icon displayed in the LocationBar. | 1329 * Updates the security icon displayed in the LocationBar. |
1285 */ | 1330 */ |
1286 @Override | 1331 @Override |
1287 public void updateSecurityIcon(int securityLevel) { | 1332 public void updateSecurityIcon(int securityLevel) { |
1288 boolean isSmallDevice = !DeviceFormFactor.isTablet(getContext()); | 1333 boolean isSmallDevice = !DeviceFormFactor.isTablet(getContext()); |
1289 int id = getSecurityIconResource(securityLevel, isSmallDevice); | 1334 boolean isOfflinePage = getCurrentTab() != null && getCurrentTab().isOff linePage(); |
1335 int id = getSecurityIconResource(securityLevel, isSmallDevice, isOffline Page); | |
1290 if (id == 0) { | 1336 if (id == 0) { |
1291 mSecurityButton.setImageDrawable(null); | 1337 mSecurityButton.setImageDrawable(null); |
1292 } else { | 1338 } else { |
1293 // ImageView#setImageResource is no-op if given resource is the curr ent one. | 1339 // ImageView#setImageResource is no-op if given resource is the curr ent one. |
1294 mSecurityButton.setImageResource(id); | 1340 mSecurityButton.setImageResource(id); |
1295 mSecurityButton.setTint(getColorStateList(securityLevel, getToolbarD ataProvider(), | 1341 mSecurityButton.setTint(getColorStateList(securityLevel, getToolbarD ataProvider(), |
1296 getResources(), ColorUtils.shouldUseOpaqueTextboxBackground( | 1342 getResources(), ColorUtils.shouldUseOpaqueTextboxBackground( |
1297 getToolbarDataProvider().getPrimaryColor()))); | 1343 getToolbarDataProvider().getPrimaryColor()))); |
1298 } | 1344 } |
1299 | 1345 |
1346 updateVerboseStatusVisibility(); | |
1347 | |
1300 boolean shouldEmphasizeHttpsScheme = shouldEmphasizeHttpsScheme(); | 1348 boolean shouldEmphasizeHttpsScheme = shouldEmphasizeHttpsScheme(); |
1301 if (mSecurityIconType == securityLevel | 1349 if (mSecurityIconResource == id |
1302 && mIsEmphasizingHttpsScheme == shouldEmphasizeHttpsScheme) { | 1350 && mIsEmphasizingHttpsScheme == shouldEmphasizeHttpsScheme) { |
1303 return; | 1351 return; |
1304 } | 1352 } |
1305 mSecurityIconType = securityLevel; | 1353 mSecurityIconResource = id; |
1306 | 1354 |
1307 updateSecurityButton(!(securityLevel == ConnectionSecurityLevel.NONE && isSmallDevice)); | 1355 changeLocationBarIcon(); |
1356 updateLocationBarIconContainerVisibility(); | |
1308 // Since we emphasize the scheme of the URL based on the security type, we need to | 1357 // Since we emphasize the scheme of the URL based on the security type, we need to |
1309 // refresh the emphasis. | 1358 // refresh the emphasis. |
1310 mUrlBar.deEmphasizeUrl(); | 1359 mUrlBar.deEmphasizeUrl(); |
1311 emphasizeUrl(); | 1360 emphasizeUrl(); |
1312 mIsEmphasizingHttpsScheme = shouldEmphasizeHttpsScheme; | 1361 mIsEmphasizingHttpsScheme = shouldEmphasizeHttpsScheme(); |
Ted C
2016/10/24 17:19:45
why this change? we calculate shouldEmphasizeHttp
fgorski
2016/10/24 22:34:14
No I think I was experimenting with removing the c
| |
1313 } | 1362 } |
1314 | 1363 |
1315 private void emphasizeUrl() { | 1364 private void emphasizeUrl() { |
1316 mUrlBar.emphasizeUrl(); | 1365 mUrlBar.emphasizeUrl(); |
1317 } | 1366 } |
1318 | 1367 |
1319 @Override | 1368 @Override |
1320 public boolean shouldEmphasizeHttpsScheme() { | 1369 public boolean shouldEmphasizeHttpsScheme() { |
1321 ToolbarDataProvider provider = getToolbarDataProvider(); | 1370 ToolbarDataProvider provider = getToolbarDataProvider(); |
1322 if (provider.isUsingBrandColor() || provider.isIncognito()) return false ; | 1371 if (provider.isUsingBrandColor() || provider.isIncognito()) return false ; |
1323 return true; | 1372 return true; |
1324 } | 1373 } |
1325 | 1374 |
1326 /** | 1375 /** |
1327 * Updates the display of the security button. | |
1328 * @param enabled Whether the security button should be displayed. | |
1329 */ | |
1330 private void updateSecurityButton(boolean enabled) { | |
1331 changeLocationBarIcon(enabled | |
1332 && (!DeviceFormFactor.isTablet(getContext()) || !mUrlHasFocus)); | |
1333 mSecurityButtonShown = enabled; | |
1334 updateLocationBarIconContainerVisibility(); | |
1335 } | |
1336 | |
1337 /** | |
1338 * @return Whether the security button is currently being displayed. | 1376 * @return Whether the security button is currently being displayed. |
1339 */ | 1377 */ |
1340 @VisibleForTesting | 1378 @VisibleForTesting |
1341 public boolean isSecurityButtonShown() { | 1379 public boolean isSecurityButtonShown() { |
1342 return mSecurityButtonShown; | 1380 return mLocationBarButtonType == BUTTON_TYPE_SECURITY_ICON; |
1343 } | 1381 } |
1344 | 1382 |
1345 /** | 1383 /** |
1346 * Sets the type of the current navigation type and updates the UI to match it. | 1384 * Sets the type of the current navigation type and updates the UI to match it. |
1347 * @param buttonType The type of navigation button to be shown. | 1385 * @param buttonType The type of navigation button to be shown. |
1348 */ | 1386 */ |
1349 private void setNavigationButtonType(NavigationButtonType buttonType) { | 1387 private void setNavigationButtonType(NavigationButtonType buttonType) { |
1388 if (!DeviceFormFactor.isTablet(getContext())) return; | |
1350 switch (buttonType) { | 1389 switch (buttonType) { |
1351 case PAGE: | 1390 case PAGE: |
1352 Drawable page = ApiCompatibilityUtils.getDrawable( | 1391 Drawable page = ApiCompatibilityUtils.getDrawable( |
1353 getResources(), R.drawable.ic_omnibox_page); | 1392 getResources(), R.drawable.ic_omnibox_page); |
1354 page.setColorFilter(mUseDarkColors | 1393 page.setColorFilter(mUseDarkColors |
1355 ? ApiCompatibilityUtils.getColor(getResources(), R.color .light_normal_color) | 1394 ? ApiCompatibilityUtils.getColor(getResources(), R.color .light_normal_color) |
1356 : Color.WHITE, PorterDuff.Mode.SRC_IN); | 1395 : Color.WHITE, PorterDuff.Mode.SRC_IN); |
1357 mNavigationButton.setImageDrawable(page); | 1396 mNavigationButton.setImageDrawable(page); |
1358 break; | 1397 break; |
1359 case MAGNIFIER: | 1398 case MAGNIFIER: |
1360 mNavigationButton.setImageResource(R.drawable.ic_omnibox_magnifi er); | 1399 mNavigationButton.setImageResource(R.drawable.ic_omnibox_magnifi er); |
1361 break; | 1400 break; |
1362 case EMPTY: | 1401 case EMPTY: |
1363 mNavigationButton.setImageDrawable(null); | 1402 mNavigationButton.setImageDrawable(null); |
1364 break; | 1403 break; |
1365 case OFFLINE: | |
1366 Drawable bolt = ApiCompatibilityUtils.getDrawable( | |
1367 getResources(), R.drawable.offline_pin); | |
1368 bolt.mutate().setColorFilter( | |
1369 ApiCompatibilityUtils.getColor(getResources(), mUseDarkC olors | |
1370 ? R.color.locationbar_status_color | |
1371 : R.color.locationbar_status_color_light), Porte rDuff.Mode.SRC_IN); | |
1372 mNavigationButton.setImageDrawable(bolt); | |
1373 break; | |
1374 default: | 1404 default: |
1375 assert false; | 1405 assert false; |
1376 } | 1406 } |
1377 | 1407 |
1378 if (mNavigationButton.getVisibility() != VISIBLE) { | 1408 if (mNavigationButton.getVisibility() != VISIBLE) { |
1379 mNavigationButton.setVisibility(VISIBLE); | 1409 mNavigationButton.setVisibility(VISIBLE); |
1380 } | 1410 } |
1381 mNavigationButtonType = buttonType; | 1411 mNavigationButtonType = buttonType; |
1382 | 1412 |
1383 updateVerboseStatusVisibility(); | |
1384 updateLocationBarIconContainerVisibility(); | 1413 updateLocationBarIconContainerVisibility(); |
1385 } | 1414 } |
1386 | 1415 |
1387 /** | 1416 /** |
1388 * Update visibility of the verbose status based on the button type and focu s state of the | 1417 * Update visibility of the verbose status based on the button type and focu s state of the |
1389 * omnibox. | 1418 * omnibox. |
1390 */ | 1419 */ |
1391 private void updateVerboseStatusVisibility() { | 1420 private void updateVerboseStatusVisibility() { |
1392 boolean verboseStatusVisible = | 1421 // Because is offline page is cleared a bit slower, we also ensure that connection security |
1393 mNavigationButtonType == NavigationButtonType.OFFLINE && !mUrlHa sFocus; | 1422 // level is NONE. |
1423 boolean verboseStatusVisible = !mUrlHasFocus && getCurrentTab() != null | |
1424 && getCurrentTab().isOfflinePage() | |
1425 && getSecurityLevel() == ConnectionSecurityLevel.NONE; | |
1394 | 1426 |
1395 int verboseStatusVisibility = verboseStatusVisible ? VISIBLE : GONE; | 1427 int verboseStatusVisibility = verboseStatusVisible ? VISIBLE : GONE; |
1396 | 1428 |
1397 mVerboseStatusTextView.setTextColor(ApiCompatibilityUtils.getColor(getRe sources(), | 1429 mVerboseStatusTextView.setTextColor(ApiCompatibilityUtils.getColor(getRe sources(), |
1398 mUseDarkColors ? R.color.locationbar_status_color | 1430 mUseDarkColors ? R.color.locationbar_status_color |
1399 : R.color.locationbar_status_color_light)); | 1431 : R.color.locationbar_status_color_light)); |
1400 mVerboseStatusTextView.setVisibility(verboseStatusVisibility); | 1432 mVerboseStatusTextView.setVisibility(verboseStatusVisibility); |
1401 | 1433 |
1402 View separator = findViewById(R.id.location_bar_verbose_status_separator ); | 1434 View separator = findViewById(R.id.location_bar_verbose_status_separator ); |
1403 separator.setBackgroundColor(ApiCompatibilityUtils.getColor(getResources (), mUseDarkColors | 1435 separator.setBackgroundColor(ApiCompatibilityUtils.getColor(getResources (), mUseDarkColors |
1404 ? R.color.locationbar_status_separator_color | 1436 ? R.color.locationbar_status_separator_color |
1405 : R.color.locationbar_status_separator_color_light)); | 1437 : R.color.locationbar_status_separator_color_light)); |
1406 separator.setVisibility(verboseStatusVisibility); | 1438 separator.setVisibility(verboseStatusVisibility); |
1407 | 1439 |
1408 findViewById(R.id.location_bar_verbose_status_extra_space) | 1440 findViewById(R.id.location_bar_verbose_status_extra_space) |
1409 .setVisibility(verboseStatusVisibility); | 1441 .setVisibility(verboseStatusVisibility); |
1410 } | 1442 } |
1411 | 1443 |
1412 /** | 1444 /** |
1413 * Update the visibility of the location bar icon container based on the sta te of the | 1445 * Update the visibility of the location bar icon container based on the sta te of the |
1414 * security and navigation icons. | 1446 * security and navigation icons. |
1415 */ | 1447 */ |
1416 protected void updateLocationBarIconContainerVisibility() { | 1448 protected void updateLocationBarIconContainerVisibility() { |
1417 boolean showContainer = | 1449 @LocationBarButtonType |
1418 mSecurityButtonShown || mNavigationButtonType != NavigationButto nType.EMPTY; | 1450 int buttonToShow = getLocationBarButtonToShow(); |
1419 findViewById(R.id.location_bar_icon).setVisibility(showContainer ? VISIB LE : GONE); | 1451 findViewById(R.id.location_bar_icon) |
1452 .setVisibility(buttonToShow != BUTTON_TYPE_NONE ? VISIBLE : GONE ); | |
1420 } | 1453 } |
1421 | 1454 |
1422 /** | 1455 /** |
1423 * Updates the layout params for the location bar start aligned views. | 1456 * Updates the layout params for the location bar start aligned views. |
1424 */ | 1457 */ |
1425 protected void updateLayoutParams() { | 1458 protected void updateLayoutParams() { |
1426 int startMargin = 0; | 1459 int startMargin = 0; |
1427 int urlContainerChildIndex = -1; | 1460 int urlContainerChildIndex = -1; |
1428 for (int i = 0; i < getChildCount(); i++) { | 1461 for (int i = 0; i < getChildCount(); i++) { |
1429 View childView = getChildAt(i); | 1462 View childView = getChildAt(i); |
(...skipping 1037 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2467 public View getContainerView() { | 2500 public View getContainerView() { |
2468 return this; | 2501 return this; |
2469 } | 2502 } |
2470 | 2503 |
2471 @Override | 2504 @Override |
2472 public void setTitleToPageTitle() { } | 2505 public void setTitleToPageTitle() { } |
2473 | 2506 |
2474 @Override | 2507 @Override |
2475 public void setShowTitle(boolean showTitle) { } | 2508 public void setShowTitle(boolean showTitle) { } |
2476 } | 2509 } |
OLD | NEW |