Bug 1077515 - part 9 - Support physical caret movement and selection commands in Editor. r=roc
authorJonathan Kew <jkew@mozilla.com>
Sat, 22 Nov 2014 14:39:04 +0000
changeset 216999 228cc7984e2f89cd09cc62aec86c477a61e69364
parent 216998 3260d0792a327498596855295ec32f604c8164a2
child 217000 23fcc95993718d7c99042c80683c844b735dee48
push id52195
push userjkew@mozilla.com
push dateSat, 22 Nov 2014 14:54:52 +0000
treeherdermozilla-inbound@203d3b5da245 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersroc
bugs1077515
milestone36.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 1077515 - part 9 - Support physical caret movement and selection commands in Editor. r=roc
editor/libeditor/nsEditorCommands.cpp
editor/libeditor/nsEditorController.cpp
--- a/editor/libeditor/nsEditorCommands.cpp
+++ b/editor/libeditor/nsEditorCommands.cpp
@@ -718,16 +718,40 @@ static const struct MoveCommand {
   { "cmd_movePageUp", "cmd_movePageDown",
     "cmd_selectPageUp", "cmd_selectPageDown",
     &nsISelectionController::PageMove },
   { "cmd_moveTop", "cmd_moveBottom",
     "cmd_selectTop", "cmd_selectBottom",
     &nsISelectionController::CompleteMove }
 };
 
+static const struct PhysicalCommand {
+  const char *move;
+  const char *select;
+  int16_t direction;
+  int16_t amount;
+} physicalCommands[] = {
+  { "cmd_moveLeft", "cmd_selectLeft",
+    nsISelectionController::MOVE_LEFT, 0 },
+  { "cmd_moveRight", "cmd_selectRight",
+    nsISelectionController::MOVE_RIGHT, 0 },
+  { "cmd_moveUp", "cmd_selectUp",
+    nsISelectionController::MOVE_UP, 0 },
+  { "cmd_moveDown", "cmd_selectDown",
+    nsISelectionController::MOVE_DOWN, 0 },
+  { "cmd_moveLeft2", "cmd_selectLeft2",
+    nsISelectionController::MOVE_LEFT, 1 },
+  { "cmd_moveRight2", "cmd_selectRight2",
+    nsISelectionController::MOVE_RIGHT, 1 },
+  { "cmd_moveUp2", "cmd_selectUp2",
+    nsISelectionController::MOVE_UP, 1 },
+  { "cmd_moveDown2", "cmd_selectDown2",
+    nsISelectionController::MOVE_DOWN, 1 }
+};
+
 NS_IMETHODIMP
 nsSelectionMoveCommands::DoCommand(const char *aCommandName,
                                    nsISupports *aCommandRefCon)
 {
   nsCOMPtr<nsIEditor> editor = do_QueryInterface(aCommandRefCon);
   NS_ENSURE_TRUE(editor, NS_ERROR_FAILURE);
 
   nsCOMPtr<nsIDOMDocument> domDoc;
@@ -763,16 +787,26 @@ nsSelectionMoveCommands::DoCommand(const
       return (selCont->*(cmd.move))(true, false);
     } else if (!nsCRT::strcmp(aCommandName, cmd.reverseSelect)) {
       return (selCont->*(cmd.move))(false, true);
     } else if (!nsCRT::strcmp(aCommandName, cmd.forwardSelect)) {
       return (selCont->*(cmd.move))(true, true);
     }
   }
 
+  // physical-direction movement/selection
+  for (size_t i = 0; i < ArrayLength(physicalCommands); i++) {
+    const PhysicalCommand& cmd = physicalCommands[i];
+    if (!nsCRT::strcmp(aCommandName, cmd.move)) {
+      return selCont->PhysicalMove(cmd.direction, cmd.amount, false);
+    } else if (!nsCRT::strcmp(aCommandName, cmd.select)) {
+      return selCont->PhysicalMove(cmd.direction, cmd.amount, true);
+    }
+  }
+
   return NS_ERROR_FAILURE;
 }
 
 NS_IMETHODIMP 
 nsSelectionMoveCommands::DoCommandParams(const char *aCommandName,
                                          nsICommandParams *aParams,
                                          nsISupports *aCommandRefCon)
 {
--- a/editor/libeditor/nsEditorController.cpp
+++ b/editor/libeditor/nsEditorController.cpp
@@ -105,13 +105,29 @@ nsresult nsEditorController::RegisterEdi
   NS_REGISTER_NEXT_COMMAND(nsSelectionMoveCommands, "cmd_selectWordNext");
   NS_REGISTER_NEXT_COMMAND(nsSelectionMoveCommands, "cmd_scrollPageUp");
   NS_REGISTER_NEXT_COMMAND(nsSelectionMoveCommands, "cmd_scrollPageDown");
   NS_REGISTER_NEXT_COMMAND(nsSelectionMoveCommands, "cmd_scrollLineUp");
   NS_REGISTER_NEXT_COMMAND(nsSelectionMoveCommands, "cmd_scrollLineDown");
   NS_REGISTER_NEXT_COMMAND(nsSelectionMoveCommands, "cmd_movePageUp");
   NS_REGISTER_NEXT_COMMAND(nsSelectionMoveCommands, "cmd_movePageDown");
   NS_REGISTER_NEXT_COMMAND(nsSelectionMoveCommands, "cmd_selectPageUp");
-  NS_REGISTER_LAST_COMMAND(nsSelectionMoveCommands, "cmd_selectPageDown");
+  NS_REGISTER_NEXT_COMMAND(nsSelectionMoveCommands, "cmd_selectPageDown");
+  NS_REGISTER_NEXT_COMMAND(nsSelectionMoveCommands, "cmd_moveLeft");
+  NS_REGISTER_NEXT_COMMAND(nsSelectionMoveCommands, "cmd_moveRight");
+  NS_REGISTER_NEXT_COMMAND(nsSelectionMoveCommands, "cmd_moveUp");
+  NS_REGISTER_NEXT_COMMAND(nsSelectionMoveCommands, "cmd_moveDown");
+  NS_REGISTER_NEXT_COMMAND(nsSelectionMoveCommands, "cmd_moveLeft2");
+  NS_REGISTER_NEXT_COMMAND(nsSelectionMoveCommands, "cmd_moveRight2");
+  NS_REGISTER_NEXT_COMMAND(nsSelectionMoveCommands, "cmd_moveUp2");
+  NS_REGISTER_NEXT_COMMAND(nsSelectionMoveCommands, "cmd_moveDown2");
+  NS_REGISTER_NEXT_COMMAND(nsSelectionMoveCommands, "cmd_selectLeft");
+  NS_REGISTER_NEXT_COMMAND(nsSelectionMoveCommands, "cmd_selectRight");
+  NS_REGISTER_NEXT_COMMAND(nsSelectionMoveCommands, "cmd_selectUp");
+  NS_REGISTER_NEXT_COMMAND(nsSelectionMoveCommands, "cmd_selectDown");
+  NS_REGISTER_NEXT_COMMAND(nsSelectionMoveCommands, "cmd_selectLeft2");
+  NS_REGISTER_NEXT_COMMAND(nsSelectionMoveCommands, "cmd_selectRight2");
+  NS_REGISTER_NEXT_COMMAND(nsSelectionMoveCommands, "cmd_selectUp2");
+  NS_REGISTER_LAST_COMMAND(nsSelectionMoveCommands, "cmd_selectDown2");
 
   return NS_OK;
 }