mirror of
https://gitlab.winehq.org/wine/wine-gecko.git
synced 2024-09-13 09:24:08 -07:00
Bug 857165 - Highlight domain when showing urls. r=mfinkle
This commit is contained in:
parent
16037cac77
commit
7c66db2d03
@ -7,6 +7,7 @@ package org.mozilla.gecko;
|
||||
|
||||
import org.mozilla.gecko.gfx.ImmutableViewportMetrics;
|
||||
import org.mozilla.gecko.gfx.LayerView;
|
||||
import org.mozilla.gecko.util.StringUtils;
|
||||
import org.mozilla.gecko.util.HardwareUtils;
|
||||
|
||||
import org.mozilla.gecko.util.ThreadUtils;
|
||||
@ -16,6 +17,7 @@ import android.content.Context;
|
||||
import android.content.SharedPreferences;
|
||||
import android.content.res.Resources;
|
||||
import android.graphics.Bitmap;
|
||||
import android.graphics.Color;
|
||||
import android.graphics.Rect;
|
||||
import android.graphics.drawable.AnimationDrawable;
|
||||
import android.graphics.drawable.ColorDrawable;
|
||||
@ -24,6 +26,9 @@ import android.graphics.drawable.StateListDrawable;
|
||||
import android.os.Build;
|
||||
import android.os.Handler;
|
||||
import android.os.SystemClock;
|
||||
import android.text.style.ForegroundColorSpan;
|
||||
import android.text.Spannable;
|
||||
import android.text.SpannableStringBuilder;
|
||||
import android.text.TextUtils;
|
||||
import android.util.AttributeSet;
|
||||
import android.util.Log;
|
||||
@ -111,6 +116,9 @@ public class BrowserToolbar implements Tabs.OnTabsChangedListener,
|
||||
private static final int TABS_EXPANDED = 2;
|
||||
|
||||
private static final int FORWARD_ANIMATION_DURATION = 450;
|
||||
private final ForegroundColorSpan mUrlColor;
|
||||
private final ForegroundColorSpan mDomainColor;
|
||||
private final ForegroundColorSpan mPrivateDomainColor;
|
||||
|
||||
private boolean mShowUrl;
|
||||
|
||||
@ -136,14 +144,18 @@ public class BrowserToolbar implements Tabs.OnTabsChangedListener,
|
||||
|
||||
@Override
|
||||
public void onPostExecute(Void v) {
|
||||
if (mShowUrl) {
|
||||
Tab tab = Tabs.getInstance().getSelectedTab();
|
||||
if (tab != null) {
|
||||
setTitle(tab.getURL());
|
||||
}
|
||||
Tab tab = Tabs.getInstance().getSelectedTab();
|
||||
if (tab != null) {
|
||||
setTitle(tab.getDisplayTitle());
|
||||
}
|
||||
}
|
||||
}).execute();
|
||||
|
||||
Resources res = mActivity.getResources();
|
||||
mUrlColor = new ForegroundColorSpan(res.getColor(R.color.url_bar_urltext));
|
||||
mDomainColor = new ForegroundColorSpan(res.getColor(R.color.url_bar_domaintext));
|
||||
mPrivateDomainColor = new ForegroundColorSpan(res.getColor(R.color.url_bar_domaintext_private));
|
||||
|
||||
}
|
||||
|
||||
public void from(RelativeLayout layout) {
|
||||
@ -424,7 +436,7 @@ public class BrowserToolbar implements Tabs.OnTabsChangedListener,
|
||||
switch(msg) {
|
||||
case TITLE:
|
||||
if (Tabs.getInstance().isSelectedTab(tab)) {
|
||||
setTitle(mShowUrl ? tab.getURL() : tab.getDisplayTitle());
|
||||
setTitle(tab.getDisplayTitle());
|
||||
}
|
||||
break;
|
||||
case START:
|
||||
@ -444,7 +456,7 @@ public class BrowserToolbar implements Tabs.OnTabsChangedListener,
|
||||
updateForwardButton(tab.canDoForward());
|
||||
setProgressVisibility(false);
|
||||
// Reset the title in case we haven't navigated to a new page yet.
|
||||
setTitle(mShowUrl ? tab.getURL() : tab.getDisplayTitle());
|
||||
setTitle(tab.getDisplayTitle());
|
||||
}
|
||||
break;
|
||||
case RESTORED:
|
||||
@ -965,8 +977,9 @@ public class BrowserToolbar implements Tabs.OnTabsChangedListener,
|
||||
}
|
||||
}
|
||||
|
||||
private void setTitle(CharSequence title) {
|
||||
private void setTitle(String title) {
|
||||
Tab tab = Tabs.getInstance().getSelectedTab();
|
||||
CharSequence displayTitle = title;
|
||||
|
||||
// Keep the title unchanged if the tab is entering reader mode
|
||||
if (tab != null && tab.isEnteringReaderMode())
|
||||
@ -976,10 +989,30 @@ public class BrowserToolbar implements Tabs.OnTabsChangedListener,
|
||||
// placeholder text. Because "about:home" and "about:privatebrowsing" don't
|
||||
// have titles, their display titles will always match their URLs.
|
||||
if (tab != null && ("about:home".equals(title) ||
|
||||
"about:privatebrowsing".equals(title)))
|
||||
title = null;
|
||||
"about:privatebrowsing".equals(title))) {
|
||||
displayTitle = null;
|
||||
}
|
||||
|
||||
mTitle.setText(title);
|
||||
if (mShowUrl && displayTitle != null) {
|
||||
title = StringUtils.stripScheme(tab.getURL());
|
||||
title = StringUtils.stripCommonSubdomains(title);
|
||||
displayTitle = title;
|
||||
|
||||
// highlight the domain name if we find one
|
||||
String baseDomain = tab.getBaseDomain();
|
||||
if (!TextUtils.isEmpty(baseDomain)) {
|
||||
SpannableStringBuilder builder = new SpannableStringBuilder(title);
|
||||
int index = title.indexOf(baseDomain);
|
||||
if (index > -1) {
|
||||
builder.setSpan(mUrlColor, 0, title.length(), Spannable.SPAN_INCLUSIVE_INCLUSIVE);
|
||||
builder.setSpan(tab.isPrivate() ? mPrivateDomainColor : mDomainColor, index, index+baseDomain.length(), Spannable.SPAN_INCLUSIVE_INCLUSIVE);
|
||||
|
||||
displayTitle = builder;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
mTitle.setText(displayTitle);
|
||||
mLayout.setContentDescription(title != null ? title : mTitle.getHint());
|
||||
}
|
||||
|
||||
@ -1164,7 +1197,7 @@ public class BrowserToolbar implements Tabs.OnTabsChangedListener,
|
||||
Tab tab = Tabs.getInstance().getSelectedTab();
|
||||
if (tab != null) {
|
||||
String url = tab.getURL();
|
||||
setTitle(mShowUrl ? tab.getURL() : tab.getDisplayTitle());
|
||||
setTitle(tab.getDisplayTitle());
|
||||
setFavicon(tab.getFavicon());
|
||||
setProgressVisibility(tab.getState() == Tab.STATE_LOADING);
|
||||
setSecurityMode(tab.getSecurityMode());
|
||||
@ -1174,17 +1207,18 @@ public class BrowserToolbar implements Tabs.OnTabsChangedListener,
|
||||
updateBackButton(tab.canDoBack());
|
||||
updateForwardButton(tab.canDoForward());
|
||||
|
||||
mAddressBarBg.setPrivateMode(tab.isPrivate());
|
||||
mLayout.setPrivateMode(tab.isPrivate());
|
||||
mTabs.setPrivateMode(tab.isPrivate());
|
||||
mTitle.setPrivateMode(tab.isPrivate());
|
||||
mMenu.setPrivateMode(tab.isPrivate());
|
||||
final boolean isPrivate = tab.isPrivate();
|
||||
mAddressBarBg.setPrivateMode(isPrivate);
|
||||
mLayout.setPrivateMode(isPrivate);
|
||||
mTabs.setPrivateMode(isPrivate);
|
||||
mTitle.setPrivateMode(isPrivate);
|
||||
mMenu.setPrivateMode(isPrivate);
|
||||
|
||||
if (mBack instanceof BackButton)
|
||||
((BackButton) mBack).setPrivateMode(tab.isPrivate());
|
||||
((BackButton) mBack).setPrivateMode(isPrivate);
|
||||
|
||||
if (mForward instanceof ForwardButton)
|
||||
((ForwardButton) mForward).setPrivateMode(tab.isPrivate());
|
||||
((ForwardButton) mForward).setPrivateMode(isPrivate);
|
||||
}
|
||||
}
|
||||
|
||||
@ -1218,7 +1252,7 @@ public class BrowserToolbar implements Tabs.OnTabsChangedListener,
|
||||
mShowUrl = sharedPreferences.getBoolean(key, false);
|
||||
Tab tab = Tabs.getInstance().getSelectedTab();
|
||||
if (tab != null) {
|
||||
setTitle(mShowUrl ? tab.getURL() : tab.getDisplayTitle());
|
||||
setTitle(tab.getDisplayTitle());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -36,6 +36,7 @@ public class Tab {
|
||||
private final int mId;
|
||||
private long mLastUsed;
|
||||
private String mUrl;
|
||||
private String mBaseDomain;
|
||||
private String mUserSearch;
|
||||
private String mTitle;
|
||||
private Bitmap mFavicon;
|
||||
@ -77,6 +78,7 @@ public class Tab {
|
||||
mId = id;
|
||||
mLastUsed = 0;
|
||||
mUrl = url;
|
||||
mBaseDomain = "";
|
||||
mUserSearch = "";
|
||||
mExternal = external;
|
||||
mParentId = parentId;
|
||||
@ -154,6 +156,10 @@ public class Tab {
|
||||
return mUrl;
|
||||
}
|
||||
|
||||
public String getBaseDomain() {
|
||||
return mBaseDomain;
|
||||
}
|
||||
|
||||
public Bitmap getFavicon() {
|
||||
return mFavicon;
|
||||
}
|
||||
@ -566,6 +572,7 @@ public class Tab {
|
||||
updateUserSearch(message.getString("userSearch"));
|
||||
|
||||
setDocumentURI(message.getString("documentURI"));
|
||||
mBaseDomain = message.optString("baseDomain");
|
||||
if (message.getBoolean("sameDocument")) {
|
||||
// We can get a location change event for the same document with an anchor tag
|
||||
// Notify listeners so that buttons like back or forward will update themselves
|
||||
|
@ -83,5 +83,9 @@
|
||||
<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>
|
||||
|
||||
</resources>
|
||||
|
||||
|
@ -3387,6 +3387,22 @@ Tab.prototype = {
|
||||
this.pluginDoorhangerTimeout = null;
|
||||
this.shouldShowPluginDoorhanger = true;
|
||||
this.clickToPlayPluginsActivated = false;
|
||||
// Borrowed from desktop Firefox: http://mxr.mozilla.org/mozilla-central/source/browser/base/content/urlbarBindings.xml#174
|
||||
let matchedURL = documentURI.match(/^((?:[a-z]+:\/\/)?(?:[^\/]+@)?)(.+?)(?::\d+)?(?:\/|$)/);
|
||||
let baseDomain = "";
|
||||
if (matchedURL) {
|
||||
var domain = "";
|
||||
[, , domain] = matchedURL;
|
||||
|
||||
try {
|
||||
baseDomain = Services.eTLD.getBaseDomainFromHost(domain);
|
||||
if (!domain.endsWith(baseDomain)) {
|
||||
// getBaseDomainFromHost converts its resultant to ACE.
|
||||
let IDNService = Cc["@mozilla.org/network/idn-service;1"].getService(Ci.nsIIDNService);
|
||||
baseDomain = IDNService.convertACEtoUTF8(baseDomain);
|
||||
}
|
||||
} catch (e) {}
|
||||
}
|
||||
|
||||
let message = {
|
||||
type: "Content:LocationChange",
|
||||
@ -3394,6 +3410,7 @@ Tab.prototype = {
|
||||
uri: fixedURI.spec,
|
||||
userSearch: this.userSearch || "",
|
||||
documentURI: documentURI,
|
||||
baseDomain: baseDomain,
|
||||
contentType: (contentType ? contentType : ""),
|
||||
sameDocument: sameDocument
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user