author | Margaret Leibovic <margaret.leibovic@gmail.com> |
Tue, 14 May 2013 16:19:37 -0700 | |
changeset 143436 | 5f45f5f6cc29783bee64fba02bf5e45f025fa00a |
parent 143435 | 5991b3688770ee14dad65c0acdf5389f7d75da91 |
child 143437 | c4f374baea0ab471d360493da85051f3920e5696 |
push id | 2697 |
push user | bbajaj@mozilla.com |
push date | Mon, 05 Aug 2013 18:49:53 +0000 |
treeherder | mozilla-beta@dfec938c7b63 [default view] [failures only] |
perfherder | [talos] [build metrics] [platform microbench] (compared to previous push) |
reviewers | wesj |
bugs | 868342 |
milestone | 24.0a1 |
first release with | nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
|
last release without | nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
|
--- a/mobile/android/base/BrowserToolbar.java +++ b/mobile/android/base/BrowserToolbar.java @@ -146,20 +146,17 @@ public class BrowserToolbar implements T if (shouldShowUrl == mShowUrl) { return; } mShowUrl = shouldShowUrl; ThreadUtils.postToUiThread(new Runnable() { @Override public void run() { - Tab tab = Tabs.getInstance().getSelectedTab(); - if (tab != null) { - setTitle(tab.getDisplayTitle()); - } + updateTitle(); } }); } @Override public boolean isObserver() { // We want to be notified of changes to be able to switch mode // without restarting. @@ -441,17 +438,17 @@ public class BrowserToolbar implements T return mLayout; } @Override public void onTabChanged(Tab tab, Tabs.TabEvents msg, Object data) { switch(msg) { case TITLE: if (Tabs.getInstance().isSelectedTab(tab)) { - setTitle(tab.getDisplayTitle()); + updateTitle(); } break; case START: if (Tabs.getInstance().isSelectedTab(tab)) { updateBackButton(tab.canDoBack()); updateForwardButton(tab.canDoForward()); Boolean showProgress = (Boolean)data; if (showProgress && tab.getState() == Tab.STATE_LOADING) @@ -461,17 +458,17 @@ public class BrowserToolbar implements T } break; case STOP: if (Tabs.getInstance().isSelectedTab(tab)) { updateBackButton(tab.canDoBack()); updateForwardButton(tab.canDoForward()); setProgressVisibility(false); // Reset the title in case we haven't navigated to a new page yet. - setTitle(tab.getDisplayTitle()); + updateTitle(); } break; case RESTORED: updateTabCount(Tabs.getInstance().getDisplayCount()); break; case SELECTED: mSwitchingTabs = true; // fall through @@ -893,53 +890,56 @@ public class BrowserToolbar implements T !url.equals("about:blank"))); if ((mShadow.getVisibility() == View.VISIBLE) != visible) { mShadow.setVisibility(visible ? View.VISIBLE : View.GONE); } } private void setTitle(CharSequence title) { - Tab tab = Tabs.getInstance().getSelectedTab(); + mTitle.setText(title); + mLayout.setContentDescription(title != null ? title : mTitle.getHint()); + } - if (tab != null) { - // Keep the title unchanged if the tab is entering reader mode - if (tab.isEnteringReaderMode()) { - return; - } - - // Setting a null title will ensure we just see the "Enter Search or Address" - // placeholder text. Because "about:home" and "about:privatebrowsing" don't - // have titles, their display titles will always match their URLs. - if ("about:home".equals(title) || "about:privatebrowsing".equals(title)) { - title = null; - } + // Sets the toolbar title according to the selected tab, obeying the mShowUrl prference. + private void updateTitle() { + Tab tab = Tabs.getInstance().getSelectedTab(); + // Keep the title unchanged if there's no selected tab, or if the tab is entering reader mode. + if (tab == null || tab.isEnteringReaderMode()) { + return; + } - String url = tab.getURL(); - if (mShowUrl && title != null && url != null) { - url = StringUtils.stripScheme(url); - title = StringUtils.stripCommonSubdomains(url); + String url = tab.getURL(); + // Setting a null title will ensure we just see the "Enter Search or Address" placeholder text. + if ("about:home".equals(url) || "about:privatebrowsing".equals(url)) { + setTitle(null); + return; + } - // highlight the domain name if we find one - String baseDomain = tab.getBaseDomain(); - if (!TextUtils.isEmpty(baseDomain)) { - SpannableStringBuilder builder = new SpannableStringBuilder(title); - int index = title.toString().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); + // If the pref to show the URL isn't set, just use the tab's display title. + if (!mShowUrl || url == null) { + setTitle(tab.getDisplayTitle()); + return; + } + + url = StringUtils.stripScheme(url); + CharSequence title = StringUtils.stripCommonSubdomains(url); - title = builder; - } - } + String baseDomain = tab.getBaseDomain(); + if (!TextUtils.isEmpty(baseDomain)) { + SpannableStringBuilder builder = new SpannableStringBuilder(title); + int index = title.toString().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); + title = builder; } } - mTitle.setText(title); - mLayout.setContentDescription(title != null ? title : mTitle.getHint()); + setTitle(title); } private void setFavicon(Bitmap image) { if (Tabs.getInstance().getSelectedTab().getState() == Tab.STATE_LOADING) return; if (image != null) { image = Bitmap.createScaledBitmap(image, mFaviconSize, mFaviconSize, false); @@ -1138,18 +1138,17 @@ public class BrowserToolbar implements T public void hide() { mLayout.setVisibility(View.GONE); } public void refresh() { Tab tab = Tabs.getInstance().getSelectedTab(); if (tab != null) { - String url = tab.getURL(); - setTitle(tab.getDisplayTitle()); + updateTitle(); setFavicon(tab.getFavicon()); setProgressVisibility(tab.getState() == Tab.STATE_LOADING); setSecurityMode(tab.getSecurityMode()); setReaderMode(tab.getReaderEnabled()); setShadowVisibility(true); updateBackButton(tab.canDoBack()); updateForwardButton(tab.canDoForward());