[haiku-webkit-commits] r268 - in webkit/trunk: WebCore WebKit/haiku/WebPositive WebKit/haiku/WebPositive/autocompletion

  • From: webkit@xxxxxxxxxxxxxxx
  • To: haiku-webkit-commits@xxxxxxxxxxxxx
  • Date: Tue, 02 Mar 2010 18:40:50 +0000

Author: stippi
Date: Tue Mar  2 18:40:50 2010
New Revision: 268
URL: http://mmlr.dyndns.org/changeset/268

Log:
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).

Modified:
   webkit/trunk/WebCore/Jamfile
   webkit/trunk/WebKit/haiku/WebPositive/BrowserWindow.cpp
   webkit/trunk/WebKit/haiku/WebPositive/BrowserWindow.h
   webkit/trunk/WebKit/haiku/WebPositive/autocompletion/AutoCompleter.cpp
   webkit/trunk/WebKit/haiku/WebPositive/autocompletion/AutoCompleter.h
   
webkit/trunk/WebKit/haiku/WebPositive/autocompletion/AutoCompleterDefaultImpl.cpp
   
webkit/trunk/WebKit/haiku/WebPositive/autocompletion/AutoCompleterDefaultImpl.h
   webkit/trunk/WebKit/haiku/WebPositive/autocompletion/TextControlCompleter.cpp
   webkit/trunk/WebKit/haiku/WebPositive/autocompletion/TextControlCompleter.h

Modified: webkit/trunk/WebCore/Jamfile
==============================================================================
--- webkit/trunk/WebCore/Jamfile        Tue Mar  2 18:37:48 2010        (r267)
+++ webkit/trunk/WebCore/Jamfile        Tue Mar  2 18:40:50 2010        (r268)
@@ -2,8 +2,8 @@
 
 local defines = [ FDefines BUILDING_HAIKU__=1
     WTF_USE_PTHREADS=1 HAVE_POSIX_MEMALIGN=1 HAVE_SYS_TIME_H=1 
ENABLE_DOM_STORAGE=1
-    ENABLE_SVG=1 ENABLE_SVG_ANIMATION=1 ENABLE_SVG_FONTS=1 
ENABLE_SVG_FOREIGN_OBJECT=1 ENABLE_SVG_USE=1
-    TEXT_CARET=1 ] ;
+    ENABLE_SVG=1 ENABLE_SVG_ANIMATION=1 ENABLE_SVG_FONTS=1 
ENABLE_SVG_FOREIGN_OBJECT=1
+    ENABLE_SVG_USE=1 ] ;
 
 # To turn off debugging symbols export NDEBUG=1 in the environment
 SubDirC++Flags $(defines) ;

Modified: webkit/trunk/WebKit/haiku/WebPositive/BrowserWindow.cpp
==============================================================================
--- webkit/trunk/WebKit/haiku/WebPositive/BrowserWindow.cpp     Tue Mar  2 
18:37:48 2010        (r267)
+++ webkit/trunk/WebKit/haiku/WebPositive/BrowserWindow.cpp     Tue Mar  2 
18:40:50 2010        (r268)
@@ -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 @@
 }
 
 
+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 @@
 
                fURLTextControl->MakeFocus(true);
 
+               fURLAutoCompleter = new TextControlCompleter(fURLTextControl,
+                       new BrowsingHistoryChoiceModel(),
+                       new BrowsingHistoryPatternSelector());
+
                fFindGroup = layoutItemFor(findGroup);
                fTabGroup = layoutItemFor(fTabManager->TabGroup());
        } else {
@@ -236,6 +301,7 @@
                fStopButton = 0;
                fGoButton = 0;
                fURLTextControl = 0;
+               fURLAutoCompleter = 0;
                fStatusText = 0;
                fLoadingProgressBar = 0;
 
@@ -275,6 +341,8 @@
 
 BrowserWindow::~BrowserWindow()
 {
+       delete fURLAutoCompleter;
+       delete fTabManager;
 }
 
 

Modified: webkit/trunk/WebKit/haiku/WebPositive/BrowserWindow.h
==============================================================================
--- webkit/trunk/WebKit/haiku/WebPositive/BrowserWindow.h       Tue Mar  2 
18:37:48 2010        (r267)
+++ webkit/trunk/WebKit/haiku/WebPositive/BrowserWindow.h       Tue Mar  2 
18:40:50 2010        (r268)
@@ -43,6 +43,7 @@
 class BTextControl;
 class IconButton;
 class TabManager;
+class TextControlCompleter;
 class BWebView;
 
 enum ToolbarPolicy {
@@ -125,6 +126,7 @@
                        IconButton*                     fStopButton;
                        BButton*                        fGoButton;
                        BTextControl*           fURLTextControl;
+                       TextControlCompleter* fURLAutoCompleter;
                        BStringView*            fStatusText;
                        BStatusBar*                     fLoadingProgressBar;
                        BLayoutItem*            fFindGroup;

Modified: webkit/trunk/WebKit/haiku/WebPositive/autocompletion/AutoCompleter.cpp
==============================================================================
--- webkit/trunk/WebKit/haiku/WebPositive/autocompletion/AutoCompleter.cpp      
Tue Mar  2 18:37:48 2010        (r267)
+++ webkit/trunk/WebKit/haiku/WebPositive/autocompletion/AutoCompleter.cpp      
Tue Mar  2 18:40:50 2010        (r268)
@@ -148,6 +148,16 @@
 }
 
 
+bool
+BAutoCompleter::IsChoiceSelected() const
+{
+       if (fCompletionStyle)
+               return fCompletionStyle->IsChoiceSelected();
+       else
+               return false;
+}
+
+
 void
 BAutoCompleter::ApplyChoice(bool hideChoices)
 {
@@ -210,3 +220,4 @@
        delete fCompletionStyle;
        fCompletionStyle = style;
 }
+

Modified: webkit/trunk/WebKit/haiku/WebPositive/autocompletion/AutoCompleter.h
==============================================================================
--- webkit/trunk/WebKit/haiku/WebPositive/autocompletion/AutoCompleter.h        
Tue Mar  2 18:37:48 2010        (r267)
+++ webkit/trunk/WebKit/haiku/WebPositive/autocompletion/AutoCompleter.h        
Tue Mar  2 18:40:50 2010        (r268)
@@ -97,6 +97,7 @@
                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 @@
                        bool                            Select(int32 index);
                        bool                            SelectNext(bool wrap = 
false);
                        bool                            SelectPrevious(bool 
wrap = false);
+                       bool                            IsChoiceSelected() 
const;
                
                        void                            ApplyChoice(bool 
hideChoices = true);
                        void                            CancelChoice();

Modified: 
webkit/trunk/WebKit/haiku/WebPositive/autocompletion/AutoCompleterDefaultImpl.cpp
==============================================================================
--- 
webkit/trunk/WebKit/haiku/WebPositive/autocompletion/AutoCompleterDefaultImpl.cpp
   Tue Mar  2 18:37:48 2010        (r267)
+++ 
webkit/trunk/WebKit/haiku/WebPositive/autocompletion/AutoCompleterDefaultImpl.cpp
   Tue Mar  2 18:40:50 2010        (r268)
@@ -96,6 +96,13 @@
 }
 
 
+bool
+BDefaultCompletionStyle::IsChoiceSelected() const
+{
+       return fSelectedIndex >= 0;
+}
+
+
 void
 BDefaultCompletionStyle::ApplyChoice(bool hideChoices)
 {
@@ -112,8 +119,10 @@
        fEditView->SetEditViewState(completedText, 
                fPatternStartPos+choiceStr.Length());
 
-       if (hideChoices)
+       if (hideChoices) {
                fChoiceView->HideChoices();
+               Select(-1);
+       }
 }
 
 

Modified: 
webkit/trunk/WebKit/haiku/WebPositive/autocompletion/AutoCompleterDefaultImpl.h
==============================================================================
--- 
webkit/trunk/WebKit/haiku/WebPositive/autocompletion/AutoCompleterDefaultImpl.h 
    Tue Mar  2 18:37:48 2010        (r267)
+++ 
webkit/trunk/WebKit/haiku/WebPositive/autocompletion/AutoCompleterDefaultImpl.h 
    Tue Mar  2 18:40:50 2010        (r268)
@@ -35,6 +35,7 @@
        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();

Modified: 
webkit/trunk/WebKit/haiku/WebPositive/autocompletion/TextControlCompleter.cpp
==============================================================================
--- 
webkit/trunk/WebKit/haiku/WebPositive/autocompletion/TextControlCompleter.cpp   
    Tue Mar  2 18:37:48 2010        (r267)
+++ 
webkit/trunk/WebKit/haiku/WebPositive/autocompletion/TextControlCompleter.cpp   
    Tue Mar  2 18:40:50 2010        (r268)
@@ -10,6 +10,7 @@
 
 #include <Looper.h>
 #include <TextControl.h>
+#include <stdio.h>
 
 #include "AutoCompleterDefaultImpl.h"
 
@@ -58,7 +59,7 @@
 {
        BRect frame = fTextControl->TextView()->Bounds();
        frame = fTextControl->TextView()->ConvertToScreen(frame);
-       frame.InsetBy(-1, -3);
+       frame.InsetBy(0, -3);
        return frame;
 }
 
@@ -68,14 +69,16 @@
        :
        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 @@
                        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();

Modified: 
webkit/trunk/WebKit/haiku/WebPositive/autocompletion/TextControlCompleter.h
==============================================================================
--- webkit/trunk/WebKit/haiku/WebPositive/autocompletion/TextControlCompleter.h 
Tue Mar  2 18:37:48 2010        (r267)
+++ webkit/trunk/WebKit/haiku/WebPositive/autocompletion/TextControlCompleter.h 
Tue Mar  2 18:40:50 2010        (r268)
@@ -36,6 +36,8 @@
        private:
                                BTextControl*   fTextControl;
        };
+private:
+                       BTextControl*           fTextControl;
 };
 
 #endif // TEXT_CONTROL_COMPLETER_H

Other related posts: