mirror of
https://github.com/mozilla/gecko-dev.git
synced 2025-02-06 06:22:33 +00:00
Bug 253889: DeCOMtaminate nsIPresShell - GetCaret(). r=roc
--HG-- extra : rebase_source : 2a05050d8cbb10dd3bb763d5d5a158cc5f3dd814
This commit is contained in:
parent
3b3307f212
commit
c82a6bc194
@ -322,8 +322,7 @@ nsCaretAccessible::GetCaretRect(nsIWidget **aOutWidget)
|
||||
nsCoreUtils::GetPresShellFor(lastNodeWithCaret);
|
||||
NS_ENSURE_TRUE(presShell, caretRect);
|
||||
|
||||
nsRefPtr<nsCaret> caret;
|
||||
presShell->GetCaret(getter_AddRefs(caret));
|
||||
nsRefPtr<nsCaret> caret = presShell->GetCaret();
|
||||
NS_ENSURE_TRUE(caret, caretRect);
|
||||
|
||||
nsCOMPtr<nsISelection> caretSelection(do_QueryReferent(mLastUsedSelection));
|
||||
|
@ -135,10 +135,8 @@ nsContentEventHandler::Init(nsQueryContentEvent* aEvent)
|
||||
NS_ENSURE_SUCCESS(rv, NS_ERROR_NOT_AVAILABLE);
|
||||
aEvent->mReply.mHasSelection = !isCollapsed;
|
||||
|
||||
nsRefPtr<nsCaret> caret;
|
||||
rv = mPresShell->GetCaret(getter_AddRefs(caret));
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
NS_ASSERTION(caret, "GetCaret succeeded, but the result is null");
|
||||
nsRefPtr<nsCaret> caret = mPresShell->GetCaret();
|
||||
NS_ASSERTION(caret, "GetCaret returned null");
|
||||
|
||||
nsRect r;
|
||||
nsIFrame* frame = caret->GetGeometry(mSelection, &r);
|
||||
@ -663,10 +661,8 @@ nsContentEventHandler::OnQueryCaretRect(nsQueryContentEvent* aEvent)
|
||||
if (NS_FAILED(rv))
|
||||
return rv;
|
||||
|
||||
nsRefPtr<nsCaret> caret;
|
||||
rv = mPresShell->GetCaret(getter_AddRefs(caret));
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
NS_ASSERTION(caret, "GetCaret succeeded, but the result is null");
|
||||
nsRefPtr<nsCaret> caret = mPresShell->GetCaret();
|
||||
NS_ASSERTION(caret, "GetCaret returned null");
|
||||
|
||||
// When the selection is collapsed and the queried offset is current caret
|
||||
// position, we should return the "real" caret rect.
|
||||
|
@ -1899,8 +1899,7 @@ nsFocusManager::SetCaretVisible(nsIPresShell* aPresShell,
|
||||
// When browsing with caret, make sure caret is visible after new focus
|
||||
// Return early if there is no caret. This can happen for the testcase
|
||||
// for bug 308025 where a window is closed in a blur handler.
|
||||
nsRefPtr<nsCaret> caret;
|
||||
aPresShell->GetCaret(getter_AddRefs(caret));
|
||||
nsRefPtr<nsCaret> caret = aPresShell->GetCaret();
|
||||
if (!caret)
|
||||
return NS_OK;
|
||||
|
||||
@ -2054,8 +2053,7 @@ nsFocusManager::GetSelectionLocation(nsIDocument* aDocument,
|
||||
if (newCaretFrame && newCaretContent) {
|
||||
// If the caret is exactly at the same position of the new frame,
|
||||
// then we can use the newCaretFrame and newCaretContent for our position
|
||||
nsRefPtr<nsCaret> caret;
|
||||
aPresShell->GetCaret(getter_AddRefs(caret));
|
||||
nsRefPtr<nsCaret> caret = aPresShell->GetCaret();
|
||||
nsRect caretRect;
|
||||
nsIFrame *frame = caret->GetGeometry(domSelection, &caretRect);
|
||||
if (frame) {
|
||||
|
@ -1981,10 +1981,9 @@ nsEditor::QueryComposition(nsTextEventReply* aReply)
|
||||
if (!mPresShellWeak) return NS_ERROR_NOT_INITIALIZED;
|
||||
nsCOMPtr<nsIPresShell> ps = do_QueryReferent(mPresShellWeak);
|
||||
if (!ps) return NS_ERROR_NOT_INITIALIZED;
|
||||
nsRefPtr<nsCaret> caretP;
|
||||
result = ps->GetCaret(getter_AddRefs(caretP));
|
||||
|
||||
if (NS_SUCCEEDED(result) && caretP) {
|
||||
nsRefPtr<nsCaret> caretP = ps->GetCaret();
|
||||
|
||||
if (caretP) {
|
||||
if (aReply) {
|
||||
caretP->SetCaretDOMSelection(selection);
|
||||
|
||||
@ -4363,10 +4362,10 @@ nsresult nsEditor::EndUpdateViewBatch()
|
||||
GetPresShell(getter_AddRefs(presShell));
|
||||
|
||||
if (presShell)
|
||||
presShell->GetCaret(getter_AddRefs(caret));
|
||||
caret = presShell->GetCaret();
|
||||
|
||||
StCaretHider caretHider(caret);
|
||||
|
||||
|
||||
PRUint32 flags = 0;
|
||||
|
||||
GetFlags(&flags);
|
||||
|
@ -870,8 +870,7 @@ nsEditorEventListener::Focus(nsIDOMEvent* aEvent)
|
||||
|
||||
nsCOMPtr<nsIPresShell> presShell = GetPresShell();
|
||||
if (presShell) {
|
||||
nsRefPtr<nsCaret> caret;
|
||||
presShell->GetCaret(getter_AddRefs(caret));
|
||||
nsRefPtr<nsCaret> caret = presShell->GetCaret();
|
||||
if (caret) {
|
||||
caret->SetIgnoreUserModify(PR_FALSE);
|
||||
if (selection) {
|
||||
@ -942,8 +941,7 @@ nsEditorEventListener::Blur(nsIDOMEvent* aEvent)
|
||||
|
||||
nsCOMPtr<nsIPresShell> presShell = GetPresShell();
|
||||
if (presShell) {
|
||||
nsRefPtr<nsCaret> caret;
|
||||
presShell->GetCaret(getter_AddRefs(caret));
|
||||
nsRefPtr<nsCaret> caret = presShell->GetCaret();
|
||||
if (caret) {
|
||||
caret->SetIgnoreUserModify(PR_TRUE);
|
||||
}
|
||||
|
@ -1576,8 +1576,7 @@ nsPlaintextEditor::SetCompositionString(const nsAString& aCompositionString, nsI
|
||||
nsresult result = GetSelection(getter_AddRefs(selection));
|
||||
if (NS_FAILED(result)) return result;
|
||||
|
||||
nsRefPtr<nsCaret> caretP;
|
||||
ps->GetCaret(getter_AddRefs(caretP));
|
||||
nsRefPtr<nsCaret> caretP = ps->GetCaret();
|
||||
|
||||
// We should return caret position if it is possible. Because this event
|
||||
// dispatcher always expects to be returned the correct caret position.
|
||||
|
@ -182,8 +182,7 @@ nsDisplayListBuilder::IsMovingFrame(nsIFrame* aFrame)
|
||||
|
||||
nsCaret *
|
||||
nsDisplayListBuilder::GetCaret() {
|
||||
nsRefPtr<nsCaret> caret;
|
||||
CurrentPresShellState()->mPresShell->GetCaret(getter_AddRefs(caret));
|
||||
nsRefPtr<nsCaret> caret = CurrentPresShellState()->mPresShell->GetCaret();
|
||||
return caret;
|
||||
}
|
||||
|
||||
@ -202,8 +201,7 @@ nsDisplayListBuilder::EnterPresShell(nsIFrame* aReferenceFrame,
|
||||
if (!mBuildCaret)
|
||||
return;
|
||||
|
||||
nsRefPtr<nsCaret> caret;
|
||||
state->mPresShell->GetCaret(getter_AddRefs(caret));
|
||||
nsRefPtr<nsCaret> caret = state->mPresShell->GetCaret();
|
||||
state->mCaretFrame = caret->GetCaretFrame();
|
||||
|
||||
if (state->mCaretFrame) {
|
||||
|
@ -585,14 +585,14 @@ public:
|
||||
/**
|
||||
* Get the caret, if it exists. AddRefs it.
|
||||
*/
|
||||
NS_IMETHOD GetCaret(nsCaret **aOutCaret) = 0;
|
||||
virtual NS_HIDDEN_(already_AddRefed<nsCaret>) GetCaret() = 0;
|
||||
|
||||
/**
|
||||
* Invalidate the caret's current position if it's outside of its frame's
|
||||
* boundaries. This function is useful if you're batching selection
|
||||
* notifications and might remove the caret's frame out from under it.
|
||||
*/
|
||||
NS_IMETHOD_(void) MaybeInvalidateCaretPosition() = 0;
|
||||
virtual NS_HIDDEN_(void) MaybeInvalidateCaretPosition() = 0;
|
||||
|
||||
/**
|
||||
* Set the current caret to a new caret. To undo this, call RestoreCaret.
|
||||
|
@ -811,8 +811,8 @@ public:
|
||||
NS_IMETHOD_(void) ClearMouseCapture(nsIView* aView);
|
||||
|
||||
// caret handling
|
||||
NS_IMETHOD GetCaret(nsCaret **aOutCaret);
|
||||
NS_IMETHOD_(void) MaybeInvalidateCaretPosition();
|
||||
virtual NS_HIDDEN_(already_AddRefed<nsCaret>) GetCaret();
|
||||
virtual NS_HIDDEN_(void) MaybeInvalidateCaretPosition();
|
||||
NS_IMETHOD SetCaretEnabled(PRBool aInEnable);
|
||||
NS_IMETHOD SetCaretReadOnly(PRBool aReadOnly);
|
||||
NS_IMETHOD GetCaretEnabled(PRBool *aOutEnabled);
|
||||
@ -2784,17 +2784,14 @@ PresShell::NotifyDestroyingFrame(nsIFrame* aFrame)
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
// note that this can return a null caret, but NS_OK
|
||||
NS_IMETHODIMP PresShell::GetCaret(nsCaret **outCaret)
|
||||
already_AddRefed<nsCaret> PresShell::GetCaret()
|
||||
{
|
||||
NS_ENSURE_ARG_POINTER(outCaret);
|
||||
|
||||
*outCaret = mCaret;
|
||||
NS_IF_ADDREF(*outCaret);
|
||||
return NS_OK;
|
||||
nsCaret* caret = mCaret;
|
||||
NS_IF_ADDREF(caret);
|
||||
return caret;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP_(void) PresShell::MaybeInvalidateCaretPosition()
|
||||
void PresShell::MaybeInvalidateCaretPosition()
|
||||
{
|
||||
if (mCaret) {
|
||||
mCaret->InvalidateOutsideCaret();
|
||||
@ -6635,9 +6632,7 @@ PresShell::PrepareToUseCaretPosition(nsIWidget* aEventWidget, nsIntPoint& aTarge
|
||||
nsresult rv;
|
||||
|
||||
// check caret visibility
|
||||
nsRefPtr<nsCaret> caret;
|
||||
rv = GetCaret(getter_AddRefs(caret));
|
||||
NS_ENSURE_SUCCESS(rv, PR_FALSE);
|
||||
nsRefPtr<nsCaret> caret = GetCaret();
|
||||
NS_ENSURE_TRUE(caret, PR_FALSE);
|
||||
|
||||
PRBool caretVisible = PR_FALSE;
|
||||
|
@ -689,9 +689,8 @@ nsTextInputSelectionImpl::SetCaretReadOnly(PRBool aReadOnly)
|
||||
nsCOMPtr<nsIPresShell> shell = do_QueryReferent(mPresShellWeak, &result);
|
||||
if (shell)
|
||||
{
|
||||
nsRefPtr<nsCaret> caret;
|
||||
if (NS_SUCCEEDED(shell->GetCaret(getter_AddRefs(caret))))
|
||||
{
|
||||
nsRefPtr<nsCaret> caret = shell->GetCaret();
|
||||
if (caret) {
|
||||
nsISelection* domSel = mFrameSelection->
|
||||
GetSelection(nsISelectionController::SELECTION_NORMAL);
|
||||
if (domSel)
|
||||
@ -716,9 +715,8 @@ nsTextInputSelectionImpl::GetCaretVisible(PRBool *_retval)
|
||||
nsCOMPtr<nsIPresShell> shell = do_QueryReferent(mPresShellWeak, &result);
|
||||
if (shell)
|
||||
{
|
||||
nsRefPtr<nsCaret> caret;
|
||||
if (NS_SUCCEEDED(shell->GetCaret(getter_AddRefs(caret))))
|
||||
{
|
||||
nsRefPtr<nsCaret> caret = shell->GetCaret();
|
||||
if (caret) {
|
||||
nsISelection* domSel = mFrameSelection->
|
||||
GetSelection(nsISelectionController::SELECTION_NORMAL);
|
||||
if (domSel)
|
||||
@ -736,9 +734,8 @@ nsTextInputSelectionImpl::SetCaretVisibilityDuringSelection(PRBool aVisibility)
|
||||
nsCOMPtr<nsIPresShell> shell = do_QueryReferent(mPresShellWeak, &result);
|
||||
if (shell)
|
||||
{
|
||||
nsRefPtr<nsCaret> caret;
|
||||
if (NS_SUCCEEDED(shell->GetCaret(getter_AddRefs(caret))))
|
||||
{
|
||||
nsRefPtr<nsCaret> caret = shell->GetCaret();
|
||||
if (caret) {
|
||||
nsISelection* domSel = mFrameSelection->
|
||||
GetSelection(nsISelectionController::SELECTION_NORMAL);
|
||||
if (domSel)
|
||||
@ -1649,9 +1646,9 @@ nsTextControlFrame::CreateAnonymousContent(nsTArray<nsIContent*>& aElements)
|
||||
getter_AddRefs(domSelection))) &&
|
||||
domSelection) {
|
||||
nsCOMPtr<nsISelectionPrivate> selPriv(do_QueryInterface(domSelection));
|
||||
nsRefPtr<nsCaret> caret;
|
||||
nsRefPtr<nsCaret> caret = shell->GetCaret();
|
||||
nsCOMPtr<nsISelectionListener> listener;
|
||||
if (NS_SUCCEEDED(shell->GetCaret(getter_AddRefs(caret))) && caret) {
|
||||
if (caret) {
|
||||
listener = do_QueryInterface(caret);
|
||||
if (listener) {
|
||||
selPriv->AddSelectionListener(listener);
|
||||
@ -1883,8 +1880,7 @@ void nsTextControlFrame::SetFocus(PRBool aOn, PRBool aRepaint)
|
||||
if (!ourSel) return;
|
||||
|
||||
nsIPresShell* presShell = PresContext()->GetPresShell();
|
||||
nsRefPtr<nsCaret> caret;
|
||||
presShell->GetCaret(getter_AddRefs(caret));
|
||||
nsRefPtr<nsCaret> caret = presShell->GetCaret();
|
||||
if (!caret) return;
|
||||
caret->SetCaretDOMSelection(ourSel);
|
||||
|
||||
|
@ -788,15 +788,12 @@ nsFrameSelection::FetchDesiredX(nscoord &aDesiredX) //the x position requested b
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nsRefPtr<nsCaret> caret;
|
||||
nsresult result = mShell->GetCaret(getter_AddRefs(caret));
|
||||
if (NS_FAILED(result))
|
||||
return result;
|
||||
nsRefPtr<nsCaret> caret = mShell->GetCaret();
|
||||
if (!caret)
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
|
||||
PRInt8 index = GetIndexFromSelectionType(nsISelectionController::SELECTION_NORMAL);
|
||||
result = caret->SetCaretDOMSelection(mDomSelections[index]);
|
||||
nsresult result = caret->SetCaretDOMSelection(mDomSelections[index]);
|
||||
if (NS_FAILED(result))
|
||||
return result;
|
||||
|
||||
@ -2086,7 +2083,6 @@ nsFrameSelection::CommonPageMove(PRBool aForward,
|
||||
// expected behavior for PageMove is to scroll AND move the caret
|
||||
// and remain relative position of the caret in view. see Bug 4302.
|
||||
|
||||
nsresult result;
|
||||
//get the frame from the scrollable view
|
||||
|
||||
nsIFrame* scrolledFrame = aScrollableFrame->GetScrolledFrame();
|
||||
@ -2098,12 +2094,9 @@ nsFrameSelection::CommonPageMove(PRBool aForward,
|
||||
nsISelection* domSel = GetSelection(nsISelectionController::SELECTION_NORMAL);
|
||||
if (!domSel)
|
||||
return;
|
||||
|
||||
nsRefPtr<nsCaret> caret;
|
||||
result = mShell->GetCaret(getter_AddRefs(caret));
|
||||
if (NS_FAILED(result))
|
||||
return;
|
||||
|
||||
|
||||
nsRefPtr<nsCaret> caret = mShell->GetCaret();
|
||||
|
||||
nsRect caretPos;
|
||||
nsIFrame* caretFrame = caret->GetGeometry(domSel, &caretPos);
|
||||
if (!caretFrame)
|
||||
@ -4195,9 +4188,8 @@ nsTypedSelection::GetPrimaryFrameForFocusNode(nsIFrame **aReturnFrame, PRInt32 *
|
||||
nsFrameSelection::HINT hint = mFrameSelection->GetHint();
|
||||
|
||||
if (aVisual) {
|
||||
nsRefPtr<nsCaret> caret;
|
||||
nsresult result = presShell->GetCaret(getter_AddRefs(caret));
|
||||
if (NS_FAILED(result) || !caret)
|
||||
nsRefPtr<nsCaret> caret = presShell->GetCaret();
|
||||
if (!caret)
|
||||
return NS_ERROR_FAILURE;
|
||||
|
||||
PRUint8 caretBidiLevel = mFrameSelection->GetCaretBidiLevel();
|
||||
@ -5558,8 +5550,7 @@ nsTypedSelection::ScrollIntoView(SelectionRegion aRegion,
|
||||
result = GetPresShell(getter_AddRefs(presShell));
|
||||
if (NS_FAILED(result) || !presShell)
|
||||
return result;
|
||||
nsRefPtr<nsCaret> caret;
|
||||
presShell->GetCaret(getter_AddRefs(caret));
|
||||
nsRefPtr<nsCaret> caret = presShell->GetCaret();
|
||||
if (caret)
|
||||
{
|
||||
// Now that text frame character offsets are always valid (though not
|
||||
|
@ -552,8 +552,7 @@ CheckCaretDrawingState() {
|
||||
if (!presShell)
|
||||
return;
|
||||
|
||||
nsRefPtr<nsCaret> caret;
|
||||
presShell->GetCaret(getter_AddRefs(caret));
|
||||
nsRefPtr<nsCaret> caret = presShell->GetCaret();
|
||||
if (!caret)
|
||||
return;
|
||||
caret->CheckCaretDrawingState();
|
||||
|
Loading…
x
Reference in New Issue
Block a user