Bug 1337718 part.5 Make IsCtrlShiftPressed() take const WidgetKeyboardEvent* instead of nsIDOMKeyEvent* r?m_kato
Additionally, this patch removes unnecessary name space wrapper of IsCtrlShiftPressed(). Perhaps, it was necessary when mozilla::EditorEventListener was nsEditorEventListener.
MozReview-Commit-ID: EHzt7aRtYgQ
--- a/editor/libeditor/EditorEventListener.cpp
+++ b/editor/libeditor/EditorEventListener.cpp
@@ -488,60 +488,54 @@ EditorEventListener::HandleEvent(nsIDOME
NS_ConvertUTF16toUTF8(eventType).get());
NS_ASSERTION(false, assertMessage.get());
#endif
return NS_OK;
}
#ifdef HANDLE_NATIVE_TEXT_DIRECTION_SWITCH
-namespace {
// This function is borrowed from Chromium's ImeInput::IsCtrlShiftPressed
-bool IsCtrlShiftPressed(nsIDOMKeyEvent* aEvent, bool& isRTL)
+bool IsCtrlShiftPressed(const WidgetKeyboardEvent* aKeyboardEvent, bool& isRTL)
{
+ MOZ_ASSERT(aKeyboardEvent);
// To check if a user is pressing only a control key and a right-shift key
// (or a left-shift key), we use the steps below:
// 1. Check if a user is pressing a control key and a right-shift key (or
// a left-shift key).
// 2. If the condition 1 is true, we should check if there are any other
// keys pressed at the same time.
// To ignore the keys checked in 1, we set their status to 0 before
// checking the key status.
- WidgetKeyboardEvent* keyboardEvent =
- aEvent->AsEvent()->WidgetEventPtr()->AsKeyboardEvent();
- MOZ_ASSERT(keyboardEvent,
- "DOM key event's internal event must be WidgetKeyboardEvent");
- if (!keyboardEvent->IsControl()) {
+ if (!aKeyboardEvent->IsControl()) {
return false;
}
- switch (keyboardEvent->mLocation) {
+ switch (aKeyboardEvent->mLocation) {
case eKeyLocationRight:
isRTL = true;
break;
case eKeyLocationLeft:
isRTL = false;
break;
default:
return false;
}
// Scan the key status to find pressed keys. We should abandon changing the
// text direction when there are other pressed keys.
- if (keyboardEvent->IsAlt() || keyboardEvent->IsOS()) {
+ if (aKeyboardEvent->IsAlt() || aKeyboardEvent->IsOS()) {
return false;
}
return true;
}
-}
-
// This logic is mostly borrowed from Chromium's
// RenderWidgetHostViewWin::OnKeyEvent.
nsresult
EditorEventListener::KeyUp(const WidgetKeyboardEvent* aKeyboardEvent)
{
if (NS_WARN_IF(!aKeyboardEvent) || DetachedFromEditor()) {
return NS_OK;
@@ -575,27 +569,30 @@ EditorEventListener::KeyDown(nsIDOMKeyEv
return NS_OK;
}
// XXX Why isn't this method check if it's consumed?
uint32_t keyCode = 0;
aKeyEvent->GetKeyCode(&keyCode);
if (keyCode == nsIDOMKeyEvent::DOM_VK_SHIFT) {
bool switchToRTL;
- if (IsCtrlShiftPressed(aKeyEvent, switchToRTL)) {
+ WidgetKeyboardEvent* keydownEvent =
+ aKeyEvent->AsEvent()->WidgetEventPtr()->AsKeyboardEvent();
+ if (IsCtrlShiftPressed(keydownEvent, switchToRTL)) {
mShouldSwitchTextDirection = true;
mSwitchToRTL = switchToRTL;
}
} else if (keyCode != nsIDOMKeyEvent::DOM_VK_CONTROL) {
// In case the user presses any other key besides Ctrl and Shift
mShouldSwitchTextDirection = false;
}
return NS_OK;
}
-#endif
+
+#endif // #ifdef HANDLE_NATIVE_TEXT_DIRECTION_SWITCH
nsresult
EditorEventListener::KeyPress(WidgetKeyboardEvent* aKeyboardEvent)
{
if (NS_WARN_IF(!aKeyboardEvent)) {
return NS_OK;
}