Bug 1546839 - part 1: Change `enum Command` to `enum class Command` and drop "Command" prefix from each item r=smaug
authorMasayuki Nakano <masayuki@d-toybox.com>
Tue, 30 Apr 2019 04:23:24 +0000
changeset 471886 2392ec437b0b5b4edd143b027114dc336bcb5084
parent 471885 0c7f3a7403bd17f2d0bb2d17cba47ea02b86c12a
child 471887 6d9207d2881a03f927ea57a47a4966748e7fae92
push id112959
push userarchaeopteryx@coole-files.de
push dateTue, 30 Apr 2019 11:38:46 +0000
treeherdermozilla-inbound@25e7e6e1239a [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerssmaug
bugs1546839
milestone68.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1546839 - part 1: Change `enum Command` to `enum class Command` and drop "Command" prefix from each item r=smaug If I remember correctly, `enum class` was not allowed when I added `enum Command`. Now, we can make it `enum class` for better type check at compile time. Differential Revision: https://phabricator.services.mozilla.com/D29169
widget/EventForwards.h
widget/WidgetEventImpl.cpp
widget/cocoa/NativeKeyBindings.h
widget/cocoa/NativeKeyBindings.mm
widget/cocoa/TextInputHandler.h
widget/cocoa/TextInputHandler.mm
widget/cocoa/nsChildView.mm
widget/gtk/NativeKeyBindings.cpp
--- a/widget/EventForwards.h
+++ b/widget/EventForwards.h
@@ -197,22 +197,22 @@ inline bool IsDataTransferAvailableOnHTM
     case EditorInputType::eInsertReplacementText:
     case EditorInputType::eInsertFromYank:
       return true;
     default:
       return false;
   }
 }
 
-#define NS_DEFINE_COMMAND(aName, aCommandStr) , Command##aName
-#define NS_DEFINE_COMMAND_NO_EXEC_COMMAND(aName) , Command##aName
+#define NS_DEFINE_COMMAND(aName, aCommandStr) , aName
+#define NS_DEFINE_COMMAND_NO_EXEC_COMMAND(aName) , aName
 
 typedef int8_t CommandInt;
-enum Command : CommandInt {
-  CommandDoNothing
+enum class Command : CommandInt {
+  DoNothing
 
 #include "mozilla/CommandList.h"
 };
 #undef NS_DEFINE_COMMAND
 #undef NS_DEFINE_COMMAND_NO_EXEC_COMMAND
 
 const char* ToChar(Command aCommand);
 
--- a/widget/WidgetEventImpl.cpp
+++ b/widget/WidgetEventImpl.cpp
@@ -71,27 +71,27 @@ const nsCString ToString(CodeNameIndex a
     return NS_LITERAL_CSTRING("USE_STRING");
   }
   nsAutoString codeName;
   WidgetKeyboardEvent::GetDOMCodeName(aCodeNameIndex, codeName);
   return NS_ConvertUTF16toUTF8(codeName);
 }
 
 const char* ToChar(Command aCommand) {
-  if (aCommand == CommandDoNothing) {
+  if (aCommand == Command::DoNothing) {
     return "CommandDoNothing";
   }
 
   switch (aCommand) {
 #define NS_DEFINE_COMMAND(aName, aCommandStr) \
-  case Command##aName:                        \
-    return "Command" #aName;
+  case Command::aName:                        \
+    return "Command::" #aName;
 #define NS_DEFINE_COMMAND_NO_EXEC_COMMAND(aName) \
-  case Command##aName:                           \
-    return "Command" #aName;
+  case Command::aName:                           \
+    return "Command::" #aName;
 
 #include "mozilla/CommandList.h"
 
 #undef NS_DEFINE_COMMAND
 #undef NS_DEFINE_COMMAND_NO_EXEC_COMMAND
 
     default:
       return "illegal command value";
@@ -1095,25 +1095,25 @@ uint32_t WidgetKeyboardEvent::GetFallbac
       return 0;
   }
 }
 
 /* static */ const char* WidgetKeyboardEvent::GetCommandStr(Command aCommand) {
 #define NS_DEFINE_COMMAND(aName, aCommandStr) , #aCommandStr
 #define NS_DEFINE_COMMAND_NO_EXEC_COMMAND(aName)
   static const char* const kCommands[] = {
-      ""  // CommandDoNothing
+      ""  // DoNothing
 #include "mozilla/CommandList.h"
   };
 #undef NS_DEFINE_COMMAND
 #undef NS_DEFINE_COMMAND_NO_EXEC_COMMAND
 
   MOZ_RELEASE_ASSERT(static_cast<size_t>(aCommand) < ArrayLength(kCommands),
                      "Illegal command enumeration value");
-  return kCommands[aCommand];
+  return kCommands[static_cast<CommandInt>(aCommand)];
 }
 
 /* static */
 uint32_t WidgetKeyboardEvent::ComputeLocationFromCodeValue(
     CodeNameIndex aCodeNameIndex) {
   // Following commented out cases are not defined in PhysicalKeyCodeNameList.h
   // but are defined by D3E spec.  So, they should be uncommented when the
   // code values are defined in the header.
--- a/widget/cocoa/NativeKeyBindings.h
+++ b/widget/cocoa/NativeKeyBindings.h
@@ -10,17 +10,17 @@
 #include "mozilla/Attributes.h"
 #include "mozilla/EventForwards.h"
 #include "nsDataHashtable.h"
 #include "nsIWidget.h"
 
 namespace mozilla {
 namespace widget {
 
-typedef nsDataHashtable<nsPtrHashKey<struct objc_selector>, CommandInt>
+typedef nsDataHashtable<nsPtrHashKey<struct objc_selector>, Command>
     SelectorCommandHashtable;
 
 class NativeKeyBindings final {
   typedef nsIWidget::NativeKeyBindingsType NativeKeyBindingsType;
 
  public:
   static NativeKeyBindings* GetInstance(NativeKeyBindingsType aType);
   static void Shutdown();
--- a/widget/cocoa/NativeKeyBindings.mm
+++ b/widget/cocoa/NativeKeyBindings.mm
@@ -65,109 +65,109 @@ void NativeKeyBindings::Init(NativeKeyBi
   // TODO: Improves correctness of left / right meaning
   // TODO: Add real paragraph motions
 
   // SEL_TO_COMMAND(cancelOperation:, );
   // SEL_TO_COMMAND(capitalizeWord:, );
   // SEL_TO_COMMAND(centerSelectionInVisibleArea:, );
   // SEL_TO_COMMAND(changeCaseOfLetter:, );
   // SEL_TO_COMMAND(complete:, );
-  SEL_TO_COMMAND(copy:, CommandCopy);
+  SEL_TO_COMMAND(copy:, Command::Copy);
   // SEL_TO_COMMAND(copyFont:, );
   // SEL_TO_COMMAND(copyRuler:, );
-  SEL_TO_COMMAND(cut:, CommandCut);
-  SEL_TO_COMMAND(delete:, CommandDelete);
-  SEL_TO_COMMAND(deleteBackward:, CommandDeleteCharBackward);
+  SEL_TO_COMMAND(cut:, Command::Cut);
+  SEL_TO_COMMAND(delete:, Command::Delete);
+  SEL_TO_COMMAND(deleteBackward:, Command::DeleteCharBackward);
   // SEL_TO_COMMAND(deleteBackwardByDecomposingPreviousCharacter:, );
-  SEL_TO_COMMAND(deleteForward:, CommandDeleteCharForward);
+  SEL_TO_COMMAND(deleteForward:, Command::DeleteCharForward);
 
   // TODO: deleteTo* selectors are also supposed to add text to a kill buffer
-  SEL_TO_COMMAND(deleteToBeginningOfLine:, CommandDeleteToBeginningOfLine);
-  SEL_TO_COMMAND(deleteToBeginningOfParagraph:, CommandDeleteToBeginningOfLine);
-  SEL_TO_COMMAND(deleteToEndOfLine:, CommandDeleteToEndOfLine);
-  SEL_TO_COMMAND(deleteToEndOfParagraph:, CommandDeleteToEndOfLine);
+  SEL_TO_COMMAND(deleteToBeginningOfLine:, Command::DeleteToBeginningOfLine);
+  SEL_TO_COMMAND(deleteToBeginningOfParagraph:, Command::DeleteToBeginningOfLine);
+  SEL_TO_COMMAND(deleteToEndOfLine:, Command::DeleteToEndOfLine);
+  SEL_TO_COMMAND(deleteToEndOfParagraph:, Command::DeleteToEndOfLine);
   // SEL_TO_COMMAND(deleteToMark:, );
 
-  SEL_TO_COMMAND(deleteWordBackward:, CommandDeleteWordBackward);
-  SEL_TO_COMMAND(deleteWordForward:, CommandDeleteWordForward);
+  SEL_TO_COMMAND(deleteWordBackward:, Command::DeleteWordBackward);
+  SEL_TO_COMMAND(deleteWordForward:, Command::DeleteWordForward);
   // SEL_TO_COMMAND(indent:, );
   // SEL_TO_COMMAND(insertBacktab:, );
   // SEL_TO_COMMAND(insertContainerBreak:, );
   // SEL_TO_COMMAND(insertLineBreak:, );
   // SEL_TO_COMMAND(insertNewline:, );
   // SEL_TO_COMMAND(insertNewlineIgnoringFieldEditor:, );
   // SEL_TO_COMMAND(insertParagraphSeparator:, );
   // SEL_TO_COMMAND(insertTab:, );
   // SEL_TO_COMMAND(insertTabIgnoringFieldEditor:, );
   // SEL_TO_COMMAND(insertDoubleQuoteIgnoringSubstitution:, );
   // SEL_TO_COMMAND(insertSingleQuoteIgnoringSubstitution:, );
   // SEL_TO_COMMAND(lowercaseWord:, );
-  SEL_TO_COMMAND(moveBackward:, CommandCharPrevious);
-  SEL_TO_COMMAND(moveBackwardAndModifySelection:, CommandSelectCharPrevious);
+  SEL_TO_COMMAND(moveBackward:, Command::CharPrevious);
+  SEL_TO_COMMAND(moveBackwardAndModifySelection:, Command::SelectCharPrevious);
   if (aType == nsIWidget::NativeKeyBindingsForSingleLineEditor) {
-    SEL_TO_COMMAND(moveDown:, CommandEndLine);
+    SEL_TO_COMMAND(moveDown:, Command::EndLine);
   } else {
-    SEL_TO_COMMAND(moveDown:, CommandLineNext);
+    SEL_TO_COMMAND(moveDown:, Command::LineNext);
   }
-  SEL_TO_COMMAND(moveDownAndModifySelection:, CommandSelectLineNext);
-  SEL_TO_COMMAND(moveForward:, CommandCharNext);
-  SEL_TO_COMMAND(moveForwardAndModifySelection:, CommandSelectCharNext);
-  SEL_TO_COMMAND(moveLeft:, CommandCharPrevious);
-  SEL_TO_COMMAND(moveLeftAndModifySelection:, CommandSelectCharPrevious);
-  SEL_TO_COMMAND(moveParagraphBackwardAndModifySelection:, CommandSelectBeginLine);
-  SEL_TO_COMMAND(moveParagraphForwardAndModifySelection:, CommandSelectEndLine);
-  SEL_TO_COMMAND(moveRight:, CommandCharNext);
-  SEL_TO_COMMAND(moveRightAndModifySelection:, CommandSelectCharNext);
-  SEL_TO_COMMAND(moveToBeginningOfDocument:, CommandMoveTop);
-  SEL_TO_COMMAND(moveToBeginningOfDocumentAndModifySelection:, CommandSelectTop);
-  SEL_TO_COMMAND(moveToBeginningOfLine:, CommandBeginLine);
-  SEL_TO_COMMAND(moveToBeginningOfLineAndModifySelection:, CommandSelectBeginLine);
-  SEL_TO_COMMAND(moveToBeginningOfParagraph:, CommandBeginLine);
-  SEL_TO_COMMAND(moveToBeginningOfParagraphAndModifySelection:, CommandSelectBeginLine);
-  SEL_TO_COMMAND(moveToEndOfDocument:, CommandMoveBottom);
-  SEL_TO_COMMAND(moveToEndOfDocumentAndModifySelection:, CommandSelectBottom);
-  SEL_TO_COMMAND(moveToEndOfLine:, CommandEndLine);
-  SEL_TO_COMMAND(moveToEndOfLineAndModifySelection:, CommandSelectEndLine);
-  SEL_TO_COMMAND(moveToEndOfParagraph:, CommandEndLine);
-  SEL_TO_COMMAND(moveToEndOfParagraphAndModifySelection:, CommandSelectEndLine);
-  SEL_TO_COMMAND(moveToLeftEndOfLine:, CommandBeginLine);
-  SEL_TO_COMMAND(moveToLeftEndOfLineAndModifySelection:, CommandSelectBeginLine);
-  SEL_TO_COMMAND(moveToRightEndOfLine:, CommandEndLine);
-  SEL_TO_COMMAND(moveToRightEndOfLineAndModifySelection:, CommandSelectEndLine);
+  SEL_TO_COMMAND(moveDownAndModifySelection:, Command::SelectLineNext);
+  SEL_TO_COMMAND(moveForward:, Command::CharNext);
+  SEL_TO_COMMAND(moveForwardAndModifySelection:, Command::SelectCharNext);
+  SEL_TO_COMMAND(moveLeft:, Command::CharPrevious);
+  SEL_TO_COMMAND(moveLeftAndModifySelection:, Command::SelectCharPrevious);
+  SEL_TO_COMMAND(moveParagraphBackwardAndModifySelection:, Command::SelectBeginLine);
+  SEL_TO_COMMAND(moveParagraphForwardAndModifySelection:, Command::SelectEndLine);
+  SEL_TO_COMMAND(moveRight:, Command::CharNext);
+  SEL_TO_COMMAND(moveRightAndModifySelection:, Command::SelectCharNext);
+  SEL_TO_COMMAND(moveToBeginningOfDocument:, Command::MoveTop);
+  SEL_TO_COMMAND(moveToBeginningOfDocumentAndModifySelection:, Command::SelectTop);
+  SEL_TO_COMMAND(moveToBeginningOfLine:, Command::BeginLine);
+  SEL_TO_COMMAND(moveToBeginningOfLineAndModifySelection:, Command::SelectBeginLine);
+  SEL_TO_COMMAND(moveToBeginningOfParagraph:, Command::BeginLine);
+  SEL_TO_COMMAND(moveToBeginningOfParagraphAndModifySelection:, Command::SelectBeginLine);
+  SEL_TO_COMMAND(moveToEndOfDocument:, Command::MoveBottom);
+  SEL_TO_COMMAND(moveToEndOfDocumentAndModifySelection:, Command::SelectBottom);
+  SEL_TO_COMMAND(moveToEndOfLine:, Command::EndLine);
+  SEL_TO_COMMAND(moveToEndOfLineAndModifySelection:, Command::SelectEndLine);
+  SEL_TO_COMMAND(moveToEndOfParagraph:, Command::EndLine);
+  SEL_TO_COMMAND(moveToEndOfParagraphAndModifySelection:, Command::SelectEndLine);
+  SEL_TO_COMMAND(moveToLeftEndOfLine:, Command::BeginLine);
+  SEL_TO_COMMAND(moveToLeftEndOfLineAndModifySelection:, Command::SelectBeginLine);
+  SEL_TO_COMMAND(moveToRightEndOfLine:, Command::EndLine);
+  SEL_TO_COMMAND(moveToRightEndOfLineAndModifySelection:, Command::SelectEndLine);
   if (aType == nsIWidget::NativeKeyBindingsForSingleLineEditor) {
-    SEL_TO_COMMAND(moveUp:, CommandBeginLine);
+    SEL_TO_COMMAND(moveUp:, Command::BeginLine);
   } else {
-    SEL_TO_COMMAND(moveUp:, CommandLinePrevious);
+    SEL_TO_COMMAND(moveUp:, Command::LinePrevious);
   }
-  SEL_TO_COMMAND(moveUpAndModifySelection:, CommandSelectLinePrevious);
-  SEL_TO_COMMAND(moveWordBackward:, CommandWordPrevious);
-  SEL_TO_COMMAND(moveWordBackwardAndModifySelection:, CommandSelectWordPrevious);
-  SEL_TO_COMMAND(moveWordForward:, CommandWordNext);
-  SEL_TO_COMMAND(moveWordForwardAndModifySelection:, CommandSelectWordNext);
-  SEL_TO_COMMAND(moveWordLeft:, CommandWordPrevious);
-  SEL_TO_COMMAND(moveWordLeftAndModifySelection:, CommandSelectWordPrevious);
-  SEL_TO_COMMAND(moveWordRight:, CommandWordNext);
-  SEL_TO_COMMAND(moveWordRightAndModifySelection:, CommandSelectWordNext);
-  SEL_TO_COMMAND(pageDown:, CommandMovePageDown);
-  SEL_TO_COMMAND(pageDownAndModifySelection:, CommandSelectPageDown);
-  SEL_TO_COMMAND(pageUp:, CommandMovePageUp);
-  SEL_TO_COMMAND(pageUpAndModifySelection:, CommandSelectPageUp);
-  SEL_TO_COMMAND(paste:, CommandPaste);
+  SEL_TO_COMMAND(moveUpAndModifySelection:, Command::SelectLinePrevious);
+  SEL_TO_COMMAND(moveWordBackward:, Command::WordPrevious);
+  SEL_TO_COMMAND(moveWordBackwardAndModifySelection:, Command::SelectWordPrevious);
+  SEL_TO_COMMAND(moveWordForward:, Command::WordNext);
+  SEL_TO_COMMAND(moveWordForwardAndModifySelection:, Command::SelectWordNext);
+  SEL_TO_COMMAND(moveWordLeft:, Command::WordPrevious);
+  SEL_TO_COMMAND(moveWordLeftAndModifySelection:, Command::SelectWordPrevious);
+  SEL_TO_COMMAND(moveWordRight:, Command::WordNext);
+  SEL_TO_COMMAND(moveWordRightAndModifySelection:, Command::SelectWordNext);
+  SEL_TO_COMMAND(pageDown:, Command::MovePageDown);
+  SEL_TO_COMMAND(pageDownAndModifySelection:, Command::SelectPageDown);
+  SEL_TO_COMMAND(pageUp:, Command::MovePageUp);
+  SEL_TO_COMMAND(pageUpAndModifySelection:, Command::SelectPageUp);
+  SEL_TO_COMMAND(paste:, Command::Paste);
   // SEL_TO_COMMAND(pasteFont:, );
   // SEL_TO_COMMAND(pasteRuler:, );
-  SEL_TO_COMMAND(scrollLineDown:, CommandScrollLineDown);
-  SEL_TO_COMMAND(scrollLineUp:, CommandScrollLineUp);
-  SEL_TO_COMMAND(scrollPageDown:, CommandScrollPageDown);
-  SEL_TO_COMMAND(scrollPageUp:, CommandScrollPageUp);
-  SEL_TO_COMMAND(scrollToBeginningOfDocument:, CommandScrollTop);
-  SEL_TO_COMMAND(scrollToEndOfDocument:, CommandScrollBottom);
-  SEL_TO_COMMAND(selectAll:, CommandSelectAll);
+  SEL_TO_COMMAND(scrollLineDown:, Command::ScrollLineDown);
+  SEL_TO_COMMAND(scrollLineUp:, Command::ScrollLineUp);
+  SEL_TO_COMMAND(scrollPageDown:, Command::ScrollPageDown);
+  SEL_TO_COMMAND(scrollPageUp:, Command::ScrollPageUp);
+  SEL_TO_COMMAND(scrollToBeginningOfDocument:, Command::ScrollTop);
+  SEL_TO_COMMAND(scrollToEndOfDocument:, Command::ScrollBottom);
+  SEL_TO_COMMAND(selectAll:, Command::SelectAll);
   // selectLine: is complex, see KeyDown
   if (aType == nsIWidget::NativeKeyBindingsForSingleLineEditor) {
-    SEL_TO_COMMAND(selectParagraph:, CommandSelectAll);
+    SEL_TO_COMMAND(selectParagraph:, Command::SelectAll);
   }
   // SEL_TO_COMMAND(selectToMark:, );
   // selectWord: is complex, see KeyDown
   // SEL_TO_COMMAND(setMark:, );
   // SEL_TO_COMMAND(showContextHelp:, );
   // SEL_TO_COMMAND(supplementalTargetForAction:sender:, );
   // SEL_TO_COMMAND(swapWithMark:, );
   // SEL_TO_COMMAND(transpose:, );
@@ -215,33 +215,32 @@ void NativeKeyBindings::GetEditCommands(
       nsCocoaUtils::GetStringForNSString(selectorString, nsSelectorString);
 
       MOZ_LOG(gNativeKeyBindingsLog, LogLevel::Info,
               ("%p NativeKeyBindings::GetEditCommands, selector=%s", this,
                NS_LossyConvertUTF16toASCII(nsSelectorString).get()));
     }
 
     // Try to find a simple mapping in the hashtable
-    CommandInt geckoCommand =
-        mSelectorToCommand.Get(reinterpret_cast<struct objc_selector*>(selector));
-
-    if (geckoCommand) {
-      aCommands.AppendElement(geckoCommand);
+    Command geckoCommand = Command::DoNothing;
+    if (mSelectorToCommand.Get(reinterpret_cast<struct objc_selector*>(selector), &geckoCommand) &&
+        geckoCommand != Command::DoNothing) {
+      aCommands.AppendElement(static_cast<CommandInt>(geckoCommand));
     } else if (selector == @selector(selectLine:)) {
       // This is functional, but Cocoa's version is direction-less in that
       // selection direction is not determined until some future directed action
       // is taken. See bug 282097, comment 79 for more details.
-      aCommands.AppendElement(CommandBeginLine);
-      aCommands.AppendElement(CommandSelectEndLine);
+      aCommands.AppendElement(static_cast<CommandInt>(Command::BeginLine));
+      aCommands.AppendElement(static_cast<CommandInt>(Command::SelectEndLine));
     } else if (selector == @selector(selectWord:)) {
       // This is functional, but Cocoa's version is direction-less in that
       // selection direction is not determined until some future directed action
       // is taken. See bug 282097, comment 79 for more details.
-      aCommands.AppendElement(CommandWordPrevious);
-      aCommands.AppendElement(CommandSelectWordNext);
+      aCommands.AppendElement(static_cast<CommandInt>(Command::WordPrevious));
+      aCommands.AppendElement(static_cast<CommandInt>(Command::SelectWordNext));
     }
   }
 
   if (!MOZ_LOG_TEST(gNativeKeyBindingsLog, LogLevel::Info)) {
     return;
   }
 
   if (aCommands.IsEmpty()) {
--- a/widget/cocoa/TextInputHandler.h
+++ b/widget/cocoa/TextInputHandler.h
@@ -607,99 +607,99 @@ class TextInputHandlerBase : public Text
       if (NS_WARN_IF(!mKeyEvent)) {
         return false;
       }
       KeyNameIndex keyNameIndex =
           TISInputSourceWrapper::ComputeGeckoKeyNameIndex([mKeyEvent keyCode]);
       Modifiers modifiers = nsCocoaUtils::ModifiersForEvent(mKeyEvent) &
                             (MODIFIER_SHIFT | MODIFIER_CONTROL | MODIFIER_ALT | MODIFIER_META);
       switch (aCommand) {
-        case CommandInsertLineBreak:
+        case Command::InsertLineBreak:
           return keyNameIndex == KEY_NAME_INDEX_Enter && modifiers == MODIFIER_CONTROL;
-        case CommandInsertParagraph:
+        case Command::InsertParagraph:
           return keyNameIndex == KEY_NAME_INDEX_Enter && modifiers == MODIFIER_NONE;
-        case CommandDeleteCharBackward:
+        case Command::DeleteCharBackward:
           return keyNameIndex == KEY_NAME_INDEX_Backspace && modifiers == MODIFIER_NONE;
-        case CommandDeleteToBeginningOfLine:
+        case Command::DeleteToBeginningOfLine:
           return keyNameIndex == KEY_NAME_INDEX_Backspace && modifiers == MODIFIER_META;
-        case CommandDeleteWordBackward:
+        case Command::DeleteWordBackward:
           return keyNameIndex == KEY_NAME_INDEX_Backspace && modifiers == MODIFIER_ALT;
-        case CommandDeleteCharForward:
+        case Command::DeleteCharForward:
           return keyNameIndex == KEY_NAME_INDEX_Delete && modifiers == MODIFIER_NONE;
-        case CommandDeleteWordForward:
+        case Command::DeleteWordForward:
           return keyNameIndex == KEY_NAME_INDEX_Delete && modifiers == MODIFIER_ALT;
-        case CommandInsertTab:
+        case Command::InsertTab:
           return keyNameIndex == KEY_NAME_INDEX_Tab && modifiers == MODIFIER_NONE;
-        case CommandInsertBacktab:
+        case Command::InsertBacktab:
           return keyNameIndex == KEY_NAME_INDEX_Tab && modifiers == MODIFIER_SHIFT;
-        case CommandCharNext:
+        case Command::CharNext:
           return keyNameIndex == KEY_NAME_INDEX_ArrowRight && modifiers == MODIFIER_NONE;
-        case CommandSelectCharNext:
+        case Command::SelectCharNext:
           return keyNameIndex == KEY_NAME_INDEX_ArrowRight && modifiers == MODIFIER_SHIFT;
-        case CommandWordNext:
+        case Command::WordNext:
           return keyNameIndex == KEY_NAME_INDEX_ArrowRight && modifiers == MODIFIER_ALT;
-        case CommandSelectWordNext:
+        case Command::SelectWordNext:
           return keyNameIndex == KEY_NAME_INDEX_ArrowRight &&
                  modifiers == (MODIFIER_ALT | MODIFIER_SHIFT);
-        case CommandEndLine:
+        case Command::EndLine:
           return keyNameIndex == KEY_NAME_INDEX_ArrowRight && modifiers == MODIFIER_META;
-        case CommandSelectEndLine:
+        case Command::SelectEndLine:
           return keyNameIndex == KEY_NAME_INDEX_ArrowRight &&
                  modifiers == (MODIFIER_META | MODIFIER_SHIFT);
-        case CommandCharPrevious:
+        case Command::CharPrevious:
           return keyNameIndex == KEY_NAME_INDEX_ArrowLeft && modifiers == MODIFIER_NONE;
-        case CommandSelectCharPrevious:
+        case Command::SelectCharPrevious:
           return keyNameIndex == KEY_NAME_INDEX_ArrowLeft && modifiers == MODIFIER_SHIFT;
-        case CommandWordPrevious:
+        case Command::WordPrevious:
           return keyNameIndex == KEY_NAME_INDEX_ArrowLeft && modifiers == MODIFIER_ALT;
-        case CommandSelectWordPrevious:
+        case Command::SelectWordPrevious:
           return keyNameIndex == KEY_NAME_INDEX_ArrowLeft &&
                  modifiers == (MODIFIER_ALT | MODIFIER_SHIFT);
-        case CommandBeginLine:
+        case Command::BeginLine:
           return keyNameIndex == KEY_NAME_INDEX_ArrowLeft && modifiers == MODIFIER_META;
-        case CommandSelectBeginLine:
+        case Command::SelectBeginLine:
           return keyNameIndex == KEY_NAME_INDEX_ArrowLeft &&
                  modifiers == (MODIFIER_META | MODIFIER_SHIFT);
-        case CommandLinePrevious:
+        case Command::LinePrevious:
           return keyNameIndex == KEY_NAME_INDEX_ArrowUp && modifiers == MODIFIER_NONE;
-        case CommandSelectLinePrevious:
+        case Command::SelectLinePrevious:
           return keyNameIndex == KEY_NAME_INDEX_ArrowUp && modifiers == MODIFIER_SHIFT;
-        case CommandMoveTop:
+        case Command::MoveTop:
           return keyNameIndex == KEY_NAME_INDEX_ArrowUp && modifiers == MODIFIER_META;
-        case CommandSelectTop:
+        case Command::SelectTop:
           return (keyNameIndex == KEY_NAME_INDEX_ArrowUp &&
                   modifiers == (MODIFIER_META | MODIFIER_SHIFT)) ||
                  (keyNameIndex == KEY_NAME_INDEX_Home && modifiers == MODIFIER_SHIFT);
-        case CommandLineNext:
+        case Command::LineNext:
           return keyNameIndex == KEY_NAME_INDEX_ArrowDown && modifiers == MODIFIER_NONE;
-        case CommandSelectLineNext:
+        case Command::SelectLineNext:
           return keyNameIndex == KEY_NAME_INDEX_ArrowDown && modifiers == MODIFIER_SHIFT;
-        case CommandMoveBottom:
+        case Command::MoveBottom:
           return keyNameIndex == KEY_NAME_INDEX_ArrowDown && modifiers == MODIFIER_META;
-        case CommandSelectBottom:
+        case Command::SelectBottom:
           return (keyNameIndex == KEY_NAME_INDEX_ArrowDown &&
                   modifiers == (MODIFIER_META | MODIFIER_SHIFT)) ||
                  (keyNameIndex == KEY_NAME_INDEX_End && modifiers == MODIFIER_SHIFT);
-        case CommandScrollPageUp:
+        case Command::ScrollPageUp:
           return keyNameIndex == KEY_NAME_INDEX_PageUp && modifiers == MODIFIER_NONE;
-        case CommandSelectPageUp:
+        case Command::SelectPageUp:
           return keyNameIndex == KEY_NAME_INDEX_PageUp && modifiers == MODIFIER_SHIFT;
-        case CommandScrollPageDown:
+        case Command::ScrollPageDown:
           return keyNameIndex == KEY_NAME_INDEX_PageDown && modifiers == MODIFIER_NONE;
-        case CommandSelectPageDown:
+        case Command::SelectPageDown:
           return keyNameIndex == KEY_NAME_INDEX_PageDown && modifiers == MODIFIER_SHIFT;
-        case CommandScrollBottom:
+        case Command::ScrollBottom:
           return keyNameIndex == KEY_NAME_INDEX_End && modifiers == MODIFIER_NONE;
-        case CommandScrollTop:
+        case Command::ScrollTop:
           return keyNameIndex == KEY_NAME_INDEX_Home && modifiers == MODIFIER_NONE;
-        case CommandCancelOperation:
+        case Command::CancelOperation:
           return (keyNameIndex == KEY_NAME_INDEX_Escape &&
                   (modifiers == MODIFIER_NONE || modifiers == MODIFIER_SHIFT)) ||
                  ([mKeyEvent keyCode] == kVK_ANSI_Period && modifiers == MODIFIER_META);
-        case CommandComplete:
+        case Command::Complete:
           return keyNameIndex == KEY_NAME_INDEX_Escape &&
                  (modifiers == MODIFIER_ALT || modifiers == (MODIFIER_ALT | MODIFIER_SHIFT));
         default:
           return false;
       }
     }
 
     void InitKeyEvent(TextInputHandlerBase* aHandler, WidgetKeyboardEvent& aKeyEvent,
--- a/widget/cocoa/TextInputHandler.mm
+++ b/widget/cocoa/TextInputHandler.mm
@@ -2512,74 +2512,74 @@ bool TextInputHandler::HandleCommand(Com
     return false;
   }
 
   // If it's in composition, we cannot dispatch keypress event.
   // Therefore, we should use different approach or give up to handle
   // the command.
   if (IsIMEComposing()) {
     switch (aCommand) {
-      case CommandInsertLineBreak:
-      case CommandInsertParagraph: {
+      case Command::InsertLineBreak:
+      case Command::InsertParagraph: {
         // Insert '\n' as committing composition.
         // Otherwise, we need to dispatch keypress event because HTMLEditor
         // doesn't treat "\n" in composition string as a line break unless
         // the whitespace is treated as pre (see bug 1350541).  In strictly
         // speaking, we should dispatch keypress event as-is if it's handling
         // NSKeyDown event or should insert it with committing composition.
         NSAttributedString* lineBreaker = [[NSAttributedString alloc] initWithString:@"\n"];
         InsertTextAsCommittingComposition(lineBreaker, nullptr);
         if (currentKeyEvent) {
           currentKeyEvent->mCompositionDispatched = true;
         }
         [lineBreaker release];
         return true;
       }
-      case CommandDeleteCharBackward:
-      case CommandDeleteCharForward:
-      case CommandDeleteToBeginningOfLine:
-      case CommandDeleteWordBackward:
-      case CommandDeleteWordForward:
+      case Command::DeleteCharBackward:
+      case Command::DeleteCharForward:
+      case Command::DeleteToBeginningOfLine:
+      case Command::DeleteWordBackward:
+      case Command::DeleteWordForward:
         // Don't remove any contents during composition.
         return false;
-      case CommandInsertTab:
-      case CommandInsertBacktab:
+      case Command::InsertTab:
+      case Command::InsertBacktab:
         // Don't move focus during composition.
         return false;
-      case CommandCharNext:
-      case CommandSelectCharNext:
-      case CommandWordNext:
-      case CommandSelectWordNext:
-      case CommandEndLine:
-      case CommandSelectEndLine:
-      case CommandCharPrevious:
-      case CommandSelectCharPrevious:
-      case CommandWordPrevious:
-      case CommandSelectWordPrevious:
-      case CommandBeginLine:
-      case CommandSelectBeginLine:
-      case CommandLinePrevious:
-      case CommandSelectLinePrevious:
-      case CommandMoveTop:
-      case CommandLineNext:
-      case CommandSelectLineNext:
-      case CommandMoveBottom:
-      case CommandSelectBottom:
-      case CommandSelectPageUp:
-      case CommandSelectPageDown:
-      case CommandScrollBottom:
-      case CommandScrollTop:
+      case Command::CharNext:
+      case Command::SelectCharNext:
+      case Command::WordNext:
+      case Command::SelectWordNext:
+      case Command::EndLine:
+      case Command::SelectEndLine:
+      case Command::CharPrevious:
+      case Command::SelectCharPrevious:
+      case Command::WordPrevious:
+      case Command::SelectWordPrevious:
+      case Command::BeginLine:
+      case Command::SelectBeginLine:
+      case Command::LinePrevious:
+      case Command::SelectLinePrevious:
+      case Command::MoveTop:
+      case Command::LineNext:
+      case Command::SelectLineNext:
+      case Command::MoveBottom:
+      case Command::SelectBottom:
+      case Command::SelectPageUp:
+      case Command::SelectPageDown:
+      case Command::ScrollBottom:
+      case Command::ScrollTop:
         // Don't move selection during composition.
         return false;
-      case CommandCancelOperation:
-      case CommandComplete:
+      case Command::CancelOperation:
+      case Command::Complete:
         // Don't handle Escape key by ourselves during composition.
         return false;
-      case CommandScrollPageUp:
-      case CommandScrollPageDown:
+      case Command::ScrollPageUp:
+      case Command::ScrollPageDown:
         // Allow to scroll.
         break;
       default:
         break;
     }
   }
 
   RefPtr<nsChildView> widget(mWidget);
@@ -2616,190 +2616,190 @@ bool TextInputHandler::HandleCommand(Com
     // set current native key event to the fake keyboard event even if it's
     // not same as what we expect since the native keyboard event caused
     // this command.
     NSEvent* keyEvent = currentKeyEvent ? currentKeyEvent->mKeyEvent : nullptr;
     keydownEvent.mNativeKeyEvent = keypressEvent.mNativeKeyEvent = keyEvent;
     NS_WARNING_ASSERTION(keypressEvent.mNativeKeyEvent,
                          "Without native key event, NativeKeyBindings cannot compute aCommand");
     switch (aCommand) {
-      case CommandInsertLineBreak:
-      case CommandInsertParagraph: {
+      case Command::InsertLineBreak:
+      case Command::InsertParagraph: {
         // Although, Shift+Enter and Enter are work differently in HTML
         // editor, we should expose actual Shift state if it's caused by
         // Enter key for compatibility with Chromium.  Chromium breaks
         // line in HTML editor with default pargraph separator when Enter
         // is pressed, with <br> element when Shift+Enter.  Safari breaks
         // line in HTML editor with default paragraph separator when
         // Enter, Shift+Enter or Option+Enter.  So, we should not change
         // Shift+Enter meaning when there was composition string or not.
         nsCocoaUtils::InitInputEvent(keypressEvent, keyEvent);
         keypressEvent.mKeyCode = NS_VK_RETURN;
         keypressEvent.mKeyNameIndex = KEY_NAME_INDEX_Enter;
         keypressEvent.mModifiers &= ~(MODIFIER_CONTROL | MODIFIER_ALT | MODIFIER_META);
-        if (aCommand == CommandInsertLineBreak) {
+        if (aCommand == Command::InsertLineBreak) {
           // In default settings, Ctrl + Enter causes insertLineBreak command.
           // So, let's make Ctrl state active of the keypress event.
           keypressEvent.mModifiers |= MODIFIER_CONTROL;
         }
         break;
       }
-      case CommandInsertTab:
-      case CommandInsertBacktab:
+      case Command::InsertTab:
+      case Command::InsertBacktab:
         nsCocoaUtils::InitInputEvent(keypressEvent, keyEvent);
         keypressEvent.mKeyCode = NS_VK_TAB;
         keypressEvent.mKeyNameIndex = KEY_NAME_INDEX_Tab;
         keypressEvent.mModifiers &= ~(MODIFIER_CONTROL | MODIFIER_ALT | MODIFIER_META);
-        if (aCommand == CommandInsertBacktab) {
+        if (aCommand == Command::InsertBacktab) {
           keypressEvent.mModifiers |= MODIFIER_SHIFT;
         }
         break;
-      case CommandDeleteCharBackward:
-      case CommandDeleteToBeginningOfLine:
-      case CommandDeleteWordBackward: {
+      case Command::DeleteCharBackward:
+      case Command::DeleteToBeginningOfLine:
+      case Command::DeleteWordBackward: {
         nsCocoaUtils::InitInputEvent(keypressEvent, keyEvent);
         keypressEvent.mKeyCode = NS_VK_BACK;
         keypressEvent.mKeyNameIndex = KEY_NAME_INDEX_Backspace;
         keypressEvent.mModifiers &= ~(MODIFIER_CONTROL | MODIFIER_ALT | MODIFIER_META);
-        if (aCommand == CommandDeleteToBeginningOfLine) {
+        if (aCommand == Command::DeleteToBeginningOfLine) {
           keypressEvent.mModifiers |= MODIFIER_META;
-        } else if (aCommand == CommandDeleteWordBackward) {
+        } else if (aCommand == Command::DeleteWordBackward) {
           keypressEvent.mModifiers |= MODIFIER_ALT;
         }
         break;
       }
-      case CommandDeleteCharForward:
-      case CommandDeleteWordForward: {
+      case Command::DeleteCharForward:
+      case Command::DeleteWordForward: {
         nsCocoaUtils::InitInputEvent(keypressEvent, keyEvent);
         keypressEvent.mKeyCode = NS_VK_DELETE;
         keypressEvent.mKeyNameIndex = KEY_NAME_INDEX_Delete;
         keypressEvent.mModifiers &= ~(MODIFIER_CONTROL | MODIFIER_ALT | MODIFIER_META);
-        if (aCommand == CommandDeleteWordForward) {
+        if (aCommand == Command::DeleteWordForward) {
           keypressEvent.mModifiers |= MODIFIER_ALT;
         }
         break;
       }
-      case CommandCharNext:
-      case CommandSelectCharNext:
-      case CommandWordNext:
-      case CommandSelectWordNext:
-      case CommandEndLine:
-      case CommandSelectEndLine: {
+      case Command::CharNext:
+      case Command::SelectCharNext:
+      case Command::WordNext:
+      case Command::SelectWordNext:
+      case Command::EndLine:
+      case Command::SelectEndLine: {
         nsCocoaUtils::InitInputEvent(keypressEvent, keyEvent);
         keypressEvent.mKeyCode = NS_VK_RIGHT;
         keypressEvent.mKeyNameIndex = KEY_NAME_INDEX_ArrowRight;
         keypressEvent.mModifiers &= ~(MODIFIER_CONTROL | MODIFIER_ALT | MODIFIER_META);
-        if (aCommand == CommandSelectCharNext || aCommand == CommandSelectWordNext ||
-            aCommand == CommandSelectEndLine) {
+        if (aCommand == Command::SelectCharNext || aCommand == Command::SelectWordNext ||
+            aCommand == Command::SelectEndLine) {
           keypressEvent.mModifiers |= MODIFIER_SHIFT;
         }
-        if (aCommand == CommandWordNext || aCommand == CommandSelectWordNext) {
+        if (aCommand == Command::WordNext || aCommand == Command::SelectWordNext) {
           keypressEvent.mModifiers |= MODIFIER_ALT;
         }
-        if (aCommand == CommandEndLine || aCommand == CommandSelectEndLine) {
+        if (aCommand == Command::EndLine || aCommand == Command::SelectEndLine) {
           keypressEvent.mModifiers |= MODIFIER_META;
         }
         break;
       }
-      case CommandCharPrevious:
-      case CommandSelectCharPrevious:
-      case CommandWordPrevious:
-      case CommandSelectWordPrevious:
-      case CommandBeginLine:
-      case CommandSelectBeginLine: {
+      case Command::CharPrevious:
+      case Command::SelectCharPrevious:
+      case Command::WordPrevious:
+      case Command::SelectWordPrevious:
+      case Command::BeginLine:
+      case Command::SelectBeginLine: {
         nsCocoaUtils::InitInputEvent(keypressEvent, keyEvent);
         keypressEvent.mKeyCode = NS_VK_LEFT;
         keypressEvent.mKeyNameIndex = KEY_NAME_INDEX_ArrowLeft;
         keypressEvent.mModifiers &= ~(MODIFIER_CONTROL | MODIFIER_ALT | MODIFIER_META);
-        if (aCommand == CommandSelectCharPrevious || aCommand == CommandSelectWordPrevious ||
-            aCommand == CommandSelectBeginLine) {
+        if (aCommand == Command::SelectCharPrevious || aCommand == Command::SelectWordPrevious ||
+            aCommand == Command::SelectBeginLine) {
           keypressEvent.mModifiers |= MODIFIER_SHIFT;
         }
-        if (aCommand == CommandWordPrevious || aCommand == CommandSelectWordPrevious) {
+        if (aCommand == Command::WordPrevious || aCommand == Command::SelectWordPrevious) {
           keypressEvent.mModifiers |= MODIFIER_ALT;
         }
-        if (aCommand == CommandBeginLine || aCommand == CommandSelectBeginLine) {
+        if (aCommand == Command::BeginLine || aCommand == Command::SelectBeginLine) {
           keypressEvent.mModifiers |= MODIFIER_META;
         }
         break;
       }
-      case CommandLinePrevious:
-      case CommandSelectLinePrevious:
-      case CommandMoveTop:
-      case CommandSelectTop: {
+      case Command::LinePrevious:
+      case Command::SelectLinePrevious:
+      case Command::MoveTop:
+      case Command::SelectTop: {
         nsCocoaUtils::InitInputEvent(keypressEvent, keyEvent);
         keypressEvent.mKeyCode = NS_VK_UP;
         keypressEvent.mKeyNameIndex = KEY_NAME_INDEX_ArrowUp;
         keypressEvent.mModifiers &= ~(MODIFIER_CONTROL | MODIFIER_ALT | MODIFIER_META);
-        if (aCommand == CommandSelectLinePrevious || aCommand == CommandSelectTop) {
+        if (aCommand == Command::SelectLinePrevious || aCommand == Command::SelectTop) {
           keypressEvent.mModifiers |= MODIFIER_SHIFT;
         }
-        if (aCommand == CommandMoveTop || aCommand == CommandSelectTop) {
+        if (aCommand == Command::MoveTop || aCommand == Command::SelectTop) {
           keypressEvent.mModifiers |= MODIFIER_META;
         }
         break;
       }
-      case CommandLineNext:
-      case CommandSelectLineNext:
-      case CommandMoveBottom:
-      case CommandSelectBottom: {
+      case Command::LineNext:
+      case Command::SelectLineNext:
+      case Command::MoveBottom:
+      case Command::SelectBottom: {
         nsCocoaUtils::InitInputEvent(keypressEvent, keyEvent);
         keypressEvent.mKeyCode = NS_VK_DOWN;
         keypressEvent.mKeyNameIndex = KEY_NAME_INDEX_ArrowDown;
         keypressEvent.mModifiers &= ~(MODIFIER_CONTROL | MODIFIER_ALT | MODIFIER_META);
-        if (aCommand == CommandSelectLineNext || aCommand == CommandSelectBottom) {
+        if (aCommand == Command::SelectLineNext || aCommand == Command::SelectBottom) {
           keypressEvent.mModifiers |= MODIFIER_SHIFT;
         }
-        if (aCommand == CommandMoveBottom || aCommand == CommandSelectBottom) {
+        if (aCommand == Command::MoveBottom || aCommand == Command::SelectBottom) {
           keypressEvent.mModifiers |= MODIFIER_META;
         }
         break;
       }
-      case CommandScrollPageUp:
-      case CommandSelectPageUp: {
+      case Command::ScrollPageUp:
+      case Command::SelectPageUp: {
         nsCocoaUtils::InitInputEvent(keypressEvent, keyEvent);
         keypressEvent.mKeyCode = NS_VK_PAGE_UP;
         keypressEvent.mKeyNameIndex = KEY_NAME_INDEX_PageUp;
         keypressEvent.mModifiers &= ~(MODIFIER_CONTROL | MODIFIER_ALT | MODIFIER_META);
-        if (aCommand == CommandSelectPageUp) {
+        if (aCommand == Command::SelectPageUp) {
           keypressEvent.mModifiers |= MODIFIER_SHIFT;
         }
         break;
       }
-      case CommandScrollPageDown:
-      case CommandSelectPageDown: {
+      case Command::ScrollPageDown:
+      case Command::SelectPageDown: {
         nsCocoaUtils::InitInputEvent(keypressEvent, keyEvent);
         keypressEvent.mKeyCode = NS_VK_PAGE_DOWN;
         keypressEvent.mKeyNameIndex = KEY_NAME_INDEX_PageDown;
         keypressEvent.mModifiers &= ~(MODIFIER_CONTROL | MODIFIER_ALT | MODIFIER_META);
-        if (aCommand == CommandSelectPageDown) {
+        if (aCommand == Command::SelectPageDown) {
           keypressEvent.mModifiers |= MODIFIER_SHIFT;
         }
         break;
       }
-      case CommandScrollBottom:
-      case CommandScrollTop: {
+      case Command::ScrollBottom:
+      case Command::ScrollTop: {
         nsCocoaUtils::InitInputEvent(keypressEvent, keyEvent);
-        if (aCommand == CommandScrollBottom) {
+        if (aCommand == Command::ScrollBottom) {
           keypressEvent.mKeyCode = NS_VK_END;
           keypressEvent.mKeyNameIndex = KEY_NAME_INDEX_End;
         } else {
           keypressEvent.mKeyCode = NS_VK_HOME;
           keypressEvent.mKeyNameIndex = KEY_NAME_INDEX_Home;
         }
         keypressEvent.mModifiers &= ~(MODIFIER_CONTROL | MODIFIER_ALT | MODIFIER_META);
         break;
       }
-      case CommandCancelOperation:
-      case CommandComplete: {
+      case Command::CancelOperation:
+      case Command::Complete: {
         nsCocoaUtils::InitInputEvent(keypressEvent, keyEvent);
         keypressEvent.mKeyCode = NS_VK_ESCAPE;
         keypressEvent.mKeyNameIndex = KEY_NAME_INDEX_Escape;
         keypressEvent.mModifiers &= ~(MODIFIER_CONTROL | MODIFIER_ALT | MODIFIER_META);
-        if (aCommand == CommandComplete) {
+        if (aCommand == Command::Complete) {
           keypressEvent.mModifiers |= MODIFIER_ALT;
         }
         break;
       }
       default:
         return false;
     }
 
@@ -2847,17 +2847,17 @@ bool TextInputHandler::HandleCommand(Com
       currentKeyEvent->mKeyPressHandled = keyPressHandled;
       currentKeyEvent->mKeyPressDispatched = keyPressDispatched;
     }
     return true;
   }
 
   // If keypress event isn't dispatched as expected, we should fallback to
   // using composition events.
-  if (aCommand == CommandInsertLineBreak || aCommand == CommandInsertParagraph) {
+  if (aCommand == Command::InsertLineBreak || aCommand == Command::InsertParagraph) {
     NSAttributedString* lineBreaker = [[NSAttributedString alloc] initWithString:@"\n"];
     InsertTextAsCommittingComposition(lineBreaker, nullptr);
     if (currentKeyEvent) {
       currentKeyEvent->mCompositionDispatched = true;
     }
     [lineBreaker release];
     return true;
   }
@@ -2948,18 +2948,18 @@ bool TextInputHandler::DoCommandBySelect
   // However, if ChildView implements cancelOperation:, calling
   // [[ChildView super] doCommandBySelector:aSelector] when Command + Period
   // causes only a call of [ChildView cancelOperation:sender].  I.e.,
   // [ChildView keyDown:theEvent] becomes to be never called.  For avoiding
   // this odd behavior, we need to handle the command before super class of
   // ChildView only when current key event is proper event to fire Escape
   // keypress event.
   if (!strcmp(aSelector, "cancelOperatiorn:") && currentKeyEvent &&
-      currentKeyEvent->IsProperKeyEvent(CommandCancelOperation)) {
-    return HandleCommand(CommandCancelOperation);
+      currentKeyEvent->IsProperKeyEvent(Command::CancelOperation)) {
+    return HandleCommand(Command::CancelOperation);
   }
 
   // Otherwise, we've not handled the command yet.  Propagate the command
   // to the super class of ChildView.
   return false;
 }
 
 #pragma mark -
--- a/widget/cocoa/nsChildView.mm
+++ b/widget/cocoa/nsChildView.mm
@@ -4903,273 +4903,273 @@ static gfx::IntPoint GetIntegerDeltaForE
 
   mTextInputHandler->HandleKeyUpEvent(theEvent);
 
   NS_OBJC_END_TRY_ABORT_BLOCK;
 }
 
 - (void)insertNewline:(id)sender {
   if (mTextInputHandler) {
-    mTextInputHandler->HandleCommand(CommandInsertParagraph);
+    mTextInputHandler->HandleCommand(Command::InsertParagraph);
   }
 }
 
 - (void)insertLineBreak:(id)sender {
   // Ctrl + Enter in the default settings.
   if (mTextInputHandler) {
-    mTextInputHandler->HandleCommand(CommandInsertLineBreak);
+    mTextInputHandler->HandleCommand(Command::InsertLineBreak);
   }
 }
 
 - (void)deleteBackward:(id)sender {
   // Backspace in the default settings.
   if (mTextInputHandler) {
-    mTextInputHandler->HandleCommand(CommandDeleteCharBackward);
+    mTextInputHandler->HandleCommand(Command::DeleteCharBackward);
   }
 }
 
 - (void)deleteBackwardByDecomposingPreviousCharacter:(id)sender {
   // Ctrl + Backspace in the default settings.
   if (mTextInputHandler) {
-    mTextInputHandler->HandleCommand(CommandDeleteCharBackward);
+    mTextInputHandler->HandleCommand(Command::DeleteCharBackward);
   }
 }
 
 - (void)deleteWordBackward:(id)sender {
   // Alt + Backspace in the default settings.
   if (mTextInputHandler) {
-    mTextInputHandler->HandleCommand(CommandDeleteWordBackward);
+    mTextInputHandler->HandleCommand(Command::DeleteWordBackward);
   }
 }
 
 - (void)deleteToBeginningOfBackward:(id)sender {
   // Command + Backspace in the default settings.
   if (mTextInputHandler) {
-    mTextInputHandler->HandleCommand(CommandDeleteToBeginningOfLine);
+    mTextInputHandler->HandleCommand(Command::DeleteToBeginningOfLine);
   }
 }
 
 - (void)deleteForward:(id)sender {
   // Delete in the default settings.
   if (mTextInputHandler) {
-    mTextInputHandler->HandleCommand(CommandDeleteCharForward);
+    mTextInputHandler->HandleCommand(Command::DeleteCharForward);
   }
 }
 
 - (void)deleteWordForward:(id)sender {
   // Alt + Delete in the default settings.
   if (mTextInputHandler) {
-    mTextInputHandler->HandleCommand(CommandDeleteWordForward);
+    mTextInputHandler->HandleCommand(Command::DeleteWordForward);
   }
 }
 
 - (void)insertTab:(id)sender {
   // Tab in the default settings.
   if (mTextInputHandler) {
-    mTextInputHandler->HandleCommand(CommandInsertTab);
+    mTextInputHandler->HandleCommand(Command::InsertTab);
   }
 }
 
 - (void)insertBacktab:(id)sender {
   // Shift + Tab in the default settings.
   if (mTextInputHandler) {
-    mTextInputHandler->HandleCommand(CommandInsertBacktab);
+    mTextInputHandler->HandleCommand(Command::InsertBacktab);
   }
 }
 
 - (void)moveRight:(id)sender {
   // RightArrow in the default settings.
   if (mTextInputHandler) {
-    mTextInputHandler->HandleCommand(CommandCharNext);
+    mTextInputHandler->HandleCommand(Command::CharNext);
   }
 }
 
 - (void)moveRightAndModifySelection:(id)sender {
   // Shift + RightArrow in the default settings.
   if (mTextInputHandler) {
-    mTextInputHandler->HandleCommand(CommandSelectCharNext);
+    mTextInputHandler->HandleCommand(Command::SelectCharNext);
   }
 }
 
 - (void)moveWordRight:(id)sender {
   // Alt + RightArrow in the default settings.
   if (mTextInputHandler) {
-    mTextInputHandler->HandleCommand(CommandWordNext);
+    mTextInputHandler->HandleCommand(Command::WordNext);
   }
 }
 
 - (void)moveWordRightAndModifySelection:(id)sender {
   // Alt + Shift + RightArrow in the default settings.
   if (mTextInputHandler) {
-    mTextInputHandler->HandleCommand(CommandSelectWordNext);
+    mTextInputHandler->HandleCommand(Command::SelectWordNext);
   }
 }
 
 - (void)moveToRightEndOfLine:(id)sender {
   // Command + RightArrow in the default settings.
   if (mTextInputHandler) {
-    mTextInputHandler->HandleCommand(CommandEndLine);
+    mTextInputHandler->HandleCommand(Command::EndLine);
   }
 }
 
 - (void)moveToRightEndOfLineAndModifySelection:(id)sender {
   // Command + Shift + RightArrow in the default settings.
   if (mTextInputHandler) {
-    mTextInputHandler->HandleCommand(CommandSelectEndLine);
+    mTextInputHandler->HandleCommand(Command::SelectEndLine);
   }
 }
 
 - (void)moveLeft:(id)sender {
   // LeftArrow in the default settings.
   if (mTextInputHandler) {
-    mTextInputHandler->HandleCommand(CommandCharPrevious);
+    mTextInputHandler->HandleCommand(Command::CharPrevious);
   }
 }
 
 - (void)moveLeftAndModifySelection:(id)sender {
   // Shift + LeftArrow in the default settings.
   if (mTextInputHandler) {
-    mTextInputHandler->HandleCommand(CommandSelectCharPrevious);
+    mTextInputHandler->HandleCommand(Command::SelectCharPrevious);
   }
 }
 
 - (void)moveWordLeft:(id)sender {
   // Alt + LeftArrow in the default settings.
   if (mTextInputHandler) {
-    mTextInputHandler->HandleCommand(CommandWordPrevious);
+    mTextInputHandler->HandleCommand(Command::WordPrevious);
   }
 }
 
 - (void)moveWordLeftAndModifySelection:(id)sender {
   // Alt + Shift + LeftArrow in the default settings.
   if (mTextInputHandler) {
-    mTextInputHandler->HandleCommand(CommandSelectWordPrevious);
+    mTextInputHandler->HandleCommand(Command::SelectWordPrevious);
   }
 }
 
 - (void)moveToLeftEndOfLine:(id)sender {
   // Command + LeftArrow in the default settings.
   if (mTextInputHandler) {
-    mTextInputHandler->HandleCommand(CommandBeginLine);
+    mTextInputHandler->HandleCommand(Command::BeginLine);
   }
 }
 
 - (void)moveToLeftEndOfLineAndModifySelection:(id)sender {
   // Command + Shift + LeftArrow in the default settings.
   if (mTextInputHandler) {
-    mTextInputHandler->HandleCommand(CommandSelectBeginLine);
+    mTextInputHandler->HandleCommand(Command::SelectBeginLine);
   }
 }
 
 - (void)moveUp:(id)sender {
   // ArrowUp in the default settings.
   if (mTextInputHandler) {
-    mTextInputHandler->HandleCommand(CommandLinePrevious);
+    mTextInputHandler->HandleCommand(Command::LinePrevious);
   }
 }
 
 - (void)moveUpAndModifySelection:(id)sender {
   // Shift + ArrowUp in the default settings.
   if (mTextInputHandler) {
-    mTextInputHandler->HandleCommand(CommandSelectLinePrevious);
+    mTextInputHandler->HandleCommand(Command::SelectLinePrevious);
   }
 }
 
 - (void)moveToBeginningOfDocument:(id)sender {
   // Command + ArrowUp in the default settings.
   if (mTextInputHandler) {
-    mTextInputHandler->HandleCommand(CommandMoveTop);
+    mTextInputHandler->HandleCommand(Command::MoveTop);
   }
 }
 
 - (void)moveToBeginningOfDocumentAndModifySelection:(id)sender {
   // Command + Shift + ArrowUp or Shift + Home in the default settings.
   if (mTextInputHandler) {
-    mTextInputHandler->HandleCommand(CommandSelectTop);
+    mTextInputHandler->HandleCommand(Command::SelectTop);
   }
 }
 
 - (void)moveDown:(id)sender {
   // ArrowDown in the default settings.
   if (mTextInputHandler) {
-    mTextInputHandler->HandleCommand(CommandLineNext);
+    mTextInputHandler->HandleCommand(Command::LineNext);
   }
 }
 
 - (void)moveDownAndModifySelection:(id)sender {
   // Shift + ArrowDown in the default settings.
   if (mTextInputHandler) {
-    mTextInputHandler->HandleCommand(CommandSelectLineNext);
+    mTextInputHandler->HandleCommand(Command::SelectLineNext);
   }
 }
 
 - (void)moveToEndOfDocument:(id)sender {
   // Command + ArrowDown in the default settings.
   if (mTextInputHandler) {
-    mTextInputHandler->HandleCommand(CommandMoveBottom);
+    mTextInputHandler->HandleCommand(Command::MoveBottom);
   }
 }
 
 - (void)moveToEndOfDocumentAndModifySelection:(id)sender {
   // Command + Shift + ArrowDown or Shift + End in the default settings.
   if (mTextInputHandler) {
-    mTextInputHandler->HandleCommand(CommandSelectBottom);
+    mTextInputHandler->HandleCommand(Command::SelectBottom);
   }
 }
 
 - (void)scrollPageUp:(id)sender {
   // PageUp in the default settings.
   if (mTextInputHandler) {
-    mTextInputHandler->HandleCommand(CommandScrollPageUp);
+    mTextInputHandler->HandleCommand(Command::ScrollPageUp);
   }
 }
 
 - (void)pageUpAndModifySelection:(id)sender {
   // Shift + PageUp in the default settings.
   if (mTextInputHandler) {
-    mTextInputHandler->HandleCommand(CommandSelectPageUp);
+    mTextInputHandler->HandleCommand(Command::SelectPageUp);
   }
 }
 
 - (void)scrollPageDown:(id)sender {
   // PageDown in the default settings.
   if (mTextInputHandler) {
-    mTextInputHandler->HandleCommand(CommandScrollPageDown);
+    mTextInputHandler->HandleCommand(Command::ScrollPageDown);
   }
 }
 
 - (void)pageDownAndModifySelection:(id)sender {
   // Shift + PageDown in the default settings.
   if (mTextInputHandler) {
-    mTextInputHandler->HandleCommand(CommandSelectPageDown);
+    mTextInputHandler->HandleCommand(Command::SelectPageDown);
   }
 }
 
 - (void)scrollToEndOfDocument:(id)sender {
   // End in the default settings.
   if (mTextInputHandler) {
-    mTextInputHandler->HandleCommand(CommandScrollBottom);
+    mTextInputHandler->HandleCommand(Command::ScrollBottom);
   }
 }
 
 - (void)scrollToBeginningOfDocument:(id)sender {
   // Home in the default settings.
   if (mTextInputHandler) {
-    mTextInputHandler->HandleCommand(CommandScrollTop);
+    mTextInputHandler->HandleCommand(Command::ScrollTop);
   }
 }
 
 // XXX Don't decleare nor implement calcelOperation: because it
 //     causes not calling keyDown: for Command + Period.
 //     We need to handle it from doCommandBySelector:.
 
 - (void)complete:(id)sender {
   // Alt + Escape or Alt + Shift + Escape in the default settings.
   if (mTextInputHandler) {
-    mTextInputHandler->HandleCommand(CommandComplete);
+    mTextInputHandler->HandleCommand(Command::Complete);
   }
 }
 
 - (void)flagsChanged:(NSEvent*)theEvent {
   NS_OBJC_BEGIN_TRY_ABORT_BLOCK;
 
   NS_ENSURE_TRUE(mGeckoChild, );
 
--- a/widget/gtk/NativeKeyBindings.cpp
+++ b/widget/gtk/NativeKeyBindings.cpp
@@ -17,48 +17,59 @@
 #include <gdk/gdk.h>
 
 namespace mozilla {
 namespace widget {
 
 static nsTArray<CommandInt>* gCurrentCommands = nullptr;
 static bool gHandled = false;
 
+inline void AddCommand(Command aCommand) {
+  MOZ_ASSERT(gCurrentCommands);
+  gCurrentCommands->AppendElement(static_cast<CommandInt>(aCommand));
+}
+
 // Common GtkEntry and GtkTextView signals
 static void copy_clipboard_cb(GtkWidget* w, gpointer user_data) {
-  gCurrentCommands->AppendElement(CommandCopy);
+  AddCommand(Command::Copy);
   g_signal_stop_emission_by_name(w, "copy_clipboard");
   gHandled = true;
 }
 
 static void cut_clipboard_cb(GtkWidget* w, gpointer user_data) {
-  gCurrentCommands->AppendElement(CommandCut);
+  AddCommand(Command::Cut);
   g_signal_stop_emission_by_name(w, "cut_clipboard");
   gHandled = true;
 }
 
 // GTK distinguishes between display lines (wrapped, as they appear on the
 // screen) and paragraphs, which are runs of text terminated by a newline.
 // We don't have this distinction, so we always use editor's notion of
 // lines, which are newline-terminated.
 
 static const Command sDeleteCommands[][2] = {
     // backward, forward
-    {CommandDeleteCharBackward, CommandDeleteCharForward},       // CHARS
-    {CommandDeleteWordBackward, CommandDeleteWordForward},       // WORD_ENDS
-    {CommandDeleteWordBackward, CommandDeleteWordForward},       // WORDS
-    {CommandDeleteToBeginningOfLine, CommandDeleteToEndOfLine},  // LINES
-    {CommandDeleteToBeginningOfLine, CommandDeleteToEndOfLine},  // LINE_ENDS
-    {CommandDeleteToBeginningOfLine,
-     CommandDeleteToEndOfLine},  // PARAGRAPH_ENDS
-    {CommandDeleteToBeginningOfLine, CommandDeleteToEndOfLine},  // PARAGRAPHS
+    // CHARS
+    {Command::DeleteCharBackward, Command::DeleteCharForward},
+    // WORD_ENDS
+    {Command::DeleteWordBackward, Command::DeleteWordForward},
+    // WORDS
+    {Command::DeleteWordBackward, Command::DeleteWordForward},
+    // LINES
+    {Command::DeleteToBeginningOfLine, Command::DeleteToEndOfLine},
+    // LINE_ENDS
+    {Command::DeleteToBeginningOfLine, Command::DeleteToEndOfLine},
+    // PARAGRAPH_ENDS
+    {Command::DeleteToBeginningOfLine, Command::DeleteToEndOfLine},
+    // PARAGRAPHS
+    {Command::DeleteToBeginningOfLine, Command::DeleteToEndOfLine},
     // This deletes from the end of the previous word to the beginning of the
     // next word, but only if the caret is not in a word.
     // XXX need to implement in editor
-    {CommandDoNothing, CommandDoNothing}  // WHITESPACE
+    {Command::DoNothing, Command::DoNothing}  // WHITESPACE
 };
 
 static void delete_from_cursor_cb(GtkWidget* w, GtkDeleteType del_type,
                                   gint count, gpointer user_data) {
   g_signal_stop_emission_by_name(w, "delete_from_cursor");
   if (count == 0) {
     // Nothing to do.
     return;
@@ -86,79 +97,79 @@ static void delete_from_cursor_cb(GtkWid
     // unsupported deletion type
     return;
   }
 
   if (del_type == GTK_DELETE_WORDS) {
     // This works like word_ends, except we first move the caret to the
     // beginning/end of the current word.
     if (forward) {
-      gCurrentCommands->AppendElement(CommandWordNext);
-      gCurrentCommands->AppendElement(CommandWordPrevious);
+      AddCommand(Command::WordNext);
+      AddCommand(Command::WordPrevious);
     } else {
-      gCurrentCommands->AppendElement(CommandWordPrevious);
-      gCurrentCommands->AppendElement(CommandWordNext);
+      AddCommand(Command::WordPrevious);
+      AddCommand(Command::WordNext);
     }
   } else if (del_type == GTK_DELETE_DISPLAY_LINES ||
              del_type == GTK_DELETE_PARAGRAPHS) {
     // This works like display_line_ends, except we first move the caret to the
     // beginning/end of the current line.
     if (forward) {
-      gCurrentCommands->AppendElement(CommandBeginLine);
+      AddCommand(Command::BeginLine);
     } else {
-      gCurrentCommands->AppendElement(CommandEndLine);
+      AddCommand(Command::EndLine);
     }
   }
 
   Command command = sDeleteCommands[del_type][forward];
-  if (!command) {
-    return;  // unsupported command
+  if (command == Command::DoNothing) {
+    return;
   }
 
   unsigned int absCount = Abs(count);
   for (unsigned int i = 0; i < absCount; ++i) {
-    gCurrentCommands->AppendElement(command);
+    AddCommand(command);
   }
 }
 
 static const Command sMoveCommands[][2][2] = {
     // non-extend { backward, forward }, extend { backward, forward }
     // GTK differentiates between logical position, which is prev/next,
     // and visual position, which is always left/right.
     // We should fix this to work the same way for RTL text input.
     {// LOGICAL_POSITIONS
-     {CommandCharPrevious, CommandCharNext},
-     {CommandSelectCharPrevious, CommandSelectCharNext}},
+     {Command::CharPrevious, Command::CharNext},
+     {Command::SelectCharPrevious, Command::SelectCharNext}},
     {// VISUAL_POSITIONS
-     {CommandCharPrevious, CommandCharNext},
-     {CommandSelectCharPrevious, CommandSelectCharNext}},
+     {Command::CharPrevious, Command::CharNext},
+     {Command::SelectCharPrevious, Command::SelectCharNext}},
     {// WORDS
-     {CommandWordPrevious, CommandWordNext},
-     {CommandSelectWordPrevious, CommandSelectWordNext}},
+     {Command::WordPrevious, Command::WordNext},
+     {Command::SelectWordPrevious, Command::SelectWordNext}},
     {// DISPLAY_LINES
-     {CommandLinePrevious, CommandLineNext},
-     {CommandSelectLinePrevious, CommandSelectLineNext}},
+     {Command::LinePrevious, Command::LineNext},
+     {Command::SelectLinePrevious, Command::SelectLineNext}},
     {// DISPLAY_LINE_ENDS
-     {CommandBeginLine, CommandEndLine},
-     {CommandSelectBeginLine, CommandSelectEndLine}},
+     {Command::BeginLine, Command::EndLine},
+     {Command::SelectBeginLine, Command::SelectEndLine}},
     {// PARAGRAPHS
-     {CommandLinePrevious, CommandLineNext},
-     {CommandSelectLinePrevious, CommandSelectLineNext}},
+     {Command::LinePrevious, Command::LineNext},
+     {Command::SelectLinePrevious, Command::SelectLineNext}},
     {// PARAGRAPH_ENDS
-     {CommandBeginLine, CommandEndLine},
-     {CommandSelectBeginLine, CommandSelectEndLine}},
+     {Command::BeginLine, Command::EndLine},
+     {Command::SelectBeginLine, Command::SelectEndLine}},
     {// PAGES
-     {CommandMovePageUp, CommandMovePageDown},
-     {CommandSelectPageUp, CommandSelectPageDown}},
+     {Command::MovePageUp, Command::MovePageDown},
+     {Command::SelectPageUp, Command::SelectPageDown}},
     {// BUFFER_ENDS
-     {CommandMoveTop, CommandMoveBottom},
-     {CommandSelectTop, CommandSelectBottom}},
+     {Command::MoveTop, Command::MoveBottom},
+     {Command::SelectTop, Command::SelectBottom}},
     {// HORIZONTAL_PAGES (unsupported)
-     {CommandDoNothing, CommandDoNothing},
-     {CommandDoNothing, CommandDoNothing}}};
+     {Command::DoNothing, Command::DoNothing},
+     {Command::DoNothing, Command::DoNothing}}};
 
 static void move_cursor_cb(GtkWidget* w, GtkMovementStep step, gint count,
                            gboolean extend_selection, gpointer user_data) {
   g_signal_stop_emission_by_name(w, "move_cursor");
   if (count == 0) {
     // Nothing to do.
     return;
   }
@@ -166,35 +177,35 @@ static void move_cursor_cb(GtkWidget* w,
   gHandled = true;
   bool forward = count > 0;
   if (uint32_t(step) >= ArrayLength(sMoveCommands)) {
     // unsupported movement type
     return;
   }
 
   Command command = sMoveCommands[step][extend_selection][forward];
-  if (!command) {
-    return;  // unsupported command
+  if (command == Command::DoNothing) {
+    return;
   }
 
   unsigned int absCount = Abs(count);
   for (unsigned int i = 0; i < absCount; ++i) {
-    gCurrentCommands->AppendElement(command);
+    AddCommand(command);
   }
 }
 
 static void paste_clipboard_cb(GtkWidget* w, gpointer user_data) {
-  gCurrentCommands->AppendElement(CommandPaste);
+  AddCommand(Command::Paste);
   g_signal_stop_emission_by_name(w, "paste_clipboard");
   gHandled = true;
 }
 
 // GtkTextView-only signals
 static void select_all_cb(GtkWidget* w, gboolean select, gpointer user_data) {
-  gCurrentCommands->AppendElement(CommandSelectAll);
+  AddCommand(Command::SelectAll);
   g_signal_stop_emission_by_name(w, "select_all");
   gHandled = true;
 }
 
 NativeKeyBindings* NativeKeyBindings::sInstanceForSingleLineEditor = nullptr;
 NativeKeyBindings* NativeKeyBindings::sInstanceForMultiLineEditor = nullptr;
 
 // static