2011-05-15 10:17:09 +00:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* vim: set ts=2 sw=2 et tw=78: */
|
2012-05-21 11:12:37 +00:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
1999-02-11 23:49:08 +00:00
|
|
|
|
2006-03-30 05:56:38 +00:00
|
|
|
/* the caret is the text cursor used, e.g., when editing */
|
1999-02-11 23:49:08 +00:00
|
|
|
|
2008-07-16 10:52:01 +00:00
|
|
|
#ifndef nsCaret_h__
|
|
|
|
#define nsCaret_h__
|
|
|
|
|
1999-02-11 23:49:08 +00:00
|
|
|
#include "nsCoord.h"
|
2000-09-14 11:45:01 +00:00
|
|
|
#include "nsISelectionListener.h"
|
2013-08-19 22:55:18 +00:00
|
|
|
#include "nsIWeakReferenceUtils.h"
|
2008-07-16 10:52:01 +00:00
|
|
|
#include "nsFrameSelection.h"
|
1999-02-11 23:49:08 +00:00
|
|
|
|
2011-04-08 01:04:40 +00:00
|
|
|
class nsRenderingContext;
|
2008-07-16 10:52:01 +00:00
|
|
|
class nsDisplayListBuilder;
|
2013-08-19 22:55:18 +00:00
|
|
|
class nsITimer;
|
2000-09-07 20:21:22 +00:00
|
|
|
|
1999-02-11 23:49:08 +00:00
|
|
|
//-----------------------------------------------------------------------------
|
2008-07-16 10:52:01 +00:00
|
|
|
class nsCaret : public nsISelectionListener
|
1999-02-11 23:49:08 +00:00
|
|
|
{
|
2000-09-07 05:26:25 +00:00
|
|
|
public:
|
1999-02-11 23:49:08 +00:00
|
|
|
|
2000-09-07 05:26:25 +00:00
|
|
|
nsCaret();
|
|
|
|
virtual ~nsCaret();
|
2008-07-16 10:52:01 +00:00
|
|
|
|
|
|
|
enum EViewCoordinates {
|
|
|
|
eTopLevelWindowCoordinates,
|
|
|
|
eRenderingViewCoordinates,
|
2008-08-13 01:55:39 +00:00
|
|
|
eClosestViewCoordinates
|
2008-07-16 10:52:01 +00:00
|
|
|
};
|
1999-02-11 23:49:08 +00:00
|
|
|
|
2000-09-07 05:26:25 +00:00
|
|
|
public:
|
2008-07-16 10:52:01 +00:00
|
|
|
|
|
|
|
NS_DECL_ISUPPORTS
|
|
|
|
|
|
|
|
nsresult Init(nsIPresShell *inPresShell);
|
|
|
|
void Terminate();
|
|
|
|
|
|
|
|
nsISelection* GetCaretDOMSelection();
|
|
|
|
nsresult SetCaretDOMSelection(nsISelection *inDOMSel);
|
|
|
|
|
|
|
|
/** GetCaretVisible will get the visibility of the caret
|
|
|
|
* This function is virtual so that it can be used by nsCaretAccessible
|
|
|
|
* without linking
|
2011-10-17 14:59:28 +00:00
|
|
|
* @param inMakeVisible true it is shown, false it is hidden
|
2008-07-16 10:52:01 +00:00
|
|
|
* @return false if and only if inMakeVisible is null, otherwise true
|
|
|
|
*/
|
2011-09-29 06:19:26 +00:00
|
|
|
virtual nsresult GetCaretVisible(bool *outMakeVisible);
|
2008-07-16 10:52:01 +00:00
|
|
|
|
|
|
|
/** SetCaretVisible will set the visibility of the caret
|
2011-10-17 14:59:28 +00:00
|
|
|
* @param inMakeVisible true to show the caret, false to hide it
|
2008-07-16 10:52:01 +00:00
|
|
|
*/
|
2011-09-29 06:19:26 +00:00
|
|
|
void SetCaretVisible(bool intMakeVisible);
|
2008-07-16 10:52:01 +00:00
|
|
|
|
|
|
|
/** SetCaretReadOnly set the appearance of the caret
|
2011-10-17 14:59:28 +00:00
|
|
|
* @param inMakeReadonly true to show the caret in a 'read only' state,
|
|
|
|
* false to show the caret in normal, editing state
|
2008-07-16 10:52:01 +00:00
|
|
|
*/
|
2011-09-29 06:19:26 +00:00
|
|
|
void SetCaretReadOnly(bool inMakeReadonly);
|
2008-07-16 10:52:01 +00:00
|
|
|
|
|
|
|
/** GetCaretReadOnly get the appearance of the caret
|
2011-10-17 14:59:28 +00:00
|
|
|
* @return true if the caret is in 'read only' state, otherwise,
|
|
|
|
* returns false
|
2008-07-16 10:52:01 +00:00
|
|
|
*/
|
2011-09-29 06:19:26 +00:00
|
|
|
bool GetCaretReadOnly()
|
2006-04-17 23:16:46 +00:00
|
|
|
{
|
|
|
|
return mReadOnly;
|
|
|
|
}
|
2000-09-14 11:45:01 +00:00
|
|
|
|
2010-01-11 21:45:16 +00:00
|
|
|
/**
|
|
|
|
* Gets the position and size of the caret that would be drawn for
|
|
|
|
* the focus node/offset of aSelection (assuming it would be drawn,
|
|
|
|
* i.e., disregarding blink status). The geometry is stored in aRect,
|
|
|
|
* and we return the frame aRect is relative to.
|
2010-03-14 22:52:45 +00:00
|
|
|
* @param aRect must be non-null
|
|
|
|
* @param aBidiIndicatorSize if non-null, set to the bidi indicator size.
|
2010-01-11 21:45:16 +00:00
|
|
|
*/
|
|
|
|
virtual nsIFrame* GetGeometry(nsISelection* aSelection,
|
2010-03-14 22:52:45 +00:00
|
|
|
nsRect* aRect,
|
2012-07-30 14:20:58 +00:00
|
|
|
nscoord* aBidiIndicatorSize = nullptr);
|
2010-01-11 21:45:16 +00:00
|
|
|
|
2008-07-16 10:52:01 +00:00
|
|
|
/** EraseCaret
|
|
|
|
* this will erase the caret if its drawn and reset drawn status
|
|
|
|
*/
|
|
|
|
void EraseCaret();
|
|
|
|
|
2011-09-29 06:19:26 +00:00
|
|
|
void SetVisibilityDuringSelection(bool aVisibility);
|
2008-07-16 10:52:01 +00:00
|
|
|
|
|
|
|
/** DrawAtPosition
|
|
|
|
*
|
|
|
|
* Draw the caret explicitly, at the specified node and offset.
|
|
|
|
* To avoid drawing glitches, you should call EraseCaret()
|
|
|
|
* after each call to DrawAtPosition().
|
|
|
|
*
|
|
|
|
* Note: This call breaks the caret's ability to blink at all.
|
|
|
|
**/
|
2012-08-22 15:56:38 +00:00
|
|
|
nsresult DrawAtPosition(nsIDOMNode* aNode, int32_t aOffset);
|
2008-07-16 10:52:01 +00:00
|
|
|
|
|
|
|
/** GetCaretFrame
|
|
|
|
* Get the current frame that the caret should be drawn in. If the caret is
|
|
|
|
* not currently visible (i.e., it is between blinks), then this will
|
|
|
|
* return null.
|
2010-04-01 02:35:48 +00:00
|
|
|
*
|
|
|
|
* @param aOffset is result of the caret offset in the content.
|
2008-07-16 10:52:01 +00:00
|
|
|
*/
|
2012-08-22 15:56:38 +00:00
|
|
|
nsIFrame* GetCaretFrame(int32_t *aOffset = nullptr);
|
2008-07-16 10:52:01 +00:00
|
|
|
|
|
|
|
/** GetCaretRect
|
|
|
|
* Get the current caret rect. Only call this when GetCaretFrame returns
|
|
|
|
* non-null.
|
|
|
|
*/
|
2006-04-17 23:16:46 +00:00
|
|
|
nsRect GetCaretRect()
|
|
|
|
{
|
|
|
|
nsRect r;
|
|
|
|
r.UnionRect(mCaretRect, GetHookRect());
|
|
|
|
return r;
|
|
|
|
}
|
2008-07-16 10:52:01 +00:00
|
|
|
|
|
|
|
/** InvalidateOutsideCaret
|
|
|
|
* Invalidate the area that the caret currently occupies if the caret is
|
|
|
|
* outside of its frame's overflow area. This is used when the content that
|
|
|
|
* the caret is currently drawn is is being deleted or reflowed.
|
|
|
|
*/
|
2006-04-17 23:16:46 +00:00
|
|
|
void InvalidateOutsideCaret();
|
2008-07-16 10:52:01 +00:00
|
|
|
|
|
|
|
/** UpdateCaretPosition
|
|
|
|
* Update the caret's current frame and rect, but don't draw yet. This is
|
|
|
|
* useful for flickerless moving of the caret (e.g., when the frame the
|
|
|
|
* caret is in reflows and is moved).
|
|
|
|
*/
|
2006-04-28 04:33:41 +00:00
|
|
|
void UpdateCaretPosition();
|
2006-04-17 23:16:46 +00:00
|
|
|
|
2008-07-16 10:52:01 +00:00
|
|
|
/** PaintCaret
|
|
|
|
* Actually paint the caret onto the given rendering context.
|
|
|
|
*/
|
2006-04-17 23:16:46 +00:00
|
|
|
void PaintCaret(nsDisplayListBuilder *aBuilder,
|
2011-04-08 01:04:40 +00:00
|
|
|
nsRenderingContext *aCtx,
|
2008-06-23 08:50:52 +00:00
|
|
|
nsIFrame *aForFrame,
|
|
|
|
const nsPoint &aOffset);
|
2008-07-16 10:52:01 +00:00
|
|
|
/**
|
|
|
|
* Sets whether the caret should only be visible in nodes that are not
|
|
|
|
* user-modify: read-only, or whether it should be visible in all nodes.
|
|
|
|
*
|
2011-10-17 14:59:28 +00:00
|
|
|
* @param aIgnoreUserModify true to have the cursor visible in all nodes,
|
|
|
|
* false to have it visible in all nodes except
|
2008-07-16 10:52:01 +00:00
|
|
|
* those with user-modify: read-only
|
|
|
|
*/
|
2000-09-14 11:45:01 +00:00
|
|
|
|
2011-09-29 06:19:26 +00:00
|
|
|
void SetIgnoreUserModify(bool aIgnoreUserModify);
|
2007-08-10 13:19:13 +00:00
|
|
|
|
2000-09-14 11:45:01 +00:00
|
|
|
//nsISelectionListener interface
|
2005-01-31 23:47:26 +00:00
|
|
|
NS_DECL_NSISELECTIONLISTENER
|
2006-04-17 23:16:46 +00:00
|
|
|
|
2000-09-07 05:26:25 +00:00
|
|
|
static void CaretBlinkCallback(nsITimer *aTimer, void *aClosure);
|
2008-07-16 10:52:01 +00:00
|
|
|
|
|
|
|
nsresult GetCaretFrameForNodeOffset(nsIContent* aContentNode,
|
2012-08-22 15:56:38 +00:00
|
|
|
int32_t aOffset,
|
2006-04-26 01:57:22 +00:00
|
|
|
nsFrameSelection::HINT aFrameHint,
|
2012-08-22 15:56:38 +00:00
|
|
|
uint8_t aBidiLevel,
|
2006-04-17 23:16:46 +00:00
|
|
|
nsIFrame** aReturnFrame,
|
2012-08-22 15:56:38 +00:00
|
|
|
int32_t* aReturnOffset);
|
2008-04-01 08:35:11 +00:00
|
|
|
|
|
|
|
NS_IMETHOD CheckCaretDrawingState();
|
|
|
|
|
|
|
|
protected:
|
2000-09-07 05:26:25 +00:00
|
|
|
|
|
|
|
void KillTimer();
|
|
|
|
nsresult PrimeTimer();
|
2006-04-17 23:16:46 +00:00
|
|
|
|
2008-07-16 10:52:01 +00:00
|
|
|
void StartBlinking();
|
|
|
|
void StopBlinking();
|
2011-06-22 18:11:48 +00:00
|
|
|
|
2011-09-29 06:19:26 +00:00
|
|
|
bool DrawAtPositionWithHint(nsIDOMNode* aNode,
|
2012-08-22 15:56:38 +00:00
|
|
|
int32_t aOffset,
|
2006-04-26 01:57:22 +00:00
|
|
|
nsFrameSelection::HINT aFrameHint,
|
2012-08-22 15:56:38 +00:00
|
|
|
uint8_t aBidiLevel,
|
2011-09-29 06:19:26 +00:00
|
|
|
bool aInvalidate);
|
2008-04-01 08:35:11 +00:00
|
|
|
|
2008-04-14 21:09:23 +00:00
|
|
|
struct Metrics {
|
|
|
|
nscoord mBidiIndicatorSize; // width and height of bidi indicator
|
|
|
|
nscoord mCaretWidth; // full caret width including bidi indicator
|
|
|
|
};
|
2012-08-22 15:56:38 +00:00
|
|
|
Metrics ComputeMetrics(nsIFrame* aFrame, int32_t aOffset, nscoord aCaretHeight);
|
2010-11-25 01:35:01 +00:00
|
|
|
nsresult GetGeometryForFrame(nsIFrame* aFrame,
|
2012-08-22 15:56:38 +00:00
|
|
|
int32_t aFrameOffset,
|
2010-11-25 01:35:01 +00:00
|
|
|
nsRect* aRect,
|
|
|
|
nscoord* aBidiIndicatorSize);
|
2008-04-14 21:09:23 +00:00
|
|
|
|
2008-04-01 08:35:11 +00:00
|
|
|
// Returns true if the caret should be drawn. When |mDrawn| is true,
|
|
|
|
// this returns true, so that we erase the drawn caret. If |aIgnoreDrawnState|
|
|
|
|
// is true, we don't take into account whether the caret is currently
|
|
|
|
// drawn or not. This can be used to determine if the caret is drawn when
|
|
|
|
// it shouldn't be.
|
2011-09-29 06:19:26 +00:00
|
|
|
bool MustDrawCaret(bool aIgnoreDrawnState);
|
2008-04-01 08:35:11 +00:00
|
|
|
|
2011-09-29 06:19:26 +00:00
|
|
|
void DrawCaret(bool aInvalidate);
|
2005-10-04 03:14:03 +00:00
|
|
|
void DrawCaretAfterBriefDelay();
|
2012-08-22 15:56:38 +00:00
|
|
|
bool UpdateCaretRects(nsIFrame* aFrame, int32_t aFrameOffset);
|
2006-04-17 23:16:46 +00:00
|
|
|
nsRect GetHookRect()
|
|
|
|
{
|
|
|
|
#ifdef IBMBIDI
|
|
|
|
return mHookRect;
|
|
|
|
#else
|
|
|
|
return nsRect();
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
void ToggleDrawnStatus() { mDrawn = !mDrawn; }
|
2000-09-07 05:26:25 +00:00
|
|
|
|
2013-02-15 20:09:28 +00:00
|
|
|
nsFrameSelection* GetFrameSelection();
|
2006-08-08 05:14:52 +00:00
|
|
|
|
2008-04-01 08:35:11 +00:00
|
|
|
// Returns true if we should not draw the caret because of XUL menu popups.
|
|
|
|
// The caret should be hidden if:
|
|
|
|
// 1. An open popup contains the caret, but a menu popup exists before the
|
|
|
|
// caret-owning popup in the popup list (i.e. a menu is in front of the
|
|
|
|
// popup with the caret). If the menu itself contains the caret we don't
|
|
|
|
// hide it.
|
|
|
|
// 2. A menu popup is open, but there is no caret present in any popup.
|
|
|
|
// 3. The caret selection is empty.
|
2011-09-29 06:19:26 +00:00
|
|
|
bool IsMenuPopupHidingCaret();
|
2008-04-01 08:35:11 +00:00
|
|
|
|
2000-09-07 20:21:22 +00:00
|
|
|
protected:
|
2000-04-27 07:37:12 +00:00
|
|
|
|
2000-09-07 20:21:22 +00:00
|
|
|
nsWeakPtr mPresShell;
|
|
|
|
nsWeakPtr mDomSelectionWeak;
|
1999-02-11 23:49:08 +00:00
|
|
|
|
2010-03-14 22:50:36 +00:00
|
|
|
nsCOMPtr<nsITimer> mBlinkTimer;
|
2000-09-07 20:21:22 +00:00
|
|
|
|
2008-04-14 21:09:23 +00:00
|
|
|
// XXX these fields should go away and the values be acquired as needed,
|
|
|
|
// probably by ComputeMetrics.
|
2012-08-22 15:56:38 +00:00
|
|
|
uint32_t mBlinkRate; // time for one cyle (on then off), in milliseconds
|
2008-04-14 21:09:23 +00:00
|
|
|
nscoord mCaretWidthCSSPx; // caret width in CSS pixels
|
2008-06-23 08:50:52 +00:00
|
|
|
float mCaretAspectRatio; // caret width/height aspect ratio
|
2008-04-14 21:09:23 +00:00
|
|
|
|
2011-09-29 06:19:26 +00:00
|
|
|
bool mVisible; // is the caret blinking
|
2008-02-27 01:49:46 +00:00
|
|
|
|
2011-09-29 06:19:26 +00:00
|
|
|
bool mDrawn; // Denotes when the caret is physically drawn on the screen.
|
|
|
|
bool mPendingDraw; // True when the last on-state draw was suppressed.
|
2008-02-27 01:49:46 +00:00
|
|
|
|
2011-09-29 06:19:26 +00:00
|
|
|
bool mReadOnly; // it the caret in readonly state (draws differently)
|
|
|
|
bool mShowDuringSelection; // show when text is selected
|
2003-02-24 10:26:20 +00:00
|
|
|
|
2011-09-29 06:19:26 +00:00
|
|
|
bool mIgnoreUserModify;
|
2008-12-14 09:05:39 +00:00
|
|
|
|
|
|
|
#ifdef IBMBIDI
|
2011-09-29 06:19:26 +00:00
|
|
|
bool mKeyboardRTL; // is the keyboard language right-to-left
|
|
|
|
bool mBidiUI; // is bidi UI turned on
|
2008-12-14 09:05:39 +00:00
|
|
|
nsRect mHookRect; // directional hook on the caret
|
2012-08-22 15:56:38 +00:00
|
|
|
uint8_t mLastBidiLevel; // saved bidi level of the last draw request, to use when we erase
|
2008-12-14 09:05:39 +00:00
|
|
|
#endif
|
2006-04-17 23:16:46 +00:00
|
|
|
nsRect mCaretRect; // the last caret rect, in the coodinates of the last frame.
|
|
|
|
|
|
|
|
nsCOMPtr<nsIContent> mLastContent; // store the content the caret was last requested to be drawn
|
|
|
|
// in (by DrawAtPosition()/DrawCaret()),
|
|
|
|
// note that this can be different than where it was
|
|
|
|
// actually drawn (anon <BR> in text control)
|
2012-08-22 15:56:38 +00:00
|
|
|
int32_t mLastContentOffset; // the offset for the last request
|
2006-04-17 23:16:46 +00:00
|
|
|
|
2010-09-09 00:15:24 +00:00
|
|
|
nsFrameSelection::HINT mLastHint; // the hint associated with the last request, see also
|
|
|
|
// mLastBidiLevel below
|
2006-04-17 23:16:46 +00:00
|
|
|
|
1999-02-11 23:49:08 +00:00
|
|
|
};
|
|
|
|
|
2008-07-16 10:52:01 +00:00
|
|
|
#endif //nsCaret_h__
|