Changed how auto-completion fills the choices. It doesn't remove choices with the
same base URL anymore, but simply uses a lower priority for every less recent choice with the same base URL, and then sorts the result list after fetching. Previously, you would only get one choice for a given base URL, and that one was more likely a longer URL, since it was visited more recently than the start page of the respective site. git-svn-id: http://svn.haiku-os.org/webpositive/webkit/trunk@286 94f232f2-1747-11df-bad5-a5bfde151594
This commit is contained in:
committed by
Alexandre Deckner
parent
5c2095b4b0
commit
0fe64862b7
@@ -94,6 +94,34 @@ layoutItemFor(BView* view)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
class URLChoice : public BAutoCompleter::Choice {
|
||||||
|
public:
|
||||||
|
URLChoice(const BString& choiceText, const BString& displayText,
|
||||||
|
int32 matchPos, int32 matchLen, int32 priority)
|
||||||
|
:
|
||||||
|
BAutoCompleter::Choice(choiceText, displayText, matchPos, matchLen),
|
||||||
|
fPriority(priority)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
bool operator<(const URLChoice& other) const
|
||||||
|
{
|
||||||
|
if (fPriority > other.fPriority)
|
||||||
|
return true;
|
||||||
|
return DisplayText() < other.DisplayText();
|
||||||
|
}
|
||||||
|
|
||||||
|
bool operator==(const URLChoice& other) const
|
||||||
|
{
|
||||||
|
return fPriority == other.fPriority
|
||||||
|
&& DisplayText() < other.DisplayText();
|
||||||
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
int32 fPriority;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
class BrowsingHistoryChoiceModel : public BAutoCompleter::ChoiceModel {
|
class BrowsingHistoryChoiceModel : public BAutoCompleter::ChoiceModel {
|
||||||
virtual void FetchChoicesFor(const BString& pattern)
|
virtual void FetchChoicesFor(const BString& pattern)
|
||||||
{
|
{
|
||||||
@@ -110,6 +138,7 @@ class BrowsingHistoryChoiceModel : public BAutoCompleter::ChoiceModel {
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
BString lastBaseURL;
|
BString lastBaseURL;
|
||||||
|
int32 priority = INT_MAX;
|
||||||
|
|
||||||
count = history->countItems();
|
count = history->countItems();
|
||||||
for (int32 i = 0; i < count; i++) {
|
for (int32 i = 0; i < count; i++) {
|
||||||
@@ -120,17 +149,20 @@ class BrowsingHistoryChoiceModel : public BAutoCompleter::ChoiceModel {
|
|||||||
continue;
|
continue;
|
||||||
if (lastBaseURL.Length() > 0
|
if (lastBaseURL.Length() > 0
|
||||||
&& choiceText.FindFirst(lastBaseURL) >= 0) {
|
&& choiceText.FindFirst(lastBaseURL) >= 0) {
|
||||||
continue;
|
priority--;
|
||||||
}
|
} else
|
||||||
|
priority = INT_MAX;
|
||||||
int32 baseURLStart = choiceText.FindFirst("://") + 3;
|
int32 baseURLStart = choiceText.FindFirst("://") + 3;
|
||||||
int32 baseURLEnd = choiceText.FindFirst("/", baseURLStart + 1);
|
int32 baseURLEnd = choiceText.FindFirst("/", baseURLStart + 1);
|
||||||
lastBaseURL.SetTo(choiceText.String() + baseURLStart,
|
lastBaseURL.SetTo(choiceText.String() + baseURLStart,
|
||||||
baseURLEnd - baseURLStart);
|
baseURLEnd - baseURLStart);
|
||||||
fChoices.AddItem(new BAutoCompleter::Choice(choiceText,
|
fChoices.AddItem(new URLChoice(choiceText,
|
||||||
choiceText, matchPos, pattern.Length()));
|
choiceText, matchPos, pattern.Length(), priority));
|
||||||
}
|
}
|
||||||
|
|
||||||
history->Unlock();
|
history->Unlock();
|
||||||
|
|
||||||
|
fChoices.SortItems(_CompareChoices);
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual int32 CountChoices() const
|
virtual int32 CountChoices() const
|
||||||
@@ -144,6 +176,17 @@ class BrowsingHistoryChoiceModel : public BAutoCompleter::ChoiceModel {
|
|||||||
fChoices.ItemAt(index));
|
fChoices.ItemAt(index));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int _CompareChoices(const void* a, const void* b)
|
||||||
|
{
|
||||||
|
const URLChoice* aChoice = *reinterpret_cast<const URLChoice* const *>(a);
|
||||||
|
const URLChoice* bChoice = *reinterpret_cast<const URLChoice* const *>(b);
|
||||||
|
if (*aChoice < *bChoice)
|
||||||
|
return -1;
|
||||||
|
else if (*aChoice == *bChoice)
|
||||||
|
return 0;
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
BList fChoices;
|
BList fChoices;
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user