Bug 1386472 - Only register the AccessibleCaretEventHub when the accessible caret is enabled; r=bzbarsky
authorEhsan Akhgari <ehsan@mozilla.com>
Tue, 01 Aug 2017 21:18:23 -0400
changeset 424894 d66d2f96f702a742f8ec3a8036fe457b33eef63d
parent 424893 59323293f48b9dea6ccaab890e01781abb59956d
child 424895 516c01f62d840744648768b6fac23feb770ffdc1
push id1567
push userjlorenzo@mozilla.com
push dateThu, 02 Nov 2017 12:36:05 +0000
treeherdermozilla-release@e512c14a0406 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbzbarsky
bugs1386472
milestone57.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 1386472 - Only register the AccessibleCaretEventHub when the accessible caret is enabled; r=bzbarsky
dom/html/nsTextEditorState.cpp
layout/base/PresShell.cpp
layout/generic/nsFrameSelection.cpp
layout/generic/nsFrameSelection.h
--- a/dom/html/nsTextEditorState.cpp
+++ b/dom/html/nsTextEditorState.cpp
@@ -351,17 +351,19 @@ nsTextInputSelectionImpl::nsTextInputSel
                                                    nsIPresShell *aShell,
                                                    nsIContent *aLimiter)
   : mScrollFrame(nullptr)
 {
   if (aSel && aShell)
   {
     mFrameSelection = aSel;//we are the owner now!
     mLimiter = aLimiter;
-    mFrameSelection->Init(aShell, mLimiter);
+    bool accessibleCaretEnabled =
+      PresShell::AccessibleCaretEnabled(aLimiter->OwnerDoc()->GetDocShell());
+    mFrameSelection->Init(aShell, mLimiter, accessibleCaretEnabled);
     mPresShellWeak = do_GetWeakReference(aShell);
   }
 }
 
 void
 nsTextInputSelectionImpl::SetScrollableFrame(nsIScrollableFrame *aScrollableFrame)
 {
   mScrollFrame = aScrollableFrame;
--- a/layout/base/PresShell.cpp
+++ b/layout/base/PresShell.cpp
@@ -976,25 +976,26 @@ 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(mDocument->GetDocShell())) {
+  bool accessibleCaretEnabled = AccessibleCaretEnabled(mDocument->GetDocShell());
+  if (accessibleCaretEnabled) {
     // Need to happen before nsFrameSelection has been set up.
     mAccessibleCaretEventHub = new AccessibleCaretEventHub(this);
   }
 
   mSelection = new nsFrameSelection();
 
   RefPtr<nsFrameSelection> frameSelection = mSelection;
-  frameSelection->Init(this, nullptr);
+  frameSelection->Init(this, nullptr, accessibleCaretEnabled);
 
   // Important: this has to happen after the selection has been set up
 #ifdef SHOW_CARET
   // make the caret
   mCaret = new nsCaret();
   mCaret->Init(this);
   mOriginalCaret = mCaret;
 
--- a/layout/generic/nsFrameSelection.cpp
+++ b/layout/generic/nsFrameSelection.cpp
@@ -8,16 +8,17 @@
  * Implementation of nsFrameSelection
  */
 
 #include "nsFrameSelection.h"
 
 #include "mozilla/Attributes.h"
 #include "mozilla/AutoRestore.h"
 #include "mozilla/EventStates.h"
+#include "mozilla/PresShell.h"
 
 #include "nsCOMPtr.h"
 #include "nsString.h"
 #include "nsISelectionListener.h"
 #include "nsContentCID.h"
 #include "nsDeviceContext.h"
 #include "nsIContent.h"
 #include "nsIDOMNode.h"
@@ -330,16 +331,18 @@ nsFrameSelection::nsFrameSelection()
     mDomSelections[i] = new Selection(this);
     mDomSelections[i]->SetType(GetSelectionTypeFromIndex(i));
   }
   mBatching = 0;
   mChangesDuringBatching = false;
   mNotifyFrames = true;
 
   mMouseDoubleDownState = false;
+  mDesiredPosSet = false;
+  mAccessibleCaretEnabled = false;
 
   mHint = CARET_ASSOCIATE_BEFORE;
   mCaretBidiLevel = BIDI_LEVEL_UNDEFINED;
   mKbdBidiLevel = NSBIDI_LTR;
 
   mDragSelectingCells = false;
   mSelectingTableCellMode = 0;
   mSelectedCellIndex = 0;
@@ -695,17 +698,18 @@ GetCellParent(nsINode *aDomNode)
       if (tag == nsGkAtoms::td || tag == nsGkAtoms::th)
         return current;
       current = current->GetParent();
     }
     return nullptr;
 }
 
 void
-nsFrameSelection::Init(nsIPresShell *aShell, nsIContent *aLimiter)
+nsFrameSelection::Init(nsIPresShell *aShell, nsIContent *aLimiter,
+                       bool aAccessibleCaretEnabled)
 {
   mShell = aShell;
   mDragState = false;
   mDesiredPosSet = false;
   mLimiter = aLimiter;
   mCaretMovementStyle =
     Preferences::GetInt("bidi.edit.caret_movement_style", 2);
 
@@ -715,21 +719,24 @@ nsFrameSelection::Init(nsIPresShell *aSh
     prefCachesInitialized = true;
 
     Preferences::AddBoolVarCache(&sSelectionEventsEnabled,
                                  "dom.select_events.enabled", false);
     Preferences::AddBoolVarCache(&sSelectionEventsOnTextControlsEnabled,
                                  "dom.select_events.textcontrols.enabled", false);
   }
 
-  RefPtr<AccessibleCaretEventHub> eventHub = mShell->GetAccessibleCaretEventHub();
-  if (eventHub) {
-    int8_t index = GetIndexFromSelectionType(SelectionType::eNormal);
-    if (mDomSelections[index]) {
-      mDomSelections[index]->AddSelectionListener(eventHub);
+  mAccessibleCaretEnabled = aAccessibleCaretEnabled;
+  if (mAccessibleCaretEnabled) {
+    RefPtr<AccessibleCaretEventHub> eventHub = mShell->GetAccessibleCaretEventHub();
+    if (eventHub) {
+      int8_t index = GetIndexFromSelectionType(SelectionType::eNormal);
+      if (mDomSelections[index]) {
+        mDomSelections[index]->AddSelectionListener(eventHub);
+      }
     }
   }
 
   bool plaintextControl = (aLimiter != nullptr);
   bool initSelectEvents = plaintextControl ?
                             sSelectionEventsOnTextControlsEnabled :
                             sSelectionEventsEnabled;
 
@@ -2949,20 +2956,22 @@ nsFrameSelection::SetDelayedCaretData(Wi
   } else {
     mDelayedMouseEventValid = false;
   }
 }
 
 void
 nsFrameSelection::DisconnectFromPresShell()
 {
-  RefPtr<AccessibleCaretEventHub> eventHub = mShell->GetAccessibleCaretEventHub();
-  if (eventHub) {
-    int8_t index = GetIndexFromSelectionType(SelectionType::eNormal);
-    mDomSelections[index]->RemoveSelectionListener(eventHub);
+  if (mAccessibleCaretEnabled) {
+    RefPtr<AccessibleCaretEventHub> eventHub = mShell->GetAccessibleCaretEventHub();
+    if (eventHub) {
+      int8_t index = GetIndexFromSelectionType(SelectionType::eNormal);
+      mDomSelections[index]->RemoveSelectionListener(eventHub);
+    }
   }
 
   StopAutoScrollTimer();
   for (size_t i = 0; i < kPresentSelectionTypeCount; i++) {
     mDomSelections[i]->Clear(nullptr);
   }
   mShell = nullptr;
 }
--- a/layout/generic/nsFrameSelection.h
+++ b/layout/generic/nsFrameSelection.h
@@ -198,18 +198,20 @@ public:
 
   NS_INLINE_DECL_CYCLE_COLLECTING_NATIVE_REFCOUNTING(nsFrameSelection)
   NS_DECL_CYCLE_COLLECTION_NATIVE_CLASS(nsFrameSelection)
 
   /** Init will initialize the frame selector with the necessary pres shell to
    *  be used by most of the methods
    *  @param aShell is the parameter to be used for most of the other calls for callbacks etc
    *  @param aLimiter limits the selection to nodes with aLimiter parents
+   *  @param aAccessibleCaretEnabled true if we should enable the accessible caret.
    */
-  void Init(nsIPresShell *aShell, nsIContent *aLimiter);
+  void Init(nsIPresShell *aShell, nsIContent *aLimiter,
+            bool aAccessibleCaretEnabled);
 
   /** HandleClick will take the focus to the new frame at the new offset and
    *  will either extend the selection from the old anchor, or replace the old anchor.
    *  the old anchor and focus position may also be used to deselect things
    *  @param aNewfocus is the content that wants the focus
    *  @param aContentOffset is the content offset of the parent aNewFocus
    *  @param aContentOffsetEnd is the content offset of the parent aNewFocus and is specified different
    *                           when you need to select to and include both start and end points
@@ -765,16 +767,17 @@ private:
   bool mDelayedMouseEventValid;
 
   bool mChangesDuringBatching;
   bool mNotifyFrames;
   bool mDragSelectingCells;
   bool mDragState;   //for drag purposes
   bool mMouseDoubleDownState; //has the doubleclick down happened
   bool mDesiredPosSet;
+  bool mAccessibleCaretEnabled;
 
   int8_t mCaretMovementStyle;
 
   static bool sSelectionEventsEnabled;
   static bool sSelectionEventsOnTextControlsEnabled;
 };
 
 #endif /* nsFrameSelection_h___ */