Bug 1321376 - In single-process mode, don't change <select> selection with cursors if popup is opened in the parent. r?Enn draft
authorMike Conley <mconley@mozilla.com>
Mon, 28 Nov 2016 16:07:01 -0800
changeset 451174 419f255a12f9dd99bf7668f5ce7b8237e0890daa
parent 451111 d4b3146a5567a7ddbcdfa5244945db55616cb8d1
child 451175 d4b9ac0b6c1987ba3a8bff1efe48adeb61615805
push id39077
push usermconley@mozilla.com
push dateMon, 19 Dec 2016 21:16:52 +0000
reviewersEnn
bugs1321376
milestone53.0a1
Bug 1321376 - In single-process mode, don't change <select> selection with cursors if popup is opened in the parent. r?Enn MozReview-Commit-ID: KylyZ6bbxno
layout/forms/nsListControlFrame.cpp
--- a/layout/forms/nsListControlFrame.cpp
+++ b/layout/forms/nsListControlFrame.cpp
@@ -2189,28 +2189,37 @@ nsListControlFrame::KeyDown(nsIDOMEvent*
                           keyEvent->mKeyCode == NS_VK_HOME ||
                           keyEvent->mKeyCode == NS_VK_END)) {
     // Don't go into multiple-select mode unless this list can handle it.
     isControlOrMeta = mControlSelectMode = GetMultiple();
   } else if (keyEvent->mKeyCode != NS_VK_SPACE) {
     mControlSelectMode = false;
   }
 
+  // We should not change the selection if the popup is "opened
+  // in the parent process" (even when we're in single-process mode).
+  bool shouldSelectByKey = !mComboboxFrame ||
+                           !mComboboxFrame->IsOpenInParentProcess();
+
   switch (keyEvent->mKeyCode) {
     case NS_VK_UP:
     case NS_VK_LEFT:
-      AdjustIndexForDisabledOpt(mEndSelectionIndex, newIndex,
-                                static_cast<int32_t>(numOptions),
-                                -1, -1);
+      if (shouldSelectByKey) {
+        AdjustIndexForDisabledOpt(mEndSelectionIndex, newIndex,
+                                  static_cast<int32_t>(numOptions),
+                                  -1, -1);
+      }
       break;
     case NS_VK_DOWN:
     case NS_VK_RIGHT:
-      AdjustIndexForDisabledOpt(mEndSelectionIndex, newIndex,
-                                static_cast<int32_t>(numOptions),
-                                1, 1);
+      if (shouldSelectByKey) {
+        AdjustIndexForDisabledOpt(mEndSelectionIndex, newIndex,
+                                  static_cast<int32_t>(numOptions),
+                                  1, 1);
+      }
       break;
     case NS_VK_RETURN:
       if (IsInDropDownMode()) {
         if (mComboboxFrame->IsDroppedDown()) {
           // If the select element is a dropdown style, Enter key should be
           // consumed while the dropdown is open for security.
           aKeyEvent->PreventDefault();
 
@@ -2240,40 +2249,48 @@ nsListControlFrame::KeyDown(nsIDOMEvent*
       AboutToRollup();
       // If the select element is a dropdown style, Enter key should be
       // consumed everytime since Escape key may be pressed accidentally after
       // the dropdown is closed by Escepe key.
       aKeyEvent->PreventDefault();
       return NS_OK;
     }
     case NS_VK_PAGE_UP: {
-      int32_t itemsPerPage =
-        std::max(1, static_cast<int32_t>(mNumDisplayRows - 1));
-      AdjustIndexForDisabledOpt(mEndSelectionIndex, newIndex,
-                                static_cast<int32_t>(numOptions),
-                                -itemsPerPage, -1);
+      if (shouldSelectByKey) {
+        int32_t itemsPerPage =
+          std::max(1, static_cast<int32_t>(mNumDisplayRows - 1));
+        AdjustIndexForDisabledOpt(mEndSelectionIndex, newIndex,
+                                  static_cast<int32_t>(numOptions),
+                                  -itemsPerPage, -1);
+      }
       break;
     }
     case NS_VK_PAGE_DOWN: {
-      int32_t itemsPerPage =
-        std::max(1, static_cast<int32_t>(mNumDisplayRows - 1));
-      AdjustIndexForDisabledOpt(mEndSelectionIndex, newIndex,
-                                static_cast<int32_t>(numOptions),
-                                itemsPerPage, 1);
+      if (shouldSelectByKey) {
+        int32_t itemsPerPage =
+          std::max(1, static_cast<int32_t>(mNumDisplayRows - 1));
+        AdjustIndexForDisabledOpt(mEndSelectionIndex, newIndex,
+                                  static_cast<int32_t>(numOptions),
+                                  itemsPerPage, 1);
+      }
       break;
     }
     case NS_VK_HOME:
-      AdjustIndexForDisabledOpt(0, newIndex,
-                                static_cast<int32_t>(numOptions),
-                                0, 1);
+      if (shouldSelectByKey) {
+        AdjustIndexForDisabledOpt(0, newIndex,
+                                  static_cast<int32_t>(numOptions),
+                                  0, 1);
+      }
       break;
     case NS_VK_END:
-      AdjustIndexForDisabledOpt(static_cast<int32_t>(numOptions) - 1, newIndex,
-                                static_cast<int32_t>(numOptions),
-                                0, -1);
+      if (shouldSelectByKey) {
+        AdjustIndexForDisabledOpt(static_cast<int32_t>(numOptions) - 1, newIndex,
+                                  static_cast<int32_t>(numOptions),
+                                  0, -1);
+      }
       break;
 
 #if defined(XP_WIN)
     case NS_VK_F4:
       if (!isControlOrMeta) {
         DropDownToggleKey(aKeyEvent);
       }
       return NS_OK;