Bug 1337718 part.5 Make IsCtrlShiftPressed() take const WidgetKeyboardEvent* instead of nsIDOMKeyEvent* r?m_kato draft
authorMasayuki Nakano <masayuki@d-toybox.com>
Wed, 08 Feb 2017 20:05:12 +0900
changeset 481125 8e01c92fe924778d7d6a2613ffda2629ec617d15
parent 481124 2c94b114eeba9e5ebca17debf726bbe10c05a88e
child 481126 f61b3dc99264a03f7ca3f07376545ef9cf43d4d5
push id44730
push usermasayuki@d-toybox.com
push dateThu, 09 Feb 2017 09:50:16 +0000
reviewersm_kato
bugs1337718
milestone54.0a1
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
editor/libeditor/EditorEventListener.cpp
--- 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;
   }