From 2a9e445535bc964d37509ef5553c7709d25d15c4 Mon Sep 17 00:00:00 2001 From: "mjudge%netscape.com" Date: Wed, 10 Feb 1999 18:55:25 +0000 Subject: [PATCH] Keyboard navigation, removing nsICollection(not used) adding PeekOffset to have the nsIFrame tell us where to go when moving a character ect. adding nsFrameTraversal to traverse frames, based on nsIEnumerator. mjudge x4661 git-svn-id: svn://10.0.0.236/trunk@20274 18797224-902f-48f8-a5cc-f745e15eee43 --- mozilla/content/base/public/nsIDocument.h | 3 +- mozilla/content/base/src/nsDocument.cpp | 4 +- mozilla/content/base/src/nsDocument.h | 5 +- .../content/base/src/nsGenericDOMDataNode.cpp | 1 - mozilla/layout/base/nsPresShell.cpp | 7 +- mozilla/layout/base/public/makefile.win | 4 +- mozilla/layout/base/public/nsIDocument.h | 3 +- mozilla/layout/base/public/nsIFrame.h | 15 +- mozilla/layout/base/src/nsDocument.cpp | 4 +- mozilla/layout/base/src/nsDocument.h | 5 +- .../layout/base/src/nsGenericDOMDataNode.cpp | 1 - mozilla/layout/base/src/nsRangeList.cpp | 53 ++-- mozilla/layout/build/nsLayoutFactory.cpp | 10 +- mozilla/layout/generic/nsFrame.cpp | 34 ++- mozilla/layout/generic/nsFrame.h | 3 +- mozilla/layout/generic/nsIFrame.h | 15 +- mozilla/layout/generic/nsTextFrame.cpp | 81 +++-- mozilla/layout/html/base/src/Makefile.in | 1 + mozilla/layout/html/base/src/makefile.win | 2 + mozilla/layout/html/base/src/nsFrame.cpp | 34 ++- mozilla/layout/html/base/src/nsFrame.h | 3 +- .../layout/html/base/src/nsFrameTraversal.cpp | 287 ++++++++++++++++++ .../layout/html/base/src/nsFrameTraversal.h | 11 + mozilla/layout/html/base/src/nsPresShell.cpp | 7 +- mozilla/layout/html/base/src/nsTextFrame.cpp | 81 +++-- mozilla/layout/macbuild/layout.mcp | Bin 121105 -> 128801 bytes 26 files changed, 530 insertions(+), 144 deletions(-) create mode 100644 mozilla/layout/html/base/src/nsFrameTraversal.cpp create mode 100644 mozilla/layout/html/base/src/nsFrameTraversal.h diff --git a/mozilla/content/base/public/nsIDocument.h b/mozilla/content/base/public/nsIDocument.h index abb08618f89..9b1019d72f9 100644 --- a/mozilla/content/base/public/nsIDocument.h +++ b/mozilla/content/base/public/nsIDocument.h @@ -30,7 +30,6 @@ class nsIDocumentContainer; class nsIDocumentObserver; class nsIPresContext; class nsIPresShell; -class nsICollection; class nsIStreamListener; class nsIStreamObserver; @@ -224,7 +223,7 @@ public: /** * Returns the Selection Object */ - NS_IMETHOD GetSelection(nsICollection ** aSelection) = 0; + NS_IMETHOD GetSelection(nsISelection ** aSelection) = 0; /** * Selects all the Content */ diff --git a/mozilla/content/base/src/nsDocument.cpp b/mozilla/content/base/src/nsDocument.cpp index 703628c6791..2123b06beaf 100644 --- a/mozilla/content/base/src/nsDocument.cpp +++ b/mozilla/content/base/src/nsDocument.cpp @@ -65,7 +65,6 @@ #include "nsLayoutCID.h" #include "nsISelection.h" #include "nsIDOMRange.h" -#include "nsICollection.h" #include "nsIEnumerator.h" static NS_DEFINE_IID(kIDOMTextIID, NS_IDOMTEXT_IID); @@ -91,7 +90,6 @@ static NS_DEFINE_IID(kICSSStyleSheetIID, NS_ICSS_STYLE_SHEET_IID); static NS_DEFINE_IID(kCRangeCID, NS_RANGE_CID); static NS_DEFINE_IID(kIDOMRange, NS_IDOMRANGE_IID); static NS_DEFINE_IID(kCRangeListCID, NS_RANGELIST_CID); -static NS_DEFINE_IID(kICollectionIID, NS_ICOLLECTION_IID); static NS_DEFINE_IID(kIEnumeratorIID, NS_IENUMERATOR_IID); static NS_DEFINE_IID(kIDOMScriptObjectFactoryIID, NS_IDOM_SCRIPT_OBJECT_FACTORY_IID); static NS_DEFINE_IID(kDOMScriptObjectFactoryCID, NS_DOM_SCRIPT_OBJECT_FACTORY_CID); @@ -1901,7 +1899,7 @@ void nsDocument::Finalize(JSContext *aContext) /** * Returns the Selection Object */ -NS_IMETHODIMP nsDocument::GetSelection(nsICollection ** aSelection) { +NS_IMETHODIMP nsDocument::GetSelection(nsISelection ** aSelection) { if (!aSelection) return NS_ERROR_NULL_POINTER; return NS_ERROR_FAILURE; diff --git a/mozilla/content/base/src/nsDocument.h b/mozilla/content/base/src/nsDocument.h index 64e2fabd5cc..2b67cba0d33 100644 --- a/mozilla/content/base/src/nsDocument.h +++ b/mozilla/content/base/src/nsDocument.h @@ -29,9 +29,10 @@ #include "nsIJSScriptObject.h" #include "nsIContent.h" -class nsICollection; class nsIEventListenerManager; class nsDOMStyleSheetCollection; +class nsISelection; + class nsPostData : public nsIPostData { public: @@ -229,7 +230,7 @@ public: /** * Returns the Selection Object */ - NS_IMETHOD GetSelection(nsICollection ** aSelection); + NS_IMETHOD GetSelection(nsISelection ** aSelection); /** * Selects all the Content */ diff --git a/mozilla/content/base/src/nsGenericDOMDataNode.cpp b/mozilla/content/base/src/nsGenericDOMDataNode.cpp index 9c9f47d4d02..491ada2669c 100644 --- a/mozilla/content/base/src/nsGenericDOMDataNode.cpp +++ b/mozilla/content/base/src/nsGenericDOMDataNode.cpp @@ -29,7 +29,6 @@ #include "nsRange.h" #include "nsISelection.h" -#include "nsICollection.h" #include "nsIEnumerator.h" diff --git a/mozilla/layout/base/nsPresShell.cpp b/mozilla/layout/base/nsPresShell.cpp index b2f6dad6cae..2af9c820316 100644 --- a/mozilla/layout/base/nsPresShell.cpp +++ b/mozilla/layout/base/nsPresShell.cpp @@ -41,7 +41,6 @@ #include "nsDOMEvent.h" #include "nsHTMLParts.h" #include "nsISelection.h" -#include "nsICollection.h" #include "nsLayoutCID.h" #include "nsIDOMRange.h" #include "nsIDOMDocument.h" @@ -160,7 +159,6 @@ static NS_DEFINE_IID(kIPresShellIID, NS_IPRESSHELL_IID); static NS_DEFINE_IID(kIDocumentObserverIID, NS_IDOCUMENT_OBSERVER_IID); static NS_DEFINE_IID(kIViewObserverIID, NS_IVIEWOBSERVER_IID); static NS_DEFINE_IID(kISelectionIID, NS_ISELECTION_IID); -static NS_DEFINE_IID(kICollectionIID, NS_ICOLLECTION_IID); static NS_DEFINE_IID(kIDOMNodeIID, NS_IDOMNODE_IID); static NS_DEFINE_IID(kIDOMRangeIID, NS_IDOMRANGE_IID); static NS_DEFINE_IID(kIDOMDocumentIID, NS_IDOMDOCUMENT_IID); @@ -490,11 +488,10 @@ PresShell::Init(nsIDocument* aDocument, mStyleSet = aStyleSet; NS_ADDREF(aStyleSet); - nsCOMPtrselection; - nsresult result = nsRepository::CreateInstance(kRangeListCID, nsnull, kICollectionIID, getter_AddRefs(selection)); + nsCOMPtrselection; + nsresult result = nsRepository::CreateInstance(kRangeListCID, nsnull, kISelectionIID, getter_AddRefs(selection)); if (!NS_SUCCEEDED(result)) return result; - selection->Clear();//clear all old selection // XXX This code causes the document object (and the entire content model) to be leaked... #if 0 nsCOMPtrrange; diff --git a/mozilla/layout/base/public/makefile.win b/mozilla/layout/base/public/makefile.win index 0bbbe773f7a..dcdeba5c3eb 100644 --- a/mozilla/layout/base/public/makefile.win +++ b/mozilla/layout/base/public/makefile.win @@ -42,12 +42,12 @@ EXPORTS = \ nsIStyleRule.h \ nsIStyleSet.h \ nsIStyleSheet.h \ - nsITextContent.h \ + nsITextContent.h \ nsLayoutAtoms.h \ nsStyleConsts.h \ nsStyleCoord.h \ nsStyleStruct.h \ - nsTextFragment.h \ + nsTextFragment.h \ $(NULL) MODULE=raptor diff --git a/mozilla/layout/base/public/nsIDocument.h b/mozilla/layout/base/public/nsIDocument.h index abb08618f89..9b1019d72f9 100644 --- a/mozilla/layout/base/public/nsIDocument.h +++ b/mozilla/layout/base/public/nsIDocument.h @@ -30,7 +30,6 @@ class nsIDocumentContainer; class nsIDocumentObserver; class nsIPresContext; class nsIPresShell; -class nsICollection; class nsIStreamListener; class nsIStreamObserver; @@ -224,7 +223,7 @@ public: /** * Returns the Selection Object */ - NS_IMETHOD GetSelection(nsICollection ** aSelection) = 0; + NS_IMETHOD GetSelection(nsISelection ** aSelection) = 0; /** * Selects all the Content */ diff --git a/mozilla/layout/base/public/nsIFrame.h b/mozilla/layout/base/public/nsIFrame.h index 535dc0c0ba1..1a75c5018ba 100644 --- a/mozilla/layout/base/public/nsIFrame.h +++ b/mozilla/layout/base/public/nsIFrame.h @@ -125,14 +125,15 @@ enum nsFramePaintLayer { }; enum nsSelectionAmount { - eCharacter = 0, - eWord = 1, - eLine = 2 //previous drawn line in flow. + eSelectCharacter = 0, + eSelectWord = 1, + eSelectLine = 2, //previous drawn line in flow. + eSelectNoAmount = 3 //just bounce back current offset. }; enum nsDirection { - eNext = 0, - ePrevious= 1 + eDirNext = 0, + eDirPrevious= 1 }; //---------------------------------------------------------------------- @@ -566,11 +567,13 @@ public: * return NS_ERROR_FAILURE * @param aAmount eWord, eCharacter, eLine * @param aDirection enum defined in this file to be eForward or eBackward + * @param aStartOffset start offset to start the peek. 0 == beginning -1 = end * @param aResultFrame frame that actually is the next/previous * @param aFrameOffset offset from frame of the frame results * @param aContentOffset offset from content of the frame results */ - NS_IMETHOD PeekOffset(nsSelectionAmount aAmount, nsDirection aDirection, nsIFrame **aResultFrame, PRInt32 *aFrameOffset, PRInt32 *aContentOffset) = 0; + NS_IMETHOD PeekOffset(nsSelectionAmount aAmount, nsDirection aDirection, PRInt32 aStartOffset, + nsIFrame **aResultFrame, PRInt32 *aFrameOffset, PRInt32 *aContentOffset) = 0; /** * See if tree verification is enabled. To enable tree verification add diff --git a/mozilla/layout/base/src/nsDocument.cpp b/mozilla/layout/base/src/nsDocument.cpp index 703628c6791..2123b06beaf 100644 --- a/mozilla/layout/base/src/nsDocument.cpp +++ b/mozilla/layout/base/src/nsDocument.cpp @@ -65,7 +65,6 @@ #include "nsLayoutCID.h" #include "nsISelection.h" #include "nsIDOMRange.h" -#include "nsICollection.h" #include "nsIEnumerator.h" static NS_DEFINE_IID(kIDOMTextIID, NS_IDOMTEXT_IID); @@ -91,7 +90,6 @@ static NS_DEFINE_IID(kICSSStyleSheetIID, NS_ICSS_STYLE_SHEET_IID); static NS_DEFINE_IID(kCRangeCID, NS_RANGE_CID); static NS_DEFINE_IID(kIDOMRange, NS_IDOMRANGE_IID); static NS_DEFINE_IID(kCRangeListCID, NS_RANGELIST_CID); -static NS_DEFINE_IID(kICollectionIID, NS_ICOLLECTION_IID); static NS_DEFINE_IID(kIEnumeratorIID, NS_IENUMERATOR_IID); static NS_DEFINE_IID(kIDOMScriptObjectFactoryIID, NS_IDOM_SCRIPT_OBJECT_FACTORY_IID); static NS_DEFINE_IID(kDOMScriptObjectFactoryCID, NS_DOM_SCRIPT_OBJECT_FACTORY_CID); @@ -1901,7 +1899,7 @@ void nsDocument::Finalize(JSContext *aContext) /** * Returns the Selection Object */ -NS_IMETHODIMP nsDocument::GetSelection(nsICollection ** aSelection) { +NS_IMETHODIMP nsDocument::GetSelection(nsISelection ** aSelection) { if (!aSelection) return NS_ERROR_NULL_POINTER; return NS_ERROR_FAILURE; diff --git a/mozilla/layout/base/src/nsDocument.h b/mozilla/layout/base/src/nsDocument.h index 64e2fabd5cc..2b67cba0d33 100644 --- a/mozilla/layout/base/src/nsDocument.h +++ b/mozilla/layout/base/src/nsDocument.h @@ -29,9 +29,10 @@ #include "nsIJSScriptObject.h" #include "nsIContent.h" -class nsICollection; class nsIEventListenerManager; class nsDOMStyleSheetCollection; +class nsISelection; + class nsPostData : public nsIPostData { public: @@ -229,7 +230,7 @@ public: /** * Returns the Selection Object */ - NS_IMETHOD GetSelection(nsICollection ** aSelection); + NS_IMETHOD GetSelection(nsISelection ** aSelection); /** * Selects all the Content */ diff --git a/mozilla/layout/base/src/nsGenericDOMDataNode.cpp b/mozilla/layout/base/src/nsGenericDOMDataNode.cpp index 9c9f47d4d02..491ada2669c 100644 --- a/mozilla/layout/base/src/nsGenericDOMDataNode.cpp +++ b/mozilla/layout/base/src/nsGenericDOMDataNode.cpp @@ -29,7 +29,6 @@ #include "nsRange.h" #include "nsISelection.h" -#include "nsICollection.h" #include "nsIEnumerator.h" diff --git a/mozilla/layout/base/src/nsRangeList.cpp b/mozilla/layout/base/src/nsRangeList.cpp index 78a493fe2e3..ad45c6495df 100644 --- a/mozilla/layout/base/src/nsRangeList.cpp +++ b/mozilla/layout/base/src/nsRangeList.cpp @@ -20,7 +20,6 @@ * nsIRangeList: the implementation of selection. */ -#include "nsICollection.h" #include "nsIFactory.h" #include "nsIEnumerator.h" #include "nsIDOMRange.h" @@ -38,7 +37,6 @@ static NS_DEFINE_IID(kIEnumeratorIID, NS_IENUMERATOR_IID); -static NS_DEFINE_IID(kICollectionIID, NS_ICOLLECTION_IID); static NS_DEFINE_IID(kISupportsIID, NS_ISUPPORTS_IID); static NS_DEFINE_IID(kISelectionIID, NS_ISELECTION_IID); static NS_DEFINE_IID(kIDOMSelectionIID, NS_IDOMSELECTION_IID); @@ -64,22 +62,13 @@ enum {FORWARD =1, BACKWARD = 0}; class nsRangeListIterator; -class nsRangeList : public nsICollection , public nsISelection, +class nsRangeList : public nsISelection, public nsIDOMSelection { public: -/*BEGIN nsICollection interfaces -see the nsICollection for more details*/ - /*interfaces for addref and release and queryinterface*/ NS_DECL_ISUPPORTS - virtual nsresult AddItem(nsISupports *aRange); - - virtual nsresult RemoveItem(nsISupports *aRange); - - virtual nsresult Clear(); -/*END nsICollection interfaces*/ /*BEGIN nsISelection interfaces*/ NS_IMETHOD HandleKeyEvent(nsIFocusTracker *aTracker, nsGUIEvent *aGuiEvent, nsIFrame *aFrame); @@ -102,6 +91,11 @@ see the nsICollection for more details*/ virtual ~nsRangeList(); private: + nsresult AddItem(nsISupports *aRange); + + nsresult RemoveItem(nsISupports *aRange); + + nsresult Clear(); friend class nsRangeListIterator; #ifdef DEBUG @@ -159,13 +153,13 @@ private: -nsresult NS_NewRangeList(nsICollection **); -nsresult NS_NewRangeList(nsICollection **aRangeList) +nsresult NS_NewRangeList(nsISelection **); +nsresult NS_NewRangeList(nsISelection **aRangeList) { nsRangeList *rlist = new nsRangeList; if (!rlist) return NS_ERROR_OUT_OF_MEMORY; - nsresult result = rlist->QueryInterface(kICollectionIID , (void **)aRangeList); + nsresult result = rlist->QueryInterface(kISelectionIID , (void **)aRangeList); if (!NS_SUCCEEDED(result)) { delete rlist; @@ -300,14 +294,12 @@ nsRangeListIterator::QueryInterface(REFNSIID aIID, void** aInstancePtr) return NS_ERROR_NULL_POINTER; } if (aIID.Equals(kISupportsIID)) { - nsICollection* tmp = mRangeList; - nsISupports* tmp2 = tmp; - - *aInstancePtr = (void*)tmp2; + nsISelection* tmp = mRangeList; + *aInstancePtr = (void*)tmp; NS_ADDREF(mRangeList); return NS_OK; } - if (aIID.Equals(kICollectionIID)) { + if (aIID.Equals(kISelectionIID)) { *aInstancePtr = (void *)mRangeList; NS_ADDREF(mRangeList); return NS_OK; @@ -348,7 +340,6 @@ nsRangeList::~nsRangeList() //END nsRangeList methods -//BEGIN nsICollection interface implementations NS_IMPL_ADDREF(nsRangeList) @@ -363,14 +354,8 @@ nsRangeList::QueryInterface(REFNSIID aIID, void** aInstancePtr) return NS_ERROR_NULL_POINTER; } if (aIID.Equals(kISupportsIID)) { - nsICollection* tmp = this; - nsISupports* tmp2 = tmp; - *aInstancePtr = (void*)tmp2; - NS_ADDREF_THIS(); - return NS_OK; - } - if (aIID.Equals(kICollectionIID)) { - *aInstancePtr = (void*)(nsICollection *)this; + nsISupports* tmp = (nsISupports *)(nsISelection *)this; + *aInstancePtr = (void*)tmp; NS_ADDREF_THIS(); return NS_OK; } @@ -475,7 +460,6 @@ nsRangeList::Clear() -//END nsICollection methods //BEGIN nsISelection methods @@ -535,14 +519,14 @@ nsRangeList::HandleKeyEvent(nsIFocusTracker *aTracker, nsGUIEvent *aGuiEvent, ns case nsIDOMEvent::VK_LEFT : //we need to look for the previous PAINTED location to move the cursor to. printf("debug vk left\n"); - if (NS_SUCCEEDED(aFrame->PeekOffset(eCharacter, ePrevious, &resultFrame, &frameOffset, &contentOffset)) && resultFrame){ + if (NS_SUCCEEDED(aFrame->PeekOffset(eSelectCharacter, eDirPrevious, endoffset, &resultFrame, &frameOffset, &contentOffset)) && resultFrame){ return TakeFocus(aTracker, resultFrame, frameOffset, contentOffset, PR_FALSE); } break; case nsIDOMEvent::VK_RIGHT : //we need to look for the next PAINTED location to move the cursor to. printf("debug vk right\n"); - if (NS_SUCCEEDED(aFrame->PeekOffset(eCharacter, eNext, &resultFrame, &frameOffset, &contentOffset)) && resultFrame){ + if (NS_SUCCEEDED(aFrame->PeekOffset(eSelectCharacter, eDirNext, endoffset, &resultFrame, &frameOffset, &contentOffset)) && resultFrame){ return TakeFocus(aTracker, resultFrame, frameOffset, contentOffset, PR_FALSE); } default :break; @@ -586,6 +570,7 @@ void nsRangeList::printSelection() #endif /* DEBUG */ + //recursive-oid method to get next frame nsIFrame * getNextFrame(nsIFrame *aStart) @@ -609,6 +594,8 @@ getNextFrame(nsIFrame *aStart) return nsnull; } + + //compare the 2 passed in frames -1 first is smaller 1 second is smaller 0 they are the same PRInt32 compareFrames(nsIFrame *aBegin, nsIFrame *aEnd) @@ -871,6 +858,8 @@ findFrameFromContent(nsIFrame *aParent, nsIContent *aContent, PRBool aTurnOff) return result; } + + //the start frame is the "root" of the tree. we need to traverse the tree to look for the content we want NS_IMETHODIMP nsRangeList::ResetSelection(nsIFocusTracker *aTracker, nsIFrame *aStartFrame) diff --git a/mozilla/layout/build/nsLayoutFactory.cpp b/mozilla/layout/build/nsLayoutFactory.cpp index da364017d5b..20155728d4f 100644 --- a/mozilla/layout/build/nsLayoutFactory.cpp +++ b/mozilla/layout/build/nsLayoutFactory.cpp @@ -23,7 +23,6 @@ #include "nsIDocument.h" #include "nsIHTMLContent.h" #include "nsITextContent.h" -#include "nsICollection.h" #include "nsIPresShell.h" #include "nsISelection.h" #include "nsIFrameUtil.h" @@ -34,7 +33,6 @@ #include "nsIServiceManager.h" #include "nsICSSParser.h" #include "nsIHTMLStyleSheet.h" -#include "nsICollection.h" #include "nsIDOMRange.h" #include "nsINameSpaceManager.h" #include "nsIScriptNameSetRegistry.h" @@ -59,8 +57,8 @@ static NS_DEFINE_CID(kRangeCID, NS_RANGE_CID); static NS_DEFINE_CID(kEventListenerManagerCID, NS_EVENTLISTENERMANAGER_CID); -nsresult NS_NewRangeList(nsICollection **); -nsresult NS_NewRange(nsIDOMRange **); +extern nsresult NS_NewRangeList(nsISelection **); +extern nsresult NS_NewRange(nsIDOMRange **); extern nsresult NS_NewFrameUtil(nsIFrameUtil** aResult); @@ -198,8 +196,8 @@ nsresult nsLayoutFactory::CreateInstance(nsISupports *aOuter, refCounted = PR_TRUE; } else if (mClassID.Equals(kCRangeListCID)) { - nsICollection *coll; - res = NS_NewRangeList((nsICollection **)&coll); + nsISelection *coll; + res = NS_NewRangeList(&coll); if (!NS_SUCCEEDED(res)) { return res; } diff --git a/mozilla/layout/generic/nsFrame.cpp b/mozilla/layout/generic/nsFrame.cpp index 9c467c04b09..4ea05d42f9f 100644 --- a/mozilla/layout/generic/nsFrame.cpp +++ b/mozilla/layout/generic/nsFrame.cpp @@ -46,6 +46,10 @@ #include "nsHTMLParts.h" #include "nsLayoutAtoms.h" +#include "nsFrameTraversal.h" +#include "nsCOMPtr.h" + + // Some Misc #defines #define SELECTION_DEBUG 0 #define FORCE_SELECTION_UPDATE 1 @@ -1850,11 +1854,33 @@ nsFrame::GetSelected(PRBool *aSelected, PRInt32 *aBeginOffset, PRInt32 *aEndOffs NS_IMETHODIMP -nsFrame::PeekOffset(nsSelectionAmount aAmount, nsDirection aDirection, nsIFrame **aResultFrame, - PRInt32 *aFrameOffset, PRInt32 *aContentOffset) +nsFrame::PeekOffset(nsSelectionAmount aAmount, nsDirection aDirection, PRInt32 aStartOffset, + nsIFrame **aResultFrame, PRInt32 *aFrameOffset, PRInt32 *aContentOffset) { - //default, no matter what grab next/ previous sibling. - return NS_ERROR_FAILURE; + //this will use the nsFrameTraversal as the default peek method. + //this should change to use geometry and also look to ALL the child lists + nsCOMPtr frameTraversal; + nsresult result = NS_NewFrameTraversal(getter_AddRefs(frameTraversal),LEAF,this); + if (NS_FAILED(result)) + return result; + nsISupports *isupports; + if (aDirection == eDirNext) + result = frameTraversal->Next(); + else + result = frameTraversal->Prev(); + + if (NS_FAILED(result)) + return result; + result = frameTraversal->CurrentItem(&isupports); + if (NS_FAILED(result)) + return result; + if (!isupports) + return NS_ERROR_NULL_POINTER; + //we must CAST here to an nsIFrame. nsIFrame doesnt really follow the rules + //for speed reasons + nsIFrame *newFrame = (nsIFrame *)isupports; + return newFrame->PeekOffset(aAmount, aDirection, aStartOffset, aResultFrame, + aFrameOffset, aContentOffset); } //----------------------------------------------------------------------------------- diff --git a/mozilla/layout/generic/nsFrame.h b/mozilla/layout/generic/nsFrame.h index 158c2e2a641..be6dbfbb03d 100644 --- a/mozilla/layout/generic/nsFrame.h +++ b/mozilla/layout/generic/nsFrame.h @@ -208,7 +208,8 @@ public: nsIFocusTracker *aTracker, nsIFrame **aActualSelected); NS_IMETHOD GetSelected(PRBool *aSelected, PRInt32 *aBeginOffset, PRInt32 *aEndOffset, PRInt32 *aBeginContentOffset); - NS_IMETHODIMP PeekOffset(nsSelectionAmount aAmount, nsDirection aDirection, nsIFrame **aResultFrame, PRInt32 *aFrameOffset, PRInt32 *aContentOffset); + NS_IMETHOD PeekOffset(nsSelectionAmount aAmount, nsDirection aDirection, PRInt32 aStartOffset, + nsIFrame **aResultFrame, PRInt32 *aFrameOffset, PRInt32 *aContentOffset); NS_IMETHOD GetOffsets(PRInt32 &aStart, PRInt32 &aEnd) const; // nsIHTMLReflow diff --git a/mozilla/layout/generic/nsIFrame.h b/mozilla/layout/generic/nsIFrame.h index 535dc0c0ba1..1a75c5018ba 100644 --- a/mozilla/layout/generic/nsIFrame.h +++ b/mozilla/layout/generic/nsIFrame.h @@ -125,14 +125,15 @@ enum nsFramePaintLayer { }; enum nsSelectionAmount { - eCharacter = 0, - eWord = 1, - eLine = 2 //previous drawn line in flow. + eSelectCharacter = 0, + eSelectWord = 1, + eSelectLine = 2, //previous drawn line in flow. + eSelectNoAmount = 3 //just bounce back current offset. }; enum nsDirection { - eNext = 0, - ePrevious= 1 + eDirNext = 0, + eDirPrevious= 1 }; //---------------------------------------------------------------------- @@ -566,11 +567,13 @@ public: * return NS_ERROR_FAILURE * @param aAmount eWord, eCharacter, eLine * @param aDirection enum defined in this file to be eForward or eBackward + * @param aStartOffset start offset to start the peek. 0 == beginning -1 = end * @param aResultFrame frame that actually is the next/previous * @param aFrameOffset offset from frame of the frame results * @param aContentOffset offset from content of the frame results */ - NS_IMETHOD PeekOffset(nsSelectionAmount aAmount, nsDirection aDirection, nsIFrame **aResultFrame, PRInt32 *aFrameOffset, PRInt32 *aContentOffset) = 0; + NS_IMETHOD PeekOffset(nsSelectionAmount aAmount, nsDirection aDirection, PRInt32 aStartOffset, + nsIFrame **aResultFrame, PRInt32 *aFrameOffset, PRInt32 *aContentOffset) = 0; /** * See if tree verification is enabled. To enable tree verification add diff --git a/mozilla/layout/generic/nsTextFrame.cpp b/mozilla/layout/generic/nsTextFrame.cpp index b792d07f51b..dfcc97e123b 100644 --- a/mozilla/layout/generic/nsTextFrame.cpp +++ b/mozilla/layout/generic/nsTextFrame.cpp @@ -129,8 +129,8 @@ public: nsIFocusTracker *aTracker, nsIFrame **aActualSelected); NS_IMETHOD GetSelected(PRBool *aSelected, PRInt32 *aBeginOffset, PRInt32 *aEndOffset, PRInt32 *aBeginContentOffset); - NS_IMETHOD PeekOffset(nsSelectionAmount aAmount, nsDirection aDirection, nsIFrame **aResultFrame, - PRInt32 *aFrameOffset, PRInt32 *aContentOffset); + NS_IMETHOD PeekOffset(nsSelectionAmount aAmount, nsDirection aDirection, PRInt32 aStartOffset, + nsIFrame **aResultFrame, PRInt32 *aFrameOffset, PRInt32 *aContentOffset); NS_IMETHOD GetOffsets(PRInt32 &start, PRInt32 &end)const; @@ -231,8 +231,7 @@ public: } }; - PRIntn PrepareUnicodeText(nsIRenderingContext& aRenderingContext, - nsTextTransformer& aTransformer, + PRIntn PrepareUnicodeText(nsTextTransformer& aTransformer, PRInt32* aIndicies, PRUnichar* aBuffer, PRInt32& aTextLen, @@ -559,8 +558,7 @@ TextFrame::Paint(nsIPresContext& aPresContext, * the prepared output. */ PRIntn -TextFrame::PrepareUnicodeText(nsIRenderingContext& aRenderingContext, - nsTextTransformer& aTX, +TextFrame::PrepareUnicodeText(nsTextTransformer& aTX, PRInt32* aIndexes, PRUnichar* aBuffer, PRInt32& aTextLen, @@ -799,7 +797,7 @@ TextFrame::PaintUnicodeText(nsIPresContext& aPresContext, // Transform text from content into renderable form nsTextTransformer tx(wordBufMem, WORD_BUF_SIZE); - PrepareUnicodeText(aRenderingContext, tx, + PrepareUnicodeText(tx, displaySelection ? ip : nsnull, paintBuf, textLength, width); ip[mContentLength] = ip[mContentLength-1]+1; //must set up last one for selection beyond edge @@ -1131,7 +1129,7 @@ TextFrame::PaintTextSlowly(nsIPresContext& aPresContext, // Transform text from content into renderable form nsTextTransformer tx(wordBufMem, WORD_BUF_SIZE); - aTextStyle.mNumSpaces = PrepareUnicodeText(aRenderingContext, tx, + aTextStyle.mNumSpaces = PrepareUnicodeText(tx, displaySelection ? ip : nsnull, paintBuf, textLength, width); if (mRect.width > mComputedWidth) { @@ -1258,7 +1256,7 @@ TextFrame::PaintAsciiText(nsIPresContext& aPresContext, // Transform text from content into renderable form nsTextTransformer tx(wordBufMem, WORD_BUF_SIZE); - PrepareUnicodeText(aRenderingContext, tx, + PrepareUnicodeText(tx, displaySelection ? ip : nsnull, rawPaintBuf, textLength, width); ip[mContentLength] = ip[mContentLength-1]+1; //must set up last one for selection beyond edge @@ -1469,7 +1467,7 @@ TextFrame::GetPosition(nsIPresContext& aCX, // Get the renderable form of the text nsTextTransformer tx(wordBufMem, WORD_BUF_SIZE); - PrepareUnicodeText(*aRendContext, tx, + PrepareUnicodeText(tx, ip, paintBuf, textLength, width); ip[mContentLength] = ip[mContentLength-1]+1; @@ -1533,7 +1531,6 @@ NS_IMETHODIMP TextFrame::SetSelected(PRBool aSelected, PRInt32 aBeginOffset, PRInt32 aEndOffset, PRBool aForceRedraw) { if (aSelected){ -printf("SetSelected selection = %d, /t %x /t begin: %d end: %d\n",aSelected, this,aBeginOffset, aEndOffset); aEndOffset = PR_MIN(aEndOffset,mContentLength); aBeginOffset = PR_MIN(aBeginOffset,mContentLength); @@ -1632,12 +1629,14 @@ TextFrame::GetSelected(PRBool *aSelected, PRInt32 *aBeginOffset, PRInt32 *aEndOf NS_IMETHODIMP -TextFrame::PeekOffset(nsSelectionAmount aAmount, nsDirection aDirection, nsIFrame **aResultFrame, +TextFrame::PeekOffset(nsSelectionAmount aAmount, nsDirection aDirection, PRInt32 aStartOffset, nsIFrame **aResultFrame, PRInt32 *aFrameOffset, PRInt32 *aContentOffset) { //default, no matter what grab next/ previous sibling. if (!aResultFrame || !aFrameOffset || !aContentOffset) return NS_ERROR_NULL_POINTER; + if (aStartOffset < 0) + aStartOffset = mContentLength; PRUnichar wordBufMem[WORD_BUF_SIZE]; PRUnichar paintBufMem[TEXT_BUF_SIZE]; PRInt32 indicies[TEXT_BUF_SIZE]; @@ -1651,46 +1650,72 @@ TextFrame::PeekOffset(nsSelectionAmount aAmount, nsDirection aDirection, nsIFra PRInt32 textLength; // Transform text from content into renderable form - int a; //EVIL EVIL EVIL //CHANGE API! nsTextTransformer tx(wordBufMem, WORD_BUF_SIZE); - PrepareUnicodeText((nsIRenderingContext &)a, tx, + PrepareUnicodeText(tx, ip, paintBuf, textLength, width); ip[mContentLength] = ip[mContentLength-1]+1; //must set up last one for selection beyond edge nsresult result(NS_OK); - PRInt32 oldPaintPos(ip[mSelectionOffset]); + PRInt32 oldPaintPos(ip[aStartOffset]); switch (aAmount){ - case eCharacter : { - if (aDirection == ePrevious){ + case eSelectNoAmount : { + *aResultFrame = this; + if (aStartOffset > mContentLength) + aStartOffset = mContentLength; //not ok normaly, but eNone means dont leave this frame + *aFrameOffset = aStartOffset; + } + break; + case eSelectCharacter : { + if (aDirection == eDirPrevious){ PRInt32 i; - for (i = mSelectionOffset -1; i >=0; i--){ - if (ip[i] < ip [mSelectionOffset]){ + for (i = aStartOffset -1; i >=0; i--){ + if (ip[i] < ip [aStartOffset]){ *aResultFrame = this; *aFrameOffset = i; break; } } - if (i <0) - result = NS_ERROR_FAILURE; //actually need to go to previous frame + if (i <0){ + nsIFrame *prev = GetPrevInFlow(); + if (prev){ + return prev->PeekOffset(eSelectNoAmount, aDirection, -1, aResultFrame, + aFrameOffset, aContentOffset); + } + else {//reached end ask the frame for help + return nsFrame::PeekOffset(eSelectNoAmount, aDirection, -1, aResultFrame, + aFrameOffset, aContentOffset); + } + } } else - if (aDirection == eNext){ + if (aDirection == eDirNext){ PRInt32 i; - for (i = mSelectionOffset +1; i <= mContentLength; i++){ - if (ip[i] > ip [mSelectionOffset]){ + for (i = aStartOffset +1; i <= mContentLength; i++){ + if (ip[i] > ip [aStartOffset]){ *aResultFrame = this; *aFrameOffset = i; break; } } - if (i > mContentLength) - result = NS_ERROR_FAILURE; //actually need to go to previous frame + if (aStartOffset == 0 && (mFlags & TEXT_SKIP_LEADING_WS)) + i--; //back up because we just skipped over some white space. why skip over the char also? + if (i > mContentLength){ + nsIFrame *next = GetNextInFlow(); + if (next){ + return next->PeekOffset(eSelectNoAmount, aDirection, 0, aResultFrame, + aFrameOffset, aContentOffset); + } + else {//reached end ask the frame for help + return nsFrame::PeekOffset(eSelectNoAmount, aDirection, 0, aResultFrame, + aFrameOffset, aContentOffset); + } + } } *aContentOffset = mContentOffset; } break; - case eWord : - case eLine : + case eSelectWord : + case eSelectLine : default: result = NS_ERROR_FAILURE; break; } // Cleanup diff --git a/mozilla/layout/html/base/src/Makefile.in b/mozilla/layout/html/base/src/Makefile.in index 78b9fa6c388..12a5f5c50c1 100644 --- a/mozilla/layout/html/base/src/Makefile.in +++ b/mozilla/layout/html/base/src/Makefile.in @@ -35,6 +35,7 @@ CPPSRCS= \ nsContainerFrame.cpp \ nsFrame.cpp \ nsFrameList.cpp \ + nsFrameTraversal.cpp \ nsGlobalVariables.cpp \ nsHRFrame.cpp \ nsHTMLAtoms.cpp \ diff --git a/mozilla/layout/html/base/src/makefile.win b/mozilla/layout/html/base/src/makefile.win index b30a8844cb2..1bc06bbf450 100644 --- a/mozilla/layout/html/base/src/makefile.win +++ b/mozilla/layout/html/base/src/makefile.win @@ -35,6 +35,7 @@ CPPSRCS= \ nsContainerFrame.cpp \ nsFrame.cpp \ nsFrameList.cpp \ + nsFrameTraversal.cpp \ nsGlobalVariables.cpp \ nsHRFrame.cpp \ nsHTMLAtoms.cpp \ @@ -74,6 +75,7 @@ CPP_OBJS= \ .\$(OBJDIR)\nsContainerFrame.obj \ .\$(OBJDIR)\nsFrame.obj \ .\$(OBJDIR)\nsFrameList.obj \ + .\$(OBJDIR)\nsFrameTraversal.obj \ .\$(OBJDIR)\nsGlobalVariables.obj \ .\$(OBJDIR)\nsHRFrame.obj \ .\$(OBJDIR)\nsHTMLAtoms.obj \ diff --git a/mozilla/layout/html/base/src/nsFrame.cpp b/mozilla/layout/html/base/src/nsFrame.cpp index 9c467c04b09..4ea05d42f9f 100644 --- a/mozilla/layout/html/base/src/nsFrame.cpp +++ b/mozilla/layout/html/base/src/nsFrame.cpp @@ -46,6 +46,10 @@ #include "nsHTMLParts.h" #include "nsLayoutAtoms.h" +#include "nsFrameTraversal.h" +#include "nsCOMPtr.h" + + // Some Misc #defines #define SELECTION_DEBUG 0 #define FORCE_SELECTION_UPDATE 1 @@ -1850,11 +1854,33 @@ nsFrame::GetSelected(PRBool *aSelected, PRInt32 *aBeginOffset, PRInt32 *aEndOffs NS_IMETHODIMP -nsFrame::PeekOffset(nsSelectionAmount aAmount, nsDirection aDirection, nsIFrame **aResultFrame, - PRInt32 *aFrameOffset, PRInt32 *aContentOffset) +nsFrame::PeekOffset(nsSelectionAmount aAmount, nsDirection aDirection, PRInt32 aStartOffset, + nsIFrame **aResultFrame, PRInt32 *aFrameOffset, PRInt32 *aContentOffset) { - //default, no matter what grab next/ previous sibling. - return NS_ERROR_FAILURE; + //this will use the nsFrameTraversal as the default peek method. + //this should change to use geometry and also look to ALL the child lists + nsCOMPtr frameTraversal; + nsresult result = NS_NewFrameTraversal(getter_AddRefs(frameTraversal),LEAF,this); + if (NS_FAILED(result)) + return result; + nsISupports *isupports; + if (aDirection == eDirNext) + result = frameTraversal->Next(); + else + result = frameTraversal->Prev(); + + if (NS_FAILED(result)) + return result; + result = frameTraversal->CurrentItem(&isupports); + if (NS_FAILED(result)) + return result; + if (!isupports) + return NS_ERROR_NULL_POINTER; + //we must CAST here to an nsIFrame. nsIFrame doesnt really follow the rules + //for speed reasons + nsIFrame *newFrame = (nsIFrame *)isupports; + return newFrame->PeekOffset(aAmount, aDirection, aStartOffset, aResultFrame, + aFrameOffset, aContentOffset); } //----------------------------------------------------------------------------------- diff --git a/mozilla/layout/html/base/src/nsFrame.h b/mozilla/layout/html/base/src/nsFrame.h index 158c2e2a641..be6dbfbb03d 100644 --- a/mozilla/layout/html/base/src/nsFrame.h +++ b/mozilla/layout/html/base/src/nsFrame.h @@ -208,7 +208,8 @@ public: nsIFocusTracker *aTracker, nsIFrame **aActualSelected); NS_IMETHOD GetSelected(PRBool *aSelected, PRInt32 *aBeginOffset, PRInt32 *aEndOffset, PRInt32 *aBeginContentOffset); - NS_IMETHODIMP PeekOffset(nsSelectionAmount aAmount, nsDirection aDirection, nsIFrame **aResultFrame, PRInt32 *aFrameOffset, PRInt32 *aContentOffset); + NS_IMETHOD PeekOffset(nsSelectionAmount aAmount, nsDirection aDirection, PRInt32 aStartOffset, + nsIFrame **aResultFrame, PRInt32 *aFrameOffset, PRInt32 *aContentOffset); NS_IMETHOD GetOffsets(PRInt32 &aStart, PRInt32 &aEnd) const; // nsIHTMLReflow diff --git a/mozilla/layout/html/base/src/nsFrameTraversal.cpp b/mozilla/layout/html/base/src/nsFrameTraversal.cpp new file mode 100644 index 00000000000..65cce65547d --- /dev/null +++ b/mozilla/layout/html/base/src/nsFrameTraversal.cpp @@ -0,0 +1,287 @@ +#include "nsFrameTraversal.h" +#include "nsFrameList.h" + + +static NS_DEFINE_IID(kIEnumeratorIID, NS_IENUMERATOR_IID); +static NS_DEFINE_IID(kISupportsIID, NS_ISUPPORTS_IID); + + +class nsFrameIterator: public nsIEnumerator +{ +public: + NS_DECL_ISUPPORTS + + virtual nsresult First(); + + virtual nsresult Last(); + + virtual nsresult Next()=0; + + virtual nsresult Prev()=0; + + virtual nsresult CurrentItem(nsISupports **aItem); + + virtual nsresult IsDone();//what does this mean??off edge? yes + + nsFrameIterator(); +protected: + void setCurrent(nsIFrame *aFrame){mCurrent = aFrame;} + nsIFrame *getCurrent(){return mCurrent;} + void setStart(nsIFrame *aFrame){mStart = aFrame;} + nsIFrame *getStart(){return mStart;} + nsIFrame *getLast(){return mLast;} + void setLast(nsIFrame *aFrame){mLast = aFrame;} + PRInt8 getOffEdge(){return mOffEdge;} + void setOffEdge(PRInt8 aOffEdge){mOffEdge = aOffEdge;} +private: + nsIFrame *mStart; + nsIFrame *mCurrent; + nsIFrame *mLast; //the last one that was in current; + PRInt8 mOffEdge; //0= no -1 to far prev, 1 to far next; +}; + + +/* +class nsFastFrameIterator: public nsFrameIterator +{ + nsFastFrameIterator(nsIFrame *start); +private : + + virtual nsresult Next(); + + virtual nsresult Prev(); + +} +*/ + +class nsLeafIterator: public nsFrameIterator +{ +public: + nsLeafIterator(nsIFrame *start); +private : + + virtual nsresult Next(); + + virtual nsresult Prev(); + +}; + +/************IMPLEMENTATIONS**************/ + +nsresult +NS_NewFrameTraversal(nsIEnumerator **aEnumerator, nsTraversalType aType, nsIFrame *aStart) +{ + if (!aEnumerator || !aStart) + return NS_ERROR_NULL_POINTER; + switch(aType) + { + case LEAF: { + nsLeafIterator *trav = new nsLeafIterator(aStart); + if (!trav) + return NS_ERROR_OUT_OF_MEMORY; + *aEnumerator = (nsIEnumerator *)trav; + NS_ADDREF(trav); + } + break; +#if 0 + case EXTENSIVE:{ + nsExtensiveTraversal *trav = new nsExtensiveTraversal(aStart); + if (!trav) + return NS_ERROR_NOMEMORY; + *aEnumerator = (nsIEnumerator *)trav; + NS_ADDREF(trav); + } + break; + case FASTEST:{ + nsFastestTraversal *trav = new nsFastestTraversal(aStart); + if (!trav) + return NS_ERROR_NOMEMORY; + *aEnumerator = (nsIEnumerator *)trav; + NS_ADDREF(trav); + } +#endif + default: + return NS_ERROR_NOT_IMPLEMENTED; + break; + } + return NS_OK; +} + + + +/*********nsFrameIterator************/ +NS_IMPL_ADDREF(nsFrameIterator) + +NS_IMPL_RELEASE(nsFrameIterator) + + + +nsFrameIterator::nsFrameIterator() +{ + mOffEdge = 0; + mLast = nsnull; + mCurrent = nsnull; + mStart = nsnull; + NS_INIT_REFCNT(); +} + + + +nsresult +nsFrameIterator::QueryInterface(REFNSIID aIID, void** aInstancePtr) +{ + if (NULL == aInstancePtr) { + return NS_ERROR_NULL_POINTER; + } + if (aIID.Equals(kISupportsIID)) { + *aInstancePtr = (void *)(nsISupports *)this; + NS_ADDREF_THIS(); + return NS_OK; + } + if (aIID.Equals(kIEnumeratorIID)) { + *aInstancePtr = (void*)(nsIEnumerator*)this; + NS_ADDREF_THIS(); + return NS_OK; + } + return NS_NOINTERFACE; +} + + + +nsresult +nsFrameIterator::CurrentItem(nsISupports **aItem) +{ + if (!aItem) + return NS_ERROR_NULL_POINTER; + *aItem = mCurrent; + return NS_OK; +} + + + +nsresult +nsFrameIterator::IsDone()//what does this mean??off edge? yes +{ + if (mOffEdge != 0) + return NS_OK; + return NS_COMFALSE; +} + + + +nsresult +nsFrameIterator::First() +{ + mCurrent = mStart; + return NS_OK; +} + + + +nsresult +nsFrameIterator::Last() +{ + return NS_ERROR_FAILURE; +} + + + +/*********LEAFITERATOR**********/ + + +nsLeafIterator::nsLeafIterator(nsIFrame *aStart) +{ + setStart(aStart); + setCurrent(aStart); + setLast(aStart); +} + + + +nsresult +nsLeafIterator::Next() +{ +//recursive-oid method to get next frame + nsIFrame *result; + nsIFrame *parent = getCurrent(); + if (!parent) + parent = getLast(); + while(NS_SUCCEEDED(parent->FirstChild(nsnull,&result)) && result) + { + parent = result; + } + if (parent != getCurrent()) + { + result = parent; + } + else { + while(parent){ + if (NS_SUCCEEDED(parent->GetNextSibling(&result)) && result){ + parent = result; + while(NS_SUCCEEDED(parent->FirstChild(nsnull,&result)) && result) + { + parent = result; + } + result = parent; + break; + } + else + if (NS_FAILED(parent->GetParent(&result)) || !result){ + result = nsnull; + break; + } + else + parent = result; + } + } + setCurrent(result); + if (!result) + setOffEdge(1); + return nsnull; +} + + + + +nsresult +nsLeafIterator::Prev() +{ +//recursive-oid method to get prev frame + nsIFrame *result; + nsIFrame *parent = getCurrent(); + if (!parent) + return NS_ERROR_FAILURE; + + parent = getLast(); + while(parent){ + nsIFrame *grandParent; + if (NS_SUCCEEDED(parent->GetParent(&grandParent)) && grandParent){ + nsIFrame * grandFchild; + if (NS_SUCCEEDED(grandParent->FirstChild(nsnull,&grandFchild)) && grandFchild){ + nsFrameList list(grandFchild); + if (result = list.GetPrevSiblingFor(parent) ){ + parent = result; + while(NS_SUCCEEDED(parent->FirstChild(nsnull,&result)) && result){ + parent = result; + while(NS_SUCCEEDED(parent->GetNextSibling(&result)) && result){ + parent = result; + } + } + result = parent; + break; + } + else + if (NS_FAILED(parent->GetParent(&result)) || !result){ + result = nsnull; + break; + } + else + parent = result; + } + } + } + setCurrent(result); + if (!result) + setOffEdge(-1); + return nsnull; +} diff --git a/mozilla/layout/html/base/src/nsFrameTraversal.h b/mozilla/layout/html/base/src/nsFrameTraversal.h new file mode 100644 index 00000000000..1ef0bbfded1 --- /dev/null +++ b/mozilla/layout/html/base/src/nsFrameTraversal.h @@ -0,0 +1,11 @@ +#ifndef NSFRAMETRAVERSAL_H +#define NSFRAMETRAVERSAL_H + +#include "nsIEnumerator.h" +#include "nsIFrame.h" + +enum nsTraversalType{LEAF, EXTENSIVE, FASTEST}; +nsresult NS_NewFrameTraversal(nsIEnumerator **aEnumerator, nsTraversalType aType, nsIFrame *aStart); + + +#endif //NSFRAMETRAVERSAL_H \ No newline at end of file diff --git a/mozilla/layout/html/base/src/nsPresShell.cpp b/mozilla/layout/html/base/src/nsPresShell.cpp index b2f6dad6cae..2af9c820316 100644 --- a/mozilla/layout/html/base/src/nsPresShell.cpp +++ b/mozilla/layout/html/base/src/nsPresShell.cpp @@ -41,7 +41,6 @@ #include "nsDOMEvent.h" #include "nsHTMLParts.h" #include "nsISelection.h" -#include "nsICollection.h" #include "nsLayoutCID.h" #include "nsIDOMRange.h" #include "nsIDOMDocument.h" @@ -160,7 +159,6 @@ static NS_DEFINE_IID(kIPresShellIID, NS_IPRESSHELL_IID); static NS_DEFINE_IID(kIDocumentObserverIID, NS_IDOCUMENT_OBSERVER_IID); static NS_DEFINE_IID(kIViewObserverIID, NS_IVIEWOBSERVER_IID); static NS_DEFINE_IID(kISelectionIID, NS_ISELECTION_IID); -static NS_DEFINE_IID(kICollectionIID, NS_ICOLLECTION_IID); static NS_DEFINE_IID(kIDOMNodeIID, NS_IDOMNODE_IID); static NS_DEFINE_IID(kIDOMRangeIID, NS_IDOMRANGE_IID); static NS_DEFINE_IID(kIDOMDocumentIID, NS_IDOMDOCUMENT_IID); @@ -490,11 +488,10 @@ PresShell::Init(nsIDocument* aDocument, mStyleSet = aStyleSet; NS_ADDREF(aStyleSet); - nsCOMPtrselection; - nsresult result = nsRepository::CreateInstance(kRangeListCID, nsnull, kICollectionIID, getter_AddRefs(selection)); + nsCOMPtrselection; + nsresult result = nsRepository::CreateInstance(kRangeListCID, nsnull, kISelectionIID, getter_AddRefs(selection)); if (!NS_SUCCEEDED(result)) return result; - selection->Clear();//clear all old selection // XXX This code causes the document object (and the entire content model) to be leaked... #if 0 nsCOMPtrrange; diff --git a/mozilla/layout/html/base/src/nsTextFrame.cpp b/mozilla/layout/html/base/src/nsTextFrame.cpp index b792d07f51b..dfcc97e123b 100644 --- a/mozilla/layout/html/base/src/nsTextFrame.cpp +++ b/mozilla/layout/html/base/src/nsTextFrame.cpp @@ -129,8 +129,8 @@ public: nsIFocusTracker *aTracker, nsIFrame **aActualSelected); NS_IMETHOD GetSelected(PRBool *aSelected, PRInt32 *aBeginOffset, PRInt32 *aEndOffset, PRInt32 *aBeginContentOffset); - NS_IMETHOD PeekOffset(nsSelectionAmount aAmount, nsDirection aDirection, nsIFrame **aResultFrame, - PRInt32 *aFrameOffset, PRInt32 *aContentOffset); + NS_IMETHOD PeekOffset(nsSelectionAmount aAmount, nsDirection aDirection, PRInt32 aStartOffset, + nsIFrame **aResultFrame, PRInt32 *aFrameOffset, PRInt32 *aContentOffset); NS_IMETHOD GetOffsets(PRInt32 &start, PRInt32 &end)const; @@ -231,8 +231,7 @@ public: } }; - PRIntn PrepareUnicodeText(nsIRenderingContext& aRenderingContext, - nsTextTransformer& aTransformer, + PRIntn PrepareUnicodeText(nsTextTransformer& aTransformer, PRInt32* aIndicies, PRUnichar* aBuffer, PRInt32& aTextLen, @@ -559,8 +558,7 @@ TextFrame::Paint(nsIPresContext& aPresContext, * the prepared output. */ PRIntn -TextFrame::PrepareUnicodeText(nsIRenderingContext& aRenderingContext, - nsTextTransformer& aTX, +TextFrame::PrepareUnicodeText(nsTextTransformer& aTX, PRInt32* aIndexes, PRUnichar* aBuffer, PRInt32& aTextLen, @@ -799,7 +797,7 @@ TextFrame::PaintUnicodeText(nsIPresContext& aPresContext, // Transform text from content into renderable form nsTextTransformer tx(wordBufMem, WORD_BUF_SIZE); - PrepareUnicodeText(aRenderingContext, tx, + PrepareUnicodeText(tx, displaySelection ? ip : nsnull, paintBuf, textLength, width); ip[mContentLength] = ip[mContentLength-1]+1; //must set up last one for selection beyond edge @@ -1131,7 +1129,7 @@ TextFrame::PaintTextSlowly(nsIPresContext& aPresContext, // Transform text from content into renderable form nsTextTransformer tx(wordBufMem, WORD_BUF_SIZE); - aTextStyle.mNumSpaces = PrepareUnicodeText(aRenderingContext, tx, + aTextStyle.mNumSpaces = PrepareUnicodeText(tx, displaySelection ? ip : nsnull, paintBuf, textLength, width); if (mRect.width > mComputedWidth) { @@ -1258,7 +1256,7 @@ TextFrame::PaintAsciiText(nsIPresContext& aPresContext, // Transform text from content into renderable form nsTextTransformer tx(wordBufMem, WORD_BUF_SIZE); - PrepareUnicodeText(aRenderingContext, tx, + PrepareUnicodeText(tx, displaySelection ? ip : nsnull, rawPaintBuf, textLength, width); ip[mContentLength] = ip[mContentLength-1]+1; //must set up last one for selection beyond edge @@ -1469,7 +1467,7 @@ TextFrame::GetPosition(nsIPresContext& aCX, // Get the renderable form of the text nsTextTransformer tx(wordBufMem, WORD_BUF_SIZE); - PrepareUnicodeText(*aRendContext, tx, + PrepareUnicodeText(tx, ip, paintBuf, textLength, width); ip[mContentLength] = ip[mContentLength-1]+1; @@ -1533,7 +1531,6 @@ NS_IMETHODIMP TextFrame::SetSelected(PRBool aSelected, PRInt32 aBeginOffset, PRInt32 aEndOffset, PRBool aForceRedraw) { if (aSelected){ -printf("SetSelected selection = %d, /t %x /t begin: %d end: %d\n",aSelected, this,aBeginOffset, aEndOffset); aEndOffset = PR_MIN(aEndOffset,mContentLength); aBeginOffset = PR_MIN(aBeginOffset,mContentLength); @@ -1632,12 +1629,14 @@ TextFrame::GetSelected(PRBool *aSelected, PRInt32 *aBeginOffset, PRInt32 *aEndOf NS_IMETHODIMP -TextFrame::PeekOffset(nsSelectionAmount aAmount, nsDirection aDirection, nsIFrame **aResultFrame, +TextFrame::PeekOffset(nsSelectionAmount aAmount, nsDirection aDirection, PRInt32 aStartOffset, nsIFrame **aResultFrame, PRInt32 *aFrameOffset, PRInt32 *aContentOffset) { //default, no matter what grab next/ previous sibling. if (!aResultFrame || !aFrameOffset || !aContentOffset) return NS_ERROR_NULL_POINTER; + if (aStartOffset < 0) + aStartOffset = mContentLength; PRUnichar wordBufMem[WORD_BUF_SIZE]; PRUnichar paintBufMem[TEXT_BUF_SIZE]; PRInt32 indicies[TEXT_BUF_SIZE]; @@ -1651,46 +1650,72 @@ TextFrame::PeekOffset(nsSelectionAmount aAmount, nsDirection aDirection, nsIFra PRInt32 textLength; // Transform text from content into renderable form - int a; //EVIL EVIL EVIL //CHANGE API! nsTextTransformer tx(wordBufMem, WORD_BUF_SIZE); - PrepareUnicodeText((nsIRenderingContext &)a, tx, + PrepareUnicodeText(tx, ip, paintBuf, textLength, width); ip[mContentLength] = ip[mContentLength-1]+1; //must set up last one for selection beyond edge nsresult result(NS_OK); - PRInt32 oldPaintPos(ip[mSelectionOffset]); + PRInt32 oldPaintPos(ip[aStartOffset]); switch (aAmount){ - case eCharacter : { - if (aDirection == ePrevious){ + case eSelectNoAmount : { + *aResultFrame = this; + if (aStartOffset > mContentLength) + aStartOffset = mContentLength; //not ok normaly, but eNone means dont leave this frame + *aFrameOffset = aStartOffset; + } + break; + case eSelectCharacter : { + if (aDirection == eDirPrevious){ PRInt32 i; - for (i = mSelectionOffset -1; i >=0; i--){ - if (ip[i] < ip [mSelectionOffset]){ + for (i = aStartOffset -1; i >=0; i--){ + if (ip[i] < ip [aStartOffset]){ *aResultFrame = this; *aFrameOffset = i; break; } } - if (i <0) - result = NS_ERROR_FAILURE; //actually need to go to previous frame + if (i <0){ + nsIFrame *prev = GetPrevInFlow(); + if (prev){ + return prev->PeekOffset(eSelectNoAmount, aDirection, -1, aResultFrame, + aFrameOffset, aContentOffset); + } + else {//reached end ask the frame for help + return nsFrame::PeekOffset(eSelectNoAmount, aDirection, -1, aResultFrame, + aFrameOffset, aContentOffset); + } + } } else - if (aDirection == eNext){ + if (aDirection == eDirNext){ PRInt32 i; - for (i = mSelectionOffset +1; i <= mContentLength; i++){ - if (ip[i] > ip [mSelectionOffset]){ + for (i = aStartOffset +1; i <= mContentLength; i++){ + if (ip[i] > ip [aStartOffset]){ *aResultFrame = this; *aFrameOffset = i; break; } } - if (i > mContentLength) - result = NS_ERROR_FAILURE; //actually need to go to previous frame + if (aStartOffset == 0 && (mFlags & TEXT_SKIP_LEADING_WS)) + i--; //back up because we just skipped over some white space. why skip over the char also? + if (i > mContentLength){ + nsIFrame *next = GetNextInFlow(); + if (next){ + return next->PeekOffset(eSelectNoAmount, aDirection, 0, aResultFrame, + aFrameOffset, aContentOffset); + } + else {//reached end ask the frame for help + return nsFrame::PeekOffset(eSelectNoAmount, aDirection, 0, aResultFrame, + aFrameOffset, aContentOffset); + } + } } *aContentOffset = mContentOffset; } break; - case eWord : - case eLine : + case eSelectWord : + case eSelectLine : default: result = NS_ERROR_FAILURE; break; } // Cleanup diff --git a/mozilla/layout/macbuild/layout.mcp b/mozilla/layout/macbuild/layout.mcp index f6c9c63c4156529e3e4361dfcbc861887318589e..07fedf3684f1820de1553c34674918151366271c 100644 GIT binary patch delta 5395 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