bug = 34896, r= hyatt. changing caret apis. this will demand that when a caret changes focus a call to setDOMSelection must be called to tell the caret what selection to listen to.

This commit is contained in:
mjudge%netscape.com 2000-06-01 02:37:40 +00:00
Родитель 030fdb7a16
Коммит a14d4fbfb0
9 изменённых файлов: 100 добавлений и 64 удалений

Просмотреть файл

@ -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<nsISelectionController> selCon;
selCon = do_QueryInterface(presShell);
if (selCon)
nsCOMPtr<nsICaret> 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.

Просмотреть файл

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

Просмотреть файл

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

Просмотреть файл

@ -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<nsISelectionController> mSelCon;
nsCOMPtr<nsICaret> mCaret;
};

Просмотреть файл

@ -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<nsISelectionController> mSelCon;
nsCOMPtr<nsICaret> mCaret;
};

Просмотреть файл

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

Просмотреть файл

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

Просмотреть файл

@ -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<nsISelectionController> selCon;
selCon = do_QueryInterface(presShell);
if (selCon)
nsCOMPtr<nsICaret> 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.

Просмотреть файл

@ -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<nsISelectionController> selCon;
selCon = do_QueryInterface(presShell);
if (selCon)
nsCOMPtr<nsICaret> 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.