2007-03-22 10:30:00 -07:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* vim: set ts=2 sw=2 et tw=78: */
|
|
|
|
/* ***** BEGIN LICENSE BLOCK *****
|
|
|
|
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
|
|
|
*
|
|
|
|
* The contents of this file are subject to the Mozilla Public License Version
|
|
|
|
* 1.1 (the "License"); you may not use this file except in compliance with
|
|
|
|
* the License. You may obtain a copy of the License at
|
|
|
|
* http://www.mozilla.org/MPL/
|
|
|
|
*
|
|
|
|
* Software distributed under the License is distributed on an "AS IS" basis,
|
|
|
|
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
|
|
|
* for the specific language governing rights and limitations under the
|
|
|
|
* License.
|
|
|
|
*
|
|
|
|
* The Original Code is mozilla.org code.
|
|
|
|
*
|
|
|
|
* The Initial Developer of the Original Code is
|
|
|
|
* Netscape Communications Corporation.
|
|
|
|
* Portions created by the Initial Developer are Copyright (C) 1998
|
|
|
|
* the Initial Developer. All Rights Reserved.
|
|
|
|
*
|
|
|
|
* Contributor(s):
|
|
|
|
* Pierre Phaneuf <pp@ludusdesign.com>
|
2010-03-14 15:52:07 -07:00
|
|
|
* Mats Palmgren <matspal@gmail.com>
|
2007-03-22 10:30:00 -07:00
|
|
|
*
|
|
|
|
* Alternatively, the contents of this file may be used under the terms of
|
|
|
|
* either of the GNU General Public License Version 2 or later (the "GPL"),
|
|
|
|
* or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
|
|
|
* in which case the provisions of the GPL or the LGPL are applicable instead
|
|
|
|
* of those above. If you wish to allow use of your version of this file only
|
|
|
|
* under the terms of either the GPL or the LGPL, and not to allow others to
|
|
|
|
* use your version of this file under the terms of the MPL, indicate your
|
|
|
|
* decision by deleting the provisions above and replace them with the notice
|
|
|
|
* and other provisions required by the GPL or the LGPL. If you do not delete
|
|
|
|
* the provisions above, a recipient may use your version of this file under
|
|
|
|
* the terms of any one of the MPL, the GPL or the LGPL.
|
|
|
|
*
|
|
|
|
* ***** END LICENSE BLOCK ***** */
|
|
|
|
|
|
|
|
/* the caret is the text cursor used, e.g., when editing */
|
|
|
|
|
|
|
|
#include "nsCOMPtr.h"
|
|
|
|
|
|
|
|
#include "nsITimer.h"
|
|
|
|
|
|
|
|
#include "nsIComponentManager.h"
|
|
|
|
#include "nsIServiceManager.h"
|
|
|
|
#include "nsFrameSelection.h"
|
|
|
|
#include "nsIFrame.h"
|
2007-08-13 13:51:16 -07:00
|
|
|
#include "nsIScrollableFrame.h"
|
2007-03-22 10:30:00 -07:00
|
|
|
#include "nsIDOMNode.h"
|
|
|
|
#include "nsIDOMRange.h"
|
|
|
|
#include "nsIFontMetrics.h"
|
|
|
|
#include "nsISelection.h"
|
|
|
|
#include "nsISelectionPrivate.h"
|
|
|
|
#include "nsIDOMCharacterData.h"
|
|
|
|
#include "nsIContent.h"
|
|
|
|
#include "nsIPresShell.h"
|
|
|
|
#include "nsIRenderingContext.h"
|
|
|
|
#include "nsIDeviceContext.h"
|
|
|
|
#include "nsPresContext.h"
|
|
|
|
#include "nsILookAndFeel.h"
|
|
|
|
#include "nsBlockFrame.h"
|
|
|
|
#include "nsISelectionController.h"
|
|
|
|
#include "nsDisplayList.h"
|
|
|
|
#include "nsCaret.h"
|
2007-11-07 20:07:00 -08:00
|
|
|
#include "nsTextFrame.h"
|
2008-04-01 01:35:11 -07:00
|
|
|
#include "nsXULPopupManager.h"
|
|
|
|
#include "nsMenuPopupFrame.h"
|
2008-04-22 20:13:55 -07:00
|
|
|
#include "nsTextFragment.h"
|
2008-06-23 01:50:52 -07:00
|
|
|
#include "nsThemeConstants.h"
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
// The bidi indicator hangs off the caret to one side, to show which
|
|
|
|
// direction the typing is in. It needs to be at least 2x2 to avoid looking like
|
|
|
|
// an insignificant dot
|
2008-04-14 14:09:23 -07:00
|
|
|
static const PRInt32 kMinBidiIndicatorPixels = 2;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
#ifdef IBMBIDI
|
|
|
|
#include "nsIBidiKeyboard.h"
|
|
|
|
#include "nsContentUtils.h"
|
|
|
|
#endif //IBMBIDI
|
|
|
|
|
2010-03-14 15:52:45 -07:00
|
|
|
/**
|
|
|
|
* Find the first frame in an in-order traversal of the frame subtree rooted
|
|
|
|
* at aFrame which is either a text frame logically at the end of a line,
|
|
|
|
* or which is aStopAtFrame. Return null if no such frame is found. We don't
|
|
|
|
* descend into the children of non-eLineParticipant frames.
|
|
|
|
*/
|
|
|
|
static nsIFrame*
|
|
|
|
CheckForTrailingTextFrameRecursive(nsIFrame* aFrame, nsIFrame* aStopAtFrame)
|
|
|
|
{
|
|
|
|
if (aFrame == aStopAtFrame ||
|
|
|
|
((aFrame->GetType() == nsGkAtoms::textFrame &&
|
|
|
|
(static_cast<nsTextFrame*>(aFrame))->IsAtEndOfLine())))
|
|
|
|
return aFrame;
|
|
|
|
if (!aFrame->IsFrameOfType(nsIFrame::eLineParticipant))
|
|
|
|
return nsnull;
|
|
|
|
|
|
|
|
for (nsIFrame* f = aFrame->GetFirstChild(nsnull); f; f = f->GetNextSibling())
|
|
|
|
{
|
|
|
|
nsIFrame* r = CheckForTrailingTextFrameRecursive(f, aStopAtFrame);
|
|
|
|
if (r)
|
|
|
|
return r;
|
|
|
|
}
|
|
|
|
return nsnull;
|
|
|
|
}
|
|
|
|
|
|
|
|
static nsLineBox*
|
|
|
|
FindContainingLine(nsIFrame* aFrame)
|
|
|
|
{
|
|
|
|
while (aFrame && aFrame->IsFrameOfType(nsIFrame::eLineParticipant))
|
|
|
|
{
|
|
|
|
nsIFrame* parent = aFrame->GetParent();
|
|
|
|
nsBlockFrame* blockParent = nsLayoutUtils::GetAsBlock(parent);
|
|
|
|
if (blockParent)
|
|
|
|
{
|
|
|
|
PRBool isValid;
|
|
|
|
nsBlockInFlowLineIterator iter(blockParent, aFrame, &isValid);
|
|
|
|
return isValid ? iter.GetLine().get() : nsnull;
|
|
|
|
}
|
|
|
|
aFrame = parent;
|
|
|
|
}
|
|
|
|
return nsnull;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
AdjustCaretFrameForLineEnd(nsIFrame** aFrame, PRInt32* aOffset)
|
|
|
|
{
|
|
|
|
nsLineBox* line = FindContainingLine(*aFrame);
|
|
|
|
if (!line)
|
|
|
|
return;
|
|
|
|
PRInt32 count = line->GetChildCount();
|
|
|
|
for (nsIFrame* f = line->mFirstChild; count > 0; --count, f = f->GetNextSibling())
|
|
|
|
{
|
|
|
|
nsIFrame* r = CheckForTrailingTextFrameRecursive(f, *aFrame);
|
|
|
|
if (r == *aFrame)
|
|
|
|
return;
|
|
|
|
if (r)
|
|
|
|
{
|
|
|
|
*aFrame = r;
|
|
|
|
NS_ASSERTION(r->GetType() == nsGkAtoms::textFrame, "Expected text frame");
|
|
|
|
*aOffset = (static_cast<nsTextFrame*>(r))->GetContentEnd();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static PRBool
|
|
|
|
FramesOnSameLineHaveZeroHeight(nsIFrame* aFrame)
|
|
|
|
{
|
|
|
|
nsLineBox* line = FindContainingLine(aFrame);
|
|
|
|
if (!line)
|
|
|
|
return aFrame->GetRect().height == 0;
|
|
|
|
PRInt32 count = line->GetChildCount();
|
|
|
|
for (nsIFrame* f = line->mFirstChild; count > 0; --count, f = f->GetNextSibling())
|
|
|
|
{
|
|
|
|
if (f->GetRect().height != 0)
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
return PR_TRUE;
|
|
|
|
}
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
nsCaret::nsCaret()
|
|
|
|
: mPresShell(nsnull)
|
|
|
|
, mBlinkRate(500)
|
|
|
|
, mVisible(PR_FALSE)
|
|
|
|
, mDrawn(PR_FALSE)
|
2009-10-16 03:55:32 -07:00
|
|
|
, mPendingDraw(PR_FALSE)
|
2007-03-22 10:30:00 -07:00
|
|
|
, mReadOnly(PR_FALSE)
|
|
|
|
, mShowDuringSelection(PR_FALSE)
|
2007-11-12 21:42:52 -08:00
|
|
|
, mIgnoreUserModify(PR_TRUE)
|
2007-03-22 10:30:00 -07:00
|
|
|
#ifdef IBMBIDI
|
|
|
|
, mKeyboardRTL(PR_FALSE)
|
2008-12-28 04:08:22 -08:00
|
|
|
, mLastBidiLevel(0)
|
2007-03-22 10:30:00 -07:00
|
|
|
#endif
|
2008-12-28 04:08:22 -08:00
|
|
|
, mLastContentOffset(0)
|
|
|
|
, mLastHint(nsFrameSelection::HINTLEFT)
|
2010-07-26 17:05:14 -07:00
|
|
|
, mLastFrameOffset(0)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
nsCaret::~nsCaret()
|
|
|
|
{
|
|
|
|
KillTimer();
|
|
|
|
}
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
2008-07-16 03:52:01 -07:00
|
|
|
nsresult nsCaret::Init(nsIPresShell *inPresShell)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
NS_ENSURE_ARG(inPresShell);
|
2008-07-16 03:52:01 -07:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
mPresShell = do_GetWeakReference(inPresShell); // the presshell owns us, so no addref
|
|
|
|
NS_ASSERTION(mPresShell, "Hey, pres shell should support weak refs");
|
|
|
|
|
|
|
|
// get nsILookAndFeel from the pres context, which has one cached.
|
|
|
|
nsILookAndFeel *lookAndFeel = nsnull;
|
|
|
|
nsPresContext *presContext = inPresShell->GetPresContext();
|
|
|
|
|
2008-04-14 14:09:23 -07:00
|
|
|
// XXX we should just do this nsILookAndFeel consultation every time
|
|
|
|
// we need these values.
|
|
|
|
mCaretWidthCSSPx = 1;
|
2008-06-23 01:50:52 -07:00
|
|
|
mCaretAspectRatio = 0;
|
2007-03-22 10:30:00 -07:00
|
|
|
if (presContext && (lookAndFeel = presContext->LookAndFeel())) {
|
|
|
|
PRInt32 tempInt;
|
2008-06-23 01:50:52 -07:00
|
|
|
float tempFloat;
|
2007-03-22 10:30:00 -07:00
|
|
|
if (NS_SUCCEEDED(lookAndFeel->GetMetric(nsILookAndFeel::eMetric_CaretWidth, tempInt)))
|
2008-04-14 14:09:23 -07:00
|
|
|
mCaretWidthCSSPx = (nscoord)tempInt;
|
2008-06-23 01:50:52 -07:00
|
|
|
if (NS_SUCCEEDED(lookAndFeel->GetMetric(nsILookAndFeel::eMetricFloat_CaretAspectRatio, tempFloat)))
|
|
|
|
mCaretAspectRatio = tempFloat;
|
2007-03-22 10:30:00 -07:00
|
|
|
if (NS_SUCCEEDED(lookAndFeel->GetMetric(nsILookAndFeel::eMetric_CaretBlinkTime, tempInt)))
|
|
|
|
mBlinkRate = (PRUint32)tempInt;
|
|
|
|
if (NS_SUCCEEDED(lookAndFeel->GetMetric(nsILookAndFeel::eMetric_ShowCaretDuringSelection, tempInt)))
|
|
|
|
mShowDuringSelection = tempInt ? PR_TRUE : PR_FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
// get the selection from the pres shell, and set ourselves up as a selection
|
|
|
|
// listener
|
|
|
|
|
|
|
|
nsCOMPtr<nsISelectionController> selCon = do_QueryReferent(mPresShell);
|
|
|
|
if (!selCon)
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
|
|
|
|
nsCOMPtr<nsISelection> domSelection;
|
|
|
|
nsresult rv = selCon->GetSelection(nsISelectionController::SELECTION_NORMAL,
|
|
|
|
getter_AddRefs(domSelection));
|
|
|
|
if (NS_FAILED(rv))
|
|
|
|
return rv;
|
|
|
|
if (!domSelection)
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
|
|
|
|
nsCOMPtr<nsISelectionPrivate> privateSelection = do_QueryInterface(domSelection);
|
|
|
|
if (privateSelection)
|
|
|
|
privateSelection->AddSelectionListener(this);
|
|
|
|
mDomSelectionWeak = do_GetWeakReference(domSelection);
|
|
|
|
|
|
|
|
// set up the blink timer
|
|
|
|
if (mVisible)
|
|
|
|
{
|
2008-07-16 03:52:01 -07:00
|
|
|
StartBlinking();
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
2008-12-14 01:05:39 -08:00
|
|
|
#ifdef IBMBIDI
|
|
|
|
mBidiUI = nsContentUtils::GetBoolPref("bidi.browser.ui");
|
|
|
|
#endif
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2008-04-22 20:13:55 -07:00
|
|
|
static PRBool
|
|
|
|
DrawCJKCaret(nsIFrame* aFrame, PRInt32 aOffset)
|
|
|
|
{
|
|
|
|
nsIContent* content = aFrame->GetContent();
|
|
|
|
const nsTextFragment* frag = content->GetText();
|
|
|
|
if (!frag)
|
|
|
|
return PR_FALSE;
|
2008-12-28 04:08:22 -08:00
|
|
|
if (aOffset < 0 || PRUint32(aOffset) >= frag->GetLength())
|
2008-04-22 20:13:55 -07:00
|
|
|
return PR_FALSE;
|
|
|
|
PRUnichar ch = frag->CharAt(aOffset);
|
|
|
|
return 0x2e80 <= ch && ch <= 0xd7ff;
|
|
|
|
}
|
|
|
|
|
2008-06-23 01:50:52 -07:00
|
|
|
nsCaret::Metrics nsCaret::ComputeMetrics(nsIFrame* aFrame, PRInt32 aOffset, nscoord aCaretHeight)
|
2008-04-14 14:09:23 -07:00
|
|
|
{
|
|
|
|
// Compute nominal sizes in appunits
|
2008-06-23 01:50:52 -07:00
|
|
|
nscoord caretWidth = (aCaretHeight * mCaretAspectRatio) +
|
|
|
|
nsPresContext::CSSPixelsToAppUnits(mCaretWidthCSSPx);
|
|
|
|
|
2008-04-22 20:13:55 -07:00
|
|
|
if (DrawCJKCaret(aFrame, aOffset)) {
|
|
|
|
caretWidth += nsPresContext::CSSPixelsToAppUnits(1);
|
|
|
|
}
|
2008-04-14 14:09:23 -07:00
|
|
|
nscoord bidiIndicatorSize = nsPresContext::CSSPixelsToAppUnits(kMinBidiIndicatorPixels);
|
2009-09-16 08:01:36 -07:00
|
|
|
bidiIndicatorSize = NS_MAX(caretWidth, bidiIndicatorSize);
|
2008-04-14 14:09:23 -07:00
|
|
|
|
|
|
|
// Round them to device pixels. Always round down, except that anything
|
|
|
|
// between 0 and 1 goes up to 1 so we don't let the caret disappear.
|
2008-04-22 20:13:55 -07:00
|
|
|
PRUint32 tpp = aFrame->PresContext()->AppUnitsPerDevPixel();
|
2008-04-14 14:09:23 -07:00
|
|
|
Metrics result;
|
|
|
|
result.mCaretWidth = NS_ROUND_BORDER_TO_PIXELS(caretWidth, tpp);
|
|
|
|
result.mBidiIndicatorSize = NS_ROUND_BORDER_TO_PIXELS(bidiIndicatorSize, tpp);
|
|
|
|
return result;
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
2008-07-16 03:52:01 -07:00
|
|
|
void nsCaret::Terminate()
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
// this doesn't erase the caret if it's drawn. Should it? We might not have
|
|
|
|
// a good drawing environment during teardown.
|
|
|
|
|
|
|
|
KillTimer();
|
|
|
|
mBlinkTimer = nsnull;
|
|
|
|
|
|
|
|
// unregiser ourselves as a selection listener
|
|
|
|
nsCOMPtr<nsISelection> domSelection = do_QueryReferent(mDomSelectionWeak);
|
|
|
|
nsCOMPtr<nsISelectionPrivate> privateSelection(do_QueryInterface(domSelection));
|
|
|
|
if (privateSelection)
|
|
|
|
privateSelection->RemoveSelectionListener(this);
|
|
|
|
mDomSelectionWeak = nsnull;
|
|
|
|
mPresShell = nsnull;
|
|
|
|
|
|
|
|
mLastContent = nsnull;
|
2010-07-26 17:05:14 -07:00
|
|
|
mLastFrame = nsnull;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
2008-07-16 03:52:01 -07:00
|
|
|
NS_IMPL_ISUPPORTS1(nsCaret, nsISelectionListener)
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
2008-07-16 03:52:01 -07:00
|
|
|
nsISelection* nsCaret::GetCaretDOMSelection()
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
nsCOMPtr<nsISelection> sel(do_QueryReferent(mDomSelectionWeak));
|
2008-07-16 03:52:01 -07:00
|
|
|
return sel;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
2008-07-16 03:52:01 -07:00
|
|
|
nsresult nsCaret::SetCaretDOMSelection(nsISelection *aDOMSel)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
NS_ENSURE_ARG_POINTER(aDOMSel);
|
|
|
|
mDomSelectionWeak = do_GetWeakReference(aDOMSel); // weak reference to pres shell
|
|
|
|
if (mVisible)
|
|
|
|
{
|
|
|
|
// Stop the caret from blinking in its previous location.
|
|
|
|
StopBlinking();
|
|
|
|
// Start the caret blinking in the new location.
|
|
|
|
StartBlinking();
|
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
2008-07-16 03:52:01 -07:00
|
|
|
void nsCaret::SetCaretVisible(PRBool inMakeVisible)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
mVisible = inMakeVisible;
|
2008-02-26 17:49:46 -08:00
|
|
|
if (mVisible) {
|
2008-07-16 03:52:01 -07:00
|
|
|
StartBlinking();
|
2008-02-26 17:49:46 -08:00
|
|
|
SetIgnoreUserModify(PR_TRUE);
|
|
|
|
} else {
|
2008-07-16 03:52:01 -07:00
|
|
|
StopBlinking();
|
2008-02-26 17:49:46 -08:00
|
|
|
SetIgnoreUserModify(PR_FALSE);
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
2008-07-16 03:52:01 -07:00
|
|
|
nsresult nsCaret::GetCaretVisible(PRBool *outMakeVisible)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
NS_ENSURE_ARG_POINTER(outMakeVisible);
|
2008-04-08 11:52:48 -07:00
|
|
|
*outMakeVisible = (mVisible && MustDrawCaret(PR_TRUE));
|
2007-03-22 10:30:00 -07:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
2008-07-16 03:52:01 -07:00
|
|
|
void nsCaret::SetCaretReadOnly(PRBool inMakeReadonly)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
mReadOnly = inMakeReadonly;
|
|
|
|
}
|
|
|
|
|
2010-03-14 15:56:26 -07:00
|
|
|
void
|
|
|
|
nsCaret::GetGeometryForFrame(nsIFrame* aFrame,
|
|
|
|
PRInt32 aFrameOffset,
|
|
|
|
nsRect* aRect,
|
|
|
|
nscoord* aBidiIndicatorSize)
|
2010-01-11 13:45:16 -08:00
|
|
|
{
|
|
|
|
nsPoint framePos(0, 0);
|
2010-03-14 15:56:26 -07:00
|
|
|
aFrame->GetPointFromOffset(aFrameOffset, &framePos);
|
|
|
|
nscoord height = aFrame->GetContentRect().height;
|
2010-03-14 15:52:45 -07:00
|
|
|
if (height == 0) {
|
|
|
|
nsCOMPtr<nsIFontMetrics> fm;
|
2010-03-14 15:56:26 -07:00
|
|
|
nsLayoutUtils::GetFontMetricsForFrame(aFrame, getter_AddRefs(fm));
|
2010-03-14 15:52:45 -07:00
|
|
|
if (fm) {
|
|
|
|
nscoord ascent, descent;
|
|
|
|
fm->GetMaxAscent(ascent);
|
|
|
|
fm->GetMaxDescent(descent);
|
|
|
|
height = ascent + descent;
|
|
|
|
|
|
|
|
// Place the caret on the baseline for inline frames, except when there is
|
|
|
|
// a frame on the line with non-zero height. XXXmats why the exception? --
|
|
|
|
// I don't know but it seems to be necessary, see bug 503531.
|
2010-03-14 15:56:26 -07:00
|
|
|
if (aFrame->GetStyleDisplay()->IsInlineOutside() &&
|
|
|
|
!FramesOnSameLineHaveZeroHeight(aFrame))
|
2010-03-14 15:52:45 -07:00
|
|
|
framePos.y -= ascent;
|
|
|
|
}
|
|
|
|
}
|
2010-03-14 15:56:26 -07:00
|
|
|
Metrics caretMetrics = ComputeMetrics(aFrame, aFrameOffset, height);
|
2010-03-14 15:52:45 -07:00
|
|
|
*aRect = nsRect(framePos, nsSize(caretMetrics.mCaretWidth, height));
|
|
|
|
|
|
|
|
// Clamp the x-position to be within our scroll frame. If we don't, then it
|
|
|
|
// clips us, and we don't appear at all. See bug 335560.
|
|
|
|
nsIFrame *scrollFrame =
|
2010-03-14 15:56:26 -07:00
|
|
|
nsLayoutUtils::GetClosestFrameOfType(aFrame, nsGkAtoms::scrollFrame);
|
2010-03-14 15:52:45 -07:00
|
|
|
if (scrollFrame) {
|
2010-03-14 15:56:26 -07:00
|
|
|
// First, use the scrollFrame to get at the scrollable view that we're in.
|
2010-03-14 15:52:45 -07:00
|
|
|
nsIScrollableFrame *sf = do_QueryFrame(scrollFrame);
|
|
|
|
nsIFrame *scrolled = sf->GetScrolledFrame();
|
2010-03-14 15:56:26 -07:00
|
|
|
nsRect caretInScroll = *aRect + aFrame->GetOffsetTo(scrolled);
|
2010-03-14 15:52:45 -07:00
|
|
|
|
2010-03-14 15:56:26 -07:00
|
|
|
// Now see if thet caret extends beyond the view's bounds. If it does,
|
2010-03-14 15:52:45 -07:00
|
|
|
// then snap it back, put it as close to the edge as it can.
|
|
|
|
nscoord overflow = caretInScroll.XMost() -
|
|
|
|
scrolled->GetOverflowRectRelativeToSelf().width;
|
|
|
|
if (overflow > 0)
|
|
|
|
aRect->x -= overflow;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (aBidiIndicatorSize)
|
|
|
|
*aBidiIndicatorSize = caretMetrics.mBidiIndicatorSize;
|
2010-03-14 15:56:26 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
nsIFrame* nsCaret::GetGeometry(nsISelection* aSelection, nsRect* aRect,
|
|
|
|
nscoord* aBidiIndicatorSize)
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsIDOMNode> focusNode;
|
|
|
|
nsresult rv = aSelection->GetFocusNode(getter_AddRefs(focusNode));
|
|
|
|
if (NS_FAILED(rv) || !focusNode)
|
|
|
|
return nsnull;
|
|
|
|
|
|
|
|
PRInt32 focusOffset;
|
|
|
|
rv = aSelection->GetFocusOffset(&focusOffset);
|
|
|
|
if (NS_FAILED(rv))
|
|
|
|
return nsnull;
|
|
|
|
|
|
|
|
nsCOMPtr<nsIContent> contentNode = do_QueryInterface(focusNode);
|
|
|
|
if (!contentNode)
|
|
|
|
return nsnull;
|
|
|
|
|
|
|
|
nsCOMPtr<nsFrameSelection> frameSelection = GetFrameSelection();
|
|
|
|
if (!frameSelection)
|
|
|
|
return nsnull;
|
|
|
|
PRUint8 bidiLevel = frameSelection->GetCaretBidiLevel();
|
|
|
|
nsIFrame* frame;
|
|
|
|
PRInt32 frameOffset;
|
|
|
|
rv = GetCaretFrameForNodeOffset(contentNode, focusOffset,
|
|
|
|
frameSelection->GetHint(), bidiLevel,
|
|
|
|
&frame, &frameOffset);
|
|
|
|
if (NS_FAILED(rv) || !frame)
|
|
|
|
return nsnull;
|
|
|
|
|
|
|
|
GetGeometryForFrame(frame, frameOffset, aRect, aBidiIndicatorSize);
|
|
|
|
return frame;
|
2010-01-11 13:45:16 -08:00
|
|
|
}
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
void nsCaret::DrawCaretAfterBriefDelay()
|
|
|
|
{
|
|
|
|
// Make sure readonly caret gets drawn again if it needs to be
|
|
|
|
if (!mBlinkTimer) {
|
|
|
|
nsresult err;
|
|
|
|
mBlinkTimer = do_CreateInstance("@mozilla.org/timer;1", &err);
|
|
|
|
if (NS_FAILED(err))
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
mBlinkTimer->InitWithFuncCallback(CaretBlinkCallback, this, 0,
|
|
|
|
nsITimer::TYPE_ONE_SHOT);
|
|
|
|
}
|
|
|
|
|
2008-07-16 03:52:01 -07:00
|
|
|
void nsCaret::EraseCaret()
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
if (mDrawn) {
|
|
|
|
DrawCaret(PR_TRUE);
|
2007-08-13 14:33:25 -07:00
|
|
|
if (mReadOnly && mBlinkRate) {
|
2007-03-22 10:30:00 -07:00
|
|
|
// If readonly we don't have a blink timer set, so caret won't
|
|
|
|
// be redrawn automatically. We need to force the caret to get
|
|
|
|
// redrawn right after the paint
|
|
|
|
DrawCaretAfterBriefDelay();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-07-16 03:52:01 -07:00
|
|
|
void nsCaret::SetVisibilityDuringSelection(PRBool aVisibility)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
mShowDuringSelection = aVisibility;
|
|
|
|
}
|
|
|
|
|
2008-07-16 03:52:01 -07:00
|
|
|
nsresult nsCaret::DrawAtPosition(nsIDOMNode* aNode, PRInt32 aOffset)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
NS_ENSURE_ARG(aNode);
|
|
|
|
|
|
|
|
PRUint8 bidiLevel;
|
2007-11-22 12:47:33 -08:00
|
|
|
nsCOMPtr<nsFrameSelection> frameSelection = GetFrameSelection();
|
2007-03-22 10:30:00 -07:00
|
|
|
if (!frameSelection)
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
bidiLevel = frameSelection->GetCaretBidiLevel();
|
2007-08-13 14:33:25 -07:00
|
|
|
|
|
|
|
// DrawAtPosition is used by consumers who want us to stay drawn where they
|
|
|
|
// tell us. Setting mBlinkRate to 0 tells us to not set a timer to erase
|
|
|
|
// ourselves, our consumer will take care of that.
|
|
|
|
mBlinkRate = 0;
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
// XXX we need to do more work here to get the correct hint.
|
|
|
|
nsresult rv = DrawAtPositionWithHint(aNode, aOffset,
|
|
|
|
nsFrameSelection::HINTLEFT,
|
|
|
|
bidiLevel, PR_TRUE)
|
|
|
|
? NS_OK : NS_ERROR_FAILURE;
|
|
|
|
ToggleDrawnStatus();
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
2010-03-31 19:35:48 -07:00
|
|
|
nsIFrame * nsCaret::GetCaretFrame(PRInt32 *aOffset)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
// Return null if we're not drawn to prevent anybody from trying to draw us.
|
|
|
|
if (!mDrawn)
|
|
|
|
return nsnull;
|
|
|
|
|
2010-07-26 17:05:14 -07:00
|
|
|
// Recompute the frame that we're supposed to draw in if the cached frame
|
|
|
|
// is stale (dead).
|
2010-03-31 19:35:48 -07:00
|
|
|
PRInt32 offset;
|
2007-03-22 10:30:00 -07:00
|
|
|
nsIFrame *frame = nsnull;
|
|
|
|
nsresult rv = GetCaretFrameForNodeOffset(mLastContent, mLastContentOffset,
|
|
|
|
mLastHint, mLastBidiLevel, &frame,
|
2010-03-31 19:35:48 -07:00
|
|
|
&offset);
|
2007-03-22 10:30:00 -07:00
|
|
|
if (NS_FAILED(rv))
|
|
|
|
return nsnull;
|
|
|
|
|
2010-03-31 19:35:48 -07:00
|
|
|
if (aOffset) {
|
|
|
|
*aOffset = offset;
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
return frame;
|
|
|
|
}
|
|
|
|
|
|
|
|
void nsCaret::InvalidateOutsideCaret()
|
|
|
|
{
|
|
|
|
nsIFrame *frame = GetCaretFrame();
|
|
|
|
|
|
|
|
// Only invalidate if we are not fully contained by our frame's rect.
|
|
|
|
if (frame && !frame->GetOverflowRect().Contains(GetCaretRect()))
|
|
|
|
InvalidateRects(mCaretRect, GetHookRect(), frame);
|
|
|
|
}
|
|
|
|
|
|
|
|
void nsCaret::UpdateCaretPosition()
|
|
|
|
{
|
|
|
|
// We'll recalculate anyway if we're not drawn right now.
|
|
|
|
if (!mDrawn)
|
|
|
|
return;
|
|
|
|
|
|
|
|
// A trick! Make the DrawCaret code recalculate the caret's current
|
|
|
|
// position.
|
|
|
|
mDrawn = PR_FALSE;
|
|
|
|
DrawCaret(PR_FALSE);
|
|
|
|
}
|
|
|
|
|
|
|
|
void nsCaret::PaintCaret(nsDisplayListBuilder *aBuilder,
|
|
|
|
nsIRenderingContext *aCtx,
|
2008-06-23 01:50:52 -07:00
|
|
|
nsIFrame* aForFrame,
|
|
|
|
const nsPoint &aOffset)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
NS_ASSERTION(mDrawn, "The caret shouldn't be drawing");
|
|
|
|
|
2008-06-23 01:50:52 -07:00
|
|
|
const nsRect drawCaretRect = mCaretRect + aOffset;
|
2010-03-31 19:35:48 -07:00
|
|
|
PRInt32 contentOffset;
|
|
|
|
nsIFrame* frame = GetCaretFrame(&contentOffset);
|
|
|
|
NS_ASSERTION(frame == aForFrame, "We're referring different frame");
|
|
|
|
nscolor foregroundColor = aForFrame->GetCaretColorAt(contentOffset);
|
2008-06-23 01:50:52 -07:00
|
|
|
|
|
|
|
// Only draw the native caret if the foreground color matches that of
|
|
|
|
// -moz-fieldtext (the color of the text in a textbox). If it doesn't match
|
|
|
|
// we are likely in contenteditable or a custom widget and we risk being hard to see
|
|
|
|
// against the background. In that case, fall back to the CSS color.
|
|
|
|
nsPresContext* presContext = aForFrame->PresContext();
|
|
|
|
|
|
|
|
if (GetHookRect().IsEmpty() && presContext) {
|
|
|
|
nsITheme *theme = presContext->GetTheme();
|
|
|
|
if (theme && theme->ThemeSupportsWidget(presContext, aForFrame, NS_THEME_TEXTFIELD_CARET)) {
|
|
|
|
nsILookAndFeel* lookAndFeel = presContext->LookAndFeel();
|
|
|
|
nscolor fieldText;
|
|
|
|
if (NS_SUCCEEDED(lookAndFeel->GetColor(nsILookAndFeel::eColor__moz_fieldtext, fieldText)) &&
|
2010-03-31 19:35:48 -07:00
|
|
|
fieldText == foregroundColor) {
|
2008-06-23 01:50:52 -07:00
|
|
|
theme->DrawWidgetBackground(aCtx, aForFrame, NS_THEME_TEXTFIELD_CARET,
|
|
|
|
drawCaretRect, drawCaretRect);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-03-31 19:35:48 -07:00
|
|
|
aCtx->SetColor(foregroundColor);
|
2008-06-23 01:50:52 -07:00
|
|
|
aCtx->FillRect(drawCaretRect);
|
2007-03-22 10:30:00 -07:00
|
|
|
if (!GetHookRect().IsEmpty())
|
|
|
|
aCtx->FillRect(GetHookRect() + aOffset);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
NS_IMETHODIMP nsCaret::NotifySelectionChanged(nsIDOMDocument *, nsISelection *aDomSel, PRInt16 aReason)
|
|
|
|
{
|
|
|
|
if (aReason & nsISelectionListener::MOUSEUP_REASON)//this wont do
|
|
|
|
return NS_OK;
|
|
|
|
|
|
|
|
nsCOMPtr<nsISelection> domSel(do_QueryReferent(mDomSelectionWeak));
|
|
|
|
|
|
|
|
// The same caret is shared amongst the document and any text widgets it
|
|
|
|
// may contain. This means that the caret could get notifications from
|
|
|
|
// multiple selections.
|
|
|
|
//
|
|
|
|
// If this notification is for a selection that is not the one the
|
|
|
|
// the caret is currently interested in (mDomSelectionWeak), then there
|
|
|
|
// is nothing to do!
|
|
|
|
|
|
|
|
if (domSel != aDomSel)
|
|
|
|
return NS_OK;
|
|
|
|
|
|
|
|
if (mVisible)
|
|
|
|
{
|
|
|
|
// Stop the caret from blinking in its previous location.
|
|
|
|
StopBlinking();
|
|
|
|
|
|
|
|
// Start the caret blinking in the new location.
|
|
|
|
StartBlinking();
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
void nsCaret::KillTimer()
|
|
|
|
{
|
|
|
|
if (mBlinkTimer)
|
|
|
|
{
|
|
|
|
mBlinkTimer->Cancel();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
nsresult nsCaret::PrimeTimer()
|
|
|
|
{
|
|
|
|
// set up the blink timer
|
|
|
|
if (!mReadOnly && mBlinkRate > 0)
|
|
|
|
{
|
|
|
|
if (!mBlinkTimer) {
|
|
|
|
nsresult err;
|
|
|
|
mBlinkTimer = do_CreateInstance("@mozilla.org/timer;1", &err);
|
|
|
|
if (NS_FAILED(err))
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
|
|
|
mBlinkTimer->InitWithFuncCallback(CaretBlinkCallback, this, mBlinkRate,
|
|
|
|
nsITimer::TYPE_REPEATING_SLACK);
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
2008-07-16 03:52:01 -07:00
|
|
|
void nsCaret::StartBlinking()
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
if (mReadOnly) {
|
|
|
|
// Make sure the one draw command we use for a readonly caret isn't
|
|
|
|
// done until the selection is set
|
|
|
|
DrawCaretAfterBriefDelay();
|
2008-07-16 03:52:01 -07:00
|
|
|
return;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
PrimeTimer();
|
|
|
|
|
|
|
|
// If we are currently drawn, then the second call to DrawCaret below will
|
|
|
|
// actually erase the caret. That would cause the caret to spend an "off"
|
|
|
|
// cycle before it appears, which is not really what we want. This first
|
|
|
|
// call to DrawCaret makes sure that the first cycle after a call to
|
|
|
|
// StartBlinking is an "on" cycle.
|
|
|
|
if (mDrawn)
|
|
|
|
DrawCaret(PR_TRUE);
|
|
|
|
|
|
|
|
DrawCaret(PR_TRUE); // draw it right away
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
2008-07-16 03:52:01 -07:00
|
|
|
void nsCaret::StopBlinking()
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
if (mDrawn) // erase the caret if necessary
|
|
|
|
DrawCaret(PR_TRUE);
|
|
|
|
|
2008-02-26 17:49:46 -08:00
|
|
|
NS_ASSERTION(!mDrawn, "Caret still drawn after StopBlinking().");
|
2007-03-22 10:30:00 -07:00
|
|
|
KillTimer();
|
|
|
|
}
|
|
|
|
|
|
|
|
PRBool
|
|
|
|
nsCaret::DrawAtPositionWithHint(nsIDOMNode* aNode,
|
|
|
|
PRInt32 aOffset,
|
|
|
|
nsFrameSelection::HINT aFrameHint,
|
|
|
|
PRUint8 aBidiLevel,
|
|
|
|
PRBool aInvalidate)
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsIContent> contentNode = do_QueryInterface(aNode);
|
|
|
|
if (!contentNode)
|
|
|
|
return PR_FALSE;
|
|
|
|
|
|
|
|
nsIFrame* theFrame = nsnull;
|
|
|
|
PRInt32 theFrameOffset = 0;
|
|
|
|
|
|
|
|
nsresult rv = GetCaretFrameForNodeOffset(contentNode, aOffset, aFrameHint, aBidiLevel,
|
|
|
|
&theFrame, &theFrameOffset);
|
|
|
|
if (NS_FAILED(rv) || !theFrame)
|
|
|
|
return PR_FALSE;
|
2007-06-27 19:48:16 -07:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
// now we have a frame, check whether it's appropriate to show the caret here
|
|
|
|
const nsStyleUserInterface* userinterface = theFrame->GetStyleUserInterface();
|
2007-08-10 06:19:13 -07:00
|
|
|
if ((!mIgnoreUserModify &&
|
|
|
|
userinterface->mUserModify == NS_STYLE_USER_MODIFY_READ_ONLY) ||
|
2007-03-22 10:30:00 -07:00
|
|
|
(userinterface->mUserInput == NS_STYLE_USER_INPUT_NONE) ||
|
|
|
|
(userinterface->mUserInput == NS_STYLE_USER_INPUT_DISABLED))
|
|
|
|
{
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!mDrawn)
|
|
|
|
{
|
|
|
|
// save stuff so we can figure out what frame we're in later.
|
|
|
|
mLastContent = contentNode;
|
|
|
|
mLastContentOffset = aOffset;
|
|
|
|
mLastHint = aFrameHint;
|
|
|
|
mLastBidiLevel = aBidiLevel;
|
2010-08-23 20:49:15 -07:00
|
|
|
mLastFrame = theFrame;
|
|
|
|
mLastFrameOffset = theFrameOffset;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
// If there has been a reflow, set the caret Bidi level to the level of the current frame
|
|
|
|
if (aBidiLevel & BIDI_LEVEL_UNDEFINED) {
|
2007-11-22 12:47:33 -08:00
|
|
|
nsCOMPtr<nsFrameSelection> frameSelection = GetFrameSelection();
|
2007-03-22 10:30:00 -07:00
|
|
|
if (!frameSelection)
|
2007-10-09 17:00:05 -07:00
|
|
|
return PR_FALSE;
|
2007-03-22 10:30:00 -07:00
|
|
|
frameSelection->SetCaretBidiLevel(NS_GET_EMBEDDING_LEVEL(theFrame));
|
|
|
|
}
|
|
|
|
|
|
|
|
// Only update the caret's rect when we're not currently drawn.
|
2010-03-14 15:54:11 -07:00
|
|
|
if (!UpdateCaretRects(theFrame, theFrameOffset))
|
2007-03-22 10:30:00 -07:00
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (aInvalidate)
|
|
|
|
InvalidateRects(mCaretRect, mHookRect, theFrame);
|
|
|
|
|
|
|
|
return PR_TRUE;
|
|
|
|
}
|
|
|
|
|
2008-07-16 03:52:01 -07:00
|
|
|
nsresult
|
2007-03-22 10:30:00 -07:00
|
|
|
nsCaret::GetCaretFrameForNodeOffset(nsIContent* aContentNode,
|
|
|
|
PRInt32 aOffset,
|
|
|
|
nsFrameSelection::HINT aFrameHint,
|
|
|
|
PRUint8 aBidiLevel,
|
|
|
|
nsIFrame** aReturnFrame,
|
|
|
|
PRInt32* aReturnOffset)
|
|
|
|
{
|
2010-07-26 17:05:14 -07:00
|
|
|
// Try to see if we can use our cached frame
|
|
|
|
if (mLastFrame.IsAlive() &&
|
|
|
|
mLastContent == aContentNode &&
|
|
|
|
mLastContentOffset == aOffset &&
|
|
|
|
mLastHint == aFrameHint &&
|
|
|
|
mLastBidiLevel == aBidiLevel) {
|
|
|
|
*aReturnFrame = mLastFrame;
|
|
|
|
*aReturnOffset = mLastFrameOffset;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
//get frame selection and find out what frame to use...
|
|
|
|
nsCOMPtr<nsIPresShell> presShell = do_QueryReferent(mPresShell);
|
|
|
|
if (!presShell)
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
|
2007-11-22 12:47:33 -08:00
|
|
|
nsCOMPtr<nsFrameSelection> frameSelection = GetFrameSelection();
|
2007-03-22 10:30:00 -07:00
|
|
|
if (!frameSelection)
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
|
|
|
|
nsIFrame* theFrame = nsnull;
|
|
|
|
PRInt32 theFrameOffset = 0;
|
|
|
|
|
|
|
|
theFrame = frameSelection->GetFrameForNodeOffset(aContentNode, aOffset,
|
|
|
|
aFrameHint, &theFrameOffset);
|
|
|
|
if (!theFrame)
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
|
2007-11-07 20:07:00 -08:00
|
|
|
// if theFrame is after a text frame that's logically at the end of the line
|
|
|
|
// (e.g. if theFrame is a <br> frame), then put the caret at the end of
|
|
|
|
// that text frame instead. This way, the caret will be positioned as if
|
|
|
|
// trailing whitespace was not trimmed.
|
|
|
|
AdjustCaretFrameForLineEnd(&theFrame, &theFrameOffset);
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
// Mamdouh : modification of the caret to work at rtl and ltr with Bidi
|
|
|
|
//
|
|
|
|
// Direction Style from this->GetStyleData()
|
|
|
|
// now in (visibility->mDirection)
|
|
|
|
// ------------------
|
|
|
|
// NS_STYLE_DIRECTION_LTR : LTR or Default
|
|
|
|
// NS_STYLE_DIRECTION_RTL
|
|
|
|
// NS_STYLE_DIRECTION_INHERIT
|
2008-12-14 01:05:39 -08:00
|
|
|
if (mBidiUI)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
// If there has been a reflow, take the caret Bidi level to be the level of the current frame
|
|
|
|
if (aBidiLevel & BIDI_LEVEL_UNDEFINED)
|
|
|
|
aBidiLevel = NS_GET_EMBEDDING_LEVEL(theFrame);
|
|
|
|
|
|
|
|
PRInt32 start;
|
|
|
|
PRInt32 end;
|
|
|
|
nsIFrame* frameBefore;
|
|
|
|
nsIFrame* frameAfter;
|
|
|
|
PRUint8 levelBefore; // Bidi level of the character before the caret
|
|
|
|
PRUint8 levelAfter; // Bidi level of the character after the caret
|
|
|
|
|
|
|
|
theFrame->GetOffsets(start, end);
|
|
|
|
if (start == 0 || end == 0 || start == theFrameOffset || end == theFrameOffset)
|
|
|
|
{
|
|
|
|
nsPrevNextBidiLevels levels = frameSelection->
|
|
|
|
GetPrevNextBidiLevels(aContentNode, aOffset, PR_FALSE);
|
|
|
|
|
|
|
|
/* Boundary condition, we need to know the Bidi levels of the characters before and after the caret */
|
|
|
|
if (levels.mFrameBefore || levels.mFrameAfter)
|
|
|
|
{
|
|
|
|
frameBefore = levels.mFrameBefore;
|
|
|
|
frameAfter = levels.mFrameAfter;
|
|
|
|
levelBefore = levels.mLevelBefore;
|
|
|
|
levelAfter = levels.mLevelAfter;
|
|
|
|
|
|
|
|
if ((levelBefore != levelAfter) || (aBidiLevel != levelBefore))
|
|
|
|
{
|
2009-09-16 08:01:36 -07:00
|
|
|
aBidiLevel = NS_MAX(aBidiLevel, NS_MIN(levelBefore, levelAfter)); // rule c3
|
|
|
|
aBidiLevel = NS_MIN(aBidiLevel, NS_MAX(levelBefore, levelAfter)); // rule c4
|
2007-03-22 10:30:00 -07:00
|
|
|
if (aBidiLevel == levelBefore // rule c1
|
2008-09-15 08:40:25 -07:00
|
|
|
|| (aBidiLevel > levelBefore && aBidiLevel < levelAfter && !((aBidiLevel ^ levelBefore) & 1)) // rule c5
|
|
|
|
|| (aBidiLevel < levelBefore && aBidiLevel > levelAfter && !((aBidiLevel ^ levelBefore) & 1))) // rule c9
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
if (theFrame != frameBefore)
|
|
|
|
{
|
|
|
|
if (frameBefore) // if there is a frameBefore, move into it
|
|
|
|
{
|
|
|
|
theFrame = frameBefore;
|
|
|
|
theFrame->GetOffsets(start, end);
|
|
|
|
theFrameOffset = end;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// if there is no frameBefore, we must be at the beginning of the line
|
|
|
|
// so we stay with the current frame.
|
|
|
|
// Exception: when the first frame on the line has a different Bidi level from the paragraph level, there is no
|
|
|
|
// real frame for the caret to be in. We have to find the visually first frame on the line.
|
|
|
|
PRUint8 baseLevel = NS_GET_BASE_LEVEL(frameAfter);
|
|
|
|
if (baseLevel != levelAfter)
|
|
|
|
{
|
|
|
|
nsPeekOffsetStruct pos;
|
|
|
|
pos.SetData(eSelectBeginLine, eDirPrevious, 0, 0, PR_FALSE, PR_TRUE, PR_FALSE, PR_TRUE);
|
|
|
|
if (NS_SUCCEEDED(frameAfter->PeekOffset(&pos))) {
|
|
|
|
theFrame = pos.mResultFrame;
|
|
|
|
theFrameOffset = pos.mContentOffset;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (aBidiLevel == levelAfter // rule c2
|
2008-09-15 08:40:25 -07:00
|
|
|
|| (aBidiLevel > levelBefore && aBidiLevel < levelAfter && !((aBidiLevel ^ levelAfter) & 1)) // rule c6
|
|
|
|
|| (aBidiLevel < levelBefore && aBidiLevel > levelAfter && !((aBidiLevel ^ levelAfter) & 1))) // rule c10
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
if (theFrame != frameAfter)
|
|
|
|
{
|
|
|
|
if (frameAfter)
|
|
|
|
{
|
|
|
|
// if there is a frameAfter, move into it
|
|
|
|
theFrame = frameAfter;
|
|
|
|
theFrame->GetOffsets(start, end);
|
|
|
|
theFrameOffset = start;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// if there is no frameAfter, we must be at the end of the line
|
|
|
|
// so we stay with the current frame.
|
|
|
|
// Exception: when the last frame on the line has a different Bidi level from the paragraph level, there is no
|
|
|
|
// real frame for the caret to be in. We have to find the visually last frame on the line.
|
|
|
|
PRUint8 baseLevel = NS_GET_BASE_LEVEL(frameBefore);
|
|
|
|
if (baseLevel != levelBefore)
|
|
|
|
{
|
|
|
|
nsPeekOffsetStruct pos;
|
|
|
|
pos.SetData(eSelectEndLine, eDirNext, 0, 0, PR_FALSE, PR_TRUE, PR_FALSE, PR_TRUE);
|
|
|
|
if (NS_SUCCEEDED(frameBefore->PeekOffset(&pos))) {
|
|
|
|
theFrame = pos.mResultFrame;
|
|
|
|
theFrameOffset = pos.mContentOffset;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (aBidiLevel > levelBefore && aBidiLevel < levelAfter // rule c7/8
|
|
|
|
&& !((levelBefore ^ levelAfter) & 1) // before and after have the same parity
|
|
|
|
&& ((aBidiLevel ^ levelAfter) & 1)) // caret has different parity
|
|
|
|
{
|
|
|
|
if (NS_SUCCEEDED(frameSelection->GetFrameFromLevel(frameAfter, eDirNext, aBidiLevel, &theFrame)))
|
|
|
|
{
|
|
|
|
theFrame->GetOffsets(start, end);
|
|
|
|
levelAfter = NS_GET_EMBEDDING_LEVEL(theFrame);
|
|
|
|
if (aBidiLevel & 1) // c8: caret to the right of the rightmost character
|
|
|
|
theFrameOffset = (levelAfter & 1) ? start : end;
|
|
|
|
else // c7: caret to the left of the leftmost character
|
|
|
|
theFrameOffset = (levelAfter & 1) ? end : start;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (aBidiLevel < levelBefore && aBidiLevel > levelAfter // rule c11/12
|
|
|
|
&& !((levelBefore ^ levelAfter) & 1) // before and after have the same parity
|
|
|
|
&& ((aBidiLevel ^ levelAfter) & 1)) // caret has different parity
|
|
|
|
{
|
|
|
|
if (NS_SUCCEEDED(frameSelection->GetFrameFromLevel(frameBefore, eDirPrevious, aBidiLevel, &theFrame)))
|
|
|
|
{
|
|
|
|
theFrame->GetOffsets(start, end);
|
|
|
|
levelBefore = NS_GET_EMBEDDING_LEVEL(theFrame);
|
|
|
|
if (aBidiLevel & 1) // c12: caret to the left of the leftmost character
|
|
|
|
theFrameOffset = (levelBefore & 1) ? end : start;
|
|
|
|
else // c11: caret to the right of the rightmost character
|
|
|
|
theFrameOffset = (levelBefore & 1) ? start : end;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
*aReturnFrame = theFrame;
|
|
|
|
*aReturnOffset = theFrameOffset;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2009-10-16 03:55:32 -07:00
|
|
|
nsresult nsCaret::CheckCaretDrawingState()
|
2008-04-01 01:35:11 -07:00
|
|
|
{
|
2009-10-16 03:55:32 -07:00
|
|
|
if (mDrawn) {
|
|
|
|
// The caret is drawn; if it shouldn't be, erase it.
|
|
|
|
if (!mVisible || !MustDrawCaret(PR_TRUE))
|
|
|
|
EraseCaret();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// The caret is not drawn; if it should be, draw it.
|
|
|
|
if (mPendingDraw && (mVisible && MustDrawCaret(PR_TRUE)))
|
|
|
|
DrawCaret(PR_TRUE);
|
|
|
|
}
|
2008-04-01 01:35:11 -07:00
|
|
|
return NS_OK;
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
/*-----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
MustDrawCaret
|
|
|
|
|
2008-04-01 01:35:11 -07:00
|
|
|
Find out if we need to do any caret drawing. This returns true if
|
|
|
|
either:
|
|
|
|
a) The caret has been drawn, and we need to erase it.
|
|
|
|
b) The caret is not drawn, and the selection is collapsed.
|
|
|
|
c) The caret is not hidden due to open XUL popups
|
|
|
|
(see IsMenuPopupHidingCaret()).
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
----------------------------------------------------------------------------- */
|
2008-04-01 01:35:11 -07:00
|
|
|
PRBool nsCaret::MustDrawCaret(PRBool aIgnoreDrawnState)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2008-04-01 01:35:11 -07:00
|
|
|
if (!aIgnoreDrawnState && mDrawn)
|
2007-03-22 10:30:00 -07:00
|
|
|
return PR_TRUE;
|
|
|
|
|
|
|
|
nsCOMPtr<nsISelection> domSelection = do_QueryReferent(mDomSelectionWeak);
|
|
|
|
if (!domSelection)
|
|
|
|
return PR_FALSE;
|
|
|
|
|
2009-10-16 03:55:32 -07:00
|
|
|
PRBool isCollapsed;
|
2007-03-22 10:30:00 -07:00
|
|
|
if (NS_FAILED(domSelection->GetIsCollapsed(&isCollapsed)))
|
|
|
|
return PR_FALSE;
|
|
|
|
|
|
|
|
if (mShowDuringSelection)
|
|
|
|
return PR_TRUE; // show the caret even in selections
|
|
|
|
|
2008-04-01 01:35:11 -07:00
|
|
|
if (IsMenuPopupHidingCaret())
|
|
|
|
return PR_FALSE;
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
return isCollapsed;
|
|
|
|
}
|
|
|
|
|
2008-04-01 01:35:11 -07:00
|
|
|
PRBool nsCaret::IsMenuPopupHidingCaret()
|
|
|
|
{
|
2008-09-08 05:23:38 -07:00
|
|
|
#ifdef MOZ_XUL
|
2008-04-01 01:35:11 -07:00
|
|
|
// Check if there are open popups.
|
|
|
|
nsXULPopupManager *popMgr = nsXULPopupManager::GetInstance();
|
2009-02-24 00:25:25 -08:00
|
|
|
nsTArray<nsIFrame*> popups = popMgr->GetVisiblePopups();
|
2008-04-01 01:35:11 -07:00
|
|
|
|
|
|
|
if (popups.Length() == 0)
|
|
|
|
return PR_FALSE; // No popups, so caret can't be hidden by them.
|
|
|
|
|
|
|
|
// Get the selection focus content, that's where the caret would
|
|
|
|
// go if it was drawn.
|
|
|
|
nsCOMPtr<nsIDOMNode> node;
|
|
|
|
nsCOMPtr<nsISelection> domSelection = do_QueryReferent(mDomSelectionWeak);
|
|
|
|
if (!domSelection)
|
|
|
|
return PR_TRUE; // No selection/caret to draw.
|
|
|
|
domSelection->GetFocusNode(getter_AddRefs(node));
|
|
|
|
if (!node)
|
|
|
|
return PR_TRUE; // No selection/caret to draw.
|
|
|
|
nsCOMPtr<nsIContent> caretContent = do_QueryInterface(node);
|
2008-04-08 23:16:09 -07:00
|
|
|
if (!caretContent)
|
|
|
|
return PR_TRUE; // No selection/caret to draw.
|
2008-04-01 01:35:11 -07:00
|
|
|
|
|
|
|
// If there's a menu popup open before the popup with
|
|
|
|
// the caret, don't show the caret.
|
|
|
|
for (PRUint32 i=0; i<popups.Length(); i++) {
|
|
|
|
nsMenuPopupFrame* popupFrame = static_cast<nsMenuPopupFrame*>(popups[i]);
|
|
|
|
nsIContent* popupContent = popupFrame->GetContent();
|
|
|
|
|
|
|
|
if (nsContentUtils::ContentIsDescendantOf(caretContent, popupContent)) {
|
|
|
|
// The caret is in this popup. There were no menu popups before this
|
|
|
|
// popup, so don't hide the caret.
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
|
2008-04-30 09:54:16 -07:00
|
|
|
if (popupFrame->PopupType() == ePopupTypeMenu && !popupFrame->IsContextMenu()) {
|
2008-04-01 01:35:11 -07:00
|
|
|
// This is an open menu popup. It does not contain the caret (else we'd
|
|
|
|
// have returned above). Even if the caret is in a subsequent popup,
|
|
|
|
// or another document/frame, it should be hidden.
|
|
|
|
return PR_TRUE;
|
|
|
|
}
|
|
|
|
}
|
2008-09-08 05:23:38 -07:00
|
|
|
#endif
|
2008-04-01 01:35:11 -07:00
|
|
|
|
|
|
|
// There are no open menu popups, no need to hide the caret.
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
void nsCaret::DrawCaret(PRBool aInvalidate)
|
|
|
|
{
|
2009-10-16 03:55:32 -07:00
|
|
|
// Do we need to draw the caret at all?
|
2008-04-01 01:35:11 -07:00
|
|
|
if (!MustDrawCaret(PR_FALSE))
|
2007-03-22 10:30:00 -07:00
|
|
|
return;
|
|
|
|
|
2009-10-16 03:55:32 -07:00
|
|
|
// Can we draw the caret now?
|
|
|
|
nsCOMPtr<nsIPresShell> presShell = do_QueryReferent(mPresShell);
|
|
|
|
NS_ENSURE_TRUE(presShell, /**/);
|
|
|
|
{
|
2010-03-31 05:43:49 -07:00
|
|
|
if (presShell->IsPaintingSuppressed())
|
2009-10-16 03:55:32 -07:00
|
|
|
{
|
|
|
|
if (!mDrawn)
|
|
|
|
mPendingDraw = PR_TRUE;
|
|
|
|
|
|
|
|
// PresShell::UnsuppressAndInvalidate() will call CheckCaretDrawingState()
|
|
|
|
// to get us drawn.
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
nsCOMPtr<nsIDOMNode> node;
|
|
|
|
PRInt32 offset;
|
|
|
|
nsFrameSelection::HINT hint;
|
|
|
|
PRUint8 bidiLevel;
|
|
|
|
|
|
|
|
if (!mDrawn)
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsISelection> domSelection = do_QueryReferent(mDomSelectionWeak);
|
|
|
|
nsCOMPtr<nsISelectionPrivate> privateSelection(do_QueryInterface(domSelection));
|
|
|
|
if (!privateSelection) return;
|
|
|
|
|
|
|
|
PRBool isCollapsed = PR_FALSE;
|
|
|
|
domSelection->GetIsCollapsed(&isCollapsed);
|
|
|
|
if (!mShowDuringSelection && !isCollapsed)
|
|
|
|
return;
|
|
|
|
|
|
|
|
PRBool hintRight;
|
|
|
|
privateSelection->GetInterlinePosition(&hintRight);//translate hint.
|
|
|
|
hint = hintRight ? nsFrameSelection::HINTRIGHT : nsFrameSelection::HINTLEFT;
|
|
|
|
|
|
|
|
// get the node and offset, which is where we want the caret to draw
|
|
|
|
domSelection->GetFocusNode(getter_AddRefs(node));
|
|
|
|
if (!node)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (NS_FAILED(domSelection->GetFocusOffset(&offset)))
|
|
|
|
return;
|
|
|
|
|
2007-11-22 12:47:33 -08:00
|
|
|
nsCOMPtr<nsFrameSelection> frameSelection = GetFrameSelection();
|
2007-03-22 10:30:00 -07:00
|
|
|
if (!frameSelection)
|
|
|
|
return;
|
2009-10-16 03:55:32 -07:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
bidiLevel = frameSelection->GetCaretBidiLevel();
|
2009-10-16 03:55:32 -07:00
|
|
|
mPendingDraw = PR_FALSE;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (!mLastContent)
|
|
|
|
{
|
|
|
|
mDrawn = PR_FALSE;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (!mLastContent->IsInDoc())
|
|
|
|
{
|
|
|
|
mLastContent = nsnull;
|
|
|
|
mDrawn = PR_FALSE;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
node = do_QueryInterface(mLastContent);
|
|
|
|
offset = mLastContentOffset;
|
|
|
|
hint = mLastHint;
|
|
|
|
bidiLevel = mLastBidiLevel;
|
|
|
|
}
|
|
|
|
|
|
|
|
DrawAtPositionWithHint(node, offset, hint, bidiLevel, aInvalidate);
|
|
|
|
ToggleDrawnStatus();
|
|
|
|
}
|
|
|
|
|
2010-03-14 15:54:11 -07:00
|
|
|
PRBool
|
|
|
|
nsCaret::UpdateCaretRects(nsIFrame* aFrame, PRInt32 aFrameOffset)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
NS_ASSERTION(aFrame, "Should have a frame here");
|
|
|
|
|
2010-03-14 15:52:45 -07:00
|
|
|
nscoord bidiIndicatorSize;
|
2010-03-14 15:56:26 -07:00
|
|
|
GetGeometryForFrame(aFrame, aFrameOffset, &mCaretRect, &bidiIndicatorSize);
|
2007-08-13 13:51:16 -07:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
// on RTL frames the right edge of mCaretRect must be equal to framePos
|
|
|
|
const nsStyleVisibility* vis = aFrame->GetStyleVisibility();
|
|
|
|
if (NS_STYLE_DIRECTION_RTL == vis->mDirection)
|
|
|
|
mCaretRect.x -= mCaretRect.width;
|
|
|
|
|
2010-03-14 15:54:11 -07:00
|
|
|
#ifdef IBMBIDI
|
2007-03-22 10:30:00 -07:00
|
|
|
mHookRect.Empty();
|
|
|
|
|
|
|
|
// Simon -- make a hook to draw to the left or right of the caret to show keyboard language direction
|
2010-03-14 15:54:11 -07:00
|
|
|
PRBool isCaretRTL = PR_FALSE;
|
2007-03-22 10:30:00 -07:00
|
|
|
nsIBidiKeyboard* bidiKeyboard = nsContentUtils::GetBidiKeyboard();
|
2010-03-14 15:54:11 -07:00
|
|
|
// if bidiKeyboard->IsLangRTL() fails, there is no way to tell the
|
|
|
|
// keyboard direction, or the user has no right-to-left keyboard
|
|
|
|
// installed, so we never draw the hook.
|
|
|
|
if (bidiKeyboard && NS_SUCCEEDED(bidiKeyboard->IsLangRTL(&isCaretRTL)) &&
|
|
|
|
mBidiUI) {
|
|
|
|
if (isCaretRTL != mKeyboardRTL) {
|
2007-03-22 10:30:00 -07:00
|
|
|
/* if the caret bidi level and the keyboard language direction are not in
|
|
|
|
* synch, the keyboard language must have been changed by the
|
|
|
|
* user, and if the caret is in a boundary condition (between left-to-right and
|
|
|
|
* right-to-left characters) it may have to change position to
|
|
|
|
* reflect the location in which the next character typed will
|
|
|
|
* appear. We will call |SelectionLanguageChange| and exit
|
|
|
|
* without drawing the caret in the old position.
|
|
|
|
*/
|
|
|
|
mKeyboardRTL = isCaretRTL;
|
2010-03-14 15:56:26 -07:00
|
|
|
nsCOMPtr<nsISelection> domSelection = do_QueryReferent(mDomSelectionWeak);
|
|
|
|
if (!domSelection ||
|
|
|
|
NS_SUCCEEDED(domSelection->SelectionLanguageChange(mKeyboardRTL)))
|
2010-03-14 15:54:11 -07:00
|
|
|
return PR_FALSE;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
// If keyboard language is RTL, draw the hook on the left; if LTR, to the right
|
|
|
|
// The height of the hook rectangle is the same as the width of the caret
|
|
|
|
// rectangle.
|
|
|
|
mHookRect.SetRect(mCaretRect.x + ((isCaretRTL) ?
|
2010-03-14 15:54:11 -07:00
|
|
|
bidiIndicatorSize * -1 :
|
2007-03-22 10:30:00 -07:00
|
|
|
mCaretRect.width),
|
2010-03-14 15:54:11 -07:00
|
|
|
mCaretRect.y + bidiIndicatorSize,
|
|
|
|
bidiIndicatorSize,
|
2007-03-22 10:30:00 -07:00
|
|
|
mCaretRect.width);
|
|
|
|
}
|
|
|
|
#endif //IBMBIDI
|
2010-03-14 15:54:11 -07:00
|
|
|
return PR_TRUE;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
// static
|
|
|
|
void nsCaret::InvalidateRects(const nsRect &aRect, const nsRect &aHook,
|
|
|
|
nsIFrame *aFrame)
|
|
|
|
{
|
|
|
|
NS_ASSERTION(aFrame, "Must have a frame to invalidate");
|
|
|
|
nsRect rect;
|
|
|
|
rect.UnionRect(aRect, aHook);
|
2008-09-18 02:47:21 -07:00
|
|
|
aFrame->Invalidate(rect);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
/* static */
|
|
|
|
void nsCaret::CaretBlinkCallback(nsITimer *aTimer, void *aClosure)
|
|
|
|
{
|
2007-07-08 00:08:04 -07:00
|
|
|
nsCaret *theCaret = reinterpret_cast<nsCaret*>(aClosure);
|
2007-03-22 10:30:00 -07:00
|
|
|
if (!theCaret) return;
|
|
|
|
|
|
|
|
theCaret->DrawCaret(PR_TRUE);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
2007-11-22 12:47:33 -08:00
|
|
|
already_AddRefed<nsFrameSelection>
|
|
|
|
nsCaret::GetFrameSelection()
|
|
|
|
{
|
2007-03-22 10:30:00 -07:00
|
|
|
nsCOMPtr<nsISelectionPrivate> privateSelection(do_QueryReferent(mDomSelectionWeak));
|
|
|
|
if (!privateSelection)
|
|
|
|
return nsnull;
|
2007-11-22 12:47:33 -08:00
|
|
|
nsFrameSelection* frameSelection = nsnull;
|
|
|
|
privateSelection->GetFrameSelection(&frameSelection);
|
2007-03-22 10:30:00 -07:00
|
|
|
return frameSelection;
|
|
|
|
}
|
|
|
|
|
2007-08-10 06:19:13 -07:00
|
|
|
void
|
|
|
|
nsCaret::SetIgnoreUserModify(PRBool aIgnoreUserModify)
|
|
|
|
{
|
2008-02-26 17:49:46 -08:00
|
|
|
if (!aIgnoreUserModify && mIgnoreUserModify && mDrawn) {
|
|
|
|
// We're turning off mIgnoreUserModify. If the caret's drawn
|
|
|
|
// in a read-only node we must erase it, else the next call
|
|
|
|
// to DrawCaret() won't erase the old caret, due to the new
|
|
|
|
// mIgnoreUserModify value.
|
|
|
|
nsIFrame *frame = GetCaretFrame();
|
|
|
|
if (frame) {
|
|
|
|
const nsStyleUserInterface* userinterface = frame->GetStyleUserInterface();
|
|
|
|
if (userinterface->mUserModify == NS_STYLE_USER_MODIFY_READ_ONLY) {
|
|
|
|
StopBlinking();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2007-08-10 06:19:13 -07:00
|
|
|
mIgnoreUserModify = aIgnoreUserModify;
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
2008-07-16 03:52:01 -07:00
|
|
|
nsresult NS_NewCaret(nsCaret** aInstancePtrResult)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
NS_PRECONDITION(aInstancePtrResult, "null ptr");
|
|
|
|
|
|
|
|
nsCaret* caret = new nsCaret();
|
|
|
|
if (nsnull == caret)
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
2008-07-16 03:52:01 -07:00
|
|
|
NS_ADDREF(caret);
|
|
|
|
*aInstancePtrResult = caret;
|
|
|
|
return NS_OK;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|