Bug 1387143 part 28. Remove nsISelection::AsSelection(). r=mats

This commit is contained in:
Boris Zbarsky 2018-05-08 13:52:42 -04:00
parent 21aa32be26
commit a44e6132ff
20 changed files with 43 additions and 63 deletions

View file

@ -48,19 +48,16 @@ SelectionManager::SelectionManager() :
void
SelectionManager::ClearControlSelectionListener()
{
// Remove 'this' registered as selection listener for the normal selection.
nsCOMPtr<nsISelection> 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<nsISelection> 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

View file

@ -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<dom::Selection> mCurrCtrlNormalSel;
WeakPtr<dom::Selection> mCurrCtrlSpellSel;
};
} // namespace a11y

View file

@ -783,10 +783,4 @@ ToSelectionTypeMask(SelectionType aSelectionType)
} // namespace mozilla
inline mozilla::dom::Selection*
nsISelection::AsSelection()
{
return static_cast<mozilla::dom::Selection*>(this);
}
#endif // mozilla_Selection_h__

View file

@ -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();
}

View file

@ -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<Selection>

View file

@ -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();
%}
};

View file

@ -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<nsISelection> sel;
RefPtr<Selection> 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 {

View file

@ -696,7 +696,7 @@ IMEContentObserver::IsEditorComposing() const
}
nsresult
IMEContentObserver::GetSelectionAndRoot(nsISelection** aSelection,
IMEContentObserver::GetSelectionAndRoot(dom::Selection** aSelection,
nsIContent** aRootContent) const
{
if (!mEditableNode || !mSelection) {

View file

@ -150,7 +150,7 @@ public:
void SuppressNotifyingIME();
void UnsuppressNotifyingIME();
nsPresContext* GetPresContext() const;
nsresult GetSelectionAndRoot(nsISelection** aSelection,
nsresult GetSelectionAndRoot(dom::Selection** aSelection,
nsIContent** aRoot) const;
/**

View file

@ -1949,7 +1949,7 @@ IMEStateManager::CreateIMEContentObserver(EditorBase* aEditorBase)
// static
nsresult
IMEStateManager::GetFocusSelectionAndRoot(nsISelection** aSelection,
IMEStateManager::GetFocusSelectionAndRoot(Selection** aSelection,
nsIContent** aRootContent)
{
if (!sActiveIMEContentObserver) {

View file

@ -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.

View file

@ -350,12 +350,12 @@ ComposerCommandsUpdater::SelectionIsCollapsed()
return true;
}
nsCOMPtr<nsISelection> domSelection = mDOMWindow->GetSelection();
RefPtr<dom::Selection> domSelection = mDOMWindow->GetSelection();
if (NS_WARN_IF(!domSelection)) {
return false;
}
return domSelection->AsSelection()->IsCollapsed();
return domSelection->IsCollapsed();
}
already_AddRefed<nsPICommandUpdater>

View file

@ -49,8 +49,7 @@ TextEditRules::CheckBidiLevelForDeletion(
nsBidiLevel levelBefore;
nsBidiLevel levelAfter;
RefPtr<nsFrameSelection> frameSelection =
aSelection->AsSelection()->GetFrameSelection();
RefPtr<nsFrameSelection> frameSelection = aSelection->GetFrameSelection();
NS_ENSURE_TRUE(frameSelection, NS_ERROR_NULL_POINTER);
nsPrevNextBidiLevels levels = frameSelection->

View file

@ -4979,7 +4979,7 @@ PresShell::CreateRangePaintInfo(nsRange* aRange,
already_AddRefed<SourceSurface>
PresShell::PaintRangePaintInfo(const nsTArray<UniquePtr<RangePaintInfo>>& aItems,
nsISelection* aSelection,
Selection* aSelection,
nsIntRegion* aRegion,
nsRect aArea,
const LayoutDeviceIntPoint aPoint,
@ -5108,7 +5108,7 @@ PresShell::PaintRangePaintInfo(const nsTArray<UniquePtr<RangePaintInfo>>& aItems
// selection.
RefPtr<nsFrameSelection> frameSelection;
if (aSelection) {
frameSelection = aSelection->AsSelection()->GetFrameSelection();
frameSelection = aSelection->GetFrameSelection();
}
else {
frameSelection = FrameSelection();

View file

@ -541,7 +541,7 @@ private:
*/
already_AddRefed<SourceSurface>
PaintRangePaintInfo(const nsTArray<UniquePtr<RangePaintInfo>>& aItems,
nsISelection* aSelection,
dom::Selection* aSelection,
nsIntRegion* aRegion,
nsRect aArea,
const LayoutDeviceIntPoint aPoint,

View file

@ -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();
}

View file

@ -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,

View file

@ -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;
}

View file

@ -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;
}

View file

@ -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,