From 07d3a9d10935bad94ff51a344684c2ca2c99313e Mon Sep 17 00:00:00 2001 From: Masayuki Nakano Date: Wed, 22 Feb 2012 16:34:31 +0900 Subject: [PATCH] Bug 630813 part.7 Implement IsKeyPressEventNecessary() in mozilla::widget::KeymapWrapper r=karlt --- widget/gtk2/nsGtkKeyUtils.cpp | 18 ++++++++++++++++++ widget/gtk2/nsGtkKeyUtils.h | 6 ++++++ widget/gtk2/nsWindow.cpp | 9 +-------- 3 files changed, 25 insertions(+), 8 deletions(-) diff --git a/widget/gtk2/nsGtkKeyUtils.cpp b/widget/gtk2/nsGtkKeyUtils.cpp index c608d25d835..2969c325598 100644 --- a/widget/gtk2/nsGtkKeyUtils.cpp +++ b/widget/gtk2/nsGtkKeyUtils.cpp @@ -942,5 +942,23 @@ KeymapWrapper::InitKeypressEvent(nsKeyEvent& aKeyEvent, altLatinCharCodes.mShiftedCharCode)); } +/* static */ bool +KeymapWrapper::IsKeyPressEventNecessary(GdkEventKey* aGdkKeyEvent) +{ + // If this is a modifier key event, we shouldn't send keypress event. + switch (ComputeDOMKeyCode(aGdkKeyEvent->keyval)) { + case NS_VK_SHIFT: + case NS_VK_CONTROL: + case NS_VK_META: + case NS_VK_ALT: + case NS_VK_CAPS_LOCK: + case NS_VK_NUM_LOCK: + case NS_VK_SCROLL_LOCK: + return false; + default: + return true; + } +} + } // namespace widget } // namespace mozilla diff --git a/widget/gtk2/nsGtkKeyUtils.h b/widget/gtk2/nsGtkKeyUtils.h index fe906acd701..1c75b85b1aa 100644 --- a/widget/gtk2/nsGtkKeyUtils.h +++ b/widget/gtk2/nsGtkKeyUtils.h @@ -133,6 +133,12 @@ public: */ static void InitKeyEvent(nsKeyEvent& aKeyEvent, GdkEventKey* aGdkKeyEvent); + /** + * IsKeyPressEventNecessary() returns TRUE when aGdkKeyEvent should cause + * a DOM keypress event. Otherwise, FALSE. + */ + static bool IsKeyPressEventNecessary(GdkEventKey* aGdkKeyEvent); + protected: /** diff --git a/widget/gtk2/nsWindow.cpp b/widget/gtk2/nsWindow.cpp index c99a860b4d2..e2c2155fbcc 100644 --- a/widget/gtk2/nsWindow.cpp +++ b/widget/gtk2/nsWindow.cpp @@ -2996,14 +2996,7 @@ nsWindow::OnKeyPressEvent(GtkWidget *aWidget, GdkEventKey *aEvent) // TODO: Instead of selectively excluding some keys from NS_KEY_PRESS events, // we should instead selectively include (as per MSDN spec; no official // spec covers KeyPress events). - if (aEvent->keyval == GDK_Shift_L - || aEvent->keyval == GDK_Shift_R - || aEvent->keyval == GDK_Control_L - || aEvent->keyval == GDK_Control_R - || aEvent->keyval == GDK_Alt_L - || aEvent->keyval == GDK_Alt_R - || aEvent->keyval == GDK_Meta_L - || aEvent->keyval == GDK_Meta_R) { + if (!KeymapWrapper::IsKeyPressEventNecessary(aEvent)) { return TRUE; }