2001-09-25 05:32:19 +04:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
2006-04-25 01:18:44 +04:00
|
|
|
/* vim: set ts=2 sw=2 et tw=78: */
|
2001-09-25 05:32:19 +04:00
|
|
|
/* ***** BEGIN LICENSE BLOCK *****
|
2004-04-18 01:52:36 +04:00
|
|
|
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
2000-03-22 02:58:02 +03:00
|
|
|
*
|
2004-04-18 01:52:36 +04: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/
|
2000-03-22 02:58:02 +03:00
|
|
|
*
|
2001-09-25 05:32:19 +04: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.
|
2000-03-22 02:58:02 +03:00
|
|
|
*
|
|
|
|
* The Original Code is mozilla.org code.
|
|
|
|
*
|
2004-04-18 01:52:36 +04:00
|
|
|
* The Initial Developer of the Original Code is
|
2001-09-25 05:32:19 +04:00
|
|
|
* Netscape Communications Corporation.
|
|
|
|
* Portions created by the Initial Developer are Copyright (C) 1998
|
|
|
|
* the Initial Developer. All Rights Reserved.
|
2000-03-22 02:58:02 +03:00
|
|
|
*
|
2001-09-25 05:32:19 +04:00
|
|
|
* Contributor(s):
|
2005-10-17 04:51:46 +04:00
|
|
|
* Mats Palmgren <mats.palmgren@bredband.net>
|
2001-09-25 05:32:19 +04:00
|
|
|
*
|
|
|
|
* Alternatively, the contents of this file may be used under the terms of
|
2004-04-18 01:52:36 +04: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-25 05:32:19 +04: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 01:52:36 +04:00
|
|
|
* use your version of this file under the terms of the MPL, indicate your
|
2001-09-25 05:32:19 +04: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 01:52:36 +04:00
|
|
|
* the terms of any one of the MPL, the GPL or the LGPL.
|
2001-09-25 05:32:19 +04:00
|
|
|
*
|
|
|
|
* ***** END LICENSE BLOCK ***** */
|
2000-03-22 02:58:02 +03:00
|
|
|
|
|
|
|
/*
|
2006-04-26 06:01:07 +04:00
|
|
|
* Implementation of selection: nsISelection,nsISelectionPrivate and nsFrameSelection
|
2000-03-22 02:58:02 +03:00
|
|
|
*/
|
|
|
|
|
2000-05-04 12:35:42 +04:00
|
|
|
#include "nsCOMPtr.h"
|
|
|
|
#include "nsWeakReference.h"
|
2000-03-22 02:58:02 +03:00
|
|
|
#include "nsIFactory.h"
|
|
|
|
#include "nsIEnumerator.h"
|
2001-09-29 12:28:41 +04:00
|
|
|
#include "nsString.h"
|
|
|
|
#include "nsReadableUtils.h"
|
2000-03-22 02:58:02 +03:00
|
|
|
#include "nsIDOMRange.h"
|
2006-04-26 06:01:07 +04:00
|
|
|
#include "nsFrameSelection.h"
|
2000-09-14 15:45:01 +04:00
|
|
|
#include "nsISelection.h"
|
2006-07-27 21:57:15 +04:00
|
|
|
#include "nsISelection2.h"
|
2000-09-14 15:45:01 +04:00
|
|
|
#include "nsISelectionPrivate.h"
|
|
|
|
#include "nsISelectionListener.h"
|
2000-03-22 02:58:02 +03:00
|
|
|
#include "nsIComponentManager.h"
|
2001-02-19 15:55:42 +03:00
|
|
|
#include "nsContentCID.h"
|
2000-03-22 02:58:02 +03:00
|
|
|
#include "nsIContent.h"
|
|
|
|
#include "nsIDOMElement.h"
|
|
|
|
#include "nsIDOMNode.h"
|
|
|
|
#include "nsRange.h"
|
2002-12-11 03:02:49 +03:00
|
|
|
#include "nsCOMArray.h"
|
2001-07-16 06:40:48 +04:00
|
|
|
#include "nsGUIEvent.h"
|
2000-03-22 02:58:02 +03:00
|
|
|
#include "nsIDOMKeyEvent.h"
|
|
|
|
#include "nsITableLayout.h"
|
|
|
|
#include "nsITableCellLayout.h"
|
2000-08-29 03:35:57 +04:00
|
|
|
#include "nsIDOMNodeList.h"
|
2006-07-28 01:46:34 +04:00
|
|
|
#include "nsTArray.h"
|
2000-03-22 02:58:02 +03:00
|
|
|
|
2000-09-14 15:45:01 +04:00
|
|
|
#include "nsISelectionListener.h"
|
2000-03-22 02:58:02 +03:00
|
|
|
#include "nsIContentIterator.h"
|
2000-04-28 17:58:08 +04:00
|
|
|
#include "nsIDocumentEncoder.h"
|
2000-03-22 02:58:02 +03:00
|
|
|
|
2001-07-25 09:16:32 +04:00
|
|
|
// for IBMBIDI
|
2001-03-21 04:16:22 +03:00
|
|
|
#include "nsFrameTraversal.h"
|
|
|
|
#include "nsILineIterator.h"
|
2007-01-30 03:06:41 +03:00
|
|
|
#include "nsGkAtoms.h"
|
2001-03-21 04:16:22 +03:00
|
|
|
#include "nsIFrameTraversal.h"
|
2004-08-06 19:55:17 +04:00
|
|
|
#include "nsLayoutUtils.h"
|
2001-03-21 04:16:22 +03:00
|
|
|
#include "nsLayoutCID.h"
|
2006-03-23 11:30:30 +03:00
|
|
|
#include "nsBidiPresUtils.h"
|
2001-03-21 04:16:22 +03:00
|
|
|
static NS_DEFINE_CID(kFrameTraversalCID, NS_FRAMETRAVERSAL_CID);
|
|
|
|
|
2000-03-22 02:58:02 +03:00
|
|
|
#include "nsIDOMText.h"
|
|
|
|
|
Landing the XPCDOM_20010329_BRANCH branch, changes mostly done by jband@netscape.com and jst@netscape.com, also some changes done by shaver@mozilla.org, peterv@netscape.com and markh@activestate.com. r= and sr= by vidur@netscape.com, jband@netscape.com, jst@netscpae.com, danm@netscape.com, hyatt@netscape.com, shaver@mozilla.org, dbradley@netscape.com, rpotts@netscape.com.
2001-05-08 20:46:42 +04:00
|
|
|
#include "nsContentUtils.h"
|
2006-05-10 21:30:15 +04:00
|
|
|
#include "nsThreadUtils.h"
|
Landing the XPCDOM_20010329_BRANCH branch, changes mostly done by jband@netscape.com and jst@netscape.com, also some changes done by shaver@mozilla.org, peterv@netscape.com and markh@activestate.com. r= and sr= by vidur@netscape.com, jband@netscape.com, jst@netscpae.com, danm@netscape.com, hyatt@netscape.com, shaver@mozilla.org, dbradley@netscape.com, rpotts@netscape.com.
2001-05-08 20:46:42 +04:00
|
|
|
|
2000-03-22 02:58:02 +03:00
|
|
|
//included for desired x position;
|
2004-08-01 03:15:21 +04:00
|
|
|
#include "nsPresContext.h"
|
2000-03-22 02:58:02 +03:00
|
|
|
#include "nsIPresShell.h"
|
|
|
|
#include "nsICaret.h"
|
|
|
|
|
|
|
|
|
|
|
|
// included for view scrolling
|
|
|
|
#include "nsIViewManager.h"
|
|
|
|
#include "nsIScrollableView.h"
|
|
|
|
#include "nsIDeviceContext.h"
|
|
|
|
#include "nsITimer.h"
|
2000-04-14 15:21:19 +04:00
|
|
|
#include "nsIServiceManager.h"
|
2006-06-16 05:54:31 +04:00
|
|
|
#include "nsFrameManager.h"
|
2002-12-11 17:24:49 +03:00
|
|
|
// notifications
|
2000-04-14 15:21:19 +04:00
|
|
|
#include "nsIDOMDocument.h"
|
|
|
|
#include "nsIDocument.h"
|
|
|
|
|
2000-04-27 11:37:12 +04:00
|
|
|
#include "nsISelectionController.h"//for the enums
|
2005-02-01 02:47:26 +03:00
|
|
|
#include "nsAutoCopyListener.h"
|
|
|
|
#include "nsCopySupport.h"
|
|
|
|
#include "nsIClipboard.h"
|
2000-03-22 02:58:02 +03:00
|
|
|
|
2006-08-08 09:14:52 +04:00
|
|
|
#ifdef IBMBIDI
|
|
|
|
#include "nsIBidiKeyboard.h"
|
|
|
|
#endif // IBMBIDI
|
|
|
|
|
2004-09-01 09:16:00 +04:00
|
|
|
#define STATUS_CHECK_RETURN_MACRO() {if (!mShell) return NS_ERROR_FAILURE;}
|
2002-08-30 05:32:11 +04:00
|
|
|
|
|
|
|
|
|
|
|
|
2002-03-22 18:26:18 +03:00
|
|
|
//#define DEBUG_TABLE 1
|
2000-03-22 02:58:02 +03:00
|
|
|
|
2000-10-14 02:37:52 +04:00
|
|
|
static NS_DEFINE_IID(kCContentIteratorCID, NS_CONTENTITERATOR_CID);
|
2000-03-22 02:58:02 +03:00
|
|
|
static NS_DEFINE_IID(kCSubtreeIteratorCID, NS_SUBTREEITERATOR_CID);
|
|
|
|
|
2001-05-04 03:59:55 +04:00
|
|
|
#undef OLD_SELECTION
|
|
|
|
#undef OLD_TABLE_SELECTION
|
|
|
|
|
|
|
|
|
2000-03-22 02:58:02 +03:00
|
|
|
//PROTOTYPES
|
2002-03-26 02:44:46 +03:00
|
|
|
class nsSelectionIterator;
|
2006-04-26 06:01:07 +04:00
|
|
|
class nsFrameSelection;
|
2002-03-26 02:44:46 +03:00
|
|
|
class nsAutoScrollTimer;
|
|
|
|
|
2006-04-26 06:01:07 +04:00
|
|
|
PRBool IsValidSelectionPoint(nsFrameSelection *aFrameSel, nsIContent *aContent);
|
|
|
|
PRBool IsValidSelectionPoint(nsFrameSelection *aFrameSel, nsIDOMNode *aDomNode);
|
2002-03-26 02:44:46 +03:00
|
|
|
|
2003-11-19 04:20:56 +03:00
|
|
|
static nsIAtom *GetTag(nsIDOMNode *aNode);
|
2000-03-22 02:58:02 +03:00
|
|
|
static nsresult ParentOffset(nsIDOMNode *aNode, nsIDOMNode **aParent, PRInt32 *aChildOffset);
|
2002-03-22 18:25:08 +03:00
|
|
|
static nsIDOMNode *GetCellParent(nsIDOMNode *aDomNode);
|
|
|
|
|
2000-03-22 02:58:02 +03:00
|
|
|
|
|
|
|
#ifdef PRINT_RANGE
|
|
|
|
static void printRange(nsIDOMRange *aDomRange);
|
|
|
|
#define DEBUG_OUT_RANGE(x) printRange(x)
|
|
|
|
#else
|
|
|
|
#define DEBUG_OUT_RANGE(x)
|
|
|
|
#endif //MOZ_DEBUG
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//#define DEBUG_SELECTION // uncomment for printf describing every collapse and extend.
|
|
|
|
//#define DEBUG_NAVIGATION
|
|
|
|
|
2000-03-31 11:17:22 +04:00
|
|
|
|
2000-06-03 03:05:06 +04:00
|
|
|
//#define DEBUG_TABLE_SELECTION 1
|
2000-03-31 11:17:22 +04:00
|
|
|
|
2006-10-21 05:30:54 +04:00
|
|
|
static PRInt32
|
|
|
|
CompareDOMPoints(nsIDOMNode* aParent1, PRInt32 aOffset1,
|
|
|
|
nsIDOMNode* aParent2, PRInt32 aOffset2)
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsINode> parent1 = do_QueryInterface(aParent1);
|
|
|
|
nsCOMPtr<nsINode> parent2 = do_QueryInterface(aParent2);
|
|
|
|
|
|
|
|
NS_ASSERTION(parent1 && parent2, "not real nodes?");
|
|
|
|
|
|
|
|
return nsContentUtils::ComparePoints(parent1, aOffset1, parent2, aOffset2);
|
|
|
|
}
|
2002-03-26 02:44:46 +03:00
|
|
|
|
2003-04-20 05:03:40 +04:00
|
|
|
struct CachedOffsetForFrame {
|
|
|
|
CachedOffsetForFrame()
|
|
|
|
: mCachedFrameOffset(0, 0) // nsPoint ctor
|
|
|
|
, mLastCaretFrame(nsnull)
|
|
|
|
, mLastContentOffset(0)
|
|
|
|
, mCanCacheFrameOffset(PR_FALSE)
|
|
|
|
{}
|
|
|
|
|
|
|
|
nsPoint mCachedFrameOffset; // cached frame offset
|
|
|
|
nsIFrame* mLastCaretFrame; // store the frame the caret was last drawn in.
|
|
|
|
PRInt32 mLastContentOffset; // store last content offset
|
|
|
|
PRPackedBool mCanCacheFrameOffset; // cached frame offset is valid?
|
|
|
|
};
|
2000-03-22 02:58:02 +03:00
|
|
|
|
2006-07-27 21:57:15 +04:00
|
|
|
struct RangeData
|
|
|
|
{
|
|
|
|
RangeData(nsIDOMRange* aRange, PRInt32 aEndIndex) :
|
|
|
|
mRange(aRange), mEndIndex(aEndIndex) {}
|
|
|
|
|
|
|
|
nsCOMPtr<nsIDOMRange> mRange;
|
|
|
|
PRInt32 mEndIndex; // index into mRangeEndings of this item
|
|
|
|
};
|
|
|
|
|
|
|
|
class nsTypedSelection : public nsISelection2,
|
Landing the XPCDOM_20010329_BRANCH branch, changes mostly done by jband@netscape.com and jst@netscape.com, also some changes done by shaver@mozilla.org, peterv@netscape.com and markh@activestate.com. r= and sr= by vidur@netscape.com, jband@netscape.com, jst@netscpae.com, danm@netscape.com, hyatt@netscape.com, shaver@mozilla.org, dbradley@netscape.com, rpotts@netscape.com.
2001-05-08 20:46:42 +04:00
|
|
|
public nsISelectionPrivate,
|
2003-04-04 05:45:06 +04:00
|
|
|
public nsSupportsWeakReference
|
2000-03-22 02:58:02 +03:00
|
|
|
{
|
|
|
|
public:
|
2000-11-29 03:13:00 +03:00
|
|
|
nsTypedSelection();
|
2006-04-26 06:01:07 +04:00
|
|
|
nsTypedSelection(nsFrameSelection *aList);
|
2000-11-29 03:13:00 +03:00
|
|
|
virtual ~nsTypedSelection();
|
2000-03-22 02:58:02 +03:00
|
|
|
|
|
|
|
NS_DECL_ISUPPORTS
|
2003-04-04 05:45:06 +04:00
|
|
|
NS_DECL_NSISELECTION
|
2006-07-27 21:57:15 +04:00
|
|
|
NS_DECL_NSISELECTION2
|
2003-04-04 05:45:06 +04:00
|
|
|
NS_DECL_NSISELECTIONPRIVATE
|
2000-03-22 02:58:02 +03:00
|
|
|
|
|
|
|
// utility methods for scrolling the selection into view
|
2004-08-01 03:15:21 +04:00
|
|
|
nsresult GetPresContext(nsPresContext **aPresContext);
|
2000-03-22 02:58:02 +03:00
|
|
|
nsresult GetPresShell(nsIPresShell **aPresShell);
|
|
|
|
nsresult GetRootScrollableView(nsIScrollableView **aScrollableView);
|
2000-08-30 23:42:47 +04:00
|
|
|
nsresult GetFrameToScrolledViewOffsets(nsIScrollableView *aScrollableView, nsIFrame *aFrame, nscoord *aXOffset, nscoord *aYOffset);
|
2000-03-22 02:58:02 +03:00
|
|
|
nsresult GetPointFromOffset(nsIFrame *aFrame, PRInt32 aContentOffset, nsPoint *aPoint);
|
2000-08-30 23:42:47 +04:00
|
|
|
nsresult GetSelectionRegionRectAndScrollableView(SelectionRegion aRegion, nsRect *aRect, nsIScrollableView **aScrollableView);
|
|
|
|
nsresult ScrollRectIntoView(nsIScrollableView *aScrollableView, nsRect& aRect, PRIntn aVPercent, PRIntn aHPercent, PRBool aScrollParentViews);
|
2000-03-22 02:58:02 +03:00
|
|
|
|
2002-06-14 00:43:32 +04:00
|
|
|
nsresult PostScrollSelectionIntoViewEvent(SelectionRegion aRegion);
|
|
|
|
NS_IMETHOD ScrollIntoView(SelectionRegion aRegion=nsISelectionController::SELECTION_FOCUS_REGION, PRBool aIsSynchronous=PR_TRUE);
|
2000-03-22 02:58:02 +03:00
|
|
|
nsresult AddItem(nsIDOMRange *aRange);
|
|
|
|
nsresult RemoveItem(nsIDOMRange *aRange);
|
2004-08-01 03:15:21 +04:00
|
|
|
nsresult Clear(nsPresContext* aPresContext);
|
2006-07-27 21:57:15 +04:00
|
|
|
|
2003-03-12 06:22:11 +03:00
|
|
|
// methods for convenience. Note, these don't addref
|
2000-03-22 02:58:02 +03:00
|
|
|
nsIDOMNode* FetchAnchorNode(); //where did the selection begin
|
|
|
|
PRInt32 FetchAnchorOffset();
|
|
|
|
|
|
|
|
nsIDOMNode* FetchOriginalAnchorNode(); //where did the ORIGINAL selection begin
|
|
|
|
PRInt32 FetchOriginalAnchorOffset();
|
|
|
|
|
|
|
|
nsIDOMNode* FetchFocusNode(); //where is the carret
|
|
|
|
PRInt32 FetchFocusOffset();
|
|
|
|
|
|
|
|
nsIDOMNode* FetchStartParent(nsIDOMRange *aRange); //skip all the com stuff and give me the start/end
|
|
|
|
PRInt32 FetchStartOffset(nsIDOMRange *aRange);
|
|
|
|
nsIDOMNode* FetchEndParent(nsIDOMRange *aRange); //skip all the com stuff and give me the start/end
|
|
|
|
PRInt32 FetchEndOffset(nsIDOMRange *aRange);
|
|
|
|
|
|
|
|
nsDirection GetDirection(){return mDirection;}
|
|
|
|
void SetDirection(nsDirection aDir){mDirection = aDir;}
|
2001-03-21 04:16:22 +03:00
|
|
|
PRBool GetTrueDirection() {return mTrueDirection;}
|
|
|
|
void SetTrueDirection(PRBool aBool){mTrueDirection = aBool;}
|
2000-03-22 02:58:02 +03:00
|
|
|
NS_IMETHOD CopyRangeToAnchorFocus(nsIDOMRange *aRange);
|
2000-08-29 03:35:57 +04:00
|
|
|
|
|
|
|
|
2000-03-22 02:58:02 +03:00
|
|
|
// NS_IMETHOD GetPrimaryFrameForRangeEndpoint(nsIDOMNode *aNode, PRInt32 aOffset, PRBool aIsEndNode, nsIFrame **aResultFrame);
|
|
|
|
NS_IMETHOD GetPrimaryFrameForAnchorNode(nsIFrame **aResultFrame);
|
2006-08-30 13:26:39 +04:00
|
|
|
NS_IMETHOD GetPrimaryFrameForFocusNode(nsIFrame **aResultFrame, PRInt32 *aOffset, PRBool aVisual);
|
2000-03-22 02:58:02 +03:00
|
|
|
NS_IMETHOD SetOriginalAnchorPoint(nsIDOMNode *aNode, PRInt32 aOffset);
|
|
|
|
NS_IMETHOD GetOriginalAnchorPoint(nsIDOMNode **aNode, PRInt32 *aOffset);
|
|
|
|
NS_IMETHOD LookUpSelection(nsIContent *aContent, PRInt32 aContentOffset, PRInt32 aContentLength,
|
|
|
|
SelectionDetails **aReturnDetails, SelectionType aType, PRBool aSlowCheck);
|
2004-08-01 03:15:21 +04:00
|
|
|
NS_IMETHOD Repaint(nsPresContext* aPresContext);
|
2000-03-22 02:58:02 +03:00
|
|
|
|
2006-06-16 05:54:31 +04:00
|
|
|
nsresult StartAutoScrollTimer(nsPresContext *aPresContext,
|
|
|
|
nsIView *aView,
|
|
|
|
nsPoint& aPoint,
|
|
|
|
PRUint32 aDelay);
|
|
|
|
|
2000-03-22 02:58:02 +03:00
|
|
|
nsresult StopAutoScrollTimer();
|
2006-06-16 05:54:31 +04:00
|
|
|
|
|
|
|
|
2006-03-23 03:13:07 +03:00
|
|
|
private:
|
2006-06-16 05:54:31 +04:00
|
|
|
friend class nsAutoScrollTimer;
|
|
|
|
|
|
|
|
nsresult DoAutoScrollView(nsPresContext *aPresContext,
|
|
|
|
nsIView *aView,
|
|
|
|
nsPoint& aPoint,
|
|
|
|
PRBool aScrollParentViews);
|
|
|
|
|
2004-08-01 03:15:21 +04:00
|
|
|
nsresult ScrollPointIntoClipView(nsPresContext *aPresContext, nsIView *aView, nsPoint& aPoint, PRBool *aDidScroll);
|
|
|
|
nsresult ScrollPointIntoView(nsPresContext *aPresContext, nsIView *aView, nsPoint& aPoint, PRBool aScrollParentViews, PRBool *aDidScroll);
|
2000-08-30 23:42:47 +04:00
|
|
|
nsresult GetViewAncestorOffset(nsIView *aView, nsIView *aAncestorView, nscoord *aXOffset, nscoord *aYOffset);
|
2000-03-22 02:58:02 +03:00
|
|
|
|
2006-03-23 03:13:07 +03:00
|
|
|
public:
|
2000-04-14 15:21:19 +04:00
|
|
|
SelectionType GetType(){return mType;}
|
|
|
|
void SetType(SelectionType aType){mType = aType;}
|
|
|
|
|
2000-05-04 12:35:42 +04:00
|
|
|
nsresult NotifySelectionListeners();
|
|
|
|
|
2006-04-14 04:28:22 +04:00
|
|
|
void DetachFromPresentation();
|
|
|
|
|
2000-03-22 02:58:02 +03:00
|
|
|
private:
|
|
|
|
friend class nsSelectionIterator;
|
|
|
|
|
2006-05-10 21:30:15 +04:00
|
|
|
class ScrollSelectionIntoViewEvent;
|
|
|
|
friend class ScrollSelectionIntoViewEvent;
|
|
|
|
|
|
|
|
class ScrollSelectionIntoViewEvent : public nsRunnable {
|
|
|
|
public:
|
|
|
|
NS_DECL_NSIRUNNABLE
|
|
|
|
ScrollSelectionIntoViewEvent(nsTypedSelection *aTypedSelection,
|
|
|
|
SelectionRegion aRegion)
|
|
|
|
: mTypedSelection(aTypedSelection),
|
|
|
|
mRegion(aRegion) {
|
|
|
|
NS_ASSERTION(aTypedSelection, "null parameter");
|
|
|
|
}
|
|
|
|
void Revoke() { mTypedSelection = nsnull; }
|
|
|
|
private:
|
|
|
|
nsTypedSelection *mTypedSelection;
|
|
|
|
SelectionRegion mRegion;
|
|
|
|
};
|
2000-03-22 02:58:02 +03:00
|
|
|
|
|
|
|
void setAnchorFocusRange(PRInt32 aIndex); //pass in index into FrameSelection
|
2004-08-01 03:15:21 +04:00
|
|
|
NS_IMETHOD selectFrames(nsPresContext* aPresContext, nsIContentIterator *aInnerIter, nsIContent *aContent, nsIDOMRange *aRange, nsIPresShell *aPresShell, PRBool aFlags);
|
|
|
|
NS_IMETHOD selectFrames(nsPresContext* aPresContext, nsIDOMRange *aRange, PRBool aSelect);
|
2000-12-21 01:13:54 +03:00
|
|
|
nsresult getTableCellLocationFromRange(nsIDOMRange *aRange, PRInt32 *aSelectionType, PRInt32 *aRow, PRInt32 *aCol);
|
|
|
|
nsresult addTableCellRange(nsIDOMRange *aRange, PRBool *aDidAddRange);
|
2000-03-22 02:58:02 +03:00
|
|
|
|
2001-05-04 03:59:55 +04:00
|
|
|
#ifdef OLD_SELECTION
|
2000-03-22 02:58:02 +03:00
|
|
|
NS_IMETHOD FixupSelectionPoints(nsIDOMRange *aRange, nsDirection *aDir, PRBool *aFixupState);
|
|
|
|
#endif //OLD_SELECTION
|
|
|
|
|
2006-07-27 21:57:15 +04:00
|
|
|
// These are the ranges inside this selection. They are kept sorted in order
|
|
|
|
// of DOM position of start and end, respectively (both of these arrays
|
|
|
|
// should have the same contents, but possibly in different orders).
|
|
|
|
//
|
|
|
|
// This data structure is sorted by the range beginnings and the range
|
|
|
|
// endings. When searching for a range, we can discard ranges whose ends
|
|
|
|
// are before the point in question, or whose beginnings are after. We can
|
|
|
|
// find these two sets of ranges on O(log n) time.
|
|
|
|
//
|
|
|
|
// Merging these two result sets takes O(n) time, so a a full query is O(log
|
|
|
|
// n + n) time. This looks worse than brute force O(n) searching, but in
|
|
|
|
// practice it is much faster. The DOM comparisons used in a brute force
|
|
|
|
// search are VERY expensive because they actually walk the DOM tree. We only
|
|
|
|
// do log(n) of these comparisons.
|
|
|
|
//
|
|
|
|
// Our O(n) merging step uses very fast integer comparisons, and, since
|
|
|
|
// we store the range ending index in the structure, we have to merge at
|
|
|
|
// most half of the results. Timing shows that this algorithm is nearly
|
|
|
|
// twice as fast doing intersections for 9 ranges, and 18 times faster for
|
|
|
|
// 250 ranges.
|
|
|
|
//
|
|
|
|
// An interval tree would give us O(log n) time lookups, which would be
|
|
|
|
// better. However, this approach gets us most of the way, and doesn't
|
|
|
|
// require rebalancing and other overhead. If this algorithm is found to be
|
|
|
|
// a bottleneck, it should be replaced with an interval tree.
|
|
|
|
//
|
|
|
|
// It has been discussed requiring selections to be disjoint in the future.
|
|
|
|
// If this requirement is added, the current design makes the most sense, we
|
|
|
|
// can just remove the array sorted by endings.
|
|
|
|
|
|
|
|
nsTArray<RangeData> mRanges;
|
|
|
|
nsTArray<PRInt32> mRangeEndings; // references info mRanges
|
|
|
|
#ifdef DEBUG
|
|
|
|
PRBool ValidateRanges();
|
|
|
|
#endif
|
|
|
|
|
|
|
|
nsresult FindInsertionPoint(
|
|
|
|
const nsTArray<PRInt32>* aRemappingArray,
|
|
|
|
nsIDOMNode* aPointNode, PRInt32 aPointOffset,
|
|
|
|
nsresult (*aComparator)(nsIDOMNode*,PRInt32,nsIDOMRange*,PRInt32*),
|
|
|
|
PRInt32* aInsertionPoint);
|
|
|
|
nsresult MoveIndexToFirstMatch(PRInt32* aIndex, nsIDOMNode* aNode,
|
|
|
|
PRInt32 aOffset,
|
|
|
|
const nsTArray<PRInt32>* aArray,
|
|
|
|
PRBool aUseBeginning);
|
|
|
|
nsresult MoveIndexToNextMismatch(PRInt32* aIndex, nsIDOMNode* aNode,
|
|
|
|
PRInt32 aOffset,
|
|
|
|
const nsTArray<PRInt32>* aRemappingArray,
|
|
|
|
PRBool aUseBeginning);
|
2006-08-10 23:56:43 +04:00
|
|
|
PRBool FindRangeGivenPoint(nsIDOMNode* aBeginNode, PRInt32 aBeginOffset,
|
|
|
|
nsIDOMNode* aEndNode, PRInt32 aEndOffset,
|
|
|
|
PRInt32 aStartSearchingHere);
|
2000-03-22 02:58:02 +03:00
|
|
|
|
|
|
|
nsCOMPtr<nsIDOMRange> mAnchorFocusRange;
|
|
|
|
nsCOMPtr<nsIDOMRange> mOriginalAnchorRange; //used as a point with range gravity for security
|
2002-12-11 03:02:49 +03:00
|
|
|
nsDirection mDirection; //FALSE = focus, anchor; TRUE = anchor, focus
|
2000-03-22 02:58:02 +03:00
|
|
|
PRBool mFixupState; //was there a fixup?
|
|
|
|
|
2006-04-26 06:01:07 +04:00
|
|
|
nsFrameSelection *mFrameSelection;
|
2000-05-13 12:07:34 +04:00
|
|
|
nsWeakPtr mPresShellWeak; //weak reference to presshell.
|
2000-11-29 03:13:00 +03:00
|
|
|
SelectionType mType;//type of this nsTypedSelection;
|
2006-06-16 05:54:31 +04:00
|
|
|
nsRefPtr<nsAutoScrollTimer> mAutoScrollTimer; // timer for autoscrolling.
|
2002-12-11 03:02:49 +03:00
|
|
|
nsCOMArray<nsISelectionListener> mSelectionListeners;
|
2006-05-10 21:30:15 +04:00
|
|
|
PRPackedBool mTrueDirection;
|
|
|
|
nsRevocableEventPtr<ScrollSelectionIntoViewEvent> mScrollEvent;
|
2003-04-20 05:03:40 +04:00
|
|
|
CachedOffsetForFrame *mCachedOffsetForFrame;
|
2000-03-22 02:58:02 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
// Stack-class to turn on/off selection batching for table selection
|
|
|
|
class nsSelectionBatcher
|
|
|
|
{
|
|
|
|
private:
|
2000-09-14 15:45:01 +04:00
|
|
|
nsCOMPtr<nsISelectionPrivate> mSelection;
|
2000-03-22 02:58:02 +03:00
|
|
|
public:
|
2000-09-14 15:45:01 +04:00
|
|
|
nsSelectionBatcher(nsISelectionPrivate *aSelection) : mSelection(aSelection)
|
2000-03-22 02:58:02 +03:00
|
|
|
{
|
|
|
|
if (mSelection) mSelection->StartBatchChanges();
|
|
|
|
}
|
|
|
|
virtual ~nsSelectionBatcher()
|
|
|
|
{
|
|
|
|
if (mSelection) mSelection->EndBatchChanges();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
class nsSelectionIterator : public nsIBidirectionalEnumerator
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
/*BEGIN nsIEnumerator interfaces
|
|
|
|
see the nsIEnumerator for more details*/
|
|
|
|
|
|
|
|
NS_DECL_ISUPPORTS
|
|
|
|
|
|
|
|
NS_DECL_NSIENUMERATOR
|
|
|
|
|
|
|
|
NS_DECL_NSIBIDIRECTIONALENUMERATOR
|
|
|
|
|
|
|
|
/*END nsIEnumerator interfaces*/
|
|
|
|
/*BEGIN Helper Methods*/
|
|
|
|
NS_IMETHOD CurrentItem(nsIDOMRange **aRange);
|
|
|
|
/*END Helper Methods*/
|
|
|
|
private:
|
2000-11-29 03:13:00 +03:00
|
|
|
friend class nsTypedSelection;
|
2000-03-22 02:58:02 +03:00
|
|
|
|
|
|
|
//lame lame lame if delete from document goes away then get rid of this unless its debug
|
2006-04-26 06:01:07 +04:00
|
|
|
friend class nsFrameSelection;
|
2000-03-22 02:58:02 +03:00
|
|
|
|
2000-11-29 03:13:00 +03:00
|
|
|
nsSelectionIterator(nsTypedSelection *);
|
2000-03-22 02:58:02 +03:00
|
|
|
virtual ~nsSelectionIterator();
|
|
|
|
PRInt32 mIndex;
|
2000-11-29 03:13:00 +03:00
|
|
|
nsTypedSelection *mDomSelection;
|
2000-03-22 02:58:02 +03:00
|
|
|
SelectionType mType;
|
|
|
|
};
|
|
|
|
|
|
|
|
class nsAutoScrollTimer : public nsITimerCallback
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
|
|
|
|
NS_DECL_ISUPPORTS
|
|
|
|
|
|
|
|
nsAutoScrollTimer()
|
2006-06-16 05:54:31 +04:00
|
|
|
: mFrameSelection(0), mSelection(0), mPresContext(0), mPoint(0,0), mDelay(30)
|
2000-03-22 02:58:02 +03:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual ~nsAutoScrollTimer()
|
|
|
|
{
|
2000-08-30 23:42:47 +04:00
|
|
|
if (mTimer)
|
|
|
|
mTimer->Cancel();
|
2000-03-22 02:58:02 +03:00
|
|
|
}
|
|
|
|
|
2004-08-01 03:15:21 +04:00
|
|
|
nsresult Start(nsPresContext *aPresContext, nsIView *aView, nsPoint &aPoint)
|
2000-03-22 02:58:02 +03:00
|
|
|
{
|
2006-06-16 05:54:31 +04:00
|
|
|
mPoint = aPoint;
|
|
|
|
|
|
|
|
// Store the presentation context. The timer will be
|
|
|
|
// stopped by the selection if the prescontext is destroyed.
|
2000-03-22 02:58:02 +03:00
|
|
|
mPresContext = aPresContext;
|
2006-06-16 05:54:31 +04:00
|
|
|
|
|
|
|
// Store the content from the nearest capturing frame. If this returns null
|
|
|
|
// the capturing frame is the root.
|
|
|
|
nsIFrame* clientFrame = NS_STATIC_CAST(nsIFrame*, aView->GetClientData());
|
|
|
|
NS_ASSERTION(clientFrame, "Missing client frame");
|
|
|
|
|
|
|
|
nsIFrame* capturingFrame = nsFrame::GetNearestCapturingFrame(clientFrame);
|
|
|
|
NS_ASSERTION(!capturingFrame || capturingFrame->GetMouseCapturer(),
|
|
|
|
"Capturing frame should have a mouse capturer" );
|
|
|
|
|
2007-03-31 01:11:41 +04:00
|
|
|
NS_ASSERTION(!capturingFrame || mPresContext == capturingFrame->PresContext(),
|
2006-06-16 05:54:31 +04:00
|
|
|
"Shouldn't have different pres contexts");
|
|
|
|
|
|
|
|
NS_ASSERTION(capturingFrame != mPresContext->PresShell()->FrameManager()->GetRootFrame(),
|
|
|
|
"Capturing frame should not be the root frame");
|
|
|
|
|
|
|
|
if (capturingFrame)
|
|
|
|
{
|
|
|
|
mContent = capturingFrame->GetContent();
|
|
|
|
NS_ASSERTION(mContent, "Need content");
|
|
|
|
|
|
|
|
NS_ASSERTION(mContent != mPresContext->PresShell()->FrameManager()->GetRootFrame()->GetContent(),
|
|
|
|
"We didn't want the root content!");
|
|
|
|
|
|
|
|
NS_ASSERTION(capturingFrame == nsFrame::GetNearestCapturingFrame(
|
|
|
|
mPresContext->PresShell()->GetPrimaryFrameFor(mContent)),
|
|
|
|
"Mapping of frame to content failed.");
|
|
|
|
}
|
|
|
|
|
|
|
|
// Check that if there was no capturing frame the content is null.
|
|
|
|
NS_ASSERTION(capturingFrame || !mContent, "Content not cleared correctly.");
|
2000-03-22 02:58:02 +03:00
|
|
|
|
|
|
|
if (!mTimer)
|
|
|
|
{
|
2000-05-17 06:49:35 +04:00
|
|
|
nsresult result;
|
2000-09-14 03:57:52 +04:00
|
|
|
mTimer = do_CreateInstance("@mozilla.org/timer;1", &result);
|
2000-03-22 02:58:02 +03:00
|
|
|
|
|
|
|
if (NS_FAILED(result))
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2002-09-07 09:38:16 +04:00
|
|
|
return mTimer->InitWithCallback(this, mDelay, nsITimer::TYPE_ONE_SHOT);
|
2000-03-22 02:58:02 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
nsresult Stop()
|
|
|
|
{
|
|
|
|
if (mTimer)
|
|
|
|
{
|
|
|
|
mTimer->Cancel();
|
|
|
|
mTimer = 0;
|
|
|
|
}
|
|
|
|
|
2006-06-16 05:54:31 +04:00
|
|
|
mContent = nsnull;
|
|
|
|
return NS_OK;
|
2000-03-22 02:58:02 +03:00
|
|
|
}
|
|
|
|
|
2006-04-26 06:01:07 +04:00
|
|
|
nsresult Init(nsFrameSelection *aFrameSelection, nsTypedSelection *aSelection)
|
2000-03-22 02:58:02 +03:00
|
|
|
{
|
|
|
|
mFrameSelection = aFrameSelection;
|
|
|
|
mSelection = aSelection;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult SetDelay(PRUint32 aDelay)
|
|
|
|
{
|
|
|
|
mDelay = aDelay;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2002-09-07 09:38:16 +04:00
|
|
|
NS_IMETHOD Notify(nsITimer *timer)
|
2000-03-22 02:58:02 +03:00
|
|
|
{
|
2006-06-16 05:54:31 +04:00
|
|
|
if (mSelection && mPresContext)
|
2000-03-22 02:58:02 +03:00
|
|
|
{
|
2006-06-16 05:54:31 +04:00
|
|
|
// If the content is null the capturing frame must be the root frame.
|
|
|
|
nsIFrame* capturingFrame;
|
|
|
|
if (mContent)
|
|
|
|
{
|
|
|
|
nsIFrame* contentFrame = mPresContext->PresShell()->GetPrimaryFrameFor(mContent);
|
|
|
|
if (contentFrame)
|
|
|
|
{
|
|
|
|
capturingFrame = nsFrame::GetNearestCapturingFrame(contentFrame);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
capturingFrame = nsnull;
|
|
|
|
}
|
|
|
|
NS_ASSERTION(!capturingFrame || capturingFrame->GetMouseCapturer(),
|
|
|
|
"Capturing frame should have a mouse capturer" );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
capturingFrame = mPresContext->PresShell()->FrameManager()->GetRootFrame();
|
|
|
|
}
|
|
|
|
|
|
|
|
// Clear the content reference now that the frame has been found.
|
|
|
|
mContent = nsnull;
|
2000-08-30 23:42:47 +04:00
|
|
|
|
2006-06-16 05:54:31 +04:00
|
|
|
// This could happen for a frame with style changed to display:none or a frame
|
|
|
|
// that was destroyed.
|
|
|
|
if (!capturingFrame) {
|
|
|
|
NS_WARNING("Frame destroyed or set to display:none before scroll timer fired.");
|
2002-09-07 09:38:16 +04:00
|
|
|
return NS_OK;
|
2006-06-16 05:54:31 +04:00
|
|
|
}
|
2000-08-30 23:42:47 +04:00
|
|
|
|
2006-06-16 05:54:31 +04:00
|
|
|
nsIView* captureView = capturingFrame->GetMouseCapturer();
|
|
|
|
|
|
|
|
nsIFrame* viewFrame = NS_STATIC_CAST(nsIFrame*, captureView->GetClientData());
|
|
|
|
NS_ASSERTION(viewFrame, "View must have a client frame");
|
|
|
|
|
|
|
|
mFrameSelection->HandleDrag(viewFrame, mPoint);
|
2000-08-30 23:42:47 +04:00
|
|
|
|
2006-06-16 05:54:31 +04:00
|
|
|
mSelection->DoAutoScrollView(mPresContext, captureView, mPoint, PR_TRUE);
|
2000-03-22 02:58:02 +03:00
|
|
|
}
|
2002-09-07 09:38:16 +04:00
|
|
|
return NS_OK;
|
2000-03-22 02:58:02 +03:00
|
|
|
}
|
|
|
|
private:
|
2006-06-16 05:54:31 +04:00
|
|
|
nsFrameSelection *mFrameSelection;
|
2000-11-29 03:13:00 +03:00
|
|
|
nsTypedSelection *mSelection;
|
2004-08-01 03:15:21 +04:00
|
|
|
nsPresContext *mPresContext;
|
2006-06-16 05:54:31 +04:00
|
|
|
nsPoint mPoint;
|
|
|
|
nsCOMPtr<nsITimer> mTimer;
|
|
|
|
nsCOMPtr<nsIContent> mContent;
|
|
|
|
PRUint32 mDelay;
|
2000-03-22 02:58:02 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
NS_IMPL_ADDREF(nsAutoScrollTimer)
|
|
|
|
NS_IMPL_RELEASE(nsAutoScrollTimer)
|
|
|
|
NS_IMPL_QUERY_INTERFACE1(nsAutoScrollTimer, nsITimerCallback)
|
|
|
|
|
2006-04-26 06:01:07 +04:00
|
|
|
nsresult NS_NewSelection(nsFrameSelection **aFrameSelection);
|
2000-03-22 02:58:02 +03:00
|
|
|
|
2006-04-26 06:01:07 +04:00
|
|
|
nsresult NS_NewSelection(nsFrameSelection **aFrameSelection)
|
2000-03-22 02:58:02 +03:00
|
|
|
{
|
2006-04-26 06:01:07 +04:00
|
|
|
nsFrameSelection *rlist = new nsFrameSelection;
|
2000-03-22 02:58:02 +03:00
|
|
|
if (!rlist)
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
2006-04-26 06:01:07 +04:00
|
|
|
*aFrameSelection = rlist;
|
2005-03-25 10:35:17 +03:00
|
|
|
NS_ADDREF(rlist);
|
2000-05-11 08:25:43 +04:00
|
|
|
return NS_OK;
|
2000-03-22 02:58:02 +03:00
|
|
|
}
|
|
|
|
|
2000-09-14 15:45:01 +04:00
|
|
|
nsresult NS_NewDomSelection(nsISelection **aDomSelection);
|
2000-03-22 02:58:02 +03:00
|
|
|
|
2000-09-14 15:45:01 +04:00
|
|
|
nsresult NS_NewDomSelection(nsISelection **aDomSelection)
|
2000-05-11 08:25:43 +04:00
|
|
|
{
|
2000-11-29 03:13:00 +03:00
|
|
|
nsTypedSelection *rlist = new nsTypedSelection;
|
2000-05-11 08:25:43 +04:00
|
|
|
if (!rlist)
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
2000-09-14 15:45:01 +04:00
|
|
|
*aDomSelection = (nsISelection *)rlist;
|
2005-03-25 10:35:17 +03:00
|
|
|
NS_ADDREF(rlist);
|
2000-05-11 08:25:43 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
2000-03-22 02:58:02 +03:00
|
|
|
|
2000-04-14 15:21:19 +04:00
|
|
|
static PRInt8
|
2000-03-31 11:17:22 +04:00
|
|
|
GetIndexFromSelectionType(SelectionType aType)
|
|
|
|
{
|
|
|
|
switch (aType)
|
|
|
|
{
|
2000-04-27 11:37:12 +04:00
|
|
|
case nsISelectionController::SELECTION_NORMAL: return 0; break;
|
|
|
|
case nsISelectionController::SELECTION_SPELLCHECK: return 1; break;
|
|
|
|
case nsISelectionController::SELECTION_IME_RAWINPUT: return 2; break;
|
|
|
|
case nsISelectionController::SELECTION_IME_SELECTEDRAWTEXT: return 3; break;
|
|
|
|
case nsISelectionController::SELECTION_IME_CONVERTEDTEXT: return 4; break;
|
|
|
|
case nsISelectionController::SELECTION_IME_SELECTEDCONVERTEDTEXT: return 5; break;
|
2003-05-17 13:00:57 +04:00
|
|
|
case nsISelectionController::SELECTION_ACCESSIBILITY: return 6; break;
|
2000-03-31 11:17:22 +04:00
|
|
|
default:return -1;break;
|
|
|
|
}
|
2000-09-13 18:11:51 +04:00
|
|
|
/* NOTREACHED */
|
|
|
|
return 0;
|
2000-03-31 11:17:22 +04:00
|
|
|
}
|
|
|
|
|
2000-04-14 15:21:19 +04:00
|
|
|
static SelectionType
|
|
|
|
GetSelectionTypeFromIndex(PRInt8 aIndex)
|
|
|
|
{
|
|
|
|
switch (aIndex)
|
|
|
|
{
|
2000-04-27 11:37:12 +04:00
|
|
|
case 0: return nsISelectionController::SELECTION_NORMAL;break;
|
|
|
|
case 1: return nsISelectionController::SELECTION_SPELLCHECK;break;
|
|
|
|
case 2: return nsISelectionController::SELECTION_IME_RAWINPUT;break;
|
|
|
|
case 3: return nsISelectionController::SELECTION_IME_SELECTEDRAWTEXT;break;
|
|
|
|
case 4: return nsISelectionController::SELECTION_IME_CONVERTEDTEXT;break;
|
|
|
|
case 5: return nsISelectionController::SELECTION_IME_SELECTEDCONVERTEDTEXT;break;
|
2003-05-17 13:00:57 +04:00
|
|
|
case 6: return nsISelectionController::SELECTION_ACCESSIBILITY;break;
|
2000-04-14 15:21:19 +04:00
|
|
|
default:
|
2000-04-27 11:37:12 +04:00
|
|
|
return nsISelectionController::SELECTION_NORMAL;break;
|
2000-04-14 15:21:19 +04:00
|
|
|
}
|
2000-09-13 18:11:51 +04:00
|
|
|
/* NOTREACHED */
|
|
|
|
return 0;
|
2000-04-14 15:21:19 +04:00
|
|
|
}
|
|
|
|
|
2002-03-26 02:44:46 +03:00
|
|
|
//utility methods to check the content vs the limiter that will hold selection to a piece of the dom
|
|
|
|
PRBool
|
2006-04-26 06:01:07 +04:00
|
|
|
IsValidSelectionPoint(nsFrameSelection *aFrameSel, nsIDOMNode *aDomNode)
|
2002-03-26 02:44:46 +03:00
|
|
|
{
|
2006-04-26 06:01:07 +04:00
|
|
|
nsCOMPtr<nsIContent> passedContent = do_QueryInterface(aDomNode);
|
2002-03-26 02:44:46 +03:00
|
|
|
if (!passedContent)
|
|
|
|
return PR_FALSE;
|
2006-04-26 06:01:07 +04:00
|
|
|
return IsValidSelectionPoint(aFrameSel, passedContent);
|
2002-03-26 02:44:46 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
The limiter is used specifically for the text areas and textfields
|
|
|
|
In that case it is the DIV tag that is anonymously created for the text
|
|
|
|
areas/fields. Text nodes and BR nodes fall beneath it. In the case of a
|
|
|
|
BR node the limiter will be the parent and the offset will point before or
|
|
|
|
after the BR node. In the case of the text node the parent content is
|
|
|
|
the text node itself and the offset will be the exact character position.
|
|
|
|
The offset is not important to check for validity. Simply look at the
|
|
|
|
passed in content. If it equals the limiter then the selection point is valid.
|
|
|
|
If its parent it the limiter then the point is also valid. In the case of
|
|
|
|
NO limiter all points are valid since you are in a topmost iframe. (browser
|
|
|
|
or composer)
|
|
|
|
*/
|
|
|
|
PRBool
|
2006-04-26 06:01:07 +04:00
|
|
|
IsValidSelectionPoint(nsFrameSelection *aFrameSel, nsIContent *aContent)
|
2002-03-26 02:44:46 +03:00
|
|
|
{
|
|
|
|
if (!aFrameSel || !aContent)
|
|
|
|
return PR_FALSE;
|
|
|
|
if (aFrameSel)
|
|
|
|
{
|
2006-04-26 06:01:07 +04:00
|
|
|
nsCOMPtr<nsIContent> tLimiter = aFrameSel->GetLimiter();
|
2002-03-26 02:44:46 +03:00
|
|
|
if (tLimiter && tLimiter != aContent)
|
|
|
|
{
|
2005-11-21 01:05:24 +03:00
|
|
|
if (tLimiter != aContent->GetParent()) //if newfocus == the limiter. that's ok. but if not there and not parent bad
|
2002-03-26 02:44:46 +03:00
|
|
|
return PR_FALSE; //not in the right content. tLimiter said so
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return PR_TRUE;
|
|
|
|
}
|
2000-03-31 11:17:22 +04:00
|
|
|
|
2004-01-06 03:36:01 +03:00
|
|
|
|
|
|
|
NS_IMPL_ADDREF(nsSelectionIterator)
|
|
|
|
NS_IMPL_RELEASE(nsSelectionIterator)
|
|
|
|
|
|
|
|
NS_INTERFACE_MAP_BEGIN(nsSelectionIterator)
|
|
|
|
NS_INTERFACE_MAP_ENTRY(nsIEnumerator)
|
|
|
|
NS_INTERFACE_MAP_ENTRY(nsIBidirectionalEnumerator)
|
|
|
|
NS_INTERFACE_MAP_END_AGGREGATED(mDomSelection)
|
|
|
|
|
|
|
|
|
2000-03-22 02:58:02 +03:00
|
|
|
///////////BEGIN nsSelectionIterator methods
|
|
|
|
|
2000-11-29 03:13:00 +03:00
|
|
|
nsSelectionIterator::nsSelectionIterator(nsTypedSelection *aList)
|
2000-03-22 02:58:02 +03:00
|
|
|
:mIndex(0)
|
|
|
|
{
|
|
|
|
if (!aList)
|
|
|
|
{
|
2006-04-26 06:01:07 +04:00
|
|
|
NS_NOTREACHED("nsFrameSelection");
|
2000-03-22 02:58:02 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
mDomSelection = aList;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
nsSelectionIterator::~nsSelectionIterator()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
////////////END nsSelectionIterator methods
|
|
|
|
|
2006-04-26 06:01:07 +04:00
|
|
|
////////////BEGIN nsSelectionIterator methods
|
2000-03-22 02:58:02 +03:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsSelectionIterator::Next()
|
|
|
|
{
|
|
|
|
mIndex++;
|
2006-07-27 21:57:15 +04:00
|
|
|
PRInt32 cnt = mDomSelection->mRanges.Length();
|
2002-12-11 03:02:49 +03:00
|
|
|
if (mIndex < cnt)
|
2000-03-22 02:58:02 +03:00
|
|
|
return NS_OK;
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsSelectionIterator::Prev()
|
|
|
|
{
|
|
|
|
mIndex--;
|
|
|
|
if (mIndex >= 0 )
|
|
|
|
return NS_OK;
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsSelectionIterator::First()
|
|
|
|
{
|
|
|
|
if (!mDomSelection)
|
|
|
|
return NS_ERROR_NULL_POINTER;
|
|
|
|
mIndex = 0;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsSelectionIterator::Last()
|
|
|
|
{
|
|
|
|
if (!mDomSelection)
|
|
|
|
return NS_ERROR_NULL_POINTER;
|
2006-07-27 21:57:15 +04:00
|
|
|
mIndex = mDomSelection->mRanges.Length() - 1;
|
2000-03-22 02:58:02 +03:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsSelectionIterator::CurrentItem(nsISupports **aItem)
|
|
|
|
{
|
|
|
|
if (!aItem)
|
|
|
|
return NS_ERROR_NULL_POINTER;
|
2002-12-11 03:02:49 +03:00
|
|
|
|
2006-07-27 21:57:15 +04:00
|
|
|
if (mIndex < 0 || mIndex >= (PRInt32)mDomSelection->mRanges.Length()) {
|
2002-12-11 03:02:49 +03:00
|
|
|
return NS_ERROR_FAILURE;
|
2000-03-22 02:58:02 +03:00
|
|
|
}
|
2002-12-11 03:02:49 +03:00
|
|
|
|
2006-07-27 21:57:15 +04:00
|
|
|
return CallQueryInterface(mDomSelection->mRanges[mIndex].mRange,
|
2002-12-11 03:02:49 +03:00
|
|
|
aItem);
|
2000-03-22 02:58:02 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsSelectionIterator::CurrentItem(nsIDOMRange **aItem)
|
|
|
|
{
|
|
|
|
if (!aItem)
|
|
|
|
return NS_ERROR_NULL_POINTER;
|
2006-07-27 21:57:15 +04:00
|
|
|
if (mIndex < 0 || mIndex >= (PRInt32)mDomSelection->mRanges.Length()) {
|
2002-12-11 03:02:49 +03:00
|
|
|
return NS_ERROR_FAILURE;
|
2000-03-22 02:58:02 +03:00
|
|
|
}
|
2002-12-11 03:02:49 +03:00
|
|
|
|
2006-07-27 21:57:15 +04:00
|
|
|
*aItem = mDomSelection->mRanges[mIndex].mRange;
|
2002-12-11 03:02:49 +03:00
|
|
|
NS_IF_ADDREF(*aItem);
|
|
|
|
return NS_OK;
|
2000-03-22 02:58:02 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsSelectionIterator::IsDone()
|
|
|
|
{
|
2006-07-27 21:57:15 +04:00
|
|
|
PRInt32 cnt = mDomSelection->mRanges.Length();
|
2002-12-11 03:02:49 +03:00
|
|
|
if (mIndex >= 0 && mIndex < cnt) {
|
2000-03-22 02:58:02 +03:00
|
|
|
return NS_ENUMERATOR_FALSE;
|
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-04-26 06:01:07 +04:00
|
|
|
////////////END nsSelectionIterator methods
|
2000-03-22 02:58:02 +03:00
|
|
|
|
|
|
|
#ifdef XP_MAC
|
|
|
|
#pragma mark -
|
|
|
|
#endif
|
|
|
|
|
2006-04-26 06:01:07 +04:00
|
|
|
////////////BEGIN nsFrameSelection methods
|
2000-03-22 02:58:02 +03:00
|
|
|
|
2006-04-26 06:01:07 +04:00
|
|
|
nsFrameSelection::nsFrameSelection()
|
2007-03-19 13:23:29 +03:00
|
|
|
: mScrollableViewProvider(nsnull),
|
|
|
|
mDelayedMouseEvent(PR_FALSE, 0, nsnull, nsMouseEvent::eReal)
|
2000-03-22 02:58:02 +03:00
|
|
|
{
|
|
|
|
PRInt32 i;
|
2000-04-27 11:37:12 +04:00
|
|
|
for (i = 0;i<nsISelectionController::NUM_SELECTIONTYPES;i++){
|
2000-03-22 02:58:02 +03:00
|
|
|
mDomSelections[i] = nsnull;
|
|
|
|
}
|
2000-04-27 11:37:12 +04:00
|
|
|
for (i = 0;i<nsISelectionController::NUM_SELECTIONTYPES;i++){
|
2000-11-29 03:13:00 +03:00
|
|
|
mDomSelections[i] = new nsTypedSelection(this);
|
2000-03-22 02:58:02 +03:00
|
|
|
if (!mDomSelections[i])
|
|
|
|
return;
|
2005-03-25 10:35:17 +03:00
|
|
|
NS_ADDREF(mDomSelections[i]);
|
2000-04-14 15:21:19 +04:00
|
|
|
mDomSelections[i]->SetType(GetSelectionTypeFromIndex(i));
|
2000-03-22 02:58:02 +03:00
|
|
|
}
|
|
|
|
mBatching = 0;
|
|
|
|
mChangesDuringBatching = PR_FALSE;
|
|
|
|
mNotifyFrames = PR_TRUE;
|
2000-05-02 07:44:17 +04:00
|
|
|
mLimiter = nsnull; //no default limiter.
|
2002-08-30 05:32:11 +04:00
|
|
|
|
|
|
|
mMouseDoubleDownState = PR_FALSE;
|
|
|
|
|
2000-03-22 02:58:02 +03:00
|
|
|
mHint = HINTLEFT;
|
2006-08-08 09:14:52 +04:00
|
|
|
#ifdef IBMBIDI
|
|
|
|
mCaretBidiLevel = BIDI_LEVEL_UNDEFINED;
|
|
|
|
#endif
|
2002-03-22 18:25:08 +03:00
|
|
|
mDragSelectingCells = PR_FALSE;
|
2000-05-16 07:03:13 +04:00
|
|
|
mSelectingTableCellMode = 0;
|
2000-03-24 05:52:07 +03:00
|
|
|
mSelectedCellIndex = 0;
|
2000-06-03 03:05:06 +04:00
|
|
|
|
2000-06-07 03:14:42 +04:00
|
|
|
// Check to see if the autocopy pref is enabled
|
|
|
|
// and add the autocopy listener if it is
|
2004-04-30 03:34:19 +04:00
|
|
|
if (nsContentUtils::GetBoolPref("clipboard.autocopy")) {
|
2005-02-01 02:47:26 +03:00
|
|
|
nsAutoCopyListener *autoCopy = nsAutoCopyListener::GetInstance();
|
2004-04-30 03:34:19 +04:00
|
|
|
|
2005-02-01 02:47:26 +03:00
|
|
|
if (autoCopy) {
|
2004-04-30 03:34:19 +04:00
|
|
|
PRInt8 index =
|
|
|
|
GetIndexFromSelectionType(nsISelectionController::SELECTION_NORMAL);
|
|
|
|
if (mDomSelections[index]) {
|
2005-02-01 02:47:26 +03:00
|
|
|
autoCopy->Listen(mDomSelections[index]);
|
2000-06-07 03:14:42 +04:00
|
|
|
}
|
|
|
|
}
|
2000-04-14 15:21:19 +04:00
|
|
|
}
|
2000-06-07 03:14:42 +04:00
|
|
|
|
2000-05-11 08:25:43 +04:00
|
|
|
mDisplaySelection = nsISelectionController::SELECTION_OFF;
|
2000-05-26 00:04:02 +04:00
|
|
|
|
|
|
|
mDelayedMouseEventValid = PR_FALSE;
|
2003-04-04 02:32:50 +04:00
|
|
|
mSelectionChangeReason = nsISelectionListener::NO_REASON;
|
2000-03-22 02:58:02 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-04-26 06:01:07 +04:00
|
|
|
nsFrameSelection::~nsFrameSelection()
|
2000-03-22 02:58:02 +03:00
|
|
|
{
|
|
|
|
PRInt32 i;
|
2000-04-27 11:37:12 +04:00
|
|
|
for (i = 0;i<nsISelectionController::NUM_SELECTIONTYPES;i++){
|
2006-04-14 04:28:22 +04:00
|
|
|
if (mDomSelections[i]) {
|
|
|
|
mDomSelections[i]->DetachFromPresentation();
|
|
|
|
NS_RELEASE(mDomSelections[i]);
|
|
|
|
}
|
2000-03-22 02:58:02 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-04-26 06:01:07 +04:00
|
|
|
NS_IMPL_ISUPPORTS1(nsFrameSelection, nsFrameSelection)
|
2000-03-22 02:58:02 +03:00
|
|
|
|
|
|
|
|
2001-02-05 18:43:46 +03:00
|
|
|
nsresult
|
2006-04-26 06:01:07 +04:00
|
|
|
nsFrameSelection::FetchDesiredX(nscoord &aDesiredX) //the x position requested by the Key Handling for up down
|
2000-03-22 02:58:02 +03:00
|
|
|
{
|
2004-09-01 09:16:00 +04:00
|
|
|
if (!mShell)
|
2000-03-22 02:58:02 +03:00
|
|
|
{
|
|
|
|
NS_ASSERTION(0,"fetch desired X failed\n");
|
2001-02-05 18:43:46 +03:00
|
|
|
return NS_ERROR_FAILURE;
|
2000-03-22 02:58:02 +03:00
|
|
|
}
|
|
|
|
if (mDesiredXSet)
|
2001-02-05 18:43:46 +03:00
|
|
|
{
|
|
|
|
aDesiredX = mDesiredX;
|
|
|
|
return NS_OK;
|
2000-03-22 02:58:02 +03:00
|
|
|
}
|
2001-02-05 18:43:46 +03:00
|
|
|
|
|
|
|
nsCOMPtr<nsICaret> caret;
|
2004-09-01 09:16:00 +04:00
|
|
|
nsresult result = mShell->GetCaret(getter_AddRefs(caret));
|
2001-02-05 18:43:46 +03:00
|
|
|
if (NS_FAILED(result))
|
|
|
|
return result;
|
|
|
|
if (!caret)
|
|
|
|
return NS_ERROR_NULL_POINTER;
|
|
|
|
|
|
|
|
nsRect coord;
|
|
|
|
PRBool collapsed;
|
|
|
|
PRInt8 index = GetIndexFromSelectionType(nsISelectionController::SELECTION_NORMAL);
|
|
|
|
result = caret->SetCaretDOMSelection(mDomSelections[index]);
|
|
|
|
if (NS_FAILED(result))
|
|
|
|
return result;
|
|
|
|
|
2002-08-27 00:55:30 +04:00
|
|
|
result = caret->GetCaretCoordinates(nsICaret::eClosestViewCoordinates, mDomSelections[index], &coord, &collapsed, nsnull);
|
2001-02-05 18:43:46 +03:00
|
|
|
if (NS_FAILED(result))
|
|
|
|
return result;
|
|
|
|
|
|
|
|
aDesiredX = coord.x;
|
|
|
|
return NS_OK;
|
2000-03-22 02:58:02 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void
|
2006-04-26 06:01:07 +04:00
|
|
|
nsFrameSelection::InvalidateDesiredX() //do not listen to mDesiredX you must get another.
|
2000-03-22 02:58:02 +03:00
|
|
|
{
|
|
|
|
mDesiredXSet = PR_FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void
|
2006-04-26 06:01:07 +04:00
|
|
|
nsFrameSelection::SetDesiredX(nscoord aX) //set the mDesiredX
|
2000-03-22 02:58:02 +03:00
|
|
|
{
|
|
|
|
mDesiredX = aX;
|
|
|
|
mDesiredXSet = PR_TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
2006-04-26 06:01:07 +04:00
|
|
|
nsFrameSelection::GetRootForContentSubtree(nsIContent *aContent,
|
|
|
|
nsIContent **aParent)
|
2000-03-22 02:58:02 +03:00
|
|
|
{
|
|
|
|
// This method returns the root of the sub-tree containing aContent.
|
|
|
|
// We do this by searching up through the parent hierarchy, and stopping
|
|
|
|
// when there are no more parents, or we hit a situation where the
|
|
|
|
// parent/child relationship becomes invalid.
|
|
|
|
//
|
|
|
|
// An example of an invalid parent/child relationship is anonymous content.
|
2005-11-21 01:05:24 +03:00
|
|
|
// Anonymous content has a pointer to its parent, but it is not listed
|
|
|
|
// as a child of its parent. In this case, the anonymous content would
|
2000-03-22 02:58:02 +03:00
|
|
|
// be considered the root of the subtree.
|
|
|
|
|
|
|
|
if (!aContent || !aParent)
|
|
|
|
return NS_ERROR_NULL_POINTER;
|
|
|
|
|
|
|
|
*aParent = 0;
|
|
|
|
|
2003-07-29 01:09:56 +04:00
|
|
|
nsIContent* child = aContent;
|
2000-03-22 02:58:02 +03:00
|
|
|
|
|
|
|
while (child)
|
|
|
|
{
|
2003-07-29 01:09:56 +04:00
|
|
|
nsIContent* parent = child->GetParent();
|
2000-03-22 02:58:02 +03:00
|
|
|
|
|
|
|
if (!parent)
|
|
|
|
break;
|
|
|
|
|
2003-09-27 08:18:26 +04:00
|
|
|
PRUint32 childCount = parent->GetChildCount();
|
2000-03-22 02:58:02 +03:00
|
|
|
|
|
|
|
if (childCount < 1)
|
|
|
|
break;
|
|
|
|
|
2003-09-27 08:18:26 +04:00
|
|
|
PRInt32 childIndex = parent->IndexOf(child);
|
2000-03-22 02:58:02 +03:00
|
|
|
|
2003-09-27 08:18:26 +04:00
|
|
|
if (childIndex < 0 || ((PRUint32)childIndex) >= childCount)
|
2000-03-22 02:58:02 +03:00
|
|
|
break;
|
|
|
|
|
|
|
|
child = parent;
|
|
|
|
}
|
|
|
|
|
2003-07-29 01:09:56 +04:00
|
|
|
NS_IF_ADDREF(*aParent = child);
|
2000-03-22 02:58:02 +03:00
|
|
|
|
2003-09-27 08:18:26 +04:00
|
|
|
return NS_OK;
|
2000-03-22 02:58:02 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
2006-04-26 06:01:07 +04:00
|
|
|
nsFrameSelection::ConstrainFrameAndPointToAnchorSubtree(nsIFrame *aFrame,
|
|
|
|
nsPoint& aPoint,
|
|
|
|
nsIFrame **aRetFrame,
|
|
|
|
nsPoint& aRetPoint)
|
2000-03-22 02:58:02 +03:00
|
|
|
{
|
|
|
|
//
|
|
|
|
// The whole point of this method is to return a frame and point that
|
|
|
|
// that lie within the same valid subtree as the anchor node's frame,
|
|
|
|
// for use with the method GetContentAndOffsetsFromPoint().
|
|
|
|
//
|
|
|
|
// A valid subtree is defined to be one where all the content nodes in
|
|
|
|
// the tree have a valid parent-child relationship.
|
|
|
|
//
|
|
|
|
// If the anchor frame and aFrame are in the same subtree, aFrame will
|
|
|
|
// be returned in aRetFrame. If they are in different subtrees, we
|
|
|
|
// return the frame for the root of the subtree.
|
|
|
|
//
|
|
|
|
|
|
|
|
if (!aFrame || !aRetFrame)
|
|
|
|
return NS_ERROR_NULL_POINTER;
|
|
|
|
|
|
|
|
*aRetFrame = aFrame;
|
|
|
|
aRetPoint = aPoint;
|
|
|
|
|
|
|
|
//
|
|
|
|
// Get the frame and content for the selection's anchor point!
|
|
|
|
//
|
|
|
|
|
|
|
|
nsresult result;
|
|
|
|
nsCOMPtr<nsIDOMNode> anchorNode;
|
|
|
|
PRInt32 anchorOffset = 0;
|
|
|
|
PRInt32 anchorFrameOffset = 0;
|
|
|
|
|
2000-04-27 11:37:12 +04:00
|
|
|
PRInt8 index = GetIndexFromSelectionType(nsISelectionController::SELECTION_NORMAL);
|
2000-03-31 11:17:22 +04:00
|
|
|
if (! mDomSelections[index])
|
2000-03-22 02:58:02 +03:00
|
|
|
return NS_ERROR_NULL_POINTER;
|
|
|
|
|
2000-03-31 11:17:22 +04:00
|
|
|
result = mDomSelections[index]->GetAnchorNode(getter_AddRefs(anchorNode));
|
2000-03-22 02:58:02 +03:00
|
|
|
|
|
|
|
if (NS_FAILED(result))
|
|
|
|
return result;
|
|
|
|
|
|
|
|
if (!anchorNode)
|
|
|
|
return NS_OK;
|
|
|
|
|
2000-03-31 11:17:22 +04:00
|
|
|
result = mDomSelections[index]->GetAnchorOffset(&anchorOffset);
|
2000-03-22 02:58:02 +03:00
|
|
|
|
|
|
|
if (NS_FAILED(result))
|
|
|
|
return result;
|
|
|
|
|
|
|
|
nsIFrame *anchorFrame = 0;
|
|
|
|
nsCOMPtr<nsIContent> anchorContent = do_QueryInterface(anchorNode);
|
|
|
|
|
|
|
|
if (!anchorContent)
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
|
2006-04-26 06:01:07 +04:00
|
|
|
anchorFrame = GetFrameForNodeOffset(anchorContent, anchorOffset,
|
|
|
|
mHint, &anchorFrameOffset);
|
2000-03-22 02:58:02 +03:00
|
|
|
|
|
|
|
//
|
|
|
|
// Now find the root of the subtree containing the anchor's content.
|
|
|
|
//
|
|
|
|
|
|
|
|
nsCOMPtr<nsIContent> anchorRoot;
|
|
|
|
result = GetRootForContentSubtree(anchorContent, getter_AddRefs(anchorRoot));
|
|
|
|
|
|
|
|
if (NS_FAILED(result))
|
|
|
|
return result;
|
|
|
|
|
|
|
|
//
|
|
|
|
// Now find the root of the subtree containing aFrame's content.
|
|
|
|
//
|
|
|
|
|
2003-08-06 07:07:12 +04:00
|
|
|
nsIContent* content = aFrame->GetContent();
|
2000-03-22 02:58:02 +03:00
|
|
|
|
|
|
|
if (content)
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsIContent> contentRoot;
|
|
|
|
|
|
|
|
result = GetRootForContentSubtree(content, getter_AddRefs(contentRoot));
|
|
|
|
|
|
|
|
if (anchorRoot == contentRoot)
|
|
|
|
{
|
|
|
|
//
|
|
|
|
// The anchor and AFrame's root are the same. There
|
|
|
|
// is no need to constrain, simply return aFrame.
|
|
|
|
//
|
|
|
|
*aRetFrame = aFrame;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// aFrame's root does not match the anchor's root, or there is no
|
|
|
|
// content associated with aFrame. Just return the primary frame
|
|
|
|
// for the anchor's root. We'll let GetContentAndOffsetsFromPoint()
|
|
|
|
// find the closest frame aPoint.
|
|
|
|
//
|
|
|
|
|
2005-08-23 02:24:29 +04:00
|
|
|
*aRetFrame = mShell->GetPrimaryFrameFor(anchorRoot);
|
2000-03-22 02:58:02 +03:00
|
|
|
|
|
|
|
if (! *aRetFrame)
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
|
|
|
|
//
|
|
|
|
// Now make sure that aRetPoint is converted to the same coordinate
|
|
|
|
// system used by aRetFrame.
|
|
|
|
//
|
|
|
|
|
2004-11-03 19:16:57 +03:00
|
|
|
aRetPoint = aPoint + aFrame->GetOffsetTo(*aRetFrame);
|
2000-03-22 02:58:02 +03:00
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2006-08-08 09:14:52 +04:00
|
|
|
#ifdef IBMBIDI
|
|
|
|
void
|
|
|
|
nsFrameSelection::SetCaretBidiLevel(PRUint8 aLevel)
|
|
|
|
{
|
|
|
|
// If the current level is undefined, we have just inserted new text.
|
|
|
|
// In this case, we don't want to reset the keyboard language
|
|
|
|
PRBool afterInsert = mCaretBidiLevel & BIDI_LEVEL_UNDEFINED;
|
|
|
|
mCaretBidiLevel = aLevel;
|
|
|
|
|
|
|
|
nsIBidiKeyboard* bidiKeyboard = nsContentUtils::GetBidiKeyboard();
|
|
|
|
if (bidiKeyboard && !afterInsert)
|
|
|
|
bidiKeyboard->SetLangFromBidiLevel(aLevel);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
PRUint8
|
|
|
|
nsFrameSelection::GetCaretBidiLevel()
|
|
|
|
{
|
|
|
|
return mCaretBidiLevel;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsFrameSelection::UndefineCaretBidiLevel()
|
|
|
|
{
|
|
|
|
mCaretBidiLevel |= BIDI_LEVEL_UNDEFINED;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2000-03-22 02:58:02 +03:00
|
|
|
#ifdef XP_MAC
|
|
|
|
#pragma mark -
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef PRINT_RANGE
|
|
|
|
void printRange(nsIDOMRange *aDomRange)
|
|
|
|
{
|
|
|
|
if (!aDomRange)
|
|
|
|
{
|
2000-10-29 02:17:53 +04:00
|
|
|
printf("NULL nsIDOMRange\n");
|
2000-03-22 02:58:02 +03:00
|
|
|
}
|
|
|
|
nsCOMPtr<nsIDOMNode> startNode;
|
|
|
|
nsCOMPtr<nsIDOMNode> endNode;
|
|
|
|
PRInt32 startOffset;
|
|
|
|
PRInt32 endOffset;
|
|
|
|
aDomRange->GetStartParent(getter_AddRefs(startNode));
|
|
|
|
aDomRange->GetStartOffset(&startOffset);
|
|
|
|
aDomRange->GetEndParent(getter_AddRefs(endNode));
|
|
|
|
aDomRange->GetEndOffset(&endOffset);
|
|
|
|
|
2000-10-29 02:17:53 +04:00
|
|
|
printf("range: 0x%lx\t start: 0x%lx %ld, \t end: 0x%lx,%ld\n",
|
2000-03-22 02:58:02 +03:00
|
|
|
(unsigned long)aDomRange,
|
|
|
|
(unsigned long)(nsIDOMNode*)startNode, (long)startOffset,
|
|
|
|
(unsigned long)(nsIDOMNode*)endNode, (long)endOffset);
|
|
|
|
|
|
|
|
}
|
|
|
|
#endif /* PRINT_RANGE */
|
|
|
|
|
2003-11-19 04:20:56 +03:00
|
|
|
static
|
|
|
|
nsIAtom *GetTag(nsIDOMNode *aNode)
|
2000-03-22 02:58:02 +03:00
|
|
|
{
|
2003-11-19 04:20:56 +03:00
|
|
|
nsCOMPtr<nsIContent> content = do_QueryInterface(aNode);
|
|
|
|
if (!content)
|
2000-03-22 02:58:02 +03:00
|
|
|
{
|
2003-11-19 04:20:56 +03:00
|
|
|
NS_NOTREACHED("bad node passed to GetTag()");
|
|
|
|
return nsnull;
|
2000-03-22 02:58:02 +03:00
|
|
|
}
|
|
|
|
|
2003-11-19 04:20:56 +03:00
|
|
|
return content->Tag();
|
2000-03-22 02:58:02 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
ParentOffset(nsIDOMNode *aNode, nsIDOMNode **aParent, PRInt32 *aChildOffset)
|
|
|
|
{
|
|
|
|
if (!aNode || !aParent || !aChildOffset)
|
|
|
|
return NS_ERROR_NULL_POINTER;
|
2003-09-27 08:18:26 +04:00
|
|
|
|
|
|
|
nsCOMPtr<nsIContent> content = do_QueryInterface(aNode);
|
|
|
|
if (content)
|
2000-03-22 02:58:02 +03:00
|
|
|
{
|
2003-07-29 01:09:56 +04:00
|
|
|
nsIContent* parent = content->GetParent();
|
|
|
|
if (parent)
|
2000-03-22 02:58:02 +03:00
|
|
|
{
|
2003-09-27 08:18:26 +04:00
|
|
|
*aChildOffset = parent->IndexOf(content);
|
|
|
|
|
|
|
|
return CallQueryInterface(parent, aParent);
|
2000-03-22 02:58:02 +03:00
|
|
|
}
|
|
|
|
}
|
2003-09-27 08:18:26 +04:00
|
|
|
|
|
|
|
return NS_OK;
|
2000-03-22 02:58:02 +03:00
|
|
|
}
|
|
|
|
|
2002-03-22 18:25:08 +03:00
|
|
|
nsIDOMNode *
|
|
|
|
GetCellParent(nsIDOMNode *aDomNode)
|
|
|
|
{
|
|
|
|
if (!aDomNode)
|
|
|
|
return 0;
|
|
|
|
nsCOMPtr<nsIDOMNode> parent(aDomNode);
|
|
|
|
nsCOMPtr<nsIDOMNode> current(aDomNode);
|
|
|
|
PRInt32 childOffset;
|
2003-11-19 04:20:56 +03:00
|
|
|
nsIAtom *tag;
|
2002-03-22 18:25:08 +03:00
|
|
|
// Start with current node and look for a table cell
|
|
|
|
while(current)
|
|
|
|
{
|
|
|
|
tag = GetTag(current);
|
2006-12-26 20:47:52 +03:00
|
|
|
if (tag == nsGkAtoms::td || tag == nsGkAtoms::th)
|
2002-03-22 18:25:08 +03:00
|
|
|
return current;
|
|
|
|
if (NS_FAILED(ParentOffset(current,getter_AddRefs(parent),&childOffset)) || !parent)
|
|
|
|
return 0;
|
|
|
|
current = parent;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
2000-03-22 02:58:02 +03:00
|
|
|
|
|
|
|
|
2006-04-26 06:01:07 +04:00
|
|
|
void
|
|
|
|
nsFrameSelection::Init(nsIPresShell *aShell, nsIContent *aLimiter)
|
2000-03-22 02:58:02 +03:00
|
|
|
{
|
2004-09-01 09:16:00 +04:00
|
|
|
mShell = aShell;
|
2000-03-22 02:58:02 +03:00
|
|
|
mMouseDownState = PR_FALSE;
|
|
|
|
mDesiredXSet = PR_FALSE;
|
2000-05-02 07:44:17 +04:00
|
|
|
mLimiter = aLimiter;
|
2006-04-08 18:45:48 +04:00
|
|
|
mCaretMovementStyle = nsContentUtils::GetIntPref("bidi.edit.caret_movement_style", 2);
|
2000-03-22 02:58:02 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
2006-04-26 06:01:07 +04:00
|
|
|
nsFrameSelection::MoveCaret(PRUint32 aKeycode,
|
|
|
|
PRBool aContinueSelection,
|
|
|
|
nsSelectionAmount aAmount)
|
2000-03-22 02:58:02 +03:00
|
|
|
{
|
2004-09-01 09:16:00 +04:00
|
|
|
nsPresContext *context = mShell->GetPresContext();
|
|
|
|
if (!context)
|
2004-09-01 22:02:04 +04:00
|
|
|
return NS_ERROR_FAILURE;
|
2000-03-22 02:58:02 +03:00
|
|
|
|
|
|
|
nsCOMPtr<nsIDOMNode> weakNodeUsed;
|
|
|
|
PRInt32 offsetused = 0;
|
|
|
|
|
|
|
|
PRBool isCollapsed;
|
2000-04-28 17:58:08 +04:00
|
|
|
nscoord desiredX = 0; //we must keep this around and revalidate it when its just UP/DOWN
|
2000-03-22 02:58:02 +03:00
|
|
|
|
2000-04-27 11:37:12 +04:00
|
|
|
PRInt8 index = GetIndexFromSelectionType(nsISelectionController::SELECTION_NORMAL);
|
2004-09-01 09:16:00 +04:00
|
|
|
nsresult result = mDomSelections[index]->GetIsCollapsed(&isCollapsed);
|
2000-03-22 02:58:02 +03:00
|
|
|
if (NS_FAILED(result))
|
|
|
|
return result;
|
|
|
|
if (aKeycode == nsIDOMKeyEvent::DOM_VK_UP || aKeycode == nsIDOMKeyEvent::DOM_VK_DOWN)
|
|
|
|
{
|
2001-02-05 18:43:46 +03:00
|
|
|
result = FetchDesiredX(desiredX);
|
|
|
|
if (NS_FAILED(result))
|
|
|
|
return result;
|
2000-03-22 02:58:02 +03:00
|
|
|
SetDesiredX(desiredX);
|
|
|
|
}
|
|
|
|
|
2005-10-17 04:51:46 +04:00
|
|
|
PRInt32 caretStyle = nsContentUtils::GetIntPref("layout.selection.caret_style", 0);
|
|
|
|
#ifdef XP_MACOSX
|
|
|
|
if (caretStyle == 0) {
|
|
|
|
caretStyle = 2; // put caret at the selection edge in the |aKeycode| direction
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
if (!isCollapsed && !aContinueSelection && caretStyle == 2) {
|
|
|
|
switch (aKeycode){
|
|
|
|
case nsIDOMKeyEvent::DOM_VK_LEFT :
|
|
|
|
case nsIDOMKeyEvent::DOM_VK_UP :
|
|
|
|
if (mDomSelections[index]->GetDirection() == eDirPrevious) { //f,a
|
|
|
|
offsetused = mDomSelections[index]->FetchFocusOffset();
|
|
|
|
weakNodeUsed = mDomSelections[index]->FetchFocusNode();
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
offsetused = mDomSelections[index]->FetchAnchorOffset();
|
|
|
|
weakNodeUsed = mDomSelections[index]->FetchAnchorNode();
|
|
|
|
}
|
|
|
|
result = mDomSelections[index]->Collapse(weakNodeUsed, offsetused);
|
|
|
|
mHint = HINTRIGHT;
|
2006-11-09 19:37:10 +03:00
|
|
|
mDomSelections[index]->ScrollIntoView();
|
2005-10-17 04:51:46 +04:00
|
|
|
return NS_OK;
|
|
|
|
|
|
|
|
case nsIDOMKeyEvent::DOM_VK_RIGHT :
|
|
|
|
case nsIDOMKeyEvent::DOM_VK_DOWN :
|
|
|
|
if (mDomSelections[index]->GetDirection() == eDirPrevious) { //f,a
|
|
|
|
offsetused = mDomSelections[index]->FetchAnchorOffset();
|
|
|
|
weakNodeUsed = mDomSelections[index]->FetchAnchorNode();
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
offsetused = mDomSelections[index]->FetchFocusOffset();
|
|
|
|
weakNodeUsed = mDomSelections[index]->FetchFocusNode();
|
|
|
|
}
|
|
|
|
result = mDomSelections[index]->Collapse(weakNodeUsed, offsetused);
|
|
|
|
mHint = HINTLEFT;
|
2006-11-09 19:37:10 +03:00
|
|
|
mDomSelections[index]->ScrollIntoView();
|
2005-10-17 04:51:46 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-07-18 11:28:38 +04:00
|
|
|
PRBool visualMovement =
|
|
|
|
(aKeycode == nsIDOMKeyEvent::DOM_VK_BACK_SPACE ||
|
2006-08-03 10:24:11 +04:00
|
|
|
aKeycode == nsIDOMKeyEvent::DOM_VK_DELETE ||
|
|
|
|
aKeycode == nsIDOMKeyEvent::DOM_VK_HOME ||
|
|
|
|
aKeycode == nsIDOMKeyEvent::DOM_VK_END) ?
|
|
|
|
PR_FALSE : // Delete operations and home/end are always logical
|
2006-07-18 11:28:38 +04:00
|
|
|
mCaretMovementStyle == 1 || (mCaretMovementStyle == 2 && !aContinueSelection);
|
|
|
|
|
2006-08-30 13:26:39 +04:00
|
|
|
nsIFrame *frame;
|
|
|
|
result = mDomSelections[index]->GetPrimaryFrameForFocusNode(&frame, &offsetused, visualMovement);
|
|
|
|
|
|
|
|
if (NS_FAILED(result) || !frame)
|
|
|
|
return result?result:NS_ERROR_FAILURE;
|
|
|
|
|
|
|
|
nsPeekOffsetStruct pos;
|
2002-04-16 06:39:54 +04:00
|
|
|
//set data using mLimiter to stop on scroll views. If we have a limiter then we stop peeking
|
|
|
|
//when we hit scrollable views. If no limiter then just let it go ahead
|
2006-07-13 10:06:29 +04:00
|
|
|
pos.SetData(aAmount, eDirPrevious, offsetused, desiredX,
|
|
|
|
PR_TRUE, mLimiter != nsnull, PR_TRUE, visualMovement);
|
2002-04-16 06:39:54 +04:00
|
|
|
|
2006-03-23 11:30:30 +03:00
|
|
|
nsBidiLevel baseLevel = nsBidiPresUtils::GetFrameBaseLevel(frame);
|
|
|
|
|
2001-06-13 04:00:55 +04:00
|
|
|
HINT tHint(mHint); //temporary variable so we dont set mHint until it is necessary
|
2000-03-22 02:58:02 +03:00
|
|
|
switch (aKeycode){
|
|
|
|
case nsIDOMKeyEvent::DOM_VK_RIGHT :
|
|
|
|
InvalidateDesiredX();
|
2006-03-23 11:30:30 +03:00
|
|
|
pos.mDirection = (baseLevel & 1) ? eDirPrevious : eDirNext;
|
2000-03-22 02:58:02 +03:00
|
|
|
break;
|
2006-07-18 11:28:38 +04:00
|
|
|
case nsIDOMKeyEvent::DOM_VK_LEFT :
|
2000-03-22 02:58:02 +03:00
|
|
|
InvalidateDesiredX();
|
2006-03-23 11:30:30 +03:00
|
|
|
pos.mDirection = (baseLevel & 1) ? eDirNext : eDirPrevious;
|
2000-03-22 02:58:02 +03:00
|
|
|
break;
|
2006-07-18 11:28:38 +04:00
|
|
|
case nsIDOMKeyEvent::DOM_VK_DELETE :
|
|
|
|
InvalidateDesiredX();
|
|
|
|
pos.mDirection = eDirNext;
|
|
|
|
break;
|
|
|
|
case nsIDOMKeyEvent::DOM_VK_BACK_SPACE :
|
|
|
|
InvalidateDesiredX();
|
|
|
|
pos.mDirection = eDirPrevious;
|
|
|
|
break;
|
2000-03-22 02:58:02 +03:00
|
|
|
case nsIDOMKeyEvent::DOM_VK_DOWN :
|
|
|
|
pos.mAmount = eSelectLine;
|
2006-07-18 11:28:38 +04:00
|
|
|
pos.mDirection = eDirNext;
|
2000-03-22 02:58:02 +03:00
|
|
|
break;
|
|
|
|
case nsIDOMKeyEvent::DOM_VK_UP :
|
|
|
|
pos.mAmount = eSelectLine;
|
2006-07-18 11:28:38 +04:00
|
|
|
pos.mDirection = eDirPrevious;
|
2000-03-22 02:58:02 +03:00
|
|
|
break;
|
|
|
|
case nsIDOMKeyEvent::DOM_VK_HOME :
|
|
|
|
InvalidateDesiredX();
|
|
|
|
pos.mAmount = eSelectBeginLine;
|
|
|
|
break;
|
|
|
|
case nsIDOMKeyEvent::DOM_VK_END :
|
|
|
|
InvalidateDesiredX();
|
|
|
|
pos.mAmount = eSelectEndLine;
|
2006-07-18 11:28:38 +04:00
|
|
|
break;
|
2000-03-22 02:58:02 +03:00
|
|
|
default :return NS_ERROR_FAILURE;
|
|
|
|
}
|
2006-07-13 10:06:29 +04:00
|
|
|
PostReason(nsISelectionListener::KEYPRESS_REASON);
|
2006-09-12 00:43:01 +04:00
|
|
|
if (NS_SUCCEEDED(result = frame->PeekOffset(&pos)) && pos.mResultContent)
|
2000-03-22 02:58:02 +03:00
|
|
|
{
|
2006-03-28 22:33:37 +04:00
|
|
|
nsIFrame *theFrame;
|
|
|
|
PRInt32 currentOffset, frameStart, frameEnd;
|
2001-03-21 04:16:22 +03:00
|
|
|
|
2006-07-18 11:28:38 +04:00
|
|
|
if (aAmount == eSelectCharacter || aAmount == eSelectWord)
|
2006-03-28 22:33:37 +04:00
|
|
|
{
|
2006-07-13 10:06:29 +04:00
|
|
|
// For left/right, PeekOffset() sets pos.mResultFrame correctly, but does not set pos.mAttachForward,
|
2006-03-28 22:33:37 +04:00
|
|
|
// so determine the hint here based on the result frame and offset:
|
|
|
|
// If we're at the end of a text frame, set the hint to HINTLEFT to indicate that we
|
|
|
|
// want the caret displayed at the end of this frame, not at the beginning of the next one.
|
|
|
|
theFrame = pos.mResultFrame;
|
|
|
|
theFrame->GetOffsets(frameStart, frameEnd);
|
|
|
|
currentOffset = pos.mContentOffset;
|
|
|
|
if (frameEnd == currentOffset && !(frameStart == 0 && frameEnd == 0))
|
|
|
|
tHint = HINTLEFT;
|
|
|
|
else
|
|
|
|
tHint = HINTRIGHT;
|
|
|
|
} else {
|
|
|
|
// For up/down and home/end, pos.mResultFrame might not be set correctly, or not at all.
|
|
|
|
// In these cases, get the frame based on the content and hint returned by PeekOffset().
|
2006-07-13 10:06:29 +04:00
|
|
|
tHint = (HINT)pos.mAttachForward;
|
2006-04-26 06:01:07 +04:00
|
|
|
theFrame = GetFrameForNodeOffset(pos.mResultContent, pos.mContentOffset,
|
|
|
|
tHint, ¤tOffset);
|
|
|
|
if (!theFrame)
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
|
2001-03-21 04:16:22 +03:00
|
|
|
theFrame->GetOffsets(frameStart, frameEnd);
|
2006-03-28 22:33:37 +04:00
|
|
|
}
|
2001-03-21 04:16:22 +03:00
|
|
|
|
2006-03-28 22:33:37 +04:00
|
|
|
if (context->BidiEnabled())
|
|
|
|
{
|
2005-11-16 12:40:52 +03:00
|
|
|
switch (aKeycode) {
|
|
|
|
case nsIDOMKeyEvent::DOM_VK_HOME:
|
|
|
|
case nsIDOMKeyEvent::DOM_VK_END:
|
2006-03-13 04:13:25 +03:00
|
|
|
// set the caret Bidi level to the paragraph embedding level
|
2006-08-08 09:14:52 +04:00
|
|
|
SetCaretBidiLevel(NS_GET_BASE_LEVEL(theFrame));
|
2005-11-16 12:40:52 +03:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
// If the current position is not a frame boundary, it's enough just to take the Bidi level of the current frame
|
|
|
|
if ((pos.mContentOffset != frameStart && pos.mContentOffset != frameEnd)
|
|
|
|
|| (eSelectLine == aAmount))
|
|
|
|
{
|
2006-08-08 09:14:52 +04:00
|
|
|
SetCaretBidiLevel(NS_GET_EMBEDDING_LEVEL(theFrame));
|
2005-11-16 12:40:52 +03:00
|
|
|
}
|
|
|
|
else
|
2006-04-26 06:01:07 +04:00
|
|
|
BidiLevelFromMove(mShell, pos.mResultContent, pos.mContentOffset, aKeycode, tHint);
|
2001-03-21 04:16:22 +03:00
|
|
|
}
|
2002-09-05 04:56:25 +04:00
|
|
|
#ifdef VISUALSELECTION
|
2001-03-21 04:16:22 +03:00
|
|
|
// Handle visual selection
|
2005-01-26 01:38:37 +03:00
|
|
|
if (aContinueSelection)
|
2001-03-21 04:16:22 +03:00
|
|
|
{
|
2006-04-26 06:01:07 +04:00
|
|
|
result = VisualSelectFrames(theFrame, pos);
|
2001-03-21 04:16:22 +03:00
|
|
|
if (NS_FAILED(result)) // Back out by collapsing the selection to the current position
|
|
|
|
result = TakeFocus(pos.mResultContent, pos.mContentOffset, pos.mContentOffset, PR_FALSE, PR_FALSE);
|
|
|
|
}
|
|
|
|
else
|
2005-01-26 01:38:37 +03:00
|
|
|
result = TakeFocus(pos.mResultContent, pos.mContentOffset, pos.mContentOffset, aContinueSelection, PR_FALSE);
|
2001-03-21 04:16:22 +03:00
|
|
|
}
|
|
|
|
else
|
2002-09-05 04:56:25 +04:00
|
|
|
#else
|
|
|
|
}
|
|
|
|
#endif // VISUALSELECTION
|
2005-01-26 01:38:37 +03:00
|
|
|
result = TakeFocus(pos.mResultContent, pos.mContentOffset, pos.mContentOffset, aContinueSelection, PR_FALSE);
|
|
|
|
} else if (aKeycode == nsIDOMKeyEvent::DOM_VK_RIGHT && !aContinueSelection) {
|
2006-11-09 19:37:10 +03:00
|
|
|
// Collapse selection if PeekOffset failed, we either
|
|
|
|
// 1. bumped into the BRFrame, bug 207623
|
|
|
|
// 2. had select-all in a text input (DIV range), bug 352759.
|
2006-09-12 00:43:01 +04:00
|
|
|
weakNodeUsed = mDomSelections[index]->FetchFocusNode();
|
|
|
|
offsetused = mDomSelections[index]->FetchFocusOffset();
|
2007-01-31 01:28:06 +03:00
|
|
|
PRBool isBRFrame = frame->GetType() == nsGkAtoms::brFrame;
|
2005-01-26 01:38:37 +03:00
|
|
|
mDomSelections[index]->Collapse(weakNodeUsed, offsetused);
|
2007-01-31 01:28:06 +03:00
|
|
|
// Note: 'frame' might be dead here.
|
|
|
|
if (isBRFrame) {
|
2006-11-09 19:37:10 +03:00
|
|
|
tHint = mHint; // 1: make the line below restore the original hint
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
tHint = HINTLEFT; // 2: we're now at the end of the frame to the left
|
|
|
|
}
|
2005-01-26 01:38:37 +03:00
|
|
|
result = NS_OK;
|
2000-03-22 02:58:02 +03:00
|
|
|
}
|
|
|
|
if (NS_SUCCEEDED(result))
|
2001-06-13 04:00:55 +04:00
|
|
|
{
|
|
|
|
mHint = tHint; //save the hint parameter now for the next time
|
2000-03-31 11:17:22 +04:00
|
|
|
result = mDomSelections[index]->ScrollIntoView();
|
2001-06-13 04:00:55 +04:00
|
|
|
}
|
2000-03-22 02:58:02 +03:00
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2006-04-26 06:01:07 +04:00
|
|
|
//END nsFrameSelection methods
|
2000-03-22 02:58:02 +03:00
|
|
|
|
|
|
|
|
2006-04-26 06:01:07 +04:00
|
|
|
//BEGIN nsFrameSelection methods
|
2000-03-22 02:58:02 +03:00
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2000-11-29 03:13:00 +03:00
|
|
|
nsTypedSelection::ToString(PRUnichar **aReturn)
|
2000-09-14 15:45:01 +04:00
|
|
|
{
|
|
|
|
return ToStringWithFormat("text/plain", 0, 0, aReturn);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2000-11-29 03:13:00 +03:00
|
|
|
nsTypedSelection::ToStringWithFormat(const char * aFormatType, PRUint32 aFlags,
|
2000-09-14 15:45:01 +04:00
|
|
|
PRInt32 aWrapCol, PRUnichar **aReturn)
|
2000-03-22 02:58:02 +03:00
|
|
|
{
|
2000-04-28 17:58:08 +04:00
|
|
|
nsresult rv = NS_OK;
|
2000-09-14 15:45:01 +04:00
|
|
|
if (!aReturn)
|
|
|
|
return NS_ERROR_NULL_POINTER;
|
2000-08-23 21:27:06 +04:00
|
|
|
|
2000-09-14 03:57:52 +04:00
|
|
|
nsCAutoString formatType( NS_DOC_ENCODER_CONTRACTID_BASE );
|
2000-09-14 15:45:01 +04:00
|
|
|
formatType.Append(aFormatType);
|
2001-10-27 10:44:19 +04:00
|
|
|
nsCOMPtr<nsIDocumentEncoder> encoder =
|
|
|
|
do_CreateInstance(formatType.get(), &rv);
|
2000-04-28 17:58:08 +04:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
nsCOMPtr<nsIPresShell> shell;
|
|
|
|
rv = GetPresShell(getter_AddRefs(shell));
|
|
|
|
if (NS_FAILED(rv) || !shell) {
|
2000-03-22 02:58:02 +03:00
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
2004-08-02 08:52:55 +04:00
|
|
|
nsIDocument *doc = shell->GetDocument();
|
2000-04-28 17:58:08 +04:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2000-03-22 02:58:02 +03:00
|
|
|
|
2006-05-01 09:25:52 +04:00
|
|
|
nsCOMPtr<nsIDOMDocument> domDoc = do_QueryInterface(doc);
|
|
|
|
NS_ASSERTION(domDoc, "Need a document");
|
|
|
|
|
2000-05-31 04:02:12 +04:00
|
|
|
// Flags should always include OutputSelectionOnly if we're coming from here:
|
|
|
|
aFlags |= nsIDocumentEncoder::OutputSelectionOnly;
|
2000-09-14 15:45:01 +04:00
|
|
|
nsAutoString readstring;
|
2004-08-04 21:33:30 +04:00
|
|
|
readstring.AssignASCII(aFormatType);
|
2006-05-01 09:25:52 +04:00
|
|
|
rv = encoder->Init(domDoc, readstring, aFlags);
|
2000-04-28 17:58:08 +04:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2000-03-22 02:58:02 +03:00
|
|
|
|
2000-04-28 17:58:08 +04:00
|
|
|
encoder->SetSelection(this);
|
2000-09-14 15:45:01 +04:00
|
|
|
if (aWrapCol != 0)
|
|
|
|
encoder->SetWrapColumn(aWrapCol);
|
2000-04-28 17:58:08 +04:00
|
|
|
|
2000-09-14 15:45:01 +04:00
|
|
|
nsAutoString tmp;
|
|
|
|
rv = encoder->EncodeToString(tmp);
|
2001-09-29 12:28:41 +04:00
|
|
|
*aReturn = ToNewUnicode(tmp);//get the unicode pointer from it. this is temporary
|
2000-04-28 17:58:08 +04:00
|
|
|
return rv;
|
2000-03-22 02:58:02 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2000-11-29 03:13:00 +03:00
|
|
|
nsTypedSelection::SetInterlinePosition(PRBool aHintRight)
|
2000-03-22 02:58:02 +03:00
|
|
|
{
|
2006-04-14 04:28:22 +04:00
|
|
|
if (!mFrameSelection)
|
|
|
|
return NS_ERROR_NOT_INITIALIZED; // Can't do selection
|
2006-04-26 06:01:07 +04:00
|
|
|
nsFrameSelection::HINT hint;
|
2000-06-28 08:00:12 +04:00
|
|
|
if (aHintRight)
|
2006-04-26 06:01:07 +04:00
|
|
|
hint = nsFrameSelection::HINTRIGHT;
|
2000-06-28 08:00:12 +04:00
|
|
|
else
|
2006-04-26 06:01:07 +04:00
|
|
|
hint = nsFrameSelection::HINTLEFT;
|
|
|
|
mFrameSelection->SetHint(hint);
|
|
|
|
|
|
|
|
return NS_OK;
|
2000-03-22 02:58:02 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2000-11-29 03:13:00 +03:00
|
|
|
nsTypedSelection::GetInterlinePosition(PRBool *aHintRight)
|
2000-03-22 02:58:02 +03:00
|
|
|
{
|
2006-04-14 04:28:22 +04:00
|
|
|
if (!mFrameSelection)
|
|
|
|
return NS_ERROR_NOT_INITIALIZED; // Can't do selection
|
2006-04-26 06:01:07 +04:00
|
|
|
*aHintRight = (mFrameSelection->GetHint() == nsFrameSelection::HINTRIGHT);
|
|
|
|
return NS_OK;
|
2000-03-22 02:58:02 +03:00
|
|
|
}
|
|
|
|
|
2003-09-27 08:18:26 +04:00
|
|
|
#ifdef VISUALSELECTION
|
|
|
|
|
|
|
|
static nsDirection
|
|
|
|
ReverseDirection(nsDirection aDirection)
|
2001-03-21 04:16:22 +03:00
|
|
|
{
|
|
|
|
return (eDirNext == aDirection) ? eDirPrevious : eDirNext;
|
|
|
|
}
|
|
|
|
|
2003-09-27 08:18:26 +04:00
|
|
|
static nsresult
|
|
|
|
FindLineContaining(nsIFrame* aFrame, nsIFrame** aBlock, PRInt32* aLine)
|
2001-03-21 04:16:22 +03:00
|
|
|
{
|
|
|
|
nsIFrame *blockFrame = aFrame;
|
2003-09-27 08:18:26 +04:00
|
|
|
nsIFrame *thisBlock = nsnull;
|
2001-03-21 04:16:22 +03:00
|
|
|
nsCOMPtr<nsILineIteratorNavigator> it;
|
|
|
|
nsresult result = NS_ERROR_FAILURE;
|
|
|
|
while (NS_FAILED(result) && blockFrame)
|
|
|
|
{
|
|
|
|
thisBlock = blockFrame;
|
2003-08-06 07:07:12 +04:00
|
|
|
blockFrame = blockFrame->GetParent();
|
|
|
|
if (blockFrame) {
|
2002-12-11 17:24:49 +03:00
|
|
|
it = do_QueryInterface(blockFrame, &result);
|
2001-03-21 04:16:22 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!blockFrame || !it)
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
*aBlock = blockFrame;
|
|
|
|
return it->FindLineContaining(thisBlock, aLine);
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2006-04-26 06:01:07 +04:00
|
|
|
nsFrameSelection::VisualSequence(nsIFrame* aSelectFrame,
|
|
|
|
nsIFrame* aCurrentFrame,
|
|
|
|
nsPeekOffsetStruct* aPos,
|
|
|
|
PRBool* aNeedVisualSelection)
|
2001-03-21 04:16:22 +03:00
|
|
|
{
|
|
|
|
nsVoidArray frameArray;
|
|
|
|
PRInt32 frameStart, frameEnd;
|
|
|
|
PRInt8 index = GetIndexFromSelectionType(nsISelectionController::SELECTION_NORMAL);
|
|
|
|
nsresult result = nsnull;
|
|
|
|
|
2004-06-01 10:20:16 +04:00
|
|
|
PRUint8 currentLevel = NS_GET_EMBEDDING_LEVEL(aCurrentFrame);
|
2006-09-12 00:43:01 +04:00
|
|
|
result = aSelectFrame->PeekOffset(aPos);
|
2001-03-21 04:16:22 +03:00
|
|
|
while (aCurrentFrame != (aSelectFrame = aPos->mResultFrame))
|
|
|
|
{
|
|
|
|
if (NS_FAILED(result))
|
|
|
|
return NS_OK; // we have passed the end of the line, and we will carry on from there
|
|
|
|
if (!aSelectFrame)
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
if (frameArray.IndexOf(aSelectFrame) > -1)
|
|
|
|
// If we have already seen this frame, we must be in an infinite loop
|
|
|
|
return NS_OK;
|
|
|
|
else
|
|
|
|
frameArray.AppendElement(aSelectFrame);
|
|
|
|
|
|
|
|
aSelectFrame->GetOffsets(frameStart, frameEnd);
|
2004-06-01 10:20:16 +04:00
|
|
|
PRUint8 bidiLevel = NS_GET_EMBEDDING_LEVEL(aSelectFrame);
|
2001-03-21 04:16:22 +03:00
|
|
|
|
|
|
|
if (currentLevel != bidiLevel)
|
|
|
|
*aNeedVisualSelection = PR_TRUE;
|
|
|
|
if ((eDirNext == aPos->mDirection) == (bidiLevel & 1))
|
|
|
|
{
|
|
|
|
mDomSelections[index]->SetDirection(eDirPrevious);
|
|
|
|
result = TakeFocus(aPos->mResultContent, frameEnd, frameStart, PR_FALSE, PR_TRUE);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
mDomSelections[index]->SetDirection(eDirNext);
|
|
|
|
result = TakeFocus(aPos->mResultContent, frameStart, frameEnd, PR_FALSE, PR_TRUE);
|
|
|
|
}
|
|
|
|
if (NS_FAILED(result))
|
|
|
|
return result;
|
|
|
|
|
|
|
|
aPos->mAmount = eSelectDir; // reset this because PeekOffset will have changed it to eSelectNoAmount
|
|
|
|
aPos->mContentOffset = 0;
|
2006-09-12 00:43:01 +04:00
|
|
|
result = aSelectFrame->PeekOffset(aPos);
|
2001-03-21 04:16:22 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2006-04-26 06:01:07 +04:00
|
|
|
nsFrameSelection::SelectToEdge(nsIFrame *aFrame,
|
|
|
|
nsIContent *aContent,
|
|
|
|
PRInt32 aOffset,
|
|
|
|
PRInt32 aEdge,
|
|
|
|
PRBool aMultipleSelection)
|
2001-03-21 04:16:22 +03:00
|
|
|
{
|
|
|
|
PRInt32 frameStart, frameEnd;
|
|
|
|
|
|
|
|
aFrame->GetOffsets(frameStart, frameEnd);
|
|
|
|
if (0 == aEdge)
|
|
|
|
aEdge = frameStart;
|
|
|
|
else if (-1 == aEdge)
|
|
|
|
aEdge = frameEnd;
|
|
|
|
if (0 == aOffset)
|
|
|
|
aOffset = frameStart;
|
|
|
|
else if (-1 == aOffset)
|
|
|
|
aOffset = frameEnd;
|
|
|
|
return TakeFocus(aContent, aOffset, aEdge, PR_FALSE, aMultipleSelection);
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2006-04-26 06:01:07 +04:00
|
|
|
nsFrameSelection::SelectLines(nsDirection aSelectionDirection,
|
|
|
|
nsIDOMNode *aAnchorNode,
|
|
|
|
nsIFrame* aAnchorFrame,
|
|
|
|
PRInt32 aAnchorOffset,
|
|
|
|
nsIDOMNode *aCurrentNode,
|
|
|
|
nsIFrame* aCurrentFrame,
|
|
|
|
PRInt32 aCurrentOffset,
|
|
|
|
nsPeekOffsetStruct aPos)
|
2001-03-21 04:16:22 +03:00
|
|
|
{
|
|
|
|
nsIFrame *startFrame, *endFrame;
|
|
|
|
PRInt32 startOffset, endOffset;
|
|
|
|
PRInt32 relativePosition;
|
|
|
|
nsCOMPtr<nsIDOMNode> startNode;
|
|
|
|
nsCOMPtr<nsIDOMNode> endNode;
|
|
|
|
nsIContent *startContent;
|
|
|
|
nsIContent *endContent;
|
|
|
|
nsresult result;
|
|
|
|
|
|
|
|
// normalize the order before we start to avoid piles of conditions later
|
2006-10-21 05:30:54 +04:00
|
|
|
relativePosition = CompareDOMPoints(aAnchorNode, aAnchorOffset,
|
|
|
|
aCurrentNode, aCurrentOffset);
|
2001-03-21 04:16:22 +03:00
|
|
|
if (0 == relativePosition)
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
else if (relativePosition < 0)
|
|
|
|
{
|
|
|
|
startNode = aAnchorNode;
|
|
|
|
startFrame = aAnchorFrame;
|
|
|
|
startOffset = aAnchorOffset;
|
|
|
|
endNode = aCurrentNode;
|
|
|
|
endFrame = aCurrentFrame;
|
|
|
|
endOffset = aCurrentOffset;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
startNode = aCurrentNode;
|
|
|
|
startFrame = aCurrentFrame;
|
|
|
|
startOffset = aCurrentOffset;
|
|
|
|
endNode = aAnchorNode;
|
|
|
|
endFrame = aAnchorFrame;
|
|
|
|
endOffset = aAnchorOffset;
|
|
|
|
}
|
2006-04-26 06:01:07 +04:00
|
|
|
|
2001-03-21 04:16:22 +03:00
|
|
|
aPos.mStartOffset = startOffset;
|
|
|
|
aPos.mDirection = eDirNext;
|
|
|
|
aPos.mAmount = eSelectLine;
|
2006-09-12 00:43:01 +04:00
|
|
|
result = startFrame->PeekOffset(&aPos);
|
2001-03-21 04:16:22 +03:00
|
|
|
if (NS_FAILED(result))
|
|
|
|
return result;
|
|
|
|
startFrame = aPos.mResultFrame;
|
|
|
|
|
|
|
|
aPos.mStartOffset = aPos.mContentOffset;
|
|
|
|
aPos.mAmount = eSelectBeginLine;
|
2006-09-12 00:43:01 +04:00
|
|
|
result = startFrame->PeekOffset(&aPos);
|
2001-03-21 04:16:22 +03:00
|
|
|
if (NS_FAILED(result))
|
|
|
|
return result;
|
|
|
|
|
|
|
|
nsIFrame *theFrame;
|
|
|
|
PRInt32 currentOffset, frameStart, frameEnd;
|
|
|
|
|
2006-04-26 06:01:07 +04:00
|
|
|
theFrame = GetFrameForNodeOffset(aPos.mResultContent, aPos.mContentOffset,
|
|
|
|
HINTLEFT, ¤tOffset);
|
|
|
|
if (!theFrame)
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
|
2001-03-21 04:16:22 +03:00
|
|
|
theFrame->GetOffsets(frameStart, frameEnd);
|
|
|
|
startOffset = frameStart;
|
|
|
|
startContent = aPos.mResultContent;
|
|
|
|
startNode = do_QueryInterface(startContent);
|
|
|
|
|
|
|
|
// If we have already overshot the endpoint, back out
|
2006-10-21 05:30:54 +04:00
|
|
|
if (CompareDOMPoints(startNode, startOffset, endNode, endOffset) >= 0)
|
2001-03-21 04:16:22 +03:00
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
|
|
|
|
aPos.mStartOffset = endOffset;
|
|
|
|
aPos.mDirection = eDirPrevious;
|
|
|
|
aPos.mAmount = eSelectLine;
|
2006-09-12 00:43:01 +04:00
|
|
|
result = endFrame->PeekOffset(&aPos);
|
2001-03-21 04:16:22 +03:00
|
|
|
if (NS_FAILED(result))
|
|
|
|
return result;
|
|
|
|
endFrame = aPos.mResultFrame;
|
|
|
|
|
|
|
|
aPos.mStartOffset = aPos.mContentOffset;
|
|
|
|
aPos.mAmount = eSelectEndLine;
|
2006-09-12 00:43:01 +04:00
|
|
|
result = endFrame->PeekOffset(&aPos);
|
2001-03-21 04:16:22 +03:00
|
|
|
if (NS_FAILED(result))
|
|
|
|
return result;
|
|
|
|
|
2006-04-26 06:01:07 +04:00
|
|
|
theFrame = GetFrameForNodeOffset(aPos.mResultContent, aPos.mContentOffset,
|
|
|
|
HINTRIGHT, ¤tOffset);
|
|
|
|
if (!theFrame)
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
|
2001-03-21 04:16:22 +03:00
|
|
|
theFrame->GetOffsets(frameStart, frameEnd);
|
|
|
|
endOffset = frameEnd;
|
|
|
|
endContent = aPos.mResultContent;
|
|
|
|
endNode = do_QueryInterface(endContent);
|
|
|
|
|
2006-10-21 05:30:54 +04:00
|
|
|
if (CompareDOMPoints(startNode, startOffset, endNode, endOffset) < 0)
|
2001-03-21 04:16:22 +03:00
|
|
|
{
|
|
|
|
TakeFocus(startContent, startOffset, startOffset, PR_FALSE, PR_TRUE);
|
|
|
|
return TakeFocus(endContent, endOffset, endOffset, PR_TRUE, PR_TRUE);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2006-04-26 06:01:07 +04:00
|
|
|
nsFrameSelection::VisualSelectFrames(nsIFrame* aCurrentFrame,
|
|
|
|
nsPeekOffsetStruct aPos)
|
2001-03-21 04:16:22 +03:00
|
|
|
{
|
|
|
|
nsCOMPtr<nsIContent> anchorContent;
|
|
|
|
nsCOMPtr<nsIDOMNode> anchorNode;
|
|
|
|
PRInt32 anchorOffset;
|
|
|
|
nsIFrame* anchorFrame;
|
|
|
|
nsCOMPtr<nsIContent> focusContent;
|
|
|
|
nsCOMPtr<nsIDOMNode> focusNode;
|
|
|
|
PRInt32 focusOffset;
|
|
|
|
nsIFrame* focusFrame;
|
|
|
|
nsCOMPtr<nsIContent> currentContent;
|
|
|
|
nsCOMPtr<nsIDOMNode> currentNode;
|
|
|
|
PRInt32 currentOffset;
|
|
|
|
nsresult result;
|
|
|
|
nsIFrame* startFrame;
|
|
|
|
PRBool needVisualSelection = PR_FALSE;
|
|
|
|
nsDirection selectionDirection;
|
|
|
|
PRInt8 index = GetIndexFromSelectionType(nsISelectionController::SELECTION_NORMAL);
|
2006-04-26 06:01:07 +04:00
|
|
|
|
2001-03-21 04:16:22 +03:00
|
|
|
result = mDomSelections[index]->GetOriginalAnchorPoint(getter_AddRefs(anchorNode), &anchorOffset);
|
|
|
|
if (NS_FAILED(result))
|
|
|
|
return result;
|
|
|
|
anchorContent = do_QueryInterface(anchorNode);
|
2006-04-26 06:01:07 +04:00
|
|
|
anchorFrame = GetFrameForNodeOffset(anchorContent, anchorOffset,
|
|
|
|
mHint, &anchorOffset);
|
|
|
|
if (!anchorFrame)
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
|
2004-06-01 10:20:16 +04:00
|
|
|
PRUint8 anchorLevel = NS_GET_EMBEDDING_LEVEL(anchorFrame);
|
|
|
|
|
2001-03-21 04:16:22 +03:00
|
|
|
currentContent = aPos.mResultContent;
|
|
|
|
currentNode = do_QueryInterface(currentContent);
|
|
|
|
currentOffset = aPos.mContentOffset;
|
2004-06-01 10:20:16 +04:00
|
|
|
PRUint8 currentLevel = NS_GET_EMBEDDING_LEVEL(aCurrentFrame);
|
2001-03-21 04:16:22 +03:00
|
|
|
|
|
|
|
// Moving from simplest case to more complicated:
|
|
|
|
// case 1: selection starts and ends in the same frame: no special treatment
|
|
|
|
if (anchorFrame == aCurrentFrame) {
|
|
|
|
mDomSelections[index]->SetTrueDirection(!(anchorLevel & 1));
|
|
|
|
return TakeFocus(currentContent, anchorOffset, currentOffset, PR_FALSE, PR_FALSE);
|
|
|
|
}
|
|
|
|
|
|
|
|
focusOffset = mDomSelections[index]->FetchFocusOffset();
|
|
|
|
focusNode = mDomSelections[index]->FetchFocusNode();
|
|
|
|
focusContent = do_QueryInterface(focusNode);
|
|
|
|
HINT hint;
|
|
|
|
if ((HINTLEFT == mHint) == (currentLevel & 1))
|
|
|
|
hint = HINTRIGHT;
|
|
|
|
else
|
|
|
|
hint = HINTLEFT;
|
|
|
|
|
2006-04-26 06:01:07 +04:00
|
|
|
focusFrame = GetFrameForNodeOffset(focusContent, focusOffset,
|
|
|
|
hint, &focusOffset);
|
|
|
|
if (!focusFrame)
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
|
2004-06-01 10:20:16 +04:00
|
|
|
PRUint8 focusLevel = NS_GET_EMBEDDING_LEVEL(focusFrame);
|
2001-03-21 04:16:22 +03:00
|
|
|
|
|
|
|
if (currentLevel != anchorLevel)
|
|
|
|
needVisualSelection = PR_TRUE;
|
|
|
|
|
|
|
|
// Make sure of the selection direction
|
|
|
|
selectionDirection = mDomSelections[index]->GetDirection();
|
|
|
|
if (!mDomSelections[index]->GetTrueDirection()) {
|
|
|
|
selectionDirection = ReverseDirection(selectionDirection);
|
|
|
|
mDomSelections[index]->SetDirection(selectionDirection);
|
|
|
|
}
|
|
|
|
|
|
|
|
PRInt32 anchorLine, currentLine;
|
|
|
|
nsIFrame* anchorBlock = nsnull;
|
|
|
|
nsIFrame* currentBlock = nsnull;
|
|
|
|
FindLineContaining(anchorFrame, &anchorBlock, &anchorLine);
|
|
|
|
FindLineContaining(aCurrentFrame, ¤tBlock, ¤tLine);
|
|
|
|
|
|
|
|
if (anchorBlock==currentBlock && anchorLine==currentLine)
|
|
|
|
{
|
|
|
|
// case 2: selection starts and ends in the same line
|
|
|
|
|
|
|
|
// Select from the anchor point to the edge of the frame
|
|
|
|
// Which edge? If the selection direction is forward the right edge, if it is backward the left edge
|
2005-11-21 01:05:24 +03:00
|
|
|
// For rtl frames the right edge is the beginning of the frame, for ltr frames it is the end and vice versa
|
2001-03-21 04:16:22 +03:00
|
|
|
if ((eDirNext == selectionDirection) == (anchorLevel & 1))
|
|
|
|
result = SelectToEdge(anchorFrame, anchorContent, anchorOffset, 0, PR_FALSE);
|
|
|
|
else
|
|
|
|
result = SelectToEdge(anchorFrame, anchorContent, anchorOffset, -1, PR_FALSE);
|
|
|
|
if (NS_FAILED(result))
|
|
|
|
return result;
|
|
|
|
|
|
|
|
// Walk the frames in visual order until we reach the current frame, selecting each frame as we go
|
|
|
|
InvalidateDesiredX();
|
|
|
|
aPos.mAmount = eSelectDir;
|
|
|
|
aPos.mStartOffset = anchorOffset;
|
|
|
|
aPos.mDirection = selectionDirection;
|
|
|
|
|
2006-09-12 00:43:01 +04:00
|
|
|
result = anchorFrame->PeekOffset(&aPos);
|
2001-03-21 04:16:22 +03:00
|
|
|
if (NS_FAILED(result))
|
|
|
|
return result;
|
|
|
|
|
|
|
|
startFrame = aPos.mResultFrame;
|
2006-04-26 06:01:07 +04:00
|
|
|
result = VisualSequence(startFrame, aCurrentFrame, &aPos, &needVisualSelection);
|
2001-03-21 04:16:22 +03:00
|
|
|
if (NS_FAILED(result))
|
|
|
|
return result;
|
|
|
|
|
|
|
|
if (!needVisualSelection)
|
|
|
|
{
|
|
|
|
if (currentLevel & 1)
|
|
|
|
mDomSelections[index]->SetDirection(ReverseDirection(selectionDirection));
|
|
|
|
// all the frames we passed through had the same Bidi level, so we can back out and do an ordinary selection
|
|
|
|
result = TakeFocus(anchorContent, anchorOffset, anchorOffset, PR_FALSE, PR_FALSE);
|
|
|
|
if (NS_FAILED(result))
|
|
|
|
return result;
|
|
|
|
result = TakeFocus(currentContent, currentOffset, currentOffset, PR_TRUE, PR_FALSE);
|
|
|
|
if (NS_FAILED(result))
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
if ((currentLevel & 1) != (focusLevel & 1))
|
|
|
|
mDomSelections[index]->SetDirection(ReverseDirection(selectionDirection));
|
|
|
|
// Select from the current point to the edge of the frame
|
|
|
|
if ((eDirNext == selectionDirection) == (currentLevel & 1))
|
|
|
|
result = SelectToEdge(aCurrentFrame, currentContent, -1, currentOffset, PR_TRUE);
|
|
|
|
else
|
|
|
|
result = SelectToEdge(aCurrentFrame, currentContent, 0, currentOffset, PR_TRUE);
|
|
|
|
if (NS_FAILED(result))
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
|
|
|
|
// case 3: selection starts and ends in different lines
|
|
|
|
|
|
|
|
// If selection direction is forwards:
|
|
|
|
// Select from the anchor point to the edge of the frame in the direction of the end of the line
|
|
|
|
// i.e. the rightmost character if the current paragraph embedding level is even (LTR paragraph)
|
|
|
|
// or the leftmost character if the current paragraph embedding level is odd (RTL paragraph)
|
|
|
|
//
|
2005-11-21 01:05:24 +03:00
|
|
|
// As before, for rtl frames the right edge is the beginning of the frame, for ltr frames it is the end and vice versa
|
2001-03-21 04:16:22 +03:00
|
|
|
//
|
|
|
|
// If selection direction is backwards, vice versa throughout
|
|
|
|
//
|
2004-06-01 10:20:16 +04:00
|
|
|
PRUint8 anchorBaseLevel = NS_GET_BASE_LEVEL(anchorFrame);
|
2001-03-21 04:16:22 +03:00
|
|
|
if ((eDirNext == selectionDirection) != ((anchorLevel & 1) == (anchorBaseLevel & 1)))
|
|
|
|
result = SelectToEdge(anchorFrame, anchorContent, anchorOffset, 0, PR_FALSE);
|
|
|
|
else
|
|
|
|
result = SelectToEdge(anchorFrame, anchorContent, anchorOffset, -1, PR_FALSE);
|
|
|
|
if (NS_FAILED(result))
|
|
|
|
return result;
|
|
|
|
|
|
|
|
// Walk the frames in visual order until we reach the end of the line
|
|
|
|
aPos.mJumpLines = PR_FALSE;
|
|
|
|
aPos.mAmount = eSelectDir;
|
|
|
|
aPos.mStartOffset = anchorOffset;
|
|
|
|
aPos.mDirection = selectionDirection;
|
|
|
|
if (anchorBaseLevel & 1)
|
|
|
|
aPos.mDirection = ReverseDirection(aPos.mDirection);
|
2006-04-26 06:01:07 +04:00
|
|
|
result = VisualSequence(anchorFrame, aCurrentFrame, &aPos, &needVisualSelection);
|
2001-03-21 04:16:22 +03:00
|
|
|
if (NS_FAILED(result))
|
|
|
|
return result;
|
|
|
|
|
|
|
|
// Select all the lines between the line containing the anchor point and the line containing the current point
|
|
|
|
aPos.mJumpLines = PR_TRUE;
|
2006-04-26 06:01:07 +04:00
|
|
|
result = SelectLines(selectionDirection, anchorNode, anchorFrame,
|
|
|
|
anchorOffset, currentNode, aCurrentFrame, currentOffset,
|
|
|
|
aPos);
|
2001-04-18 03:03:38 +04:00
|
|
|
if (NS_FAILED(result))
|
|
|
|
return result;
|
2001-03-21 04:16:22 +03:00
|
|
|
|
|
|
|
// Go to the current point
|
2004-06-01 10:20:16 +04:00
|
|
|
PRUint8 currentBaseLevel = NS_GET_BASE_LEVEL(aCurrentFrame);
|
2001-03-21 04:16:22 +03:00
|
|
|
// Walk the frames in visual order until we reach the beginning of the line
|
|
|
|
aPos.mJumpLines = PR_FALSE;
|
|
|
|
if ((currentBaseLevel & 1) == (anchorBaseLevel & 1))
|
|
|
|
aPos.mDirection = ReverseDirection(aPos.mDirection);
|
|
|
|
aPos.mStartOffset = currentOffset;
|
2006-04-26 06:01:07 +04:00
|
|
|
result = VisualSequence(aCurrentFrame, anchorFrame, &aPos, &needVisualSelection);
|
2001-03-21 04:16:22 +03:00
|
|
|
if (NS_FAILED(result))
|
|
|
|
return result;
|
|
|
|
|
|
|
|
// Select from the current point to the edge of the frame
|
|
|
|
if (currentLevel & 1)
|
|
|
|
mDomSelections[index]->SetDirection(ReverseDirection(selectionDirection));
|
|
|
|
|
|
|
|
if ((eDirPrevious == selectionDirection) != ((currentLevel & 1) == (currentBaseLevel & 1)))
|
|
|
|
result = SelectToEdge(aCurrentFrame, currentContent, 0, currentOffset, PR_TRUE);
|
|
|
|
else
|
|
|
|
result = SelectToEdge(aCurrentFrame, currentContent, -1, currentOffset, PR_TRUE);
|
|
|
|
if (NS_FAILED(result))
|
|
|
|
return result;
|
|
|
|
|
|
|
|
// restore original selection direction
|
|
|
|
// mDomSelections[index]->SetDirection(selectionDirection);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Sometimes we have to lie about the selection direction, so we will have to remember when we are doing so
|
|
|
|
mDomSelections[index]->SetTrueDirection(mDomSelections[index]->GetDirection() == selectionDirection);
|
|
|
|
|
|
|
|
mDomSelections[index]->SetOriginalAnchorPoint(anchorNode, anchorOffset);
|
|
|
|
NotifySelectionListeners(nsISelectionController::SELECTION_NORMAL);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
2002-09-05 04:56:25 +04:00
|
|
|
#endif // VISUALSELECTION
|
2001-03-21 04:16:22 +03:00
|
|
|
|
2006-04-26 06:01:07 +04:00
|
|
|
nsPrevNextBidiLevels
|
|
|
|
nsFrameSelection::GetPrevNextBidiLevels(nsIContent *aNode,
|
|
|
|
PRUint32 aContentOffset,
|
|
|
|
PRBool aJumpLines)
|
2005-10-17 03:26:22 +04:00
|
|
|
{
|
2006-04-26 06:01:07 +04:00
|
|
|
return GetPrevNextBidiLevels(aNode, aContentOffset, mHint, aJumpLines);
|
2005-10-17 03:26:22 +04:00
|
|
|
}
|
|
|
|
|
2006-04-26 06:01:07 +04:00
|
|
|
nsPrevNextBidiLevels
|
|
|
|
nsFrameSelection::GetPrevNextBidiLevels(nsIContent *aNode,
|
|
|
|
PRUint32 aContentOffset,
|
|
|
|
HINT aHint,
|
|
|
|
PRBool aJumpLines)
|
|
|
|
{
|
2001-03-21 04:16:22 +03:00
|
|
|
// Get the level of the frames on each side
|
|
|
|
nsIFrame *currentFrame;
|
|
|
|
PRInt32 currentOffset;
|
|
|
|
PRInt32 frameStart, frameEnd;
|
|
|
|
nsDirection direction;
|
2006-04-26 06:01:07 +04:00
|
|
|
|
|
|
|
nsPrevNextBidiLevels levels;
|
|
|
|
levels.SetData(nsnull, nsnull, 0, 0);
|
2001-04-18 03:03:38 +04:00
|
|
|
|
2006-04-26 06:01:07 +04:00
|
|
|
currentFrame = GetFrameForNodeOffset(aNode, aContentOffset,
|
|
|
|
aHint, ¤tOffset);
|
|
|
|
if (!currentFrame)
|
|
|
|
return levels;
|
2001-03-21 04:16:22 +03:00
|
|
|
|
|
|
|
currentFrame->GetOffsets(frameStart, frameEnd);
|
|
|
|
|
|
|
|
if (0 == frameStart && 0 == frameEnd)
|
|
|
|
direction = eDirPrevious;
|
|
|
|
else if (frameStart == currentOffset)
|
|
|
|
direction = eDirPrevious;
|
|
|
|
else if (frameEnd == currentOffset)
|
|
|
|
direction = eDirNext;
|
|
|
|
else {
|
|
|
|
// we are neither at the beginning nor at the end of the frame, so we have no worries
|
2006-04-26 06:01:07 +04:00
|
|
|
levels.SetData(currentFrame, currentFrame,
|
|
|
|
NS_GET_EMBEDDING_LEVEL(currentFrame),
|
|
|
|
NS_GET_EMBEDDING_LEVEL(currentFrame));
|
|
|
|
return levels;
|
2001-03-21 04:16:22 +03:00
|
|
|
}
|
|
|
|
|
2006-09-12 00:43:01 +04:00
|
|
|
nsIFrame *newFrame;
|
|
|
|
PRInt32 offset;
|
|
|
|
PRBool jumpedLine;
|
|
|
|
nsresult rv = currentFrame->GetFrameFromDirection(direction, PR_FALSE,
|
|
|
|
aJumpLines, PR_TRUE,
|
|
|
|
&newFrame, &offset, &jumpedLine);
|
|
|
|
if (NS_FAILED(rv))
|
|
|
|
newFrame = nsnull;
|
2001-03-21 04:16:22 +03:00
|
|
|
|
2006-08-14 15:25:57 +04:00
|
|
|
PRUint8 baseLevel = NS_GET_BASE_LEVEL(currentFrame);
|
|
|
|
PRUint8 currentLevel = NS_GET_EMBEDDING_LEVEL(currentFrame);
|
|
|
|
PRUint8 newLevel = newFrame ? NS_GET_EMBEDDING_LEVEL(newFrame) : baseLevel;
|
|
|
|
|
|
|
|
// If not jumping lines, disregard br frames, since they might be positioned incorrectly.
|
|
|
|
// XXX This could be removed once bug 339786 is fixed.
|
|
|
|
if (!aJumpLines) {
|
2006-12-26 20:47:52 +03:00
|
|
|
if (currentFrame->GetType() == nsGkAtoms::brFrame) {
|
2006-08-14 15:25:57 +04:00
|
|
|
currentFrame = nsnull;
|
|
|
|
currentLevel = baseLevel;
|
|
|
|
}
|
2006-12-26 20:47:52 +03:00
|
|
|
if (newFrame && newFrame->GetType() == nsGkAtoms::brFrame) {
|
2006-08-14 15:25:57 +04:00
|
|
|
newFrame = nsnull;
|
|
|
|
newLevel = baseLevel;
|
|
|
|
}
|
2001-03-21 04:16:22 +03:00
|
|
|
}
|
2006-08-14 15:25:57 +04:00
|
|
|
|
|
|
|
if (direction == eDirNext)
|
|
|
|
levels.SetData(currentFrame, newFrame, currentLevel, newLevel);
|
|
|
|
else
|
|
|
|
levels.SetData(newFrame, currentFrame, newLevel, currentLevel);
|
2001-03-21 04:16:22 +03:00
|
|
|
|
2006-04-26 06:01:07 +04:00
|
|
|
return levels;
|
2001-03-21 04:16:22 +03:00
|
|
|
}
|
|
|
|
|
2006-04-26 06:01:07 +04:00
|
|
|
nsresult
|
|
|
|
nsFrameSelection::GetFrameFromLevel(nsIFrame *aFrameIn,
|
|
|
|
nsDirection aDirection,
|
|
|
|
PRUint8 aBidiLevel,
|
|
|
|
nsIFrame **aFrameOut)
|
2001-03-21 04:16:22 +03:00
|
|
|
{
|
|
|
|
PRUint8 foundLevel = 0;
|
|
|
|
nsIFrame *foundFrame = aFrameIn;
|
|
|
|
|
|
|
|
nsCOMPtr<nsIBidirectionalEnumerator> frameTraversal;
|
|
|
|
nsresult result;
|
|
|
|
nsCOMPtr<nsIFrameTraversal> trav(do_CreateInstance(kFrameTraversalCID,&result));
|
|
|
|
if (NS_FAILED(result))
|
|
|
|
return result;
|
|
|
|
|
2006-08-30 17:38:16 +04:00
|
|
|
result = trav->NewFrameTraversal(getter_AddRefs(frameTraversal),
|
|
|
|
mShell->GetPresContext(), aFrameIn,
|
|
|
|
eLeaf,
|
|
|
|
PR_FALSE, // aVisual
|
|
|
|
PR_FALSE, // aLockInScrollView
|
|
|
|
PR_FALSE // aFollowOOFs
|
|
|
|
);
|
2001-03-21 04:16:22 +03:00
|
|
|
if (NS_FAILED(result))
|
|
|
|
return result;
|
|
|
|
nsISupports *isupports = nsnull;
|
|
|
|
|
|
|
|
do {
|
|
|
|
*aFrameOut = foundFrame;
|
|
|
|
if (aDirection == eDirNext)
|
|
|
|
result = frameTraversal->Next();
|
|
|
|
else
|
|
|
|
result = frameTraversal->Prev();
|
|
|
|
|
|
|
|
if (NS_FAILED(result))
|
|
|
|
return result;
|
|
|
|
result = frameTraversal->CurrentItem(&isupports);
|
|
|
|
if (NS_FAILED(result))
|
|
|
|
return result;
|
|
|
|
if (!isupports)
|
|
|
|
return NS_ERROR_NULL_POINTER;
|
2005-11-21 01:05:24 +03:00
|
|
|
//we must CAST here to an nsIFrame. nsIFrame doesn't really follow the rules
|
2001-03-21 04:16:22 +03:00
|
|
|
//for speed reasons
|
|
|
|
foundFrame = (nsIFrame *)isupports;
|
2004-06-01 10:20:16 +04:00
|
|
|
foundLevel = NS_GET_EMBEDDING_LEVEL(foundFrame);
|
2001-03-21 04:16:22 +03:00
|
|
|
|
|
|
|
} while (foundLevel > aBidiLevel);
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2003-07-21 23:51:34 +04:00
|
|
|
|
2006-04-26 06:01:07 +04:00
|
|
|
nsresult
|
2006-07-12 11:07:36 +04:00
|
|
|
nsFrameSelection::MaintainSelection(nsSelectionAmount aAmount)
|
2003-07-21 23:51:34 +04:00
|
|
|
{
|
|
|
|
PRInt8 index = GetIndexFromSelectionType(nsISelectionController::SELECTION_NORMAL);
|
|
|
|
nsCOMPtr<nsIDOMRange> range;
|
|
|
|
nsresult rv = mDomSelections[index]->GetRangeAt(0, getter_AddRefs(range));
|
|
|
|
if (NS_FAILED(rv))
|
|
|
|
return rv;
|
|
|
|
if (!range)
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
|
2006-07-12 11:07:36 +04:00
|
|
|
mMaintainedAmount = aAmount;
|
|
|
|
|
2003-07-21 23:51:34 +04:00
|
|
|
nsCOMPtr<nsIDOMNode> startNode;
|
|
|
|
nsCOMPtr<nsIDOMNode> endNode;
|
|
|
|
PRInt32 startOffset;
|
|
|
|
PRInt32 endOffset;
|
|
|
|
range->GetStartContainer(getter_AddRefs(startNode));
|
|
|
|
range->GetEndContainer(getter_AddRefs(endNode));
|
|
|
|
range->GetStartOffset(&startOffset);
|
|
|
|
range->GetEndOffset(&endOffset);
|
|
|
|
|
|
|
|
mMaintainRange = nsnull;
|
|
|
|
NS_NewRange(getter_AddRefs(mMaintainRange));
|
|
|
|
if (!mMaintainRange)
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
|
|
|
|
mMaintainRange->SetStart(startNode, startOffset);
|
|
|
|
return mMaintainRange->SetEnd(endNode, endOffset);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-03-21 04:16:22 +03:00
|
|
|
/** After moving the caret, its Bidi level is set according to the following rules:
|
|
|
|
*
|
|
|
|
* After moving over a character with left/right arrow, set to the Bidi level of the last moved over character.
|
|
|
|
* After Home and End, set to the paragraph embedding level.
|
|
|
|
* After up/down arrow, PageUp/Down, set to the lower level of the 2 surrounding characters.
|
|
|
|
* After mouse click, set to the level of the current frame.
|
|
|
|
*
|
|
|
|
* The following two methods use GetPrevNextBidiLevels to determine the new Bidi level.
|
|
|
|
* BidiLevelFromMove is called when the caret is moved in response to a keyboard event
|
|
|
|
*
|
|
|
|
* @param aPresShell is the presentation shell
|
|
|
|
* @param aNode is the content node
|
|
|
|
* @param aContentOffset is the new caret position, as an offset into aNode
|
|
|
|
* @param aKeycode is the keyboard event that moved the caret to the new position
|
2005-08-08 11:35:48 +04:00
|
|
|
* @param aHint is the hint indicating in what logical direction the caret moved
|
2001-03-21 04:16:22 +03:00
|
|
|
*/
|
2006-04-26 06:01:07 +04:00
|
|
|
void nsFrameSelection::BidiLevelFromMove(nsIPresShell* aPresShell,
|
|
|
|
nsIContent *aNode,
|
|
|
|
PRUint32 aContentOffset,
|
|
|
|
PRUint32 aKeycode,
|
|
|
|
HINT aHint)
|
|
|
|
{
|
2001-03-21 04:16:22 +03:00
|
|
|
switch (aKeycode) {
|
|
|
|
|
|
|
|
// Right and Left: the new cursor Bidi level is the level of the character moved over
|
|
|
|
case nsIDOMKeyEvent::DOM_VK_RIGHT:
|
|
|
|
case nsIDOMKeyEvent::DOM_VK_LEFT:
|
2006-04-26 06:01:07 +04:00
|
|
|
{
|
|
|
|
nsPrevNextBidiLevels levels = GetPrevNextBidiLevels(aNode, aContentOffset,
|
|
|
|
aHint, PR_FALSE);
|
|
|
|
|
2005-08-08 11:35:48 +04:00
|
|
|
if (HINTLEFT == aHint)
|
2006-08-08 09:14:52 +04:00
|
|
|
SetCaretBidiLevel(levels.mLevelBefore);
|
2001-03-21 04:16:22 +03:00
|
|
|
else
|
2006-08-08 09:14:52 +04:00
|
|
|
SetCaretBidiLevel(levels.mLevelAfter);
|
2001-03-21 04:16:22 +03:00
|
|
|
break;
|
2006-04-26 06:01:07 +04:00
|
|
|
}
|
2001-03-21 04:16:22 +03:00
|
|
|
/*
|
|
|
|
// Up and Down: the new cursor Bidi level is the smaller of the two surrounding characters
|
|
|
|
case nsIDOMKeyEvent::DOM_VK_UP:
|
|
|
|
case nsIDOMKeyEvent::DOM_VK_DOWN:
|
|
|
|
GetPrevNextBidiLevels(aContext, aNode, aContentOffset, &firstFrame, &secondFrame, &firstLevel, &secondLevel);
|
2001-10-01 00:35:55 +04:00
|
|
|
aPresShell->SetCaretBidiLevel(PR_MIN(firstLevel, secondLevel));
|
2001-03-21 04:16:22 +03:00
|
|
|
break;
|
|
|
|
*/
|
|
|
|
|
|
|
|
default:
|
2006-08-08 09:14:52 +04:00
|
|
|
UndefineCaretBidiLevel();
|
2001-03-21 04:16:22 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* BidiLevelFromClick is called when the caret is repositioned by clicking the mouse
|
|
|
|
*
|
|
|
|
* @param aNode is the content node
|
|
|
|
* @param aContentOffset is the new caret position, as an offset into aNode
|
|
|
|
*/
|
2006-04-26 06:01:07 +04:00
|
|
|
void nsFrameSelection::BidiLevelFromClick(nsIContent *aNode,
|
|
|
|
PRUint32 aContentOffset)
|
2001-03-21 04:16:22 +03:00
|
|
|
{
|
|
|
|
nsIFrame* clickInFrame=nsnull;
|
|
|
|
PRInt32 OffsetNotUsed;
|
|
|
|
|
2006-04-26 06:01:07 +04:00
|
|
|
clickInFrame = GetFrameForNodeOffset(aNode, aContentOffset, mHint, &OffsetNotUsed);
|
|
|
|
if (!clickInFrame)
|
2001-04-18 03:03:38 +04:00
|
|
|
return;
|
|
|
|
|
2006-08-08 09:14:52 +04:00
|
|
|
SetCaretBidiLevel(NS_GET_EMBEDDING_LEVEL(clickInFrame));
|
2001-03-21 04:16:22 +03:00
|
|
|
}
|
|
|
|
|
2003-07-21 23:51:34 +04:00
|
|
|
|
|
|
|
PRBool
|
2006-04-26 06:01:07 +04:00
|
|
|
nsFrameSelection::AdjustForMaintainedSelection(nsIContent *aContent,
|
|
|
|
PRInt32 aOffset)
|
2003-07-21 23:51:34 +04:00
|
|
|
{
|
|
|
|
// Is the desired content and offset currently in selection?
|
|
|
|
// If the double click flag is set then don't continue selection if the
|
|
|
|
// desired content and offset are currently inside a selection.
|
|
|
|
// This will stop double click then mouse-drag from undoing the desired
|
|
|
|
// selecting of a word.
|
|
|
|
if (!mMaintainRange)
|
|
|
|
return PR_FALSE;
|
|
|
|
|
|
|
|
nsCOMPtr<nsIDOMNode> rangenode;
|
|
|
|
PRInt32 rangeOffset;
|
|
|
|
mMaintainRange->GetStartContainer(getter_AddRefs(rangenode));
|
|
|
|
mMaintainRange->GetStartOffset(&rangeOffset);
|
|
|
|
|
|
|
|
nsCOMPtr<nsIDOMNode> domNode = do_QueryInterface(aContent);
|
|
|
|
if (domNode)
|
|
|
|
{
|
|
|
|
PRInt8 index = GetIndexFromSelectionType(nsISelectionController::SELECTION_NORMAL);
|
|
|
|
nsCOMPtr<nsIDOMNSRange> nsrange = do_QueryInterface(mMaintainRange);
|
|
|
|
if (nsrange)
|
|
|
|
{
|
|
|
|
PRBool insideSelection = PR_FALSE;
|
|
|
|
nsrange->IsPointInRange(domNode, aOffset, &insideSelection);
|
|
|
|
|
|
|
|
// Done when we find a range that we are in
|
|
|
|
if (insideSelection)
|
|
|
|
{
|
|
|
|
mDomSelections[index]->Collapse(rangenode, rangeOffset);
|
|
|
|
mMaintainRange->GetEndContainer(getter_AddRefs(rangenode));
|
|
|
|
mMaintainRange->GetEndOffset(&rangeOffset);
|
|
|
|
mDomSelections[index]->Extend(rangenode,rangeOffset);
|
|
|
|
return PR_TRUE; // dragging in selection aborted
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-10-21 05:30:54 +04:00
|
|
|
PRInt32 relativePosition = CompareDOMPoints(rangenode, rangeOffset,
|
|
|
|
domNode, aOffset);
|
2003-07-21 23:51:34 +04:00
|
|
|
// if == 0 or -1 do nothing if < 0 then we need to swap direction
|
|
|
|
if (relativePosition > 0
|
|
|
|
&& (mDomSelections[index]->GetDirection() == eDirNext))
|
|
|
|
{
|
|
|
|
mMaintainRange->GetEndContainer(getter_AddRefs(rangenode));
|
|
|
|
mMaintainRange->GetEndOffset(&rangeOffset);
|
|
|
|
mDomSelections[index]->Collapse(rangenode, rangeOffset);
|
|
|
|
}
|
|
|
|
else if (relativePosition < 0
|
|
|
|
&& (mDomSelections[index]->GetDirection() == eDirPrevious))
|
|
|
|
mDomSelections[index]->Collapse(rangenode, rangeOffset);
|
|
|
|
}
|
|
|
|
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-04-26 06:45:18 +04:00
|
|
|
nsresult
|
2006-04-26 06:01:07 +04:00
|
|
|
nsFrameSelection::HandleClick(nsIContent *aNewFocus,
|
|
|
|
PRUint32 aContentOffset,
|
|
|
|
PRUint32 aContentEndOffset,
|
|
|
|
PRBool aContinueSelection,
|
|
|
|
PRBool aMultipleSelection,
|
|
|
|
PRBool aHint)
|
2000-03-22 02:58:02 +03:00
|
|
|
{
|
2000-05-02 07:44:17 +04:00
|
|
|
if (!aNewFocus)
|
|
|
|
return NS_ERROR_INVALID_ARG;
|
2003-07-21 23:51:34 +04:00
|
|
|
|
2000-03-22 02:58:02 +03:00
|
|
|
InvalidateDesiredX();
|
2003-07-21 23:51:34 +04:00
|
|
|
|
|
|
|
if (!aContinueSelection)
|
|
|
|
mMaintainRange = nsnull;
|
|
|
|
|
2000-04-12 07:04:11 +04:00
|
|
|
mHint = HINT(aHint);
|
2000-03-22 02:58:02 +03:00
|
|
|
// Don't take focus when dragging off of a table
|
2002-03-22 18:25:08 +03:00
|
|
|
if (!mDragSelectingCells)
|
2000-04-14 00:21:32 +04:00
|
|
|
{
|
2001-03-21 04:16:22 +03:00
|
|
|
BidiLevelFromClick(aNewFocus, aContentOffset);
|
2000-09-14 15:45:01 +04:00
|
|
|
PostReason(nsISelectionListener::MOUSEDOWN_REASON + nsISelectionListener::DRAG_REASON);
|
2003-07-21 23:51:34 +04:00
|
|
|
if (aContinueSelection &&
|
|
|
|
AdjustForMaintainedSelection(aNewFocus, aContentOffset))
|
|
|
|
return NS_OK; //shift clicked to maintained selection. rejected.
|
|
|
|
|
2000-03-22 02:58:02 +03:00
|
|
|
return TakeFocus(aNewFocus, aContentOffset, aContentEndOffset, aContinueSelection, aMultipleSelection);
|
2000-04-14 00:21:32 +04:00
|
|
|
}
|
2000-03-22 02:58:02 +03:00
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2006-04-26 06:01:07 +04:00
|
|
|
void
|
|
|
|
nsFrameSelection::HandleDrag(nsIFrame *aFrame, nsPoint aPoint)
|
2000-03-22 02:58:02 +03:00
|
|
|
{
|
2006-04-26 06:01:07 +04:00
|
|
|
if (!aFrame)
|
|
|
|
return;
|
2000-03-22 02:58:02 +03:00
|
|
|
|
|
|
|
nsresult result;
|
|
|
|
nsIFrame *newFrame = 0;
|
|
|
|
nsPoint newPoint;
|
|
|
|
|
2006-04-26 06:01:07 +04:00
|
|
|
result = ConstrainFrameAndPointToAnchorSubtree(aFrame, aPoint, &newFrame, newPoint);
|
2000-03-22 02:58:02 +03:00
|
|
|
if (NS_FAILED(result))
|
2006-04-26 06:01:07 +04:00
|
|
|
return;
|
2000-03-22 02:58:02 +03:00
|
|
|
if (!newFrame)
|
2006-04-26 06:01:07 +04:00
|
|
|
return;
|
2000-03-22 02:58:02 +03:00
|
|
|
|
2006-02-27 08:57:37 +03:00
|
|
|
nsIFrame::ContentOffsets offsets =
|
|
|
|
newFrame->GetContentOffsetsFromPoint(newPoint);
|
2006-11-22 20:34:15 +03:00
|
|
|
if (!offsets.content)
|
|
|
|
return;
|
2000-08-09 03:38:00 +04:00
|
|
|
|
2003-07-21 23:51:34 +04:00
|
|
|
if ((newFrame->GetStateBits() & NS_FRAME_SELECTED_CONTENT) &&
|
2006-02-27 08:57:37 +03:00
|
|
|
AdjustForMaintainedSelection(offsets.content, offsets.offset))
|
2006-04-26 06:01:07 +04:00
|
|
|
return;
|
2002-08-30 05:32:11 +04:00
|
|
|
|
2006-07-12 11:07:36 +04:00
|
|
|
// Adjust offsets according to maintained amount
|
|
|
|
if (mMaintainRange &&
|
|
|
|
mMaintainedAmount != eSelectNoAmount) {
|
|
|
|
|
|
|
|
nsCOMPtr<nsIDOMNode> rangenode;
|
|
|
|
PRInt32 rangeOffset;
|
|
|
|
mMaintainRange->GetStartContainer(getter_AddRefs(rangenode));
|
|
|
|
mMaintainRange->GetStartOffset(&rangeOffset);
|
|
|
|
nsCOMPtr<nsIDOMNode> domNode = do_QueryInterface(offsets.content);
|
2006-10-21 05:30:54 +04:00
|
|
|
PRInt32 relativePosition = CompareDOMPoints(rangenode, rangeOffset,
|
|
|
|
domNode, offsets.offset);
|
2006-07-12 11:07:36 +04:00
|
|
|
|
|
|
|
nsDirection direction = relativePosition > 0 ? eDirPrevious : eDirNext;
|
|
|
|
nsSelectionAmount amount = mMaintainedAmount;
|
|
|
|
if (amount == eSelectBeginLine && direction == eDirNext)
|
|
|
|
amount = eSelectEndLine;
|
|
|
|
|
2006-07-13 13:08:56 +04:00
|
|
|
PRInt32 offset;
|
|
|
|
nsIFrame* frame = GetFrameForNodeOffset(offsets.content, offsets.offset, HINTRIGHT, &offset);
|
2006-07-12 11:07:36 +04:00
|
|
|
nsPeekOffsetStruct pos;
|
2006-07-13 13:08:56 +04:00
|
|
|
pos.SetData(amount, direction, offset, 0,
|
2006-07-13 10:06:29 +04:00
|
|
|
PR_FALSE, mLimiter != nsnull, PR_FALSE, PR_FALSE);
|
2006-07-12 11:07:36 +04:00
|
|
|
|
2006-09-12 00:43:01 +04:00
|
|
|
if (frame && NS_SUCCEEDED(frame->PeekOffset(&pos)) && pos.mResultContent) {
|
2006-07-12 11:07:36 +04:00
|
|
|
offsets.content = pos.mResultContent;
|
|
|
|
offsets.offset = pos.mContentOffset;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-04-26 06:01:07 +04:00
|
|
|
// XXX Code not up to date
|
2002-09-05 04:56:25 +04:00
|
|
|
#ifdef VISUALSELECTION
|
2006-04-26 06:01:07 +04:00
|
|
|
if (mShell->GetPresContext()->BidiEnabled()) {
|
|
|
|
PRUint8 level;
|
|
|
|
nsPeekOffsetStruct pos;
|
|
|
|
//set data using mLimiter to stop on scroll views. If we have a limiter then we stop peeking
|
|
|
|
//when we hit scrollable views. If no limiter then just let it go ahead
|
2006-07-13 10:06:29 +04:00
|
|
|
pos.SetData(eSelectDir, eDirNext, startPos, 0,
|
|
|
|
PR_TRUE, mLimiter != nsnull, PR_FALSE, PR_TRUE);
|
2006-04-26 06:01:07 +04:00
|
|
|
mHint = HINT(beginOfContent);
|
|
|
|
HINT saveHint = mHint;
|
|
|
|
if (NS_GET_EMBEDDING_LEVEL(newFrame) & 1)
|
|
|
|
mHint = (mHint==HINTLEFT) ? HINTRIGHT : HINTLEFT;
|
|
|
|
pos.mResultContent = newContent;
|
|
|
|
pos.mContentOffset = contentOffsetEnd;
|
|
|
|
result = VisualSelectFrames(newFrame, pos);
|
|
|
|
if (NS_FAILED(result))
|
|
|
|
HandleClick(newContent, startPos, contentOffsetEnd, PR_TRUE,
|
|
|
|
PR_FALSE, beginOfContent);
|
|
|
|
mHint = saveHint;
|
2000-03-22 02:58:02 +03:00
|
|
|
}
|
2006-04-26 06:01:07 +04:00
|
|
|
else
|
|
|
|
#endif // VISUALSELECTION
|
|
|
|
HandleClick(offsets.content, offsets.offset, offsets.offset,
|
|
|
|
PR_TRUE, PR_FALSE, offsets.associateWithNext);
|
2000-03-22 02:58:02 +03:00
|
|
|
}
|
|
|
|
|
2006-04-26 06:01:07 +04:00
|
|
|
nsresult
|
|
|
|
nsFrameSelection::StartAutoScrollTimer(nsIView *aView,
|
|
|
|
nsPoint aPoint,
|
|
|
|
PRUint32 aDelay)
|
2000-03-22 02:58:02 +03:00
|
|
|
{
|
2000-04-27 11:37:12 +04:00
|
|
|
PRInt8 index = GetIndexFromSelectionType(nsISelectionController::SELECTION_NORMAL);
|
2006-04-26 06:01:07 +04:00
|
|
|
return mDomSelections[index]->StartAutoScrollTimer(mShell->GetPresContext(),
|
|
|
|
aView, aPoint, aDelay);
|
2000-03-22 02:58:02 +03:00
|
|
|
}
|
|
|
|
|
2006-04-26 06:01:07 +04:00
|
|
|
void
|
|
|
|
nsFrameSelection::StopAutoScrollTimer()
|
2000-03-22 02:58:02 +03:00
|
|
|
{
|
2000-04-27 11:37:12 +04:00
|
|
|
PRInt8 index = GetIndexFromSelectionType(nsISelectionController::SELECTION_NORMAL);
|
2006-04-26 06:01:07 +04:00
|
|
|
mDomSelections[index]->StopAutoScrollTimer();
|
2000-03-22 02:58:02 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
hard to go from nodes to frames, easy the other way!
|
|
|
|
*/
|
2006-04-26 06:01:07 +04:00
|
|
|
nsresult
|
|
|
|
nsFrameSelection::TakeFocus(nsIContent *aNewFocus,
|
|
|
|
PRUint32 aContentOffset,
|
|
|
|
PRUint32 aContentEndOffset,
|
|
|
|
PRBool aContinueSelection,
|
|
|
|
PRBool aMultipleSelection)
|
2000-03-22 02:58:02 +03:00
|
|
|
{
|
|
|
|
if (!aNewFocus)
|
|
|
|
return NS_ERROR_NULL_POINTER;
|
2000-05-31 04:02:12 +04:00
|
|
|
|
2000-03-22 02:58:02 +03:00
|
|
|
STATUS_CHECK_RETURN_MACRO();
|
2000-05-02 07:44:17 +04:00
|
|
|
|
2002-03-26 02:44:46 +03:00
|
|
|
if (!IsValidSelectionPoint(this,aNewFocus))
|
|
|
|
return NS_ERROR_FAILURE;
|
2000-05-02 07:44:17 +04:00
|
|
|
|
2002-03-22 18:25:08 +03:00
|
|
|
// Clear all table selection data
|
|
|
|
mSelectingTableCellMode = 0;
|
|
|
|
mDragSelectingCells = PR_FALSE;
|
|
|
|
mStartSelectedCell = nsnull;
|
|
|
|
mEndSelectedCell = nsnull;
|
|
|
|
mAppendStartSelectedCell = nsnull;
|
|
|
|
|
2000-03-22 02:58:02 +03:00
|
|
|
//HACKHACKHACK
|
2003-07-29 01:09:56 +04:00
|
|
|
if (!aNewFocus->GetParent())
|
2000-03-22 02:58:02 +03:00
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
//END HACKHACKHACK /checking for root frames/content
|
2000-05-11 08:25:43 +04:00
|
|
|
|
2000-04-27 11:37:12 +04:00
|
|
|
PRInt8 index = GetIndexFromSelectionType(nsISelectionController::SELECTION_NORMAL);
|
2003-07-29 01:09:56 +04:00
|
|
|
nsCOMPtr<nsIDOMNode> domNode = do_QueryInterface(aNewFocus);
|
2000-03-22 02:58:02 +03:00
|
|
|
//traverse through document and unselect crap here
|
|
|
|
if (!aContinueSelection){ //single click? setting cursor down
|
|
|
|
PRUint32 batching = mBatching;//hack to use the collapse code.
|
|
|
|
PRBool changes = mChangesDuringBatching;
|
|
|
|
mBatching = 1;
|
|
|
|
|
|
|
|
if (aMultipleSelection){
|
|
|
|
nsCOMPtr<nsIDOMRange> newRange;
|
|
|
|
NS_NewRange(getter_AddRefs(newRange));
|
|
|
|
|
|
|
|
newRange->SetStart(domNode,aContentOffset);
|
|
|
|
newRange->SetEnd(domNode,aContentOffset);
|
2000-03-31 11:17:22 +04:00
|
|
|
mDomSelections[index]->AddRange(newRange);
|
2000-03-22 02:58:02 +03:00
|
|
|
mBatching = batching;
|
|
|
|
mChangesDuringBatching = changes;
|
2000-03-31 11:17:22 +04:00
|
|
|
mDomSelections[index]->SetOriginalAnchorPoint(domNode,aContentOffset);
|
2000-03-22 02:58:02 +03:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2002-04-17 03:26:22 +04:00
|
|
|
PRBool oldDesiredXSet = mDesiredXSet; //need to keep old desired X if it was set.
|
2000-03-31 11:17:22 +04:00
|
|
|
mDomSelections[index]->Collapse(domNode, aContentOffset);
|
2002-04-17 03:26:22 +04:00
|
|
|
mDesiredXSet = oldDesiredXSet; //now reset desired X back.
|
2000-03-22 02:58:02 +03:00
|
|
|
mBatching = batching;
|
|
|
|
mChangesDuringBatching = changes;
|
|
|
|
}
|
2001-03-21 04:16:22 +03:00
|
|
|
if (aContentEndOffset != aContentOffset)
|
2003-01-17 15:09:23 +03:00
|
|
|
mDomSelections[index]->Extend(domNode,aContentEndOffset);
|
2002-03-22 18:25:08 +03:00
|
|
|
|
|
|
|
//find out if we are inside a table. if so, find out which one and which cell
|
|
|
|
//once we do that, the next time we get a takefocus, check the parent tree.
|
|
|
|
//if we are no longer inside same table ,cell then switch to table selection mode.
|
|
|
|
// BUT only do this in an editor
|
|
|
|
|
|
|
|
PRInt16 displaySelection;
|
2004-09-01 09:16:00 +04:00
|
|
|
nsresult result = mShell->GetSelectionFlags(&displaySelection);
|
2002-03-22 18:25:08 +03:00
|
|
|
if (NS_FAILED(result))
|
|
|
|
return result;
|
|
|
|
|
|
|
|
// Editor has DISPLAY_ALL selection type
|
|
|
|
if (displaySelection == nsISelectionDisplay::DISPLAY_ALL)
|
|
|
|
{
|
|
|
|
mCellParent = GetCellParent(domNode);
|
|
|
|
#ifdef DEBUG_TABLE_SELECTION
|
|
|
|
if (mCellParent)
|
|
|
|
printf(" * TakeFocus - Collapsing into new cell\n");
|
|
|
|
#endif
|
|
|
|
}
|
2000-03-22 02:58:02 +03:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
// Now update the range list:
|
|
|
|
if (aContinueSelection && domNode)
|
|
|
|
{
|
2002-03-22 18:25:08 +03:00
|
|
|
PRInt32 offset;
|
|
|
|
nsIDOMNode *cellparent = GetCellParent(domNode);
|
|
|
|
if (mCellParent && cellparent && cellparent != mCellParent) //switch to cell selection mode
|
2000-03-22 02:58:02 +03:00
|
|
|
{
|
2002-03-22 18:25:08 +03:00
|
|
|
#ifdef DEBUG_TABLE_SELECTION
|
|
|
|
printf(" * TakeFocus - moving into new cell\n");
|
|
|
|
#endif
|
|
|
|
nsCOMPtr<nsIDOMNode> parent;
|
|
|
|
nsCOMPtr<nsIContent> parentContent;
|
2005-04-29 03:48:28 +04:00
|
|
|
nsMouseEvent event(PR_FALSE, 0, nsnull, nsMouseEvent::eReal);
|
2002-03-22 18:25:08 +03:00
|
|
|
nsresult result;
|
|
|
|
|
|
|
|
// Start selecting in the cell we were in before
|
|
|
|
result = ParentOffset(mCellParent, getter_AddRefs(parent),&offset);
|
|
|
|
parentContent = do_QueryInterface(parent);
|
|
|
|
if (parentContent)
|
|
|
|
result = HandleTableSelection(parentContent, offset, nsISelectionPrivate::TABLESELECTION_CELL, &event);
|
|
|
|
|
|
|
|
// Find the parent of this new cell and extend selection to it
|
|
|
|
result = ParentOffset(cellparent,getter_AddRefs(parent),&offset);
|
|
|
|
parentContent = do_QueryInterface(parent);
|
|
|
|
|
|
|
|
// XXXX We need to REALLY get the current key shift state
|
|
|
|
// (we'd need to add event listener -- let's not bother for now)
|
|
|
|
event.isShift = PR_FALSE; //aContinueSelection;
|
|
|
|
if (parentContent)
|
|
|
|
{
|
|
|
|
mCellParent = cellparent;
|
|
|
|
// Continue selection into next cell
|
|
|
|
result = HandleTableSelection(parentContent, offset, nsISelectionPrivate::TABLESELECTION_CELL, &event);
|
|
|
|
}
|
2000-03-22 02:58:02 +03:00
|
|
|
}
|
|
|
|
else
|
2002-03-22 18:25:08 +03:00
|
|
|
{
|
|
|
|
// XXXX Problem: Shift+click in browser is appending text selection to selected table!!!
|
|
|
|
// is this the place to erase seleced cells ?????
|
2005-11-21 01:05:24 +03:00
|
|
|
if (mDomSelections[index]->GetDirection() == eDirNext && aContentEndOffset > aContentOffset) //didn't go far enough
|
2002-03-22 18:25:08 +03:00
|
|
|
{
|
|
|
|
mDomSelections[index]->Extend(domNode, aContentEndOffset);//this will only redraw the diff
|
|
|
|
}
|
|
|
|
else
|
|
|
|
mDomSelections[index]->Extend(domNode, aContentOffset);
|
|
|
|
}
|
2000-03-22 02:58:02 +03:00
|
|
|
}
|
|
|
|
}
|
2000-05-31 04:02:12 +04:00
|
|
|
|
|
|
|
// Don't notify selection listeners if batching is on:
|
|
|
|
if (GetBatching())
|
|
|
|
return NS_OK;
|
2000-04-27 11:37:12 +04:00
|
|
|
return NotifySelectionListeners(nsISelectionController::SELECTION_NORMAL);
|
2000-03-22 02:58:02 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2006-04-26 06:01:07 +04:00
|
|
|
SelectionDetails*
|
|
|
|
nsFrameSelection::LookUpSelection(nsIContent *aContent, PRInt32 aContentOffset,
|
|
|
|
PRInt32 aContentLength, PRBool aSlowCheck)
|
2000-03-22 02:58:02 +03:00
|
|
|
{
|
2006-04-26 06:01:07 +04:00
|
|
|
if (!aContent || !mShell)
|
|
|
|
return nsnull;
|
2005-01-31 20:57:35 +03:00
|
|
|
|
2006-04-26 06:01:07 +04:00
|
|
|
SelectionDetails* details = nsnull;
|
2005-01-31 20:57:35 +03:00
|
|
|
|
2006-07-27 21:57:15 +04:00
|
|
|
for (PRInt32 j = 0; j < nsISelectionController::NUM_SELECTIONTYPES; j++) {
|
|
|
|
if (mDomSelections[j]) {
|
|
|
|
mDomSelections[j]->LookUpSelection(aContent, aContentOffset,
|
|
|
|
aContentLength, &details, (SelectionType)(1<<j), aSlowCheck);
|
|
|
|
}
|
2000-03-22 02:58:02 +03:00
|
|
|
}
|
|
|
|
|
2006-04-26 06:01:07 +04:00
|
|
|
return details;
|
|
|
|
}
|
2000-03-22 02:58:02 +03:00
|
|
|
|
2006-04-26 06:01:07 +04:00
|
|
|
void
|
|
|
|
nsFrameSelection::SetMouseDownState(PRBool aState)
|
2000-03-22 02:58:02 +03:00
|
|
|
{
|
2000-05-13 13:10:16 +04:00
|
|
|
if (mMouseDownState == aState)
|
2006-04-26 06:01:07 +04:00
|
|
|
return;
|
|
|
|
|
2000-03-22 02:58:02 +03:00
|
|
|
mMouseDownState = aState;
|
2006-04-26 06:01:07 +04:00
|
|
|
|
2000-03-22 02:58:02 +03:00
|
|
|
if (!mMouseDownState)
|
|
|
|
{
|
2006-04-26 06:01:07 +04:00
|
|
|
PostReason(nsISelectionListener::MOUSEUP_REASON);
|
|
|
|
NotifySelectionListeners(nsISelectionController::SELECTION_NORMAL); //notify that reason is mouse up please.
|
2000-03-22 02:58:02 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-04-26 06:01:07 +04:00
|
|
|
nsISelection*
|
|
|
|
nsFrameSelection::GetSelection(SelectionType aType)
|
2000-03-22 02:58:02 +03:00
|
|
|
{
|
2000-03-31 11:17:22 +04:00
|
|
|
PRInt8 index = GetIndexFromSelectionType(aType);
|
|
|
|
if (index < 0)
|
2006-04-26 06:01:07 +04:00
|
|
|
return nsnull;
|
|
|
|
|
|
|
|
return NS_STATIC_CAST(nsISelection*, mDomSelections[index]);
|
2000-03-22 02:58:02 +03:00
|
|
|
}
|
|
|
|
|
2006-04-26 06:01:07 +04:00
|
|
|
nsresult
|
|
|
|
nsFrameSelection::ScrollSelectionIntoView(SelectionType aType,
|
|
|
|
SelectionRegion aRegion,
|
|
|
|
PRBool aIsSynchronous)
|
2000-03-22 02:58:02 +03:00
|
|
|
{
|
2000-03-31 11:17:22 +04:00
|
|
|
PRInt8 index = GetIndexFromSelectionType(aType);
|
|
|
|
if (index < 0)
|
|
|
|
return NS_ERROR_INVALID_ARG;
|
2000-03-22 02:58:02 +03:00
|
|
|
|
2000-03-31 11:17:22 +04:00
|
|
|
if (!mDomSelections[index])
|
2000-03-22 02:58:02 +03:00
|
|
|
return NS_ERROR_NULL_POINTER;
|
|
|
|
|
2002-06-14 00:43:32 +04:00
|
|
|
return mDomSelections[index]->ScrollIntoView(aRegion, aIsSynchronous);
|
2000-03-22 02:58:02 +03:00
|
|
|
}
|
|
|
|
|
2006-04-26 06:01:07 +04:00
|
|
|
nsresult
|
|
|
|
nsFrameSelection::RepaintSelection(SelectionType aType)
|
2000-03-22 02:58:02 +03:00
|
|
|
{
|
2000-03-31 11:17:22 +04:00
|
|
|
PRInt8 index = GetIndexFromSelectionType(aType);
|
|
|
|
if (index < 0)
|
|
|
|
return NS_ERROR_INVALID_ARG;
|
|
|
|
if (!mDomSelections[index])
|
2000-03-22 02:58:02 +03:00
|
|
|
return NS_ERROR_NULL_POINTER;
|
2006-04-26 06:01:07 +04:00
|
|
|
return mDomSelections[index]->Repaint(mShell->GetPresContext());
|
2000-03-22 02:58:02 +03:00
|
|
|
}
|
|
|
|
|
2006-04-26 06:01:07 +04:00
|
|
|
nsIFrame*
|
|
|
|
nsFrameSelection::GetFrameForNodeOffset(nsIContent *aNode,
|
|
|
|
PRInt32 aOffset,
|
|
|
|
HINT aHint,
|
|
|
|
PRInt32 *aReturnOffset)
|
2000-03-22 02:58:02 +03:00
|
|
|
{
|
2006-04-26 06:01:07 +04:00
|
|
|
if (!aNode || !aReturnOffset)
|
|
|
|
return nsnull;
|
2000-03-22 02:58:02 +03:00
|
|
|
|
|
|
|
if (aOffset < 0)
|
2006-04-26 06:01:07 +04:00
|
|
|
return nsnull;
|
2000-03-22 02:58:02 +03:00
|
|
|
|
|
|
|
*aReturnOffset = aOffset;
|
|
|
|
|
2000-05-01 04:26:37 +04:00
|
|
|
nsCOMPtr<nsIContent> theNode = aNode;
|
|
|
|
|
2006-05-05 10:52:21 +04:00
|
|
|
if (aNode->IsNodeOfType(nsINode::eELEMENT))
|
2000-03-22 02:58:02 +03:00
|
|
|
{
|
|
|
|
PRInt32 childIndex = 0;
|
2007-02-05 00:24:49 +03:00
|
|
|
PRInt32 numChildren = theNode->GetChildCount();
|
2000-03-22 02:58:02 +03:00
|
|
|
|
2000-06-28 08:00:12 +04:00
|
|
|
if (aHint == HINTLEFT)
|
2000-03-22 02:58:02 +03:00
|
|
|
{
|
|
|
|
if (aOffset > 0)
|
|
|
|
childIndex = aOffset - 1;
|
|
|
|
else
|
|
|
|
childIndex = aOffset;
|
|
|
|
}
|
|
|
|
else // HINTRIGHT
|
|
|
|
{
|
|
|
|
if (aOffset >= numChildren)
|
2005-08-22 05:32:03 +04:00
|
|
|
{
|
|
|
|
if (numChildren > 0)
|
|
|
|
childIndex = numChildren - 1;
|
|
|
|
else
|
|
|
|
childIndex = 0;
|
|
|
|
}
|
2000-03-22 02:58:02 +03:00
|
|
|
else
|
|
|
|
childIndex = aOffset;
|
|
|
|
}
|
2000-05-02 07:44:17 +04:00
|
|
|
|
2007-01-30 22:36:55 +03:00
|
|
|
if (childIndex > 0 || numChildren > 0) {
|
2007-01-30 22:29:55 +03:00
|
|
|
nsCOMPtr<nsIContent> childNode = theNode->GetChildAt(childIndex);
|
2000-03-22 02:58:02 +03:00
|
|
|
|
2007-01-30 22:29:55 +03:00
|
|
|
if (!childNode)
|
|
|
|
return nsnull;
|
2000-03-22 02:58:02 +03:00
|
|
|
|
2007-01-30 22:29:55 +03:00
|
|
|
theNode = childNode;
|
|
|
|
}
|
2000-05-01 22:21:30 +04:00
|
|
|
|
2000-03-22 02:58:02 +03:00
|
|
|
#ifdef DONT_DO_THIS_YET
|
|
|
|
// XXX: We can't use this code yet because the hinting
|
|
|
|
// can cause us to attatch to the wrong line frame.
|
|
|
|
|
|
|
|
// Now that we have the child node, check if it too
|
|
|
|
// can contain children. If so, call this method again!
|
|
|
|
|
2006-05-05 10:52:21 +04:00
|
|
|
if (theNode->IsNodeOfType(nsINode::eELEMENT))
|
2000-03-22 02:58:02 +03:00
|
|
|
{
|
|
|
|
PRInt32 newOffset = 0;
|
|
|
|
|
|
|
|
if (aOffset > childIndex)
|
|
|
|
{
|
2003-09-27 08:18:26 +04:00
|
|
|
numChildren = theNode->GetChildCount();
|
2000-03-22 02:58:02 +03:00
|
|
|
|
|
|
|
newOffset = numChildren;
|
|
|
|
}
|
|
|
|
|
2006-04-26 06:01:07 +04:00
|
|
|
return GetFrameForNodeOffset(theNode, newOffset, aHint, aReturnOffset);
|
2000-03-22 02:58:02 +03:00
|
|
|
}
|
|
|
|
else
|
|
|
|
#endif // DONT_DO_THIS_YET
|
|
|
|
{
|
2000-05-01 04:26:37 +04:00
|
|
|
// Check to see if theNode is a text node. If it is, translate
|
2000-03-22 02:58:02 +03:00
|
|
|
// aOffset into an offset into the text node.
|
|
|
|
|
2000-05-01 04:26:37 +04:00
|
|
|
nsCOMPtr<nsIDOMText> textNode = do_QueryInterface(theNode);
|
2000-03-22 02:58:02 +03:00
|
|
|
|
|
|
|
if (textNode)
|
|
|
|
{
|
|
|
|
if (aOffset > childIndex)
|
|
|
|
{
|
|
|
|
PRUint32 textLength = 0;
|
|
|
|
|
2006-04-26 06:01:07 +04:00
|
|
|
nsresult rv = textNode->GetLength(&textLength);
|
|
|
|
if (NS_FAILED(rv))
|
|
|
|
return nsnull;
|
2000-03-22 02:58:02 +03:00
|
|
|
|
|
|
|
*aReturnOffset = (PRInt32)textLength;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
*aReturnOffset = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-04-26 06:01:07 +04:00
|
|
|
nsIFrame* returnFrame = mShell->GetPrimaryFrameFor(theNode);
|
|
|
|
if (!returnFrame)
|
|
|
|
return nsnull;
|
2003-03-12 06:22:11 +03:00
|
|
|
|
2000-03-22 02:58:02 +03:00
|
|
|
// find the child frame containing the offset we want
|
2006-04-26 06:01:07 +04:00
|
|
|
returnFrame->GetChildFrameContainingOffset(*aReturnOffset, aHint,
|
|
|
|
&aOffset, &returnFrame);
|
|
|
|
return returnFrame;
|
2000-03-22 02:58:02 +03:00
|
|
|
}
|
|
|
|
|
2006-04-26 06:01:07 +04:00
|
|
|
void
|
|
|
|
nsFrameSelection::CommonPageMove(PRBool aForward,
|
|
|
|
PRBool aExtend,
|
|
|
|
nsIScrollableView *aScrollableView)
|
2002-08-27 00:55:30 +04:00
|
|
|
{
|
2006-04-26 06:01:07 +04:00
|
|
|
if (!aScrollableView)
|
|
|
|
return;
|
2002-08-27 00:55:30 +04:00
|
|
|
// expected behavior for PageMove is to scroll AND move the caret
|
|
|
|
// and remain relative position of the caret in view. see Bug 4302.
|
|
|
|
|
|
|
|
nsresult result;
|
|
|
|
//get the frame from the scrollable view
|
|
|
|
|
|
|
|
nsIFrame* mainframe = nsnull;
|
|
|
|
|
|
|
|
// The view's client data points back to its frame
|
|
|
|
nsIView *scrolledView;
|
|
|
|
result = aScrollableView->GetScrolledView(scrolledView);
|
|
|
|
|
|
|
|
if (NS_FAILED(result))
|
2006-04-26 06:01:07 +04:00
|
|
|
return;
|
2002-08-27 00:55:30 +04:00
|
|
|
|
2003-08-06 07:07:12 +04:00
|
|
|
if (scrolledView)
|
|
|
|
mainframe = NS_STATIC_CAST(nsIFrame*, scrolledView->GetClientData());
|
2002-08-27 00:55:30 +04:00
|
|
|
|
|
|
|
if (!mainframe)
|
2006-04-26 06:01:07 +04:00
|
|
|
return;
|
2002-08-27 00:55:30 +04:00
|
|
|
|
|
|
|
// find out where the caret is.
|
2006-04-26 06:01:07 +04:00
|
|
|
// we should know mDesiredX value of nsFrameSelection, but I havent seen that behavior in other windows applications yet.
|
|
|
|
nsISelection* domSel = GetSelection(nsISelectionController::SELECTION_NORMAL);
|
2002-08-27 00:55:30 +04:00
|
|
|
|
|
|
|
if (!domSel)
|
2006-04-26 06:01:07 +04:00
|
|
|
return;
|
2002-08-27 00:55:30 +04:00
|
|
|
|
|
|
|
nsCOMPtr<nsICaret> caret;
|
|
|
|
nsRect caretPos;
|
|
|
|
PRBool isCollapsed;
|
2004-09-01 09:16:00 +04:00
|
|
|
result = mShell->GetCaret(getter_AddRefs(caret));
|
2002-08-27 00:55:30 +04:00
|
|
|
|
|
|
|
if (NS_FAILED(result))
|
2006-04-26 06:01:07 +04:00
|
|
|
return;
|
2002-08-27 00:55:30 +04:00
|
|
|
|
|
|
|
nsIView *caretView;
|
|
|
|
result = caret->GetCaretCoordinates(nsICaret::eClosestViewCoordinates, domSel, &caretPos, &isCollapsed, &caretView);
|
|
|
|
|
|
|
|
if (NS_FAILED(result))
|
2006-04-26 06:01:07 +04:00
|
|
|
return;
|
2002-08-27 00:55:30 +04:00
|
|
|
|
|
|
|
//need to adjust caret jump by percentage scroll
|
2004-11-25 01:05:36 +03:00
|
|
|
nsSize scrollDelta;
|
|
|
|
aScrollableView->GetPageScrollDistances(&scrollDelta);
|
|
|
|
|
2002-08-27 00:55:30 +04:00
|
|
|
if (aForward)
|
2004-11-25 01:05:36 +03:00
|
|
|
caretPos.y += scrollDelta.height;
|
2002-08-27 00:55:30 +04:00
|
|
|
else
|
2004-11-25 01:05:36 +03:00
|
|
|
caretPos.y -= scrollDelta.height;
|
2002-08-27 00:55:30 +04:00
|
|
|
|
|
|
|
|
|
|
|
if (caretView)
|
|
|
|
{
|
2004-11-03 19:16:57 +03:00
|
|
|
caretPos += caretView->GetOffsetTo(scrolledView);
|
2002-08-27 00:55:30 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
// get a content at desired location
|
|
|
|
nsPoint desiredPoint;
|
|
|
|
desiredPoint.x = caretPos.x;
|
|
|
|
desiredPoint.y = caretPos.y + caretPos.height/2;
|
2006-02-27 08:57:37 +03:00
|
|
|
nsIFrame::ContentOffsets offsets =
|
|
|
|
mainframe->GetContentOffsetsFromPoint(desiredPoint);
|
|
|
|
|
|
|
|
if (!offsets.content)
|
2006-04-26 06:01:07 +04:00
|
|
|
return;
|
2002-08-27 00:55:30 +04:00
|
|
|
|
|
|
|
// scroll one page
|
2003-03-12 06:22:11 +03:00
|
|
|
aScrollableView->ScrollByPages(0, aForward ? 1 : -1);
|
2006-02-27 08:57:37 +03:00
|
|
|
|
2002-08-27 00:55:30 +04:00
|
|
|
// place the caret
|
2006-04-26 06:01:07 +04:00
|
|
|
HandleClick(offsets.content, offsets.offset,
|
|
|
|
offsets.offset, aExtend, PR_FALSE, PR_TRUE);
|
2002-08-27 00:55:30 +04:00
|
|
|
}
|
|
|
|
|
2006-04-26 06:01:07 +04:00
|
|
|
nsresult
|
|
|
|
nsFrameSelection::CharacterMove(PRBool aForward, PRBool aExtend)
|
2000-03-22 02:58:02 +03:00
|
|
|
{
|
|
|
|
if (aForward)
|
|
|
|
return MoveCaret(nsIDOMKeyEvent::DOM_VK_RIGHT,aExtend,eSelectCharacter);
|
|
|
|
else
|
|
|
|
return MoveCaret(nsIDOMKeyEvent::DOM_VK_LEFT,aExtend,eSelectCharacter);
|
|
|
|
}
|
|
|
|
|
2006-04-26 06:01:07 +04:00
|
|
|
nsresult
|
|
|
|
nsFrameSelection::WordMove(PRBool aForward, PRBool aExtend)
|
2000-03-22 02:58:02 +03:00
|
|
|
{
|
|
|
|
if (aForward)
|
|
|
|
return MoveCaret(nsIDOMKeyEvent::DOM_VK_RIGHT,aExtend,eSelectWord);
|
|
|
|
else
|
|
|
|
return MoveCaret(nsIDOMKeyEvent::DOM_VK_LEFT,aExtend,eSelectWord);
|
|
|
|
}
|
|
|
|
|
2006-07-18 11:28:38 +04:00
|
|
|
nsresult
|
|
|
|
nsFrameSelection::WordExtendForDelete(PRBool aForward)
|
|
|
|
{
|
|
|
|
if (aForward)
|
|
|
|
return MoveCaret(nsIDOMKeyEvent::DOM_VK_DELETE, PR_TRUE, eSelectWord);
|
|
|
|
else
|
|
|
|
return MoveCaret(nsIDOMKeyEvent::DOM_VK_BACK_SPACE, PR_TRUE, eSelectWord);
|
|
|
|
}
|
|
|
|
|
2006-04-26 06:01:07 +04:00
|
|
|
nsresult
|
|
|
|
nsFrameSelection::LineMove(PRBool aForward, PRBool aExtend)
|
2000-03-22 02:58:02 +03:00
|
|
|
{
|
|
|
|
if (aForward)
|
|
|
|
return MoveCaret(nsIDOMKeyEvent::DOM_VK_DOWN,aExtend,eSelectLine);
|
|
|
|
else
|
|
|
|
return MoveCaret(nsIDOMKeyEvent::DOM_VK_UP,aExtend,eSelectLine);
|
|
|
|
}
|
|
|
|
|
2006-04-26 06:01:07 +04:00
|
|
|
nsresult
|
|
|
|
nsFrameSelection::IntraLineMove(PRBool aForward, PRBool aExtend)
|
2000-03-22 02:58:02 +03:00
|
|
|
{
|
|
|
|
if (aForward)
|
|
|
|
return MoveCaret(nsIDOMKeyEvent::DOM_VK_END,aExtend,eSelectLine);
|
|
|
|
else
|
|
|
|
return MoveCaret(nsIDOMKeyEvent::DOM_VK_HOME,aExtend,eSelectLine);
|
|
|
|
}
|
|
|
|
|
2006-04-26 06:01:07 +04:00
|
|
|
nsresult
|
|
|
|
nsFrameSelection::SelectAll()
|
2000-03-22 02:58:02 +03:00
|
|
|
{
|
2000-06-29 09:25:01 +04:00
|
|
|
nsCOMPtr<nsIContent> rootContent;
|
|
|
|
if (mLimiter)
|
|
|
|
{
|
|
|
|
rootContent = mLimiter;//addrefit
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2004-09-01 09:16:00 +04:00
|
|
|
nsIDocument *doc = mShell->GetDocument();
|
2001-10-24 08:50:37 +04:00
|
|
|
if (!doc)
|
|
|
|
return NS_ERROR_FAILURE;
|
2003-10-22 10:09:48 +04:00
|
|
|
rootContent = doc->GetRootContent();
|
2000-06-29 09:25:01 +04:00
|
|
|
if (!rootContent)
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
2003-09-27 08:18:26 +04:00
|
|
|
PRInt32 numChildren = rootContent->GetChildCount();
|
2000-09-14 15:45:01 +04:00
|
|
|
PostReason(nsISelectionListener::NO_REASON);
|
2000-06-29 09:25:01 +04:00
|
|
|
return TakeFocus(mLimiter, 0, numChildren, PR_FALSE, PR_FALSE);
|
2000-03-22 02:58:02 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
//////////END FRAMESELECTION
|
|
|
|
|
2006-04-26 06:01:07 +04:00
|
|
|
void
|
|
|
|
nsFrameSelection::StartBatchChanges()
|
2000-03-22 02:58:02 +03:00
|
|
|
{
|
|
|
|
mBatching++;
|
|
|
|
}
|
|
|
|
|
2006-04-26 06:01:07 +04:00
|
|
|
void
|
|
|
|
nsFrameSelection::EndBatchChanges()
|
2000-03-22 02:58:02 +03:00
|
|
|
{
|
|
|
|
mBatching--;
|
|
|
|
NS_ASSERTION(mBatching >=0,"Bad mBatching");
|
|
|
|
if (mBatching == 0 && mChangesDuringBatching){
|
|
|
|
mChangesDuringBatching = PR_FALSE;
|
2000-04-27 11:37:12 +04:00
|
|
|
NotifySelectionListeners(nsISelectionController::SELECTION_NORMAL);
|
2000-03-22 02:58:02 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2000-08-09 03:38:00 +04:00
|
|
|
|
2000-03-22 02:58:02 +03:00
|
|
|
nsresult
|
2006-04-26 06:01:07 +04:00
|
|
|
nsFrameSelection::NotifySelectionListeners(SelectionType aType)
|
2000-03-22 02:58:02 +03:00
|
|
|
{
|
2000-05-04 12:35:42 +04:00
|
|
|
PRInt8 index = GetIndexFromSelectionType(aType);
|
|
|
|
if (index >=0)
|
2000-03-22 02:58:02 +03:00
|
|
|
{
|
2000-05-04 12:35:42 +04:00
|
|
|
return mDomSelections[index]->NotifySelectionListeners();
|
2000-03-22 02:58:02 +03:00
|
|
|
}
|
2000-05-04 12:35:42 +04:00
|
|
|
return NS_ERROR_FAILURE;
|
2000-03-22 02:58:02 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
// Start of Table Selection methods
|
|
|
|
|
2000-03-23 07:24:58 +03:00
|
|
|
static PRBool IsCell(nsIContent *aContent)
|
|
|
|
{
|
2006-12-26 20:47:52 +03:00
|
|
|
return ((aContent->Tag() == nsGkAtoms::td ||
|
|
|
|
aContent->Tag() == nsGkAtoms::th) &&
|
2006-05-05 10:52:21 +04:00
|
|
|
aContent->IsNodeOfType(nsINode::eHTML));
|
2000-03-23 07:24:58 +03:00
|
|
|
}
|
|
|
|
|
2000-05-16 07:03:13 +04:00
|
|
|
nsITableCellLayout*
|
2006-04-26 06:01:07 +04:00
|
|
|
nsFrameSelection::GetCellLayout(nsIContent *aCellContent)
|
2000-05-16 07:03:13 +04:00
|
|
|
{
|
|
|
|
// Get frame for cell
|
2005-08-23 02:24:29 +04:00
|
|
|
nsIFrame *cellFrame = mShell->GetPrimaryFrameFor(aCellContent);
|
2002-12-11 17:24:49 +03:00
|
|
|
if (!cellFrame)
|
|
|
|
return nsnull;
|
|
|
|
|
2000-05-16 07:03:13 +04:00
|
|
|
nsITableCellLayout *cellLayoutObject = nsnull;
|
2002-12-11 17:24:49 +03:00
|
|
|
CallQueryInterface(cellFrame, &cellLayoutObject);
|
|
|
|
|
2000-05-16 07:03:13 +04:00
|
|
|
return cellLayoutObject;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsITableLayout*
|
2006-04-26 06:01:07 +04:00
|
|
|
nsFrameSelection::GetTableLayout(nsIContent *aTableContent)
|
2000-05-16 07:03:13 +04:00
|
|
|
{
|
|
|
|
// Get frame for table
|
2005-08-23 02:24:29 +04:00
|
|
|
nsIFrame *tableFrame = mShell->GetPrimaryFrameFor(aTableContent);
|
2002-12-11 17:24:49 +03:00
|
|
|
if (!tableFrame)
|
|
|
|
return nsnull;
|
|
|
|
|
2000-05-16 07:03:13 +04:00
|
|
|
nsITableLayout *tableLayoutObject = nsnull;
|
2002-12-11 17:24:49 +03:00
|
|
|
CallQueryInterface(tableFrame, &tableLayoutObject);
|
|
|
|
|
2000-05-16 07:03:13 +04:00
|
|
|
return tableLayoutObject;
|
|
|
|
}
|
|
|
|
|
2000-05-31 04:07:58 +04:00
|
|
|
nsresult
|
2006-04-26 06:01:07 +04:00
|
|
|
nsFrameSelection::ClearNormalSelection()
|
2000-05-31 04:07:58 +04:00
|
|
|
{
|
|
|
|
PRInt8 index = GetIndexFromSelectionType(nsISelectionController::SELECTION_NORMAL);
|
2000-09-14 15:45:01 +04:00
|
|
|
return mDomSelections[index]->RemoveAllRanges();
|
2000-05-31 04:07:58 +04:00
|
|
|
}
|
|
|
|
|
2000-12-21 01:13:54 +03:00
|
|
|
// Table selection support.
|
|
|
|
// TODO: Separate table methods into a separate nsITableSelection interface
|
2000-03-22 02:58:02 +03:00
|
|
|
nsresult
|
2006-04-26 06:01:07 +04:00
|
|
|
nsFrameSelection::HandleTableSelection(nsIContent *aParentContent, PRInt32 aContentOffset, PRInt32 aTarget, nsMouseEvent *aMouseEvent)
|
2000-03-22 02:58:02 +03:00
|
|
|
{
|
2002-03-22 18:25:08 +03:00
|
|
|
NS_ENSURE_TRUE(aParentContent, NS_ERROR_NULL_POINTER);
|
|
|
|
NS_ENSURE_TRUE(aMouseEvent, NS_ERROR_NULL_POINTER);
|
|
|
|
|
|
|
|
if (mMouseDownState && mDragSelectingCells && (aTarget & nsISelectionPrivate::TABLESELECTION_TABLE))
|
2000-03-22 02:58:02 +03:00
|
|
|
{
|
|
|
|
// We were selecting cells and user drags mouse in table border or inbetween cells,
|
|
|
|
// just do nothing
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsCOMPtr<nsIDOMNode> parentNode = do_QueryInterface(aParentContent);
|
2003-09-27 08:18:26 +04:00
|
|
|
if (!parentNode)
|
|
|
|
return NS_ERROR_FAILURE;
|
2003-06-14 00:10:01 +04:00
|
|
|
|
2003-09-27 08:18:26 +04:00
|
|
|
nsresult result = NS_OK;
|
2000-03-22 02:58:02 +03:00
|
|
|
|
2003-09-27 08:18:26 +04:00
|
|
|
nsIContent *childContent = aParentContent->GetChildAt(aContentOffset);
|
2000-05-31 04:07:58 +04:00
|
|
|
nsCOMPtr<nsIDOMNode> childNode = do_QueryInterface(childContent);
|
2003-09-27 08:18:26 +04:00
|
|
|
if (!childNode)
|
|
|
|
return NS_ERROR_FAILURE;
|
2000-03-22 02:58:02 +03:00
|
|
|
|
2003-09-27 08:18:26 +04:00
|
|
|
// When doing table selection, always set the direction to next so
|
|
|
|
// we can be sure that anchorNode's offset always points to the
|
|
|
|
// selected cell
|
2000-05-16 07:03:13 +04:00
|
|
|
PRInt8 index = GetIndexFromSelectionType(nsISelectionController::SELECTION_NORMAL);
|
2000-03-31 11:17:22 +04:00
|
|
|
mDomSelections[index]->SetDirection(eDirNext);
|
2000-03-22 02:58:02 +03:00
|
|
|
|
2000-05-16 07:03:13 +04:00
|
|
|
// Stack-class to wrap all table selection changes in
|
|
|
|
// BeginBatchChanges() / EndBatchChanges()
|
|
|
|
nsSelectionBatcher selectionBatcher(mDomSelections[index]);
|
|
|
|
|
2000-05-31 04:07:58 +04:00
|
|
|
PRInt32 startRowIndex, startColIndex, curRowIndex, curColIndex;
|
2002-03-22 18:25:08 +03:00
|
|
|
if (mMouseDownState && mDragSelectingCells)
|
2000-03-22 02:58:02 +03:00
|
|
|
{
|
2000-05-16 07:03:13 +04:00
|
|
|
// We are drag-selecting
|
2000-12-21 01:13:54 +03:00
|
|
|
if (aTarget != nsISelectionPrivate::TABLESELECTION_TABLE)
|
2000-03-22 02:58:02 +03:00
|
|
|
{
|
|
|
|
// If dragging in the same cell as last event, do nothing
|
2000-05-31 04:07:58 +04:00
|
|
|
if (mEndSelectedCell == childContent)
|
2000-03-22 02:58:02 +03:00
|
|
|
return NS_OK;
|
|
|
|
|
2001-01-04 03:24:39 +03:00
|
|
|
#ifdef DEBUG_TABLE_SELECTION
|
|
|
|
printf(" mStartSelectedCell = %x, mEndSelectedCell = %x, childContent = %x \n", mStartSelectedCell, mEndSelectedCell, childContent);
|
|
|
|
#endif
|
2000-05-31 04:07:58 +04:00
|
|
|
// aTarget can be any "cell mode",
|
|
|
|
// so we can easily drag-select rows and columns
|
|
|
|
// Once we are in row or column mode,
|
|
|
|
// we can drift into any cell to stay in that mode
|
|
|
|
// even if aTarget = TABLESELECTION_CELL
|
|
|
|
|
2000-12-21 01:13:54 +03:00
|
|
|
if (mSelectingTableCellMode == nsISelectionPrivate::TABLESELECTION_ROW ||
|
|
|
|
mSelectingTableCellMode == nsISelectionPrivate::TABLESELECTION_COLUMN)
|
2000-05-16 07:03:13 +04:00
|
|
|
{
|
2000-05-31 04:07:58 +04:00
|
|
|
if (mEndSelectedCell)
|
|
|
|
{
|
|
|
|
// Also check if cell is in same row/col
|
|
|
|
result = GetCellIndexes(mEndSelectedCell, startRowIndex, startColIndex);
|
|
|
|
if (NS_FAILED(result)) return result;
|
|
|
|
result = GetCellIndexes(childContent, curRowIndex, curColIndex);
|
|
|
|
if (NS_FAILED(result)) return result;
|
|
|
|
|
2001-01-04 03:24:39 +03:00
|
|
|
#ifdef DEBUG_TABLE_SELECTION
|
|
|
|
printf(" curRowIndex = %d, startRowIndex = %d, curColIndex = %d, startColIndex = %d\n", curRowIndex, startRowIndex, curColIndex, startColIndex);
|
|
|
|
#endif
|
2000-12-21 01:13:54 +03:00
|
|
|
if ((mSelectingTableCellMode == nsISelectionPrivate::TABLESELECTION_ROW && startRowIndex == curRowIndex) ||
|
|
|
|
(mSelectingTableCellMode == nsISelectionPrivate::TABLESELECTION_COLUMN && startColIndex == curColIndex))
|
2000-05-31 04:07:58 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
2000-06-03 03:05:06 +04:00
|
|
|
#ifdef DEBUG_TABLE_SELECTION
|
2001-01-04 03:24:39 +03:00
|
|
|
printf(" Dragged into a new column or row\n");
|
2000-03-22 02:58:02 +03:00
|
|
|
#endif
|
2000-05-31 04:07:58 +04:00
|
|
|
// Continue dragging row or column selection
|
|
|
|
return SelectRowOrColumn(childContent, mSelectingTableCellMode);
|
2000-05-16 07:03:13 +04:00
|
|
|
}
|
2000-12-21 01:13:54 +03:00
|
|
|
else if (mSelectingTableCellMode == nsISelectionPrivate::TABLESELECTION_CELL)
|
2000-05-16 07:03:13 +04:00
|
|
|
{
|
2000-06-03 03:05:06 +04:00
|
|
|
#ifdef DEBUG_TABLE_SELECTION
|
2000-10-29 02:17:53 +04:00
|
|
|
printf("HandleTableSelection: Dragged into a new cell\n");
|
2000-05-16 07:03:13 +04:00
|
|
|
#endif
|
2000-05-31 04:07:58 +04:00
|
|
|
// Trick for quick selection of rows and columns
|
|
|
|
// Hold down shift, then start selecting in one direction
|
|
|
|
// If next cell dragged into is in same row, select entire row,
|
|
|
|
// if next cell is in same column, select entire column
|
|
|
|
if (mStartSelectedCell && aMouseEvent->isShift)
|
|
|
|
{
|
|
|
|
result = GetCellIndexes(mStartSelectedCell, startRowIndex, startColIndex);
|
|
|
|
if (NS_FAILED(result)) return result;
|
|
|
|
result = GetCellIndexes(childContent, curRowIndex, curColIndex);
|
|
|
|
if (NS_FAILED(result)) return result;
|
|
|
|
|
|
|
|
if (startRowIndex == curRowIndex ||
|
|
|
|
startColIndex == curColIndex)
|
|
|
|
{
|
|
|
|
// Force new selection block
|
|
|
|
mStartSelectedCell = nsnull;
|
2000-09-14 15:45:01 +04:00
|
|
|
mDomSelections[index]->RemoveAllRanges();
|
2000-05-31 04:07:58 +04:00
|
|
|
|
2000-12-21 01:13:54 +03:00
|
|
|
if (startRowIndex == curRowIndex)
|
|
|
|
mSelectingTableCellMode = nsISelectionPrivate::TABLESELECTION_ROW;
|
|
|
|
else
|
|
|
|
mSelectingTableCellMode = nsISelectionPrivate::TABLESELECTION_COLUMN;
|
2000-05-31 04:07:58 +04:00
|
|
|
|
|
|
|
return SelectRowOrColumn(childContent, mSelectingTableCellMode);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2000-05-16 07:03:13 +04:00
|
|
|
// Reselect block of cells to new end location
|
2002-03-22 18:25:08 +03:00
|
|
|
return SelectBlockOfCells(mStartSelectedCell, childContent);
|
2000-05-16 07:03:13 +04:00
|
|
|
}
|
2000-03-22 02:58:02 +03:00
|
|
|
}
|
2000-05-16 07:03:13 +04:00
|
|
|
// Do nothing if dragging in table, but outside a cell
|
|
|
|
return NS_OK;
|
2000-03-22 02:58:02 +03:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2000-05-31 04:07:58 +04:00
|
|
|
// Not dragging -- mouse event is down or up
|
|
|
|
if (mMouseDownState)
|
|
|
|
{
|
2000-06-03 03:05:06 +04:00
|
|
|
#ifdef DEBUG_TABLE_SELECTION
|
2000-10-29 02:17:53 +04:00
|
|
|
printf("HandleTableSelection: Mouse down event\n");
|
2000-05-31 04:07:58 +04:00
|
|
|
#endif
|
|
|
|
// Clear cell we stored in mouse-down
|
|
|
|
mUnselectCellOnMouseUp = nsnull;
|
|
|
|
|
2000-12-21 01:13:54 +03:00
|
|
|
if (aTarget == nsISelectionPrivate::TABLESELECTION_CELL)
|
2000-03-22 02:58:02 +03:00
|
|
|
{
|
2000-05-31 04:07:58 +04:00
|
|
|
PRBool isSelected = PR_FALSE;
|
|
|
|
|
|
|
|
// Check if we have other selected cells
|
|
|
|
nsCOMPtr<nsIDOMNode> previousCellNode;
|
|
|
|
GetFirstSelectedCellAndRange(getter_AddRefs(previousCellNode), nsnull);
|
|
|
|
if (previousCellNode)
|
2000-03-22 02:58:02 +03:00
|
|
|
{
|
2000-05-31 04:07:58 +04:00
|
|
|
// We have at least 1 other selected cell
|
|
|
|
|
|
|
|
// Check if new cell is already selected
|
2005-08-23 02:24:29 +04:00
|
|
|
nsIFrame *cellFrame = mShell->GetPrimaryFrameFor(childContent);
|
2000-05-31 04:07:58 +04:00
|
|
|
if (!cellFrame) return NS_ERROR_NULL_POINTER;
|
|
|
|
result = cellFrame->GetSelected(&isSelected);
|
|
|
|
if (NS_FAILED(result)) return result;
|
2000-03-22 02:58:02 +03:00
|
|
|
}
|
2000-05-31 04:07:58 +04:00
|
|
|
else
|
|
|
|
{
|
|
|
|
// No cells selected -- remove non-cell selection
|
2000-09-14 15:45:01 +04:00
|
|
|
mDomSelections[index]->RemoveAllRanges();
|
2000-05-31 04:07:58 +04:00
|
|
|
}
|
2002-03-22 18:25:08 +03:00
|
|
|
mDragSelectingCells = PR_TRUE; // Signal to start drag-cell-selection
|
2000-05-31 04:07:58 +04:00
|
|
|
mSelectingTableCellMode = aTarget;
|
|
|
|
// Set start for new drag-selection block (not appended)
|
|
|
|
mStartSelectedCell = childContent;
|
|
|
|
// The initial block end is same as the start
|
|
|
|
mEndSelectedCell = childContent;
|
|
|
|
|
|
|
|
if (isSelected)
|
|
|
|
{
|
|
|
|
// Remember this cell to (possibly) unselect it on mouseup
|
|
|
|
mUnselectCellOnMouseUp = childContent;
|
2000-06-03 03:05:06 +04:00
|
|
|
#ifdef DEBUG_TABLE_SELECTION
|
2000-10-29 02:17:53 +04:00
|
|
|
printf("HandleTableSelection: Saving mUnselectCellOnMouseUp\n");
|
2000-03-23 07:24:58 +03:00
|
|
|
#endif
|
2000-05-31 04:07:58 +04:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// Select an unselected cell
|
|
|
|
// but first remove existing selection if not in same table
|
|
|
|
nsCOMPtr<nsIContent> previousCellContent = do_QueryInterface(previousCellNode);
|
2001-02-16 06:33:12 +03:00
|
|
|
if (previousCellContent && !IsInSameTable(previousCellContent, childContent, nsnull))
|
2000-06-03 03:05:06 +04:00
|
|
|
{
|
2000-09-14 15:45:01 +04:00
|
|
|
mDomSelections[index]->RemoveAllRanges();
|
|
|
|
// Reset selection mode that is cleared in RemoveAllRanges
|
2000-06-03 03:05:06 +04:00
|
|
|
mSelectingTableCellMode = aTarget;
|
|
|
|
}
|
2000-05-31 04:07:58 +04:00
|
|
|
|
|
|
|
nsCOMPtr<nsIDOMElement> cellElement = do_QueryInterface(childContent);
|
|
|
|
return SelectCellElement(cellElement);
|
|
|
|
}
|
2000-05-16 07:03:13 +04:00
|
|
|
|
2000-05-31 04:07:58 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
2000-12-21 01:13:54 +03:00
|
|
|
else if (aTarget == nsISelectionPrivate::TABLESELECTION_TABLE)
|
2000-05-31 04:07:58 +04:00
|
|
|
{
|
|
|
|
//TODO: We currently select entire table when clicked between cells,
|
|
|
|
// should we restrict to only around border?
|
|
|
|
// *** How do we get location data for cell and click?
|
2002-03-22 18:25:08 +03:00
|
|
|
mDragSelectingCells = PR_FALSE;
|
2000-05-31 04:07:58 +04:00
|
|
|
mStartSelectedCell = nsnull;
|
|
|
|
mEndSelectedCell = nsnull;
|
|
|
|
|
|
|
|
// Remove existing selection and select the table
|
2000-09-14 15:45:01 +04:00
|
|
|
mDomSelections[index]->RemoveAllRanges();
|
2000-05-31 04:07:58 +04:00
|
|
|
return CreateAndAddRange(parentNode, aContentOffset);
|
|
|
|
}
|
2000-12-21 01:13:54 +03:00
|
|
|
else if (aTarget == nsISelectionPrivate::TABLESELECTION_ROW || aTarget == nsISelectionPrivate::TABLESELECTION_COLUMN)
|
2000-05-31 04:07:58 +04:00
|
|
|
{
|
2001-01-04 03:24:39 +03:00
|
|
|
#ifdef DEBUG_TABLE_SELECTION
|
|
|
|
printf("aTarget == %d\n", aTarget);
|
|
|
|
#endif
|
|
|
|
|
2000-05-31 04:07:58 +04:00
|
|
|
// Start drag-selecting mode so multiple rows/cols can be selected
|
|
|
|
// Note: Currently, nsFrame::GetDataForTableSelection
|
|
|
|
// will never call us for row or column selection on mouse down
|
2002-03-22 18:25:08 +03:00
|
|
|
mDragSelectingCells = PR_TRUE;
|
2000-05-16 07:03:13 +04:00
|
|
|
|
2000-05-31 04:07:58 +04:00
|
|
|
// Force new selection block
|
|
|
|
mStartSelectedCell = nsnull;
|
2000-09-14 15:45:01 +04:00
|
|
|
mDomSelections[index]->RemoveAllRanges();
|
|
|
|
// Always do this AFTER RemoveAllRanges
|
2000-06-03 03:05:06 +04:00
|
|
|
mSelectingTableCellMode = aTarget;
|
2000-05-31 04:07:58 +04:00
|
|
|
return SelectRowOrColumn(childContent, aTarget);
|
|
|
|
}
|
2000-03-23 07:24:58 +03:00
|
|
|
}
|
2000-05-31 04:07:58 +04:00
|
|
|
else
|
2000-03-22 02:58:02 +03:00
|
|
|
{
|
2000-06-03 03:05:06 +04:00
|
|
|
#ifdef DEBUG_TABLE_SELECTION
|
2002-03-22 18:25:08 +03:00
|
|
|
printf("HandleTableSelection: Mouse UP event. mDragSelectingCells=%d, mStartSelectedCell=%d\n", mDragSelectingCells, mStartSelectedCell);
|
2000-05-31 04:07:58 +04:00
|
|
|
#endif
|
|
|
|
// First check if we are extending a block selection
|
|
|
|
PRInt32 rangeCount;
|
|
|
|
result = mDomSelections[index]->GetRangeCount(&rangeCount);
|
2002-08-30 05:32:11 +04:00
|
|
|
if (NS_FAILED(result))
|
|
|
|
return result;
|
2000-03-23 07:24:58 +03:00
|
|
|
|
2000-05-31 04:07:58 +04:00
|
|
|
if (rangeCount > 0 && aMouseEvent->isShift &&
|
|
|
|
mAppendStartSelectedCell && mAppendStartSelectedCell != childContent)
|
|
|
|
{
|
2002-03-22 18:25:08 +03:00
|
|
|
// Shift key is down: append a block selection
|
|
|
|
mDragSelectingCells = PR_FALSE;
|
|
|
|
return SelectBlockOfCells(mAppendStartSelectedCell, childContent);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (mDragSelectingCells)
|
|
|
|
mAppendStartSelectedCell = mStartSelectedCell;
|
|
|
|
|
|
|
|
mDragSelectingCells = PR_FALSE;
|
|
|
|
mStartSelectedCell = nsnull;
|
|
|
|
mEndSelectedCell = nsnull;
|
|
|
|
|
|
|
|
// Any other mouseup actions require that Ctrl or Cmd key is pressed
|
|
|
|
// else stop table selection mode
|
|
|
|
PRBool doMouseUpAction = PR_FALSE;
|
|
|
|
#if defined(XP_MAC) || defined(XP_MACOSX)
|
|
|
|
doMouseUpAction = aMouseEvent->isMeta;
|
|
|
|
#else
|
|
|
|
doMouseUpAction = aMouseEvent->isControl;
|
|
|
|
#endif
|
|
|
|
if (!doMouseUpAction)
|
|
|
|
{
|
|
|
|
#ifdef DEBUG_TABLE_SELECTION
|
|
|
|
printf("HandleTableSelection: Ending cell selection on mouseup: mAppendStartSelectedCell=%d\n", mAppendStartSelectedCell);
|
|
|
|
#endif
|
|
|
|
return NS_OK;
|
2000-05-31 04:07:58 +04:00
|
|
|
}
|
|
|
|
// Unselect a cell only if it wasn't
|
|
|
|
// just selected on mousedown
|
|
|
|
if( childContent == mUnselectCellOnMouseUp)
|
2000-03-22 02:58:02 +03:00
|
|
|
{
|
2000-05-31 04:07:58 +04:00
|
|
|
// Scan ranges to find the cell to unselect (the selection range to remove)
|
|
|
|
nsCOMPtr<nsIDOMNode> previousCellParent;
|
|
|
|
nsCOMPtr<nsIDOMRange> range;
|
|
|
|
PRInt32 offset;
|
2000-06-03 03:05:06 +04:00
|
|
|
#ifdef DEBUG_TABLE_SELECTION
|
2000-10-29 02:17:53 +04:00
|
|
|
printf("HandleTableSelection: Unselecting mUnselectCellOnMouseUp; rangeCount=%d\n", rangeCount);
|
2000-05-31 04:07:58 +04:00
|
|
|
#endif
|
|
|
|
for( PRInt32 i = 0; i < rangeCount; i++)
|
2000-03-22 02:58:02 +03:00
|
|
|
{
|
2000-05-31 04:07:58 +04:00
|
|
|
result = mDomSelections[index]->GetRangeAt(i, getter_AddRefs(range));
|
|
|
|
if (NS_FAILED(result)) return result;
|
|
|
|
if (!range) return NS_ERROR_NULL_POINTER;
|
|
|
|
|
|
|
|
nsCOMPtr<nsIDOMNode> parent;
|
2000-08-24 07:54:30 +04:00
|
|
|
result = range->GetStartContainer(getter_AddRefs(parent));
|
2000-05-31 04:07:58 +04:00
|
|
|
if (NS_FAILED(result)) return result;
|
|
|
|
if (!parent) return NS_ERROR_NULL_POINTER;
|
|
|
|
|
|
|
|
range->GetStartOffset(&offset);
|
|
|
|
// Be sure previous selection is a table cell
|
|
|
|
nsCOMPtr<nsIContent> parentContent = do_QueryInterface(parent);
|
2003-09-27 08:18:26 +04:00
|
|
|
nsCOMPtr<nsIContent> child = parentContent->GetChildAt(offset);
|
2001-02-16 08:12:08 +03:00
|
|
|
if (child && IsCell(child))
|
2000-05-31 04:07:58 +04:00
|
|
|
previousCellParent = parent;
|
|
|
|
|
|
|
|
// We're done if we didn't find parent of a previously-selected cell
|
|
|
|
if (!previousCellParent) break;
|
|
|
|
|
|
|
|
if (previousCellParent == parentNode && offset == aContentOffset)
|
|
|
|
{
|
|
|
|
// Cell is already selected
|
|
|
|
if (rangeCount == 1)
|
|
|
|
{
|
2000-06-03 03:05:06 +04:00
|
|
|
#ifdef DEBUG_TABLE_SELECTION
|
2000-10-29 02:17:53 +04:00
|
|
|
printf("HandleTableSelection: Unselecting single selected cell\n");
|
2000-03-22 02:58:02 +03:00
|
|
|
#endif
|
2000-05-31 04:07:58 +04:00
|
|
|
// This was the only cell selected.
|
|
|
|
// Collapse to "normal" selection inside the cell
|
|
|
|
mStartSelectedCell = nsnull;
|
|
|
|
mEndSelectedCell = nsnull;
|
2001-02-16 06:33:12 +03:00
|
|
|
mAppendStartSelectedCell = nsnull;
|
2000-05-31 04:07:58 +04:00
|
|
|
//TODO: We need a "Collapse to just before deepest child" routine
|
|
|
|
// Even better, should we collapse to just after the LAST deepest child
|
|
|
|
// (i.e., at the end of the cell's contents)?
|
|
|
|
return mDomSelections[index]->Collapse(childNode, 0);
|
|
|
|
}
|
2000-06-03 03:05:06 +04:00
|
|
|
#ifdef DEBUG_TABLE_SELECTION
|
2000-10-29 02:17:53 +04:00
|
|
|
printf("HandleTableSelection: Removing cell from multi-cell selection\n");
|
2000-03-22 02:58:02 +03:00
|
|
|
#endif
|
2002-03-22 18:25:08 +03:00
|
|
|
// Unselecting the start of previous block
|
|
|
|
// XXX What do we use now!
|
|
|
|
if (childContent == mAppendStartSelectedCell)
|
|
|
|
mAppendStartSelectedCell = nsnull;
|
|
|
|
|
2000-05-31 04:07:58 +04:00
|
|
|
// Deselect cell by removing its range from selection
|
|
|
|
return mDomSelections[index]->RemoveRange(range);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
mUnselectCellOnMouseUp = nsnull;
|
2000-03-22 02:58:02 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
2006-04-26 06:01:07 +04:00
|
|
|
nsFrameSelection::SelectBlockOfCells(nsIContent *aStartCell, nsIContent *aEndCell)
|
2000-03-22 02:58:02 +03:00
|
|
|
{
|
2002-03-22 18:25:08 +03:00
|
|
|
NS_ENSURE_TRUE(aStartCell, NS_ERROR_NULL_POINTER);
|
|
|
|
NS_ENSURE_TRUE(aEndCell, NS_ERROR_NULL_POINTER);
|
2000-03-23 07:24:58 +03:00
|
|
|
mEndSelectedCell = aEndCell;
|
2000-03-22 02:58:02 +03:00
|
|
|
|
2000-05-31 04:07:58 +04:00
|
|
|
nsCOMPtr<nsIContent> startCell;
|
|
|
|
nsresult result = NS_OK;
|
2000-03-22 02:58:02 +03:00
|
|
|
|
2000-05-31 04:07:58 +04:00
|
|
|
// If new end cell is in a different table, do nothing
|
|
|
|
nsCOMPtr<nsIContent> table;
|
2002-03-22 18:25:08 +03:00
|
|
|
if (!IsInSameTable(aStartCell, aEndCell, getter_AddRefs(table)))
|
2000-05-31 04:07:58 +04:00
|
|
|
return NS_OK;
|
2000-03-22 02:58:02 +03:00
|
|
|
|
|
|
|
// Get starting and ending cells' location in the cellmap
|
2000-03-24 05:52:07 +03:00
|
|
|
PRInt32 startRowIndex, startColIndex, endRowIndex, endColIndex;
|
2002-03-22 18:25:08 +03:00
|
|
|
result = GetCellIndexes(aStartCell, startRowIndex, startColIndex);
|
2000-03-22 02:58:02 +03:00
|
|
|
if(NS_FAILED(result)) return result;
|
|
|
|
result = GetCellIndexes(aEndCell, endRowIndex, endColIndex);
|
|
|
|
if(NS_FAILED(result)) return result;
|
|
|
|
|
2000-03-24 05:52:07 +03:00
|
|
|
// Get TableLayout interface to access cell data based on cellmap location
|
2000-03-22 02:58:02 +03:00
|
|
|
// frames are not ref counted, so don't use an nsCOMPtr
|
2000-05-16 07:03:13 +04:00
|
|
|
nsITableLayout *tableLayoutObject = GetTableLayout(table);
|
2000-03-22 02:58:02 +03:00
|
|
|
if (!tableLayoutObject) return NS_ERROR_FAILURE;
|
|
|
|
|
2000-03-24 05:52:07 +03:00
|
|
|
PRInt32 curRowIndex, curColIndex;
|
|
|
|
|
2002-03-22 18:25:08 +03:00
|
|
|
if (mDragSelectingCells)
|
2000-03-24 05:52:07 +03:00
|
|
|
{
|
2002-03-22 18:25:08 +03:00
|
|
|
// Drag selecting: remove selected cells outside of new block limits
|
2000-05-31 04:07:58 +04:00
|
|
|
|
|
|
|
PRInt8 index = GetIndexFromSelectionType(nsISelectionController::SELECTION_NORMAL);
|
|
|
|
|
|
|
|
nsCOMPtr<nsIDOMNode> cellNode;
|
|
|
|
nsCOMPtr<nsIDOMRange> range;
|
|
|
|
result = GetFirstSelectedCellAndRange(getter_AddRefs(cellNode), getter_AddRefs(range));
|
2000-03-24 05:52:07 +03:00
|
|
|
if (NS_FAILED(result)) return result;
|
|
|
|
|
2000-05-31 04:07:58 +04:00
|
|
|
PRInt32 minRowIndex = PR_MIN(startRowIndex, endRowIndex);
|
|
|
|
PRInt32 maxRowIndex = PR_MAX(startRowIndex, endRowIndex);
|
|
|
|
PRInt32 minColIndex = PR_MIN(startColIndex, endColIndex);
|
|
|
|
PRInt32 maxColIndex = PR_MAX(startColIndex, endColIndex);
|
|
|
|
|
|
|
|
while (cellNode)
|
2000-03-24 05:52:07 +03:00
|
|
|
{
|
2000-05-31 04:07:58 +04:00
|
|
|
nsCOMPtr<nsIContent> childContent = do_QueryInterface(cellNode);
|
|
|
|
result = GetCellIndexes(childContent, curRowIndex, curColIndex);
|
|
|
|
if (NS_FAILED(result)) return result;
|
|
|
|
|
2000-06-03 03:05:06 +04:00
|
|
|
#ifdef DEBUG_TABLE_SELECTION
|
2000-10-29 02:17:53 +04:00
|
|
|
if (!range)
|
|
|
|
printf("SelectBlockOfCells -- range is null\n");
|
2000-05-31 04:07:58 +04:00
|
|
|
#endif
|
|
|
|
if (range &&
|
|
|
|
(curRowIndex < minRowIndex || curRowIndex > maxRowIndex ||
|
|
|
|
curColIndex < minColIndex || curColIndex > maxColIndex))
|
|
|
|
{
|
|
|
|
mDomSelections[index]->RemoveRange(range);
|
|
|
|
// Since we've removed the range, decrement pointer to next range
|
|
|
|
mSelectedCellIndex--;
|
|
|
|
}
|
|
|
|
result = GetNextSelectedCellAndRange(getter_AddRefs(cellNode), getter_AddRefs(range));
|
|
|
|
if (NS_FAILED(result)) return result;
|
|
|
|
}
|
2000-03-24 05:52:07 +03:00
|
|
|
}
|
|
|
|
|
2000-05-16 07:03:13 +04:00
|
|
|
nsCOMPtr<nsIDOMElement> cellElement;
|
2000-03-24 05:52:07 +03:00
|
|
|
PRInt32 rowSpan, colSpan, actualRowSpan, actualColSpan;
|
2000-03-22 02:58:02 +03:00
|
|
|
PRBool isSelected;
|
|
|
|
|
2000-03-24 05:52:07 +03:00
|
|
|
// Note that we select block in the direction of user's mouse dragging,
|
2000-03-22 02:58:02 +03:00
|
|
|
// which means start cell may be after the end cell in either row or column
|
|
|
|
PRInt32 row = startRowIndex;
|
|
|
|
while(PR_TRUE)
|
|
|
|
{
|
|
|
|
PRInt32 col = startColIndex;
|
|
|
|
while(PR_TRUE)
|
|
|
|
{
|
2000-05-16 07:03:13 +04:00
|
|
|
result = tableLayoutObject->GetCellDataAt(row, col, *getter_AddRefs(cellElement),
|
2000-03-22 02:58:02 +03:00
|
|
|
curRowIndex, curColIndex, rowSpan, colSpan,
|
|
|
|
actualRowSpan, actualColSpan, isSelected);
|
|
|
|
if (NS_FAILED(result)) return result;
|
|
|
|
|
|
|
|
NS_ASSERTION(actualColSpan, "!actualColSpan is 0!");
|
|
|
|
|
2000-03-24 05:52:07 +03:00
|
|
|
// Skip cells that are spanned from previous locations or are already selected
|
2000-05-16 07:03:13 +04:00
|
|
|
if (!isSelected && cellElement && row == curRowIndex && col == curColIndex)
|
2000-03-22 02:58:02 +03:00
|
|
|
{
|
2000-05-16 07:03:13 +04:00
|
|
|
result = SelectCellElement(cellElement);
|
2000-03-22 02:58:02 +03:00
|
|
|
if (NS_FAILED(result)) return result;
|
|
|
|
}
|
|
|
|
// Done when we reach end column
|
|
|
|
if (col == endColIndex) break;
|
|
|
|
|
|
|
|
if (startColIndex < endColIndex)
|
|
|
|
col ++;
|
|
|
|
else
|
|
|
|
col--;
|
|
|
|
};
|
|
|
|
if (row == endRowIndex) break;
|
|
|
|
|
|
|
|
if (startRowIndex < endRowIndex)
|
|
|
|
row++;
|
|
|
|
else
|
|
|
|
row--;
|
|
|
|
};
|
2000-03-24 05:52:07 +03:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2000-05-16 07:03:13 +04:00
|
|
|
nsresult
|
2006-04-26 06:01:07 +04:00
|
|
|
nsFrameSelection::SelectRowOrColumn(nsIContent *aCellContent, PRUint32 aTarget)
|
2000-05-16 07:03:13 +04:00
|
|
|
{
|
|
|
|
if (!aCellContent) return NS_ERROR_NULL_POINTER;
|
|
|
|
|
|
|
|
nsCOMPtr<nsIContent> table;
|
|
|
|
nsresult result = GetParentTable(aCellContent, getter_AddRefs(table));
|
|
|
|
if (NS_FAILED(result)) return PR_FALSE;
|
|
|
|
if (!table) return NS_ERROR_NULL_POINTER;
|
|
|
|
|
|
|
|
// Get table and cell layout interfaces to access
|
|
|
|
// cell data based on cellmap location
|
|
|
|
// Frames are not ref counted, so don't use an nsCOMPtr
|
|
|
|
nsITableLayout *tableLayout = GetTableLayout(table);
|
|
|
|
if (!tableLayout) return NS_ERROR_FAILURE;
|
|
|
|
nsITableCellLayout *cellLayout = GetCellLayout(aCellContent);
|
|
|
|
if (!cellLayout) return NS_ERROR_FAILURE;
|
|
|
|
|
|
|
|
// Get location of target cell:
|
|
|
|
PRInt32 rowIndex, colIndex, curRowIndex, curColIndex;
|
|
|
|
result = cellLayout->GetCellIndexes(rowIndex, colIndex);
|
|
|
|
if (NS_FAILED(result)) return result;
|
|
|
|
|
|
|
|
// Be sure we start at proper beginning
|
|
|
|
// (This allows us to select row or col given ANY cell!)
|
2000-12-21 01:13:54 +03:00
|
|
|
if (aTarget == nsISelectionPrivate::TABLESELECTION_ROW)
|
2000-05-16 07:03:13 +04:00
|
|
|
colIndex = 0;
|
2000-12-21 01:13:54 +03:00
|
|
|
if (aTarget == nsISelectionPrivate::TABLESELECTION_COLUMN)
|
2000-05-16 07:03:13 +04:00
|
|
|
rowIndex = 0;
|
|
|
|
|
|
|
|
nsCOMPtr<nsIDOMElement> cellElement;
|
|
|
|
nsCOMPtr<nsIDOMElement> firstCell;
|
|
|
|
nsCOMPtr<nsIDOMElement> lastCell;
|
|
|
|
PRInt32 rowSpan, colSpan, actualRowSpan, actualColSpan;
|
|
|
|
PRBool isSelected;
|
|
|
|
|
|
|
|
do {
|
|
|
|
// Loop through all cells in column or row to find first and last
|
|
|
|
result = tableLayout->GetCellDataAt(rowIndex, colIndex, *getter_AddRefs(cellElement),
|
|
|
|
curRowIndex, curColIndex, rowSpan, colSpan,
|
|
|
|
actualRowSpan, actualColSpan, isSelected);
|
|
|
|
if (NS_FAILED(result)) return result;
|
|
|
|
if (cellElement)
|
|
|
|
{
|
2000-05-31 04:07:58 +04:00
|
|
|
NS_ASSERTION(actualRowSpan > 0 && actualColSpan> 0, "SelectRowOrColumn: Bad rowspan or colspan\n");
|
2000-05-16 07:03:13 +04:00
|
|
|
if (!firstCell)
|
|
|
|
firstCell = cellElement;
|
|
|
|
|
|
|
|
lastCell = cellElement;
|
|
|
|
|
|
|
|
// Move to next cell in cellmap, skipping spanned locations
|
2000-12-21 01:13:54 +03:00
|
|
|
if (aTarget == nsISelectionPrivate::TABLESELECTION_ROW)
|
2000-05-16 07:03:13 +04:00
|
|
|
colIndex += actualColSpan;
|
|
|
|
else
|
|
|
|
rowIndex += actualRowSpan;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
while (cellElement);
|
|
|
|
|
|
|
|
// Use SelectBlockOfCells:
|
|
|
|
// This will replace existing selection,
|
|
|
|
// but allow unselecting by dragging out of selected region
|
|
|
|
if (firstCell && lastCell)
|
|
|
|
{
|
|
|
|
if (!mStartSelectedCell)
|
|
|
|
{
|
|
|
|
// We are starting a new block, so select the first cell
|
|
|
|
result = SelectCellElement(firstCell);
|
|
|
|
if (NS_FAILED(result)) return result;
|
2000-05-31 04:07:58 +04:00
|
|
|
mStartSelectedCell = do_QueryInterface(firstCell);
|
2000-05-16 07:03:13 +04:00
|
|
|
}
|
|
|
|
nsCOMPtr<nsIContent> lastCellContent = do_QueryInterface(lastCell);
|
2002-03-22 18:25:08 +03:00
|
|
|
result = SelectBlockOfCells(mStartSelectedCell, lastCellContent);
|
2001-01-04 03:24:39 +03:00
|
|
|
|
|
|
|
// This gets set to the cell at end of row/col,
|
|
|
|
// but we need it to be the cell under cursor
|
|
|
|
mEndSelectedCell = aCellContent;
|
|
|
|
return result;
|
2000-05-16 07:03:13 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
#if 0
|
|
|
|
// This is a more efficient strategy that appends row to current selection,
|
|
|
|
// but doesn't allow dragging OFF of an existing selection to unselect!
|
|
|
|
do {
|
|
|
|
// Loop through all cells in column or row
|
2003-06-14 00:10:01 +04:00
|
|
|
result = tableLayout->GetCellDataAt(rowIndex, colIndex,
|
|
|
|
getter_AddRefs(cellElement),
|
|
|
|
curRowIndex, curColIndex,
|
|
|
|
rowSpan, colSpan,
|
|
|
|
actualRowSpan, actualColSpan,
|
|
|
|
isSelected);
|
2000-05-16 07:03:13 +04:00
|
|
|
if (NS_FAILED(result)) return result;
|
|
|
|
// We're done when cell is not found
|
|
|
|
if (!cellElement) break;
|
|
|
|
|
|
|
|
|
|
|
|
// Check spans else we infinitely loop
|
|
|
|
NS_ASSERTION(actualColSpan, "actualColSpan is 0!");
|
|
|
|
NS_ASSERTION(actualRowSpan, "actualRowSpan is 0!");
|
|
|
|
|
|
|
|
// Skip cells that are already selected or span from outside our region
|
|
|
|
if (!isSelected && rowIndex == curRowIndex && colIndex == curColIndex)
|
|
|
|
{
|
|
|
|
result = SelectCellElement(cellElement);
|
|
|
|
if (NS_FAILED(result)) return result;
|
|
|
|
}
|
|
|
|
// Move to next row or column in cellmap, skipping spanned locations
|
2000-12-21 01:13:54 +03:00
|
|
|
if (aTarget == nsISelectionPrivate::TABLESELECTION_ROW)
|
2000-05-16 07:03:13 +04:00
|
|
|
colIndex += actualColSpan;
|
|
|
|
else
|
|
|
|
rowIndex += actualRowSpan;
|
|
|
|
}
|
|
|
|
while (cellElement);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2000-03-24 05:52:07 +03:00
|
|
|
nsresult
|
2006-04-26 06:01:07 +04:00
|
|
|
nsFrameSelection::GetFirstCellNodeInRange(nsIDOMRange *aRange,
|
|
|
|
nsIDOMNode **aCellNode)
|
2000-03-24 05:52:07 +03:00
|
|
|
{
|
|
|
|
if (!aRange || !aCellNode) return NS_ERROR_NULL_POINTER;
|
|
|
|
|
|
|
|
*aCellNode = nsnull;
|
|
|
|
|
|
|
|
nsCOMPtr<nsIDOMNode> startParent;
|
2000-08-24 07:54:30 +04:00
|
|
|
nsresult result = aRange->GetStartContainer(getter_AddRefs(startParent));
|
2003-09-27 08:18:26 +04:00
|
|
|
if (NS_FAILED(result))
|
|
|
|
return result;
|
|
|
|
if (!startParent)
|
|
|
|
return NS_ERROR_FAILURE;
|
2000-03-24 05:52:07 +03:00
|
|
|
|
|
|
|
PRInt32 offset;
|
|
|
|
result = aRange->GetStartOffset(&offset);
|
2003-09-27 08:18:26 +04:00
|
|
|
if (NS_FAILED(result))
|
|
|
|
return result;
|
2000-03-24 05:52:07 +03:00
|
|
|
|
|
|
|
nsCOMPtr<nsIContent> parentContent = do_QueryInterface(startParent);
|
2003-09-27 08:18:26 +04:00
|
|
|
nsCOMPtr<nsIContent> childContent = parentContent->GetChildAt(offset);
|
|
|
|
if (!childContent)
|
|
|
|
return NS_ERROR_NULL_POINTER;
|
2000-03-24 05:52:07 +03:00
|
|
|
// Don't return node if not a cell
|
|
|
|
if (!IsCell(childContent)) return NS_OK;
|
|
|
|
|
|
|
|
nsCOMPtr<nsIDOMNode> childNode = do_QueryInterface(childContent);
|
|
|
|
if (childNode)
|
2000-03-22 02:58:02 +03:00
|
|
|
{
|
2000-03-24 05:52:07 +03:00
|
|
|
*aCellNode = childNode;
|
|
|
|
NS_ADDREF(*aCellNode);
|
2000-03-22 02:58:02 +03:00
|
|
|
}
|
2000-03-24 05:52:07 +03:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
2006-04-26 06:01:07 +04:00
|
|
|
nsFrameSelection::GetFirstSelectedCellAndRange(nsIDOMNode **aCell,
|
|
|
|
nsIDOMRange **aRange)
|
2000-03-24 05:52:07 +03:00
|
|
|
{
|
2000-05-31 04:07:58 +04:00
|
|
|
if (!aCell) return NS_ERROR_NULL_POINTER;
|
2000-03-24 05:52:07 +03:00
|
|
|
*aCell = nsnull;
|
2000-05-31 04:07:58 +04:00
|
|
|
|
|
|
|
// aRange is optional
|
|
|
|
if (aRange)
|
|
|
|
*aRange = nsnull;
|
2000-03-24 05:52:07 +03:00
|
|
|
|
|
|
|
nsCOMPtr<nsIDOMRange> firstRange;
|
2000-04-27 11:37:12 +04:00
|
|
|
PRInt8 index = GetIndexFromSelectionType(nsISelectionController::SELECTION_NORMAL);
|
2000-03-31 11:17:22 +04:00
|
|
|
nsresult result = mDomSelections[index]->GetRangeAt(0, getter_AddRefs(firstRange));
|
2000-03-24 05:52:07 +03:00
|
|
|
if (NS_FAILED(result)) return result;
|
|
|
|
if (!firstRange) return NS_ERROR_FAILURE;
|
|
|
|
|
|
|
|
nsCOMPtr<nsIDOMNode> cellNode;
|
|
|
|
result = GetFirstCellNodeInRange(firstRange, getter_AddRefs(cellNode));
|
|
|
|
if (NS_FAILED(result)) return result;
|
|
|
|
if (!cellNode) return NS_OK;
|
|
|
|
|
|
|
|
*aCell = cellNode;
|
|
|
|
NS_ADDREF(*aCell);
|
2000-05-31 04:07:58 +04:00
|
|
|
if (aRange)
|
|
|
|
{
|
|
|
|
*aRange = firstRange;
|
|
|
|
NS_ADDREF(*aRange);
|
|
|
|
}
|
2000-03-24 05:52:07 +03:00
|
|
|
|
|
|
|
// Setup for next cell
|
|
|
|
mSelectedCellIndex = 1;
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
2006-04-26 06:01:07 +04:00
|
|
|
nsFrameSelection::GetNextSelectedCellAndRange(nsIDOMNode **aCell,
|
|
|
|
nsIDOMRange **aRange)
|
2000-03-24 05:52:07 +03:00
|
|
|
{
|
2000-05-31 04:07:58 +04:00
|
|
|
if (!aCell) return NS_ERROR_NULL_POINTER;
|
2000-03-24 05:52:07 +03:00
|
|
|
*aCell = nsnull;
|
2000-05-31 04:07:58 +04:00
|
|
|
|
|
|
|
// aRange is optional
|
|
|
|
if (aRange)
|
|
|
|
*aRange = nsnull;
|
2000-03-24 05:52:07 +03:00
|
|
|
|
|
|
|
PRInt32 rangeCount;
|
2000-04-27 11:37:12 +04:00
|
|
|
PRInt8 index = GetIndexFromSelectionType(nsISelectionController::SELECTION_NORMAL);
|
2000-03-31 11:17:22 +04:00
|
|
|
nsresult result = mDomSelections[index]->GetRangeCount(&rangeCount);
|
2000-03-24 05:52:07 +03:00
|
|
|
if (NS_FAILED(result)) return result;
|
|
|
|
|
|
|
|
// Don't even try if index exceeds range count
|
|
|
|
if (mSelectedCellIndex >= rangeCount)
|
|
|
|
{
|
|
|
|
// Should we reset index?
|
|
|
|
// Maybe better to force recalling GetFirstSelectedCell()
|
|
|
|
//mSelectedCellIndex = 0;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Get first node in next range of selection - test if it's a cell
|
|
|
|
nsCOMPtr<nsIDOMRange> range;
|
2000-03-31 11:17:22 +04:00
|
|
|
result = mDomSelections[index]->GetRangeAt(mSelectedCellIndex, getter_AddRefs(range));
|
2000-03-24 05:52:07 +03:00
|
|
|
if (NS_FAILED(result)) return result;
|
|
|
|
if (!range) return NS_ERROR_FAILURE;
|
|
|
|
|
|
|
|
nsCOMPtr<nsIDOMNode> cellNode;
|
|
|
|
result = GetFirstCellNodeInRange(range, getter_AddRefs(cellNode));
|
|
|
|
if (NS_FAILED(result)) return result;
|
|
|
|
// No cell in selection range
|
|
|
|
if (!cellNode) return NS_OK;
|
|
|
|
|
|
|
|
*aCell = cellNode;
|
|
|
|
NS_ADDREF(*aCell);
|
2000-05-31 04:07:58 +04:00
|
|
|
if (aRange)
|
|
|
|
{
|
|
|
|
*aRange = range;
|
|
|
|
NS_ADDREF(*aRange);
|
|
|
|
}
|
2000-03-24 05:52:07 +03:00
|
|
|
|
|
|
|
// Setup for next cell
|
|
|
|
mSelectedCellIndex++;
|
|
|
|
|
|
|
|
return NS_OK;
|
2000-03-22 02:58:02 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
2006-04-26 06:01:07 +04:00
|
|
|
nsFrameSelection::GetCellIndexes(nsIContent *aCell,
|
|
|
|
PRInt32 &aRowIndex,
|
|
|
|
PRInt32 &aColIndex)
|
2000-03-22 02:58:02 +03:00
|
|
|
{
|
|
|
|
if (!aCell) return NS_ERROR_NULL_POINTER;
|
|
|
|
|
|
|
|
aColIndex=0; // initialize out params
|
|
|
|
aRowIndex=0;
|
|
|
|
|
2000-05-16 07:03:13 +04:00
|
|
|
nsITableCellLayout *cellLayoutObject = GetCellLayout(aCell);
|
2000-03-22 02:58:02 +03:00
|
|
|
if (!cellLayoutObject) return NS_ERROR_FAILURE;
|
|
|
|
return cellLayoutObject->GetCellIndexes(aRowIndex, aColIndex);
|
|
|
|
}
|
|
|
|
|
|
|
|
PRBool
|
2006-04-26 06:01:07 +04:00
|
|
|
nsFrameSelection::IsInSameTable(nsIContent *aContent1,
|
|
|
|
nsIContent *aContent2,
|
|
|
|
nsIContent **aTable)
|
2000-03-22 02:58:02 +03:00
|
|
|
{
|
|
|
|
if (!aContent1 || !aContent2) return PR_FALSE;
|
|
|
|
|
|
|
|
// aTable is optional:
|
|
|
|
if(aTable) *aTable = nsnull;
|
|
|
|
|
|
|
|
nsCOMPtr<nsIContent> tableNode1;
|
|
|
|
nsCOMPtr<nsIContent> tableNode2;
|
|
|
|
|
|
|
|
nsresult result = GetParentTable(aContent1, getter_AddRefs(tableNode1));
|
|
|
|
if (NS_FAILED(result)) return PR_FALSE;
|
|
|
|
result = GetParentTable(aContent2, getter_AddRefs(tableNode2));
|
|
|
|
if (NS_FAILED(result)) return PR_FALSE;
|
|
|
|
|
|
|
|
// Must be in the same table
|
|
|
|
if (tableNode1 && (tableNode1 == tableNode2))
|
|
|
|
{
|
|
|
|
if (aTable)
|
|
|
|
{
|
|
|
|
*aTable = tableNode1;
|
|
|
|
NS_ADDREF(*aTable);
|
|
|
|
}
|
|
|
|
return PR_TRUE;;
|
|
|
|
}
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
2006-04-26 06:01:07 +04:00
|
|
|
nsFrameSelection::GetParentTable(nsIContent *aCell, nsIContent **aTable)
|
2000-03-22 02:58:02 +03:00
|
|
|
{
|
2003-06-14 00:10:01 +04:00
|
|
|
if (!aCell || !aTable) {
|
2000-03-22 02:58:02 +03:00
|
|
|
return NS_ERROR_NULL_POINTER;
|
2003-06-14 00:10:01 +04:00
|
|
|
}
|
2000-03-22 02:58:02 +03:00
|
|
|
|
2003-07-29 01:09:56 +04:00
|
|
|
for (nsIContent* parent = aCell->GetParent(); parent;
|
|
|
|
parent = parent->GetParent()) {
|
2006-12-26 20:47:52 +03:00
|
|
|
if (parent->Tag() == nsGkAtoms::table &&
|
2006-05-05 10:52:21 +04:00
|
|
|
parent->IsNodeOfType(nsINode::eHTML)) {
|
2000-03-22 02:58:02 +03:00
|
|
|
*aTable = parent;
|
|
|
|
NS_ADDREF(*aTable);
|
2003-06-14 00:10:01 +04:00
|
|
|
|
2000-03-22 02:58:02 +03:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
}
|
2003-06-14 00:10:01 +04:00
|
|
|
|
|
|
|
return NS_OK;
|
2000-03-22 02:58:02 +03:00
|
|
|
}
|
|
|
|
|
2000-05-16 07:03:13 +04:00
|
|
|
nsresult
|
2006-04-26 06:01:07 +04:00
|
|
|
nsFrameSelection::SelectCellElement(nsIDOMElement *aCellElement)
|
2000-05-16 07:03:13 +04:00
|
|
|
{
|
|
|
|
nsCOMPtr<nsIContent> cellContent = do_QueryInterface(aCellElement);
|
2000-05-31 04:07:58 +04:00
|
|
|
|
2003-09-27 08:18:26 +04:00
|
|
|
if (!cellContent) {
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsIContent *parent = cellContent->GetParent();
|
|
|
|
nsCOMPtr<nsIDOMNode> parentNode(do_QueryInterface(parent));
|
|
|
|
if (!parentNode) {
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
2000-05-31 04:07:58 +04:00
|
|
|
// Get child offset
|
2003-09-27 08:18:26 +04:00
|
|
|
PRInt32 offset = parent->IndexOf(cellContent);
|
|
|
|
|
|
|
|
return CreateAndAddRange(parentNode, offset);
|
2000-05-16 07:03:13 +04:00
|
|
|
}
|
|
|
|
|
2000-12-21 01:13:54 +03:00
|
|
|
nsresult
|
|
|
|
nsTypedSelection::getTableCellLocationFromRange(nsIDOMRange *aRange, PRInt32 *aSelectionType, PRInt32 *aRow, PRInt32 *aCol)
|
|
|
|
{
|
|
|
|
if (!aRange || !aSelectionType || !aRow || !aCol)
|
|
|
|
return NS_ERROR_NULL_POINTER;
|
|
|
|
|
|
|
|
*aSelectionType = nsISelectionPrivate::TABLESELECTION_NONE;
|
|
|
|
*aRow = 0;
|
|
|
|
*aCol = 0;
|
|
|
|
|
|
|
|
// Must have access to frame selection to get cell info
|
|
|
|
if (!mFrameSelection) return NS_OK;
|
|
|
|
|
|
|
|
nsresult result = GetTableSelectionType(aRange, aSelectionType);
|
|
|
|
if (NS_FAILED(result)) return result;
|
|
|
|
|
|
|
|
// Don't fail if range does not point to a single table cell,
|
|
|
|
// let aSelectionType tell user if we don't have a cell
|
|
|
|
if (*aSelectionType != nsISelectionPrivate::TABLESELECTION_CELL)
|
|
|
|
return NS_OK;
|
|
|
|
|
|
|
|
// Get the child content (the cell) pointed to by starting node of range
|
|
|
|
// We do minimal checking since GetTableSelectionType assures
|
|
|
|
// us that this really is a table cell
|
|
|
|
nsCOMPtr<nsIDOMNode> startNode;
|
|
|
|
result = aRange->GetStartContainer(getter_AddRefs(startNode));
|
2003-09-27 08:18:26 +04:00
|
|
|
if (NS_FAILED(result))
|
|
|
|
return result;
|
2000-12-21 01:13:54 +03:00
|
|
|
|
|
|
|
nsCOMPtr<nsIContent> content(do_QueryInterface(startNode));
|
2003-09-27 08:18:26 +04:00
|
|
|
if (!content)
|
|
|
|
return NS_ERROR_FAILURE;
|
2000-12-21 01:13:54 +03:00
|
|
|
PRInt32 startOffset;
|
|
|
|
result = aRange->GetStartOffset(&startOffset);
|
2003-09-27 08:18:26 +04:00
|
|
|
if (NS_FAILED(result))
|
|
|
|
return result;
|
2000-12-21 01:13:54 +03:00
|
|
|
|
2003-09-27 08:18:26 +04:00
|
|
|
nsIContent *child = content->GetChildAt(startOffset);
|
|
|
|
if (!child)
|
|
|
|
return NS_ERROR_FAILURE;
|
2000-12-21 01:13:54 +03:00
|
|
|
|
|
|
|
//Note: This is a non-ref-counted pointer to the frame
|
|
|
|
nsITableCellLayout *cellLayout = mFrameSelection->GetCellLayout(child);
|
2003-09-27 08:18:26 +04:00
|
|
|
if (NS_FAILED(result))
|
|
|
|
return result;
|
|
|
|
if (!cellLayout)
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
|
2000-12-21 01:13:54 +03:00
|
|
|
return cellLayout->GetCellIndexes(*aRow, *aCol);
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
nsTypedSelection::addTableCellRange(nsIDOMRange *aRange, PRBool *aDidAddRange)
|
|
|
|
{
|
|
|
|
if (!aDidAddRange)
|
|
|
|
return NS_ERROR_NULL_POINTER;
|
|
|
|
|
|
|
|
*aDidAddRange = PR_FALSE;
|
|
|
|
|
|
|
|
if (!mFrameSelection)
|
|
|
|
return NS_OK;
|
|
|
|
|
|
|
|
if (!aRange)
|
|
|
|
return NS_ERROR_NULL_POINTER;
|
|
|
|
|
|
|
|
nsresult result;
|
|
|
|
|
2001-01-04 03:24:39 +03:00
|
|
|
// Get if we are adding a cell selection and the row, col of cell if we are
|
|
|
|
PRInt32 newRow, newCol, tableMode;
|
|
|
|
result = getTableCellLocationFromRange(aRange, &tableMode, &newRow, &newCol);
|
2000-12-21 01:13:54 +03:00
|
|
|
if (NS_FAILED(result)) return result;
|
2001-01-04 03:24:39 +03:00
|
|
|
|
|
|
|
// If not adding a cell range, we are done here
|
|
|
|
if (tableMode != nsISelectionPrivate::TABLESELECTION_CELL)
|
|
|
|
{
|
|
|
|
mFrameSelection->mSelectingTableCellMode = tableMode;
|
|
|
|
// Don't fail if range isn't a selected cell, aDidAddRange tells caller if we didn't proceed
|
2000-12-21 01:13:54 +03:00
|
|
|
return NS_OK;
|
2001-01-04 03:24:39 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
// Set frame selection mode only if not already set to a table mode
|
|
|
|
// so we don't loose the select row and column flags (not detected by getTableCellLocation)
|
|
|
|
if (mFrameSelection->mSelectingTableCellMode == TABLESELECTION_NONE)
|
|
|
|
mFrameSelection->mSelectingTableCellMode = tableMode;
|
2000-12-21 01:13:54 +03:00
|
|
|
|
2006-07-27 21:57:15 +04:00
|
|
|
return AddItem(aRange);
|
2000-12-21 01:13:54 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
//TODO: Figure out TABLESELECTION_COLUMN and TABLESELECTION_ALLCELLS
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsTypedSelection::GetTableSelectionType(nsIDOMRange* aRange, PRInt32* aTableSelectionType)
|
|
|
|
{
|
|
|
|
if (!aRange || !aTableSelectionType)
|
|
|
|
return NS_ERROR_NULL_POINTER;
|
|
|
|
|
|
|
|
*aTableSelectionType = nsISelectionPrivate::TABLESELECTION_NONE;
|
|
|
|
|
|
|
|
// Must have access to frame selection to get cell info
|
|
|
|
if(!mFrameSelection) return NS_OK;
|
|
|
|
|
|
|
|
nsCOMPtr<nsIDOMNode> startNode;
|
|
|
|
nsresult result = aRange->GetStartContainer(getter_AddRefs(startNode));
|
|
|
|
if (NS_FAILED(result)) return result;
|
|
|
|
if (!startNode) return NS_ERROR_FAILURE;
|
|
|
|
|
|
|
|
nsCOMPtr<nsIDOMNode> endNode;
|
|
|
|
result = aRange->GetEndContainer(getter_AddRefs(endNode));
|
|
|
|
if (NS_FAILED(result)) return result;
|
|
|
|
if (!endNode) return NS_ERROR_FAILURE;
|
|
|
|
|
|
|
|
// Not a single selected node
|
|
|
|
if (startNode != endNode) return NS_OK;
|
|
|
|
|
2006-06-22 23:07:33 +04:00
|
|
|
nsCOMPtr<nsINode> node = do_QueryInterface(startNode);
|
|
|
|
if (!node) return NS_ERROR_FAILURE;
|
2000-12-21 01:13:54 +03:00
|
|
|
|
2003-09-27 08:18:26 +04:00
|
|
|
// if we simply cannot have children, return NS_OK as a non-failing,
|
|
|
|
// non-completing case for table selection
|
2006-06-22 23:07:33 +04:00
|
|
|
if (!node->IsNodeOfType(nsINode::eELEMENT))
|
|
|
|
return NS_OK; //definitely not a table row/cell
|
|
|
|
|
|
|
|
nsCOMPtr<nsIContent> content = do_QueryInterface(startNode);
|
|
|
|
NS_ASSERTION(content, "No content here?");
|
2001-05-19 03:07:54 +04:00
|
|
|
|
2000-12-21 01:13:54 +03:00
|
|
|
PRInt32 startOffset;
|
|
|
|
PRInt32 endOffset;
|
|
|
|
result = aRange->GetEndOffset(&endOffset);
|
|
|
|
if (NS_FAILED(result)) return result;
|
|
|
|
result = aRange->GetStartOffset(&startOffset);
|
|
|
|
if (NS_FAILED(result)) return result;
|
|
|
|
|
|
|
|
// Not a single selected node
|
|
|
|
if ((endOffset - startOffset) != 1)
|
|
|
|
return NS_OK;
|
|
|
|
|
2006-05-05 10:52:21 +04:00
|
|
|
if (!content->IsNodeOfType(nsINode::eHTML)) {
|
2003-11-19 04:20:56 +03:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsIAtom *tag = content->Tag();
|
2000-12-21 01:13:54 +03:00
|
|
|
|
2006-12-26 20:47:52 +03:00
|
|
|
if (tag == nsGkAtoms::tr)
|
2000-12-21 01:13:54 +03:00
|
|
|
{
|
|
|
|
*aTableSelectionType = nsISelectionPrivate::TABLESELECTION_CELL;
|
|
|
|
}
|
|
|
|
else //check to see if we are selecting a table or row (column and all cells not done yet)
|
|
|
|
{
|
2003-09-27 08:18:26 +04:00
|
|
|
nsIContent *child = content->GetChildAt(startOffset);
|
|
|
|
if (!child)
|
|
|
|
return NS_ERROR_FAILURE;
|
2000-12-21 01:13:54 +03:00
|
|
|
|
2003-11-19 04:20:56 +03:00
|
|
|
tag = child->Tag();
|
2000-12-21 01:13:54 +03:00
|
|
|
|
2006-12-26 20:47:52 +03:00
|
|
|
if (tag == nsGkAtoms::table)
|
2000-12-21 01:13:54 +03:00
|
|
|
*aTableSelectionType = nsISelectionPrivate::TABLESELECTION_TABLE;
|
2006-12-26 20:47:52 +03:00
|
|
|
else if (tag == nsGkAtoms::tr)
|
2000-12-21 01:13:54 +03:00
|
|
|
*aTableSelectionType = nsISelectionPrivate::TABLESELECTION_ROW;
|
|
|
|
}
|
2003-11-19 04:20:56 +03:00
|
|
|
|
2000-12-21 01:13:54 +03:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2000-03-22 02:58:02 +03:00
|
|
|
nsresult
|
2006-04-26 06:01:07 +04:00
|
|
|
nsFrameSelection::CreateAndAddRange(nsIDOMNode *aParentNode, PRInt32 aOffset)
|
2000-03-22 02:58:02 +03:00
|
|
|
{
|
|
|
|
if (!aParentNode) return NS_ERROR_NULL_POINTER;
|
|
|
|
nsCOMPtr<nsIDOMRange> range;
|
|
|
|
NS_NewRange(getter_AddRefs(range));
|
|
|
|
if (!range) return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
|
|
|
|
// Set range around child at given offset
|
|
|
|
nsresult result = range->SetStart(aParentNode, aOffset);
|
|
|
|
if (NS_FAILED(result)) return result;
|
|
|
|
result = range->SetEnd(aParentNode, aOffset+1);
|
|
|
|
if (NS_FAILED(result)) return result;
|
|
|
|
|
2000-04-27 11:37:12 +04:00
|
|
|
PRInt8 index = GetIndexFromSelectionType(nsISelectionController::SELECTION_NORMAL);
|
2000-03-31 11:17:22 +04:00
|
|
|
return mDomSelections[index]->AddRange(range);
|
2000-03-22 02:58:02 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
// End of Table Selection
|
|
|
|
|
2006-04-26 06:01:07 +04:00
|
|
|
//END nsFrameSelection methods
|
2000-03-22 02:58:02 +03:00
|
|
|
|
|
|
|
|
|
|
|
#ifdef XP_MAC
|
|
|
|
#pragma mark -
|
|
|
|
#endif
|
|
|
|
|
2000-09-14 15:45:01 +04:00
|
|
|
//BEGIN nsISelection interface implementations
|
2000-03-22 02:58:02 +03:00
|
|
|
|
|
|
|
|
|
|
|
|
2006-04-26 06:45:18 +04:00
|
|
|
nsresult
|
2006-04-26 06:01:07 +04:00
|
|
|
nsFrameSelection::DeleteFromDocument()
|
2000-03-22 02:58:02 +03:00
|
|
|
{
|
|
|
|
nsresult res;
|
|
|
|
|
|
|
|
// If we're already collapsed, then set ourselves to include the
|
|
|
|
// last item BEFORE the current range, rather than the range itself,
|
|
|
|
// before we do the delete.
|
|
|
|
PRBool isCollapsed;
|
2000-04-27 11:37:12 +04:00
|
|
|
PRInt8 index = GetIndexFromSelectionType(nsISelectionController::SELECTION_NORMAL);
|
2000-03-31 11:17:22 +04:00
|
|
|
mDomSelections[index]->GetIsCollapsed( &isCollapsed);
|
2000-03-22 02:58:02 +03:00
|
|
|
if (isCollapsed)
|
|
|
|
{
|
|
|
|
// If the offset is positive, then it's easy:
|
2000-03-31 11:17:22 +04:00
|
|
|
if (mDomSelections[index]->FetchFocusOffset() > 0)
|
2000-03-22 02:58:02 +03:00
|
|
|
{
|
2000-03-31 11:17:22 +04:00
|
|
|
mDomSelections[index]->Extend(mDomSelections[index]->FetchFocusNode(), mDomSelections[index]->FetchFocusOffset() - 1);
|
2000-03-22 02:58:02 +03:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// Otherwise it's harder, have to find the previous node
|
2000-10-29 02:17:53 +04:00
|
|
|
printf("Sorry, don't know how to delete across frame boundaries yet\n");
|
2000-03-22 02:58:02 +03:00
|
|
|
return NS_ERROR_NOT_IMPLEMENTED;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Get an iterator
|
2000-03-31 11:17:22 +04:00
|
|
|
nsSelectionIterator iter(mDomSelections[index]);
|
2000-03-22 02:58:02 +03:00
|
|
|
res = iter.First();
|
2001-11-19 09:45:00 +03:00
|
|
|
if (NS_FAILED(res))
|
2000-03-22 02:58:02 +03:00
|
|
|
return res;
|
|
|
|
|
|
|
|
nsCOMPtr<nsIDOMRange> range;
|
|
|
|
while (iter.IsDone())
|
|
|
|
{
|
|
|
|
res = iter.CurrentItem(NS_STATIC_CAST(nsIDOMRange**, getter_AddRefs(range)));
|
2001-11-19 09:45:00 +03:00
|
|
|
if (NS_FAILED(res))
|
2000-03-22 02:58:02 +03:00
|
|
|
return res;
|
|
|
|
res = range->DeleteContents();
|
2001-11-19 09:45:00 +03:00
|
|
|
if (NS_FAILED(res))
|
2000-03-22 02:58:02 +03:00
|
|
|
return res;
|
|
|
|
iter.Next();
|
|
|
|
}
|
|
|
|
|
|
|
|
// Collapse to the new location.
|
|
|
|
// If we deleted one character, then we move back one element.
|
|
|
|
// FIXME We don't know how to do this past frame boundaries yet.
|
|
|
|
if (isCollapsed)
|
2000-03-31 11:17:22 +04:00
|
|
|
mDomSelections[index]->Collapse(mDomSelections[index]->FetchAnchorNode(), mDomSelections[index]->FetchAnchorOffset()-1);
|
|
|
|
else if (mDomSelections[index]->FetchAnchorOffset() > 0)
|
|
|
|
mDomSelections[index]->Collapse(mDomSelections[index]->FetchAnchorNode(), mDomSelections[index]->FetchAnchorOffset());
|
2000-03-22 02:58:02 +03:00
|
|
|
#ifdef DEBUG
|
|
|
|
else
|
2000-10-29 02:17:53 +04:00
|
|
|
printf("Don't know how to set selection back past frame boundary\n");
|
2000-03-22 02:58:02 +03:00
|
|
|
#endif
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2006-04-26 06:01:07 +04:00
|
|
|
void
|
|
|
|
nsFrameSelection::SetDelayedCaretData(nsMouseEvent *aMouseEvent)
|
2000-05-26 00:04:02 +04:00
|
|
|
{
|
|
|
|
if (aMouseEvent)
|
|
|
|
{
|
|
|
|
mDelayedMouseEventValid = PR_TRUE;
|
|
|
|
mDelayedMouseEvent = *aMouseEvent;
|
|
|
|
|
2005-12-16 07:58:33 +03:00
|
|
|
// Don't cache the widget. We don't need it and it could go away.
|
|
|
|
mDelayedMouseEvent.widget = nsnull;
|
2000-05-26 00:04:02 +04:00
|
|
|
}
|
|
|
|
else
|
|
|
|
mDelayedMouseEventValid = PR_FALSE;
|
|
|
|
}
|
|
|
|
|
2006-04-26 06:01:07 +04:00
|
|
|
nsMouseEvent*
|
|
|
|
nsFrameSelection::GetDelayedCaretData()
|
2000-05-26 00:04:02 +04:00
|
|
|
{
|
|
|
|
if (mDelayedMouseEventValid)
|
2006-04-26 06:01:07 +04:00
|
|
|
return &mDelayedMouseEvent;
|
|
|
|
|
|
|
|
return nsnull;
|
2002-08-30 05:32:11 +04:00
|
|
|
}
|
|
|
|
|
2000-09-14 15:45:01 +04:00
|
|
|
//END nsISelection interface implementations
|
2000-03-22 02:58:02 +03:00
|
|
|
|
2003-04-04 05:45:06 +04:00
|
|
|
#if 0
|
2000-03-22 02:58:02 +03:00
|
|
|
#pragma mark -
|
|
|
|
#endif
|
|
|
|
|
2000-11-29 03:13:00 +03:00
|
|
|
// nsTypedSelection implementation
|
2000-03-22 02:58:02 +03:00
|
|
|
|
|
|
|
// note: this can return a nil anchor node
|
|
|
|
|
2006-04-26 06:01:07 +04:00
|
|
|
nsTypedSelection::nsTypedSelection(nsFrameSelection *aList)
|
2000-03-22 02:58:02 +03:00
|
|
|
{
|
|
|
|
mFrameSelection = aList;
|
|
|
|
mFixupState = PR_FALSE;
|
|
|
|
mDirection = eDirNext;
|
2003-04-20 07:14:09 +04:00
|
|
|
mCachedOffsetForFrame = nsnull;
|
2000-03-22 02:58:02 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2000-11-29 03:13:00 +03:00
|
|
|
nsTypedSelection::nsTypedSelection()
|
2000-05-11 08:25:43 +04:00
|
|
|
{
|
2000-05-13 12:07:34 +04:00
|
|
|
mFrameSelection = nsnull;
|
2000-05-11 08:25:43 +04:00
|
|
|
mFixupState = PR_FALSE;
|
|
|
|
mDirection = eDirNext;
|
2003-04-20 05:03:40 +04:00
|
|
|
mCachedOffsetForFrame = nsnull;
|
2000-05-11 08:25:43 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2000-03-22 02:58:02 +03:00
|
|
|
|
2000-11-29 03:13:00 +03:00
|
|
|
nsTypedSelection::~nsTypedSelection()
|
2000-03-22 02:58:02 +03:00
|
|
|
{
|
2006-04-14 04:28:22 +04:00
|
|
|
DetachFromPresentation();
|
|
|
|
}
|
|
|
|
|
|
|
|
void nsTypedSelection::DetachFromPresentation() {
|
2000-03-22 02:58:02 +03:00
|
|
|
setAnchorFocusRange(-1);
|
|
|
|
|
2000-07-28 07:48:26 +04:00
|
|
|
if (mAutoScrollTimer) {
|
|
|
|
mAutoScrollTimer->Stop();
|
2006-06-16 05:54:31 +04:00
|
|
|
mAutoScrollTimer = nsnull;
|
2000-07-28 07:48:26 +04:00
|
|
|
}
|
2002-06-14 00:43:32 +04:00
|
|
|
|
2006-05-10 21:30:15 +04:00
|
|
|
mScrollEvent.Revoke();
|
2003-04-20 05:03:40 +04:00
|
|
|
|
2006-04-14 04:28:22 +04:00
|
|
|
if (mCachedOffsetForFrame) {
|
|
|
|
delete mCachedOffsetForFrame;
|
|
|
|
mCachedOffsetForFrame = nsnull;
|
|
|
|
}
|
|
|
|
|
|
|
|
mFrameSelection = nsnull;
|
2000-03-22 02:58:02 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
Landing the XPCDOM_20010329_BRANCH branch, changes mostly done by jband@netscape.com and jst@netscape.com, also some changes done by shaver@mozilla.org, peterv@netscape.com and markh@activestate.com. r= and sr= by vidur@netscape.com, jband@netscape.com, jst@netscpae.com, danm@netscape.com, hyatt@netscape.com, shaver@mozilla.org, dbradley@netscape.com, rpotts@netscape.com.
2001-05-08 20:46:42 +04:00
|
|
|
// QueryInterface implementation for nsRange
|
|
|
|
NS_INTERFACE_MAP_BEGIN(nsTypedSelection)
|
|
|
|
NS_INTERFACE_MAP_ENTRY(nsISelection)
|
2006-07-27 21:57:15 +04:00
|
|
|
NS_INTERFACE_MAP_ENTRY(nsISelection2)
|
Landing the XPCDOM_20010329_BRANCH branch, changes mostly done by jband@netscape.com and jst@netscape.com, also some changes done by shaver@mozilla.org, peterv@netscape.com and markh@activestate.com. r= and sr= by vidur@netscape.com, jband@netscape.com, jst@netscpae.com, danm@netscape.com, hyatt@netscape.com, shaver@mozilla.org, dbradley@netscape.com, rpotts@netscape.com.
2001-05-08 20:46:42 +04:00
|
|
|
NS_INTERFACE_MAP_ENTRY(nsISelectionPrivate)
|
|
|
|
NS_INTERFACE_MAP_ENTRY(nsISupportsWeakReference)
|
|
|
|
NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsISelection)
|
|
|
|
NS_INTERFACE_MAP_ENTRY_CONTENT_CLASSINFO(Selection)
|
|
|
|
NS_INTERFACE_MAP_END
|
2000-03-22 02:58:02 +03:00
|
|
|
|
|
|
|
|
Landing the XPCDOM_20010329_BRANCH branch, changes mostly done by jband@netscape.com and jst@netscape.com, also some changes done by shaver@mozilla.org, peterv@netscape.com and markh@activestate.com. r= and sr= by vidur@netscape.com, jband@netscape.com, jst@netscpae.com, danm@netscape.com, hyatt@netscape.com, shaver@mozilla.org, dbradley@netscape.com, rpotts@netscape.com.
2001-05-08 20:46:42 +04:00
|
|
|
NS_IMPL_ADDREF(nsTypedSelection)
|
2000-11-29 03:13:00 +03:00
|
|
|
NS_IMPL_RELEASE(nsTypedSelection)
|
2000-03-22 02:58:02 +03:00
|
|
|
|
|
|
|
|
2000-05-13 12:07:34 +04:00
|
|
|
NS_IMETHODIMP
|
2000-11-29 03:13:00 +03:00
|
|
|
nsTypedSelection::SetPresShell(nsIPresShell *aPresShell)
|
2000-05-13 12:07:34 +04:00
|
|
|
{
|
2003-07-25 23:06:59 +04:00
|
|
|
mPresShellWeak = do_GetWeakReference(aPresShell);
|
2000-05-13 12:07:34 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
2000-03-22 02:58:02 +03:00
|
|
|
|
2000-05-13 12:07:34 +04:00
|
|
|
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2000-11-29 03:13:00 +03:00
|
|
|
nsTypedSelection::GetAnchorNode(nsIDOMNode** aAnchorNode)
|
2000-03-22 02:58:02 +03:00
|
|
|
{
|
2003-03-12 06:22:11 +03:00
|
|
|
if (!aAnchorNode)
|
|
|
|
return NS_ERROR_NULL_POINTER;
|
2000-08-27 01:23:25 +04:00
|
|
|
*aAnchorNode = nsnull;
|
|
|
|
if(!mAnchorFocusRange)
|
2003-03-12 06:22:11 +03:00
|
|
|
return NS_OK;
|
2000-08-27 01:23:25 +04:00
|
|
|
|
2000-03-22 02:58:02 +03:00
|
|
|
nsresult result;
|
|
|
|
if (GetDirection() == eDirNext){
|
2000-08-24 07:54:30 +04:00
|
|
|
result = mAnchorFocusRange->GetStartContainer(aAnchorNode);
|
2000-03-22 02:58:02 +03:00
|
|
|
}
|
|
|
|
else{
|
2000-08-24 07:54:30 +04:00
|
|
|
result = mAnchorFocusRange->GetEndContainer(aAnchorNode);
|
2000-03-22 02:58:02 +03:00
|
|
|
}
|
2003-03-12 06:22:11 +03:00
|
|
|
return result;
|
2000-03-22 02:58:02 +03:00
|
|
|
}
|
|
|
|
|
2000-05-13 12:07:34 +04:00
|
|
|
NS_IMETHODIMP
|
2000-11-29 03:13:00 +03:00
|
|
|
nsTypedSelection::GetAnchorOffset(PRInt32* aAnchorOffset)
|
2000-03-22 02:58:02 +03:00
|
|
|
{
|
2003-03-12 06:22:11 +03:00
|
|
|
if (!aAnchorOffset)
|
|
|
|
return NS_ERROR_NULL_POINTER;
|
2000-08-27 01:23:25 +04:00
|
|
|
*aAnchorOffset = nsnull;
|
|
|
|
if(!mAnchorFocusRange)
|
|
|
|
return NS_OK;
|
|
|
|
|
2000-03-22 02:58:02 +03:00
|
|
|
nsresult result;
|
|
|
|
if (GetDirection() == eDirNext){
|
|
|
|
result = mAnchorFocusRange->GetStartOffset(aAnchorOffset);
|
|
|
|
}
|
|
|
|
else{
|
|
|
|
result = mAnchorFocusRange->GetEndOffset(aAnchorOffset);
|
|
|
|
}
|
2003-03-12 06:22:11 +03:00
|
|
|
return result;
|
2000-03-22 02:58:02 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
// note: this can return a nil focus node
|
2000-05-13 12:07:34 +04:00
|
|
|
NS_IMETHODIMP
|
2000-11-29 03:13:00 +03:00
|
|
|
nsTypedSelection::GetFocusNode(nsIDOMNode** aFocusNode)
|
2000-03-22 02:58:02 +03:00
|
|
|
{
|
2003-03-12 06:22:11 +03:00
|
|
|
if (!aFocusNode)
|
|
|
|
return NS_ERROR_NULL_POINTER;
|
2000-08-27 01:23:25 +04:00
|
|
|
*aFocusNode = nsnull;
|
|
|
|
if(!mAnchorFocusRange)
|
|
|
|
return NS_OK;
|
|
|
|
|
2000-03-22 02:58:02 +03:00
|
|
|
nsresult result;
|
|
|
|
if (GetDirection() == eDirNext){
|
2000-08-24 07:54:30 +04:00
|
|
|
result = mAnchorFocusRange->GetEndContainer(aFocusNode);
|
2000-03-22 02:58:02 +03:00
|
|
|
}
|
|
|
|
else{
|
2000-08-24 07:54:30 +04:00
|
|
|
result = mAnchorFocusRange->GetStartContainer(aFocusNode);
|
2000-03-22 02:58:02 +03:00
|
|
|
}
|
|
|
|
|
2003-03-12 06:22:11 +03:00
|
|
|
return result;
|
2000-03-22 02:58:02 +03:00
|
|
|
}
|
|
|
|
|
2000-11-29 03:13:00 +03:00
|
|
|
NS_IMETHODIMP nsTypedSelection::GetFocusOffset(PRInt32* aFocusOffset)
|
2000-03-22 02:58:02 +03:00
|
|
|
{
|
2003-03-12 06:22:11 +03:00
|
|
|
if (!aFocusOffset)
|
|
|
|
return NS_ERROR_NULL_POINTER;
|
2000-08-27 01:23:25 +04:00
|
|
|
*aFocusOffset = nsnull;
|
|
|
|
if(!mAnchorFocusRange)
|
|
|
|
return NS_OK;
|
|
|
|
|
|
|
|
nsresult result;
|
2000-03-22 02:58:02 +03:00
|
|
|
if (GetDirection() == eDirNext){
|
|
|
|
result = mAnchorFocusRange->GetEndOffset(aFocusOffset);
|
|
|
|
}
|
|
|
|
else{
|
|
|
|
result = mAnchorFocusRange->GetStartOffset(aFocusOffset);
|
|
|
|
}
|
2003-03-12 06:22:11 +03:00
|
|
|
return result;
|
2000-03-22 02:58:02 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2000-11-29 03:13:00 +03:00
|
|
|
void nsTypedSelection::setAnchorFocusRange(PRInt32 indx)
|
2000-03-22 02:58:02 +03:00
|
|
|
{
|
2006-07-27 21:57:15 +04:00
|
|
|
if (indx >= (PRInt32)mRanges.Length())
|
2000-03-22 02:58:02 +03:00
|
|
|
return;
|
|
|
|
if (indx < 0) //release all
|
|
|
|
{
|
2001-08-21 22:38:20 +04:00
|
|
|
mAnchorFocusRange = nsnull;
|
2000-03-22 02:58:02 +03:00
|
|
|
}
|
|
|
|
else{
|
2006-07-27 21:57:15 +04:00
|
|
|
mAnchorFocusRange = mRanges[indx].mRange;
|
2000-03-22 02:58:02 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
nsIDOMNode*
|
2000-11-29 03:13:00 +03:00
|
|
|
nsTypedSelection::FetchAnchorNode()
|
2000-03-22 02:58:02 +03:00
|
|
|
{ //where did the selection begin
|
|
|
|
nsCOMPtr<nsIDOMNode>returnval;
|
|
|
|
GetAnchorNode(getter_AddRefs(returnval));//this queries
|
|
|
|
return returnval;
|
|
|
|
}//at end it will release, no addreff was called
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
PRInt32
|
2000-11-29 03:13:00 +03:00
|
|
|
nsTypedSelection::FetchAnchorOffset()
|
2000-03-22 02:58:02 +03:00
|
|
|
{
|
|
|
|
PRInt32 returnval;
|
|
|
|
if (NS_SUCCEEDED(GetAnchorOffset(&returnval)))//this queries
|
|
|
|
return returnval;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
nsIDOMNode*
|
2000-11-29 03:13:00 +03:00
|
|
|
nsTypedSelection::FetchOriginalAnchorNode() //where did the ORIGINAL selection begin
|
2000-03-22 02:58:02 +03:00
|
|
|
{
|
|
|
|
nsCOMPtr<nsIDOMNode>returnval;
|
|
|
|
PRInt32 unused;
|
|
|
|
GetOriginalAnchorPoint(getter_AddRefs(returnval), &unused);//this queries
|
|
|
|
return returnval;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
PRInt32
|
2000-11-29 03:13:00 +03:00
|
|
|
nsTypedSelection::FetchOriginalAnchorOffset()
|
2000-03-22 02:58:02 +03:00
|
|
|
{
|
|
|
|
nsCOMPtr<nsIDOMNode>unused;
|
|
|
|
PRInt32 returnval;
|
|
|
|
if (NS_SUCCEEDED(GetOriginalAnchorPoint(getter_AddRefs(unused), &returnval)))//this queries
|
|
|
|
return returnval;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
nsIDOMNode*
|
2000-11-29 03:13:00 +03:00
|
|
|
nsTypedSelection::FetchFocusNode()
|
2000-03-22 02:58:02 +03:00
|
|
|
{ //where is the carret
|
|
|
|
nsCOMPtr<nsIDOMNode>returnval;
|
|
|
|
GetFocusNode(getter_AddRefs(returnval));//this queries
|
|
|
|
return returnval;
|
|
|
|
}//at end it will release, no addreff was called
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
PRInt32
|
2000-11-29 03:13:00 +03:00
|
|
|
nsTypedSelection::FetchFocusOffset()
|
2000-03-22 02:58:02 +03:00
|
|
|
{
|
|
|
|
PRInt32 returnval;
|
|
|
|
if (NS_SUCCEEDED(GetFocusOffset(&returnval)))//this queries
|
|
|
|
return returnval;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
nsIDOMNode*
|
2000-11-29 03:13:00 +03:00
|
|
|
nsTypedSelection::FetchStartParent(nsIDOMRange *aRange) //skip all the com stuff and give me the start/end
|
2000-03-22 02:58:02 +03:00
|
|
|
{
|
|
|
|
if (!aRange)
|
|
|
|
return nsnull;
|
|
|
|
nsCOMPtr<nsIDOMNode> returnval;
|
2000-08-24 07:54:30 +04:00
|
|
|
aRange->GetStartContainer(getter_AddRefs(returnval));
|
2000-03-22 02:58:02 +03:00
|
|
|
return returnval;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
PRInt32
|
2000-11-29 03:13:00 +03:00
|
|
|
nsTypedSelection::FetchStartOffset(nsIDOMRange *aRange)
|
2000-03-22 02:58:02 +03:00
|
|
|
{
|
|
|
|
if (!aRange)
|
|
|
|
return nsnull;
|
|
|
|
PRInt32 returnval;
|
|
|
|
if (NS_SUCCEEDED(aRange->GetStartOffset(&returnval)))
|
|
|
|
return returnval;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
nsIDOMNode*
|
2000-11-29 03:13:00 +03:00
|
|
|
nsTypedSelection::FetchEndParent(nsIDOMRange *aRange) //skip all the com stuff and give me the start/end
|
2000-03-22 02:58:02 +03:00
|
|
|
{
|
|
|
|
if (!aRange)
|
|
|
|
return nsnull;
|
|
|
|
nsCOMPtr<nsIDOMNode> returnval;
|
2000-08-24 07:54:30 +04:00
|
|
|
aRange->GetEndContainer(getter_AddRefs(returnval));
|
2000-03-22 02:58:02 +03:00
|
|
|
return returnval;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
PRInt32
|
2000-11-29 03:13:00 +03:00
|
|
|
nsTypedSelection::FetchEndOffset(nsIDOMRange *aRange)
|
2000-03-22 02:58:02 +03:00
|
|
|
{
|
|
|
|
if (!aRange)
|
|
|
|
return nsnull;
|
|
|
|
PRInt32 returnval;
|
|
|
|
if (NS_SUCCEEDED(aRange->GetEndOffset(&returnval)))
|
|
|
|
return returnval;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2006-07-27 21:57:15 +04:00
|
|
|
static nsresult
|
|
|
|
CompareToRangeStart(nsIDOMNode* aCompareNode, PRInt32 aCompareOffset,
|
|
|
|
nsIDOMRange* aRange, PRInt32* cmp)
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsIDOMNode> startNode;
|
|
|
|
nsresult rv = aRange->GetStartContainer(getter_AddRefs(startNode));
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
PRInt32 startOffset;
|
|
|
|
rv = aRange->GetStartOffset(&startOffset);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2006-10-21 05:30:54 +04:00
|
|
|
*cmp = CompareDOMPoints(aCompareNode, aCompareOffset,
|
|
|
|
startNode, startOffset);
|
2006-07-27 21:57:15 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
static nsresult
|
|
|
|
CompareToRangeEnd(nsIDOMNode* aCompareNode, PRInt32 aCompareOffset,
|
|
|
|
nsIDOMRange* aRange, PRInt32* cmp)
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsIDOMNode> endNode;
|
|
|
|
nsresult rv = aRange->GetEndContainer(getter_AddRefs(endNode));
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
PRInt32 endOffset;
|
|
|
|
rv = aRange->GetEndOffset(&endOffset);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2006-10-21 05:30:54 +04:00
|
|
|
*cmp = CompareDOMPoints(aCompareNode, aCompareOffset,
|
|
|
|
endNode, endOffset);
|
2006-07-27 21:57:15 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef DEBUG
|
|
|
|
// checks the indices to make sure the range bookkeeping is up-to-date, useful
|
|
|
|
// for debugging to make sure everything is consistent
|
|
|
|
PRBool
|
|
|
|
nsTypedSelection::ValidateRanges()
|
|
|
|
{
|
|
|
|
if (mRanges.Length() != mRangeEndings.Length()) {
|
|
|
|
NS_NOTREACHED("Lengths don't match");
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
// check the main array and make sure they refer to the correct sorted ones
|
|
|
|
PRUint32 i;
|
|
|
|
for (i = 0; i < mRanges.Length(); i ++) {
|
|
|
|
if (mRanges[i].mEndIndex < 0 ||
|
|
|
|
mRanges[i].mEndIndex >= (PRInt32)mRangeEndings.Length()) {
|
|
|
|
NS_NOTREACHED("Sorted index is out of bounds");
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
if (mRangeEndings[mRanges[i].mEndIndex] != (PRInt32)i) {
|
|
|
|
NS_NOTREACHED("Beginning or ending isn't correct");
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// check the other array to make sure they all refer to valid indices
|
|
|
|
for (i = 0; i < mRangeEndings.Length(); i ++) {
|
|
|
|
if (mRangeEndings[i] < 0 ||
|
|
|
|
mRangeEndings[i] >= (PRInt32)mRanges.Length()) {
|
|
|
|
NS_NOTREACHED("Ending refers to invalid index");
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return PR_TRUE;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
// nsTypedSelection::FindInsertionPoint
|
|
|
|
//
|
|
|
|
// Binary searches the sorted array of ranges for the insertion point for
|
|
|
|
// the given node/offset. The given comparator is used, and the index where
|
|
|
|
// the point should appear in the array is placed in *aInsertionPoint;
|
|
|
|
//
|
|
|
|
// If the remapping array is given, we'll find the position in that array
|
|
|
|
// for the insertion, where that array contains indices that reference
|
|
|
|
// the range array. This can be NULL to not use a remapping array.
|
|
|
|
//
|
|
|
|
// If there is item(s) in the array equal to the input point, we will return
|
|
|
|
// a random index between or adjacent to this item(s).
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
nsTypedSelection::FindInsertionPoint(
|
|
|
|
const nsTArray<PRInt32>* aRemappingArray,
|
|
|
|
nsIDOMNode* aPointNode, PRInt32 aPointOffset,
|
|
|
|
nsresult (*aComparator)(nsIDOMNode*,PRInt32,nsIDOMRange*,PRInt32*),
|
|
|
|
PRInt32* aInsertionPoint)
|
|
|
|
{
|
|
|
|
nsresult rv;
|
|
|
|
NS_ASSERTION(!aRemappingArray || aRemappingArray->Length() == mRanges.Length(),
|
|
|
|
"Remapping array must have the same entries as the range array");
|
|
|
|
|
|
|
|
PRInt32 beginSearch = 0;
|
|
|
|
PRInt32 endSearch = mRanges.Length(); // one beyond what to check
|
|
|
|
while (endSearch - beginSearch > 0) {
|
|
|
|
PRInt32 center = (endSearch - beginSearch) / 2 + beginSearch;
|
|
|
|
|
|
|
|
nsIDOMRange* range;
|
|
|
|
if (aRemappingArray)
|
|
|
|
range = mRanges[(*aRemappingArray)[center]].mRange;
|
|
|
|
else
|
|
|
|
range = mRanges[center].mRange;
|
|
|
|
|
|
|
|
PRInt32 cmp;
|
|
|
|
rv = aComparator(aPointNode, aPointOffset, range, &cmp);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
if (cmp < 0) { // point < cur
|
|
|
|
endSearch = center;
|
|
|
|
} else if (cmp > 0) { // point > cur
|
|
|
|
beginSearch = center + 1;
|
|
|
|
} else { // found match, done
|
|
|
|
beginSearch = center;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
*aInsertionPoint = beginSearch;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2000-03-22 02:58:02 +03:00
|
|
|
nsresult
|
2000-11-29 03:13:00 +03:00
|
|
|
nsTypedSelection::AddItem(nsIDOMRange *aItem)
|
2000-03-22 02:58:02 +03:00
|
|
|
{
|
2006-07-27 21:57:15 +04:00
|
|
|
nsresult rv;
|
2000-03-22 02:58:02 +03:00
|
|
|
if (!aItem)
|
|
|
|
return NS_ERROR_NULL_POINTER;
|
|
|
|
|
2006-07-27 21:57:15 +04:00
|
|
|
NS_ASSERTION(ValidateRanges(), "Ranges out of sync");
|
|
|
|
|
|
|
|
// a common case is that we have no ranges yet
|
|
|
|
if (mRanges.Length() == 0) {
|
|
|
|
if (! mRanges.AppendElement(RangeData(aItem, 0)))
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
if (! mRangeEndings.AppendElement(0)) {
|
|
|
|
mRanges.Clear();
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2006-08-10 23:56:43 +04:00
|
|
|
nsCOMPtr<nsIDOMNode> beginNode;
|
|
|
|
PRInt32 beginOffset;
|
|
|
|
rv = aItem->GetStartContainer(getter_AddRefs(beginNode));
|
2006-07-27 21:57:15 +04:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2006-08-10 23:56:43 +04:00
|
|
|
rv = aItem->GetStartOffset(&beginOffset);
|
2006-07-27 21:57:15 +04:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
PRInt32 beginInsertionPoint;
|
2006-08-10 23:56:43 +04:00
|
|
|
rv = FindInsertionPoint(nsnull, beginNode, beginOffset,
|
2006-07-27 21:57:15 +04:00
|
|
|
CompareToRangeStart, &beginInsertionPoint);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
// XXX Performance: 99% of the time, the beginning array and the ending array
|
|
|
|
// will be the same because the ranges do not overlap. We could save a few
|
|
|
|
// compares (which can be expensive) in this common case by special casing
|
|
|
|
// this.
|
|
|
|
|
2006-08-10 23:56:43 +04:00
|
|
|
nsCOMPtr<nsIDOMNode> endNode;
|
|
|
|
PRInt32 endOffset;
|
|
|
|
rv = aItem->GetEndContainer(getter_AddRefs(endNode));
|
2006-07-27 21:57:15 +04:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2006-08-10 23:56:43 +04:00
|
|
|
rv = aItem->GetEndOffset(&endOffset);
|
2006-07-27 21:57:15 +04:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2006-08-10 23:56:43 +04:00
|
|
|
// make sure that this range is not already in the selection
|
|
|
|
if (FindRangeGivenPoint(beginNode, beginOffset, endNode, endOffset,
|
|
|
|
beginInsertionPoint)) {
|
|
|
|
// silently succeed, this range is already in the selection
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2006-07-27 21:57:15 +04:00
|
|
|
PRInt32 endInsertionPoint;
|
2006-08-10 23:56:43 +04:00
|
|
|
rv = FindInsertionPoint(&mRangeEndings, endNode, endOffset,
|
2006-07-27 21:57:15 +04:00
|
|
|
CompareToRangeEnd, &endInsertionPoint);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2006-08-10 23:56:43 +04:00
|
|
|
|
2006-07-27 21:57:15 +04:00
|
|
|
// insert the range, being careful to revert everything on error to keep
|
|
|
|
// consistency
|
|
|
|
if (! mRanges.InsertElementAt(beginInsertionPoint,
|
|
|
|
RangeData(aItem, endInsertionPoint))) {
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
}
|
|
|
|
if (! mRangeEndings.InsertElementAt(endInsertionPoint, beginInsertionPoint)) {
|
|
|
|
mRanges.RemoveElementAt(beginInsertionPoint);
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
}
|
|
|
|
|
|
|
|
// adjust the end indices that point to the main list
|
|
|
|
PRUint32 i;
|
|
|
|
for (i = 0; i < mRangeEndings.Length(); i ++) {
|
|
|
|
if (mRangeEndings[i] >= beginInsertionPoint)
|
|
|
|
mRangeEndings[i] ++;
|
|
|
|
}
|
|
|
|
|
|
|
|
// the last loop updated the inserted index as well, so we need to put it
|
|
|
|
// back (this saves a comparison in that loop)
|
|
|
|
mRangeEndings[endInsertionPoint] = beginInsertionPoint;
|
|
|
|
|
|
|
|
// adjust the begin/end indices
|
|
|
|
for (i = endInsertionPoint + 1; i < mRangeEndings.Length(); i ++)
|
|
|
|
mRanges[mRangeEndings[i]].mEndIndex = i;
|
|
|
|
|
|
|
|
NS_ASSERTION(ValidateRanges(), "Ranges out of sync");
|
|
|
|
return NS_OK;
|
|
|
|
}
|
2000-03-22 02:58:02 +03:00
|
|
|
|
|
|
|
|
|
|
|
nsresult
|
2000-11-29 03:13:00 +03:00
|
|
|
nsTypedSelection::RemoveItem(nsIDOMRange *aItem)
|
2000-03-22 02:58:02 +03:00
|
|
|
{
|
2002-12-11 03:02:49 +03:00
|
|
|
if (!aItem)
|
2000-03-22 02:58:02 +03:00
|
|
|
return NS_ERROR_NULL_POINTER;
|
2006-07-27 21:57:15 +04:00
|
|
|
NS_ASSERTION(ValidateRanges(), "Ranges out of sync");
|
|
|
|
|
|
|
|
// Find the range's index & remove it. We could use FindInsertionPoint to
|
|
|
|
// get O(log n) time, but that requires many expensive DOM comparisons.
|
|
|
|
// For even several thousand items, this is probably faster because the
|
|
|
|
// comparisons are so fast.
|
|
|
|
PRInt32 idx = -1;
|
|
|
|
PRUint32 i;
|
|
|
|
for (i = 0; i < mRanges.Length(); i ++) {
|
|
|
|
if (mRanges[i].mRange == aItem) {
|
|
|
|
idx = (PRInt32)i;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2006-07-27 22:39:18 +04:00
|
|
|
if (idx < 0)
|
2006-07-27 21:57:15 +04:00
|
|
|
return NS_ERROR_INVALID_ARG;
|
|
|
|
mRanges.RemoveElementAt(idx);
|
2000-03-22 02:58:02 +03:00
|
|
|
|
2006-07-27 21:57:15 +04:00
|
|
|
// need to update the range ending list to reflect the removed item
|
|
|
|
PRInt32 endingIndex = -1;
|
|
|
|
for (i = 0; i < mRangeEndings.Length(); i ++) {
|
|
|
|
if (mRangeEndings[i] == idx)
|
|
|
|
endingIndex = i;
|
|
|
|
if (mRangeEndings[i] > idx)
|
|
|
|
mRangeEndings[i] --;
|
|
|
|
}
|
|
|
|
NS_ASSERTION(endingIndex >= 0 && endingIndex < (PRInt32)mRangeEndings.Length(),
|
|
|
|
"Index not found in ending list");
|
|
|
|
|
|
|
|
// remove from the sorted lists
|
|
|
|
mRangeEndings.RemoveElementAt(endingIndex);
|
|
|
|
|
|
|
|
// adjust indices of the RangeData structures
|
|
|
|
for (i = endingIndex; i < mRangeEndings.Length(); i ++)
|
|
|
|
mRanges[mRangeEndings[i]].mEndIndex = i;
|
|
|
|
|
|
|
|
NS_ASSERTION(ValidateRanges(), "Ranges out of sync");
|
|
|
|
return NS_OK;
|
|
|
|
}
|
2000-03-22 02:58:02 +03:00
|
|
|
|
|
|
|
|
|
|
|
nsresult
|
2004-08-01 03:15:21 +04:00
|
|
|
nsTypedSelection::Clear(nsPresContext* aPresContext)
|
2000-03-22 02:58:02 +03:00
|
|
|
{
|
|
|
|
setAnchorFocusRange(-1);
|
2006-07-27 21:57:15 +04:00
|
|
|
|
|
|
|
for (PRInt32 i = 0; i < (PRInt32)mRanges.Length(); i ++)
|
|
|
|
selectFrames(aPresContext, mRanges[i].mRange, 0);
|
|
|
|
mRanges.Clear();
|
|
|
|
mRangeEndings.Clear();
|
|
|
|
|
2000-03-22 02:58:02 +03:00
|
|
|
// Reset direction so for more dependable table selection range handling
|
|
|
|
SetDirection(eDirNext);
|
2006-06-20 04:30:18 +04:00
|
|
|
|
|
|
|
// If this was an ATTENTION selection, change it back to normal now
|
|
|
|
if (mFrameSelection->GetDisplaySelection() ==
|
|
|
|
nsISelectionController::SELECTION_ATTENTION) {
|
|
|
|
mFrameSelection->SetDisplaySelection(nsISelectionController::SELECTION_ON);
|
|
|
|
}
|
|
|
|
|
2000-03-22 02:58:02 +03:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2006-07-27 21:57:15 +04:00
|
|
|
// nsTypedSelection::MoveIndexToFirstMatch
|
|
|
|
//
|
|
|
|
// This adjusts the given index backwards in the range array so that it
|
|
|
|
// points to the first match of (node,offset). There might be any number
|
|
|
|
// of identical sequencial items in the array and the index can initially
|
|
|
|
// point to any one of them. When complete, the index will be moved to
|
|
|
|
// point to the first one of these. If the index does not point to a
|
|
|
|
// match of (node,offset) or there is only one match, the index will be
|
|
|
|
// untouched.
|
|
|
|
//
|
|
|
|
// If there are multiple ranges beginning at the requested position, we'll
|
|
|
|
// get a random index in between those from FindInsertionPoint. We want the
|
|
|
|
// index to be at the first match in the array.
|
|
|
|
//
|
|
|
|
// If the remapping array (sorted list containing indices into mRanges)
|
|
|
|
// is given, we'll use that for sorting and consider the index into
|
|
|
|
// that array. If NULL, we'll just use mRanges directly.
|
|
|
|
//
|
|
|
|
// If aUseBeginning is set we'll compare to the range beginnings in the
|
|
|
|
// selection. If false, we'll compare to range endings.
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
nsTypedSelection::MoveIndexToFirstMatch(PRInt32* aIndex, nsIDOMNode* aNode,
|
|
|
|
PRInt32 aOffset,
|
|
|
|
const nsTArray<PRInt32>* aRemappingArray,
|
|
|
|
PRBool aUseBeginning)
|
|
|
|
{
|
|
|
|
nsresult rv;
|
|
|
|
nsCOMPtr<nsIDOMNode> curNode;
|
|
|
|
PRInt32 curOffset;
|
|
|
|
while (*aIndex > 0) {
|
|
|
|
nsIDOMRange* range;
|
|
|
|
if (aRemappingArray)
|
|
|
|
range = mRanges[(*aRemappingArray)[(*aIndex) - 1]].mRange;
|
|
|
|
else
|
|
|
|
range = mRanges[(*aIndex) - 1].mRange;
|
|
|
|
|
|
|
|
if (aUseBeginning) {
|
|
|
|
rv = range->GetStartContainer(getter_AddRefs(curNode));
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
rv = range->GetStartOffset(&curOffset);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
} else {
|
|
|
|
rv = range->GetEndContainer(getter_AddRefs(curNode));
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
rv = range->GetEndOffset(&curOffset);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (curNode != aNode)
|
|
|
|
break; // not a match
|
|
|
|
if (curOffset != aOffset)
|
|
|
|
break; // not a match
|
|
|
|
|
|
|
|
// the previous node matches, go back one
|
|
|
|
(*aIndex) --;
|
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
// nsTypedSelection::MoveIndexToNextMismatch
|
|
|
|
//
|
|
|
|
// The same as MoveIndexToFirstMatch but increments the index until it
|
|
|
|
// points to something that doesn't match (node,offset).
|
|
|
|
//
|
|
|
|
// If there is one or more range ending at the requested position, we
|
|
|
|
// want to start checking the first one that ends inside the range. This
|
|
|
|
// moves the given index to point to the first index inside the range.
|
|
|
|
// It may be one past the last item in the array.
|
|
|
|
//
|
|
|
|
// If the requested DOM position is '9', and the caller got index 3
|
|
|
|
// from FindInsertionPoint with points in the range array:
|
|
|
|
// 6 8 9 9 9 13 19
|
|
|
|
// ^
|
|
|
|
// input
|
|
|
|
// The input point will point to a random '9' in the array, or possibly
|
|
|
|
// the '13', which are all valid points for a new '9' to live in this array.
|
|
|
|
// This function will move the index to point to the '13' in this case,
|
|
|
|
// which is the first offset not matching the input position.
|
|
|
|
//
|
|
|
|
// See MoveIndexToFirstMatch for the meaning of aRemappingArray and
|
|
|
|
// aUseBeginning.
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
nsTypedSelection::MoveIndexToNextMismatch(PRInt32* aIndex, nsIDOMNode* aNode,
|
|
|
|
PRInt32 aOffset,
|
|
|
|
const nsTArray<PRInt32>* aRemappingArray,
|
|
|
|
PRBool aUseBeginning)
|
|
|
|
{
|
|
|
|
nsresult rv;
|
|
|
|
nsCOMPtr<nsIDOMNode> curNode;
|
|
|
|
PRInt32 curOffset;
|
|
|
|
while (*aIndex < (PRInt32)mRanges.Length()) {
|
|
|
|
nsIDOMRange* range;
|
|
|
|
if (aRemappingArray)
|
|
|
|
range = mRanges[(*aRemappingArray)[*aIndex]].mRange;
|
|
|
|
else
|
|
|
|
range = mRanges[*aIndex].mRange;
|
|
|
|
|
|
|
|
if (aUseBeginning) {
|
|
|
|
rv = range->GetStartContainer(getter_AddRefs(curNode));
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
rv = range->GetStartOffset(&curOffset);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
} else {
|
|
|
|
rv = range->GetEndContainer(getter_AddRefs(curNode));
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
rv = range->GetEndOffset(&curOffset);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (curNode != aNode)
|
|
|
|
break; // mismatch
|
|
|
|
if (curOffset != aOffset)
|
|
|
|
break; // mismatch
|
|
|
|
|
|
|
|
// this node matches, go to the next one
|
|
|
|
(*aIndex) ++;
|
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
// nsTypedSelection::GetRangesForInterval
|
|
|
|
//
|
|
|
|
// XPCOM wrapper for the COMArray version
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsTypedSelection::GetRangesForInterval(nsIDOMNode* aBeginNode, PRInt32 aBeginOffset,
|
|
|
|
nsIDOMNode* aEndNode, PRInt32 aEndOffset,
|
|
|
|
PRBool aAllowAdjacent,
|
|
|
|
PRUint32 *aResultCount,
|
|
|
|
nsIDOMRange ***aResults)
|
|
|
|
{
|
|
|
|
if (! aBeginNode || ! aEndNode || ! aResultCount || ! aResults)
|
|
|
|
return NS_ERROR_NULL_POINTER;
|
|
|
|
|
2006-09-24 10:04:00 +04:00
|
|
|
*aResultCount = 0;
|
|
|
|
*aResults = nsnull;
|
|
|
|
|
2006-07-27 21:57:15 +04:00
|
|
|
nsCOMArray<nsIDOMRange> results;
|
2006-09-24 10:04:00 +04:00
|
|
|
nsresult rv = GetRangesForIntervalCOMArray(aBeginNode, aBeginOffset,
|
|
|
|
aEndNode, aEndOffset,
|
|
|
|
aAllowAdjacent,
|
|
|
|
&results);
|
2006-07-27 21:57:15 +04:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
if (results.Count() == 0)
|
|
|
|
return NS_OK;
|
|
|
|
|
|
|
|
*aResults = NS_STATIC_CAST(nsIDOMRange**,
|
|
|
|
nsMemory::Alloc(sizeof(nsIDOMRange*) * results.Count()));
|
|
|
|
NS_ENSURE_TRUE(*aResults, NS_ERROR_OUT_OF_MEMORY);
|
|
|
|
|
|
|
|
*aResultCount = results.Count();
|
|
|
|
for (PRInt32 i = 0; i < results.Count(); i ++)
|
|
|
|
NS_ADDREF((*aResults)[i] = results[i]);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
// nsTypedSelection::GetRangesForIntervalCOMArray
|
|
|
|
//
|
|
|
|
// Fills a COM array with the ranges overlapping the range specified by
|
|
|
|
// the given endpoints. Ranges in the selection exactly adjacent to the
|
|
|
|
// input range are not returned unless aAllowAdjacent is set.
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsTypedSelection::GetRangesForIntervalCOMArray(nsIDOMNode* aBeginNode, PRInt32 aBeginOffset,
|
|
|
|
nsIDOMNode* aEndNode, PRInt32 aEndOffset,
|
|
|
|
PRBool aAllowAdjacent,
|
|
|
|
nsCOMArray<nsIDOMRange>* aRanges)
|
|
|
|
{
|
|
|
|
nsresult rv;
|
|
|
|
NS_ASSERTION(ValidateRanges(), "Ranges out of sync");
|
|
|
|
aRanges->Clear();
|
|
|
|
if (mRanges.Length() == 0)
|
|
|
|
return NS_OK;
|
|
|
|
|
|
|
|
// Ranges that begin after the checked range, and ranges that end before
|
|
|
|
// the checked range can be discarded. The beginning index is the offset
|
|
|
|
// into the beginning array of the first item we DON'T have to check.
|
|
|
|
|
|
|
|
// ...index into the beginning array that is the FIRST ITEM OUTSIDE
|
|
|
|
// OUR RANGE
|
|
|
|
PRInt32 beginningIndex;
|
|
|
|
rv = FindInsertionPoint(nsnull, aEndNode, aEndOffset,
|
|
|
|
&CompareToRangeStart, &beginningIndex);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
if (beginningIndex == 0)
|
|
|
|
return NS_OK; // optimization: all ranges are after us
|
|
|
|
|
|
|
|
// ...index into the ending array that is the FIRST ITEM WE WANT TO CHECK
|
|
|
|
PRInt32 endingIndex;
|
|
|
|
rv = FindInsertionPoint(&mRangeEndings, aBeginNode, aBeginOffset,
|
|
|
|
&CompareToRangeEnd, &endingIndex);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
if (endingIndex == (PRInt32)mRangeEndings.Length())
|
|
|
|
return NS_OK; // optimization: all ranges are before us
|
|
|
|
|
|
|
|
// adjust the indices in case of exact matches, FindInsertionPoint will
|
|
|
|
// give us a random index that would still be sorted if there is a match
|
|
|
|
if (aAllowAdjacent) {
|
|
|
|
// include adjacent points
|
|
|
|
//
|
|
|
|
// Recall that we want all things in mRangeEndings (indexed by endingIndex)
|
|
|
|
// before the requested beginning, and everything in mRanges (indexed by
|
|
|
|
// beginningIndex) after the requested ending.
|
|
|
|
//
|
|
|
|
// 1 3 5 5 5 8 9 10 10 10 11 12 <-- imaginary DOM positions of ranges
|
|
|
|
// ^ ^ <-- we have this
|
|
|
|
// ^ ^ <-- compute this range
|
|
|
|
// endingIndex beginningIndex
|
|
|
|
rv = MoveIndexToFirstMatch(&endingIndex, aBeginNode, aBeginOffset,
|
|
|
|
&mRangeEndings, PR_FALSE);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
rv = MoveIndexToNextMismatch(&beginningIndex, aEndNode, aEndOffset,
|
|
|
|
nsnull, PR_TRUE);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
} else {
|
|
|
|
// exclude adjacent points, see previous case
|
|
|
|
// 1 3 5 5 5 8 9 10 10 10 11 12 <-- imaginary DOM positions of ranges
|
|
|
|
// ^ ^ <-- we have this
|
|
|
|
// ^ ^ <-- compute this range
|
|
|
|
// endingIndex beginningIndex
|
|
|
|
rv = MoveIndexToNextMismatch(&endingIndex, aBeginNode, aBeginOffset,
|
|
|
|
&mRangeEndings, PR_FALSE);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
rv = MoveIndexToFirstMatch(&beginningIndex, aEndNode, aEndOffset,
|
|
|
|
nsnull, PR_TRUE);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
}
|
|
|
|
|
|
|
|
// check for overlaps in the two ranges by linearly searching the smallest
|
|
|
|
// set of matches
|
|
|
|
if (beginningIndex > (PRInt32)mRangeEndings.Length() - endingIndex) {
|
|
|
|
// check ending array because its smaller
|
|
|
|
for (PRInt32 i = endingIndex; i < (PRInt32)mRangeEndings.Length(); i ++) {
|
|
|
|
if (mRangeEndings[i] < beginningIndex) {
|
|
|
|
if (! aRanges->AppendObject(mRanges[mRangeEndings[i]].mRange))
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
for (PRInt32 i = 0; i < beginningIndex; i ++) {
|
|
|
|
if (mRanges[i].mEndIndex >= endingIndex) {
|
|
|
|
if (! aRanges->AppendObject(mRanges[i].mRange))
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2006-08-10 23:56:43 +04:00
|
|
|
// RangeMatches*Point
|
|
|
|
//
|
|
|
|
// Compares the range beginning or ending point, and returns true if it
|
|
|
|
// exactly matches the given DOM point.
|
|
|
|
|
|
|
|
static PRBool
|
|
|
|
RangeMatchesBeginPoint(nsIDOMRange* aRange, nsIDOMNode* aNode, PRInt32 aOffset)
|
|
|
|
{
|
|
|
|
PRInt32 offset;
|
|
|
|
nsresult rv = aRange->GetStartOffset(&offset);
|
|
|
|
if (NS_FAILED(rv) || offset != aOffset)
|
|
|
|
return PR_FALSE;
|
|
|
|
|
|
|
|
nsCOMPtr<nsIDOMNode> node;
|
|
|
|
rv = aRange->GetStartContainer(getter_AddRefs(node));
|
|
|
|
if (NS_FAILED(rv) || node != aNode)
|
|
|
|
return PR_FALSE;
|
|
|
|
|
|
|
|
return PR_TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static PRBool
|
|
|
|
RangeMatchesEndPoint(nsIDOMRange* aRange, nsIDOMNode* aNode, PRInt32 aOffset)
|
|
|
|
{
|
|
|
|
PRInt32 offset;
|
|
|
|
nsresult rv = aRange->GetEndOffset(&offset);
|
|
|
|
if (NS_FAILED(rv) || offset != aOffset)
|
|
|
|
return PR_FALSE;
|
|
|
|
|
|
|
|
nsCOMPtr<nsIDOMNode> node;
|
|
|
|
rv = aRange->GetEndContainer(getter_AddRefs(node));
|
|
|
|
if (NS_FAILED(rv) || node != aNode)
|
|
|
|
return PR_FALSE;
|
|
|
|
|
|
|
|
return PR_TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// nsTypedSelection::FindRangeGivenPoint
|
|
|
|
//
|
|
|
|
// Searches for the range matching the exact given range points. We search
|
|
|
|
// in the array of beginnings, and start from the given index. This index
|
|
|
|
// should be the result of FindInsertionPoint, which will return any index
|
|
|
|
// within a range of identical ones.
|
|
|
|
//
|
|
|
|
// Therefore, this function searches backwards and forwards from that point
|
|
|
|
// of all matching beginning points, and then compares the ending points to
|
|
|
|
// find a match. Returns true if a match was found, false if not.
|
|
|
|
|
|
|
|
PRBool
|
|
|
|
nsTypedSelection::FindRangeGivenPoint(
|
|
|
|
nsIDOMNode* aBeginNode, PRInt32 aBeginOffset,
|
|
|
|
nsIDOMNode* aEndNode, PRInt32 aEndOffset,
|
|
|
|
PRInt32 aStartSearchingHere)
|
|
|
|
{
|
|
|
|
PRInt32 i;
|
|
|
|
NS_ASSERTION(aStartSearchingHere >= 0 && aStartSearchingHere <= (PRInt32)mRanges.Length(),
|
|
|
|
"Input searching seed is not in range.");
|
|
|
|
|
|
|
|
// search backwards for a begin match
|
|
|
|
for (i = aStartSearchingHere; i >= 0 && i < (PRInt32)mRanges.Length(); i --) {
|
|
|
|
if (RangeMatchesBeginPoint(mRanges[i].mRange, aBeginNode, aBeginOffset)) {
|
|
|
|
if (RangeMatchesEndPoint(mRanges[i].mRange, aEndNode, aEndOffset))
|
|
|
|
return PR_TRUE;
|
|
|
|
} else {
|
|
|
|
// done with matches going backwards
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// search forwards for a begin match
|
|
|
|
for (i = aStartSearchingHere + 1; i < (PRInt32)mRanges.Length(); i ++) {
|
|
|
|
if (RangeMatchesBeginPoint(mRanges[i].mRange, aBeginNode, aBeginOffset)) {
|
|
|
|
if (RangeMatchesEndPoint(mRanges[i].mRange, aEndNode, aEndOffset))
|
|
|
|
return PR_TRUE;
|
|
|
|
} else {
|
|
|
|
// done with matches going forwards
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// match not found
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
|
2000-03-22 02:58:02 +03:00
|
|
|
//utility method to get the primary frame of node or use the offset to get frame of child node
|
|
|
|
|
|
|
|
#if 0
|
|
|
|
NS_IMETHODIMP
|
2000-11-29 03:13:00 +03:00
|
|
|
nsTypedSelection::GetPrimaryFrameForRangeEndpoint(nsIDOMNode *aNode, PRInt32 aOffset, PRBool aIsEndNode, nsIFrame **aReturnFrame)
|
2000-03-22 02:58:02 +03:00
|
|
|
{
|
|
|
|
if (!aNode || !aReturnFrame)
|
|
|
|
return NS_ERROR_NULL_POINTER;
|
|
|
|
|
|
|
|
if (aOffset < 0)
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
|
|
|
|
*aReturnFrame = 0;
|
|
|
|
|
2003-03-12 06:22:11 +03:00
|
|
|
nsresult result = NS_OK;
|
2000-03-22 02:58:02 +03:00
|
|
|
|
2003-06-21 04:15:41 +04:00
|
|
|
nsCOMPtr<nsIDOMNode> node = aNode;
|
2000-03-22 02:58:02 +03:00
|
|
|
|
|
|
|
if (!node)
|
|
|
|
return NS_ERROR_NULL_POINTER;
|
|
|
|
|
|
|
|
nsCOMPtr<nsIContent> content = do_QueryInterface(node, &result);
|
|
|
|
|
|
|
|
if (NS_FAILED(result))
|
|
|
|
return result;
|
|
|
|
|
|
|
|
if (!content)
|
|
|
|
return NS_ERROR_NULL_POINTER;
|
|
|
|
|
2006-05-05 10:52:21 +04:00
|
|
|
if (content->IsNodeOfType(nsINode::eELEMENT))
|
2000-03-22 02:58:02 +03:00
|
|
|
{
|
|
|
|
if (aIsEndNode)
|
|
|
|
aOffset--;
|
|
|
|
|
|
|
|
if (aOffset >= 0)
|
|
|
|
{
|
2003-09-27 08:18:26 +04:00
|
|
|
nsIContent *child = content->GetChildAt(aOffset);
|
2000-03-22 02:58:02 +03:00
|
|
|
if (!child) //out of bounds?
|
|
|
|
return NS_ERROR_FAILURE;
|
2003-09-27 08:18:26 +04:00
|
|
|
|
|
|
|
content = child; // releases the focusnode
|
2000-03-22 02:58:02 +03:00
|
|
|
}
|
|
|
|
}
|
2005-08-23 02:24:29 +04:00
|
|
|
*aReturnFrame = mFrameSelection->GetShell()->GetPrimaryFrameFor(content);
|
|
|
|
return NS_OK;
|
2000-03-22 02:58:02 +03:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2000-11-29 03:13:00 +03:00
|
|
|
nsTypedSelection::GetPrimaryFrameForAnchorNode(nsIFrame **aReturnFrame)
|
2000-03-22 02:58:02 +03:00
|
|
|
{
|
|
|
|
if (!aReturnFrame)
|
|
|
|
return NS_ERROR_NULL_POINTER;
|
|
|
|
|
|
|
|
PRInt32 frameOffset = 0;
|
|
|
|
*aReturnFrame = 0;
|
|
|
|
nsCOMPtr<nsIContent> content = do_QueryInterface(FetchAnchorNode());
|
2000-05-11 08:25:43 +04:00
|
|
|
if (content && mFrameSelection)
|
2000-06-28 08:00:12 +04:00
|
|
|
{
|
2006-04-26 06:01:07 +04:00
|
|
|
*aReturnFrame = mFrameSelection->
|
|
|
|
GetFrameForNodeOffset(content, FetchAnchorOffset(),
|
|
|
|
mFrameSelection->GetHint(), &frameOffset);
|
|
|
|
if (*aReturnFrame)
|
|
|
|
return NS_OK;
|
2000-06-28 08:00:12 +04:00
|
|
|
}
|
2000-03-22 02:58:02 +03:00
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2006-08-30 13:26:39 +04:00
|
|
|
nsTypedSelection::GetPrimaryFrameForFocusNode(nsIFrame **aReturnFrame, PRInt32 *aOffsetUsed,
|
|
|
|
PRBool aVisual)
|
2000-03-22 02:58:02 +03:00
|
|
|
{
|
|
|
|
if (!aReturnFrame)
|
|
|
|
return NS_ERROR_NULL_POINTER;
|
|
|
|
|
2005-11-16 12:37:01 +03:00
|
|
|
nsCOMPtr<nsIContent> content = do_QueryInterface(FetchFocusNode());
|
|
|
|
if (!content || !mFrameSelection)
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
|
|
|
|
nsIPresShell *presShell = mFrameSelection->GetShell();
|
|
|
|
|
2000-03-22 02:58:02 +03:00
|
|
|
PRInt32 frameOffset = 0;
|
|
|
|
*aReturnFrame = 0;
|
2003-04-18 01:08:44 +04:00
|
|
|
if (!aOffsetUsed)
|
|
|
|
aOffsetUsed = &frameOffset;
|
2006-04-26 06:01:07 +04:00
|
|
|
|
|
|
|
nsFrameSelection::HINT hint = mFrameSelection->GetHint();
|
2000-03-22 02:58:02 +03:00
|
|
|
|
2006-08-30 13:26:39 +04:00
|
|
|
if (aVisual) {
|
|
|
|
nsCOMPtr<nsICaret> caret;
|
|
|
|
nsresult result = presShell->GetCaret(getter_AddRefs(caret));
|
|
|
|
if (NS_FAILED(result) || !caret)
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
|
|
|
|
PRUint8 caretBidiLevel = mFrameSelection->GetCaretBidiLevel();
|
2005-11-16 12:37:01 +03:00
|
|
|
|
2006-08-30 13:26:39 +04:00
|
|
|
return caret->GetCaretFrameForNodeOffset(content, FetchFocusOffset(),
|
|
|
|
hint, caretBidiLevel, aReturnFrame, aOffsetUsed);
|
|
|
|
}
|
|
|
|
|
|
|
|
*aReturnFrame = mFrameSelection->
|
|
|
|
GetFrameForNodeOffset(content, FetchFocusOffset(),
|
|
|
|
hint, aOffsetUsed);
|
|
|
|
if (!*aReturnFrame)
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
|
|
|
|
return NS_OK;
|
2000-03-22 02:58:02 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//select all content children of aContent
|
|
|
|
NS_IMETHODIMP
|
2004-08-01 03:15:21 +04:00
|
|
|
nsTypedSelection::selectFrames(nsPresContext* aPresContext,
|
2000-03-22 02:58:02 +03:00
|
|
|
nsIContentIterator *aInnerIter,
|
|
|
|
nsIContent *aContent,
|
|
|
|
nsIDOMRange *aRange,
|
2000-03-31 11:17:22 +04:00
|
|
|
nsIPresShell *aPresShell,
|
2000-03-22 02:58:02 +03:00
|
|
|
PRBool aFlags)
|
|
|
|
{
|
2000-05-11 08:25:43 +04:00
|
|
|
if (!mFrameSelection)
|
|
|
|
return NS_OK;//nothing to do
|
2000-03-31 11:17:22 +04:00
|
|
|
nsresult result;
|
2000-10-14 02:37:52 +04:00
|
|
|
if (!aInnerIter)
|
|
|
|
return NS_ERROR_NULL_POINTER;
|
2006-10-26 00:24:00 +04:00
|
|
|
result = aInnerIter->Init(aContent);
|
2000-03-22 02:58:02 +03:00
|
|
|
nsIFrame *frame;
|
|
|
|
if (NS_SUCCEEDED(result))
|
|
|
|
{
|
|
|
|
// First select frame of content passed in
|
2005-08-23 02:24:29 +04:00
|
|
|
frame = mFrameSelection->GetShell()->GetPrimaryFrameFor(aContent);
|
|
|
|
if (frame)
|
2001-05-04 03:59:55 +04:00
|
|
|
{
|
|
|
|
//NOTE: eSpreadDown is now IGNORED. Selected state is set only for given frame
|
2001-04-18 03:31:34 +04:00
|
|
|
frame->SetSelected(aPresContext, nsnull, aFlags, eSpreadDown);
|
2001-05-04 03:59:55 +04:00
|
|
|
#ifndef OLD_TABLE_SELECTION
|
2006-04-26 06:01:07 +04:00
|
|
|
if (mFrameSelection->GetTableCellSelection())
|
2001-05-04 03:59:55 +04:00
|
|
|
{
|
2002-12-11 17:24:49 +03:00
|
|
|
nsITableCellLayout *tcl = nsnull;
|
|
|
|
CallQueryInterface(frame, &tcl);
|
|
|
|
if (tcl)
|
2001-05-04 03:59:55 +04:00
|
|
|
{
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif //OLD_TABLE_SELECTION
|
|
|
|
}
|
2000-03-22 02:58:02 +03:00
|
|
|
// Now iterated through the child frames and set them
|
2004-01-24 03:46:17 +03:00
|
|
|
while (!aInnerIter->IsDone())
|
2000-03-22 02:58:02 +03:00
|
|
|
{
|
2004-01-24 03:46:17 +03:00
|
|
|
nsIContent *innercontent = aInnerIter->GetCurrentNode();
|
|
|
|
|
2005-08-23 02:24:29 +04:00
|
|
|
frame = mFrameSelection->GetShell()->GetPrimaryFrameFor(innercontent);
|
|
|
|
if (frame)
|
2000-09-13 04:05:29 +04:00
|
|
|
{
|
2004-01-24 03:46:17 +03:00
|
|
|
//NOTE: eSpreadDown is now IGNORED. Selected state is set only
|
|
|
|
//for given frame
|
|
|
|
|
|
|
|
//spread from here to hit all frames in flow
|
|
|
|
frame->SetSelected(aPresContext, nsnull,aFlags,eSpreadDown);
|
|
|
|
nsRect frameRect = frame->GetRect();
|
|
|
|
|
|
|
|
//if a rect is 0 height/width then try to notify next
|
|
|
|
//available in flow of selection status.
|
|
|
|
while (!frameRect.width || !frameRect.height)
|
2002-08-07 21:47:28 +04:00
|
|
|
{
|
2004-01-24 03:46:17 +03:00
|
|
|
//try to notify next in flow that its content is selected.
|
2004-09-14 06:28:03 +04:00
|
|
|
frame = frame->GetNextInFlow();
|
|
|
|
if (frame)
|
2002-08-07 03:56:50 +04:00
|
|
|
{
|
2004-01-24 03:46:17 +03:00
|
|
|
frameRect = frame->GetRect();
|
|
|
|
frame->SetSelected(aPresContext, nsnull,aFlags,eSpreadDown);
|
2002-08-07 03:56:50 +04:00
|
|
|
}
|
2004-01-24 03:46:17 +03:00
|
|
|
else
|
|
|
|
break;
|
2002-08-07 21:47:28 +04:00
|
|
|
}
|
2004-01-24 03:46:17 +03:00
|
|
|
//if the frame is splittable and this frame is 0,0 then set
|
|
|
|
//the next in flow frame to be selected also
|
2000-09-13 04:05:29 +04:00
|
|
|
}
|
2004-01-24 03:46:17 +03:00
|
|
|
|
|
|
|
aInnerIter->Next();
|
2000-03-22 02:58:02 +03:00
|
|
|
}
|
2004-01-24 03:46:17 +03:00
|
|
|
|
2000-03-22 02:58:02 +03:00
|
|
|
#if 0
|
2005-08-23 02:24:29 +04:00
|
|
|
frame = mFrameSelection->GetShell()->GetPrimaryFrameFor(content);
|
|
|
|
if (frame)
|
2000-03-22 02:58:02 +03:00
|
|
|
frame->SetSelected(aRange,aFlags,eSpreadDown);//spread from here to hit all frames in flow
|
|
|
|
#endif
|
2004-01-24 03:46:17 +03:00
|
|
|
|
2000-03-22 02:58:02 +03:00
|
|
|
return NS_OK;
|
|
|
|
}
|
2004-01-24 03:46:17 +03:00
|
|
|
|
2000-03-22 02:58:02 +03:00
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//the idea of this helper method is to select, deselect "top to bottom" traversing through the frames
|
|
|
|
NS_IMETHODIMP
|
2004-08-01 03:15:21 +04:00
|
|
|
nsTypedSelection::selectFrames(nsPresContext* aPresContext, nsIDOMRange *aRange, PRBool aFlags)
|
2000-03-22 02:58:02 +03:00
|
|
|
{
|
2000-05-11 08:25:43 +04:00
|
|
|
if (!mFrameSelection)
|
|
|
|
return NS_OK;//nothing to do
|
2000-03-31 11:17:22 +04:00
|
|
|
if (!aRange || !aPresContext)
|
2000-03-22 02:58:02 +03:00
|
|
|
return NS_ERROR_NULL_POINTER;
|
2002-12-11 17:24:49 +03:00
|
|
|
|
|
|
|
nsresult result;
|
|
|
|
nsCOMPtr<nsIContentIterator> iter = do_CreateInstance(
|
2000-10-14 02:37:52 +04:00
|
|
|
kCSubtreeIteratorCID,
|
2002-12-11 17:24:49 +03:00
|
|
|
&result);
|
2000-03-22 02:58:02 +03:00
|
|
|
if (NS_FAILED(result))
|
|
|
|
return result;
|
2002-12-11 17:24:49 +03:00
|
|
|
|
|
|
|
nsCOMPtr<nsIContentIterator> inneriter = do_CreateInstance(
|
2000-10-14 02:37:52 +04:00
|
|
|
kCContentIteratorCID,
|
2002-12-11 17:24:49 +03:00
|
|
|
&result);
|
2000-03-31 11:17:22 +04:00
|
|
|
|
2000-03-22 02:58:02 +03:00
|
|
|
if ((NS_SUCCEEDED(result)) && iter && inneriter)
|
|
|
|
{
|
2003-12-21 08:36:36 +03:00
|
|
|
nsIPresShell *presShell = aPresContext->GetPresShell();
|
2006-10-26 00:24:00 +04:00
|
|
|
result = iter->Init(aRange);
|
2000-04-02 09:05:31 +04:00
|
|
|
|
2000-03-22 02:58:02 +03:00
|
|
|
// loop through the content iterator for each content node
|
|
|
|
// for each text node:
|
|
|
|
// get the frame for the content, and from it the style context
|
|
|
|
// ask the style context about the property
|
|
|
|
nsCOMPtr<nsIContent> content;
|
|
|
|
nsIFrame *frame;
|
|
|
|
//we must call first one explicitly
|
|
|
|
content = do_QueryInterface(FetchStartParent(aRange), &result);
|
|
|
|
if (NS_FAILED(result) || !content)
|
|
|
|
return result;
|
2003-09-27 08:18:26 +04:00
|
|
|
|
2006-05-05 10:52:21 +04:00
|
|
|
if (!content->IsNodeOfType(nsINode::eELEMENT))
|
2000-03-22 02:58:02 +03:00
|
|
|
{
|
2005-08-23 02:24:29 +04:00
|
|
|
frame = mFrameSelection->GetShell()->GetPrimaryFrameFor(content);
|
|
|
|
if (frame)
|
2000-03-22 02:58:02 +03:00
|
|
|
frame->SetSelected(aPresContext, aRange,aFlags,eSpreadDown);//spread from here to hit all frames in flow
|
|
|
|
}
|
|
|
|
//end start content
|
2004-01-24 03:46:17 +03:00
|
|
|
iter->First();
|
|
|
|
|
|
|
|
while (!iter->IsDone())
|
2000-03-22 02:58:02 +03:00
|
|
|
{
|
2004-01-24 03:46:17 +03:00
|
|
|
content = iter->GetCurrentNode();
|
|
|
|
|
2000-03-31 11:17:22 +04:00
|
|
|
selectFrames(aPresContext, inneriter, content, aRange, presShell,aFlags);
|
2004-01-24 03:46:17 +03:00
|
|
|
|
|
|
|
iter->Next();
|
2000-03-22 02:58:02 +03:00
|
|
|
}
|
|
|
|
//we must now do the last one if it is not the same as the first
|
|
|
|
if (FetchEndParent(aRange) != FetchStartParent(aRange))
|
|
|
|
{
|
|
|
|
content = do_QueryInterface(FetchEndParent(aRange), &result);
|
|
|
|
if (NS_FAILED(result) || !content)
|
|
|
|
return result;
|
2003-09-27 08:18:26 +04:00
|
|
|
|
2006-05-05 10:52:21 +04:00
|
|
|
if (!content->IsNodeOfType(nsINode::eELEMENT))
|
2000-03-22 02:58:02 +03:00
|
|
|
{
|
2005-08-23 02:24:29 +04:00
|
|
|
frame = mFrameSelection->GetShell()->GetPrimaryFrameFor(content);
|
|
|
|
if (frame)
|
2000-03-22 02:58:02 +03:00
|
|
|
frame->SetSelected(aPresContext, aRange,aFlags,eSpreadDown);//spread from here to hit all frames in flow
|
|
|
|
}
|
|
|
|
}
|
|
|
|
//end end parent
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2006-07-27 21:57:15 +04:00
|
|
|
// nsTypedSelection::LookUpSelection
|
|
|
|
//
|
|
|
|
// This function is called when a node wants to know where the selection is
|
|
|
|
// over itself.
|
|
|
|
//
|
|
|
|
// Usually, this is called when we already know there is a selection over
|
|
|
|
// the node in question, and we only need to find the boundaries of it on
|
|
|
|
// that node. This is when slowCheck is false--a strict test is not needed.
|
|
|
|
// Other times, the caller has no idea, and wants us to test everything,
|
|
|
|
// so we are supposed to determine whether there is a selection over the
|
|
|
|
// node at all.
|
|
|
|
//
|
|
|
|
// A previous version of this code used this flag to do less work when
|
|
|
|
// inclusion was already known (slowCheck=false). However, our tree
|
|
|
|
// structure allows us to quickly determine ranges overlapping the node,
|
|
|
|
// so we just ignore the slowCheck flag and do the full test every time.
|
|
|
|
//
|
|
|
|
// PERFORMANCE: a common case is that we are doing a fast check with exactly
|
|
|
|
// one range in the selection. In this case, this function is slower than
|
|
|
|
// brute force because of the overhead of checking the tree. We can optimize
|
|
|
|
// this case to make it faster by doing the same thing the previous version
|
|
|
|
// of this function did in the case of 1 range. This would also mean that
|
|
|
|
// the aSlowCheck flag would have meaning again.
|
2000-03-22 02:58:02 +03:00
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2006-07-27 21:57:15 +04:00
|
|
|
nsTypedSelection::LookUpSelection(nsIContent *aContent, PRInt32 aContentOffset,
|
|
|
|
PRInt32 aContentLength,
|
|
|
|
SelectionDetails **aReturnDetails,
|
|
|
|
SelectionType aType, PRBool aSlowCheck)
|
2000-03-22 02:58:02 +03:00
|
|
|
{
|
2006-07-27 21:57:15 +04:00
|
|
|
nsresult rv;
|
|
|
|
if (! aContent || ! aReturnDetails)
|
|
|
|
return NS_ERROR_NULL_POINTER;
|
2000-03-22 02:58:02 +03:00
|
|
|
|
2006-07-27 21:57:15 +04:00
|
|
|
// it is common to have no ranges, to optimize that
|
|
|
|
if (mRanges.Length() == 0)
|
|
|
|
return NS_OK;
|
2000-03-22 02:58:02 +03:00
|
|
|
|
2006-07-27 21:57:15 +04:00
|
|
|
nsCOMPtr<nsIDOMNode> node = do_QueryInterface(aContent, &rv);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2000-03-22 02:58:02 +03:00
|
|
|
|
2006-07-27 21:57:15 +04:00
|
|
|
nsCOMArray<nsIDOMRange> overlappingRanges;
|
|
|
|
rv = GetRangesForIntervalCOMArray(node, aContentOffset,
|
|
|
|
node, aContentOffset + aContentLength,
|
|
|
|
PR_FALSE,
|
|
|
|
&overlappingRanges);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
if (overlappingRanges.Count() == 0)
|
|
|
|
return NS_OK;
|
|
|
|
|
|
|
|
for (PRInt32 i = 0; i < overlappingRanges.Count(); i ++) {
|
|
|
|
nsCOMPtr<nsIDOMNode> startNode, endNode;
|
|
|
|
PRInt32 startOffset, endOffset;
|
|
|
|
nsIDOMRange* range = overlappingRanges[i];
|
|
|
|
range->GetStartContainer(getter_AddRefs(startNode));
|
|
|
|
range->GetStartOffset(&startOffset);
|
|
|
|
range->GetEndContainer(getter_AddRefs(endNode));
|
|
|
|
range->GetEndOffset(&endOffset);
|
|
|
|
|
|
|
|
PRInt32 start = -1, end = -1;
|
|
|
|
if (startNode == node && endNode == node) {
|
|
|
|
if (startOffset < (aContentOffset + aContentLength) &&
|
|
|
|
endOffset > aContentOffset) {
|
|
|
|
// this range is totally inside the requested content range
|
|
|
|
start = PR_MAX(0, startOffset - aContentOffset);
|
|
|
|
end = PR_MIN(aContentLength, endOffset - aContentOffset);
|
2000-03-22 02:58:02 +03:00
|
|
|
}
|
2006-07-27 21:57:15 +04:00
|
|
|
// otherwise, range is inside the requested node, but does not intersect
|
|
|
|
// the requested content range, so ignore it
|
|
|
|
} else if (startNode == node) {
|
|
|
|
if (startOffset < (aContentOffset + aContentLength)) {
|
|
|
|
// the beginning of the range is inside the requested node, but the
|
|
|
|
// end is outside, select everything from there to the end
|
|
|
|
start = PR_MAX(0, startOffset - aContentOffset);
|
|
|
|
end = aContentLength;
|
2000-03-22 02:58:02 +03:00
|
|
|
}
|
2006-07-27 21:57:15 +04:00
|
|
|
} else if (endNode == node) {
|
|
|
|
if (endOffset > aContentOffset) {
|
|
|
|
// the end of the range is inside the requested node, but the beginning
|
|
|
|
// is outside, select everything from the beginning to there
|
|
|
|
start = 0;
|
|
|
|
end = PR_MIN(aContentLength, endOffset - aContentOffset);
|
2000-03-22 02:58:02 +03:00
|
|
|
}
|
2006-07-27 21:57:15 +04:00
|
|
|
} else {
|
|
|
|
// this range does not begin or end in the requested node, but since
|
|
|
|
// GetRangesForInterval returned this range, we know it overlaps.
|
|
|
|
// Therefore, this node is enclosed in the range, and we select all
|
|
|
|
// of it.
|
|
|
|
start = 0;
|
|
|
|
end = aContentLength;
|
2000-03-22 02:58:02 +03:00
|
|
|
}
|
2006-07-27 21:57:15 +04:00
|
|
|
if (start < 0)
|
|
|
|
continue; // the ranges do not overlap the input range
|
|
|
|
|
|
|
|
SelectionDetails* details = new SelectionDetails;
|
|
|
|
if (! details)
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
|
|
|
|
details->mNext = *aReturnDetails;
|
|
|
|
details->mStart = start;
|
|
|
|
details->mEnd = end;
|
|
|
|
details->mType = aType;
|
2000-03-22 02:58:02 +03:00
|
|
|
*aReturnDetails = details;
|
2006-07-27 21:57:15 +04:00
|
|
|
}
|
2000-03-22 02:58:02 +03:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2004-08-01 03:15:21 +04:00
|
|
|
nsTypedSelection::Repaint(nsPresContext* aPresContext)
|
2000-03-22 02:58:02 +03:00
|
|
|
{
|
2006-07-27 21:57:15 +04:00
|
|
|
PRInt32 arrCount = (PRInt32)mRanges.Length();
|
2000-03-22 02:58:02 +03:00
|
|
|
|
|
|
|
if (arrCount < 1)
|
|
|
|
return NS_OK;
|
|
|
|
|
2002-12-11 03:02:49 +03:00
|
|
|
PRInt32 i;
|
|
|
|
nsIDOMRange* range;
|
|
|
|
|
2000-03-22 02:58:02 +03:00
|
|
|
for (i = 0; i < arrCount; i++)
|
|
|
|
{
|
2006-07-27 21:57:15 +04:00
|
|
|
range = mRanges[i].mRange;
|
2000-03-22 02:58:02 +03:00
|
|
|
|
|
|
|
if (!range)
|
2002-12-11 03:02:49 +03:00
|
|
|
return NS_ERROR_UNEXPECTED;
|
2000-03-22 02:58:02 +03:00
|
|
|
|
2002-12-11 03:02:49 +03:00
|
|
|
nsresult rv = selectFrames(aPresContext, range, PR_TRUE);
|
2000-03-22 02:58:02 +03:00
|
|
|
|
2002-12-11 03:02:49 +03:00
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
return rv;
|
|
|
|
}
|
2000-03-22 02:58:02 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2003-04-20 05:03:40 +04:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsTypedSelection::GetCanCacheFrameOffset(PRBool *aCanCacheFrameOffset)
|
|
|
|
{
|
|
|
|
NS_ENSURE_ARG_POINTER(aCanCacheFrameOffset);
|
|
|
|
|
|
|
|
if (mCachedOffsetForFrame)
|
|
|
|
*aCanCacheFrameOffset = mCachedOffsetForFrame->mCanCacheFrameOffset;
|
|
|
|
else
|
|
|
|
*aCanCacheFrameOffset = PR_FALSE;
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsTypedSelection::SetCanCacheFrameOffset(PRBool aCanCacheFrameOffset)
|
|
|
|
{
|
|
|
|
if (!mCachedOffsetForFrame) {
|
|
|
|
mCachedOffsetForFrame = new CachedOffsetForFrame;
|
|
|
|
}
|
|
|
|
|
|
|
|
mCachedOffsetForFrame->mCanCacheFrameOffset = aCanCacheFrameOffset;
|
|
|
|
|
2003-06-11 07:29:59 +04:00
|
|
|
// clean up cached frame when turn off cache
|
|
|
|
// fix bug 207936
|
|
|
|
if (!aCanCacheFrameOffset) {
|
|
|
|
mCachedOffsetForFrame->mLastCaretFrame = nsnull;
|
|
|
|
}
|
|
|
|
|
2003-04-20 05:03:40 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsTypedSelection::GetCachedFrameOffset(nsIFrame *aFrame, PRInt32 inOffset, nsPoint& aPoint)
|
|
|
|
{
|
|
|
|
if (!mCachedOffsetForFrame) {
|
|
|
|
mCachedOffsetForFrame = new CachedOffsetForFrame;
|
|
|
|
}
|
|
|
|
|
2006-04-28 08:33:41 +04:00
|
|
|
nsresult rv = NS_OK;
|
2003-06-11 07:29:59 +04:00
|
|
|
if (mCachedOffsetForFrame->mCanCacheFrameOffset &&
|
|
|
|
mCachedOffsetForFrame->mLastCaretFrame &&
|
2003-04-20 05:03:40 +04:00
|
|
|
(aFrame == mCachedOffsetForFrame->mLastCaretFrame) &&
|
|
|
|
(inOffset == mCachedOffsetForFrame->mLastContentOffset))
|
|
|
|
{
|
|
|
|
// get cached frame offset
|
|
|
|
aPoint = mCachedOffsetForFrame->mCachedFrameOffset;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2006-04-25 01:18:44 +04:00
|
|
|
// Recalculate frame offset and cache it. Don't cache a frame offset if
|
|
|
|
// GetPointFromOffset fails, though.
|
2006-04-28 08:33:41 +04:00
|
|
|
rv = GetPointFromOffset(aFrame, inOffset, &aPoint);
|
2006-04-25 01:18:44 +04:00
|
|
|
if (NS_SUCCEEDED(rv) && mCachedOffsetForFrame->mCanCacheFrameOffset) {
|
2003-04-20 05:03:40 +04:00
|
|
|
mCachedOffsetForFrame->mCachedFrameOffset = aPoint;
|
|
|
|
mCachedOffsetForFrame->mLastCaretFrame = aFrame;
|
|
|
|
mCachedOffsetForFrame->mLastContentOffset = inOffset;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-04-28 08:33:41 +04:00
|
|
|
return rv;
|
2003-04-20 05:03:40 +04:00
|
|
|
}
|
|
|
|
|
2005-08-24 21:44:28 +04:00
|
|
|
NS_IMETHODIMP
|
2006-04-26 06:01:07 +04:00
|
|
|
nsTypedSelection::GetFrameSelection(nsFrameSelection **aFrameSelection) {
|
2005-08-24 21:44:28 +04:00
|
|
|
NS_ENSURE_ARG_POINTER(aFrameSelection);
|
|
|
|
*aFrameSelection = mFrameSelection;
|
2007-03-23 03:06:38 +03:00
|
|
|
NS_IF_ADDREF(*aFrameSelection);
|
2005-08-24 21:44:28 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2000-03-22 02:58:02 +03:00
|
|
|
nsresult
|
2006-06-16 05:54:31 +04:00
|
|
|
nsTypedSelection::StartAutoScrollTimer(nsPresContext *aPresContext,
|
|
|
|
nsIView *aView,
|
|
|
|
nsPoint& aPoint,
|
|
|
|
PRUint32 aDelay)
|
2000-03-22 02:58:02 +03:00
|
|
|
{
|
2006-06-16 05:54:31 +04:00
|
|
|
NS_PRECONDITION(aView, "Need a view");
|
|
|
|
|
2000-03-22 02:58:02 +03:00
|
|
|
nsresult result;
|
2000-05-11 08:25:43 +04:00
|
|
|
if (!mFrameSelection)
|
|
|
|
return NS_OK;//nothing to do
|
2000-03-22 02:58:02 +03:00
|
|
|
|
|
|
|
if (!mAutoScrollTimer)
|
|
|
|
{
|
2006-06-16 05:54:31 +04:00
|
|
|
mAutoScrollTimer = new nsAutoScrollTimer();
|
2000-03-22 02:58:02 +03:00
|
|
|
|
|
|
|
if (!mAutoScrollTimer)
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
|
|
|
|
result = mAutoScrollTimer->Init(mFrameSelection, this);
|
|
|
|
|
|
|
|
if (NS_FAILED(result))
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
result = mAutoScrollTimer->SetDelay(aDelay);
|
|
|
|
|
|
|
|
if (NS_FAILED(result))
|
|
|
|
return result;
|
|
|
|
|
2004-07-20 04:02:43 +04:00
|
|
|
return DoAutoScrollView(aPresContext, aView, aPoint, PR_TRUE);
|
2000-03-22 02:58:02 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
2000-11-29 03:13:00 +03:00
|
|
|
nsTypedSelection::StopAutoScrollTimer()
|
2000-03-22 02:58:02 +03:00
|
|
|
{
|
|
|
|
if (mAutoScrollTimer)
|
|
|
|
return mAutoScrollTimer->Stop();
|
|
|
|
|
2000-04-12 07:04:11 +04:00
|
|
|
return NS_OK;
|
2000-03-22 02:58:02 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
2000-11-29 03:13:00 +03:00
|
|
|
nsTypedSelection::GetViewAncestorOffset(nsIView *aView, nsIView *aAncestorView, nscoord *aXOffset, nscoord *aYOffset)
|
2000-08-30 23:42:47 +04:00
|
|
|
{
|
|
|
|
// Note: A NULL aAncestorView pointer means that the caller wants
|
|
|
|
// the view's global offset.
|
|
|
|
|
|
|
|
if (!aView || !aXOffset || !aYOffset)
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
|
2004-11-03 19:16:57 +03:00
|
|
|
nsPoint offset = aView->GetOffsetTo(aAncestorView);
|
2000-08-30 23:42:47 +04:00
|
|
|
|
2004-11-03 19:16:57 +03:00
|
|
|
*aXOffset = offset.x;
|
|
|
|
*aYOffset = offset.y;
|
2000-08-30 23:42:47 +04:00
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
2004-08-01 03:15:21 +04:00
|
|
|
nsTypedSelection::ScrollPointIntoClipView(nsPresContext *aPresContext, nsIView *aView, nsPoint& aPoint, PRBool *aDidScroll)
|
2000-03-22 02:58:02 +03:00
|
|
|
{
|
|
|
|
nsresult result;
|
|
|
|
|
2000-08-30 23:42:47 +04:00
|
|
|
if (!aPresContext || !aView || !aDidScroll)
|
2000-03-22 02:58:02 +03:00
|
|
|
return NS_ERROR_NULL_POINTER;
|
|
|
|
|
2000-08-30 23:42:47 +04:00
|
|
|
*aDidScroll = PR_FALSE;
|
2000-03-22 02:58:02 +03:00
|
|
|
|
|
|
|
//
|
2000-08-30 23:42:47 +04:00
|
|
|
// Get aView's scrollable view.
|
2000-03-22 02:58:02 +03:00
|
|
|
//
|
|
|
|
|
2004-09-21 08:41:08 +04:00
|
|
|
nsIScrollableView *scrollableView =
|
|
|
|
nsLayoutUtils::GetNearestScrollingView(aView, nsLayoutUtils::eEither);
|
2000-08-30 23:42:47 +04:00
|
|
|
|
|
|
|
if (!scrollableView)
|
|
|
|
return NS_OK; // Nothing to do!
|
|
|
|
|
|
|
|
//
|
|
|
|
// Get the view that is being scrolled.
|
|
|
|
//
|
|
|
|
|
|
|
|
nsIView *scrolledView = 0;
|
|
|
|
|
|
|
|
result = scrollableView->GetScrolledView(scrolledView);
|
|
|
|
|
|
|
|
//
|
|
|
|
// Now walk up aView's hierarchy, this time keeping track of
|
|
|
|
// the view offsets until you hit the scrolledView.
|
|
|
|
//
|
|
|
|
|
|
|
|
nsPoint viewOffset(0,0);
|
|
|
|
|
|
|
|
result = GetViewAncestorOffset(aView, scrolledView, &viewOffset.x, &viewOffset.y);
|
|
|
|
|
|
|
|
if (NS_FAILED(result))
|
|
|
|
return result;
|
|
|
|
|
|
|
|
//
|
|
|
|
// See if aPoint is outside the clip view's boundaries.
|
|
|
|
// If it is, scroll the view till it is inside the visible area!
|
|
|
|
//
|
|
|
|
|
2004-09-21 02:25:07 +04:00
|
|
|
nsRect bounds = scrollableView->View()->GetBounds();
|
2000-08-30 23:42:47 +04:00
|
|
|
|
|
|
|
result = scrollableView->GetScrollPosition(bounds.x,bounds.y);
|
|
|
|
|
|
|
|
if (NS_FAILED(result))
|
|
|
|
return result;
|
|
|
|
|
|
|
|
//
|
|
|
|
// Calculate the amount we would have to scroll in
|
|
|
|
// the vertical and horizontal directions to get the point
|
|
|
|
// within the clip area.
|
|
|
|
//
|
|
|
|
|
|
|
|
nscoord dx = 0, dy = 0;
|
|
|
|
|
2004-09-21 08:41:08 +04:00
|
|
|
nsPresContext::ScrollbarStyles ss =
|
|
|
|
nsLayoutUtils::ScrollbarStylesOfView(scrollableView);
|
|
|
|
|
|
|
|
if (ss.mHorizontal != NS_STYLE_OVERFLOW_HIDDEN) {
|
|
|
|
nscoord e = aPoint.x + viewOffset.x;
|
2000-08-30 23:42:47 +04:00
|
|
|
|
2004-09-21 08:41:08 +04:00
|
|
|
nscoord x1 = bounds.x;
|
|
|
|
nscoord x2 = bounds.x + bounds.width;
|
|
|
|
|
|
|
|
if (e < x1)
|
|
|
|
dx = e - x1;
|
|
|
|
else if (e > x2)
|
|
|
|
dx = e - x2;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (ss.mVertical != NS_STYLE_OVERFLOW_HIDDEN) {
|
|
|
|
nscoord e = aPoint.y + viewOffset.y;
|
|
|
|
|
|
|
|
nscoord y1 = bounds.y;
|
|
|
|
nscoord y2 = bounds.y + bounds.height;
|
|
|
|
|
|
|
|
if (e < y1)
|
|
|
|
dy = e - y1;
|
|
|
|
else if (e > y2)
|
|
|
|
dy = e - y2;
|
|
|
|
}
|
2000-08-30 23:42:47 +04:00
|
|
|
|
|
|
|
//
|
2006-03-23 03:13:07 +03:00
|
|
|
// Now scroll the view if necessary.
|
2000-08-30 23:42:47 +04:00
|
|
|
//
|
|
|
|
|
2006-03-23 03:13:07 +03:00
|
|
|
if (dx != 0 || dy != 0)
|
2000-03-22 02:58:02 +03:00
|
|
|
{
|
2006-03-23 03:13:07 +03:00
|
|
|
// Make sure latest bits are available before we scroll them.
|
|
|
|
aPresContext->GetViewManager()->Composite();
|
2000-03-22 02:58:02 +03:00
|
|
|
|
2006-03-23 03:13:07 +03:00
|
|
|
// Now scroll the view!
|
2000-03-22 02:58:02 +03:00
|
|
|
|
2006-03-23 03:13:07 +03:00
|
|
|
result = scrollableView->ScrollTo(bounds.x + dx, bounds.y + dy,
|
|
|
|
NS_VMREFRESH_NO_SYNC);
|
2000-03-22 02:58:02 +03:00
|
|
|
|
2006-03-23 03:13:07 +03:00
|
|
|
if (NS_FAILED(result))
|
|
|
|
return result;
|
2000-08-30 23:42:47 +04:00
|
|
|
|
2006-03-23 03:13:07 +03:00
|
|
|
nsPoint newPos;
|
2000-08-30 23:42:47 +04:00
|
|
|
|
2006-03-23 03:13:07 +03:00
|
|
|
result = scrollableView->GetScrollPosition(newPos.x, newPos.y);
|
2000-08-30 23:42:47 +04:00
|
|
|
|
2006-03-23 03:13:07 +03:00
|
|
|
if (NS_FAILED(result))
|
|
|
|
return result;
|
2000-08-30 23:42:47 +04:00
|
|
|
|
2006-03-23 03:13:07 +03:00
|
|
|
*aDidScroll = (bounds.x != newPos.x || bounds.y != newPos.y);
|
2000-08-30 23:42:47 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
2000-03-22 02:58:02 +03:00
|
|
|
|
2000-08-30 23:42:47 +04:00
|
|
|
nsresult
|
2004-08-01 03:15:21 +04:00
|
|
|
nsTypedSelection::ScrollPointIntoView(nsPresContext *aPresContext, nsIView *aView, nsPoint& aPoint, PRBool aScrollParentViews, PRBool *aDidScroll)
|
2000-08-30 23:42:47 +04:00
|
|
|
{
|
|
|
|
if (!aPresContext || !aView || !aDidScroll)
|
|
|
|
return NS_ERROR_NULL_POINTER;
|
|
|
|
|
|
|
|
nsresult result;
|
|
|
|
|
|
|
|
*aDidScroll = PR_FALSE;
|
|
|
|
|
|
|
|
//
|
|
|
|
// Calculate the global offset of the view.
|
|
|
|
//
|
|
|
|
|
|
|
|
nsPoint globalOffset;
|
|
|
|
|
|
|
|
result = GetViewAncestorOffset(aView, nsnull, &globalOffset.x, &globalOffset.y);
|
|
|
|
|
|
|
|
if (NS_FAILED(result))
|
|
|
|
return result;
|
|
|
|
|
|
|
|
//
|
|
|
|
// Convert aPoint into global coordinates so it is easier to map
|
|
|
|
// into other views.
|
|
|
|
//
|
|
|
|
|
|
|
|
nsPoint globalPoint = aPoint + globalOffset;
|
|
|
|
|
|
|
|
//
|
|
|
|
// Scroll the point into the visible rect of the closest
|
|
|
|
// scrollable view.
|
|
|
|
//
|
|
|
|
result = ScrollPointIntoClipView(aPresContext, aView, aPoint, aDidScroll);
|
|
|
|
|
|
|
|
if (NS_FAILED(result))
|
|
|
|
return result;
|
|
|
|
|
|
|
|
//
|
|
|
|
// Now scroll the parent scrollable views.
|
|
|
|
//
|
|
|
|
|
|
|
|
if (aScrollParentViews)
|
|
|
|
{
|
|
|
|
//
|
|
|
|
// Find aView's parent scrollable view.
|
|
|
|
//
|
|
|
|
|
2004-09-21 08:41:08 +04:00
|
|
|
nsIScrollableView *scrollableView =
|
|
|
|
nsLayoutUtils::GetNearestScrollingView(aView, nsLayoutUtils::eEither);
|
2000-08-30 23:42:47 +04:00
|
|
|
|
|
|
|
if (scrollableView)
|
|
|
|
{
|
|
|
|
//
|
|
|
|
// Convert scrollableView to nsIView.
|
|
|
|
//
|
|
|
|
|
|
|
|
nsIView *scrolledView = 0;
|
2004-09-21 02:25:07 +04:00
|
|
|
nsIView *view = scrollableView->View();
|
2000-08-30 23:42:47 +04:00
|
|
|
|
|
|
|
if (view)
|
2000-03-22 02:58:02 +03:00
|
|
|
{
|
|
|
|
//
|
2000-08-30 23:42:47 +04:00
|
|
|
// Now get the scrollableView's parent, then search for it's
|
|
|
|
// closest scrollable view.
|
2000-03-22 02:58:02 +03:00
|
|
|
//
|
|
|
|
|
2003-08-06 07:07:12 +04:00
|
|
|
view = view->GetParent();
|
2000-08-30 23:42:47 +04:00
|
|
|
|
|
|
|
while (view)
|
2000-03-22 02:58:02 +03:00
|
|
|
{
|
2004-09-21 08:41:08 +04:00
|
|
|
scrollableView =
|
|
|
|
nsLayoutUtils::GetNearestScrollingView(view,
|
|
|
|
nsLayoutUtils::eEither);
|
2000-08-30 23:42:47 +04:00
|
|
|
|
|
|
|
if (!scrollableView)
|
|
|
|
break;
|
|
|
|
|
|
|
|
scrolledView = 0;
|
|
|
|
result = scrollableView->GetScrolledView(scrolledView);
|
|
|
|
|
|
|
|
if (NS_FAILED(result))
|
|
|
|
return result;
|
2000-03-22 02:58:02 +03:00
|
|
|
|
|
|
|
//
|
2000-08-30 23:42:47 +04:00
|
|
|
// Map the global point into this scrolledView's coordinate space.
|
2000-03-22 02:58:02 +03:00
|
|
|
//
|
|
|
|
|
2000-08-30 23:42:47 +04:00
|
|
|
result = GetViewAncestorOffset(scrolledView, nsnull, &globalOffset.x, &globalOffset.y);
|
2000-03-22 02:58:02 +03:00
|
|
|
|
2000-08-30 23:42:47 +04:00
|
|
|
if (NS_FAILED(result))
|
|
|
|
return result;
|
2000-03-22 02:58:02 +03:00
|
|
|
|
2000-08-30 23:42:47 +04:00
|
|
|
nsPoint newPoint = globalPoint - globalOffset;
|
2000-03-22 02:58:02 +03:00
|
|
|
|
2000-08-30 23:42:47 +04:00
|
|
|
//
|
|
|
|
// Scroll the point into the visible rect of the scrolled view.
|
|
|
|
//
|
2000-03-22 02:58:02 +03:00
|
|
|
|
2000-08-30 23:42:47 +04:00
|
|
|
PRBool parentDidScroll = PR_FALSE;
|
2000-03-22 02:58:02 +03:00
|
|
|
|
2000-08-30 23:42:47 +04:00
|
|
|
result = ScrollPointIntoClipView(aPresContext, scrolledView, newPoint, &parentDidScroll);
|
2000-03-22 02:58:02 +03:00
|
|
|
|
2000-08-30 23:42:47 +04:00
|
|
|
if (NS_FAILED(result))
|
|
|
|
return result;
|
2000-03-22 02:58:02 +03:00
|
|
|
|
2000-08-30 23:42:47 +04:00
|
|
|
*aDidScroll = *aDidScroll || parentDidScroll;
|
|
|
|
|
|
|
|
//
|
|
|
|
// Now get the parent of this scrollable view so we
|
|
|
|
// can scroll the next parent view.
|
|
|
|
//
|
|
|
|
|
2004-09-21 02:25:07 +04:00
|
|
|
view = scrollableView->View()->GetParent();
|
2000-03-22 02:58:02 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2000-08-30 23:42:47 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
2006-06-16 05:54:31 +04:00
|
|
|
nsTypedSelection::DoAutoScrollView(nsPresContext *aPresContext,
|
|
|
|
nsIView *aView,
|
|
|
|
nsPoint& aPoint,
|
|
|
|
PRBool aScrollParentViews)
|
2000-08-30 23:42:47 +04:00
|
|
|
{
|
|
|
|
if (!aPresContext || !aView)
|
|
|
|
return NS_ERROR_NULL_POINTER;
|
|
|
|
|
|
|
|
nsresult result;
|
|
|
|
|
|
|
|
if (mAutoScrollTimer)
|
|
|
|
result = mAutoScrollTimer->Stop();
|
|
|
|
|
|
|
|
//
|
|
|
|
// Calculate the global offset of the view.
|
|
|
|
//
|
|
|
|
|
|
|
|
nsPoint globalOffset;
|
|
|
|
result = GetViewAncestorOffset(aView, nsnull, &globalOffset.x, &globalOffset.y);
|
2006-06-16 05:54:31 +04:00
|
|
|
NS_ENSURE_SUCCESS(result, result);
|
2000-08-30 23:42:47 +04:00
|
|
|
|
|
|
|
//
|
|
|
|
// Convert aPoint into global coordinates so we can get back
|
|
|
|
// to the same point after all the parent views have scrolled.
|
|
|
|
//
|
|
|
|
nsPoint globalPoint = aPoint + globalOffset;
|
|
|
|
//
|
|
|
|
// Now scroll aPoint into view.
|
|
|
|
//
|
|
|
|
|
|
|
|
PRBool didScroll = PR_FALSE;
|
|
|
|
|
|
|
|
result = ScrollPointIntoView(aPresContext, aView, aPoint, aScrollParentViews, &didScroll);
|
2006-06-16 05:54:31 +04:00
|
|
|
NS_ENSURE_SUCCESS(result, result);
|
2000-08-30 23:42:47 +04:00
|
|
|
|
|
|
|
//
|
2004-11-10 10:27:11 +03:00
|
|
|
// Start the AutoScroll timer if necessary.
|
2000-08-30 23:42:47 +04:00
|
|
|
//
|
|
|
|
|
|
|
|
if (didScroll && mAutoScrollTimer)
|
|
|
|
{
|
|
|
|
//
|
|
|
|
// Map the globalPoint back into aView's coordinate system. We
|
|
|
|
// have to get the globalOffsets again because aView's
|
2005-11-21 01:05:24 +03:00
|
|
|
// window and its parents may have changed their offsets.
|
2000-08-30 23:42:47 +04:00
|
|
|
//
|
|
|
|
result = GetViewAncestorOffset(aView, nsnull, &globalOffset.x, &globalOffset.y);
|
2006-06-16 05:54:31 +04:00
|
|
|
NS_ENSURE_SUCCESS(result, result);
|
2000-08-30 23:42:47 +04:00
|
|
|
|
|
|
|
nsPoint svPoint = globalPoint - globalOffset;
|
2006-06-16 05:54:31 +04:00
|
|
|
mAutoScrollTimer->Start(aPresContext, aView, svPoint);
|
2000-08-30 23:42:47 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2000-03-22 02:58:02 +03:00
|
|
|
NS_IMETHODIMP
|
2000-11-29 03:13:00 +03:00
|
|
|
nsTypedSelection::GetEnumerator(nsIEnumerator **aIterator)
|
2000-03-22 02:58:02 +03:00
|
|
|
{
|
|
|
|
nsresult status = NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
nsSelectionIterator *iterator = new nsSelectionIterator(this);
|
2001-11-19 09:45:00 +03:00
|
|
|
if ( iterator && NS_FAILED(status = CallQueryInterface(iterator, aIterator)) )
|
2003-03-12 06:22:11 +03:00
|
|
|
delete iterator;
|
2000-03-22 02:58:02 +03:00
|
|
|
return status;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2000-09-14 15:45:01 +04:00
|
|
|
/** RemoveAllRanges zeroes the selection
|
2000-03-22 02:58:02 +03:00
|
|
|
*/
|
|
|
|
NS_IMETHODIMP
|
2000-11-29 03:13:00 +03:00
|
|
|
nsTypedSelection::RemoveAllRanges()
|
2000-03-22 02:58:02 +03:00
|
|
|
{
|
2000-05-11 08:25:43 +04:00
|
|
|
if (!mFrameSelection)
|
|
|
|
return NS_OK;//nothing to do
|
2004-08-01 03:15:21 +04:00
|
|
|
nsCOMPtr<nsPresContext> presContext;
|
2000-03-22 02:58:02 +03:00
|
|
|
GetPresContext(getter_AddRefs(presContext));
|
|
|
|
|
2000-06-03 03:05:06 +04:00
|
|
|
|
2003-03-12 06:22:11 +03:00
|
|
|
nsresult result = Clear(presContext);
|
2000-03-22 02:58:02 +03:00
|
|
|
if (NS_FAILED(result))
|
2003-03-12 06:22:11 +03:00
|
|
|
return result;
|
2000-06-03 03:05:06 +04:00
|
|
|
|
2003-03-12 06:22:11 +03:00
|
|
|
// Turn off signal for table selection
|
2000-06-03 03:05:06 +04:00
|
|
|
mFrameSelection->ClearTableCellSelection();
|
|
|
|
|
2000-04-14 15:21:19 +04:00
|
|
|
return mFrameSelection->NotifySelectionListeners(GetType());
|
2000-03-22 02:58:02 +03:00
|
|
|
// Also need to notify the frames!
|
2004-02-21 00:38:31 +03:00
|
|
|
// PresShell::CharacterDataChanged should do that on DocumentChanged
|
2000-03-22 02:58:02 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/** AddRange adds the specified range to the selection
|
|
|
|
* @param aRange is the range to be added
|
|
|
|
*/
|
|
|
|
NS_IMETHODIMP
|
2000-11-29 03:13:00 +03:00
|
|
|
nsTypedSelection::AddRange(nsIDOMRange* aRange)
|
2000-03-22 02:58:02 +03:00
|
|
|
{
|
2000-12-21 01:13:54 +03:00
|
|
|
if (!aRange) return NS_ERROR_NULL_POINTER;
|
|
|
|
|
|
|
|
// This inserts a table cell range in proper document order
|
2006-04-18 02:06:25 +04:00
|
|
|
// and returns NS_OK if range doesn't contain just one table cell
|
2000-12-21 01:13:54 +03:00
|
|
|
PRBool didAddRange;
|
|
|
|
nsresult result = addTableCellRange(aRange, &didAddRange);
|
|
|
|
if (NS_FAILED(result)) return result;
|
|
|
|
|
|
|
|
if (!didAddRange)
|
|
|
|
{
|
|
|
|
result = AddItem(aRange);
|
|
|
|
if (NS_FAILED(result)) return result;
|
|
|
|
}
|
|
|
|
|
2000-03-22 02:58:02 +03:00
|
|
|
PRInt32 count;
|
|
|
|
result = GetRangeCount(&count);
|
2000-12-21 01:13:54 +03:00
|
|
|
if (NS_FAILED(result)) return result;
|
|
|
|
|
2000-03-22 02:58:02 +03:00
|
|
|
if (count <= 0)
|
|
|
|
{
|
|
|
|
NS_ASSERTION(0,"bad count after additem\n");
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
setAnchorFocusRange(count -1);
|
2000-08-10 02:34:17 +04:00
|
|
|
|
2006-05-11 20:28:01 +04:00
|
|
|
// Make sure the caret appears on the next line, if at a newline
|
2006-05-22 20:56:44 +04:00
|
|
|
if (mType == nsISelectionController::SELECTION_NORMAL)
|
|
|
|
SetInterlinePosition(PR_TRUE);
|
2006-05-11 20:28:01 +04:00
|
|
|
|
2004-08-01 03:15:21 +04:00
|
|
|
nsCOMPtr<nsPresContext> presContext;
|
2000-03-22 02:58:02 +03:00
|
|
|
GetPresContext(getter_AddRefs(presContext));
|
|
|
|
selectFrames(presContext, aRange, PR_TRUE);
|
2000-12-21 01:13:54 +03:00
|
|
|
|
2000-04-12 07:04:11 +04:00
|
|
|
//ScrollIntoView(); this should not happen automatically
|
2000-05-11 08:25:43 +04:00
|
|
|
if (!mFrameSelection)
|
|
|
|
return NS_OK;//nothing to do
|
2000-12-21 01:13:54 +03:00
|
|
|
|
2000-04-14 15:21:19 +04:00
|
|
|
return mFrameSelection->NotifySelectionListeners(GetType());
|
2000-03-22 02:58:02 +03:00
|
|
|
}
|
|
|
|
|
2006-07-31 22:25:22 +04:00
|
|
|
// nsTypedSelection::RemoveRange
|
|
|
|
//
|
|
|
|
// Removes the given range from the selection. The tricky part is updating
|
|
|
|
// the flags on the frames that indicate whether they have a selection or
|
|
|
|
// not. There could be several selection ranges on the frame, and clearing
|
|
|
|
// the bit would cause the selection to not be drawn, even when there is
|
|
|
|
// another range on the frame (bug 346185).
|
|
|
|
//
|
|
|
|
// We therefore find any ranges that intersect the same nodes as the range
|
|
|
|
// being removed, and cause them to set the selected bits back on their
|
|
|
|
// selected frames after we've cleared the bit from ours.
|
|
|
|
|
2000-03-22 02:58:02 +03:00
|
|
|
NS_IMETHODIMP
|
2000-11-29 03:13:00 +03:00
|
|
|
nsTypedSelection::RemoveRange(nsIDOMRange* aRange)
|
2000-03-22 02:58:02 +03:00
|
|
|
{
|
|
|
|
if (!aRange)
|
|
|
|
return NS_ERROR_INVALID_ARG;
|
2006-07-31 22:25:22 +04:00
|
|
|
nsresult rv = RemoveItem(aRange);
|
|
|
|
if (NS_FAILED(rv))
|
|
|
|
return rv;
|
|
|
|
|
|
|
|
nsCOMPtr<nsIDOMNode> beginNode, endNode;
|
|
|
|
rv = aRange->GetStartContainer(getter_AddRefs(beginNode));
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
rv = aRange->GetEndContainer(getter_AddRefs(endNode));
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
// find out the length of the end node, so we can select all of it
|
|
|
|
PRInt32 beginOffset, endOffset;
|
|
|
|
PRUint16 endNodeType = nsIDOMNode::ELEMENT_NODE;
|
|
|
|
endNode->GetNodeType(&endNodeType);
|
|
|
|
if (endNodeType == nsIDOMNode::TEXT_NODE) {
|
|
|
|
// Get the length of the text. We can't just use the offset because
|
|
|
|
// another range could be touching this text node but not intersect our
|
|
|
|
// range.
|
|
|
|
beginOffset = 0;
|
|
|
|
nsAutoString endNodeValue;
|
|
|
|
endNode->GetNodeValue(endNodeValue);
|
|
|
|
endOffset = endNodeValue.Length();
|
|
|
|
} else {
|
|
|
|
// For non-text nodes, the given offsets should be sufficient.
|
|
|
|
aRange->GetStartOffset(&beginOffset);
|
|
|
|
aRange->GetEndOffset(&endOffset);
|
|
|
|
}
|
|
|
|
|
|
|
|
// clear the selected bit from the removed range's frames
|
2004-08-01 03:15:21 +04:00
|
|
|
nsCOMPtr<nsPresContext> presContext;
|
2000-03-22 02:58:02 +03:00
|
|
|
GetPresContext(getter_AddRefs(presContext));
|
2006-05-31 01:59:56 +04:00
|
|
|
selectFrames(presContext, aRange, PR_FALSE);
|
2006-07-31 22:25:22 +04:00
|
|
|
|
|
|
|
// add back the selected bit for each range touching our nodes
|
|
|
|
nsCOMArray<nsIDOMRange> affectedRanges;
|
|
|
|
rv = GetRangesForIntervalCOMArray(beginNode, beginOffset,
|
|
|
|
endNode, endOffset,
|
|
|
|
PR_TRUE, &affectedRanges);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
for (PRInt32 i = 0; i < affectedRanges.Count(); i ++)
|
|
|
|
selectFrames(presContext, affectedRanges[i], PR_TRUE);
|
|
|
|
|
2006-05-31 01:59:56 +04:00
|
|
|
// When the selection is user-created it makes sense to scroll the range
|
|
|
|
// into view. The spell-check selection, however, is created and destroyed
|
|
|
|
// in the background. We don't want to scroll in this case or the view
|
|
|
|
// might appear to be moving randomly (bug 337871).
|
|
|
|
if (mType != nsISelectionController::SELECTION_SPELLCHECK &&
|
|
|
|
aRange == mAnchorFocusRange.get())
|
2000-03-22 02:58:02 +03:00
|
|
|
{
|
2006-07-27 21:57:15 +04:00
|
|
|
PRInt32 cnt = mRanges.Length();
|
2002-12-11 03:02:49 +03:00
|
|
|
if (cnt > 0)
|
2000-03-22 02:58:02 +03:00
|
|
|
{
|
2002-12-11 03:02:49 +03:00
|
|
|
setAnchorFocusRange(cnt - 1);//reset anchor to LAST range.
|
2000-03-22 02:58:02 +03:00
|
|
|
ScrollIntoView();
|
|
|
|
}
|
|
|
|
}
|
2000-05-11 08:25:43 +04:00
|
|
|
if (!mFrameSelection)
|
|
|
|
return NS_OK;//nothing to do
|
2000-04-14 15:21:19 +04:00
|
|
|
return mFrameSelection->NotifySelectionListeners(GetType());
|
2000-03-22 02:58:02 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2002-03-26 02:44:46 +03:00
|
|
|
|
2000-03-22 02:58:02 +03:00
|
|
|
/*
|
|
|
|
* Collapse sets the whole selection to be one point.
|
|
|
|
*/
|
|
|
|
NS_IMETHODIMP
|
2000-11-29 03:13:00 +03:00
|
|
|
nsTypedSelection::Collapse(nsIDOMNode* aParentNode, PRInt32 aOffset)
|
2000-03-22 02:58:02 +03:00
|
|
|
{
|
|
|
|
if (!aParentNode)
|
|
|
|
return NS_ERROR_INVALID_ARG;
|
2006-04-14 04:28:22 +04:00
|
|
|
if (!mFrameSelection)
|
|
|
|
return NS_ERROR_NOT_INITIALIZED; // Can't do selection
|
2002-04-17 03:26:22 +04:00
|
|
|
mFrameSelection->InvalidateDesiredX();
|
2002-03-26 02:44:46 +03:00
|
|
|
if (!IsValidSelectionPoint(mFrameSelection, aParentNode))
|
|
|
|
return NS_ERROR_FAILURE;
|
2000-03-22 02:58:02 +03:00
|
|
|
nsresult result;
|
|
|
|
// Delete all of the current ranges
|
|
|
|
if (NS_FAILED(SetOriginalAnchorPoint(aParentNode,aOffset)))
|
|
|
|
return NS_ERROR_FAILURE; //???
|
2004-08-01 03:15:21 +04:00
|
|
|
nsCOMPtr<nsPresContext> presContext;
|
2000-03-22 02:58:02 +03:00
|
|
|
GetPresContext(getter_AddRefs(presContext));
|
|
|
|
Clear(presContext);
|
|
|
|
|
2003-03-12 06:22:11 +03:00
|
|
|
// Turn off signal for table selection
|
2000-06-03 03:05:06 +04:00
|
|
|
if (mFrameSelection)
|
|
|
|
mFrameSelection->ClearTableCellSelection();
|
|
|
|
|
2000-03-22 02:58:02 +03:00
|
|
|
nsCOMPtr<nsIDOMRange> range;
|
|
|
|
NS_NewRange(getter_AddRefs(range));
|
|
|
|
if (! range){
|
2006-04-26 06:01:07 +04:00
|
|
|
NS_ASSERTION(PR_FALSE,"Couldn't make a range - nsFrameSelection::Collapse");
|
2000-03-22 02:58:02 +03:00
|
|
|
return NS_ERROR_UNEXPECTED;
|
|
|
|
}
|
|
|
|
result = range->SetEnd(aParentNode, aOffset);
|
|
|
|
if (NS_FAILED(result))
|
|
|
|
return result;
|
|
|
|
result = range->SetStart(aParentNode, aOffset);
|
|
|
|
if (NS_FAILED(result))
|
|
|
|
return result;
|
|
|
|
|
|
|
|
#ifdef DEBUG_SELECTION
|
|
|
|
if (aParentNode)
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsIContent>content;
|
|
|
|
content = do_QueryInterface(aParentNode);
|
|
|
|
if (!content)
|
|
|
|
return NS_ERROR_FAILURE;
|
2003-11-19 04:20:56 +03:00
|
|
|
|
|
|
|
const char *tagString;
|
|
|
|
content->Tag()->GetUTF8String(&tagString);
|
2005-10-17 04:51:46 +04:00
|
|
|
printf ("Sel. Collapse to %p %s %d\n", content.get(), tagString, aOffset);
|
2000-03-22 02:58:02 +03:00
|
|
|
}
|
|
|
|
else {
|
2000-10-29 02:17:53 +04:00
|
|
|
printf ("Sel. Collapse set to null parent.\n");
|
2000-03-22 02:58:02 +03:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
result = AddItem(range);
|
|
|
|
setAnchorFocusRange(0);
|
|
|
|
selectFrames(presContext, range,PR_TRUE);
|
|
|
|
if (NS_FAILED(result))
|
|
|
|
return result;
|
2000-05-11 08:25:43 +04:00
|
|
|
if (!mFrameSelection)
|
2003-03-12 06:22:11 +03:00
|
|
|
return NS_OK;//nothing to do
|
|
|
|
return mFrameSelection->NotifySelectionListeners(GetType());
|
2000-03-22 02:58:02 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Sets the whole selection to be one point
|
|
|
|
* at the start of the current selection
|
|
|
|
*/
|
|
|
|
NS_IMETHODIMP
|
2000-11-29 03:13:00 +03:00
|
|
|
nsTypedSelection::CollapseToStart()
|
2000-03-22 02:58:02 +03:00
|
|
|
{
|
|
|
|
PRInt32 cnt;
|
|
|
|
nsresult rv = GetRangeCount(&cnt);
|
2002-12-11 03:02:49 +03:00
|
|
|
if (NS_FAILED(rv) || cnt <= 0)
|
2003-03-12 06:22:11 +03:00
|
|
|
return NS_ERROR_FAILURE;
|
2000-03-22 02:58:02 +03:00
|
|
|
|
2000-12-21 01:13:54 +03:00
|
|
|
// Get the first range
|
2006-07-27 21:57:15 +04:00
|
|
|
nsIDOMRange* firstRange = mRanges[0].mRange;
|
2000-03-22 02:58:02 +03:00
|
|
|
if (!firstRange)
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
|
|
|
|
nsCOMPtr<nsIDOMNode> parent;
|
2000-08-24 07:54:30 +04:00
|
|
|
rv = firstRange->GetStartContainer(getter_AddRefs(parent));
|
2000-03-22 02:58:02 +03:00
|
|
|
if (NS_SUCCEEDED(rv))
|
|
|
|
{
|
|
|
|
if (parent)
|
|
|
|
{
|
|
|
|
PRInt32 startOffset;
|
|
|
|
firstRange->GetStartOffset(&startOffset);
|
|
|
|
rv = Collapse(parent, startOffset);
|
|
|
|
} else {
|
|
|
|
// not very likely!
|
|
|
|
rv = NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Sets the whole selection to be one point
|
|
|
|
* at the end of the current selection
|
|
|
|
*/
|
|
|
|
NS_IMETHODIMP
|
2000-11-29 03:13:00 +03:00
|
|
|
nsTypedSelection::CollapseToEnd()
|
2000-03-22 02:58:02 +03:00
|
|
|
{
|
|
|
|
PRInt32 cnt;
|
|
|
|
nsresult rv = GetRangeCount(&cnt);
|
2002-12-11 03:02:49 +03:00
|
|
|
if (NS_FAILED(rv) || cnt <= 0)
|
2003-03-12 06:22:11 +03:00
|
|
|
return NS_ERROR_FAILURE;
|
2000-03-22 02:58:02 +03:00
|
|
|
|
2000-12-21 01:13:54 +03:00
|
|
|
// Get the last range
|
2006-07-27 21:57:15 +04:00
|
|
|
nsIDOMRange* lastRange = mRanges[cnt-1].mRange;
|
2000-03-22 02:58:02 +03:00
|
|
|
if (!lastRange)
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
|
|
|
|
nsCOMPtr<nsIDOMNode> parent;
|
2000-08-24 07:54:30 +04:00
|
|
|
rv = lastRange->GetEndContainer(getter_AddRefs(parent));
|
2000-03-22 02:58:02 +03:00
|
|
|
if (NS_SUCCEEDED(rv))
|
|
|
|
{
|
|
|
|
if (parent)
|
|
|
|
{
|
|
|
|
PRInt32 endOffset;
|
|
|
|
lastRange->GetEndOffset(&endOffset);
|
|
|
|
rv = Collapse(parent, endOffset);
|
|
|
|
} else {
|
|
|
|
// not very likely!
|
|
|
|
rv = NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* IsCollapsed -- is the whole selection just one point, or unset?
|
|
|
|
*/
|
|
|
|
NS_IMETHODIMP
|
2000-11-29 03:13:00 +03:00
|
|
|
nsTypedSelection::GetIsCollapsed(PRBool* aIsCollapsed)
|
2000-03-22 02:58:02 +03:00
|
|
|
{
|
2003-03-12 06:22:11 +03:00
|
|
|
if (!aIsCollapsed)
|
|
|
|
return NS_ERROR_NULL_POINTER;
|
|
|
|
|
2006-07-27 21:57:15 +04:00
|
|
|
PRInt32 cnt = (PRInt32)mRanges.Length();;
|
2002-12-11 03:02:49 +03:00
|
|
|
if (cnt == 0)
|
2000-03-22 02:58:02 +03:00
|
|
|
{
|
|
|
|
*aIsCollapsed = PR_TRUE;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (cnt != 1)
|
|
|
|
{
|
|
|
|
*aIsCollapsed = PR_FALSE;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2006-07-27 21:57:15 +04:00
|
|
|
return mRanges[0].mRange->GetCollapsed(aIsCollapsed);
|
2000-03-22 02:58:02 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2000-11-29 03:13:00 +03:00
|
|
|
nsTypedSelection::GetRangeCount(PRInt32* aRangeCount)
|
2000-03-22 02:58:02 +03:00
|
|
|
{
|
|
|
|
if (!aRangeCount)
|
2003-03-12 06:22:11 +03:00
|
|
|
return NS_ERROR_NULL_POINTER;
|
2000-03-22 02:58:02 +03:00
|
|
|
|
2006-07-27 21:57:15 +04:00
|
|
|
*aRangeCount = (PRInt32)mRanges.Length();
|
|
|
|
NS_ASSERTION(ValidateRanges(), "Ranges out of sync");
|
2003-03-12 06:22:11 +03:00
|
|
|
|
|
|
|
return NS_OK;
|
2000-03-22 02:58:02 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2000-11-29 03:13:00 +03:00
|
|
|
nsTypedSelection::GetRangeAt(PRInt32 aIndex, nsIDOMRange** aReturn)
|
2000-03-22 02:58:02 +03:00
|
|
|
{
|
2003-03-12 06:22:11 +03:00
|
|
|
if (!aReturn)
|
|
|
|
return NS_ERROR_NULL_POINTER;
|
2006-07-27 21:57:15 +04:00
|
|
|
NS_ASSERTION(ValidateRanges(), "Ranges out of sync");
|
2000-03-22 02:58:02 +03:00
|
|
|
|
2006-07-27 21:57:15 +04:00
|
|
|
PRInt32 cnt = (PRInt32)mRanges.Length();
|
2003-03-12 06:22:11 +03:00
|
|
|
if (aIndex < 0 || aIndex >= cnt)
|
|
|
|
return NS_ERROR_INVALID_ARG;
|
2000-03-22 02:58:02 +03:00
|
|
|
|
2006-07-27 21:57:15 +04:00
|
|
|
*aReturn = mRanges[aIndex].mRange;
|
2002-12-11 03:02:49 +03:00
|
|
|
NS_IF_ADDREF(*aReturn);
|
2003-03-12 06:22:11 +03:00
|
|
|
|
|
|
|
return NS_OK;
|
2000-03-22 02:58:02 +03:00
|
|
|
}
|
|
|
|
|
2001-05-04 03:59:55 +04:00
|
|
|
#ifdef OLD_SELECTION
|
2000-03-22 02:58:02 +03:00
|
|
|
|
|
|
|
//may change parameters may not.
|
|
|
|
//return NS_ERROR_FAILURE if invalid new selection between anchor and passed in parameters
|
|
|
|
NS_IMETHODIMP
|
2000-11-29 03:13:00 +03:00
|
|
|
nsTypedSelection::FixupSelectionPoints(nsIDOMRange *aRange , nsDirection *aDir, PRBool *aFixupState)
|
2000-03-22 02:58:02 +03:00
|
|
|
{
|
|
|
|
if (!aRange || !aFixupState)
|
|
|
|
return NS_ERROR_NULL_POINTER;
|
|
|
|
*aFixupState = PR_FALSE;
|
|
|
|
nsresult res;
|
|
|
|
|
|
|
|
//startNode is the beginning or "anchor" of the range
|
|
|
|
//end Node is the end or "focus of the range
|
|
|
|
nsCOMPtr<nsIDOMNode> startNode;
|
|
|
|
nsCOMPtr<nsIDOMNode> endNode;
|
|
|
|
PRInt32 startOffset;
|
|
|
|
PRInt32 endOffset;
|
|
|
|
nsresult result;
|
|
|
|
if (*aDir == eDirNext)
|
|
|
|
{
|
|
|
|
if (NS_FAILED(GetOriginalAnchorPoint(getter_AddRefs(startNode), &startOffset)))
|
|
|
|
{
|
|
|
|
aRange->GetStartParent(getter_AddRefs(startNode));
|
|
|
|
aRange->GetStartOffset(&startOffset);
|
|
|
|
}
|
|
|
|
aRange->GetEndParent(getter_AddRefs(endNode));
|
|
|
|
aRange->GetEndOffset(&endOffset);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (NS_FAILED(GetOriginalAnchorPoint(getter_AddRefs(startNode), &startOffset)))
|
|
|
|
{
|
|
|
|
aRange->GetEndParent(getter_AddRefs(startNode));
|
|
|
|
aRange->GetEndOffset(&startOffset);
|
|
|
|
}
|
|
|
|
aRange->GetStartParent(getter_AddRefs(endNode));
|
|
|
|
aRange->GetStartOffset(&endOffset);
|
|
|
|
}
|
|
|
|
if (!startNode || !endNode)
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
|
|
|
|
// if end node is a tbody then all bets are off we cannot select "rows"
|
2003-11-19 04:20:56 +03:00
|
|
|
nsIAtom *atom = GetTag(endNode);
|
2006-12-26 20:47:52 +03:00
|
|
|
if (atom == nsGkAtoms::tbody)
|
2000-03-22 02:58:02 +03:00
|
|
|
return NS_ERROR_FAILURE; //cannot select INTO row node ony cells
|
|
|
|
|
|
|
|
//get common parent
|
|
|
|
nsCOMPtr<nsIDOMNode> parent;
|
|
|
|
nsCOMPtr<nsIDOMRange> subRange;
|
|
|
|
NS_NewRange(getter_AddRefs(subRange));
|
|
|
|
if (!subRange) return NS_ERROR_OUT_OF_MEMORY
|
|
|
|
|
|
|
|
result = subRange->SetStart(startNode,startOffset);
|
|
|
|
if (NS_FAILED(result))
|
|
|
|
return result;
|
|
|
|
result = subRange->SetEnd(endNode,endOffset);
|
|
|
|
if (NS_FAILED(result))
|
|
|
|
{
|
|
|
|
result = subRange->SetEnd(startNode,startOffset);
|
|
|
|
if (NS_FAILED(result))
|
|
|
|
return result;
|
|
|
|
result = subRange->SetStart(endNode,endOffset);
|
|
|
|
if (NS_FAILED(result))
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
res = subRange->GetCommonParent(getter_AddRefs(parent));
|
|
|
|
if (NS_FAILED(res) || !parent)
|
|
|
|
return res;
|
|
|
|
|
|
|
|
//look for dest. if you see a cell you are in "cell mode"
|
|
|
|
//if you see a table you select "whole" table
|
|
|
|
|
|
|
|
//src first
|
|
|
|
nsCOMPtr<nsIDOMNode> tempNode;
|
|
|
|
nsCOMPtr<nsIDOMNode> tempNode2;
|
|
|
|
PRBool cellMode = PR_FALSE;
|
|
|
|
PRBool dirtystart = PR_FALSE;
|
|
|
|
PRBool dirtyend = PR_FALSE;
|
|
|
|
if (startNode != endNode)
|
|
|
|
{
|
|
|
|
if (parent != startNode)
|
|
|
|
{
|
|
|
|
result = startNode->GetParentNode(getter_AddRefs(tempNode));
|
|
|
|
if (NS_FAILED(result) || !tempNode)
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
while (tempNode != parent)
|
|
|
|
{
|
|
|
|
atom = GetTag(tempNode);
|
2006-12-26 20:47:52 +03:00
|
|
|
if (atom == nsGkAtoms::table) //select whole table if in cell mode, wait for cell
|
2000-03-22 02:58:02 +03:00
|
|
|
{
|
|
|
|
result = ParentOffset(tempNode, getter_AddRefs(startNode), &startOffset);
|
|
|
|
if (NS_FAILED(result))
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
if (*aDir == eDirPrevious) //select after
|
|
|
|
startOffset++;
|
|
|
|
dirtystart = PR_TRUE;
|
|
|
|
cellMode = PR_FALSE;
|
|
|
|
}
|
2006-12-26 20:47:52 +03:00
|
|
|
else if (atom == nsGkAtoms::td ||
|
|
|
|
atom == nsGkAtoms::th) //you are in "cell" mode put selection to end of cell
|
2000-03-22 02:58:02 +03:00
|
|
|
{
|
|
|
|
cellMode = PR_TRUE;
|
|
|
|
result = ParentOffset(tempNode, getter_AddRefs(startNode), &startOffset);
|
|
|
|
if (NS_FAILED(result))
|
|
|
|
return result;
|
|
|
|
if (*aDir == eDirPrevious) //select after
|
|
|
|
startOffset++;
|
|
|
|
dirtystart = PR_TRUE;
|
|
|
|
}
|
|
|
|
result = tempNode->GetParentNode(getter_AddRefs(tempNode2));
|
|
|
|
if (NS_FAILED(result) || !tempNode2)
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
tempNode = tempNode2;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//now for dest node
|
|
|
|
if (parent != endNode)
|
|
|
|
{
|
|
|
|
result = endNode->GetParentNode(getter_AddRefs(tempNode));
|
|
|
|
PRBool found = !cellMode;
|
|
|
|
if (NS_FAILED(result) || !tempNode)
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
while (tempNode != parent)
|
|
|
|
{
|
|
|
|
atom = GetTag(tempNode);
|
2006-12-26 20:47:52 +03:00
|
|
|
if (atom == nsGkAtoms::table) //select whole table if in cell mode, wait for cell
|
2000-03-22 02:58:02 +03:00
|
|
|
{
|
|
|
|
if (!cellMode)
|
|
|
|
{
|
|
|
|
result = ParentOffset(tempNode, getter_AddRefs(endNode), &endOffset);
|
|
|
|
if (NS_FAILED(result))
|
|
|
|
return result;
|
|
|
|
if (*aDir == eDirNext) //select after
|
|
|
|
endOffset++;
|
|
|
|
dirtyend = PR_TRUE;
|
|
|
|
}
|
|
|
|
else
|
2005-11-21 01:05:24 +03:00
|
|
|
found = PR_FALSE; //didn't find the right cell yet
|
2000-03-22 02:58:02 +03:00
|
|
|
}
|
2006-12-26 20:47:52 +03:00
|
|
|
else if (atom == nsGkAtoms::td ||
|
|
|
|
atom == nsGkAtoms::th) //you are in "cell" mode put selection to end of cell
|
2000-03-22 02:58:02 +03:00
|
|
|
{
|
|
|
|
result = ParentOffset(tempNode, getter_AddRefs(endNode), &endOffset);
|
|
|
|
if (NS_FAILED(result))
|
|
|
|
return result;
|
|
|
|
if (*aDir == eDirNext) //select after
|
|
|
|
endOffset++;
|
|
|
|
found = PR_TRUE;
|
|
|
|
dirtyend = PR_TRUE;
|
|
|
|
}
|
|
|
|
result = tempNode->GetParentNode(getter_AddRefs(tempNode2));
|
|
|
|
if (NS_FAILED(result) || !tempNode2)
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
tempNode = tempNode2;
|
|
|
|
}
|
|
|
|
if (!found)
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (*aDir == eDirNext)
|
|
|
|
{
|
|
|
|
if (FetchAnchorNode() == startNode.get() && FetchFocusNode() == endNode.get() &&
|
|
|
|
FetchAnchorOffset() == startOffset && FetchFocusOffset() == endOffset)
|
|
|
|
{
|
|
|
|
*aFixupState = PR_FALSE;
|
|
|
|
return NS_ERROR_FAILURE;//nothing to do
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (FetchAnchorNode() == endNode.get() && FetchFocusNode() == startNode.get() &&
|
|
|
|
FetchAnchorOffset() == endOffset && FetchFocusOffset() == startOffset)
|
|
|
|
{
|
|
|
|
*aFixupState = PR_FALSE;
|
|
|
|
return NS_ERROR_FAILURE;//nothing to do
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (mFixupState && !dirtyend && !dirtystart)//no mor fixup! all bets off
|
|
|
|
{
|
|
|
|
dirtystart = PR_TRUE;//force a reset of anchor positions
|
|
|
|
dirtystart = PR_TRUE;
|
|
|
|
*aFixupState = PR_TRUE;//redraw all selection here
|
|
|
|
mFixupState = PR_FALSE;//no more fixup for next time
|
|
|
|
}
|
|
|
|
else
|
|
|
|
if ((dirtystart || dirtyend) && *aDir != mDirection) //fixup took place but new direction all bets are off
|
|
|
|
{
|
|
|
|
*aFixupState = PR_TRUE;
|
|
|
|
//mFixupState = PR_FALSE;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
if (dirtystart && (FetchAnchorNode() != startNode.get() || FetchAnchorOffset() != startOffset))
|
|
|
|
{
|
|
|
|
*aFixupState = PR_TRUE;
|
|
|
|
mFixupState = PR_TRUE;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
if (dirtyend && (FetchFocusNode() != endNode.get() || FetchFocusOffset() != endOffset))
|
|
|
|
{
|
|
|
|
*aFixupState = PR_TRUE;
|
|
|
|
mFixupState = PR_TRUE;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
mFixupState = dirtystart || dirtyend;
|
|
|
|
*aFixupState = PR_FALSE;
|
|
|
|
}
|
|
|
|
if (dirtystart || dirtyend){
|
|
|
|
if (*aDir == eDirNext)
|
|
|
|
{
|
|
|
|
if (NS_FAILED(aRange->SetStart(startNode,startOffset)) || NS_FAILED(aRange->SetEnd(endNode, endOffset)))
|
|
|
|
{
|
|
|
|
*aDir = eDirPrevious;
|
|
|
|
aRange->SetStart(endNode, endOffset);
|
|
|
|
aRange->SetEnd(startNode, startOffset);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (NS_FAILED(aRange->SetStart(endNode,endOffset)) || NS_FAILED(aRange->SetEnd(startNode, startOffset)))
|
|
|
|
{
|
|
|
|
*aDir = eDirNext;
|
|
|
|
aRange->SetStart(startNode, startOffset);
|
|
|
|
aRange->SetEnd(endNode, endOffset);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
#endif //OLD_SELECTION
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2000-11-29 03:13:00 +03:00
|
|
|
nsTypedSelection::SetOriginalAnchorPoint(nsIDOMNode *aNode, PRInt32 aOffset)
|
2000-03-22 02:58:02 +03:00
|
|
|
{
|
|
|
|
if (!aNode){
|
|
|
|
mOriginalAnchorRange = 0;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
nsCOMPtr<nsIDOMRange> newRange;
|
|
|
|
nsresult result;
|
|
|
|
NS_NewRange(getter_AddRefs(newRange));
|
|
|
|
if (!newRange) return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
|
|
|
|
result = newRange->SetStart(aNode,aOffset);
|
|
|
|
if (NS_FAILED(result))
|
|
|
|
return result;
|
|
|
|
result = newRange->SetEnd(aNode,aOffset);
|
|
|
|
if (NS_FAILED(result))
|
|
|
|
return result;
|
|
|
|
|
|
|
|
mOriginalAnchorRange = newRange;
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2000-11-29 03:13:00 +03:00
|
|
|
nsTypedSelection::GetOriginalAnchorPoint(nsIDOMNode **aNode, PRInt32 *aOffset)
|
2000-03-22 02:58:02 +03:00
|
|
|
{
|
|
|
|
if (!aNode || !aOffset || !mOriginalAnchorRange)
|
|
|
|
return NS_ERROR_NULL_POINTER;
|
|
|
|
nsresult result;
|
2000-08-24 07:54:30 +04:00
|
|
|
result = mOriginalAnchorRange->GetStartContainer(aNode);
|
2000-03-22 02:58:02 +03:00
|
|
|
if (NS_FAILED(result))
|
|
|
|
return result;
|
|
|
|
result = mOriginalAnchorRange->GetStartOffset(aOffset);
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
utility function
|
|
|
|
*/
|
|
|
|
NS_IMETHODIMP
|
2000-11-29 03:13:00 +03:00
|
|
|
nsTypedSelection::CopyRangeToAnchorFocus(nsIDOMRange *aRange)
|
2000-03-22 02:58:02 +03:00
|
|
|
{
|
|
|
|
nsCOMPtr<nsIDOMNode> startNode;
|
|
|
|
nsCOMPtr<nsIDOMNode> endNode;
|
|
|
|
PRInt32 startOffset;
|
|
|
|
PRInt32 endOffset;
|
2000-08-24 07:54:30 +04:00
|
|
|
aRange->GetStartContainer(getter_AddRefs(startNode));
|
|
|
|
aRange->GetEndContainer(getter_AddRefs(endNode));
|
2000-03-22 02:58:02 +03:00
|
|
|
aRange->GetStartOffset(&startOffset);
|
|
|
|
aRange->GetEndOffset(&endOffset);
|
|
|
|
if (NS_FAILED(mAnchorFocusRange->SetStart(startNode,startOffset)))
|
|
|
|
{
|
|
|
|
if (NS_FAILED(mAnchorFocusRange->SetEnd(endNode,endOffset)))
|
|
|
|
return NS_ERROR_FAILURE;//???
|
|
|
|
if (NS_FAILED(mAnchorFocusRange->SetStart(startNode,startOffset)))
|
|
|
|
return NS_ERROR_FAILURE;//???
|
|
|
|
}
|
|
|
|
else if (NS_FAILED(mAnchorFocusRange->SetEnd(endNode,endOffset)))
|
|
|
|
return NS_ERROR_FAILURE;//???
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
Notes which might come in handy for extend:
|
|
|
|
|
|
|
|
We can tell the direction of the selection by asking for the anchors selection
|
|
|
|
if the begin is less than the end then we know the selection is to the "right".
|
|
|
|
else it is a backwards selection.
|
|
|
|
a = anchor
|
|
|
|
1 = old cursor
|
|
|
|
2 = new cursor
|
|
|
|
|
|
|
|
if (a <= 1 && 1 <=2) a,1,2 or (a1,2)
|
|
|
|
if (a < 2 && 1 > 2) a,2,1
|
|
|
|
if (1 < a && a <2) 1,a,2
|
|
|
|
if (a > 2 && 2 >1) 1,2,a
|
|
|
|
if (2 < a && a <1) 2,a,1
|
|
|
|
if (a > 1 && 1 >2) 2,1,a
|
|
|
|
then execute
|
|
|
|
a 1 2 select from 1 to 2
|
|
|
|
a 2 1 deselect from 2 to 1
|
|
|
|
1 a 2 deselect from 1 to a select from a to 2
|
|
|
|
1 2 a deselect from 1 to 2
|
|
|
|
2 1 a = continue selection from 2 to 1
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Extend extends the selection away from the anchor.
|
|
|
|
* We don't need to know the direction, because we always change the focus.
|
|
|
|
*/
|
|
|
|
NS_IMETHODIMP
|
2000-11-29 03:13:00 +03:00
|
|
|
nsTypedSelection::Extend(nsIDOMNode* aParentNode, PRInt32 aOffset)
|
2000-03-22 02:58:02 +03:00
|
|
|
{
|
|
|
|
if (!aParentNode)
|
|
|
|
return NS_ERROR_INVALID_ARG;
|
|
|
|
|
|
|
|
// First, find the range containing the old focus point:
|
2002-12-11 03:02:49 +03:00
|
|
|
if (!mAnchorFocusRange)
|
2000-03-22 02:58:02 +03:00
|
|
|
return NS_ERROR_NOT_INITIALIZED;
|
2002-03-26 02:44:46 +03:00
|
|
|
|
2006-04-14 04:28:22 +04:00
|
|
|
if (!mFrameSelection)
|
|
|
|
return NS_ERROR_NOT_INITIALIZED; // Can't do selection
|
|
|
|
|
2002-03-26 02:44:46 +03:00
|
|
|
nsresult res;
|
|
|
|
if (!IsValidSelectionPoint(mFrameSelection, aParentNode))
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
|
2000-03-22 02:58:02 +03:00
|
|
|
//mFrameSelection->InvalidateDesiredX();
|
|
|
|
nsCOMPtr<nsIDOMRange> difRange;
|
|
|
|
NS_NewRange(getter_AddRefs(difRange));
|
|
|
|
nsCOMPtr<nsIDOMRange> range;
|
2000-04-12 14:34:19 +04:00
|
|
|
|
|
|
|
if (FetchFocusNode() == aParentNode && FetchFocusOffset() == aOffset)
|
|
|
|
return NS_ERROR_FAILURE;//same node nothing to do!
|
|
|
|
|
2000-08-24 07:54:30 +04:00
|
|
|
res = mAnchorFocusRange->CloneRange(getter_AddRefs(range));
|
2000-03-22 02:58:02 +03:00
|
|
|
//range = mAnchorFocusRange;
|
|
|
|
|
|
|
|
nsCOMPtr<nsIDOMNode> startNode;
|
|
|
|
nsCOMPtr<nsIDOMNode> endNode;
|
|
|
|
PRInt32 startOffset;
|
|
|
|
PRInt32 endOffset;
|
|
|
|
|
2000-08-24 07:54:30 +04:00
|
|
|
range->GetStartContainer(getter_AddRefs(startNode));
|
|
|
|
range->GetEndContainer(getter_AddRefs(endNode));
|
2000-03-22 02:58:02 +03:00
|
|
|
range->GetStartOffset(&startOffset);
|
|
|
|
range->GetEndOffset(&endOffset);
|
|
|
|
|
|
|
|
|
|
|
|
nsDirection dir = GetDirection();
|
|
|
|
PRBool fixupState = PR_FALSE; //if there was a previous fixup the optimal drawing erasing will NOT work
|
|
|
|
if (NS_FAILED(res))
|
|
|
|
return res;
|
|
|
|
|
|
|
|
NS_NewRange(getter_AddRefs(difRange));
|
|
|
|
//compare anchor to old cursor.
|
|
|
|
|
|
|
|
if (NS_FAILED(res))
|
|
|
|
return res;
|
2006-10-21 05:30:54 +04:00
|
|
|
PRInt32 result1 = CompareDOMPoints(FetchAnchorNode(),
|
|
|
|
FetchAnchorOffset(),
|
|
|
|
FetchFocusNode(),
|
|
|
|
FetchFocusOffset());
|
2000-03-22 02:58:02 +03:00
|
|
|
//compare old cursor to new cursor
|
2006-10-21 05:30:54 +04:00
|
|
|
PRInt32 result2 = CompareDOMPoints(FetchFocusNode(),
|
|
|
|
FetchFocusOffset(),
|
|
|
|
aParentNode, aOffset);
|
2000-03-22 02:58:02 +03:00
|
|
|
//compare anchor to new cursor
|
2006-10-21 05:30:54 +04:00
|
|
|
PRInt32 result3 = CompareDOMPoints(FetchAnchorNode(),
|
|
|
|
FetchAnchorOffset(),
|
|
|
|
aParentNode, aOffset);
|
2000-03-22 02:58:02 +03:00
|
|
|
|
|
|
|
if (result2 == 0) //not selecting anywhere
|
|
|
|
return NS_OK;
|
|
|
|
|
2004-08-01 03:15:21 +04:00
|
|
|
nsCOMPtr<nsPresContext> presContext;
|
2000-03-22 02:58:02 +03:00
|
|
|
GetPresContext(getter_AddRefs(presContext));
|
|
|
|
if ((result1 == 0 && result3 < 0) || (result1 <= 0 && result2 < 0)){//a1,2 a,1,2
|
|
|
|
//select from 1 to 2 unless they are collapsed
|
|
|
|
res = range->SetEnd(aParentNode,aOffset);
|
|
|
|
if (NS_FAILED(res))
|
|
|
|
return res;
|
|
|
|
dir = eDirNext;
|
|
|
|
res = difRange->SetEnd(FetchEndParent(range), FetchEndOffset(range));
|
|
|
|
res |= difRange->SetStart(FetchFocusNode(), FetchFocusOffset());
|
|
|
|
if (NS_FAILED(res))
|
|
|
|
return res;
|
2001-05-04 03:59:55 +04:00
|
|
|
#ifdef OLD_SELECTION
|
2000-03-22 02:58:02 +03:00
|
|
|
res = FixupSelectionPoints(range, &dir, &fixupState);
|
|
|
|
#endif
|
|
|
|
if (NS_FAILED(res))
|
|
|
|
return res;
|
|
|
|
if (fixupState)
|
|
|
|
{
|
2001-05-04 03:59:55 +04:00
|
|
|
#ifdef OLD_SELECTION
|
2000-03-22 02:58:02 +03:00
|
|
|
selectFrames(mAnchorFocusRange, PR_FALSE);
|
|
|
|
selectFrames(range, PR_TRUE);
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
else{
|
|
|
|
selectFrames(presContext, difRange , PR_TRUE);
|
|
|
|
}
|
|
|
|
res = CopyRangeToAnchorFocus(range);
|
|
|
|
if (NS_FAILED(res))
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
else if (result1 == 0 && result3 > 0){//2, a1
|
|
|
|
//select from 2 to 1a
|
|
|
|
dir = eDirPrevious;
|
|
|
|
res = range->SetStart(aParentNode,aOffset);
|
|
|
|
if (NS_FAILED(res))
|
|
|
|
return res;
|
2001-05-04 03:59:55 +04:00
|
|
|
#ifdef OLD_SELECTION
|
2000-03-22 02:58:02 +03:00
|
|
|
res = FixupSelectionPoints(range, &dir, &fixupState);
|
|
|
|
if (NS_FAILED(res))
|
|
|
|
return res;
|
|
|
|
if (fixupState) //unselect previous and select new state has changed to not fixed up
|
|
|
|
{
|
|
|
|
selectFrames(mAnchorFocusRange, PR_FALSE);
|
|
|
|
selectFrames(range, PR_TRUE);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
#endif
|
|
|
|
selectFrames(presContext, range, PR_TRUE);
|
|
|
|
res = CopyRangeToAnchorFocus(range);
|
|
|
|
if (NS_FAILED(res))
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
else if (result3 <= 0 && result2 >= 0) {//a,2,1 or a2,1 or a,21 or a21
|
|
|
|
//deselect from 2 to 1
|
|
|
|
res = difRange->SetEnd(FetchFocusNode(), FetchFocusOffset());
|
|
|
|
res |= difRange->SetStart(aParentNode, aOffset);
|
|
|
|
if (NS_FAILED(res))
|
|
|
|
return res;
|
|
|
|
|
|
|
|
res = range->SetEnd(aParentNode,aOffset);
|
|
|
|
if (NS_FAILED(res))
|
|
|
|
return res;
|
2001-05-04 03:59:55 +04:00
|
|
|
#ifdef OLD_SELECTION
|
2000-03-22 02:58:02 +03:00
|
|
|
dir = eDirNext;
|
|
|
|
res = FixupSelectionPoints(range, &dir, &fixupState);
|
|
|
|
#endif
|
|
|
|
if (NS_FAILED(res))
|
|
|
|
return res;
|
|
|
|
if (fixupState) //unselect previous and select new state has changed to not fixed up
|
|
|
|
{
|
2001-05-04 03:59:55 +04:00
|
|
|
#ifdef OLD_SELECTION
|
2000-03-22 02:58:02 +03:00
|
|
|
selectFrames(mAnchorFocusRange, PR_FALSE);
|
|
|
|
selectFrames(range, PR_TRUE);
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
res = CopyRangeToAnchorFocus(range);
|
|
|
|
if (NS_FAILED(res))
|
|
|
|
return res;
|
2001-05-11 12:01:40 +04:00
|
|
|
RemoveItem(mAnchorFocusRange);
|
|
|
|
selectFrames(presContext, difRange, PR_FALSE);//deselect now if fixup succeeded
|
|
|
|
AddItem(mAnchorFocusRange);
|
2000-03-22 02:58:02 +03:00
|
|
|
difRange->SetEnd(FetchEndParent(range),FetchEndOffset(range));
|
|
|
|
selectFrames(presContext, difRange, PR_TRUE);//must reselect last node maybe more if fixup did something
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (result1 >= 0 && result3 <= 0) {//1,a,2 or 1a,2 or 1,a2 or 1a2
|
|
|
|
if (GetDirection() == eDirPrevious){
|
|
|
|
res = range->SetStart(endNode,endOffset);
|
|
|
|
if (NS_FAILED(res))
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
dir = eDirNext;
|
|
|
|
res = range->SetEnd(aParentNode,aOffset);
|
|
|
|
if (NS_FAILED(res))
|
|
|
|
return res;
|
2001-05-04 03:59:55 +04:00
|
|
|
#ifdef OLD_SELECTION
|
2000-03-22 02:58:02 +03:00
|
|
|
res = FixupSelectionPoints(range, &dir, &fixupState);
|
|
|
|
if (NS_FAILED(res))
|
|
|
|
return res;
|
|
|
|
|
|
|
|
if (fixupState) //unselect previous and select new state has changed to not fixed up
|
|
|
|
{
|
|
|
|
selectFrames(mAnchorFocusRange, PR_FALSE);
|
|
|
|
selectFrames(range, PR_TRUE);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
#endif
|
|
|
|
{
|
|
|
|
if (FetchFocusNode() != FetchAnchorNode() || FetchFocusOffset() != FetchAnchorOffset() ){//if collapsed diff dont do anything
|
|
|
|
res = difRange->SetStart(FetchFocusNode(), FetchFocusOffset());
|
|
|
|
res |= difRange->SetEnd(FetchAnchorNode(), FetchAnchorOffset());
|
|
|
|
if (NS_FAILED(res))
|
|
|
|
return res;
|
|
|
|
res = CopyRangeToAnchorFocus(range);
|
|
|
|
if (NS_FAILED(res))
|
|
|
|
return res;
|
|
|
|
//deselect from 1 to a
|
2001-05-11 12:01:40 +04:00
|
|
|
RemoveItem(mAnchorFocusRange);
|
2000-03-22 02:58:02 +03:00
|
|
|
selectFrames(presContext, difRange , PR_FALSE);
|
2001-05-11 12:01:40 +04:00
|
|
|
AddItem(mAnchorFocusRange);
|
2000-03-22 02:58:02 +03:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
res = CopyRangeToAnchorFocus(range);
|
|
|
|
if (NS_FAILED(res))
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
//select from a to 2
|
|
|
|
selectFrames(presContext, range , PR_TRUE);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (result2 <= 0 && result3 >= 0) {//1,2,a or 12,a or 1,2a or 12a
|
|
|
|
//deselect from 1 to 2
|
|
|
|
res = difRange->SetEnd(aParentNode, aOffset);
|
|
|
|
res |= difRange->SetStart(FetchFocusNode(), FetchFocusOffset());
|
|
|
|
if (NS_FAILED(res))
|
|
|
|
return res;
|
|
|
|
dir = eDirPrevious;
|
|
|
|
res = range->SetStart(aParentNode,aOffset);
|
|
|
|
if (NS_FAILED(res))
|
|
|
|
return res;
|
|
|
|
|
2001-05-04 03:59:55 +04:00
|
|
|
#ifdef OLD_SELECTION
|
2000-03-22 02:58:02 +03:00
|
|
|
res = FixupSelectionPoints(range, &dir, &fixupState);
|
|
|
|
#endif
|
|
|
|
if (NS_FAILED(res))
|
|
|
|
return res;
|
|
|
|
if (fixupState) //unselect previous and select new state has changed to not fixed up
|
|
|
|
{
|
2001-05-04 03:59:55 +04:00
|
|
|
#ifdef OLD_SELECTION
|
2000-03-22 02:58:02 +03:00
|
|
|
selectFrames(mAnchorFocusRange, PR_FALSE);
|
|
|
|
selectFrames(range, PR_TRUE);
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
res = CopyRangeToAnchorFocus(range);
|
|
|
|
if (NS_FAILED(res))
|
|
|
|
return res;
|
2001-05-11 12:01:40 +04:00
|
|
|
RemoveItem(mAnchorFocusRange);
|
2000-03-22 02:58:02 +03:00
|
|
|
selectFrames(presContext, difRange , PR_FALSE);
|
2001-05-11 12:01:40 +04:00
|
|
|
AddItem(mAnchorFocusRange);
|
2000-03-22 02:58:02 +03:00
|
|
|
difRange->SetStart(FetchStartParent(range),FetchStartOffset(range));
|
|
|
|
selectFrames(presContext, difRange, PR_TRUE);//must reselect last node
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (result3 >= 0 && result1 <= 0) {//2,a,1 or 2a,1 or 2,a1 or 2a1
|
|
|
|
if (GetDirection() == eDirNext){
|
|
|
|
range->SetEnd(startNode,startOffset);
|
|
|
|
}
|
|
|
|
dir = eDirPrevious;
|
|
|
|
res = range->SetStart(aParentNode,aOffset);
|
|
|
|
if (NS_FAILED(res))
|
|
|
|
return res;
|
2001-05-04 03:59:55 +04:00
|
|
|
#ifdef OLD_SELECTION
|
2000-03-22 02:58:02 +03:00
|
|
|
res = FixupSelectionPoints(range, &dir, &fixupState);
|
|
|
|
if (NS_FAILED(res))
|
|
|
|
return res;
|
|
|
|
if (fixupState) //unselect previous and select new state has changed to not fixed up
|
|
|
|
{
|
|
|
|
selectFrames(mAnchorFocusRange, PR_FALSE);
|
|
|
|
selectFrames(range, PR_TRUE);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
#endif
|
|
|
|
{
|
|
|
|
//deselect from a to 1
|
|
|
|
if (FetchFocusNode() != FetchAnchorNode() || FetchFocusOffset() != FetchAnchorOffset() ){//if collapsed diff dont do anything
|
|
|
|
res = difRange->SetStart(FetchAnchorNode(), FetchAnchorOffset());
|
|
|
|
res |= difRange->SetEnd(FetchFocusNode(), FetchFocusOffset());
|
|
|
|
res = CopyRangeToAnchorFocus(range);
|
|
|
|
if (NS_FAILED(res))
|
|
|
|
return res;
|
2001-05-11 12:01:40 +04:00
|
|
|
RemoveItem(mAnchorFocusRange);
|
2000-03-22 02:58:02 +03:00
|
|
|
selectFrames(presContext, difRange, 0);
|
2001-05-11 12:01:40 +04:00
|
|
|
AddItem(mAnchorFocusRange);
|
2000-03-22 02:58:02 +03:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
res = CopyRangeToAnchorFocus(range);
|
|
|
|
if (NS_FAILED(res))
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
//select from 2 to a
|
|
|
|
selectFrames(presContext, range , PR_TRUE);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (result2 >= 0 && result1 >= 0) {//2,1,a or 21,a or 2,1a or 21a
|
|
|
|
//select from 2 to 1
|
|
|
|
res = range->SetStart(aParentNode,aOffset);
|
|
|
|
if (NS_FAILED(res))
|
|
|
|
return res;
|
|
|
|
dir = eDirPrevious;
|
|
|
|
res = difRange->SetEnd(FetchFocusNode(), FetchFocusOffset());
|
|
|
|
res |= difRange->SetStart(FetchStartParent(range), FetchStartOffset(range));
|
|
|
|
if (NS_FAILED(res))
|
|
|
|
return res;
|
|
|
|
|
2001-05-04 03:59:55 +04:00
|
|
|
#ifdef OLD_SELECTION
|
2000-03-22 02:58:02 +03:00
|
|
|
res = FixupSelectionPoints(range, &dir, &fixupState);
|
|
|
|
#endif
|
|
|
|
if (NS_FAILED(res))
|
|
|
|
return res;
|
|
|
|
if (fixupState) //unselect previous and select new state has changed to not fixed up
|
|
|
|
{
|
2001-05-04 03:59:55 +04:00
|
|
|
#ifdef OLD_SELECTION
|
2000-03-22 02:58:02 +03:00
|
|
|
selectFrames(mAnchorFocusRange, PR_FALSE);
|
|
|
|
selectFrames(range, PR_TRUE);
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
selectFrames(presContext, difRange, PR_TRUE);
|
|
|
|
}
|
|
|
|
res = CopyRangeToAnchorFocus(range);
|
|
|
|
if (NS_FAILED(res))
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
|
|
|
DEBUG_OUT_RANGE(range);
|
|
|
|
#if 0
|
|
|
|
if (eDirNext == mDirection)
|
2000-10-29 02:17:53 +04:00
|
|
|
printf(" direction = 1 LEFT TO RIGHT\n");
|
2000-03-22 02:58:02 +03:00
|
|
|
else
|
2000-10-29 02:17:53 +04:00
|
|
|
printf(" direction = 0 RIGHT TO LEFT\n");
|
2000-03-22 02:58:02 +03:00
|
|
|
#endif
|
|
|
|
SetDirection(dir);
|
|
|
|
#ifdef DEBUG_SELECTION
|
|
|
|
if (aParentNode)
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsIContent>content;
|
|
|
|
content = do_QueryInterface(aParentNode);
|
2003-11-19 04:20:56 +03:00
|
|
|
|
|
|
|
const char *tagString;
|
|
|
|
content->Tag()->GetUTF8String(&tagString);
|
2005-10-17 04:51:46 +04:00
|
|
|
printf ("Sel. Extend to %p %s %d\n", content.get(), tagString, aOffset);
|
2000-03-22 02:58:02 +03:00
|
|
|
}
|
|
|
|
else {
|
2000-10-29 02:17:53 +04:00
|
|
|
printf ("Sel. Extend set to null parent.\n");
|
2000-03-22 02:58:02 +03:00
|
|
|
}
|
|
|
|
#endif
|
2000-05-11 08:25:43 +04:00
|
|
|
if (!mFrameSelection)
|
|
|
|
return NS_OK;//nothing to do
|
2000-04-14 15:21:19 +04:00
|
|
|
return mFrameSelection->NotifySelectionListeners(GetType());
|
2000-03-22 02:58:02 +03:00
|
|
|
}
|
|
|
|
|
2003-09-27 08:18:26 +04:00
|
|
|
static nsresult
|
|
|
|
GetChildOffset(nsIDOMNode *aChild, nsIDOMNode *aParent, PRInt32 &aOffset)
|
2000-09-13 00:54:41 +04:00
|
|
|
{
|
|
|
|
NS_ASSERTION((aChild && aParent), "bad args");
|
|
|
|
nsCOMPtr<nsIContent> content = do_QueryInterface(aParent);
|
|
|
|
nsCOMPtr<nsIContent> cChild = do_QueryInterface(aChild);
|
2003-09-27 08:18:26 +04:00
|
|
|
|
|
|
|
if (!cChild || !content)
|
|
|
|
return NS_ERROR_NULL_POINTER;
|
|
|
|
|
|
|
|
aOffset = content->IndexOf(cChild);
|
|
|
|
|
|
|
|
return NS_OK;
|
2000-09-13 00:54:41 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2000-11-29 03:13:00 +03:00
|
|
|
nsTypedSelection::SelectAllChildren(nsIDOMNode* aParentNode)
|
2000-09-13 00:54:41 +04:00
|
|
|
{
|
|
|
|
NS_ENSURE_ARG_POINTER(aParentNode);
|
|
|
|
|
|
|
|
if (mFrameSelection)
|
|
|
|
{
|
2000-09-14 15:45:01 +04:00
|
|
|
mFrameSelection->PostReason(nsISelectionListener::SELECTALL_REASON);
|
2000-09-13 00:54:41 +04:00
|
|
|
}
|
|
|
|
nsresult result = Collapse(aParentNode, 0);
|
|
|
|
if (NS_SUCCEEDED(result))
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsIDOMNode>lastChild;
|
|
|
|
result = aParentNode->GetLastChild(getter_AddRefs(lastChild));
|
|
|
|
if ((NS_SUCCEEDED(result)) && lastChild)
|
|
|
|
{
|
|
|
|
PRInt32 numBodyChildren=0;
|
|
|
|
GetChildOffset(lastChild, aParentNode, numBodyChildren);
|
|
|
|
if (mFrameSelection)
|
|
|
|
{
|
2000-09-14 15:45:01 +04:00
|
|
|
mFrameSelection->PostReason(nsISelectionListener::SELECTALL_REASON);
|
2000-09-13 00:54:41 +04:00
|
|
|
}
|
|
|
|
result = Extend(aParentNode, numBodyChildren+1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2000-03-22 02:58:02 +03:00
|
|
|
NS_IMETHODIMP
|
2006-07-27 21:57:15 +04:00
|
|
|
nsTypedSelection::ContainsNode(nsIDOMNode* aNode, PRBool aAllowPartial,
|
|
|
|
PRBool* aYes)
|
2000-03-22 02:58:02 +03:00
|
|
|
{
|
2006-07-27 21:57:15 +04:00
|
|
|
nsresult rv;
|
2000-03-22 02:58:02 +03:00
|
|
|
if (!aYes)
|
|
|
|
return NS_ERROR_NULL_POINTER;
|
2006-07-27 21:57:15 +04:00
|
|
|
NS_ASSERTION(ValidateRanges(), "Ranges out of sync");
|
2000-03-22 02:58:02 +03:00
|
|
|
*aYes = PR_FALSE;
|
|
|
|
|
2006-08-03 23:22:50 +04:00
|
|
|
if (mRanges.Length() == 0 || !aNode)
|
2006-07-27 21:57:15 +04:00
|
|
|
return NS_OK;
|
|
|
|
|
|
|
|
PRUint16 nodeType;
|
|
|
|
aNode->GetNodeType(&nodeType);
|
|
|
|
PRUint32 nodeLength;
|
|
|
|
if (nodeType == nsIDOMNode::TEXT_NODE) {
|
|
|
|
nsAutoString nodeValue;
|
|
|
|
rv = aNode->GetNodeValue(nodeValue);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
nodeLength = nodeValue.Length();
|
|
|
|
} else {
|
|
|
|
nsCOMPtr<nsIDOMNodeList> aChildNodes;
|
|
|
|
rv = aNode->GetChildNodes(getter_AddRefs(aChildNodes));
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
rv = aChildNodes->GetLength(&nodeLength);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
}
|
|
|
|
|
|
|
|
nsCOMArray<nsIDOMRange> overlappingRanges;
|
|
|
|
rv = GetRangesForIntervalCOMArray(aNode, 0, aNode, nodeLength,
|
|
|
|
PR_FALSE, &overlappingRanges);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
if (overlappingRanges.Count() == 0)
|
|
|
|
return NS_OK; // no ranges overlap
|
|
|
|
|
|
|
|
// if the caller said partial intersections are OK, we're done
|
|
|
|
if (aAllowPartial) {
|
|
|
|
*aYes = PR_TRUE;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
2000-08-29 10:37:12 +04:00
|
|
|
|
2006-07-27 21:57:15 +04:00
|
|
|
// text nodes always count as inside
|
|
|
|
if (nodeType == nsIDOMNode::TEXT_NODE) {
|
|
|
|
*aYes = PR_TRUE;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
2000-03-22 02:58:02 +03:00
|
|
|
|
2006-07-27 21:57:15 +04:00
|
|
|
// The caller wants to know if the node is entirely within the given range,
|
|
|
|
// so we have to check all intersecting ranges.
|
|
|
|
nsCOMPtr<nsIContent> content (do_QueryInterface(aNode, &rv));
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
for (PRInt32 i = 0; i < overlappingRanges.Count(); i ++) {
|
|
|
|
PRBool nodeStartsBeforeRange, nodeEndsAfterRange;
|
|
|
|
if (NS_SUCCEEDED(nsRange::CompareNodeToRange(content, overlappingRanges[i],
|
|
|
|
&nodeStartsBeforeRange,
|
|
|
|
&nodeEndsAfterRange))) {
|
|
|
|
if (!nodeStartsBeforeRange && !nodeEndsAfterRange) {
|
|
|
|
*aYes = PR_TRUE;
|
|
|
|
return NS_OK;
|
2000-03-22 02:58:02 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2000-08-29 03:35:57 +04:00
|
|
|
|
2000-03-22 02:58:02 +03:00
|
|
|
nsresult
|
2004-08-01 03:15:21 +04:00
|
|
|
nsTypedSelection::GetPresContext(nsPresContext **aPresContext)
|
2000-03-22 02:58:02 +03:00
|
|
|
{
|
2000-05-11 08:25:43 +04:00
|
|
|
if (!mFrameSelection)
|
|
|
|
return NS_ERROR_FAILURE;//nothing to do
|
2004-09-01 09:16:00 +04:00
|
|
|
nsIPresShell *shell = mFrameSelection->GetShell();
|
2000-03-22 02:58:02 +03:00
|
|
|
|
2004-09-01 09:16:00 +04:00
|
|
|
if (!shell)
|
2000-03-22 02:58:02 +03:00
|
|
|
return NS_ERROR_NULL_POINTER;
|
|
|
|
|
2004-09-01 09:16:00 +04:00
|
|
|
NS_IF_ADDREF(*aPresContext = shell->GetPresContext());
|
|
|
|
return NS_OK;
|
2000-03-22 02:58:02 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
2000-11-29 03:13:00 +03:00
|
|
|
nsTypedSelection::GetPresShell(nsIPresShell **aPresShell)
|
2000-03-22 02:58:02 +03:00
|
|
|
{
|
2000-05-13 12:07:34 +04:00
|
|
|
if (mPresShellWeak)
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsIPresShell> presShell = do_QueryReferent(mPresShellWeak);
|
|
|
|
if (presShell)
|
|
|
|
NS_ADDREF(*aPresShell = presShell);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
2000-03-22 02:58:02 +03:00
|
|
|
nsresult rv = NS_OK;
|
2000-05-11 08:25:43 +04:00
|
|
|
if (!mFrameSelection)
|
|
|
|
return NS_ERROR_FAILURE;//nothing to do
|
2000-03-22 02:58:02 +03:00
|
|
|
|
2004-09-01 09:16:00 +04:00
|
|
|
nsIPresShell *shell = mFrameSelection->GetShell();
|
2000-03-22 02:58:02 +03:00
|
|
|
|
2003-07-25 23:06:59 +04:00
|
|
|
mPresShellWeak = do_GetWeakReference(shell); // the presshell owns us, so no addref
|
2000-05-13 12:07:34 +04:00
|
|
|
if (mPresShellWeak)
|
|
|
|
NS_ADDREF(*aPresShell = shell);
|
2000-03-22 02:58:02 +03:00
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
2000-11-29 03:13:00 +03:00
|
|
|
nsTypedSelection::GetRootScrollableView(nsIScrollableView **aScrollableView)
|
2000-03-22 02:58:02 +03:00
|
|
|
{
|
|
|
|
//
|
|
|
|
// NOTE: This method returns a NON-AddRef'd pointer
|
|
|
|
// to the scrollable view!
|
|
|
|
//
|
2000-05-13 12:07:34 +04:00
|
|
|
NS_ENSURE_ARG_POINTER(aScrollableView);
|
|
|
|
|
2000-05-11 08:25:43 +04:00
|
|
|
if (!mFrameSelection)
|
|
|
|
return NS_ERROR_FAILURE;//nothing to do
|
2006-05-04 01:39:55 +04:00
|
|
|
|
2006-04-26 06:01:07 +04:00
|
|
|
nsIScrollableView *scrollView = mFrameSelection->GetScrollableView();
|
2000-05-13 12:07:34 +04:00
|
|
|
if (!scrollView)
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsIPresShell> presShell;
|
2000-03-22 02:58:02 +03:00
|
|
|
|
2006-05-04 01:39:55 +04:00
|
|
|
nsresult rv = GetPresShell(getter_AddRefs(presShell));
|
2000-03-22 02:58:02 +03:00
|
|
|
|
2000-05-13 12:07:34 +04:00
|
|
|
if (NS_FAILED(rv))
|
|
|
|
return rv;
|
2000-03-22 02:58:02 +03:00
|
|
|
|
2000-05-13 12:07:34 +04:00
|
|
|
if (!presShell)
|
|
|
|
return NS_ERROR_NULL_POINTER;
|
2000-03-22 02:58:02 +03:00
|
|
|
|
2003-08-06 07:07:12 +04:00
|
|
|
nsIViewManager* viewManager = presShell->GetViewManager();
|
2000-03-22 02:58:02 +03:00
|
|
|
|
2000-05-13 12:07:34 +04:00
|
|
|
if (!viewManager)
|
|
|
|
return NS_ERROR_NULL_POINTER;
|
2000-03-22 02:58:02 +03:00
|
|
|
|
2000-05-13 12:07:34 +04:00
|
|
|
//
|
|
|
|
// nsIViewManager::GetRootScrollableView() does not
|
|
|
|
// AddRef the pointer it returns.
|
|
|
|
//
|
|
|
|
return viewManager->GetRootScrollableView(aScrollableView);
|
|
|
|
}
|
2001-05-11 17:25:38 +04:00
|
|
|
|
2006-05-04 01:39:55 +04:00
|
|
|
*aScrollableView = scrollView;
|
|
|
|
return NS_OK;
|
2000-03-22 02:58:02 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
2000-11-29 03:13:00 +03:00
|
|
|
nsTypedSelection::GetFrameToScrolledViewOffsets(nsIScrollableView *aScrollableView, nsIFrame *aFrame, nscoord *aX, nscoord *aY)
|
2000-03-22 02:58:02 +03:00
|
|
|
{
|
|
|
|
nsresult rv = NS_OK;
|
2000-05-11 08:25:43 +04:00
|
|
|
if (!mFrameSelection)
|
|
|
|
return NS_ERROR_FAILURE;//nothing to do
|
2000-03-22 02:58:02 +03:00
|
|
|
|
2000-08-30 23:42:47 +04:00
|
|
|
if (!aScrollableView || !aFrame || !aX || !aY) {
|
2000-03-22 02:58:02 +03:00
|
|
|
return NS_ERROR_NULL_POINTER;
|
|
|
|
}
|
|
|
|
|
|
|
|
*aX = 0;
|
|
|
|
*aY = 0;
|
|
|
|
|
|
|
|
nsIView* scrolledView;
|
|
|
|
nsPoint offset;
|
|
|
|
nsIView* closestView;
|
|
|
|
|
|
|
|
// Determine the offset from aFrame to the scrolled view. We do that by
|
|
|
|
// getting the offset from its closest view and then walking up
|
2000-08-30 23:42:47 +04:00
|
|
|
aScrollableView->GetScrolledView(scrolledView);
|
2004-09-01 09:16:00 +04:00
|
|
|
nsIPresShell *shell = mFrameSelection->GetShell();
|
2000-03-22 02:58:02 +03:00
|
|
|
|
2004-09-01 09:16:00 +04:00
|
|
|
if (!shell)
|
2000-03-22 02:58:02 +03:00
|
|
|
return NS_ERROR_NULL_POINTER;
|
|
|
|
|
2004-12-26 22:48:54 +03:00
|
|
|
aFrame->GetOffsetFromView(offset, &closestView);
|
2000-03-22 02:58:02 +03:00
|
|
|
|
|
|
|
// XXX Deal with the case where there is a scrolled element, e.g., a
|
|
|
|
// DIV in the middle...
|
2004-11-03 19:16:57 +03:00
|
|
|
offset += closestView->GetOffsetTo(scrolledView);
|
2000-03-22 02:58:02 +03:00
|
|
|
|
|
|
|
*aX = offset.x;
|
|
|
|
*aY = offset.y;
|
|
|
|
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
2000-11-29 03:13:00 +03:00
|
|
|
nsTypedSelection::GetPointFromOffset(nsIFrame *aFrame, PRInt32 aContentOffset, nsPoint *aPoint)
|
2000-03-22 02:58:02 +03:00
|
|
|
{
|
|
|
|
nsresult rv = NS_OK;
|
2000-05-11 08:25:43 +04:00
|
|
|
if (!mFrameSelection)
|
|
|
|
return NS_ERROR_FAILURE;//nothing to do
|
2000-03-22 02:58:02 +03:00
|
|
|
if (!aFrame || !aPoint)
|
|
|
|
return NS_ERROR_NULL_POINTER;
|
|
|
|
|
|
|
|
aPoint->x = 0;
|
|
|
|
aPoint->y = 0;
|
|
|
|
|
|
|
|
//
|
|
|
|
// Retrieve the device context. We need one to create
|
|
|
|
// a rendering context.
|
|
|
|
//
|
|
|
|
|
2004-09-01 09:16:00 +04:00
|
|
|
nsIPresShell *shell = mFrameSelection->GetShell();
|
|
|
|
if (!shell)
|
2000-03-22 02:58:02 +03:00
|
|
|
return NS_ERROR_NULL_POINTER;
|
|
|
|
|
2004-09-01 09:16:00 +04:00
|
|
|
nsPresContext *presContext = shell->GetPresContext();
|
2000-03-22 02:58:02 +03:00
|
|
|
if (!presContext)
|
|
|
|
return NS_ERROR_NULL_POINTER;
|
|
|
|
|
|
|
|
//
|
|
|
|
// Now get the closest view with a widget so we can create
|
|
|
|
// a rendering context.
|
|
|
|
//
|
|
|
|
|
2003-08-06 07:07:12 +04:00
|
|
|
nsIWidget* widget = nsnull;
|
|
|
|
nsIView *closestView = nsnull;
|
2000-03-22 02:58:02 +03:00
|
|
|
nsPoint offset(0, 0);
|
|
|
|
|
2004-12-26 22:48:54 +03:00
|
|
|
rv = aFrame->GetOffsetFromView(offset, &closestView);
|
2000-03-22 02:58:02 +03:00
|
|
|
|
|
|
|
while (!widget && closestView)
|
|
|
|
{
|
2003-08-06 07:07:12 +04:00
|
|
|
widget = closestView->GetWidget();
|
2000-03-22 02:58:02 +03:00
|
|
|
|
|
|
|
if (!widget)
|
|
|
|
{
|
2003-08-06 07:07:12 +04:00
|
|
|
closestView = closestView->GetParent();
|
2000-03-22 02:58:02 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!closestView)
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
|
|
|
|
//
|
|
|
|
// Create a rendering context. This context is used by text frames
|
|
|
|
// to calculate text widths so it can figure out where the point is
|
|
|
|
// in the frame.
|
|
|
|
//
|
|
|
|
|
2003-03-12 06:22:11 +03:00
|
|
|
nsCOMPtr<nsIRenderingContext> rendContext;
|
2000-03-22 02:58:02 +03:00
|
|
|
|
2004-02-03 01:17:21 +03:00
|
|
|
rv = presContext->DeviceContext()->
|
|
|
|
CreateRenderingContext(closestView, *getter_AddRefs(rendContext));
|
2000-03-22 02:58:02 +03:00
|
|
|
|
2003-03-12 06:22:11 +03:00
|
|
|
if (NS_FAILED(rv))
|
|
|
|
return rv;
|
2000-03-22 02:58:02 +03:00
|
|
|
|
|
|
|
if (!rendContext)
|
2003-03-12 06:22:11 +03:00
|
|
|
return NS_ERROR_NULL_POINTER;
|
2000-03-22 02:58:02 +03:00
|
|
|
|
|
|
|
//
|
|
|
|
// Now get the point and return!
|
|
|
|
//
|
|
|
|
|
2003-03-12 06:22:11 +03:00
|
|
|
rv = aFrame->GetPointFromOffset(presContext, rendContext, aContentOffset, aPoint);
|
2000-03-22 02:58:02 +03:00
|
|
|
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
2000-11-29 03:13:00 +03:00
|
|
|
nsTypedSelection::GetSelectionRegionRectAndScrollableView(SelectionRegion aRegion, nsRect *aRect, nsIScrollableView **aScrollableView)
|
2000-03-22 02:58:02 +03:00
|
|
|
{
|
2000-05-11 08:25:43 +04:00
|
|
|
if (!mFrameSelection)
|
2006-11-09 19:37:10 +03:00
|
|
|
return NS_ERROR_FAILURE; // nothing to do
|
2000-03-22 02:58:02 +03:00
|
|
|
|
2006-11-09 19:37:10 +03:00
|
|
|
NS_ENSURE_TRUE(aRect && aScrollableView, NS_ERROR_NULL_POINTER);
|
2000-03-22 02:58:02 +03:00
|
|
|
|
2006-11-09 19:37:10 +03:00
|
|
|
aRect->SetRect(0, 0, 0, 0);
|
|
|
|
*aScrollableView = nsnull;
|
2000-03-22 02:58:02 +03:00
|
|
|
|
2006-11-09 19:37:10 +03:00
|
|
|
nsIDOMNode *node = nsnull;
|
2000-03-22 02:58:02 +03:00
|
|
|
PRInt32 nodeOffset = 0;
|
2006-11-09 19:37:10 +03:00
|
|
|
nsIFrame *frame = nsnull;
|
2000-03-22 02:58:02 +03:00
|
|
|
|
2006-11-09 19:37:10 +03:00
|
|
|
switch (aRegion) {
|
|
|
|
case nsISelectionController::SELECTION_ANCHOR_REGION:
|
|
|
|
node = FetchAnchorNode();
|
|
|
|
nodeOffset = FetchAnchorOffset();
|
|
|
|
break;
|
|
|
|
case nsISelectionController::SELECTION_FOCUS_REGION:
|
|
|
|
node = FetchFocusNode();
|
|
|
|
nodeOffset = FetchFocusOffset();
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
return NS_ERROR_FAILURE;
|
2000-03-22 02:58:02 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!node)
|
|
|
|
return NS_ERROR_NULL_POINTER;
|
|
|
|
|
|
|
|
nsCOMPtr<nsIContent> content = do_QueryInterface(node);
|
2006-11-09 19:37:10 +03:00
|
|
|
NS_ENSURE_TRUE(content.get(), NS_ERROR_FAILURE);
|
2000-03-22 02:58:02 +03:00
|
|
|
PRInt32 frameOffset = 0;
|
2006-11-09 19:37:10 +03:00
|
|
|
frame = mFrameSelection->GetFrameForNodeOffset(content, nodeOffset,
|
|
|
|
mFrameSelection->GetHint(),
|
|
|
|
&frameOffset);
|
2000-03-22 02:58:02 +03:00
|
|
|
if (!frame)
|
2000-08-30 23:42:47 +04:00
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
|
2006-11-09 19:37:10 +03:00
|
|
|
// Get the frame's nearest scrollable view.
|
|
|
|
nsIFrame* parentWithView = frame->GetAncestorWithView();
|
2000-08-30 23:42:47 +04:00
|
|
|
if (!parentWithView)
|
|
|
|
return NS_ERROR_FAILURE;
|
2003-08-06 07:07:12 +04:00
|
|
|
nsIView* view = parentWithView->GetView();
|
2004-09-21 08:41:08 +04:00
|
|
|
*aScrollableView =
|
|
|
|
nsLayoutUtils::GetNearestScrollingView(view, nsLayoutUtils::eEither);
|
2000-08-30 23:42:47 +04:00
|
|
|
if (!*aScrollableView)
|
|
|
|
return NS_OK;
|
|
|
|
|
|
|
|
// Figure out what node type we have, then get the
|
|
|
|
// appropriate rect for it's nodeOffset.
|
2000-03-22 02:58:02 +03:00
|
|
|
PRUint16 nodeType = nsIDOMNode::ELEMENT_NODE;
|
2006-11-09 19:37:10 +03:00
|
|
|
nsresult rv = node->GetNodeType(&nodeType);
|
|
|
|
if (NS_FAILED(rv))
|
|
|
|
return rv;
|
2000-03-22 02:58:02 +03:00
|
|
|
|
2006-11-09 19:37:10 +03:00
|
|
|
nsPoint pt(0, 0);
|
|
|
|
if (nodeType == nsIDOMNode::TEXT_NODE) {
|
|
|
|
nsIFrame* childFrame = nsnull;
|
|
|
|
frameOffset = 0;
|
|
|
|
rv = frame->GetChildFrameContainingOffset(nodeOffset,
|
|
|
|
mFrameSelection->GetHint(),
|
|
|
|
&frameOffset, &childFrame);
|
|
|
|
if (NS_FAILED(rv))
|
|
|
|
return rv;
|
2000-03-22 02:58:02 +03:00
|
|
|
if (!childFrame)
|
|
|
|
return NS_ERROR_NULL_POINTER;
|
|
|
|
|
|
|
|
frame = childFrame;
|
|
|
|
|
|
|
|
// Get the x coordinate of the offset into the text frame.
|
2006-11-09 19:37:10 +03:00
|
|
|
rv = GetCachedFrameOffset(frame, nodeOffset, pt);
|
|
|
|
if (NS_FAILED(rv))
|
|
|
|
return rv;
|
|
|
|
}
|
2000-03-22 02:58:02 +03:00
|
|
|
|
2006-11-09 19:37:10 +03:00
|
|
|
// Get the frame's rect in scroll view coordinates.
|
|
|
|
*aRect = frame->GetRect();
|
|
|
|
rv = GetFrameToScrolledViewOffsets(*aScrollableView, frame, &aRect->x,
|
|
|
|
&aRect->y);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2000-03-22 02:58:02 +03:00
|
|
|
|
2006-11-09 19:37:10 +03:00
|
|
|
if (nodeType == nsIDOMNode::TEXT_NODE) {
|
2000-03-22 02:58:02 +03:00
|
|
|
aRect->x += pt.x;
|
2006-11-09 19:37:10 +03:00
|
|
|
}
|
|
|
|
else if (mFrameSelection->GetHint() == nsFrameSelection::HINTLEFT) {
|
|
|
|
// It's the frame's right edge we're interested in.
|
|
|
|
aRect->x += aRect->width;
|
|
|
|
}
|
2000-03-22 02:58:02 +03:00
|
|
|
|
2006-11-09 19:37:10 +03:00
|
|
|
nsRect clipRect = (*aScrollableView)->View()->GetBounds();
|
|
|
|
rv = (*aScrollableView)->GetScrollPosition(clipRect.x, clipRect.y);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2000-03-22 02:58:02 +03:00
|
|
|
|
2006-11-09 19:37:10 +03:00
|
|
|
// If the point we are interested in is outside the clip region, we aim
|
|
|
|
// to over-scroll it by a quarter of the clip's width.
|
|
|
|
PRInt32 pad = clipRect.width >> 2;
|
2000-03-22 02:58:02 +03:00
|
|
|
|
2006-11-09 19:37:10 +03:00
|
|
|
if (pad <= 0)
|
|
|
|
pad = 3; // Arbitrary
|
2000-03-22 02:58:02 +03:00
|
|
|
|
2006-11-09 19:37:10 +03:00
|
|
|
if (aRect->x >= clipRect.XMost()) {
|
|
|
|
aRect->width = pad;
|
2000-03-22 02:58:02 +03:00
|
|
|
}
|
2006-11-09 19:37:10 +03:00
|
|
|
else if (aRect->x <= clipRect.x) {
|
|
|
|
aRect->x -= pad;
|
|
|
|
aRect->width = pad;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
aRect->width = 60; // Arbitrary
|
2000-03-22 02:58:02 +03:00
|
|
|
}
|
|
|
|
|
2006-11-09 19:37:10 +03:00
|
|
|
return rv;
|
2000-03-22 02:58:02 +03:00
|
|
|
}
|
|
|
|
|
2006-03-23 03:13:07 +03:00
|
|
|
static void
|
|
|
|
ClampPointInsideRect(nsPoint& aPoint, const nsRect& aRect)
|
|
|
|
{
|
|
|
|
if (aPoint.x < aRect.x)
|
|
|
|
aPoint.x = aRect.x;
|
|
|
|
if (aPoint.x > aRect.XMost())
|
|
|
|
aPoint.x = aRect.XMost();
|
|
|
|
if (aPoint.y < aRect.y)
|
|
|
|
aPoint.y = aRect.y;
|
|
|
|
if (aPoint.y > aRect.YMost())
|
|
|
|
aPoint.y = aRect.YMost();
|
|
|
|
}
|
|
|
|
|
2000-03-22 02:58:02 +03:00
|
|
|
nsresult
|
2000-11-29 03:13:00 +03:00
|
|
|
nsTypedSelection::ScrollRectIntoView(nsIScrollableView *aScrollableView,
|
2000-08-30 23:42:47 +04:00
|
|
|
nsRect& aRect,
|
2000-03-22 02:58:02 +03:00
|
|
|
PRIntn aVPercent,
|
2000-08-30 23:42:47 +04:00
|
|
|
PRIntn aHPercent,
|
|
|
|
PRBool aScrollParentViews)
|
2000-03-22 02:58:02 +03:00
|
|
|
{
|
|
|
|
nsresult rv = NS_OK;
|
2000-05-11 08:25:43 +04:00
|
|
|
if (!mFrameSelection)
|
|
|
|
return NS_OK;//nothing to do
|
2000-03-22 02:58:02 +03:00
|
|
|
|
2000-08-30 23:42:47 +04:00
|
|
|
if (!aScrollableView)
|
2000-03-22 02:58:02 +03:00
|
|
|
return NS_ERROR_NULL_POINTER;
|
|
|
|
|
|
|
|
// Determine the visible rect in the scrolled view's coordinate space.
|
|
|
|
// The size of the visible area is the clip view size
|
2004-09-21 02:25:07 +04:00
|
|
|
nsRect visibleRect = aScrollableView->View()->GetBounds();
|
2001-12-01 17:31:45 +03:00
|
|
|
aScrollableView->GetScrollPosition(visibleRect.x, visibleRect.y);
|
2000-03-22 02:58:02 +03:00
|
|
|
|
|
|
|
// The actual scroll offsets
|
|
|
|
nscoord scrollOffsetX = visibleRect.x;
|
|
|
|
nscoord scrollOffsetY = visibleRect.y;
|
|
|
|
|
2004-09-21 08:41:08 +04:00
|
|
|
nsPresContext::ScrollbarStyles ss =
|
|
|
|
nsLayoutUtils::ScrollbarStylesOfView(aScrollableView);
|
|
|
|
|
2000-03-22 02:58:02 +03:00
|
|
|
// See how aRect should be positioned vertically
|
2004-09-21 08:41:08 +04:00
|
|
|
if (ss.mVertical != NS_STYLE_OVERFLOW_HIDDEN) {
|
|
|
|
if (NS_PRESSHELL_SCROLL_ANYWHERE == aVPercent) {
|
|
|
|
// The caller doesn't care where aRect is positioned vertically,
|
|
|
|
// so long as it's fully visible
|
|
|
|
if (aRect.y < visibleRect.y) {
|
|
|
|
// Scroll up so aRect's top edge is visible
|
2000-03-22 02:58:02 +03:00
|
|
|
scrollOffsetY = aRect.y;
|
2004-09-21 08:41:08 +04:00
|
|
|
} else if (aRect.YMost() > visibleRect.YMost()) {
|
|
|
|
// Scroll down so aRect's bottom edge is visible. Make sure
|
|
|
|
// aRect's top edge is still visible
|
|
|
|
scrollOffsetY += aRect.YMost() - visibleRect.YMost();
|
|
|
|
if (scrollOffsetY > aRect.y) {
|
|
|
|
scrollOffsetY = aRect.y;
|
|
|
|
}
|
2000-03-22 02:58:02 +03:00
|
|
|
}
|
2004-09-21 08:41:08 +04:00
|
|
|
} else {
|
|
|
|
// Align the aRect edge according to the specified percentage
|
|
|
|
nscoord frameAlignY = aRect.y + (aRect.height * aVPercent) / 100;
|
|
|
|
scrollOffsetY = frameAlignY - (visibleRect.height * aVPercent) / 100;
|
2000-03-22 02:58:02 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// See how the aRect should be positioned horizontally
|
2004-09-21 08:41:08 +04:00
|
|
|
if (ss.mHorizontal != NS_STYLE_OVERFLOW_HIDDEN) {
|
|
|
|
if (NS_PRESSHELL_SCROLL_ANYWHERE == aHPercent) {
|
|
|
|
// The caller doesn't care where the aRect is positioned horizontally,
|
|
|
|
// so long as it's fully visible
|
|
|
|
if (aRect.x < visibleRect.x) {
|
|
|
|
// Scroll left so the aRect's left edge is visible
|
2000-03-22 02:58:02 +03:00
|
|
|
scrollOffsetX = aRect.x;
|
2004-09-21 08:41:08 +04:00
|
|
|
} else if (aRect.XMost() > visibleRect.XMost()) {
|
|
|
|
// Scroll right so the aRect's right edge is visible. Make sure the
|
|
|
|
// aRect's left edge is still visible
|
|
|
|
scrollOffsetX += aRect.XMost() - visibleRect.XMost();
|
|
|
|
if (scrollOffsetX > aRect.x) {
|
|
|
|
scrollOffsetX = aRect.x;
|
|
|
|
}
|
2000-03-22 02:58:02 +03:00
|
|
|
}
|
2004-09-21 08:41:08 +04:00
|
|
|
|
|
|
|
} else {
|
|
|
|
// Align the aRect edge according to the specified percentage
|
|
|
|
nscoord frameAlignX = aRect.x + (aRect.width * aHPercent) / 100;
|
|
|
|
scrollOffsetX = frameAlignX - (visibleRect.width * aHPercent) / 100;
|
2000-03-22 02:58:02 +03:00
|
|
|
}
|
|
|
|
}
|
2000-08-30 23:42:47 +04:00
|
|
|
|
|
|
|
aScrollableView->ScrollTo(scrollOffsetX, scrollOffsetY, NS_VMREFRESH_IMMEDIATE);
|
|
|
|
|
|
|
|
if (aScrollParentViews)
|
|
|
|
{
|
|
|
|
//
|
|
|
|
// Get aScrollableView's scrolled view.
|
|
|
|
//
|
|
|
|
|
|
|
|
nsIView *scrolledView = 0;
|
|
|
|
|
|
|
|
rv = aScrollableView->GetScrolledView(scrolledView);
|
|
|
|
|
|
|
|
if (NS_FAILED(rv))
|
|
|
|
return rv;
|
|
|
|
|
|
|
|
if (!scrolledView)
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
|
|
|
|
//
|
|
|
|
// Check if aScrollableRect has a parent scrollable view!
|
|
|
|
//
|
|
|
|
|
2004-09-21 02:25:07 +04:00
|
|
|
nsIView *view = aScrollableView->View()->GetParent();
|
2000-08-30 23:42:47 +04:00
|
|
|
|
|
|
|
if (view)
|
|
|
|
{
|
2004-09-21 08:41:08 +04:00
|
|
|
nsIScrollableView *parentSV =
|
|
|
|
nsLayoutUtils::GetNearestScrollingView(view, nsLayoutUtils::eEither);
|
2000-08-30 23:42:47 +04:00
|
|
|
|
|
|
|
if (parentSV)
|
|
|
|
{
|
2006-03-23 03:13:07 +03:00
|
|
|
//
|
|
|
|
// Clip the x dimensions of aRect so that they are
|
|
|
|
// completely within the bounds of the scrolledView.
|
|
|
|
// This helps avoid unnecessary scrolling of parent
|
|
|
|
// scrolled views.
|
|
|
|
//
|
|
|
|
nsRect svRect = scrolledView->GetBounds() - scrolledView->GetPosition();
|
|
|
|
nsPoint topLeft = aRect.TopLeft();
|
|
|
|
nsPoint bottomRight = aRect.BottomRight();
|
|
|
|
ClampPointInsideRect(topLeft, svRect);
|
|
|
|
ClampPointInsideRect(bottomRight, svRect);
|
|
|
|
nsRect newRect(topLeft.x, topLeft.y, bottomRight.x - topLeft.x,
|
|
|
|
bottomRight.y - topLeft.y);
|
|
|
|
|
2000-08-30 23:42:47 +04:00
|
|
|
//
|
|
|
|
// We have a parent scrollable view, so now map aRect
|
|
|
|
// into it's scrolled view's coordinate space.
|
|
|
|
//
|
|
|
|
|
|
|
|
rv = parentSV->GetScrolledView(view);
|
|
|
|
|
|
|
|
if (NS_FAILED(rv))
|
|
|
|
return rv;
|
|
|
|
|
|
|
|
if (!view)
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
|
2006-03-23 03:13:07 +03:00
|
|
|
nscoord offsetX, offsetY;
|
|
|
|
rv = GetViewAncestorOffset(scrolledView, view, &offsetX, &offsetY);
|
2000-08-30 23:42:47 +04:00
|
|
|
|
|
|
|
if (NS_FAILED(rv))
|
|
|
|
return rv;
|
|
|
|
|
2006-03-23 03:13:07 +03:00
|
|
|
newRect.x += offsetX;
|
|
|
|
newRect.y += offsetY;
|
2000-08-30 23:42:47 +04:00
|
|
|
|
|
|
|
//
|
|
|
|
// Now scroll the rect into the parent's view.
|
|
|
|
//
|
|
|
|
|
|
|
|
rv = ScrollRectIntoView(parentSV, newRect, aVPercent, aHPercent, aScrollParentViews);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2000-03-22 02:58:02 +03:00
|
|
|
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
2006-05-10 21:30:15 +04:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsTypedSelection::ScrollSelectionIntoViewEvent::Run()
|
2002-06-14 00:43:32 +04:00
|
|
|
{
|
2006-05-10 21:30:15 +04:00
|
|
|
if (!mTypedSelection)
|
|
|
|
return NS_OK; // event revoked
|
2002-06-14 00:43:32 +04:00
|
|
|
|
2006-05-10 21:30:15 +04:00
|
|
|
mTypedSelection->mScrollEvent.Forget();
|
|
|
|
mTypedSelection->ScrollIntoView(mRegion, PR_TRUE);
|
|
|
|
return NS_OK;
|
2002-06-14 00:43:32 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
nsTypedSelection::PostScrollSelectionIntoViewEvent(SelectionRegion aRegion)
|
|
|
|
{
|
2006-05-10 21:30:15 +04:00
|
|
|
// If we've already posted an event, revoke it and place a new one at the
|
|
|
|
// end of the queue to make sure that any new pending reflow events are
|
|
|
|
// processed before we scroll. This will insure that we scroll to the
|
|
|
|
// correct place on screen.
|
|
|
|
mScrollEvent.Revoke();
|
2002-06-14 00:43:32 +04:00
|
|
|
|
2006-05-10 21:30:15 +04:00
|
|
|
nsRefPtr<ScrollSelectionIntoViewEvent> ev =
|
|
|
|
new ScrollSelectionIntoViewEvent(this, aRegion);
|
|
|
|
nsresult rv = NS_DispatchToCurrentThread(ev);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2002-06-14 00:43:32 +04:00
|
|
|
|
2006-05-10 21:30:15 +04:00
|
|
|
mScrollEvent = ev;
|
|
|
|
return NS_OK;
|
2002-06-14 00:43:32 +04:00
|
|
|
}
|
|
|
|
|
2000-03-22 02:58:02 +03:00
|
|
|
NS_IMETHODIMP
|
2002-06-14 00:43:32 +04:00
|
|
|
nsTypedSelection::ScrollIntoView(SelectionRegion aRegion, PRBool aIsSynchronous)
|
2000-03-22 02:58:02 +03:00
|
|
|
{
|
|
|
|
nsresult result;
|
2000-05-11 08:25:43 +04:00
|
|
|
if (!mFrameSelection)
|
|
|
|
return NS_OK;//nothing to do
|
2000-03-22 02:58:02 +03:00
|
|
|
|
|
|
|
if (mFrameSelection->GetBatching())
|
|
|
|
return NS_OK;
|
|
|
|
|
2002-06-14 00:43:32 +04:00
|
|
|
if (!aIsSynchronous)
|
|
|
|
return PostScrollSelectionIntoViewEvent(aRegion);
|
|
|
|
|
2000-03-22 02:58:02 +03:00
|
|
|
//
|
|
|
|
// Shut the caret off before scrolling to avoid
|
|
|
|
// leaving caret turds on the screen!
|
|
|
|
//
|
|
|
|
nsCOMPtr<nsIPresShell> presShell;
|
|
|
|
result = GetPresShell(getter_AddRefs(presShell));
|
2007-03-23 20:32:34 +03:00
|
|
|
if (NS_FAILED(result) || !presShell)
|
2000-03-22 02:58:02 +03:00
|
|
|
return result;
|
2000-06-01 06:37:40 +04:00
|
|
|
nsCOMPtr<nsICaret> caret;
|
|
|
|
presShell->GetCaret(getter_AddRefs(caret));
|
|
|
|
if (caret)
|
2000-04-27 11:37:12 +04:00
|
|
|
{
|
2003-03-12 06:22:11 +03:00
|
|
|
StCaretHider caretHider(caret); // stack-based class hides and shows the caret
|
2000-03-22 02:58:02 +03:00
|
|
|
|
2005-07-30 06:43:17 +04:00
|
|
|
// We are going to scroll to a character offset within a frame by
|
|
|
|
// using APIs on the scrollable view directly. So we need to
|
|
|
|
// flush out pending reflows to make sure that frames are up-to-date.
|
|
|
|
// We crash otherwise - bug 252970#c97
|
|
|
|
presShell->FlushPendingNotifications(Flush_OnlyReflow);
|
|
|
|
|
2000-04-27 11:37:12 +04:00
|
|
|
//
|
|
|
|
// Scroll the selection region into view.
|
|
|
|
//
|
2000-08-30 23:42:47 +04:00
|
|
|
|
2006-04-18 00:56:25 +04:00
|
|
|
nsRect rect;
|
|
|
|
nsIScrollableView *scrollableView = 0;
|
2000-08-30 23:42:47 +04:00
|
|
|
|
2006-04-18 00:56:25 +04:00
|
|
|
result = GetSelectionRegionRectAndScrollableView(aRegion, &rect, &scrollableView);
|
2000-03-22 02:58:02 +03:00
|
|
|
|
2000-04-27 11:37:12 +04:00
|
|
|
if (NS_FAILED(result))
|
|
|
|
return result;
|
2000-03-22 02:58:02 +03:00
|
|
|
|
2000-08-30 23:42:47 +04:00
|
|
|
//
|
|
|
|
// It's ok if we don't have a scrollable view, just return early.
|
|
|
|
//
|
2006-04-18 00:56:25 +04:00
|
|
|
if (!scrollableView)
|
2000-08-30 23:42:47 +04:00
|
|
|
return NS_OK;
|
|
|
|
|
2006-04-18 00:56:25 +04:00
|
|
|
result = ScrollRectIntoView(scrollableView, rect, NS_PRESSHELL_SCROLL_ANYWHERE, NS_PRESSHELL_SCROLL_ANYWHERE, PR_TRUE);
|
2000-04-27 11:37:12 +04:00
|
|
|
}
|
2000-03-22 02:58:02 +03:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2000-11-29 03:13:00 +03:00
|
|
|
nsTypedSelection::AddSelectionListener(nsISelectionListener* aNewListener)
|
2000-03-22 02:58:02 +03:00
|
|
|
{
|
2000-05-04 12:35:42 +04:00
|
|
|
if (!aNewListener)
|
|
|
|
return NS_ERROR_NULL_POINTER;
|
2003-03-12 06:22:11 +03:00
|
|
|
return mSelectionListeners.AppendObject(aNewListener) ? NS_OK : NS_ERROR_FAILURE; // addrefs
|
2000-03-22 02:58:02 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2000-11-29 03:13:00 +03:00
|
|
|
nsTypedSelection::RemoveSelectionListener(nsISelectionListener* aListenerToRemove)
|
2000-03-22 02:58:02 +03:00
|
|
|
{
|
2000-05-04 12:35:42 +04:00
|
|
|
if (!aListenerToRemove )
|
|
|
|
return NS_ERROR_NULL_POINTER;
|
2003-03-12 06:22:11 +03:00
|
|
|
return mSelectionListeners.RemoveObject(aListenerToRemove) ? NS_OK : NS_ERROR_FAILURE; // releases
|
2000-03-22 02:58:02 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2000-05-04 12:35:42 +04:00
|
|
|
nsresult
|
2000-11-29 03:13:00 +03:00
|
|
|
nsTypedSelection::NotifySelectionListeners()
|
2000-05-04 12:35:42 +04:00
|
|
|
{
|
2000-05-11 08:25:43 +04:00
|
|
|
if (!mFrameSelection)
|
|
|
|
return NS_OK;//nothing to do
|
2000-05-04 12:35:42 +04:00
|
|
|
|
|
|
|
if (mFrameSelection->GetBatching()){
|
|
|
|
mFrameSelection->SetDirty();
|
|
|
|
return NS_OK;
|
|
|
|
}
|
2002-12-11 03:02:49 +03:00
|
|
|
PRInt32 cnt = mSelectionListeners.Count();
|
2006-09-18 12:47:06 +04:00
|
|
|
nsCOMArray<nsISelectionListener> selectionListeners(mSelectionListeners);
|
2000-05-04 12:35:42 +04:00
|
|
|
|
|
|
|
nsCOMPtr<nsIDOMDocument> domdoc;
|
|
|
|
nsCOMPtr<nsIPresShell> shell;
|
2002-12-11 03:02:49 +03:00
|
|
|
nsresult rv = GetPresShell(getter_AddRefs(shell));
|
2000-05-04 12:35:42 +04:00
|
|
|
if (NS_SUCCEEDED(rv) && shell)
|
2004-08-02 08:52:55 +04:00
|
|
|
domdoc = do_QueryInterface(shell->GetDocument());
|
2000-06-09 09:14:19 +04:00
|
|
|
short reason = mFrameSelection->PopReason();
|
2002-12-11 03:02:49 +03:00
|
|
|
for (PRInt32 i = 0; i < cnt; i++)
|
2000-05-04 12:35:42 +04:00
|
|
|
{
|
2006-09-18 12:47:06 +04:00
|
|
|
nsISelectionListener* thisListener = selectionListeners[i];
|
2000-05-04 12:35:42 +04:00
|
|
|
if (thisListener)
|
2003-03-12 06:22:11 +03:00
|
|
|
thisListener->NotifySelectionChanged(domdoc, this, reason);
|
2000-05-04 12:35:42 +04:00
|
|
|
}
|
2003-03-12 06:22:11 +03:00
|
|
|
return NS_OK;
|
2000-05-04 12:35:42 +04:00
|
|
|
}
|
2000-03-22 02:58:02 +03:00
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2000-11-29 03:13:00 +03:00
|
|
|
nsTypedSelection::StartBatchChanges()
|
2000-03-22 02:58:02 +03:00
|
|
|
{
|
2006-04-26 06:01:07 +04:00
|
|
|
if (mFrameSelection)
|
|
|
|
mFrameSelection->StartBatchChanges();
|
|
|
|
|
|
|
|
return NS_OK;
|
2000-03-22 02:58:02 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2000-11-29 03:13:00 +03:00
|
|
|
nsTypedSelection::EndBatchChanges()
|
2000-03-22 02:58:02 +03:00
|
|
|
{
|
2006-04-26 06:01:07 +04:00
|
|
|
if (mFrameSelection)
|
|
|
|
mFrameSelection->EndBatchChanges();
|
|
|
|
|
|
|
|
return NS_OK;
|
2000-03-22 02:58:02 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2000-11-29 03:13:00 +03:00
|
|
|
nsTypedSelection::DeleteFromDocument()
|
2000-03-22 02:58:02 +03:00
|
|
|
{
|
2000-05-11 08:25:43 +04:00
|
|
|
if (!mFrameSelection)
|
|
|
|
return NS_OK;//nothing to do
|
2000-03-22 02:58:02 +03:00
|
|
|
return mFrameSelection->DeleteFromDocument();
|
|
|
|
}
|
|
|
|
|
2001-03-21 04:16:22 +03:00
|
|
|
/** SelectionLanguageChange modifies the cursor Bidi level after a change in keyboard direction
|
|
|
|
* @param aLangRTL is PR_TRUE if the new language is right-to-left or PR_FALSE if the new language is left-to-right
|
|
|
|
*/
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsTypedSelection::SelectionLanguageChange(PRBool aLangRTL)
|
|
|
|
{
|
2006-04-14 04:28:22 +04:00
|
|
|
if (!mFrameSelection)
|
|
|
|
return NS_ERROR_NOT_INITIALIZED; // Can't do selection
|
2001-03-21 04:16:22 +03:00
|
|
|
nsresult result;
|
|
|
|
nsCOMPtr<nsIDOMNode> focusNode;
|
|
|
|
nsCOMPtr<nsIContent> focusContent;
|
|
|
|
PRInt32 focusOffset;
|
|
|
|
nsIFrame *focusFrame = 0;
|
|
|
|
|
|
|
|
focusOffset = FetchFocusOffset();
|
|
|
|
focusNode = FetchFocusNode();
|
2006-08-30 13:26:39 +04:00
|
|
|
result = GetPrimaryFrameForFocusNode(&focusFrame, nsnull, PR_FALSE);
|
2001-03-21 04:16:22 +03:00
|
|
|
if (NS_FAILED(result) || !focusFrame)
|
|
|
|
return result?result:NS_ERROR_FAILURE;
|
|
|
|
|
|
|
|
PRInt32 frameStart, frameEnd;
|
|
|
|
focusFrame->GetOffsets(frameStart, frameEnd);
|
2004-08-01 03:15:21 +04:00
|
|
|
nsCOMPtr<nsPresContext> context;
|
2004-06-01 10:20:16 +04:00
|
|
|
PRUint8 levelBefore, levelAfter;
|
2001-03-21 04:16:22 +03:00
|
|
|
result = GetPresContext(getter_AddRefs(context));
|
|
|
|
if (NS_FAILED(result) || !context)
|
|
|
|
return result?result:NS_ERROR_FAILURE;
|
|
|
|
|
2004-06-01 10:20:16 +04:00
|
|
|
PRUint8 level = NS_GET_EMBEDDING_LEVEL(focusFrame);
|
2001-03-21 04:16:22 +03:00
|
|
|
if ((focusOffset != frameStart) && (focusOffset != frameEnd))
|
|
|
|
// the cursor is not at a frame boundary, so the level of both the characters (logically) before and after the cursor
|
|
|
|
// is equal to the frame level
|
|
|
|
levelBefore = levelAfter = level;
|
|
|
|
else {
|
|
|
|
// the cursor is at a frame boundary, so use GetPrevNextBidiLevels to find the level of the characters
|
|
|
|
// before and after the cursor
|
|
|
|
focusContent = do_QueryInterface(focusNode);
|
|
|
|
/*
|
2006-04-26 06:01:07 +04:00
|
|
|
nsFrameSelection::HINT hint;
|
2001-03-21 04:16:22 +03:00
|
|
|
|
|
|
|
if ((focusOffset == frameStart && level) // beginning of an RTL frame
|
|
|
|
|| (focusOffset == frameEnd && !level)) { // end of an LTR frame
|
2006-04-26 06:01:07 +04:00
|
|
|
hint = nsFrameSelection::HINTRIGHT;
|
2001-03-21 04:16:22 +03:00
|
|
|
}
|
|
|
|
else { // end of an RTL frame or beginning of an LTR frame
|
2006-04-26 06:01:07 +04:00
|
|
|
hint = nsFrameSelection::HINTLEFT;
|
2001-03-21 04:16:22 +03:00
|
|
|
}
|
|
|
|
mFrameSelection->SetHint(hint);
|
|
|
|
*/
|
2006-04-26 06:01:07 +04:00
|
|
|
nsPrevNextBidiLevels levels = mFrameSelection->
|
|
|
|
GetPrevNextBidiLevels(focusContent, focusOffset, PR_FALSE);
|
|
|
|
|
|
|
|
levelBefore = levels.mLevelBefore;
|
|
|
|
levelAfter = levels.mLevelAfter;
|
2001-03-21 04:16:22 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
if ((levelBefore & 1) == (levelAfter & 1)) {
|
|
|
|
// if cursor is between two characters with the same orientation, changing the keyboard language
|
|
|
|
// must toggle the cursor level between the level of the character with the lowest level
|
|
|
|
// (if the new language corresponds to the orientation of that character) and this level plus 1
|
|
|
|
// (if the new language corresponds to the opposite orientation)
|
|
|
|
if ((level != levelBefore) && (level != levelAfter))
|
|
|
|
level = PR_MIN(levelBefore, levelAfter);
|
|
|
|
if ((level & 1) == aLangRTL)
|
2006-08-08 09:14:52 +04:00
|
|
|
mFrameSelection->SetCaretBidiLevel(level);
|
2001-03-21 04:16:22 +03:00
|
|
|
else
|
2006-08-08 09:14:52 +04:00
|
|
|
mFrameSelection->SetCaretBidiLevel(level + 1);
|
2001-03-21 04:16:22 +03:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
// if cursor is between characters with opposite orientations, changing the keyboard language must change
|
|
|
|
// the cursor level to that of the adjacent character with the orientation corresponding to the new language.
|
|
|
|
if ((levelBefore & 1) == aLangRTL)
|
2006-08-08 09:14:52 +04:00
|
|
|
mFrameSelection->SetCaretBidiLevel(levelBefore);
|
2001-03-21 04:16:22 +03:00
|
|
|
else
|
2006-08-08 09:14:52 +04:00
|
|
|
mFrameSelection->SetCaretBidiLevel(levelAfter);
|
2001-03-21 04:16:22 +03:00
|
|
|
}
|
2005-09-18 18:18:28 +04:00
|
|
|
|
|
|
|
// The caret might have moved, so invalidate the desired X position
|
|
|
|
// for future usages of up-arrow or down-arrow
|
|
|
|
mFrameSelection->InvalidateDesiredX();
|
|
|
|
|
2001-03-21 04:16:22 +03:00
|
|
|
return NS_OK;
|
|
|
|
}
|
2005-02-01 02:47:26 +03:00
|
|
|
|
|
|
|
|
|
|
|
// nsAutoCopyListener
|
|
|
|
|
|
|
|
nsAutoCopyListener* nsAutoCopyListener::sInstance = nsnull;
|
|
|
|
|
|
|
|
NS_IMPL_ISUPPORTS1(nsAutoCopyListener, nsISelectionListener)
|
|
|
|
|
|
|
|
/*
|
|
|
|
* What we do now:
|
|
|
|
* On every selection change, we copy to the clipboard anew, creating a
|
|
|
|
* HTML buffer, a transferable, an nsISupportsString and
|
|
|
|
* a huge mess every time. This is basically what nsPresShell::DoCopy does
|
|
|
|
* to move the selection into the clipboard for Edit->Copy.
|
|
|
|
*
|
|
|
|
* What we should do, to make our end of the deal faster:
|
|
|
|
* Create a singleton transferable with our own magic converter. When selection
|
|
|
|
* changes (use a quick cache to detect ``real'' changes), we put the new
|
|
|
|
* nsISelection in the transferable. Our magic converter will take care of
|
|
|
|
* transferable->whatever-other-format when the time comes to actually
|
|
|
|
* hand over the clipboard contents.
|
|
|
|
*
|
|
|
|
* Other issues:
|
|
|
|
* - which X clipboard should we populate?
|
|
|
|
* - should we use a different one than Edit->Copy, so that inadvertant
|
|
|
|
* selections (or simple clicks, which currently cause a selection
|
|
|
|
* notification, regardless of if they're in the document which currently has
|
|
|
|
* selection!) don't lose the contents of the ``application''? Or should we
|
|
|
|
* just put some intelligence in the ``is this a real selection?'' code to
|
|
|
|
* protect our selection against clicks in other documents that don't create
|
|
|
|
* selections?
|
|
|
|
* - maybe we should just never clear the X clipboard? That would make this
|
|
|
|
* problem just go away, which is very tempting.
|
|
|
|
*/
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsAutoCopyListener::NotifySelectionChanged(nsIDOMDocument *aDoc,
|
|
|
|
nsISelection *aSel, PRInt16 aReason)
|
|
|
|
{
|
|
|
|
if (!(aReason & nsISelectionListener::MOUSEUP_REASON ||
|
|
|
|
aReason & nsISelectionListener::SELECTALL_REASON ||
|
|
|
|
aReason & nsISelectionListener::KEYPRESS_REASON))
|
|
|
|
return NS_OK; //dont care if we are still dragging
|
|
|
|
|
|
|
|
PRBool collapsed;
|
|
|
|
if (!aDoc || !aSel ||
|
|
|
|
NS_FAILED(aSel->GetIsCollapsed(&collapsed)) || collapsed) {
|
|
|
|
#ifdef DEBUG_CLIPBOARD
|
|
|
|
fprintf(stderr, "CLIPBOARD: no selection/collapsed selection\n");
|
|
|
|
#endif
|
|
|
|
/* clear X clipboard? */
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsCOMPtr<nsIDocument> doc = do_QueryInterface(aDoc);
|
|
|
|
NS_ENSURE_TRUE(doc, NS_ERROR_FAILURE);
|
|
|
|
|
|
|
|
// call the copy code
|
|
|
|
return nsCopySupport::HTMLCopy(aSel, doc, nsIClipboard::kSelectionClipboard);
|
|
|
|
}
|