Bug 1463576 - 1. Add layout.accessiblecaret.script_change_update_mode pref; r=bz
authorJim Chen <nchen@mozilla.com>
Fri, 01 Jun 2018 13:39:20 -0400
changeset 475230 92022a2097214fdffc0db0737c82fcfc2c53a356
parent 475229 cc8d552173981747b96c95bd2b0953d685ad7947
child 475231 fb9bb29f0b40fc2fb830c46331f9d8b14aa331f0
push id9374
push userjlund@mozilla.com
push dateMon, 18 Jun 2018 21:43:20 +0000
treeherdermozilla-beta@160e085dfb0b [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbz
bugs1463576
milestone62.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 1463576 - 1. Add layout.accessiblecaret.script_change_update_mode pref; r=bz Currently, if the "layout.accessiblecaret.allow_script_change_updates" pref is false, we always hide accessible carets when the selection changes due to JS calls (e.g. setSelectionRange(0, 1)). If the pref is true, instead, we update the accessible carets if they are already visible. In either case, we never show the carets if they're invisible. However for testing purposes, it's useful to make it so we do try to show the carets if they're invisible. This patch replaces that pref with the new integer pref "layout.accessiblecaret.script_change_update_mode", which can be 0 or 1, which correspond to the old pref, or the value 2, which introduces this new behavior of always showing the carets. MozReview-Commit-ID: Bf1gPpIzcyb
layout/base/AccessibleCaretManager.cpp
layout/base/AccessibleCaretManager.h
mobile/android/app/mobile.js
modules/libpref/init/all.js
--- a/layout/base/AccessibleCaretManager.cpp
+++ b/layout/base/AccessibleCaretManager.cpp
@@ -73,18 +73,19 @@ std::ostream& operator<<(std::ostream& a
 #undef AC_PROCESS_ENUM_TO_STREAM
 
 /* static */ bool
 AccessibleCaretManager::sSelectionBarEnabled = false;
 /* static */ bool
 AccessibleCaretManager::sCaretShownWhenLongTappingOnEmptyContent = false;
 /* static */ bool
 AccessibleCaretManager::sCaretsAlwaysTilt = false;
-/* static */ bool
-AccessibleCaretManager::sCaretsScriptUpdates = false;
+/* static */ int32_t
+AccessibleCaretManager::sCaretsScriptUpdates =
+    AccessibleCaretManager::kScriptAlwaysHide;
 /* static */ bool
 AccessibleCaretManager::sCaretsAllowDraggingAcrossOtherCaret = true;
 /* static */ bool
 AccessibleCaretManager::sHapticFeedback = false;
 /* static */ bool
 AccessibleCaretManager::sExtendSelectionForPhoneNumber = false;
 /* static */ bool
 AccessibleCaretManager::sHideCaretsForMouseInput = true;
@@ -102,18 +103,18 @@ AccessibleCaretManager::AccessibleCaretM
   static bool addedPrefs = false;
   if (!addedPrefs) {
     Preferences::AddBoolVarCache(&sSelectionBarEnabled,
                                  "layout.accessiblecaret.bar.enabled");
     Preferences::AddBoolVarCache(&sCaretShownWhenLongTappingOnEmptyContent,
       "layout.accessiblecaret.caret_shown_when_long_tapping_on_empty_content");
     Preferences::AddBoolVarCache(&sCaretsAlwaysTilt,
                                  "layout.accessiblecaret.always_tilt");
-    Preferences::AddBoolVarCache(&sCaretsScriptUpdates,
-      "layout.accessiblecaret.allow_script_change_updates");
+    Preferences::AddIntVarCache(&sCaretsScriptUpdates,
+      "layout.accessiblecaret.script_change_update_mode");
     Preferences::AddBoolVarCache(&sCaretsAllowDraggingAcrossOtherCaret,
       "layout.accessiblecaret.allow_dragging_across_other_caret", true);
     Preferences::AddBoolVarCache(&sHapticFeedback,
                                  "layout.accessiblecaret.hapticfeedback");
     Preferences::AddBoolVarCache(&sExtendSelectionForPhoneNumber,
       "layout.accessiblecaret.extend_selection_for_phone_number");
     Preferences::AddBoolVarCache(&sHideCaretsForMouseInput,
       "layout.accessiblecaret.hide_carets_for_mouse_input");
@@ -149,21 +150,22 @@ AccessibleCaretManager::OnSelectionChang
   // eSetSelection events from the Fennec widget IME can be generated
   // by autoSuggest / autoCorrect composition changes, or by TYPE_REPLACE_TEXT
   // actions, either positioning cursor for text insert, or selecting
   // text-to-be-replaced. None should affect AccessibleCaret visibility.
   if (aReason & nsISelectionListener::IME_REASON) {
     return NS_OK;
   }
 
-  // Move the cursor by Javascript / or unknown internal.
+  // Move the cursor by JavaScript or unknown internal call.
   if (aReason == nsISelectionListener::NO_REASON) {
-    // Update visible carets, if javascript changes are allowed.
-    if (sCaretsScriptUpdates &&
-        (mFirstCaret->IsLogicallyVisible() || mSecondCaret->IsLogicallyVisible())) {
+    if (sCaretsScriptUpdates == kScriptAlwaysShow ||
+        (sCaretsScriptUpdates == kScriptUpdateVisible &&
+         (mFirstCaret->IsLogicallyVisible() ||
+          mSecondCaret->IsLogicallyVisible()))) {
         UpdateCarets();
         return NS_OK;
     }
     // Default for NO_REASON is to make hidden.
     HideCarets();
     return NS_OK;
   }
 
--- a/layout/base/AccessibleCaretManager.h
+++ b/layout/base/AccessibleCaretManager.h
@@ -344,20 +344,29 @@ protected:
   // which is based on the emptiness of the content, into something more
   // heuristic. See UpdateCaretsForCursorMode() for the details.
   static bool sCaretShownWhenLongTappingOnEmptyContent;
 
   // Preference to make carets always tilt in selection mode. By default, the
   // carets become tilt only when they are overlapping.
   static bool sCaretsAlwaysTilt;
 
-  // By default, javascript content selection changes closes AccessibleCarets and
-  // UI interactions. Optionally, we can try to maintain the active UI, keeping
-  // carets and ActionBar available.
-  static bool sCaretsScriptUpdates;
+  enum ScriptUpdateMode : int32_t {
+    // By default, always hide carets for selection changes due to JS calls.
+    kScriptAlwaysHide,
+    // Update any visible carets for selection changes due to JS calls,
+    // but don't show carets if carets are hidden.
+    kScriptUpdateVisible,
+    // Always show carets for selection changes due to JS calls.
+    kScriptAlwaysShow
+  };
+
+  // Preference to indicate how to update carets for selection changes due to
+  // JS calls, as one of the ScriptUpdateMode constants.
+  static int32_t sCaretsScriptUpdates;
 
   // Preference to allow one caret to be dragged across the other caret without
   // any limitation. When set to false, one caret cannot be dragged across the
   // other one.
   static bool sCaretsAllowDraggingAcrossOtherCaret;
 
   // AccessibleCaret pref for haptic feedback behaviour on longPress.
   static bool sHapticFeedback;
--- a/mobile/android/app/mobile.js
+++ b/mobile/android/app/mobile.js
@@ -776,19 +776,19 @@ pref("layout.accessiblecaret.height", "2
 pref("layout.accessiblecaret.margin-left", "-11.5");
 
 // Android needs to show the caret when long tapping on an empty content.
 pref("layout.accessiblecaret.caret_shown_when_long_tapping_on_empty_content", true);
 
 // Androids carets are always tilt to match the text selection guideline.
 pref("layout.accessiblecaret.always_tilt", true);
 
-// Selection change notifications generated by Javascript changes
-// update active AccessibleCarets / UI interactions.
-pref("layout.accessiblecaret.allow_script_change_updates", true);
+// Update any visible carets for selection changes due to JS calls,
+// but don't show carets if carets are hidden.
+pref("layout.accessiblecaret.script_change_update_mode", 1);
 
 // Optionally provide haptic feedback on longPress selection events.
 pref("layout.accessiblecaret.hapticfeedback", true);
 
 // Initial text selection on long-press is enhanced to provide
 // a smarter phone-number selection for direct-dial ActionBar action.
 pref("layout.accessiblecaret.extend_selection_for_phone_number", true);
 
--- a/modules/libpref/init/all.js
+++ b/modules/libpref/init/all.js
@@ -5466,19 +5466,21 @@ pref("layout.accessiblecaret.caret_shown
 
 // Simulate long tap to select words on the platforms where APZ is not enabled
 // or long tap events does not fired by APZ.
 pref("layout.accessiblecaret.use_long_tap_injector", false);
 
 // By default, carets become tilt only when they are overlapping.
 pref("layout.accessiblecaret.always_tilt", false);
 
-// Selection change notifications generated by Javascript hide
-// AccessibleCarets and close UI interaction by default.
-pref("layout.accessiblecaret.allow_script_change_updates", false);
+// 0 = by default, always hide carets for selection changes due to JS calls.
+// 1 = update any visible carets for selection changes due to JS calls,
+//     but don't show carets if carets are hidden.
+// 2 = always show carets for selection changes due to JS calls.
+pref("layout.accessiblecaret.script_change_update_mode", 0);
 
 // Allow one caret to be dragged across the other caret without any limitation.
 // This matches the built-in convention for all desktop platforms.
 pref("layout.accessiblecaret.allow_dragging_across_other_caret", true);
 
 // Optionally provide haptic feedback on longPress selection events.
 pref("layout.accessiblecaret.hapticfeedback", false);