2000-03-22 02:58:02 +03:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
|
|
|
*
|
|
|
|
* The contents of this file are subject to the Netscape 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/NPL/
|
|
|
|
*
|
|
|
|
* Software distributed under the License is distributed on an "AS
|
|
|
|
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
|
|
|
|
* implied. See the License for the specific language governing
|
|
|
|
* rights and limitations under the License.
|
|
|
|
*
|
|
|
|
* The Original Code is mozilla.org code.
|
|
|
|
*
|
|
|
|
* The Initial Developer of the Original Code is Netscape
|
|
|
|
* Communications Corporation. Portions created by Netscape are
|
|
|
|
* Copyright (C) 1998 Netscape Communications Corporation. All
|
|
|
|
* Rights Reserved.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
2000-09-14 15:45:01 +04:00
|
|
|
* Implementation of selection: nsISelection,nsISelectionPrivate and nsIFrameSelection
|
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"
|
|
|
|
#include "nsIDOMRange.h"
|
|
|
|
#include "nsIFrameSelection.h"
|
2000-09-14 15:45:01 +04:00
|
|
|
#include "nsISelection.h"
|
|
|
|
#include "nsISelectionPrivate.h"
|
|
|
|
#include "nsISelectionListener.h"
|
2000-03-22 02:58:02 +03:00
|
|
|
#include "nsIFocusTracker.h"
|
|
|
|
#include "nsIComponentManager.h"
|
|
|
|
#include "nsLayoutCID.h"
|
|
|
|
#include "nsIContent.h"
|
|
|
|
#include "nsIDOMElement.h"
|
|
|
|
#include "nsIDOMNode.h"
|
|
|
|
#include "nsRange.h"
|
|
|
|
#include "nsISupportsArray.h"
|
|
|
|
#include "nsIDOMKeyEvent.h"
|
|
|
|
#include "nsITableLayout.h"
|
|
|
|
#include "nsITableCellLayout.h"
|
2000-08-29 03:35:57 +04:00
|
|
|
#include "nsIDOMNodeList.h"
|
|
|
|
#include "nsITextContent.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-05-13 12:07:34 +04:00
|
|
|
#include "nsIIndependentSelection.h"
|
2000-06-07 03:14:42 +04:00
|
|
|
#include "nsIPref.h"
|
2000-03-22 02:58:02 +03:00
|
|
|
|
|
|
|
#include "nsIDOMText.h"
|
|
|
|
|
|
|
|
//included for desired x position;
|
|
|
|
#include "nsIPresContext.h"
|
|
|
|
#include "nsIPresShell.h"
|
|
|
|
#include "nsICaret.h"
|
|
|
|
|
|
|
|
|
|
|
|
// included for view scrolling
|
|
|
|
#include "nsIViewManager.h"
|
|
|
|
#include "nsIScrollableView.h"
|
|
|
|
#include "nsIDeviceContext.h"
|
|
|
|
#include "nsITimer.h"
|
|
|
|
#include "nsITimerCallback.h"
|
2000-04-14 15:21:19 +04:00
|
|
|
#include "nsIServiceManager.h"
|
|
|
|
#include "nsIAutoCopy.h"
|
|
|
|
|
|
|
|
//nodtifications
|
|
|
|
#include "nsIDOMDocument.h"
|
|
|
|
#include "nsIDocument.h"
|
|
|
|
|
2000-04-27 11:37:12 +04:00
|
|
|
#include "nsISelectionController.h"//for the enums
|
2000-03-22 02:58:02 +03:00
|
|
|
|
2000-11-29 03:13:00 +03:00
|
|
|
/*included so html can call into nsISelection code with no security issues*/
|
|
|
|
#include "nsISecurityCheckedComponent.h"
|
|
|
|
|
2000-03-22 02:58:02 +03:00
|
|
|
#define STATUS_CHECK_RETURN_MACRO() {if (!mTracker) return NS_ERROR_FAILURE;}
|
2000-05-17 07:07:31 +04:00
|
|
|
//#define DEBUG_TABLE 1
|
2000-03-22 02:58:02 +03:00
|
|
|
|
2000-10-14 02:37:52 +04:00
|
|
|
// Selection's use of generated content iterators has been turned off
|
|
|
|
// temporarily since it bogs down selection in large documents. Using
|
|
|
|
// generated content iterators is slower because it must resolve the style
|
|
|
|
// for the content to find out if it has any before/after style, and it
|
|
|
|
// increases the number of calls to GetPrimaryFrame() which is very expensive.
|
|
|
|
//
|
|
|
|
// We can reduce the number of calls to GetPrimaryFrame() during selection
|
|
|
|
// by a good factor (maybe 2-3 times) if we just ignore the generated content
|
|
|
|
// and NOT hilite it when we cross it.
|
|
|
|
//
|
|
|
|
// #1 the output system doesn't handle it right now anyway so selecting
|
|
|
|
// has no REAL benefit to generated content.
|
|
|
|
// #2 there is no available way given to me by troy that can give back the
|
|
|
|
// necessary data without a frame to work from.
|
|
|
|
#ifdef USE_SELECTION_GENERATED_CONTENT_ITERATOR_CODE
|
2000-03-31 11:17:22 +04:00
|
|
|
static NS_DEFINE_IID(kCGenContentIteratorCID, NS_GENERATEDCONTENTITERATOR_CID);
|
2000-04-02 09:05:31 +04:00
|
|
|
static NS_DEFINE_IID(kCGenSubtreeIteratorCID, NS_GENERATEDSUBTREEITERATOR_CID);
|
2000-10-14 02:37:52 +04:00
|
|
|
#else
|
|
|
|
static NS_DEFINE_IID(kCContentIteratorCID, NS_CONTENTITERATOR_CID);
|
2000-03-22 02:58:02 +03:00
|
|
|
static NS_DEFINE_IID(kCSubtreeIteratorCID, NS_SUBTREEITERATOR_CID);
|
2000-10-14 02:37:52 +04:00
|
|
|
#endif // USE_SELECTION_GENERATED_CONTENT_ITERATOR_CODE
|
2000-03-22 02:58:02 +03:00
|
|
|
|
|
|
|
//PROTOTYPES
|
2000-04-28 17:58:08 +04:00
|
|
|
#if OLD_SELECTION
|
2000-03-22 02:58:02 +03:00
|
|
|
static nsCOMPtr<nsIAtom> GetTag(nsIDOMNode *aNode);
|
|
|
|
static nsresult ParentOffset(nsIDOMNode *aNode, nsIDOMNode **aParent, PRInt32 *aChildOffset);
|
2000-04-28 17:58:08 +04:00
|
|
|
#endif
|
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 OLD_SELECTION 0
|
|
|
|
|
|
|
|
//#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
|
|
|
|
2000-03-22 02:58:02 +03:00
|
|
|
class nsSelectionIterator;
|
|
|
|
class nsSelection;
|
|
|
|
class nsAutoScrollTimer;
|
|
|
|
|
2000-11-29 03:13:00 +03:00
|
|
|
class nsTypedSelection : public nsISelection ,
|
|
|
|
public nsISelectionPrivate,
|
|
|
|
public nsSupportsWeakReference,
|
|
|
|
public nsIIndependentSelection,
|
|
|
|
public nsISecurityCheckedComponent
|
2000-03-22 02:58:02 +03:00
|
|
|
{
|
|
|
|
public:
|
2000-11-29 03:13:00 +03:00
|
|
|
nsTypedSelection();
|
|
|
|
nsTypedSelection(nsSelection *aList);
|
|
|
|
virtual ~nsTypedSelection();
|
2000-03-22 02:58:02 +03:00
|
|
|
|
|
|
|
NS_DECL_ISUPPORTS
|
2000-05-13 12:07:34 +04:00
|
|
|
/*BEGIN nsIIndependentSelection interface implementations */
|
|
|
|
NS_IMETHOD SetPresShell(nsIPresShell *aPresShell);
|
2000-03-22 02:58:02 +03:00
|
|
|
|
2000-09-14 15:45:01 +04:00
|
|
|
/*BEGIN nsISelection,Private interface implementations*/
|
2000-03-22 02:58:02 +03:00
|
|
|
NS_IMETHOD GetAnchorNode(nsIDOMNode** aAnchorNode);
|
|
|
|
NS_IMETHOD GetAnchorOffset(PRInt32* aAnchorOffset);
|
|
|
|
NS_IMETHOD GetFocusNode(nsIDOMNode** aFocusNode);
|
|
|
|
NS_IMETHOD GetFocusOffset(PRInt32* aFocusOffset);
|
|
|
|
NS_IMETHOD GetIsCollapsed(PRBool* aIsCollapsed);
|
|
|
|
NS_IMETHOD GetRangeCount(PRInt32* aRangeCount);
|
|
|
|
NS_IMETHOD GetRangeAt(PRInt32 aIndex, nsIDOMRange** aReturn);
|
2000-09-14 15:45:01 +04:00
|
|
|
NS_IMETHOD RemoveAllRanges();
|
2000-12-21 01:13:54 +03:00
|
|
|
NS_IMETHOD GetTableSelectionType(nsIDOMRange* aRange, PRInt32* aTableSelectionType);
|
2000-03-22 02:58:02 +03:00
|
|
|
NS_IMETHOD Collapse(nsIDOMNode* aParentNode, PRInt32 aOffset);
|
|
|
|
NS_IMETHOD CollapseToStart();
|
|
|
|
NS_IMETHOD CollapseToEnd();
|
2000-09-13 00:54:41 +04:00
|
|
|
NS_IMETHOD SelectAllChildren(nsIDOMNode* parentNode);
|
2000-03-22 02:58:02 +03:00
|
|
|
NS_IMETHOD Extend(nsIDOMNode* aParentNode, PRInt32 aOffset);
|
|
|
|
NS_IMETHOD ContainsNode(nsIDOMNode* aNode, PRBool aRecursive, PRBool* aAYes);
|
|
|
|
NS_IMETHOD DeleteFromDocument();
|
|
|
|
NS_IMETHOD AddRange(nsIDOMRange* aRange);
|
|
|
|
NS_IMETHOD RemoveRange(nsIDOMRange* aRange);
|
|
|
|
|
|
|
|
NS_IMETHOD StartBatchChanges();
|
|
|
|
NS_IMETHOD EndBatchChanges();
|
|
|
|
|
2000-09-14 15:45:01 +04:00
|
|
|
NS_IMETHOD AddSelectionListener(nsISelectionListener* aNewListener);
|
|
|
|
NS_IMETHOD RemoveSelectionListener(nsISelectionListener* aListenerToRemove);
|
2000-03-22 02:58:02 +03:00
|
|
|
NS_IMETHOD GetEnumerator(nsIEnumerator **aIterator);
|
|
|
|
|
2000-09-14 15:45:01 +04:00
|
|
|
NS_IMETHOD ToString(PRUnichar **_retval);
|
|
|
|
NS_IMETHOD ToStringWithFormat(const char *aFormatType, PRUint32 aFlags, PRInt32 aWrapCount, PRUnichar ** aReturn);
|
2000-08-09 03:38:00 +04:00
|
|
|
|
2000-09-14 15:45:01 +04:00
|
|
|
NS_IMETHOD GetInterlinePosition(PRBool *aInterlinePosition);
|
|
|
|
NS_IMETHOD SetInterlinePosition(PRBool aInterlinePosition);
|
2000-04-28 10:21:31 +04:00
|
|
|
|
2000-09-14 15:45:01 +04:00
|
|
|
/*END nsISelection interface implementations*/
|
2000-11-29 03:13:00 +03:00
|
|
|
/* nsISecurityCheckedComponent */
|
|
|
|
NS_DECL_NSISECURITYCHECKEDCOMPONENT
|
|
|
|
/*END nsISecurityCheckedComponent*/
|
2000-03-22 02:58:02 +03:00
|
|
|
|
|
|
|
// utility methods for scrolling the selection into view
|
|
|
|
nsresult GetPresContext(nsIPresContext **aPresContext);
|
|
|
|
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
|
|
|
|
2000-04-27 11:37:12 +04:00
|
|
|
NS_IMETHOD ScrollIntoView(SelectionRegion aRegion=nsISelectionController::SELECTION_FOCUS_REGION);
|
2000-03-22 02:58:02 +03:00
|
|
|
nsresult AddItem(nsIDOMRange *aRange);
|
|
|
|
nsresult RemoveItem(nsIDOMRange *aRange);
|
|
|
|
|
|
|
|
nsresult Clear(nsIPresContext* aPresContext);
|
|
|
|
// methods for convenience. Note, these don't addref
|
|
|
|
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;}
|
|
|
|
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);
|
|
|
|
NS_IMETHOD GetPrimaryFrameForFocusNode(nsIFrame **aResultFrame);
|
|
|
|
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);
|
|
|
|
NS_IMETHOD Repaint(nsIPresContext* aPresContext);
|
|
|
|
|
|
|
|
nsresult StartAutoScrollTimer(nsIPresContext *aPresContext, nsIFrame *aFrame, nsPoint& aPoint, PRUint32 aDelay);
|
|
|
|
nsresult StopAutoScrollTimer();
|
|
|
|
nsresult DoAutoScroll(nsIPresContext *aPresContext, nsIFrame *aFrame, nsPoint& aPoint);
|
2000-08-30 23:42:47 +04:00
|
|
|
nsresult DoAutoScrollView(nsIPresContext *aPresContext, nsIView *aView, nsPoint& aPoint, PRBool aScrollParentViews);
|
|
|
|
nsresult ScrollPointIntoClipView(nsIPresContext *aPresContext, nsIView *aView, nsPoint& aPoint, PRBool *aDidScroll);
|
|
|
|
nsresult ScrollPointIntoView(nsIPresContext *aPresContext, nsIView *aView, nsPoint& aPoint, PRBool aScrollParentViews, PRBool *aDidScroll);
|
|
|
|
nsresult GetViewAncestorOffset(nsIView *aView, nsIView *aAncestorView, nscoord *aXOffset, nscoord *aYOffset);
|
|
|
|
nsresult GetClosestScrollableView(nsIView *aView, nsIScrollableView **aScrollableView);
|
2000-03-22 02:58:02 +03:00
|
|
|
|
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();
|
|
|
|
|
2000-03-22 02:58:02 +03:00
|
|
|
private:
|
|
|
|
friend class nsSelectionIterator;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void setAnchorFocusRange(PRInt32 aIndex); //pass in index into FrameSelection
|
2000-03-31 11:17:22 +04:00
|
|
|
NS_IMETHOD selectFrames(nsIPresContext* aPresContext, nsIContentIterator *aInnerIter, nsIContent *aContent, nsIDOMRange *aRange, nsIPresShell *aPresShell, PRBool aFlags);
|
2000-03-22 02:58:02 +03:00
|
|
|
NS_IMETHOD selectFrames(nsIPresContext* 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
|
|
|
|
|
|
|
#if OLD_SELECTION
|
|
|
|
NS_IMETHOD FixupSelectionPoints(nsIDOMRange *aRange, nsDirection *aDir, PRBool *aFixupState);
|
|
|
|
#endif //OLD_SELECTION
|
|
|
|
|
|
|
|
nsCOMPtr<nsISupportsArray> mRangeArray;
|
|
|
|
|
|
|
|
nsCOMPtr<nsIDOMRange> mAnchorFocusRange;
|
|
|
|
nsCOMPtr<nsIDOMRange> mOriginalAnchorRange; //used as a point with range gravity for security
|
|
|
|
nsDirection mDirection; //FALSE = focus, anchor; TRUE = anchor,focus
|
|
|
|
PRBool mFixupState; //was there a fixup?
|
|
|
|
|
|
|
|
nsSelection *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;
|
2000-03-22 02:58:02 +03:00
|
|
|
nsAutoScrollTimer *mAutoScrollTimer; // timer for autoscrolling.
|
2000-05-04 12:35:42 +04:00
|
|
|
nsCOMPtr<nsISupportsArray> mSelectionListeners;
|
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 nsSelection : public nsIFrameSelection
|
|
|
|
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
/*interfaces for addref and release and queryinterface*/
|
|
|
|
|
|
|
|
NS_DECL_ISUPPORTS
|
|
|
|
|
|
|
|
/*BEGIN nsIFrameSelection interfaces*/
|
2000-05-02 07:44:17 +04:00
|
|
|
NS_IMETHOD Init(nsIFocusTracker *aTracker, nsIContent *aLimiter);
|
2000-05-13 12:07:34 +04:00
|
|
|
NS_IMETHOD SetScrollableView(nsIScrollableView *aScrollView);
|
|
|
|
|
2000-03-22 02:58:02 +03:00
|
|
|
NS_IMETHOD ShutDown();
|
|
|
|
NS_IMETHOD HandleTextEvent(nsGUIEvent *aGUIEvent);
|
|
|
|
NS_IMETHOD HandleKeyEvent(nsIPresContext* aPresContext, nsGUIEvent *aGuiEvent);
|
|
|
|
NS_IMETHOD HandleClick(nsIContent *aNewFocus, PRUint32 aContentOffset, PRUint32 aContentEndOffset,
|
|
|
|
PRBool aContinueSelection, PRBool aMultipleSelection,PRBool aHint);
|
|
|
|
NS_IMETHOD HandleDrag(nsIPresContext *aPresContext, nsIFrame *aFrame, nsPoint& aPoint);
|
2000-12-21 01:13:54 +03:00
|
|
|
NS_IMETHOD HandleTableSelection(nsIContent *aParentContent, PRInt32 aContentOffset, PRInt32 aTarget, nsMouseEvent *aMouseEvent);
|
2000-03-22 02:58:02 +03:00
|
|
|
NS_IMETHOD StartAutoScrollTimer(nsIPresContext *aPresContext, nsIFrame *aFrame, nsPoint& aPoint, PRUint32 aDelay);
|
|
|
|
NS_IMETHOD StopAutoScrollTimer();
|
|
|
|
NS_IMETHOD EnableFrameNotification(PRBool aEnable){mNotifyFrames = aEnable; return NS_OK;}
|
|
|
|
NS_IMETHOD LookUpSelection(nsIContent *aContent, PRInt32 aContentOffset, PRInt32 aContentLength,
|
|
|
|
SelectionDetails **aReturnDetails, PRBool aSlowCheck);
|
|
|
|
NS_IMETHOD SetMouseDownState(PRBool aState);
|
|
|
|
NS_IMETHOD GetMouseDownState(PRBool *aState);
|
2000-04-14 00:21:32 +04:00
|
|
|
|
2000-05-16 07:03:13 +04:00
|
|
|
NS_IMETHOD GetTableCellSelection(PRBool *aState){if (aState){*aState = mSelectingTableCellMode != 0; return NS_OK;}return NS_ERROR_NULL_POINTER;}
|
2000-06-03 03:05:06 +04:00
|
|
|
NS_IMETHOD ClearTableCellSelection(){mSelectingTableCellMode = 0; return NS_OK;}
|
2000-04-14 00:21:32 +04:00
|
|
|
NS_IMETHOD GetTableCellSelectionStyleColor(const nsStyleColor **aStyleColor);
|
|
|
|
|
2000-09-14 15:45:01 +04:00
|
|
|
NS_IMETHOD GetSelection(SelectionType aType, nsISelection **aDomSelection);
|
2000-03-22 02:58:02 +03:00
|
|
|
NS_IMETHOD ScrollSelectionIntoView(SelectionType aType, SelectionRegion aRegion);
|
|
|
|
NS_IMETHOD RepaintSelection(nsIPresContext* aPresContext, SelectionType aType);
|
2000-06-28 08:00:12 +04:00
|
|
|
NS_IMETHOD GetFrameForNodeOffset(nsIContent *aNode, PRInt32 aOffset, HINT aHint, nsIFrame **aReturnFrame, PRInt32 *aReturnOffset);
|
2000-08-09 03:38:00 +04:00
|
|
|
|
|
|
|
NS_IMETHOD AdjustOffsetsFromStyle(nsIFrame *aFrame, PRBool *changeSelection,
|
|
|
|
nsIContent** outContent, PRInt32* outStartOffset, PRInt32* outEndOffset);
|
|
|
|
|
2000-06-28 08:00:12 +04:00
|
|
|
NS_IMETHOD SetHint(HINT aHintRight);
|
|
|
|
NS_IMETHOD GetHint(HINT *aHintRight);
|
2000-03-22 02:58:02 +03:00
|
|
|
NS_IMETHOD CharacterMove(PRBool aForward, PRBool aExtend);
|
|
|
|
NS_IMETHOD WordMove(PRBool aForward, PRBool aExtend);
|
|
|
|
NS_IMETHOD LineMove(PRBool aForward, PRBool aExtend);
|
2000-04-14 00:21:32 +04:00
|
|
|
NS_IMETHOD IntraLineMove(PRBool aForward, PRBool aExtend);
|
2000-03-22 02:58:02 +03:00
|
|
|
NS_IMETHOD SelectAll();
|
2000-04-28 10:21:31 +04:00
|
|
|
NS_IMETHOD SetDisplaySelection(PRInt16 aState);
|
|
|
|
NS_IMETHOD GetDisplaySelection(PRInt16 *aState);
|
2000-05-26 00:04:02 +04:00
|
|
|
NS_IMETHOD SetDelayCaretOverExistingSelection(PRBool aDelay);
|
|
|
|
NS_IMETHOD GetDelayCaretOverExistingSelection(PRBool *aDelay);
|
|
|
|
NS_IMETHOD SetDelayedCaretData(nsMouseEvent *aMouseEvent);
|
|
|
|
NS_IMETHOD GetDelayedCaretData(nsMouseEvent **aMouseEvent);
|
2000-08-02 05:47:55 +04:00
|
|
|
NS_IMETHOD GetLimiter(nsIContent **aLimiterContent);
|
2000-03-22 02:58:02 +03:00
|
|
|
/*END nsIFrameSelection interfacse*/
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
nsSelection();
|
|
|
|
virtual ~nsSelection();
|
|
|
|
|
|
|
|
NS_IMETHOD StartBatchChanges();
|
|
|
|
NS_IMETHOD EndBatchChanges();
|
|
|
|
NS_IMETHOD DeleteFromDocument();
|
2000-04-28 10:21:31 +04:00
|
|
|
|
2000-03-22 02:58:02 +03:00
|
|
|
nsIFocusTracker *GetTracker(){return mTracker;}
|
2000-12-21 01:13:54 +03:00
|
|
|
|
2000-03-22 02:58:02 +03:00
|
|
|
private:
|
|
|
|
NS_IMETHOD TakeFocus(nsIContent *aNewFocus, PRUint32 aContentOffset, PRUint32 aContentEndOffset,
|
|
|
|
PRBool aContinueSelection, PRBool aMultipleSelection);
|
|
|
|
|
2000-06-09 09:14:19 +04:00
|
|
|
//post and pop reasons for notifications. we may stack these later
|
|
|
|
void PostReason(short aReason){mReason = aReason;}
|
|
|
|
short PopReason(){short retval = mReason; mReason=0;return retval;}
|
|
|
|
|
2000-11-29 03:13:00 +03:00
|
|
|
friend class nsTypedSelection;
|
2000-03-22 02:58:02 +03:00
|
|
|
#ifdef DEBUG
|
|
|
|
void printSelection(); // for debugging
|
|
|
|
#endif /* DEBUG */
|
|
|
|
|
|
|
|
void ResizeBuffer(PRUint32 aNewBufSize);
|
|
|
|
/*HELPER METHODS*/
|
|
|
|
nsresult MoveCaret(PRUint32 aKeycode, PRBool aContinue, nsSelectionAmount aAmount);
|
|
|
|
|
|
|
|
nscoord FetchDesiredX(); //the x position requested by the Key Handling for up down
|
|
|
|
void InvalidateDesiredX(); //do not listen to mDesiredX you must get another.
|
|
|
|
void SetDesiredX(nscoord aX); //set the mDesiredX
|
|
|
|
|
|
|
|
nsresult GetRootForContentSubtree(nsIContent *aContent, nsIContent **aParent);
|
|
|
|
nsresult GetGlobalViewOffsetsFromFrame(nsIPresContext *aPresContext, nsIFrame *aFrame, nscoord *offsetX, nscoord *offsetY);
|
|
|
|
nsresult ConstrainFrameAndPointToAnchorSubtree(nsIPresContext *aPresContext, nsIFrame *aFrame, nsPoint& aPoint, nsIFrame **aRetFrame, nsPoint& aRetPoint);
|
|
|
|
|
|
|
|
PRUint32 GetBatching(){return mBatching;}
|
|
|
|
PRBool GetNotifyFrames(){return mNotifyFrames;}
|
|
|
|
void SetDirty(PRBool aDirty=PR_TRUE){if (mBatching) mChangesDuringBatching = aDirty;}
|
|
|
|
|
2000-04-14 15:21:19 +04:00
|
|
|
nsresult NotifySelectionListeners(SelectionType aType); // add parameters to say collapsed etc?
|
2000-03-22 02:58:02 +03:00
|
|
|
|
2000-08-09 03:38:00 +04:00
|
|
|
// utility method to lookup frame style
|
|
|
|
nsresult FrameOrParentHasSpecialSelectionStyle(nsIFrame* aFrame, PRUint8 aSelectionStyle, nsIFrame* *foundFrame);
|
2000-03-22 02:58:02 +03:00
|
|
|
|
2000-11-29 03:13:00 +03:00
|
|
|
nsTypedSelection *mDomSelections[nsISelectionController::NUM_SELECTIONTYPES];
|
2000-05-13 12:07:34 +04:00
|
|
|
nsIScrollableView *GetScrollView(){return mScrollView;}
|
2000-03-22 02:58:02 +03:00
|
|
|
|
2000-05-16 07:03:13 +04:00
|
|
|
// Table selection support.
|
|
|
|
// Interfaces that let us get info based on cellmap locations
|
|
|
|
nsITableLayout* GetTableLayout(nsIContent *aTableContent);
|
|
|
|
nsITableCellLayout* GetCellLayout(nsIContent *aCellContent);
|
2000-12-21 01:13:54 +03:00
|
|
|
|
2000-03-24 05:52:07 +03:00
|
|
|
nsresult SelectBlockOfCells(nsIContent *aEndNode);
|
2000-05-16 07:03:13 +04:00
|
|
|
nsresult SelectRowOrColumn(nsIContent *aCellContent, PRUint32 aTarget);
|
2000-03-22 02:58:02 +03:00
|
|
|
nsresult GetCellIndexes(nsIContent *aCell, PRInt32 &aRowIndex, PRInt32 &aColIndex);
|
2000-05-16 07:03:13 +04:00
|
|
|
|
2000-03-24 05:52:07 +03:00
|
|
|
nsresult GetFirstSelectedCellAndRange(nsIDOMNode **aCell, nsIDOMRange **aRange);
|
|
|
|
nsresult GetNextSelectedCellAndRange(nsIDOMNode **aCell, nsIDOMRange **aRange);
|
|
|
|
nsresult GetFirstCellNodeInRange(nsIDOMRange *aRange, nsIDOMNode **aCellNode);
|
2000-03-22 02:58:02 +03:00
|
|
|
// aTableNode may be null if table isn't needed to be returned
|
|
|
|
PRBool IsInSameTable(nsIContent *aContent1, nsIContent *aContent2, nsIContent **aTableNode);
|
|
|
|
nsresult GetParentTable(nsIContent *aCellNode, nsIContent **aTableNode);
|
2000-05-16 07:03:13 +04:00
|
|
|
nsresult SelectCellElement(nsIDOMElement* aCellElement);
|
2000-03-22 02:58:02 +03:00
|
|
|
nsresult CreateAndAddRange(nsIDOMNode *aParentNode, PRInt32 aOffset);
|
2000-05-31 04:07:58 +04:00
|
|
|
nsresult ClearNormalSelection();
|
2000-03-22 02:58:02 +03:00
|
|
|
|
|
|
|
nsCOMPtr<nsIContent> mStartSelectedCell;
|
|
|
|
nsCOMPtr<nsIContent> mEndSelectedCell;
|
2000-05-31 04:07:58 +04:00
|
|
|
nsCOMPtr<nsIContent> mAppendStartSelectedCell;
|
|
|
|
nsCOMPtr<nsIContent> mUnselectCellOnMouseUp;
|
2000-05-16 07:03:13 +04:00
|
|
|
PRBool mSelectingTableCells;
|
2000-12-21 01:13:54 +03:00
|
|
|
PRInt32 mSelectingTableCellMode;
|
2000-05-16 07:03:13 +04:00
|
|
|
PRInt32 mSelectedCellIndex;
|
2000-03-22 02:58:02 +03:00
|
|
|
|
|
|
|
//batching
|
|
|
|
PRInt32 mBatching;
|
|
|
|
PRBool mChangesDuringBatching;
|
|
|
|
PRBool mNotifyFrames;
|
2000-05-04 12:35:42 +04:00
|
|
|
|
2000-05-02 07:44:17 +04:00
|
|
|
nsIContent *mLimiter; //limit selection navigation to a child of this node.
|
2000-03-22 02:58:02 +03:00
|
|
|
nsIFocusTracker *mTracker;
|
2000-05-02 07:44:17 +04:00
|
|
|
PRBool mMouseDownState; //for drag purposes
|
|
|
|
PRInt16 mDisplaySelection; //for visual display purposes.
|
2000-03-22 02:58:02 +03:00
|
|
|
PRInt32 mDesiredX;
|
|
|
|
PRBool mDesiredXSet;
|
2000-05-13 12:07:34 +04:00
|
|
|
nsIScrollableView *mScrollView;
|
2000-05-26 00:04:02 +04:00
|
|
|
|
|
|
|
PRBool mDelayCaretOverExistingSelection;
|
|
|
|
PRBool mDelayedMouseEventValid;
|
|
|
|
nsMouseEvent mDelayedMouseEvent;
|
2000-06-09 09:14:19 +04:00
|
|
|
short mReason; //reason for notifications of selection changing
|
2000-03-22 02:58:02 +03:00
|
|
|
public:
|
|
|
|
static nsIAtom *sTableAtom;
|
2000-08-10 02:34:17 +04:00
|
|
|
static nsIAtom *sRowAtom;
|
2000-03-22 02:58:02 +03:00
|
|
|
static nsIAtom *sCellAtom;
|
|
|
|
static nsIAtom *sTbodyAtom;
|
|
|
|
static PRInt32 sInstanceCount;
|
2000-04-14 00:21:32 +04:00
|
|
|
static nsStyleColor sTableStyleColor;
|
2000-03-22 02:58:02 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
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
|
|
|
|
friend class nsSelection;
|
|
|
|
|
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()
|
2000-08-30 23:42:47 +04:00
|
|
|
: mSelection(0), mView(0), mPresContext(0), mPoint(0,0), mDelay(30)
|
2000-03-22 02:58:02 +03:00
|
|
|
{
|
|
|
|
NS_INIT_ISUPPORTS();
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual ~nsAutoScrollTimer()
|
|
|
|
{
|
2000-08-30 23:42:47 +04:00
|
|
|
if (mTimer)
|
|
|
|
mTimer->Cancel();
|
2000-03-22 02:58:02 +03:00
|
|
|
}
|
|
|
|
|
2000-08-30 23:42:47 +04:00
|
|
|
nsresult Start(nsIPresContext *aPresContext, nsIView *aView, nsPoint &aPoint)
|
2000-03-22 02:58:02 +03:00
|
|
|
{
|
2000-08-30 23:42:47 +04:00
|
|
|
mView = aView;
|
2000-03-22 02:58:02 +03:00
|
|
|
mPresContext = aPresContext;
|
|
|
|
mPoint = aPoint;
|
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
return mTimer->Init(this, mDelay);
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult Stop()
|
|
|
|
{
|
|
|
|
nsresult result = NS_OK;
|
|
|
|
|
|
|
|
if (mTimer)
|
|
|
|
{
|
|
|
|
mTimer->Cancel();
|
|
|
|
mTimer = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2000-11-29 03:13:00 +03:00
|
|
|
nsresult Init(nsSelection *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;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHOD_(void) Notify(nsITimer *timer)
|
|
|
|
{
|
2000-08-30 23:42:47 +04:00
|
|
|
if (mSelection && mPresContext && mView)
|
2000-03-22 02:58:02 +03:00
|
|
|
{
|
2000-08-30 23:42:47 +04:00
|
|
|
void *clientData = 0;
|
|
|
|
mView->GetClientData(clientData);
|
|
|
|
nsIFrame *frame = (nsIFrame *)clientData;
|
|
|
|
|
|
|
|
if (!frame)
|
|
|
|
return;
|
|
|
|
|
2000-04-12 07:04:11 +04:00
|
|
|
//the frame passed in here will be a root frame for the view. there is no need to call the constrain
|
|
|
|
//method here. the root frame has NO content now unfortunately...
|
|
|
|
PRInt32 startPos = 0;
|
|
|
|
PRInt32 contentOffsetEnd = 0;
|
|
|
|
PRBool beginOfContent;
|
|
|
|
nsCOMPtr<nsIContent> newContent;
|
2000-08-30 23:42:47 +04:00
|
|
|
nsresult result = frame->GetContentAndOffsetsFromPoint(mPresContext, mPoint,
|
2000-04-12 07:04:11 +04:00
|
|
|
getter_AddRefs(newContent),
|
|
|
|
startPos, contentOffsetEnd,beginOfContent);
|
|
|
|
|
|
|
|
if (NS_SUCCEEDED(result))
|
|
|
|
result = mFrameSelection->HandleClick(newContent, startPos, contentOffsetEnd , PR_TRUE, PR_FALSE, beginOfContent);
|
2000-08-30 23:42:47 +04:00
|
|
|
|
2000-04-12 07:04:11 +04:00
|
|
|
//mFrameSelection->HandleDrag(mPresContext, mFrame, mPoint);
|
2000-08-30 23:42:47 +04:00
|
|
|
mSelection->DoAutoScrollView(mPresContext, mView, mPoint, PR_TRUE);
|
2000-03-22 02:58:02 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
private:
|
|
|
|
nsSelection *mFrameSelection;
|
2000-11-29 03:13:00 +03:00
|
|
|
nsTypedSelection *mSelection;
|
2000-05-17 06:49:35 +04:00
|
|
|
nsCOMPtr<nsITimer> mTimer;
|
2000-08-30 23:42:47 +04:00
|
|
|
nsIView *mView;
|
2000-03-22 02:58:02 +03:00
|
|
|
nsIPresContext *mPresContext;
|
|
|
|
nsPoint mPoint;
|
|
|
|
PRUint32 mDelay;
|
|
|
|
};
|
|
|
|
|
|
|
|
NS_IMPL_ADDREF(nsAutoScrollTimer)
|
|
|
|
NS_IMPL_RELEASE(nsAutoScrollTimer)
|
|
|
|
NS_IMPL_QUERY_INTERFACE1(nsAutoScrollTimer, nsITimerCallback)
|
|
|
|
|
2000-08-30 23:42:47 +04:00
|
|
|
nsresult NS_NewAutoScrollTimer(nsAutoScrollTimer **aResult);
|
|
|
|
|
2000-03-22 02:58:02 +03:00
|
|
|
nsresult NS_NewAutoScrollTimer(nsAutoScrollTimer **aResult)
|
|
|
|
{
|
|
|
|
if (!aResult)
|
|
|
|
return NS_ERROR_NULL_POINTER;
|
|
|
|
|
|
|
|
*aResult = (nsAutoScrollTimer*) new nsAutoScrollTimer;
|
|
|
|
|
|
|
|
if (!aResult)
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
|
|
|
|
NS_ADDREF(*aResult);
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult NS_NewSelection(nsIFrameSelection **aFrameSelection);
|
|
|
|
|
|
|
|
nsresult NS_NewSelection(nsIFrameSelection **aFrameSelection)
|
|
|
|
{
|
|
|
|
nsSelection *rlist = new nsSelection;
|
|
|
|
if (!rlist)
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
*aFrameSelection = (nsIFrameSelection *)rlist;
|
2000-05-11 08:25:43 +04:00
|
|
|
rlist->AddRef();
|
|
|
|
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;
|
2000-05-11 08:25:43 +04:00
|
|
|
rlist->AddRef();
|
|
|
|
return NS_OK;
|
|
|
|
}
|
2000-03-22 02:58:02 +03:00
|
|
|
|
|
|
|
//Horrible statics but no choice
|
|
|
|
nsIAtom *nsSelection::sTableAtom = 0;
|
2000-08-10 02:34:17 +04:00
|
|
|
nsIAtom *nsSelection::sRowAtom = 0;
|
2000-03-22 02:58:02 +03:00
|
|
|
nsIAtom *nsSelection::sCellAtom = 0;
|
|
|
|
nsIAtom *nsSelection::sTbodyAtom = 0;
|
|
|
|
PRInt32 nsSelection::sInstanceCount = 0;
|
2000-04-14 00:21:32 +04:00
|
|
|
nsStyleColor nsSelection::sTableStyleColor;
|
2000-03-31 11:17:22 +04: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;
|
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;
|
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
|
|
|
}
|
|
|
|
|
2000-03-31 11:17:22 +04:00
|
|
|
|
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)
|
|
|
|
{
|
|
|
|
NS_INIT_REFCNT();
|
|
|
|
if (!aList)
|
|
|
|
{
|
|
|
|
NS_NOTREACHED("nsSelection");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
mDomSelection = aList;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
nsSelectionIterator::~nsSelectionIterator()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
////////////END nsSelectionIterator methods
|
|
|
|
|
|
|
|
////////////BEGIN nsIFrameSelectionIterator methods
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsSelectionIterator::Next()
|
|
|
|
{
|
|
|
|
mIndex++;
|
|
|
|
PRUint32 cnt;
|
|
|
|
nsresult rv = mDomSelection->mRangeArray->Count(&cnt);
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
if (mIndex < (PRInt32)cnt)
|
|
|
|
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;
|
|
|
|
PRUint32 cnt;
|
|
|
|
nsresult rv = mDomSelection->mRangeArray->Count(&cnt);
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
mIndex = (PRInt32)cnt-1;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsSelectionIterator::CurrentItem(nsISupports **aItem)
|
|
|
|
{
|
|
|
|
if (!aItem)
|
|
|
|
return NS_ERROR_NULL_POINTER;
|
|
|
|
PRUint32 cnt;
|
|
|
|
nsresult rv = mDomSelection->mRangeArray->Count(&cnt);
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
if (mIndex >=0 && mIndex < (PRInt32)cnt){
|
|
|
|
*aItem = mDomSelection->mRangeArray->ElementAt(mIndex);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMPL_ADDREF(nsSelectionIterator)
|
|
|
|
|
|
|
|
NS_IMPL_RELEASE(nsSelectionIterator)
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsSelectionIterator::CurrentItem(nsIDOMRange **aItem)
|
|
|
|
{
|
|
|
|
if (!aItem)
|
|
|
|
return NS_ERROR_NULL_POINTER;
|
|
|
|
PRUint32 cnt;
|
|
|
|
nsresult rv = mDomSelection->mRangeArray->Count(&cnt);
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
if (mIndex >=0 && mIndex < (PRInt32)cnt){
|
|
|
|
nsCOMPtr<nsISupports> indexIsupports = dont_AddRef(mDomSelection->mRangeArray->ElementAt(mIndex));
|
|
|
|
return indexIsupports->QueryInterface(NS_GET_IID(nsIDOMRange),(void **)aItem);
|
|
|
|
}
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsSelectionIterator::IsDone()
|
|
|
|
{
|
|
|
|
PRUint32 cnt;
|
|
|
|
nsresult rv = mDomSelection->mRangeArray->Count(&cnt);
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
if (mIndex >= 0 && mIndex < (PRInt32)cnt ) {
|
|
|
|
return NS_ENUMERATOR_FALSE;
|
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsSelectionIterator::QueryInterface(REFNSIID aIID, void** aInstancePtr)
|
|
|
|
{
|
|
|
|
if (nsnull == aInstancePtr) {
|
|
|
|
return NS_ERROR_NULL_POINTER;
|
|
|
|
}
|
|
|
|
if (aIID.Equals(NS_GET_IID(nsIEnumerator))) {
|
|
|
|
*aInstancePtr = NS_STATIC_CAST(nsIEnumerator*, this);
|
|
|
|
NS_ADDREF_THIS();
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
if (aIID.Equals(NS_GET_IID(nsIBidirectionalEnumerator))) {
|
|
|
|
*aInstancePtr = NS_STATIC_CAST(nsIBidirectionalEnumerator*, this);
|
|
|
|
NS_ADDREF_THIS();
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
return mDomSelection->QueryInterface(aIID, aInstancePtr);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
////////////END nsIFrameSelectionIterator methods
|
|
|
|
|
|
|
|
#ifdef XP_MAC
|
|
|
|
#pragma mark -
|
|
|
|
#endif
|
|
|
|
|
|
|
|
////////////BEGIN nsSelection methods
|
|
|
|
|
|
|
|
nsSelection::nsSelection()
|
|
|
|
{
|
|
|
|
NS_INIT_REFCNT();
|
|
|
|
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;
|
|
|
|
mDomSelections[i]->AddRef();
|
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.
|
2000-03-22 02:58:02 +03:00
|
|
|
|
|
|
|
if (sInstanceCount <= 0)
|
|
|
|
{
|
|
|
|
sTableAtom = NS_NewAtom("table");
|
2000-08-10 02:34:17 +04:00
|
|
|
sRowAtom = NS_NewAtom("tr");
|
|
|
|
sCellAtom = NS_NewAtom("td");
|
2000-03-22 02:58:02 +03:00
|
|
|
sTbodyAtom = NS_NewAtom("tbody");
|
2000-04-14 00:21:32 +04:00
|
|
|
sTableStyleColor.mColor = NS_RGB(128,0,0);
|
|
|
|
sTableStyleColor.mBackgroundColor = NS_RGB(128,0,0);
|
|
|
|
sTableStyleColor.mOpacity= (float)1;
|
|
|
|
sTableStyleColor.mBackgroundAttachment=0;
|
|
|
|
sTableStyleColor.mBackgroundFlags=NS_STYLE_BG_IMAGE_NONE;
|
|
|
|
sTableStyleColor.mBackgroundRepeat=1;
|
|
|
|
sTableStyleColor.mBackgroundXPosition=0;
|
|
|
|
sTableStyleColor.mBackgroundYPosition=0;
|
|
|
|
sTableStyleColor.mCursor=1;
|
2000-03-22 02:58:02 +03:00
|
|
|
}
|
|
|
|
mHint = HINTLEFT;
|
|
|
|
sInstanceCount ++;
|
|
|
|
mSelectingTableCells = PR_FALSE;
|
2000-05-16 07:03:13 +04:00
|
|
|
mSelectingTableCellMode = 0;
|
2000-04-14 00:21:32 +04:00
|
|
|
|
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
|
|
|
|
nsresult rv;
|
2000-09-14 03:57:52 +04:00
|
|
|
NS_WITH_SERVICE(nsIPref, prefs, "@mozilla.org/preferences;1", &rv);
|
2000-06-07 03:14:42 +04:00
|
|
|
if (NS_SUCCEEDED(rv) && prefs)
|
2000-04-14 15:21:19 +04:00
|
|
|
{
|
2000-06-07 03:14:42 +04:00
|
|
|
static char pref[] = "clipboard.autocopy";
|
|
|
|
PRBool autoCopy = PR_FALSE;
|
|
|
|
if (NS_SUCCEEDED(prefs->GetBoolPref(pref, &autoCopy)) && autoCopy)
|
|
|
|
{
|
2000-09-14 03:57:52 +04:00
|
|
|
NS_WITH_SERVICE(nsIAutoCopyService, autoCopyService, "@mozilla.org/autocopy;1", &rv);
|
2000-06-07 03:14:42 +04:00
|
|
|
|
|
|
|
if (NS_SUCCEEDED(rv) && autoCopyService)
|
|
|
|
{
|
|
|
|
PRInt8 index = GetIndexFromSelectionType(nsISelectionController::SELECTION_NORMAL);
|
|
|
|
if (mDomSelections[index])
|
|
|
|
autoCopyService->Listen(mDomSelections[index]);
|
|
|
|
}
|
|
|
|
}
|
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
|
|
|
|
|
|
|
mDelayCaretOverExistingSelection = PR_TRUE;
|
|
|
|
mDelayedMouseEventValid = PR_FALSE;
|
2000-09-14 15:45:01 +04:00
|
|
|
mReason = nsISelectionListener::NO_REASON;
|
2000-03-22 02:58:02 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2000-05-11 08:25:43 +04:00
|
|
|
nsSelection::~nsSelection()
|
2000-03-22 02:58:02 +03:00
|
|
|
{
|
|
|
|
if (sInstanceCount <= 1)
|
|
|
|
{
|
|
|
|
NS_IF_RELEASE(sTableAtom);
|
2000-08-10 02:34:17 +04:00
|
|
|
NS_IF_RELEASE(sRowAtom);
|
2000-03-22 02:58:02 +03:00
|
|
|
NS_IF_RELEASE(sCellAtom);
|
|
|
|
NS_IF_RELEASE(sTbodyAtom);
|
|
|
|
}
|
|
|
|
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
|
|
|
if (mDomSelections[i])
|
|
|
|
NS_IF_RELEASE(mDomSelections[i]);
|
|
|
|
}
|
|
|
|
sInstanceCount--;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
NS_IMPL_ADDREF(nsSelection)
|
|
|
|
|
|
|
|
NS_IMPL_RELEASE(nsSelection)
|
|
|
|
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsSelection::QueryInterface(REFNSIID aIID, void** aInstancePtr)
|
|
|
|
{
|
|
|
|
if (nsnull == aInstancePtr) {
|
|
|
|
return NS_ERROR_NULL_POINTER;
|
|
|
|
}
|
|
|
|
if (aIID.Equals(NS_GET_IID(nsIFrameSelection))) {
|
|
|
|
nsIFrameSelection* tmp = this;
|
|
|
|
*aInstancePtr = (void*) tmp;
|
|
|
|
NS_ADDREF_THIS();
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
if (aIID.Equals(NS_GET_IID(nsISupports))) {
|
|
|
|
// use *first* base class for ISupports
|
|
|
|
nsIFrameSelection* tmp1 = this;
|
|
|
|
nsISupports* tmp2 = tmp1;
|
|
|
|
*aInstancePtr = (void*) tmp2;
|
|
|
|
NS_ADDREF_THIS();
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
NS_ASSERTION(PR_FALSE,"bad query interface in FrameSelection");
|
|
|
|
return NS_NOINTERFACE;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
nscoord
|
|
|
|
nsSelection::FetchDesiredX() //the x position requested by the Key Handling for up down
|
|
|
|
{
|
|
|
|
if (!mTracker)
|
|
|
|
{
|
|
|
|
NS_ASSERTION(0,"fetch desired X failed\n");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
if (mDesiredXSet)
|
|
|
|
return mDesiredX;
|
|
|
|
else {
|
|
|
|
nsRect coord;
|
|
|
|
PRBool collapsed;
|
|
|
|
nsCOMPtr<nsICaret> caret;
|
|
|
|
nsCOMPtr<nsIPresContext> context;
|
|
|
|
nsCOMPtr<nsIPresShell> shell;
|
|
|
|
nsresult result = mTracker->GetPresContext(getter_AddRefs(context));
|
|
|
|
if (NS_FAILED(result) || !context)
|
|
|
|
return result;
|
|
|
|
result = context->GetShell(getter_AddRefs(shell));
|
|
|
|
if (NS_FAILED(result) || !shell)
|
|
|
|
return result;
|
|
|
|
result = shell->GetCaret(getter_AddRefs(caret));
|
|
|
|
if (NS_FAILED(result) || !caret)
|
|
|
|
return result;
|
|
|
|
|
2000-05-04 12:35:42 +04:00
|
|
|
PRInt8 index = GetIndexFromSelectionType(nsISelectionController::SELECTION_NORMAL);
|
|
|
|
result = caret->GetWindowRelativeCoordinates(coord,collapsed,mDomSelections[index]);
|
2000-03-22 02:58:02 +03:00
|
|
|
if (NS_FAILED(result))
|
|
|
|
return result;
|
|
|
|
return coord.x;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
nsSelection::InvalidateDesiredX() //do not listen to mDesiredX you must get another.
|
|
|
|
{
|
|
|
|
mDesiredXSet = PR_FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
nsSelection::SetDesiredX(nscoord aX) //set the mDesiredX
|
|
|
|
{
|
|
|
|
mDesiredX = aX;
|
|
|
|
mDesiredXSet = PR_TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
nsSelection::GetRootForContentSubtree(nsIContent *aContent, nsIContent **aParent)
|
|
|
|
{
|
|
|
|
// 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.
|
|
|
|
// Anonymous content has a pointer to it's parent, but it is not listed
|
|
|
|
// as a child of it's parent. In this case, the anonymous content would
|
|
|
|
// be considered the root of the subtree.
|
|
|
|
|
2000-04-28 17:58:08 +04:00
|
|
|
nsresult result = NS_OK;
|
2000-03-22 02:58:02 +03:00
|
|
|
|
|
|
|
if (!aContent || !aParent)
|
|
|
|
return NS_ERROR_NULL_POINTER;
|
|
|
|
|
|
|
|
*aParent = 0;
|
|
|
|
|
|
|
|
nsCOMPtr<nsIContent> parent = do_QueryInterface(aContent);
|
|
|
|
nsCOMPtr<nsIContent> child = parent;
|
|
|
|
|
|
|
|
while (child)
|
|
|
|
{
|
|
|
|
result = child->GetParent(*getter_AddRefs(parent));
|
|
|
|
|
|
|
|
if (NS_FAILED(result))
|
|
|
|
return result;
|
|
|
|
|
|
|
|
if (!parent)
|
|
|
|
break;
|
|
|
|
|
|
|
|
PRInt32 childIndex = 0;
|
|
|
|
PRInt32 childCount = 0;
|
|
|
|
|
|
|
|
result = parent->ChildCount(childCount);
|
|
|
|
|
|
|
|
if (NS_FAILED(result))
|
|
|
|
return result;
|
|
|
|
|
|
|
|
if (childCount < 1)
|
|
|
|
break;
|
|
|
|
|
|
|
|
result = parent->IndexOf(child, childIndex);
|
|
|
|
|
|
|
|
if (NS_FAILED(result))
|
|
|
|
return result;
|
|
|
|
|
|
|
|
if (childIndex < 0 || childIndex >= childCount)
|
|
|
|
break;
|
|
|
|
|
|
|
|
child = parent;
|
|
|
|
}
|
|
|
|
|
|
|
|
*aParent = child;
|
|
|
|
|
|
|
|
NS_IF_ADDREF(*aParent);
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
nsSelection::GetGlobalViewOffsetsFromFrame(nsIPresContext *aPresContext, nsIFrame *aFrame, nscoord *offsetX, nscoord *offsetY)
|
|
|
|
{
|
|
|
|
//
|
|
|
|
// The idea here is to figure out what the offset of aFrame's view
|
|
|
|
// is within the global space. Where I define the global space to
|
|
|
|
// be the coordinate system that exists above all views.
|
|
|
|
//
|
|
|
|
// The offsets are calculated by walking up the view parent hierarchy,
|
|
|
|
// adding up all the view positions, until there are no more views.
|
|
|
|
//
|
|
|
|
// A point in a view's coordinate space can be converted to the global
|
|
|
|
// coordinate space by simply adding the offsets returned by this method
|
|
|
|
// to the point itself.
|
|
|
|
//
|
|
|
|
|
|
|
|
if (!aPresContext || !aFrame || !offsetX || !offsetY)
|
|
|
|
return NS_ERROR_NULL_POINTER;
|
|
|
|
|
|
|
|
*offsetX = *offsetY = 0;
|
|
|
|
|
|
|
|
nsresult result;
|
|
|
|
nsIFrame *frame = aFrame;
|
|
|
|
nsIView *view;
|
|
|
|
|
|
|
|
while (frame)
|
|
|
|
{
|
|
|
|
result = frame->GetParentWithView(aPresContext, &frame);
|
|
|
|
|
|
|
|
if (NS_FAILED(result))
|
|
|
|
return result;
|
|
|
|
|
|
|
|
if (frame) {
|
|
|
|
view = 0;
|
|
|
|
|
|
|
|
result = frame->GetView(aPresContext, &view);
|
|
|
|
|
|
|
|
if (NS_FAILED(result))
|
|
|
|
return result;
|
|
|
|
|
|
|
|
if (view)
|
|
|
|
{
|
|
|
|
nscoord vX = 0, vY = 0;
|
|
|
|
|
|
|
|
result = view->GetPosition(&vX, &vY);
|
|
|
|
|
|
|
|
if (NS_FAILED(result))
|
|
|
|
return result;
|
|
|
|
|
|
|
|
*offsetX += vX;
|
|
|
|
*offsetY += vY;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
nsSelection::ConstrainFrameAndPointToAnchorSubtree(nsIPresContext *aPresContext, nsIFrame *aFrame, nsPoint& aPoint, nsIFrame **aRetFrame, nsPoint& aRetPoint)
|
|
|
|
{
|
|
|
|
//
|
|
|
|
// 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;
|
|
|
|
|
2000-06-28 08:00:12 +04:00
|
|
|
result = GetFrameForNodeOffset(anchorContent, anchorOffset, mHint, &anchorFrame, &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.
|
|
|
|
//
|
|
|
|
|
|
|
|
nsCOMPtr<nsIContent> content;
|
|
|
|
|
|
|
|
result = aFrame->GetContent(getter_AddRefs(content));
|
|
|
|
|
|
|
|
if (NS_FAILED(result))
|
|
|
|
return result;
|
|
|
|
|
|
|
|
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.
|
|
|
|
//
|
|
|
|
|
|
|
|
result = mTracker->GetPrimaryFrameFor(anchorRoot, aRetFrame);
|
|
|
|
|
|
|
|
if (NS_FAILED(result))
|
|
|
|
return result;
|
|
|
|
|
|
|
|
if (! *aRetFrame)
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
|
|
|
|
//
|
|
|
|
// Now make sure that aRetPoint is converted to the same coordinate
|
|
|
|
// system used by aRetFrame.
|
|
|
|
//
|
|
|
|
|
|
|
|
nsPoint frameOffset;
|
|
|
|
nsPoint retFrameOffset;
|
|
|
|
|
|
|
|
result = GetGlobalViewOffsetsFromFrame(aPresContext, aFrame, &frameOffset.x, &frameOffset.y);
|
|
|
|
|
|
|
|
if (NS_FAILED(result))
|
|
|
|
return result;
|
|
|
|
|
|
|
|
result = GetGlobalViewOffsetsFromFrame(aPresContext, *aRetFrame, &retFrameOffset.x, &retFrameOffset.y);
|
|
|
|
|
|
|
|
if (NS_FAILED(result))
|
|
|
|
return result;
|
|
|
|
|
|
|
|
aRetPoint = aPoint + frameOffset - retFrameOffset;
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
#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 */
|
|
|
|
|
|
|
|
#if OLD_SELECTION
|
|
|
|
nsCOMPtr<nsIAtom> GetTag(nsIDOMNode *aNode)
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsIAtom> atom;
|
|
|
|
|
|
|
|
if (!aNode)
|
|
|
|
{
|
2000-08-29 03:35:57 +04:00
|
|
|
NS_NOTREACHED("null node passed to GetTag()");
|
2000-03-22 02:58:02 +03:00
|
|
|
return atom;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsCOMPtr<nsIContent> content = do_QueryInterface(aNode);
|
|
|
|
if (content)
|
|
|
|
content->GetTag(*getter_AddRefs(atom));
|
|
|
|
|
|
|
|
return atom;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
ParentOffset(nsIDOMNode *aNode, nsIDOMNode **aParent, PRInt32 *aChildOffset)
|
|
|
|
{
|
|
|
|
if (!aNode || !aParent || !aChildOffset)
|
|
|
|
return NS_ERROR_NULL_POINTER;
|
|
|
|
nsresult result = NS_OK;
|
|
|
|
nsCOMPtr<nsIContent> content;
|
|
|
|
result = aNode->QueryInterface(NS_GET_IID(nsIContent),getter_AddRefs(content));
|
|
|
|
if (NS_SUCCEEDED(result) && content)
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsIContent> parent;
|
|
|
|
result = content->GetParent(*getter_AddRefs(parent));
|
|
|
|
if (NS_SUCCEEDED(result) && parent)
|
|
|
|
{
|
|
|
|
result = parent->IndexOf(content, *aChildOffset);
|
|
|
|
if (NS_SUCCEEDED(result))
|
|
|
|
result = parent->QueryInterface(NS_GET_IID(nsIDOMNode),(void **)aParent);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2000-05-02 07:44:17 +04:00
|
|
|
nsSelection::Init(nsIFocusTracker *aTracker, nsIContent *aLimiter)
|
2000-03-22 02:58:02 +03:00
|
|
|
{
|
|
|
|
mTracker = aTracker;
|
|
|
|
mMouseDownState = PR_FALSE;
|
|
|
|
mDesiredXSet = PR_FALSE;
|
2000-05-02 07:44:17 +04:00
|
|
|
mLimiter = aLimiter;
|
2000-05-13 12:07:34 +04:00
|
|
|
mScrollView = nsnull;
|
2000-03-22 02:58:02 +03:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2000-05-13 12:07:34 +04:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsSelection::SetScrollableView(nsIScrollableView *aScrollView)
|
|
|
|
{
|
|
|
|
mScrollView = aScrollView;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
2000-03-22 02:58:02 +03:00
|
|
|
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsSelection::ShutDown()
|
|
|
|
{
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsSelection::HandleTextEvent(nsGUIEvent *aGUIEvent)
|
|
|
|
{
|
|
|
|
if (!aGUIEvent)
|
|
|
|
return NS_ERROR_NULL_POINTER;
|
|
|
|
|
|
|
|
#ifdef DEBUG_TAGUE
|
2000-10-29 02:17:53 +04:00
|
|
|
printf("nsSelection: HandleTextEvent\n");
|
2000-03-22 02:58:02 +03:00
|
|
|
#endif
|
|
|
|
nsresult result(NS_OK);
|
|
|
|
if (NS_TEXT_EVENT == aGUIEvent->message) {
|
2000-04-27 11:37:12 +04:00
|
|
|
PRInt8 index = GetIndexFromSelectionType(nsISelectionController::SELECTION_NORMAL);
|
2000-03-31 11:17:22 +04:00
|
|
|
result = mDomSelections[index]->ScrollIntoView();
|
2000-03-22 02:58:02 +03:00
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
nsSelection::MoveCaret(PRUint32 aKeycode, PRBool aContinue, nsSelectionAmount aAmount)
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsIPresContext> context;
|
|
|
|
nsresult result = mTracker->GetPresContext(getter_AddRefs(context));
|
|
|
|
if (NS_FAILED(result) || !context)
|
|
|
|
return result?result:NS_ERROR_FAILURE;
|
|
|
|
|
|
|
|
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);
|
2000-03-31 11:17:22 +04:00
|
|
|
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)
|
|
|
|
{
|
|
|
|
desiredX= FetchDesiredX();
|
|
|
|
SetDesiredX(desiredX);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!isCollapsed && !aContinue) {
|
|
|
|
switch (aKeycode){
|
|
|
|
case nsIDOMKeyEvent::DOM_VK_LEFT :
|
|
|
|
case nsIDOMKeyEvent::DOM_VK_UP : {
|
2000-03-31 11:17:22 +04:00
|
|
|
if ((mDomSelections[index]->GetDirection() == eDirPrevious)) { //f,a
|
|
|
|
offsetused = mDomSelections[index]->FetchFocusOffset();
|
|
|
|
weakNodeUsed = mDomSelections[index]->FetchFocusNode();
|
2000-03-22 02:58:02 +03:00
|
|
|
}
|
|
|
|
else {
|
2000-03-31 11:17:22 +04:00
|
|
|
offsetused = mDomSelections[index]->FetchAnchorOffset();
|
|
|
|
weakNodeUsed = mDomSelections[index]->FetchAnchorNode();
|
2000-03-22 02:58:02 +03:00
|
|
|
}
|
2000-03-31 11:17:22 +04:00
|
|
|
result = mDomSelections[index]->Collapse(weakNodeUsed,offsetused);
|
|
|
|
mDomSelections[index]->ScrollIntoView();
|
2000-03-22 02:58:02 +03:00
|
|
|
return NS_OK;
|
|
|
|
} break;
|
|
|
|
case nsIDOMKeyEvent::DOM_VK_RIGHT :
|
|
|
|
case nsIDOMKeyEvent::DOM_VK_DOWN : {
|
2000-03-31 11:17:22 +04:00
|
|
|
if ((mDomSelections[index]->GetDirection() == eDirPrevious)) { //f,a
|
|
|
|
offsetused = mDomSelections[index]->FetchAnchorOffset();
|
|
|
|
weakNodeUsed = mDomSelections[index]->FetchAnchorNode();
|
2000-03-22 02:58:02 +03:00
|
|
|
}
|
|
|
|
else {
|
2000-03-31 11:17:22 +04:00
|
|
|
offsetused = mDomSelections[index]->FetchFocusOffset();
|
|
|
|
weakNodeUsed = mDomSelections[index]->FetchFocusNode();
|
2000-03-22 02:58:02 +03:00
|
|
|
}
|
2000-03-31 11:17:22 +04:00
|
|
|
result = mDomSelections[index]->Collapse(weakNodeUsed,offsetused);
|
|
|
|
mDomSelections[index]->ScrollIntoView();
|
2000-03-22 02:58:02 +03:00
|
|
|
return NS_OK;
|
|
|
|
} break;
|
|
|
|
|
|
|
|
}
|
|
|
|
// if (keyEvent->keyCode == nsIDOMKeyEvent::DOM_VK_UP || keyEvent->keyCode == nsIDOMKeyEvent::DOM_VK_DOWN)
|
|
|
|
// SetDesiredX(desiredX);
|
|
|
|
}
|
|
|
|
|
2000-03-31 11:17:22 +04:00
|
|
|
offsetused = mDomSelections[index]->FetchFocusOffset();
|
|
|
|
weakNodeUsed = mDomSelections[index]->FetchFocusNode();
|
2000-04-12 14:34:19 +04:00
|
|
|
|
|
|
|
|
2000-03-22 02:58:02 +03:00
|
|
|
nsIFrame *frame;
|
2000-03-31 11:17:22 +04:00
|
|
|
result = mDomSelections[index]->GetPrimaryFrameForFocusNode(&frame);
|
2000-03-22 02:58:02 +03:00
|
|
|
|
|
|
|
if (NS_FAILED(result) || !frame)
|
|
|
|
return result?result:NS_ERROR_FAILURE;
|
|
|
|
nsCOMPtr<nsIContent> content;
|
|
|
|
result = frame->GetContent(getter_AddRefs(content));
|
|
|
|
nsCOMPtr<nsIDOMNode> node = do_QueryInterface(content);
|
2000-04-12 14:34:19 +04:00
|
|
|
nsCOMPtr<nsIDOMNode> parentNode;
|
|
|
|
//we also need to check to see if the result frame's content's parent is equal to the weaknode used of course.
|
2000-05-05 09:37:27 +04:00
|
|
|
//except for special case of text frames where they are their own parent.
|
|
|
|
nsCOMPtr<nsIDOMText> textNode = do_QueryInterface(node);
|
|
|
|
if (NS_SUCCEEDED(result) && textNode && node != weakNodeUsed)//then the offset is meaningless.
|
|
|
|
{
|
|
|
|
offsetused = 0;//0 because when grabbing a child content we grab the IDX'th object or: body has 2 children,
|
|
|
|
//index 0 of parent is the first child so if we say the first child is the frame then say offset is 0 we are correct
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
result = node->GetParentNode(getter_AddRefs(parentNode));
|
|
|
|
if ((NS_FAILED(result) || parentNode != weakNodeUsed) && node != weakNodeUsed) //we are not pointing to same node! offset is meaningless
|
|
|
|
offsetused = -1;
|
|
|
|
}
|
2000-03-22 02:58:02 +03:00
|
|
|
nsPeekOffsetStruct pos;
|
|
|
|
pos.SetData(mTracker, desiredX, aAmount, eDirPrevious, offsetused, PR_FALSE,PR_TRUE, PR_TRUE);
|
|
|
|
switch (aKeycode){
|
|
|
|
case nsIDOMKeyEvent::DOM_VK_RIGHT :
|
|
|
|
InvalidateDesiredX();
|
|
|
|
pos.mDirection = eDirNext;
|
|
|
|
mHint = HINTLEFT;//stick to this line
|
2000-09-14 15:45:01 +04:00
|
|
|
PostReason(nsISelectionListener::KEYPRESS_REASON);
|
2000-03-22 02:58:02 +03:00
|
|
|
break;
|
|
|
|
case nsIDOMKeyEvent::DOM_VK_LEFT : //no break
|
|
|
|
InvalidateDesiredX();
|
|
|
|
mHint = HINTRIGHT;//stick to opposite of movement
|
2000-09-14 15:45:01 +04:00
|
|
|
PostReason(nsISelectionListener::KEYPRESS_REASON);
|
2000-03-22 02:58:02 +03:00
|
|
|
break;
|
|
|
|
case nsIDOMKeyEvent::DOM_VK_DOWN :
|
|
|
|
pos.mAmount = eSelectLine;
|
|
|
|
pos.mDirection = eDirNext;//no break here
|
2000-09-14 15:45:01 +04:00
|
|
|
PostReason(nsISelectionListener::KEYPRESS_REASON);
|
2000-03-22 02:58:02 +03:00
|
|
|
break;
|
|
|
|
case nsIDOMKeyEvent::DOM_VK_UP :
|
|
|
|
pos.mAmount = eSelectLine;
|
2000-09-14 15:45:01 +04:00
|
|
|
PostReason(nsISelectionListener::KEYPRESS_REASON);
|
2000-03-22 02:58:02 +03:00
|
|
|
break;
|
|
|
|
case nsIDOMKeyEvent::DOM_VK_HOME :
|
|
|
|
InvalidateDesiredX();
|
|
|
|
pos.mAmount = eSelectBeginLine;
|
|
|
|
mHint = HINTRIGHT;//stick to opposite of movement
|
2000-09-14 15:45:01 +04:00
|
|
|
PostReason(nsISelectionListener::KEYPRESS_REASON);
|
2000-03-22 02:58:02 +03:00
|
|
|
break;
|
|
|
|
case nsIDOMKeyEvent::DOM_VK_END :
|
|
|
|
InvalidateDesiredX();
|
|
|
|
pos.mAmount = eSelectEndLine;
|
|
|
|
mHint = HINTLEFT;//stick to this line
|
2000-09-14 15:45:01 +04:00
|
|
|
PostReason(nsISelectionListener::KEYPRESS_REASON);
|
2000-03-22 02:58:02 +03:00
|
|
|
break;
|
|
|
|
default :return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
pos.mPreferLeft = mHint;
|
|
|
|
if (NS_SUCCEEDED(result) && NS_SUCCEEDED(result = frame->PeekOffset(context, &pos)) && pos.mResultContent)
|
|
|
|
{
|
|
|
|
mHint = (HINT)pos.mPreferLeft;
|
|
|
|
result = TakeFocus(pos.mResultContent, pos.mContentOffset, pos.mContentOffset, aContinue, PR_FALSE);
|
|
|
|
}
|
|
|
|
else if (NS_FAILED(result))
|
|
|
|
{
|
|
|
|
if (nsIDOMKeyEvent::DOM_VK_UP == aKeycode)
|
|
|
|
{
|
|
|
|
pos.mPreferLeft = HINTRIGHT;
|
|
|
|
pos.mAmount = eSelectBeginLine;
|
|
|
|
InvalidateDesiredX();
|
|
|
|
}
|
|
|
|
else if(nsIDOMKeyEvent::DOM_VK_DOWN == aKeycode)
|
|
|
|
{
|
|
|
|
pos.mPreferLeft = HINTLEFT;
|
|
|
|
pos.mAmount = eSelectEndLine;
|
|
|
|
InvalidateDesiredX();
|
|
|
|
}
|
|
|
|
if (nsIDOMKeyEvent::DOM_VK_UP == aKeycode || nsIDOMKeyEvent::DOM_VK_DOWN == aKeycode )
|
|
|
|
{
|
|
|
|
if (NS_SUCCEEDED(result = frame->PeekOffset(context, &pos)) && pos.mResultContent)
|
|
|
|
{
|
|
|
|
mHint = (HINT)pos.mPreferLeft;
|
2000-09-14 15:45:01 +04:00
|
|
|
PostReason(nsISelectionListener::MOUSEUP_REASON);//force an update as though we used the mouse.
|
2000-03-22 02:58:02 +03:00
|
|
|
result = TakeFocus(pos.mResultContent, pos.mContentOffset, pos.mContentOffset, aContinue, PR_FALSE);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (NS_SUCCEEDED(result))
|
2000-03-31 11:17:22 +04:00
|
|
|
result = mDomSelections[index]->ScrollIntoView();
|
2000-03-22 02:58:02 +03:00
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** This raises a question, if this method is called and the aFrame does not reflect the current
|
|
|
|
* focus DomNode, it is invalid? The answer now is yes.
|
|
|
|
*/
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsSelection::HandleKeyEvent(nsIPresContext* aPresContext, nsGUIEvent *aGuiEvent)
|
|
|
|
{
|
|
|
|
if (!aGuiEvent)
|
|
|
|
return NS_ERROR_NULL_POINTER;
|
|
|
|
STATUS_CHECK_RETURN_MACRO();
|
|
|
|
|
|
|
|
nsresult result = NS_ERROR_FAILURE;
|
|
|
|
if (NS_KEY_PRESS == aGuiEvent->message) {
|
|
|
|
nsKeyEvent *keyEvent = (nsKeyEvent *)aGuiEvent; //this is ok. It really is a keyevent
|
|
|
|
switch (keyEvent->keyCode)
|
|
|
|
{
|
|
|
|
case nsIDOMKeyEvent::DOM_VK_LEFT :
|
|
|
|
case nsIDOMKeyEvent::DOM_VK_UP :
|
|
|
|
case nsIDOMKeyEvent::DOM_VK_DOWN :
|
|
|
|
case nsIDOMKeyEvent::DOM_VK_RIGHT :
|
|
|
|
case nsIDOMKeyEvent::DOM_VK_HOME :
|
|
|
|
case nsIDOMKeyEvent::DOM_VK_END :
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
|
|
|
//XXX Need xp way get platfrom specific behavior into key navigation.
|
|
|
|
//XXX This really shouldn't have to use an ifdef
|
|
|
|
#ifdef _WIN32
|
|
|
|
if (keyEvent->isAlt) {
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
nsSelectionAmount amount = eSelectCharacter;
|
|
|
|
if (keyEvent->isControl)
|
|
|
|
amount = eSelectWord;
|
|
|
|
return MoveCaret(keyEvent->keyCode, keyEvent->isShift, amount);
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
//END nsSelection methods
|
|
|
|
|
|
|
|
|
|
|
|
//BEGIN nsIFrameSelection methods
|
|
|
|
|
|
|
|
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-04-28 17:58:08 +04:00
|
|
|
nsCOMPtr<nsIDocumentEncoder> encoder;
|
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);
|
2000-05-13 12:07:34 +04:00
|
|
|
rv = nsComponentManager::CreateInstance(formatType,
|
2000-04-28 17:58:08 +04:00
|
|
|
nsnull,
|
|
|
|
NS_GET_IID(nsIDocumentEncoder),
|
|
|
|
getter_AddRefs(encoder));
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2000-04-28 17:58:08 +04:00
|
|
|
nsCOMPtr<nsIDocument> doc;
|
|
|
|
rv = shell->GetDocument(getter_AddRefs(doc));
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2000-03-22 02:58:02 +03:00
|
|
|
|
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;
|
|
|
|
readstring.AssignWithConversion(aFormatType);
|
|
|
|
rv = encoder->Init(doc, 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);
|
|
|
|
*aReturn = tmp.ToNewUnicode();//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
|
|
|
{
|
2000-06-28 08:00:12 +04:00
|
|
|
nsIFrameSelection::HINT hint;
|
|
|
|
if (aHintRight)
|
|
|
|
hint = nsIFrameSelection::HINTRIGHT;
|
|
|
|
else
|
|
|
|
hint = nsIFrameSelection::HINTLEFT;
|
|
|
|
return mFrameSelection->SetHint(hint);
|
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
|
|
|
{
|
2000-06-28 08:00:12 +04:00
|
|
|
nsIFrameSelection::HINT hint;
|
|
|
|
nsresult rv = mFrameSelection->GetHint(&hint);
|
|
|
|
if (hint == nsIFrameSelection::HINTRIGHT)
|
|
|
|
*aHintRight = PR_TRUE;
|
|
|
|
else
|
|
|
|
*aHintRight = PR_FALSE;
|
|
|
|
return rv;
|
2000-03-22 02:58:02 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsSelection::HandleClick(nsIContent *aNewFocus, PRUint32 aContentOffset,
|
|
|
|
PRUint32 aContentEndOffset, PRBool aContinueSelection,
|
|
|
|
PRBool aMultipleSelection, PRBool aHint)
|
|
|
|
{
|
2000-05-02 07:44:17 +04:00
|
|
|
if (!aNewFocus)
|
|
|
|
return NS_ERROR_INVALID_ARG;
|
2000-03-22 02:58:02 +03:00
|
|
|
InvalidateDesiredX();
|
|
|
|
|
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
|
|
|
|
if (!mSelectingTableCells)
|
2000-04-14 00:21:32 +04:00
|
|
|
{
|
2000-09-14 15:45:01 +04:00
|
|
|
PostReason(nsISelectionListener::MOUSEDOWN_REASON + nsISelectionListener::DRAG_REASON);
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsSelection::HandleDrag(nsIPresContext *aPresContext, nsIFrame *aFrame, nsPoint& aPoint)
|
|
|
|
{
|
|
|
|
if (!aPresContext || !aFrame)
|
|
|
|
return NS_ERROR_NULL_POINTER;
|
|
|
|
|
|
|
|
nsresult result;
|
|
|
|
nsIFrame *newFrame = 0;
|
|
|
|
nsPoint newPoint;
|
|
|
|
|
|
|
|
result = ConstrainFrameAndPointToAnchorSubtree(aPresContext, aFrame, aPoint, &newFrame, newPoint);
|
|
|
|
|
|
|
|
if (NS_FAILED(result))
|
|
|
|
return result;
|
|
|
|
|
|
|
|
if (!newFrame)
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
|
|
|
|
nsCOMPtr<nsIPresShell> presShell;
|
|
|
|
|
|
|
|
result = aPresContext->GetShell(getter_AddRefs(presShell));
|
|
|
|
|
|
|
|
if (NS_FAILED(result))
|
|
|
|
return result;
|
|
|
|
|
|
|
|
PRInt32 startPos = 0;
|
|
|
|
PRInt32 contentOffsetEnd = 0;
|
|
|
|
PRBool beginOfContent;
|
|
|
|
nsCOMPtr<nsIContent> newContent;
|
|
|
|
|
|
|
|
result = newFrame->GetContentAndOffsetsFromPoint(aPresContext, newPoint,
|
|
|
|
getter_AddRefs(newContent),
|
2000-08-09 03:38:00 +04:00
|
|
|
startPos, contentOffsetEnd, beginOfContent);
|
|
|
|
|
|
|
|
// do we have CSS that changes selection behaviour?
|
|
|
|
{
|
|
|
|
PRBool changeSelection;
|
|
|
|
nsCOMPtr<nsIContent> selectContent;
|
|
|
|
PRInt32 newStart, newEnd;
|
|
|
|
if (NS_SUCCEEDED(AdjustOffsetsFromStyle(newFrame, &changeSelection, getter_AddRefs(selectContent), &newStart, &newEnd))
|
|
|
|
&& changeSelection)
|
|
|
|
{
|
|
|
|
newContent = selectContent;
|
|
|
|
startPos = newStart;
|
|
|
|
contentOffsetEnd = newEnd;
|
|
|
|
}
|
|
|
|
}
|
2000-03-22 02:58:02 +03:00
|
|
|
|
|
|
|
if (NS_SUCCEEDED(result))
|
|
|
|
{
|
|
|
|
result = HandleClick(newContent, startPos, contentOffsetEnd , PR_TRUE, PR_FALSE, beginOfContent);
|
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsSelection::StartAutoScrollTimer(nsIPresContext *aPresContext, nsIFrame *aFrame, nsPoint& aPoint, PRUint32 aDelay)
|
|
|
|
{
|
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]->StartAutoScrollTimer(aPresContext, aFrame, aPoint, aDelay);
|
2000-03-22 02:58:02 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsSelection::StopAutoScrollTimer()
|
|
|
|
{
|
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]->StopAutoScrollTimer();
|
2000-03-22 02:58:02 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
hard to go from nodes to frames, easy the other way!
|
|
|
|
*/
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsSelection::TakeFocus(nsIContent *aNewFocus, PRUint32 aContentOffset,
|
|
|
|
PRUint32 aContentEndOffset, PRBool aContinueSelection, PRBool aMultipleSelection)
|
|
|
|
{
|
|
|
|
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
|
|
|
|
|
|
|
if (mLimiter )
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsIContent> parent;
|
|
|
|
nsresult rv = aNewFocus->GetParent(*getter_AddRefs(parent));
|
|
|
|
if (NS_FAILED(rv))
|
|
|
|
return rv;
|
2000-06-09 09:14:19 +04:00
|
|
|
if (mLimiter != parent.get() && mLimiter != aNewFocus) //if newfocus == the limiter. thats ok.
|
2000-05-02 07:44:17 +04:00
|
|
|
return NS_ERROR_FAILURE; //not in the right content. mLimiter said so
|
|
|
|
}
|
|
|
|
|
2000-03-22 02:58:02 +03:00
|
|
|
//HACKHACKHACK
|
|
|
|
nsCOMPtr<nsIContent> content;
|
|
|
|
nsCOMPtr<nsIDOMNode> domNode;
|
|
|
|
nsCOMPtr<nsIContent> parent;
|
|
|
|
nsCOMPtr<nsIContent> parent2;
|
|
|
|
if (NS_FAILED(aNewFocus->GetParent(*getter_AddRefs(parent))) || !parent)
|
|
|
|
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);
|
2000-03-22 02:58:02 +03:00
|
|
|
domNode = do_QueryInterface(aNewFocus);
|
|
|
|
//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
|
|
|
|
{
|
2000-03-31 11:17:22 +04:00
|
|
|
mDomSelections[index]->Collapse(domNode, aContentOffset);
|
2000-03-22 02:58:02 +03:00
|
|
|
mBatching = batching;
|
|
|
|
mChangesDuringBatching = changes;
|
|
|
|
}
|
|
|
|
if (aContentEndOffset > aContentOffset)
|
2000-03-31 11:17:22 +04:00
|
|
|
mDomSelections[index]->Extend(domNode,aContentEndOffset);
|
2000-03-22 02:58:02 +03:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
// Now update the range list:
|
|
|
|
if (aContinueSelection && domNode)
|
|
|
|
{
|
2000-03-31 11:17:22 +04:00
|
|
|
if (mDomSelections[index]->GetDirection() == eDirNext && aContentEndOffset > aContentOffset) //didnt go far enough
|
2000-03-22 02:58:02 +03:00
|
|
|
{
|
2000-03-31 11:17:22 +04:00
|
|
|
mDomSelections[index]->Extend(domNode, aContentEndOffset);//this will only redraw the diff
|
2000-03-22 02:58:02 +03:00
|
|
|
}
|
|
|
|
else
|
2000-03-31 11:17:22 +04:00
|
|
|
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
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
NS_METHOD
|
|
|
|
nsSelection::LookUpSelection(nsIContent *aContent, PRInt32 aContentOffset, PRInt32 aContentLength,
|
|
|
|
SelectionDetails **aReturnDetails, PRBool aSlowCheck)
|
|
|
|
{
|
|
|
|
if (!aContent || !aReturnDetails)
|
|
|
|
return NS_ERROR_NULL_POINTER;
|
|
|
|
|
|
|
|
STATUS_CHECK_RETURN_MACRO();
|
|
|
|
|
2000-06-03 03:05:06 +04:00
|
|
|
// Never use "slow check" when in table selection mode
|
|
|
|
if (aSlowCheck)
|
|
|
|
aSlowCheck = (mSelectingTableCellMode == 0);
|
|
|
|
|
2000-03-22 02:58:02 +03:00
|
|
|
*aReturnDetails = nsnull;
|
|
|
|
PRInt8 j;
|
2000-04-27 11:37:12 +04:00
|
|
|
for (j = (PRInt8) 0; j < (PRInt8)nsISelectionController::NUM_SELECTIONTYPES; j++){
|
2000-03-22 02:58:02 +03:00
|
|
|
if (mDomSelections[j])
|
2000-03-31 11:17:22 +04:00
|
|
|
mDomSelections[j]->LookUpSelection(aContent, aContentOffset, aContentLength, aReturnDetails, (SelectionType)(1<<j), aSlowCheck);
|
2000-03-22 02:58:02 +03:00
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
NS_METHOD
|
|
|
|
nsSelection::SetMouseDownState(PRBool aState)
|
|
|
|
{
|
2000-05-13 13:10:16 +04:00
|
|
|
if (mMouseDownState == aState)
|
|
|
|
return NS_OK;
|
2000-03-22 02:58:02 +03:00
|
|
|
mMouseDownState = aState;
|
|
|
|
if (!mMouseDownState)
|
|
|
|
{
|
2000-05-31 04:07:58 +04:00
|
|
|
// Mouse up kills dragging-table cell selection
|
2000-06-03 03:05:06 +04:00
|
|
|
#ifdef DEBUG_TABLE_SELECTION
|
2000-10-29 02:17:53 +04:00
|
|
|
printf("SetMouseDownState to FALSE - stopping cell selection\n");
|
2000-05-31 04:07:58 +04:00
|
|
|
#endif
|
2000-03-22 02:58:02 +03:00
|
|
|
mSelectingTableCells = PR_FALSE;
|
|
|
|
mStartSelectedCell = nsnull;
|
|
|
|
mEndSelectedCell = nsnull;
|
2000-09-14 17:23:31 +04:00
|
|
|
|
|
|
|
short reason;
|
|
|
|
if (aState)
|
|
|
|
reason = nsISelectionListener::MOUSEDOWN_REASON;
|
|
|
|
else
|
|
|
|
reason = nsISelectionListener::MOUSEUP_REASON;
|
|
|
|
PostReason(reason);//not a drag reason
|
2000-05-13 12:07:34 +04:00
|
|
|
NotifySelectionListeners(nsISelectionController::SELECTION_NORMAL);//notify that reason is mouse up please.
|
2000-03-22 02:58:02 +03:00
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
NS_METHOD
|
|
|
|
nsSelection::GetMouseDownState(PRBool *aState)
|
|
|
|
{
|
|
|
|
if (!aState)
|
|
|
|
return NS_ERROR_NULL_POINTER;
|
|
|
|
*aState = mMouseDownState;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2000-03-31 11:17:22 +04:00
|
|
|
|
2000-04-14 00:21:32 +04:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsSelection::GetTableCellSelectionStyleColor(const nsStyleColor **aStyleColor)
|
|
|
|
{
|
|
|
|
if (!aStyleColor)
|
|
|
|
return NS_ERROR_NULL_POINTER;
|
|
|
|
*aStyleColor = &sTableStyleColor;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2000-03-22 02:58:02 +03:00
|
|
|
NS_IMETHODIMP
|
2000-09-14 15:45:01 +04:00
|
|
|
nsSelection::GetSelection(SelectionType aType, nsISelection **aDomSelection)
|
2000-03-22 02:58:02 +03:00
|
|
|
{
|
|
|
|
if (!aDomSelection)
|
|
|
|
return NS_ERROR_NULL_POINTER;
|
2000-03-31 11:17:22 +04:00
|
|
|
PRInt8 index = GetIndexFromSelectionType(aType);
|
|
|
|
if (index < 0)
|
|
|
|
return NS_ERROR_INVALID_ARG;
|
2000-09-14 15:45:01 +04:00
|
|
|
*aDomSelection = NS_REINTERPRET_CAST(nsISelection *,mDomSelections[index]);
|
2000-03-22 02:58:02 +03:00
|
|
|
(*aDomSelection)->AddRef();
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsSelection::ScrollSelectionIntoView(SelectionType aType, SelectionRegion aRegion)
|
|
|
|
{
|
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;
|
|
|
|
|
2000-03-31 11:17:22 +04:00
|
|
|
return mDomSelections[index]->ScrollIntoView(aRegion);
|
2000-03-22 02:58:02 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsSelection::RepaintSelection(nsIPresContext* aPresContext, SelectionType aType)
|
|
|
|
{
|
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;
|
2000-03-31 11:17:22 +04:00
|
|
|
return mDomSelections[index]->Repaint(aPresContext);
|
2000-03-22 02:58:02 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2000-06-28 08:00:12 +04:00
|
|
|
nsSelection::GetFrameForNodeOffset(nsIContent *aNode, PRInt32 aOffset, HINT aHint, nsIFrame **aReturnFrame, PRInt32 *aReturnOffset)
|
2000-03-22 02:58:02 +03:00
|
|
|
{
|
|
|
|
if (!aNode || !aReturnFrame || !aReturnOffset)
|
|
|
|
return NS_ERROR_NULL_POINTER;
|
|
|
|
|
|
|
|
if (aOffset < 0)
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
|
|
|
|
*aReturnOffset = aOffset;
|
|
|
|
|
|
|
|
nsresult result;
|
|
|
|
PRBool canContainChildren = PR_FALSE;
|
|
|
|
|
|
|
|
result = aNode->CanContainChildren(canContainChildren);
|
|
|
|
|
|
|
|
if (NS_FAILED(result))
|
|
|
|
return result;
|
|
|
|
|
2000-05-01 04:26:37 +04:00
|
|
|
nsCOMPtr<nsIContent> theNode = aNode;
|
|
|
|
|
2000-03-22 02:58:02 +03:00
|
|
|
if (canContainChildren)
|
|
|
|
{
|
|
|
|
PRInt32 childIndex = 0;
|
|
|
|
PRInt32 numChildren = 0;
|
|
|
|
|
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
|
|
|
|
{
|
2000-05-01 04:26:37 +04:00
|
|
|
result = theNode->ChildCount(numChildren);
|
2000-03-22 02:58:02 +03:00
|
|
|
|
|
|
|
if (NS_FAILED(result))
|
|
|
|
return result;
|
|
|
|
|
|
|
|
if (aOffset >= numChildren)
|
|
|
|
{
|
|
|
|
if (numChildren > 0)
|
|
|
|
childIndex = numChildren - 1;
|
|
|
|
else
|
|
|
|
childIndex = 0;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
childIndex = aOffset;
|
|
|
|
}
|
2000-05-02 07:44:17 +04:00
|
|
|
|
2000-05-01 22:21:30 +04:00
|
|
|
nsCOMPtr<nsIContent> childNode;
|
|
|
|
|
|
|
|
result = theNode->ChildAt(childIndex, *getter_AddRefs(childNode));
|
2000-03-22 02:58:02 +03:00
|
|
|
|
|
|
|
if (NS_FAILED(result))
|
|
|
|
return result;
|
|
|
|
|
2000-05-01 22:21:30 +04:00
|
|
|
if (!childNode)
|
2000-03-22 02:58:02 +03:00
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
|
2000-05-01 22:21:30 +04:00
|
|
|
theNode = childNode;
|
|
|
|
|
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!
|
|
|
|
|
2000-05-01 04:26:37 +04:00
|
|
|
result = theNode->CanContainChildren(canContainChildren);
|
2000-03-22 02:58:02 +03:00
|
|
|
|
|
|
|
if (NS_FAILED(result))
|
|
|
|
return result;
|
|
|
|
|
|
|
|
if (canContainChildren)
|
|
|
|
{
|
|
|
|
PRInt32 newOffset = 0;
|
|
|
|
|
|
|
|
if (aOffset > childIndex)
|
|
|
|
{
|
2000-05-01 04:26:37 +04:00
|
|
|
result = theNode->ChildCount(numChildren);
|
2000-03-22 02:58:02 +03:00
|
|
|
|
|
|
|
if (NS_FAILED(result))
|
|
|
|
return result;
|
|
|
|
|
|
|
|
newOffset = numChildren;
|
|
|
|
}
|
|
|
|
|
2000-06-28 08:00:12 +04:00
|
|
|
return GetFrameForNodeOffset(theNode, newOffset, aHint, aReturnFrame,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;
|
|
|
|
|
|
|
|
result = textNode->GetLength(&textLength);
|
|
|
|
|
|
|
|
if (NS_FAILED(result))
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
|
|
|
|
*aReturnOffset = (PRInt32)textLength;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
*aReturnOffset = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2000-05-01 04:26:37 +04:00
|
|
|
result = mTracker->GetPrimaryFrameFor(theNode, aReturnFrame);
|
2000-03-22 02:58:02 +03:00
|
|
|
if (NS_FAILED(result))
|
|
|
|
return result;
|
|
|
|
|
|
|
|
if (!*aReturnFrame)
|
|
|
|
return NS_ERROR_UNEXPECTED;
|
|
|
|
|
|
|
|
// find the child frame containing the offset we want
|
2000-06-28 08:00:12 +04:00
|
|
|
result = (*aReturnFrame)->GetChildFrameContainingOffset(*aReturnOffset, aHint, &aOffset, aReturnFrame);
|
2000-03-22 02:58:02 +03:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsSelection::CharacterMove(PRBool aForward, PRBool aExtend)
|
|
|
|
{
|
|
|
|
if (aForward)
|
|
|
|
return MoveCaret(nsIDOMKeyEvent::DOM_VK_RIGHT,aExtend,eSelectCharacter);
|
|
|
|
else
|
|
|
|
return MoveCaret(nsIDOMKeyEvent::DOM_VK_LEFT,aExtend,eSelectCharacter);
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsSelection::WordMove(PRBool aForward, PRBool aExtend)
|
|
|
|
{
|
|
|
|
if (aForward)
|
|
|
|
return MoveCaret(nsIDOMKeyEvent::DOM_VK_RIGHT,aExtend,eSelectWord);
|
|
|
|
else
|
|
|
|
return MoveCaret(nsIDOMKeyEvent::DOM_VK_LEFT,aExtend,eSelectWord);
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsSelection::LineMove(PRBool aForward, PRBool aExtend)
|
|
|
|
{
|
|
|
|
if (aForward)
|
|
|
|
return MoveCaret(nsIDOMKeyEvent::DOM_VK_DOWN,aExtend,eSelectLine);
|
|
|
|
else
|
|
|
|
return MoveCaret(nsIDOMKeyEvent::DOM_VK_UP,aExtend,eSelectLine);
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsSelection::IntraLineMove(PRBool aForward, PRBool aExtend)
|
|
|
|
{
|
|
|
|
if (aForward)
|
|
|
|
return MoveCaret(nsIDOMKeyEvent::DOM_VK_END,aExtend,eSelectLine);
|
|
|
|
else
|
|
|
|
return MoveCaret(nsIDOMKeyEvent::DOM_VK_HOME,aExtend,eSelectLine);
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP nsSelection::SelectAll()
|
|
|
|
{
|
2000-06-29 09:25:01 +04:00
|
|
|
nsCOMPtr<nsIContent> rootContent;
|
|
|
|
if (mLimiter)
|
|
|
|
{
|
|
|
|
rootContent = mLimiter;//addrefit
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
nsresult rv;
|
|
|
|
nsCOMPtr<nsIPresShell> shell(do_QueryInterface(mTracker,&rv));
|
|
|
|
if (NS_FAILED(rv) || !shell) {
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsCOMPtr<nsIDocument> doc;
|
|
|
|
rv = shell->GetDocument(getter_AddRefs(doc));
|
|
|
|
if (NS_FAILED(rv) || !doc)
|
|
|
|
return rv?rv:NS_ERROR_FAILURE;
|
|
|
|
rootContent = getter_AddRefs(doc->GetRootContent());
|
|
|
|
if (!rootContent)
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
PRInt32 numChildren;
|
|
|
|
rootContent->ChildCount(numChildren);
|
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
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsSelection::StartBatchChanges()
|
|
|
|
{
|
|
|
|
nsresult result(NS_OK);
|
|
|
|
mBatching++;
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsSelection::EndBatchChanges()
|
|
|
|
{
|
|
|
|
nsresult result(NS_OK);
|
|
|
|
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
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2000-08-09 03:38:00 +04:00
|
|
|
|
2000-03-22 02:58:02 +03:00
|
|
|
nsresult
|
2000-04-14 15:21:19 +04:00
|
|
|
nsSelection::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
|
|
|
}
|
|
|
|
|
2000-08-09 03:38:00 +04:00
|
|
|
nsresult
|
|
|
|
nsSelection::FrameOrParentHasSpecialSelectionStyle(nsIFrame* aFrame, PRUint8 aSelectionStyle, nsIFrame* *foundFrame)
|
|
|
|
{
|
|
|
|
nsIFrame* thisFrame = aFrame;
|
|
|
|
|
|
|
|
while (thisFrame)
|
|
|
|
{
|
|
|
|
const nsStyleUserInterface* userinterface;
|
|
|
|
thisFrame->GetStyleData(eStyleStruct_UserInterface, (const nsStyleStruct*&)userinterface);
|
|
|
|
|
|
|
|
if (userinterface->mUserSelect == aSelectionStyle)
|
|
|
|
{
|
|
|
|
*foundFrame = thisFrame;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
thisFrame->GetParent(&thisFrame);
|
|
|
|
}
|
|
|
|
|
|
|
|
*foundFrame = nsnull;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
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)
|
|
|
|
{
|
2000-12-21 01:13:54 +03:00
|
|
|
nsCOMPtr<nsIAtom> tag;
|
|
|
|
aContent->GetTag(*getter_AddRefs(tag));
|
|
|
|
return (tag != 0 && tag.get() == nsSelection::sCellAtom);
|
2000-03-23 07:24:58 +03:00
|
|
|
}
|
|
|
|
|
2000-05-16 07:03:13 +04:00
|
|
|
nsITableCellLayout*
|
|
|
|
nsSelection::GetCellLayout(nsIContent *aCellContent)
|
|
|
|
{
|
|
|
|
// Get frame for cell
|
|
|
|
nsIFrame *cellFrame = nsnull;
|
|
|
|
nsresult result = GetTracker()->GetPrimaryFrameFor(aCellContent, &cellFrame);
|
|
|
|
if (!cellFrame) return nsnull;
|
|
|
|
nsITableCellLayout *cellLayoutObject = nsnull;
|
|
|
|
result = cellFrame->QueryInterface(NS_GET_IID(nsITableCellLayout), (void**)(&cellLayoutObject));
|
|
|
|
if (NS_FAILED(result)) return nsnull;
|
|
|
|
return cellLayoutObject;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsITableLayout*
|
|
|
|
nsSelection::GetTableLayout(nsIContent *aTableContent)
|
|
|
|
{
|
|
|
|
// Get frame for table
|
|
|
|
nsIFrame *tableFrame = nsnull;
|
|
|
|
nsresult result = GetTracker()->GetPrimaryFrameFor(aTableContent, &tableFrame);
|
|
|
|
if (!tableFrame) return nsnull;
|
|
|
|
nsITableLayout *tableLayoutObject = nsnull;
|
|
|
|
result = tableFrame->QueryInterface(NS_GET_IID(nsITableLayout), (void**)(&tableLayoutObject));
|
|
|
|
if (NS_FAILED(result)) return nsnull;
|
|
|
|
return tableLayoutObject;
|
|
|
|
}
|
|
|
|
|
2000-05-31 04:07:58 +04:00
|
|
|
nsresult
|
|
|
|
nsSelection::ClearNormalSelection()
|
|
|
|
{
|
|
|
|
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
|
2000-12-21 01:13:54 +03:00
|
|
|
nsSelection::HandleTableSelection(nsIContent *aParentContent, PRInt32 aContentOffset, PRInt32 aTarget, nsMouseEvent *aMouseEvent)
|
2000-03-22 02:58:02 +03:00
|
|
|
{
|
|
|
|
if (!aParentContent) return NS_ERROR_NULL_POINTER;
|
2000-12-21 01:13:54 +03:00
|
|
|
if (mSelectingTableCells && (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);
|
|
|
|
if (!parentNode) return NS_ERROR_FAILURE;
|
|
|
|
|
2000-05-31 04:07:58 +04:00
|
|
|
nsCOMPtr<nsIContent> childContent;
|
|
|
|
nsresult result = aParentContent->ChildAt(aContentOffset, *getter_AddRefs(childContent));
|
2000-03-22 02:58:02 +03:00
|
|
|
if (NS_FAILED(result)) return result;
|
2000-05-31 04:07:58 +04:00
|
|
|
if (!childContent) return NS_ERROR_FAILURE;
|
2000-03-22 02:58:02 +03:00
|
|
|
|
2000-05-31 04:07:58 +04:00
|
|
|
nsCOMPtr<nsIDOMNode> childNode = do_QueryInterface(childContent);
|
|
|
|
if (!childNode) return NS_ERROR_FAILURE;
|
2000-03-22 02:58:02 +03: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;
|
2000-03-22 02:58:02 +03:00
|
|
|
if (mSelectingTableCells)
|
|
|
|
{
|
2000-05-16 07:03:13 +04:00
|
|
|
// We are drag-selecting
|
2001-01-04 03:24:39 +03:00
|
|
|
#ifdef DEBUG_TABLE_SELECTION
|
|
|
|
printf("HandleTableSelection: mSelectingTableCellMode = %x\n", mSelectingTableCellMode);
|
|
|
|
#endif
|
2000-03-22 02:58:02 +03:00
|
|
|
|
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
|
|
|
// Clear this to be sure SelectBlockOfCells works correctly
|
|
|
|
mAppendStartSelectedCell = nsnull;
|
|
|
|
|
|
|
|
// 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
|
2000-05-31 04:07:58 +04:00
|
|
|
return SelectBlockOfCells(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
|
2000-03-23 07:24:58 +03:00
|
|
|
|
2000-05-31 04:07:58 +04:00
|
|
|
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
|
|
|
|
nsIFrame *cellFrame = nsnull;
|
|
|
|
result = GetTracker()->GetPrimaryFrameFor(childContent, &cellFrame);
|
|
|
|
if (NS_FAILED(result)) return result;
|
|
|
|
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
|
|
|
}
|
|
|
|
mSelectingTableCells = PR_TRUE; // Signal to start drag-cell-selection
|
|
|
|
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);
|
|
|
|
if (!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?
|
|
|
|
mSelectingTableCells = PR_FALSE;
|
|
|
|
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
|
|
|
|
mSelectingTableCells = 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
|
2000-10-29 02:17:53 +04:00
|
|
|
printf("HandleTableSelection: Mouse UP event\n");
|
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);
|
2000-03-22 02:58:02 +03: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)
|
|
|
|
{
|
|
|
|
// If Shift is down as well, append a block selection
|
|
|
|
return SelectBlockOfCells(childContent);
|
|
|
|
}
|
|
|
|
|
|
|
|
// 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);
|
|
|
|
nsCOMPtr<nsIContent> childContent;
|
|
|
|
result = parentContent->ChildAt(offset, *getter_AddRefs(childContent));
|
|
|
|
if (NS_FAILED(result)) return result;
|
|
|
|
if (childContent && IsCell(childContent))
|
|
|
|
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
|
|
|
|
mSelectingTableCells = PR_FALSE;
|
|
|
|
mStartSelectedCell = nsnull;
|
|
|
|
mEndSelectedCell = nsnull;
|
|
|
|
mSelectingTableCellMode = 0;
|
|
|
|
//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
|
2000-05-31 04:07:58 +04:00
|
|
|
//TODO: Should we try to reassign to a different existing cell?
|
|
|
|
//mStartSelectedCell = nsnull;
|
|
|
|
//mEndSelectedCell = nsnull;
|
|
|
|
// Other cells are selected:
|
|
|
|
// Deselect cell by removing its range from selection
|
|
|
|
return mDomSelections[index]->RemoveRange(range);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
mUnselectCellOnMouseUp = nsnull;
|
|
|
|
// Should we just return here?
|
|
|
|
// (we failed to unselect the cell)
|
2000-03-22 02:58:02 +03:00
|
|
|
}
|
2000-05-31 04:07:58 +04:00
|
|
|
// We have mouse up in a cell that was just selected on mouse down,
|
|
|
|
// (and no drag or shift-extend action intervened)
|
|
|
|
// Use it as the start of a block that
|
|
|
|
// we may append by using Shift+click in another cell
|
|
|
|
mAppendStartSelectedCell = childContent;
|
2000-06-03 03:05:06 +04:00
|
|
|
#ifdef DEBUG_TABLE_SELECTION
|
2000-10-29 02:17:53 +04:00
|
|
|
printf("HandleTableSelection: Setting mAppendStartSelectedCell for append block\n");
|
2000-03-22 02:58:02 +03:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
2000-03-24 05:52:07 +03:00
|
|
|
nsSelection::SelectBlockOfCells(nsIContent *aEndCell)
|
2000-03-22 02:58:02 +03:00
|
|
|
{
|
2000-03-23 07:24:58 +03:00
|
|
|
if (!aEndCell) return NS_ERROR_NULL_POINTER;
|
|
|
|
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 (mAppendStartSelectedCell)
|
|
|
|
{
|
|
|
|
// We are appending a new block
|
2000-06-03 03:05:06 +04:00
|
|
|
#ifdef DEBUG_TABLE_SELECTION
|
2000-10-29 02:17:53 +04:00
|
|
|
printf("SelectBlockOfCells -- using mAppendStartSelectedCell\n");
|
2000-05-31 04:07:58 +04:00
|
|
|
#endif
|
|
|
|
startCell = mAppendStartSelectedCell;
|
|
|
|
}
|
|
|
|
else if (mStartSelectedCell)
|
|
|
|
{
|
|
|
|
startCell = mStartSelectedCell;
|
2000-06-03 03:05:06 +04:00
|
|
|
#ifdef DEBUG_TABLE_SELECTION
|
2000-10-29 02:17:53 +04:00
|
|
|
printf("SelectBlockOfCells -- using mStartSelectedCell\n");
|
2000-05-31 04:07:58 +04:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!startCell)
|
|
|
|
{
|
2000-06-03 03:05:06 +04:00
|
|
|
#ifdef DEBUG_TABLE_SELECTION
|
2000-10-29 02:17:53 +04:00
|
|
|
printf("SelectBlockOfCells -- NO START CELL!\n");
|
2000-05-31 04:07:58 +04:00
|
|
|
#endif
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
// If new end cell is in a different table, do nothing
|
|
|
|
nsCOMPtr<nsIContent> table;
|
|
|
|
if (!IsInSameTable(startCell, aEndCell, getter_AddRefs(table)))
|
|
|
|
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;
|
2000-05-31 04:07:58 +04:00
|
|
|
result = GetCellIndexes(startCell, 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;
|
|
|
|
|
2000-05-31 04:07:58 +04:00
|
|
|
if (!mAppendStartSelectedCell)
|
2000-03-24 05:52:07 +03:00
|
|
|
{
|
2000-05-31 04:07:58 +04:00
|
|
|
// Not appending - remove selected cells outside of new block limits
|
|
|
|
|
|
|
|
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
|
|
|
|
nsSelection::SelectRowOrColumn(nsIContent *aCellContent, PRUint32 aTarget)
|
|
|
|
{
|
|
|
|
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);
|
2001-01-04 03:24:39 +03:00
|
|
|
result = SelectBlockOfCells(lastCellContent);
|
|
|
|
|
|
|
|
// 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
|
|
|
|
result = tableLayout->GetCellDataAt(rowIndex, colIndex, *getter_AddRefs(cellElement),
|
|
|
|
curRowIndex, curColIndex, rowSpan, colSpan,
|
|
|
|
actualRowSpan, actualColSpan, isSelected);
|
|
|
|
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
|
|
|
|
nsSelection::GetFirstCellNodeInRange(nsIDOMRange *aRange, nsIDOMNode **aCellNode)
|
|
|
|
{
|
|
|
|
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));
|
2000-03-24 05:52:07 +03:00
|
|
|
if (NS_FAILED(result)) return result;
|
|
|
|
if (!startParent) return NS_ERROR_FAILURE;
|
|
|
|
|
|
|
|
PRInt32 offset;
|
|
|
|
result = aRange->GetStartOffset(&offset);
|
|
|
|
if (NS_FAILED(result)) return result;
|
|
|
|
|
|
|
|
nsCOMPtr<nsIContent> parentContent = do_QueryInterface(startParent);
|
|
|
|
nsCOMPtr<nsIContent> childContent;
|
|
|
|
result = parentContent->ChildAt(offset, *getter_AddRefs(childContent));
|
|
|
|
if (NS_FAILED(result)) return result;
|
|
|
|
if (!childContent) return NS_ERROR_NULL_POINTER;
|
|
|
|
// 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
|
|
|
|
nsSelection::GetFirstSelectedCellAndRange(nsIDOMNode **aCell, nsIDOMRange **aRange)
|
|
|
|
{
|
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
|
|
|
|
nsSelection::GetNextSelectedCellAndRange(nsIDOMNode **aCell, nsIDOMRange **aRange)
|
|
|
|
{
|
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
|
|
|
|
nsSelection::GetCellIndexes(nsIContent *aCell, PRInt32 &aRowIndex, PRInt32 &aColIndex)
|
|
|
|
{
|
|
|
|
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
|
|
|
|
nsSelection::IsInSameTable(nsIContent *aContent1, nsIContent *aContent2, nsIContent **aTable)
|
|
|
|
{
|
|
|
|
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
|
|
|
|
nsSelection::GetParentTable(nsIContent *aCell, nsIContent **aTable)
|
|
|
|
{
|
|
|
|
if (!aCell || !aTable)
|
|
|
|
return NS_ERROR_NULL_POINTER;
|
|
|
|
|
|
|
|
nsCOMPtr<nsIContent> parent;
|
|
|
|
nsresult result = aCell->GetParent(*getter_AddRefs(parent));
|
|
|
|
|
|
|
|
while (NS_SUCCEEDED(result) && parent)
|
|
|
|
{
|
|
|
|
nsIAtom *tag;
|
|
|
|
parent->GetTag(tag);
|
|
|
|
if (tag && tag == nsSelection::sTableAtom)
|
|
|
|
{
|
|
|
|
*aTable = parent;
|
|
|
|
NS_ADDREF(*aTable);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
nsCOMPtr<nsIContent> temp;
|
|
|
|
result = parent->GetParent(*getter_AddRefs(temp));
|
|
|
|
parent = temp;
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2000-05-16 07:03:13 +04:00
|
|
|
nsresult
|
|
|
|
nsSelection::SelectCellElement(nsIDOMElement *aCellElement)
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsIDOMNode> cellNode = do_QueryInterface(aCellElement);
|
|
|
|
nsCOMPtr<nsIDOMNode> parent;
|
|
|
|
nsresult result = cellNode->GetParentNode(getter_AddRefs(parent));
|
|
|
|
if (NS_FAILED(result)) return result;
|
|
|
|
if (!parent) return NS_ERROR_FAILURE;
|
|
|
|
|
|
|
|
nsCOMPtr<nsIContent> parentContent = do_QueryInterface(parent);
|
|
|
|
nsCOMPtr<nsIContent> cellContent = do_QueryInterface(aCellElement);
|
2000-05-31 04:07:58 +04:00
|
|
|
|
|
|
|
// Get child offset
|
2000-05-16 07:03:13 +04:00
|
|
|
PRInt32 offset;
|
|
|
|
result = parentContent->IndexOf(cellContent, offset);
|
|
|
|
if (NS_FAILED(result)) return result;
|
|
|
|
return CreateAndAddRange(parent, offset);
|
|
|
|
}
|
|
|
|
|
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));
|
|
|
|
if (NS_FAILED(result)) return result;
|
|
|
|
|
|
|
|
nsCOMPtr<nsIContent> content(do_QueryInterface(startNode));
|
|
|
|
if (!content) return NS_ERROR_FAILURE;
|
|
|
|
PRInt32 startOffset;
|
|
|
|
result = aRange->GetStartOffset(&startOffset);
|
|
|
|
if (NS_FAILED(result)) return result;
|
|
|
|
|
|
|
|
nsCOMPtr<nsIContent> child;
|
|
|
|
result = content->ChildAt(startOffset, *getter_AddRefs(child));
|
|
|
|
if (NS_FAILED(result)) return result;
|
|
|
|
if (!child) return NS_ERROR_FAILURE;
|
|
|
|
|
|
|
|
//Note: This is a non-ref-counted pointer to the frame
|
|
|
|
nsITableCellLayout *cellLayout = mFrameSelection->GetCellLayout(child);
|
|
|
|
if (NS_FAILED(result)) return result;
|
|
|
|
if (!cellLayout) return NS_ERROR_FAILURE;
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
|
|
|
if (!mRangeArray)
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
|
|
|
|
nsresult result;
|
|
|
|
nsCOMPtr<nsISupports> isupp = do_QueryInterface(aRange, &result);
|
|
|
|
if (NS_FAILED(result)) return 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
|
|
|
|
|
|
|
PRUint32 count;
|
|
|
|
result = mRangeArray->Count(&count);
|
|
|
|
if (NS_FAILED(result)) return result;
|
|
|
|
|
|
|
|
if (count > 0)
|
|
|
|
{
|
|
|
|
// Adding a cell range to existing list of cell ranges
|
|
|
|
PRUint32 index;
|
|
|
|
PRInt32 row, col;
|
|
|
|
// Insert range at appropriate location
|
|
|
|
for (index = 0; index < count; index++)
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsISupports> element = dont_AddRef(mRangeArray->ElementAt(index));
|
|
|
|
nsCOMPtr<nsIDOMRange> range = do_QueryInterface(element);
|
|
|
|
if (!range) return NS_ERROR_FAILURE;
|
|
|
|
|
|
|
|
PRInt32 selectionMode;
|
|
|
|
result = getTableCellLocationFromRange(range, &selectionMode, &row, &col);
|
|
|
|
if (NS_FAILED(result)) return result;
|
|
|
|
|
|
|
|
// Don't proceed if range not a table cell
|
|
|
|
if (selectionMode != nsISelectionPrivate::TABLESELECTION_CELL)
|
|
|
|
return NS_OK;
|
|
|
|
|
|
|
|
if (row > newRow ||
|
|
|
|
(row == newRow && col > newCol))
|
|
|
|
{
|
|
|
|
// Existing selected cell is after cell to add,
|
|
|
|
// so insert at this index
|
|
|
|
result = mRangeArray->InsertElementAt(isupp, index);
|
|
|
|
*aDidAddRange = NS_SUCCEEDED(result);
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// If here, we are adding a selected cell range
|
|
|
|
// to end of range array or it's the first selected range
|
|
|
|
result = mRangeArray->AppendElement(isupp);
|
|
|
|
*aDidAddRange = NS_SUCCEEDED(result);
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
//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;
|
|
|
|
|
|
|
|
nsCOMPtr<nsIContent> content = do_QueryInterface(startNode);
|
|
|
|
if (!content) return NS_ERROR_FAILURE;
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
|
|
|
nsCOMPtr<nsIAtom> atom;
|
|
|
|
content->GetTag(*getter_AddRefs(atom));
|
|
|
|
if (!atom) return NS_ERROR_FAILURE;
|
|
|
|
|
|
|
|
if (atom.get() == nsSelection::sRowAtom)
|
|
|
|
{
|
|
|
|
*aTableSelectionType = nsISelectionPrivate::TABLESELECTION_CELL;
|
|
|
|
}
|
|
|
|
else //check to see if we are selecting a table or row (column and all cells not done yet)
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsIContent> child;
|
|
|
|
result = content->ChildAt(startOffset, *getter_AddRefs(child));
|
|
|
|
if (NS_FAILED(result)) return result;
|
|
|
|
if (!child) return NS_ERROR_FAILURE;
|
|
|
|
|
|
|
|
child->GetTag(*getter_AddRefs(atom));
|
|
|
|
if (!atom) return NS_ERROR_FAILURE;
|
|
|
|
|
|
|
|
if (atom.get() == nsSelection::sTableAtom)
|
|
|
|
*aTableSelectionType = nsISelectionPrivate::TABLESELECTION_TABLE;
|
|
|
|
else if (atom.get() == nsSelection::sRowAtom)
|
|
|
|
*aTableSelectionType = nsISelectionPrivate::TABLESELECTION_ROW;
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2000-03-22 02:58:02 +03:00
|
|
|
nsresult
|
|
|
|
nsSelection::CreateAndAddRange(nsIDOMNode *aParentNode, PRInt32 aOffset)
|
|
|
|
{
|
|
|
|
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
|
|
|
|
|
2000-08-09 03:38:00 +04:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsSelection::AdjustOffsetsFromStyle(nsIFrame *aFrame, PRBool *changeSelection,
|
|
|
|
nsIContent** outContent, PRInt32* outStartOffset, PRInt32* outEndOffset)
|
|
|
|
{
|
|
|
|
|
|
|
|
*changeSelection = PR_FALSE;
|
|
|
|
*outContent = nsnull;
|
|
|
|
|
|
|
|
nsresult rv;
|
|
|
|
nsIFrame* selectAllFrame;
|
|
|
|
rv = FrameOrParentHasSpecialSelectionStyle(aFrame, NS_STYLE_USER_SELECT_ALL, &selectAllFrame);
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
|
|
|
|
if (!selectAllFrame)
|
|
|
|
return NS_OK;
|
|
|
|
|
|
|
|
nsCOMPtr<nsIContent> selectAllContent;
|
|
|
|
selectAllFrame->GetContent(getter_AddRefs(selectAllContent));
|
|
|
|
if (selectAllContent)
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsIContent> parentContent;
|
|
|
|
rv = selectAllContent->GetParent(*getter_AddRefs(parentContent));
|
|
|
|
if (parentContent)
|
|
|
|
{
|
|
|
|
PRInt32 startOffset;
|
|
|
|
rv = parentContent->IndexOf(selectAllContent, startOffset);
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
if (startOffset < 0)
|
|
|
|
{
|
|
|
|
// hrmm, this is probably anonymous content. Let's go up another level
|
|
|
|
// do we need to do this if we get the right frameSelection to start with?
|
|
|
|
nsCOMPtr<nsIContent> superParent;
|
|
|
|
parentContent->GetParent(*getter_AddRefs(superParent));
|
|
|
|
if (superParent)
|
|
|
|
{
|
|
|
|
PRInt32 superStartOffset;
|
|
|
|
rv = superParent->IndexOf(parentContent, superStartOffset);
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
if (superStartOffset < 0)
|
|
|
|
return NS_ERROR_FAILURE; // give up
|
|
|
|
|
|
|
|
parentContent = superParent;
|
|
|
|
startOffset = superStartOffset;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IF_ADDREF(*outContent = parentContent);
|
|
|
|
|
|
|
|
*outStartOffset = startOffset;
|
|
|
|
*outEndOffset = startOffset + 1;
|
|
|
|
|
|
|
|
*changeSelection = PR_TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2000-03-22 02:58:02 +03:00
|
|
|
NS_IMETHODIMP
|
2000-06-28 08:00:12 +04:00
|
|
|
nsSelection::SetHint(HINT aHintRight)
|
2000-03-22 02:58:02 +03:00
|
|
|
{
|
2000-06-28 08:00:12 +04:00
|
|
|
mHint = aHintRight;
|
2000-03-22 02:58:02 +03:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2000-06-28 08:00:12 +04:00
|
|
|
nsSelection::GetHint(HINT *aHintRight)
|
2000-03-22 02:58:02 +03:00
|
|
|
{
|
2000-06-28 08:00:12 +04:00
|
|
|
*aHintRight = mHint;
|
2000-03-22 02:58:02 +03:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//END nsIFrameSelection methods
|
|
|
|
|
|
|
|
|
|
|
|
#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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** DeleteFromDocument
|
|
|
|
* will return NS_OK if it handles the event or NS_COMFALSE if not.
|
|
|
|
*/
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsSelection::DeleteFromDocument()
|
|
|
|
{
|
|
|
|
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();
|
|
|
|
if (!NS_SUCCEEDED(res))
|
|
|
|
return res;
|
|
|
|
|
|
|
|
nsCOMPtr<nsIDOMRange> range;
|
|
|
|
while (iter.IsDone())
|
|
|
|
{
|
|
|
|
res = iter.CurrentItem(NS_STATIC_CAST(nsIDOMRange**, getter_AddRefs(range)));
|
|
|
|
if (!NS_SUCCEEDED(res))
|
|
|
|
return res;
|
|
|
|
res = range->DeleteContents();
|
|
|
|
if (!NS_SUCCEEDED(res))
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2000-04-28 10:21:31 +04:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsSelection::SetDisplaySelection(PRInt16 aToggle)
|
|
|
|
{
|
|
|
|
mDisplaySelection = aToggle;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsSelection::GetDisplaySelection(PRInt16 *aToggle)
|
|
|
|
{
|
|
|
|
if (!aToggle)
|
|
|
|
return NS_ERROR_INVALID_ARG;
|
|
|
|
*aToggle = mDisplaySelection;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2000-05-26 00:04:02 +04:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsSelection::SetDelayCaretOverExistingSelection(PRBool aDelay)
|
|
|
|
{
|
|
|
|
mDelayCaretOverExistingSelection = aDelay;
|
|
|
|
|
|
|
|
if (! aDelay)
|
|
|
|
mDelayedMouseEventValid = PR_FALSE;
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsSelection::GetDelayCaretOverExistingSelection(PRBool *aDelay)
|
|
|
|
{
|
|
|
|
if (!aDelay)
|
|
|
|
return NS_ERROR_NULL_POINTER;
|
|
|
|
|
|
|
|
*aDelay = mDelayCaretOverExistingSelection;
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsSelection::SetDelayedCaretData(nsMouseEvent *aMouseEvent)
|
|
|
|
{
|
|
|
|
if (aMouseEvent)
|
|
|
|
{
|
|
|
|
mDelayedMouseEventValid = PR_TRUE;
|
|
|
|
mDelayedMouseEvent = *aMouseEvent;
|
|
|
|
|
|
|
|
// XXX: Hmmm, should we AddRef mDelayedMouseEvent->widget?
|
|
|
|
// Doing so might introduce a leak if things in the app
|
|
|
|
// are not released in the correct order though, so for now
|
|
|
|
// don't do anything.
|
|
|
|
}
|
|
|
|
else
|
|
|
|
mDelayedMouseEventValid = PR_FALSE;
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsSelection::GetDelayedCaretData(nsMouseEvent **aMouseEvent)
|
|
|
|
{
|
|
|
|
if (!aMouseEvent)
|
|
|
|
return NS_ERROR_NULL_POINTER;
|
|
|
|
|
|
|
|
if (mDelayedMouseEventValid)
|
|
|
|
*aMouseEvent = &mDelayedMouseEvent;
|
|
|
|
else
|
|
|
|
*aMouseEvent = 0;
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2000-08-02 05:47:55 +04:00
|
|
|
// Frame needs to get the limiting content node for parent node searches
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsSelection::GetLimiter(nsIContent **aLimiterContent)
|
|
|
|
{
|
|
|
|
if (!aLimiterContent) return NS_ERROR_NULL_POINTER;
|
|
|
|
*aLimiterContent = mLimiter;
|
2000-08-02 06:39:10 +04:00
|
|
|
NS_IF_ADDREF(*aLimiterContent);
|
2000-08-02 05:47:55 +04:00
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2000-09-14 15:45:01 +04:00
|
|
|
//END nsISelection interface implementations
|
2000-03-22 02:58:02 +03:00
|
|
|
|
|
|
|
#ifdef XP_MAC
|
|
|
|
#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
|
|
|
|
|
2000-11-29 03:13:00 +03:00
|
|
|
nsTypedSelection::nsTypedSelection(nsSelection *aList)
|
2000-03-22 02:58:02 +03:00
|
|
|
{
|
|
|
|
mFrameSelection = aList;
|
|
|
|
mFixupState = PR_FALSE;
|
|
|
|
mDirection = eDirNext;
|
|
|
|
NS_NewISupportsArray(getter_AddRefs(mRangeArray));
|
|
|
|
mAutoScrollTimer = nsnull;
|
2000-05-04 12:35:42 +04:00
|
|
|
NS_NewISupportsArray(getter_AddRefs(mSelectionListeners));
|
2000-03-22 02:58:02 +03:00
|
|
|
NS_INIT_REFCNT();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
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;
|
|
|
|
NS_NewISupportsArray(getter_AddRefs(mRangeArray));
|
|
|
|
mAutoScrollTimer = nsnull;
|
|
|
|
NS_NewISupportsArray(getter_AddRefs(mSelectionListeners));
|
|
|
|
NS_INIT_REFCNT();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
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
|
|
|
{
|
|
|
|
PRUint32 cnt = 0;
|
2000-05-04 12:35:42 +04:00
|
|
|
if (mSelectionListeners)
|
|
|
|
{
|
|
|
|
nsresult rv = mSelectionListeners->Count(&cnt);
|
|
|
|
NS_ASSERTION(NS_SUCCEEDED(rv), "Count failed");
|
|
|
|
for (PRUint32 i=0;i < cnt; i++)
|
|
|
|
{
|
|
|
|
mSelectionListeners->RemoveElementAt(i);
|
|
|
|
}
|
|
|
|
}
|
2000-03-22 02:58:02 +03:00
|
|
|
nsresult rv = mRangeArray->Count(&cnt);
|
|
|
|
NS_ASSERTION(NS_SUCCEEDED(rv), "Count failed");
|
|
|
|
PRUint32 j;
|
|
|
|
for (j=0; j<cnt; j++)
|
|
|
|
{
|
|
|
|
mRangeArray->RemoveElementAt(0);
|
|
|
|
}
|
|
|
|
setAnchorFocusRange(-1);
|
|
|
|
|
2000-07-28 07:48:26 +04:00
|
|
|
if (mAutoScrollTimer) {
|
|
|
|
mAutoScrollTimer->Stop();
|
|
|
|
NS_RELEASE(mAutoScrollTimer);
|
|
|
|
}
|
2000-03-22 02:58:02 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2000-11-29 03:13:00 +03:00
|
|
|
NS_IMPL_ADDREF(nsTypedSelection)
|
2000-03-22 02:58:02 +03:00
|
|
|
|
2000-11-29 03:13:00 +03:00
|
|
|
NS_IMPL_RELEASE(nsTypedSelection)
|
2000-03-22 02:58:02 +03:00
|
|
|
|
2000-11-29 03:13:00 +03:00
|
|
|
NS_IMPL_QUERY_INTERFACE5(nsTypedSelection, nsISelection, nsISelectionPrivate, nsISupportsWeakReference, nsIIndependentSelection, nsISecurityCheckedComponent)
|
2000-05-13 12:07:34 +04:00
|
|
|
|
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
|
|
|
{
|
|
|
|
mPresShellWeak = getter_AddRefs(NS_GetWeakReference(aPresShell));
|
|
|
|
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
|
|
|
{
|
2000-08-27 01:23:25 +04:00
|
|
|
if (!aAnchorNode)
|
|
|
|
return NS_ERROR_NULL_POINTER;
|
|
|
|
*aAnchorNode = 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->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
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
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
|
|
|
{
|
2000-08-27 01:23:25 +04:00
|
|
|
if (!aAnchorOffset)
|
2000-03-22 02:58:02 +03:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
// 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
|
|
|
{
|
2000-08-27 01:23:25 +04:00
|
|
|
if (!aFocusNode)
|
2000-03-22 02:58:02 +03:00
|
|
|
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
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2000-11-29 03:13:00 +03:00
|
|
|
NS_IMETHODIMP nsTypedSelection::GetFocusOffset(PRInt32* aFocusOffset)
|
2000-03-22 02:58:02 +03:00
|
|
|
{
|
2000-08-27 01:23:25 +04:00
|
|
|
if (!aFocusOffset)
|
2000-03-22 02:58:02 +03:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2000-11-29 03:13:00 +03:00
|
|
|
void nsTypedSelection::setAnchorFocusRange(PRInt32 indx)
|
2000-03-22 02:58:02 +03:00
|
|
|
{
|
|
|
|
PRUint32 cnt;
|
|
|
|
nsresult rv = mRangeArray->Count(&cnt);
|
|
|
|
if (NS_FAILED(rv)) return; // XXX error?
|
|
|
|
if (((PRUint32)indx) >= cnt )
|
|
|
|
return;
|
|
|
|
if (indx < 0) //release all
|
|
|
|
{
|
|
|
|
mAnchorFocusRange = nsCOMPtr<nsIDOMRange>();
|
|
|
|
}
|
|
|
|
else{
|
|
|
|
nsCOMPtr<nsISupports> indexIsupports = dont_AddRef(mRangeArray->ElementAt(indx));
|
|
|
|
mAnchorFocusRange = do_QueryInterface(indexIsupports);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
2000-11-29 03:13:00 +03:00
|
|
|
nsTypedSelection::AddItem(nsIDOMRange *aItem)
|
2000-03-22 02:58:02 +03:00
|
|
|
{
|
|
|
|
if (!mRangeArray)
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
if (!aItem)
|
|
|
|
return NS_ERROR_NULL_POINTER;
|
|
|
|
nsresult result;
|
|
|
|
nsCOMPtr<nsISupports> isupp = do_QueryInterface(aItem, &result);
|
|
|
|
if (NS_SUCCEEDED(result)) {
|
|
|
|
result = mRangeArray->AppendElement(isupp);
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
nsresult
|
2000-11-29 03:13:00 +03:00
|
|
|
nsTypedSelection::RemoveItem(nsIDOMRange *aItem)
|
2000-03-22 02:58:02 +03:00
|
|
|
{
|
|
|
|
if (!mRangeArray)
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
if (!aItem )
|
|
|
|
return NS_ERROR_NULL_POINTER;
|
|
|
|
PRUint32 cnt;
|
|
|
|
nsresult rv = mRangeArray->Count(&cnt);
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
for (PRUint32 i = 0; i < cnt;i++)
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsISupports> indexIsupports = dont_AddRef(mRangeArray->ElementAt(i));
|
|
|
|
nsCOMPtr<nsISupports> isupp;
|
|
|
|
aItem->QueryInterface(NS_GET_IID(nsISupports),getter_AddRefs(isupp));
|
|
|
|
if (isupp.get() == indexIsupports.get())
|
|
|
|
{
|
|
|
|
mRangeArray->RemoveElementAt(i);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return NS_COMFALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
nsresult
|
2000-11-29 03:13:00 +03:00
|
|
|
nsTypedSelection::Clear(nsIPresContext* aPresContext)
|
2000-03-22 02:58:02 +03:00
|
|
|
{
|
|
|
|
setAnchorFocusRange(-1);
|
|
|
|
if (!mRangeArray)
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
// Get an iterator
|
|
|
|
while (PR_TRUE)
|
|
|
|
{
|
|
|
|
PRUint32 cnt;
|
|
|
|
nsresult rv = mRangeArray->Count(&cnt);
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
if (cnt == 0)
|
|
|
|
break;
|
|
|
|
nsCOMPtr<nsISupports> isupportsindex = dont_AddRef(mRangeArray->ElementAt(0));
|
|
|
|
nsCOMPtr<nsIDOMRange> range = do_QueryInterface(isupportsindex);
|
|
|
|
mRangeArray->RemoveElementAt(0);
|
|
|
|
selectFrames(aPresContext, range, 0);
|
|
|
|
// Does RemoveElementAt also delete the elements?
|
|
|
|
}
|
|
|
|
// Reset direction so for more dependable table selection range handling
|
|
|
|
SetDirection(eDirNext);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
//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;
|
|
|
|
|
|
|
|
nsresult result = NS_OK;
|
|
|
|
|
|
|
|
nsCOMPtr<nsIDOMNode> node = dont_QueryInterface(aNode);
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
|
|
|
PRBool canContainChildren = PR_FALSE;
|
|
|
|
|
|
|
|
result = content->CanContainChildren(canContainChildren);
|
|
|
|
|
|
|
|
if (NS_SUCCEEDED(result) && canContainChildren)
|
|
|
|
{
|
|
|
|
if (aIsEndNode)
|
|
|
|
aOffset--;
|
|
|
|
|
|
|
|
if (aOffset >= 0)
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsIContent> child;
|
|
|
|
result = content->ChildAt(aOffset, *getter_AddRefs(child));
|
|
|
|
if (NS_FAILED(result))
|
|
|
|
return result;
|
|
|
|
if (!child) //out of bounds?
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
content = child;//releases the focusnode
|
|
|
|
}
|
|
|
|
}
|
|
|
|
result = mFrameSelection->GetTracker()->GetPrimaryFrameFor(content,aReturnFrame);
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
#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
|
|
|
{
|
|
|
|
nsIFrameSelection::HINT hint;
|
|
|
|
mFrameSelection->GetHint(&hint);
|
|
|
|
return mFrameSelection->GetFrameForNodeOffset(content, FetchAnchorOffset(),hint,aReturnFrame, &frameOffset);
|
|
|
|
}
|
2000-03-22 02:58:02 +03:00
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2000-11-29 03:13:00 +03:00
|
|
|
nsTypedSelection::GetPrimaryFrameForFocusNode(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(FetchFocusNode());
|
2000-05-11 08:25:43 +04:00
|
|
|
if (content && mFrameSelection)
|
2000-06-28 08:00:12 +04:00
|
|
|
{
|
|
|
|
nsIFrameSelection::HINT hint;
|
|
|
|
mFrameSelection->GetHint(&hint);
|
|
|
|
return mFrameSelection->GetFrameForNodeOffset(content, FetchFocusOffset(),hint,aReturnFrame, &frameOffset);
|
|
|
|
}
|
2000-03-22 02:58:02 +03:00
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//select all content children of aContent
|
|
|
|
NS_IMETHODIMP
|
2000-11-29 03:13:00 +03:00
|
|
|
nsTypedSelection::selectFrames(nsIPresContext* 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;
|
|
|
|
#ifdef USE_SELECTION_GENERATED_CONTENT_ITERATOR_CODE
|
2000-03-31 11:17:22 +04:00
|
|
|
nsCOMPtr<nsIGeneratedContentIterator> genericiter = do_QueryInterface(aInnerIter);
|
|
|
|
if (genericiter && aPresShell)
|
|
|
|
{
|
2000-04-02 09:05:31 +04:00
|
|
|
result = genericiter->Init(aPresShell,aContent);
|
2000-03-31 11:17:22 +04:00
|
|
|
}
|
|
|
|
else
|
2000-10-14 02:37:52 +04:00
|
|
|
#endif // USE_SELECTION_GENERATED_CONTENT_ITERATOR_CODE
|
2000-03-31 11:17:22 +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
|
|
|
|
result = mFrameSelection->GetTracker()->GetPrimaryFrameFor(aContent, &frame);
|
|
|
|
if (NS_SUCCEEDED(result) && frame)
|
|
|
|
//NOTE: aRange and eSpreadDown are now IGNORED. Selected state is set only for given frame
|
|
|
|
frame->SetSelected(aPresContext, aRange, aFlags, eSpreadDown);
|
|
|
|
|
|
|
|
// Now iterated through the child frames and set them
|
|
|
|
nsCOMPtr<nsIContent> innercontent;
|
|
|
|
while (NS_ENUMERATOR_FALSE == aInnerIter->IsDone())
|
|
|
|
{
|
|
|
|
result = aInnerIter->CurrentNode(getter_AddRefs(innercontent));
|
2000-09-13 04:05:29 +04:00
|
|
|
if (NS_SUCCEEDED(result) && innercontent)
|
|
|
|
{
|
|
|
|
result = mFrameSelection->GetTracker()->GetPrimaryFrameFor(innercontent, &frame);
|
|
|
|
if (NS_SUCCEEDED(result) && frame)
|
|
|
|
//NOTE: aRange and eSpreadDown are now IGNORED. Selected state is set only for given frame
|
|
|
|
frame->SetSelected(aPresContext, aRange,aFlags,eSpreadDown);//spread from here to hit all frames in flow
|
|
|
|
}
|
2000-03-22 02:58:02 +03:00
|
|
|
result = aInnerIter->Next();
|
|
|
|
if (NS_FAILED(result))
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
#if 0
|
|
|
|
result = mFrameSelection->GetTracker()->GetPrimaryFrameFor(content, &frame);
|
|
|
|
if (NS_SUCCEEDED(result) && frame)
|
|
|
|
frame->SetSelected(aRange,aFlags,eSpreadDown);//spread from here to hit all frames in flow
|
|
|
|
#endif
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//the idea of this helper method is to select, deselect "top to bottom" traversing through the frames
|
|
|
|
NS_IMETHODIMP
|
2000-11-29 03:13:00 +03:00
|
|
|
nsTypedSelection::selectFrames(nsIPresContext* 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;
|
|
|
|
nsCOMPtr<nsIContentIterator> iter;
|
|
|
|
nsCOMPtr<nsIContentIterator> inneriter;
|
2000-10-14 02:37:52 +04:00
|
|
|
nsresult result = nsComponentManager::CreateInstance(
|
|
|
|
#ifdef USE_SELECTION_GENERATED_CONTENT_ITERATOR_CODE
|
|
|
|
kCGenSubtreeIteratorCID,
|
|
|
|
#else
|
|
|
|
kCSubtreeIteratorCID,
|
|
|
|
#endif // USE_SELECTION_GENERATED_CONTENT_ITERATOR_CODE
|
|
|
|
nsnull,
|
2000-03-22 02:58:02 +03:00
|
|
|
NS_GET_IID(nsIContentIterator),
|
|
|
|
getter_AddRefs(iter));
|
|
|
|
if (NS_FAILED(result))
|
|
|
|
return result;
|
2000-10-14 02:37:52 +04:00
|
|
|
result = nsComponentManager::CreateInstance(
|
|
|
|
#ifdef USE_SELECTION_GENERATED_CONTENT_ITERATOR_CODE
|
|
|
|
kCGenContentIteratorCID,
|
|
|
|
#else
|
|
|
|
kCContentIteratorCID,
|
|
|
|
#endif // USE_SELECTION_GENERATED_CONTENT_ITERATOR_CODE
|
|
|
|
nsnull,
|
2000-03-22 02:58:02 +03:00
|
|
|
NS_GET_IID(nsIContentIterator),
|
|
|
|
getter_AddRefs(inneriter));
|
2000-03-31 11:17:22 +04:00
|
|
|
|
2000-03-22 02:58:02 +03:00
|
|
|
if ((NS_SUCCEEDED(result)) && iter && inneriter)
|
|
|
|
{
|
2000-03-31 11:17:22 +04:00
|
|
|
nsCOMPtr<nsIPresShell> presShell;
|
|
|
|
result = aPresContext->GetShell(getter_AddRefs(presShell));
|
|
|
|
if (NS_FAILED(result) && presShell)
|
|
|
|
presShell = 0;
|
2000-10-14 02:37:52 +04:00
|
|
|
#ifdef USE_SELECTION_GENERATED_CONTENT_ITERATOR_CODE
|
2000-04-02 09:05:31 +04:00
|
|
|
nsCOMPtr<nsIGeneratedContentIterator> genericiter = do_QueryInterface(iter);
|
|
|
|
if (genericiter && presShell)
|
|
|
|
result = genericiter->Init(presShell,aRange);
|
|
|
|
else
|
2000-10-14 02:37:52 +04:00
|
|
|
#endif // USE_SELECTION_GENERATED_CONTENT_ITERATOR_CODE
|
2000-04-02 09:05:31 +04:00
|
|
|
result = iter->Init(aRange);
|
|
|
|
|
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;
|
|
|
|
PRBool canContainChildren = PR_FALSE;
|
|
|
|
result = content->CanContainChildren(canContainChildren);
|
|
|
|
if (NS_SUCCEEDED(result) && !canContainChildren)
|
|
|
|
{
|
|
|
|
result = mFrameSelection->GetTracker()->GetPrimaryFrameFor(content, &frame);
|
|
|
|
if (NS_SUCCEEDED(result) && frame)
|
|
|
|
frame->SetSelected(aPresContext, aRange,aFlags,eSpreadDown);//spread from here to hit all frames in flow
|
|
|
|
}
|
|
|
|
//end start content
|
|
|
|
result = iter->First();
|
|
|
|
while (NS_SUCCEEDED(result) && NS_ENUMERATOR_FALSE == iter->IsDone())
|
|
|
|
{
|
|
|
|
result = iter->CurrentNode(getter_AddRefs(content));
|
|
|
|
if (NS_FAILED(result) || !content)
|
|
|
|
return result;
|
2000-03-31 11:17:22 +04:00
|
|
|
selectFrames(aPresContext, inneriter, content, aRange, presShell,aFlags);
|
2000-03-22 02:58:02 +03:00
|
|
|
result = iter->Next();
|
|
|
|
}
|
|
|
|
//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;
|
|
|
|
canContainChildren = PR_FALSE;
|
|
|
|
result = content->CanContainChildren(canContainChildren);
|
|
|
|
if (NS_SUCCEEDED(result) && !canContainChildren)
|
|
|
|
{
|
|
|
|
result = mFrameSelection->GetTracker()->GetPrimaryFrameFor(content, &frame);
|
|
|
|
if (NS_SUCCEEDED(result) && frame)
|
|
|
|
frame->SetSelected(aPresContext, aRange,aFlags,eSpreadDown);//spread from here to hit all frames in flow
|
|
|
|
}
|
|
|
|
}
|
|
|
|
//end end parent
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2000-11-29 03:13:00 +03:00
|
|
|
nsTypedSelection::LookUpSelection(nsIContent *aContent, PRInt32 aContentOffset, PRInt32 aContentLength,
|
2000-03-22 02:58:02 +03:00
|
|
|
SelectionDetails **aReturnDetails, SelectionType aType, PRBool aSlowCheck)
|
|
|
|
{
|
|
|
|
PRInt32 cnt;
|
|
|
|
nsresult rv = GetRangeCount(&cnt);
|
|
|
|
if (NS_FAILED(rv))
|
|
|
|
return rv;
|
|
|
|
PRInt32 i;
|
|
|
|
|
|
|
|
nsCOMPtr<nsIDOMNode> passedInNode;
|
|
|
|
passedInNode = do_QueryInterface(aContent);
|
|
|
|
if (!passedInNode)
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
|
|
|
|
SelectionDetails *details = nsnull;
|
|
|
|
SelectionDetails *newDetails = details;
|
|
|
|
|
|
|
|
for (i =0; i<cnt; i++){
|
|
|
|
nsCOMPtr<nsIDOMRange> range;
|
|
|
|
nsCOMPtr<nsISupports> isupportsindex = dont_AddRef(mRangeArray->ElementAt(i));
|
|
|
|
range = do_QueryInterface(isupportsindex);
|
|
|
|
if (range){
|
|
|
|
nsCOMPtr<nsIDOMNode> startNode;
|
|
|
|
nsCOMPtr<nsIDOMNode> endNode;
|
|
|
|
PRInt32 startOffset;
|
|
|
|
PRInt32 endOffset;
|
2000-08-24 07:54:30 +04:00
|
|
|
range->GetStartContainer(getter_AddRefs(startNode));
|
2000-03-22 02:58:02 +03:00
|
|
|
range->GetStartOffset(&startOffset);
|
2000-08-24 07:54:30 +04:00
|
|
|
range->GetEndContainer(getter_AddRefs(endNode));
|
2000-03-22 02:58:02 +03:00
|
|
|
range->GetEndOffset(&endOffset);
|
|
|
|
if (passedInNode == startNode && passedInNode == endNode){
|
|
|
|
if (startOffset < (aContentOffset + aContentLength) &&
|
|
|
|
endOffset > aContentOffset){
|
|
|
|
if (!details){
|
|
|
|
details = new SelectionDetails;
|
|
|
|
|
|
|
|
newDetails = details;
|
|
|
|
}
|
|
|
|
else{
|
|
|
|
newDetails->mNext = new SelectionDetails;
|
|
|
|
newDetails = newDetails->mNext;
|
|
|
|
}
|
|
|
|
if (!newDetails)
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
newDetails->mNext = nsnull;
|
|
|
|
newDetails->mStart = PR_MAX(0,startOffset - aContentOffset);
|
|
|
|
newDetails->mEnd = PR_MIN(aContentLength, endOffset - aContentOffset);
|
|
|
|
newDetails->mType = aType;
|
|
|
|
}
|
|
|
|
}
|
2000-05-13 12:07:34 +04:00
|
|
|
else if (passedInNode == startNode){ //are we at the beginning?
|
2000-03-22 02:58:02 +03:00
|
|
|
if (startOffset < (aContentOffset + aContentLength)){
|
|
|
|
if (!details){
|
|
|
|
details = new SelectionDetails;
|
|
|
|
newDetails = details;
|
|
|
|
}
|
|
|
|
else{
|
|
|
|
newDetails->mNext = new SelectionDetails;
|
|
|
|
newDetails = newDetails->mNext;
|
|
|
|
}
|
|
|
|
if (!newDetails)
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
newDetails->mNext = nsnull;
|
|
|
|
newDetails->mStart = PR_MAX(0,startOffset - aContentOffset);
|
|
|
|
newDetails->mEnd = aContentLength;
|
|
|
|
newDetails->mType = aType;
|
|
|
|
}
|
|
|
|
}
|
2000-05-13 12:07:34 +04:00
|
|
|
else if (passedInNode == endNode){//are we at the end?
|
2000-03-22 02:58:02 +03:00
|
|
|
if (endOffset > aContentOffset){
|
|
|
|
if (!details){
|
|
|
|
details = new SelectionDetails;
|
|
|
|
newDetails = details;
|
|
|
|
}
|
|
|
|
else{
|
|
|
|
newDetails->mNext = new SelectionDetails;
|
|
|
|
newDetails = newDetails->mNext;
|
|
|
|
}
|
|
|
|
if (!newDetails)
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
newDetails->mNext = nsnull;
|
|
|
|
newDetails->mStart = 0;
|
|
|
|
newDetails->mEnd = PR_MIN(aContentLength, endOffset - aContentOffset);
|
|
|
|
newDetails->mType = aType;
|
|
|
|
}
|
|
|
|
}
|
2000-05-13 12:07:34 +04:00
|
|
|
else { //then we MUST be completely selected! unless someone needs us to check to make sure with slowcheck
|
|
|
|
|
|
|
|
if (cnt > 1 || aSlowCheck){ //if more than 1 selection or we need to do slow check see if farther than start or less than end.
|
2000-03-22 02:58:02 +03:00
|
|
|
//we only have to look at start offset because anything else would have been in the range
|
|
|
|
PRInt32 resultnum = ComparePoints(startNode, startOffset
|
|
|
|
,passedInNode, aContentOffset);
|
|
|
|
if (resultnum > 0)
|
|
|
|
continue;
|
|
|
|
resultnum = ComparePoints(endNode, endOffset,
|
|
|
|
passedInNode, aContentOffset );
|
|
|
|
if (resultnum <0)
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!details){
|
|
|
|
details = new SelectionDetails;
|
|
|
|
newDetails = details;
|
|
|
|
}
|
|
|
|
else{
|
|
|
|
newDetails->mNext = new SelectionDetails;
|
|
|
|
newDetails = newDetails->mNext;
|
|
|
|
}
|
|
|
|
if (!newDetails)
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
newDetails->mNext = nsnull;
|
|
|
|
newDetails->mStart = 0;
|
|
|
|
newDetails->mEnd = aContentLength;
|
|
|
|
newDetails->mType = aType;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (*aReturnDetails && newDetails)
|
|
|
|
newDetails->mNext = *aReturnDetails;
|
|
|
|
if (details)
|
|
|
|
*aReturnDetails = details;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2000-11-29 03:13:00 +03:00
|
|
|
nsTypedSelection::Repaint(nsIPresContext* aPresContext)
|
2000-03-22 02:58:02 +03:00
|
|
|
{
|
|
|
|
PRUint32 arrCount = 0;
|
|
|
|
|
|
|
|
if (!mRangeArray)
|
|
|
|
return NS_ERROR_NULL_POINTER;
|
|
|
|
|
|
|
|
nsCOMPtr<nsISupports> isupp;
|
|
|
|
nsCOMPtr<nsIDOMRange> range;
|
|
|
|
|
|
|
|
nsresult result = mRangeArray->Count(&arrCount);
|
|
|
|
|
|
|
|
if (NS_FAILED(result))
|
|
|
|
return result;
|
|
|
|
|
|
|
|
if (arrCount < 1)
|
|
|
|
return NS_OK;
|
|
|
|
|
|
|
|
PRUint32 i;
|
|
|
|
|
|
|
|
for (i = 0; i < arrCount; i++)
|
|
|
|
{
|
|
|
|
result = mRangeArray->GetElementAt(i, getter_AddRefs(isupp));
|
|
|
|
|
|
|
|
if (NS_FAILED(result))
|
|
|
|
return result;
|
|
|
|
|
|
|
|
if (!isupp)
|
|
|
|
return NS_ERROR_NULL_POINTER;
|
|
|
|
|
|
|
|
range = do_QueryInterface(isupp);
|
|
|
|
|
|
|
|
if (!range)
|
|
|
|
return NS_ERROR_NULL_POINTER;
|
|
|
|
|
|
|
|
result = selectFrames(aPresContext, range, PR_TRUE);
|
|
|
|
|
|
|
|
if (NS_FAILED(result))
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
2000-11-29 03:13:00 +03:00
|
|
|
nsTypedSelection::StartAutoScrollTimer(nsIPresContext *aPresContext, nsIFrame *aFrame, nsPoint& aPoint, PRUint32 aDelay)
|
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)
|
|
|
|
{
|
|
|
|
result = NS_NewAutoScrollTimer(&mAutoScrollTimer);
|
|
|
|
|
|
|
|
if (NS_FAILED(result))
|
|
|
|
return result;
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
|
|
|
return DoAutoScroll(aPresContext, aFrame, aPoint);
|
|
|
|
}
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
|
|
|
*aXOffset = 0;
|
|
|
|
*aYOffset = 0;
|
|
|
|
|
|
|
|
nsIView *view = aView;
|
|
|
|
|
|
|
|
while (view && view != aAncestorView)
|
|
|
|
{
|
|
|
|
nscoord x = 0, y = 0;
|
|
|
|
nsresult result = view->GetPosition(&x, &y);
|
|
|
|
|
|
|
|
if (NS_FAILED(result))
|
|
|
|
return result;
|
|
|
|
|
|
|
|
*aXOffset += x;
|
|
|
|
*aYOffset += y;
|
|
|
|
|
|
|
|
result = view->GetParent(view);
|
|
|
|
|
|
|
|
if (NS_FAILED(result))
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
2000-11-29 03:13:00 +03:00
|
|
|
nsTypedSelection::GetClosestScrollableView(nsIView *aView, nsIScrollableView **aScrollableView)
|
2000-08-30 23:42:47 +04:00
|
|
|
{
|
|
|
|
if (!aView || !aScrollableView)
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
|
|
|
|
*aScrollableView = 0;
|
|
|
|
|
|
|
|
while (!*aScrollableView && aView)
|
|
|
|
{
|
|
|
|
nsresult result = aView->QueryInterface(NS_GET_IID(nsIScrollableView), (void **)aScrollableView);
|
|
|
|
|
|
|
|
if (!*aScrollableView)
|
|
|
|
{
|
|
|
|
result = aView->GetParent(aView);
|
|
|
|
|
|
|
|
if (NS_FAILED(result))
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
2000-11-29 03:13:00 +03:00
|
|
|
nsTypedSelection::ScrollPointIntoClipView(nsIPresContext *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
|
|
|
//
|
|
|
|
|
|
|
|
nsIScrollableView *scrollableView = 0;
|
|
|
|
|
2000-08-30 23:42:47 +04:00
|
|
|
result = GetClosestScrollableView(aView, &scrollableView);
|
|
|
|
|
|
|
|
if (NS_FAILED(result))
|
|
|
|
return result;
|
|
|
|
|
|
|
|
if (!scrollableView)
|
|
|
|
return NS_OK; // Nothing to do!
|
|
|
|
|
|
|
|
//
|
|
|
|
// Get the clip view.
|
|
|
|
//
|
|
|
|
|
|
|
|
const nsIView *cView = 0;
|
|
|
|
|
|
|
|
result = scrollableView->GetClipView(&cView);
|
|
|
|
|
|
|
|
if (NS_FAILED(result))
|
|
|
|
return result;
|
|
|
|
|
|
|
|
//
|
|
|
|
// Get the view that is being scrolled.
|
|
|
|
//
|
|
|
|
|
|
|
|
nsIView *scrolledView = 0;
|
|
|
|
|
|
|
|
result = scrollableView->GetScrolledView(scrolledView);
|
|
|
|
if (!cView)
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
|
|
|
|
//
|
|
|
|
// 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!
|
|
|
|
//
|
|
|
|
|
|
|
|
nsRect bounds;
|
|
|
|
|
|
|
|
result = cView->GetBounds(bounds);
|
|
|
|
|
|
|
|
if (NS_FAILED(result))
|
|
|
|
return result;
|
|
|
|
|
|
|
|
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;
|
|
|
|
nsPoint ePoint = aPoint;
|
|
|
|
|
|
|
|
ePoint.x += viewOffset.x;
|
|
|
|
ePoint.y += viewOffset.y;
|
|
|
|
|
|
|
|
nscoord x1 = bounds.x;
|
|
|
|
nscoord x2 = bounds.x + bounds.width;
|
|
|
|
nscoord y1 = bounds.y;
|
|
|
|
nscoord y2 = bounds.y + bounds.height;
|
|
|
|
|
|
|
|
if (ePoint.x < x1)
|
|
|
|
dx = ePoint.x - x1;
|
|
|
|
else if (ePoint.x > x2)
|
|
|
|
dx = ePoint.x - x2;
|
|
|
|
|
|
|
|
if (ePoint.y < y1)
|
|
|
|
dy = ePoint.y - y1;
|
|
|
|
else if (ePoint.y > y2)
|
|
|
|
dy = ePoint.y - y2;
|
|
|
|
|
|
|
|
//
|
|
|
|
// Now clip the scroll amounts so that we don't scroll
|
|
|
|
// beyond the ends of the document.
|
|
|
|
//
|
|
|
|
|
|
|
|
nscoord scrollX = 0, scrollY = 0;
|
|
|
|
nscoord docWidth = 0, docHeight = 0;
|
|
|
|
|
|
|
|
result = scrollableView->GetScrollPosition(scrollX, scrollY);
|
|
|
|
|
|
|
|
if (NS_SUCCEEDED(result))
|
|
|
|
result = scrollableView->GetContainerSize(&docWidth, &docHeight);
|
|
|
|
|
|
|
|
if (NS_SUCCEEDED(result))
|
2000-03-22 02:58:02 +03:00
|
|
|
{
|
2000-08-30 23:42:47 +04:00
|
|
|
if (dx < 0 && scrollX == 0)
|
|
|
|
dx = 0;
|
|
|
|
else if (dx > 0)
|
|
|
|
{
|
|
|
|
x1 = scrollX + dx + bounds.width;
|
|
|
|
|
|
|
|
if (x1 > docWidth)
|
|
|
|
dx -= x1 - docWidth;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (dy < 0 && scrollY == 0)
|
|
|
|
dy = 0;
|
|
|
|
else if (dy > 0)
|
|
|
|
{
|
|
|
|
y1 = scrollY + dy + bounds.height;
|
|
|
|
|
|
|
|
if (y1 > docHeight)
|
|
|
|
dy -= y1 - docHeight;
|
|
|
|
}
|
|
|
|
|
2000-03-22 02:58:02 +03:00
|
|
|
//
|
2000-08-30 23:42:47 +04:00
|
|
|
// Now scroll the view if neccessary.
|
2000-03-22 02:58:02 +03:00
|
|
|
//
|
|
|
|
|
2000-08-30 23:42:47 +04:00
|
|
|
if (dx != 0 || dy != 0)
|
2000-03-22 02:58:02 +03:00
|
|
|
{
|
2000-08-30 23:42:47 +04:00
|
|
|
// Get the PresShell
|
|
|
|
nsCOMPtr<nsIPresShell> presShell;
|
|
|
|
result = aPresContext->GetShell(getter_AddRefs(presShell));
|
|
|
|
NS_ENSURE_TRUE(presShell,result);
|
2000-03-22 02:58:02 +03:00
|
|
|
|
2000-08-30 23:42:47 +04:00
|
|
|
// Get the ViewManager
|
|
|
|
nsCOMPtr<nsIViewManager> viewManager;
|
|
|
|
result = presShell->GetViewManager(getter_AddRefs(viewManager));
|
|
|
|
NS_ENSURE_TRUE(viewManager,result);
|
2000-03-22 02:58:02 +03:00
|
|
|
|
2000-08-30 23:42:47 +04:00
|
|
|
// Make sure latest bits are available before we scroll them.
|
|
|
|
|
|
|
|
viewManager->Composite();
|
2000-03-22 02:58:02 +03:00
|
|
|
|
2000-08-30 23:42:47 +04:00
|
|
|
// Now scroll the view!
|
2000-03-22 02:58:02 +03:00
|
|
|
|
2000-08-30 23:42:47 +04:00
|
|
|
result = scrollableView->ScrollTo(scrollX + dx, scrollY + dy, NS_VMREFRESH_NO_SYNC);
|
2000-03-22 02:58:02 +03:00
|
|
|
|
2000-08-30 23:42:47 +04:00
|
|
|
if (NS_FAILED(result))
|
|
|
|
return result;
|
|
|
|
|
|
|
|
nsPoint newPos;
|
|
|
|
|
|
|
|
result = scrollableView->GetScrollPosition(newPos.x, newPos.y);
|
|
|
|
|
|
|
|
if (NS_FAILED(result))
|
|
|
|
return result;
|
|
|
|
|
|
|
|
*aDidScroll = (bounds.x != newPos.x || bounds.y != newPos.y);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
2000-03-22 02:58:02 +03:00
|
|
|
|
2000-08-30 23:42:47 +04:00
|
|
|
nsresult
|
2000-11-29 03:13:00 +03:00
|
|
|
nsTypedSelection::ScrollPointIntoView(nsIPresContext *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.
|
|
|
|
//
|
|
|
|
|
|
|
|
nsIScrollableView *scrollableView = 0;
|
|
|
|
|
|
|
|
result = GetClosestScrollableView(aView, &scrollableView);
|
|
|
|
|
|
|
|
if (NS_FAILED(result))
|
|
|
|
return result;
|
|
|
|
|
|
|
|
if (scrollableView)
|
|
|
|
{
|
|
|
|
//
|
|
|
|
// Convert scrollableView to nsIView.
|
|
|
|
//
|
|
|
|
|
|
|
|
nsIView *scrolledView = 0;
|
|
|
|
nsIView *view = 0;
|
|
|
|
|
|
|
|
result = scrollableView->QueryInterface(NS_GET_IID(nsIView), (void**)&view);
|
|
|
|
|
|
|
|
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
|
|
|
//
|
|
|
|
|
2000-08-30 23:42:47 +04:00
|
|
|
result = view->GetParent(view);
|
2000-03-22 02:58:02 +03:00
|
|
|
|
2000-08-30 23:42:47 +04:00
|
|
|
if (NS_FAILED(result))
|
|
|
|
return result;
|
|
|
|
|
|
|
|
while (view)
|
2000-03-22 02:58:02 +03:00
|
|
|
{
|
2000-08-30 23:42:47 +04:00
|
|
|
result = GetClosestScrollableView(view, &scrollableView);
|
2000-03-22 02:58:02 +03:00
|
|
|
|
|
|
|
if (NS_FAILED(result))
|
2000-08-30 23:42:47 +04:00
|
|
|
return result;
|
|
|
|
|
|
|
|
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.
|
|
|
|
//
|
|
|
|
|
|
|
|
view = 0;
|
|
|
|
result = scrollableView->QueryInterface(NS_GET_IID(nsIView), (void**)&view);
|
|
|
|
|
|
|
|
if (NS_FAILED(result))
|
|
|
|
return result;
|
|
|
|
|
|
|
|
if (view)
|
|
|
|
view->GetParent(view);
|
2000-03-22 02:58:02 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2000-08-30 23:42:47 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
2000-11-29 03:13:00 +03:00
|
|
|
nsTypedSelection::DoAutoScrollView(nsIPresContext *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);
|
|
|
|
|
|
|
|
if (NS_FAILED(result))
|
|
|
|
return result;
|
|
|
|
|
|
|
|
//
|
|
|
|
// 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);
|
|
|
|
|
|
|
|
if (NS_FAILED(result))
|
|
|
|
return result;
|
|
|
|
|
|
|
|
//
|
|
|
|
// Start the AutoScroll timer if neccessary.
|
|
|
|
//
|
|
|
|
|
|
|
|
if (didScroll && mAutoScrollTimer)
|
|
|
|
{
|
|
|
|
//
|
|
|
|
// Map the globalPoint back into aView's coordinate system. We
|
|
|
|
// have to get the globalOffsets again because aView's
|
|
|
|
// window and it's parents may have changed their offsets.
|
|
|
|
//
|
|
|
|
result = GetViewAncestorOffset(aView, nsnull, &globalOffset.x, &globalOffset.y);
|
|
|
|
|
|
|
|
if (NS_FAILED(result))
|
|
|
|
return result;
|
|
|
|
|
|
|
|
nsPoint svPoint = globalPoint - globalOffset;
|
|
|
|
|
|
|
|
result = mAutoScrollTimer->Start(aPresContext, aView, svPoint);
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
2000-11-29 03:13:00 +03:00
|
|
|
nsTypedSelection::DoAutoScroll(nsIPresContext *aPresContext, nsIFrame *aFrame, nsPoint& aPoint)
|
2000-08-30 23:42:47 +04:00
|
|
|
{
|
|
|
|
nsresult result;
|
|
|
|
|
|
|
|
if (!aPresContext || !aFrame)
|
|
|
|
return NS_ERROR_NULL_POINTER;
|
|
|
|
|
|
|
|
//
|
|
|
|
// Find the closest view to the frame!
|
|
|
|
//
|
|
|
|
|
|
|
|
nsIView *closestView = 0;
|
|
|
|
|
|
|
|
result = aFrame->GetView(aPresContext, &closestView);
|
|
|
|
|
|
|
|
if (NS_FAILED(result))
|
|
|
|
return result;
|
|
|
|
|
|
|
|
if (!closestView)
|
|
|
|
{
|
|
|
|
//
|
|
|
|
// aFrame doesn't contain a view, so walk aFrame's parent hierarchy
|
|
|
|
// till you find a parent with a view.
|
|
|
|
//
|
|
|
|
|
|
|
|
nsIFrame *parentFrame = aFrame;
|
|
|
|
|
|
|
|
result = aFrame->GetParent(&parentFrame);
|
|
|
|
|
|
|
|
if (NS_FAILED(result))
|
|
|
|
return result;
|
|
|
|
|
|
|
|
if (!parentFrame)
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
|
|
|
|
while (!closestView && parentFrame)
|
|
|
|
{
|
|
|
|
result = parentFrame->GetView(aPresContext, &closestView);
|
|
|
|
|
|
|
|
if (NS_FAILED(result))
|
|
|
|
return result;
|
|
|
|
|
|
|
|
if (!closestView)
|
|
|
|
result = parentFrame->GetParent(&parentFrame);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!closestView)
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
|
|
|
return DoAutoScrollView(aPresContext, closestView, aPoint, PR_TRUE);
|
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);
|
|
|
|
if ( iterator && !NS_SUCCEEDED(status = CallQueryInterface(iterator, aIterator)) )
|
|
|
|
delete iterator;
|
|
|
|
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
|
2000-03-22 02:58:02 +03:00
|
|
|
nsCOMPtr<nsIPresContext> presContext;
|
|
|
|
GetPresContext(getter_AddRefs(presContext));
|
|
|
|
|
2000-06-03 03:05:06 +04:00
|
|
|
|
2000-03-22 02:58:02 +03:00
|
|
|
nsresult result = Clear(presContext);
|
|
|
|
if (NS_FAILED(result))
|
|
|
|
return result;
|
2000-06-03 03:05:06 +04:00
|
|
|
|
|
|
|
// Turn off signal for table selection
|
|
|
|
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!
|
|
|
|
// PresShell::ContentChanged should do that on DocumentChanged
|
|
|
|
}
|
|
|
|
|
|
|
|
/** 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
|
|
|
|
// and returns NS_ERROR_FAILURE if range doesn't contain just one table cell
|
|
|
|
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
|
|
|
|
2000-03-22 02:58:02 +03:00
|
|
|
nsCOMPtr<nsIPresContext> presContext;
|
|
|
|
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
|
|
|
}
|
|
|
|
|
|
|
|
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;
|
2000-04-28 17:58:08 +04:00
|
|
|
RemoveItem(aRange);
|
2000-03-22 02:58:02 +03:00
|
|
|
|
|
|
|
nsCOMPtr<nsIPresContext> presContext;
|
|
|
|
GetPresContext(getter_AddRefs(presContext));
|
|
|
|
selectFrames(presContext, aRange, PR_FALSE);
|
|
|
|
if (aRange == mAnchorFocusRange.get())
|
|
|
|
{
|
|
|
|
PRUint32 cnt;
|
|
|
|
nsresult rv = mRangeArray->Count(&cnt);
|
|
|
|
if (NS_SUCCEEDED(rv) && cnt > 0 )
|
|
|
|
{
|
|
|
|
setAnchorFocusRange(cnt -1);//reset anchor to LAST range.
|
|
|
|
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
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* 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;
|
|
|
|
|
|
|
|
nsresult result;
|
|
|
|
// Delete all of the current ranges
|
|
|
|
if (NS_FAILED(SetOriginalAnchorPoint(aParentNode,aOffset)))
|
|
|
|
return NS_ERROR_FAILURE; //???
|
|
|
|
nsCOMPtr<nsIPresContext> presContext;
|
|
|
|
GetPresContext(getter_AddRefs(presContext));
|
|
|
|
Clear(presContext);
|
|
|
|
|
2000-06-03 03:05:06 +04:00
|
|
|
// Turn off signal for table selection
|
|
|
|
if (mFrameSelection)
|
|
|
|
mFrameSelection->ClearTableCellSelection();
|
|
|
|
|
2000-03-22 02:58:02 +03:00
|
|
|
nsCOMPtr<nsIDOMRange> range;
|
|
|
|
NS_NewRange(getter_AddRefs(range));
|
|
|
|
if (! range){
|
|
|
|
NS_ASSERTION(PR_FALSE,"Couldn't make a range - nsSelection::Collapse");
|
|
|
|
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;
|
2000-12-21 01:13:54 +03:00
|
|
|
nsCOMPtr<nsIAtom> tag;
|
|
|
|
content->GetTag(*getter_AddRefs(tag));
|
2000-03-22 02:58:02 +03:00
|
|
|
if (tag)
|
|
|
|
{
|
2000-08-23 21:27:06 +04:00
|
|
|
nsAutoString tagString;
|
2000-03-22 02:58:02 +03:00
|
|
|
tag->ToString(tagString);
|
|
|
|
char * tagCString = tagString.ToNewCString();
|
2000-10-29 02:17:53 +04:00
|
|
|
printf ("Sel. Collapse to %p %s %d\n", content, tagCString, aOffset);
|
2000-03-22 02:58:02 +03:00
|
|
|
delete [] tagCString;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
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)
|
|
|
|
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
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* 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);
|
|
|
|
if (NS_FAILED(rv) || cnt<=0 || !mRangeArray)
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
|
2000-12-21 01:13:54 +03:00
|
|
|
// Get the first range
|
|
|
|
nsCOMPtr<nsISupports> element = dont_AddRef(mRangeArray->ElementAt(0));
|
2000-03-22 02:58:02 +03:00
|
|
|
nsCOMPtr<nsIDOMRange> firstRange = do_QueryInterface(element);
|
|
|
|
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);
|
|
|
|
if (NS_FAILED(rv) || cnt<=0 || !mRangeArray)
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
|
2000-12-21 01:13:54 +03:00
|
|
|
// Get the last range
|
|
|
|
nsCOMPtr<nsISupports> element = dont_AddRef(mRangeArray->ElementAt(cnt-1));
|
2000-03-22 02:58:02 +03:00
|
|
|
nsCOMPtr<nsIDOMRange> lastRange = do_QueryInterface(element);
|
|
|
|
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
|
|
|
{
|
|
|
|
if (!aIsCollapsed)
|
|
|
|
return NS_ERROR_NULL_POINTER;
|
|
|
|
|
|
|
|
PRUint32 cnt = 0;
|
|
|
|
if (mRangeArray) {
|
|
|
|
nsresult rv = mRangeArray->Count(&cnt);
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
}
|
|
|
|
if (!mRangeArray || (cnt == 0))
|
|
|
|
{
|
|
|
|
*aIsCollapsed = PR_TRUE;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (cnt != 1)
|
|
|
|
{
|
|
|
|
*aIsCollapsed = PR_FALSE;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsCOMPtr<nsISupports> nsisup(dont_AddRef(mRangeArray->ElementAt(0)));
|
|
|
|
nsCOMPtr<nsIDOMRange> range;
|
|
|
|
nsresult rv;
|
|
|
|
range = do_QueryInterface(nsisup,&rv);
|
|
|
|
if (NS_FAILED(rv))
|
|
|
|
{
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
2000-08-24 07:54:30 +04:00
|
|
|
return (range->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)
|
|
|
|
return NS_ERROR_NULL_POINTER;
|
|
|
|
|
|
|
|
if (mRangeArray)
|
|
|
|
{
|
|
|
|
PRUint32 cnt;
|
|
|
|
nsresult rv = mRangeArray->Count(&cnt);
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
*aRangeCount = cnt;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
*aRangeCount = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2000-11-29 03:13:00 +03:00
|
|
|
nsTypedSelection::GetRangeAt(PRInt32 aIndex, nsIDOMRange** aReturn)
|
2000-03-22 02:58:02 +03:00
|
|
|
{
|
|
|
|
if (!aReturn)
|
|
|
|
return NS_ERROR_NULL_POINTER;
|
|
|
|
|
|
|
|
if (!mRangeArray)
|
|
|
|
return NS_ERROR_INVALID_ARG;
|
|
|
|
|
|
|
|
PRUint32 cnt;
|
|
|
|
nsresult rv = mRangeArray->Count(&cnt);
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
if (aIndex < 0 || ((PRUint32)aIndex) >= cnt)
|
|
|
|
return NS_ERROR_INVALID_ARG;
|
|
|
|
|
|
|
|
// the result of all this is one additional ref on the item, as
|
|
|
|
// the caller would expect.
|
|
|
|
//
|
|
|
|
// ElementAt addrefs once
|
|
|
|
// do_QueryInterface addrefs once
|
|
|
|
// when the COMPtr goes out of scope, it releases.
|
|
|
|
//
|
|
|
|
nsISupports* element = mRangeArray->ElementAt((PRUint32)aIndex);
|
|
|
|
nsCOMPtr<nsIDOMRange> foundRange = do_QueryInterface(element);
|
|
|
|
*aReturn = foundRange;
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
#if OLD_SELECTION
|
|
|
|
|
|
|
|
//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"
|
|
|
|
nsCOMPtr<nsIAtom> atom;
|
|
|
|
atom = GetTag(endNode);
|
|
|
|
if (atom.get() == nsSelection::sTbodyAtom)
|
|
|
|
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);
|
|
|
|
if (atom.get() == nsSelection::sTableAtom) //select whole table if in cell mode, wait for cell
|
|
|
|
{
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
else if (atom.get() == nsSelection::sCellAtom) //you are in "cell" mode put selection to end of cell
|
|
|
|
{
|
|
|
|
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);
|
|
|
|
if (atom.get() == nsSelection::sTableAtom) //select whole table if in cell mode, wait for cell
|
|
|
|
{
|
|
|
|
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
|
|
|
|
found = PR_FALSE; //didnt find the right cell yet
|
|
|
|
}
|
|
|
|
else if (atom.get() == nsSelection::sCellAtom) //you are in "cell" mode put selection to end of cell
|
|
|
|
{
|
|
|
|
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:
|
|
|
|
if (!mRangeArray || !mAnchorFocusRange)
|
|
|
|
return NS_ERROR_NOT_INITIALIZED;
|
|
|
|
//mFrameSelection->InvalidateDesiredX();
|
|
|
|
nsCOMPtr<nsIDOMRange> difRange;
|
|
|
|
nsresult res;
|
|
|
|
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;
|
|
|
|
PRInt32 result1 = ComparePoints(FetchAnchorNode(), FetchAnchorOffset()
|
|
|
|
,FetchFocusNode(), FetchFocusOffset());
|
|
|
|
//compare old cursor to new cursor
|
|
|
|
PRInt32 result2 = ComparePoints(FetchFocusNode(), FetchFocusOffset(),
|
|
|
|
aParentNode, aOffset );
|
|
|
|
//compare anchor to new cursor
|
|
|
|
PRInt32 result3 = ComparePoints(FetchAnchorNode(), FetchAnchorOffset(),
|
|
|
|
aParentNode , aOffset );
|
|
|
|
|
|
|
|
if (result2 == 0) //not selecting anywhere
|
|
|
|
return NS_OK;
|
|
|
|
|
|
|
|
nsCOMPtr<nsIPresContext> presContext;
|
|
|
|
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;
|
|
|
|
#if OLD_SELECTION
|
|
|
|
res = FixupSelectionPoints(range, &dir, &fixupState);
|
|
|
|
#endif
|
|
|
|
if (NS_FAILED(res))
|
|
|
|
return res;
|
|
|
|
if (fixupState)
|
|
|
|
{
|
|
|
|
#if OLD_SELECTION
|
|
|
|
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;
|
|
|
|
#if OLD_SELECTION
|
|
|
|
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;
|
|
|
|
#if OLD_SELECTION
|
|
|
|
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
|
|
|
|
{
|
|
|
|
#if OLD_SELECTION
|
|
|
|
selectFrames(mAnchorFocusRange, PR_FALSE);
|
|
|
|
selectFrames(range, PR_TRUE);
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
res = CopyRangeToAnchorFocus(range);
|
|
|
|
if (NS_FAILED(res))
|
|
|
|
return res;
|
|
|
|
selectFrames(presContext, difRange, 0);//deselect now if fixup succeeded
|
|
|
|
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;
|
|
|
|
#if OLD_SELECTION
|
|
|
|
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
|
|
|
|
selectFrames(presContext, difRange , PR_FALSE);
|
|
|
|
}
|
|
|
|
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;
|
|
|
|
|
|
|
|
#if OLD_SELECTION
|
|
|
|
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
|
|
|
|
{
|
|
|
|
#if OLD_SELECTION
|
|
|
|
selectFrames(mAnchorFocusRange, PR_FALSE);
|
|
|
|
selectFrames(range, PR_TRUE);
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
res = CopyRangeToAnchorFocus(range);
|
|
|
|
if (NS_FAILED(res))
|
|
|
|
return res;
|
|
|
|
selectFrames(presContext, difRange , PR_FALSE);
|
|
|
|
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;
|
|
|
|
#if OLD_SELECTION
|
|
|
|
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;
|
|
|
|
selectFrames(presContext, difRange, 0);
|
|
|
|
}
|
|
|
|
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;
|
|
|
|
|
|
|
|
#if OLD_SELECTION
|
|
|
|
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
|
|
|
|
{
|
|
|
|
#if OLD_SELECTION
|
|
|
|
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);
|
2000-12-21 01:13:54 +03:00
|
|
|
nsCOMPtr<nsIAtom> tag;
|
|
|
|
content->GetTag(*getter_AddRefs(tag));
|
2000-03-22 02:58:02 +03:00
|
|
|
if (tag)
|
|
|
|
{
|
2000-08-23 21:27:06 +04:00
|
|
|
nsAutoString tagString;
|
2000-03-22 02:58:02 +03:00
|
|
|
tag->ToString(tagString);
|
|
|
|
char * tagCString = tagString.ToNewCString();
|
2000-10-29 02:17:53 +04:00
|
|
|
printf ("Sel. Extend to %p %s %d\n", content, tagCString, aOffset);
|
2000-03-22 02:58:02 +03:00
|
|
|
delete [] tagCString;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2000-09-13 00:54:41 +04:00
|
|
|
static inline nsresult GetChildOffset(nsIDOMNode *aChild, nsIDOMNode *aParent, PRInt32 &aOffset)
|
|
|
|
{
|
|
|
|
NS_ASSERTION((aChild && aParent), "bad args");
|
|
|
|
if (!aChild || !aParent) return NS_ERROR_NULL_POINTER;
|
|
|
|
nsCOMPtr<nsIContent> content = do_QueryInterface(aParent);
|
|
|
|
nsCOMPtr<nsIContent> cChild = do_QueryInterface(aChild);
|
|
|
|
if (!cChild || !content) return NS_ERROR_NULL_POINTER;
|
|
|
|
nsresult res = content->IndexOf(cChild, aOffset);
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
|
|
|
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
|
2000-11-29 03:13:00 +03:00
|
|
|
nsTypedSelection::ContainsNode(nsIDOMNode* aNode, PRBool aRecursive, PRBool* aYes)
|
2000-03-22 02:58:02 +03:00
|
|
|
{
|
|
|
|
if (!aYes)
|
|
|
|
return NS_ERROR_NULL_POINTER;
|
|
|
|
*aYes = PR_FALSE;
|
|
|
|
|
|
|
|
// Iterate over the ranges in the selection checking for the content:
|
|
|
|
if (!mRangeArray)
|
|
|
|
return NS_OK;
|
|
|
|
|
|
|
|
PRUint32 cnt;
|
|
|
|
nsresult rv = mRangeArray->Count(&cnt);
|
|
|
|
if (NS_FAILED(rv))
|
|
|
|
return rv;
|
|
|
|
for (PRUint32 i=0; i < cnt; ++i)
|
|
|
|
{
|
2000-05-01 04:26:37 +04:00
|
|
|
nsCOMPtr<nsISupports> element = dont_AddRef(mRangeArray->ElementAt(i));
|
2000-08-29 09:43:03 +04:00
|
|
|
nsCOMPtr<nsIDOMRange> range = do_QueryInterface(element);
|
2000-03-22 02:58:02 +03:00
|
|
|
if (!range)
|
|
|
|
return NS_ERROR_UNEXPECTED;
|
2000-08-29 10:37:12 +04:00
|
|
|
|
2000-03-22 02:58:02 +03:00
|
|
|
nsCOMPtr<nsIContent> content (do_QueryInterface(aNode));
|
|
|
|
if (content)
|
|
|
|
{
|
2000-08-29 23:55:16 +04:00
|
|
|
if (IsNodeIntersectsRange(content, range))
|
2000-03-22 02:58:02 +03:00
|
|
|
{
|
|
|
|
// If recursive, then we're done -- IsNodeIntersectsRange does the right thing
|
|
|
|
if (aRecursive)
|
|
|
|
{
|
|
|
|
*aYes = PR_TRUE;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
// else not recursive -- node itself must be contained,
|
|
|
|
// so we need to do more checking
|
|
|
|
PRBool nodeStartsBeforeRange, nodeEndsAfterRange;
|
2000-08-29 23:55:16 +04:00
|
|
|
if (NS_SUCCEEDED(CompareNodeToRange(content, range,
|
2000-03-22 02:58:02 +03:00
|
|
|
&nodeStartsBeforeRange,
|
|
|
|
&nodeEndsAfterRange)))
|
|
|
|
{
|
|
|
|
#ifdef DEBUG_ContainsNode
|
|
|
|
nsAutoString name, value;
|
|
|
|
aNode->GetNodeName(name);
|
|
|
|
aNode->GetNodeValue(value);
|
2000-10-29 02:17:53 +04:00
|
|
|
printf("%s [%s]: %d, %d\n", name.ToNewCString(), value.ToNewCString(),
|
2000-03-22 02:58:02 +03:00
|
|
|
nodeStartsBeforeRange, nodeEndsAfterRange);
|
|
|
|
#endif
|
|
|
|
PRUint16 nodeType;
|
|
|
|
aNode->GetNodeType(&nodeType);
|
|
|
|
if ((!nodeStartsBeforeRange && !nodeEndsAfterRange)
|
|
|
|
|| (nodeType == nsIDOMNode::TEXT_NODE))
|
|
|
|
{
|
|
|
|
*aYes = PR_TRUE;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2000-08-29 03:35:57 +04:00
|
|
|
|
2000-03-22 02:58:02 +03:00
|
|
|
nsresult
|
2000-11-29 03:13:00 +03:00
|
|
|
nsTypedSelection::GetPresContext(nsIPresContext **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
|
2000-03-22 02:58:02 +03:00
|
|
|
nsIFocusTracker *tracker = mFrameSelection->GetTracker();
|
|
|
|
|
|
|
|
if (!tracker)
|
|
|
|
return NS_ERROR_NULL_POINTER;
|
|
|
|
|
|
|
|
return tracker->GetPresContext(aPresContext);
|
|
|
|
}
|
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
nsIFocusTracker *tracker = mFrameSelection->GetTracker();
|
|
|
|
|
|
|
|
if (!tracker)
|
|
|
|
return NS_ERROR_NULL_POINTER;
|
|
|
|
|
|
|
|
nsCOMPtr<nsIPresContext> presContext;
|
|
|
|
|
|
|
|
rv = tracker->GetPresContext(getter_AddRefs(presContext));
|
|
|
|
|
|
|
|
if (NS_FAILED(rv))
|
|
|
|
return rv;
|
|
|
|
|
|
|
|
if (!presContext)
|
|
|
|
return NS_ERROR_NULL_POINTER;
|
|
|
|
|
2000-05-13 12:07:34 +04:00
|
|
|
nsCOMPtr<nsIPresShell> shell;
|
|
|
|
rv = presContext->GetShell(getter_AddRefs(shell));
|
|
|
|
mPresShellWeak = getter_AddRefs(NS_GetWeakReference(shell)); // the presshell owns us, so no addref
|
|
|
|
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
|
2000-03-22 02:58:02 +03:00
|
|
|
nsresult rv = NS_OK;
|
2000-05-13 12:07:34 +04:00
|
|
|
nsIScrollableView *scrollView = mFrameSelection->GetScrollView();
|
|
|
|
if (!scrollView)
|
|
|
|
{
|
2000-03-22 02:58:02 +03:00
|
|
|
|
2000-05-13 12:07:34 +04:00
|
|
|
nsCOMPtr<nsIPresShell> presShell;
|
2000-03-22 02:58:02 +03:00
|
|
|
|
2000-05-13 12:07:34 +04:00
|
|
|
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
|
|
|
|
2000-05-13 12:07:34 +04:00
|
|
|
nsCOMPtr<nsIViewManager> viewManager;
|
2000-03-22 02:58:02 +03:00
|
|
|
|
2000-05-13 12:07:34 +04:00
|
|
|
rv = presShell->GetViewManager(getter_AddRefs(viewManager));
|
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 (!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);
|
|
|
|
}
|
|
|
|
else //SCROLLVIEW_FROM_FRAME
|
|
|
|
{
|
|
|
|
*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);
|
2000-03-22 02:58:02 +03:00
|
|
|
nsIFocusTracker *tracker = mFrameSelection->GetTracker();
|
|
|
|
|
|
|
|
if (!tracker)
|
|
|
|
return NS_ERROR_NULL_POINTER;
|
|
|
|
|
|
|
|
nsCOMPtr<nsIPresContext> presContext;
|
|
|
|
tracker->GetPresContext(getter_AddRefs(presContext));
|
|
|
|
aFrame->GetOffsetFromView(presContext, offset, &closestView);
|
|
|
|
|
|
|
|
// XXX Deal with the case where there is a scrolled element, e.g., a
|
|
|
|
// DIV in the middle...
|
|
|
|
while ((closestView != nsnull) && (closestView != scrolledView)) {
|
|
|
|
nscoord dx, dy;
|
|
|
|
|
|
|
|
// Update the offset
|
|
|
|
closestView->GetPosition(&dx, &dy);
|
|
|
|
offset.MoveBy(dx, dy);
|
|
|
|
|
|
|
|
// Get its parent view
|
|
|
|
closestView->GetParent(closestView);
|
|
|
|
}
|
|
|
|
|
|
|
|
*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.
|
|
|
|
//
|
|
|
|
|
|
|
|
nsIFocusTracker *tracker = mFrameSelection->GetTracker();
|
|
|
|
|
|
|
|
if (!tracker)
|
|
|
|
return NS_ERROR_NULL_POINTER;
|
|
|
|
|
|
|
|
nsCOMPtr<nsIPresContext> presContext;
|
|
|
|
|
|
|
|
rv = tracker->GetPresContext(getter_AddRefs(presContext));
|
|
|
|
|
|
|
|
if (NS_FAILED(rv))
|
|
|
|
return rv;
|
|
|
|
|
|
|
|
if (!presContext)
|
|
|
|
return NS_ERROR_NULL_POINTER;
|
|
|
|
|
|
|
|
nsCOMPtr<nsIDeviceContext> deviceContext;
|
|
|
|
|
|
|
|
rv = presContext->GetDeviceContext(getter_AddRefs(deviceContext));
|
|
|
|
|
|
|
|
if (NS_FAILED(rv))
|
|
|
|
return rv;
|
|
|
|
|
|
|
|
if (!deviceContext)
|
|
|
|
return NS_ERROR_NULL_POINTER;
|
|
|
|
|
|
|
|
//
|
|
|
|
// Now get the closest view with a widget so we can create
|
|
|
|
// a rendering context.
|
|
|
|
//
|
|
|
|
|
|
|
|
nsCOMPtr<nsIWidget> widget;
|
|
|
|
nsIView *closestView = 0;
|
|
|
|
nsPoint offset(0, 0);
|
|
|
|
|
|
|
|
rv = aFrame->GetOffsetFromView(presContext, offset, &closestView);
|
|
|
|
|
|
|
|
while (!widget && closestView)
|
|
|
|
{
|
|
|
|
rv = closestView->GetWidget(*getter_AddRefs(widget));
|
|
|
|
|
|
|
|
if (NS_FAILED(rv))
|
|
|
|
return rv;
|
|
|
|
|
|
|
|
if (!widget)
|
|
|
|
{
|
|
|
|
rv = closestView->GetParent(closestView);
|
|
|
|
|
|
|
|
if (NS_FAILED(rv))
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
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.
|
|
|
|
//
|
|
|
|
|
|
|
|
nsCOMPtr<nsIRenderingContext> rendContext;
|
|
|
|
|
|
|
|
rv = deviceContext->CreateRenderingContext(closestView, *getter_AddRefs(rendContext));
|
|
|
|
|
|
|
|
if (NS_FAILED(rv))
|
|
|
|
return rv;
|
|
|
|
|
|
|
|
if (!rendContext)
|
|
|
|
return NS_ERROR_NULL_POINTER;
|
|
|
|
|
|
|
|
//
|
|
|
|
// Now get the point and return!
|
|
|
|
//
|
|
|
|
|
|
|
|
rv = aFrame->GetPointFromOffset(presContext, rendContext, aContentOffset, aPoint);
|
|
|
|
|
|
|
|
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
|
|
|
{
|
|
|
|
nsresult result = 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 (!aRect || !aScrollableView)
|
2000-03-22 02:58:02 +03:00
|
|
|
return NS_ERROR_NULL_POINTER;
|
|
|
|
|
|
|
|
// Init aRect:
|
|
|
|
|
|
|
|
aRect->x = 0;
|
|
|
|
aRect->y = 0;
|
|
|
|
aRect->width = 0;
|
|
|
|
aRect->height = 0;
|
|
|
|
|
2000-08-30 23:42:47 +04:00
|
|
|
*aScrollableView = 0;
|
|
|
|
|
2000-03-22 02:58:02 +03:00
|
|
|
nsIDOMNode *node = 0;
|
|
|
|
PRInt32 nodeOffset = 0;
|
|
|
|
PRBool isEndNode = PR_TRUE;
|
|
|
|
nsIFrame *frame = 0;
|
|
|
|
|
|
|
|
switch (aRegion)
|
|
|
|
{
|
2000-04-27 11:37:12 +04:00
|
|
|
case nsISelectionController::SELECTION_ANCHOR_REGION:
|
2000-03-22 02:58:02 +03:00
|
|
|
node = FetchAnchorNode();
|
|
|
|
nodeOffset = FetchAnchorOffset();
|
|
|
|
isEndNode = GetDirection() == eDirPrevious;
|
|
|
|
break;
|
2000-04-27 11:37:12 +04:00
|
|
|
case nsISelectionController::SELECTION_FOCUS_REGION:
|
2000-03-22 02:58:02 +03:00
|
|
|
node = FetchFocusNode();
|
|
|
|
nodeOffset = FetchFocusOffset();
|
|
|
|
isEndNode = GetDirection() == eDirNext;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!node)
|
|
|
|
return NS_ERROR_NULL_POINTER;
|
|
|
|
|
|
|
|
nsCOMPtr<nsIContent> content = do_QueryInterface(node);
|
|
|
|
PRInt32 frameOffset = 0;
|
|
|
|
|
|
|
|
if (content)
|
2000-06-28 08:00:12 +04:00
|
|
|
{
|
|
|
|
nsIFrameSelection::HINT hint;
|
|
|
|
mFrameSelection->GetHint(&hint);
|
|
|
|
result = mFrameSelection->GetFrameForNodeOffset(content, nodeOffset, hint, &frame, &frameOffset);
|
|
|
|
}
|
2000-03-22 02:58:02 +03:00
|
|
|
else
|
|
|
|
result = NS_ERROR_FAILURE;
|
2000-08-30 23:42:47 +04:00
|
|
|
|
2000-03-22 02:58:02 +03:00
|
|
|
if(NS_FAILED(result))
|
|
|
|
return result;
|
|
|
|
|
|
|
|
if (!frame)
|
|
|
|
return NS_ERROR_NULL_POINTER;
|
|
|
|
|
2000-08-30 23:42:47 +04:00
|
|
|
//
|
|
|
|
// Get the frame's scrollable view.
|
|
|
|
//
|
|
|
|
|
|
|
|
nsCOMPtr<nsIPresContext> presContext;
|
|
|
|
|
|
|
|
result = GetPresContext(getter_AddRefs(presContext));
|
|
|
|
|
|
|
|
if (NS_FAILED(result))
|
|
|
|
return result;
|
|
|
|
|
|
|
|
if (!presContext)
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
|
|
|
|
|
|
|
|
nsIView *view = 0;
|
|
|
|
nsIFrame *parentWithView = 0;
|
|
|
|
|
|
|
|
result = frame->GetParentWithView(presContext, &parentWithView);
|
|
|
|
|
|
|
|
if (NS_FAILED(result))
|
|
|
|
return result;
|
|
|
|
|
|
|
|
if (!parentWithView)
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
|
|
|
|
result = parentWithView->GetView(presContext, &view);
|
|
|
|
|
|
|
|
if (NS_FAILED(result))
|
|
|
|
return result;
|
|
|
|
|
|
|
|
if (!view)
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
|
|
|
|
result = GetClosestScrollableView(view, aScrollableView);
|
|
|
|
|
|
|
|
if (NS_FAILED(result))
|
|
|
|
return result;
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
|
|
|
result = node->GetNodeType(&nodeType);
|
|
|
|
|
|
|
|
if (NS_FAILED(result))
|
|
|
|
return NS_ERROR_NULL_POINTER;
|
|
|
|
|
|
|
|
if (nodeType == nsIDOMNode::TEXT_NODE)
|
|
|
|
{
|
|
|
|
nsIFrame *childFrame = 0;
|
|
|
|
frameOffset = 0;
|
|
|
|
|
|
|
|
result = frame->GetChildFrameContainingOffset(nodeOffset, mFrameSelection->mHint, &frameOffset, &childFrame);
|
|
|
|
|
|
|
|
if (NS_FAILED(result))
|
|
|
|
return result;
|
|
|
|
|
|
|
|
if (!childFrame)
|
|
|
|
return NS_ERROR_NULL_POINTER;
|
|
|
|
|
|
|
|
frame = childFrame;
|
|
|
|
|
|
|
|
//
|
|
|
|
// Get the x coordinate of the offset into the text frame.
|
|
|
|
// The x coordinate will be relative to the frame's origin,
|
|
|
|
// so we'll have to translate it into the root view's coordinate
|
|
|
|
// system.
|
|
|
|
//
|
|
|
|
nsPoint pt;
|
|
|
|
|
|
|
|
result = GetPointFromOffset(frame, nodeOffset, &pt);
|
|
|
|
|
|
|
|
if (NS_FAILED(result))
|
|
|
|
return result;
|
|
|
|
|
|
|
|
//
|
|
|
|
// Get the frame's rect.
|
|
|
|
//
|
|
|
|
result = frame->GetRect(*aRect);
|
|
|
|
|
|
|
|
if (NS_FAILED(result))
|
|
|
|
return result;
|
|
|
|
|
|
|
|
//
|
|
|
|
// Translate the frame's rect into root view coordinates.
|
|
|
|
//
|
2000-08-30 23:42:47 +04:00
|
|
|
result = GetFrameToScrolledViewOffsets(*aScrollableView, frame, &aRect->x, &aRect->y);
|
2000-03-22 02:58:02 +03:00
|
|
|
|
|
|
|
if (NS_FAILED(result))
|
|
|
|
return result;
|
|
|
|
|
|
|
|
//
|
|
|
|
// Now add the offset's x coordinate.
|
|
|
|
//
|
|
|
|
aRect->x += pt.x;
|
|
|
|
|
|
|
|
//
|
|
|
|
// Adjust the width of the rect to account for any neccessary
|
|
|
|
// padding!
|
|
|
|
//
|
|
|
|
|
|
|
|
const nsIView* clipView = 0;
|
|
|
|
nsRect clipRect;
|
|
|
|
|
2000-08-30 23:42:47 +04:00
|
|
|
result = (*aScrollableView)->GetScrollPosition(clipRect.x, clipRect.y);
|
2000-03-22 02:58:02 +03:00
|
|
|
|
|
|
|
if (NS_FAILED(result))
|
|
|
|
return result;
|
|
|
|
|
2000-08-30 23:42:47 +04:00
|
|
|
result = (*aScrollableView)->GetClipView(&clipView);
|
2000-03-22 02:58:02 +03:00
|
|
|
|
|
|
|
if (NS_FAILED(result))
|
|
|
|
return result;
|
|
|
|
|
|
|
|
result = clipView->GetDimensions(&clipRect.width, &clipRect.height);
|
|
|
|
|
|
|
|
if (NS_FAILED(result))
|
|
|
|
return result;
|
|
|
|
|
|
|
|
// If the point we are interested is outside the clip
|
|
|
|
// region, we will scroll it into view with a padding
|
|
|
|
// equal to a quarter of the clip's width.
|
|
|
|
|
|
|
|
PRInt32 pad = clipRect.width >> 2;
|
|
|
|
|
|
|
|
if (pad <= 0)
|
|
|
|
pad = 3; // Arbitrary
|
|
|
|
|
|
|
|
if (aRect->x >= clipRect.XMost())
|
|
|
|
aRect->width = pad;
|
|
|
|
else if (aRect->x <= clipRect.x)
|
|
|
|
{
|
|
|
|
aRect->x -= pad;
|
|
|
|
aRect->width = pad;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
aRect->width = 60; // Arbitrary
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
//
|
|
|
|
// Must be a non-text frame, just scroll the frame
|
|
|
|
// into view.
|
|
|
|
//
|
|
|
|
result = frame->GetRect(*aRect);
|
|
|
|
|
|
|
|
if (NS_FAILED(result))
|
|
|
|
return result;
|
|
|
|
|
2000-08-30 23:42:47 +04:00
|
|
|
result = GetFrameToScrolledViewOffsets(*aScrollableView, frame, &aRect->x, &aRect->y);
|
2000-03-22 02:58:02 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
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
|
|
|
|
const nsIView* clipView;
|
|
|
|
nsRect visibleRect;
|
|
|
|
|
2000-08-30 23:42:47 +04:00
|
|
|
aScrollableView->GetScrollPosition(visibleRect.x, visibleRect.y);
|
|
|
|
aScrollableView->GetClipView(&clipView);
|
2000-03-22 02:58:02 +03:00
|
|
|
clipView->GetDimensions(&visibleRect.width, &visibleRect.height);
|
|
|
|
|
|
|
|
// The actual scroll offsets
|
|
|
|
nscoord scrollOffsetX = visibleRect.x;
|
|
|
|
nscoord scrollOffsetY = visibleRect.y;
|
|
|
|
|
|
|
|
// See how aRect should be positioned vertically
|
|
|
|
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
|
|
|
|
scrollOffsetY = aRect.y;
|
|
|
|
} 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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
// Align the aRect edge according to the specified percentage
|
|
|
|
nscoord frameAlignY = aRect.y + (aRect.height * aVPercent) / 100;
|
|
|
|
scrollOffsetY = frameAlignY - (visibleRect.height * aVPercent) / 100;
|
|
|
|
}
|
|
|
|
|
|
|
|
// See how the aRect should be positioned horizontally
|
|
|
|
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
|
|
|
|
scrollOffsetX = aRect.x;
|
|
|
|
} 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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
} 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-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!
|
|
|
|
//
|
|
|
|
|
|
|
|
nsIView *view = 0;
|
|
|
|
|
|
|
|
rv = aScrollableView->QueryInterface(NS_GET_IID(nsIView), (void **)&view);
|
|
|
|
|
|
|
|
if (NS_FAILED(rv))
|
|
|
|
return rv;
|
|
|
|
|
|
|
|
if (!view)
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
|
|
|
|
rv = view->GetParent(view);
|
|
|
|
|
|
|
|
if (NS_FAILED(rv))
|
|
|
|
return rv;
|
|
|
|
|
|
|
|
if (view)
|
|
|
|
{
|
|
|
|
nsIScrollableView *parentSV = 0;
|
|
|
|
|
|
|
|
rv = GetClosestScrollableView(view, &parentSV);
|
|
|
|
|
|
|
|
if (NS_FAILED(rv))
|
|
|
|
return rv;
|
|
|
|
|
|
|
|
if (parentSV)
|
|
|
|
{
|
|
|
|
//
|
|
|
|
// We have a parent scrollable view, so now map aRect
|
|
|
|
// into it's scrolled view's coordinate space.
|
|
|
|
//
|
|
|
|
|
|
|
|
nsRect newRect;
|
|
|
|
|
|
|
|
rv = parentSV->GetScrolledView(view);
|
|
|
|
|
|
|
|
if (NS_FAILED(rv))
|
|
|
|
return rv;
|
|
|
|
|
|
|
|
if (!view)
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
|
|
|
|
rv = GetViewAncestorOffset(scrolledView, view, &newRect.x, &newRect.y);
|
|
|
|
|
|
|
|
if (NS_FAILED(rv))
|
|
|
|
return rv;
|
|
|
|
|
|
|
|
newRect.x += aRect.x;
|
|
|
|
newRect.y += aRect.y;
|
|
|
|
newRect.width = aRect.width;
|
|
|
|
newRect.height = aRect.height;
|
|
|
|
|
|
|
|
//
|
|
|
|
// 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;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2000-11-29 03:13:00 +03:00
|
|
|
nsTypedSelection::ScrollIntoView(SelectionRegion aRegion)
|
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;
|
|
|
|
|
|
|
|
//
|
|
|
|
// Shut the caret off before scrolling to avoid
|
|
|
|
// leaving caret turds on the screen!
|
|
|
|
//
|
|
|
|
nsCOMPtr<nsIPresShell> presShell;
|
|
|
|
result = GetPresShell(getter_AddRefs(presShell));
|
|
|
|
if (NS_FAILED(result))
|
|
|
|
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
|
|
|
{
|
2000-06-01 06:37:40 +04:00
|
|
|
StCaretHider caretHider(caret); // stack-based class hides and shows the caret
|
2000-03-22 02:58:02 +03:00
|
|
|
|
2000-04-27 11:37:12 +04:00
|
|
|
//
|
|
|
|
// Scroll the selection region into view.
|
|
|
|
//
|
2000-08-30 23:42:47 +04:00
|
|
|
|
2000-04-27 11:37:12 +04:00
|
|
|
nsRect rect;
|
2000-08-30 23:42:47 +04:00
|
|
|
nsIScrollableView *scrollableView = 0;
|
|
|
|
|
|
|
|
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.
|
|
|
|
//
|
|
|
|
if (!scrollableView)
|
|
|
|
return NS_OK;
|
|
|
|
|
|
|
|
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 (!mSelectionListeners)
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
if (!aNewListener)
|
|
|
|
return NS_ERROR_NULL_POINTER;
|
|
|
|
nsresult result;
|
|
|
|
nsCOMPtr<nsISupports> isupports = do_QueryInterface(aNewListener , &result);
|
|
|
|
if (NS_SUCCEEDED(result))
|
|
|
|
result = mSelectionListeners->AppendElement(isupports) ? NS_OK : NS_ERROR_FAILURE; // addrefs
|
|
|
|
return result;
|
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 (!mSelectionListeners)
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
if (!aListenerToRemove )
|
|
|
|
return NS_ERROR_NULL_POINTER;
|
|
|
|
nsCOMPtr<nsISupports> isupports = do_QueryInterface(aListenerToRemove);
|
|
|
|
return mSelectionListeners->RemoveElement(isupports) ? 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
|
|
|
{
|
|
|
|
if (!mSelectionListeners)
|
|
|
|
return NS_ERROR_FAILURE;
|
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;
|
|
|
|
}
|
|
|
|
PRUint32 cnt;
|
|
|
|
nsresult rv = mSelectionListeners->Count(&cnt);
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
|
|
|
|
nsCOMPtr<nsIDOMDocument> domdoc;
|
|
|
|
nsCOMPtr<nsIDocument> doc;
|
|
|
|
nsCOMPtr<nsIPresShell> shell;
|
|
|
|
rv = GetPresShell(getter_AddRefs(shell));
|
|
|
|
if (NS_SUCCEEDED(rv) && shell)
|
|
|
|
{
|
|
|
|
rv = shell->GetDocument(getter_AddRefs(doc));
|
|
|
|
if (NS_FAILED(rv))
|
|
|
|
doc = 0;
|
|
|
|
domdoc = do_QueryInterface(doc);
|
|
|
|
}
|
2000-06-09 09:14:19 +04:00
|
|
|
short reason = mFrameSelection->PopReason();
|
2000-05-04 12:35:42 +04:00
|
|
|
for (PRUint32 i = 0; i < cnt;i++)
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsISupports> isupports(dont_AddRef(mSelectionListeners->ElementAt(i)));
|
2000-09-14 15:45:01 +04:00
|
|
|
nsCOMPtr<nsISelectionListener> thisListener = do_QueryInterface(isupports);
|
2000-05-04 12:35:42 +04:00
|
|
|
if (thisListener)
|
2000-06-09 09:14:19 +04:00
|
|
|
thisListener->NotifySelectionChanged(domdoc,this, reason);
|
2000-05-04 12:35:42 +04:00
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|
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
|
|
|
{
|
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->StartBatchChanges();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2000-11-29 03:13:00 +03:00
|
|
|
nsTypedSelection::EndBatchChanges()
|
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->EndBatchChanges();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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();
|
|
|
|
}
|
|
|
|
|
2000-11-29 03:13:00 +03:00
|
|
|
|
|
|
|
static const char* kAllAccess = "AllAccess";
|
|
|
|
static const char* kNoAccess = "NoAccess";
|
|
|
|
|
|
|
|
/* string canCreateWrapper (in nsIIDPtr iid); */
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsTypedSelection::CanCreateWrapper(const nsIID * iid, char **_retval)
|
|
|
|
{
|
|
|
|
if (iid->Equals(NS_GET_IID(nsISelection))) {
|
|
|
|
*_retval = nsCRT::strdup(kAllAccess);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
*_retval = nsCRT::strdup(kNoAccess);
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* string canCallMethod (in nsIIDPtr iid, in wstring methodName); */
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsTypedSelection::CanCallMethod(const nsIID * iid, const PRUnichar *methodName, char **_retval)
|
|
|
|
{
|
|
|
|
if (iid->Equals(NS_GET_IID(nsISelection))) {
|
|
|
|
*_retval = nsCRT::strdup(kAllAccess);
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* string canGetProperty (in nsIIDPtr iid, in wstring propertyName); */
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsTypedSelection::CanGetProperty(const nsIID * iid, const PRUnichar *propertyName, char **_retval)
|
|
|
|
{
|
|
|
|
if (iid->Equals(NS_GET_IID(nsISelection))) {
|
|
|
|
*_retval = nsCRT::strdup(kAllAccess);
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* string canSetProperty (in nsIIDPtr iid, in wstring propertyName); */
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsTypedSelection::CanSetProperty(const nsIID * iid, const PRUnichar *propertyName, char **_retval)
|
|
|
|
{
|
|
|
|
if (iid->Equals(NS_GET_IID(nsISelection))) {
|
|
|
|
*_retval = nsCRT::strdup(kAllAccess);
|
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|