diff --git a/layout/base/nsPresShell.cpp b/layout/base/nsPresShell.cpp index 9d5257722e01..25a0164acf82 100644 --- a/layout/base/nsPresShell.cpp +++ b/layout/base/nsPresShell.cpp @@ -92,6 +92,7 @@ #include "PLDHashTable.h" #include "mozilla/dom/BeforeAfterKeyboardEventBinding.h" #include "mozilla/dom/Touch.h" +#include "mozilla/dom/TouchEvent.h" #include "mozilla/dom/PointerEventBinding.h" #include "nsIObserverService.h" #include "nsDocShell.h" // for reflow observation @@ -734,17 +735,29 @@ static bool sSynthMouseMove = true; static uint32_t sNextPresShellId; static bool sPointerEventEnabled = true; static bool sAccessibleCaretEnabled = false; +static bool sAccessibleCaretOnTouch = false; static bool sBeforeAfterKeyboardEventEnabled = false; /* static */ bool -PresShell::AccessibleCaretEnabled() +PresShell::AccessibleCaretEnabled(nsIDocShell* aDocShell) { static bool initialized = false; if (!initialized) { Preferences::AddBoolVarCache(&sAccessibleCaretEnabled, "layout.accessiblecaret.enabled"); + Preferences::AddBoolVarCache(&sAccessibleCaretOnTouch, "layout.accessiblecaret.enabled_on_touch"); initialized = true; } - return sAccessibleCaretEnabled; + // If the pref forces it on, then enable it. + if (sAccessibleCaretEnabled) { + return true; + } + // If the touch pref is on, and touch events are enabled (this depends + // on the specific device running), then enable it. + if (sAccessibleCaretOnTouch && dom::TouchEvent::PrefEnabled(aDocShell)) { + return true; + } + // Otherwise, disabled. + return false; } /* static */ bool @@ -898,7 +911,7 @@ PresShell::Init(nsIDocument* aDocument, // Add the preference style sheet. UpdatePreferenceStyles(); - if (AccessibleCaretEnabled()) { + if (AccessibleCaretEnabled(mDocument->GetDocShell())) { // Need to happen before nsFrameSelection has been set up. mAccessibleCaretEventHub = new AccessibleCaretEventHub(this); } @@ -7603,7 +7616,7 @@ PresShell::HandleEvent(nsIFrame* aFrame, RecordMouseLocation(aEvent); - if (AccessibleCaretEnabled()) { + if (AccessibleCaretEnabled(mDocument->GetDocShell())) { // We have to target the focus window because regardless of where the // touch goes, we want to access the copy paste manager. nsCOMPtr window = GetFocusedDOMWindowInOurWindow(); diff --git a/layout/base/nsPresShell.h b/layout/base/nsPresShell.h index 9765f76d3435..19475ccd06a8 100644 --- a/layout/base/nsPresShell.h +++ b/layout/base/nsPresShell.h @@ -40,6 +40,7 @@ #include "MobileViewportManager.h" #include "ZoomConstraintsClient.h" +class nsIDocShell; class nsRange; struct RangePaintInfo; @@ -94,7 +95,7 @@ public: // nsISupports NS_DECL_ISUPPORTS - static bool AccessibleCaretEnabled(); + static bool AccessibleCaretEnabled(nsIDocShell* aDocShell); // BeforeAfterKeyboardEvent preference static bool BeforeAfterKeyboardEventEnabled(); diff --git a/modules/libpref/init/all.js b/modules/libpref/init/all.js index ec797bc65ada..5df7ec05a1cf 100644 --- a/modules/libpref/init/all.js +++ b/modules/libpref/init/all.js @@ -5166,6 +5166,16 @@ pref("snav.enabled", false); // New implementation to unify touch-caret and selection-carets. pref("layout.accessiblecaret.enabled", false); +// On Nightly, enable the accessible caret on platforms/devices +// that we detect have touch support. Note that this pref is an +// additional way to enable the accessible carets, rather than +// overriding the layout.accessiblecaret.enabled pref. +#ifdef NIGHTLY_BUILD +pref("layout.accessiblecaret.enabled_on_touch", true); +#else +pref("layout.accessiblecaret.enabled_on_touch", false); +#endif + // CSS attributes of the AccessibleCaret in CSS pixels. pref("layout.accessiblecaret.width", "34.0"); pref("layout.accessiblecaret.height", "36.0"); diff --git a/testing/profiles/prefs_general.js b/testing/profiles/prefs_general.js index 7d9510995a5f..538118c12016 100644 --- a/testing/profiles/prefs_general.js +++ b/testing/profiles/prefs_general.js @@ -48,6 +48,7 @@ user_pref("app.update.url.android", ""); // Make sure GMPInstallManager won't hit the network. user_pref("media.gmp-manager.url.override", "http://%(server)s/dummy-gmp-manager.xml"); user_pref("dom.w3c_touch_events.enabled", 1); +user_pref("layout.accessiblecaret.enabled_on_touch", false); user_pref("dom.undo_manager.enabled", true); user_pref("dom.webcomponents.enabled", true); user_pref("dom.webcomponents.customelements.enabled", true);