[haiku-webkit-commits] r498 - webkit/trunk/WebKit/haiku/WebPositive

  • From: webkit@xxxxxxxxxxxxxxx
  • To: haiku-webkit-commits@xxxxxxxxxxxxx
  • Date: Sun, 16 May 2010 20:41:50 +0000

Author: stippi
Date: Sun May 16 20:41:50 2010
New Revision: 498
URL: http://mmlr.dyndns.org/changeset/498

Log:
Remember the current URL input contents and selection when switching away from
a tab, and restore them when switching back.

Modified:
   webkit/trunk/WebKit/haiku/WebPositive/BrowserWindow.cpp

Modified: webkit/trunk/WebKit/haiku/WebPositive/BrowserWindow.cpp
==============================================================================
--- webkit/trunk/WebKit/haiku/WebPositive/BrowserWindow.cpp     Sun May 16 
20:41:07 2010        (r497)
+++ webkit/trunk/WebKit/haiku/WebPositive/BrowserWindow.cpp     Sun May 16 
20:41:50 2010        (r498)
@@ -148,7 +148,9 @@
        PageUserData(BView* focusedView)
                :
                fFocusedView(focusedView),
-               fPageIcon(NULL)
+               fPageIcon(NULL),
+               fURLInputSelectionStart(-1),
+               fURLInputSelectionEnd(-1)
        {
        }
 
@@ -181,9 +183,38 @@
                return fPageIcon;
        }
 
+       void SetURLInputContents(const char* text)
+       {
+               fURLInputContents = text;
+       }
+
+       const char* URLInputContents() const
+       {
+               return fURLInputContents.String();
+       }
+
+       void SetURLInputSelection(int32 selectionStart, int32 selectionEnd)
+       {
+               fURLInputSelectionStart = selectionStart;
+               fURLInputSelectionEnd = selectionEnd;
+       }
+
+       int32 URLInputSelectionStart() const
+       {
+               return fURLInputSelectionStart;
+       }
+
+       int32 URLInputSelectionEnd() const
+       {
+               return fURLInputSelectionEnd;
+       }
+
 private:
        BView*          fFocusedView;
        BBitmap*        fPageIcon;
+       BString         fURLInputContents;
+       int32           fURLInputSelectionStart;
+       int32           fURLInputSelectionEnd;
 };
 
 
@@ -883,10 +914,17 @@
                // later.
                PageUserData* userData = static_cast<PageUserData*>(
                        CurrentWebView()->GetUserData());
-               if (userData)
-                       userData->SetFocusedView(CurrentFocus());
-               else
-                       CurrentWebView()->SetUserData(new 
PageUserData(CurrentFocus()));
+               if (userData == NULL) {
+                       userData = new PageUserData(CurrentFocus());
+                       CurrentWebView()->SetUserData(userData);
+               }
+               userData->SetFocusedView(CurrentFocus());
+               userData->SetURLInputContents(fURLInputGroup->Text());
+               int32 selectionStart;
+               int32 selectionEnd;
+               fURLInputGroup->TextView()->GetSelection(&selectionStart,
+                       &selectionEnd);
+               userData->SetURLInputSelection(selectionStart, selectionEnd);
        }
 
        BWebWindow::SetCurrentWebView(webView);
@@ -900,10 +938,8 @@
                PageUserData* userData = static_cast<PageUserData*>(
                        webView->GetUserData());
                BView* focusedView = NULL;
-               if (userData != NULL) {
+               if (userData != NULL)
                        focusedView = userData->FocusedView();
-                       fURLInputGroup->SetPageIcon(userData->PageIcon());
-               }
 
                if (focusedView != NULL
                        && viewIsChild(GetLayout()->View(), focusedView)) {
@@ -911,7 +947,19 @@
                } else
                        webView->MakeFocus(true);
 
-               fURLInputGroup->SetText(webView->MainFrameURL());
+               if (userData != NULL) {
+                       fURLInputGroup->SetPageIcon(userData->PageIcon());
+                       fURLInputGroup->SetText(userData->URLInputContents());
+                       if (userData->URLInputSelectionStart() >= 0) {
+                               fURLInputGroup->TextView()->Select(
+                                       userData->URLInputSelectionStart(),
+                                       userData->URLInputSelectionEnd());
+                       }
+               } else {
+                       fURLInputGroup->SetPageIcon(NULL);
+                       fURLInputGroup->SetText(webView->MainFrameURL());
+               }
+
                // Trigger update of the interface to the new page, by 
requesting
                // to resend all notifications.
                webView->WebPage()->ResendNotifications();

Other related posts: