Bug 630813 part.7 Implement IsKeyPressEventNecessary() in mozilla::widget::KeymapWrapper r=karlt

This commit is contained in:
Masayuki Nakano 2012-02-22 16:34:31 +09:00
Родитель 6ec24bfd10
Коммит 07d3a9d109
3 изменённых файлов: 25 добавлений и 8 удалений

Просмотреть файл

@ -942,5 +942,23 @@ KeymapWrapper::InitKeypressEvent(nsKeyEvent& aKeyEvent,
altLatinCharCodes.mShiftedCharCode)); 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 widget
} // namespace mozilla } // namespace mozilla

Просмотреть файл

@ -133,6 +133,12 @@ public:
*/ */
static void InitKeyEvent(nsKeyEvent& aKeyEvent, GdkEventKey* aGdkKeyEvent); 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: protected:
/** /**

Просмотреть файл

@ -2996,14 +2996,7 @@ nsWindow::OnKeyPressEvent(GtkWidget *aWidget, GdkEventKey *aEvent)
// TODO: Instead of selectively excluding some keys from NS_KEY_PRESS events, // TODO: Instead of selectively excluding some keys from NS_KEY_PRESS events,
// we should instead selectively include (as per MSDN spec; no official // we should instead selectively include (as per MSDN spec; no official
// spec covers KeyPress events). // spec covers KeyPress events).
if (aEvent->keyval == GDK_Shift_L if (!KeymapWrapper::IsKeyPressEventNecessary(aEvent)) {
|| 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) {
return TRUE; return TRUE;
} }