Bug 1250671 - Show full URL in URL bar on tablets. r=mcomella, a=ritu
authorSebastian Kaspari <s.kaspari@gmail.com>
Tue, 23 Feb 2016 16:05:36 -0800
changeset 325274 ecdc38c5ea399fcc91b001f4d104ba61bcf540a2
parent 325273 c63a2db7aafa18f7a5374c2bd431f5fbf0274361
child 325275 79e59014d1725bb530ebef57b60dc668bd217389
push id1128
push userjlund@mozilla.com
push dateWed, 01 Jun 2016 01:31:59 +0000
treeherdermozilla-release@fe0d30de989d [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmcomella, ritu
bugs1250671
milestone47.0a2
Bug 1250671 - Show full URL in URL bar on tablets. r=mcomella, a=ritu MozReview-Commit-ID: 9zEh5jNm1Tr
mobile/android/base/java/org/mozilla/gecko/toolbar/ToolbarDisplayLayout.java
mobile/android/base/resources/values/colors.xml
--- a/mobile/android/base/java/org/mozilla/gecko/toolbar/ToolbarDisplayLayout.java
+++ b/mobile/android/base/java/org/mozilla/gecko/toolbar/ToolbarDisplayLayout.java
@@ -17,25 +17,24 @@ import org.mozilla.gecko.SiteIdentity;
 import org.mozilla.gecko.SiteIdentity.MixedMode;
 import org.mozilla.gecko.SiteIdentity.SecurityMode;
 import org.mozilla.gecko.SiteIdentity.TrackingMode;
 import org.mozilla.gecko.Tab;
 import org.mozilla.gecko.animation.PropertyAnimator;
 import org.mozilla.gecko.animation.ViewHelper;
 import org.mozilla.gecko.toolbar.BrowserToolbarTabletBase.ForwardButtonAnimation;
 import org.mozilla.gecko.util.ColorUtils;
+import org.mozilla.gecko.util.HardwareUtils;
 import org.mozilla.gecko.util.StringUtils;
 import org.mozilla.gecko.widget.themed.ThemedLinearLayout;
 import org.mozilla.gecko.widget.themed.ThemedTextView;
 
 import android.content.Context;
 import android.os.SystemClock;
-import android.support.annotation.Nullable;
 import android.support.annotation.NonNull;
-import android.support.v4.content.ContextCompat;
 import android.text.Spannable;
 import android.text.SpannableString;
 import android.text.SpannableStringBuilder;
 import android.text.TextUtils;
 import android.text.style.ForegroundColorSpan;
 import android.util.AttributeSet;
 import android.util.Log;
 import android.view.LayoutInflater;
@@ -120,30 +119,38 @@ public class ToolbarDisplayLayout extend
     private static final int LEVEL_WARNING_MINOR = 3;
     private static final int LEVEL_LOCK_DISABLED = 4;
     // Levels for displaying Tracking Protection state icons.
     private static final int LEVEL_SHIELD_ENABLED = 5;
     private static final int LEVEL_SHIELD_DISABLED = 6;
     // Icon used for about:home
     private static final int LEVEL_SEARCH_ICON = 999;
 
-    private final ForegroundColorSpan mBlockedColor;
+    private final ForegroundColorSpan mUrlColorSpan;
+    private final ForegroundColorSpan mBlockedColorSpan;
+    private final ForegroundColorSpan mDomainColorSpan;
+    private final ForegroundColorSpan mPrivateDomainColorSpan;
+    private final ForegroundColorSpan mCertificateOwnerColorSpan;
 
     public ToolbarDisplayLayout(Context context, AttributeSet attrs) {
         super(context, attrs);
         setOrientation(HORIZONTAL);
 
         mActivity = (BrowserApp) context;
 
         LayoutInflater.from(context).inflate(R.layout.toolbar_display_layout, this);
 
         mTitle = (ThemedTextView) findViewById(R.id.url_bar_title);
         mTitlePadding = mTitle.getPaddingRight();
 
-        mBlockedColor = new ForegroundColorSpan(ColorUtils.getColor(context, R.color.url_bar_blockedtext));
+        mUrlColorSpan = new ForegroundColorSpan(ColorUtils.getColor(context, R.color.url_bar_urltext));
+        mBlockedColorSpan = new ForegroundColorSpan(ColorUtils.getColor(context, R.color.url_bar_blockedtext));
+        mDomainColorSpan = new ForegroundColorSpan(ColorUtils.getColor(context, R.color.url_bar_domaintext));
+        mPrivateDomainColorSpan = new ForegroundColorSpan(ColorUtils.getColor(context, R.color.url_bar_domaintext_private));
+        mCertificateOwnerColorSpan = new ForegroundColorSpan(ColorUtils.getColor(context, R.color.affirmative_green));
 
         mSiteSecurity = (ImageButton) findViewById(R.id.site_security);
 
         mSiteIdentityPopup = new SiteIdentityPopup(mActivity);
         mSiteIdentityPopup.setAnchor(this);
         mSiteIdentityPopup.setOnVisibilityChangeListener(mActivity);
 
         mStop = (ImageButton) findViewById(R.id.stop);
@@ -244,17 +251,17 @@ public class ToolbarDisplayLayout extend
             return;
         }
 
         // Show the about:blocked page title in red, regardless of prefs
         if (tab.getErrorType() == Tab.ErrorType.BLOCKED) {
             final String title = tab.getDisplayTitle();
 
             final SpannableStringBuilder builder = new SpannableStringBuilder(title);
-            builder.setSpan(mBlockedColor, 0, title.length(), Spannable.SPAN_INCLUSIVE_INCLUSIVE);
+            builder.setSpan(mBlockedColorSpan, 0, title.length(), Spannable.SPAN_INCLUSIVE_INCLUSIVE);
 
             setTitle(builder);
             setContentDescription(null);
             return;
         }
 
         final String baseDomain = tab.getBaseDomain();
 
@@ -266,35 +273,56 @@ public class ToolbarDisplayLayout extend
 
         // This value is not visible to screen readers but we rely on it when running UI tests. Screen
         // readers will instead focus BrowserToolbar and read the "base domain" from there. UI tests
         // will read the content description to obtain the full URL for performing assertions.
         setContentDescription(strippedURL);
 
         final SiteIdentity siteIdentity = tab.getSiteIdentity();
         if (siteIdentity.hasOwner()) {
-            final String title;
-
-            if (siteIdentity.hasCountry()) {
-                title = String.format("%s (%s)", siteIdentity.getOwner(), siteIdentity.getCountry());
-            } else {
-                title = siteIdentity.getOwner();
-            }
-
-            final int color = ContextCompat.getColor(getContext(), R.color.affirmative_green);
-
-            final SpannableString spannable = new SpannableString(title);
-            spannable.setSpan(new ForegroundColorSpan(color), 0, title.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
-
-            setTitle(spannable);
-        } else if (!TextUtils.isEmpty(baseDomain)) {
+            // Show Owner of EV certificate as title
+            updateTitleFromSiteIdentity(siteIdentity);
+        } else if (!HardwareUtils.isTablet() && !TextUtils.isEmpty(baseDomain)) {
+            // Show just the base domain as title
             setTitle(baseDomain);
         } else {
-            setTitle(strippedURL);
+            // Display full URL as title
+            updateAndColorTitleFromFullURL(strippedURL, baseDomain, tab.isPrivate());
+        }
+    }
+
+    private void updateTitleFromSiteIdentity(SiteIdentity siteIdentity) {
+        final String title;
+
+        if (siteIdentity.hasCountry()) {
+            title = String.format("%s (%s)", siteIdentity.getOwner(), siteIdentity.getCountry());
+        } else {
+            title = siteIdentity.getOwner();
         }
+
+        final SpannableString spannable = new SpannableString(title);
+        spannable.setSpan(mCertificateOwnerColorSpan, 0, title.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
+
+        setTitle(spannable);
+    }
+
+    private void updateAndColorTitleFromFullURL(String url, String baseDomain, boolean isPrivate) {
+        int index = url.indexOf(baseDomain);
+        if (index == -1) {
+            setTitle(url);
+            return;
+        }
+
+        final SpannableStringBuilder builder = new SpannableStringBuilder(url);
+
+        builder.setSpan(mUrlColorSpan, 0, url.length(), Spannable.SPAN_INCLUSIVE_INCLUSIVE);
+        builder.setSpan(isPrivate ? mPrivateDomainColorSpan : mDomainColorSpan,
+                index, index + baseDomain.length(), Spannable.SPAN_INCLUSIVE_INCLUSIVE);
+
+        setTitle(builder);
     }
 
     private String stripAboutReaderURL(final String url) {
         if (!AboutPages.isAboutReader(url)) {
             return url;
         }
 
         return ReaderModeUtils.getUrlFromAboutReader(url);
--- a/mobile/android/base/resources/values/colors.xml
+++ b/mobile/android/base/resources/values/colors.xml
@@ -105,16 +105,19 @@
   <color name="url_bar_text_highlight_pb">#FFD06BFF</color>
   <color name="tab_row_pressed">#4D000000</color>
 
   <color name="textbox_background">#FFF</color>
   <color name="textbox_background_disabled">#DDD</color>
   <color name="textbox_stroke">#000</color>
   <color name="textbox_stroke_disabled">#666</color>
 
+  <color name="url_bar_urltext">#A6A6A6</color>
+  <color name="url_bar_domaintext">#000</color>
+  <color name="url_bar_domaintext_private">#FFF</color>
   <color name="url_bar_blockedtext">#b14646</color>
   <color name="url_bar_shadow">#12000000</color>
 
   <color name="home_button_bar_bg">#FFF5F7F9</color>
 
   <color name="panel_image_item_background">#D1D9E1</color>
   <color name="panel_icon_item_title_background">#32000000</color>
   <color name="panel_tab_text_normal">#FFBFBFBF</color>