Wired everything and improved the TextControlCompleter behavior a bit with
regards to eating the B_RETURN key before we can dispatch in BrowserWindow. So autocompletion for URLs basically works. What's missing is: * Much better grouping of matches. * Fix the delay when the BrowsingHistory is first accessed (lazy loads itself from disk just then, ought to do it in the application thread after startup, which probably makes it unnoticable before the user starts typing a URL). git-svn-id: http://svn.haiku-os.org/webpositive/webkit/trunk@268 94f232f2-1747-11df-bad5-a5bfde151594
This commit is contained in:
committed by
Alexandre Deckner
parent
fd5768c40d
commit
1a52acbc07
@@ -37,6 +37,7 @@
|
||||
#include "BrowserApp.h"
|
||||
#include "BrowsingHistory.h"
|
||||
#include "IconButton.h"
|
||||
#include "TextControlCompleter.h"
|
||||
#include "WebPage.h"
|
||||
#include "WebTabView.h"
|
||||
#include "WebView.h"
|
||||
@@ -93,6 +94,66 @@ layoutItemFor(BView* view)
|
||||
}
|
||||
|
||||
|
||||
class BrowsingHistoryChoiceModel : public BAutoCompleter::ChoiceModel {
|
||||
virtual void FetchChoicesFor(const BString& pattern)
|
||||
{
|
||||
int32 count = CountChoices();
|
||||
for (int32 i = 0; i < count; i++) {
|
||||
delete reinterpret_cast<BAutoCompleter::Choice*>(
|
||||
fChoices.ItemAtFast(i));
|
||||
}
|
||||
fChoices.MakeEmpty();
|
||||
|
||||
// Search through BrowsingHistory for any matches.
|
||||
BrowsingHistory* history = BrowsingHistory::defaultInstance();
|
||||
if (!history->Lock())
|
||||
return;
|
||||
|
||||
count = history->countItems();
|
||||
for (int32 i = 0; i < count; i++) {
|
||||
BrowsingHistoryItem item = history->historyItemAt(i);
|
||||
const BString& choiceText = item.url();
|
||||
int32 matchPos = choiceText.IFindFirst(pattern);
|
||||
if (matchPos < 0)
|
||||
continue;
|
||||
fChoices.AddItem(new BAutoCompleter::Choice(choiceText,
|
||||
choiceText, matchPos, pattern.Length()));
|
||||
}
|
||||
|
||||
history->Unlock();
|
||||
}
|
||||
|
||||
virtual int32 CountChoices() const
|
||||
{
|
||||
return fChoices.CountItems();
|
||||
}
|
||||
|
||||
virtual const BAutoCompleter::Choice* ChoiceAt(int32 index) const
|
||||
{
|
||||
return reinterpret_cast<BAutoCompleter::Choice*>(
|
||||
fChoices.ItemAt(index));
|
||||
}
|
||||
|
||||
private:
|
||||
BList fChoices;
|
||||
};
|
||||
|
||||
|
||||
class BrowsingHistoryPatternSelector : public BAutoCompleter::PatternSelector {
|
||||
virtual void SelectPatternBounds(const BString& text, int32 caretPos,
|
||||
int32* start, int32* length)
|
||||
{
|
||||
if (!start || !length)
|
||||
return;
|
||||
*start = 0;
|
||||
*length = text.Length();
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
// #pragma mark - BrowserWindow
|
||||
|
||||
|
||||
BrowserWindow::BrowserWindow(BRect frame, const BMessenger& downloadListener,
|
||||
ToolbarPolicy toolbarPolicy)
|
||||
: BWebWindow(frame, kApplicationName,
|
||||
@@ -228,6 +289,10 @@ BrowserWindow::BrowserWindow(BRect frame, const BMessenger& downloadListener,
|
||||
|
||||
fURLTextControl->MakeFocus(true);
|
||||
|
||||
fURLAutoCompleter = new TextControlCompleter(fURLTextControl,
|
||||
new BrowsingHistoryChoiceModel(),
|
||||
new BrowsingHistoryPatternSelector());
|
||||
|
||||
fFindGroup = layoutItemFor(findGroup);
|
||||
fTabGroup = layoutItemFor(fTabManager->TabGroup());
|
||||
} else {
|
||||
@@ -236,6 +301,7 @@ BrowserWindow::BrowserWindow(BRect frame, const BMessenger& downloadListener,
|
||||
fStopButton = 0;
|
||||
fGoButton = 0;
|
||||
fURLTextControl = 0;
|
||||
fURLAutoCompleter = 0;
|
||||
fStatusText = 0;
|
||||
fLoadingProgressBar = 0;
|
||||
|
||||
@@ -275,6 +341,8 @@ BrowserWindow::BrowserWindow(BRect frame, const BMessenger& downloadListener,
|
||||
|
||||
BrowserWindow::~BrowserWindow()
|
||||
{
|
||||
delete fURLAutoCompleter;
|
||||
delete fTabManager;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -43,6 +43,7 @@ class BStringView;
|
||||
class BTextControl;
|
||||
class IconButton;
|
||||
class TabManager;
|
||||
class TextControlCompleter;
|
||||
class BWebView;
|
||||
|
||||
enum ToolbarPolicy {
|
||||
@@ -125,6 +126,7 @@ private:
|
||||
IconButton* fStopButton;
|
||||
BButton* fGoButton;
|
||||
BTextControl* fURLTextControl;
|
||||
TextControlCompleter* fURLAutoCompleter;
|
||||
BStringView* fStatusText;
|
||||
BStatusBar* fLoadingProgressBar;
|
||||
BLayoutItem* fFindGroup;
|
||||
|
||||
@@ -148,6 +148,16 @@ BAutoCompleter::SelectPrevious(bool wrap)
|
||||
}
|
||||
|
||||
|
||||
bool
|
||||
BAutoCompleter::IsChoiceSelected() const
|
||||
{
|
||||
if (fCompletionStyle)
|
||||
return fCompletionStyle->IsChoiceSelected();
|
||||
else
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
BAutoCompleter::ApplyChoice(bool hideChoices)
|
||||
{
|
||||
@@ -210,3 +220,4 @@ BAutoCompleter::SetCompletionStyle(CompletionStyle* style)
|
||||
delete fCompletionStyle;
|
||||
fCompletionStyle = style;
|
||||
}
|
||||
|
||||
|
||||
@@ -97,6 +97,7 @@ public:
|
||||
virtual bool Select(int32 index) = 0;
|
||||
virtual bool SelectNext(bool wrap = false) = 0;
|
||||
virtual bool SelectPrevious(bool wrap = false) = 0;
|
||||
virtual bool IsChoiceSelected() const = 0;
|
||||
|
||||
virtual void ApplyChoice(bool hideChoices = true) = 0;
|
||||
virtual void CancelChoice() = 0;
|
||||
@@ -135,6 +136,7 @@ protected:
|
||||
bool Select(int32 index);
|
||||
bool SelectNext(bool wrap = false);
|
||||
bool SelectPrevious(bool wrap = false);
|
||||
bool IsChoiceSelected() const;
|
||||
|
||||
void ApplyChoice(bool hideChoices = true);
|
||||
void CancelChoice();
|
||||
|
||||
@@ -96,6 +96,13 @@ BDefaultCompletionStyle::SelectPrevious(bool wrap)
|
||||
}
|
||||
|
||||
|
||||
bool
|
||||
BDefaultCompletionStyle::IsChoiceSelected() const
|
||||
{
|
||||
return fSelectedIndex >= 0;
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
BDefaultCompletionStyle::ApplyChoice(bool hideChoices)
|
||||
{
|
||||
@@ -112,8 +119,10 @@ BDefaultCompletionStyle::ApplyChoice(bool hideChoices)
|
||||
fEditView->SetEditViewState(completedText,
|
||||
fPatternStartPos+choiceStr.Length());
|
||||
|
||||
if (hideChoices)
|
||||
if (hideChoices) {
|
||||
fChoiceView->HideChoices();
|
||||
Select(-1);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -35,6 +35,7 @@ public:
|
||||
virtual bool Select(int32 index);
|
||||
virtual bool SelectNext(bool wrap = false);
|
||||
virtual bool SelectPrevious(bool wrap = false);
|
||||
virtual bool IsChoiceSelected() const;
|
||||
|
||||
virtual void ApplyChoice(bool hideChoices = true);
|
||||
virtual void CancelChoice();
|
||||
|
||||
@@ -10,6 +10,7 @@
|
||||
|
||||
#include <Looper.h>
|
||||
#include <TextControl.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#include "AutoCompleterDefaultImpl.h"
|
||||
|
||||
@@ -58,7 +59,7 @@ TextControlCompleter::TextControlWrapper::GetAdjustmentFrame()
|
||||
{
|
||||
BRect frame = fTextControl->TextView()->Bounds();
|
||||
frame = fTextControl->TextView()->ConvertToScreen(frame);
|
||||
frame.InsetBy(-1, -3);
|
||||
frame.InsetBy(0, -3);
|
||||
return frame;
|
||||
}
|
||||
|
||||
@@ -68,14 +69,16 @@ TextControlCompleter::TextControlCompleter(BTextControl* textControl,
|
||||
:
|
||||
BAutoCompleter(new TextControlWrapper(textControl), model,
|
||||
new BDefaultChoiceView(), patternSelector),
|
||||
BMessageFilter(B_KEY_DOWN)
|
||||
BMessageFilter(B_KEY_DOWN),
|
||||
fTextControl(textControl)
|
||||
{
|
||||
textControl->TextView()->AddFilter(this);
|
||||
fTextControl->TextView()->AddFilter(this);
|
||||
}
|
||||
|
||||
|
||||
TextControlCompleter::~TextControlCompleter()
|
||||
{
|
||||
fTextControl->TextView()->RemoveFilter(this);
|
||||
}
|
||||
|
||||
|
||||
@@ -99,9 +102,12 @@ TextControlCompleter::Filter(BMessage* message, BHandler** target)
|
||||
CancelChoice();
|
||||
return B_SKIP_MESSAGE;
|
||||
case B_RETURN:
|
||||
ApplyChoice();
|
||||
EditViewStateChanged();
|
||||
return B_SKIP_MESSAGE;
|
||||
if (IsChoiceSelected()) {
|
||||
ApplyChoice();
|
||||
EditViewStateChanged();
|
||||
} else
|
||||
CancelChoice();
|
||||
return B_DISPATCH_MESSAGE;
|
||||
case B_TAB: {
|
||||
// make sure that the choices-view is closed when tabbing out:
|
||||
CancelChoice();
|
||||
|
||||
@@ -36,6 +36,8 @@ private:
|
||||
private:
|
||||
BTextControl* fTextControl;
|
||||
};
|
||||
private:
|
||||
BTextControl* fTextControl;
|
||||
};
|
||||
|
||||
#endif // TEXT_CONTROL_COMPLETER_H
|
||||
|
||||
Reference in New Issue
Block a user