Bug 1195722 - Add a new pref to enable the accessible carets if touch events are supported, and enable the pref on nightly. r?tylin
MozReview-Commit-ID: 5jWaGPYTkAo
--- a/layout/base/nsPresShell.cpp
+++ b/layout/base/nsPresShell.cpp
@@ -87,16 +87,17 @@
#include "nsIDOMHTMLDocument.h"
#include "nsFrameManager.h"
#include "nsXPCOM.h"
#include "nsILayoutHistoryState.h"
#include "nsILineIterator.h" // for ScrollContentIntoView
#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
#include "nsIBaseWindow.h"
#include "nsError.h"
#include "nsLayoutUtils.h"
#include "nsViewportInfo.h"
#include "nsCSSRendering.h"
@@ -729,27 +730,39 @@ nsIPresShell::FrameSelection()
}
//----------------------------------------------------------------------
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.enable_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
PresShell::BeforeAfterKeyboardEventEnabled()
{
static bool sInitialized = false;
if (!sInitialized) {
Preferences::AddBoolVarCache(&sBeforeAfterKeyboardEventEnabled,
@@ -893,17 +906,17 @@ PresShell::Init(nsIDocument* aDocument,
// Notify our prescontext that it now has a compatibility mode. Note that
// this MUST happen after we set up our style set but before we create any
// frames.
mPresContext->CompatibilityModeChanged();
// 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);
}
mSelection = new nsFrameSelection();
mSelection->Init(this, nullptr);
@@ -7598,17 +7611,17 @@ PresShell::HandleEvent(nsIFrame* aFrame,
if (mIsDestroying ||
(sDisableNonTestMouseEvents && !aEvent->mFlags.mIsSynthesizedForTests &&
aEvent->HasMouseEventMessage())) {
return NS_OK;
}
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<nsPIDOMWindowOuter> window = GetFocusedDOMWindowInOurWindow();
nsCOMPtr<nsIDocument> retargetEventDoc =
window ? window->GetExtantDoc() : nullptr;
nsCOMPtr<nsIPresShell> presShell =
retargetEventDoc ? retargetEventDoc->GetShell() : nullptr;
--- a/layout/base/nsPresShell.h
+++ b/layout/base/nsPresShell.h
@@ -35,16 +35,17 @@
#include "mozilla/Attributes.h"
#include "mozilla/EventForwards.h"
#include "mozilla/MemoryReporting.h"
#include "mozilla/StyleSetHandle.h"
#include "mozilla/UniquePtr.h"
#include "MobileViewportManager.h"
#include "ZoomConstraintsClient.h"
+class nsIDocShell;
class nsRange;
struct RangePaintInfo;
struct nsCallbackEventRequest;
#ifdef MOZ_REFLOW_PERF
class ReflowCountMgr;
#endif
@@ -89,17 +90,17 @@ class PresShell final : public nsIPresSh
public:
PresShell();
NS_DECL_AND_IMPL_ZEROING_OPERATOR_NEW
// nsISupports
NS_DECL_ISUPPORTS
- static bool AccessibleCaretEnabled();
+ static bool AccessibleCaretEnabled(nsIDocShell* aDocShell);
// BeforeAfterKeyboardEvent preference
static bool BeforeAfterKeyboardEventEnabled();
static bool IsTargetIframe(nsINode* aTarget);
void Init(nsIDocument* aDocument, nsPresContext* aPresContext,
nsViewManager* aViewManager, mozilla::StyleSetHandle aStyleSet);
--- a/modules/libpref/init/all.js
+++ b/modules/libpref/init/all.js
@@ -5159,16 +5159,26 @@ pref("browser.safebrowsing.id", "Firefox
#endif
// Turn off Spatial navigation by default.
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.enable_on_touch", true);
+#else
+pref("layout.accessiblecaret.enable_on_touch", false);
+#endif
+
// 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 no selection bars at the two ends of the selection highlight.
pref("layout.accessiblecaret.bar.enabled", false);