2001-09-28 20:14:13 +00:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* ***** BEGIN LICENSE BLOCK *****
|
2004-04-18 14:30:37 +00:00
|
|
|
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
1999-02-11 23:49:08 +00:00
|
|
|
*
|
2004-04-18 14:30:37 +00:00
|
|
|
* 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/
|
1999-02-11 23:49:08 +00:00
|
|
|
*
|
2001-09-28 20:14:13 +00:00
|
|
|
* 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.
|
1999-02-11 23:49:08 +00:00
|
|
|
*
|
1999-11-06 03:40:37 +00:00
|
|
|
* The Original Code is mozilla.org code.
|
|
|
|
*
|
2004-04-18 14:30:37 +00:00
|
|
|
* The Initial Developer of the Original Code is
|
2001-09-28 20:14:13 +00:00
|
|
|
* Netscape Communications Corporation.
|
|
|
|
* Portions created by the Initial Developer are Copyright (C) 1998
|
|
|
|
* the Initial Developer. All Rights Reserved.
|
1999-11-06 03:40:37 +00:00
|
|
|
*
|
2001-09-28 20:14:13 +00:00
|
|
|
* Contributor(s):
|
2000-02-02 22:24:56 +00:00
|
|
|
* Pierre Phaneuf <pp@ludusdesign.com>
|
2001-09-28 20:14:13 +00:00
|
|
|
*
|
|
|
|
* Alternatively, the contents of this file may be used under the terms of
|
2004-04-18 14:30:37 +00:00
|
|
|
* 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"),
|
2001-09-28 20:14:13 +00:00
|
|
|
* 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
|
2004-04-18 14:30:37 +00:00
|
|
|
* use your version of this file under the terms of the MPL, indicate your
|
2001-09-28 20:14:13 +00:00
|
|
|
* 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
|
2004-04-18 14:30:37 +00:00
|
|
|
* the terms of any one of the MPL, the GPL or the LGPL.
|
2001-09-28 20:14:13 +00:00
|
|
|
*
|
|
|
|
* ***** END LICENSE BLOCK ***** */
|
1999-02-11 23:49:08 +00:00
|
|
|
|
|
|
|
|
|
|
|
#include "nsCOMPtr.h"
|
|
|
|
|
|
|
|
#include "nsITimer.h"
|
|
|
|
|
1999-07-14 22:18:29 +00:00
|
|
|
#include "nsIComponentManager.h"
|
2001-07-16 02:40:48 +00:00
|
|
|
#include "nsIServiceManager.h"
|
1999-02-12 00:55:46 +00:00
|
|
|
#include "nsIFrameSelection.h"
|
1999-02-11 23:49:08 +00:00
|
|
|
#include "nsIFrame.h"
|
|
|
|
#include "nsIDOMNode.h"
|
|
|
|
#include "nsIDOMRange.h"
|
2001-04-13 00:17:21 +00:00
|
|
|
#include "nsIFontMetrics.h"
|
2000-09-14 11:45:01 +00:00
|
|
|
#include "nsISelection.h"
|
|
|
|
#include "nsISelectionPrivate.h"
|
1999-02-11 23:49:08 +00:00
|
|
|
#include "nsIDOMCharacterData.h"
|
|
|
|
#include "nsIContent.h"
|
|
|
|
#include "nsIPresShell.h"
|
|
|
|
#include "nsIRenderingContext.h"
|
1999-03-02 04:26:49 +00:00
|
|
|
#include "nsIDeviceContext.h"
|
1999-02-11 23:49:08 +00:00
|
|
|
#include "nsIView.h"
|
2000-09-07 05:26:25 +00:00
|
|
|
#include "nsIScrollableView.h"
|
1999-03-02 04:26:49 +00:00
|
|
|
#include "nsIViewManager.h"
|
2004-07-31 23:15:21 +00:00
|
|
|
#include "nsPresContext.h"
|
1999-07-14 22:18:29 +00:00
|
|
|
#include "nsILookAndFeel.h"
|
1999-09-14 23:41:19 +00:00
|
|
|
#include "nsBlockFrame.h"
|
2000-04-27 07:37:12 +00:00
|
|
|
#include "nsISelectionController.h"
|
1999-02-11 23:49:08 +00:00
|
|
|
|
|
|
|
#include "nsCaret.h"
|
|
|
|
|
2004-10-13 02:24:38 +00: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
|
|
|
|
static const PRUint32 kMinBidiIndicatorPixels = 2;
|
|
|
|
|
2004-06-29 19:12:19 +00:00
|
|
|
#if !defined(XP_UNIX) || defined(XP_MACOSX)
|
2000-09-07 20:21:22 +00:00
|
|
|
// Because of drawing issues, we currently always make a new RC. See bug 28068
|
|
|
|
// Before removing this, stuff will need to be fixed and tested on all platforms.
|
|
|
|
// For example, turning this off on Mac right now causes drawing problems on pages
|
|
|
|
// with form elements.
|
|
|
|
#define DONT_REUSE_RENDERING_CONTEXT
|
2004-06-29 19:12:19 +00:00
|
|
|
#endif
|
1999-02-11 23:49:08 +00:00
|
|
|
|
2001-03-21 01:16:22 +00:00
|
|
|
#ifdef IBMBIDI
|
|
|
|
//-------------------------------IBM BIDI--------------------------------------
|
|
|
|
// Mamdouh : Modifiaction of the caret to work with Bidi in the LTR and RTL
|
|
|
|
#include "nsLayoutAtoms.h"
|
|
|
|
//------------------------------END OF IBM BIDI--------------------------------
|
|
|
|
#endif //IBMBIDI
|
|
|
|
|
1999-02-11 23:49:08 +00:00
|
|
|
//-----------------------------------------------------------------------------
|
1999-10-08 20:41:19 +00:00
|
|
|
|
1999-02-11 23:49:08 +00:00
|
|
|
nsCaret::nsCaret()
|
2000-09-07 05:26:25 +00:00
|
|
|
: mPresShell(nsnull)
|
|
|
|
, mBlinkRate(500)
|
|
|
|
, mVisible(PR_FALSE)
|
|
|
|
, mDrawn(PR_FALSE)
|
2001-03-21 05:32:22 +00:00
|
|
|
, mReadOnly(PR_FALSE)
|
2001-04-05 19:53:13 +00:00
|
|
|
, mShowDuringSelection(PR_FALSE)
|
1999-04-01 23:57:35 +00:00
|
|
|
, mLastCaretFrame(nsnull)
|
2000-09-07 20:21:22 +00:00
|
|
|
, mLastCaretView(nsnull)
|
1999-04-01 23:57:35 +00:00
|
|
|
, mLastContentOffset(0)
|
2003-02-27 23:09:51 +00:00
|
|
|
#ifdef IBMBIDI
|
|
|
|
, mKeyboardRTL(PR_FALSE)
|
|
|
|
#endif
|
1999-02-11 23:49:08 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
nsCaret::~nsCaret()
|
|
|
|
{
|
2000-09-07 05:26:25 +00:00
|
|
|
KillTimer();
|
1999-02-11 23:49:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
1999-07-14 22:18:29 +00:00
|
|
|
NS_IMETHODIMP nsCaret::Init(nsIPresShell *inPresShell)
|
1999-02-11 23:49:08 +00:00
|
|
|
{
|
2003-02-27 23:09:51 +00:00
|
|
|
NS_ENSURE_ARG(inPresShell);
|
2000-09-07 05:26:25 +00:00
|
|
|
|
2003-07-25 19:06:59 +00:00
|
|
|
mPresShell = do_GetWeakReference(inPresShell); // the presshell owns us, so no addref
|
2003-02-27 23:09:51 +00:00
|
|
|
NS_ASSERTION(mPresShell, "Hey, pres shell should support weak refs");
|
2000-04-27 07:37:12 +00:00
|
|
|
|
2003-02-27 23:09:51 +00:00
|
|
|
// get nsILookAndFeel from the pres context, which has one cached.
|
2004-01-21 09:35:59 +00:00
|
|
|
nsILookAndFeel *lookAndFeel = nsnull;
|
2004-08-20 20:34:37 +00:00
|
|
|
nsPresContext *presContext = inPresShell->GetPresContext();
|
2003-02-27 23:09:51 +00:00
|
|
|
|
2004-10-13 01:12:14 +00:00
|
|
|
PRInt32 caretPixelsWidth = 1;
|
2004-08-20 20:34:37 +00:00
|
|
|
if (presContext && (lookAndFeel = presContext->LookAndFeel())) {
|
2000-09-07 05:26:25 +00:00
|
|
|
PRInt32 tempInt;
|
2004-10-13 01:12:14 +00:00
|
|
|
if (NS_SUCCEEDED(lookAndFeel->GetMetric(nsILookAndFeel::eMetric_CaretWidth, tempInt)))
|
|
|
|
caretPixelsWidth = (nscoord)tempInt;
|
2003-02-27 23:09:51 +00:00
|
|
|
if (NS_SUCCEEDED(lookAndFeel->GetMetric(nsILookAndFeel::eMetric_CaretBlinkTime, tempInt)))
|
1999-07-14 22:18:29 +00:00
|
|
|
mBlinkRate = (PRUint32)tempInt;
|
2003-02-27 23:09:51 +00:00
|
|
|
if (NS_SUCCEEDED(lookAndFeel->GetMetric(nsILookAndFeel::eMetric_ShowCaretDuringSelection, tempInt)))
|
2001-04-05 19:53:13 +00:00
|
|
|
mShowDuringSelection = tempInt ? PR_TRUE : PR_FALSE;
|
1999-07-14 22:18:29 +00:00
|
|
|
}
|
|
|
|
|
2004-10-13 01:12:14 +00:00
|
|
|
float tDevUnitsToTwips;
|
|
|
|
tDevUnitsToTwips = presContext->DeviceContext()->DevUnitsToTwips();
|
|
|
|
mCaretTwipsWidth = (nscoord)(tDevUnitsToTwips * (float)caretPixelsWidth);
|
|
|
|
mBidiIndicatorTwipsSize = (nscoord)(tDevUnitsToTwips * (float)kMinBidiIndicatorPixels);
|
|
|
|
if (mBidiIndicatorTwipsSize < mCaretTwipsWidth) {
|
|
|
|
mBidiIndicatorTwipsSize = mCaretTwipsWidth;
|
|
|
|
}
|
|
|
|
|
2000-09-07 05:26:25 +00:00
|
|
|
// get the selection from the pres shell, and set ourselves up as a selection
|
|
|
|
// listener
|
2003-02-27 23:09:51 +00:00
|
|
|
|
2000-04-27 07:37:12 +00:00
|
|
|
nsCOMPtr<nsISelectionController> selCon = do_QueryReferent(mPresShell);
|
2003-02-27 23:09:51 +00:00
|
|
|
if (!selCon)
|
2000-04-27 07:37:12 +00:00
|
|
|
return NS_ERROR_FAILURE;
|
2003-02-27 23:09:51 +00:00
|
|
|
|
|
|
|
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);
|
2003-07-25 19:06:59 +00:00
|
|
|
mDomSelectionWeak = do_GetWeakReference(domSelection);
|
2000-09-07 05:26:25 +00:00
|
|
|
|
|
|
|
// set up the blink timer
|
|
|
|
if (mVisible)
|
|
|
|
{
|
2003-02-27 23:09:51 +00:00
|
|
|
rv = StartBlinking();
|
|
|
|
if (NS_FAILED(rv))
|
|
|
|
return rv;
|
2000-09-07 05:26:25 +00:00
|
|
|
}
|
2003-02-27 23:09:51 +00:00
|
|
|
|
2001-03-21 01:16:22 +00:00
|
|
|
#ifdef IBMBIDI
|
|
|
|
PRBool isRTL;
|
|
|
|
mBidiKeyboard = do_GetService("@mozilla.org/widget/bidikeyboard;1");
|
|
|
|
mBidiKeyboard->IsLangRTL(&isRTL);
|
|
|
|
mKeyboardRTL = isRTL;
|
|
|
|
#endif
|
2000-09-07 05:26:25 +00:00
|
|
|
|
|
|
|
return NS_OK;
|
1999-02-11 23:49:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
2003-02-27 23:09:51 +00:00
|
|
|
NS_IMETHODIMP nsCaret::Terminate()
|
1999-02-11 23:49:08 +00:00
|
|
|
{
|
2003-02-27 23:09:51 +00: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;
|
|
|
|
|
|
|
|
mRendContext = nsnull;
|
2000-09-14 11:45:01 +00:00
|
|
|
|
2003-02-27 23:09:51 +00:00
|
|
|
// 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;
|
2000-09-07 05:26:25 +00:00
|
|
|
|
2003-02-27 23:09:51 +00:00
|
|
|
mLastCaretFrame = nsnull;
|
|
|
|
mLastCaretView = nsnull;
|
|
|
|
|
|
|
|
#ifdef IBMBIDI
|
|
|
|
mBidiKeyboard = nsnull;
|
|
|
|
#endif
|
2000-09-07 05:26:25 +00:00
|
|
|
|
2003-02-27 23:09:51 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
2000-09-07 05:26:25 +00:00
|
|
|
|
|
|
|
|
2003-02-27 23:09:51 +00:00
|
|
|
//-----------------------------------------------------------------------------
|
2003-09-07 22:37:27 +00:00
|
|
|
NS_IMPL_ISUPPORTS2(nsCaret, nsICaret, nsISelectionListener)
|
1999-02-11 23:49:08 +00:00
|
|
|
|
2002-09-26 00:07:53 +00:00
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
NS_IMETHODIMP nsCaret::GetCaretDOMSelection(nsISelection **aDOMSel)
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsISelection> sel(do_QueryReferent(mDomSelectionWeak));
|
|
|
|
|
|
|
|
NS_IF_ADDREF(*aDOMSel = sel);
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
1999-02-11 23:49:08 +00:00
|
|
|
//-----------------------------------------------------------------------------
|
2000-09-14 11:45:01 +00:00
|
|
|
NS_IMETHODIMP nsCaret::SetCaretDOMSelection(nsISelection *aDOMSel)
|
1999-02-11 23:49:08 +00:00
|
|
|
{
|
2000-06-01 02:37:40 +00:00
|
|
|
NS_ENSURE_ARG_POINTER(aDOMSel);
|
2003-07-25 19:06:59 +00:00
|
|
|
mDomSelectionWeak = do_GetWeakReference(aDOMSel); // weak reference to pres shell
|
2000-06-01 02:37:40 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
NS_IMETHODIMP nsCaret::SetCaretVisible(PRBool inMakeVisible)
|
|
|
|
{
|
2000-09-07 05:26:25 +00:00
|
|
|
mVisible = inMakeVisible;
|
|
|
|
nsresult err = NS_OK;
|
|
|
|
if (mVisible)
|
|
|
|
err = StartBlinking();
|
|
|
|
else
|
|
|
|
err = StopBlinking();
|
|
|
|
|
|
|
|
return err;
|
1999-02-11 23:49:08 +00:00
|
|
|
}
|
|
|
|
|
2003-02-27 23:09:51 +00:00
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
2000-06-01 02:37:40 +00:00
|
|
|
NS_IMETHODIMP nsCaret::GetCaretVisible(PRBool *outMakeVisible)
|
|
|
|
{
|
|
|
|
NS_ENSURE_ARG_POINTER(outMakeVisible);
|
|
|
|
*outMakeVisible = mVisible;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
1999-02-11 23:49:08 +00:00
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
2000-06-01 02:37:40 +00:00
|
|
|
NS_IMETHODIMP nsCaret::SetCaretReadOnly(PRBool inMakeReadonly)
|
1999-02-11 23:49:08 +00:00
|
|
|
{
|
2000-09-07 05:26:25 +00:00
|
|
|
mReadOnly = inMakeReadonly;
|
|
|
|
return NS_OK;
|
1999-02-11 23:49:08 +00:00
|
|
|
}
|
|
|
|
|
1999-02-13 04:47:45 +00:00
|
|
|
|
1999-04-27 21:59:18 +00:00
|
|
|
//-----------------------------------------------------------------------------
|
2002-08-26 20:55:30 +00:00
|
|
|
NS_IMETHODIMP nsCaret::GetCaretCoordinates(EViewCoordinates aRelativeToType, nsISelection *aDOMSel, nsRect *outCoordinates, PRBool *outIsCollapsed, nsIView **outView)
|
1999-04-27 21:59:18 +00:00
|
|
|
{
|
2000-09-07 05:26:25 +00:00
|
|
|
if (!mPresShell)
|
|
|
|
return NS_ERROR_NOT_INITIALIZED;
|
2001-02-05 15:43:24 +00:00
|
|
|
if (!outCoordinates || !outIsCollapsed)
|
|
|
|
return NS_ERROR_NULL_POINTER;
|
2003-02-27 23:09:51 +00:00
|
|
|
|
|
|
|
nsCOMPtr<nsISelection> domSelection = aDOMSel;
|
|
|
|
nsCOMPtr<nsISelectionPrivate> privateSelection(do_QueryInterface(domSelection));
|
|
|
|
if (!privateSelection)
|
2000-09-07 05:26:25 +00:00
|
|
|
return NS_ERROR_NOT_INITIALIZED; // no selection
|
2001-02-05 15:43:24 +00:00
|
|
|
|
2002-08-26 20:55:30 +00:00
|
|
|
if (outView)
|
|
|
|
*outView = nsnull;
|
|
|
|
|
2000-09-07 05:26:25 +00:00
|
|
|
// fill in defaults for failure
|
2001-02-05 15:43:24 +00:00
|
|
|
outCoordinates->x = -1;
|
|
|
|
outCoordinates->y = -1;
|
|
|
|
outCoordinates->width = -1;
|
|
|
|
outCoordinates->height = -1;
|
|
|
|
*outIsCollapsed = PR_FALSE;
|
2000-09-07 05:26:25 +00:00
|
|
|
|
2003-02-27 23:09:51 +00:00
|
|
|
nsresult err = domSelection->GetIsCollapsed(outIsCollapsed);
|
2000-09-07 05:26:25 +00:00
|
|
|
if (NS_FAILED(err))
|
|
|
|
return err;
|
|
|
|
|
|
|
|
nsCOMPtr<nsIDOMNode> focusNode;
|
|
|
|
|
|
|
|
err = domSelection->GetFocusNode(getter_AddRefs(focusNode));
|
|
|
|
if (NS_FAILED(err))
|
|
|
|
return err;
|
|
|
|
if (!focusNode)
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
|
|
|
|
PRInt32 focusOffset;
|
|
|
|
err = domSelection->GetFocusOffset(&focusOffset);
|
|
|
|
if (NS_FAILED(err))
|
|
|
|
return err;
|
|
|
|
|
1999-11-23 20:30:21 +00:00
|
|
|
/*
|
2000-09-07 05:26:25 +00:00
|
|
|
// is this a text node?
|
|
|
|
nsCOMPtr<nsIDOMCharacterData> nodeAsText = do_QueryInterface(focusNode);
|
|
|
|
// note that we only work with text nodes here, unlike when drawing the caret.
|
|
|
|
// this is because this routine is intended for IME support, which only cares about text.
|
|
|
|
if (!nodeAsText)
|
|
|
|
return NS_ERROR_UNEXPECTED;
|
|
|
|
*/
|
|
|
|
nsCOMPtr<nsIContent>contentNode = do_QueryInterface(focusNode);
|
|
|
|
if (!contentNode)
|
|
|
|
return NS_ERROR_FAILURE;
|
1999-05-18 22:24:55 +00:00
|
|
|
|
2000-09-07 05:26:25 +00:00
|
|
|
// find the frame that contains the content node that has focus
|
|
|
|
nsIFrame* theFrame = nsnull;
|
|
|
|
PRInt32 theFrameOffset = 0;
|
2000-06-28 04:00:12 +00:00
|
|
|
PRBool hintRight;
|
2000-09-14 11:45:01 +00:00
|
|
|
privateSelection->GetInterlinePosition(&hintRight);//translate hint.
|
2000-06-28 04:00:12 +00:00
|
|
|
nsIFrameSelection::HINT hint;
|
|
|
|
if (hintRight)
|
|
|
|
hint = nsIFrameSelection::HINTRIGHT;
|
|
|
|
else
|
|
|
|
hint = nsIFrameSelection::HINTLEFT;
|
2004-08-29 03:08:44 +00:00
|
|
|
|
|
|
|
nsCOMPtr<nsIPresShell> presShell = do_QueryReferent(mPresShell);
|
|
|
|
err = presShell->FrameSelection()->GetFrameForNodeOffset(contentNode,
|
|
|
|
focusOffset, hint,
|
|
|
|
&theFrame,
|
|
|
|
&theFrameOffset);
|
2000-09-07 05:26:25 +00:00
|
|
|
if (NS_FAILED(err) || !theFrame)
|
|
|
|
return err;
|
|
|
|
|
|
|
|
nsPoint viewOffset(0, 0);
|
|
|
|
nsRect clipRect;
|
|
|
|
nsIView *drawingView; // views are not refcounted
|
2001-04-19 22:46:29 +00:00
|
|
|
|
2002-08-26 20:55:30 +00:00
|
|
|
GetViewForRendering(theFrame, aRelativeToType, viewOffset, clipRect, &drawingView, outView);
|
2000-09-07 05:26:25 +00:00
|
|
|
if (!drawingView)
|
|
|
|
return NS_ERROR_UNEXPECTED;
|
|
|
|
// ramp up to make a rendering context for measuring text.
|
|
|
|
// First, we get the pres context ...
|
2004-08-20 20:34:37 +00:00
|
|
|
nsPresContext *presContext = presShell->GetPresContext();
|
|
|
|
|
2000-09-07 05:26:25 +00:00
|
|
|
// ... then tell it to make a rendering context
|
|
|
|
nsCOMPtr<nsIRenderingContext> rendContext;
|
2004-02-02 22:17:21 +00:00
|
|
|
err = presContext->DeviceContext()->
|
|
|
|
CreateRenderingContext(drawingView, *getter_AddRefs(rendContext));
|
2000-09-07 05:26:25 +00:00
|
|
|
if (NS_FAILED(err))
|
|
|
|
return err;
|
|
|
|
if (!rendContext)
|
|
|
|
return NS_ERROR_UNEXPECTED;
|
|
|
|
|
|
|
|
// now we can measure the offset into the frame.
|
|
|
|
nsPoint framePos(0, 0);
|
|
|
|
theFrame->GetPointFromOffset(presContext, rendContext, theFrameOffset, &framePos);
|
|
|
|
|
2001-02-05 15:43:24 +00:00
|
|
|
// we don't need drawingView anymore so reuse that; reset viewOffset values for our purposes
|
|
|
|
if (aRelativeToType == eClosestViewCoordinates)
|
2002-08-26 20:55:30 +00:00
|
|
|
{
|
2001-02-05 15:43:24 +00:00
|
|
|
theFrame->GetOffsetFromView(presContext, viewOffset, &drawingView);
|
2002-08-26 20:55:30 +00:00
|
|
|
if (outView)
|
|
|
|
*outView = drawingView;
|
|
|
|
}
|
2000-09-07 05:26:25 +00:00
|
|
|
// now add the frame offset to the view offset, and we're done
|
|
|
|
viewOffset += framePos;
|
2001-02-05 15:43:24 +00:00
|
|
|
outCoordinates->x = viewOffset.x;
|
|
|
|
outCoordinates->y = viewOffset.y;
|
2003-07-02 10:30:00 +00:00
|
|
|
outCoordinates->height = theFrame->GetSize().height;
|
2002-06-25 22:54:23 +00:00
|
|
|
outCoordinates->width = mCaretTwipsWidth;
|
2000-09-07 05:26:25 +00:00
|
|
|
|
|
|
|
return NS_OK;
|
1999-04-27 21:59:18 +00:00
|
|
|
}
|
|
|
|
|
1999-04-01 23:57:35 +00:00
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
NS_IMETHODIMP nsCaret::ClearFrameRefs(nsIFrame* aFrame)
|
|
|
|
{
|
2004-06-25 09:57:35 +00:00
|
|
|
EraseCaret(); // make sure that the caret is erased completely
|
|
|
|
|
2000-09-07 05:26:25 +00:00
|
|
|
if (mLastCaretFrame == aFrame)
|
|
|
|
{
|
|
|
|
mLastCaretFrame = nsnull; // frames are not refcounted.
|
2000-09-07 20:21:22 +00:00
|
|
|
mLastCaretView = nsnull;
|
2000-09-07 05:26:25 +00:00
|
|
|
mLastContentOffset = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
mDrawn = PR_FALSE; // assume that the view has been cleared, and ensure
|
|
|
|
// that we don't try to use the frame.
|
|
|
|
return NS_OK;
|
1999-04-01 23:57:35 +00:00
|
|
|
}
|
|
|
|
|
2000-06-09 04:22:20 +00:00
|
|
|
NS_IMETHODIMP nsCaret::EraseCaret()
|
|
|
|
{
|
|
|
|
if (mDrawn)
|
|
|
|
DrawCaret();
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2003-02-27 23:09:51 +00:00
|
|
|
NS_IMETHODIMP nsCaret::SetVisibilityDuringSelection(PRBool aVisibility)
|
|
|
|
{
|
|
|
|
mShowDuringSelection = aVisibility;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP nsCaret::DrawAtPosition(nsIDOMNode* aNode, PRInt32 aOffset)
|
|
|
|
{
|
|
|
|
NS_ENSURE_ARG(aNode);
|
|
|
|
|
|
|
|
// XXX we need to do more work here to get the correct hint.
|
|
|
|
if (!SetupDrawingFrameAndOffset(aNode, aOffset, nsIFrameSelection::HINTLEFT))
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
|
|
|
|
GetCaretRectAndInvert();
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
1999-04-01 23:57:35 +00:00
|
|
|
|
1999-03-02 04:26:49 +00:00
|
|
|
#ifdef XP_MAC
|
1999-02-11 23:49:08 +00:00
|
|
|
#pragma mark -
|
1999-03-02 04:26:49 +00:00
|
|
|
#endif
|
1999-02-11 23:49:08 +00:00
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
2000-09-14 11:45:01 +00:00
|
|
|
NS_IMETHODIMP nsCaret::NotifySelectionChanged(nsIDOMDocument *, nsISelection *aDomSel, short aReason)
|
1999-02-11 23:49:08 +00:00
|
|
|
{
|
2000-09-14 11:45:01 +00:00
|
|
|
if (aReason & nsISelectionListener::MOUSEUP_REASON)//this wont do
|
2000-06-09 04:22:20 +00:00
|
|
|
return NS_OK;
|
2002-04-26 13:11:47 +00:00
|
|
|
|
2000-09-14 11:45:01 +00:00
|
|
|
nsCOMPtr<nsISelection> domSel(do_QueryReferent(mDomSelectionWeak));
|
2002-04-26 13:11:47 +00:00
|
|
|
|
|
|
|
// 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;
|
|
|
|
|
2000-09-07 05:26:25 +00:00
|
|
|
if (mVisible)
|
2002-04-26 13:11:47 +00:00
|
|
|
{
|
|
|
|
// Stop the caret from blinking in its previous location.
|
|
|
|
StopBlinking();
|
|
|
|
|
|
|
|
// Start the caret blinking in the new location.
|
2000-09-07 05:26:25 +00:00
|
|
|
StartBlinking();
|
2002-04-26 13:11:47 +00:00
|
|
|
}
|
|
|
|
|
2000-09-07 05:26:25 +00:00
|
|
|
return NS_OK;
|
1999-02-11 23:49:08 +00:00
|
|
|
}
|
|
|
|
|
1999-03-02 04:26:49 +00:00
|
|
|
#ifdef XP_MAC
|
1999-02-11 23:49:08 +00:00
|
|
|
#pragma mark -
|
1999-03-02 04:26:49 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
void nsCaret::KillTimer()
|
|
|
|
{
|
2000-09-07 05:26:25 +00:00
|
|
|
if (mBlinkTimer)
|
|
|
|
{
|
|
|
|
mBlinkTimer->Cancel();
|
|
|
|
}
|
1999-03-02 04:26:49 +00:00
|
|
|
}
|
1999-02-11 23:49:08 +00:00
|
|
|
|
1999-02-17 02:08:01 +00:00
|
|
|
|
1999-02-11 23:49:08 +00:00
|
|
|
//-----------------------------------------------------------------------------
|
1999-02-17 02:08:01 +00:00
|
|
|
nsresult nsCaret::PrimeTimer()
|
1999-02-11 23:49:08 +00:00
|
|
|
{
|
2000-09-07 05:26:25 +00:00
|
|
|
// set up the blink timer
|
|
|
|
if (!mReadOnly && mBlinkRate > 0)
|
|
|
|
{
|
2003-05-26 07:03:29 +00:00
|
|
|
if (!mBlinkTimer) {
|
|
|
|
nsresult err;
|
|
|
|
mBlinkTimer = do_CreateInstance("@mozilla.org/timer;1", &err);
|
|
|
|
if (NS_FAILED(err))
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
2002-09-07 05:38:16 +00:00
|
|
|
mBlinkTimer->InitWithFuncCallback(CaretBlinkCallback, this, mBlinkRate,
|
2003-05-26 07:03:29 +00:00
|
|
|
nsITimer::TYPE_REPEATING_SLACK);
|
2000-09-07 05:26:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
1999-02-17 02:08:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
nsresult nsCaret::StartBlinking()
|
|
|
|
{
|
2000-09-07 05:26:25 +00:00
|
|
|
PrimeTimer();
|
1999-03-03 01:11:28 +00:00
|
|
|
|
2000-09-07 05:26:25 +00:00
|
|
|
//NS_ASSERTION(!mDrawn, "Caret should not be drawn here");
|
|
|
|
DrawCaret(); // draw it right away
|
|
|
|
|
|
|
|
return NS_OK;
|
1999-02-11 23:49:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
nsresult nsCaret::StopBlinking()
|
|
|
|
{
|
2000-09-07 05:26:25 +00:00
|
|
|
if (mDrawn) // erase the caret if necessary
|
|
|
|
DrawCaret();
|
|
|
|
|
|
|
|
KillTimer();
|
|
|
|
|
|
|
|
return NS_OK;
|
1999-02-11 23:49:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
1999-04-01 23:57:35 +00:00
|
|
|
// Get the nsIFrame and the content offset for the current caret position.
|
1999-04-27 21:59:18 +00:00
|
|
|
// Returns PR_TRUE if we should go ahead and draw, PR_FALSE otherwise.
|
1999-04-01 23:57:35 +00:00
|
|
|
//
|
2003-02-27 23:09:51 +00:00
|
|
|
PRBool nsCaret::SetupDrawingFrameAndOffset(nsIDOMNode* aNode, PRInt32 aOffset, nsIFrameSelection::HINT aFrameHint)
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsIContent> contentNode = do_QueryInterface(aNode);
|
2000-09-07 20:21:22 +00:00
|
|
|
if (!contentNode) return PR_FALSE;
|
|
|
|
|
|
|
|
//get frame selection and find out what frame to use...
|
|
|
|
nsCOMPtr<nsIPresShell> presShell = do_QueryReferent(mPresShell);
|
|
|
|
if (!presShell)
|
|
|
|
return PR_FALSE;
|
2000-09-07 05:26:25 +00:00
|
|
|
|
2004-08-29 03:08:44 +00:00
|
|
|
nsIFrameSelection *frameSelection = presShell->FrameSelection();
|
2000-09-07 20:21:22 +00:00
|
|
|
nsIFrame* theFrame = nsnull;
|
|
|
|
PRInt32 theFrameOffset = 0;
|
|
|
|
|
2003-02-27 23:09:51 +00:00
|
|
|
nsresult rv = frameSelection->GetFrameForNodeOffset(contentNode, aOffset, aFrameHint, &theFrame, &theFrameOffset);
|
2000-09-07 20:21:22 +00:00
|
|
|
if (NS_FAILED(rv) || !theFrame)
|
|
|
|
return PR_FALSE;
|
|
|
|
|
2001-03-21 01:16:22 +00:00
|
|
|
#ifdef IBMBIDI
|
|
|
|
PRUint8 bidiLevel=0;
|
|
|
|
// Mamdouh : modification of the caret to work at rtl and ltr with Bidi
|
|
|
|
//
|
|
|
|
// Direction Style from this->GetStyleData()
|
2001-05-31 22:19:43 +00:00
|
|
|
// now in (visibility->mDirection)
|
2001-03-21 01:16:22 +00:00
|
|
|
// ------------------
|
|
|
|
// NS_STYLE_DIRECTION_LTR : LTR or Default
|
|
|
|
// NS_STYLE_DIRECTION_RTL
|
|
|
|
// NS_STYLE_DIRECTION_INHERIT
|
2004-08-20 20:34:37 +00:00
|
|
|
nsPresContext *presContext = presShell->GetPresContext();
|
2004-04-13 00:28:44 +00:00
|
|
|
if (presContext && presContext->BidiEnabled())
|
2001-03-21 01:16:22 +00:00
|
|
|
{
|
2001-09-30 20:35:55 +00:00
|
|
|
presShell->GetCaretBidiLevel(&bidiLevel);
|
2001-03-21 01:16:22 +00:00
|
|
|
if (bidiLevel & BIDI_LEVEL_UNDEFINED)
|
|
|
|
{
|
|
|
|
PRUint8 newBidiLevel;
|
|
|
|
bidiLevel &= ~BIDI_LEVEL_UNDEFINED;
|
|
|
|
// There has been a reflow, so we reset the cursor Bidi level to the level of the current frame
|
|
|
|
if (!presContext) // Use the style default or default to 0
|
2003-05-15 03:42:21 +00:00
|
|
|
{
|
|
|
|
newBidiLevel = theFrame->GetStyleVisibility()->mDirection;
|
|
|
|
}
|
2001-03-21 01:16:22 +00:00
|
|
|
else
|
|
|
|
{
|
2004-06-01 06:20:16 +00:00
|
|
|
newBidiLevel = NS_GET_EMBEDDING_LEVEL(theFrame);
|
2001-09-30 20:35:55 +00:00
|
|
|
presShell->SetCaretBidiLevel(newBidiLevel);
|
2001-03-21 01:16:22 +00:00
|
|
|
bidiLevel = newBidiLevel;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
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)
|
|
|
|
{
|
|
|
|
/* Boundary condition, we need to know the Bidi levels of the characters before and after the cursor */
|
2003-02-27 23:09:51 +00:00
|
|
|
if (NS_SUCCEEDED(frameSelection->GetPrevNextBidiLevels(presContext, contentNode, aOffset,
|
2001-03-21 01:16:22 +00:00
|
|
|
&frameBefore, &frameAfter,
|
|
|
|
&levelBefore, &levelAfter)))
|
|
|
|
{
|
|
|
|
if ((levelBefore != levelAfter) || (bidiLevel != levelBefore))
|
|
|
|
{
|
|
|
|
bidiLevel = PR_MAX(bidiLevel, PR_MIN(levelBefore, levelAfter)); // rule c3
|
|
|
|
bidiLevel = PR_MIN(bidiLevel, PR_MAX(levelBefore, levelAfter)); // rule c4
|
|
|
|
if (bidiLevel == levelBefore // rule c1
|
|
|
|
|| bidiLevel > levelBefore && bidiLevel < levelAfter && !((bidiLevel ^ levelBefore) & 1) // rule c5
|
|
|
|
|| bidiLevel < levelBefore && bidiLevel > levelAfter && !((bidiLevel ^ levelBefore) & 1)) // rule c9
|
|
|
|
{
|
|
|
|
if (theFrame != frameBefore)
|
|
|
|
{
|
|
|
|
if (frameBefore) // if there is a frameBefore, move into it, setting HINTLEFT to make sure we stay there
|
|
|
|
{
|
|
|
|
theFrame = frameBefore;
|
|
|
|
theFrame->GetOffsets(start, end);
|
|
|
|
theFrameOffset = end;
|
|
|
|
// frameSelection->SetHint(nsIFrameSelection::HINTLEFT);
|
|
|
|
}
|
|
|
|
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 first frame whose level is the same as the
|
|
|
|
// paragraph level, and put the caret at the end of the frame before that.
|
2004-06-01 06:20:16 +00:00
|
|
|
PRUint8 baseLevel = NS_GET_BASE_LEVEL(frameAfter);
|
2001-03-21 01:16:22 +00:00
|
|
|
if (baseLevel != levelAfter)
|
|
|
|
{
|
|
|
|
if (NS_SUCCEEDED(frameSelection->GetFrameFromLevel(presContext, frameAfter, eDirNext, baseLevel, &theFrame)))
|
|
|
|
{
|
|
|
|
theFrame->GetOffsets(start, end);
|
2004-06-01 06:20:16 +00:00
|
|
|
levelAfter = NS_GET_EMBEDDING_LEVEL(theFrame);
|
2001-03-21 01:16:22 +00:00
|
|
|
if (baseLevel & 1) // RTL paragraph: caret to the right of the rightmost character
|
|
|
|
theFrameOffset = (levelAfter & 1) ? start : end;
|
|
|
|
else // LTR paragraph: caret to the left of the leftmost character
|
|
|
|
theFrameOffset = (levelAfter & 1) ? end : start;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (bidiLevel == levelAfter // rule c2
|
|
|
|
|| bidiLevel > levelBefore && bidiLevel < levelAfter && !((bidiLevel ^ levelAfter) & 1) // rule c6
|
|
|
|
|| bidiLevel < levelBefore && bidiLevel > levelAfter && !((bidiLevel ^ levelAfter) & 1)) // rule c10
|
|
|
|
{
|
|
|
|
if (theFrame != frameAfter)
|
|
|
|
{
|
|
|
|
if (frameAfter)
|
|
|
|
{
|
|
|
|
// if there is a frameAfter, move into it, setting HINTRIGHT to make sure we stay there
|
|
|
|
theFrame = frameAfter;
|
|
|
|
theFrame->GetOffsets(start, end);
|
|
|
|
theFrameOffset = start;
|
|
|
|
// frameSelection->SetHint(nsIFrameSelection::HINTRIGHT);
|
|
|
|
}
|
|
|
|
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 last frame whose level is the same as the
|
|
|
|
// paragraph level, and put the caret at the end of the frame after that.
|
2004-06-01 06:20:16 +00:00
|
|
|
|
|
|
|
PRUint8 baseLevel = NS_GET_BASE_LEVEL(frameBefore);
|
2001-03-21 01:16:22 +00:00
|
|
|
if (baseLevel != levelBefore)
|
|
|
|
{
|
|
|
|
if (NS_SUCCEEDED(frameSelection->GetFrameFromLevel(presContext, frameBefore, eDirPrevious, baseLevel, &theFrame)))
|
|
|
|
{
|
|
|
|
theFrame->GetOffsets(start, end);
|
2004-06-01 06:20:16 +00:00
|
|
|
levelBefore = NS_GET_EMBEDDING_LEVEL(theFrame);
|
2001-03-21 01:16:22 +00:00
|
|
|
if (baseLevel & 1) // RTL paragraph: caret to the left of the leftmost character
|
|
|
|
theFrameOffset = (levelBefore & 1) ? end : start;
|
|
|
|
else // RTL paragraph: caret to the right of the rightmost character
|
|
|
|
theFrameOffset = (levelBefore & 1) ? start : end;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (bidiLevel > levelBefore && bidiLevel < levelAfter // rule c7/8
|
|
|
|
&& !((levelBefore ^ levelAfter) & 1) // before and after have the same parity
|
|
|
|
&& ((bidiLevel ^ levelAfter) & 1)) // cursor has different parity
|
|
|
|
{
|
|
|
|
if (NS_SUCCEEDED(frameSelection->GetFrameFromLevel(presContext, frameAfter, eDirNext, bidiLevel, &theFrame)))
|
|
|
|
{
|
|
|
|
theFrame->GetOffsets(start, end);
|
2004-06-01 06:20:16 +00:00
|
|
|
levelAfter = NS_GET_EMBEDDING_LEVEL(theFrame);
|
2001-03-21 01:16:22 +00:00
|
|
|
if (bidiLevel & 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 (bidiLevel < levelBefore && bidiLevel > levelAfter // rule c11/12
|
|
|
|
&& !((levelBefore ^ levelAfter) & 1) // before and after have the same parity
|
|
|
|
&& ((bidiLevel ^ levelAfter) & 1)) // cursor has different parity
|
|
|
|
{
|
|
|
|
if (NS_SUCCEEDED(frameSelection->GetFrameFromLevel(presContext, frameBefore, eDirPrevious, bidiLevel, &theFrame)))
|
|
|
|
{
|
|
|
|
theFrame->GetOffsets(start, end);
|
2004-06-01 06:20:16 +00:00
|
|
|
levelBefore = NS_GET_EMBEDDING_LEVEL(theFrame);
|
2001-03-21 01:16:22 +00:00
|
|
|
if (bidiLevel & 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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif // IBMBIDI
|
2001-07-19 06:56:46 +00:00
|
|
|
|
|
|
|
// now we have a frame, check whether it's appropriate to show the caret here
|
2003-05-15 03:42:21 +00:00
|
|
|
const nsStyleUserInterface* userinterface = theFrame->GetStyleUserInterface();
|
|
|
|
if (
|
2001-07-19 06:56:46 +00:00
|
|
|
#ifdef SUPPORT_USER_MODIFY
|
2003-05-15 03:42:21 +00:00
|
|
|
// editable content still defaults to NS_STYLE_USER_MODIFY_READ_ONLY at present. See bug 15284
|
|
|
|
(userinterface->mUserModify == NS_STYLE_USER_MODIFY_READ_ONLY) ||
|
2001-07-19 06:56:46 +00:00
|
|
|
#endif
|
2003-05-15 03:42:21 +00:00
|
|
|
(userinterface->mUserInput == NS_STYLE_USER_INPUT_NONE) ||
|
|
|
|
(userinterface->mUserInput == NS_STYLE_USER_INPUT_DISABLED))
|
|
|
|
{
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
2001-07-19 06:56:46 +00:00
|
|
|
|
|
|
|
// mark the frame, so we get notified on deletion.
|
|
|
|
// frames are never unmarked, which means that we'll touch every frame we visit.
|
|
|
|
// this is not ideal.
|
2003-07-02 10:30:00 +00:00
|
|
|
theFrame->AddStateBits(NS_FRAME_EXTERNAL_REFERENCE);
|
2001-07-19 06:56:46 +00:00
|
|
|
|
2000-09-07 20:21:22 +00:00
|
|
|
mLastCaretFrame = theFrame;
|
|
|
|
mLastContentOffset = theFrameOffset;
|
|
|
|
return PR_TRUE;
|
1999-02-11 23:49:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
1999-04-01 23:57:35 +00:00
|
|
|
//-----------------------------------------------------------------------------
|
2002-08-26 20:55:30 +00:00
|
|
|
void nsCaret::GetViewForRendering(nsIFrame *caretFrame, EViewCoordinates coordType, nsPoint &viewOffset, nsRect& outClipRect, nsIView **outRenderingView, nsIView **outRelativeView)
|
1999-04-01 23:57:35 +00:00
|
|
|
{
|
2002-08-26 20:55:30 +00:00
|
|
|
|
|
|
|
if (!caretFrame || !outRenderingView)
|
2000-09-07 05:26:25 +00:00
|
|
|
return;
|
2002-08-26 20:55:30 +00:00
|
|
|
|
|
|
|
//#59405, on windows and unix, the coordinate for IME need to be view (nearest native window) related.
|
|
|
|
if (coordType == eIMECoordinates)
|
|
|
|
#if defined(XP_MAC) || defined(XP_MACOSX)
|
|
|
|
coordType = eTopLevelWindowCoordinates;
|
|
|
|
#else
|
|
|
|
coordType = eRenderingViewCoordinates;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
*outRenderingView = nsnull;
|
|
|
|
if (outRelativeView)
|
|
|
|
*outRelativeView = nsnull;
|
|
|
|
|
2000-09-07 05:26:25 +00:00
|
|
|
NS_ASSERTION(caretFrame, "Should have frame here");
|
2000-04-27 07:37:12 +00:00
|
|
|
nsCOMPtr<nsIPresShell> presShell = do_QueryReferent(mPresShell);
|
2000-09-07 05:26:25 +00:00
|
|
|
if (!presShell)
|
2000-04-27 07:37:12 +00:00
|
|
|
return;
|
2000-09-07 05:26:25 +00:00
|
|
|
|
|
|
|
viewOffset.x = 0;
|
|
|
|
viewOffset.y = 0;
|
2000-09-07 20:21:22 +00:00
|
|
|
|
|
|
|
nsPoint withinViewOffset(0, 0);
|
2000-09-07 05:26:25 +00:00
|
|
|
// get the offset of this frame from its parent view (walks up frame hierarchy)
|
|
|
|
nsIView* theView = nsnull;
|
2004-08-20 20:34:37 +00:00
|
|
|
caretFrame->GetOffsetFromView(presShell->GetPresContext(),
|
|
|
|
withinViewOffset, &theView);
|
2000-09-07 05:26:25 +00:00
|
|
|
if (theView == nsnull) return;
|
2002-08-26 20:55:30 +00:00
|
|
|
|
|
|
|
if (outRelativeView && coordType == eClosestViewCoordinates)
|
|
|
|
*outRelativeView = theView;
|
|
|
|
|
2000-09-07 05:26:25 +00:00
|
|
|
nsIView* returnView = nsnull; // views are not refcounted
|
|
|
|
|
|
|
|
// coorinates relative to the view we are going to use for drawing
|
2001-02-05 15:43:24 +00:00
|
|
|
if (coordType == eRenderingViewCoordinates)
|
2000-09-07 05:26:25 +00:00
|
|
|
{
|
|
|
|
nsIScrollableView* scrollableView = nsnull;
|
|
|
|
|
2000-09-07 20:21:22 +00:00
|
|
|
nsPoint drawViewOffset(0, 0); // offset to the view we are using to draw
|
|
|
|
|
2000-09-07 05:26:25 +00:00
|
|
|
// walk up to the first view with a widget
|
|
|
|
do {
|
|
|
|
//is this a scrollable view?
|
|
|
|
if (!scrollableView)
|
|
|
|
theView->QueryInterface(NS_GET_IID(nsIScrollableView), (void **)&scrollableView);
|
|
|
|
|
2003-07-02 10:30:00 +00:00
|
|
|
if (theView->HasWidget())
|
2000-09-07 05:26:25 +00:00
|
|
|
{
|
|
|
|
returnView = theView;
|
|
|
|
break;
|
|
|
|
}
|
2003-07-02 10:30:00 +00:00
|
|
|
drawViewOffset += theView->GetPosition();
|
|
|
|
theView = theView->GetParent();
|
2000-09-07 05:26:25 +00:00
|
|
|
} while (theView);
|
2000-09-07 20:21:22 +00:00
|
|
|
|
|
|
|
viewOffset = withinViewOffset;
|
|
|
|
viewOffset += drawViewOffset;
|
|
|
|
|
2000-09-07 05:26:25 +00:00
|
|
|
if (scrollableView)
|
|
|
|
{
|
2004-09-20 22:25:07 +00:00
|
|
|
nsRect bounds = scrollableView->View()->GetBounds();
|
2000-09-07 05:26:25 +00:00
|
|
|
scrollableView->GetScrollPosition(bounds.x, bounds.y);
|
|
|
|
|
2000-09-07 20:21:22 +00:00
|
|
|
bounds += drawViewOffset; // offset to coords of returned view
|
2000-09-07 05:26:25 +00:00
|
|
|
outClipRect = bounds;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2004-05-29 19:57:00 +00:00
|
|
|
NS_ASSERTION(returnView, "bulletproofing, see bug #24329");
|
|
|
|
if (returnView)
|
|
|
|
outClipRect = returnView->GetBounds();
|
2000-09-07 05:26:25 +00:00
|
|
|
}
|
2002-08-26 20:55:30 +00:00
|
|
|
|
|
|
|
if (outRelativeView)
|
|
|
|
*outRelativeView = returnView;
|
2000-09-07 05:26:25 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// window-relative coordinates (walk right to the top of the view hierarchy)
|
|
|
|
// we don't do anything with clipping here
|
2000-09-19 21:55:59 +00:00
|
|
|
viewOffset = withinViewOffset;
|
|
|
|
|
2000-09-07 05:26:25 +00:00
|
|
|
do {
|
2003-07-02 10:30:00 +00:00
|
|
|
if (!returnView && theView->HasWidget())
|
|
|
|
returnView = theView;
|
2000-09-07 05:26:25 +00:00
|
|
|
// is this right?
|
2003-07-02 10:30:00 +00:00
|
|
|
viewOffset += theView->GetPosition();
|
2000-09-07 05:26:25 +00:00
|
|
|
|
2002-08-26 20:55:30 +00:00
|
|
|
if (outRelativeView && coordType == eTopLevelWindowCoordinates)
|
|
|
|
*outRelativeView = theView;
|
|
|
|
|
2003-07-02 10:30:00 +00:00
|
|
|
theView = theView->GetParent();
|
2000-09-07 05:26:25 +00:00
|
|
|
} while (theView);
|
|
|
|
}
|
|
|
|
|
2002-08-26 20:55:30 +00:00
|
|
|
*outRenderingView = returnView;
|
1999-04-01 23:57:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
1999-09-14 23:41:19 +00:00
|
|
|
/*-----------------------------------------------------------------------------
|
|
|
|
|
2000-09-07 05:26:25 +00:00
|
|
|
MustDrawCaret
|
|
|
|
|
|
|
|
FInd out if we need to do any caret drawing. This returns true if
|
|
|
|
either a) or b)
|
|
|
|
a) caret has been drawn, and we need to erase it.
|
|
|
|
b) caret is not drawn, and selection is collapsed
|
|
|
|
|
1999-09-14 23:41:19 +00:00
|
|
|
----------------------------------------------------------------------------- */
|
|
|
|
PRBool nsCaret::MustDrawCaret()
|
|
|
|
{
|
2001-04-25 19:52:49 +00:00
|
|
|
nsCOMPtr<nsIPresShell> presShell = do_QueryReferent(mPresShell);
|
|
|
|
if (presShell) {
|
|
|
|
PRBool isPaintingSuppressed;
|
|
|
|
presShell->IsPaintingSuppressed(&isPaintingSuppressed);
|
|
|
|
if (isPaintingSuppressed)
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
|
2003-02-27 23:09:51 +00:00
|
|
|
if (mDrawn)
|
|
|
|
return PR_TRUE;
|
|
|
|
|
|
|
|
nsCOMPtr<nsISelection> domSelection = do_QueryReferent(mDomSelectionWeak);
|
2000-06-07 01:18:41 +00:00
|
|
|
if (!domSelection)
|
|
|
|
return PR_FALSE;
|
2000-09-07 05:26:25 +00:00
|
|
|
PRBool isCollapsed;
|
1999-09-14 23:41:19 +00:00
|
|
|
|
2000-09-07 05:26:25 +00:00
|
|
|
if (NS_FAILED(domSelection->GetIsCollapsed(&isCollapsed)))
|
|
|
|
return PR_FALSE;
|
2000-12-28 03:27:23 +00:00
|
|
|
|
2001-04-05 19:53:13 +00:00
|
|
|
if (mShowDuringSelection)
|
2000-12-28 03:27:23 +00:00
|
|
|
return PR_TRUE; // show the caret even in selections
|
|
|
|
|
2000-09-07 05:26:25 +00:00
|
|
|
return isCollapsed;
|
1999-09-14 23:41:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*-----------------------------------------------------------------------------
|
|
|
|
|
2000-09-07 20:21:22 +00:00
|
|
|
DrawCaret
|
|
|
|
|
1999-09-14 23:41:19 +00:00
|
|
|
----------------------------------------------------------------------------- */
|
|
|
|
|
2000-09-07 20:21:22 +00:00
|
|
|
void nsCaret::DrawCaret()
|
1999-04-01 23:57:35 +00:00
|
|
|
{
|
2000-09-07 20:21:22 +00:00
|
|
|
// do we need to draw the caret at all?
|
|
|
|
if (!MustDrawCaret())
|
|
|
|
return;
|
|
|
|
|
|
|
|
// if we are drawing, not erasing, then set up the frame etc.
|
|
|
|
if (!mDrawn)
|
|
|
|
{
|
2003-02-27 23:09:51 +00:00
|
|
|
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.
|
|
|
|
nsIFrameSelection::HINT hint = (hintRight) ? nsIFrameSelection::HINTRIGHT : nsIFrameSelection::HINTLEFT;
|
|
|
|
|
|
|
|
// get the node and offset, which is where we want the caret to draw
|
|
|
|
nsCOMPtr<nsIDOMNode> focusNode;
|
|
|
|
domSelection->GetFocusNode(getter_AddRefs(focusNode));
|
|
|
|
if (!focusNode)
|
|
|
|
return;
|
|
|
|
|
|
|
|
PRInt32 contentOffset;
|
|
|
|
if (NS_FAILED(domSelection->GetFocusOffset(&contentOffset)))
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (!SetupDrawingFrameAndOffset(focusNode, contentOffset, hint))
|
2000-09-07 20:21:22 +00:00
|
|
|
return;
|
|
|
|
}
|
2003-02-27 23:09:51 +00:00
|
|
|
|
|
|
|
GetCaretRectAndInvert();
|
|
|
|
}
|
|
|
|
|
|
|
|
void nsCaret::GetCaretRectAndInvert()
|
|
|
|
{
|
2000-09-07 05:26:25 +00:00
|
|
|
NS_ASSERTION(mLastCaretFrame != nsnull, "Should have a frame here");
|
|
|
|
|
2003-07-02 10:30:00 +00:00
|
|
|
nsRect frameRect = mLastCaretFrame->GetRect();
|
2001-04-13 00:17:21 +00:00
|
|
|
|
2000-09-07 05:26:25 +00:00
|
|
|
frameRect.x = 0; // the origin is accounted for in GetViewForRendering()
|
|
|
|
frameRect.y = 0;
|
|
|
|
|
|
|
|
nsPoint viewOffset(0, 0);
|
|
|
|
nsRect clipRect;
|
|
|
|
nsIView *drawingView;
|
2002-08-26 20:55:30 +00:00
|
|
|
GetViewForRendering(mLastCaretFrame, eRenderingViewCoordinates, viewOffset, clipRect, &drawingView, nsnull);
|
2002-04-12 02:05:12 +00:00
|
|
|
|
2003-07-02 10:30:00 +00:00
|
|
|
if (!drawingView)
|
2000-09-07 05:26:25 +00:00
|
|
|
return;
|
|
|
|
|
|
|
|
frameRect += viewOffset;
|
|
|
|
|
2000-04-27 07:37:12 +00:00
|
|
|
nsCOMPtr<nsIPresShell> presShell = do_QueryReferent(mPresShell);
|
2000-09-07 20:21:22 +00:00
|
|
|
if (!presShell) return;
|
|
|
|
|
2004-08-20 20:34:37 +00:00
|
|
|
nsPresContext *presContext = presShell->GetPresContext();
|
1999-09-14 23:41:19 +00:00
|
|
|
|
2000-09-07 20:21:22 +00:00
|
|
|
// if the view changed, or we don't have a rendering context, make one
|
2003-02-27 23:09:51 +00:00
|
|
|
// because of drawing issues, always make a new RC at the moment. See bug 28068
|
2000-09-07 20:21:22 +00:00
|
|
|
if (
|
|
|
|
#ifdef DONT_REUSE_RENDERING_CONTEXT
|
|
|
|
PR_TRUE ||
|
|
|
|
#endif
|
|
|
|
(mLastCaretView != drawingView) || !mRendContext)
|
2000-09-07 05:26:25 +00:00
|
|
|
{
|
2000-09-07 20:21:22 +00:00
|
|
|
mRendContext = nsnull; // free existing one if we have one
|
|
|
|
|
2004-02-02 22:17:21 +00:00
|
|
|
nsresult rv = presContext->DeviceContext()->
|
|
|
|
CreateRenderingContext(drawingView, *getter_AddRefs(mRendContext));
|
|
|
|
|
|
|
|
if (NS_FAILED(rv) || !mRendContext)
|
2000-09-07 20:21:22 +00:00
|
|
|
return;
|
2000-09-07 05:26:25 +00:00
|
|
|
}
|
2000-09-07 20:21:22 +00:00
|
|
|
|
|
|
|
// push a known good state
|
|
|
|
mRendContext->PushState();
|
|
|
|
|
2001-04-13 00:17:21 +00:00
|
|
|
// if we got a zero-height frame, it's probably a BR frame at the end of a non-empty line
|
|
|
|
// (see BRFrame::Reflow). In that case, figure out a height. We have to do this
|
|
|
|
// after we've got an RC.
|
|
|
|
if (frameRect.height == 0)
|
|
|
|
{
|
2003-05-15 03:42:21 +00:00
|
|
|
const nsStyleFont* fontStyle = mLastCaretFrame->GetStyleFont();
|
|
|
|
const nsStyleVisibility* vis = mLastCaretFrame->GetStyleVisibility();
|
2004-06-08 23:53:59 +00:00
|
|
|
mRendContext->SetFont(fontStyle->mFont, vis->mLangGroup);
|
2002-05-24 20:11:14 +00:00
|
|
|
|
2001-04-13 00:17:21 +00:00
|
|
|
nsCOMPtr<nsIFontMetrics> fm;
|
|
|
|
mRendContext->GetFontMetrics(*getter_AddRefs(fm));
|
|
|
|
if (fm)
|
|
|
|
{
|
|
|
|
nscoord ascent, descent;
|
|
|
|
fm->GetMaxAscent(ascent);
|
|
|
|
fm->GetMaxDescent(descent);
|
|
|
|
frameRect.height = ascent + descent;
|
|
|
|
frameRect.y -= ascent; // BR frames sit on the baseline of the text, so we need to subtract
|
|
|
|
// the ascent to account for the frame height.
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2000-09-07 20:21:22 +00:00
|
|
|
// views are not refcounted
|
|
|
|
mLastCaretView = drawingView;
|
|
|
|
|
2000-09-07 05:26:25 +00:00
|
|
|
if (!mDrawn)
|
|
|
|
{
|
2003-04-20 01:03:40 +00:00
|
|
|
nsPoint framePos(0, 0);
|
2000-09-07 05:26:25 +00:00
|
|
|
nsRect caretRect = frameRect;
|
2003-04-20 01:03:40 +00:00
|
|
|
nsCOMPtr<nsISelection> domSelection = do_QueryReferent(mDomSelectionWeak);
|
|
|
|
nsCOMPtr<nsISelectionPrivate> privateSelection = do_QueryInterface(domSelection);
|
2003-02-24 10:26:20 +00:00
|
|
|
|
2003-04-20 01:03:40 +00:00
|
|
|
// if cache in selection is available, apply it, else refresh it
|
|
|
|
privateSelection->GetCachedFrameOffset(mLastCaretFrame,mLastContentOffset, framePos);
|
2003-02-24 10:26:20 +00:00
|
|
|
|
2003-04-20 01:03:40 +00:00
|
|
|
caretRect += framePos;
|
2003-04-02 05:48:09 +00:00
|
|
|
|
2000-09-07 05:26:25 +00:00
|
|
|
caretRect.width = mCaretTwipsWidth;
|
|
|
|
|
2004-11-10 07:14:08 +00:00
|
|
|
// Check if the caret intersects with the right edge
|
|
|
|
// of the frame. If it does, and the frame's right edge
|
|
|
|
// is close to the right edge of the clipRect, we may
|
|
|
|
// need to adjust the caret's x position so that it
|
|
|
|
// remains visible.
|
2000-09-07 05:26:25 +00:00
|
|
|
|
2003-01-09 01:01:38 +00:00
|
|
|
nscoord caretXMost = caretRect.XMost();
|
|
|
|
nscoord frameXMost = frameRect.XMost();
|
2000-09-07 05:26:25 +00:00
|
|
|
|
2004-11-10 07:14:08 +00:00
|
|
|
if (caretXMost > frameXMost)
|
2000-09-07 05:26:25 +00:00
|
|
|
{
|
2004-11-10 07:14:08 +00:00
|
|
|
nscoord clipXMost = clipRect.XMost();
|
2000-09-07 05:26:25 +00:00
|
|
|
|
2004-11-10 07:14:08 +00:00
|
|
|
if (caretRect.x == frameRect.x && caretRect.x <= clipXMost &&
|
|
|
|
caretXMost > clipXMost)
|
2003-01-09 01:01:38 +00:00
|
|
|
{
|
2004-11-10 07:14:08 +00:00
|
|
|
// The left side of the caret is attached to the left edge of
|
|
|
|
// the frame, and it is wider than the frame itself. It also
|
|
|
|
// overlaps the right edge of the clipRect so we need to nudge
|
|
|
|
// it to the left so that it remains visible.
|
|
|
|
//
|
|
|
|
// We usually hit this case when the caret is attached to a
|
|
|
|
// br frame (which is about 1 twip in width) that is positioned
|
|
|
|
// at the right edge of the content area because it is right aligned
|
|
|
|
// or the right margin pushed it beyond the width of the view port.
|
|
|
|
|
|
|
|
caretRect.x = clipXMost - caretRect.width;
|
2003-01-09 01:01:38 +00:00
|
|
|
}
|
2004-11-10 07:14:08 +00:00
|
|
|
else if (caretRect.x == frameXMost && frameXMost == clipXMost)
|
2003-01-09 01:01:38 +00:00
|
|
|
{
|
2004-11-10 07:14:08 +00:00
|
|
|
// The left side of the caret is attached to the right edge of
|
|
|
|
// the frame, but it's going to get clipped because it's positioned
|
|
|
|
// on the right edge of the clipRect, so nudge it to the
|
|
|
|
// left so it remains visible.
|
|
|
|
//
|
|
|
|
// We usually hit this case when the caret is after the last
|
|
|
|
// character on the line, and the line exceeds the width of the
|
|
|
|
// view port.
|
|
|
|
|
|
|
|
caretRect.x = clipXMost - caretRect.width;
|
2003-01-09 01:01:38 +00:00
|
|
|
}
|
2000-09-07 05:26:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
mCaretRect.IntersectRect(clipRect, caretRect);
|
2001-03-21 01:16:22 +00:00
|
|
|
#ifdef IBMBIDI
|
|
|
|
// Simon -- make a hook to draw to the left or right of the caret to show keyboard language direction
|
|
|
|
PRBool bidiEnabled;
|
|
|
|
nsRect hookRect;
|
|
|
|
PRBool bidiLevel=PR_FALSE;
|
|
|
|
if (mBidiKeyboard)
|
|
|
|
mBidiKeyboard->IsLangRTL(&bidiLevel);
|
|
|
|
if (bidiLevel)
|
|
|
|
{
|
|
|
|
bidiEnabled = PR_TRUE;
|
2001-05-16 13:40:08 +00:00
|
|
|
presContext->SetBidiEnabled(bidiEnabled);
|
2001-03-21 01:16:22 +00:00
|
|
|
}
|
|
|
|
else
|
2004-04-13 00:28:44 +00:00
|
|
|
bidiEnabled = presContext->BidiEnabled();
|
2001-03-21 01:16:22 +00:00
|
|
|
if (bidiEnabled)
|
|
|
|
{
|
|
|
|
if (bidiLevel != mKeyboardRTL)
|
|
|
|
{
|
2001-05-16 12:18:19 +00: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.
|
|
|
|
*/
|
2001-03-21 01:16:22 +00:00
|
|
|
mKeyboardRTL = bidiLevel;
|
|
|
|
nsCOMPtr<nsISelection> domSelection = do_QueryReferent(mDomSelectionWeak);
|
|
|
|
if (domSelection)
|
|
|
|
{
|
|
|
|
if (NS_SUCCEEDED(domSelection->SelectionLanguageChange(mKeyboardRTL)))
|
2001-05-16 12:18:19 +00:00
|
|
|
{
|
2004-04-18 13:13:35 +00:00
|
|
|
mRendContext->PopState();
|
2001-03-21 01:16:22 +00:00
|
|
|
return;
|
2001-05-16 12:18:19 +00:00
|
|
|
}
|
2001-03-21 01:16:22 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
// If keyboard language is RTL, draw the hook on the left; if LTR, to the right
|
|
|
|
hookRect.SetRect(caretRect.x + caretRect.width * ((bidiLevel) ? -1 : 1),
|
2004-10-13 01:12:14 +00:00
|
|
|
caretRect.y + mBidiIndicatorTwipsSize,
|
|
|
|
mBidiIndicatorTwipsSize, mBidiIndicatorTwipsSize);
|
2001-03-21 01:16:22 +00:00
|
|
|
mHookRect.IntersectRect(clipRect, hookRect);
|
|
|
|
}
|
|
|
|
#endif //IBMBIDI
|
2000-09-07 05:26:25 +00:00
|
|
|
}
|
2001-03-21 01:16:22 +00:00
|
|
|
|
2001-02-15 05:07:46 +00:00
|
|
|
if (mReadOnly)
|
|
|
|
mRendContext->SetColor(NS_RGB(85, 85, 85)); // we are drawing it; gray
|
|
|
|
else
|
|
|
|
mRendContext->SetColor(NS_RGB(255,255,255));
|
2003-02-27 23:09:51 +00:00
|
|
|
|
2000-09-07 20:21:22 +00:00
|
|
|
mRendContext->InvertRect(mCaretRect);
|
2002-04-12 02:05:12 +00:00
|
|
|
|
|
|
|
// Ensure the buffer is flushed (Cocoa needs this), since we're drawing
|
|
|
|
// outside the normal painting process.
|
|
|
|
mRendContext->FlushRect(mCaretRect);
|
|
|
|
|
2001-03-21 01:16:22 +00:00
|
|
|
#ifdef IBMBIDI
|
|
|
|
if (!mHookRect.IsEmpty()) // if Bidi support is disabled, the rectangle remains empty and won't be drawn
|
|
|
|
mRendContext->InvertRect(mHookRect);
|
|
|
|
#endif
|
2000-06-09 04:22:20 +00:00
|
|
|
|
2004-04-18 13:13:35 +00:00
|
|
|
mRendContext->PopState();
|
2002-04-12 02:05:12 +00:00
|
|
|
|
2000-09-07 20:21:22 +00:00
|
|
|
ToggleDrawnStatus();
|
2000-09-07 05:26:25 +00:00
|
|
|
|
2000-09-07 20:21:22 +00:00
|
|
|
#ifdef DONT_REUSE_RENDERING_CONTEXT
|
|
|
|
mRendContext = nsnull;
|
|
|
|
#endif
|
1999-04-01 23:57:35 +00:00
|
|
|
}
|
|
|
|
|
1999-03-02 04:26:49 +00:00
|
|
|
#ifdef XP_MAC
|
1999-02-11 23:49:08 +00:00
|
|
|
#pragma mark -
|
1999-03-02 04:26:49 +00:00
|
|
|
#endif
|
1999-02-11 23:49:08 +00:00
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
/* static */
|
|
|
|
void nsCaret::CaretBlinkCallback(nsITimer *aTimer, void *aClosure)
|
|
|
|
{
|
2000-09-07 05:26:25 +00:00
|
|
|
nsCaret *theCaret = NS_REINTERPRET_CAST(nsCaret*, aClosure);
|
|
|
|
if (!theCaret) return;
|
|
|
|
|
|
|
|
theCaret->DrawCaret();
|
1999-02-11 23:49:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
nsresult NS_NewCaret(nsICaret** aInstancePtrResult)
|
|
|
|
{
|
1999-09-14 23:41:19 +00:00
|
|
|
NS_PRECONDITION(aInstancePtrResult, "null ptr");
|
1999-02-11 23:49:08 +00:00
|
|
|
|
|
|
|
nsCaret* caret = new nsCaret();
|
|
|
|
if (nsnull == caret)
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
|
1999-09-14 23:41:19 +00:00
|
|
|
return caret->QueryInterface(NS_GET_IID(nsICaret), (void**) aInstancePtrResult);
|
1999-02-11 23:49:08 +00:00
|
|
|
}
|
|
|
|
|