mirror of
https://gitlab.winehq.org/wine/wine-gecko.git
synced 2024-09-13 09:24:08 -07:00
Bug 944533 - Factor out title display prefs into separate class (r=margaret)
This commit is contained in:
parent
576f1cb502
commit
dc0ec28480
@ -316,6 +316,7 @@ gbjar.sources += [
|
|||||||
'toolbar/ToolbarDisplayLayout.java',
|
'toolbar/ToolbarDisplayLayout.java',
|
||||||
'toolbar/ToolbarEditLayout.java',
|
'toolbar/ToolbarEditLayout.java',
|
||||||
'toolbar/ToolbarEditText.java',
|
'toolbar/ToolbarEditText.java',
|
||||||
|
'toolbar/ToolbarTitlePrefs.java',
|
||||||
'TouchEventInterceptor.java',
|
'TouchEventInterceptor.java',
|
||||||
'updater/UpdateService.java',
|
'updater/UpdateService.java',
|
||||||
'updater/UpdateServiceHelper.java',
|
'updater/UpdateServiceHelper.java',
|
||||||
|
@ -20,7 +20,6 @@ import org.mozilla.gecko.animation.PropertyAnimator.PropertyAnimationListener;
|
|||||||
import org.mozilla.gecko.animation.ViewHelper;
|
import org.mozilla.gecko.animation.ViewHelper;
|
||||||
import org.mozilla.gecko.menu.GeckoMenu;
|
import org.mozilla.gecko.menu.GeckoMenu;
|
||||||
import org.mozilla.gecko.menu.MenuPopup;
|
import org.mozilla.gecko.menu.MenuPopup;
|
||||||
import org.mozilla.gecko.PrefsHelper;
|
|
||||||
import org.mozilla.gecko.toolbar.ToolbarDisplayLayout.OnStopListener;
|
import org.mozilla.gecko.toolbar.ToolbarDisplayLayout.OnStopListener;
|
||||||
import org.mozilla.gecko.toolbar.ToolbarDisplayLayout.UpdateFlags;
|
import org.mozilla.gecko.toolbar.ToolbarDisplayLayout.UpdateFlags;
|
||||||
import org.mozilla.gecko.util.Clipboard;
|
import org.mozilla.gecko.util.Clipboard;
|
||||||
@ -73,8 +72,6 @@ public class BrowserToolbar extends GeckoRelativeLayout
|
|||||||
GeckoMenu.ActionItemBarPresenter,
|
GeckoMenu.ActionItemBarPresenter,
|
||||||
GeckoEventListener {
|
GeckoEventListener {
|
||||||
private static final String LOGTAG = "GeckoToolbar";
|
private static final String LOGTAG = "GeckoToolbar";
|
||||||
public static final String PREF_TITLEBAR_MODE = "browser.chrome.titlebarMode";
|
|
||||||
public static final String PREF_TRIM_URLS = "browser.urlbar.trimURLs";
|
|
||||||
|
|
||||||
public interface OnActivateListener {
|
public interface OnActivateListener {
|
||||||
public void onActivate();
|
public void onActivate();
|
||||||
@ -137,6 +134,8 @@ public class BrowserToolbar extends GeckoRelativeLayout
|
|||||||
private int mUrlBarViewOffset;
|
private int mUrlBarViewOffset;
|
||||||
private int mDefaultForwardMargin;
|
private int mDefaultForwardMargin;
|
||||||
|
|
||||||
|
private ToolbarTitlePrefs mTitlePrefs;
|
||||||
|
|
||||||
private static final Interpolator sButtonsInterpolator = new AccelerateInterpolator();
|
private static final Interpolator sButtonsInterpolator = new AccelerateInterpolator();
|
||||||
|
|
||||||
private static final int FORWARD_ANIMATION_DURATION = 450;
|
private static final int FORWARD_ANIMATION_DURATION = 450;
|
||||||
@ -147,11 +146,6 @@ public class BrowserToolbar extends GeckoRelativeLayout
|
|||||||
|
|
||||||
private final LightweightTheme mTheme;
|
private final LightweightTheme mTheme;
|
||||||
|
|
||||||
private boolean mShowUrl;
|
|
||||||
private boolean mTrimURLs;
|
|
||||||
|
|
||||||
private Integer mPrefObserverId;
|
|
||||||
|
|
||||||
public BrowserToolbar(Context context) {
|
public BrowserToolbar(Context context) {
|
||||||
this(context, null);
|
this(context, null);
|
||||||
}
|
}
|
||||||
@ -168,58 +162,9 @@ public class BrowserToolbar extends GeckoRelativeLayout
|
|||||||
|
|
||||||
Tabs.registerOnTabsChangedListener(this);
|
Tabs.registerOnTabsChangedListener(this);
|
||||||
mSwitchingTabs = true;
|
mSwitchingTabs = true;
|
||||||
|
|
||||||
mAnimatingEntry = false;
|
mAnimatingEntry = false;
|
||||||
mShowUrl = false;
|
|
||||||
mTrimURLs = true;
|
|
||||||
|
|
||||||
final String[] prefs = {
|
mTitlePrefs = new ToolbarTitlePrefs();
|
||||||
PREF_TITLEBAR_MODE,
|
|
||||||
PREF_TRIM_URLS
|
|
||||||
};
|
|
||||||
// listen to the title bar pref.
|
|
||||||
mPrefObserverId = PrefsHelper.getPrefs(prefs, new PrefsHelper.PrefHandlerBase() {
|
|
||||||
@Override
|
|
||||||
public void prefValue(String pref, String str) {
|
|
||||||
// Handles PREF_TITLEBAR_MODE, which is always a string.
|
|
||||||
int value = Integer.parseInt(str);
|
|
||||||
boolean shouldShowUrl = (value == 1);
|
|
||||||
|
|
||||||
if (shouldShowUrl == mShowUrl) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
mShowUrl = shouldShowUrl;
|
|
||||||
|
|
||||||
triggerTitleUpdate();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void prefValue(String pref, boolean value) {
|
|
||||||
// Handles PREF_TRIM_URLS, which should usually be a boolean.
|
|
||||||
if (value == mTrimURLs) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
mTrimURLs = value;
|
|
||||||
|
|
||||||
triggerTitleUpdate();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean isObserver() {
|
|
||||||
// We want to be notified of changes to be able to switch mode
|
|
||||||
// without restarting.
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
private void triggerTitleUpdate() {
|
|
||||||
ThreadUtils.postToUiThread(new Runnable() {
|
|
||||||
@Override
|
|
||||||
public void run() {
|
|
||||||
updateTitle();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
Resources res = getResources();
|
Resources res = getResources();
|
||||||
mUrlColor = new ForegroundColorSpan(res.getColor(R.color.url_bar_urltext));
|
mUrlColor = new ForegroundColorSpan(res.getColor(R.color.url_bar_urltext));
|
||||||
@ -715,7 +660,8 @@ public class BrowserToolbar extends GeckoRelativeLayout
|
|||||||
setContentDescription(contentDescription);
|
setContentDescription(contentDescription);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Sets the toolbar title according to the selected tab, obeying the mShowUrl preference.
|
// Sets the toolbar title according to the selected tab, obeying the
|
||||||
|
// ToolbarTitlePrefs.shouldShowUrl() preference.
|
||||||
private void updateTitle() {
|
private void updateTitle() {
|
||||||
final Tab tab = Tabs.getInstance().getSelectedTab();
|
final Tab tab = Tabs.getInstance().getSelectedTab();
|
||||||
// Keep the title unchanged if there's no selected tab, or if the tab is entering reader mode.
|
// Keep the title unchanged if there's no selected tab, or if the tab is entering reader mode.
|
||||||
@ -745,13 +691,13 @@ public class BrowserToolbar extends GeckoRelativeLayout
|
|||||||
}
|
}
|
||||||
|
|
||||||
// If the pref to show the URL isn't set, just use the tab's display title.
|
// If the pref to show the URL isn't set, just use the tab's display title.
|
||||||
if (!mShowUrl || url == null) {
|
if (!mTitlePrefs.shouldShowUrl() || url == null) {
|
||||||
setTitle(tab.getDisplayTitle());
|
setTitle(tab.getDisplayTitle());
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
CharSequence title = url;
|
CharSequence title = url;
|
||||||
if (mTrimURLs) {
|
if (mTitlePrefs.shouldTrimUrls()) {
|
||||||
title = StringUtils.stripCommonSubdomains(StringUtils.stripScheme(url));
|
title = StringUtils.stripCommonSubdomains(StringUtils.stripScheme(url));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1332,10 +1278,7 @@ public class BrowserToolbar extends GeckoRelativeLayout
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void onDestroy() {
|
public void onDestroy() {
|
||||||
if (mPrefObserverId != null) {
|
mTitlePrefs.close();
|
||||||
PrefsHelper.removeObserver(mPrefObserverId);
|
|
||||||
mPrefObserverId = null;
|
|
||||||
}
|
|
||||||
Tabs.unregisterOnTabsChangedListener(this);
|
Tabs.unregisterOnTabsChangedListener(this);
|
||||||
|
|
||||||
unregisterEventListener("Reader:Click");
|
unregisterEventListener("Reader:Click");
|
||||||
|
99
mobile/android/base/toolbar/ToolbarTitlePrefs.java
Normal file
99
mobile/android/base/toolbar/ToolbarTitlePrefs.java
Normal file
@ -0,0 +1,99 @@
|
|||||||
|
/* -*- Mode: Java; c-basic-offset: 4; tab-width: 20; indent-tabs-mode: nil; -*-
|
||||||
|
* This Source Code Form is subject to the terms of the Mozilla Public
|
||||||
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||||
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||||
|
|
||||||
|
package org.mozilla.gecko.toolbar;
|
||||||
|
|
||||||
|
import org.mozilla.gecko.PrefsHelper;
|
||||||
|
import org.mozilla.gecko.Tab;
|
||||||
|
import org.mozilla.gecko.Tabs;
|
||||||
|
import org.mozilla.gecko.util.ThreadUtils;
|
||||||
|
|
||||||
|
class ToolbarTitlePrefs {
|
||||||
|
public static final String PREF_TITLEBAR_MODE = "browser.chrome.titlebarMode";
|
||||||
|
public static final String PREF_TRIM_URLS = "browser.urlbar.trimURLs";
|
||||||
|
|
||||||
|
interface OnChangeListener {
|
||||||
|
public void onChange();
|
||||||
|
}
|
||||||
|
|
||||||
|
final String[] prefs = {
|
||||||
|
PREF_TITLEBAR_MODE,
|
||||||
|
PREF_TRIM_URLS
|
||||||
|
};
|
||||||
|
|
||||||
|
private boolean mShowUrl;
|
||||||
|
private boolean mTrimUrls;
|
||||||
|
|
||||||
|
private Integer mPrefObserverId;
|
||||||
|
|
||||||
|
ToolbarTitlePrefs() {
|
||||||
|
mShowUrl = false;
|
||||||
|
mTrimUrls = true;
|
||||||
|
|
||||||
|
mPrefObserverId = PrefsHelper.getPrefs(prefs, new TitlePrefsHandler());
|
||||||
|
}
|
||||||
|
|
||||||
|
boolean shouldShowUrl() {
|
||||||
|
return mShowUrl;
|
||||||
|
}
|
||||||
|
|
||||||
|
boolean shouldTrimUrls() {
|
||||||
|
return mTrimUrls;
|
||||||
|
}
|
||||||
|
|
||||||
|
void close() {
|
||||||
|
if (mPrefObserverId != null) {
|
||||||
|
PrefsHelper.removeObserver(mPrefObserverId);
|
||||||
|
mPrefObserverId = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private class TitlePrefsHandler extends PrefsHelper.PrefHandlerBase {
|
||||||
|
@Override
|
||||||
|
public void prefValue(String pref, String str) {
|
||||||
|
// Handles PREF_TITLEBAR_MODE, which is always a string.
|
||||||
|
int value = Integer.parseInt(str);
|
||||||
|
boolean shouldShowUrl = (value == 1);
|
||||||
|
|
||||||
|
if (shouldShowUrl == mShowUrl) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
mShowUrl = shouldShowUrl;
|
||||||
|
|
||||||
|
triggerChangeListener();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void prefValue(String pref, boolean value) {
|
||||||
|
// Handles PREF_TRIM_URLS, which should usually be a boolean.
|
||||||
|
if (value == mTrimUrls) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
mTrimUrls = value;
|
||||||
|
|
||||||
|
triggerChangeListener();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isObserver() {
|
||||||
|
// We want to be notified of changes to be able to switch mode
|
||||||
|
// without restarting.
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void triggerChangeListener() {
|
||||||
|
ThreadUtils.postToUiThread(new Runnable() {
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
final Tabs tabs = Tabs.getInstance();
|
||||||
|
final Tab tab = tabs.getSelectedTab();
|
||||||
|
if (tab != null) {
|
||||||
|
tabs.notifyListeners(tab, Tabs.TabEvents.TITLE);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user