From e07fc6b71df68266b262583b4d9ca43138ea6c9f Mon Sep 17 00:00:00 2001 From: stippi Date: Wed, 5 May 2010 11:04:24 +0000 Subject: [PATCH] * Changed the implementation of context menus in DownloadProgressViews. The views were intercepting mouse messages even if the window was not showing. Now secondary clicks are intercepted in DownloadWindow and the target view is found, which makes this much cheaper. * Offset context menus by 2 pixels, so the mouse does not start directly over an item. git-svn-id: http://svn.haiku-os.org/webpositive/webkit/trunk@488 94f232f2-1747-11df-bad5-a5bfde151594 --- src/apps/webpositive/BrowserWindow.cpp | 18 ++++--- src/apps/webpositive/BrowserWindow.h | 1 + src/apps/webpositive/DownloadProgressView.cpp | 52 +++++++------------ src/apps/webpositive/DownloadProgressView.h | 4 +- src/apps/webpositive/DownloadWindow.cpp | 30 +++++++++++ src/apps/webpositive/DownloadWindow.h | 2 + 6 files changed, 65 insertions(+), 42 deletions(-) diff --git a/src/apps/webpositive/BrowserWindow.cpp b/src/apps/webpositive/BrowserWindow.cpp index ee72d6b890..92873f1d97 100644 --- a/src/apps/webpositive/BrowserWindow.cpp +++ b/src/apps/webpositive/BrowserWindow.cpp @@ -1300,16 +1300,22 @@ void BrowserWindow::_UpdateTabGroupVisibility() { if (Lock()) { - if (fInterfaceVisible) { - fTabGroup->SetVisible(fShowTabsIfSinglePageOpen - || fTabManager->CountTabs() > 1); - } + if (fInterfaceVisible) + fTabGroup->SetVisible(_TabGroupShouldBeVisible()); fTabManager->SetCloseButtonsAvailable(fTabManager->CountTabs() > 1); Unlock(); } } +bool +BrowserWindow::_TabGroupShouldBeVisible() const +{ + return (fShowTabsIfSinglePageOpen || fTabManager->CountTabs() > 1) + && (fVisibleInterfaceElements & INTERFACE_ELEMENT_TABS) != 0; +} + + void BrowserWindow::_ShutdownTab(int32 index) { @@ -1868,9 +1874,7 @@ BrowserWindow::_ShowInterface(bool show) fMenuGroup->SetVisible( (fVisibleInterfaceElements & INTERFACE_ELEMENT_MENU) != 0); #endif - fTabGroup->SetVisible((fShowTabsIfSinglePageOpen - || fTabManager->CountTabs() > 1) - && (fVisibleInterfaceElements & INTERFACE_ELEMENT_TABS) != 0); + fTabGroup->SetVisible(_TabGroupShouldBeVisible()); fNavigationGroup->SetVisible( (fVisibleInterfaceElements & INTERFACE_ELEMENT_NAVIGATION) != 0); fStatusGroup->SetVisible( diff --git a/src/apps/webpositive/BrowserWindow.h b/src/apps/webpositive/BrowserWindow.h index 1750584fb3..5d272b2eb8 100644 --- a/src/apps/webpositive/BrowserWindow.h +++ b/src/apps/webpositive/BrowserWindow.h @@ -152,6 +152,7 @@ private: private: void _UpdateTitle(const BString &title); void _UpdateTabGroupVisibility(); + bool _TabGroupShouldBeVisible() const; void _ShutdownTab(int32 index); void _TabChanged(int32 index); diff --git a/src/apps/webpositive/DownloadProgressView.cpp b/src/apps/webpositive/DownloadProgressView.cpp index e7914e8736..f0c4e5bb3b 100644 --- a/src/apps/webpositive/DownloadProgressView.cpp +++ b/src/apps/webpositive/DownloadProgressView.cpp @@ -208,10 +208,6 @@ DownloadProgressView::DownloadProgressView(const BMessage* archive) bool DownloadProgressView::Init(BMessage* archive) { - // We need to receive mouse events even for the areas of children views, - // so we can pop up a context menu. - SetEventMask(B_POINTER_EVENTS); - fCurrentSize = 0; fExpectedSize = 0; fLastUpdateTime = 0; @@ -339,35 +335,6 @@ DownloadProgressView::AllAttached() } -void -DownloadProgressView::MouseDown(BPoint where) -{ - if (!Bounds().Contains(where)) - return; - - int32 buttons; - if (Window()->CurrentMessage()->FindInt32("buttons", &buttons) != B_OK) - return; - - if ((buttons & B_SECONDARY_MOUSE_BUTTON) == 0) - return; - - where = ConvertToScreen(where) + BPoint(2, 2); - - BPopUpMenu* contextMenu = new BPopUpMenu("download context"); - BMenuItem* copyURL = new BMenuItem("Copy URL to clipboard", - new BMessage(COPY_URL_TO_CLIPBOARD)); - copyURL->SetEnabled(fURL.Length() > 0); - contextMenu->AddItem(copyURL); - BMenuItem* openFolder = new BMenuItem("Open containing folder", - new BMessage(OPEN_CONTAINING_FOLDER)); - contextMenu->AddItem(openFolder); - - contextMenu->SetTargetForItems(this); - contextMenu->Go(where, true, true, true); -} - - void DownloadProgressView::Draw(BRect updateRect) { @@ -588,6 +555,25 @@ DownloadProgressView::MessageReceived(BMessage* message) } +void +DownloadProgressView::ShowContextMenu(BPoint screenWhere) +{ + screenWhere += BPoint(2, 2); + + BPopUpMenu* contextMenu = new BPopUpMenu("download context"); + BMenuItem* copyURL = new BMenuItem("Copy URL to clipboard", + new BMessage(COPY_URL_TO_CLIPBOARD)); + copyURL->SetEnabled(fURL.Length() > 0); + contextMenu->AddItem(copyURL); + BMenuItem* openFolder = new BMenuItem("Open containing folder", + new BMessage(OPEN_CONTAINING_FOLDER)); + contextMenu->AddItem(openFolder); + + contextMenu->SetTargetForItems(this); + contextMenu->Go(screenWhere, true, true, true); +} + + BWebDownload* DownloadProgressView::Download() const { diff --git a/src/apps/webpositive/DownloadProgressView.h b/src/apps/webpositive/DownloadProgressView.h index 256245442d..32a021b169 100644 --- a/src/apps/webpositive/DownloadProgressView.h +++ b/src/apps/webpositive/DownloadProgressView.h @@ -57,12 +57,12 @@ public: virtual void DetachedFromWindow(); virtual void AllAttached(); - virtual void MouseDown(BPoint where); - virtual void Draw(BRect updateRect); virtual void MessageReceived(BMessage* message); + void ShowContextMenu(BPoint screenWhere); + BWebDownload* Download() const; const BString& URL() const; bool IsMissing() const; diff --git a/src/apps/webpositive/DownloadWindow.cpp b/src/apps/webpositive/DownloadWindow.cpp index 7fa39a6b0a..00d57dc50f 100644 --- a/src/apps/webpositive/DownloadWindow.cpp +++ b/src/apps/webpositive/DownloadWindow.cpp @@ -198,6 +198,36 @@ DownloadWindow::~DownloadWindow() } +void +DownloadWindow::DispatchMessage(BMessage* message, BHandler* target) +{ + // We need to intercept mouse down events inside the area of download + // progress views (regardless of whether they have children at the click), + // so that they may display a context menu. + BPoint where; + int32 buttons; + if (message->what == B_MOUSE_DOWN + && message->FindPoint("screen_where", &where) == B_OK + && message->FindInt32("buttons", &buttons) == B_OK + && (buttons & B_SECONDARY_MOUSE_BUTTON) != 0) { + for (int32 i = fDownloadViewsLayout->CountItems() - 1; + BLayoutItem* item = fDownloadViewsLayout->ItemAt(i); i--) { + DownloadProgressView* view = dynamic_cast( + item->View()); + if (!view) + continue; + BPoint viewWhere(where); + view->ConvertFromScreen(&viewWhere); + if (view->Bounds().Contains(viewWhere)) { + view->ShowContextMenu(where); + return; + } + } + } + BWindow::DispatchMessage(message, target); +} + + void DownloadWindow::MessageReceived(BMessage* message) { diff --git a/src/apps/webpositive/DownloadWindow.h b/src/apps/webpositive/DownloadWindow.h index 92d299c89b..e4e62bfecc 100644 --- a/src/apps/webpositive/DownloadWindow.h +++ b/src/apps/webpositive/DownloadWindow.h @@ -45,6 +45,8 @@ public: SettingsMessage* settings); virtual ~DownloadWindow(); + virtual void DispatchMessage(BMessage* message, + BHandler* target); virtual void MessageReceived(BMessage* message); virtual bool QuitRequested();