diff --git a/widget/gtk2/nsGtkKeyUtils.cpp b/widget/gtk2/nsGtkKeyUtils.cpp index c5fba595ab8..01a05aa4fdf 100644 --- a/widget/gtk2/nsGtkKeyUtils.cpp +++ b/widget/gtk2/nsGtkKeyUtils.cpp @@ -562,11 +562,86 @@ KeymapWrapper::InitInputEvent(nsInputEvent& aInputEvent, aInputEvent.isMeta = false; PR_LOG(gKeymapWrapperLog, PR_LOG_DEBUG, - ("KeymapWrapper(%p): InitInputEvent, aModifierState=0x%08X " - "aKeyEvent={ isShift=%s, isControl=%s, isAlt=%s, isMeta=%s }", + ("KeymapWrapper(%p): InitInputEvent, aModifierState=0x%08X, " + "aInputEvent={ isShift=%s, isControl=%s, isAlt=%s, isMeta=%s }", keymapWrapper, aModifierState, GetBoolName(aInputEvent.isShift), GetBoolName(aInputEvent.isControl), GetBoolName(aInputEvent.isAlt), GetBoolName(aInputEvent.isMeta))); + + switch(aInputEvent.eventStructType) { + case NS_MOUSE_EVENT: + case NS_MOUSE_SCROLL_EVENT: + case NS_DRAG_EVENT: + case NS_SIMPLE_GESTURE_EVENT: + case NS_MOZTOUCH_EVENT: + break; + default: + return; + } + + nsMouseEvent_base& mouseEvent = static_cast(aInputEvent); + mouseEvent.modifiers = 0; + if (aInputEvent.isShift) { + mouseEvent.modifiers |= MODIFIER_SHIFT; + } + if (aInputEvent.isControl) { + mouseEvent.modifiers |= MODIFIER_CONTROL; + } + if (aInputEvent.isAlt) { + mouseEvent.modifiers |= MODIFIER_ALT; + } + if (keymapWrapper->AreModifiersActive(SUPER, aModifierState) || + keymapWrapper->AreModifiersActive(HYPER, aModifierState)) { + mouseEvent.modifiers |= MODIFIER_WIN; + } + if (keymapWrapper->AreModifiersActive(ALTGR, aModifierState)) { + mouseEvent.modifiers |= MODIFIER_ALTGRAPH; + } + if (keymapWrapper->AreModifiersActive(CAPS_LOCK, aModifierState)) { + mouseEvent.modifiers |= MODIFIER_CAPSLOCK; + } + if (keymapWrapper->AreModifiersActive(NUM_LOCK, aModifierState)) { + mouseEvent.modifiers |= MODIFIER_NUMLOCK; + } + if (keymapWrapper->AreModifiersActive(SCROLL_LOCK, aModifierState)) { + mouseEvent.modifiers |= MODIFIER_SCROLL; + } + + PR_LOG(gKeymapWrapperLog, PR_LOG_DEBUG, + ("KeymapWrapper(%p): InitInputEvent, aInputEvent has modifiers, " + "aInputEvent.modifiers=0x%04X (Shift: %s, Control: %s, Alt: %s, " + "Win: %s, AltGr: %s, CapsLock: %s, NumLock: %s, ScrollLock: %s)", + keymapWrapper, mouseEvent.modifiers, + GetBoolName(mouseEvent.modifiers & MODIFIER_SHIFT), + GetBoolName(mouseEvent.modifiers & MODIFIER_CONTROL), + GetBoolName(mouseEvent.modifiers & MODIFIER_ALT), + GetBoolName(mouseEvent.modifiers & MODIFIER_WIN), + GetBoolName(mouseEvent.modifiers & MODIFIER_ALTGRAPH), + GetBoolName(mouseEvent.modifiers & MODIFIER_CAPSLOCK), + GetBoolName(mouseEvent.modifiers & MODIFIER_NUMLOCK), + GetBoolName(mouseEvent.modifiers & MODIFIER_SCROLL))); + + mouseEvent.buttons = 0; + if (aModifierState & GDK_BUTTON1_MASK) { + mouseEvent.buttons |= nsMouseEvent::eLeftButtonFlag; + } + if (aModifierState & GDK_BUTTON3_MASK) { + mouseEvent.buttons |= nsMouseEvent::eRightButtonFlag; + } + if (aModifierState & GDK_BUTTON2_MASK) { + mouseEvent.buttons |= nsMouseEvent::eMiddleButtonFlag; + } + + PR_LOG(gKeymapWrapperLog, PR_LOG_DEBUG, + ("KeymapWrapper(%p): InitInputEvent, aInputEvent has buttons, " + "aInputEvent.buttons=0x%04X (Left: %s, Right: %s, Middle: %s, " + "4th (BACK): %s, 5th (FORWARD): %s)", + keymapWrapper, mouseEvent.buttons, + GetBoolName(mouseEvent.buttons & nsMouseEvent::eLeftButtonFlag), + GetBoolName(mouseEvent.buttons & nsMouseEvent::eRightButtonFlag), + GetBoolName(mouseEvent.buttons & nsMouseEvent::eMiddleButtonFlag), + GetBoolName(mouseEvent.buttons & nsMouseEvent::e4thButtonFlag), + GetBoolName(mouseEvent.buttons & nsMouseEvent::e5thButtonFlag))); } /* static */ PRUint32 diff --git a/widget/gtk2/nsWindow.cpp b/widget/gtk2/nsWindow.cpp index 78d2adecb83..6ae3daeb088 100644 --- a/widget/gtk2/nsWindow.cpp +++ b/widget/gtk2/nsWindow.cpp @@ -2656,7 +2656,27 @@ nsWindow::InitButtonEvent(nsMouseEvent &aEvent, aEvent.refPoint = point - WidgetToScreenOffset(); } - KeymapWrapper::InitInputEvent(aEvent, aGdkEvent->state); + guint modifierState = aGdkEvent->state; + // aEvent's state doesn't include this event's information. Therefore, + // if aEvent is mouse button down event, we need to set it manually. + // Note that we cannot do same thing for NS_MOUSE_BUTTON_UP because + // system may have two or more mice and same button of another mouse + // may be still pressed. + if (aGdkEvent->type != GDK_BUTTON_RELEASE) { + switch (aGdkEvent->button) { + case 1: + modifierState |= GDK_BUTTON1_MASK; + break; + case 2: + modifierState |= GDK_BUTTON2_MASK; + break; + case 3: + modifierState |= GDK_BUTTON3_MASK; + break; + } + } + + KeymapWrapper::InitInputEvent(aEvent, modifierState); aEvent.time = aGdkEvent->time;