From a44e6132ffb58e3b93c9afdda2c2e4573d16e978 Mon Sep 17 00:00:00 2001 From: Boris Zbarsky Date: Tue, 8 May 2018 13:52:42 -0400 Subject: [PATCH] Bug 1387143 part 28. Remove nsISelection::AsSelection(). r=mats --- accessible/base/SelectionManager.cpp | 15 ++++++--------- accessible/base/SelectionManager.h | 6 ++++-- dom/base/Selection.h | 6 ------ dom/base/nsCopySupport.cpp | 2 +- dom/base/nsGlobalWindowOuter.cpp | 4 +--- dom/base/nsISelection.idl | 10 ---------- dom/events/ContentEventHandler.cpp | 4 ++-- dom/events/IMEContentObserver.cpp | 2 +- dom/events/IMEContentObserver.h | 2 +- dom/events/IMEStateManager.cpp | 2 +- dom/events/IMEStateManager.h | 6 +++++- editor/composer/ComposerCommandsUpdater.cpp | 4 ++-- editor/libeditor/TextEditRulesBidi.cpp | 3 +-- layout/base/PresShell.cpp | 4 ++-- layout/base/PresShell.h | 2 +- layout/base/nsCaret.cpp | 10 +++++----- layout/base/nsCaret.h | 4 ++-- layout/generic/nsFrameSelection.cpp | 2 +- toolkit/components/find/nsWebBrowserFind.cpp | 15 ++++++--------- toolkit/components/find/nsWebBrowserFind.h | 3 +-- 20 files changed, 43 insertions(+), 63 deletions(-) diff --git a/accessible/base/SelectionManager.cpp b/accessible/base/SelectionManager.cpp index 1c5214c9d8d0..6d3f47bc3dd1 100644 --- a/accessible/base/SelectionManager.cpp +++ b/accessible/base/SelectionManager.cpp @@ -48,19 +48,16 @@ SelectionManager::SelectionManager() : void SelectionManager::ClearControlSelectionListener() { - // Remove 'this' registered as selection listener for the normal selection. - nsCOMPtr normalSel = do_QueryReferent(mCurrCtrlNormalSel); - if (normalSel) { - normalSel->AsSelection()->RemoveSelectionListener(this); + if (mCurrCtrlNormalSel) { + mCurrCtrlNormalSel->RemoveSelectionListener(this); mCurrCtrlNormalSel = nullptr; } // Remove 'this' registered as selection listener for the spellcheck // selection. - nsCOMPtr spellSel = do_QueryReferent(mCurrCtrlSpellSel); - if (spellSel) { - spellSel->AsSelection()->RemoveSelectionListener(this); + if (mCurrCtrlSpellSel) { + mCurrCtrlSpellSel->RemoveSelectionListener(this); mCurrCtrlSpellSel = nullptr; } } @@ -85,12 +82,12 @@ SelectionManager::SetControlSelectionListener(dom::Element* aFocusedElm) // Register 'this' as selection listener for the normal selection. Selection* normalSel = frameSel->GetSelection(SelectionType::eNormal); normalSel->AddSelectionListener(this); - mCurrCtrlNormalSel = do_GetWeakReference(normalSel); + mCurrCtrlNormalSel = normalSel; // Register 'this' as selection listener for the spell check selection. Selection* spellSel = frameSel->GetSelection(SelectionType::eSpellCheck); spellSel->AddSelectionListener(this); - mCurrCtrlSpellSel = do_GetWeakReference(spellSel); + mCurrCtrlSpellSel = spellSel; } void diff --git a/accessible/base/SelectionManager.h b/accessible/base/SelectionManager.h index a483eebaef7e..44f1f9210162 100644 --- a/accessible/base/SelectionManager.h +++ b/accessible/base/SelectionManager.h @@ -8,6 +8,7 @@ #include "nsIFrame.h" #include "nsISelectionListener.h" +#include "mozilla/WeakPtr.h" class nsIPresShell; @@ -15,6 +16,7 @@ namespace mozilla { namespace dom { class Element; +class Selection; } namespace a11y { @@ -123,8 +125,8 @@ private: // Currently focused control. int32_t mCaretOffset; HyperTextAccessible* mAccWithCaret; - nsWeakPtr mCurrCtrlNormalSel; - nsWeakPtr mCurrCtrlSpellSel; + WeakPtr mCurrCtrlNormalSel; + WeakPtr mCurrCtrlSpellSel; }; } // namespace a11y diff --git a/dom/base/Selection.h b/dom/base/Selection.h index ecc5f2d3b4c0..55210308b4ef 100644 --- a/dom/base/Selection.h +++ b/dom/base/Selection.h @@ -783,10 +783,4 @@ ToSelectionTypeMask(SelectionType aSelectionType) } // namespace mozilla -inline mozilla::dom::Selection* -nsISelection::AsSelection() -{ - return static_cast(this); -} - #endif // mozilla_Selection_h__ diff --git a/dom/base/nsCopySupport.cpp b/dom/base/nsCopySupport.cpp index 5ac99b3188f2..6773c73823f4 100644 --- a/dom/base/nsCopySupport.cpp +++ b/dom/base/nsCopySupport.cpp @@ -333,7 +333,7 @@ nsCopySupport::GetTransferableForNode(nsINode* aNode, if (NS_WARN_IF(result.Failed())) { return result.StealNSResult(); } - selection->AsSelection()->AddRangeInternal(*range, aDoc, result); + selection->AddRangeInternal(*range, aDoc, result); if (NS_WARN_IF(result.Failed())) { return result.StealNSResult(); } diff --git a/dom/base/nsGlobalWindowOuter.cpp b/dom/base/nsGlobalWindowOuter.cpp index 9988f3f35ac7..4db07708552e 100644 --- a/dom/base/nsGlobalWindowOuter.cpp +++ b/dom/base/nsGlobalWindowOuter.cpp @@ -6324,9 +6324,7 @@ nsGlobalWindowOuter::GetSelectionOuter() if (!presShell) { return nullptr; } - nsISelection* domSelection = - presShell->GetCurrentSelection(SelectionType::eNormal); - return domSelection ? domSelection->AsSelection() : nullptr; + return presShell->GetCurrentSelection(SelectionType::eNormal); } already_AddRefed diff --git a/dom/base/nsISelection.idl b/dom/base/nsISelection.idl index 9ea83ba0a66f..84440ae25639 100644 --- a/dom/base/nsISelection.idl +++ b/dom/base/nsISelection.idl @@ -28,14 +28,4 @@ class Selection; [shim(Selection), uuid(e0a4d4b3-f34e-44bd-b1f2-4e3bde9b6915)] interface nsISelection : nsISupports { - -%{C++ - /** - * AsSelection() returns a pointer to Selection class. - * - * In order to avoid circular dependency issues, this method is defined - * in mozilla/dom/Selection.h. Consumers need to #include that header. - */ - inline mozilla::dom::Selection* AsSelection(); -%} }; diff --git a/dom/events/ContentEventHandler.cpp b/dom/events/ContentEventHandler.cpp index a21a328a5bd0..5c0f5a1a8eaa 100644 --- a/dom/events/ContentEventHandler.cpp +++ b/dom/events/ContentEventHandler.cpp @@ -3127,11 +3127,11 @@ ContentEventHandler::OnSelectionEvent(WidgetSelectionEvent* aEvent) // Get selection to manipulate // XXX why do we need to get them from ISM? This method should work fine // without ISM. - nsCOMPtr sel; + RefPtr sel; nsresult rv = IMEStateManager::GetFocusSelectionAndRoot(getter_AddRefs(sel), getter_AddRefs(mRootContent)); - mSelection = sel ? sel->AsSelection() : nullptr; + mSelection = sel; if (rv != NS_ERROR_NOT_AVAILABLE) { NS_ENSURE_SUCCESS(rv, rv); } else { diff --git a/dom/events/IMEContentObserver.cpp b/dom/events/IMEContentObserver.cpp index d9388df5792d..15b65ac88491 100644 --- a/dom/events/IMEContentObserver.cpp +++ b/dom/events/IMEContentObserver.cpp @@ -696,7 +696,7 @@ IMEContentObserver::IsEditorComposing() const } nsresult -IMEContentObserver::GetSelectionAndRoot(nsISelection** aSelection, +IMEContentObserver::GetSelectionAndRoot(dom::Selection** aSelection, nsIContent** aRootContent) const { if (!mEditableNode || !mSelection) { diff --git a/dom/events/IMEContentObserver.h b/dom/events/IMEContentObserver.h index 832a272bc397..1852f268b475 100644 --- a/dom/events/IMEContentObserver.h +++ b/dom/events/IMEContentObserver.h @@ -150,7 +150,7 @@ public: void SuppressNotifyingIME(); void UnsuppressNotifyingIME(); nsPresContext* GetPresContext() const; - nsresult GetSelectionAndRoot(nsISelection** aSelection, + nsresult GetSelectionAndRoot(dom::Selection** aSelection, nsIContent** aRoot) const; /** diff --git a/dom/events/IMEStateManager.cpp b/dom/events/IMEStateManager.cpp index 8291d7876f37..105b69267ed6 100644 --- a/dom/events/IMEStateManager.cpp +++ b/dom/events/IMEStateManager.cpp @@ -1949,7 +1949,7 @@ IMEStateManager::CreateIMEContentObserver(EditorBase* aEditorBase) // static nsresult -IMEStateManager::GetFocusSelectionAndRoot(nsISelection** aSelection, +IMEStateManager::GetFocusSelectionAndRoot(Selection** aSelection, nsIContent** aRootContent) { if (!sActiveIMEContentObserver) { diff --git a/dom/events/IMEStateManager.h b/dom/events/IMEStateManager.h index 49a275e2c49d..a39fb2295bd1 100644 --- a/dom/events/IMEStateManager.h +++ b/dom/events/IMEStateManager.h @@ -25,6 +25,10 @@ class IMEContentObserver; class TextCompositionArray; class TextComposition; +namespace dom { +class Selection; +} // namespace dom + /** * IMEStateManager manages InputContext (e.g., active editor type, IME enabled * state and IME open state) of nsIWidget instances, manages IMEContentObserver @@ -151,7 +155,7 @@ public: // control compared to having the two methods incorporated into OnChangeFocus // Get the focused editor's selection and root - static nsresult GetFocusSelectionAndRoot(nsISelection** aSel, + static nsresult GetFocusSelectionAndRoot(dom::Selection** aSel, nsIContent** aRoot); // This method updates the current IME state. However, if the enabled state // isn't changed by the new state, this method does nothing. diff --git a/editor/composer/ComposerCommandsUpdater.cpp b/editor/composer/ComposerCommandsUpdater.cpp index dbab18ac7474..4a8f74305880 100644 --- a/editor/composer/ComposerCommandsUpdater.cpp +++ b/editor/composer/ComposerCommandsUpdater.cpp @@ -350,12 +350,12 @@ ComposerCommandsUpdater::SelectionIsCollapsed() return true; } - nsCOMPtr domSelection = mDOMWindow->GetSelection(); + RefPtr domSelection = mDOMWindow->GetSelection(); if (NS_WARN_IF(!domSelection)) { return false; } - return domSelection->AsSelection()->IsCollapsed(); + return domSelection->IsCollapsed(); } already_AddRefed diff --git a/editor/libeditor/TextEditRulesBidi.cpp b/editor/libeditor/TextEditRulesBidi.cpp index 293e83b8e53f..fd8decbb0039 100644 --- a/editor/libeditor/TextEditRulesBidi.cpp +++ b/editor/libeditor/TextEditRulesBidi.cpp @@ -49,8 +49,7 @@ TextEditRules::CheckBidiLevelForDeletion( nsBidiLevel levelBefore; nsBidiLevel levelAfter; - RefPtr frameSelection = - aSelection->AsSelection()->GetFrameSelection(); + RefPtr frameSelection = aSelection->GetFrameSelection(); NS_ENSURE_TRUE(frameSelection, NS_ERROR_NULL_POINTER); nsPrevNextBidiLevels levels = frameSelection-> diff --git a/layout/base/PresShell.cpp b/layout/base/PresShell.cpp index afc0f3d5c0d0..aa2d1d2c574a 100644 --- a/layout/base/PresShell.cpp +++ b/layout/base/PresShell.cpp @@ -4979,7 +4979,7 @@ PresShell::CreateRangePaintInfo(nsRange* aRange, already_AddRefed PresShell::PaintRangePaintInfo(const nsTArray>& aItems, - nsISelection* aSelection, + Selection* aSelection, nsIntRegion* aRegion, nsRect aArea, const LayoutDeviceIntPoint aPoint, @@ -5108,7 +5108,7 @@ PresShell::PaintRangePaintInfo(const nsTArray>& aItems // selection. RefPtr frameSelection; if (aSelection) { - frameSelection = aSelection->AsSelection()->GetFrameSelection(); + frameSelection = aSelection->GetFrameSelection(); } else { frameSelection = FrameSelection(); diff --git a/layout/base/PresShell.h b/layout/base/PresShell.h index 60ac4afa00ff..d91d6f30d624 100644 --- a/layout/base/PresShell.h +++ b/layout/base/PresShell.h @@ -541,7 +541,7 @@ private: */ already_AddRefed PaintRangePaintInfo(const nsTArray>& aItems, - nsISelection* aSelection, + dom::Selection* aSelection, nsIntRegion* aRegion, nsRect aArea, const LayoutDeviceIntPoint aPoint, diff --git a/layout/base/nsCaret.cpp b/layout/base/nsCaret.cpp index 1b5046fc4cf8..26d6466633da 100644 --- a/layout/base/nsCaret.cpp +++ b/layout/base/nsCaret.cpp @@ -415,22 +415,22 @@ nsCaret::GetFrameAndOffset(Selection* aSelection, } /* static */ nsIFrame* -nsCaret::GetGeometry(nsISelection* aSelection, nsRect* aRect) +nsCaret::GetGeometry(Selection* aSelection, nsRect* aRect) { int32_t frameOffset; - Selection* selection = aSelection ? aSelection->AsSelection() : nullptr; - nsIFrame* frame = GetFrameAndOffset(selection, nullptr, 0, &frameOffset); + nsIFrame* frame = GetFrameAndOffset(aSelection, nullptr, 0, &frameOffset); if (frame) { *aRect = GetGeometryForFrame(frame, frameOffset, nullptr); } return frame; } -void nsCaret::SchedulePaint(nsISelection* aSelection) +void +nsCaret::SchedulePaint(Selection* aSelection) { Selection* selection; if (aSelection) { - selection = aSelection->AsSelection(); + selection = aSelection; } else { selection = GetSelection(); } diff --git a/layout/base/nsCaret.h b/layout/base/nsCaret.h index a96727de1548..e61ae16c1960 100644 --- a/layout/base/nsCaret.h +++ b/layout/base/nsCaret.h @@ -137,7 +137,7 @@ class nsCaret final : public nsISelectionListener * Schedule a repaint for the frame where the caret would appear. * Does not check visibility etc. */ - void SchedulePaint(nsISelection* aSelection = nullptr); + void SchedulePaint(mozilla::dom::Selection* aSelection = nullptr); /** * Returns a frame to paint in, and the bounds of the painted caret @@ -176,7 +176,7 @@ class nsCaret final : public nsISelectionListener * This rect does not include any extra decorations for bidi. * @param aRect must be non-null */ - static nsIFrame* GetGeometry(nsISelection* aSelection, + static nsIFrame* GetGeometry(mozilla::dom::Selection* aSelection, nsRect* aRect); static nsresult GetCaretFrameForNodeOffset(nsFrameSelection* aFrameSelection, nsIContent* aContentNode, diff --git a/layout/generic/nsFrameSelection.cpp b/layout/generic/nsFrameSelection.cpp index 667fc10fc059..c5c9d5d6ec3e 100644 --- a/layout/generic/nsFrameSelection.cpp +++ b/layout/generic/nsFrameSelection.cpp @@ -1739,7 +1739,7 @@ nsFrameSelection::CommonPageMove(bool aForward, // find out where the caret is. // we should know mDesiredPos value of nsFrameSelection, but I havent seen that behavior in other windows applications yet. - nsISelection* domSel = GetSelection(SelectionType::eNormal); + Selection* domSel = GetSelection(SelectionType::eNormal); if (!domSel) { return; } diff --git a/toolkit/components/find/nsWebBrowserFind.cpp b/toolkit/components/find/nsWebBrowserFind.cpp index 959b29b53096..7b7099cda4b3 100644 --- a/toolkit/components/find/nsWebBrowserFind.cpp +++ b/toolkit/components/find/nsWebBrowserFind.cpp @@ -22,7 +22,6 @@ #include "nsIDocument.h" #include "nsIDOMDocument.h" #include "nsISelectionController.h" -#include "nsISelection.h" #include "nsIFrame.h" #include "nsITextControlFrame.h" #include "nsReadableUtils.h" @@ -485,15 +484,13 @@ nsWebBrowserFind::SetRangeAroundDocument(nsRange* aSearchRange, nsresult nsWebBrowserFind::GetSearchLimits(nsRange* aSearchRange, nsRange* aStartPt, nsRange* aEndPt, - nsIDOMDocument* aDoc, nsISelection* aSel, + nsIDOMDocument* aDoc, Selection* aSel, bool aWrap) { NS_ENSURE_ARG_POINTER(aSel); - Selection* sel = aSel->AsSelection(); - // There is a selection. - uint32_t count = sel->RangeCount(); + uint32_t count = aSel->RangeCount(); if (count < 1) { return SetRangeAroundDocument(aSearchRange, aStartPt, aEndPt, aDoc); } @@ -519,7 +516,7 @@ nsWebBrowserFind::GetSearchLimits(nsRange* aSearchRange, if (!mFindBackwards && !aWrap) { // This isn't quite right, since the selection's ranges aren't // necessarily in order; but they usually will be. - range = sel->GetRangeAt(count - 1); + range = aSel->GetRangeAt(count - 1); if (!range) { return NS_ERROR_UNEXPECTED; } @@ -538,7 +535,7 @@ nsWebBrowserFind::GetSearchLimits(nsRange* aSearchRange, } // Backward, not wrapping: DocStart to SelStart else if (mFindBackwards && !aWrap) { - range = sel->GetRangeAt(0); + range = aSel->GetRangeAt(0); if (!range) { return NS_ERROR_UNEXPECTED; } @@ -557,7 +554,7 @@ nsWebBrowserFind::GetSearchLimits(nsRange* aSearchRange, } // Forward, wrapping: DocStart to SelEnd else if (!mFindBackwards && aWrap) { - range = sel->GetRangeAt(count - 1); + range = aSel->GetRangeAt(count - 1); if (!range) { return NS_ERROR_UNEXPECTED; } @@ -576,7 +573,7 @@ nsWebBrowserFind::GetSearchLimits(nsRange* aSearchRange, } // Backward, wrapping: SelStart to DocEnd else if (mFindBackwards && aWrap) { - range = sel->GetRangeAt(0); + range = aSel->GetRangeAt(0); if (!range) { return NS_ERROR_UNEXPECTED; } diff --git a/toolkit/components/find/nsWebBrowserFind.h b/toolkit/components/find/nsWebBrowserFind.h index 39fbb2745188..027e0418ddb0 100644 --- a/toolkit/components/find/nsWebBrowserFind.h +++ b/toolkit/components/find/nsWebBrowserFind.h @@ -21,7 +21,6 @@ #define NS_WEB_BROWSER_FIND_CID \ {0x57cf9383, 0x3405, 0x11d5, {0xbe, 0x5b, 0xaa, 0x20, 0xfa, 0x2c, 0xf3, 0x7c}} -class nsISelection; class nsIDOMWindow; class nsIDocShell; @@ -75,7 +74,7 @@ protected: nsresult GetRootNode(nsIDOMDocument* aDomDoc, nsIDOMNode** aNode); nsresult GetSearchLimits(nsRange* aRange, nsRange* aStartPt, nsRange* aEndPt, - nsIDOMDocument* aDoc, nsISelection* aSel, + nsIDOMDocument* aDoc, mozilla::dom::Selection* aSel, bool aWrap); nsresult SetRangeAroundDocument(nsRange* aSearchRange, nsRange* aStartPoint,