* 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
This commit is contained in:
stippi
2012-07-03 15:44:09 +02:00
committed by Alexandre Deckner
parent e7c6e9f747
commit e07fc6b71d
6 changed files with 65 additions and 42 deletions
+11 -7
View File
@@ -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(
+1
View File
@@ -152,6 +152,7 @@ private:
private:
void _UpdateTitle(const BString &title);
void _UpdateTabGroupVisibility();
bool _TabGroupShouldBeVisible() const;
void _ShutdownTab(int32 index);
void _TabChanged(int32 index);
+19 -33
View File
@@ -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
{
+2 -2
View File
@@ -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;
+30
View File
@@ -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<DownloadProgressView*>(
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)
{
+2
View File
@@ -45,6 +45,8 @@ public:
SettingsMessage* settings);
virtual ~DownloadWindow();
virtual void DispatchMessage(BMessage* message,
BHandler* target);
virtual void MessageReceived(BMessage* message);
virtual bool QuitRequested();