diff --git a/layout/base/nsCaret.cpp b/layout/base/nsCaret.cpp index 37c0b0b1f75..0e487073489 100644 --- a/layout/base/nsCaret.cpp +++ b/layout/base/nsCaret.cpp @@ -49,7 +49,7 @@ nsCaret::nsCaret() : mPresShell(nsnull) , mBlinkTimer(nsnull) , mBlinkRate(500) -, mVisible(PR_TRUE) +, mVisible(PR_FALSE) , mReadOnly(PR_TRUE) , mDrawn(PR_FALSE) { @@ -75,7 +75,7 @@ NS_METHOD nsCaret::Init(nsIPresShell *inPresShell, nsCaretProperties *inCaretPro mPresShell = inPresShell; // the presshell owns us, so no addref mBlinkRate = inCaretProperties->GetCaretBlinkRate(); - mCaretWidth = inCaretProperties->GetCaretWidth(); + mCaretWidth = NSIntPointsToTwips(inCaretProperties->GetCaretWidth()); // get the selection from the pres shell, and set ourselves up as a selection // listener @@ -150,13 +150,33 @@ NS_METHOD nsCaret::SetCaretReadOnly(PRBool inMakeReadonly) return NS_OK; } + +//----------------------------------------------------------------------------- +NS_METHOD nsCaret::Refresh() +{ + + if (mVisible) + { + StopBlinking(); + StartBlinking(); + } + + return NS_OK; +} + + #pragma mark - //----------------------------------------------------------------------------- NS_METHOD nsCaret::NotifySelectionChanged() { - StopBlinking(); - StartBlinking(); + + if (mVisible) + { + StopBlinking(); + StartBlinking(); + } + return NS_OK; } @@ -169,16 +189,21 @@ nsresult nsCaret::StartBlinking() mBlinkTimer = nsnull; // set up the blink timer - nsresult err = NS_NewTimer(&mBlinkTimer); + if (mBlinkRate > 0) + { + nsresult err = NS_NewTimer(&mBlinkTimer); + + if (NS_FAILED(err)) + return err; + + mBlinkTimer->Init(CaretBlinkCallback, this, mBlinkRate); + } - if (NS_FAILED(err)) - return err; - NS_ASSERTION(!mDrawn, "Caret should not be drawn here"); DrawCaret(); // draw it right away - return mBlinkTimer->Init(CaretBlinkCallback, this, mBlinkRate); + return NS_OK; } @@ -306,7 +331,8 @@ void nsCaret::DrawCaret() } // prime the timer again - mBlinkTimer->Init(CaretBlinkCallback, this, mBlinkRate); + if (mBlinkTimer) + mBlinkTimer->Init(CaretBlinkCallback, this, mBlinkRate); } diff --git a/layout/base/nsCaret.h b/layout/base/nsCaret.h index 2cccca503e1..a6d51ab5a6d 100644 --- a/layout/base/nsCaret.h +++ b/layout/base/nsCaret.h @@ -49,6 +49,7 @@ class nsCaret : public nsICaret, NS_IMETHOD SetCaretVisible(PRBool inMakeVisible); NS_IMETHOD SetCaretReadOnly(PRBool inMakeReadonly); + NS_IMETHOD Refresh(); /* nsIDOMSelectionListener interface */ NS_IMETHOD NotifySelectionChanged(); diff --git a/layout/base/nsICaret.h b/layout/base/nsICaret.h index 2e752fd4f95..5a75d08d30d 100644 --- a/layout/base/nsICaret.h +++ b/layout/base/nsICaret.h @@ -41,6 +41,11 @@ public: * PR_FALSE to show the caret in normal, editing state */ NS_IMETHOD SetCaretReadOnly(PRBool inMakeReadonly) = 0; + + /** Refresh + * Refresh the caret after the frame it is being drawn in has painted + */ + NS_IMETHOD Refresh() = 0; }; extern nsresult NS_NewCaret(nsICaret** aInstancePtrResult); diff --git a/layout/base/public/nsICaret.h b/layout/base/public/nsICaret.h index 2e752fd4f95..5a75d08d30d 100644 --- a/layout/base/public/nsICaret.h +++ b/layout/base/public/nsICaret.h @@ -41,6 +41,11 @@ public: * PR_FALSE to show the caret in normal, editing state */ NS_IMETHOD SetCaretReadOnly(PRBool inMakeReadonly) = 0; + + /** Refresh + * Refresh the caret after the frame it is being drawn in has painted + */ + NS_IMETHOD Refresh() = 0; }; extern nsresult NS_NewCaret(nsICaret** aInstancePtrResult); diff --git a/layout/base/src/nsCaret.cpp b/layout/base/src/nsCaret.cpp index 37c0b0b1f75..0e487073489 100644 --- a/layout/base/src/nsCaret.cpp +++ b/layout/base/src/nsCaret.cpp @@ -49,7 +49,7 @@ nsCaret::nsCaret() : mPresShell(nsnull) , mBlinkTimer(nsnull) , mBlinkRate(500) -, mVisible(PR_TRUE) +, mVisible(PR_FALSE) , mReadOnly(PR_TRUE) , mDrawn(PR_FALSE) { @@ -75,7 +75,7 @@ NS_METHOD nsCaret::Init(nsIPresShell *inPresShell, nsCaretProperties *inCaretPro mPresShell = inPresShell; // the presshell owns us, so no addref mBlinkRate = inCaretProperties->GetCaretBlinkRate(); - mCaretWidth = inCaretProperties->GetCaretWidth(); + mCaretWidth = NSIntPointsToTwips(inCaretProperties->GetCaretWidth()); // get the selection from the pres shell, and set ourselves up as a selection // listener @@ -150,13 +150,33 @@ NS_METHOD nsCaret::SetCaretReadOnly(PRBool inMakeReadonly) return NS_OK; } + +//----------------------------------------------------------------------------- +NS_METHOD nsCaret::Refresh() +{ + + if (mVisible) + { + StopBlinking(); + StartBlinking(); + } + + return NS_OK; +} + + #pragma mark - //----------------------------------------------------------------------------- NS_METHOD nsCaret::NotifySelectionChanged() { - StopBlinking(); - StartBlinking(); + + if (mVisible) + { + StopBlinking(); + StartBlinking(); + } + return NS_OK; } @@ -169,16 +189,21 @@ nsresult nsCaret::StartBlinking() mBlinkTimer = nsnull; // set up the blink timer - nsresult err = NS_NewTimer(&mBlinkTimer); + if (mBlinkRate > 0) + { + nsresult err = NS_NewTimer(&mBlinkTimer); + + if (NS_FAILED(err)) + return err; + + mBlinkTimer->Init(CaretBlinkCallback, this, mBlinkRate); + } - if (NS_FAILED(err)) - return err; - NS_ASSERTION(!mDrawn, "Caret should not be drawn here"); DrawCaret(); // draw it right away - return mBlinkTimer->Init(CaretBlinkCallback, this, mBlinkRate); + return NS_OK; } @@ -306,7 +331,8 @@ void nsCaret::DrawCaret() } // prime the timer again - mBlinkTimer->Init(CaretBlinkCallback, this, mBlinkRate); + if (mBlinkTimer) + mBlinkTimer->Init(CaretBlinkCallback, this, mBlinkRate); } diff --git a/layout/base/src/nsCaret.h b/layout/base/src/nsCaret.h index 2cccca503e1..a6d51ab5a6d 100644 --- a/layout/base/src/nsCaret.h +++ b/layout/base/src/nsCaret.h @@ -49,6 +49,7 @@ class nsCaret : public nsICaret, NS_IMETHOD SetCaretVisible(PRBool inMakeVisible); NS_IMETHOD SetCaretReadOnly(PRBool inMakeReadonly); + NS_IMETHOD Refresh(); /* nsIDOMSelectionListener interface */ NS_IMETHOD NotifySelectionChanged();