Ticket #13550: 0001-WebPositive-fixed-a-lot-about-how-navigation-works-m.patch

File 0001-WebPositive-fixed-a-lot-about-how-navigation-works-m.patch, 10.0 KB (added by accessays, 7 years ago)

Patch #1

  • src/apps/webpositive/BrowserWindow.cpp

    From ff135da9f97f18afc7f199a1823a79d1f5c53a6d Mon Sep 17 00:00:00 2001
    From: Wiktor <vikkindhart@gmail.com>
    Date: Mon, 12 Jun 2017 01:07:43 +0200
    Subject: [PATCH] WebPositive: fixed a lot about how navigation works (+misc).
    
    Changed the way navigation controls are updated, now several functions
    call ResendNotifications() in order to correctly display the controls.
    Also fixed (again) how URL locking works, removing the need for a timeout,
    now URL input is considered locked when it is focused and original text was
    changed. Removed fPreviousText from URLInputGroup::URLTextView, as now
    pressing ESC will change URL input's text to the current URL. This should
    fix a possible problem when URL changes while being edited and pressing ESC
    would yield the old URL.
    ---
     src/apps/webpositive/BrowserWindow.cpp | 56 ++++++++++++++++++++-----
     src/apps/webpositive/URLInputGroup.cpp | 74 +++++++++-------------------------
     src/apps/webpositive/URLInputGroup.h   |  9 +----
     3 files changed, 66 insertions(+), 73 deletions(-)
    
    diff --git a/src/apps/webpositive/BrowserWindow.cpp b/src/apps/webpositive/BrowserWindow.cpp
    index e899593..ca2f169 100644
    a b BrowserWindow::DispatchMessage(BMessage* message, BHandler* target)  
    735735                // Do it in such a way that the user sees the Go-button go down.
    736736                _InvokeButtonVisibly(fURLInputGroup->GoButton());
    737737                return;
    738             }
    739             // Lock the URL text control to prevent changes while user is
    740             // typing and set a timer to unlock it after a set period
    741             // of time.
    742             else {
    743                 fURLInputGroup->LockURLInput();
     738            } else if (bytes[0] == B_ESCAPE) {
     739                // Replace edited text with the current URL.
     740                fURLInputGroup->LockURLInput(false);
     741                fURLInputGroup->SetText(CurrentWebView()->MainFrameURL());
    744742            }
    745743        } else if (target == fFindTextControl->TextView()) {
    746744            // Handle B_RETURN when the find text control has focus.
    void  
    810808BrowserWindow::MessageReceived(BMessage* message)
    811809{
    812810    switch (message->what) {
     811        case LOAD_COMMITTED:
     812        {
     813            fStopButton->SetEnabled(true);
     814            break;
     815        }
     816        case LOAD_DL_COMPLETED:
     817        case LOAD_FAILED:
     818        case LOAD_FINISHED:
     819        {
     820            // Force update of navigation controls and disable the stop button
     821            CurrentWebView()->WebPage()->ResendNotifications();
     822            // fStopButton->SetEnabled(false);
     823            break;
     824        }
    813825        case OPEN_LOCATION:
    814826            _ShowInterface(true);
    815827            if (fURLInputGroup->TextView()->IsFocus())
    BrowserWindow::SetCurrentWebView(BWebView* webView)  
    13141326        } else
    13151327            webView->MakeFocus(true);
    13161328
     1329        bool state = fURLInputGroup->IsURLInputLocked();
     1330        fURLInputGroup->LockURLInput(false);
     1331            // Unlock it so the following code can update the URL
     1332
    13171333        if (userData != NULL) {
    13181334            fURLInputGroup->SetPageIcon(userData->PageIcon());
    13191335            if (userData->URLInputContents().Length())
    13201336                fURLInputGroup->SetText(userData->URLInputContents());
    13211337            else
    13221338                fURLInputGroup->SetText(webView->MainFrameURL());
     1339
    13231340            if (userData->URLInputSelectionStart() >= 0) {
    13241341                fURLInputGroup->TextView()->Select(
    13251342                    userData->URLInputSelectionStart(),
    BrowserWindow::SetCurrentWebView(BWebView* webView)  
    13301347            fURLInputGroup->SetText(webView->MainFrameURL());
    13311348        }
    13321349
     1350        fURLInputGroup->LockURLInput(state);
     1351            // Restore the state
     1352
    13331353        // Trigger update of the interface to the new page, by requesting
    13341354        // to resend all notifications.
    13351355        webView->WebPage()->ResendNotifications();
    BrowserWindow::CloseWindowRequested(BWebView* view)  
    14741494void
    14751495BrowserWindow::LoadNegotiating(const BString& url, BWebView* view)
    14761496{
    1477     if (view != CurrentWebView())
     1497    if (view != CurrentWebView()) {
     1498        // Update the userData contents instead so the user sees
     1499        // the correct URL when they switch back to that tab.
     1500        PageUserData* userData = static_cast<PageUserData*>(
     1501            view->GetUserData());
     1502        if (userData != NULL) {
     1503            if (userData->URLInputContents().Length() == 0)
     1504                userData->SetURLInputContents(url);
     1505        }
    14781506        return;
     1507    }
    14791508
    14801509    fURLInputGroup->SetText(url.String());
    14811510
    BrowserWindow::LoadProgress(float progress, BWebView* view)  
    15081537
    15091538    if (progress < 100 && fLoadingProgressBar->IsHidden())
    15101539        _ShowProgressBar(true);
    1511     else if (progress == 100 && !fLoadingProgressBar->IsHidden())
    1512         _ShowProgressBar(false);
     1540    else if (progress == 100) {
     1541        fStopButton->SetEnabled(false);
     1542        if (!fLoadingProgressBar->IsHidden())
     1543            _ShowProgressBar(false);
     1544    }
    15131545    fLoadingProgressBar->SetTo(progress);
    15141546}
    15151547
    BrowserWindow::LoadFinished(const BString& url, BWebView* view)  
    15351567    if (view != CurrentWebView())
    15361568        return;
    15371569
    1538     fURLInputGroup->SetText(url.String());
    1539 
    15401570    BString status(B_TRANSLATE_COMMENT("%url finished", "Loading URL "
    15411571        "finished. Don't translate variable %url."));
    15421572    status.ReplaceFirst("%url", url);
    void  
    17291759BrowserWindow::UpdateGlobalHistory(const BString& url)
    17301760{
    17311761    BrowsingHistory::DefaultInstance()->AddItem(BrowsingHistoryItem(url));
     1762    CurrentWebView()->WebPage()->ResendNotifications();
     1763        // Update the navigation controls
     1764
     1765    fURLInputGroup->SetText(CurrentWebView()->MainFrameURL());
    17321766}
    17331767
    17341768
  • src/apps/webpositive/URLInputGroup.cpp

    diff --git a/src/apps/webpositive/URLInputGroup.cpp b/src/apps/webpositive/URLInputGroup.cpp
    index 0106378..cdc0ab2 100644
    a b public:  
    151151    virtual void                MouseDown(BPoint where);
    152152    virtual void                KeyDown(const char* bytes, int32 numBytes);
    153153    virtual void                MakeFocus(bool focused = true);
    154     virtual void                SetPreviousText(const char* text);
    155154
    156155    virtual BSize               MinSize();
    157156    virtual BSize               MaxSize();
    private:  
    170169private:
    171170            URLInputGroup*      fURLInputGroup;
    172171            TextViewCompleter*  fURLAutoCompleter;
    173             BString             fPreviousText;
    174172            bool                fUpdateAutoCompleterChoices;
    175173};
    176174
    URLInputGroup::URLTextView::URLTextView(URLInputGroup* parent)  
    181179    fURLInputGroup(parent),
    182180    fURLAutoCompleter(new TextViewCompleter(this,
    183181        new BrowsingHistoryChoiceModel())),
    184     fPreviousText(""),
    185182    fUpdateAutoCompleterChoices(true)
    186183{
    187184    MakeResizable(true);
    URLInputGroup::URLTextView::KeyDown(const char* bytes, int32 numBytes)  
    285282            break;
    286283
    287284        case B_ESCAPE:
    288             // Revert to text as it was when we received keyboard focus.
    289             SetText(fPreviousText.String());
     285            // Text already unlocked && replaced in BrowserWindow,
     286            // now select it.
    290287            SelectAll();
    291288            break;
    292289
    URLInputGroup::URLTextView::KeyDown(const char* bytes, int32 numBytes)  
    295292            break;
    296293
    297294        default:
     295        {
     296            BString currentText = Text();
    298297            BTextView::KeyDown(bytes, numBytes);
     298            // Lock the URL input if it was modified
     299            if (!fURLInputGroup->IsURLInputLocked()
     300                && Text() != currentText) {
     301                fURLInputGroup->LockURLInput();
     302            }
    299303            break;
     304        }
    300305    }
    301306}
    302307
    303308void
    304309URLInputGroup::URLTextView::MakeFocus(bool focus)
    305310{
    306     // Unlock the URL input ahead of time if focus was lost.
    307     if (!focus) {
     311    // Unlock the URL input if focus was lost.
     312    if (!focus)
    308313        fURLInputGroup->LockURLInput(false);
    309     }
    310314
    311315    if (focus == IsFocus())
    312316        return;
    313317
    314318    BTextView::MakeFocus(focus);
    315319
    316     if (focus) {
    317         fPreviousText = Text();
     320    if (focus)
    318321        SelectAll();
    319     }
    320322
    321323    fURLInputGroup->Invalidate();
    322324}
    323325
    324326
    325 void
    326 URLInputGroup::URLTextView::SetPreviousText(const char* text)
    327 {
    328     fPreviousText = text;
    329 }
    330 
    331 
    332327BSize
    333328URLInputGroup::URLTextView::MinSize()
    334329{
    private:  
    596591URLInputGroup::URLInputGroup(BMessage* goMessage)
    597592    :
    598593    BGroupView(B_HORIZONTAL, 0.0),
    599     fURLLockTimeout(NULL),
    600594    fWindowActive(false),
    601595    fURLLocked(false)
    602596{
    URLInputGroup::URLInputGroup(BMessage* goMessage)  
    629623
    630624URLInputGroup::~URLInputGroup()
    631625{
    632     delete fURLLockTimeout;
    633626}
    634627
    635628
    URLInputGroup::TextView() const  
    683676void
    684677URLInputGroup::SetText(const char* text)
    685678{
    686     // Ignore setting the text, if the user edited the URL in the last
    687     // couple of seconds. Instead set the previous text in the text view,
    688     // so if the user presses ESC the input will update to show the new
    689     // text.
    690     if (fURLLocked) {
    691         fTextView->SetPreviousText(text);
     679    // Ignore setting the text, if the input is locked.
     680    if (fURLLocked)
    692681        return;
    693     }
    694682
    695683    if (!text || !Text() || strcmp(Text(), text) != 0) {
    696684        fTextView->SetUpdateAutoCompleterChoices(false);
    URLInputGroup::SetPageIcon(const BBitmap* icon)  
    721709}
    722710
    723711
    724 void
    725 URLInputGroup::LockURLInput(bool lock)
     712bool
     713URLInputGroup::IsURLInputLocked() const
    726714{
    727     fURLLocked = lock;
    728     if (lock) {
    729         if (fURLLockTimeout == NULL) {
    730             fURLLockTimeout = new BMessageRunner(this,
    731                 new BMessage(MSG_LOCK_TIMEOUT), LOCK_TIMEOUT, 1);
    732         } else {
    733             fURLLockTimeout->SetInterval(LOCK_TIMEOUT);
    734         }
    735     }
     715    return fURLLocked;
    736716}
    737717
    738718
    739719void
    740 URLInputGroup::MessageReceived(BMessage* message)
     720URLInputGroup::LockURLInput(bool lock)
    741721{
    742     switch (message->what) {
    743         case MSG_LOCK_TIMEOUT:
    744         {
    745             delete fURLLockTimeout;
    746             fURLLockTimeout = NULL;
    747             LockURLInput(false);
    748             break;
    749         }
    750         default:
    751         {
    752             BGroupView(message);
    753             break;
    754         }
    755     }
     722    fURLLocked = lock;
    756723}
    757 
  • src/apps/webpositive/URLInputGroup.h

    diff --git a/src/apps/webpositive/URLInputGroup.h b/src/apps/webpositive/URLInputGroup.h
    index 2e5bd72..21bae63 100644
    a b  
    66#define URL_INPUT_GROUP_H
    77
    88#include <GroupView.h>
    9 #include <MessageRunner.h>
    109
    1110class BButton;
    1211class BTextView;
    1312
    1413
    1514class URLInputGroup : public BGroupView {
    16 private:
    17     static  const   uint32      MSG_LOCK_TIMEOUT = 'loti';
    18     static  const   bigtime_t   LOCK_TIMEOUT = 1000000;
    19         // Lock will timeout in one second
    20 
    2115public:
    2216                                URLInputGroup(BMessage* goMessage);
    2317    virtual                     ~URLInputGroup();
    public:  
    3529
    3630            void                SetPageIcon(const BBitmap* icon);
    3731
     32            bool                IsURLInputLocked() const;
    3833    virtual void                LockURLInput(bool lock = true);
    39     virtual void                MessageReceived(BMessage* message);
    4034
    4135private:
    4236            class PageIconView;
    4337            class URLTextView;
    4438
    45             BMessageRunner*     fURLLockTimeout;
    4639            PageIconView*       fIconView;
    4740            URLTextView*        fTextView;
    4841            BButton*            fGoButton;