From 0fe64862b7c900e74058496e7fe439ded4a18f3d Mon Sep 17 00:00:00 2001 From: stippi Date: Thu, 4 Mar 2010 19:35:26 +0000 Subject: [PATCH] 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 --- src/apps/webpositive/BrowserWindow.cpp | 51 ++++++++++++++++++++++++-- 1 file changed, 47 insertions(+), 4 deletions(-) diff --git a/src/apps/webpositive/BrowserWindow.cpp b/src/apps/webpositive/BrowserWindow.cpp index fc01924a22..46b04fed51 100644 --- a/src/apps/webpositive/BrowserWindow.cpp +++ b/src/apps/webpositive/BrowserWindow.cpp @@ -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 { virtual void FetchChoicesFor(const BString& pattern) { @@ -110,6 +138,7 @@ class BrowsingHistoryChoiceModel : public BAutoCompleter::ChoiceModel { return; BString lastBaseURL; + int32 priority = INT_MAX; count = history->countItems(); for (int32 i = 0; i < count; i++) { @@ -120,17 +149,20 @@ class BrowsingHistoryChoiceModel : public BAutoCompleter::ChoiceModel { continue; if (lastBaseURL.Length() > 0 && choiceText.FindFirst(lastBaseURL) >= 0) { - continue; - } + priority--; + } else + priority = INT_MAX; int32 baseURLStart = choiceText.FindFirst("://") + 3; int32 baseURLEnd = choiceText.FindFirst("/", baseURLStart + 1); lastBaseURL.SetTo(choiceText.String() + baseURLStart, baseURLEnd - baseURLStart); - fChoices.AddItem(new BAutoCompleter::Choice(choiceText, - choiceText, matchPos, pattern.Length())); + fChoices.AddItem(new URLChoice(choiceText, + choiceText, matchPos, pattern.Length(), priority)); } history->Unlock(); + + fChoices.SortItems(_CompareChoices); } virtual int32 CountChoices() const @@ -144,6 +176,17 @@ class BrowsingHistoryChoiceModel : public BAutoCompleter::ChoiceModel { fChoices.ItemAt(index)); } + static int _CompareChoices(const void* a, const void* b) + { + const URLChoice* aChoice = *reinterpret_cast(a); + const URLChoice* bChoice = *reinterpret_cast(b); + if (*aChoice < *bChoice) + return -1; + else if (*aChoice == *bChoice) + return 0; + return 1; + } + private: BList fChoices; };