Ticket #13550: 0001-Fixed-again-the-way-URL-locking-works.patch

File 0001-Fixed-again-the-way-URL-locking-works.patch, 8.0 KB (added by accessays, 7 years ago)
  • src/apps/webpositive/BrowserWindow.cpp

    From 4635cfdcd550912e6f35742c687f2a1661373209 Mon Sep 17 00:00:00 2001
    From: Victor <vikkindhart@gmail.com>
    Date: Sat, 17 Jun 2017 14:01:52 +0000
    Subject: [PATCH] Fixed (again) the way URL locking works.
    
    URL input is considered locked when it is focused and original text was
    changed. Pressing ESC will now change URL input's text to the current URL.
    ---
     src/apps/webpositive/BrowserWindow.cpp | 30 ++++++++++----
     src/apps/webpositive/URLInputGroup.cpp | 73 +++++++++-------------------------
     src/apps/webpositive/URLInputGroup.h   |  9 +----
     3 files changed, 42 insertions(+), 70 deletions(-)
    
    diff --git a/src/apps/webpositive/BrowserWindow.cpp b/src/apps/webpositive/BrowserWindow.cpp
    index e899593..066d189 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.
    BrowserWindow::SetCurrentWebView(BWebView* webView)  
    13141312        } else
    13151313            webView->MakeFocus(true);
    13161314
     1315        bool state = fURLInputGroup->IsURLInputLocked();
     1316        fURLInputGroup->LockURLInput(false);
     1317            // Unlock it so the following code can update the URL
     1318
    13171319        if (userData != NULL) {
    13181320            fURLInputGroup->SetPageIcon(userData->PageIcon());
    13191321            if (userData->URLInputContents().Length())
    BrowserWindow::SetCurrentWebView(BWebView* webView)  
    13301332            fURLInputGroup->SetText(webView->MainFrameURL());
    13311333        }
    13321334
     1335        fURLInputGroup->LockURLInput(state);
     1336            // Restore the state
     1337
    13331338        // Trigger update of the interface to the new page, by requesting
    13341339        // to resend all notifications.
    13351340        webView->WebPage()->ResendNotifications();
    BrowserWindow::CloseWindowRequested(BWebView* view)  
    14741479void
    14751480BrowserWindow::LoadNegotiating(const BString& url, BWebView* view)
    14761481{
    1477     if (view != CurrentWebView())
    1478         return;
     1482    if (view != CurrentWebView()) {
     1483        // Update the userData contents instead so the user sees
     1484        // the correct URL when they switch back to that tab.
     1485        PageUserData* userData = static_cast<PageUserData*>(
     1486            view->GetUserData());
     1487        if (userData != NULL && userData->URLInputContents().Length() == 0) {
     1488            userData->SetURLInputContents(url);
     1489        }
     1490    }
    14791491
    14801492    fURLInputGroup->SetText(url.String());
    14811493
    void  
    17291741BrowserWindow::UpdateGlobalHistory(const BString& url)
    17301742{
    17311743    BrowsingHistory::DefaultInstance()->AddItem(BrowsingHistoryItem(url));
     1744
     1745    fURLInputGroup->SetText(CurrentWebView()->MainFrameURL());
    17321746}
    17331747
    17341748
  • src/apps/webpositive/URLInputGroup.cpp

    diff --git a/src/apps/webpositive/URLInputGroup.cpp b/src/apps/webpositive/URLInputGroup.cpp
    index 0106378..9a0437e 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();
    299302            break;
     303        }
    300304    }
    301305}
    302306
    303307void
    304308URLInputGroup::URLTextView::MakeFocus(bool focus)
    305309{
    306     // Unlock the URL input ahead of time if focus was lost.
    307     if (!focus) {
     310    // Unlock the URL input if focus was lost.
     311    if (!focus)
    308312        fURLInputGroup->LockURLInput(false);
    309     }
    310313
    311314    if (focus == IsFocus())
    312315        return;
    313316
    314317    BTextView::MakeFocus(focus);
    315318
    316     if (focus) {
    317         fPreviousText = Text();
     319    if (focus)
    318320        SelectAll();
    319     }
    320321
    321322    fURLInputGroup->Invalidate();
    322323}
    323324
    324325
    325 void
    326 URLInputGroup::URLTextView::SetPreviousText(const char* text)
    327 {
    328     fPreviousText = text;
    329 }
    330 
    331 
    332326BSize
    333327URLInputGroup::URLTextView::MinSize()
    334328{
    private:  
    596590URLInputGroup::URLInputGroup(BMessage* goMessage)
    597591    :
    598592    BGroupView(B_HORIZONTAL, 0.0),
    599     fURLLockTimeout(NULL),
    600593    fWindowActive(false),
    601594    fURLLocked(false)
    602595{
    URLInputGroup::URLInputGroup(BMessage* goMessage)  
    629622
    630623URLInputGroup::~URLInputGroup()
    631624{
    632     delete fURLLockTimeout;
    633625}
    634626
    635627
    URLInputGroup::TextView() const  
    683675void
    684676URLInputGroup::SetText(const char* text)
    685677{
    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);
     678    // Ignore setting the text, if the input is locked.
     679    if (fURLLocked)
    692680        return;
    693     }
    694681
    695682    if (!text || !Text() || strcmp(Text(), text) != 0) {
    696683        fTextView->SetUpdateAutoCompleterChoices(false);
    URLInputGroup::SetPageIcon(const BBitmap* icon)  
    721708}
    722709
    723710
    724 void
    725 URLInputGroup::LockURLInput(bool lock)
     711bool
     712URLInputGroup::IsURLInputLocked() const
    726713{
    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     }
     714    return fURLLocked;
    736715}
    737716
    738717
    739718void
    740 URLInputGroup::MessageReceived(BMessage* message)
     719URLInputGroup::LockURLInput(bool lock)
    741720{
    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     }
     721    fURLLocked = lock;
    756722}
    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;