2011-05-15 14:17:09 +04: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 15:12:37 +04: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-12 02:49:08 +03:00
|
|
|
|
2006-03-30 09:56:38 +04:00
|
|
|
/* the caret is the text cursor used, e.g., when editing */
|
1999-02-12 02:49:08 +03:00
|
|
|
|
2008-07-16 14:52:01 +04:00
|
|
|
#ifndef nsCaret_h__
|
|
|
|
#define nsCaret_h__
|
|
|
|
|
1999-02-12 02:49:08 +03:00
|
|
|
#include "nsCoord.h"
|
2000-09-14 15:45:01 +04:00
|
|
|
#include "nsISelectionListener.h"
|
2000-09-08 00:21:22 +04:00
|
|
|
#include "nsITimer.h"
|
2000-04-27 11:37:12 +04:00
|
|
|
#include "nsWeakPtr.h"
|
2008-07-16 14:52:01 +04:00
|
|
|
#include "nsFrameSelection.h"
|
1999-02-12 02:49:08 +03:00
|
|
|
|
2011-04-08 05:04:40 +04:00
|
|
|
class nsRenderingContext;
|
2008-07-16 14:52:01 +04:00
|
|
|
class nsDisplayListBuilder;
|
2000-09-08 00:21:22 +04:00
|
|
|
|
1999-02-12 02:49:08 +03:00
|
|
|
//-----------------------------------------------------------------------------
|
2008-07-16 14:52:01 +04:00
|
|
|
class nsCaret : public nsISelectionListener
|
1999-02-12 02:49:08 +03:00
|
|
|
{
|
2000-09-07 09:26:25 +04:00
|
|
|
public:
|
1999-02-12 02:49:08 +03:00
|
|
|
|
2000-09-07 09:26:25 +04:00
|
|
|
nsCaret();
|
|
|
|
virtual ~nsCaret();
|
2008-07-16 14:52:01 +04:00
|
|
|
|
|
|
|
enum EViewCoordinates {
|
|
|
|
eTopLevelWindowCoordinates,
|
|
|
|
eRenderingViewCoordinates,
|
2008-08-13 05:55:39 +04:00
|
|
|
eClosestViewCoordinates
|
2008-07-16 14:52:01 +04:00
|
|
|
};
|
1999-02-12 02:49:08 +03:00
|
|
|
|
2000-09-07 09:26:25 +04:00
|
|
|
public:
|
2008-07-16 14:52:01 +04: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 18:59:28 +04:00
|
|
|
* @param inMakeVisible true it is shown, false it is hidden
|
2008-07-16 14:52:01 +04:00
|
|
|
* @return false if and only if inMakeVisible is null, otherwise true
|
|
|
|
*/
|
2011-09-29 10:19:26 +04:00
|
|
|
virtual nsresult GetCaretVisible(bool *outMakeVisible);
|
2008-07-16 14:52:01 +04:00
|
|
|
|
|
|
|
/** SetCaretVisible will set the visibility of the caret
|
2011-10-17 18:59:28 +04:00
|
|
|
* @param inMakeVisible true to show the caret, false to hide it
|
2008-07-16 14:52:01 +04:00
|
|
|
*/
|
2011-09-29 10:19:26 +04:00
|
|
|
void SetCaretVisible(bool intMakeVisible);
|
2008-07-16 14:52:01 +04:00
|
|
|
|
|
|
|
/** SetCaretReadOnly set the appearance of the caret
|
2011-10-17 18:59:28 +04: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 14:52:01 +04:00
|
|
|
*/
|
2011-09-29 10:19:26 +04:00
|
|
|
void SetCaretReadOnly(bool inMakeReadonly);
|
2008-07-16 14:52:01 +04:00
|
|
|
|
|
|
|
/** GetCaretReadOnly get the appearance of the caret
|
2011-10-17 18:59:28 +04:00
|
|
|
* @return true if the caret is in 'read only' state, otherwise,
|
|
|
|
* returns false
|
2008-07-16 14:52:01 +04:00
|
|
|
*/
|
2011-09-29 10:19:26 +04:00
|
|
|
bool GetCaretReadOnly()
|
2006-04-18 03:16:46 +04:00
|
|
|
{
|
|
|
|
return mReadOnly;
|
|
|
|
}
|
2000-09-14 15:45:01 +04:00
|
|
|
|
2010-01-12 00:45:16 +03: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-15 01:52:45 +03:00
|
|
|
* @param aRect must be non-null
|
|
|
|
* @param aBidiIndicatorSize if non-null, set to the bidi indicator size.
|
2010-01-12 00:45:16 +03:00
|
|
|
*/
|
|
|
|
virtual nsIFrame* GetGeometry(nsISelection* aSelection,
|
2010-03-15 01:52:45 +03:00
|
|
|
nsRect* aRect,
|
2012-07-30 18:20:58 +04:00
|
|
|
nscoord* aBidiIndicatorSize = nullptr);
|
2010-01-12 00:45:16 +03:00
|
|
|
|
2008-07-16 14:52:01 +04:00
|
|
|
/** EraseCaret
|
|
|
|
* this will erase the caret if its drawn and reset drawn status
|
|
|
|
*/
|
|
|
|
void EraseCaret();
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
void SetVisibilityDuringSelection(bool aVisibility);
|
2008-07-16 14:52:01 +04: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 19:56:38 +04:00
|
|
|
nsresult DrawAtPosition(nsIDOMNode* aNode, int32_t aOffset);
|
2008-07-16 14:52:01 +04: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 06:35:48 +04:00
|
|
|
*
|
|
|
|
* @param aOffset is result of the caret offset in the content.
|
2008-07-16 14:52:01 +04:00
|
|
|
*/
|
2012-08-22 19:56:38 +04:00
|
|
|
nsIFrame* GetCaretFrame(int32_t *aOffset = nullptr);
|
2008-07-16 14:52:01 +04:00
|
|
|
|
|
|
|
/** GetCaretRect
|
|
|
|
* Get the current caret rect. Only call this when GetCaretFrame returns
|
|
|
|
* non-null.
|
|
|
|
*/
|
2006-04-18 03:16:46 +04:00
|
|
|
nsRect GetCaretRect()
|
|
|
|
{
|
|
|
|
nsRect r;
|
|
|
|
r.UnionRect(mCaretRect, GetHookRect());
|
|
|
|
return r;
|
|
|
|
}
|
2008-07-16 14:52:01 +04: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-18 03:16:46 +04:00
|
|
|
void InvalidateOutsideCaret();
|
2008-07-16 14:52:01 +04: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 08:33:41 +04:00
|
|
|
void UpdateCaretPosition();
|
2006-04-18 03:16:46 +04:00
|
|
|
|
2008-07-16 14:52:01 +04:00
|
|
|
/** PaintCaret
|
|
|
|
* Actually paint the caret onto the given rendering context.
|
|
|
|
*/
|
2006-04-18 03:16:46 +04:00
|
|
|
void PaintCaret(nsDisplayListBuilder *aBuilder,
|
2011-04-08 05:04:40 +04:00
|
|
|
nsRenderingContext *aCtx,
|
2008-06-23 12:50:52 +04:00
|
|
|
nsIFrame *aForFrame,
|
|
|
|
const nsPoint &aOffset);
|
2008-07-16 14:52:01 +04: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 18:59:28 +04:00
|
|
|
* @param aIgnoreUserModify true to have the cursor visible in all nodes,
|
|
|
|
* false to have it visible in all nodes except
|
2008-07-16 14:52:01 +04:00
|
|
|
* those with user-modify: read-only
|
|
|
|
*/
|
2000-09-14 15:45:01 +04:00
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
void SetIgnoreUserModify(bool aIgnoreUserModify);
|
2007-08-10 17:19:13 +04:00
|
|
|
|
2000-09-14 15:45:01 +04:00
|
|
|
//nsISelectionListener interface
|
2005-02-01 02:47:26 +03:00
|
|
|
NS_DECL_NSISELECTIONLISTENER
|
2006-04-18 03:16:46 +04:00
|
|
|
|
2000-09-07 09:26:25 +04:00
|
|
|
static void CaretBlinkCallback(nsITimer *aTimer, void *aClosure);
|
2008-07-16 14:52:01 +04:00
|
|
|
|
|
|
|
nsresult GetCaretFrameForNodeOffset(nsIContent* aContentNode,
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t aOffset,
|
2006-04-26 05:57:22 +04:00
|
|
|
nsFrameSelection::HINT aFrameHint,
|
2012-08-22 19:56:38 +04:00
|
|
|
uint8_t aBidiLevel,
|
2006-04-18 03:16:46 +04:00
|
|
|
nsIFrame** aReturnFrame,
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t* aReturnOffset);
|
2008-04-01 12:35:11 +04:00
|
|
|
|
|
|
|
NS_IMETHOD CheckCaretDrawingState();
|
|
|
|
|
|
|
|
protected:
|
2000-09-07 09:26:25 +04:00
|
|
|
|
|
|
|
void KillTimer();
|
|
|
|
nsresult PrimeTimer();
|
2006-04-18 03:16:46 +04:00
|
|
|
|
2008-07-16 14:52:01 +04:00
|
|
|
void StartBlinking();
|
|
|
|
void StopBlinking();
|
2011-06-22 22:11:48 +04:00
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool DrawAtPositionWithHint(nsIDOMNode* aNode,
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t aOffset,
|
2006-04-26 05:57:22 +04:00
|
|
|
nsFrameSelection::HINT aFrameHint,
|
2012-08-22 19:56:38 +04:00
|
|
|
uint8_t aBidiLevel,
|
2011-09-29 10:19:26 +04:00
|
|
|
bool aInvalidate);
|
2008-04-01 12:35:11 +04:00
|
|
|
|
2008-04-15 01:09:23 +04:00
|
|
|
struct Metrics {
|
|
|
|
nscoord mBidiIndicatorSize; // width and height of bidi indicator
|
|
|
|
nscoord mCaretWidth; // full caret width including bidi indicator
|
|
|
|
};
|
2012-08-22 19:56:38 +04:00
|
|
|
Metrics ComputeMetrics(nsIFrame* aFrame, int32_t aOffset, nscoord aCaretHeight);
|
2010-11-25 04:35:01 +03:00
|
|
|
nsresult GetGeometryForFrame(nsIFrame* aFrame,
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t aFrameOffset,
|
2010-11-25 04:35:01 +03:00
|
|
|
nsRect* aRect,
|
|
|
|
nscoord* aBidiIndicatorSize);
|
2008-04-15 01:09:23 +04:00
|
|
|
|
2008-04-01 12:35:11 +04: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 10:19:26 +04:00
|
|
|
bool MustDrawCaret(bool aIgnoreDrawnState);
|
2008-04-01 12:35:11 +04:00
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
void DrawCaret(bool aInvalidate);
|
2005-10-04 07:14:03 +04:00
|
|
|
void DrawCaretAfterBriefDelay();
|
2012-08-22 19:56:38 +04:00
|
|
|
bool UpdateCaretRects(nsIFrame* aFrame, int32_t aFrameOffset);
|
2006-04-18 03:16:46 +04:00
|
|
|
nsRect GetHookRect()
|
|
|
|
{
|
|
|
|
#ifdef IBMBIDI
|
|
|
|
return mHookRect;
|
|
|
|
#else
|
|
|
|
return nsRect();
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
void ToggleDrawnStatus() { mDrawn = !mDrawn; }
|
2000-09-07 09:26:25 +04:00
|
|
|
|
2013-02-16 00:09:28 +04:00
|
|
|
nsFrameSelection* GetFrameSelection();
|
2006-08-08 09:14:52 +04:00
|
|
|
|
2008-04-01 12:35:11 +04: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 10:19:26 +04:00
|
|
|
bool IsMenuPopupHidingCaret();
|
2008-04-01 12:35:11 +04:00
|
|
|
|
2000-09-08 00:21:22 +04:00
|
|
|
protected:
|
2000-04-27 11:37:12 +04:00
|
|
|
|
2000-09-08 00:21:22 +04:00
|
|
|
nsWeakPtr mPresShell;
|
|
|
|
nsWeakPtr mDomSelectionWeak;
|
1999-02-12 02:49:08 +03:00
|
|
|
|
2010-03-15 01:50:36 +03:00
|
|
|
nsCOMPtr<nsITimer> mBlinkTimer;
|
2000-09-08 00:21:22 +04:00
|
|
|
|
2008-04-15 01:09:23 +04:00
|
|
|
// XXX these fields should go away and the values be acquired as needed,
|
|
|
|
// probably by ComputeMetrics.
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t mBlinkRate; // time for one cyle (on then off), in milliseconds
|
2008-04-15 01:09:23 +04:00
|
|
|
nscoord mCaretWidthCSSPx; // caret width in CSS pixels
|
2008-06-23 12:50:52 +04:00
|
|
|
float mCaretAspectRatio; // caret width/height aspect ratio
|
2008-04-15 01:09:23 +04:00
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool mVisible; // is the caret blinking
|
2008-02-27 04:49:46 +03:00
|
|
|
|
2011-09-29 10:19:26 +04: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 04:49:46 +03:00
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool mReadOnly; // it the caret in readonly state (draws differently)
|
|
|
|
bool mShowDuringSelection; // show when text is selected
|
2003-02-24 13:26:20 +03:00
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool mIgnoreUserModify;
|
2008-12-14 12:05:39 +03:00
|
|
|
|
|
|
|
#ifdef IBMBIDI
|
2011-09-29 10:19:26 +04:00
|
|
|
bool mKeyboardRTL; // is the keyboard language right-to-left
|
|
|
|
bool mBidiUI; // is bidi UI turned on
|
2008-12-14 12:05:39 +03:00
|
|
|
nsRect mHookRect; // directional hook on the caret
|
2012-08-22 19:56:38 +04:00
|
|
|
uint8_t mLastBidiLevel; // saved bidi level of the last draw request, to use when we erase
|
2008-12-14 12:05:39 +03:00
|
|
|
#endif
|
2006-04-18 03:16:46 +04: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 19:56:38 +04:00
|
|
|
int32_t mLastContentOffset; // the offset for the last request
|
2006-04-18 03:16:46 +04:00
|
|
|
|
2010-09-09 04:15:24 +04:00
|
|
|
nsFrameSelection::HINT mLastHint; // the hint associated with the last request, see also
|
|
|
|
// mLastBidiLevel below
|
2006-04-18 03:16:46 +04:00
|
|
|
|
1999-02-12 02:49:08 +03:00
|
|
|
};
|
|
|
|
|
2008-07-16 14:52:01 +04:00
|
|
|
#endif //nsCaret_h__
|