Bug 1360278 - Add preference to trigger context menu on mouse up for GTK+ and macOS, r=mstange,smaug

MozReview-Commit-ID: Bg60bD8jIg6

--HG--
extra : rebase_source : cc8bd5796096f49ad4fdab81885a426afd6117e4
This commit is contained in:
Robin Grenet 2017-11-16 13:35:58 +01:00
parent 7245bd41b2
commit 34508b32f6
6 changed files with 69 additions and 9 deletions

View File

@ -234,6 +234,10 @@ pref("browser.sessionhistory.max_total_viewers", -1);
pref("ui.use_native_colors", true);
pref("ui.click_hold_context_menus", false);
// Pop up context menu on mouseup instead of mousedown, if that's the OS default.
// Note: ignored on Windows (context menus always use mouseup)
pref("ui.context_menus.after_mouseup", false);
// Duration of timeout of incremental search in menus (ms). 0 means infinite.
pref("ui.menu.incremental_search.timeout", 1000);
// If true, all popups won't hide automatically on blur

View File

@ -4700,8 +4700,10 @@ NSEvent* gLastDragMouseDownEvent = nil;
if (!mGeckoChild)
return;
// Let the superclass do the context menu stuff.
[super rightMouseDown:theEvent];
if (!nsBaseWidget::ShowContextMenuAfterMouseUp()) {
// Let the superclass do the context menu stuff.
[super rightMouseDown:theEvent];
}
NS_OBJC_END_TRY_ABORT_BLOCK;
}
@ -4724,6 +4726,23 @@ NSEvent* gLastDragMouseDownEvent = nil;
nsAutoRetainCocoaObject kungFuDeathGrip(self);
mGeckoChild->DispatchInputEvent(&geckoEvent);
if (!mGeckoChild)
return;
if (nsBaseWidget::ShowContextMenuAfterMouseUp()) {
// Let the superclass do the context menu stuff, but pretend it's rightMouseDown.
NSEvent *dupeEvent = [NSEvent mouseEventWithType:NSRightMouseDown
location:theEvent.locationInWindow
modifierFlags:theEvent.modifierFlags
timestamp:theEvent.timestamp
windowNumber:theEvent.windowNumber
context:theEvent.context
eventNumber:theEvent.eventNumber
clickCount:theEvent.clickCount
pressure:theEvent.pressure];
[super rightMouseDown:dupeEvent];
}
NS_OBJC_END_TRY_ABORT_BLOCK;
}

View File

@ -2737,6 +2737,19 @@ static guint ButtonMaskFromGDKButton(guint button)
return GDK_BUTTON1_MASK << (button - 1);
}
void
nsWindow::DispatchContextMenuEventFromMouseEvent(uint16_t domButton,
GdkEventButton *aEvent)
{
if (domButton == WidgetMouseEvent::eRightButton && MOZ_LIKELY(!mIsDestroyed)) {
WidgetMouseEvent contextMenuEvent(true, eContextMenu, this,
WidgetMouseEvent::eReal);
InitButtonEvent(contextMenuEvent, aEvent);
contextMenuEvent.pressure = mLastMotionPressure;
DispatchInputEvent(&contextMenuEvent);
}
}
void
nsWindow::OnButtonPressEvent(GdkEventButton *aEvent)
{
@ -2806,13 +2819,8 @@ nsWindow::OnButtonPressEvent(GdkEventButton *aEvent)
DispatchInputEvent(&event);
// right menu click on linux should also pop up a context menu
if (domButton == WidgetMouseEvent::eRightButton &&
MOZ_LIKELY(!mIsDestroyed)) {
WidgetMouseEvent contextMenuEvent(true, eContextMenu, this,
WidgetMouseEvent::eReal);
InitButtonEvent(contextMenuEvent, aEvent);
contextMenuEvent.pressure = mLastMotionPressure;
DispatchInputEvent(&contextMenuEvent);
if (!nsBaseWidget::ShowContextMenuAfterMouseUp()) {
DispatchContextMenuEventFromMouseEvent(domButton, aEvent);
}
}
@ -2848,6 +2856,11 @@ nsWindow::OnButtonReleaseEvent(GdkEventButton *aEvent)
DispatchInputEvent(&event);
mLastMotionPressure = pressure;
// right menu click on linux should also pop up a context menu
if (nsBaseWidget::ShowContextMenuAfterMouseUp()) {
DispatchContextMenuEventFromMouseEvent(domButton, aEvent);
}
}
void

View File

@ -245,6 +245,8 @@ private:
void UpdateClientOffset();
void DispatchContextMenuEventFromMouseEvent(uint16_t domButton,
GdkEventButton *aEvent);
public:
void ThemeChanged(void);
void OnDPIChanged(void);

View File

@ -1218,6 +1218,22 @@ nsBaseWidget::DispatchEventToAPZOnly(mozilla::WidgetInputEvent* aEvent)
}
}
// static
bool
nsBaseWidget::ShowContextMenuAfterMouseUp()
{
static bool gContextMenuAfterMouseUp = false;
static bool gContextMenuAfterMouseUpCached = false;
if (!gContextMenuAfterMouseUpCached) {
Preferences::AddBoolVarCache(&gContextMenuAfterMouseUp,
"ui.context_menus.after_mouseup",
false);
gContextMenuAfterMouseUpCached = true;
}
return gContextMenuAfterMouseUp;
}
nsIDocument*
nsBaseWidget::GetDocument() const
{

View File

@ -417,6 +417,12 @@ public:
void RecvScreenPixels(mozilla::ipc::Shmem&& aMem, const ScreenIntSize& aSize) override {};
#endif
/**
* Whether context menus should only appear on mouseup instead of mousedown,
* on OSes where they normally appear on mousedown (macOS, *nix).
*/
static bool ShowContextMenuAfterMouseUp();
protected:
// These are methods for CompositorWidgetWrapper, and should only be
// accessed from that class. Derived widgets can choose which methods to