Bug 1241008 - Add preference to show or hide selection bars. r=mtseng
--- a/layout/base/AccessibleCaretManager.cpp
+++ b/layout/base/AccessibleCaretManager.cpp
@@ -60,16 +60,18 @@ std::ostream& operator<<(std::ostream& a
AC_PROCESS_ENUM_TO_STREAM(UpdateCaretsHint::Default);
AC_PROCESS_ENUM_TO_STREAM(UpdateCaretsHint::RespectOldAppearance);
}
return aStream;
}
#undef AC_PROCESS_ENUM_TO_STREAM
/*static*/ bool
+AccessibleCaretManager::sSelectionBarEnabled = false;
+/*static*/ bool
AccessibleCaretManager::sCaretsExtendedVisibility = false;
/*static*/ bool
AccessibleCaretManager::sHapticFeedback = false;
AccessibleCaretManager::AccessibleCaretManager(nsIPresShell* aPresShell)
: mPresShell(aPresShell)
{
if (!mPresShell) {
@@ -78,16 +80,18 @@ AccessibleCaretManager::AccessibleCaretM
mFirstCaret = MakeUnique<AccessibleCaret>(mPresShell);
mSecondCaret = MakeUnique<AccessibleCaret>(mPresShell);
mCaretTimeoutTimer = do_CreateInstance("@mozilla.org/timer;1");
static bool addedPrefs = false;
if (!addedPrefs) {
+ Preferences::AddBoolVarCache(&sSelectionBarEnabled,
+ "layout.accessiblecaret.bar.enabled");
Preferences::AddBoolVarCache(&sCaretsExtendedVisibility,
"layout.accessiblecaret.extendedvisibility");
Preferences::AddBoolVarCache(&sHapticFeedback,
"layout.accessiblecaret.hapticfeedback");
addedPrefs = true;
}
}
@@ -314,17 +318,17 @@ AccessibleCaretManager::UpdateCaretsForS
HideCarets();
return;
}
auto updateSingleCaret = [](AccessibleCaret* aCaret, nsIFrame* aFrame,
int32_t aOffset) -> PositionChangedResult
{
PositionChangedResult result = aCaret->SetPosition(aFrame, aOffset);
- aCaret->SetSelectionBarEnabled(true);
+ aCaret->SetSelectionBarEnabled(sSelectionBarEnabled);
switch (result) {
case PositionChangedResult::NotChanged:
// Do nothing
break;
case PositionChangedResult::Changed:
aCaret->SetAppearance(Appearance::Normal);
--- a/layout/base/AccessibleCaretManager.h
+++ b/layout/base/AccessibleCaretManager.h
@@ -242,16 +242,20 @@ protected:
static const int32_t kAutoScrollTimerDelay = 30;
// Clicking on the boundary of input or textarea will move the caret to the
// front or end of the content. To avoid this, we need to deflate the content
// boundary by 61 app units, which is 1 pixel + 1 app unit as defined in
// AppUnit.h.
static const int32_t kBoundaryAppUnits = 61;
+ // Preference to show selection bars at the two ends in selection mode. The
+ // selection bar is always disabled in cursor mode.
+ static bool sSelectionBarEnabled;
+
// AccessibleCaret visibility preference. Used to avoid hiding caret during
// (NO_REASON) selection change notifications generated by keyboard IME, and to
// maintain a visible ActionBar while carets NotShown during scroll and while
// cursor is on an empty input.
static bool sCaretsExtendedVisibility;
// AccessibleCaret pref for haptic feedback behaviour on longPress.
static bool sHapticFeedback;
--- a/modules/libpref/init/all.js
+++ b/modules/libpref/init/all.js
@@ -4909,16 +4909,19 @@ pref("snav.enabled", false);
pref("layout.accessiblecaret.enabled", false);
// CSS attributes of the AccessibleCaret in CSS pixels.
pref("layout.accessiblecaret.width", "34.0");
pref("layout.accessiblecaret.height", "36.0");
pref("layout.accessiblecaret.margin-left", "-18.5");
pref("layout.accessiblecaret.bar.width", "2.0");
+// Show the selection bars at the two ends of the selection highlight.
+pref("layout.accessiblecaret.bar.enabled", true);
+
// Timeout in milliseconds to hide the accessiblecaret under cursor mode while
// no one touches it. Set the value to 0 to disable this feature.
pref("layout.accessiblecaret.timeout_ms", 3000);
// 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", true);