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