diff --git a/mozilla/layout/base/nsIFrameSelection.h b/mozilla/layout/base/nsIFrameSelection.h deleted file mode 100644 index e69de29bb2d..00000000000 diff --git a/mozilla/layout/base/nsIPresShell.h b/mozilla/layout/base/nsIPresShell.h index 0588822a216..3b97086a229 100644 --- a/mozilla/layout/base/nsIPresShell.h +++ b/mozilla/layout/base/nsIPresShell.h @@ -83,7 +83,7 @@ class nsAString; class nsStringArray; class nsICaret; class nsStyleContext; -class nsIFrameSelection; +class nsFrameSelection; class nsFrameManager; class nsILayoutHistoryState; class nsIReflowCallback; @@ -95,6 +95,8 @@ class nsCSSFrameConstructor; class nsISelection; template class nsCOMArray; +typedef short SelectionType; + #define NS_IPRESSHELL_IID \ { 0xa736d2fd, 0x0191, 0x42ea, \ { 0xb1, 0xb0, 0x80, 0x45, 0x1d, 0xfa, 0x03, 0x53 } } @@ -252,7 +254,7 @@ public: * You cannot go back and forth anymore with QI between nsIDOM sel and * nsIFrame sel. */ - nsIFrameSelection* FrameSelection() { return mSelection; } + nsFrameSelection* FrameSelection() { return mSelection; } // Make shell be a document observer NS_IMETHOD BeginObservingDocument() = 0; @@ -508,6 +510,8 @@ public: * else NS_OK */ NS_IMETHOD GetSelectionFlags(PRInt16 *aOutEnabled) = 0; + + virtual nsISelection* GetCurrentSelection(SelectionType aType) = 0; /** * Interface to dispatch events via the presshell @@ -757,7 +761,7 @@ protected: nsStyleSet* mStyleSet; // [OWNS] nsCSSFrameConstructor* mFrameConstructor; // [OWNS] nsIViewManager* mViewManager; // [WEAK] docViewer owns it so I don't have to - nsIFrameSelection* mSelection; + nsFrameSelection* mSelection; nsFrameManagerBase mFrameManager; // [OWNS] nsWeakPtr mForwardingContainer; diff --git a/mozilla/layout/base/nsPresShell.cpp b/mozilla/layout/base/nsPresShell.cpp index 83884a825cf..05ac45af32b 100644 --- a/mozilla/layout/base/nsPresShell.cpp +++ b/mozilla/layout/base/nsPresShell.cpp @@ -113,7 +113,7 @@ #include "nsIScrollableView.h" #include "nsIParser.h" #include "nsParserCIID.h" -#include "nsIFrameSelection.h" +#include "nsFrameSelection.h" #include "nsIDOMNSHTMLInputElement.h" //optimization for ::DoXXX commands #include "nsIDOMNSHTMLTextAreaElement.h" #include "nsViewsCID.h" @@ -1042,8 +1042,9 @@ public: NS_IMETHOD SelectAlternateStyleSheet(const nsString& aSheetTitle); NS_IMETHOD ListAlternateStyleSheets(nsStringArray& aTitleList); NS_IMETHOD SetPreferenceStyleRules(PRBool aForceReflow); - + NS_IMETHOD GetSelection(SelectionType aType, nsISelection** aSelection); + virtual nsISelection* GetCurrentSelection(SelectionType aType); NS_IMETHOD SetDisplaySelection(PRInt16 aToggle); NS_IMETHOD GetDisplaySelection(PRInt16 *aToggle); @@ -1749,11 +1750,8 @@ PresShell::Init(nsIDocument* aDocument, return result; } - result = mSelection->Init(this, nsnull); - if (NS_FAILED(result)) { - mStyleSet = nsnull; - return result; - } + mSelection->Init(this, nsnull); + // Important: this has to happen after the selection has been set up #ifdef SHOW_CARET // make the caret @@ -2547,13 +2545,15 @@ nsresult PresShell::SetPrefFocusRules(void) NS_IMETHODIMP PresShell::SetDisplaySelection(PRInt16 aToggle) { - return mSelection->SetDisplaySelection(aToggle); + mSelection->SetDisplaySelection(aToggle); + return NS_OK; } NS_IMETHODIMP PresShell::GetDisplaySelection(PRInt16 *aToggle) { - return mSelection->GetDisplaySelection(aToggle); + *aToggle = mSelection->GetDisplaySelection(); + return NS_OK; } NS_IMETHODIMP @@ -2561,7 +2561,24 @@ PresShell::GetSelection(SelectionType aType, nsISelection **aSelection) { if (!aSelection || !mSelection) return NS_ERROR_NULL_POINTER; - return mSelection->GetSelection(aType, aSelection); + + *aSelection = mSelection->GetSelection(aType); + + if (!(*aSelection)) + return NS_ERROR_INVALID_ARG; + + NS_ADDREF(*aSelection); + + return NS_OK; +} + +nsISelection* +PresShell::GetCurrentSelection(SelectionType aType) +{ + if (!mSelection) + return nsnull; + + return mSelection->GetSelection(aType); } NS_IMETHODIMP @@ -2579,7 +2596,7 @@ PresShell::RepaintSelection(SelectionType aType) if (!mSelection) return NS_ERROR_NULL_POINTER; - return mSelection->RepaintSelection(mPresContext, aType); + return mSelection->RepaintSelection(aType); } // Make shell be a document observer @@ -2607,17 +2624,6 @@ PresShell::EndObservingDocument() if (mDocument) { mDocument->RemoveObserver(this); } - if (mSelection){ - nsCOMPtr domselection; - nsresult result; - result = mSelection->GetSelection(nsISelectionController::SELECTION_NORMAL, getter_AddRefs(domselection)); - if (NS_FAILED(result)) - return result; - if (!domselection) - return NS_ERROR_UNEXPECTED; - mSelection->ShutDown(); - } - return NS_OK; } @@ -3207,7 +3213,7 @@ PresShell::PageMove(PRBool aForward, PRBool aExtend) return NS_ERROR_UNEXPECTED; nsIView *scrolledView; result = scrollableView->GetScrolledView(scrolledView); - mSelection->CommonPageMove(aForward, aExtend, scrollableView, mSelection); + mSelection->CommonPageMove(aForward, aExtend, scrollableView); // do ScrollSelectionIntoView() return ScrollSelectionIntoView(nsISelectionController::SELECTION_NORMAL, nsISelectionController::SELECTION_FOCUS_REGION, PR_TRUE); } @@ -3707,9 +3713,8 @@ PresShell::GetViewToScroll(nsLayoutUtils::Direction aDirection) nsCOMPtr focusedContent; esm->GetFocusedContent(getter_AddRefs(focusedContent)); if (!focusedContent && mSelection) { - nsCOMPtr domSelection; - mSelection->GetSelection(nsISelectionController::SELECTION_NORMAL, - getter_AddRefs(domSelection)); + nsISelection* domSelection = mSelection-> + GetSelection(nsISelectionController::SELECTION_NORMAL); if (domSelection) { nsCOMPtr focusedNode; domSelection->GetFocusNode(getter_AddRefs(focusedNode)); @@ -4079,11 +4084,9 @@ PresShell::GoToAnchor(const nsAString& aAnchorName, PRBool aScroll) } if (jumpToRange) { // Select the anchor - nsCOMPtr sel; - if (NS_SUCCEEDED( - GetSelection(nsISelectionController::SELECTION_NORMAL, - getter_AddRefs(sel))) && - sel) { + nsISelection* sel = mSelection-> + GetSelection(nsISelectionController::SELECTION_NORMAL); + if (sel) { sel->RemoveAllRanges(); sel->AddRange(jumpToRange); if (!selectAnchor) { @@ -4448,7 +4451,7 @@ NS_IMETHODIMP PresShell::GetLinkLocation(nsIDOMNode* aNode, nsAString& aLocation NS_IMETHODIMP PresShell::GetSelectionForCopy(nsISelection** outSelection) { - nsresult rv = NS_OK; + nsresult rv; *outSelection = nsnull; @@ -4478,16 +4481,20 @@ PresShell::GetSelectionForCopy(nsISelection** outSelection) if (!htmlInputFrame) return NS_ERROR_FAILURE; nsCOMPtr selCon; - rv = htmlInputFrame->GetSelectionController(mPresContext,getter_AddRefs(selCon)); + rv = htmlInputFrame-> + GetSelectionController(mPresContext,getter_AddRefs(selCon)); if (NS_FAILED(rv)) return rv; if (!selCon) return NS_ERROR_FAILURE; - rv = selCon->GetSelection(nsISelectionController::SELECTION_NORMAL, getter_AddRefs(sel)); + rv = selCon->GetSelection(nsISelectionController::SELECTION_NORMAL, + getter_AddRefs(sel)); } } - if (!sel) //get selection from this PresShell - rv = GetSelection(nsISelectionController::SELECTION_NORMAL, getter_AddRefs(sel)); - + if (!sel) { + sel = mSelection->GetSelection(nsISelectionController::SELECTION_NORMAL); + rv = NS_OK; + } + *outSelection = sel; NS_IF_ADDREF(*outSelection); return rv; @@ -5829,8 +5836,7 @@ PresShell::HandleEvent(nsIView *aView, nsPoint eventPoint = nsLayoutUtils::GetEventCoordinatesRelativeTo(aEvent, frame); - nsIFrame* targetFrame = - nsLayoutUtils::GetFrameForPoint(frame, eventPoint); + nsIFrame* targetFrame = nsLayoutUtils::GetFrameForPoint(frame, eventPoint); if (targetFrame) { PresShell* shell = NS_STATIC_CAST(PresShell*, targetFrame->GetPresContext()->PresShell()); diff --git a/mozilla/layout/build/nsLayoutModule.cpp b/mozilla/layout/build/nsLayoutModule.cpp index b1316335977..85e47fd514d 100644 --- a/mozilla/layout/build/nsLayoutModule.cpp +++ b/mozilla/layout/build/nsLayoutModule.cpp @@ -78,7 +78,7 @@ #include "nsIDocumentViewer.h" #include "nsIEventListenerManager.h" #include "nsIFactory.h" -#include "nsIFrameSelection.h" +#include "nsFrameSelection.h" #include "nsIFrameUtil.h" #include "nsIGenericFactory.h" #include "nsIHTMLCSSStyleSheet.h" @@ -476,7 +476,7 @@ nsresult NS_CreateFrameTraversal(nsIFrameTraversal** aResult); nsresult NS_NewSelectionImageService(nsISelectionImageService** aResult); #endif -nsresult NS_NewSelection(nsIFrameSelection** aResult); +nsresult NS_NewSelection(nsFrameSelection** aResult); nsresult NS_NewDomSelection(nsISelection** aResult); nsresult NS_NewDocumentViewer(nsIDocumentViewer** aResult); nsresult NS_NewRange(nsIDOMRange** aResult); @@ -558,7 +558,7 @@ MAKE_CTOR(CreateImageDocument, nsIDocument, NS_NewIma MAKE_CTOR(CreateCSSParser, nsICSSParser, NS_NewCSSParser) MAKE_CTOR(CreateCSSLoader, nsICSSLoader, NS_NewCSSLoader) MAKE_CTOR(CreateDOMSelection, nsISelection, NS_NewDomSelection) -MAKE_CTOR(CreateSelection, nsIFrameSelection, NS_NewSelection) +MAKE_CTOR(CreateSelection, nsFrameSelection, NS_NewSelection) MAKE_CTOR(CreateRange, nsIDOMRange, NS_NewRange) MAKE_CTOR(CreateRangeUtils, nsIRangeUtils, NS_NewRangeUtils) MAKE_CTOR(CreateContentIterator, nsIContentIterator, NS_NewContentIterator) diff --git a/mozilla/layout/forms/nsComboboxControlFrame.cpp b/mozilla/layout/forms/nsComboboxControlFrame.cpp index c686a4e6911..3f3432888c3 100644 --- a/mozilla/layout/forms/nsComboboxControlFrame.cpp +++ b/mozilla/layout/forms/nsComboboxControlFrame.cpp @@ -1514,7 +1514,7 @@ nsComboboxControlFrame::GetFrameName(nsAString& aResult) const //---------------------------------------------------------------------- void nsComboboxControlFrame::ShowDropDown(PRBool aDoDropDown) -{ +{ if (nsFormControlHelper::GetDisabled(mContent)) { return; } diff --git a/mozilla/layout/forms/nsITextControlFrame.h b/mozilla/layout/forms/nsITextControlFrame.h index 78bedbc9e5f..1e9ea5ce55f 100644 --- a/mozilla/layout/forms/nsITextControlFrame.h +++ b/mozilla/layout/forms/nsITextControlFrame.h @@ -43,7 +43,7 @@ class nsIEditor; class nsIDocShell; class nsISelectionController; -class nsIFrameSelection; +class nsFrameSelection; #define NS_IGFXTEXTCONTROLFRAME2_IID \ {/* 0c3b64da-4431-11da-94fd-00e08161165f*/ \ @@ -89,7 +89,7 @@ public: NS_IMETHOD GetSelectionRange(PRInt32* aSelectionStart, PRInt32* aSelectionEnd) = 0; virtual nsISelectionController* GetOwnedSelectionController() = 0; - virtual nsIFrameSelection* GetOwnedFrameSelection() = 0; + virtual nsFrameSelection* GetOwnedFrameSelection() = 0; }; NS_DEFINE_STATIC_IID_ACCESSOR(nsITextControlFrame, diff --git a/mozilla/layout/forms/nsTextControlFrame.cpp b/mozilla/layout/forms/nsTextControlFrame.cpp index 78709e0b154..61ef475aa08 100644 --- a/mozilla/layout/forms/nsTextControlFrame.cpp +++ b/mozilla/layout/forms/nsTextControlFrame.cpp @@ -44,7 +44,7 @@ #include "nsIDOMNSHTMLInputElement.h" #include "nsIFormControl.h" #include "nsIServiceManager.h" -#include "nsIFrameSelection.h" +#include "nsFrameSelection.h" #include "nsIPlaintextEditor.h" #include "nsEditorCID.h" #include "nsLayoutCID.h" @@ -535,7 +535,7 @@ class nsTextInputSelectionImpl : public nsSupportsWeakReference public: NS_DECL_ISUPPORTS - nsTextInputSelectionImpl(nsIFrameSelection *aSel, nsIPresShell *aShell, nsIContent *aLimiter); + nsTextInputSelectionImpl(nsFrameSelection *aSel, nsIPresShell *aShell, nsIContent *aLimiter); ~nsTextInputSelectionImpl(){} //NSISELECTIONCONTROLLER INTERFACES @@ -565,7 +565,7 @@ public: NS_IMETHOD CheckVisibility(nsIDOMNode *node, PRInt16 startOffset, PRInt16 EndOffset, PRBool *_retval); private: - nsCOMPtr mFrameSelection; + nsCOMPtr mFrameSelection; nsCOMPtr mLimiter; nsWeakPtr mPresShellWeak; }; @@ -576,7 +576,7 @@ NS_IMPL_ISUPPORTS2(nsTextInputSelectionImpl, nsISelectionController, nsISupports // BEGIN nsTextInputSelectionImpl -nsTextInputSelectionImpl::nsTextInputSelectionImpl(nsIFrameSelection *aSel, nsIPresShell *aShell, nsIContent *aLimiter) +nsTextInputSelectionImpl::nsTextInputSelectionImpl(nsFrameSelection *aSel, nsIPresShell *aShell, nsIContent *aLimiter) { if (aSel && aShell) { @@ -590,17 +590,21 @@ nsTextInputSelectionImpl::nsTextInputSelectionImpl(nsIFrameSelection *aSel, nsIP NS_IMETHODIMP nsTextInputSelectionImpl::SetDisplaySelection(PRInt16 aToggle) { - if (mFrameSelection) - return mFrameSelection->SetDisplaySelection(aToggle); - return NS_ERROR_NULL_POINTER; + if (!mFrameSelection) + return NS_ERROR_NULL_POINTER; + + mFrameSelection->SetDisplaySelection(aToggle); + return NS_OK; } NS_IMETHODIMP nsTextInputSelectionImpl::GetDisplaySelection(PRInt16 *aToggle) { - if (mFrameSelection) - return mFrameSelection->GetDisplaySelection(aToggle); - return NS_ERROR_NULL_POINTER; + if (!mFrameSelection) + return NS_ERROR_NULL_POINTER; + + *aToggle = mFrameSelection->GetDisplaySelection(); + return NS_OK; } NS_IMETHODIMP @@ -619,9 +623,16 @@ nsTextInputSelectionImpl::GetSelectionFlags(PRInt16 *aOutEnable) NS_IMETHODIMP nsTextInputSelectionImpl::GetSelection(PRInt16 type, nsISelection **_retval) { - if (mFrameSelection) - return mFrameSelection->GetSelection(type, _retval); - return NS_ERROR_NULL_POINTER; + if (!mFrameSelection) + return NS_ERROR_NULL_POINTER; + + *_retval = mFrameSelection->GetSelection(type); + + if (!(*_retval)) + return NS_ERROR_FAILURE; + + NS_ADDREF(*_retval); + return NS_OK; } NS_IMETHODIMP @@ -630,8 +641,7 @@ nsTextInputSelectionImpl::ScrollSelectionIntoView(PRInt16 aType, PRInt16 aRegion if (mFrameSelection) { nsresult rv = mFrameSelection->ScrollSelectionIntoView(aType, aRegion, aIsSynchronous); - nsIScrollableView* scrollableView = nsnull; - mFrameSelection->GetScrollableView(&scrollableView); + nsIScrollableView* scrollableView = mFrameSelection->GetScrollableView(); if (!scrollableView) { return rv; } @@ -654,23 +664,19 @@ nsTextInputSelectionImpl::ScrollSelectionIntoView(PRInt16 aType, PRInt16 aRegion NS_IMETHODIMP nsTextInputSelectionImpl::RepaintSelection(PRInt16 type) { - if (!mPresShellWeak) return NS_ERROR_NOT_INITIALIZED; - nsCOMPtr presShell = do_QueryReferent(mPresShellWeak); - if (presShell) - { - nsPresContext *context = presShell->GetPresContext(); - if (context) - { - return mFrameSelection->RepaintSelection(context, type); - } - } - return NS_ERROR_FAILURE; + if (!mFrameSelection) + return NS_ERROR_FAILURE; + + return mFrameSelection->RepaintSelection(type); } NS_IMETHODIMP nsTextInputSelectionImpl::RepaintSelection(nsPresContext* aPresContext, SelectionType aSelectionType) { - return RepaintSelection(aSelectionType); + if (!mFrameSelection) + return NS_ERROR_FAILURE; + + return mFrameSelection->RepaintSelection(aSelectionType); } NS_IMETHODIMP @@ -699,15 +705,13 @@ nsTextInputSelectionImpl::SetCaretReadOnly(PRBool aReadOnly) if (shell) { nsCOMPtr caret; - if (NS_SUCCEEDED(result = shell->GetCaret(getter_AddRefs(caret)))) + if (NS_SUCCEEDED(shell->GetCaret(getter_AddRefs(caret)))) { - nsCOMPtr domSel; - if (NS_SUCCEEDED(result = mFrameSelection->GetSelection(nsISelectionController::SELECTION_NORMAL, getter_AddRefs(domSel)))) - { + nsISelection* domSel = mFrameSelection-> + GetSelection(nsISelectionController::SELECTION_NORMAL); + if (domSel) return caret->SetCaretReadOnly(aReadOnly); - } } - } return NS_ERROR_FAILURE; } @@ -721,15 +725,13 @@ nsTextInputSelectionImpl::GetCaretEnabled(PRBool *_retval) if (shell) { nsCOMPtr caret; - if (NS_SUCCEEDED(result = shell->GetCaret(getter_AddRefs(caret)))) + if (NS_SUCCEEDED(shell->GetCaret(getter_AddRefs(caret)))) { - nsCOMPtr domSel; - if (NS_SUCCEEDED(result = mFrameSelection->GetSelection(nsISelectionController::SELECTION_NORMAL, getter_AddRefs(domSel)))) - { + nsISelection* domSel = mFrameSelection-> + GetSelection(nsISelectionController::SELECTION_NORMAL); + if (domSel) return caret->GetCaretVisible(_retval); - } } - } return NS_ERROR_FAILURE; } @@ -743,15 +745,13 @@ nsTextInputSelectionImpl::SetCaretVisibilityDuringSelection(PRBool aVisibility) if (shell) { nsCOMPtr caret; - if (NS_SUCCEEDED(result = shell->GetCaret(getter_AddRefs(caret)))) + if (NS_SUCCEEDED(shell->GetCaret(getter_AddRefs(caret)))) { - nsCOMPtr domSel; - if (NS_SUCCEEDED(result = mFrameSelection->GetSelection(nsISelectionController::SELECTION_NORMAL, getter_AddRefs(domSel)))) - { + nsISelection* domSel = mFrameSelection-> + GetSelection(nsISelectionController::SELECTION_NORMAL); + if (domSel) return caret->SetVisibilityDuringSelection(aVisibility); - } } - } return NS_ERROR_FAILURE; } @@ -810,13 +810,9 @@ nsTextInputSelectionImpl::PageMove(PRBool aForward, PRBool aExtend) return NS_ERROR_NULL_POINTER; //get the scroll view - nsIScrollableView *scrollableView; - nsresult result = mFrameSelection->GetScrollableView(&scrollableView); - if (NS_FAILED(result)) - return result; - - // XXX A WTF moment; why does it need a pointer to itself? - mFrameSelection->CommonPageMove(aForward, aExtend, scrollableView, mFrameSelection); + nsIScrollableView *scrollableView = mFrameSelection->GetScrollableView(); + if (scrollableView) + mFrameSelection->CommonPageMove(aForward, aExtend, scrollableView); } return ScrollSelectionIntoView(nsISelectionController::SELECTION_NORMAL, nsISelectionController::SELECTION_FOCUS_REGION, PR_TRUE); } @@ -824,11 +820,8 @@ nsTextInputSelectionImpl::PageMove(PRBool aForward, PRBool aExtend) NS_IMETHODIMP nsTextInputSelectionImpl::CompleteScroll(PRBool aForward) { - nsIScrollableView *scrollableView; - nsresult result; - result = mFrameSelection->GetScrollableView(&scrollableView); - if (NS_FAILED(result)) - return result; + nsIScrollableView *scrollableView = mFrameSelection->GetScrollableView(); + if (!scrollableView) return NS_ERROR_NOT_INITIALIZED; @@ -839,17 +832,13 @@ NS_IMETHODIMP nsTextInputSelectionImpl::CompleteMove(PRBool aForward, PRBool aExtend) { // grab the parent / root DIV for this text widget - nsresult result; - nsCOMPtr parentDIV; - result = mFrameSelection->GetLimiter(getter_AddRefs(parentDIV)); - if (NS_FAILED(result)) - return result; + nsIContent* parentDIV = mFrameSelection->GetLimiter(); if (!parentDIV) return NS_ERROR_UNEXPECTED; // make the caret be either at the very beginning (0) or the very end PRInt32 offset = 0; - nsIFrameSelection::HINT hint = nsIFrameSelection::HINTLEFT; + nsFrameSelection::HINT hint = nsFrameSelection::HINTLEFT; if (aForward) { offset = parentDIV->GetChildCount(); @@ -864,7 +853,7 @@ nsTextInputSelectionImpl::CompleteMove(PRBool aForward, PRBool aExtend) if (child->Tag() == nsHTMLAtoms::br) { --offset; - hint = nsIFrameSelection::HINTRIGHT; // for Bug 106855 + hint = nsFrameSelection::HINTRIGHT; // for Bug 106855 } } } @@ -879,11 +868,7 @@ nsTextInputSelectionImpl::CompleteMove(PRBool aForward, PRBool aExtend) NS_IMETHODIMP nsTextInputSelectionImpl::ScrollPage(PRBool aForward) { - nsIScrollableView *scrollableView; - nsresult result; - result = mFrameSelection->GetScrollableView(&scrollableView); - if (NS_FAILED(result)) - return result; + nsIScrollableView *scrollableView = mFrameSelection->GetScrollableView(); if (!scrollableView) return NS_ERROR_NOT_INITIALIZED; @@ -893,11 +878,7 @@ nsTextInputSelectionImpl::ScrollPage(PRBool aForward) NS_IMETHODIMP nsTextInputSelectionImpl::ScrollLine(PRBool aForward) { - nsIScrollableView *scrollableView; - nsresult result; - result = mFrameSelection->GetScrollableView(&scrollableView); - if (NS_FAILED(result)) - return result; + nsIScrollableView *scrollableView = mFrameSelection->GetScrollableView(); if (!scrollableView) return NS_ERROR_NOT_INITIALIZED; @@ -908,11 +889,7 @@ nsTextInputSelectionImpl::ScrollLine(PRBool aForward) NS_IMETHODIMP nsTextInputSelectionImpl::ScrollHorizontal(PRBool aLeft) { - nsIScrollableView *scrollableView; - nsresult result; - result = mFrameSelection->GetScrollableView(&scrollableView); - if (NS_FAILED(result)) - return result; + nsIScrollableView *scrollableView = mFrameSelection->GetScrollableView(); if (!scrollableView) return NS_ERROR_NOT_INITIALIZED; diff --git a/mozilla/layout/forms/nsTextControlFrame.h b/mozilla/layout/forms/nsTextControlFrame.h index 994cbb9f8a3..4dbe8a919f4 100644 --- a/mozilla/layout/forms/nsTextControlFrame.h +++ b/mozilla/layout/forms/nsTextControlFrame.h @@ -137,7 +137,7 @@ public: NS_IMETHOD GetSelectionRange(PRInt32* aSelectionStart, PRInt32* aSelectionEnd); virtual nsISelectionController* GetOwnedSelectionController() { return mSelCon; } - virtual nsIFrameSelection* GetOwnedFrameSelection() + virtual nsFrameSelection* GetOwnedFrameSelection() { return mFrameSel; } // nsIPhonetic @@ -283,7 +283,7 @@ private: PRPackedBool mDidPreDestroy; // has PreDestroy been called nsCOMPtr mSelCon; - nsCOMPtr mFrameSel; + nsCOMPtr mFrameSel; nsTextInputListener* mTextListener; // XXX This seems unsafe; what's keeping it around? nsIScrollableView *mScrollableView; diff --git a/mozilla/layout/generic/Makefile.in b/mozilla/layout/generic/Makefile.in index b272aee04d0..ed79a68de29 100644 --- a/mozilla/layout/generic/Makefile.in +++ b/mozilla/layout/generic/Makefile.in @@ -106,6 +106,7 @@ EXPORTS = \ nsIScrollableViewProvider.h \ nsIStatefulFrame.h \ nsReflowType.h \ + nsFrameSelection.h \ $(NULL) ifdef IBMBIDI diff --git a/mozilla/layout/generic/nsBRFrame.cpp b/mozilla/layout/generic/nsBRFrame.cpp index 882baa4eed5..a8bed43a24c 100644 --- a/mozilla/layout/generic/nsBRFrame.cpp +++ b/mozilla/layout/generic/nsBRFrame.cpp @@ -51,7 +51,7 @@ //FOR SELECTION #include "nsIContent.h" -#include "nsIFrameSelection.h" +#include "nsFrameSelection.h" //END INCLUDES FOR SELECTION class BRFrame : public nsFrame { diff --git a/mozilla/layout/generic/nsBlockFrame.cpp b/mozilla/layout/generic/nsBlockFrame.cpp index de7075f6091..186901802a6 100644 --- a/mozilla/layout/generic/nsBlockFrame.cpp +++ b/mozilla/layout/generic/nsBlockFrame.cpp @@ -72,7 +72,7 @@ #include "nsLayoutAtoms.h" #include "nsITextContent.h" #include "nsStyleChangeList.h" -#include "nsIFrameSelection.h" +#include "nsFrameSelection.h" #include "nsSpaceManager.h" #include "nsIntervalSet.h" #include "prenv.h" diff --git a/mozilla/layout/generic/nsFrame.cpp b/mozilla/layout/generic/nsFrame.cpp index 5f8732d21d9..c45c45cc736 100644 --- a/mozilla/layout/generic/nsFrame.cpp +++ b/mozilla/layout/generic/nsFrame.cpp @@ -82,7 +82,7 @@ #include "nsIEventStateManager.h" #include "nsISelection.h" #include "nsISelectionPrivate.h" -#include "nsIFrameSelection.h" +#include "nsFrameSelection.h" #include "nsHTMLParts.h" #include "nsLayoutAtoms.h" #include "nsCSSAnonBoxes.h" @@ -861,9 +861,9 @@ nsFrame::DisplaySelectionOverlay(nsDisplayListBuilder* aBuilder, if (!(displaySelection & aContentType)) return NS_OK; - PRInt16 selectionValue; - nsIFrameSelection* frameSelection = GetFrameSelection(); - frameSelection->GetDisplaySelection(&selectionValue); + nsFrameSelection* frameSelection = GetFrameSelection(); + PRInt16 selectionValue = frameSelection->GetDisplaySelection(); + if (selectionValue <= nsISelectionController::SELECTION_HIDDEN) return NS_OK; // selection is hidden or off @@ -878,12 +878,11 @@ nsFrame::DisplaySelectionOverlay(nsDisplayListBuilder* aBuilder, SelectionDetails *details; //look up to see what selection(s) are on this frame - rv = frameSelection->LookUpSelection(newContent, offset, - 1, &details, PR_FALSE); + details = frameSelection->LookUpSelection(newContent, offset, 1, PR_FALSE); // XXX is the above really necessary? We don't actually DO anything // with the details other than test that they're non-null - if (NS_FAILED(rv) || !details) - return rv; + if (!details) + return NS_OK; while (details) { SelectionDetails *next = details->mNext; @@ -1583,7 +1582,7 @@ nsFrame::HandleEvent(nsPresContext* aPresContext, } NS_IMETHODIMP -nsFrame::GetDataForTableSelection(nsIFrameSelection *aFrameSelection, +nsFrame::GetDataForTableSelection(nsFrameSelection *aFrameSelection, nsIPresShell *aPresShell, nsMouseEvent *aMouseEvent, nsIContent **aParentContent, PRInt32 *aContentOffset, PRInt32 *aTarget) { @@ -1599,8 +1598,7 @@ nsFrame::GetDataForTableSelection(nsIFrameSelection *aFrameSelection, if (NS_FAILED(result)) return result; - PRBool selectingTableCells = PR_FALSE; - aFrameSelection->GetTableCellSelection(&selectingTableCells); + PRBool selectingTableCells = aFrameSelection->GetTableCellSelection(); // DISPLAY_ALL means we're in an editor. // If already in cell selection mode, @@ -1632,13 +1630,14 @@ nsFrame::GetDataForTableSelection(nsIFrameSelection *aFrameSelection, PRBool foundTable = PR_FALSE; // Get the limiting node to stop parent frame search - nsCOMPtr limiter; - result = aFrameSelection->GetLimiter(getter_AddRefs(limiter)); + nsIContent* limiter = aFrameSelection->GetLimiter(); //We don't initiate row/col selection from here now, // but we may in future //PRBool selectColumn = PR_FALSE; //PRBool selectRow = PR_FALSE; + + result = NS_OK; while (frame && NS_SUCCEEDED(result)) { @@ -1669,7 +1668,7 @@ nsFrame::GetDataForTableSelection(nsIFrameSelection *aFrameSelection, frame = frame->GetParent(); result = NS_OK; // Stop if we have hit the selection's limiting content node - if (frame && frame->GetContent() == limiter.get()) + if (frame && frame->GetContent() == limiter) break; } } @@ -1841,15 +1840,13 @@ nsFrame::HandlePress(nsPresContext* aPresContext, // XXX This is screwy; it really should use the selection frame, not the // event frame - nsIFrameSelection* frameselection; + nsFrameSelection* frameselection; if (useFrameSelection) frameselection = GetFrameSelection(); else frameselection = shell->FrameSelection(); - PRInt16 displayresult = nsISelectionController::SELECTION_OFF; - frameselection->GetDisplaySelection(&displayresult); - if (displayresult == nsISelectionController::SELECTION_OFF) + if (frameselection->GetDisplaySelection() == nsISelectionController::SELECTION_OFF) return NS_OK;//nothing to do we cannot affect selection from here nsMouseEvent *me = (nsMouseEvent *)aEvent; @@ -1861,8 +1858,7 @@ nsFrame::HandlePress(nsPresContext* aPresContext, if (me->clickCount >1 ) { - rv = frameselection->SetMouseDownState( PR_TRUE ); - + frameselection->SetMouseDownState(PR_TRUE); frameselection->SetMouseDoubleDown(PR_TRUE); return HandleMultiplePress(aPresContext, aEvent, aEventStatus); } @@ -1880,15 +1876,11 @@ nsFrame::HandlePress(nsPresContext* aPresContext, rv = GetDataForTableSelection(frameselection, shell, me, getter_AddRefs(parentContent), &contentOffset, &target); if (NS_SUCCEEDED(rv) && parentContent) { - rv = frameselection->SetMouseDownState( PR_TRUE ); - if (NS_FAILED(rv)) return rv; - + frameselection->SetMouseDownState(PR_TRUE); return frameselection->HandleTableSelection(parentContent, contentOffset, target, me); } - PRBool supportsDelay = PR_FALSE; - - frameselection->GetDelayCaretOverExistingSelection(&supportsDelay); + PRBool supportsDelay = frameselection->GetDelayCaretOverExistingSelection(); frameselection->SetDelayedCaretData(0); if (supportsDelay) @@ -1903,12 +1895,8 @@ nsFrame::HandlePress(nsPresContext* aPresContext, if (isSelected) { - rv = frameselection->LookUpSelection(offsets.content, 0, - offsets.EndOffset(), &details, - PR_FALSE); - - if (NS_FAILED(rv)) - return rv; + details = frameselection->LookUpSelection(offsets.content, 0, + offsets.EndOffset(), PR_FALSE); // // If there are any details, check to see if the user clicked @@ -1932,12 +1920,9 @@ nsFrame::HandlePress(nsPresContext* aPresContext, offsets.EndOffset() <= curDetail->mEnd) { delete details; - rv = frameselection->SetMouseDownState( PR_FALSE ); - - if (NS_FAILED(rv)) - return rv; - - return frameselection->SetDelayedCaretData(me); + frameselection->SetMouseDownState(PR_FALSE); + frameselection->SetDelayedCaretData(me); + return NS_OK; } curDetail = curDetail->mNext; @@ -1948,10 +1933,7 @@ nsFrame::HandlePress(nsPresContext* aPresContext, } } - rv = frameselection->SetMouseDownState( PR_TRUE ); - - if (NS_FAILED(rv)) - return rv; + frameselection->SetMouseDownState(PR_TRUE); #if defined(XP_MAC) || defined(XP_MACOSX) PRBool control = me->isMeta; @@ -1977,7 +1959,7 @@ nsFrame::HandlePress(nsPresContext* aPresContext, // -moz-user-select: all or a non-text node without children). // Therefore, disable selection extension during mouse moves. // XXX This is a bit hacky; shouldn't editor be able to deal with this? - rv = frameselection->SetMouseDownState( PR_FALSE ); + frameselection->SetMouseDownState(PR_FALSE); } return rv; @@ -1997,7 +1979,6 @@ nsFrame::HandleMultiplePress(nsPresContext* aPresContext, return NS_OK; } - nsresult rv; if (DisplaySelection(aPresContext) == nsISelectionController::SELECTION_OFF) { return NS_OK; } @@ -2030,15 +2011,17 @@ nsFrame::HandleMultiplePress(nsPresContext* aPresContext, ContentOffsets offsets = GetContentOffsetsFromPoint(pt); if (!offsets.content) return NS_ERROR_FAILURE; - nsIFrame* result; + nsIFrame* theFrame; PRInt32 offset; // Maybe make this a static helper? - rv = GetPresContext()->GetPresShell()->FrameSelection()-> + theFrame = GetPresContext()->GetPresShell()->FrameSelection()-> GetFrameForNodeOffset(offsets.content, offsets.offset, - nsIFrameSelection::HINT(offsets.associateWithNext), - &result, &offset); - NS_ENSURE_SUCCESS(rv, rv); - nsFrame* frame = NS_STATIC_CAST(nsFrame*, result); + nsFrameSelection::HINT(offsets.associateWithNext), + &offset); + if (!theFrame) + return NS_ERROR_FAILURE; + + nsFrame* frame = NS_STATIC_CAST(nsFrame*, theFrame); return frame->PeekBackwardAndForward(beginAmount, endAmount, offsets.offset, aPresContext, @@ -2151,9 +2134,9 @@ NS_IMETHODIMP nsFrame::HandleDrag(nsPresContext* aPresContext, } nsIPresShell *presShell = aPresContext->PresShell(); - nsIFrameSelection* frameselection = GetFrameSelection(); - PRBool mouseDown = PR_FALSE; - if (NS_SUCCEEDED(frameselection->GetMouseDownState(&mouseDown)) && !mouseDown) + nsFrameSelection* frameselection = GetFrameSelection(); + PRBool mouseDown = frameselection->GetMouseDownState(); + if (!mouseDown) return NS_OK; frameselection->StopAutoScrollTimer(); @@ -2171,7 +2154,7 @@ NS_IMETHODIMP nsFrame::HandleDrag(nsPresContext* aPresContext, frameselection->HandleTableSelection(parentContent, contentOffset, target, me); } else { nsPoint pt = nsLayoutUtils::GetEventCoordinatesRelativeTo(aEvent, this); - frameselection->HandleDrag(aPresContext, this, pt); + frameselection->HandleDrag(this, pt); } nsIView* captureView = GetNearestCapturingView(this); @@ -2181,8 +2164,7 @@ NS_IMETHODIMP nsFrame::HandleDrag(nsPresContext* aPresContext, nsPoint pt = nsLayoutUtils::GetEventCoordinatesForNearestView(aEvent, this, &eventView); nsPoint capturePt = pt + eventView->GetOffsetTo(captureView); - frameselection->StartAutoScrollTimer(aPresContext, captureView, capturePt, - 30); + frameselection->StartAutoScrollTimer(captureView, capturePt, 30); } return NS_OK; @@ -2203,42 +2185,31 @@ NS_IMETHODIMP nsFrame::HandleRelease(nsPresContext* aPresContext, if (activeFrame != this && NS_STATIC_CAST(nsFrame*, activeFrame)->DisplaySelection(activeFrame->GetPresContext()) != nsISelectionController::SELECTION_OFF) { - nsIFrameSelection* frameSelection = activeFrame->GetFrameSelection(); - frameSelection->SetMouseDownState( PR_FALSE ); + nsFrameSelection* frameSelection = activeFrame->GetFrameSelection(); + frameSelection->SetMouseDownState(PR_FALSE); frameSelection->StopAutoScrollTimer(); } if (DisplaySelection(aPresContext) == nsISelectionController::SELECTION_OFF) return NS_OK; - nsIFrameSelection* frameselection = GetFrameSelection(); + nsFrameSelection* frameselection = GetFrameSelection(); nsresult result = NS_OK; NS_ENSURE_ARG_POINTER(aEventStatus); if (nsEventStatus_eConsumeNoDefault != *aEventStatus) { - PRBool supportsDelay = PR_FALSE; - - frameselection->GetDelayCaretOverExistingSelection(&supportsDelay); - - if (supportsDelay) + if (frameselection->GetDelayCaretOverExistingSelection()) { // Check if the frameselection recorded the mouse going down. // If not, the user must have clicked in a part of the selection. // Place the caret before continuing! - PRBool mouseDown = PR_FALSE; + PRBool mouseDown = frameselection->GetMouseDownState(); - result = frameselection->GetMouseDownState(&mouseDown); + nsMouseEvent *me = frameselection->GetDelayedCaretData(); - if (NS_FAILED(result)) - return result; - - nsMouseEvent *me = 0; - - result = frameselection->GetDelayedCaretData(&me); - - if (NS_SUCCEEDED(result) && !mouseDown && me && me->clickCount < 2) + if (!mouseDown && me && me->clickCount < 2) { // We are doing this to simulate what we would have done on HandlePress. // We didn't do it there to give the user an opportunity to drag @@ -2249,11 +2220,7 @@ NS_IMETHODIMP nsFrame::HandleRelease(nsPresContext* aPresContext, // * that's the normal click position to use (although really, in // the normal case, small movements that don't count as a drag // can do selection) - result = frameselection->SetMouseDownState( PR_TRUE ); - - nsCOMPtr content; - PRInt32 startOffset = 0, endOffset = 0; - PRBool beginFrameContent = PR_FALSE; + frameselection->SetMouseDownState(PR_TRUE); nsPoint pt = nsLayoutUtils::GetEventCoordinatesRelativeTo(aEvent, this); ContentOffsets offsets = GetContentOffsetsFromPoint(pt); @@ -2279,19 +2246,19 @@ NS_IMETHODIMP nsFrame::HandleRelease(nsPresContext* aPresContext, if (NS_SUCCEEDED(result) && parentContent) { - frameselection->SetMouseDownState( PR_FALSE ); + frameselection->SetMouseDownState(PR_FALSE); result = frameselection->HandleTableSelection(parentContent, contentOffset, target, me); if (NS_FAILED(result)) return result; } } - result = frameselection->SetDelayedCaretData(0); + frameselection->SetDelayedCaretData(0); } } // Now handle the normal HandleRelase business. if (NS_SUCCEEDED(result) && frameselection) { - frameselection->SetMouseDownState( PR_FALSE ); + frameselection->SetMouseDownState(PR_FALSE); frameselection->StopAutoScrollTimer(); } @@ -3619,7 +3586,7 @@ nsFrame::GetSelectionController(nsPresContext *aPresContext, nsISelectionControl return CallQueryInterface(aPresContext->GetPresShell(), aSelCon); } -nsIFrameSelection* nsIFrame::GetFrameSelection() +nsFrameSelection* nsIFrame::GetFrameSelection() { nsIFrame *frame = this; while (frame && (frame->GetStateBits() & NS_FRAME_INDEPENDENT_SELECTION)) { diff --git a/mozilla/layout/generic/nsFrame.h b/mozilla/layout/generic/nsFrame.h index e0bf5c89812..1d70c42f565 100644 --- a/mozilla/layout/generic/nsFrame.h +++ b/mozilla/layout/generic/nsFrame.h @@ -51,7 +51,7 @@ #include "nsIPresShell.h" #include "nsHTMLReflowCommand.h" -#include "nsIFrameSelection.h" +#include "nsFrameSelection.h" #include "nsHTMLReflowState.h" #include "nsHTMLReflowMetrics.h" @@ -507,7 +507,7 @@ protected: // of the enclosing cell or table (if not inside a cell) // aTarget tells us what table element to select (currently only cell and table supported) // (enums for this are defined in nsIFrame.h) - NS_IMETHOD GetDataForTableSelection(nsIFrameSelection *aFrameSelection, + NS_IMETHOD GetDataForTableSelection(nsFrameSelection *aFrameSelection, nsIPresShell *aPresShell, nsMouseEvent *aMouseEvent, nsIContent **aParentContent, PRInt32 *aContentOffset, PRInt32 *aTarget); diff --git a/mozilla/layout/generic/nsFrameSelection.h b/mozilla/layout/generic/nsFrameSelection.h new file mode 100644 index 00000000000..0afa65f2084 --- /dev/null +++ b/mozilla/layout/generic/nsFrameSelection.h @@ -0,0 +1,590 @@ +/* + * ***** BEGIN LICENSE BLOCK ***** + * Version: MPL 1.1/GPL 2.0/LGPL 2.1 + * + * The contents of this file are subject to the Mozilla Public License Version + * 1.1 (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * http://www.mozilla.org/MPL/ + * + * Software distributed under the License is distributed on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License + * for the specific language governing rights and limitations under the + * License. + * + * Alternatively, the contents of this file may be used under the terms of + * either of the GNU General Public License Version 2 or later (the "GPL"), + * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), + * in which case the provisions of the GPL or the LGPL are applicable instead + * of those above. If you wish to allow use of your version of this file only + * under the terms of either the GPL or the LGPL, and not to allow others to + * use your version of this file under the terms of the MPL, indicate your + * decision by deleting the provisions above and replace them with the notice + * and other provisions required by the GPL or the LGPL. If you do not delete + * the provisions above, a recipient may use your version of this file under + * the terms of any one of the MPL, the GPL or the LGPL. + * + * ***** END LICENSE BLOCK ***** + */ + +#ifndef nsFrameSelection_h___ +#define nsFrameSelection_h___ + +#include "nsIFrame.h" +#include "nsIContent.h" +#include "nsISelectionController.h" + +#include "nsITableLayout.h" +#include "nsITableCellLayout.h" +#include "nsIDOMElement.h" +#include "nsGUIEvent.h" + +// IID for the nsFrameSelection interface +// cdfa6280-eba6-4938-9406-427818da8ce3 +#define NS_FRAME_SELECTION_IID \ +{ 0xcdfa6280, 0xeba6, 0x4938, \ + { 0x94, 0x06, 0x42, 0x78, 0x18, 0xda, 0x8c, 0xe3 } } + +//---------------------------------------------------------------------- + +// Selection interface + +struct SelectionDetails +{ + PRInt32 mStart; + PRInt32 mEnd; + SelectionType mType; + SelectionDetails *mNext; +}; + +class nsIPresShell; + +/*PeekOffsetStruct + * @param mShell is used to get the PresContext useful for measuring text etc. + * @param mDesiredX is the "desired" location of the new caret + * @param mAmount eWord, eCharacter, eLine + * @param mDirection enum defined in this file to be eForward or eBackward + * @param mStartOffset start offset to start the peek. 0 == beginning -1 = end + * @param mResultContent content that actually is the next/previous + * @param mResultOffset offset for result content + * @param mResultFrame resulting frame for peeking + * @param mEatingWS boolean to tell us the state of our search for Next/Prev + * @param mPreferLeft true = prev line end, false = next line begin + * @param mJumpLines if this is true then it's ok to cross lines while peeking + * @param mScrollViewStop if this is true then stop peeking across scroll view boundary +*/ +struct nsPeekOffsetStruct +{ + void SetData(nsIPresShell *aShell, + nscoord aDesiredX, + nsSelectionAmount aAmount, + nsDirection aDirection, + PRInt32 aStartOffset, + PRBool aEatingWS, + PRBool aPreferLeft, + PRBool aJumpLines, + PRBool aScrollViewStop, + PRBool aIsKeyboardSelect, + PRBool aVisual) + { + mShell=aShell; + mDesiredX=aDesiredX; + mAmount=aAmount; + mDirection=aDirection; + mStartOffset=aStartOffset; + mEatingWS=aEatingWS; + mPreferLeft=aPreferLeft; + mJumpLines = aJumpLines; + mScrollViewStop = aScrollViewStop; + mIsKeyboardSelect = aIsKeyboardSelect; + mVisual = aVisual; + } + nsIPresShell *mShell; + nscoord mDesiredX; + nsSelectionAmount mAmount; + nsDirection mDirection; + PRInt32 mStartOffset; + nsCOMPtr mResultContent; + PRInt32 mContentOffset; + PRInt32 mContentOffsetEnd; + nsIFrame *mResultFrame; + PRBool mEatingWS; + PRBool mPreferLeft; + PRBool mJumpLines; + PRBool mScrollViewStop; + PRBool mIsKeyboardSelect; + PRBool mVisual; +}; + +struct nsPrevNextBidiLevels +{ + void SetData(nsIFrame* aFrameBefore, + nsIFrame* aFrameAfter, + PRUint8 aLevelBefore, + PRUint8 aLevelAfter) + { + mFrameBefore = aFrameBefore; + mFrameAfter = aFrameAfter; + mLevelBefore = aLevelBefore; + mLevelAfter = aLevelAfter; + } + nsIFrame* mFrameBefore; + nsIFrame* mFrameAfter; + PRUint8 mLevelBefore; + PRUint8 mLevelAfter; +}; + +class nsTypedSelection; +class nsIScrollableView; + +class nsFrameSelection : public nsISupports { +public: + NS_DECLARE_STATIC_IID_ACCESSOR(NS_FRAME_SELECTION_IID) + enum HINT { HINTLEFT = 0, HINTRIGHT = 1}; //end of this line or beginning of next + /*interfaces for addref and release and queryinterface*/ + + NS_DECL_ISUPPORTS + + /** Init will initialize the frame selector with the necessary pres shell to + * be used by most of the methods + * @param aShell is the parameter to be used for most of the other calls for callbacks etc + * @param aLimiter limits the selection to nodes with aLimiter parents + */ + void Init(nsIPresShell *aShell, nsIContent *aLimiter); + + /* SetScrollableView sets the scroll view + * @param aScrollView is the scroll view for this selection. + */ + void SetScrollableView(nsIScrollableView *aScrollView) { mScrollView = aScrollView; } + + /* GetScrollableView gets the current scroll view + */ + nsIScrollableView* GetScrollableView() { return mScrollView; } + + /** HandleClick will take the focus to the new frame at the new offset and + * will either extend the selection from the old anchor, or replace the old anchor. + * the old anchor and focus position may also be used to deselect things + * @param aNewfocus is the content that wants the focus + * @param aContentOffset is the content offset of the parent aNewFocus + * @param aContentOffsetEnd is the content offset of the parent aNewFocus and is specified different + * when you need to select to and include both start and end points + * @param aContinueSelection is the flag that tells the selection to keep the old anchor point or not. + * @param aMultipleSelection will tell the frame selector to replace /or not the old selection. + * cannot coexist with aContinueSelection + * @param aHint will tell the selection which direction geometrically to actually show the caret on. + * 1 = end of this line 0 = beginning of this line + */ + nsresult HandleClick(nsIContent *aNewFocus, + PRUint32 aContentOffset, + PRUint32 aContentEndOffset, + PRBool aContinueSelection, + PRBool aMultipleSelection, + PRBool aHint); + + /** HandleDrag extends the selection to contain the frame closest to aPoint. + * @param aPresContext is the context to use when figuring out what frame contains the point. + * @param aFrame is the parent of all frames to use when searching for the closest frame to the point. + * @param aPoint is relative to aFrame + */ + void HandleDrag(nsIFrame *aFrame, nsPoint aPoint); + + /** HandleTableSelection will set selection to a table, cell, etc + * depending on information contained in aFlags + * @param aParentContent is the paretent of either a table or cell that user clicked or dragged the mouse in + * @param aContentOffset is the offset of the table or cell + * @param aTarget indicates what to select (defined in nsISelectionPrivate.idl/nsISelectionPrivate.h): + * TABLESELECTION_CELL We should select a cell (content points to the cell) + * TABLESELECTION_ROW We should select a row (content points to any cell in row) + * TABLESELECTION_COLUMN We should select a row (content points to any cell in column) + * TABLESELECTION_TABLE We should select a table (content points to the table) + * TABLESELECTION_ALLCELLS We should select all cells (content points to any cell in table) + * @param aMouseEvent passed in so we can get where event occurred and what keys are pressed + */ + nsresult HandleTableSelection(nsIContent *aParentContent, + PRInt32 aContentOffset, + PRInt32 aTarget, + nsMouseEvent *aMouseEvent); + + /** StartAutoScrollTimer is responsible for scrolling views so that aPoint is always + * visible, and for selecting any frame that contains aPoint. The timer will also reset + * itself to fire again if we have not scrolled to the end of the document. + * @param aPresContext is the context to use when figuring out what frame contains the point. + * @param aView is view to use when searching for the closest frame to the point, + * which is the view that is capturing the mouse + * @param aPoint is relative to the view. + * @param aDelay is the timer's interval. + */ + nsresult StartAutoScrollTimer(nsIView *aView, + nsPoint aPoint, + PRUint32 aDelay); + + /** StopAutoScrollTimer stops any active auto scroll timer. + */ + void StopAutoScrollTimer(); + + /** Lookup Selection + * returns in frame coordinates the selection beginning and ending with the type of selection given + * @param aContent is the content asking + * @param aContentOffset is the starting content boundary + * @param aContentLength is the length of the content piece asking + * @param aReturnDetails linkedlist of return values for the selection. + * @param aSlowCheck will check using slow method with no shortcuts + */ + SelectionDetails* LookUpSelection(nsIContent *aContent, + PRInt32 aContentOffset, + PRInt32 aContentLength, + PRBool aSlowCheck); + + /** SetMouseDownState(PRBool); + * sets the mouse state to aState for resons of drag state. + * @param aState is the new state of mousedown + */ + void SetMouseDownState(PRBool aState); + + /** GetMouseDownState(PRBool *); + * gets the mouse state to aState for resons of drag state. + * @param aState will hold the state of mousedown + */ + PRBool GetMouseDownState() { return mMouseDownState; } + + /** + if we are in table cell selection mode. aka ctrl click in table cell + */ + PRBool GetTableCellSelection() { return mSelectingTableCellMode != 0; } + void ClearTableCellSelection(){ mSelectingTableCellMode = 0; } + + /** GetSelection + * no query interface for selection. must use this method now. + * @param aSelectionType enum value defined in nsISelection for the seleciton you want. + */ + nsISelection* GetSelection(SelectionType aType); + + /** + * ScrollSelectionIntoView scrolls a region of the selection, + * so that it is visible in the scrolled view. + * + * @param aType the selection to scroll into view. + * @param aRegion the region inside the selection to scroll into view. + * @param aIsSynchronous when PR_TRUE, scrolls the selection into view + * at some point after the method returns.request which is processed + */ + nsresult ScrollSelectionIntoView(SelectionType aType, + SelectionRegion aRegion, + PRBool aIsSynchronous); + + /** RepaintSelection repaints the selected frames that are inside the selection + * specified by aSelectionType. + * @param aSelectionType enum value defined in nsISelection for the seleciton you want. + */ + nsresult RepaintSelection(SelectionType aType); + + /** GetFrameForNodeOffset given a node and its child offset, return the nsIFrame and + * the offset into that frame. + * @param aNode input parameter for the node to look at + * @param aOffset offset into above node. + * @param aReturnOffset will contain offset into frame. + */ + nsIFrame* GetFrameForNodeOffset(nsIContent *aNode, + PRInt32 aOffset, + HINT aHint, + PRInt32 *aReturnOffset); + + /** + * Scrolling then moving caret placement code in common to text areas and + * content areas should be located in the implementer + * This method will accept the following parameters and perform the scroll + * and caret movement. It remains for the caller to call the final + * ScrollCaretIntoView if that called wants to be sure the caret is always + * visible. + * + * @param aForward if PR_TRUE, scroll forward if not scroll backward + * @param aExtend if PR_TRUE, extend selection to the new point + * @param aScrollableView the view that needs the scrolling + */ + void CommonPageMove(PRBool aForward, + PRBool aExtend, + nsIScrollableView *aScrollableView); + + void SetHint(HINT aHintRight) { mHint = aHintRight; } + HINT GetHint() { return mHint; } + + /** CharacterMove will generally be called from the nsiselectioncontroller implementations. + * the effect being the selection will move one character left or right. + * @param aForward move forward in document. + * @param aExtend continue selection + */ + nsresult CharacterMove(PRBool aForward, PRBool aExtend); + + /** WordMove will generally be called from the nsiselectioncontroller implementations. + * the effect being the selection will move one word left or right. + * @param aForward move forward in document. + * @param aExtend continue selection + */ + nsresult WordMove(PRBool aForward, PRBool aExtend); + + /** LineMove will generally be called from the nsiselectioncontroller implementations. + * the effect being the selection will move one line up or down. + * @param aForward move forward in document. + * @param aExtend continue selection + */ + nsresult LineMove(PRBool aForward, PRBool aExtend); + + /** IntraLineMove will generally be called from the nsiselectioncontroller implementations. + * the effect being the selection will move to beginning or end of line + * @param aForward move forward in document. + * @param aExtend continue selection + */ + nsresult IntraLineMove(PRBool aForward, PRBool aExtend); + + /** Select All will generally be called from the nsiselectioncontroller implementations. + * it will select the whole doc + */ + nsresult SelectAll(); + + /** Sets/Gets The display selection enum. + */ + void SetDisplaySelection(PRInt16 aState) { mDisplaySelection = aState; } + PRInt16 GetDisplaySelection() { return mDisplaySelection; } + + /** Allow applications to specify how we should place the caret + * when the user clicks over an existing selection. A aDelay + * value of PR_TRUE means delay clearing the selection and + * placing the caret until MouseUp, when the user clicks over + * an existing selection. This is especially useful when applications + * want to support Drag & Drop of the current selection. A value + * of PR_FALSE means place the caret immediately. If the application + * never calls this method, the nsIFrameSelection implementation + * assumes the default value is PR_TRUE. + * @param aDelay PR_TRUE if we should delay caret placement. + */ + void SetDelayCaretOverExistingSelection(PRBool aDelay); + + /** Get the current delay caret setting. + */ + PRBool GetDelayCaretOverExistingSelection() { return mDelayCaretOverExistingSelection; } + + /** If we are delaying caret placement til MouseUp (see + * Set/GetDelayCaretOverExistingSelection()), this method + * can be used to store the data received during the MouseDown + * so that we can place the caret during the MouseUp event. + * @aMouseEvent the event received by the selection MouseDown + * handling method. A NULL value can be use to tell this method + * that any data is storing is no longer valid. + */ + void SetDelayedCaretData(nsMouseEvent *aMouseEvent); + + /** Get the delayed MouseDown event data necessary to place the + * caret during MouseUp processing. + * @return a pointer to the event received + * by the selection during MouseDown processing. It can be NULL + * if the data is no longer valid. + */ + nsMouseEvent* GetDelayedCaretData(); + + /** Get the content node that limits the selection + * When searching up a nodes for parents, as in a text edit field + * in an browser page, we must stop at this node else we reach into the + * parent page, which is very bad! + */ + nsIContent* GetLimiter() { return mLimiter; } + + /** This will tell the frame selection that a double click has been pressed + * so it can track abort future drags if inside the same selection + * @aDoubleDown has the double click down happened + */ + void SetMouseDoubleDown(PRBool aDoubleDown) { mMouseDoubleDownState = aDoubleDown; } + + /** This will return whether the double down flag was set. + * @return whether the double down flag was set + */ + PRBool GetMouseDoubleDown() { return mMouseDoubleDownState; } + + /** GetPrevNextBidiLevels will return the frames and associated Bidi levels of the characters + * logically before and after a (collapsed) selection. + * @param aNode is the node containing the selection + * @param aContentOffset is the offset of the selection in the node + * @param aJumpLines If PR_TRUE, look across line boundaries. + * If PR_FALSE, behave as if there were base-level frames at line edges. + * + * @return A struct holding the before/after frame and the before/after level. + * + * At the beginning and end of each line there is assumed to be a frame with + * Bidi level equal to the paragraph embedding level. + * In these cases the before frame and after frame respectively will be + * nsnull. + * + * This method is virtual since it gets called from outside of layout. + */ + virtual nsPrevNextBidiLevels GetPrevNextBidiLevels(nsIContent *aNode, + PRUint32 aContentOffset, + PRBool aJumpLines); + + /** GetFrameFromLevel will scan in a given direction + * until it finds a frame with a Bidi level less than or equal to a given level. + * It will return the last frame before this. + * @param aPresContext is the context to use + * @param aFrameIn is the frame to start from + * @param aDirection is the direction to scan + * @param aBidiLevel is the level to search for + * @param aFrameOut will hold the frame returned + */ + nsresult GetFrameFromLevel(nsIFrame *aFrameIn, + nsDirection aDirection, + PRUint8 aBidiLevel, + nsIFrame **aFrameOut); + + /** + * MaintainSelection will track the current selection as being "sticky". + * Dragging or extending selection will never allow for a subset + * (or the whole) of the maintained selection to become unselected. + * Primary use: double click selecting then dragging on second click + */ + nsresult MaintainSelection(); + + + nsFrameSelection(); + virtual ~nsFrameSelection(); + + void StartBatchChanges(); + void EndBatchChanges(); + nsresult DeleteFromDocument(); + + nsIPresShell *GetShell() {return mShell;} + +private: + nsresult TakeFocus(nsIContent *aNewFocus, + PRUint32 aContentOffset, + PRUint32 aContentEndOffset, + PRBool aContinueSelection, + PRBool aMultipleSelection); + + void BidiLevelFromMove(nsIPresShell* aPresShell, + nsIContent *aNode, + PRUint32 aContentOffset, + PRUint32 aKeycode, + HINT aHint); + void BidiLevelFromClick(nsIContent *aNewFocus, PRUint32 aContentOffset); + nsPrevNextBidiLevels GetPrevNextBidiLevels(nsIContent *aNode, + PRUint32 aContentOffset, + HINT aHint, + PRBool aJumpLines); +#ifdef VISUALSELECTION + NS_IMETHOD VisualSelectFrames(nsIFrame* aCurrentFrame, + nsPeekOffsetStruct aPos); + NS_IMETHOD VisualSequence(nsIFrame* aSelectFrame, + nsIFrame* aCurrentFrame, + nsPeekOffsetStruct* aPos, + PRBool* aNeedVisualSelection); + NS_IMETHOD SelectToEdge(nsIFrame *aFrame, + nsIContent *aContent, + PRInt32 aOffset, + PRInt32 aEdge, + PRBool aMultipleSelection); + NS_IMETHOD SelectLines(nsDirection aSelectionDirection, + nsIDOMNode *aAnchorNode, + nsIFrame* aAnchorFrame, + PRInt32 aAnchorOffset, + nsIDOMNode *aCurrentNode, + nsIFrame* aCurrentFrame, + PRInt32 aCurrentOffset, + nsPeekOffsetStruct aPos); +#endif // VISUALSELECTION + + PRBool AdjustForMaintainedSelection(nsIContent *aContent, PRInt32 aOffset); + +// post and pop reasons for notifications. we may stack these later + void PostReason(PRInt16 aReason) { mSelectionChangeReason = aReason; } + PRInt16 PopReason() + { + PRInt16 retval = mSelectionChangeReason; + mSelectionChangeReason = 0; + return retval; + } + + friend class nsTypedSelection; +#ifdef DEBUG + void printSelection(); // for debugging +#endif /* DEBUG */ + + void ResizeBuffer(PRUint32 aNewBufSize); +/*HELPER METHODS*/ + nsresult MoveCaret(PRUint32 aKeycode, PRBool aContinueSelection, nsSelectionAmount aAmount); + + nsresult FetchDesiredX(nscoord &aDesiredX); //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 ConstrainFrameAndPointToAnchorSubtree(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;} + + nsresult NotifySelectionListeners(SelectionType aType); // add parameters to say collapsed etc? + + nsTypedSelection *mDomSelections[nsISelectionController::NUM_SELECTIONTYPES]; + + // Table selection support. + // Interfaces that let us get info based on cellmap locations + nsITableLayout* GetTableLayout(nsIContent *aTableContent); + nsITableCellLayout* GetCellLayout(nsIContent *aCellContent); + + nsresult SelectBlockOfCells(nsIContent *aStartNode, nsIContent *aEndNode); + nsresult SelectRowOrColumn(nsIContent *aCellContent, PRUint32 aTarget); + nsresult GetCellIndexes(nsIContent *aCell, PRInt32 &aRowIndex, PRInt32 &aColIndex); + + nsresult GetFirstSelectedCellAndRange(nsIDOMNode **aCell, nsIDOMRange **aRange); + nsresult GetNextSelectedCellAndRange(nsIDOMNode **aCell, nsIDOMRange **aRange); + nsresult GetFirstCellNodeInRange(nsIDOMRange *aRange, nsIDOMNode **aCellNode); + // 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); + nsresult SelectCellElement(nsIDOMElement* aCellElement); + nsresult CreateAndAddRange(nsIDOMNode *aParentNode, PRInt32 aOffset); + nsresult ClearNormalSelection(); + + nsCOMPtr mCellParent; //used to snap to table selection + nsCOMPtr mStartSelectedCell; + nsCOMPtr mEndSelectedCell; + nsCOMPtr mAppendStartSelectedCell; + nsCOMPtr mUnselectCellOnMouseUp; + PRInt32 mSelectingTableCellMode; + PRInt32 mSelectedCellIndex; + + // maintain selection + nsCOMPtr mMaintainRange; + + //batching + PRInt32 mBatching; + + nsIContent *mLimiter; //limit selection navigation to a child of this node. + nsIPresShell *mShell; + + PRInt16 mSelectionChangeReason; // reason for notifications of selection changing + PRInt16 mDisplaySelection; //for visual display purposes. + + HINT mHint; //hint to tell if the selection is at the end of this line or beginning of next + + PRInt32 mDesiredX; + nsIScrollableView *mScrollView; + + nsMouseEvent mDelayedMouseEvent; + + PRPackedBool mDelayCaretOverExistingSelection; + PRPackedBool mDelayedMouseEventValid; + + PRPackedBool mChangesDuringBatching; + PRPackedBool mNotifyFrames; + PRPackedBool mIsEditor; + PRPackedBool mDragSelectingCells; + PRPackedBool mMouseDownState; //for drag purposes + PRPackedBool mMouseDoubleDownState; //has the doubleclick down happened + PRPackedBool mDesiredXSet; + + PRInt8 mCaretMovementStyle; +}; + +NS_DEFINE_STATIC_IID_ACCESSOR(nsFrameSelection, NS_FRAME_SELECTION_IID) + +#endif /* nsFrameSelection_h___ */ diff --git a/mozilla/layout/generic/nsIFrame.h b/mozilla/layout/generic/nsIFrame.h index 4595b8fa60b..d895e07419e 100644 --- a/mozilla/layout/generic/nsIFrame.h +++ b/mozilla/layout/generic/nsIFrame.h @@ -1313,9 +1313,9 @@ public: NS_IMETHOD GetSelectionController(nsPresContext *aPresContext, nsISelectionController **aSelCon) = 0; /** - * Call to get nsIFrameSelection for this frame; does not addref + * Call to get nsFrameSelection for this frame; does not addref */ - nsIFrameSelection* GetFrameSelection(); + nsFrameSelection* GetFrameSelection(); /** EndSelection related calls */ @@ -1333,7 +1333,7 @@ public: * nsIFrame and the frame offset. THIS DOES NOT CHANGE SELECTION STATE * uses frame's begin selection state to start. if no selection on this frame will * return NS_ERROR_FAILURE - * @param aPOS is defined in nsIFrameSelection + * @param aPOS is defined in nsFrameSelection */ NS_IMETHOD PeekOffset(nsPresContext* aPresContext, nsPeekOffsetStruct *aPos) = 0; diff --git a/mozilla/layout/generic/nsSelection.cpp b/mozilla/layout/generic/nsSelection.cpp index bc136123652..62f56834f0e 100644 --- a/mozilla/layout/generic/nsSelection.cpp +++ b/mozilla/layout/generic/nsSelection.cpp @@ -38,7 +38,7 @@ * ***** END LICENSE BLOCK ***** */ /* - * Implementation of selection: nsISelection,nsISelectionPrivate and nsIFrameSelection + * Implementation of selection: nsISelection,nsISelectionPrivate and nsFrameSelection */ #include "nsCOMPtr.h" @@ -48,7 +48,7 @@ #include "nsString.h" #include "nsReadableUtils.h" #include "nsIDOMRange.h" -#include "nsIFrameSelection.h" +#include "nsFrameSelection.h" #include "nsISelection.h" #include "nsISelectionPrivate.h" #include "nsISelectionListener.h" @@ -143,12 +143,12 @@ static NS_DEFINE_IID(kCSubtreeIteratorCID, NS_SUBTREEITERATOR_CID); //PROTOTYPES class nsSelectionIterator; -class nsSelection; +class nsFrameSelection; class nsAutoScrollTimer; struct nsScrollSelectionIntoViewEvent; -PRBool IsValidSelectionPoint(nsSelection *aFrameSel, nsIContent *aContent); -PRBool IsValidSelectionPoint(nsSelection *aFrameSel, nsIDOMNode *aDomNode); +PRBool IsValidSelectionPoint(nsFrameSelection *aFrameSel, nsIContent *aContent); +PRBool IsValidSelectionPoint(nsFrameSelection *aFrameSel, nsIDOMNode *aDomNode); static nsIAtom *GetTag(nsIDOMNode *aNode); static nsresult ParentOffset(nsIDOMNode *aNode, nsIDOMNode **aParent, PRInt32 *aChildOffset); @@ -191,7 +191,7 @@ class nsTypedSelection : public nsISelection, { public: nsTypedSelection(); - nsTypedSelection(nsSelection *aList); + nsTypedSelection(nsFrameSelection *aList); virtual ~nsTypedSelection(); NS_DECL_ISUPPORTS @@ -282,7 +282,7 @@ private: nsDirection mDirection; //FALSE = focus, anchor; TRUE = anchor, focus PRBool mFixupState; //was there a fixup? - nsSelection *mFrameSelection; + nsFrameSelection *mFrameSelection; nsWeakPtr mPresShellWeak; //weak reference to presshell. SelectionType mType;//type of this nsTypedSelection; nsAutoScrollTimer *mAutoScrollTimer; // timer for autoscrolling. @@ -309,226 +309,6 @@ public: } }; -class nsSelection : public nsIFrameSelection - -{ -public: - /*interfaces for addref and release and queryinterface*/ - - NS_DECL_ISUPPORTS - -/*BEGIN nsIFrameSelection interfaces*/ - NS_IMETHOD Init(nsIPresShell *aShell, nsIContent *aLimiter); - NS_IMETHOD SetScrollableView(nsIScrollableView *aScrollView); - NS_IMETHOD GetScrollableView(nsIScrollableView **aScrollView) {*aScrollView = mScrollView; return NS_OK;} - - NS_IMETHOD ShutDown(); - NS_IMETHOD HandleTextEvent(nsGUIEvent *aGUIEvent); - NS_IMETHOD HandleKeyEvent(nsPresContext* aPresContext, nsGUIEvent *aGuiEvent); - NS_IMETHOD HandleClick(nsIContent *aNewFocus, PRUint32 aContentOffset, PRUint32 aContentEndOffset, - PRBool aContinueSelection, PRBool aMultipleSelection,PRBool aHint); - NS_IMETHOD HandleDrag(nsPresContext *aPresContext, nsIFrame *aFrame, nsPoint& aPoint); - NS_IMETHOD HandleTableSelection(nsIContent *aParentContent, PRInt32 aContentOffset, PRInt32 aTarget, nsMouseEvent *aMouseEvent); - NS_IMETHOD StartAutoScrollTimer(nsPresContext *aPresContext, nsIView *aView, 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); - - NS_IMETHOD GetTableCellSelection(PRBool *aState){if (aState){*aState = mSelectingTableCellMode != 0; return NS_OK;}return NS_ERROR_NULL_POINTER;} - NS_IMETHOD ClearTableCellSelection(){mSelectingTableCellMode = 0; return NS_OK;} - - NS_IMETHOD GetSelection(SelectionType aType, nsISelection **aDomSelection); - NS_IMETHOD ScrollSelectionIntoView(SelectionType aType, SelectionRegion aRegion, PRBool aIsSynchronous); - NS_IMETHOD RepaintSelection(nsPresContext* aPresContext, SelectionType aType); - NS_IMETHOD GetFrameForNodeOffset(nsIContent *aNode, PRInt32 aOffset, HINT aHint, nsIFrame **aReturnFrame, PRInt32 *aReturnOffset); - NS_IMETHOD CommonPageMove(PRBool aForward, PRBool aExtend, nsIScrollableView *aScrollableView, nsIFrameSelection *aFrameSel); - - NS_IMETHOD SetHint(HINT aHintRight); - NS_IMETHOD GetHint(HINT *aHintRight); - NS_IMETHOD CharacterMove(PRBool aForward, PRBool aExtend); - NS_IMETHOD WordMove(PRBool aForward, PRBool aExtend); - NS_IMETHOD LineMove(PRBool aForward, PRBool aExtend); - NS_IMETHOD IntraLineMove(PRBool aForward, PRBool aExtend); - NS_IMETHOD SelectAll(); - NS_IMETHOD SetDisplaySelection(PRInt16 aState); - NS_IMETHOD GetDisplaySelection(PRInt16 *aState); - NS_IMETHOD SetDelayCaretOverExistingSelection(PRBool aDelay); - NS_IMETHOD GetDelayCaretOverExistingSelection(PRBool *aDelay); - NS_IMETHOD SetDelayedCaretData(nsMouseEvent *aMouseEvent); - NS_IMETHOD GetDelayedCaretData(nsMouseEvent **aMouseEvent); - NS_IMETHOD GetLimiter(nsIContent **aLimiterContent); - NS_IMETHOD SetMouseDoubleDown(PRBool aDoubleDown); - NS_IMETHOD GetMouseDoubleDown(PRBool *aDoubleDown); - NS_IMETHOD GetPrevNextBidiLevels(nsPresContext *aPresContext, - nsIContent *aNode, - PRUint32 aContentOffset, - PRBool aJumpLines, - nsIFrame **aPrevFrame, - nsIFrame **aNextFrame, - PRUint8 *aPrevLevel, - PRUint8 *aNextLevel); - NS_IMETHOD GetFrameFromLevel(nsPresContext *aPresContext, - nsIFrame *aFrameIn, - nsDirection aDirection, - PRUint8 aBidiLevel, - nsIFrame **aFrameOut); - NS_IMETHOD MaintainSelection(); - /*END nsIFrameSelection interfaces */ - - - - nsSelection(); - virtual ~nsSelection(); - - NS_IMETHOD StartBatchChanges(); - NS_IMETHOD EndBatchChanges(); - NS_IMETHOD DeleteFromDocument(); - - nsIPresShell *GetShell() {return mShell;} - -private: - NS_IMETHOD TakeFocus(nsIContent *aNewFocus, PRUint32 aContentOffset, PRUint32 aContentEndOffset, - PRBool aContinueSelection, PRBool aMultipleSelection); - - void BidiLevelFromMove(nsPresContext* aContext, - nsIPresShell* aPresShell, - nsIContent *aNode, - PRUint32 aContentOffset, - PRUint32 aKeycode, - HINT aHint); - void BidiLevelFromClick(nsIContent *aNewFocus, PRUint32 aContentOffset); - NS_IMETHOD GetPrevNextBidiLevels(nsPresContext *aPresContext, - nsIContent *aNode, - PRUint32 aContentOffset, - HINT aHint, - PRBool aJumpLines, - nsIFrame **aPrevFrame, - nsIFrame **aNextFrame, - PRUint8 *aPrevLevel, - PRUint8 *aNextLevel); -#ifdef VISUALSELECTION - NS_IMETHOD VisualSelectFrames(nsPresContext* aContext, - nsIFrame* aCurrentFrame, - nsPeekOffsetStruct aPos); - NS_IMETHOD VisualSequence(nsPresContext *aPresContext, - nsIFrame* aSelectFrame, - nsIFrame* aCurrentFrame, - nsPeekOffsetStruct* aPos, - PRBool* aNeedVisualSelection); - NS_IMETHOD SelectToEdge(nsIFrame *aFrame, - nsIContent *aContent, - PRInt32 aOffset, - PRInt32 aEdge, - PRBool aMultipleSelection); - NS_IMETHOD SelectLines(nsPresContext *aPresContext, - nsDirection aSelectionDirection, - nsIDOMNode *aAnchorNode, - nsIFrame* aAnchorFrame, - PRInt32 aAnchorOffset, - nsIDOMNode *aCurrentNode, - nsIFrame* aCurrentFrame, - PRInt32 aCurrentOffset, - nsPeekOffsetStruct aPos); -#endif // VISUALSELECTION - - PRBool AdjustForMaintainedSelection(nsIContent *aContent, PRInt32 aOffset); - -// post and pop reasons for notifications. we may stack these later - void PostReason(PRInt16 aReason) { mSelectionChangeReason = aReason; } - PRInt16 PopReason() - { - PRInt16 retval = mSelectionChangeReason; - mSelectionChangeReason = 0; - return retval; - } - - friend class nsTypedSelection; -#ifdef DEBUG - void printSelection(); // for debugging -#endif /* DEBUG */ - - void ResizeBuffer(PRUint32 aNewBufSize); -/*HELPER METHODS*/ - nsresult MoveCaret(PRUint32 aKeycode, PRBool aContinueSelection, nsSelectionAmount aAmount); - - nsresult FetchDesiredX(nscoord &aDesiredX); //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 ConstrainFrameAndPointToAnchorSubtree(nsPresContext *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;} - - nsresult NotifySelectionListeners(SelectionType aType); // add parameters to say collapsed etc? - - nsTypedSelection *mDomSelections[nsISelectionController::NUM_SELECTIONTYPES]; - - // Table selection support. - // Interfaces that let us get info based on cellmap locations - nsITableLayout* GetTableLayout(nsIContent *aTableContent); - nsITableCellLayout* GetCellLayout(nsIContent *aCellContent); - - nsresult SelectBlockOfCells(nsIContent *aStartNode, nsIContent *aEndNode); - nsresult SelectRowOrColumn(nsIContent *aCellContent, PRUint32 aTarget); - nsresult GetCellIndexes(nsIContent *aCell, PRInt32 &aRowIndex, PRInt32 &aColIndex); - - nsresult GetFirstSelectedCellAndRange(nsIDOMNode **aCell, nsIDOMRange **aRange); - nsresult GetNextSelectedCellAndRange(nsIDOMNode **aCell, nsIDOMRange **aRange); - nsresult GetFirstCellNodeInRange(nsIDOMRange *aRange, nsIDOMNode **aCellNode); - // 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); - nsresult SelectCellElement(nsIDOMElement* aCellElement); - nsresult CreateAndAddRange(nsIDOMNode *aParentNode, PRInt32 aOffset); - nsresult ClearNormalSelection(); - - nsCOMPtr mCellParent; //used to snap to table selection - nsCOMPtr mStartSelectedCell; - nsCOMPtr mEndSelectedCell; - nsCOMPtr mAppendStartSelectedCell; - nsCOMPtr mUnselectCellOnMouseUp; - PRInt32 mSelectingTableCellMode; - PRInt32 mSelectedCellIndex; - - // maintain selection - nsCOMPtr mMaintainRange; - - //batching - PRInt32 mBatching; - - nsIContent *mLimiter; //limit selection navigation to a child of this node. - nsIPresShell *mShell; - - PRInt16 mSelectionChangeReason; // reason for notifications of selection changing - PRInt16 mDisplaySelection; //for visual display purposes. - - HINT mHint; //hint to tell if the selection is at the end of this line or beginning of next - - PRInt32 mDesiredX; - nsIScrollableView *mScrollView; - - nsMouseEvent mDelayedMouseEvent; - - PRPackedBool mDelayCaretOverExistingSelection; - PRPackedBool mDelayedMouseEventValid; - - PRPackedBool mChangesDuringBatching; - PRPackedBool mNotifyFrames; - PRPackedBool mIsEditor; - PRPackedBool mDragSelectingCells; - PRPackedBool mMouseDownState; //for drag purposes - PRPackedBool mMouseDoubleDownState; //has the doubleclick down happened - PRPackedBool mDesiredXSet; - - PRInt8 mCaretMovementStyle; -}; - class nsSelectionIterator : public nsIBidirectionalEnumerator { public: @@ -549,7 +329,7 @@ private: friend class nsTypedSelection; //lame lame lame if delete from document goes away then get rid of this unless its debug - friend class nsSelection; + friend class nsFrameSelection; nsSelectionIterator(nsTypedSelection *); virtual ~nsSelectionIterator(); @@ -606,7 +386,7 @@ public: return result; } - nsresult Init(nsSelection *aFrameSelection, nsTypedSelection *aSelection) + nsresult Init(nsFrameSelection *aFrameSelection, nsTypedSelection *aSelection) { mFrameSelection = aFrameSelection; mSelection = aSelection; @@ -628,14 +408,14 @@ public: if (!frame) return NS_OK; - mFrameSelection->HandleDrag(mPresContext, frame, mPoint); + mFrameSelection->HandleDrag(frame, mPoint); mSelection->DoAutoScrollView(mPresContext, mView, mPoint, PR_TRUE); } return NS_OK; } private: - nsSelection *mFrameSelection; + nsFrameSelection *mFrameSelection; nsTypedSelection *mSelection; nsCOMPtr mTimer; nsIView *mView; @@ -665,14 +445,14 @@ nsresult NS_NewAutoScrollTimer(nsAutoScrollTimer **aResult) return NS_OK; } -nsresult NS_NewSelection(nsIFrameSelection **aFrameSelection); +nsresult NS_NewSelection(nsFrameSelection **aFrameSelection); -nsresult NS_NewSelection(nsIFrameSelection **aFrameSelection) +nsresult NS_NewSelection(nsFrameSelection **aFrameSelection) { - nsSelection *rlist = new nsSelection; + nsFrameSelection *rlist = new nsFrameSelection; if (!rlist) return NS_ERROR_OUT_OF_MEMORY; - *aFrameSelection = (nsIFrameSelection *)rlist; + *aFrameSelection = rlist; NS_ADDREF(rlist); return NS_OK; } @@ -728,13 +508,12 @@ GetSelectionTypeFromIndex(PRInt8 aIndex) //utility methods to check the content vs the limiter that will hold selection to a piece of the dom PRBool -IsValidSelectionPoint(nsSelection *aFrameSel, nsIDOMNode *aDomNode) +IsValidSelectionPoint(nsFrameSelection *aFrameSel, nsIDOMNode *aDomNode) { - nsCOMPtr passedContent; - passedContent = do_QueryInterface(aDomNode); + nsCOMPtr passedContent = do_QueryInterface(aDomNode); if (!passedContent) return PR_FALSE; - return IsValidSelectionPoint(aFrameSel,passedContent); + return IsValidSelectionPoint(aFrameSel, passedContent); } /* @@ -751,17 +530,13 @@ NO limiter all points are valid since you are in a topmost iframe. (browser or composer) */ PRBool -IsValidSelectionPoint(nsSelection *aFrameSel, nsIContent *aContent) +IsValidSelectionPoint(nsFrameSelection *aFrameSel, nsIContent *aContent) { if (!aFrameSel || !aContent) return PR_FALSE; if (aFrameSel) { - nsresult result; - nsCOMPtr tLimiter; - result = aFrameSel->GetLimiter(getter_AddRefs(tLimiter)); - if (NS_FAILED(result)) - return PR_FALSE; + nsCOMPtr tLimiter = aFrameSel->GetLimiter(); if (tLimiter && tLimiter != aContent) { if (tLimiter != aContent->GetParent()) //if newfocus == the limiter. that's ok. but if not there and not parent bad @@ -788,7 +563,7 @@ nsSelectionIterator::nsSelectionIterator(nsTypedSelection *aList) { if (!aList) { - NS_NOTREACHED("nsSelection"); + NS_NOTREACHED("nsFrameSelection"); return; } mDomSelection = aList; @@ -804,7 +579,7 @@ nsSelectionIterator::~nsSelectionIterator() ////////////END nsSelectionIterator methods -////////////BEGIN nsIFrameSelectionIterator methods +////////////BEGIN nsSelectionIterator methods @@ -895,15 +670,15 @@ nsSelectionIterator::IsDone() } -////////////END nsIFrameSelectionIterator methods +////////////END nsSelectionIterator methods #ifdef XP_MAC #pragma mark - #endif -////////////BEGIN nsSelection methods +////////////BEGIN nsFrameSelection methods -nsSelection::nsSelection() +nsFrameSelection::nsFrameSelection() : mDelayedMouseEvent(PR_FALSE, 0, nsnull, nsMouseEvent::eReal) { PRInt32 i; @@ -951,7 +726,7 @@ nsSelection::nsSelection() } -nsSelection::~nsSelection() +nsFrameSelection::~nsFrameSelection() { PRInt32 i; for (i = 0;imessage) { - PRInt8 index = GetIndexFromSelectionType(nsISelectionController::SELECTION_NORMAL); - result = mDomSelections[index]->ScrollIntoView(); - } - return result; -} - - nsresult -nsSelection::MoveCaret(PRUint32 aKeycode, PRBool aContinueSelection, nsSelectionAmount aAmount) +nsFrameSelection::MoveCaret(PRUint32 aKeycode, + PRBool aContinueSelection, + nsSelectionAmount aAmount) { nsPresContext *context = mShell->GetPresContext(); if (!context) @@ -1454,8 +1201,11 @@ nsSelection::MoveCaret(PRUint32 aKeycode, PRBool aContinueSelection, nsSelection // For up/down and home/end, pos.mResultFrame might not be set correctly, or not at all. // In these cases, get the frame based on the content and hint returned by PeekOffset(). tHint = (HINT)pos.mPreferLeft; - result = GetFrameForNodeOffset(pos.mResultContent, pos.mContentOffset, tHint, &theFrame, ¤tOffset); - NS_ENSURE_SUCCESS(result, result); + theFrame = GetFrameForNodeOffset(pos.mResultContent, pos.mContentOffset, + tHint, ¤tOffset); + if (!theFrame) + return NS_ERROR_FAILURE; + theFrame->GetOffsets(frameStart, frameEnd); } @@ -1476,13 +1226,13 @@ nsSelection::MoveCaret(PRUint32 aKeycode, PRBool aContinueSelection, nsSelection mShell->SetCaretBidiLevel(NS_GET_EMBEDDING_LEVEL(theFrame)); } else - BidiLevelFromMove(context, mShell, pos.mResultContent, pos.mContentOffset, aKeycode, tHint); + BidiLevelFromMove(mShell, pos.mResultContent, pos.mContentOffset, aKeycode, tHint); } #ifdef VISUALSELECTION // Handle visual selection if (aContinueSelection) { - result = VisualSelectFrames(context, theFrame, pos); + result = VisualSelectFrames(theFrame, pos); if (NS_FAILED(result)) // Back out by collapsing the selection to the current position result = TakeFocus(pos.mResultContent, pos.mContentOffset, pos.mContentOffset, PR_FALSE, PR_FALSE); } @@ -1509,53 +1259,10 @@ nsSelection::MoveCaret(PRUint32 aKeycode, PRBool aContinueSelection, nsSelection return result; } +//END nsFrameSelection methods -/** 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(nsPresContext* 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 platform 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 +//BEGIN nsFrameSelection methods NS_IMETHODIMP nsTypedSelection::ToString(PRUnichar **aReturn) @@ -1609,12 +1316,14 @@ nsTypedSelection::SetInterlinePosition(PRBool aHintRight) { if (!mFrameSelection) return NS_ERROR_NOT_INITIALIZED; // Can't do selection - nsIFrameSelection::HINT hint; + nsFrameSelection::HINT hint; if (aHintRight) - hint = nsIFrameSelection::HINTRIGHT; + hint = nsFrameSelection::HINTRIGHT; else - hint = nsIFrameSelection::HINTLEFT; - return mFrameSelection->SetHint(hint); + hint = nsFrameSelection::HINTLEFT; + mFrameSelection->SetHint(hint); + + return NS_OK; } NS_IMETHODIMP @@ -1622,13 +1331,8 @@ nsTypedSelection::GetInterlinePosition(PRBool *aHintRight) { if (!mFrameSelection) return NS_ERROR_NOT_INITIALIZED; // Can't do selection - nsIFrameSelection::HINT hint; - nsresult rv = mFrameSelection->GetHint(&hint); - if (hint == nsIFrameSelection::HINTRIGHT) - *aHintRight = PR_TRUE; - else - *aHintRight = PR_FALSE; - return rv; + *aHintRight = (mFrameSelection->GetHint() == nsFrameSelection::HINTRIGHT); + return NS_OK; } #ifdef VISUALSELECTION @@ -1661,19 +1365,20 @@ FindLineContaining(nsIFrame* aFrame, nsIFrame** aBlock, PRInt32* aLine) } NS_IMETHODIMP -nsSelection::VisualSequence(nsPresContext *aPresContext, - nsIFrame* aSelectFrame, - nsIFrame* aCurrentFrame, - nsPeekOffsetStruct* aPos, - PRBool* aNeedVisualSelection) +nsFrameSelection::VisualSequence(nsIFrame* aSelectFrame, + nsIFrame* aCurrentFrame, + nsPeekOffsetStruct* aPos, + PRBool* aNeedVisualSelection) { nsVoidArray frameArray; PRInt32 frameStart, frameEnd; PRInt8 index = GetIndexFromSelectionType(nsISelectionController::SELECTION_NORMAL); nsresult result = nsnull; + nsPresContext* presContext = mShell->GetPresContext(); + PRUint8 currentLevel = NS_GET_EMBEDDING_LEVEL(aCurrentFrame); - result = aSelectFrame->PeekOffset(aPresContext, aPos); + result = aSelectFrame->PeekOffset(presContext, aPos); while (aCurrentFrame != (aSelectFrame = aPos->mResultFrame)) { if (NS_FAILED(result)) @@ -1706,14 +1411,18 @@ nsSelection::VisualSequence(nsPresContext *aPresContext, aPos->mAmount = eSelectDir; // reset this because PeekOffset will have changed it to eSelectNoAmount aPos->mContentOffset = 0; - result = aSelectFrame->PeekOffset(aPresContext, aPos); + result = aSelectFrame->PeekOffset(presContext, aPos); } return NS_OK; } NS_IMETHODIMP -nsSelection::SelectToEdge(nsIFrame *aFrame, nsIContent *aContent, PRInt32 aOffset, PRInt32 aEdge, PRBool aMultipleSelection) +nsFrameSelection::SelectToEdge(nsIFrame *aFrame, + nsIContent *aContent, + PRInt32 aOffset, + PRInt32 aEdge, + PRBool aMultipleSelection) { PRInt32 frameStart, frameEnd; @@ -1730,15 +1439,14 @@ nsSelection::SelectToEdge(nsIFrame *aFrame, nsIContent *aContent, PRInt32 aOffse } NS_IMETHODIMP -nsSelection::SelectLines(nsPresContext *aPresContext, - nsDirection aSelectionDirection, - nsIDOMNode *aAnchorNode, - nsIFrame* aAnchorFrame, - PRInt32 aAnchorOffset, - nsIDOMNode *aCurrentNode, - nsIFrame* aCurrentFrame, - PRInt32 aCurrentOffset, - nsPeekOffsetStruct aPos) +nsFrameSelection::SelectLines(nsDirection aSelectionDirection, + nsIDOMNode *aAnchorNode, + nsIFrame* aAnchorFrame, + PRInt32 aAnchorOffset, + nsIDOMNode *aCurrentNode, + nsIFrame* aCurrentFrame, + PRInt32 aCurrentOffset, + nsPeekOffsetStruct aPos) { nsIFrame *startFrame, *endFrame; PRInt32 startOffset, endOffset; @@ -1772,27 +1480,31 @@ nsSelection::SelectLines(nsPresContext *aPresContext, endFrame = aAnchorFrame; endOffset = aAnchorOffset; } + + nsPresContext* presContext = mShell->GetPresContext(); aPos.mStartOffset = startOffset; aPos.mDirection = eDirNext; aPos.mAmount = eSelectLine; - result = startFrame->PeekOffset(aPresContext, &aPos); + result = startFrame->PeekOffset(presContext, &aPos); if (NS_FAILED(result)) return result; startFrame = aPos.mResultFrame; aPos.mStartOffset = aPos.mContentOffset; aPos.mAmount = eSelectBeginLine; - result = startFrame->PeekOffset(aPresContext, &aPos); + result = startFrame->PeekOffset(presContext, &aPos); if (NS_FAILED(result)) return result; nsIFrame *theFrame; PRInt32 currentOffset, frameStart, frameEnd; - result = GetFrameForNodeOffset(aPos.mResultContent, aPos.mContentOffset, HINTLEFT, &theFrame, ¤tOffset); - if (NS_FAILED(result)) - return result; + theFrame = GetFrameForNodeOffset(aPos.mResultContent, aPos.mContentOffset, + HINTLEFT, ¤tOffset); + if (!theFrame) + return NS_ERROR_FAILURE; + theFrame->GetOffsets(frameStart, frameEnd); startOffset = frameStart; startContent = aPos.mResultContent; @@ -1805,20 +1517,22 @@ nsSelection::SelectLines(nsPresContext *aPresContext, aPos.mStartOffset = endOffset; aPos.mDirection = eDirPrevious; aPos.mAmount = eSelectLine; - result = endFrame->PeekOffset(aPresContext, &aPos); + result = endFrame->PeekOffset(presContext, &aPos); if (NS_FAILED(result)) return result; endFrame = aPos.mResultFrame; aPos.mStartOffset = aPos.mContentOffset; aPos.mAmount = eSelectEndLine; - result = endFrame->PeekOffset(aPresContext, &aPos); + result = endFrame->PeekOffset(presContext, &aPos); if (NS_FAILED(result)) return result; - result = GetFrameForNodeOffset(aPos.mResultContent, aPos.mContentOffset, HINTRIGHT, &theFrame, ¤tOffset); - if (NS_FAILED(result)) - return result; + theFrame = GetFrameForNodeOffset(aPos.mResultContent, aPos.mContentOffset, + HINTRIGHT, ¤tOffset); + if (!theFrame) + return NS_ERROR_FAILURE; + theFrame->GetOffsets(frameStart, frameEnd); endOffset = frameEnd; endContent = aPos.mResultContent; @@ -1834,9 +1548,8 @@ nsSelection::SelectLines(nsPresContext *aPresContext, } NS_IMETHODIMP -nsSelection::VisualSelectFrames(nsPresContext *aPresContext, - nsIFrame* aCurrentFrame, - nsPeekOffsetStruct aPos) +nsFrameSelection::VisualSelectFrames(nsIFrame* aCurrentFrame, + nsPeekOffsetStruct aPos) { nsCOMPtr anchorContent; nsCOMPtr anchorNode; @@ -1854,14 +1567,18 @@ nsSelection::VisualSelectFrames(nsPresContext *aPresContext, PRBool needVisualSelection = PR_FALSE; nsDirection selectionDirection; PRInt8 index = GetIndexFromSelectionType(nsISelectionController::SELECTION_NORMAL); + + nsPresContext* presContext = mShell->GetPresContext(); result = mDomSelections[index]->GetOriginalAnchorPoint(getter_AddRefs(anchorNode), &anchorOffset); if (NS_FAILED(result)) return result; anchorContent = do_QueryInterface(anchorNode); - result = GetFrameForNodeOffset(anchorContent, anchorOffset, mHint, &anchorFrame, &anchorOffset); - if (NS_FAILED(result)) - return result; + anchorFrame = GetFrameForNodeOffset(anchorContent, anchorOffset, + mHint, &anchorOffset); + if (!anchorFrame) + return NS_ERROR_FAILURE; + PRUint8 anchorLevel = NS_GET_EMBEDDING_LEVEL(anchorFrame); currentContent = aPos.mResultContent; @@ -1885,9 +1602,11 @@ nsSelection::VisualSelectFrames(nsPresContext *aPresContext, else hint = HINTLEFT; - result = GetFrameForNodeOffset(focusContent, focusOffset, hint, &focusFrame, &focusOffset); - if (NS_FAILED(result)) - return result; + focusFrame = GetFrameForNodeOffset(focusContent, focusOffset, + hint, &focusOffset); + if (!focusFrame) + return NS_ERROR_FAILURE; + PRUint8 focusLevel = NS_GET_EMBEDDING_LEVEL(focusFrame); if (currentLevel != anchorLevel) @@ -1926,12 +1645,12 @@ nsSelection::VisualSelectFrames(nsPresContext *aPresContext, aPos.mStartOffset = anchorOffset; aPos.mDirection = selectionDirection; - result = anchorFrame->PeekOffset(aPresContext, &aPos); + result = anchorFrame->PeekOffset(presContext, &aPos); if (NS_FAILED(result)) return result; startFrame = aPos.mResultFrame; - result = VisualSequence(aPresContext, startFrame, aCurrentFrame, &aPos, &needVisualSelection); + result = VisualSequence(startFrame, aCurrentFrame, &aPos, &needVisualSelection); if (NS_FAILED(result)) return result; @@ -1987,15 +1706,15 @@ nsSelection::VisualSelectFrames(nsPresContext *aPresContext, aPos.mDirection = selectionDirection; if (anchorBaseLevel & 1) aPos.mDirection = ReverseDirection(aPos.mDirection); - result = VisualSequence(aPresContext, anchorFrame, aCurrentFrame, &aPos, &needVisualSelection); + result = VisualSequence(anchorFrame, aCurrentFrame, &aPos, &needVisualSelection); if (NS_FAILED(result)) return result; // Select all the lines between the line containing the anchor point and the line containing the current point aPos.mJumpLines = PR_TRUE; - result = SelectLines(aPresContext, selectionDirection, - anchorNode, anchorFrame, anchorOffset, - currentNode, aCurrentFrame, currentOffset, aPos); + result = SelectLines(selectionDirection, anchorNode, anchorFrame, + anchorOffset, currentNode, aCurrentFrame, currentOffset, + aPos); if (NS_FAILED(result)) return result; @@ -2006,7 +1725,7 @@ nsSelection::VisualSelectFrames(nsPresContext *aPresContext, if ((currentBaseLevel & 1) == (anchorBaseLevel & 1)) aPos.mDirection = ReverseDirection(aPos.mDirection); aPos.mStartOffset = currentOffset; - result = VisualSequence(aPresContext, aCurrentFrame, anchorFrame, &aPos, &needVisualSelection); + result = VisualSequence(aCurrentFrame, anchorFrame, &aPos, &needVisualSelection); if (NS_FAILED(result)) return result; @@ -2034,45 +1753,34 @@ nsSelection::VisualSelectFrames(nsPresContext *aPresContext, } #endif // VISUALSELECTION -NS_IMETHODIMP -nsSelection::GetPrevNextBidiLevels(nsPresContext *aPresContext, - nsIContent *aNode, - PRUint32 aContentOffset, - PRBool aJumpLines, - nsIFrame **aPrevFrame, - nsIFrame **aNextFrame, - PRUint8 *aPrevLevel, - PRUint8 *aNextLevel) +nsPrevNextBidiLevels +nsFrameSelection::GetPrevNextBidiLevels(nsIContent *aNode, + PRUint32 aContentOffset, + PRBool aJumpLines) { - return GetPrevNextBidiLevels(aPresContext, aNode, aContentOffset, mHint, aJumpLines, - aPrevFrame, aNextFrame, aPrevLevel, aNextLevel); + return GetPrevNextBidiLevels(aNode, aContentOffset, mHint, aJumpLines); } -NS_IMETHODIMP -nsSelection::GetPrevNextBidiLevels(nsPresContext *aPresContext, - nsIContent *aNode, - PRUint32 aContentOffset, - HINT aHint, - PRBool aJumpLines, - nsIFrame **aPrevFrame, - nsIFrame **aNextFrame, - PRUint8 *aPrevLevel, - PRUint8 *aNextLevel) +nsPrevNextBidiLevels +nsFrameSelection::GetPrevNextBidiLevels(nsIContent *aNode, + PRUint32 aContentOffset, + HINT aHint, + PRBool aJumpLines) { - if (!aPrevFrame || !aNextFrame) - return NS_ERROR_NULL_POINTER; // Get the level of the frames on each side nsIFrame *currentFrame; PRInt32 currentOffset; PRInt32 frameStart, frameEnd; nsDirection direction; - nsresult result; + + nsPrevNextBidiLevels levels; + levels.SetData(nsnull, nsnull, 0, 0); - *aPrevLevel = *aNextLevel = 0; + currentFrame = GetFrameForNodeOffset(aNode, aContentOffset, + aHint, ¤tOffset); + if (!currentFrame) + return levels; - result = GetFrameForNodeOffset(aNode, aContentOffset, aHint, ¤tFrame, ¤tOffset); - if (NS_FAILED(result)) - return result; currentFrame->GetOffsets(frameStart, frameEnd); if (0 == frameStart && 0 == frameEnd) @@ -2083,9 +1791,10 @@ nsSelection::GetPrevNextBidiLevels(nsPresContext *aPresContext, direction = eDirNext; else { // we are neither at the beginning nor at the end of the frame, so we have no worries - *aPrevFrame = *aNextFrame = currentFrame; - *aPrevLevel = *aNextLevel = NS_GET_EMBEDDING_LEVEL(currentFrame); - return NS_OK; + levels.SetData(currentFrame, currentFrame, + NS_GET_EMBEDDING_LEVEL(currentFrame), + NS_GET_EMBEDDING_LEVEL(currentFrame)); + return levels; } /* @@ -2103,23 +1812,24 @@ nsSelection::GetPrevNextBidiLevels(nsPresContext *aPresContext, PRInt32 thisLine; nsILineIteratorNavigator* it; // This is qi'd off a frame, and those aren't // refcounted - result = NS_ERROR_FAILURE; - while (NS_FAILED(result) && blockFrame) + nsresult rv = NS_ERROR_FAILURE; + while (NS_FAILED(rv) && blockFrame) { thisBlock = blockFrame; blockFrame = blockFrame->GetParent(); if (blockFrame) { - result = CallQueryInterface(blockFrame, &it); + rv = CallQueryInterface(blockFrame, &it); } } - if (!blockFrame || !it) - return NS_ERROR_FAILURE; - result = it->FindLineContaining(thisBlock, &thisLine); - if (NS_FAILED(result)) - return result; - if (thisLine < 0) - return NS_ERROR_FAILURE; + if (!blockFrame || !it) + return levels; + + if (NS_FAILED(it->FindLineContaining(thisBlock, &thisLine))) + return levels; + + if (thisLine < 0) + return levels; nsIFrame *firstFrame; nsIFrame *lastFrame; @@ -2127,10 +1837,9 @@ nsSelection::GetPrevNextBidiLevels(nsPresContext *aPresContext, PRInt32 lineFrameCount; PRUint32 lineFlags; - result = it->GetLine(thisLine, &firstFrame, &lineFrameCount,nonUsedRect, - &lineFlags); - if (NS_FAILED(result)) - return result; + if (NS_FAILED(it->GetLine(thisLine, &firstFrame, + &lineFrameCount, nonUsedRect, &lineFlags))) + return levels; lastFrame = firstFrame; @@ -2162,42 +1871,41 @@ nsSelection::GetPrevNextBidiLevels(nsPresContext *aPresContext, // set aPrevLevel to the embedding level of the current frame // set aNextFrame to null // set aNextLevel to the paragraph embedding level - *aPrevFrame = currentFrame; - *aPrevLevel = NS_GET_EMBEDDING_LEVEL(currentFrame); - *aNextLevel = NS_GET_BASE_LEVEL(currentFrame); - *aNextFrame = nsnull; - return NS_OK; + levels.SetData(currentFrame, nsnull, + NS_GET_EMBEDDING_LEVEL(currentFrame), + NS_GET_BASE_LEVEL(currentFrame)); + return levels; } if (direction == eDirPrevious && firstFrame == currentFrame) { // Beginning of line: set aPrevFrame to null // set aPrevLevel to the paragraph embedding level // set aNextFrame to the current frame // set aNextLevel to the embedding level of the current frame - *aNextFrame = currentFrame; - *aNextLevel = NS_GET_EMBEDDING_LEVEL(currentFrame); - *aPrevLevel = NS_GET_BASE_LEVEL(currentFrame); - *aPrevFrame = nsnull; - return NS_OK; + levels.SetData(nsnull, currentFrame, + NS_GET_EMBEDDING_LEVEL(currentFrame), + NS_GET_BASE_LEVEL(currentFrame)); + return levels; } } //if (!aJumpLines) // Find the adjacent frame nsCOMPtr frameTraversal; - result = NS_NewFrameTraversal(getter_AddRefs(frameTraversal),LEAF, aPresContext, currentFrame, PR_TRUE); - if (NS_FAILED(result)) - return result; - - nsISupports *isupports = nsnull; - if (direction == eDirNext) - result = frameTraversal->Next(); - else - result = frameTraversal->Prev(); + if (NS_FAILED(NS_NewFrameTraversal(getter_AddRefs(frameTraversal), + LEAF, mShell->GetPresContext(), + currentFrame, PR_TRUE))) + return levels; - if (NS_SUCCEEDED(result)) { - result = frameTraversal->CurrentItem(&isupports); - if (NS_FAILED(result)) - return result; + nsresult rv; + if (direction == eDirNext) + rv = frameTraversal->Next(); + else + rv = frameTraversal->Prev(); + + nsISupports *isupports = nsnull; + if (NS_SUCCEEDED(rv)) { + if (NS_FAILED(frameTraversal->CurrentItem(&isupports))) + return levels; } //we must CAST here to an nsIFrame. nsIFrame doesn't really follow the rules @@ -2205,27 +1913,28 @@ nsSelection::GetPrevNextBidiLevels(nsPresContext *aPresContext, nsIFrame *newFrame = (nsIFrame *)isupports; if (direction == eDirNext) { - *aPrevFrame = currentFrame; - *aPrevLevel = NS_GET_EMBEDDING_LEVEL(currentFrame); - *aNextFrame = newFrame; - *aNextLevel = newFrame ? NS_GET_EMBEDDING_LEVEL(newFrame) : NS_GET_BASE_LEVEL(currentFrame); + levels.SetData(currentFrame, newFrame, + NS_GET_EMBEDDING_LEVEL(currentFrame), + newFrame ? NS_GET_EMBEDDING_LEVEL(newFrame) : + NS_GET_BASE_LEVEL(currentFrame)); + return levels; } else { - *aNextFrame = currentFrame; - *aNextLevel = NS_GET_EMBEDDING_LEVEL(currentFrame); - *aPrevFrame = newFrame; - *aPrevLevel = newFrame ? NS_GET_EMBEDDING_LEVEL(newFrame) : NS_GET_BASE_LEVEL(currentFrame); + levels.SetData(newFrame, currentFrame, + newFrame ? NS_GET_EMBEDDING_LEVEL(newFrame) : + NS_GET_BASE_LEVEL(currentFrame), + NS_GET_EMBEDDING_LEVEL(currentFrame)); + return levels; } - return NS_OK; - + return levels; } -NS_IMETHODIMP nsSelection::GetFrameFromLevel(nsPresContext *aPresContext, - nsIFrame *aFrameIn, - nsDirection aDirection, - PRUint8 aBidiLevel, - nsIFrame **aFrameOut) +nsresult +nsFrameSelection::GetFrameFromLevel(nsIFrame *aFrameIn, + nsDirection aDirection, + PRUint8 aBidiLevel, + nsIFrame **aFrameOut) { PRUint8 foundLevel = 0; nsIFrame *foundFrame = aFrameIn; @@ -2236,7 +1945,8 @@ NS_IMETHODIMP nsSelection::GetFrameFromLevel(nsPresContext *aPresContext, if (NS_FAILED(result)) return result; - result = trav->NewFrameTraversal(getter_AddRefs(frameTraversal),LEAF, aPresContext, aFrameIn); + result = trav->NewFrameTraversal(getter_AddRefs(frameTraversal), LEAF, + mShell->GetPresContext(), aFrameIn); if (NS_FAILED(result)) return result; nsISupports *isupports = nsnull; @@ -2266,8 +1976,8 @@ NS_IMETHODIMP nsSelection::GetFrameFromLevel(nsPresContext *aPresContext, } -NS_IMETHODIMP -nsSelection::MaintainSelection() +nsresult +nsFrameSelection::MaintainSelection() { PRInt8 index = GetIndexFromSelectionType(nsISelectionController::SELECTION_NORMAL); nsCOMPtr range; @@ -2306,26 +2016,19 @@ nsSelection::MaintainSelection() * The following two methods use GetPrevNextBidiLevels to determine the new Bidi level. * BidiLevelFromMove is called when the caret is moved in response to a keyboard event * - * @param aContext is the presentation context * @param aPresShell is the presentation shell * @param aNode is the content node * @param aContentOffset is the new caret position, as an offset into aNode * @param aKeycode is the keyboard event that moved the caret to the new position * @param aHint is the hint indicating in what logical direction the caret moved */ -void nsSelection::BidiLevelFromMove(nsPresContext* aContext, - nsIPresShell* aPresShell, - nsIContent *aNode, - PRUint32 aContentOffset, - PRUint32 aKeycode, - HINT aHint) +void nsFrameSelection::BidiLevelFromMove(nsIPresShell* aPresShell, + nsIContent *aNode, + PRUint32 aContentOffset, + PRUint32 aKeycode, + HINT aHint) { - PRUint8 firstLevel; - PRUint8 secondLevel; PRUint8 currentLevel; - nsIFrame* firstFrame=nsnull; - nsIFrame* secondFrame=nsnull; - aPresShell->GetCaretBidiLevel(¤tLevel); switch (aKeycode) { @@ -2333,13 +2036,16 @@ void nsSelection::BidiLevelFromMove(nsPresContext* aContext, // Right and Left: the new cursor Bidi level is the level of the character moved over case nsIDOMKeyEvent::DOM_VK_RIGHT: case nsIDOMKeyEvent::DOM_VK_LEFT: - GetPrevNextBidiLevels(aContext, aNode, aContentOffset, aHint, PR_FALSE, &firstFrame, &secondFrame, &firstLevel, &secondLevel); - if (HINTLEFT == aHint) - aPresShell->SetCaretBidiLevel(firstLevel); - else - aPresShell->SetCaretBidiLevel(secondLevel); - break; + { + nsPrevNextBidiLevels levels = GetPrevNextBidiLevels(aNode, aContentOffset, + aHint, PR_FALSE); + if (HINTLEFT == aHint) + aPresShell->SetCaretBidiLevel(levels.mLevelBefore); + else + aPresShell->SetCaretBidiLevel(levels.mLevelAfter); + break; + } /* // Up and Down: the new cursor Bidi level is the smaller of the two surrounding characters case nsIDOMKeyEvent::DOM_VK_UP: @@ -2360,13 +2066,14 @@ void nsSelection::BidiLevelFromMove(nsPresContext* aContext, * @param aNode is the content node * @param aContentOffset is the new caret position, as an offset into aNode */ -void nsSelection::BidiLevelFromClick(nsIContent *aNode, PRUint32 aContentOffset) +void nsFrameSelection::BidiLevelFromClick(nsIContent *aNode, + PRUint32 aContentOffset) { nsIFrame* clickInFrame=nsnull; PRInt32 OffsetNotUsed; - nsresult result = GetFrameForNodeOffset(aNode, aContentOffset, mHint, &clickInFrame, &OffsetNotUsed); - if (NS_FAILED(result)) + clickInFrame = GetFrameForNodeOffset(aNode, aContentOffset, mHint, &OffsetNotUsed); + if (!clickInFrame) return; mShell->SetCaretBidiLevel(NS_GET_EMBEDDING_LEVEL(clickInFrame)); @@ -2374,7 +2081,8 @@ void nsSelection::BidiLevelFromClick(nsIContent *aNode, PRUint32 aContentOffset) PRBool -nsSelection::AdjustForMaintainedSelection(nsIContent *aContent, PRInt32 aOffset) +nsFrameSelection::AdjustForMaintainedSelection(nsIContent *aContent, + PRInt32 aOffset) { // Is the desired content and offset currently in selection? // If the double click flag is set then don't continue selection if the @@ -2430,9 +2138,12 @@ nsSelection::AdjustForMaintainedSelection(nsIContent *aContent, PRInt32 aOffset) NS_IMETHODIMP -nsSelection::HandleClick(nsIContent *aNewFocus, PRUint32 aContentOffset, - PRUint32 aContentEndOffset, PRBool aContinueSelection, - PRBool aMultipleSelection, PRBool aHint) +nsFrameSelection::HandleClick(nsIContent *aNewFocus, + PRUint32 aContentOffset, + PRUint32 aContentEndOffset, + PRBool aContinueSelection, + PRBool aMultipleSelection, + PRBool aHint) { if (!aNewFocus) return NS_ERROR_INVALID_ARG; @@ -2458,81 +2169,82 @@ nsSelection::HandleClick(nsIContent *aNewFocus, PRUint32 aContentOffset, return NS_OK; } -NS_IMETHODIMP -nsSelection::HandleDrag(nsPresContext *aPresContext, nsIFrame *aFrame, nsPoint& aPoint) +void +nsFrameSelection::HandleDrag(nsIFrame *aFrame, nsPoint aPoint) { - if (!aPresContext || !aFrame) - return NS_ERROR_NULL_POINTER; + if (!aFrame) + return; nsresult result; nsIFrame *newFrame = 0; nsPoint newPoint; - result = ConstrainFrameAndPointToAnchorSubtree(aPresContext, aFrame, aPoint, &newFrame, newPoint); + result = ConstrainFrameAndPointToAnchorSubtree(aFrame, aPoint, &newFrame, newPoint); if (NS_FAILED(result)) - return result; + return; if (!newFrame) - return NS_ERROR_FAILURE; + return; nsIFrame::ContentOffsets offsets = newFrame->GetContentOffsetsFromPoint(newPoint); if ((newFrame->GetStateBits() & NS_FRAME_SELECTED_CONTENT) && AdjustForMaintainedSelection(offsets.content, offsets.offset)) - return NS_OK; + return; - if (NS_SUCCEEDED(result)) - { - // XXX Code not up to date + // XXX Code not up to date #ifdef VISUALSELECTION - if (aPresContext->BidiEnabled()) { - PRUint8 level; - nsPeekOffsetStruct pos; - //set data using mLimiter to stop on scroll views. If we have a limiter then we stop peeking - //when we hit scrollable views. If no limiter then just let it go ahead - pos.SetData(mShell, 0, eSelectDir, eDirNext, startPos, PR_FALSE, - PR_TRUE, PR_TRUE, mLimiter != nsnull, PR_FALSE); - mHint = HINT(beginOfContent); - HINT saveHint = mHint; - if (NS_GET_EMBEDDING_LEVEL(newFrame) & 1) - mHint = (mHint==HINTLEFT) ? HINTRIGHT : HINTLEFT; - pos.mResultContent = newContent; - pos.mContentOffset = contentOffsetEnd; - result = VisualSelectFrames(aPresContext, newFrame, pos); - if (NS_FAILED(result)) - result = HandleClick(newContent, startPos, contentOffsetEnd, PR_TRUE, - PR_FALSE, beginOfContent); - mHint = saveHint; - } - else -#endif // VISUALSELECTION - result = HandleClick(offsets.content, offsets.offset, offsets.offset, - PR_TRUE, PR_FALSE, offsets.associateWithNext); + if (mShell->GetPresContext()->BidiEnabled()) { + PRUint8 level; + nsPeekOffsetStruct pos; + //set data using mLimiter to stop on scroll views. If we have a limiter then we stop peeking + //when we hit scrollable views. If no limiter then just let it go ahead + pos.SetData(mShell, 0, eSelectDir, eDirNext, startPos, PR_FALSE, + PR_TRUE, PR_TRUE, mLimiter != nsnull, PR_FALSE); + mHint = HINT(beginOfContent); + HINT saveHint = mHint; + if (NS_GET_EMBEDDING_LEVEL(newFrame) & 1) + mHint = (mHint==HINTLEFT) ? HINTRIGHT : HINTLEFT; + pos.mResultContent = newContent; + pos.mContentOffset = contentOffsetEnd; + result = VisualSelectFrames(newFrame, pos); + if (NS_FAILED(result)) + HandleClick(newContent, startPos, contentOffsetEnd, PR_TRUE, + PR_FALSE, beginOfContent); + mHint = saveHint; } - - return result; + else +#endif // VISUALSELECTION + HandleClick(offsets.content, offsets.offset, offsets.offset, + PR_TRUE, PR_FALSE, offsets.associateWithNext); } -NS_IMETHODIMP -nsSelection::StartAutoScrollTimer(nsPresContext *aPresContext, nsIView *aView, nsPoint& aPoint, PRUint32 aDelay) +nsresult +nsFrameSelection::StartAutoScrollTimer(nsIView *aView, + nsPoint aPoint, + PRUint32 aDelay) { PRInt8 index = GetIndexFromSelectionType(nsISelectionController::SELECTION_NORMAL); - return mDomSelections[index]->StartAutoScrollTimer(aPresContext, aView, aPoint, aDelay); + return mDomSelections[index]->StartAutoScrollTimer(mShell->GetPresContext(), + aView, aPoint, aDelay); } -NS_IMETHODIMP -nsSelection::StopAutoScrollTimer() +void +nsFrameSelection::StopAutoScrollTimer() { PRInt8 index = GetIndexFromSelectionType(nsISelectionController::SELECTION_NORMAL); - return mDomSelections[index]->StopAutoScrollTimer(); + mDomSelections[index]->StopAutoScrollTimer(); } /** 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) +nsresult +nsFrameSelection::TakeFocus(nsIContent *aNewFocus, + PRUint32 aContentOffset, + PRUint32 aContentEndOffset, + PRBool aContinueSelection, + PRBool aMultipleSelection) { if (!aNewFocus) return NS_ERROR_NULL_POINTER; @@ -2662,17 +2374,12 @@ printf(" * TakeFocus - moving into new cell\n"); -NS_METHOD -nsSelection::LookUpSelection(nsIContent *aContent, PRInt32 aContentOffset, PRInt32 aContentLength, - SelectionDetails **aReturnDetails, PRBool aSlowCheck) +SelectionDetails* +nsFrameSelection::LookUpSelection(nsIContent *aContent, PRInt32 aContentOffset, + PRInt32 aContentLength, PRBool aSlowCheck) { - if (!aContent || !aReturnDetails) - return NS_ERROR_NULL_POINTER; - - STATUS_CHECK_RETURN_MACRO(); - - - *aReturnDetails = nsnull; + if (!aContent || !mShell) + return nsnull; // if any of the additional selections are set, always do a slow check. The // issue is that the NS_FRAME_SELECTED_CONTENT bit is set when any of the @@ -2688,61 +2395,46 @@ nsSelection::LookUpSelection(nsIContent *aContent, PRInt32 aContentOffset, PRInt } } } + + SelectionDetails* details = nsnull; for (j = (PRInt8) 0; j < (PRInt8)nsISelectionController::NUM_SELECTIONTYPES; j++){ if (mDomSelections[j]) - mDomSelections[j]->LookUpSelection(aContent, aContentOffset, aContentLength, aReturnDetails, (SelectionType)(1<LookUpSelection(aContent, aContentOffset, aContentLength, &details, (SelectionType)(1<ScrollIntoView(aRegion, aIsSynchronous); } -NS_IMETHODIMP -nsSelection::RepaintSelection(nsPresContext* aPresContext, SelectionType aType) +nsresult +nsFrameSelection::RepaintSelection(SelectionType aType) { PRInt8 index = GetIndexFromSelectionType(aType); if (index < 0) return NS_ERROR_INVALID_ARG; if (!mDomSelections[index]) return NS_ERROR_NULL_POINTER; - return mDomSelections[index]->Repaint(aPresContext); + return mDomSelections[index]->Repaint(mShell->GetPresContext()); } -NS_IMETHODIMP -nsSelection::GetFrameForNodeOffset(nsIContent *aNode, PRInt32 aOffset, HINT aHint, nsIFrame **aReturnFrame, PRInt32 *aReturnOffset) +nsIFrame* +nsFrameSelection::GetFrameForNodeOffset(nsIContent *aNode, + PRInt32 aOffset, + HINT aHint, + PRInt32 *aReturnOffset) { - if (!aNode || !aReturnFrame || !aReturnOffset) - return NS_ERROR_NULL_POINTER; + if (!aNode || !aReturnOffset) + return nsnull; if (aOffset < 0) - return NS_ERROR_FAILURE; + return nsnull; *aReturnOffset = aOffset; - nsresult result = NS_OK; - nsCOMPtr theNode = aNode; if (aNode->IsContentOfType(nsIContent::eELEMENT)) @@ -2810,7 +2503,7 @@ nsSelection::GetFrameForNodeOffset(nsIContent *aNode, PRInt32 aOffset, HINT aHin nsCOMPtr childNode = theNode->GetChildAt(childIndex); if (!childNode) - return NS_ERROR_FAILURE; + return nsnull; theNode = childNode; @@ -2832,7 +2525,7 @@ nsSelection::GetFrameForNodeOffset(nsIContent *aNode, PRInt32 aOffset, HINT aHin newOffset = numChildren; } - return GetFrameForNodeOffset(theNode, newOffset, aHint, aReturnFrame,aReturnOffset); + return GetFrameForNodeOffset(theNode, newOffset, aHint, aReturnOffset); } else #endif // DONT_DO_THIS_YET @@ -2848,10 +2541,9 @@ nsSelection::GetFrameForNodeOffset(nsIContent *aNode, PRInt32 aOffset, HINT aHin { PRUint32 textLength = 0; - result = textNode->GetLength(&textLength); - - if (NS_FAILED(result)) - return NS_ERROR_FAILURE; + nsresult rv = textNode->GetLength(&textLength); + if (NS_FAILED(rv)) + return nsnull; *aReturnOffset = (PRInt32)textLength; } @@ -2861,23 +2553,23 @@ nsSelection::GetFrameForNodeOffset(nsIContent *aNode, PRInt32 aOffset, HINT aHin } } - *aReturnFrame = mShell->GetPrimaryFrameFor(theNode); - if (!*aReturnFrame) - return NS_ERROR_UNEXPECTED; + nsIFrame* returnFrame = mShell->GetPrimaryFrameFor(theNode); + if (!returnFrame) + return nsnull; // find the child frame containing the offset we want - result = (*aReturnFrame)->GetChildFrameContainingOffset(*aReturnOffset, aHint, &aOffset, aReturnFrame); - return result; + returnFrame->GetChildFrameContainingOffset(*aReturnOffset, aHint, + &aOffset, &returnFrame); + return returnFrame; } -NS_IMETHODIMP -nsSelection::CommonPageMove(PRBool aForward, - PRBool aExtend, - nsIScrollableView *aScrollableView, - nsIFrameSelection *aFrameSel) +void +nsFrameSelection::CommonPageMove(PRBool aForward, + PRBool aExtend, + nsIScrollableView *aScrollableView) { - if ( !aScrollableView || !aFrameSel) - return NS_ERROR_NULL_POINTER; + if (!aScrollableView) + return; // expected behavior for PageMove is to scroll AND move the caret // and remain relative position of the caret in view. see Bug 4302. @@ -2891,21 +2583,20 @@ nsSelection::CommonPageMove(PRBool aForward, result = aScrollableView->GetScrolledView(scrolledView); if (NS_FAILED(result)) - return result; + return; if (scrolledView) mainframe = NS_STATIC_CAST(nsIFrame*, scrolledView->GetClientData()); if (!mainframe) - return NS_ERROR_FAILURE; + return; // find out where the caret is. - // we should know mDesiredX value of nsSelection, but I havent seen that behavior in other windows applications yet. - nsCOMPtr domSel; - aFrameSel->GetSelection(nsISelectionController::SELECTION_NORMAL, getter_AddRefs(domSel)); + // we should know mDesiredX value of nsFrameSelection, but I havent seen that behavior in other windows applications yet. + nsISelection* domSel = GetSelection(nsISelectionController::SELECTION_NORMAL); if (!domSel) - return NS_ERROR_UNEXPECTED; + return; nsCOMPtr caret; nsRect caretPos; @@ -2913,13 +2604,13 @@ nsSelection::CommonPageMove(PRBool aForward, result = mShell->GetCaret(getter_AddRefs(caret)); if (NS_FAILED(result)) - return result; + return; nsIView *caretView; result = caret->GetCaretCoordinates(nsICaret::eClosestViewCoordinates, domSel, &caretPos, &isCollapsed, &caretView); if (NS_FAILED(result)) - return result; + return; //need to adjust caret jump by percentage scroll nsSize scrollDelta; @@ -2944,20 +2635,18 @@ nsSelection::CommonPageMove(PRBool aForward, mainframe->GetContentOffsetsFromPoint(desiredPoint); if (!offsets.content) - return NS_ERROR_UNEXPECTED; + return; // scroll one page aScrollableView->ScrollByPages(0, aForward ? 1 : -1); // place the caret - result = aFrameSel->HandleClick(offsets.content, offsets.offset, - offsets.offset, aExtend, PR_FALSE, PR_TRUE); - - return result; + HandleClick(offsets.content, offsets.offset, + offsets.offset, aExtend, PR_FALSE, PR_TRUE); } -NS_IMETHODIMP -nsSelection::CharacterMove(PRBool aForward, PRBool aExtend) +nsresult +nsFrameSelection::CharacterMove(PRBool aForward, PRBool aExtend) { if (aForward) return MoveCaret(nsIDOMKeyEvent::DOM_VK_RIGHT,aExtend,eSelectCharacter); @@ -2965,8 +2654,8 @@ nsSelection::CharacterMove(PRBool aForward, PRBool aExtend) return MoveCaret(nsIDOMKeyEvent::DOM_VK_LEFT,aExtend,eSelectCharacter); } -NS_IMETHODIMP -nsSelection::WordMove(PRBool aForward, PRBool aExtend) +nsresult +nsFrameSelection::WordMove(PRBool aForward, PRBool aExtend) { if (aForward) return MoveCaret(nsIDOMKeyEvent::DOM_VK_RIGHT,aExtend,eSelectWord); @@ -2974,8 +2663,8 @@ nsSelection::WordMove(PRBool aForward, PRBool aExtend) return MoveCaret(nsIDOMKeyEvent::DOM_VK_LEFT,aExtend,eSelectWord); } -NS_IMETHODIMP -nsSelection::LineMove(PRBool aForward, PRBool aExtend) +nsresult +nsFrameSelection::LineMove(PRBool aForward, PRBool aExtend) { if (aForward) return MoveCaret(nsIDOMKeyEvent::DOM_VK_DOWN,aExtend,eSelectLine); @@ -2983,8 +2672,8 @@ nsSelection::LineMove(PRBool aForward, PRBool aExtend) return MoveCaret(nsIDOMKeyEvent::DOM_VK_UP,aExtend,eSelectLine); } -NS_IMETHODIMP -nsSelection::IntraLineMove(PRBool aForward, PRBool aExtend) +nsresult +nsFrameSelection::IntraLineMove(PRBool aForward, PRBool aExtend) { if (aForward) return MoveCaret(nsIDOMKeyEvent::DOM_VK_END,aExtend,eSelectLine); @@ -2992,7 +2681,8 @@ nsSelection::IntraLineMove(PRBool aForward, PRBool aExtend) return MoveCaret(nsIDOMKeyEvent::DOM_VK_HOME,aExtend,eSelectLine); } -NS_IMETHODIMP nsSelection::SelectAll() +nsresult +nsFrameSelection::SelectAll() { nsCOMPtr rootContent; if (mLimiter) @@ -3015,31 +2705,26 @@ NS_IMETHODIMP nsSelection::SelectAll() //////////END FRAMESELECTION -NS_IMETHODIMP -nsSelection::StartBatchChanges() +void +nsFrameSelection::StartBatchChanges() { - nsresult result(NS_OK); mBatching++; - return result; } - -NS_IMETHODIMP -nsSelection::EndBatchChanges() +void +nsFrameSelection::EndBatchChanges() { - nsresult result(NS_OK); mBatching--; NS_ASSERTION(mBatching >=0,"Bad mBatching"); if (mBatching == 0 && mChangesDuringBatching){ mChangesDuringBatching = PR_FALSE; NotifySelectionListeners(nsISelectionController::SELECTION_NORMAL); } - return result; } nsresult -nsSelection::NotifySelectionListeners(SelectionType aType) +nsFrameSelection::NotifySelectionListeners(SelectionType aType) { PRInt8 index = GetIndexFromSelectionType(aType); if (index >=0) @@ -3059,7 +2744,7 @@ static PRBool IsCell(nsIContent *aContent) } nsITableCellLayout* -nsSelection::GetCellLayout(nsIContent *aCellContent) +nsFrameSelection::GetCellLayout(nsIContent *aCellContent) { // Get frame for cell nsIFrame *cellFrame = mShell->GetPrimaryFrameFor(aCellContent); @@ -3073,7 +2758,7 @@ nsSelection::GetCellLayout(nsIContent *aCellContent) } nsITableLayout* -nsSelection::GetTableLayout(nsIContent *aTableContent) +nsFrameSelection::GetTableLayout(nsIContent *aTableContent) { // Get frame for table nsIFrame *tableFrame = mShell->GetPrimaryFrameFor(aTableContent); @@ -3087,7 +2772,7 @@ nsSelection::GetTableLayout(nsIContent *aTableContent) } nsresult -nsSelection::ClearNormalSelection() +nsFrameSelection::ClearNormalSelection() { PRInt8 index = GetIndexFromSelectionType(nsISelectionController::SELECTION_NORMAL); return mDomSelections[index]->RemoveAllRanges(); @@ -3096,7 +2781,7 @@ nsSelection::ClearNormalSelection() // Table selection support. // TODO: Separate table methods into a separate nsITableSelection interface nsresult -nsSelection::HandleTableSelection(nsIContent *aParentContent, PRInt32 aContentOffset, PRInt32 aTarget, nsMouseEvent *aMouseEvent) +nsFrameSelection::HandleTableSelection(nsIContent *aParentContent, PRInt32 aContentOffset, PRInt32 aTarget, nsMouseEvent *aMouseEvent) { NS_ENSURE_TRUE(aParentContent, NS_ERROR_NULL_POINTER); NS_ENSURE_TRUE(aMouseEvent, NS_ERROR_NULL_POINTER); @@ -3420,7 +3105,7 @@ printf("HandleTableSelection: Removing cell from multi-cell selection\n"); } nsresult -nsSelection::SelectBlockOfCells(nsIContent *aStartCell, nsIContent *aEndCell) +nsFrameSelection::SelectBlockOfCells(nsIContent *aStartCell, nsIContent *aEndCell) { NS_ENSURE_TRUE(aStartCell, NS_ERROR_NULL_POINTER); NS_ENSURE_TRUE(aEndCell, NS_ERROR_NULL_POINTER); @@ -3531,7 +3216,7 @@ printf("SelectBlockOfCells -- range is null\n"); } nsresult -nsSelection::SelectRowOrColumn(nsIContent *aCellContent, PRUint32 aTarget) +nsFrameSelection::SelectRowOrColumn(nsIContent *aCellContent, PRUint32 aTarget) { if (!aCellContent) return NS_ERROR_NULL_POINTER; @@ -3649,7 +3334,8 @@ nsSelection::SelectRowOrColumn(nsIContent *aCellContent, PRUint32 aTarget) } nsresult -nsSelection::GetFirstCellNodeInRange(nsIDOMRange *aRange, nsIDOMNode **aCellNode) +nsFrameSelection::GetFirstCellNodeInRange(nsIDOMRange *aRange, + nsIDOMNode **aCellNode) { if (!aRange || !aCellNode) return NS_ERROR_NULL_POINTER; @@ -3684,7 +3370,8 @@ nsSelection::GetFirstCellNodeInRange(nsIDOMRange *aRange, nsIDOMNode **aCellNode } nsresult -nsSelection::GetFirstSelectedCellAndRange(nsIDOMNode **aCell, nsIDOMRange **aRange) +nsFrameSelection::GetFirstSelectedCellAndRange(nsIDOMNode **aCell, + nsIDOMRange **aRange) { if (!aCell) return NS_ERROR_NULL_POINTER; *aCell = nsnull; @@ -3719,7 +3406,8 @@ nsSelection::GetFirstSelectedCellAndRange(nsIDOMNode **aCell, nsIDOMRange **aRan } nsresult -nsSelection::GetNextSelectedCellAndRange(nsIDOMNode **aCell, nsIDOMRange **aRange) +nsFrameSelection::GetNextSelectedCellAndRange(nsIDOMNode **aCell, + nsIDOMRange **aRange) { if (!aCell) return NS_ERROR_NULL_POINTER; *aCell = nsnull; @@ -3769,7 +3457,9 @@ nsSelection::GetNextSelectedCellAndRange(nsIDOMNode **aCell, nsIDOMRange **aRang } nsresult -nsSelection::GetCellIndexes(nsIContent *aCell, PRInt32 &aRowIndex, PRInt32 &aColIndex) +nsFrameSelection::GetCellIndexes(nsIContent *aCell, + PRInt32 &aRowIndex, + PRInt32 &aColIndex) { if (!aCell) return NS_ERROR_NULL_POINTER; @@ -3782,7 +3472,9 @@ nsSelection::GetCellIndexes(nsIContent *aCell, PRInt32 &aRowIndex, PRInt32 &aCol } PRBool -nsSelection::IsInSameTable(nsIContent *aContent1, nsIContent *aContent2, nsIContent **aTable) +nsFrameSelection::IsInSameTable(nsIContent *aContent1, + nsIContent *aContent2, + nsIContent **aTable) { if (!aContent1 || !aContent2) return PR_FALSE; @@ -3811,7 +3503,7 @@ nsSelection::IsInSameTable(nsIContent *aContent1, nsIContent *aContent2, nsICont } nsresult -nsSelection::GetParentTable(nsIContent *aCell, nsIContent **aTable) +nsFrameSelection::GetParentTable(nsIContent *aCell, nsIContent **aTable) { if (!aCell || !aTable) { return NS_ERROR_NULL_POINTER; @@ -3832,7 +3524,7 @@ nsSelection::GetParentTable(nsIContent *aCell, nsIContent **aTable) } nsresult -nsSelection::SelectCellElement(nsIDOMElement *aCellElement) +nsFrameSelection::SelectCellElement(nsIDOMElement *aCellElement) { nsCOMPtr cellContent = do_QueryInterface(aCellElement); @@ -4046,7 +3738,7 @@ nsTypedSelection::GetTableSelectionType(nsIDOMRange* aRange, PRInt32* aTableSele } nsresult -nsSelection::CreateAndAddRange(nsIDOMNode *aParentNode, PRInt32 aOffset) +nsFrameSelection::CreateAndAddRange(nsIDOMNode *aParentNode, PRInt32 aOffset) { if (!aParentNode) return NS_ERROR_NULL_POINTER; nsCOMPtr range; @@ -4065,22 +3757,7 @@ nsSelection::CreateAndAddRange(nsIDOMNode *aParentNode, PRInt32 aOffset) // End of Table Selection -NS_IMETHODIMP -nsSelection::SetHint(HINT aHintRight) -{ - mHint = aHintRight; - return NS_OK; -} - -NS_IMETHODIMP -nsSelection::GetHint(HINT *aHintRight) -{ - *aHintRight = mHint; - return NS_OK; -} - - -//END nsIFrameSelection methods +//END nsFrameSelection methods #ifdef XP_MAC @@ -4092,7 +3769,7 @@ nsSelection::GetHint(HINT *aHintRight) NS_IMETHODIMP -nsSelection::DeleteFromDocument() +nsFrameSelection::DeleteFromDocument() { nsresult res; @@ -4150,47 +3827,17 @@ nsSelection::DeleteFromDocument() return NS_OK; } - -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; -} - -NS_IMETHODIMP -nsSelection::SetDelayCaretOverExistingSelection(PRBool aDelay) +void +nsFrameSelection::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) +void +nsFrameSelection::SetDelayedCaretData(nsMouseEvent *aMouseEvent) { if (aMouseEvent) { @@ -4202,49 +3849,17 @@ nsSelection::SetDelayedCaretData(nsMouseEvent *aMouseEvent) } else mDelayedMouseEventValid = PR_FALSE; - - return NS_OK; } -NS_IMETHODIMP -nsSelection::GetDelayedCaretData(nsMouseEvent **aMouseEvent) +nsMouseEvent* +nsFrameSelection::GetDelayedCaretData() { - if (!aMouseEvent) - return NS_ERROR_NULL_POINTER; - if (mDelayedMouseEventValid) - *aMouseEvent = &mDelayedMouseEvent; - else - *aMouseEvent = 0; - - return NS_OK; + return &mDelayedMouseEvent; + + return nsnull; } -// 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; - NS_IF_ADDREF(*aLimiterContent); - - return NS_OK; -} - -NS_IMETHODIMP -nsSelection::SetMouseDoubleDown(PRBool aDoubleDown) -{ - mMouseDoubleDownState = aDoubleDown; - return NS_OK; -} - -NS_IMETHODIMP -nsSelection::GetMouseDoubleDown(PRBool *aDoubleDown) -{ - *aDoubleDown = mMouseDoubleDownState; - return NS_OK; -} - //END nsISelection interface implementations #if 0 @@ -4255,7 +3870,7 @@ nsSelection::GetMouseDoubleDown(PRBool *aDoubleDown) // note: this can return a nil anchor node -nsTypedSelection::nsTypedSelection(nsSelection *aList) +nsTypedSelection::nsTypedSelection(nsFrameSelection *aList) { mFrameSelection = aList; mFixupState = PR_FALSE; @@ -4636,9 +4251,11 @@ nsTypedSelection::GetPrimaryFrameForAnchorNode(nsIFrame **aReturnFrame) nsCOMPtr content = do_QueryInterface(FetchAnchorNode()); if (content && mFrameSelection) { - nsIFrameSelection::HINT hint; - mFrameSelection->GetHint(&hint); - return mFrameSelection->GetFrameForNodeOffset(content, FetchAnchorOffset(),hint,aReturnFrame, &frameOffset); + *aReturnFrame = mFrameSelection-> + GetFrameForNodeOffset(content, FetchAnchorOffset(), + mFrameSelection->GetHint(), &frameOffset); + if (*aReturnFrame) + return NS_OK; } return NS_ERROR_FAILURE; } @@ -4664,15 +4281,14 @@ nsTypedSelection::GetPrimaryFrameForFocusNode(nsIFrame **aReturnFrame, PRInt32 * *aReturnFrame = 0; if (!aOffsetUsed) aOffsetUsed = &frameOffset; + + nsFrameSelection::HINT hint = mFrameSelection->GetHint(); - nsIFrameSelection::HINT hint; - mFrameSelection->GetHint(&hint); - PRUint8 caretBidiLevel; presShell->GetCaretBidiLevel(&caretBidiLevel); - return caret->GetCaretFrameForNodeOffset(content, FetchFocusOffset(), hint, caretBidiLevel, - aReturnFrame, aOffsetUsed); + return caret->GetCaretFrameForNodeOffset(content, FetchFocusOffset(), + hint, caretBidiLevel, aReturnFrame, aOffsetUsed); } @@ -4710,9 +4326,7 @@ nsTypedSelection::selectFrames(nsPresContext* aPresContext, //NOTE: eSpreadDown is now IGNORED. Selected state is set only for given frame frame->SetSelected(aPresContext, nsnull, aFlags, eSpreadDown); #ifndef OLD_TABLE_SELECTION - PRBool tablesel; - mFrameSelection->GetTableCellSelection(&tablesel); - if (tablesel) + if (mFrameSelection->GetTableCellSelection()) { nsITableCellLayout *tcl = nsnull; CallQueryInterface(frame, &tcl); @@ -5080,7 +4694,7 @@ nsTypedSelection::GetCachedFrameOffset(nsIFrame *aFrame, PRInt32 inOffset, nsPoi } NS_IMETHODIMP -nsTypedSelection::GetFrameSelection(nsIFrameSelection **aFrameSelection) { +nsTypedSelection::GetFrameSelection(nsFrameSelection **aFrameSelection) { NS_ENSURE_ARG_POINTER(aFrameSelection); *aFrameSelection = mFrameSelection; NS_ADDREF(*aFrameSelection); @@ -5577,7 +5191,7 @@ nsTypedSelection::Collapse(nsIDOMNode* aParentNode, PRInt32 aOffset) nsCOMPtr range; NS_NewRange(getter_AddRefs(range)); if (! range){ - NS_ASSERTION(PR_FALSE,"Couldn't make a range - nsSelection::Collapse"); + NS_ASSERTION(PR_FALSE,"Couldn't make a range - nsFrameSelection::Collapse"); return NS_ERROR_UNEXPECTED; } result = range->SetEnd(aParentNode, aOffset); @@ -6548,11 +6162,8 @@ nsTypedSelection::GetRootScrollableView(nsIScrollableView **aScrollableView) if (!mFrameSelection) return NS_ERROR_FAILURE;//nothing to do nsresult rv; - nsIScrollableView *scrollView; - rv = mFrameSelection->GetScrollableView(&scrollView); - if ( NS_FAILED(rv)) - return rv; - + + nsIScrollableView *scrollView = mFrameSelection->GetScrollableView(); if (!scrollView) { @@ -6746,9 +6357,13 @@ nsTypedSelection::GetSelectionRegionRectAndScrollableView(SelectionRegion aRegio if (content) { - nsIFrameSelection::HINT hint; - mFrameSelection->GetHint(&hint); - result = mFrameSelection->GetFrameForNodeOffset(content, nodeOffset, hint, &frame, &frameOffset); + frame = mFrameSelection->GetFrameForNodeOffset(content, nodeOffset, + mFrameSelection->GetHint(), &frameOffset); + + if (frame) + result = NS_OK; + else + result = NS_ERROR_FAILURE; } else result = NS_ERROR_FAILURE; @@ -7247,9 +6862,10 @@ nsTypedSelection::NotifySelectionListeners() NS_IMETHODIMP nsTypedSelection::StartBatchChanges() { - if (!mFrameSelection) - return NS_OK;//nothing to do - return mFrameSelection->StartBatchChanges(); + if (mFrameSelection) + mFrameSelection->StartBatchChanges(); + + return NS_OK; } @@ -7257,9 +6873,10 @@ nsTypedSelection::StartBatchChanges() NS_IMETHODIMP nsTypedSelection::EndBatchChanges() { - if (!mFrameSelection) - return NS_OK;//nothing to do - return mFrameSelection->EndBatchChanges(); + if (mFrameSelection) + mFrameSelection->EndBatchChanges(); + + return NS_OK; } @@ -7308,22 +6925,24 @@ nsTypedSelection::SelectionLanguageChange(PRBool aLangRTL) else { // the cursor is at a frame boundary, so use GetPrevNextBidiLevels to find the level of the characters // before and after the cursor - nsIFrame* frameBefore = nsnull; - nsIFrame* frameAfter = nsnull; focusContent = do_QueryInterface(focusNode); /* - nsIFrameSelection::HINT hint; + nsFrameSelection::HINT hint; if ((focusOffset == frameStart && level) // beginning of an RTL frame || (focusOffset == frameEnd && !level)) { // end of an LTR frame - hint = nsIFrameSelection::HINTRIGHT; + hint = nsFrameSelection::HINTRIGHT; } else { // end of an RTL frame or beginning of an LTR frame - hint = nsIFrameSelection::HINTLEFT; + hint = nsFrameSelection::HINTLEFT; } mFrameSelection->SetHint(hint); */ - mFrameSelection->GetPrevNextBidiLevels(context, focusContent, focusOffset, PR_FALSE, &frameBefore, &frameAfter, &levelBefore, &levelAfter); + nsPrevNextBidiLevels levels = mFrameSelection-> + GetPrevNextBidiLevels(focusContent, focusOffset, PR_FALSE); + + levelBefore = levels.mLevelBefore; + levelAfter = levels.mLevelAfter; } nsIPresShell* shell = context->GetPresShell(); diff --git a/mozilla/layout/generic/nsTextFrame.cpp b/mozilla/layout/generic/nsTextFrame.cpp index 98281dd5436..c51e1d3b775 100644 --- a/mozilla/layout/generic/nsTextFrame.cpp +++ b/mozilla/layout/generic/nsTextFrame.cpp @@ -86,7 +86,7 @@ #include "nsTextFragment.h" #include "nsHTMLAtoms.h" #include "nsLayoutAtoms.h" -#include "nsIFrameSelection.h" +#include "nsFrameSelection.h" #include "nsISelection.h" #include "nsIDOMRange.h" #include "nsILookAndFeel.h" @@ -2779,9 +2779,8 @@ nsTextFrame::IsTextInSelection() getter_AddRefs(content), &offset, &length); if (NS_SUCCEEDED(rv) && content) { - rv = GetFrameSelection()->LookUpSelection(content, mContentOffset, - mContentLength, &details, - PR_FALSE); + details = GetFrameSelection()->LookUpSelection(content, mContentOffset, + mContentLength, PR_FALSE); } //where are the selection points "really" @@ -2931,9 +2930,8 @@ nsTextFrame::PaintUnicodeText(nsPresContext* aPresContext, getter_AddRefs(content), &offset, &length); if (NS_SUCCEEDED(rv) && content) { - rv = GetFrameSelection()->LookUpSelection(content, mContentOffset, - mContentLength, &details, - PR_FALSE); + details = GetFrameSelection()->LookUpSelection(content, mContentOffset, + mContentLength, PR_FALSE); } //where are the selection points "really" @@ -3657,9 +3655,8 @@ nsTextFrame::PaintTextSlowly(nsPresContext* aPresContext, getter_AddRefs(content), &offset, &length); if (NS_SUCCEEDED(rv)) { - rv = GetFrameSelection()->LookUpSelection(content, mContentOffset, - mContentLength, &details, - PR_FALSE); + details = GetFrameSelection()->LookUpSelection(content, mContentOffset, + mContentLength, PR_FALSE); } //where are the selection points "really" @@ -3902,9 +3899,8 @@ nsTextFrame::PaintAsciiText(nsPresContext* aPresContext, getter_AddRefs(content), &offset, &length); if (NS_SUCCEEDED(rv)) { - rv = GetFrameSelection()->LookUpSelection(content, mContentOffset, - mContentLength, &details, - PR_FALSE); + details = GetFrameSelection()->LookUpSelection(content, mContentOffset, + mContentLength, PR_FALSE); } //where are the selection points "really" @@ -4270,8 +4266,8 @@ nsTextFrame::SetSelected(nsPresContext* aPresContext, getter_AddRefs(content), &offset, &length); if (NS_SUCCEEDED(rv) && content) { - rv = GetFrameSelection()->LookUpSelection(content, offset, - length, &details, PR_TRUE); + details = GetFrameSelection()->LookUpSelection(content, offset, + length, PR_TRUE); // PR_TRUE last param used here! we need to see if we are still selected. so no shortcut } if (!details) diff --git a/mozilla/layout/mathml/base/src/nsMathMLmoFrame.cpp b/mozilla/layout/mathml/base/src/nsMathMLmoFrame.cpp index 60b0d304302..243aefcf0c9 100644 --- a/mozilla/layout/mathml/base/src/nsMathMLmoFrame.cpp +++ b/mozilla/layout/mathml/base/src/nsMathMLmoFrame.cpp @@ -96,9 +96,9 @@ nsMathMLmoFrame::IsFrameInSelection(nsIFrame* aFrame) if (!isSelected) return PR_FALSE; - SelectionDetails* details = nsnull; - aFrame->GetFrameSelection()->LookUpSelection(aFrame->GetContent(), 0, 1, - &details, PR_TRUE); + SelectionDetails* details = aFrame->GetFrameSelection()-> + LookUpSelection(aFrame->GetContent(), 0, 1, PR_TRUE); + if (!details) return PR_FALSE; diff --git a/mozilla/layout/svg/base/src/nsSVGGlyphFrame.cpp b/mozilla/layout/svg/base/src/nsSVGGlyphFrame.cpp index 9a35d8f0c84..f45b986e1ea 100644 --- a/mozilla/layout/svg/base/src/nsSVGGlyphFrame.cpp +++ b/mozilla/layout/svg/base/src/nsSVGGlyphFrame.cpp @@ -1159,7 +1159,7 @@ nsSVGGlyphFrame::GetHighlight(PRUint32 *charnum, PRUint32 *nchars, nscolor *fore // get the selection details SelectionDetails *details = nsnull; { - nsCOMPtr frameSelection; + nsCOMPtr frameSelection; { nsCOMPtr controller; GetSelectionController(presContext, getter_AddRefs(controller)); @@ -1178,8 +1178,9 @@ nsSVGGlyphFrame::GetHighlight(PRUint32 *charnum, PRUint32 *nchars, nscolor *fore return NS_ERROR_FAILURE; } - frameSelection->LookUpSelection(mContent, 0, fragment->GetLength(), - &details, PR_FALSE); + details = frameSelection->LookUpSelection( + mContent, 0, fragment->GetLength(), PR_FALSE + ); } #if defined(DEBUG) && defined(SVG_DEBUG_SELECTION) diff --git a/mozilla/layout/tables/nsTableCellFrame.cpp b/mozilla/layout/tables/nsTableCellFrame.cpp index 48b6de792c5..00282770175 100644 --- a/mozilla/layout/tables/nsTableCellFrame.cpp +++ b/mozilla/layout/tables/nsTableCellFrame.cpp @@ -65,7 +65,7 @@ #include "nsDisplayList.h" //TABLECELL SELECTION -#include "nsIFrameSelection.h" +#include "nsFrameSelection.h" #include "nsILookAndFeel.h" @@ -283,13 +283,9 @@ nsTableCellFrame::DecorateForSelection(nsIRenderingContext& aRenderingContext, nsPresContext* presContext = GetPresContext(); displaySelection = DisplaySelection(presContext); if (displaySelection) { - nsIFrameSelection *frameSelection = - presContext->PresShell()->FrameSelection(); + nsFrameSelection *frameSelection = presContext->PresShell()->FrameSelection(); - PRBool tableCellSelectionMode; - nsresult result = - frameSelection->GetTableCellSelection(&tableCellSelectionMode); - if (NS_SUCCEEDED(result) && tableCellSelectionMode) { + if (frameSelection->GetTableCellSelection()) { nscolor bordercolor; if (displaySelection == nsISelectionController::SELECTION_DISABLED) { bordercolor = NS_RGB(176,176,176);// disabled color @@ -481,9 +477,7 @@ nsTableCellFrame::SetSelected(nsPresContext* aPresContext, // only this frame is considered nsFrame::SetSelected(aPresContext, aRange, aSelected, aSpread); - PRBool tableCellSelectionMode; - nsresult result = aPresContext->PresShell()->FrameSelection()->GetTableCellSelection(&tableCellSelectionMode); - if (NS_SUCCEEDED(result) && tableCellSelectionMode) { + if (aPresContext->PresShell()->FrameSelection()->GetTableCellSelection()) { // Selection can affect content, border and outline Invalidate(GetOverflowRect(), PR_FALSE); }