Bug 1387176 - move member initialization from the constructor to class definition for nsFrameSelection. r=TYLin
authorJeremy Chen <jeremychen@mozilla.com>
Fri, 17 Nov 2017 16:18:40 +0800
changeset 437024 27f247440ce78a1c65af4ca270cabf2594da465f
parent 437023 10df6e7390f6e380de796950a77cbcdd91a6342c
child 437025 8053ce4e6ab8131f8dbe9ecde24c13426050f10d
push id117
push userfmarier@mozilla.com
push dateTue, 28 Nov 2017 20:17:16 +0000
reviewersTYLin
bugs1387176
milestone59.0a1
Bug 1387176 - move member initialization from the constructor to class definition for nsFrameSelection. r=TYLin In this patch, we move the member assignments in nsFrameSelection's constructor to nsFrameSelection's class definition. This is a pre-patch for switching nsFrameSelection to use per-member defaults. With this patch, all the uninitialized members can be tracked easily. MozReview-Commit-ID: 1HhTDlV73QN
layout/generic/nsFrameSelection.cpp
layout/generic/nsFrameSelection.h
--- a/layout/generic/nsFrameSelection.cpp
+++ b/layout/generic/nsFrameSelection.cpp
@@ -300,31 +300,16 @@ struct MOZ_RAII AutoPrepareFocusRange
 ////////////BEGIN nsFrameSelection methods
 
 nsFrameSelection::nsFrameSelection()
 {
   for (size_t i = 0; i < ArrayLength(mDomSelections); i++) {
     mDomSelections[i] = new Selection(this);
     mDomSelections[i]->SetType(kPresentSelectionTypes[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;
 
   nsAutoCopyListener *autoCopy = nullptr;
   // On macOS, cache the current selection to send to osx service menu.
 #ifdef XP_MACOSX
   autoCopy = nsAutoCopyListener::GetInstance(nsIClipboard::kSelectionCache);
 #endif
 
   // Check to see if the autocopy pref is enabled
@@ -334,26 +319,16 @@ nsFrameSelection::nsFrameSelection()
   }
 
   if (autoCopy) {
     int8_t index = GetIndexFromSelectionType(SelectionType::eNormal);
     if (mDomSelections[index]) {
       autoCopy->Listen(mDomSelections[index]);
     }
   }
-
-  mDisplaySelection = nsISelectionController::SELECTION_OFF;
-  mSelectionChangeReason = nsISelectionListener::NO_REASON;
-
-  mDelayedMouseEventValid = false;
-  // These values are not used since they are only valid when
-  // mDelayedMouseEventValid is true, and setting mDelayedMouseEventValid
-  //alwaysoverrides these values.
-  mDelayedMouseEventIsShift = false;
-  mDelayedMouseEventClickCount = 0;
 }
 
 nsFrameSelection::~nsFrameSelection()
 {
 }
 
 NS_IMPL_CYCLE_COLLECTION_CLASS(nsFrameSelection)
 
--- a/layout/generic/nsFrameSelection.h
+++ b/layout/generic/nsFrameSelection.h
@@ -699,20 +699,16 @@ private:
   // nsFrameSelection may get deleted when calling this,
   // so remember to use nsCOMPtr when needed.
   nsresult     NotifySelectionListeners(mozilla::SelectionType aSelectionType);
   // Update the selection cache on repaint when the
   // selection being repainted is not empty.
   nsresult     UpdateSelectionCacheOnRepaintSelection(mozilla::dom::
                                                       Selection* aSel);
 
-  RefPtr<mozilla::dom::Selection>
-    mDomSelections[
-      sizeof(mozilla::kPresentSelectionTypes) / sizeof(mozilla::SelectionType)];
-
   // Table selection support.
   nsITableCellLayout* GetCellLayout(nsIContent *aCellContent) const;
 
   nsresult SelectBlockOfCells(nsIContent *aStartNode, nsIContent *aEndNode);
   nsresult SelectRowOrColumn(nsIContent *aCellContent, uint32_t aTarget);
   nsresult UnselectCells(nsIContent *aTable,
                          int32_t aStartRowIndex, int32_t aStartColumnIndex,
                          int32_t aEndRowIndex, int32_t aEndColumnIndex,
@@ -730,57 +726,68 @@ private:
   nsRange* GetNextCellRange();
   nsIContent* GetFirstCellNodeInRange(nsRange *aRange) const;
   // Returns non-null table if in same table, null otherwise
   nsIContent* IsInSameTable(nsIContent *aContent1, nsIContent *aContent2) const;
   // Might return null
   nsIContent* GetParentTable(nsIContent *aCellNode) const;
   nsresult CreateAndAddRange(nsINode* aContainer, int32_t aOffset);
 
+  ////////////BEGIN nsFrameSelection members
+
+  RefPtr<mozilla::dom::Selection>
+    mDomSelections[
+      sizeof(mozilla::kPresentSelectionTypes) / sizeof(mozilla::SelectionType)];
+
   nsCOMPtr<nsINode> mCellParent; //used to snap to table selection
   nsCOMPtr<nsIContent> mStartSelectedCell;
   nsCOMPtr<nsIContent> mEndSelectedCell;
   nsCOMPtr<nsIContent> mAppendStartSelectedCell;
   nsCOMPtr<nsIContent> mUnselectCellOnMouseUp;
-  int32_t  mSelectingTableCellMode;
-  int32_t  mSelectedCellIndex;
+  int32_t  mSelectingTableCellMode = 0;
+  int32_t  mSelectedCellIndex = 0;
 
   // maintain selection
   RefPtr<nsRange> mMaintainRange;
   nsSelectionAmount mMaintainedAmount;
 
   //batching
-  int32_t mBatching;
+  int32_t mBatching = 0;
 
   // Limit selection navigation to a child of this node.
   nsCOMPtr<nsIContent> mLimiter;
   // Limit selection navigation to a descendant of this node.
   nsCOMPtr<nsIContent> mAncestorLimiter;
 
   nsIPresShell *mShell;
-
-  int16_t mSelectionChangeReason; // reason for notifications of selection changing
-  int16_t mDisplaySelection; //for visual display purposes.
+  // Reason for notifications of selection changing.
+  int16_t mSelectionChangeReason = nsISelectionListener::NO_REASON;
+  // For visual display purposes.
+  int16_t mDisplaySelection = nsISelectionController::SELECTION_OFF;
 
-  CaretAssociateHint mHint;   //hint to tell if the selection is at the end of this line or beginning of next
-  nsBidiLevel mCaretBidiLevel;
-  nsBidiLevel mKbdBidiLevel;
+  // Hint to tell if the selection is at the end of this line or beginning of next.
+  CaretAssociateHint mHint = mozilla::CARET_ASSOCIATE_BEFORE;
+  nsBidiLevel mCaretBidiLevel = BIDI_LEVEL_UNDEFINED;
+  nsBidiLevel mKbdBidiLevel = NSBIDI_LTR;
 
   nsPoint mDesiredPos;
-  uint32_t mDelayedMouseEventClickCount;
-  bool mDelayedMouseEventIsShift;
-  bool mDelayedMouseEventValid;
+  bool mDelayedMouseEventValid = false;
+  // These values are not used since they are only valid when
+  // mDelayedMouseEventValid is true, and setting mDelayedMouseEventValid
+  // always overrides these values.
+  uint32_t mDelayedMouseEventClickCount = 0;
+  bool mDelayedMouseEventIsShift = false;
 
-  bool mChangesDuringBatching;
-  bool mNotifyFrames;
-  bool mDragSelectingCells;
+  bool mChangesDuringBatching = false;
+  bool mNotifyFrames = true;
+  bool mDragSelectingCells = false;
   bool mDragState;   //for drag purposes
-  bool mMouseDoubleDownState; //has the doubleclick down happened
-  bool mDesiredPosSet;
-  bool mAccessibleCaretEnabled;
+  bool mMouseDoubleDownState = false; //has the doubleclick down happened
+  bool mDesiredPosSet = false;
+  bool mAccessibleCaretEnabled = false;
 
   int8_t mCaretMovementStyle;
 
   static bool sSelectionEventsEnabled;
   static bool sSelectionEventsOnTextControlsEnabled;
 };
 
 #endif /* nsFrameSelection_h___ */