Ticket #13548: 0002-Changed-URL-input-locking-to-use-BMessageRunner.patch

File 0002-Changed-URL-input-locking-to-use-BMessageRunner.patch, 6.1 KB (added by accessays, 7 years ago)

Patched patch

  • src/apps/webpositive/BrowserWindow.cpp

    From 806334f2c9bc762407bc8161b23d00b73e0255e5 Mon Sep 17 00:00:00 2001
    From: Wiktor <vikkindhart@gmail.com>
    Date: Sun, 11 Jun 2017 11:14:17 +0200
    Subject: [PATCH] Changed URL input locking to use BMessageRunner.
    
    In the current state, opening a link in a new tab will cause URL input to
    become empty. This fixes the issue by changing the way locking works and
    implementing a lock timeout. The text passed to SetText() will be instead
    stored as previous text, so if the user presses ESC after editing the URL,
    URL input will update to the latest sent text (i. e. current URL). Also
    fixed two lines the style checker was complaining about.
    Fixes #13548.
    ---
     src/apps/webpositive/BrowserWindow.cpp | 12 +++++--
     src/apps/webpositive/URLInputGroup.cpp | 63 ++++++++++++++++++++++++++++++++--
     src/apps/webpositive/URLInputGroup.h   | 11 ++++++
     3 files changed, 80 insertions(+), 6 deletions(-)
    
    diff --git a/src/apps/webpositive/BrowserWindow.cpp b/src/apps/webpositive/BrowserWindow.cpp
    index 49eb6f6..e899593 100644
    a b BrowserWindow::DispatchMessage(BMessage* message, BHandler* target)  
    736736                _InvokeButtonVisibly(fURLInputGroup->GoButton());
    737737                return;
    738738            }
     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();
     744            }
    739745        } else if (target == fFindTextControl->TextView()) {
    740746            // Handle B_RETURN when the find text control has focus.
    741747            if (bytes[0] == B_RETURN) {
    BrowserWindow::MessageReceived(BMessage* message)  
    844850            entry_ref ref;
    845851            BString name;
    846852
    847             if (message->FindRef("directory", &ref) == B_OK &&
    848                 message->FindString("name", &name) == B_OK) {
     853            if (message->FindRef("directory", &ref) == B_OK
     854                && message->FindString("name", &name) == B_OK) {
    849855                BDirectory dir(&ref);
    850856                BFile output(&dir, name,
    851857                    B_WRITE_ONLY | B_CREATE_FILE | B_ERASE_FILE);
    BrowserWindow::_EncodeURIComponent(const BString& search)  
    24482454void
    24492455BrowserWindow::_VisitURL(const BString& url)
    24502456{
    2451     //fURLInputGroup->TextView()->SetText(url);
     2457    // fURLInputGroup->TextView()->SetText(url);
    24522458    CurrentWebView()->LoadURL(url.String());
    24532459}
    24542460
  • src/apps/webpositive/URLInputGroup.cpp

    diff --git a/src/apps/webpositive/URLInputGroup.cpp b/src/apps/webpositive/URLInputGroup.cpp
    index 45c083f..0106378 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);
    154155
    155156    virtual BSize               MinSize();
    156157    virtual BSize               MaxSize();
    URLInputGroup::URLTextView::KeyDown(const char* bytes, int32 numBytes)  
    302303void
    303304URLInputGroup::URLTextView::MakeFocus(bool focus)
    304305{
     306    // Unlock the URL input ahead of time if focus was lost.
     307    if (!focus) {
     308        fURLInputGroup->LockURLInput(false);
     309    }
     310
    305311    if (focus == IsFocus())
    306312        return;
    307313
    URLInputGroup::URLTextView::MakeFocus(bool focus)  
    316322}
    317323
    318324
     325void
     326URLInputGroup::URLTextView::SetPreviousText(const char* text)
     327{
     328    fPreviousText = text;
     329}
     330
     331
    319332BSize
    320333URLInputGroup::URLTextView::MinSize()
    321334{
    private:  
    583596URLInputGroup::URLInputGroup(BMessage* goMessage)
    584597    :
    585598    BGroupView(B_HORIZONTAL, 0.0),
    586     fWindowActive(false)
     599    fURLLockTimeout(NULL),
     600    fWindowActive(false),
     601    fURLLocked(false)
    587602{
    588603    GroupLayout()->SetInsets(2, 2, 2, 2);
    589604
    URLInputGroup::URLInputGroup(BMessage* goMessage)  
    608623
    609624    SetExplicitAlignment(BAlignment(B_ALIGN_USE_FULL_WIDTH,
    610625        B_ALIGN_VERTICAL_CENTER));
     626
    611627}
    612628
    613629
    614630URLInputGroup::~URLInputGroup()
    615631{
     632    delete fURLLockTimeout;
    616633}
    617634
    618635
    URLInputGroup::TextView() const  
    666683void
    667684URLInputGroup::SetText(const char* text)
    668685{
    669     // Ignore setting the text, if the user is currently editing the URL.
    670     if (fWindowActive && fTextView->IsFocus())
     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);
    671692        return;
     693    }
    672694
    673695    if (!text || !Text() || strcmp(Text(), text) != 0) {
    674696        fTextView->SetUpdateAutoCompleterChoices(false);
    URLInputGroup::SetPageIcon(const BBitmap* icon)  
    698720    fIconView->SetIcon(icon);
    699721}
    700722
     723
     724void
     725URLInputGroup::LockURLInput(bool lock)
     726{
     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    }
     736}
     737
     738
     739void
     740URLInputGroup::MessageReceived(BMessage* message)
     741{
     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    }
     756}
     757
  • src/apps/webpositive/URLInputGroup.h

    diff --git a/src/apps/webpositive/URLInputGroup.h b/src/apps/webpositive/URLInputGroup.h
    index d71f713..2e5bd72 100644
    a b  
    66#define URL_INPUT_GROUP_H
    77
    88#include <GroupView.h>
     9#include <MessageRunner.h>
    910
    1011class BButton;
    1112class BTextView;
    1213
    1314
    1415class URLInputGroup : public BGroupView {
     16private:
     17    static  const   uint32      MSG_LOCK_TIMEOUT = 'loti';
     18    static  const   bigtime_t   LOCK_TIMEOUT = 1000000;
     19        // Lock will timeout in one second
     20
    1521public:
    1622                                URLInputGroup(BMessage* goMessage);
    1723    virtual                     ~URLInputGroup();
    public:  
    2935
    3036            void                SetPageIcon(const BBitmap* icon);
    3137
     38    virtual void                LockURLInput(bool lock = true);
     39    virtual void                MessageReceived(BMessage* message);
     40
    3241private:
    3342            class PageIconView;
    3443            class URLTextView;
    3544
     45            BMessageRunner*     fURLLockTimeout;
    3646            PageIconView*       fIconView;
    3747            URLTextView*        fTextView;
    3848            BButton*            fGoButton;
    3949            bool                fWindowActive;
     50            bool                fURLLocked;
    4051};
    4152
    4253#endif // URL_INPUT_GROUP_H