1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* vim: set ts=8 sts=2 et sw=2 tw=80: */
3 /* This Source Code Form is subject to the terms of the Mozilla Public
4 * License, v. 2.0. If a copy of the MPL was not distributed with this
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
7 /* the caret is the text cursor used, e.g., when editing */
14 #include "mozilla/CaretAssociationHint.h"
15 #include "mozilla/gfx/2D.h"
16 #include "mozilla/intl/BidiEmbeddingLevel.h"
17 #include "mozilla/StaticPrefs_bidi.h"
19 #include "nsFontMetrics.h"
21 #include "nsFrameSelection.h"
23 #include "nsIScrollableFrame.h"
24 #include "nsIContent.h"
25 #include "nsIFrameInlines.h"
26 #include "nsLayoutUtils.h"
27 #include "nsPresContext.h"
28 #include "nsBlockFrame.h"
29 #include "nsISelectionController.h"
30 #include "nsTextFrame.h"
31 #include "nsXULPopupManager.h"
32 #include "nsMenuPopupFrame.h"
33 #include "nsTextFragment.h"
34 #include "mozilla/Preferences.h"
35 #include "mozilla/PresShell.h"
36 #include "mozilla/LookAndFeel.h"
37 #include "mozilla/dom/Selection.h"
38 #include "nsIBidiKeyboard.h"
39 #include "nsContentUtils.h"
40 #include "SelectionMovementUtils.h"
42 using namespace mozilla
;
43 using namespace mozilla::dom
;
44 using namespace mozilla::gfx
;
46 using BidiEmbeddingLevel
= mozilla::intl::BidiEmbeddingLevel
;
48 // The bidi indicator hangs off the caret to one side, to show which
49 // direction the typing is in. It needs to be at least 2x2 to avoid looking
50 // like an insignificant dot
51 static const int32_t kMinBidiIndicatorPixels
= 2;
53 nsCaret::nsCaret() = default;
55 nsCaret::~nsCaret() { StopBlinking(); }
57 nsresult
nsCaret::Init(PresShell
* aPresShell
) {
58 NS_ENSURE_ARG(aPresShell
);
61 do_GetWeakReference(aPresShell
); // the presshell owns us, so no addref
62 NS_ASSERTION(mPresShell
, "Hey, pres shell should support weak refs");
64 RefPtr
<Selection
> selection
=
65 aPresShell
->GetSelection(nsISelectionController::SELECTION_NORMAL
);
67 return NS_ERROR_FAILURE
;
70 selection
->AddSelectionListener(this);
71 mDomSelectionWeak
= selection
;
72 UpdateCaretPositionFromSelectionIfNeeded();
77 static bool DrawCJKCaret(nsIFrame
* aFrame
, int32_t aOffset
) {
78 nsIContent
* content
= aFrame
->GetContent();
79 const nsTextFragment
* frag
= content
->GetText();
83 if (aOffset
< 0 || static_cast<uint32_t>(aOffset
) >= frag
->GetLength()) {
86 const char16_t ch
= frag
->CharAt(AssertedCast
<uint32_t>(aOffset
));
87 return 0x2e80 <= ch
&& ch
<= 0xd7ff;
90 nsCaret::Metrics
nsCaret::ComputeMetrics(nsIFrame
* aFrame
, int32_t aOffset
,
91 nscoord aCaretHeight
) {
92 // Compute nominal sizes in appunits
95 LookAndFeel::GetFloat(LookAndFeel::FloatID::CaretAspectRatio
, 0.0f
)) +
96 nsPresContext::CSSPixelsToAppUnits(
97 LookAndFeel::GetInt(LookAndFeel::IntID::CaretWidth
, 1));
99 if (DrawCJKCaret(aFrame
, aOffset
)) {
100 caretWidth
+= nsPresContext::CSSPixelsToAppUnits(1);
102 nscoord bidiIndicatorSize
=
103 nsPresContext::CSSPixelsToAppUnits(kMinBidiIndicatorPixels
);
104 bidiIndicatorSize
= std::max(caretWidth
, bidiIndicatorSize
);
106 // Round them to device pixels. Always round down, except that anything
107 // between 0 and 1 goes up to 1 so we don't let the caret disappear.
108 int32_t tpp
= aFrame
->PresContext()->AppUnitsPerDevPixel();
110 result
.mCaretWidth
= NS_ROUND_BORDER_TO_PIXELS(caretWidth
, tpp
);
111 result
.mBidiIndicatorSize
= NS_ROUND_BORDER_TO_PIXELS(bidiIndicatorSize
, tpp
);
115 void nsCaret::Terminate() {
116 // this doesn't erase the caret if it's drawn. Should it? We might not have
117 // a good drawing environment during teardown.
120 mBlinkTimer
= nullptr;
122 // unregiser ourselves as a selection listener
123 if (mDomSelectionWeak
) {
124 mDomSelectionWeak
->RemoveSelectionListener(this);
126 mDomSelectionWeak
= nullptr;
127 mPresShell
= nullptr;
131 NS_IMPL_ISUPPORTS(nsCaret
, nsISelectionListener
)
133 Selection
* nsCaret::GetSelection() { return mDomSelectionWeak
; }
135 void nsCaret::SetSelection(Selection
* aDOMSel
) {
137 mDomSelectionWeak
= aDOMSel
;
138 UpdateCaretPositionFromSelectionIfNeeded();
143 void nsCaret::SetVisible(bool aVisible
) {
144 const bool wasVisible
= mVisible
;
146 mIgnoreUserModify
= aVisible
;
147 if (mVisible
!= wasVisible
) {
148 CaretVisibilityMaybeChanged();
152 bool nsCaret::IsVisible() const { return mVisible
&& !mHideCount
; }
154 void nsCaret::CaretVisibilityMaybeChanged() {
158 // We ignore caret position updates when the caret is not visible, so we
159 // update the caret position here if needed.
160 UpdateCaretPositionFromSelectionIfNeeded();
164 void nsCaret::AddForceHide() {
165 MOZ_ASSERT(mHideCount
< UINT32_MAX
);
166 if (++mHideCount
> 1) {
169 CaretVisibilityMaybeChanged();
172 void nsCaret::RemoveForceHide() {
173 if (!mHideCount
|| --mHideCount
) {
176 CaretVisibilityMaybeChanged();
179 void nsCaret::SetCaretReadOnly(bool aReadOnly
) {
180 mReadOnly
= aReadOnly
;
185 // Clamp the inline-position to be within our closest scroll frame and any
186 // ancestor clips if any. If we don't, then it clips us, and we don't appear at
187 // all. See bug 335560 and bug 1539720.
188 static nsPoint
AdjustRectForClipping(const nsRect
& aRect
, nsIFrame
* aFrame
,
190 nsRect rectRelativeToClip
= aRect
;
191 nsIScrollableFrame
* sf
= nullptr;
192 nsIFrame
* scrollFrame
= nullptr;
193 for (nsIFrame
* current
= aFrame
; current
; current
= current
->GetParent()) {
194 if ((sf
= do_QueryFrame(current
))) {
195 scrollFrame
= current
;
198 if (current
->IsTransformed()) {
199 // We don't account for transforms in rectRelativeToCurrent, so stop
203 rectRelativeToClip
+= current
->GetPosition();
210 nsRect clipRect
= sf
->GetScrollPortRect();
212 const auto& disp
= *scrollFrame
->StyleDisplay();
213 if (disp
.mOverflowClipBoxBlock
== StyleOverflowClipBox::ContentBox
||
214 disp
.mOverflowClipBoxInline
== StyleOverflowClipBox::ContentBox
) {
215 const WritingMode wm
= scrollFrame
->GetWritingMode();
216 const bool cbH
= (wm
.IsVertical() ? disp
.mOverflowClipBoxBlock
217 : disp
.mOverflowClipBoxInline
) ==
218 StyleOverflowClipBox::ContentBox
;
219 const bool cbV
= (wm
.IsVertical() ? disp
.mOverflowClipBoxInline
220 : disp
.mOverflowClipBoxBlock
) ==
221 StyleOverflowClipBox::ContentBox
;
222 nsMargin padding
= scrollFrame
->GetUsedPadding();
224 padding
.left
= padding
.right
= 0;
227 padding
.top
= padding
.bottom
= 0;
229 clipRect
.Deflate(padding
);
233 // Now see if the caret extends beyond the view's bounds. If it does, then
234 // snap it back, put it as close to the edge as it can.
236 nscoord overflow
= rectRelativeToClip
.YMost() - clipRect
.YMost();
238 offset
.y
-= overflow
;
240 overflow
= rectRelativeToClip
.y
- clipRect
.y
;
242 offset
.y
-= overflow
;
246 nscoord overflow
= rectRelativeToClip
.XMost() - clipRect
.XMost();
248 offset
.x
-= overflow
;
250 overflow
= rectRelativeToClip
.x
- clipRect
.x
;
252 offset
.x
-= overflow
;
260 nsRect
nsCaret::GetGeometryForFrame(nsIFrame
* aFrame
, int32_t aFrameOffset
,
261 nscoord
* aBidiIndicatorSize
) {
262 nsPoint
framePos(0, 0);
264 nsresult rv
= aFrame
->GetPointFromOffset(aFrameOffset
, &framePos
);
266 if (aBidiIndicatorSize
) {
267 *aBidiIndicatorSize
= 0;
272 nsIFrame
* frame
= aFrame
->GetContentInsertionFrame();
276 NS_ASSERTION(!frame
->HasAnyStateBits(NS_FRAME_IN_REFLOW
),
277 "We should not be in the middle of reflow");
278 WritingMode wm
= aFrame
->GetWritingMode();
279 RefPtr
<nsFontMetrics
> fm
=
280 nsLayoutUtils::GetInflatedFontMetricsForFrame(aFrame
);
281 const auto caretBlockAxisMetrics
= frame
->GetCaretBlockAxisMetrics(wm
, *fm
);
282 const bool vertical
= wm
.IsVertical();
283 Metrics caretMetrics
=
284 ComputeMetrics(aFrame
, aFrameOffset
, caretBlockAxisMetrics
.mExtent
);
286 nscoord inlineOffset
= 0;
287 if (nsTextFrame
* textFrame
= do_QueryFrame(aFrame
)) {
288 if (gfxTextRun
* textRun
= textFrame
->GetTextRun(nsTextFrame::eInflated
)) {
289 // For "upstream" text where the textrun direction is reversed from the
290 // frame's inline-dir we want the caret to be painted before rather than
291 // after its nominal inline position, so we offset by its width.
292 const bool textRunDirIsReverseOfFrame
=
293 wm
.IsInlineReversed() != textRun
->IsInlineReversed();
294 // However, in sideways-lr mode we invert this behavior because this is
295 // the one writing mode where bidi-LTR corresponds to inline-reversed
296 // already, which reverses the desired caret placement behavior.
297 // Note that the following condition is equivalent to:
298 // if ( (!textRun->IsSidewaysLeft() && textRunDirIsReverseOfFrame) ||
299 // (textRun->IsSidewaysLeft() && !textRunDirIsReverseOfFrame) )
300 if (textRunDirIsReverseOfFrame
!= textRun
->IsSidewaysLeft()) {
301 inlineOffset
= wm
.IsBidiLTR() ? -caretMetrics
.mCaretWidth
302 : caretMetrics
.mCaretWidth
;
307 // on RTL frames the right edge of mCaretRect must be equal to framePos
308 if (aFrame
->StyleVisibility()->mDirection
== StyleDirection::Rtl
) {
310 inlineOffset
-= caretMetrics
.mCaretWidth
;
312 inlineOffset
-= caretMetrics
.mCaretWidth
;
317 framePos
.x
= caretBlockAxisMetrics
.mOffset
;
318 framePos
.y
+= inlineOffset
;
320 framePos
.x
+= inlineOffset
;
321 framePos
.y
= caretBlockAxisMetrics
.mOffset
;
324 rect
= nsRect(framePos
, vertical
? nsSize(caretBlockAxisMetrics
.mExtent
,
325 caretMetrics
.mCaretWidth
)
326 : nsSize(caretMetrics
.mCaretWidth
,
327 caretBlockAxisMetrics
.mExtent
));
329 rect
.MoveBy(AdjustRectForClipping(rect
, aFrame
, vertical
));
330 if (aBidiIndicatorSize
) {
331 *aBidiIndicatorSize
= caretMetrics
.mBidiIndicatorSize
;
336 auto nsCaret::CaretPositionFor(const Selection
* aSelection
) -> CaretPosition
{
340 const nsFrameSelection
* frameSelection
= aSelection
->GetFrameSelection();
341 if (!frameSelection
) {
344 nsINode
* node
= aSelection
->GetFocusNode();
350 int32_t(aSelection
->FocusOffset()),
351 frameSelection
->GetHint(),
352 frameSelection
->GetCaretBidiLevel(),
356 CaretFrameData
nsCaret::GetFrameAndOffset(const CaretPosition
& aPosition
) {
357 nsINode
* focusNode
= aPosition
.mContent
;
358 int32_t focusOffset
= aPosition
.mOffset
;
360 if (!focusNode
|| !focusNode
->IsContent()) {
364 nsIContent
* contentNode
= focusNode
->AsContent();
365 return SelectionMovementUtils::GetCaretFrameForNodeOffset(
366 nullptr, contentNode
, focusOffset
, aPosition
.mHint
, aPosition
.mBidiLevel
,
367 ForceEditableRegion::No
);
371 nsIFrame
* nsCaret::GetGeometry(const Selection
* aSelection
, nsRect
* aRect
) {
372 auto data
= GetFrameAndOffset(CaretPositionFor(aSelection
));
375 GetGeometryForFrame(data
.mFrame
, data
.mOffsetInFrameContent
, nullptr);
380 [[nodiscard
]] static nsIFrame
* GetContainingBlockIfNeeded(nsIFrame
* aFrame
) {
381 if (aFrame
->IsBlockOutside() || aFrame
->IsBlockFrameOrSubclass()) {
384 return aFrame
->GetContainingBlock();
387 void nsCaret::SchedulePaint() {
388 if (mLastPaintedFrame
) {
389 mLastPaintedFrame
->SchedulePaint();
390 mLastPaintedFrame
= nullptr;
392 auto data
= GetFrameAndOffset(mCaretPosition
);
396 nsIFrame
* frame
= data
.mFrame
;
397 if (nsIFrame
* cb
= GetContainingBlockIfNeeded(frame
)) {
400 frame
->SchedulePaint();
403 void nsCaret::SetVisibilityDuringSelection(bool aVisibility
) {
404 if (mShowDuringSelection
== aVisibility
) {
407 mShowDuringSelection
= aVisibility
;
408 if (mHiddenDuringSelection
&& aVisibility
) {
410 mHiddenDuringSelection
= false;
415 void nsCaret::UpdateCaretPositionFromSelectionIfNeeded() {
416 if (mFixedCaretPosition
) {
419 CaretPosition newPos
= CaretPositionFor(GetSelection());
420 if (newPos
== mCaretPosition
) {
423 mCaretPosition
= newPos
;
427 void nsCaret::SetCaretPosition(nsINode
* aNode
, int32_t aOffset
) {
428 // Schedule a paint with the old position to invalidate.
429 mFixedCaretPosition
= !!aNode
;
430 if (mFixedCaretPosition
) {
431 mCaretPosition
= {aNode
, aOffset
};
434 UpdateCaretPositionFromSelectionIfNeeded();
439 void nsCaret::CheckSelectionLanguageChange() {
440 if (!StaticPrefs::bidi_browser_ui()) {
444 bool isKeyboardRTL
= false;
445 nsIBidiKeyboard
* bidiKeyboard
= nsContentUtils::GetBidiKeyboard();
447 bidiKeyboard
->IsLangRTL(&isKeyboardRTL
);
449 // Call SelectionLanguageChange on every paint. Mostly it will be a noop
450 // but it should be fast anyway. This guarantees we never paint the caret
451 // at the wrong place.
452 Selection
* selection
= GetSelection();
454 selection
->SelectionLanguageChange(isKeyboardRTL
);
458 // This ensures that the caret is not affected by clips on inlines and so forth.
459 [[nodiscard
]] static nsIFrame
* MapToContainingBlock(nsIFrame
* aFrame
,
462 nsIFrame
* containingBlock
= GetContainingBlockIfNeeded(aFrame
);
463 if (!containingBlock
) {
467 *aCaretRect
= nsLayoutUtils::TransformFrameRectToAncestor(aFrame
, *aCaretRect
,
469 *aHookRect
= nsLayoutUtils::TransformFrameRectToAncestor(aFrame
, *aHookRect
,
471 return containingBlock
;
474 nsIFrame
* nsCaret::GetPaintGeometry(nsRect
* aCaretRect
, nsRect
* aHookRect
,
475 nscolor
* aCaretColor
) {
476 // Return null if we should not be visible.
477 if (!IsVisible() || !mIsBlinkOn
) {
481 // Update selection language direction now so the new direction will be
482 // taken into account when computing the caret position below.
483 CheckSelectionLanguageChange();
485 auto data
= GetFrameAndOffset(mCaretPosition
);
486 MOZ_ASSERT(!!data
.mFrame
== !!data
.mUnadjustedFrame
);
491 nsIFrame
* frame
= data
.mFrame
;
492 nsIFrame
* unadjustedFrame
= data
.mUnadjustedFrame
;
493 int32_t frameOffset(data
.mOffsetInFrameContent
);
494 // Now we have a frame, check whether it's appropriate to show the caret here.
495 // Note we need to check the unadjusted frame, otherwise consider the
498 // <div contenteditable><span contenteditable=false>Text </span><br>
500 // Where the selection is targeting the <br>. We want to display the caret,
501 // since the <br> we're focused at is editable, but we do want to paint it at
502 // the adjusted frame offset, so that we can see the collapsed whitespace.
503 const nsStyleUI
* ui
= unadjustedFrame
->StyleUI();
504 if ((!mIgnoreUserModify
&& ui
->UserModify() == StyleUserModify::ReadOnly
) ||
505 unadjustedFrame
->IsContentDisabled()) {
509 // If the offset falls outside of the frame, then don't paint the caret.
510 if (frame
->IsTextFrame()) {
511 auto [startOffset
, endOffset
] = frame
->GetOffsets();
512 if (startOffset
> frameOffset
|| endOffset
< frameOffset
) {
518 *aCaretColor
= frame
->GetCaretColorAt(frameOffset
);
521 ComputeCaretRects(frame
, frameOffset
, aCaretRect
, aHookRect
);
522 return MapToContainingBlock(frame
, aCaretRect
, aHookRect
);
525 nsIFrame
* nsCaret::GetPaintGeometry(nsRect
* aRect
) {
528 nsIFrame
* frame
= GetPaintGeometry(&caretRect
, &hookRect
);
529 aRect
->UnionRect(caretRect
, hookRect
);
533 void nsCaret::PaintCaret(DrawTarget
& aDrawTarget
, nsIFrame
* aForFrame
,
534 const nsPoint
& aOffset
) {
538 nsIFrame
* frame
= GetPaintGeometry(&caretRect
, &hookRect
, &color
);
539 MOZ_ASSERT(frame
== aForFrame
, "We're referring different frame");
545 int32_t appUnitsPerDevPixel
= frame
->PresContext()->AppUnitsPerDevPixel();
546 Rect devPxCaretRect
= NSRectToSnappedRect(caretRect
+ aOffset
,
547 appUnitsPerDevPixel
, aDrawTarget
);
549 NSRectToSnappedRect(hookRect
+ aOffset
, appUnitsPerDevPixel
, aDrawTarget
);
551 ColorPattern
pattern(ToDeviceColor(color
));
552 aDrawTarget
.FillRect(devPxCaretRect
, pattern
);
553 if (!hookRect
.IsEmpty()) {
554 aDrawTarget
.FillRect(devPxHookRect
, pattern
);
559 nsCaret::NotifySelectionChanged(Document
*, Selection
* aDomSel
, int16_t aReason
,
561 // The same caret is shared amongst the document and any text widgets it
562 // may contain. This means that the caret could get notifications from
563 // multiple selections.
565 // If this notification is for a selection that is not the one the
566 // the caret is currently interested in (mDomSelectionWeak), or the caret
567 // position is fixed, then there is nothing to do!
568 if (mDomSelectionWeak
!= aDomSel
) {
572 // Check if we need to hide / un-hide the caret due to the selection being
574 if (!mShowDuringSelection
&&
575 !aDomSel
->IsCollapsed() != mHiddenDuringSelection
) {
576 if (mHiddenDuringSelection
) {
581 mHiddenDuringSelection
= !mHiddenDuringSelection
;
584 // We don't bother computing the caret position when invisible. We'll do it if
585 // we become visible in CaretVisibilityMaybeChanged().
587 UpdateCaretPositionFromSelectionIfNeeded();
594 void nsCaret::ResetBlinking() {
595 using IntID
= LookAndFeel::IntID
;
597 // The default caret blinking rate (in ms of blinking interval)
598 constexpr uint32_t kDefaultBlinkRate
= 500;
599 // The default caret blinking count (-1 for "never stop blinking")
600 constexpr int32_t kDefaultBlinkCount
= -1;
604 if (mReadOnly
|| !IsVisible()) {
610 LookAndFeel::GetInt(IntID::CaretBlinkTime
, kDefaultBlinkRate
);
613 // Make sure to reset the remaining blink count even if the blink rate
616 LookAndFeel::GetInt(IntID::CaretBlinkCount
, kDefaultBlinkCount
);
619 if (mBlinkRate
== blinkRate
) {
620 // If the rate hasn't changed, then there is nothing else to do.
624 mBlinkRate
= blinkRate
;
627 mBlinkTimer
->Cancel();
629 mBlinkTimer
= NS_NewTimer(GetMainThreadSerialEventTarget());
636 mBlinkTimer
->InitWithNamedFuncCallback(CaretBlinkCallback
, this, blinkRate
,
637 nsITimer::TYPE_REPEATING_SLACK
,
638 "nsCaret::CaretBlinkCallback_timer");
642 void nsCaret::StopBlinking() {
644 mBlinkTimer
->Cancel();
649 size_t nsCaret::SizeOfIncludingThis(mozilla::MallocSizeOf aMallocSizeOf
) const {
650 size_t total
= aMallocSizeOf(this);
652 // We only want the size of the nsWeakReference object, not the PresShell
653 // (since we don't own the PresShell).
654 total
+= mPresShell
->SizeOfOnlyThis(aMallocSizeOf
);
657 total
+= mBlinkTimer
->SizeOfIncludingThis(aMallocSizeOf
);
662 void nsCaret::ComputeCaretRects(nsIFrame
* aFrame
, int32_t aFrameOffset
,
663 nsRect
* aCaretRect
, nsRect
* aHookRect
) {
664 NS_ASSERTION(aFrame
, "Should have a frame here");
666 WritingMode wm
= aFrame
->GetWritingMode();
667 bool isVertical
= wm
.IsVertical();
669 nscoord bidiIndicatorSize
;
670 *aCaretRect
= GetGeometryForFrame(aFrame
, aFrameOffset
, &bidiIndicatorSize
);
672 // Simon -- make a hook to draw to the left or right of the caret to show
673 // keyboard language direction
674 aHookRect
->SetEmpty();
675 if (!StaticPrefs::bidi_browser_ui()) {
680 nsIBidiKeyboard
* bidiKeyboard
= nsContentUtils::GetBidiKeyboard();
681 // if bidiKeyboard->IsLangRTL() fails, there is no way to tell the
682 // keyboard direction, or the user has no right-to-left keyboard
683 // installed, so we never draw the hook.
684 if (bidiKeyboard
&& NS_SUCCEEDED(bidiKeyboard
->IsLangRTL(&isCaretRTL
))) {
685 // If keyboard language is RTL, draw the hook on the left; if LTR, to the
686 // right The height of the hook rectangle is the same as the width of the
689 if (wm
.IsSidewaysLR()) {
690 aHookRect
->SetRect(aCaretRect
->x
+ bidiIndicatorSize
,
691 aCaretRect
->y
+ (!isCaretRTL
? bidiIndicatorSize
* -1
692 : aCaretRect
->height
),
693 aCaretRect
->height
, bidiIndicatorSize
);
695 aHookRect
->SetRect(aCaretRect
->XMost() - bidiIndicatorSize
,
696 aCaretRect
->y
+ (isCaretRTL
? bidiIndicatorSize
* -1
697 : aCaretRect
->height
),
698 aCaretRect
->height
, bidiIndicatorSize
);
701 aHookRect
->SetRect(aCaretRect
->x
+ (isCaretRTL
? bidiIndicatorSize
* -1
702 : aCaretRect
->width
),
703 aCaretRect
->y
+ bidiIndicatorSize
, bidiIndicatorSize
,
710 void nsCaret::CaretBlinkCallback(nsITimer
* aTimer
, void* aClosure
) {
711 nsCaret
* theCaret
= reinterpret_cast<nsCaret
*>(aClosure
);
715 theCaret
->mIsBlinkOn
= !theCaret
->mIsBlinkOn
;
716 theCaret
->SchedulePaint();
718 // mBlinkCount of -1 means blink count is not enabled.
719 if (theCaret
->mBlinkCount
== -1) {
723 // Track the blink count, but only at end of a blink cycle.
724 if (theCaret
->mIsBlinkOn
) {
725 // If we exceeded the blink count, stop the timer.
726 if (--theCaret
->mBlinkCount
<= 0) {
727 theCaret
->StopBlinking();
732 void nsCaret::SetIgnoreUserModify(bool aIgnoreUserModify
) {
733 mIgnoreUserModify
= aIgnoreUserModify
;