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 644 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
655 this(context, attrs, R.layout.location_bar); | 655 this(context, attrs, R.layout.location_bar); |
656 } | 656 } |
657 | 657 |
658 public LocationBarLayout(Context context, AttributeSet attrs, int layoutId)
{ | 658 public LocationBarLayout(Context context, AttributeSet attrs, int layoutId)
{ |
659 super(context, attrs); | 659 super(context, attrs); |
660 | 660 |
661 LayoutInflater.from(context).inflate(layoutId, this, true); | 661 LayoutInflater.from(context).inflate(layoutId, this, true); |
662 mNavigationButton = (ImageView) findViewById(R.id.navigation_button); | 662 mNavigationButton = (ImageView) findViewById(R.id.navigation_button); |
663 assert mNavigationButton != null : "Missing navigation type view."; | 663 assert mNavigationButton != null : "Missing navigation type view."; |
664 | 664 |
665 mNavigationButtonType = DeviceFormFactor.isTablet(context) | 665 mNavigationButtonType = DeviceFormFactor.isTablet() ? NavigationButtonTy
pe.PAGE |
666 ? NavigationButtonType.PAGE : NavigationButtonType.EMPTY; | 666 : NavigationButtonTy
pe.EMPTY; |
667 | 667 |
668 mSecurityButton = (TintedImageButton) findViewById(R.id.security_button)
; | 668 mSecurityButton = (TintedImageButton) findViewById(R.id.security_button)
; |
669 mSecurityIconResource = 0; | 669 mSecurityIconResource = 0; |
670 | 670 |
671 mVerboseStatusTextView = (TextView) findViewById(R.id.location_bar_verbo
se_status); | 671 mVerboseStatusTextView = (TextView) findViewById(R.id.location_bar_verbo
se_status); |
672 | 672 |
673 mDeleteButton = (TintedImageButton) findViewById(R.id.delete_button); | 673 mDeleteButton = (TintedImageButton) findViewById(R.id.delete_button); |
674 | 674 |
675 mUrlBar = (UrlBar) findViewById(R.id.url_bar); | 675 mUrlBar = (UrlBar) findViewById(R.id.url_bar); |
676 // The HTC Sense IME will attempt to autocomplete words in the Omnibox w
hen Prediction is | 676 // The HTC Sense IME will attempt to autocomplete words in the Omnibox w
hen Prediction is |
(...skipping 218 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
895 // call to onNativeLibraryReady, so this assert will not fire. | 895 // call to onNativeLibraryReady, so this assert will not fire. |
896 assert mNativeInitialized : | 896 assert mNativeInitialized : |
897 "Setting Autocomplete Profile before native side initialized"; | 897 "Setting Autocomplete Profile before native side initialized"; |
898 mAutocomplete.setProfile(profile); | 898 mAutocomplete.setProfile(profile); |
899 mOmniboxPrerender.initializeForProfile(profile); | 899 mOmniboxPrerender.initializeForProfile(profile); |
900 } | 900 } |
901 | 901 |
902 @LocationBarButtonType private int getLocationBarButtonToShow() { | 902 @LocationBarButtonType private int getLocationBarButtonToShow() { |
903 boolean isOffline = | 903 boolean isOffline = |
904 getCurrentTab() != null && OfflinePageUtils.isOfflinePage(getCur
rentTab()); | 904 getCurrentTab() != null && OfflinePageUtils.isOfflinePage(getCur
rentTab()); |
905 boolean isTablet = DeviceFormFactor.isTablet(getContext()); | 905 boolean isTablet = DeviceFormFactor.isTablet(); |
906 | 906 |
907 // The navigation icon type is only applicable on tablets. While smalle
r form factors do | 907 // The navigation icon type is only applicable on tablets. While smalle
r form factors do |
908 // not have an icon visible to the user when the URL is focused, BUTTON_
TYPE_NONE is not | 908 // not have an icon visible to the user when the URL is focused, BUTTON_
TYPE_NONE is not |
909 // returned as it will trigger an undesired jump during the animation as
it attempts to | 909 // returned as it will trigger an undesired jump during the animation as
it attempts to |
910 // hide the icon. | 910 // hide the icon. |
911 if (mUrlHasFocus && isTablet) return BUTTON_TYPE_NAVIGATION_ICON; | 911 if (mUrlHasFocus && isTablet) return BUTTON_TYPE_NAVIGATION_ICON; |
912 | 912 |
913 return getSecurityIconResource(getSecurityLevel(), !isTablet, isOffline)
!= 0 | 913 return getSecurityIconResource(getSecurityLevel(), !isTablet, isOffline)
!= 0 |
914 ? BUTTON_TYPE_SECURITY_ICON | 914 ? BUTTON_TYPE_SECURITY_ICON |
915 : BUTTON_TYPE_NONE; | 915 : BUTTON_TYPE_NONE; |
(...skipping 332 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1248 OmniboxSuggestion suggestion) { | 1248 OmniboxSuggestion suggestion) { |
1249 if (suggestion.isUrlSuggestion()) { | 1249 if (suggestion.isUrlSuggestion()) { |
1250 return NavigationButtonType.PAGE; | 1250 return NavigationButtonType.PAGE; |
1251 } else { | 1251 } else { |
1252 return NavigationButtonType.MAGNIFIER; | 1252 return NavigationButtonType.MAGNIFIER; |
1253 } | 1253 } |
1254 } | 1254 } |
1255 | 1255 |
1256 // Updates the navigation button based on the URL string | 1256 // Updates the navigation button based on the URL string |
1257 private void updateNavigationButton() { | 1257 private void updateNavigationButton() { |
1258 boolean isTablet = DeviceFormFactor.isTablet(getContext()); | 1258 boolean isTablet = DeviceFormFactor.isTablet(); |
1259 NavigationButtonType type = NavigationButtonType.EMPTY; | 1259 NavigationButtonType type = NavigationButtonType.EMPTY; |
1260 if (isTablet && !mSuggestionItems.isEmpty()) { | 1260 if (isTablet && !mSuggestionItems.isEmpty()) { |
1261 // If there are suggestions showing, show the icon for the default s
uggestion. | 1261 // If there are suggestions showing, show the icon for the default s
uggestion. |
1262 type = suggestionTypeToNavigationButtonType( | 1262 type = suggestionTypeToNavigationButtonType( |
1263 mSuggestionItems.get(0).getSuggestion()); | 1263 mSuggestionItems.get(0).getSuggestion()); |
1264 } else if (isTablet) { | 1264 } else if (isTablet) { |
1265 type = NavigationButtonType.PAGE; | 1265 type = NavigationButtonType.PAGE; |
1266 } | 1266 } |
1267 | 1267 |
1268 if (type != mNavigationButtonType) setNavigationButtonType(type); | 1268 if (type != mNavigationButtonType) setNavigationButtonType(type); |
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1340 } | 1340 } |
1341 assert list != null : "Missing ColorStateList for Security Button."; | 1341 assert list != null : "Missing ColorStateList for Security Button."; |
1342 return list; | 1342 return list; |
1343 } | 1343 } |
1344 | 1344 |
1345 /** | 1345 /** |
1346 * Updates the security icon displayed in the LocationBar. | 1346 * Updates the security icon displayed in the LocationBar. |
1347 */ | 1347 */ |
1348 @Override | 1348 @Override |
1349 public void updateSecurityIcon(int securityLevel) { | 1349 public void updateSecurityIcon(int securityLevel) { |
1350 boolean isSmallDevice = !DeviceFormFactor.isTablet(getContext()); | 1350 boolean isSmallDevice = !DeviceFormFactor.isTablet(); |
1351 boolean isOfflinePage = | 1351 boolean isOfflinePage = |
1352 getCurrentTab() != null && OfflinePageUtils.isOfflinePage(getCur
rentTab()); | 1352 getCurrentTab() != null && OfflinePageUtils.isOfflinePage(getCur
rentTab()); |
1353 int id = getSecurityIconResource(securityLevel, isSmallDevice, isOffline
Page); | 1353 int id = getSecurityIconResource(securityLevel, isSmallDevice, isOffline
Page); |
1354 if (id == 0) { | 1354 if (id == 0) { |
1355 mSecurityButton.setImageDrawable(null); | 1355 mSecurityButton.setImageDrawable(null); |
1356 } else { | 1356 } else { |
1357 // ImageView#setImageResource is no-op if given resource is the curr
ent one. | 1357 // ImageView#setImageResource is no-op if given resource is the curr
ent one. |
1358 mSecurityButton.setImageResource(id); | 1358 mSecurityButton.setImageResource(id); |
1359 mSecurityButton.setTint(getColorStateList(securityLevel, getToolbarD
ataProvider(), | 1359 mSecurityButton.setTint(getColorStateList(securityLevel, getToolbarD
ataProvider(), |
1360 getResources(), ColorUtils.shouldUseOpaqueTextboxBackground( | 1360 getResources(), ColorUtils.shouldUseOpaqueTextboxBackground( |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1396 @VisibleForTesting | 1396 @VisibleForTesting |
1397 public boolean isSecurityButtonShown() { | 1397 public boolean isSecurityButtonShown() { |
1398 return mLocationBarButtonType == BUTTON_TYPE_SECURITY_ICON; | 1398 return mLocationBarButtonType == BUTTON_TYPE_SECURITY_ICON; |
1399 } | 1399 } |
1400 | 1400 |
1401 /** | 1401 /** |
1402 * Sets the type of the current navigation type and updates the UI to match
it. | 1402 * Sets the type of the current navigation type and updates the UI to match
it. |
1403 * @param buttonType The type of navigation button to be shown. | 1403 * @param buttonType The type of navigation button to be shown. |
1404 */ | 1404 */ |
1405 private void setNavigationButtonType(NavigationButtonType buttonType) { | 1405 private void setNavigationButtonType(NavigationButtonType buttonType) { |
1406 if (!DeviceFormFactor.isTablet(getContext())) return; | 1406 if (!DeviceFormFactor.isTablet()) return; |
1407 switch (buttonType) { | 1407 switch (buttonType) { |
1408 case PAGE: | 1408 case PAGE: |
1409 Drawable page = ApiCompatibilityUtils.getDrawable( | 1409 Drawable page = ApiCompatibilityUtils.getDrawable( |
1410 getResources(), R.drawable.ic_omnibox_page); | 1410 getResources(), R.drawable.ic_omnibox_page); |
1411 page.setColorFilter(mUseDarkColors | 1411 page.setColorFilter(mUseDarkColors |
1412 ? ApiCompatibilityUtils.getColor(getResources(), R.color
.light_normal_color) | 1412 ? ApiCompatibilityUtils.getColor(getResources(), R.color
.light_normal_color) |
1413 : Color.WHITE, PorterDuff.Mode.SRC_IN); | 1413 : Color.WHITE, PorterDuff.Mode.SRC_IN); |
1414 mNavigationButton.setImageDrawable(page); | 1414 mNavigationButton.setImageDrawable(page); |
1415 break; | 1415 break; |
1416 case MAGNIFIER: | 1416 case MAGNIFIER: |
(...skipping 1080 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2497 } | 2497 } |
2498 | 2498 |
2499 @Override | 2499 @Override |
2500 public void setTitleToPageTitle() { } | 2500 public void setTitleToPageTitle() { } |
2501 | 2501 |
2502 @Override | 2502 @Override |
2503 public void setShowTitle(boolean showTitle) { } | 2503 public void setShowTitle(boolean showTitle) { } |
2504 | 2504 |
2505 @Override | 2505 @Override |
2506 public boolean mustQueryUrlBarLocationForSuggestions() { | 2506 public boolean mustQueryUrlBarLocationForSuggestions() { |
2507 return DeviceFormFactor.isTablet(getContext()); | 2507 return DeviceFormFactor.isTablet(); |
2508 } | 2508 } |
2509 } | 2509 } |
OLD | NEW |