зеркало из https://github.com/mozilla/pjs.git
Bug 463459 - Use a separate pref instead of empty restrict/match values to specify defaults. r=dietrich, a1.9.1=beltzner
This commit is contained in:
Родитель
97c1f90054
Коммит
89229bc7e3
|
@ -244,6 +244,14 @@ pref("browser.urlbar.restrict.tag", "+");
|
|||
pref("browser.urlbar.match.title", "#");
|
||||
pref("browser.urlbar.match.url", "@");
|
||||
|
||||
// The default behavior for the urlbar can be configured to use any combination
|
||||
// of the restrict or match filters with each additional filter restricting
|
||||
// more (intersection). Add the following values to set the behavior as the
|
||||
// default: 1: history, 2: bookmark, 4: tag, 8: title, 16: url
|
||||
// E.g., 0 = show all results (no filtering), 1 = only visited pages in history,
|
||||
// 2 = only bookmarks, 3 = visited bookmarks, 1+16 = history matching in the url
|
||||
pref("browser.urlbar.default.behavior", 0);
|
||||
|
||||
// Number of milliseconds to wait for the http headers (and thus
|
||||
// the Content-Disposition filename) before giving up and falling back to
|
||||
// picking a filename without that info in hand so that the user sees some
|
||||
|
|
|
@ -124,6 +124,7 @@
|
|||
#define PREF_AUTOCOMPLETE_FILTER_JAVASCRIPT "urlbar.filter.javascript"
|
||||
#define PREF_AUTOCOMPLETE_ENABLED "urlbar.autocomplete.enabled"
|
||||
#define PREF_AUTOCOMPLETE_MAX_RICH_RESULTS "urlbar.maxRichResults"
|
||||
#define PREF_AUTOCOMPLETE_DEFAULT_BEHAVIOR "urlbar.default.behavior"
|
||||
#define PREF_AUTOCOMPLETE_RESTRICT_HISTORY "urlbar.restrict.history"
|
||||
#define PREF_AUTOCOMPLETE_RESTRICT_BOOKMARK "urlbar.restrict.bookmark"
|
||||
#define PREF_AUTOCOMPLETE_RESTRICT_TAG "urlbar.restrict.tag"
|
||||
|
@ -320,6 +321,12 @@ const PRInt32 nsNavHistory::kAutoCompleteIndex_BookmarkTitle = 4;
|
|||
const PRInt32 nsNavHistory::kAutoCompleteIndex_Tags = 5;
|
||||
const PRInt32 nsNavHistory::kAutoCompleteIndex_VisitCount = 6;
|
||||
|
||||
const PRInt32 nsNavHistory::kAutoCompleteBehaviorHistory = 1 << 0;
|
||||
const PRInt32 nsNavHistory::kAutoCompleteBehaviorBookmark = 1 << 1;
|
||||
const PRInt32 nsNavHistory::kAutoCompleteBehaviorTag = 1 << 2;
|
||||
const PRInt32 nsNavHistory::kAutoCompleteBehaviorTitle = 1 << 3;
|
||||
const PRInt32 nsNavHistory::kAutoCompleteBehaviorUrl = 1 << 4;
|
||||
|
||||
static const char* gQuitApplicationMessage = "quit-application";
|
||||
static const char* gXpcomShutdown = "xpcom-shutdown";
|
||||
static const char* gAutoCompleteFeedback = "autocomplete-will-enter-text";
|
||||
|
@ -372,11 +379,8 @@ nsNavHistory::nsNavHistory() : mBatchLevel(0),
|
|||
mAutoCompleteMatchUrl(NS_LITERAL_STRING("@")),
|
||||
mAutoCompleteSearchChunkSize(100),
|
||||
mAutoCompleteSearchTimeout(100),
|
||||
mRestrictHistory(PR_FALSE),
|
||||
mRestrictBookmark(PR_FALSE),
|
||||
mRestrictTag(PR_FALSE),
|
||||
mMatchTitle(PR_FALSE),
|
||||
mMatchUrl(PR_FALSE),
|
||||
mAutoCompleteDefaultBehavior(0),
|
||||
mAutoCompleteCurrentBehavior(0),
|
||||
mPreviousChunkOffset(-1),
|
||||
mAutoCompleteFinishedSearch(PR_FALSE),
|
||||
mExpireDaysMin(0),
|
||||
|
@ -502,6 +506,7 @@ nsNavHistory::Init()
|
|||
pbi->AddObserver(PREF_AUTOCOMPLETE_SEARCH_SOURCES, this, PR_FALSE);
|
||||
pbi->AddObserver(PREF_AUTOCOMPLETE_FILTER_JAVASCRIPT, this, PR_FALSE);
|
||||
pbi->AddObserver(PREF_AUTOCOMPLETE_MAX_RICH_RESULTS, this, PR_FALSE);
|
||||
pbi->AddObserver(PREF_AUTOCOMPLETE_DEFAULT_BEHAVIOR, this, PR_FALSE);
|
||||
pbi->AddObserver(PREF_AUTOCOMPLETE_RESTRICT_HISTORY, this, PR_FALSE);
|
||||
pbi->AddObserver(PREF_AUTOCOMPLETE_RESTRICT_BOOKMARK, this, PR_FALSE);
|
||||
pbi->AddObserver(PREF_AUTOCOMPLETE_RESTRICT_TAG, this, PR_FALSE);
|
||||
|
@ -2068,6 +2073,8 @@ nsNavHistory::LoadPrefs(PRBool aInitializing)
|
|||
&mAutoCompleteSearchChunkSize);
|
||||
mPrefBranch->GetIntPref(PREF_AUTOCOMPLETE_SEARCH_TIMEOUT,
|
||||
&mAutoCompleteSearchTimeout);
|
||||
mPrefBranch->GetIntPref(PREF_AUTOCOMPLETE_DEFAULT_BEHAVIOR,
|
||||
&mAutoCompleteDefaultBehavior);
|
||||
nsXPIDLCString prefStr;
|
||||
mPrefBranch->GetCharPref(PREF_AUTOCOMPLETE_RESTRICT_HISTORY,
|
||||
getter_Copies(prefStr));
|
||||
|
|
|
@ -737,11 +737,14 @@ protected:
|
|||
PRInt32 mAutoCompleteSearchTimeout;
|
||||
nsCOMPtr<nsITimer> mAutoCompleteTimer;
|
||||
|
||||
PRBool mRestrictHistory;
|
||||
PRBool mRestrictBookmark;
|
||||
PRBool mRestrictTag;
|
||||
PRBool mMatchTitle;
|
||||
PRBool mMatchUrl;
|
||||
static const PRInt32 kAutoCompleteBehaviorHistory;
|
||||
static const PRInt32 kAutoCompleteBehaviorBookmark;
|
||||
static const PRInt32 kAutoCompleteBehaviorTag;
|
||||
static const PRInt32 kAutoCompleteBehaviorTitle;
|
||||
static const PRInt32 kAutoCompleteBehaviorUrl;
|
||||
|
||||
PRInt32 mAutoCompleteDefaultBehavior; // kAutoCompleteBehavior* bitmap
|
||||
PRInt32 mAutoCompleteCurrentBehavior; // kAutoCompleteBehavior* bitmap
|
||||
|
||||
// Original search string for case-sensitive usage
|
||||
nsString mOrigSearchString;
|
||||
|
|
|
@ -83,6 +83,12 @@
|
|||
#define NS_AUTOCOMPLETESIMPLERESULT_CONTRACTID \
|
||||
"@mozilla.org/autocomplete/simple-result;1"
|
||||
|
||||
// Helpers to get and set fields in the mAutoCompleteCurrentBehavior bitmap
|
||||
#define GET_BEHAVIOR(aBitName) \
|
||||
(mAutoCompleteCurrentBehavior & kAutoCompleteBehavior##aBitName)
|
||||
#define SET_BEHAVIOR(aBitName) \
|
||||
mAutoCompleteCurrentBehavior |= kAutoCompleteBehavior##aBitName
|
||||
|
||||
// Helper to get a particular column with a desired name from the bookmark and
|
||||
// tags table based on if we want to include tags or not
|
||||
#define SQL_STR_FRAGMENT_GET_BOOK_TAG(name, column, comparison, getMostRecent) \
|
||||
|
@ -792,18 +798,14 @@ nsNavHistory::AddSearchToken(nsAutoString &aToken)
|
|||
void
|
||||
nsNavHistory::ProcessTokensForSpecialSearch()
|
||||
{
|
||||
// If any of the special searches are empty, automatically use it
|
||||
mRestrictHistory = mAutoCompleteRestrictHistory.IsEmpty();
|
||||
mRestrictBookmark = mAutoCompleteRestrictBookmark.IsEmpty();
|
||||
mRestrictTag = mAutoCompleteRestrictTag.IsEmpty();
|
||||
mMatchTitle = mAutoCompleteMatchTitle.IsEmpty();
|
||||
mMatchUrl = mAutoCompleteMatchUrl.IsEmpty();
|
||||
// Start with the default behavior
|
||||
mAutoCompleteCurrentBehavior = mAutoCompleteDefaultBehavior;
|
||||
|
||||
// If we're searching only one of history or bookmark, we can use filters
|
||||
if (mAutoCompleteSearchSources == SEARCH_HISTORY)
|
||||
mRestrictHistory = PR_TRUE;
|
||||
SET_BEHAVIOR(History);
|
||||
else if (mAutoCompleteSearchSources == SEARCH_BOOKMARK)
|
||||
mRestrictBookmark = PR_TRUE;
|
||||
SET_BEHAVIOR(Bookmark);
|
||||
// SEARCH_BOTH doesn't require any filtering
|
||||
|
||||
// Determine which special searches to apply
|
||||
|
@ -812,15 +814,15 @@ nsNavHistory::ProcessTokensForSpecialSearch()
|
|||
const nsString *token = mCurrentSearchTokens.StringAt(i);
|
||||
|
||||
if (token->Equals(mAutoCompleteRestrictHistory))
|
||||
mRestrictHistory = PR_TRUE;
|
||||
SET_BEHAVIOR(History);
|
||||
else if (token->Equals(mAutoCompleteRestrictBookmark))
|
||||
mRestrictBookmark = PR_TRUE;
|
||||
SET_BEHAVIOR(Bookmark);
|
||||
else if (token->Equals(mAutoCompleteRestrictTag))
|
||||
mRestrictTag = PR_TRUE;
|
||||
SET_BEHAVIOR(Tag);
|
||||
else if (token->Equals(mAutoCompleteMatchTitle))
|
||||
mMatchTitle = PR_TRUE;
|
||||
SET_BEHAVIOR(Title);
|
||||
else if (token->Equals(mAutoCompleteMatchUrl))
|
||||
mMatchUrl = PR_TRUE;
|
||||
SET_BEHAVIOR(Url);
|
||||
else
|
||||
needToRemove = PR_FALSE;
|
||||
|
||||
|
@ -831,9 +833,9 @@ nsNavHistory::ProcessTokensForSpecialSearch()
|
|||
|
||||
// We can use optimized queries for restricts, so check for the most
|
||||
// restrictive query first
|
||||
mDBCurrentQuery = mRestrictTag ? GetDBAutoCompleteTagsQuery() :
|
||||
mRestrictBookmark ? GetDBAutoCompleteStarQuery() :
|
||||
mRestrictHistory ? GetDBAutoCompleteHistoryQuery() :
|
||||
mDBCurrentQuery = GET_BEHAVIOR(Tag) ? GetDBAutoCompleteTagsQuery() :
|
||||
GET_BEHAVIOR(Bookmark) ? GetDBAutoCompleteStarQuery() :
|
||||
GET_BEHAVIOR(History) ? GetDBAutoCompleteHistoryQuery() :
|
||||
static_cast<mozIStorageStatement *>(mDBAutoCompleteQuery);
|
||||
}
|
||||
|
||||
|
@ -1026,9 +1028,9 @@ nsNavHistory::AutoCompleteProcessSearch(mozIStorageStatement* aQuery,
|
|||
// only history items, only bookmarks, only tags. If a given restrict
|
||||
// is active, make sure a corresponding condition is *not* true. If
|
||||
// any are violated, matchAll will be false.
|
||||
PRBool matchAll = !((mRestrictHistory && visitCount == 0) ||
|
||||
(mRestrictBookmark && !parentId) ||
|
||||
(mRestrictTag && entryTags.IsEmpty()));
|
||||
PRBool matchAll = !((GET_BEHAVIOR(History) && visitCount == 0) ||
|
||||
(GET_BEHAVIOR(Bookmark) && !parentId) ||
|
||||
(GET_BEHAVIOR(Tag) && entryTags.IsEmpty()));
|
||||
|
||||
// Unescape the url to search for unescaped terms
|
||||
nsString entryURL = FixupURIText(escapedEntryURL);
|
||||
|
@ -1045,14 +1047,14 @@ nsNavHistory::AutoCompleteProcessSearch(mozIStorageStatement* aQuery,
|
|||
|
||||
// Make sure we match something in the title or tags if we have to
|
||||
matchAll = matchTags || matchTitle;
|
||||
if (mMatchTitle && !matchAll)
|
||||
if (GET_BEHAVIOR(Title) && !matchAll)
|
||||
break;
|
||||
|
||||
// Check if the url matches the search term
|
||||
PRBool matchUrl = (*tokenMatchesTarget)(*token, entryURL);
|
||||
// If we don't match the url when we have to, reset matchAll to
|
||||
// false; otherwise keep track that we did match the current search
|
||||
if (mMatchUrl && !matchUrl)
|
||||
if (GET_BEHAVIOR(Url) && !matchUrl)
|
||||
matchAll = PR_FALSE;
|
||||
else
|
||||
matchAll |= matchUrl;
|
||||
|
|
|
@ -135,15 +135,21 @@ let gTests = [
|
|||
["20: foo @ + -> in url, is tag",
|
||||
"foo @ +", [10,11]],
|
||||
|
||||
// Test default usage by making the special search empty
|
||||
// Test default usage by setting certain bits of default.behavior to 1
|
||||
["21: foo -> default history",
|
||||
"foo", [1,2,3,5,10], function() makeDefault("restrict.history")],
|
||||
"foo", [1,2,3,5,10], function() makeDefault(1)],
|
||||
["22: foo -> default history, is star",
|
||||
"foo", [5,10], function() makeDefault("restrict.bookmark")],
|
||||
"foo", [5,10], function() makeDefault(3)],
|
||||
["23: foo -> default history, is star, in url",
|
||||
"foo", [10], function() makeDefault("match.url")],
|
||||
"foo", [10], function() makeDefault(19)],
|
||||
|
||||
// Change the default to be less restrictive to make sure we find more
|
||||
["24: foo -> default is star, in url",
|
||||
"foo", [6,7,10,11], function() makeDefault(18)],
|
||||
["25: foo -> default in url",
|
||||
"foo", [2,3,6,7,10,11], function() makeDefault(16)],
|
||||
];
|
||||
|
||||
function makeDefault(pref) {
|
||||
prefs.setCharPref("browser.urlbar." + pref, "");
|
||||
function makeDefault(aDefault) {
|
||||
prefs.setIntPref("browser.urlbar.default.behavior", aDefault);
|
||||
}
|
||||
|
|
Загрузка…
Ссылка в новой задаче