diff --git a/content/base/src/nsSelection.cpp b/content/base/src/nsSelection.cpp index 69ed2dc3388..209a07097cf 100644 --- a/content/base/src/nsSelection.cpp +++ b/content/base/src/nsSelection.cpp @@ -3827,13 +3827,13 @@ nsDOMSelection::DoAutoScroll(nsIPresContext *aPresContext, nsIFrame *aFrame, nsP nsIView *view = (nsIView*)frameView; nscoord x, y; - while (view && view != scrolledView) + while (view && view != cView) { result = view->GetParent(view); if (NS_FAILED(result)) view = 0; - else if (view && view != scrolledView) + else if (view && view != cView) { result = view->GetPosition(&x, &y); @@ -5517,11 +5517,11 @@ nsDOMSelection::ScrollIntoView(SelectionRegion aRegion) result = GetPresShell(getter_AddRefs(presShell)); if (NS_FAILED(result)) return result; - nsCOMPtr selCon; - selCon = do_QueryInterface(presShell); - if (selCon) + nsCOMPtr caret; + presShell->GetCaret(getter_AddRefs(caret)); + if (caret) { - StCaretHider caretHider(selCon); // stack-based class hides and shows the caret + StCaretHider caretHider(caret); // stack-based class hides and shows the caret // // Scroll the selection region into view. diff --git a/layout/base/nsCaret.cpp b/layout/base/nsCaret.cpp index a6595ce85d1..360bfd69751 100644 --- a/layout/base/nsCaret.cpp +++ b/layout/base/nsCaret.cpp @@ -158,11 +158,18 @@ NS_IMETHODIMP nsCaret::QueryInterface(const nsIID& aIID, return status; } +//----------------------------------------------------------------------------- +NS_IMETHODIMP nsCaret::SetCaretDOMSelection(nsIDOMSelection *aDOMSel) +{ + NS_ENSURE_ARG_POINTER(aDOMSel); + mDomSelectionWeak = getter_AddRefs( NS_GetWeakReference(aDOMSel) ); // weak reference to pres shell + return NS_OK; +} + //----------------------------------------------------------------------------- -NS_IMETHODIMP nsCaret::SetCaretVisible(PRBool inMakeVisible, nsIDOMSelection *aDOMSel) +NS_IMETHODIMP nsCaret::SetCaretVisible(PRBool inMakeVisible) { - mDomSelectionWeak = getter_AddRefs( NS_GetWeakReference(aDOMSel) ); // weak reference to pres shell mVisible = inMakeVisible; nsresult err = NS_OK; if (mVisible) @@ -173,12 +180,17 @@ NS_IMETHODIMP nsCaret::SetCaretVisible(PRBool inMakeVisible, nsIDOMSelection *aD return err; } +NS_IMETHODIMP nsCaret::GetCaretVisible(PRBool *outMakeVisible) +{ + NS_ENSURE_ARG_POINTER(outMakeVisible); + *outMakeVisible = mVisible; + return NS_OK; +} + //----------------------------------------------------------------------------- -NS_IMETHODIMP nsCaret::SetCaretReadOnly(PRBool inMakeReadonly, nsIDOMSelection *aDOMSel) +NS_IMETHODIMP nsCaret::SetCaretReadOnly(PRBool inMakeReadonly) { - mDomSelectionWeak = getter_AddRefs( NS_GetWeakReference(aDOMSel) ); // weak reference to pres shell - mReadOnly = inMakeReadonly; return NS_OK; } @@ -323,12 +335,11 @@ NS_IMETHODIMP nsCaret::ClearFrameRefs(nsIFrame* aFrame) //----------------------------------------------------------------------------- NS_IMETHODIMP nsCaret::NotifySelectionChanged(nsIDOMDocument *, nsIDOMSelection *aDomSel, short) { + if (mVisible) + StopBlinking(); mDomSelectionWeak = getter_AddRefs( NS_GetWeakReference(aDomSel) ); // weak reference to pres shell if (mVisible) - { - StopBlinking(); StartBlinking(); - } return NS_OK; } diff --git a/layout/base/nsCaret.h b/layout/base/nsCaret.h index 1ab9ae9be17..f810a53afdf 100644 --- a/layout/base/nsCaret.h +++ b/layout/base/nsCaret.h @@ -53,9 +53,11 @@ class nsCaret : public nsICaret, // nsICaret interface NS_IMETHOD Init(nsIPresShell *inPresShell); - NS_IMETHOD SetCaretVisible(PRBool inMakeVisible, nsIDOMSelection *aSel); - NS_IMETHOD SetCaretReadOnly(PRBool inMakeReadonly, nsIDOMSelection *aSel); - NS_IMETHOD GetWindowRelativeCoordinates(nsRect& outCoordinates, PRBool& outIsCollapsed, nsIDOMSelection *aDOMSel); + NS_IMETHOD SetCaretDOMSelection(nsIDOMSelection *inDOMSel); + NS_IMETHOD GetCaretVisible(PRBool *outMakeVisible); + NS_IMETHOD SetCaretVisible(PRBool intMakeVisible); + NS_IMETHOD SetCaretReadOnly(PRBool inMakeReadonly); + NS_IMETHOD GetWindowRelativeCoordinates(nsRect& outCoordinates, PRBool& outIsCollapsed, nsIDOMSelection *inDOMSel); NS_IMETHOD ClearFrameRefs(nsIFrame* aFrame); //nsIDOMSelectionListener interface diff --git a/layout/base/nsICaret.h b/layout/base/nsICaret.h index a9654f49662..f5dba482160 100644 --- a/layout/base/nsICaret.h +++ b/layout/base/nsICaret.h @@ -44,16 +44,23 @@ public: NS_IMETHOD Init(nsIPresShell *inPresShell) = 0; + NS_IMETHOD SetCaretDOMSelection(nsIDOMSelection *aDOMSel) = 0; + /** SetCaretVisible will set the visibility of the caret * @param inMakeVisible PR_TRUE to show the caret, PR_FALSE to hide it */ - NS_IMETHOD SetCaretVisible(PRBool inMakeVisible, nsIDOMSelection *aDOMSel) = 0; + NS_IMETHOD SetCaretVisible(PRBool inMakeVisible) = 0; + + /** GetCaretVisible will get the visibility of the caret + * @param inMakeVisible PR_TRUE it is shown, PR_FALSE it is hidden + */ + NS_IMETHOD GetCaretVisible(PRBool *outMakeVisible) = 0; /** SetCaretReadOnly set the appearance of the caret * @param inMakeReadonly PR_TRUE to show the caret in a 'read only' state, * PR_FALSE to show the caret in normal, editing state */ - NS_IMETHOD SetCaretReadOnly(PRBool inMakeReadonly, nsIDOMSelection *aDOMSel) = 0; + NS_IMETHOD SetCaretReadOnly(PRBool inMakeReadonly) = 0; /** GetWindowRelativeCoordinates * Get the position of the caret in (top-level) window coordinates. @@ -80,30 +87,28 @@ extern nsresult NS_NewCaret(nsICaret** aInstancePtrResult); class StCaretHider { public: - StCaretHider(nsISelectionController* aSelCon) - : mWasVisible(PR_FALSE), mSelCon(nsnull) + StCaretHider(nsICaret* aSelCon) + : mWasVisible(PR_FALSE), mCaret(aSelCon) { - mSelCon = aSelCon; // addrefs - if (mSelCon) + if (mCaret) { - mSelCon->GetCaretEnabled(&mWasVisible); + mCaret->GetCaretVisible(&mWasVisible); if (mWasVisible) - mSelCon->SetCaretEnabled(PR_FALSE); + mCaret->SetCaretVisible(PR_FALSE); } } ~StCaretHider() { - if (mSelCon && mWasVisible) - mSelCon->SetCaretEnabled(PR_TRUE); + if (mCaret && mWasVisible) + mCaret->SetCaretVisible(PR_TRUE); // nsCOMPtr releases mPresShell } protected: PRBool mWasVisible; - nsCOMPtr mSelCon; - + nsCOMPtr mCaret; }; diff --git a/layout/base/public/nsICaret.h b/layout/base/public/nsICaret.h index a9654f49662..f5dba482160 100644 --- a/layout/base/public/nsICaret.h +++ b/layout/base/public/nsICaret.h @@ -44,16 +44,23 @@ public: NS_IMETHOD Init(nsIPresShell *inPresShell) = 0; + NS_IMETHOD SetCaretDOMSelection(nsIDOMSelection *aDOMSel) = 0; + /** SetCaretVisible will set the visibility of the caret * @param inMakeVisible PR_TRUE to show the caret, PR_FALSE to hide it */ - NS_IMETHOD SetCaretVisible(PRBool inMakeVisible, nsIDOMSelection *aDOMSel) = 0; + NS_IMETHOD SetCaretVisible(PRBool inMakeVisible) = 0; + + /** GetCaretVisible will get the visibility of the caret + * @param inMakeVisible PR_TRUE it is shown, PR_FALSE it is hidden + */ + NS_IMETHOD GetCaretVisible(PRBool *outMakeVisible) = 0; /** SetCaretReadOnly set the appearance of the caret * @param inMakeReadonly PR_TRUE to show the caret in a 'read only' state, * PR_FALSE to show the caret in normal, editing state */ - NS_IMETHOD SetCaretReadOnly(PRBool inMakeReadonly, nsIDOMSelection *aDOMSel) = 0; + NS_IMETHOD SetCaretReadOnly(PRBool inMakeReadonly) = 0; /** GetWindowRelativeCoordinates * Get the position of the caret in (top-level) window coordinates. @@ -80,30 +87,28 @@ extern nsresult NS_NewCaret(nsICaret** aInstancePtrResult); class StCaretHider { public: - StCaretHider(nsISelectionController* aSelCon) - : mWasVisible(PR_FALSE), mSelCon(nsnull) + StCaretHider(nsICaret* aSelCon) + : mWasVisible(PR_FALSE), mCaret(aSelCon) { - mSelCon = aSelCon; // addrefs - if (mSelCon) + if (mCaret) { - mSelCon->GetCaretEnabled(&mWasVisible); + mCaret->GetCaretVisible(&mWasVisible); if (mWasVisible) - mSelCon->SetCaretEnabled(PR_FALSE); + mCaret->SetCaretVisible(PR_FALSE); } } ~StCaretHider() { - if (mSelCon && mWasVisible) - mSelCon->SetCaretEnabled(PR_TRUE); + if (mCaret && mWasVisible) + mCaret->SetCaretVisible(PR_TRUE); // nsCOMPtr releases mPresShell } protected: PRBool mWasVisible; - nsCOMPtr mSelCon; - + nsCOMPtr mCaret; }; diff --git a/layout/base/src/nsCaret.cpp b/layout/base/src/nsCaret.cpp index a6595ce85d1..360bfd69751 100644 --- a/layout/base/src/nsCaret.cpp +++ b/layout/base/src/nsCaret.cpp @@ -158,11 +158,18 @@ NS_IMETHODIMP nsCaret::QueryInterface(const nsIID& aIID, return status; } +//----------------------------------------------------------------------------- +NS_IMETHODIMP nsCaret::SetCaretDOMSelection(nsIDOMSelection *aDOMSel) +{ + NS_ENSURE_ARG_POINTER(aDOMSel); + mDomSelectionWeak = getter_AddRefs( NS_GetWeakReference(aDOMSel) ); // weak reference to pres shell + return NS_OK; +} + //----------------------------------------------------------------------------- -NS_IMETHODIMP nsCaret::SetCaretVisible(PRBool inMakeVisible, nsIDOMSelection *aDOMSel) +NS_IMETHODIMP nsCaret::SetCaretVisible(PRBool inMakeVisible) { - mDomSelectionWeak = getter_AddRefs( NS_GetWeakReference(aDOMSel) ); // weak reference to pres shell mVisible = inMakeVisible; nsresult err = NS_OK; if (mVisible) @@ -173,12 +180,17 @@ NS_IMETHODIMP nsCaret::SetCaretVisible(PRBool inMakeVisible, nsIDOMSelection *aD return err; } +NS_IMETHODIMP nsCaret::GetCaretVisible(PRBool *outMakeVisible) +{ + NS_ENSURE_ARG_POINTER(outMakeVisible); + *outMakeVisible = mVisible; + return NS_OK; +} + //----------------------------------------------------------------------------- -NS_IMETHODIMP nsCaret::SetCaretReadOnly(PRBool inMakeReadonly, nsIDOMSelection *aDOMSel) +NS_IMETHODIMP nsCaret::SetCaretReadOnly(PRBool inMakeReadonly) { - mDomSelectionWeak = getter_AddRefs( NS_GetWeakReference(aDOMSel) ); // weak reference to pres shell - mReadOnly = inMakeReadonly; return NS_OK; } @@ -323,12 +335,11 @@ NS_IMETHODIMP nsCaret::ClearFrameRefs(nsIFrame* aFrame) //----------------------------------------------------------------------------- NS_IMETHODIMP nsCaret::NotifySelectionChanged(nsIDOMDocument *, nsIDOMSelection *aDomSel, short) { + if (mVisible) + StopBlinking(); mDomSelectionWeak = getter_AddRefs( NS_GetWeakReference(aDomSel) ); // weak reference to pres shell if (mVisible) - { - StopBlinking(); StartBlinking(); - } return NS_OK; } diff --git a/layout/base/src/nsCaret.h b/layout/base/src/nsCaret.h index 1ab9ae9be17..f810a53afdf 100644 --- a/layout/base/src/nsCaret.h +++ b/layout/base/src/nsCaret.h @@ -53,9 +53,11 @@ class nsCaret : public nsICaret, // nsICaret interface NS_IMETHOD Init(nsIPresShell *inPresShell); - NS_IMETHOD SetCaretVisible(PRBool inMakeVisible, nsIDOMSelection *aSel); - NS_IMETHOD SetCaretReadOnly(PRBool inMakeReadonly, nsIDOMSelection *aSel); - NS_IMETHOD GetWindowRelativeCoordinates(nsRect& outCoordinates, PRBool& outIsCollapsed, nsIDOMSelection *aDOMSel); + NS_IMETHOD SetCaretDOMSelection(nsIDOMSelection *inDOMSel); + NS_IMETHOD GetCaretVisible(PRBool *outMakeVisible); + NS_IMETHOD SetCaretVisible(PRBool intMakeVisible); + NS_IMETHOD SetCaretReadOnly(PRBool inMakeReadonly); + NS_IMETHOD GetWindowRelativeCoordinates(nsRect& outCoordinates, PRBool& outIsCollapsed, nsIDOMSelection *inDOMSel); NS_IMETHOD ClearFrameRefs(nsIFrame* aFrame); //nsIDOMSelectionListener interface diff --git a/layout/base/src/nsSelection.cpp b/layout/base/src/nsSelection.cpp index 69ed2dc3388..209a07097cf 100644 --- a/layout/base/src/nsSelection.cpp +++ b/layout/base/src/nsSelection.cpp @@ -3827,13 +3827,13 @@ nsDOMSelection::DoAutoScroll(nsIPresContext *aPresContext, nsIFrame *aFrame, nsP nsIView *view = (nsIView*)frameView; nscoord x, y; - while (view && view != scrolledView) + while (view && view != cView) { result = view->GetParent(view); if (NS_FAILED(result)) view = 0; - else if (view && view != scrolledView) + else if (view && view != cView) { result = view->GetPosition(&x, &y); @@ -5517,11 +5517,11 @@ nsDOMSelection::ScrollIntoView(SelectionRegion aRegion) result = GetPresShell(getter_AddRefs(presShell)); if (NS_FAILED(result)) return result; - nsCOMPtr selCon; - selCon = do_QueryInterface(presShell); - if (selCon) + nsCOMPtr caret; + presShell->GetCaret(getter_AddRefs(caret)); + if (caret) { - StCaretHider caretHider(selCon); // stack-based class hides and shows the caret + StCaretHider caretHider(caret); // stack-based class hides and shows the caret // // Scroll the selection region into view. diff --git a/layout/generic/nsSelection.cpp b/layout/generic/nsSelection.cpp index 69ed2dc3388..209a07097cf 100644 --- a/layout/generic/nsSelection.cpp +++ b/layout/generic/nsSelection.cpp @@ -3827,13 +3827,13 @@ nsDOMSelection::DoAutoScroll(nsIPresContext *aPresContext, nsIFrame *aFrame, nsP nsIView *view = (nsIView*)frameView; nscoord x, y; - while (view && view != scrolledView) + while (view && view != cView) { result = view->GetParent(view); if (NS_FAILED(result)) view = 0; - else if (view && view != scrolledView) + else if (view && view != cView) { result = view->GetPosition(&x, &y); @@ -5517,11 +5517,11 @@ nsDOMSelection::ScrollIntoView(SelectionRegion aRegion) result = GetPresShell(getter_AddRefs(presShell)); if (NS_FAILED(result)) return result; - nsCOMPtr selCon; - selCon = do_QueryInterface(presShell); - if (selCon) + nsCOMPtr caret; + presShell->GetCaret(getter_AddRefs(caret)); + if (caret) { - StCaretHider caretHider(selCon); // stack-based class hides and shows the caret + StCaretHider caretHider(caret); // stack-based class hides and shows the caret // // Scroll the selection region into view.