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

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

Patch to the issue

  • src/apps/webpositive/BrowserWindow.cpp

    From 93b4113386d67ddf6688b38e862c10ebd1d3c68f 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 | 62 ++++++++++++++++++++++++++++++++--
     src/apps/webpositive/URLInputGroup.h   | 11 ++++++
     3 files changed, 79 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..5f6b2a9 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
    URLInputGroup::TextView() const  
    666682void
    667683URLInputGroup::SetText(const char* text)
    668684{
    669     // Ignore setting the text, if the user is currently editing the URL.
    670     if (fWindowActive && fTextView->IsFocus())
     685    // Ignore setting the text, if the user edited the URL in the last
     686    // couple of seconds. Instead set the previous text in the text view,
     687    // so if the user presses ESC the input will update to show the new
     688    // text.
     689    if (fURLLocked) {
     690        fTextView->SetPreviousText(text);
    671691        return;
     692    }
    672693
    673694    if (!text || !Text() || strcmp(Text(), text) != 0) {
    674695        fTextView->SetUpdateAutoCompleterChoices(false);
    URLInputGroup::SetPageIcon(const BBitmap* icon)  
    698719    fIconView->SetIcon(icon);
    699720}
    700721
     722
     723void
     724URLInputGroup::LockURLInput(bool lock)
     725{
     726    fURLLocked = lock;
     727    if (lock) {
     728        if (fURLLockTimeout == NULL) {
     729            fURLLockTimeout = new BMessageRunner(this,
     730                new BMessage(MSG_LOCK_TIMEOUT), LOCK_TIMEOUT, 1);
     731        } else {
     732            fURLLockTimeout->SetInterval(LOCK_TIMEOUT);
     733        }
     734    }
     735}
     736
     737
     738void
     739URLInputGroup::MessageReceived(BMessage* message)
     740{
     741    switch (message->what) {
     742        case MSG_LOCK_TIMEOUT:
     743        {
     744            delete fURLLockTimeout;
     745            fURLLockTimeout = NULL;
     746            LockURLInput(false);
     747            break;
     748        }
     749        default:
     750        {
     751            BGroupView(message);
     752            break;
     753        }
     754    }
     755}
     756
  • 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