diff --git a/mozilla/content/base/public/nsISelectionController.idl b/mozilla/content/base/public/nsISelectionController.idl index 610bee20f54..be4b3415341 100644 --- a/mozilla/content/base/public/nsISelectionController.idl +++ b/mozilla/content/base/public/nsISelectionController.idl @@ -23,10 +23,75 @@ #include "nsISupports.idl" +#include "domstubs.idl" + + +%{C++ + +class nsIDOMSelection; +typedef short SelectionType; +typedef short SelectionRegion; +%} + [scriptable, uuid(D2D1D179-85A7-11d3-9932-00108301233C)] interface nsISelectionController : nsISupports { + const short SELECTION_NONE=0; + const short SELECTION_NORMAL=1; + const short SELECTION_SPELLCHECK=2; + const short SELECTION_IME_RAWINPUT=4; + const short SELECTION_IME_SELECTEDRAWTEXT=8; + const short SELECTION_IME_CONVERTEDTEXT=16; + const short SELECTION_IME_SELECTEDCONVERTEDTEXT=32; + const short NUM_SELECTIONTYPES=6; + + + const short SELECTION_ANCHOR_REGION = 0; + const short SELECTION_FOCUS_REGION = 1; + const short NUM_SELECTION_REGIONS = 2; + + /** + * GetSelection will return the selection that the presentation + * shell may implement. + * + * @param aType will hold the type of selection //SelectionType + * @param _return will hold the return value + */ + nsIDOMSelection getSelection(in short type); + + /** + * ScrollSelectionIntoView scrolls a region of the selection, + * so that it is visible in the scrolled view. + * + * @param aType the selection to scroll into view. //SelectionType + * @param aRegion the region inside the selection to scroll into view. //SelectionRegion + */ + void scrollSelectionIntoView(in short type, in short region); + /** + * RepaintSelection repaints the selection specified by aType. + * + * @param aType specifies the selection to repaint. + */ + void repaintSelection(in short type); + + /** + * Set the caret as enabled or disabled. An enabled caret will + * draw or blink when made visible. A disabled caret will never show up. + * Can be called any time. + * @param aEnable PR_TRUE to enable caret. PR_FALSE to disable. + * @return always NS_OK + */ + void setCaretEnabled(in boolean enabled); + + /** + * Gets the current state of the caret. + * @param aEnabled [OUT] set to the current caret state, as set by SetCaretEnabled + * @return if aOutEnabled==null, returns NS_ERROR_INVALID_ARG + * else NS_OK + */ + boolean getCaretEnabled(); + /** CharacterMove will move the selection one character forward/backward in the document. * this will also have the effect of collapsing the selection if the aExtend = PR_FALSE * the "point" of selection that is extended is considered the "focus" point. diff --git a/mozilla/content/base/src/nsDocumentViewer.cpp b/mozilla/content/base/src/nsDocumentViewer.cpp index de5a4423515..95babda7424 100644 --- a/mozilla/content/base/src/nsDocumentViewer.cpp +++ b/mozilla/content/base/src/nsDocumentViewer.cpp @@ -81,6 +81,7 @@ //focus #include "nsIDOMEventReceiver.h" #include "nsIDOMFocusListener.h" +#include "nsISelectionController.h" static NS_DEFINE_CID(kEventQueueService, NS_EVENTQUEUESERVICE_CID); @@ -1023,8 +1024,11 @@ nsresult DocumentViewerImpl::GetDocumentSelection(nsIDOMSelection **aSelection) { if (!aSelection) return NS_ERROR_NULL_POINTER; if (!mPresShell) return NS_ERROR_NOT_INITIALIZED; - - return mPresShell->GetSelection(SELECTION_NORMAL, aSelection); + nsCOMPtr selcon; + selcon = do_QueryInterface(mPresShell); + if (selcon) + return selcon->GetSelection(nsISelectionController::SELECTION_NORMAL, aSelection); + return NS_ERROR_FAILURE; } NS_IMETHODIMP @@ -1811,10 +1815,14 @@ nsDocViewerFocusListener::Focus(nsIDOMEvent* aEvent) nsCOMPtr ps; result = mDocViewer->GetPresShell(*getter_AddRefs(ps)); - if(NS_FAILED(result) || !ps) return result?result:NS_ERROR_FAILURE; - ps->RepaintSelection(SELECTION_NORMAL); + + nsCOMPtr selcon; + selcon = do_QueryInterface(ps,&result); + if(NS_FAILED(result) || !selcon) + return result?result:NS_ERROR_FAILURE; + selcon->RepaintSelection(nsISelectionController::SELECTION_NORMAL); } return result; } @@ -1841,10 +1849,14 @@ nsDocViewerFocusListener::Blur(nsIDOMEvent* aEvent) nsCOMPtr ps; result = mDocViewer->GetPresShell(*getter_AddRefs(ps));//deref once cause it take a ptr ref - if(NS_FAILED(result) || !ps) return result?result:NS_ERROR_FAILURE; - ps->RepaintSelection(SELECTION_NORMAL); + + nsCOMPtr selcon; + selcon = do_QueryInterface(ps,&result); + if(NS_FAILED(result) || !selcon) + return result?result:NS_ERROR_FAILURE; + selcon->RepaintSelection(nsISelectionController::SELECTION_NORMAL); } return result; } diff --git a/mozilla/content/base/src/nsSelection.cpp b/mozilla/content/base/src/nsSelection.cpp index 83be3aa908e..b0727318d52 100644 --- a/mozilla/content/base/src/nsSelection.cpp +++ b/mozilla/content/base/src/nsSelection.cpp @@ -69,6 +69,7 @@ #include "nsIDOMDocument.h" #include "nsIDocument.h" +#include "nsISelectionController.h"//for the enums #define STATUS_CHECK_RETURN_MACRO() {if (!mTracker) return NS_ERROR_FAILURE;} //#define DEBUG_TABLE 1 @@ -156,7 +157,7 @@ public: nsresult GetSelectionRegionRect(SelectionRegion aRegion, nsRect *aRect); nsresult ScrollRectIntoView(nsRect& aRect, PRIntn aVPercent, PRIntn aHPercent); - NS_IMETHOD ScrollIntoView(SelectionRegion aRegion=SELECTION_FOCUS_REGION); + NS_IMETHOD ScrollIntoView(SelectionRegion aRegion=nsISelectionController::SELECTION_FOCUS_REGION); nsresult AddItem(nsIDOMRange *aRange); nsresult RemoveItem(nsIDOMRange *aRange); @@ -320,7 +321,7 @@ private: NS_IMETHOD SetHint(PRBool aHintRight); NS_IMETHOD GetHint(PRBool *aHintRight); - nsDOMSelection *mDomSelections[NUM_SELECTIONTYPES]; + nsDOMSelection *mDomSelections[nsISelectionController::NUM_SELECTIONTYPES]; // Table selection support. Unfortunately, we can't get at nsITableCellLayout // and nsITableLayout through nsIFrame, so we have to duplicate editor code here @@ -537,12 +538,12 @@ GetIndexFromSelectionType(SelectionType aType) { switch (aType) { - case SELECTION_NORMAL: return 0; break; - case SELECTION_SPELLCHECK: return 1; break; - case SELECTION_IME_RAWINPUT: return 2; break; - case SELECTION_IME_SELECTEDRAWTEXT: return 3; break; - case SELECTION_IME_CONVERTEDTEXT: return 4; break; - case SELECTION_IME_SELECTEDCONVERTEDTEXT: return 5; break; + case nsISelectionController::SELECTION_NORMAL: return 0; break; + case nsISelectionController::SELECTION_SPELLCHECK: return 1; break; + case nsISelectionController::SELECTION_IME_RAWINPUT: return 2; break; + case nsISelectionController::SELECTION_IME_SELECTEDRAWTEXT: return 3; break; + case nsISelectionController::SELECTION_IME_CONVERTEDTEXT: return 4; break; + case nsISelectionController::SELECTION_IME_SELECTEDCONVERTEDTEXT: return 5; break; default:return -1;break; } } @@ -552,14 +553,14 @@ GetSelectionTypeFromIndex(PRInt8 aIndex) { switch (aIndex) { - case 0: return SELECTION_NORMAL;break; - case 1: return SELECTION_SPELLCHECK;break; - case 2: return SELECTION_IME_RAWINPUT;break; - case 3: return SELECTION_IME_SELECTEDRAWTEXT;break; - case 4: return SELECTION_IME_CONVERTEDTEXT;break; - case 5: return SELECTION_IME_SELECTEDCONVERTEDTEXT;break; + case 0: return nsISelectionController::SELECTION_NORMAL;break; + case 1: return nsISelectionController::SELECTION_SPELLCHECK;break; + case 2: return nsISelectionController::SELECTION_IME_RAWINPUT;break; + case 3: return nsISelectionController::SELECTION_IME_SELECTEDRAWTEXT;break; + case 4: return nsISelectionController::SELECTION_IME_CONVERTEDTEXT;break; + case 5: return nsISelectionController::SELECTION_IME_SELECTEDCONVERTEDTEXT;break; default: - return SELECTION_NORMAL;break; + return nsISelectionController::SELECTION_NORMAL;break; } } @@ -728,10 +729,10 @@ nsSelection::nsSelection() { NS_INIT_REFCNT(); PRInt32 i; - for (i = 0;iListen(mDomSelections[index]); } @@ -796,7 +797,7 @@ nsSelection::~nsSelection() NS_IF_RELEASE(sTbodyAtom); } PRInt32 i; - for (i = 0;imessage) { - PRInt8 index = GetIndexFromSelectionType(SELECTION_NORMAL); + PRInt8 index = GetIndexFromSelectionType(nsISelectionController::SELECTION_NORMAL); result = mDomSelections[index]->ScrollIntoView(); } return result; @@ -1265,7 +1266,7 @@ nsSelection::MoveCaret(PRUint32 aKeycode, PRBool aContinue, nsSelectionAmount aA PRBool isCollapsed; nscoord desiredX; //we must keep this around and revalidate it when its just UP/DOWN - PRInt8 index = GetIndexFromSelectionType(SELECTION_NORMAL); + PRInt8 index = GetIndexFromSelectionType(nsISelectionController::SELECTION_NORMAL); result = mDomSelections[index]->GetIsCollapsed(&isCollapsed); if (NS_FAILED(result)) return result; @@ -1571,14 +1572,14 @@ nsSelection::HandleDrag(nsIPresContext *aPresContext, nsIFrame *aFrame, nsPoint& NS_IMETHODIMP nsSelection::StartAutoScrollTimer(nsIPresContext *aPresContext, nsIFrame *aFrame, nsPoint& aPoint, PRUint32 aDelay) { - PRInt8 index = GetIndexFromSelectionType(SELECTION_NORMAL); + PRInt8 index = GetIndexFromSelectionType(nsISelectionController::SELECTION_NORMAL); return mDomSelections[index]->StartAutoScrollTimer(aPresContext, aFrame, aPoint, aDelay); } NS_IMETHODIMP nsSelection::StopAutoScrollTimer() { - PRInt8 index = GetIndexFromSelectionType(SELECTION_NORMAL); + PRInt8 index = GetIndexFromSelectionType(nsISelectionController::SELECTION_NORMAL); return mDomSelections[index]->StopAutoScrollTimer(); } @@ -1605,7 +1606,7 @@ nsSelection::TakeFocus(nsIContent *aNewFocus, PRUint32 aContentOffset, //return NS_ERROR_FAILURE; //END HACKHACKHACK /checking for root frames/content - PRInt8 index = GetIndexFromSelectionType(SELECTION_NORMAL); + PRInt8 index = GetIndexFromSelectionType(nsISelectionController::SELECTION_NORMAL); domNode = do_QueryInterface(aNewFocus); //traverse through document and unselect crap here if (!aContinueSelection){ //single click? setting cursor down @@ -1646,7 +1647,7 @@ nsSelection::TakeFocus(nsIContent *aNewFocus, PRUint32 aContentOffset, } } - return NotifySelectionListeners(SELECTION_NORMAL); + return NotifySelectionListeners(nsISelectionController::SELECTION_NORMAL); } @@ -1662,7 +1663,7 @@ nsSelection::LookUpSelection(nsIContent *aContent, PRInt32 aContentOffset, PRInt *aReturnDetails = nsnull; PRInt8 j; - for (j = (PRInt8) 0; j < (PRInt8)NUM_SELECTIONTYPES; j++){ + for (j = (PRInt8) 0; j < (PRInt8)nsISelectionController::NUM_SELECTIONTYPES; j++){ if (mDomSelections[j]) mDomSelections[j]->LookUpSelection(aContent, aContentOffset, aContentLength, aReturnDetails, (SelectionType)(1<=0,"Bad mBatching"); if (mBatching == 0 && mChangesDuringBatching){ mChangesDuringBatching = PR_FALSE; - NotifySelectionListeners(SELECTION_NORMAL); + NotifySelectionListeners(nsISelectionController::SELECTION_NORMAL); } return result; } @@ -2038,7 +2039,7 @@ nsSelection::HandleTableSelection(nsIContent *aParentContent, PRInt32 aContentOf // Stack-class to wrap all table selection changes in // BeginBatchChanges() / EndBatchChanges() - PRInt8 index = GetIndexFromSelectionType(SELECTION_NORMAL); + PRInt8 index = GetIndexFromSelectionType(nsISelectionController::SELECTION_NORMAL); nsSelectionBatcher selectionBatcher(mDomSelections[index]); // When doing table selection, always set the direction to next @@ -2252,7 +2253,7 @@ nsSelection::SelectBlockOfCells(nsIContent *aEndCell) PRInt32 curRowIndex, curColIndex; // Examine all cell nodes, starting with first one found above - PRInt8 index = GetIndexFromSelectionType(SELECTION_NORMAL); + PRInt8 index = GetIndexFromSelectionType(nsISelectionController::SELECTION_NORMAL); while (cellNode) { nsCOMPtr cellContent = do_QueryInterface(cellNode); @@ -2367,7 +2368,7 @@ nsSelection::GetFirstSelectedCellAndRange(nsIDOMNode **aCell, nsIDOMRange **aRan *aRange = nsnull; nsCOMPtr firstRange; - PRInt8 index = GetIndexFromSelectionType(SELECTION_NORMAL); + PRInt8 index = GetIndexFromSelectionType(nsISelectionController::SELECTION_NORMAL); nsresult result = mDomSelections[index]->GetRangeAt(0, getter_AddRefs(firstRange)); if (NS_FAILED(result)) return result; if (!firstRange) return NS_ERROR_FAILURE; @@ -2396,7 +2397,7 @@ nsSelection::GetNextSelectedCellAndRange(nsIDOMNode **aCell, nsIDOMRange **aRang *aRange = nsnull; PRInt32 rangeCount; - PRInt8 index = GetIndexFromSelectionType(SELECTION_NORMAL); + PRInt8 index = GetIndexFromSelectionType(nsISelectionController::SELECTION_NORMAL); nsresult result = mDomSelections[index]->GetRangeCount(&rangeCount); if (NS_FAILED(result)) return result; @@ -2520,7 +2521,7 @@ nsSelection::CreateAndAddRange(nsIDOMNode *aParentNode, PRInt32 aOffset) result = range->SetEnd(aParentNode, aOffset+1); if (NS_FAILED(result)) return result; - PRInt8 index = GetIndexFromSelectionType(SELECTION_NORMAL); + PRInt8 index = GetIndexFromSelectionType(nsISelectionController::SELECTION_NORMAL); return mDomSelections[index]->AddRange(range); } @@ -2572,7 +2573,7 @@ nsSelection::DeleteFromDocument() // last item BEFORE the current range, rather than the range itself, // before we do the delete. PRBool isCollapsed; - PRInt8 index = GetIndexFromSelectionType(SELECTION_NORMAL); + PRInt8 index = GetIndexFromSelectionType(nsISelectionController::SELECTION_NORMAL); mDomSelections[index]->GetIsCollapsed( &isCollapsed); if (isCollapsed) { @@ -4870,12 +4871,12 @@ nsDOMSelection::GetSelectionRegionRect(SelectionRegion aRegion, nsRect *aRect) switch (aRegion) { - case SELECTION_ANCHOR_REGION: + case nsISelectionController::SELECTION_ANCHOR_REGION: node = FetchAnchorNode(); nodeOffset = FetchAnchorOffset(); isEndNode = GetDirection() == eDirPrevious; break; - case SELECTION_FOCUS_REGION: + case nsISelectionController::SELECTION_FOCUS_REGION: node = FetchFocusNode(); nodeOffset = FetchFocusOffset(); isEndNode = GetDirection() == eDirNext; @@ -5116,19 +5117,23 @@ nsDOMSelection::ScrollIntoView(SelectionRegion aRegion) result = GetPresShell(getter_AddRefs(presShell)); if (NS_FAILED(result)) return result; + nsCOMPtr selCon; + selCon = do_QueryInterface(presShell); + if (selCon) + { + StCaretHider caretHider(selCon); // stack-based class hides and shows the caret - StCaretHider caretHider(presShell); // stack-based class hides and shows the caret + // + // Scroll the selection region into view. + // + nsRect rect; + result = GetSelectionRegionRect(aRegion, &rect); - // - // Scroll the selection region into view. - // - nsRect rect; - result = GetSelectionRegionRect(aRegion, &rect); + if (NS_FAILED(result)) + return result; - if (NS_FAILED(result)) - return result; - - result = ScrollRectIntoView(rect, NS_PRESSHELL_SCROLL_ANYWHERE, NS_PRESSHELL_SCROLL_ANYWHERE); + result = ScrollRectIntoView(rect, NS_PRESSHELL_SCROLL_ANYWHERE, NS_PRESSHELL_SCROLL_ANYWHERE); + } return result; } diff --git a/mozilla/docshell/base/nsWebShell.cpp b/mozilla/docshell/base/nsWebShell.cpp index 2bfe718c658..e7400b1e255 100644 --- a/mozilla/docshell/base/nsWebShell.cpp +++ b/mozilla/docshell/base/nsWebShell.cpp @@ -1497,9 +1497,12 @@ nsWebShell::SelectAll(void) nsCOMPtr presShell; rv = docViewer->GetPresShell(*getter_AddRefs(presShell)); if (NS_FAILED(rv) || !presShell) return rv; + + nsCOMPtr selCon = do_QueryInterface(presShell); + if (NS_FAILED(rv) || !selCon) return rv; nsCOMPtr selection; - rv = presShell->GetSelection(SELECTION_NORMAL, getter_AddRefs(selection)); + rv = selCon->GetSelection(nsISelectionController::SELECTION_NORMAL, getter_AddRefs(selection)); if (NS_FAILED(rv) || !selection) return rv; // Get the document object diff --git a/mozilla/editor/base/IMETextTxn.cpp b/mozilla/editor/base/IMETextTxn.cpp index 079668581e9..1f899068bcd 100644 --- a/mozilla/editor/base/IMETextTxn.cpp +++ b/mozilla/editor/base/IMETextTxn.cpp @@ -113,8 +113,8 @@ NS_IMETHODIMP IMETextTxn::Undo(void) printf("Undo IME Text element = %p\n", mElement.get()); #endif - nsCOMPtr ps = do_QueryReferent(mPresShellWeak); - if (!ps) return NS_ERROR_NOT_INITIALIZED; + nsCOMPtr selCon = do_QueryReferent(mPresShellWeak); + if (!selCon) return NS_ERROR_NOT_INITIALIZED; nsresult result; PRUint32 length = mStringToInsert.Length(); @@ -122,7 +122,7 @@ NS_IMETHODIMP IMETextTxn::Undo(void) if (NS_SUCCEEDED(result)) { // set the selection to the insertion point where the string was removed nsCOMPtr selection; - result = ps->GetSelection(SELECTION_NORMAL, getter_AddRefs(selection)); + result = selCon->GetSelection(nsISelectionController::SELECTION_NORMAL, getter_AddRefs(selection)); if (NS_SUCCEEDED(result) && selection) { result = selection->Collapse(mElement, mOffset); NS_ASSERTION((NS_SUCCEEDED(result)), "selection could not be collapsed after undo of IME insert."); @@ -242,16 +242,16 @@ static SelectionType TextRangeToSelection(int aTextRangeType) switch(aTextRangeType) { case nsIPrivateTextRange::TEXTRANGE_RAWINPUT: - return SELECTION_IME_RAWINPUT; + return nsISelectionController::SELECTION_IME_RAWINPUT; case nsIPrivateTextRange::TEXTRANGE_SELECTEDRAWTEXT: - return SELECTION_IME_SELECTEDRAWTEXT; + return nsISelectionController::SELECTION_IME_SELECTEDRAWTEXT; case nsIPrivateTextRange::TEXTRANGE_CONVERTEDTEXT: - return SELECTION_IME_CONVERTEDTEXT; + return nsISelectionController::SELECTION_IME_CONVERTEDTEXT; case nsIPrivateTextRange::TEXTRANGE_SELECTEDCONVERTEDTEXT: - return SELECTION_IME_SELECTEDCONVERTEDTEXT; + return nsISelectionController::SELECTION_IME_SELECTEDCONVERTEDTEXT; case nsIPrivateTextRange::TEXTRANGE_CARETPOSITION: default: - return SELECTION_NORMAL; + return nsISelectionController::SELECTION_NORMAL; }; } @@ -267,10 +267,10 @@ NS_IMETHODIMP IMETextTxn::GetData(nsString& aResult,nsIPrivateTextRangeList** aT static SelectionType sel[4]= { - SELECTION_IME_RAWINPUT, - SELECTION_IME_SELECTEDRAWTEXT, - SELECTION_IME_CONVERTEDTEXT, - SELECTION_IME_SELECTEDCONVERTEDTEXT + nsISelectionController::SELECTION_IME_RAWINPUT, + nsISelectionController::SELECTION_IME_SELECTEDRAWTEXT, + nsISelectionController::SELECTION_IME_CONVERTEDTEXT, + nsISelectionController::SELECTION_IME_SELECTEDCONVERTEDTEXT }; NS_IMETHODIMP IMETextTxn::CollapseTextSelection(void) @@ -309,13 +309,14 @@ NS_IMETHODIMP IMETextTxn::CollapseTextSelection(void) // // run through the text range list, if any // - nsCOMPtr ps = do_QueryReferent(mPresShellWeak); - if (!ps) return NS_ERROR_NOT_INITIALIZED; + nsCOMPtr selCon = do_QueryReferent(mPresShellWeak); + if (!selCon) return NS_ERROR_NOT_INITIALIZED; + result = mRangeList->GetLength(&textRangeListLength); if(NS_FAILED(result)) return result; nsCOMPtr selection; - result = ps->GetSelection(SELECTION_NORMAL, getter_AddRefs(selection)); + result = selCon->GetSelection(nsISelectionController::SELECTION_NORMAL, getter_AddRefs(selection)); nsCOMPtr imeSel; if(NS_SUCCEEDED(result)) { @@ -324,7 +325,7 @@ NS_IMETHODIMP IMETextTxn::CollapseTextSelection(void) { for(PRInt8 selIdx = 0; selIdx < 4;selIdx++) { - result = ps->GetSelection(sel[selIdx], getter_AddRefs(imeSel)); + result = selCon->GetSelection(sel[selIdx], getter_AddRefs(imeSel)); if(NS_SUCCEEDED(result)) { result = imeSel->ClearSelection(); @@ -369,7 +370,7 @@ NS_IMETHODIMP IMETextTxn::CollapseTextSelection(void) nsCOMPtr newRange; - result= ps->GetSelection(TextRangeToSelection(textRangeType), + result= selCon->GetSelection(TextRangeToSelection(textRangeType), getter_AddRefs(imeSel)); NS_ASSERTION(NS_SUCCEEDED(result), "Cannot get selction"); if(NS_FAILED(result)) diff --git a/mozilla/editor/base/PlaceholderTxn.cpp b/mozilla/editor/base/PlaceholderTxn.cpp index 0c048e54cf2..9188958e7b5 100644 --- a/mozilla/editor/base/PlaceholderTxn.cpp +++ b/mozilla/editor/base/PlaceholderTxn.cpp @@ -100,10 +100,10 @@ NS_IMETHODIMP PlaceholderTxn::Undo(void) if (NS_FAILED(res)) return res; // now restore selection - nsCOMPtr ps = do_QueryReferent(mPresShellWeak); - if (!ps) return NS_ERROR_NOT_INITIALIZED; + nsCOMPtr selCon = do_QueryReferent(mPresShellWeak); + if (!selCon) return NS_ERROR_NOT_INITIALIZED; nsCOMPtr selection; - res = ps->GetSelection(SELECTION_NORMAL, getter_AddRefs(selection)); + res = selCon->GetSelection(nsISelectionController::SELECTION_NORMAL, getter_AddRefs(selection)); if (NS_FAILED(res)) return res; if (!selection) return NS_ERROR_NULL_POINTER; if (!mStartSel) return NS_ERROR_NULL_POINTER; @@ -119,10 +119,10 @@ NS_IMETHODIMP PlaceholderTxn::Redo(void) if (NS_FAILED(res)) return res; // now restore selection - nsCOMPtr ps = do_QueryReferent(mPresShellWeak); - if (!ps) return NS_ERROR_NOT_INITIALIZED; + nsCOMPtr selCon = do_QueryReferent(mPresShellWeak); + if (!selCon) return NS_ERROR_NOT_INITIALIZED; nsCOMPtr selection; - res = ps->GetSelection(SELECTION_NORMAL, getter_AddRefs(selection)); + res = selCon->GetSelection(nsISelectionController::SELECTION_NORMAL, getter_AddRefs(selection)); if (NS_FAILED(res)) return res; if (!selection) return NS_ERROR_NULL_POINTER; res = mEndSel.RestoreSelection(selection); @@ -272,10 +272,10 @@ NS_IMETHODIMP PlaceholderTxn::Commit() NS_IMETHODIMP PlaceholderTxn::RememberEndingSelection() { - nsCOMPtr ps = do_QueryReferent(mPresShellWeak); - if (!ps) return NS_ERROR_NOT_INITIALIZED; + nsCOMPtr selCon = do_QueryReferent(mPresShellWeak); + if (!selCon) return NS_ERROR_NOT_INITIALIZED; nsCOMPtr selection; - nsresult res = ps->GetSelection(SELECTION_NORMAL, getter_AddRefs(selection)); + nsresult res = selCon->GetSelection(nsISelectionController::SELECTION_NORMAL, getter_AddRefs(selection)); if (NS_FAILED(res)) return res; if (!selection) return NS_ERROR_NULL_POINTER; res = mEndSel.SaveSelection(selection); diff --git a/mozilla/editor/base/nsEditor.cpp b/mozilla/editor/base/nsEditor.cpp index 5bb01ccab6c..cfce5e8cbb7 100644 --- a/mozilla/editor/base/nsEditor.cpp +++ b/mozilla/editor/base/nsEditor.cpp @@ -817,7 +817,7 @@ nsEditor::~nsEditor() NS_IMPL_ADDREF(nsEditor) NS_IMPL_RELEASE(nsEditor) -NS_IMPL_QUERY_INTERFACE2(nsEditor, nsIEditor, nsIEditorIMESupport) +NS_IMPL_QUERY_INTERFACE3(nsEditor, nsIEditor, nsIEditorIMESupport, nsISupportsWeakReference) #ifdef XP_MAC #pragma mark - @@ -928,10 +928,27 @@ nsEditor::GetPresShell(nsIPresShell **aPS) if (!mPresShellWeak) return NS_ERROR_NOT_INITIALIZED; nsCOMPtr ps = do_QueryReferent(mPresShellWeak); if (!ps) return NS_ERROR_NOT_INITIALIZED; - return ps->QueryInterface(NS_GET_IID(nsIPresShell), (void **)aPS); + NS_ADDREF(*aPS = ps); + return NS_OK; } +NS_IMETHODIMP +nsEditor::GetSelectionController(nsISelectionController **aSel) +{ + if (!aSel) + return NS_ERROR_NULL_POINTER; + *aSel = nsnull; // init out param + NS_PRECONDITION(mPresShellWeak, "bad state, null mPresShellWeak"); + if (!mPresShellWeak) return NS_ERROR_NOT_INITIALIZED; + nsCOMPtr selCon = do_QueryReferent(mPresShellWeak); + if (!selCon) return NS_ERROR_NOT_INITIALIZED; + NS_ADDREF(*aSel = selCon); + return NS_OK; +} + + + NS_IMETHODIMP nsEditor::GetSelection(nsIDOMSelection **aSelection) { @@ -939,9 +956,9 @@ nsEditor::GetSelection(nsIDOMSelection **aSelection) return NS_ERROR_NULL_POINTER; *aSelection = nsnull; if (!mPresShellWeak) return NS_ERROR_NOT_INITIALIZED; - nsCOMPtr ps = do_QueryReferent(mPresShellWeak); - if (!ps) return NS_ERROR_NOT_INITIALIZED; - nsresult result = ps->GetSelection(SELECTION_NORMAL, aSelection); // does an addref + nsCOMPtr selcon = do_QueryReferent(mPresShellWeak); + if (!selcon) return NS_ERROR_NOT_INITIALIZED; + nsresult result = selcon->GetSelection(nsISelectionController::SELECTION_NORMAL, aSelection); // does an addref return result; } @@ -1257,9 +1274,9 @@ NS_IMETHODIMP nsEditor::SelectAll() nsCOMPtr selection; if (!mPresShellWeak) return NS_ERROR_NOT_INITIALIZED; - nsCOMPtr ps = do_QueryReferent(mPresShellWeak); - if (!ps) return NS_ERROR_NOT_INITIALIZED; - nsresult result = ps->GetSelection(SELECTION_NORMAL, getter_AddRefs(selection)); + nsCOMPtr selcon = do_QueryReferent(mPresShellWeak); + if (!selcon) return NS_ERROR_NOT_INITIALIZED; + nsresult result = selcon->GetSelection(nsISelectionController::SELECTION_NORMAL, getter_AddRefs(selection)); if (NS_SUCCEEDED(result) && selection) { result = SelectEntireDocument(selection); @@ -1273,9 +1290,9 @@ NS_IMETHODIMP nsEditor::BeginningOfDocument() nsCOMPtr selection; if (!mPresShellWeak) return NS_ERROR_NOT_INITIALIZED; - nsCOMPtr ps = do_QueryReferent(mPresShellWeak); - if (!ps) return NS_ERROR_NOT_INITIALIZED; - nsresult result = ps->GetSelection(SELECTION_NORMAL, getter_AddRefs(selection)); + nsCOMPtr selcon = do_QueryReferent(mPresShellWeak); + if (!selcon) return NS_ERROR_NOT_INITIALIZED; + nsresult result = selcon->GetSelection(nsISelectionController::SELECTION_NORMAL, getter_AddRefs(selection)); if (NS_SUCCEEDED(result) && selection) { nsCOMPtr nodeList; @@ -1332,9 +1349,9 @@ NS_IMETHODIMP nsEditor::EndOfDocument() nsCOMPtr selection; if (!mPresShellWeak) return NS_ERROR_NOT_INITIALIZED; - nsCOMPtr ps = do_QueryReferent(mPresShellWeak); - if (!ps) return NS_ERROR_NOT_INITIALIZED; - nsresult result = ps->GetSelection(SELECTION_NORMAL, getter_AddRefs(selection)); + nsCOMPtr selcon = do_QueryReferent(mPresShellWeak); + if (!selcon) return NS_ERROR_NOT_INITIALIZED; + nsresult result = selcon->GetSelection(nsISelectionController::SELECTION_NORMAL, getter_AddRefs(selection)); if (NS_SUCCEEDED(result) && selection) { nsCOMPtr nodeList; @@ -4886,12 +4903,12 @@ nsresult nsEditor::EndUpdateViewBatch() { NS_PRECONDITION(mUpdateCount>0, "bad state"); - nsCOMPtr presShell; - nsresult rv = GetPresShell(getter_AddRefs(presShell)); + nsCOMPtr selCon; + nsresult rv = GetSelectionController(getter_AddRefs(selCon)); if (NS_FAILED(rv)) return rv; - StCaretHider caretHider(presShell); + StCaretHider caretHider(selCon); nsCOMPtrselection; nsresult selectionResult = GetSelection(getter_AddRefs(selection)); @@ -4910,7 +4927,10 @@ nsresult nsEditor::EndUpdateViewBatch() #else mViewManager->EndUpdateViewBatch(NS_VMREFRESH_IMMEDIATE); #endif - presShell->EndReflowBatching(PR_TRUE); + nsCOMPtr presShell; + nsresult rv = GetPresShell(getter_AddRefs(presShell)); + if (NS_SUCCEEDED(rv) && presShell) + presShell->EndReflowBatching(PR_TRUE); } } @@ -5147,7 +5167,7 @@ NS_IMETHODIMP nsEditor::CreateTxnForDeleteElement(nsIDOMNode * aElement, if (!mPresShellWeak) return NS_ERROR_NOT_INITIALIZED; nsCOMPtr ps = do_QueryReferent(mPresShellWeak); if (!ps) return NS_ERROR_NOT_INITIALIZED; - result = ps->GetSelection(SELECTION_NORMAL, getter_AddRefs(selection)); + result = ps->GetSelection(nsISelectionController::SELECTION_NORMAL, getter_AddRefs(selection)); if (NS_SUCCEEDED(result) && selection) { PRBool collapsed; @@ -5230,9 +5250,9 @@ nsEditor::CreateTxnForDeleteSelection(nsIEditor::EDirection aAction, nsresult result; nsCOMPtr selection; if (!mPresShellWeak) return NS_ERROR_NOT_INITIALIZED; - nsCOMPtr ps = do_QueryReferent(mPresShellWeak); - if (!ps) return NS_ERROR_NOT_INITIALIZED; - result = ps->GetSelection(SELECTION_NORMAL, getter_AddRefs(selection)); + nsCOMPtr selcon = do_QueryReferent(mPresShellWeak); + if (!selcon) return NS_ERROR_NOT_INITIALIZED; + result = selcon->GetSelection(nsISelectionController::SELECTION_NORMAL, getter_AddRefs(selection)); if ((NS_SUCCEEDED(result)) && selection) { // Check whether the selection is collapsed and we should do nothing: diff --git a/mozilla/editor/base/nsEditor.h b/mozilla/editor/base/nsEditor.h index 1039a5bdf42..4b5d20f9bb1 100644 --- a/mozilla/editor/base/nsEditor.h +++ b/mozilla/editor/base/nsEditor.h @@ -24,7 +24,7 @@ #define __editor_h__ #include "nsCOMPtr.h" -#include "nsWeakPtr.h" +#include "nsWeakReference.h" #include "nsIEditor.h" #include "nsIEditorIMESupport.h" @@ -140,7 +140,8 @@ class nsSelectionState * delegate the actual commands to the editor independent of the XPFE implementation. */ class nsEditor : public nsIEditor, - public nsIEditorIMESupport + public nsIEditorIMESupport, + public nsSupportsWeakReference { public: @@ -192,6 +193,7 @@ public: NS_IMETHOD SetFlags(PRUint32 aFlags) = 0; NS_IMETHOD GetDocument(nsIDOMDocument **aDoc); NS_IMETHOD GetPresShell(nsIPresShell **aPS); + NS_IMETHOD GetSelectionController(nsISelectionController **aSel); NS_IMETHOD GetSelection(nsIDOMSelection **aSelection); NS_IMETHOD EnableUndo(PRBool aEnable); diff --git a/mozilla/editor/base/nsEditorCommands.cpp b/mozilla/editor/base/nsEditorCommands.cpp index a890024f38e..2a623f6dff2 100644 --- a/mozilla/editor/base/nsEditorCommands.cpp +++ b/mozilla/editor/base/nsEditorCommands.cpp @@ -279,15 +279,11 @@ nsSelectionMoveCommands::DoCommand(const PRUnichar *aCommand, nsISupports * refC return NS_ERROR_FAILURE; nsresult rv; - - nsCOMPtr presShell; - rv = aEditor->GetPresShell(getter_AddRefs(presShell)); - if (NS_FAILED(rv) || !presShell) - return rv ? rv : NS_ERROR_FAILURE; - - nsCOMPtr selCont = do_QueryInterface(presShell); - if (!selCont) - return NS_ERROR_FAILURE; + + nsCOMPtr selCont; + rv = aEditor->GetSelectionController(getter_AddRefs(selCont)); + if (NS_FAILED(rv) || !selCont) + return rv?rv:NS_ERROR_FAILURE; nsAutoString cmdString(aCommand); diff --git a/mozilla/editor/base/nsEditorController.cpp b/mozilla/editor/base/nsEditorController.cpp index 419cabebf80..5b9e2ce5bac 100644 --- a/mozilla/editor/base/nsEditorController.cpp +++ b/mozilla/editor/base/nsEditorController.cpp @@ -295,42 +295,7 @@ NS_IMETHODIMP nsEditorController::GetSelectionController(nsISelectionController if (NS_FAILED(result) || !editor) return result ? result : NS_ERROR_FAILURE; - nsCOMPtr presShell; - result = editor->GetPresShell(getter_AddRefs(presShell)); - if (NS_FAILED(result) || !presShell) - return result ? result : NS_ERROR_FAILURE; - - nsCOMPtr selController = do_QueryInterface(presShell); - if (selController) - { - *aSelCon = selController; - NS_ADDREF(*aSelCon); - return NS_OK; - } - return NS_ERROR_FAILURE; -/* - NS_ENSURE_ARG_POINTER(aSelCon); - nsCOMPtr doc; - mContent->GetDocument(*getter_AddRefs(doc)); - - *aSelCon = nsnull; - if (doc) - { - PRInt32 i = doc->GetNumberOfShells(); - if (i == 0) - return NS_ERROR_FAILURE; - - nsCOMPtr presShell = getter_AddRefs(doc->GetShellAt(0)); - nsCOMPtr selController = do_QueryInterface(presShell); - if (selController) - { - *aSelCon = selController; - (*aSelCon)->AddRef(); - return NS_OK; - } - } - return NS_ERROR_FAILURE; - */ + return editor->GetSelectionController(aSelCon); } NS_IMETHODIMP nsEditorController::GetFrame(nsIGfxTextControlFrame **aFrame) diff --git a/mozilla/editor/base/nsEditorEventListeners.cpp b/mozilla/editor/base/nsEditorEventListeners.cpp index 10b753cb68e..a9685174f13 100644 --- a/mozilla/editor/base/nsEditorEventListeners.cpp +++ b/mozilla/editor/base/nsEditorEventListeners.cpp @@ -330,17 +330,14 @@ nsTextEditorKeyListener::ProcessShortCutKeys(nsIDOMEvent* aKeyEvent, PRBool& aPr nsresult nsTextEditorKeyListener::ScrollSelectionIntoView() { - nsCOMPtr presShell; + nsCOMPtr selCon; - nsresult result = mEditor->GetPresShell(getter_AddRefs(presShell)); + nsresult result = mEditor->GetSelectionController(getter_AddRefs(selCon)); - if (NS_FAILED(result)) - return result; + if (NS_FAILED(result) || ! selCon) + return result ? result: NS_ERROR_FAILURE; - if (!presShell) - return NS_ERROR_NULL_POINTER; - - return presShell->ScrollSelectionIntoView(SELECTION_NORMAL, SELECTION_FOCUS_REGION); + return selCon->ScrollSelectionIntoView(nsISelectionController::SELECTION_NORMAL, nsISelectionController::SELECTION_FOCUS_REGION); } /* @@ -1077,13 +1074,13 @@ nsTextEditorFocusListener::Focus(nsIDOMEvent* aEvent) nsCOMPtreditor = do_QueryInterface(mEditor); if (editor) { - nsCOMPtrps; - editor->GetPresShell(getter_AddRefs(ps)); - if (ps) + nsCOMPtrselCon; + editor->GetSelectionController(getter_AddRefs(selCon)); + if (selCon) { if (! (flags & nsIHTMLEditor::eEditorReadonlyMask)) { // only enable caret if the editor is not readonly - ps->SetCaretEnabled(PR_TRUE); + selCon->SetCaretEnabled(PR_TRUE); } nsCOMPtrdomDoc; @@ -1109,7 +1106,7 @@ nsTextEditorFocusListener::Focus(nsIDOMEvent* aEvent) } // end hack repaint #else - ps->RepaintSelection(SELECTION_NORMAL); + selCon->RepaintSelection(nsISelectionController::SELECTION_NORMAL); #endif } } @@ -1129,11 +1126,11 @@ nsTextEditorFocusListener::Blur(nsIDOMEvent* aEvent) nsCOMPtreditor = do_QueryInterface(mEditor); if (editor) { - nsCOMPtrps; - editor->GetPresShell(getter_AddRefs(ps)); - if (ps) + nsCOMPtrselCon; + editor->GetSelectionController(getter_AddRefs(selCon)); + if (selCon) { - ps->SetCaretEnabled(PR_FALSE); + selCon->SetCaretEnabled(PR_FALSE); nsCOMPtrdomDoc; editor->GetDocument(getter_AddRefs(domDoc)); @@ -1159,7 +1156,7 @@ nsTextEditorFocusListener::Blur(nsIDOMEvent* aEvent) } // end hack repaint #else - ps->RepaintSelection(SELECTION_NORMAL); + selCon->RepaintSelection(nsISelectionController::SELECTION_NORMAL); #endif } } diff --git a/mozilla/editor/base/nsEditorShell.cpp b/mozilla/editor/base/nsEditorShell.cpp index 29fac1b1695..e3bbd618631 100644 --- a/mozilla/editor/base/nsEditorShell.cpp +++ b/mozilla/editor/base/nsEditorShell.cpp @@ -685,15 +685,12 @@ nsEditorShell::ScrollSelectionIntoView() { nsCOMPtr editor = do_QueryInterface(mEditor); if (!editor) return NS_ERROR_NOT_INITIALIZED; - nsCOMPtr presShell; - nsresult result = editor->GetPresShell(getter_AddRefs(presShell)); - if (NS_FAILED(result)) - return result; - if (!presShell) - return NS_ERROR_NULL_POINTER; - - return presShell->ScrollSelectionIntoView(SELECTION_NORMAL, - SELECTION_FOCUS_REGION); + nsCOMPtr selCon; + editor->GetSelectionController(getter_AddRefs(selCon)); + if (!selCon) + return NS_ERROR_UNEXPECTED; + return selCon->ScrollSelectionIntoView(nsISelectionController::SELECTION_NORMAL, + nsISelectionController::SELECTION_FOCUS_REGION); } NS_IMETHODIMP @@ -2839,12 +2836,11 @@ nsEditorShell::GetSelectionController(nsISelectionController** aSelectionControl if (!editor) return NS_ERROR_NOT_INITIALIZED; - nsCOMPtr presShell; - nsresult rv = editor->GetPresShell(getter_AddRefs(presShell)); + nsCOMPtr selCont; + nsresult rv = editor->GetSelectionController(getter_AddRefs(selCont)); if (NS_FAILED(rv)) return rv; - nsCOMPtr selCont (do_QueryInterface(presShell)); if (!selCont) return NS_ERROR_NO_INTERFACE; *aSelectionController = selCont; diff --git a/mozilla/editor/base/nsHTMLEditRules.cpp b/mozilla/editor/base/nsHTMLEditRules.cpp index 52d9cf7aec6..184eb4aa51f 100644 --- a/mozilla/editor/base/nsHTMLEditRules.cpp +++ b/mozilla/editor/base/nsHTMLEditRules.cpp @@ -168,9 +168,9 @@ nsHTMLEditRules::BeforeEdit(PRInt32 action, nsIEditor::EDirection aDirection) nsComponentManager::CreateInstance(kRangeCID, nsnull, NS_GET_IID(nsIDOMRange), getter_AddRefs(mUtilRange)); // turn off caret - nsCOMPtr pres; - mEditor->GetPresShell(getter_AddRefs(pres)); - if (pres) pres->SetCaretEnabled(PR_FALSE); + nsCOMPtr selCon; + mEditor->GetSelectionController(getter_AddRefs(selCon)); + if (selCon) selCon->SetCaretEnabled(PR_FALSE); // check that selection is in subtree defined by body node ConfirmSelectionInBody(); // let rules remember the top level action @@ -260,9 +260,9 @@ nsHTMLEditRules::AfterEdit(PRInt32 action, nsIEditor::EDirection aDirection) res = CreateBogusNodeIfNeeded(selection); // turn on caret - nsCOMPtr pres; - mEditor->GetPresShell(getter_AddRefs(pres)); - if (pres) pres->SetCaretEnabled(PR_TRUE); + nsCOMPtr selCon; + mEditor->GetSelectionController(getter_AddRefs(selCon)); + if (selCon) selCon->SetCaretEnabled(PR_TRUE); } return res; diff --git a/mozilla/editor/base/nsHTMLEditor.cpp b/mozilla/editor/base/nsHTMLEditor.cpp index 5015b1e03db..3d07461717d 100644 --- a/mozilla/editor/base/nsHTMLEditor.cpp +++ b/mozilla/editor/base/nsHTMLEditor.cpp @@ -4339,9 +4339,9 @@ NS_IMETHODIMP nsHTMLEditor::InsertFromTransferable(nsITransferable *transferable // Try to scroll the selection into view if the paste/drop succeeded if (NS_SUCCEEDED(rv)) { - nsCOMPtr presShell; - if (NS_SUCCEEDED(GetPresShell(getter_AddRefs(presShell))) && presShell) - presShell->ScrollSelectionIntoView(SELECTION_NORMAL, SELECTION_FOCUS_REGION); + nsCOMPtr selCon; + if (NS_SUCCEEDED(GetSelectionController(getter_AddRefs(selCon))) && selCon) + selCon->ScrollSelectionIntoView(nsISelectionController::SELECTION_NORMAL, nsISelectionController::SELECTION_FOCUS_REGION); } return rv; diff --git a/mozilla/editor/base/nsStyleSheetTxns.cpp b/mozilla/editor/base/nsStyleSheetTxns.cpp index a0a62773050..3f885a83944 100644 --- a/mozilla/editor/base/nsStyleSheetTxns.cpp +++ b/mozilla/editor/base/nsStyleSheetTxns.cpp @@ -68,8 +68,14 @@ AddStyleSheetTxn::Do() if (!mEditor || !mSheet) return NS_ERROR_NOT_INITIALIZED; + nsCOMPtr selCon; + mEditor->GetSelectionController(getter_AddRefs(selCon)); + if (!selCon) + return NS_ERROR_UNEXPECTED; + nsCOMPtr presShell; - mEditor->GetPresShell(getter_AddRefs(presShell)); + presShell = do_QueryInterface(selCon); + if (!presShell) return NS_ERROR_UNEXPECTED; @@ -99,8 +105,13 @@ AddStyleSheetTxn::Undo() if (!mEditor || !mSheet) return NS_ERROR_NOT_INITIALIZED; + nsCOMPtr selCon; + mEditor->GetSelectionController(getter_AddRefs(selCon)); + if (!selCon) + return NS_ERROR_UNEXPECTED; + nsCOMPtr presShell; - mEditor->GetPresShell(getter_AddRefs(presShell)); + presShell = do_QueryInterface(selCon); if (!presShell) return NS_ERROR_UNEXPECTED; @@ -205,8 +216,13 @@ RemoveStyleSheetTxn::Do() if (!mEditor || !mSheet) return NS_ERROR_NOT_INITIALIZED; + nsCOMPtr selCon; + mEditor->GetSelectionController(getter_AddRefs(selCon)); + if (!selCon) + return NS_ERROR_UNEXPECTED; + nsCOMPtr presShell; - mEditor->GetPresShell(getter_AddRefs(presShell)); + presShell = do_QueryInterface(selCon); if (!presShell) return NS_ERROR_UNEXPECTED; @@ -236,8 +252,13 @@ RemoveStyleSheetTxn::Undo() if (!mEditor || !mSheet) return NS_ERROR_NOT_INITIALIZED; + nsCOMPtr selCon; + mEditor->GetSelectionController(getter_AddRefs(selCon)); + if (!selCon) + return NS_ERROR_UNEXPECTED; + nsCOMPtr presShell; - mEditor->GetPresShell(getter_AddRefs(presShell)); + presShell = do_QueryInterface(selCon); if (!presShell) return NS_ERROR_UNEXPECTED; diff --git a/mozilla/editor/composer/src/nsEditorShell.cpp b/mozilla/editor/composer/src/nsEditorShell.cpp index 29fac1b1695..e3bbd618631 100644 --- a/mozilla/editor/composer/src/nsEditorShell.cpp +++ b/mozilla/editor/composer/src/nsEditorShell.cpp @@ -685,15 +685,12 @@ nsEditorShell::ScrollSelectionIntoView() { nsCOMPtr editor = do_QueryInterface(mEditor); if (!editor) return NS_ERROR_NOT_INITIALIZED; - nsCOMPtr presShell; - nsresult result = editor->GetPresShell(getter_AddRefs(presShell)); - if (NS_FAILED(result)) - return result; - if (!presShell) - return NS_ERROR_NULL_POINTER; - - return presShell->ScrollSelectionIntoView(SELECTION_NORMAL, - SELECTION_FOCUS_REGION); + nsCOMPtr selCon; + editor->GetSelectionController(getter_AddRefs(selCon)); + if (!selCon) + return NS_ERROR_UNEXPECTED; + return selCon->ScrollSelectionIntoView(nsISelectionController::SELECTION_NORMAL, + nsISelectionController::SELECTION_FOCUS_REGION); } NS_IMETHODIMP @@ -2839,12 +2836,11 @@ nsEditorShell::GetSelectionController(nsISelectionController** aSelectionControl if (!editor) return NS_ERROR_NOT_INITIALIZED; - nsCOMPtr presShell; - nsresult rv = editor->GetPresShell(getter_AddRefs(presShell)); + nsCOMPtr selCont; + nsresult rv = editor->GetSelectionController(getter_AddRefs(selCont)); if (NS_FAILED(rv)) return rv; - nsCOMPtr selCont (do_QueryInterface(presShell)); if (!selCont) return NS_ERROR_NO_INTERFACE; *aSelectionController = selCont; diff --git a/mozilla/editor/libeditor/base/IMETextTxn.cpp b/mozilla/editor/libeditor/base/IMETextTxn.cpp index 079668581e9..1f899068bcd 100644 --- a/mozilla/editor/libeditor/base/IMETextTxn.cpp +++ b/mozilla/editor/libeditor/base/IMETextTxn.cpp @@ -113,8 +113,8 @@ NS_IMETHODIMP IMETextTxn::Undo(void) printf("Undo IME Text element = %p\n", mElement.get()); #endif - nsCOMPtr ps = do_QueryReferent(mPresShellWeak); - if (!ps) return NS_ERROR_NOT_INITIALIZED; + nsCOMPtr selCon = do_QueryReferent(mPresShellWeak); + if (!selCon) return NS_ERROR_NOT_INITIALIZED; nsresult result; PRUint32 length = mStringToInsert.Length(); @@ -122,7 +122,7 @@ NS_IMETHODIMP IMETextTxn::Undo(void) if (NS_SUCCEEDED(result)) { // set the selection to the insertion point where the string was removed nsCOMPtr selection; - result = ps->GetSelection(SELECTION_NORMAL, getter_AddRefs(selection)); + result = selCon->GetSelection(nsISelectionController::SELECTION_NORMAL, getter_AddRefs(selection)); if (NS_SUCCEEDED(result) && selection) { result = selection->Collapse(mElement, mOffset); NS_ASSERTION((NS_SUCCEEDED(result)), "selection could not be collapsed after undo of IME insert."); @@ -242,16 +242,16 @@ static SelectionType TextRangeToSelection(int aTextRangeType) switch(aTextRangeType) { case nsIPrivateTextRange::TEXTRANGE_RAWINPUT: - return SELECTION_IME_RAWINPUT; + return nsISelectionController::SELECTION_IME_RAWINPUT; case nsIPrivateTextRange::TEXTRANGE_SELECTEDRAWTEXT: - return SELECTION_IME_SELECTEDRAWTEXT; + return nsISelectionController::SELECTION_IME_SELECTEDRAWTEXT; case nsIPrivateTextRange::TEXTRANGE_CONVERTEDTEXT: - return SELECTION_IME_CONVERTEDTEXT; + return nsISelectionController::SELECTION_IME_CONVERTEDTEXT; case nsIPrivateTextRange::TEXTRANGE_SELECTEDCONVERTEDTEXT: - return SELECTION_IME_SELECTEDCONVERTEDTEXT; + return nsISelectionController::SELECTION_IME_SELECTEDCONVERTEDTEXT; case nsIPrivateTextRange::TEXTRANGE_CARETPOSITION: default: - return SELECTION_NORMAL; + return nsISelectionController::SELECTION_NORMAL; }; } @@ -267,10 +267,10 @@ NS_IMETHODIMP IMETextTxn::GetData(nsString& aResult,nsIPrivateTextRangeList** aT static SelectionType sel[4]= { - SELECTION_IME_RAWINPUT, - SELECTION_IME_SELECTEDRAWTEXT, - SELECTION_IME_CONVERTEDTEXT, - SELECTION_IME_SELECTEDCONVERTEDTEXT + nsISelectionController::SELECTION_IME_RAWINPUT, + nsISelectionController::SELECTION_IME_SELECTEDRAWTEXT, + nsISelectionController::SELECTION_IME_CONVERTEDTEXT, + nsISelectionController::SELECTION_IME_SELECTEDCONVERTEDTEXT }; NS_IMETHODIMP IMETextTxn::CollapseTextSelection(void) @@ -309,13 +309,14 @@ NS_IMETHODIMP IMETextTxn::CollapseTextSelection(void) // // run through the text range list, if any // - nsCOMPtr ps = do_QueryReferent(mPresShellWeak); - if (!ps) return NS_ERROR_NOT_INITIALIZED; + nsCOMPtr selCon = do_QueryReferent(mPresShellWeak); + if (!selCon) return NS_ERROR_NOT_INITIALIZED; + result = mRangeList->GetLength(&textRangeListLength); if(NS_FAILED(result)) return result; nsCOMPtr selection; - result = ps->GetSelection(SELECTION_NORMAL, getter_AddRefs(selection)); + result = selCon->GetSelection(nsISelectionController::SELECTION_NORMAL, getter_AddRefs(selection)); nsCOMPtr imeSel; if(NS_SUCCEEDED(result)) { @@ -324,7 +325,7 @@ NS_IMETHODIMP IMETextTxn::CollapseTextSelection(void) { for(PRInt8 selIdx = 0; selIdx < 4;selIdx++) { - result = ps->GetSelection(sel[selIdx], getter_AddRefs(imeSel)); + result = selCon->GetSelection(sel[selIdx], getter_AddRefs(imeSel)); if(NS_SUCCEEDED(result)) { result = imeSel->ClearSelection(); @@ -369,7 +370,7 @@ NS_IMETHODIMP IMETextTxn::CollapseTextSelection(void) nsCOMPtr newRange; - result= ps->GetSelection(TextRangeToSelection(textRangeType), + result= selCon->GetSelection(TextRangeToSelection(textRangeType), getter_AddRefs(imeSel)); NS_ASSERTION(NS_SUCCEEDED(result), "Cannot get selction"); if(NS_FAILED(result)) diff --git a/mozilla/editor/libeditor/base/PlaceholderTxn.cpp b/mozilla/editor/libeditor/base/PlaceholderTxn.cpp index 0c048e54cf2..9188958e7b5 100644 --- a/mozilla/editor/libeditor/base/PlaceholderTxn.cpp +++ b/mozilla/editor/libeditor/base/PlaceholderTxn.cpp @@ -100,10 +100,10 @@ NS_IMETHODIMP PlaceholderTxn::Undo(void) if (NS_FAILED(res)) return res; // now restore selection - nsCOMPtr ps = do_QueryReferent(mPresShellWeak); - if (!ps) return NS_ERROR_NOT_INITIALIZED; + nsCOMPtr selCon = do_QueryReferent(mPresShellWeak); + if (!selCon) return NS_ERROR_NOT_INITIALIZED; nsCOMPtr selection; - res = ps->GetSelection(SELECTION_NORMAL, getter_AddRefs(selection)); + res = selCon->GetSelection(nsISelectionController::SELECTION_NORMAL, getter_AddRefs(selection)); if (NS_FAILED(res)) return res; if (!selection) return NS_ERROR_NULL_POINTER; if (!mStartSel) return NS_ERROR_NULL_POINTER; @@ -119,10 +119,10 @@ NS_IMETHODIMP PlaceholderTxn::Redo(void) if (NS_FAILED(res)) return res; // now restore selection - nsCOMPtr ps = do_QueryReferent(mPresShellWeak); - if (!ps) return NS_ERROR_NOT_INITIALIZED; + nsCOMPtr selCon = do_QueryReferent(mPresShellWeak); + if (!selCon) return NS_ERROR_NOT_INITIALIZED; nsCOMPtr selection; - res = ps->GetSelection(SELECTION_NORMAL, getter_AddRefs(selection)); + res = selCon->GetSelection(nsISelectionController::SELECTION_NORMAL, getter_AddRefs(selection)); if (NS_FAILED(res)) return res; if (!selection) return NS_ERROR_NULL_POINTER; res = mEndSel.RestoreSelection(selection); @@ -272,10 +272,10 @@ NS_IMETHODIMP PlaceholderTxn::Commit() NS_IMETHODIMP PlaceholderTxn::RememberEndingSelection() { - nsCOMPtr ps = do_QueryReferent(mPresShellWeak); - if (!ps) return NS_ERROR_NOT_INITIALIZED; + nsCOMPtr selCon = do_QueryReferent(mPresShellWeak); + if (!selCon) return NS_ERROR_NOT_INITIALIZED; nsCOMPtr selection; - nsresult res = ps->GetSelection(SELECTION_NORMAL, getter_AddRefs(selection)); + nsresult res = selCon->GetSelection(nsISelectionController::SELECTION_NORMAL, getter_AddRefs(selection)); if (NS_FAILED(res)) return res; if (!selection) return NS_ERROR_NULL_POINTER; res = mEndSel.SaveSelection(selection); diff --git a/mozilla/editor/libeditor/base/nsEditor.cpp b/mozilla/editor/libeditor/base/nsEditor.cpp index 5bb01ccab6c..cfce5e8cbb7 100644 --- a/mozilla/editor/libeditor/base/nsEditor.cpp +++ b/mozilla/editor/libeditor/base/nsEditor.cpp @@ -817,7 +817,7 @@ nsEditor::~nsEditor() NS_IMPL_ADDREF(nsEditor) NS_IMPL_RELEASE(nsEditor) -NS_IMPL_QUERY_INTERFACE2(nsEditor, nsIEditor, nsIEditorIMESupport) +NS_IMPL_QUERY_INTERFACE3(nsEditor, nsIEditor, nsIEditorIMESupport, nsISupportsWeakReference) #ifdef XP_MAC #pragma mark - @@ -928,10 +928,27 @@ nsEditor::GetPresShell(nsIPresShell **aPS) if (!mPresShellWeak) return NS_ERROR_NOT_INITIALIZED; nsCOMPtr ps = do_QueryReferent(mPresShellWeak); if (!ps) return NS_ERROR_NOT_INITIALIZED; - return ps->QueryInterface(NS_GET_IID(nsIPresShell), (void **)aPS); + NS_ADDREF(*aPS = ps); + return NS_OK; } +NS_IMETHODIMP +nsEditor::GetSelectionController(nsISelectionController **aSel) +{ + if (!aSel) + return NS_ERROR_NULL_POINTER; + *aSel = nsnull; // init out param + NS_PRECONDITION(mPresShellWeak, "bad state, null mPresShellWeak"); + if (!mPresShellWeak) return NS_ERROR_NOT_INITIALIZED; + nsCOMPtr selCon = do_QueryReferent(mPresShellWeak); + if (!selCon) return NS_ERROR_NOT_INITIALIZED; + NS_ADDREF(*aSel = selCon); + return NS_OK; +} + + + NS_IMETHODIMP nsEditor::GetSelection(nsIDOMSelection **aSelection) { @@ -939,9 +956,9 @@ nsEditor::GetSelection(nsIDOMSelection **aSelection) return NS_ERROR_NULL_POINTER; *aSelection = nsnull; if (!mPresShellWeak) return NS_ERROR_NOT_INITIALIZED; - nsCOMPtr ps = do_QueryReferent(mPresShellWeak); - if (!ps) return NS_ERROR_NOT_INITIALIZED; - nsresult result = ps->GetSelection(SELECTION_NORMAL, aSelection); // does an addref + nsCOMPtr selcon = do_QueryReferent(mPresShellWeak); + if (!selcon) return NS_ERROR_NOT_INITIALIZED; + nsresult result = selcon->GetSelection(nsISelectionController::SELECTION_NORMAL, aSelection); // does an addref return result; } @@ -1257,9 +1274,9 @@ NS_IMETHODIMP nsEditor::SelectAll() nsCOMPtr selection; if (!mPresShellWeak) return NS_ERROR_NOT_INITIALIZED; - nsCOMPtr ps = do_QueryReferent(mPresShellWeak); - if (!ps) return NS_ERROR_NOT_INITIALIZED; - nsresult result = ps->GetSelection(SELECTION_NORMAL, getter_AddRefs(selection)); + nsCOMPtr selcon = do_QueryReferent(mPresShellWeak); + if (!selcon) return NS_ERROR_NOT_INITIALIZED; + nsresult result = selcon->GetSelection(nsISelectionController::SELECTION_NORMAL, getter_AddRefs(selection)); if (NS_SUCCEEDED(result) && selection) { result = SelectEntireDocument(selection); @@ -1273,9 +1290,9 @@ NS_IMETHODIMP nsEditor::BeginningOfDocument() nsCOMPtr selection; if (!mPresShellWeak) return NS_ERROR_NOT_INITIALIZED; - nsCOMPtr ps = do_QueryReferent(mPresShellWeak); - if (!ps) return NS_ERROR_NOT_INITIALIZED; - nsresult result = ps->GetSelection(SELECTION_NORMAL, getter_AddRefs(selection)); + nsCOMPtr selcon = do_QueryReferent(mPresShellWeak); + if (!selcon) return NS_ERROR_NOT_INITIALIZED; + nsresult result = selcon->GetSelection(nsISelectionController::SELECTION_NORMAL, getter_AddRefs(selection)); if (NS_SUCCEEDED(result) && selection) { nsCOMPtr nodeList; @@ -1332,9 +1349,9 @@ NS_IMETHODIMP nsEditor::EndOfDocument() nsCOMPtr selection; if (!mPresShellWeak) return NS_ERROR_NOT_INITIALIZED; - nsCOMPtr ps = do_QueryReferent(mPresShellWeak); - if (!ps) return NS_ERROR_NOT_INITIALIZED; - nsresult result = ps->GetSelection(SELECTION_NORMAL, getter_AddRefs(selection)); + nsCOMPtr selcon = do_QueryReferent(mPresShellWeak); + if (!selcon) return NS_ERROR_NOT_INITIALIZED; + nsresult result = selcon->GetSelection(nsISelectionController::SELECTION_NORMAL, getter_AddRefs(selection)); if (NS_SUCCEEDED(result) && selection) { nsCOMPtr nodeList; @@ -4886,12 +4903,12 @@ nsresult nsEditor::EndUpdateViewBatch() { NS_PRECONDITION(mUpdateCount>0, "bad state"); - nsCOMPtr presShell; - nsresult rv = GetPresShell(getter_AddRefs(presShell)); + nsCOMPtr selCon; + nsresult rv = GetSelectionController(getter_AddRefs(selCon)); if (NS_FAILED(rv)) return rv; - StCaretHider caretHider(presShell); + StCaretHider caretHider(selCon); nsCOMPtrselection; nsresult selectionResult = GetSelection(getter_AddRefs(selection)); @@ -4910,7 +4927,10 @@ nsresult nsEditor::EndUpdateViewBatch() #else mViewManager->EndUpdateViewBatch(NS_VMREFRESH_IMMEDIATE); #endif - presShell->EndReflowBatching(PR_TRUE); + nsCOMPtr presShell; + nsresult rv = GetPresShell(getter_AddRefs(presShell)); + if (NS_SUCCEEDED(rv) && presShell) + presShell->EndReflowBatching(PR_TRUE); } } @@ -5147,7 +5167,7 @@ NS_IMETHODIMP nsEditor::CreateTxnForDeleteElement(nsIDOMNode * aElement, if (!mPresShellWeak) return NS_ERROR_NOT_INITIALIZED; nsCOMPtr ps = do_QueryReferent(mPresShellWeak); if (!ps) return NS_ERROR_NOT_INITIALIZED; - result = ps->GetSelection(SELECTION_NORMAL, getter_AddRefs(selection)); + result = ps->GetSelection(nsISelectionController::SELECTION_NORMAL, getter_AddRefs(selection)); if (NS_SUCCEEDED(result) && selection) { PRBool collapsed; @@ -5230,9 +5250,9 @@ nsEditor::CreateTxnForDeleteSelection(nsIEditor::EDirection aAction, nsresult result; nsCOMPtr selection; if (!mPresShellWeak) return NS_ERROR_NOT_INITIALIZED; - nsCOMPtr ps = do_QueryReferent(mPresShellWeak); - if (!ps) return NS_ERROR_NOT_INITIALIZED; - result = ps->GetSelection(SELECTION_NORMAL, getter_AddRefs(selection)); + nsCOMPtr selcon = do_QueryReferent(mPresShellWeak); + if (!selcon) return NS_ERROR_NOT_INITIALIZED; + result = selcon->GetSelection(nsISelectionController::SELECTION_NORMAL, getter_AddRefs(selection)); if ((NS_SUCCEEDED(result)) && selection) { // Check whether the selection is collapsed and we should do nothing: diff --git a/mozilla/editor/libeditor/base/nsEditor.h b/mozilla/editor/libeditor/base/nsEditor.h index 1039a5bdf42..4b5d20f9bb1 100644 --- a/mozilla/editor/libeditor/base/nsEditor.h +++ b/mozilla/editor/libeditor/base/nsEditor.h @@ -24,7 +24,7 @@ #define __editor_h__ #include "nsCOMPtr.h" -#include "nsWeakPtr.h" +#include "nsWeakReference.h" #include "nsIEditor.h" #include "nsIEditorIMESupport.h" @@ -140,7 +140,8 @@ class nsSelectionState * delegate the actual commands to the editor independent of the XPFE implementation. */ class nsEditor : public nsIEditor, - public nsIEditorIMESupport + public nsIEditorIMESupport, + public nsSupportsWeakReference { public: @@ -192,6 +193,7 @@ public: NS_IMETHOD SetFlags(PRUint32 aFlags) = 0; NS_IMETHOD GetDocument(nsIDOMDocument **aDoc); NS_IMETHOD GetPresShell(nsIPresShell **aPS); + NS_IMETHOD GetSelectionController(nsISelectionController **aSel); NS_IMETHOD GetSelection(nsIDOMSelection **aSelection); NS_IMETHOD EnableUndo(PRBool aEnable); diff --git a/mozilla/editor/libeditor/base/nsEditorCommands.cpp b/mozilla/editor/libeditor/base/nsEditorCommands.cpp index a890024f38e..2a623f6dff2 100644 --- a/mozilla/editor/libeditor/base/nsEditorCommands.cpp +++ b/mozilla/editor/libeditor/base/nsEditorCommands.cpp @@ -279,15 +279,11 @@ nsSelectionMoveCommands::DoCommand(const PRUnichar *aCommand, nsISupports * refC return NS_ERROR_FAILURE; nsresult rv; - - nsCOMPtr presShell; - rv = aEditor->GetPresShell(getter_AddRefs(presShell)); - if (NS_FAILED(rv) || !presShell) - return rv ? rv : NS_ERROR_FAILURE; - - nsCOMPtr selCont = do_QueryInterface(presShell); - if (!selCont) - return NS_ERROR_FAILURE; + + nsCOMPtr selCont; + rv = aEditor->GetSelectionController(getter_AddRefs(selCont)); + if (NS_FAILED(rv) || !selCont) + return rv?rv:NS_ERROR_FAILURE; nsAutoString cmdString(aCommand); diff --git a/mozilla/editor/libeditor/base/nsEditorController.cpp b/mozilla/editor/libeditor/base/nsEditorController.cpp index 419cabebf80..5b9e2ce5bac 100644 --- a/mozilla/editor/libeditor/base/nsEditorController.cpp +++ b/mozilla/editor/libeditor/base/nsEditorController.cpp @@ -295,42 +295,7 @@ NS_IMETHODIMP nsEditorController::GetSelectionController(nsISelectionController if (NS_FAILED(result) || !editor) return result ? result : NS_ERROR_FAILURE; - nsCOMPtr presShell; - result = editor->GetPresShell(getter_AddRefs(presShell)); - if (NS_FAILED(result) || !presShell) - return result ? result : NS_ERROR_FAILURE; - - nsCOMPtr selController = do_QueryInterface(presShell); - if (selController) - { - *aSelCon = selController; - NS_ADDREF(*aSelCon); - return NS_OK; - } - return NS_ERROR_FAILURE; -/* - NS_ENSURE_ARG_POINTER(aSelCon); - nsCOMPtr doc; - mContent->GetDocument(*getter_AddRefs(doc)); - - *aSelCon = nsnull; - if (doc) - { - PRInt32 i = doc->GetNumberOfShells(); - if (i == 0) - return NS_ERROR_FAILURE; - - nsCOMPtr presShell = getter_AddRefs(doc->GetShellAt(0)); - nsCOMPtr selController = do_QueryInterface(presShell); - if (selController) - { - *aSelCon = selController; - (*aSelCon)->AddRef(); - return NS_OK; - } - } - return NS_ERROR_FAILURE; - */ + return editor->GetSelectionController(aSelCon); } NS_IMETHODIMP nsEditorController::GetFrame(nsIGfxTextControlFrame **aFrame) diff --git a/mozilla/editor/libeditor/base/nsStyleSheetTxns.cpp b/mozilla/editor/libeditor/base/nsStyleSheetTxns.cpp index a0a62773050..3f885a83944 100644 --- a/mozilla/editor/libeditor/base/nsStyleSheetTxns.cpp +++ b/mozilla/editor/libeditor/base/nsStyleSheetTxns.cpp @@ -68,8 +68,14 @@ AddStyleSheetTxn::Do() if (!mEditor || !mSheet) return NS_ERROR_NOT_INITIALIZED; + nsCOMPtr selCon; + mEditor->GetSelectionController(getter_AddRefs(selCon)); + if (!selCon) + return NS_ERROR_UNEXPECTED; + nsCOMPtr presShell; - mEditor->GetPresShell(getter_AddRefs(presShell)); + presShell = do_QueryInterface(selCon); + if (!presShell) return NS_ERROR_UNEXPECTED; @@ -99,8 +105,13 @@ AddStyleSheetTxn::Undo() if (!mEditor || !mSheet) return NS_ERROR_NOT_INITIALIZED; + nsCOMPtr selCon; + mEditor->GetSelectionController(getter_AddRefs(selCon)); + if (!selCon) + return NS_ERROR_UNEXPECTED; + nsCOMPtr presShell; - mEditor->GetPresShell(getter_AddRefs(presShell)); + presShell = do_QueryInterface(selCon); if (!presShell) return NS_ERROR_UNEXPECTED; @@ -205,8 +216,13 @@ RemoveStyleSheetTxn::Do() if (!mEditor || !mSheet) return NS_ERROR_NOT_INITIALIZED; + nsCOMPtr selCon; + mEditor->GetSelectionController(getter_AddRefs(selCon)); + if (!selCon) + return NS_ERROR_UNEXPECTED; + nsCOMPtr presShell; - mEditor->GetPresShell(getter_AddRefs(presShell)); + presShell = do_QueryInterface(selCon); if (!presShell) return NS_ERROR_UNEXPECTED; @@ -236,8 +252,13 @@ RemoveStyleSheetTxn::Undo() if (!mEditor || !mSheet) return NS_ERROR_NOT_INITIALIZED; + nsCOMPtr selCon; + mEditor->GetSelectionController(getter_AddRefs(selCon)); + if (!selCon) + return NS_ERROR_UNEXPECTED; + nsCOMPtr presShell; - mEditor->GetPresShell(getter_AddRefs(presShell)); + presShell = do_QueryInterface(selCon); if (!presShell) return NS_ERROR_UNEXPECTED; diff --git a/mozilla/editor/libeditor/html/nsHTMLEditRules.cpp b/mozilla/editor/libeditor/html/nsHTMLEditRules.cpp index 52d9cf7aec6..184eb4aa51f 100644 --- a/mozilla/editor/libeditor/html/nsHTMLEditRules.cpp +++ b/mozilla/editor/libeditor/html/nsHTMLEditRules.cpp @@ -168,9 +168,9 @@ nsHTMLEditRules::BeforeEdit(PRInt32 action, nsIEditor::EDirection aDirection) nsComponentManager::CreateInstance(kRangeCID, nsnull, NS_GET_IID(nsIDOMRange), getter_AddRefs(mUtilRange)); // turn off caret - nsCOMPtr pres; - mEditor->GetPresShell(getter_AddRefs(pres)); - if (pres) pres->SetCaretEnabled(PR_FALSE); + nsCOMPtr selCon; + mEditor->GetSelectionController(getter_AddRefs(selCon)); + if (selCon) selCon->SetCaretEnabled(PR_FALSE); // check that selection is in subtree defined by body node ConfirmSelectionInBody(); // let rules remember the top level action @@ -260,9 +260,9 @@ nsHTMLEditRules::AfterEdit(PRInt32 action, nsIEditor::EDirection aDirection) res = CreateBogusNodeIfNeeded(selection); // turn on caret - nsCOMPtr pres; - mEditor->GetPresShell(getter_AddRefs(pres)); - if (pres) pres->SetCaretEnabled(PR_TRUE); + nsCOMPtr selCon; + mEditor->GetSelectionController(getter_AddRefs(selCon)); + if (selCon) selCon->SetCaretEnabled(PR_TRUE); } return res; diff --git a/mozilla/editor/libeditor/html/nsHTMLEditor.cpp b/mozilla/editor/libeditor/html/nsHTMLEditor.cpp index 5015b1e03db..3d07461717d 100644 --- a/mozilla/editor/libeditor/html/nsHTMLEditor.cpp +++ b/mozilla/editor/libeditor/html/nsHTMLEditor.cpp @@ -4339,9 +4339,9 @@ NS_IMETHODIMP nsHTMLEditor::InsertFromTransferable(nsITransferable *transferable // Try to scroll the selection into view if the paste/drop succeeded if (NS_SUCCEEDED(rv)) { - nsCOMPtr presShell; - if (NS_SUCCEEDED(GetPresShell(getter_AddRefs(presShell))) && presShell) - presShell->ScrollSelectionIntoView(SELECTION_NORMAL, SELECTION_FOCUS_REGION); + nsCOMPtr selCon; + if (NS_SUCCEEDED(GetSelectionController(getter_AddRefs(selCon))) && selCon) + selCon->ScrollSelectionIntoView(nsISelectionController::SELECTION_NORMAL, nsISelectionController::SELECTION_FOCUS_REGION); } return rv; diff --git a/mozilla/editor/libeditor/text/nsEditorEventListeners.cpp b/mozilla/editor/libeditor/text/nsEditorEventListeners.cpp index 10b753cb68e..a9685174f13 100644 --- a/mozilla/editor/libeditor/text/nsEditorEventListeners.cpp +++ b/mozilla/editor/libeditor/text/nsEditorEventListeners.cpp @@ -330,17 +330,14 @@ nsTextEditorKeyListener::ProcessShortCutKeys(nsIDOMEvent* aKeyEvent, PRBool& aPr nsresult nsTextEditorKeyListener::ScrollSelectionIntoView() { - nsCOMPtr presShell; + nsCOMPtr selCon; - nsresult result = mEditor->GetPresShell(getter_AddRefs(presShell)); + nsresult result = mEditor->GetSelectionController(getter_AddRefs(selCon)); - if (NS_FAILED(result)) - return result; + if (NS_FAILED(result) || ! selCon) + return result ? result: NS_ERROR_FAILURE; - if (!presShell) - return NS_ERROR_NULL_POINTER; - - return presShell->ScrollSelectionIntoView(SELECTION_NORMAL, SELECTION_FOCUS_REGION); + return selCon->ScrollSelectionIntoView(nsISelectionController::SELECTION_NORMAL, nsISelectionController::SELECTION_FOCUS_REGION); } /* @@ -1077,13 +1074,13 @@ nsTextEditorFocusListener::Focus(nsIDOMEvent* aEvent) nsCOMPtreditor = do_QueryInterface(mEditor); if (editor) { - nsCOMPtrps; - editor->GetPresShell(getter_AddRefs(ps)); - if (ps) + nsCOMPtrselCon; + editor->GetSelectionController(getter_AddRefs(selCon)); + if (selCon) { if (! (flags & nsIHTMLEditor::eEditorReadonlyMask)) { // only enable caret if the editor is not readonly - ps->SetCaretEnabled(PR_TRUE); + selCon->SetCaretEnabled(PR_TRUE); } nsCOMPtrdomDoc; @@ -1109,7 +1106,7 @@ nsTextEditorFocusListener::Focus(nsIDOMEvent* aEvent) } // end hack repaint #else - ps->RepaintSelection(SELECTION_NORMAL); + selCon->RepaintSelection(nsISelectionController::SELECTION_NORMAL); #endif } } @@ -1129,11 +1126,11 @@ nsTextEditorFocusListener::Blur(nsIDOMEvent* aEvent) nsCOMPtreditor = do_QueryInterface(mEditor); if (editor) { - nsCOMPtrps; - editor->GetPresShell(getter_AddRefs(ps)); - if (ps) + nsCOMPtrselCon; + editor->GetSelectionController(getter_AddRefs(selCon)); + if (selCon) { - ps->SetCaretEnabled(PR_FALSE); + selCon->SetCaretEnabled(PR_FALSE); nsCOMPtrdomDoc; editor->GetDocument(getter_AddRefs(domDoc)); @@ -1159,7 +1156,7 @@ nsTextEditorFocusListener::Blur(nsIDOMEvent* aEvent) } // end hack repaint #else - ps->RepaintSelection(SELECTION_NORMAL); + selCon->RepaintSelection(nsISelectionController::SELECTION_NORMAL); #endif } } diff --git a/mozilla/editor/libeditor/txtsvc/nsTextServicesDocument.cpp b/mozilla/editor/libeditor/txtsvc/nsTextServicesDocument.cpp index 37c9fcdf638..b8b60ddb64d 100644 --- a/mozilla/editor/libeditor/txtsvc/nsTextServicesDocument.cpp +++ b/mozilla/editor/libeditor/txtsvc/nsTextServicesDocument.cpp @@ -248,9 +248,9 @@ nsTextServicesDocument::InitWithDocument(nsIDOMDocument *aDOMDocument, nsIPresSh if (!aDOMDocument || !aPresShell) return NS_ERROR_NULL_POINTER; - NS_ASSERTION(!mPresShell, "mPresShell already initialized!"); + NS_ASSERTION(!mSelCon, "mSelCon already initialized!"); - if (mPresShell) + if (mSelCon) return NS_ERROR_FAILURE; NS_ASSERTION(!mDOMDocument, "mDOMDocument already initialized!"); @@ -260,7 +260,7 @@ nsTextServicesDocument::InitWithDocument(nsIDOMDocument *aDOMDocument, nsIPresSh LOCK_DOC(this); - mPresShell = do_QueryInterface(aPresShell); + mSelCon = do_QueryInterface(aPresShell); mDOMDocument = do_QueryInterface(aDOMDocument); result = CreateDocumentContentIterator(getter_AddRefs(mIterator)); @@ -284,7 +284,7 @@ NS_IMETHODIMP nsTextServicesDocument::InitWithEditor(nsIEditor *aEditor) { nsresult result = NS_OK; - nsCOMPtr presShell; + nsCOMPtr selCon; nsCOMPtr doc; if (!aEditor) @@ -292,10 +292,10 @@ nsTextServicesDocument::InitWithEditor(nsIEditor *aEditor) LOCK_DOC(this); - // Check to see if we already have an mPresShell. If we do, it + // Check to see if we already have an mSelCon. If we do, it // better be the same one the editor uses! - result = aEditor->GetPresShell(getter_AddRefs(presShell)); + result = aEditor->GetSelectionController(getter_AddRefs(selCon)); if (NS_FAILED(result)) { @@ -303,14 +303,14 @@ nsTextServicesDocument::InitWithEditor(nsIEditor *aEditor) return result; } - if (!presShell || (mPresShell && presShell != mPresShell)) + if (!selCon || (mSelCon && selCon != mSelCon)) { UNLOCK_DOC(this); return NS_ERROR_FAILURE; } - if (!mPresShell) - mPresShell = presShell; + if (!mSelCon) + mSelCon = selCon; // Check to see if we already have an mDOMDocument. If we do, it // better be the same one the editor uses! @@ -575,7 +575,7 @@ nsTextServicesDocument::FirstSelectedBlock(TSDBlockSelectionStatus *aSelStatus, *aSelStatus = nsITextServicesDocument::eBlockNotFound; *aSelOffset = *aSelLength = -1; - if (!mPresShell || !mIterator) + if (!mSelCon || !mIterator) { UNLOCK_DOC(this); return NS_ERROR_FAILURE; @@ -584,7 +584,7 @@ nsTextServicesDocument::FirstSelectedBlock(TSDBlockSelectionStatus *aSelStatus, nsCOMPtr selection; PRBool isCollapsed = PR_FALSE; - result = mPresShell->GetSelection(SELECTION_NORMAL, getter_AddRefs(selection)); + result = mSelCon->GetSelection(nsISelectionController::SELECTION_NORMAL, getter_AddRefs(selection)); if (NS_FAILED(result)) { @@ -1066,7 +1066,7 @@ nsTextServicesDocument::LastSelectedBlock(TSDBlockSelectionStatus *aSelStatus, P *aSelStatus = nsITextServicesDocument::eBlockNotFound; *aSelOffset = *aSelLength = -1; - if (!mPresShell || !mIterator) + if (!mSelCon || !mIterator) { UNLOCK_DOC(this); return NS_ERROR_FAILURE; @@ -1075,7 +1075,7 @@ nsTextServicesDocument::LastSelectedBlock(TSDBlockSelectionStatus *aSelStatus, P nsCOMPtr selection; PRBool isCollapsed = PR_FALSE; - result = mPresShell->GetSelection(SELECTION_NORMAL, getter_AddRefs(selection)); + result = mSelCon->GetSelection(nsISelectionController::SELECTION_NORMAL, getter_AddRefs(selection)); if (NS_FAILED(result)) { @@ -1714,7 +1714,7 @@ nsTextServicesDocument::SetSelection(PRInt32 aOffset, PRInt32 aLength) { nsresult result; - if (!mPresShell || aOffset < 0 || aLength < 0) + if (!mSelCon || aOffset < 0 || aLength < 0) return NS_ERROR_FAILURE; LOCK_DOC(this); @@ -1735,12 +1735,12 @@ nsTextServicesDocument::ScrollSelectionIntoView() { nsresult result; - if (!mPresShell) + if (!mSelCon) return NS_ERROR_FAILURE; LOCK_DOC(this); - result = mPresShell->ScrollSelectionIntoView(SELECTION_NORMAL, SELECTION_FOCUS_REGION); + result = mSelCon->ScrollSelectionIntoView(nsISelectionController::SELECTION_NORMAL, nsISelectionController::SELECTION_FOCUS_REGION); UNLOCK_DOC(this); @@ -2125,7 +2125,7 @@ nsTextServicesDocument::InsertText(const nsString *aText) mSelStartIndex = mSelEndIndex = i; - result = mPresShell->GetSelection(SELECTION_NORMAL, getter_AddRefs(selection)); + result = mSelCon->GetSelection(nsISelectionController::SELECTION_NORMAL, getter_AddRefs(selection)); if (NS_FAILED(result)) { @@ -2963,7 +2963,7 @@ nsTextServicesDocument::SetSelectionInternal(PRInt32 aOffset, PRInt32 aLength, P { nsresult result = NS_OK; - if (!mPresShell || aOffset < 0 || aLength < 0) + if (!mSelCon || aOffset < 0 || aLength < 0) return NS_ERROR_FAILURE; nsIDOMNode *sNode = 0, *eNode = 0; @@ -3013,7 +3013,7 @@ nsTextServicesDocument::SetSelectionInternal(PRInt32 aOffset, PRInt32 aLength, P if (aDoUpdate) { - result = mPresShell->GetSelection(SELECTION_NORMAL, getter_AddRefs(selection)); + result = mSelCon->GetSelection(nsISelectionController::SELECTION_NORMAL, getter_AddRefs(selection)); if (NS_FAILED(result)) return result; @@ -3100,7 +3100,7 @@ nsTextServicesDocument::GetSelection(nsITextServicesDocument::TSDBlockSelectionS *aSelOffset = -1; *aSelLength = -1; - if (!mDOMDocument || !mPresShell) + if (!mDOMDocument || !mSelCon) return NS_ERROR_FAILURE; if (mIteratorStatus == nsTextServicesDocument::eIsDone) @@ -3109,7 +3109,7 @@ nsTextServicesDocument::GetSelection(nsITextServicesDocument::TSDBlockSelectionS nsCOMPtr selection; PRBool isCollapsed; - result = mPresShell->GetSelection(SELECTION_NORMAL, getter_AddRefs(selection)); + result = mSelCon->GetSelection(nsISelectionController::SELECTION_NORMAL, getter_AddRefs(selection)); if (NS_FAILED(result)) return result; @@ -3143,7 +3143,7 @@ nsTextServicesDocument::GetCollapsedSelection(nsITextServicesDocument::TSDBlockS nsresult result; nsCOMPtr selection; - result = mPresShell->GetSelection(SELECTION_NORMAL, getter_AddRefs(selection)); + result = mSelCon->GetSelection(nsISelectionController::SELECTION_NORMAL, getter_AddRefs(selection)); if (NS_FAILED(result)) return result; @@ -3474,7 +3474,7 @@ nsTextServicesDocument::GetUncollapsedSelection(nsITextServicesDocument::TSDBloc nsCOMPtr range; OffsetEntry *entry; - result = mPresShell->GetSelection(SELECTION_NORMAL, getter_AddRefs(selection)); + result = mSelCon->GetSelection(nsISelectionController::SELECTION_NORMAL, getter_AddRefs(selection)); if (NS_FAILED(result)) return result; diff --git a/mozilla/editor/libeditor/txtsvc/nsTextServicesDocument.h b/mozilla/editor/libeditor/txtsvc/nsTextServicesDocument.h index bfd458b893d..3e800940e31 100644 --- a/mozilla/editor/libeditor/txtsvc/nsTextServicesDocument.h +++ b/mozilla/editor/libeditor/txtsvc/nsTextServicesDocument.h @@ -78,7 +78,7 @@ private: } TSDIteratorStatus; nsCOMPtr mDOMDocument; - nsCOMPtr mPresShell; + nsCOMPtrmSelCon; nsCOMPtr mEditor; nsCOMPtr mIterator; TSDIteratorStatus mIteratorStatus; diff --git a/mozilla/editor/public/nsIEditor.h b/mozilla/editor/public/nsIEditor.h index 5561f635cba..2058400594f 100644 --- a/mozilla/editor/public/nsIEditor.h +++ b/mozilla/editor/public/nsIEditor.h @@ -45,7 +45,7 @@ class nsIOutputStream; class nsIEditActionListener; class nsIDocumentStateListener; class nsFileSpec; - +class nsISelectionController; class nsIEditor : public nsISupports { public: @@ -98,7 +98,15 @@ public: * * @param aPS [OUT] the pres shell, refcounted */ - NS_IMETHOD GetPresShell(nsIPresShell **aPS)=0; + //NS_IMETHOD GetPresShell(nsIPresShell **aPS)=0; + + /** + * return the selection controller for the current presentation + * + * @param aSelCon [OUT] the selection controller, refcounted + */ + NS_IMETHOD GetSelectionController(nsISelectionController **aSel)=0; + /** * return the DOM Selection for the presentation shell that has focus diff --git a/mozilla/editor/txtsvc/src/nsTextServicesDocument.cpp b/mozilla/editor/txtsvc/src/nsTextServicesDocument.cpp index 37c9fcdf638..b8b60ddb64d 100644 --- a/mozilla/editor/txtsvc/src/nsTextServicesDocument.cpp +++ b/mozilla/editor/txtsvc/src/nsTextServicesDocument.cpp @@ -248,9 +248,9 @@ nsTextServicesDocument::InitWithDocument(nsIDOMDocument *aDOMDocument, nsIPresSh if (!aDOMDocument || !aPresShell) return NS_ERROR_NULL_POINTER; - NS_ASSERTION(!mPresShell, "mPresShell already initialized!"); + NS_ASSERTION(!mSelCon, "mSelCon already initialized!"); - if (mPresShell) + if (mSelCon) return NS_ERROR_FAILURE; NS_ASSERTION(!mDOMDocument, "mDOMDocument already initialized!"); @@ -260,7 +260,7 @@ nsTextServicesDocument::InitWithDocument(nsIDOMDocument *aDOMDocument, nsIPresSh LOCK_DOC(this); - mPresShell = do_QueryInterface(aPresShell); + mSelCon = do_QueryInterface(aPresShell); mDOMDocument = do_QueryInterface(aDOMDocument); result = CreateDocumentContentIterator(getter_AddRefs(mIterator)); @@ -284,7 +284,7 @@ NS_IMETHODIMP nsTextServicesDocument::InitWithEditor(nsIEditor *aEditor) { nsresult result = NS_OK; - nsCOMPtr presShell; + nsCOMPtr selCon; nsCOMPtr doc; if (!aEditor) @@ -292,10 +292,10 @@ nsTextServicesDocument::InitWithEditor(nsIEditor *aEditor) LOCK_DOC(this); - // Check to see if we already have an mPresShell. If we do, it + // Check to see if we already have an mSelCon. If we do, it // better be the same one the editor uses! - result = aEditor->GetPresShell(getter_AddRefs(presShell)); + result = aEditor->GetSelectionController(getter_AddRefs(selCon)); if (NS_FAILED(result)) { @@ -303,14 +303,14 @@ nsTextServicesDocument::InitWithEditor(nsIEditor *aEditor) return result; } - if (!presShell || (mPresShell && presShell != mPresShell)) + if (!selCon || (mSelCon && selCon != mSelCon)) { UNLOCK_DOC(this); return NS_ERROR_FAILURE; } - if (!mPresShell) - mPresShell = presShell; + if (!mSelCon) + mSelCon = selCon; // Check to see if we already have an mDOMDocument. If we do, it // better be the same one the editor uses! @@ -575,7 +575,7 @@ nsTextServicesDocument::FirstSelectedBlock(TSDBlockSelectionStatus *aSelStatus, *aSelStatus = nsITextServicesDocument::eBlockNotFound; *aSelOffset = *aSelLength = -1; - if (!mPresShell || !mIterator) + if (!mSelCon || !mIterator) { UNLOCK_DOC(this); return NS_ERROR_FAILURE; @@ -584,7 +584,7 @@ nsTextServicesDocument::FirstSelectedBlock(TSDBlockSelectionStatus *aSelStatus, nsCOMPtr selection; PRBool isCollapsed = PR_FALSE; - result = mPresShell->GetSelection(SELECTION_NORMAL, getter_AddRefs(selection)); + result = mSelCon->GetSelection(nsISelectionController::SELECTION_NORMAL, getter_AddRefs(selection)); if (NS_FAILED(result)) { @@ -1066,7 +1066,7 @@ nsTextServicesDocument::LastSelectedBlock(TSDBlockSelectionStatus *aSelStatus, P *aSelStatus = nsITextServicesDocument::eBlockNotFound; *aSelOffset = *aSelLength = -1; - if (!mPresShell || !mIterator) + if (!mSelCon || !mIterator) { UNLOCK_DOC(this); return NS_ERROR_FAILURE; @@ -1075,7 +1075,7 @@ nsTextServicesDocument::LastSelectedBlock(TSDBlockSelectionStatus *aSelStatus, P nsCOMPtr selection; PRBool isCollapsed = PR_FALSE; - result = mPresShell->GetSelection(SELECTION_NORMAL, getter_AddRefs(selection)); + result = mSelCon->GetSelection(nsISelectionController::SELECTION_NORMAL, getter_AddRefs(selection)); if (NS_FAILED(result)) { @@ -1714,7 +1714,7 @@ nsTextServicesDocument::SetSelection(PRInt32 aOffset, PRInt32 aLength) { nsresult result; - if (!mPresShell || aOffset < 0 || aLength < 0) + if (!mSelCon || aOffset < 0 || aLength < 0) return NS_ERROR_FAILURE; LOCK_DOC(this); @@ -1735,12 +1735,12 @@ nsTextServicesDocument::ScrollSelectionIntoView() { nsresult result; - if (!mPresShell) + if (!mSelCon) return NS_ERROR_FAILURE; LOCK_DOC(this); - result = mPresShell->ScrollSelectionIntoView(SELECTION_NORMAL, SELECTION_FOCUS_REGION); + result = mSelCon->ScrollSelectionIntoView(nsISelectionController::SELECTION_NORMAL, nsISelectionController::SELECTION_FOCUS_REGION); UNLOCK_DOC(this); @@ -2125,7 +2125,7 @@ nsTextServicesDocument::InsertText(const nsString *aText) mSelStartIndex = mSelEndIndex = i; - result = mPresShell->GetSelection(SELECTION_NORMAL, getter_AddRefs(selection)); + result = mSelCon->GetSelection(nsISelectionController::SELECTION_NORMAL, getter_AddRefs(selection)); if (NS_FAILED(result)) { @@ -2963,7 +2963,7 @@ nsTextServicesDocument::SetSelectionInternal(PRInt32 aOffset, PRInt32 aLength, P { nsresult result = NS_OK; - if (!mPresShell || aOffset < 0 || aLength < 0) + if (!mSelCon || aOffset < 0 || aLength < 0) return NS_ERROR_FAILURE; nsIDOMNode *sNode = 0, *eNode = 0; @@ -3013,7 +3013,7 @@ nsTextServicesDocument::SetSelectionInternal(PRInt32 aOffset, PRInt32 aLength, P if (aDoUpdate) { - result = mPresShell->GetSelection(SELECTION_NORMAL, getter_AddRefs(selection)); + result = mSelCon->GetSelection(nsISelectionController::SELECTION_NORMAL, getter_AddRefs(selection)); if (NS_FAILED(result)) return result; @@ -3100,7 +3100,7 @@ nsTextServicesDocument::GetSelection(nsITextServicesDocument::TSDBlockSelectionS *aSelOffset = -1; *aSelLength = -1; - if (!mDOMDocument || !mPresShell) + if (!mDOMDocument || !mSelCon) return NS_ERROR_FAILURE; if (mIteratorStatus == nsTextServicesDocument::eIsDone) @@ -3109,7 +3109,7 @@ nsTextServicesDocument::GetSelection(nsITextServicesDocument::TSDBlockSelectionS nsCOMPtr selection; PRBool isCollapsed; - result = mPresShell->GetSelection(SELECTION_NORMAL, getter_AddRefs(selection)); + result = mSelCon->GetSelection(nsISelectionController::SELECTION_NORMAL, getter_AddRefs(selection)); if (NS_FAILED(result)) return result; @@ -3143,7 +3143,7 @@ nsTextServicesDocument::GetCollapsedSelection(nsITextServicesDocument::TSDBlockS nsresult result; nsCOMPtr selection; - result = mPresShell->GetSelection(SELECTION_NORMAL, getter_AddRefs(selection)); + result = mSelCon->GetSelection(nsISelectionController::SELECTION_NORMAL, getter_AddRefs(selection)); if (NS_FAILED(result)) return result; @@ -3474,7 +3474,7 @@ nsTextServicesDocument::GetUncollapsedSelection(nsITextServicesDocument::TSDBloc nsCOMPtr range; OffsetEntry *entry; - result = mPresShell->GetSelection(SELECTION_NORMAL, getter_AddRefs(selection)); + result = mSelCon->GetSelection(nsISelectionController::SELECTION_NORMAL, getter_AddRefs(selection)); if (NS_FAILED(result)) return result; diff --git a/mozilla/editor/txtsvc/src/nsTextServicesDocument.h b/mozilla/editor/txtsvc/src/nsTextServicesDocument.h index bfd458b893d..3e800940e31 100644 --- a/mozilla/editor/txtsvc/src/nsTextServicesDocument.h +++ b/mozilla/editor/txtsvc/src/nsTextServicesDocument.h @@ -78,7 +78,7 @@ private: } TSDIteratorStatus; nsCOMPtr mDOMDocument; - nsCOMPtr mPresShell; + nsCOMPtrmSelCon; nsCOMPtr mEditor; nsCOMPtr mIterator; TSDIteratorStatus mIteratorStatus; diff --git a/mozilla/embedding/browser/activex/src/control/MozillaBrowser.cpp b/mozilla/embedding/browser/activex/src/control/MozillaBrowser.cpp index 2065d948c06..216e525adb3 100644 --- a/mozilla/embedding/browser/activex/src/control/MozillaBrowser.cpp +++ b/mozilla/embedding/browser/activex/src/control/MozillaBrowser.cpp @@ -36,6 +36,7 @@ #include "nsFileSpec.h" #include "nsILocalFile.h" #include "nsIContentViewerFile.h" +#include "nsISelectionController.h" static NS_DEFINE_CID(kWindowCID, NS_WINDOW_CID); static NS_DEFINE_IID(kIWidgetIID, NS_IWIDGET_IID); @@ -439,8 +440,13 @@ LRESULT CMozillaBrowser::OnCut(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL& b return NS_ERROR_NOT_INITIALIZED; } - nsCOMPtr selection; //Get a pointer to the DOM selection - res = pIPresShell->GetSelection(SELECTION_NORMAL, getter_AddRefs(selection)); + nsCOMPtr pISelectionController; + pISelectionController = do_QueryInterface(pIPresShell); + if ( NS_FAILED(res) || !pISelectionController) + return res?res:NS_ERROR_FAILURE; + + nsCOMPtr selection; //Get a pointer to the DOM selection + res = pISelectionController->GetSelection(nsISelectionController::SELECTION_NORMAL, getter_AddRefs(selection)); if ( NS_FAILED(res) ) return res; res = pIPresShell->DoCopy(); //Copy the selection to the clipboard diff --git a/mozilla/extensions/xmlterm/base/mozXMLTermListeners.cpp b/mozilla/extensions/xmlterm/base/mozXMLTermListeners.cpp index 43b4c4badea..2b8cc1e8560 100644 --- a/mozilla/extensions/xmlterm/base/mozXMLTermListeners.cpp +++ b/mozilla/extensions/xmlterm/base/mozXMLTermListeners.cpp @@ -633,9 +633,12 @@ mozXMLTermMouseListener::MouseClick(nsIDOMEvent* aMouseEvent) result = mXMLTerminal->GetPresShell(getter_AddRefs(presShell)); if (NS_FAILED(result) || !presShell) return NS_OK; // Do not consume mouse event - + nsCOMPtr selCon; + selCon = do_QueryInterface(presShell); + if (!selCon) + return NS_ERROR_FAILURE; nsCOMPtr selection; - result = presShell->GetSelection(SELECTION_NORMAL, + result = selCon->GetSelection(SELECTION_NORMAL, getter_AddRefs(selection)); if (NS_FAILED(result) || !selection) diff --git a/mozilla/extensions/xmlterm/base/mozXMLTermSession.cpp b/mozilla/extensions/xmlterm/base/mozXMLTermSession.cpp index c3bdbdc984a..d24cb1fc8ab 100644 --- a/mozilla/extensions/xmlterm/base/mozXMLTermSession.cpp +++ b/mozilla/extensions/xmlterm/base/mozXMLTermSession.cpp @@ -1117,8 +1117,12 @@ NS_IMETHODIMP mozXMLTermSession::Abort(mozILineTermAux* lineTermAux, SetDOMText(textNode, errMsg); // Collapse selection and position cursor + nsCOMPtr selCon; + selCon = do_QueryInterface(mPresShell); + if (!selCon) + return NS_ERROR_FAILURE; nsCOMPtr selection; - result = mPresShell->GetSelection(SELECTION_NORMAL, + result = selCon->GetSelection(SELECTION_NORMAL, getter_AddRefs(selection)); if (NS_SUCCEEDED(result) && selection) { selection->Collapse(textNode, errMsg.Length()); @@ -1156,9 +1160,13 @@ NS_IMETHODIMP mozXMLTermSession::DisplayInput(const nsString& aString, nsCRT::free(temCString); // Collapse selection and position cursor + nsCOMPtr selCon; + selCon = do_QueryInterface(mPresShell); + if (!selCon) + return NS_ERROR_FAILURE; nsCOMPtr selection; - result = mPresShell->GetSelection(SELECTION_NORMAL, + result = selCon->GetSelection(SELECTION_NORMAL, getter_AddRefs(selection)); if (NS_FAILED(result) || !selection) return NS_ERROR_FAILURE; @@ -2222,7 +2230,11 @@ NS_IMETHODIMP mozXMLTermSession::AppendLineLS(const nsString& aString, // Get selection nsCOMPtr selection; - result = mPresShell->GetSelection(SELECTION_NORMAL, + nsCOMPtr selCon; + selCon = do_QueryInterface(mPresShell); + if (!selCon) + return NS_ERROR_FAILURE; + result = selCon->GetSelection(SELECTION_NORMAL, getter_AddRefs(selection)); if (NS_FAILED(result) || !selection) return NS_ERROR_FAILURE; @@ -2807,7 +2819,11 @@ void mozXMLTermSession::PositionOutputCursor(mozILineTermAux* lineTermAux) // Get selection nsCOMPtr selection; - result = mPresShell->GetSelection(SELECTION_NORMAL, + nsCOMPtr selCon; + selCon = do_QueryInterface(mPresShell); + if (!selCon) + return NS_ERROR_FAILURE; + result = selCon->GetSelection(SELECTION_NORMAL, getter_AddRefs(selection)); if (NS_SUCCEEDED(result) && selection) { // Position cursor at end of line @@ -3373,7 +3389,11 @@ NS_IMETHODIMP mozXMLTermSession::PositionScreenCursor(PRInt32 aRow, // Get selection nsCOMPtr selection; - result = mPresShell->GetSelection(SELECTION_NORMAL, + nsCOMPtr selCon; + selCon = do_QueryInterface(mPresShell); + if (!selCon) + return NS_ERROR_FAILURE; + result = selCon->GetSelection(SELECTION_NORMAL, getter_AddRefs(selection)); if (NS_SUCCEEDED(result) && selection) { diff --git a/mozilla/layout/base/nsCaret.cpp b/mozilla/layout/base/nsCaret.cpp index 2686dca4c09..9a6f7d94500 100644 --- a/mozilla/layout/base/nsCaret.cpp +++ b/mozilla/layout/base/nsCaret.cpp @@ -44,6 +44,7 @@ #include "nsILookAndFeel.h" #include "nsWidgetsCID.h" // for NS_LOOKANDFEEL_CID #include "nsBlockFrame.h" +#include "nsISelectionController.h" #include "nsCaret.h" @@ -79,8 +80,8 @@ NS_IMETHODIMP nsCaret::Init(nsIPresShell *inPresShell) if (!inPresShell) return NS_ERROR_NULL_POINTER; - mPresShell = inPresShell; // the presshell owns us, so no addref - + mPresShell = getter_AddRefs(NS_GetWeakReference(inPresShell)); // the presshell owns us, so no addref + nsILookAndFeel* touchyFeely; if (NS_SUCCEEDED(nsComponentManager::CreateInstance(kLookAndFeelCID, nsnull, NS_GET_IID(nsILookAndFeel), (void**)&touchyFeely))) { @@ -98,10 +99,16 @@ NS_IMETHODIMP nsCaret::Init(nsIPresShell *inPresShell) // listener nsCOMPtr domSelection; - if (NS_SUCCEEDED(mPresShell->GetSelection(SELECTION_NORMAL, getter_AddRefs(domSelection)))) + nsCOMPtr selCon = do_QueryReferent(mPresShell); + if (selCon) { - domSelection->AddSelectionListener(this); - } + if (NS_SUCCEEDED(selCon->GetSelection(nsISelectionController::SELECTION_NORMAL, getter_AddRefs(domSelection)))) + { + domSelection->AddSelectionListener(this); + } + } + else + return NS_ERROR_FAILURE; // set up the blink timer if (mVisible) @@ -181,9 +188,16 @@ NS_IMETHODIMP nsCaret::GetWindowRelativeCoordinates(nsRect& outCoordinates, PRBo return NS_ERROR_NOT_INITIALIZED; nsCOMPtr domSelection; - nsresult err = mPresShell->GetSelection(SELECTION_NORMAL,getter_AddRefs(domSelection)); - if (NS_FAILED(err)) - return err; + nsCOMPtr selCon = do_QueryReferent(mPresShell); + nsresult err; + if (selCon) + { + err = selCon->GetSelection(nsISelectionController::SELECTION_NORMAL,getter_AddRefs(domSelection)); + if (NS_FAILED(err)) + return err; + } + else + return NS_ERROR_FAILURE; if (!domSelection) return NS_ERROR_NOT_INITIALIZED; // no selection @@ -227,9 +241,13 @@ NS_IMETHODIMP nsCaret::GetWindowRelativeCoordinates(nsRect& outCoordinates, PRBo //get frame selection and find out what frame to use... nsCOMPtr frameSelection; - err = mPresShell->GetFrameSelection(getter_AddRefs(frameSelection)); - if (NS_FAILED(err) || !frameSelection) - return err; + nsCOMPtr presShell = do_QueryReferent(mPresShell); + if (presShell) + err = presShell->GetFrameSelection(getter_AddRefs(frameSelection)); + else + return NS_ERROR_FAILURE; + if (NS_FAILED(err) || !frameSelection) + return err?err : NS_ERROR_FAILURE; // find the frame that contains the content node that has focus nsIFrame* theFrame = nsnull; @@ -247,7 +265,7 @@ NS_IMETHODIMP nsCaret::GetWindowRelativeCoordinates(nsRect& outCoordinates, PRBo // ramp up to make a rendering context for measuring text. // First, we get the pres context ... nsCOMPtr presContext; - err = mPresShell->GetPresContext(getter_AddRefs(presContext)); + err = presShell->GetPresContext(getter_AddRefs(presContext)); if (NS_FAILED(err)) return err; @@ -386,10 +404,16 @@ nsresult nsCaret::StopBlinking() PRBool nsCaret::SetupDrawingFrameAndOffset() { nsCOMPtr domSelection; - nsresult err = mPresShell->GetSelection(SELECTION_NORMAL, getter_AddRefs(domSelection)); - if (!NS_SUCCEEDED(err) || !domSelection) - return PR_FALSE; - + nsCOMPtr selCon = do_QueryReferent(mPresShell); + nsresult err; + if (selCon) + { + err = selCon->GetSelection(nsISelectionController::SELECTION_NORMAL, getter_AddRefs(domSelection)); + if (!NS_SUCCEEDED(err) || !domSelection) + return PR_FALSE; + } + else + return NS_ERROR_FAILURE; PRBool isCollapsed; if (domSelection && NS_SUCCEEDED(domSelection->GetIsCollapsed(&isCollapsed)) && isCollapsed) @@ -433,7 +457,11 @@ PRBool nsCaret::SetupDrawingFrameAndOffset() //get frame selection and find out what frame to use... nsCOMPtr frameSelection; - err = mPresShell->GetFrameSelection(getter_AddRefs(frameSelection)); + nsCOMPtr presShell = do_QueryReferent(mPresShell); + if (presShell) + err = presShell->GetFrameSelection(getter_AddRefs(frameSelection)); + else + return NS_ERROR_FAILURE; if (NS_FAILED(err) || !frameSelection) return PR_FALSE; @@ -476,7 +504,11 @@ void nsCaret::GetViewForRendering(nsIFrame *caretFrame, EViewCoordinates coordTy nsIView* theView = nsnull; NS_ASSERTION(caretFrame, "Should have frame here"); nsCOMPtr presContext; - mPresShell->GetPresContext(getter_AddRefs(presContext)); + nsCOMPtr presShell = do_QueryReferent(mPresShell); + if (presShell) + presShell->GetPresContext(getter_AddRefs(presContext)); + else + return; caretFrame->GetOffsetFromView(presContext, viewOffset, &theView); if (theView == nsnull) return; @@ -526,10 +558,15 @@ PRBool nsCaret::MustDrawCaret() return PR_TRUE; nsCOMPtr domSelection; - nsresult err = mPresShell->GetSelection(SELECTION_NORMAL, getter_AddRefs(domSelection)); - if (NS_FAILED(err) || !domSelection) - return PR_FALSE; - + nsCOMPtr selCon = do_QueryReferent(mPresShell); + if (selCon) + { + nsresult err = selCon->GetSelection(nsISelectionController::SELECTION_NORMAL, getter_AddRefs(domSelection)); + if (NS_FAILED(err) || !domSelection) + return PR_FALSE; + } + else + return NS_ERROR_FAILURE; PRBool isCollapsed; if (NS_FAILED(domSelection->GetIsCollapsed(&isCollapsed))) @@ -573,8 +610,14 @@ void nsCaret::DrawCaretWithContext(nsIRenderingContext* inRendContext) frameRect += viewOffset; nsCOMPtr presContext; - if (NS_FAILED(mPresShell->GetPresContext(getter_AddRefs(presContext)))) - return; + nsCOMPtr presShell = do_QueryReferent(mPresShell); + if (presShell) + { + if (NS_FAILED(presShell->GetPresContext(getter_AddRefs(presContext)))) + return; + } + else + return; // make a rendering context, if we didn't get passed one nsCOMPtr localRC = do_QueryInterface(inRendContext); // OK if inRendContext is null diff --git a/mozilla/layout/base/nsCaret.h b/mozilla/layout/base/nsCaret.h index f2aa093d8fa..7d6d36af444 100644 --- a/mozilla/layout/base/nsCaret.h +++ b/mozilla/layout/base/nsCaret.h @@ -25,10 +25,12 @@ #include "nsCoord.h" #include "nsIDOMSelectionListener.h" #include "nsICaret.h" +#include "nsWeakPtr.h" class nsITimer; class nsIView; class nsIRenderingContext; +class nsISelectionController; // {E14B66F6-BFC5-11d2-B57E-00105AA83B2F} #define NS_CARET_CID \ @@ -83,8 +85,9 @@ class nsCaret : public nsICaret, void DrawCaret(); void ToggleDrawnStatus() { mDrawn = !mDrawn; } - nsIPresShell *mPresShell; // we rely on the nsEditor to refCount this - nsITimer* mBlinkTimer; + nsCOMPtr mPresShell; + + nsITimer* mBlinkTimer; PRUint32 mBlinkRate; // time for one cyle (off then on), in milliseconds nscoord mCaretWidth; // caret width in twips diff --git a/mozilla/layout/base/nsDocumentViewer.cpp b/mozilla/layout/base/nsDocumentViewer.cpp index de5a4423515..95babda7424 100644 --- a/mozilla/layout/base/nsDocumentViewer.cpp +++ b/mozilla/layout/base/nsDocumentViewer.cpp @@ -81,6 +81,7 @@ //focus #include "nsIDOMEventReceiver.h" #include "nsIDOMFocusListener.h" +#include "nsISelectionController.h" static NS_DEFINE_CID(kEventQueueService, NS_EVENTQUEUESERVICE_CID); @@ -1023,8 +1024,11 @@ nsresult DocumentViewerImpl::GetDocumentSelection(nsIDOMSelection **aSelection) { if (!aSelection) return NS_ERROR_NULL_POINTER; if (!mPresShell) return NS_ERROR_NOT_INITIALIZED; - - return mPresShell->GetSelection(SELECTION_NORMAL, aSelection); + nsCOMPtr selcon; + selcon = do_QueryInterface(mPresShell); + if (selcon) + return selcon->GetSelection(nsISelectionController::SELECTION_NORMAL, aSelection); + return NS_ERROR_FAILURE; } NS_IMETHODIMP @@ -1811,10 +1815,14 @@ nsDocViewerFocusListener::Focus(nsIDOMEvent* aEvent) nsCOMPtr ps; result = mDocViewer->GetPresShell(*getter_AddRefs(ps)); - if(NS_FAILED(result) || !ps) return result?result:NS_ERROR_FAILURE; - ps->RepaintSelection(SELECTION_NORMAL); + + nsCOMPtr selcon; + selcon = do_QueryInterface(ps,&result); + if(NS_FAILED(result) || !selcon) + return result?result:NS_ERROR_FAILURE; + selcon->RepaintSelection(nsISelectionController::SELECTION_NORMAL); } return result; } @@ -1841,10 +1849,14 @@ nsDocViewerFocusListener::Blur(nsIDOMEvent* aEvent) nsCOMPtr ps; result = mDocViewer->GetPresShell(*getter_AddRefs(ps));//deref once cause it take a ptr ref - if(NS_FAILED(result) || !ps) return result?result:NS_ERROR_FAILURE; - ps->RepaintSelection(SELECTION_NORMAL); + + nsCOMPtr selcon; + selcon = do_QueryInterface(ps,&result); + if(NS_FAILED(result) || !selcon) + return result?result:NS_ERROR_FAILURE; + selcon->RepaintSelection(nsISelectionController::SELECTION_NORMAL); } return result; } diff --git a/mozilla/layout/base/nsICaret.h b/mozilla/layout/base/nsICaret.h index 982773ff52b..50e7b5c4faf 100644 --- a/mozilla/layout/base/nsICaret.h +++ b/mozilla/layout/base/nsICaret.h @@ -80,29 +80,29 @@ extern nsresult NS_NewCaret(nsICaret** aInstancePtrResult); class StCaretHider { public: - StCaretHider(nsIPresShell* aPresShell) - : mWasVisible(PR_FALSE), mPresShell(nsnull) + StCaretHider(nsISelectionController* aSelCon) + : mWasVisible(PR_FALSE), mSelCon(nsnull) { - mPresShell = aPresShell; // addrefs - if (mPresShell) + mSelCon = aSelCon; // addrefs + if (mSelCon) { - mPresShell->GetCaretEnabled(&mWasVisible); + mSelCon->GetCaretEnabled(&mWasVisible); if (mWasVisible) - mPresShell->SetCaretEnabled(PR_FALSE); + mSelCon->SetCaretEnabled(PR_FALSE); } } ~StCaretHider() { - if (mPresShell && mWasVisible) - mPresShell->SetCaretEnabled(PR_TRUE); + if (mSelCon && mWasVisible) + mSelCon->SetCaretEnabled(PR_TRUE); // nsCOMPtr releases mPresShell } protected: PRBool mWasVisible; - nsCOMPtr mPresShell; + nsCOMPtr mSelCon; }; diff --git a/mozilla/layout/base/nsIFrameSelection.h b/mozilla/layout/base/nsIFrameSelection.h index 7668f3c0db8..0194e705ad8 100644 --- a/mozilla/layout/base/nsIFrameSelection.h +++ b/mozilla/layout/base/nsIFrameSelection.h @@ -38,6 +38,7 @@ #include "nsIContent.h" #include "nsCOMPtr.h" #include "nsIStyleContext.h" +#include "nsISelectionController.h" // IID for the nsIFrameSelection interface diff --git a/mozilla/layout/base/nsIPresShell.h b/mozilla/layout/base/nsIPresShell.h index b47bf20f1ad..7dcf0cf6962 100644 --- a/mozilla/layout/base/nsIPresShell.h +++ b/mozilla/layout/base/nsIPresShell.h @@ -29,6 +29,9 @@ #include "nsIReflowCommand.h" #include "nsGUIEvent.h" +#include "nsISelectionController.h" //for the selection enums. + + class nsIContent; class nsIContentIterator; class nsIDocument; @@ -62,19 +65,6 @@ class nsIArena; #define NS_PRESSHELL_SCROLL_ANYWHERE -1 #define NS_PRESSHELL_SCROLL_IF_NOT_VISIBLE -2 -typedef enum SelectionType{ - SELECTION_NONE = 0, - SELECTION_NORMAL = 1, - SELECTION_SPELLCHECK = 2, - SELECTION_IME_RAWINPUT= 4, - SELECTION_IME_SELECTEDRAWTEXT = 8, - SELECTION_IME_CONVERTEDTEXT = 16, - SELECTION_IME_SELECTEDCONVERTEDTEXT = 32, - NUM_SELECTIONTYPES=6} SelectionType; - -typedef enum SelectionRegion{SELECTION_ANCHOR_REGION = 0, - SELECTION_FOCUS_REGION, - NUM_SELECTION_REGIONS} SelectionRegion; // debug VerifyReflow flags #define VERIFY_REFLOW_ON 0x01 @@ -135,30 +125,6 @@ public: */ NS_IMETHOD ListAlternateStyleSheets(nsStringArray& aTitleList) = 0; - /** - * GetSelection will return the selection that the presentation - * shell may implement. - * - * @param aSelection will hold the return value - */ - NS_IMETHOD GetSelection(SelectionType aType, nsIDOMSelection** aSelection) = 0; - - /** - * 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. - */ - NS_IMETHOD ScrollSelectionIntoView(SelectionType aType, SelectionRegion aRegion) = 0; - - /** - * RepaintSelection repaints the selection specified by aType. - * - * @param aType specifies the selection to repaint. - */ - NS_IMETHOD RepaintSelection(SelectionType aType) = 0; - /** * GetFrameSelection will return the Frame based selection API you * cannot go back and forth anymore with QI with nsIDOM sel and nsIFrame sel. @@ -351,23 +317,6 @@ public: * Get the caret, if it exists. AddRefs it. */ NS_IMETHOD GetCaret(nsICaret **aOutCaret) = 0; - - /** - * Set the caret as enabled or disabled. An enabled caret will - * draw or blink when made visible. A disabled caret will never show up. - * Can be called any time. - * @param aEnable PR_TRUE to enable caret. PR_FALSE to disable. - * @return always NS_OK - */ - NS_IMETHOD SetCaretEnabled(PRBool aInEnable) = 0; - - /** - * Gets the current state of the caret. - * @param aEnabled [OUT] set to the current caret state, as set by SetCaretEnabled - * @return if aOutEnabled==null, returns NS_ERROR_INVALID_ARG - * else NS_OK - */ - NS_IMETHOD GetCaretEnabled(PRBool *aOutEnabled) = 0; /** * Should the images have borders etc. Actual visual effects are determined diff --git a/mozilla/layout/base/nsPresShell.cpp b/mozilla/layout/base/nsPresShell.cpp index d7fafc58c51..069247272ac 100644 --- a/mozilla/layout/base/nsPresShell.cpp +++ b/mozilla/layout/base/nsPresShell.cpp @@ -19,7 +19,7 @@ * * Contributor(s): */ - + #define PL_ARENA_CONST_ALIGN_MASK 3 #include "nsIPresShell.h" #include "nsISpaceManager.h" @@ -551,6 +551,7 @@ public: NS_IMETHOD GetActiveAlternateStyleSheet(nsString& aSheetTitle); NS_IMETHOD SelectAlternateStyleSheet(const nsString& aSheetTitle); NS_IMETHOD ListAlternateStyleSheets(nsStringArray& aTitleList); + NS_IMETHOD GetSelection(SelectionType aType, nsIDOMSelection** aSelection); NS_IMETHOD ScrollSelectionIntoView(SelectionType aType, SelectionRegion aRegion); NS_IMETHOD RepaintSelection(SelectionType aType); @@ -1378,7 +1379,7 @@ PresShell::EndObservingDocument() if (mSelection){ nsCOMPtr domselection; nsresult result; - result = mSelection->GetSelection(SELECTION_NORMAL, getter_AddRefs(domselection)); + result = mSelection->GetSelection(nsISelectionController::SELECTION_NORMAL, getter_AddRefs(domselection)); if (NS_FAILED(result)) return result; if (!domselection) @@ -2471,7 +2472,7 @@ PresShell::DoCopy() nsresult rv; nsIDOMSelection* sel; - GetSelection(SELECTION_NORMAL, &sel); + GetSelection(nsISelectionController::SELECTION_NORMAL, &sel); if (sel != nsnull) doc->CreateXIF(buffer,sel); @@ -4251,10 +4252,14 @@ PresShellViewEventListener::HideCaret() if (mPresShell && 0 == mCallCount) { - result = mPresShell->GetCaretEnabled(&mWasVisible); + nsCOMPtr selCon = do_QueryInterface(mPresShell); + if (selCon) + { + result = selCon->GetCaretEnabled(&mWasVisible); - if (NS_SUCCEEDED(result) && mWasVisible) - result = mPresShell->SetCaretEnabled(PR_FALSE); + if (NS_SUCCEEDED(result) && mWasVisible) + result = selCon->SetCaretEnabled(PR_FALSE); + } } ++mCallCount; @@ -4270,7 +4275,11 @@ PresShellViewEventListener::RestoreCaretVisibility() --mCallCount; if (mPresShell && 0 == mCallCount && mWasVisible) - result = mPresShell->SetCaretEnabled(PR_TRUE); + { + nsCOMPtr selCon = do_QueryInterface(mPresShell); + if (selCon) + result = selCon->SetCaretEnabled(PR_TRUE); + } return result; } diff --git a/mozilla/layout/base/public/nsICaret.h b/mozilla/layout/base/public/nsICaret.h index 982773ff52b..50e7b5c4faf 100644 --- a/mozilla/layout/base/public/nsICaret.h +++ b/mozilla/layout/base/public/nsICaret.h @@ -80,29 +80,29 @@ extern nsresult NS_NewCaret(nsICaret** aInstancePtrResult); class StCaretHider { public: - StCaretHider(nsIPresShell* aPresShell) - : mWasVisible(PR_FALSE), mPresShell(nsnull) + StCaretHider(nsISelectionController* aSelCon) + : mWasVisible(PR_FALSE), mSelCon(nsnull) { - mPresShell = aPresShell; // addrefs - if (mPresShell) + mSelCon = aSelCon; // addrefs + if (mSelCon) { - mPresShell->GetCaretEnabled(&mWasVisible); + mSelCon->GetCaretEnabled(&mWasVisible); if (mWasVisible) - mPresShell->SetCaretEnabled(PR_FALSE); + mSelCon->SetCaretEnabled(PR_FALSE); } } ~StCaretHider() { - if (mPresShell && mWasVisible) - mPresShell->SetCaretEnabled(PR_TRUE); + if (mSelCon && mWasVisible) + mSelCon->SetCaretEnabled(PR_TRUE); // nsCOMPtr releases mPresShell } protected: PRBool mWasVisible; - nsCOMPtr mPresShell; + nsCOMPtr mSelCon; }; diff --git a/mozilla/layout/base/public/nsIFrameSelection.h b/mozilla/layout/base/public/nsIFrameSelection.h index 7668f3c0db8..0194e705ad8 100644 --- a/mozilla/layout/base/public/nsIFrameSelection.h +++ b/mozilla/layout/base/public/nsIFrameSelection.h @@ -38,6 +38,7 @@ #include "nsIContent.h" #include "nsCOMPtr.h" #include "nsIStyleContext.h" +#include "nsISelectionController.h" // IID for the nsIFrameSelection interface diff --git a/mozilla/layout/base/public/nsIPresShell.h b/mozilla/layout/base/public/nsIPresShell.h index b47bf20f1ad..7dcf0cf6962 100644 --- a/mozilla/layout/base/public/nsIPresShell.h +++ b/mozilla/layout/base/public/nsIPresShell.h @@ -29,6 +29,9 @@ #include "nsIReflowCommand.h" #include "nsGUIEvent.h" +#include "nsISelectionController.h" //for the selection enums. + + class nsIContent; class nsIContentIterator; class nsIDocument; @@ -62,19 +65,6 @@ class nsIArena; #define NS_PRESSHELL_SCROLL_ANYWHERE -1 #define NS_PRESSHELL_SCROLL_IF_NOT_VISIBLE -2 -typedef enum SelectionType{ - SELECTION_NONE = 0, - SELECTION_NORMAL = 1, - SELECTION_SPELLCHECK = 2, - SELECTION_IME_RAWINPUT= 4, - SELECTION_IME_SELECTEDRAWTEXT = 8, - SELECTION_IME_CONVERTEDTEXT = 16, - SELECTION_IME_SELECTEDCONVERTEDTEXT = 32, - NUM_SELECTIONTYPES=6} SelectionType; - -typedef enum SelectionRegion{SELECTION_ANCHOR_REGION = 0, - SELECTION_FOCUS_REGION, - NUM_SELECTION_REGIONS} SelectionRegion; // debug VerifyReflow flags #define VERIFY_REFLOW_ON 0x01 @@ -135,30 +125,6 @@ public: */ NS_IMETHOD ListAlternateStyleSheets(nsStringArray& aTitleList) = 0; - /** - * GetSelection will return the selection that the presentation - * shell may implement. - * - * @param aSelection will hold the return value - */ - NS_IMETHOD GetSelection(SelectionType aType, nsIDOMSelection** aSelection) = 0; - - /** - * 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. - */ - NS_IMETHOD ScrollSelectionIntoView(SelectionType aType, SelectionRegion aRegion) = 0; - - /** - * RepaintSelection repaints the selection specified by aType. - * - * @param aType specifies the selection to repaint. - */ - NS_IMETHOD RepaintSelection(SelectionType aType) = 0; - /** * GetFrameSelection will return the Frame based selection API you * cannot go back and forth anymore with QI with nsIDOM sel and nsIFrame sel. @@ -351,23 +317,6 @@ public: * Get the caret, if it exists. AddRefs it. */ NS_IMETHOD GetCaret(nsICaret **aOutCaret) = 0; - - /** - * Set the caret as enabled or disabled. An enabled caret will - * draw or blink when made visible. A disabled caret will never show up. - * Can be called any time. - * @param aEnable PR_TRUE to enable caret. PR_FALSE to disable. - * @return always NS_OK - */ - NS_IMETHOD SetCaretEnabled(PRBool aInEnable) = 0; - - /** - * Gets the current state of the caret. - * @param aEnabled [OUT] set to the current caret state, as set by SetCaretEnabled - * @return if aOutEnabled==null, returns NS_ERROR_INVALID_ARG - * else NS_OK - */ - NS_IMETHOD GetCaretEnabled(PRBool *aOutEnabled) = 0; /** * Should the images have borders etc. Actual visual effects are determined diff --git a/mozilla/layout/base/public/nsISelectionController.idl b/mozilla/layout/base/public/nsISelectionController.idl index 610bee20f54..be4b3415341 100644 --- a/mozilla/layout/base/public/nsISelectionController.idl +++ b/mozilla/layout/base/public/nsISelectionController.idl @@ -23,10 +23,75 @@ #include "nsISupports.idl" +#include "domstubs.idl" + + +%{C++ + +class nsIDOMSelection; +typedef short SelectionType; +typedef short SelectionRegion; +%} + [scriptable, uuid(D2D1D179-85A7-11d3-9932-00108301233C)] interface nsISelectionController : nsISupports { + const short SELECTION_NONE=0; + const short SELECTION_NORMAL=1; + const short SELECTION_SPELLCHECK=2; + const short SELECTION_IME_RAWINPUT=4; + const short SELECTION_IME_SELECTEDRAWTEXT=8; + const short SELECTION_IME_CONVERTEDTEXT=16; + const short SELECTION_IME_SELECTEDCONVERTEDTEXT=32; + const short NUM_SELECTIONTYPES=6; + + + const short SELECTION_ANCHOR_REGION = 0; + const short SELECTION_FOCUS_REGION = 1; + const short NUM_SELECTION_REGIONS = 2; + + /** + * GetSelection will return the selection that the presentation + * shell may implement. + * + * @param aType will hold the type of selection //SelectionType + * @param _return will hold the return value + */ + nsIDOMSelection getSelection(in short type); + + /** + * ScrollSelectionIntoView scrolls a region of the selection, + * so that it is visible in the scrolled view. + * + * @param aType the selection to scroll into view. //SelectionType + * @param aRegion the region inside the selection to scroll into view. //SelectionRegion + */ + void scrollSelectionIntoView(in short type, in short region); + /** + * RepaintSelection repaints the selection specified by aType. + * + * @param aType specifies the selection to repaint. + */ + void repaintSelection(in short type); + + /** + * Set the caret as enabled or disabled. An enabled caret will + * draw or blink when made visible. A disabled caret will never show up. + * Can be called any time. + * @param aEnable PR_TRUE to enable caret. PR_FALSE to disable. + * @return always NS_OK + */ + void setCaretEnabled(in boolean enabled); + + /** + * Gets the current state of the caret. + * @param aEnabled [OUT] set to the current caret state, as set by SetCaretEnabled + * @return if aOutEnabled==null, returns NS_ERROR_INVALID_ARG + * else NS_OK + */ + boolean getCaretEnabled(); + /** CharacterMove will move the selection one character forward/backward in the document. * this will also have the effect of collapsing the selection if the aExtend = PR_FALSE * the "point" of selection that is extended is considered the "focus" point. diff --git a/mozilla/layout/base/src/nsCaret.cpp b/mozilla/layout/base/src/nsCaret.cpp index 2686dca4c09..9a6f7d94500 100644 --- a/mozilla/layout/base/src/nsCaret.cpp +++ b/mozilla/layout/base/src/nsCaret.cpp @@ -44,6 +44,7 @@ #include "nsILookAndFeel.h" #include "nsWidgetsCID.h" // for NS_LOOKANDFEEL_CID #include "nsBlockFrame.h" +#include "nsISelectionController.h" #include "nsCaret.h" @@ -79,8 +80,8 @@ NS_IMETHODIMP nsCaret::Init(nsIPresShell *inPresShell) if (!inPresShell) return NS_ERROR_NULL_POINTER; - mPresShell = inPresShell; // the presshell owns us, so no addref - + mPresShell = getter_AddRefs(NS_GetWeakReference(inPresShell)); // the presshell owns us, so no addref + nsILookAndFeel* touchyFeely; if (NS_SUCCEEDED(nsComponentManager::CreateInstance(kLookAndFeelCID, nsnull, NS_GET_IID(nsILookAndFeel), (void**)&touchyFeely))) { @@ -98,10 +99,16 @@ NS_IMETHODIMP nsCaret::Init(nsIPresShell *inPresShell) // listener nsCOMPtr domSelection; - if (NS_SUCCEEDED(mPresShell->GetSelection(SELECTION_NORMAL, getter_AddRefs(domSelection)))) + nsCOMPtr selCon = do_QueryReferent(mPresShell); + if (selCon) { - domSelection->AddSelectionListener(this); - } + if (NS_SUCCEEDED(selCon->GetSelection(nsISelectionController::SELECTION_NORMAL, getter_AddRefs(domSelection)))) + { + domSelection->AddSelectionListener(this); + } + } + else + return NS_ERROR_FAILURE; // set up the blink timer if (mVisible) @@ -181,9 +188,16 @@ NS_IMETHODIMP nsCaret::GetWindowRelativeCoordinates(nsRect& outCoordinates, PRBo return NS_ERROR_NOT_INITIALIZED; nsCOMPtr domSelection; - nsresult err = mPresShell->GetSelection(SELECTION_NORMAL,getter_AddRefs(domSelection)); - if (NS_FAILED(err)) - return err; + nsCOMPtr selCon = do_QueryReferent(mPresShell); + nsresult err; + if (selCon) + { + err = selCon->GetSelection(nsISelectionController::SELECTION_NORMAL,getter_AddRefs(domSelection)); + if (NS_FAILED(err)) + return err; + } + else + return NS_ERROR_FAILURE; if (!domSelection) return NS_ERROR_NOT_INITIALIZED; // no selection @@ -227,9 +241,13 @@ NS_IMETHODIMP nsCaret::GetWindowRelativeCoordinates(nsRect& outCoordinates, PRBo //get frame selection and find out what frame to use... nsCOMPtr frameSelection; - err = mPresShell->GetFrameSelection(getter_AddRefs(frameSelection)); - if (NS_FAILED(err) || !frameSelection) - return err; + nsCOMPtr presShell = do_QueryReferent(mPresShell); + if (presShell) + err = presShell->GetFrameSelection(getter_AddRefs(frameSelection)); + else + return NS_ERROR_FAILURE; + if (NS_FAILED(err) || !frameSelection) + return err?err : NS_ERROR_FAILURE; // find the frame that contains the content node that has focus nsIFrame* theFrame = nsnull; @@ -247,7 +265,7 @@ NS_IMETHODIMP nsCaret::GetWindowRelativeCoordinates(nsRect& outCoordinates, PRBo // ramp up to make a rendering context for measuring text. // First, we get the pres context ... nsCOMPtr presContext; - err = mPresShell->GetPresContext(getter_AddRefs(presContext)); + err = presShell->GetPresContext(getter_AddRefs(presContext)); if (NS_FAILED(err)) return err; @@ -386,10 +404,16 @@ nsresult nsCaret::StopBlinking() PRBool nsCaret::SetupDrawingFrameAndOffset() { nsCOMPtr domSelection; - nsresult err = mPresShell->GetSelection(SELECTION_NORMAL, getter_AddRefs(domSelection)); - if (!NS_SUCCEEDED(err) || !domSelection) - return PR_FALSE; - + nsCOMPtr selCon = do_QueryReferent(mPresShell); + nsresult err; + if (selCon) + { + err = selCon->GetSelection(nsISelectionController::SELECTION_NORMAL, getter_AddRefs(domSelection)); + if (!NS_SUCCEEDED(err) || !domSelection) + return PR_FALSE; + } + else + return NS_ERROR_FAILURE; PRBool isCollapsed; if (domSelection && NS_SUCCEEDED(domSelection->GetIsCollapsed(&isCollapsed)) && isCollapsed) @@ -433,7 +457,11 @@ PRBool nsCaret::SetupDrawingFrameAndOffset() //get frame selection and find out what frame to use... nsCOMPtr frameSelection; - err = mPresShell->GetFrameSelection(getter_AddRefs(frameSelection)); + nsCOMPtr presShell = do_QueryReferent(mPresShell); + if (presShell) + err = presShell->GetFrameSelection(getter_AddRefs(frameSelection)); + else + return NS_ERROR_FAILURE; if (NS_FAILED(err) || !frameSelection) return PR_FALSE; @@ -476,7 +504,11 @@ void nsCaret::GetViewForRendering(nsIFrame *caretFrame, EViewCoordinates coordTy nsIView* theView = nsnull; NS_ASSERTION(caretFrame, "Should have frame here"); nsCOMPtr presContext; - mPresShell->GetPresContext(getter_AddRefs(presContext)); + nsCOMPtr presShell = do_QueryReferent(mPresShell); + if (presShell) + presShell->GetPresContext(getter_AddRefs(presContext)); + else + return; caretFrame->GetOffsetFromView(presContext, viewOffset, &theView); if (theView == nsnull) return; @@ -526,10 +558,15 @@ PRBool nsCaret::MustDrawCaret() return PR_TRUE; nsCOMPtr domSelection; - nsresult err = mPresShell->GetSelection(SELECTION_NORMAL, getter_AddRefs(domSelection)); - if (NS_FAILED(err) || !domSelection) - return PR_FALSE; - + nsCOMPtr selCon = do_QueryReferent(mPresShell); + if (selCon) + { + nsresult err = selCon->GetSelection(nsISelectionController::SELECTION_NORMAL, getter_AddRefs(domSelection)); + if (NS_FAILED(err) || !domSelection) + return PR_FALSE; + } + else + return NS_ERROR_FAILURE; PRBool isCollapsed; if (NS_FAILED(domSelection->GetIsCollapsed(&isCollapsed))) @@ -573,8 +610,14 @@ void nsCaret::DrawCaretWithContext(nsIRenderingContext* inRendContext) frameRect += viewOffset; nsCOMPtr presContext; - if (NS_FAILED(mPresShell->GetPresContext(getter_AddRefs(presContext)))) - return; + nsCOMPtr presShell = do_QueryReferent(mPresShell); + if (presShell) + { + if (NS_FAILED(presShell->GetPresContext(getter_AddRefs(presContext)))) + return; + } + else + return; // make a rendering context, if we didn't get passed one nsCOMPtr localRC = do_QueryInterface(inRendContext); // OK if inRendContext is null diff --git a/mozilla/layout/base/src/nsCaret.h b/mozilla/layout/base/src/nsCaret.h index f2aa093d8fa..7d6d36af444 100644 --- a/mozilla/layout/base/src/nsCaret.h +++ b/mozilla/layout/base/src/nsCaret.h @@ -25,10 +25,12 @@ #include "nsCoord.h" #include "nsIDOMSelectionListener.h" #include "nsICaret.h" +#include "nsWeakPtr.h" class nsITimer; class nsIView; class nsIRenderingContext; +class nsISelectionController; // {E14B66F6-BFC5-11d2-B57E-00105AA83B2F} #define NS_CARET_CID \ @@ -83,8 +85,9 @@ class nsCaret : public nsICaret, void DrawCaret(); void ToggleDrawnStatus() { mDrawn = !mDrawn; } - nsIPresShell *mPresShell; // we rely on the nsEditor to refCount this - nsITimer* mBlinkTimer; + nsCOMPtr mPresShell; + + nsITimer* mBlinkTimer; PRUint32 mBlinkRate; // time for one cyle (off then on), in milliseconds nscoord mCaretWidth; // caret width in twips diff --git a/mozilla/layout/base/src/nsDocumentViewer.cpp b/mozilla/layout/base/src/nsDocumentViewer.cpp index de5a4423515..95babda7424 100644 --- a/mozilla/layout/base/src/nsDocumentViewer.cpp +++ b/mozilla/layout/base/src/nsDocumentViewer.cpp @@ -81,6 +81,7 @@ //focus #include "nsIDOMEventReceiver.h" #include "nsIDOMFocusListener.h" +#include "nsISelectionController.h" static NS_DEFINE_CID(kEventQueueService, NS_EVENTQUEUESERVICE_CID); @@ -1023,8 +1024,11 @@ nsresult DocumentViewerImpl::GetDocumentSelection(nsIDOMSelection **aSelection) { if (!aSelection) return NS_ERROR_NULL_POINTER; if (!mPresShell) return NS_ERROR_NOT_INITIALIZED; - - return mPresShell->GetSelection(SELECTION_NORMAL, aSelection); + nsCOMPtr selcon; + selcon = do_QueryInterface(mPresShell); + if (selcon) + return selcon->GetSelection(nsISelectionController::SELECTION_NORMAL, aSelection); + return NS_ERROR_FAILURE; } NS_IMETHODIMP @@ -1811,10 +1815,14 @@ nsDocViewerFocusListener::Focus(nsIDOMEvent* aEvent) nsCOMPtr ps; result = mDocViewer->GetPresShell(*getter_AddRefs(ps)); - if(NS_FAILED(result) || !ps) return result?result:NS_ERROR_FAILURE; - ps->RepaintSelection(SELECTION_NORMAL); + + nsCOMPtr selcon; + selcon = do_QueryInterface(ps,&result); + if(NS_FAILED(result) || !selcon) + return result?result:NS_ERROR_FAILURE; + selcon->RepaintSelection(nsISelectionController::SELECTION_NORMAL); } return result; } @@ -1841,10 +1849,14 @@ nsDocViewerFocusListener::Blur(nsIDOMEvent* aEvent) nsCOMPtr ps; result = mDocViewer->GetPresShell(*getter_AddRefs(ps));//deref once cause it take a ptr ref - if(NS_FAILED(result) || !ps) return result?result:NS_ERROR_FAILURE; - ps->RepaintSelection(SELECTION_NORMAL); + + nsCOMPtr selcon; + selcon = do_QueryInterface(ps,&result); + if(NS_FAILED(result) || !selcon) + return result?result:NS_ERROR_FAILURE; + selcon->RepaintSelection(nsISelectionController::SELECTION_NORMAL); } return result; } diff --git a/mozilla/layout/base/src/nsSelection.cpp b/mozilla/layout/base/src/nsSelection.cpp index 83be3aa908e..b0727318d52 100644 --- a/mozilla/layout/base/src/nsSelection.cpp +++ b/mozilla/layout/base/src/nsSelection.cpp @@ -69,6 +69,7 @@ #include "nsIDOMDocument.h" #include "nsIDocument.h" +#include "nsISelectionController.h"//for the enums #define STATUS_CHECK_RETURN_MACRO() {if (!mTracker) return NS_ERROR_FAILURE;} //#define DEBUG_TABLE 1 @@ -156,7 +157,7 @@ public: nsresult GetSelectionRegionRect(SelectionRegion aRegion, nsRect *aRect); nsresult ScrollRectIntoView(nsRect& aRect, PRIntn aVPercent, PRIntn aHPercent); - NS_IMETHOD ScrollIntoView(SelectionRegion aRegion=SELECTION_FOCUS_REGION); + NS_IMETHOD ScrollIntoView(SelectionRegion aRegion=nsISelectionController::SELECTION_FOCUS_REGION); nsresult AddItem(nsIDOMRange *aRange); nsresult RemoveItem(nsIDOMRange *aRange); @@ -320,7 +321,7 @@ private: NS_IMETHOD SetHint(PRBool aHintRight); NS_IMETHOD GetHint(PRBool *aHintRight); - nsDOMSelection *mDomSelections[NUM_SELECTIONTYPES]; + nsDOMSelection *mDomSelections[nsISelectionController::NUM_SELECTIONTYPES]; // Table selection support. Unfortunately, we can't get at nsITableCellLayout // and nsITableLayout through nsIFrame, so we have to duplicate editor code here @@ -537,12 +538,12 @@ GetIndexFromSelectionType(SelectionType aType) { switch (aType) { - case SELECTION_NORMAL: return 0; break; - case SELECTION_SPELLCHECK: return 1; break; - case SELECTION_IME_RAWINPUT: return 2; break; - case SELECTION_IME_SELECTEDRAWTEXT: return 3; break; - case SELECTION_IME_CONVERTEDTEXT: return 4; break; - case SELECTION_IME_SELECTEDCONVERTEDTEXT: return 5; break; + case nsISelectionController::SELECTION_NORMAL: return 0; break; + case nsISelectionController::SELECTION_SPELLCHECK: return 1; break; + case nsISelectionController::SELECTION_IME_RAWINPUT: return 2; break; + case nsISelectionController::SELECTION_IME_SELECTEDRAWTEXT: return 3; break; + case nsISelectionController::SELECTION_IME_CONVERTEDTEXT: return 4; break; + case nsISelectionController::SELECTION_IME_SELECTEDCONVERTEDTEXT: return 5; break; default:return -1;break; } } @@ -552,14 +553,14 @@ GetSelectionTypeFromIndex(PRInt8 aIndex) { switch (aIndex) { - case 0: return SELECTION_NORMAL;break; - case 1: return SELECTION_SPELLCHECK;break; - case 2: return SELECTION_IME_RAWINPUT;break; - case 3: return SELECTION_IME_SELECTEDRAWTEXT;break; - case 4: return SELECTION_IME_CONVERTEDTEXT;break; - case 5: return SELECTION_IME_SELECTEDCONVERTEDTEXT;break; + case 0: return nsISelectionController::SELECTION_NORMAL;break; + case 1: return nsISelectionController::SELECTION_SPELLCHECK;break; + case 2: return nsISelectionController::SELECTION_IME_RAWINPUT;break; + case 3: return nsISelectionController::SELECTION_IME_SELECTEDRAWTEXT;break; + case 4: return nsISelectionController::SELECTION_IME_CONVERTEDTEXT;break; + case 5: return nsISelectionController::SELECTION_IME_SELECTEDCONVERTEDTEXT;break; default: - return SELECTION_NORMAL;break; + return nsISelectionController::SELECTION_NORMAL;break; } } @@ -728,10 +729,10 @@ nsSelection::nsSelection() { NS_INIT_REFCNT(); PRInt32 i; - for (i = 0;iListen(mDomSelections[index]); } @@ -796,7 +797,7 @@ nsSelection::~nsSelection() NS_IF_RELEASE(sTbodyAtom); } PRInt32 i; - for (i = 0;imessage) { - PRInt8 index = GetIndexFromSelectionType(SELECTION_NORMAL); + PRInt8 index = GetIndexFromSelectionType(nsISelectionController::SELECTION_NORMAL); result = mDomSelections[index]->ScrollIntoView(); } return result; @@ -1265,7 +1266,7 @@ nsSelection::MoveCaret(PRUint32 aKeycode, PRBool aContinue, nsSelectionAmount aA PRBool isCollapsed; nscoord desiredX; //we must keep this around and revalidate it when its just UP/DOWN - PRInt8 index = GetIndexFromSelectionType(SELECTION_NORMAL); + PRInt8 index = GetIndexFromSelectionType(nsISelectionController::SELECTION_NORMAL); result = mDomSelections[index]->GetIsCollapsed(&isCollapsed); if (NS_FAILED(result)) return result; @@ -1571,14 +1572,14 @@ nsSelection::HandleDrag(nsIPresContext *aPresContext, nsIFrame *aFrame, nsPoint& NS_IMETHODIMP nsSelection::StartAutoScrollTimer(nsIPresContext *aPresContext, nsIFrame *aFrame, nsPoint& aPoint, PRUint32 aDelay) { - PRInt8 index = GetIndexFromSelectionType(SELECTION_NORMAL); + PRInt8 index = GetIndexFromSelectionType(nsISelectionController::SELECTION_NORMAL); return mDomSelections[index]->StartAutoScrollTimer(aPresContext, aFrame, aPoint, aDelay); } NS_IMETHODIMP nsSelection::StopAutoScrollTimer() { - PRInt8 index = GetIndexFromSelectionType(SELECTION_NORMAL); + PRInt8 index = GetIndexFromSelectionType(nsISelectionController::SELECTION_NORMAL); return mDomSelections[index]->StopAutoScrollTimer(); } @@ -1605,7 +1606,7 @@ nsSelection::TakeFocus(nsIContent *aNewFocus, PRUint32 aContentOffset, //return NS_ERROR_FAILURE; //END HACKHACKHACK /checking for root frames/content - PRInt8 index = GetIndexFromSelectionType(SELECTION_NORMAL); + PRInt8 index = GetIndexFromSelectionType(nsISelectionController::SELECTION_NORMAL); domNode = do_QueryInterface(aNewFocus); //traverse through document and unselect crap here if (!aContinueSelection){ //single click? setting cursor down @@ -1646,7 +1647,7 @@ nsSelection::TakeFocus(nsIContent *aNewFocus, PRUint32 aContentOffset, } } - return NotifySelectionListeners(SELECTION_NORMAL); + return NotifySelectionListeners(nsISelectionController::SELECTION_NORMAL); } @@ -1662,7 +1663,7 @@ nsSelection::LookUpSelection(nsIContent *aContent, PRInt32 aContentOffset, PRInt *aReturnDetails = nsnull; PRInt8 j; - for (j = (PRInt8) 0; j < (PRInt8)NUM_SELECTIONTYPES; j++){ + for (j = (PRInt8) 0; j < (PRInt8)nsISelectionController::NUM_SELECTIONTYPES; j++){ if (mDomSelections[j]) mDomSelections[j]->LookUpSelection(aContent, aContentOffset, aContentLength, aReturnDetails, (SelectionType)(1<=0,"Bad mBatching"); if (mBatching == 0 && mChangesDuringBatching){ mChangesDuringBatching = PR_FALSE; - NotifySelectionListeners(SELECTION_NORMAL); + NotifySelectionListeners(nsISelectionController::SELECTION_NORMAL); } return result; } @@ -2038,7 +2039,7 @@ nsSelection::HandleTableSelection(nsIContent *aParentContent, PRInt32 aContentOf // Stack-class to wrap all table selection changes in // BeginBatchChanges() / EndBatchChanges() - PRInt8 index = GetIndexFromSelectionType(SELECTION_NORMAL); + PRInt8 index = GetIndexFromSelectionType(nsISelectionController::SELECTION_NORMAL); nsSelectionBatcher selectionBatcher(mDomSelections[index]); // When doing table selection, always set the direction to next @@ -2252,7 +2253,7 @@ nsSelection::SelectBlockOfCells(nsIContent *aEndCell) PRInt32 curRowIndex, curColIndex; // Examine all cell nodes, starting with first one found above - PRInt8 index = GetIndexFromSelectionType(SELECTION_NORMAL); + PRInt8 index = GetIndexFromSelectionType(nsISelectionController::SELECTION_NORMAL); while (cellNode) { nsCOMPtr cellContent = do_QueryInterface(cellNode); @@ -2367,7 +2368,7 @@ nsSelection::GetFirstSelectedCellAndRange(nsIDOMNode **aCell, nsIDOMRange **aRan *aRange = nsnull; nsCOMPtr firstRange; - PRInt8 index = GetIndexFromSelectionType(SELECTION_NORMAL); + PRInt8 index = GetIndexFromSelectionType(nsISelectionController::SELECTION_NORMAL); nsresult result = mDomSelections[index]->GetRangeAt(0, getter_AddRefs(firstRange)); if (NS_FAILED(result)) return result; if (!firstRange) return NS_ERROR_FAILURE; @@ -2396,7 +2397,7 @@ nsSelection::GetNextSelectedCellAndRange(nsIDOMNode **aCell, nsIDOMRange **aRang *aRange = nsnull; PRInt32 rangeCount; - PRInt8 index = GetIndexFromSelectionType(SELECTION_NORMAL); + PRInt8 index = GetIndexFromSelectionType(nsISelectionController::SELECTION_NORMAL); nsresult result = mDomSelections[index]->GetRangeCount(&rangeCount); if (NS_FAILED(result)) return result; @@ -2520,7 +2521,7 @@ nsSelection::CreateAndAddRange(nsIDOMNode *aParentNode, PRInt32 aOffset) result = range->SetEnd(aParentNode, aOffset+1); if (NS_FAILED(result)) return result; - PRInt8 index = GetIndexFromSelectionType(SELECTION_NORMAL); + PRInt8 index = GetIndexFromSelectionType(nsISelectionController::SELECTION_NORMAL); return mDomSelections[index]->AddRange(range); } @@ -2572,7 +2573,7 @@ nsSelection::DeleteFromDocument() // last item BEFORE the current range, rather than the range itself, // before we do the delete. PRBool isCollapsed; - PRInt8 index = GetIndexFromSelectionType(SELECTION_NORMAL); + PRInt8 index = GetIndexFromSelectionType(nsISelectionController::SELECTION_NORMAL); mDomSelections[index]->GetIsCollapsed( &isCollapsed); if (isCollapsed) { @@ -4870,12 +4871,12 @@ nsDOMSelection::GetSelectionRegionRect(SelectionRegion aRegion, nsRect *aRect) switch (aRegion) { - case SELECTION_ANCHOR_REGION: + case nsISelectionController::SELECTION_ANCHOR_REGION: node = FetchAnchorNode(); nodeOffset = FetchAnchorOffset(); isEndNode = GetDirection() == eDirPrevious; break; - case SELECTION_FOCUS_REGION: + case nsISelectionController::SELECTION_FOCUS_REGION: node = FetchFocusNode(); nodeOffset = FetchFocusOffset(); isEndNode = GetDirection() == eDirNext; @@ -5116,19 +5117,23 @@ nsDOMSelection::ScrollIntoView(SelectionRegion aRegion) result = GetPresShell(getter_AddRefs(presShell)); if (NS_FAILED(result)) return result; + nsCOMPtr selCon; + selCon = do_QueryInterface(presShell); + if (selCon) + { + StCaretHider caretHider(selCon); // stack-based class hides and shows the caret - StCaretHider caretHider(presShell); // stack-based class hides and shows the caret + // + // Scroll the selection region into view. + // + nsRect rect; + result = GetSelectionRegionRect(aRegion, &rect); - // - // Scroll the selection region into view. - // - nsRect rect; - result = GetSelectionRegionRect(aRegion, &rect); + if (NS_FAILED(result)) + return result; - if (NS_FAILED(result)) - return result; - - result = ScrollRectIntoView(rect, NS_PRESSHELL_SCROLL_ANYWHERE, NS_PRESSHELL_SCROLL_ANYWHERE); + result = ScrollRectIntoView(rect, NS_PRESSHELL_SCROLL_ANYWHERE, NS_PRESSHELL_SCROLL_ANYWHERE); + } return result; } diff --git a/mozilla/layout/generic/nsFrame.cpp b/mozilla/layout/generic/nsFrame.cpp index 33292094a2f..cca6bf5d4e5 100644 --- a/mozilla/layout/generic/nsFrame.cpp +++ b/mozilla/layout/generic/nsFrame.cpp @@ -981,9 +981,9 @@ nsFrame::HandleMultiplePress(nsIPresContext* aPresContext, return NS_OK; nsCOMPtr shell; nsresult rv = aPresContext->GetShell(getter_AddRefs(shell)); - + nsCOMPtr selcon = do_QueryInterface(shell); - if (NS_SUCCEEDED(rv) && shell) { + if (NS_SUCCEEDED(rv) && shell && selcon) { nsCOMPtr acx; nsCOMPtr tracker; tracker = do_QueryInterface(shell, &rv); @@ -1038,7 +1038,7 @@ nsFrame::HandleMultiplePress(nsIPresContext* aPresContext, return rv; nsCOMPtr selection; - if (NS_SUCCEEDED(shell->GetSelection(SELECTION_NORMAL, getter_AddRefs(selection)))){ + if (NS_SUCCEEDED(selcon->GetSelection(nsISelectionController::SELECTION_NORMAL, getter_AddRefs(selection)))){ rv = selection->Collapse(startNode,startpos.mContentOffset); if (NS_FAILED(rv)) return rv; diff --git a/mozilla/layout/generic/nsSelection.cpp b/mozilla/layout/generic/nsSelection.cpp index 83be3aa908e..b0727318d52 100644 --- a/mozilla/layout/generic/nsSelection.cpp +++ b/mozilla/layout/generic/nsSelection.cpp @@ -69,6 +69,7 @@ #include "nsIDOMDocument.h" #include "nsIDocument.h" +#include "nsISelectionController.h"//for the enums #define STATUS_CHECK_RETURN_MACRO() {if (!mTracker) return NS_ERROR_FAILURE;} //#define DEBUG_TABLE 1 @@ -156,7 +157,7 @@ public: nsresult GetSelectionRegionRect(SelectionRegion aRegion, nsRect *aRect); nsresult ScrollRectIntoView(nsRect& aRect, PRIntn aVPercent, PRIntn aHPercent); - NS_IMETHOD ScrollIntoView(SelectionRegion aRegion=SELECTION_FOCUS_REGION); + NS_IMETHOD ScrollIntoView(SelectionRegion aRegion=nsISelectionController::SELECTION_FOCUS_REGION); nsresult AddItem(nsIDOMRange *aRange); nsresult RemoveItem(nsIDOMRange *aRange); @@ -320,7 +321,7 @@ private: NS_IMETHOD SetHint(PRBool aHintRight); NS_IMETHOD GetHint(PRBool *aHintRight); - nsDOMSelection *mDomSelections[NUM_SELECTIONTYPES]; + nsDOMSelection *mDomSelections[nsISelectionController::NUM_SELECTIONTYPES]; // Table selection support. Unfortunately, we can't get at nsITableCellLayout // and nsITableLayout through nsIFrame, so we have to duplicate editor code here @@ -537,12 +538,12 @@ GetIndexFromSelectionType(SelectionType aType) { switch (aType) { - case SELECTION_NORMAL: return 0; break; - case SELECTION_SPELLCHECK: return 1; break; - case SELECTION_IME_RAWINPUT: return 2; break; - case SELECTION_IME_SELECTEDRAWTEXT: return 3; break; - case SELECTION_IME_CONVERTEDTEXT: return 4; break; - case SELECTION_IME_SELECTEDCONVERTEDTEXT: return 5; break; + case nsISelectionController::SELECTION_NORMAL: return 0; break; + case nsISelectionController::SELECTION_SPELLCHECK: return 1; break; + case nsISelectionController::SELECTION_IME_RAWINPUT: return 2; break; + case nsISelectionController::SELECTION_IME_SELECTEDRAWTEXT: return 3; break; + case nsISelectionController::SELECTION_IME_CONVERTEDTEXT: return 4; break; + case nsISelectionController::SELECTION_IME_SELECTEDCONVERTEDTEXT: return 5; break; default:return -1;break; } } @@ -552,14 +553,14 @@ GetSelectionTypeFromIndex(PRInt8 aIndex) { switch (aIndex) { - case 0: return SELECTION_NORMAL;break; - case 1: return SELECTION_SPELLCHECK;break; - case 2: return SELECTION_IME_RAWINPUT;break; - case 3: return SELECTION_IME_SELECTEDRAWTEXT;break; - case 4: return SELECTION_IME_CONVERTEDTEXT;break; - case 5: return SELECTION_IME_SELECTEDCONVERTEDTEXT;break; + case 0: return nsISelectionController::SELECTION_NORMAL;break; + case 1: return nsISelectionController::SELECTION_SPELLCHECK;break; + case 2: return nsISelectionController::SELECTION_IME_RAWINPUT;break; + case 3: return nsISelectionController::SELECTION_IME_SELECTEDRAWTEXT;break; + case 4: return nsISelectionController::SELECTION_IME_CONVERTEDTEXT;break; + case 5: return nsISelectionController::SELECTION_IME_SELECTEDCONVERTEDTEXT;break; default: - return SELECTION_NORMAL;break; + return nsISelectionController::SELECTION_NORMAL;break; } } @@ -728,10 +729,10 @@ nsSelection::nsSelection() { NS_INIT_REFCNT(); PRInt32 i; - for (i = 0;iListen(mDomSelections[index]); } @@ -796,7 +797,7 @@ nsSelection::~nsSelection() NS_IF_RELEASE(sTbodyAtom); } PRInt32 i; - for (i = 0;imessage) { - PRInt8 index = GetIndexFromSelectionType(SELECTION_NORMAL); + PRInt8 index = GetIndexFromSelectionType(nsISelectionController::SELECTION_NORMAL); result = mDomSelections[index]->ScrollIntoView(); } return result; @@ -1265,7 +1266,7 @@ nsSelection::MoveCaret(PRUint32 aKeycode, PRBool aContinue, nsSelectionAmount aA PRBool isCollapsed; nscoord desiredX; //we must keep this around and revalidate it when its just UP/DOWN - PRInt8 index = GetIndexFromSelectionType(SELECTION_NORMAL); + PRInt8 index = GetIndexFromSelectionType(nsISelectionController::SELECTION_NORMAL); result = mDomSelections[index]->GetIsCollapsed(&isCollapsed); if (NS_FAILED(result)) return result; @@ -1571,14 +1572,14 @@ nsSelection::HandleDrag(nsIPresContext *aPresContext, nsIFrame *aFrame, nsPoint& NS_IMETHODIMP nsSelection::StartAutoScrollTimer(nsIPresContext *aPresContext, nsIFrame *aFrame, nsPoint& aPoint, PRUint32 aDelay) { - PRInt8 index = GetIndexFromSelectionType(SELECTION_NORMAL); + PRInt8 index = GetIndexFromSelectionType(nsISelectionController::SELECTION_NORMAL); return mDomSelections[index]->StartAutoScrollTimer(aPresContext, aFrame, aPoint, aDelay); } NS_IMETHODIMP nsSelection::StopAutoScrollTimer() { - PRInt8 index = GetIndexFromSelectionType(SELECTION_NORMAL); + PRInt8 index = GetIndexFromSelectionType(nsISelectionController::SELECTION_NORMAL); return mDomSelections[index]->StopAutoScrollTimer(); } @@ -1605,7 +1606,7 @@ nsSelection::TakeFocus(nsIContent *aNewFocus, PRUint32 aContentOffset, //return NS_ERROR_FAILURE; //END HACKHACKHACK /checking for root frames/content - PRInt8 index = GetIndexFromSelectionType(SELECTION_NORMAL); + PRInt8 index = GetIndexFromSelectionType(nsISelectionController::SELECTION_NORMAL); domNode = do_QueryInterface(aNewFocus); //traverse through document and unselect crap here if (!aContinueSelection){ //single click? setting cursor down @@ -1646,7 +1647,7 @@ nsSelection::TakeFocus(nsIContent *aNewFocus, PRUint32 aContentOffset, } } - return NotifySelectionListeners(SELECTION_NORMAL); + return NotifySelectionListeners(nsISelectionController::SELECTION_NORMAL); } @@ -1662,7 +1663,7 @@ nsSelection::LookUpSelection(nsIContent *aContent, PRInt32 aContentOffset, PRInt *aReturnDetails = nsnull; PRInt8 j; - for (j = (PRInt8) 0; j < (PRInt8)NUM_SELECTIONTYPES; j++){ + for (j = (PRInt8) 0; j < (PRInt8)nsISelectionController::NUM_SELECTIONTYPES; j++){ if (mDomSelections[j]) mDomSelections[j]->LookUpSelection(aContent, aContentOffset, aContentLength, aReturnDetails, (SelectionType)(1<=0,"Bad mBatching"); if (mBatching == 0 && mChangesDuringBatching){ mChangesDuringBatching = PR_FALSE; - NotifySelectionListeners(SELECTION_NORMAL); + NotifySelectionListeners(nsISelectionController::SELECTION_NORMAL); } return result; } @@ -2038,7 +2039,7 @@ nsSelection::HandleTableSelection(nsIContent *aParentContent, PRInt32 aContentOf // Stack-class to wrap all table selection changes in // BeginBatchChanges() / EndBatchChanges() - PRInt8 index = GetIndexFromSelectionType(SELECTION_NORMAL); + PRInt8 index = GetIndexFromSelectionType(nsISelectionController::SELECTION_NORMAL); nsSelectionBatcher selectionBatcher(mDomSelections[index]); // When doing table selection, always set the direction to next @@ -2252,7 +2253,7 @@ nsSelection::SelectBlockOfCells(nsIContent *aEndCell) PRInt32 curRowIndex, curColIndex; // Examine all cell nodes, starting with first one found above - PRInt8 index = GetIndexFromSelectionType(SELECTION_NORMAL); + PRInt8 index = GetIndexFromSelectionType(nsISelectionController::SELECTION_NORMAL); while (cellNode) { nsCOMPtr cellContent = do_QueryInterface(cellNode); @@ -2367,7 +2368,7 @@ nsSelection::GetFirstSelectedCellAndRange(nsIDOMNode **aCell, nsIDOMRange **aRan *aRange = nsnull; nsCOMPtr firstRange; - PRInt8 index = GetIndexFromSelectionType(SELECTION_NORMAL); + PRInt8 index = GetIndexFromSelectionType(nsISelectionController::SELECTION_NORMAL); nsresult result = mDomSelections[index]->GetRangeAt(0, getter_AddRefs(firstRange)); if (NS_FAILED(result)) return result; if (!firstRange) return NS_ERROR_FAILURE; @@ -2396,7 +2397,7 @@ nsSelection::GetNextSelectedCellAndRange(nsIDOMNode **aCell, nsIDOMRange **aRang *aRange = nsnull; PRInt32 rangeCount; - PRInt8 index = GetIndexFromSelectionType(SELECTION_NORMAL); + PRInt8 index = GetIndexFromSelectionType(nsISelectionController::SELECTION_NORMAL); nsresult result = mDomSelections[index]->GetRangeCount(&rangeCount); if (NS_FAILED(result)) return result; @@ -2520,7 +2521,7 @@ nsSelection::CreateAndAddRange(nsIDOMNode *aParentNode, PRInt32 aOffset) result = range->SetEnd(aParentNode, aOffset+1); if (NS_FAILED(result)) return result; - PRInt8 index = GetIndexFromSelectionType(SELECTION_NORMAL); + PRInt8 index = GetIndexFromSelectionType(nsISelectionController::SELECTION_NORMAL); return mDomSelections[index]->AddRange(range); } @@ -2572,7 +2573,7 @@ nsSelection::DeleteFromDocument() // last item BEFORE the current range, rather than the range itself, // before we do the delete. PRBool isCollapsed; - PRInt8 index = GetIndexFromSelectionType(SELECTION_NORMAL); + PRInt8 index = GetIndexFromSelectionType(nsISelectionController::SELECTION_NORMAL); mDomSelections[index]->GetIsCollapsed( &isCollapsed); if (isCollapsed) { @@ -4870,12 +4871,12 @@ nsDOMSelection::GetSelectionRegionRect(SelectionRegion aRegion, nsRect *aRect) switch (aRegion) { - case SELECTION_ANCHOR_REGION: + case nsISelectionController::SELECTION_ANCHOR_REGION: node = FetchAnchorNode(); nodeOffset = FetchAnchorOffset(); isEndNode = GetDirection() == eDirPrevious; break; - case SELECTION_FOCUS_REGION: + case nsISelectionController::SELECTION_FOCUS_REGION: node = FetchFocusNode(); nodeOffset = FetchFocusOffset(); isEndNode = GetDirection() == eDirNext; @@ -5116,19 +5117,23 @@ nsDOMSelection::ScrollIntoView(SelectionRegion aRegion) result = GetPresShell(getter_AddRefs(presShell)); if (NS_FAILED(result)) return result; + nsCOMPtr selCon; + selCon = do_QueryInterface(presShell); + if (selCon) + { + StCaretHider caretHider(selCon); // stack-based class hides and shows the caret - StCaretHider caretHider(presShell); // stack-based class hides and shows the caret + // + // Scroll the selection region into view. + // + nsRect rect; + result = GetSelectionRegionRect(aRegion, &rect); - // - // Scroll the selection region into view. - // - nsRect rect; - result = GetSelectionRegionRect(aRegion, &rect); + if (NS_FAILED(result)) + return result; - if (NS_FAILED(result)) - return result; - - result = ScrollRectIntoView(rect, NS_PRESSHELL_SCROLL_ANYWHERE, NS_PRESSHELL_SCROLL_ANYWHERE); + result = ScrollRectIntoView(rect, NS_PRESSHELL_SCROLL_ANYWHERE, NS_PRESSHELL_SCROLL_ANYWHERE); + } return result; } diff --git a/mozilla/layout/generic/nsTextFrame.cpp b/mozilla/layout/generic/nsTextFrame.cpp index 089309f90f5..8e79726652b 100644 --- a/mozilla/layout/generic/nsTextFrame.cpp +++ b/mozilla/layout/generic/nsTextFrame.cpp @@ -781,7 +781,7 @@ inline nscolor EnsureDifferentColors(nscolor colorA, nscolor colorB) class DrawSelectionIterator { enum {DISABLED_COLOR = NS_RGB(176,176,176)}; - enum {SELECTION_TYPES_WE_CARE_ABOUT=SELECTION_NONE+SELECTION_NORMAL}; + enum {SELECTION_TYPES_WE_CARE_ABOUT=nsISelectionController::SELECTION_NONE+nsISelectionController::SELECTION_NORMAL}; public: DrawSelectionIterator(const SelectionDetails *aSelDetails, PRUnichar *aText, PRUint32 aTextLength, nsTextFrame::TextStyle &aTextStyle, @@ -1002,7 +1002,7 @@ DrawSelectionIterator::CurrentForeGroundColor() colorSet = PR_TRUE; } } - else if (mTypes[mCurrentIdx] | SELECTION_NORMAL)//Find color based on mTypes[mCurrentIdx]; + else if (mTypes[mCurrentIdx] | nsISelectionController::SELECTION_NORMAL)//Find color based on mTypes[mCurrentIdx]; { foreColor = mOldStyle.mSelectionTextColor; colorSet = PR_TRUE; @@ -1026,7 +1026,7 @@ DrawSelectionIterator::CurrentBackGroundColor(nscolor &aColor) return PR_TRUE; } } - else if (mTypes[mCurrentIdx] | SELECTION_NORMAL) + else if (mTypes[mCurrentIdx] | nsISelectionController::SELECTION_NORMAL) { aColor = (mSelectionStatus==nsIDocument::SELECTION_ON)?mOldStyle.mSelectionBGColor:mDisabledColor; return PR_TRUE; @@ -1591,7 +1591,7 @@ nsTextFrame::PaintTextDecorations(nsIRenderingContext& aRenderingContext, } switch (aDetails->mType) { - case SELECTION_NORMAL: + case nsISelectionController::SELECTION_NORMAL: #if 0 { //using new selectionpainting now @@ -1612,12 +1612,12 @@ nsTextFrame::PaintTextDecorations(nsIRenderingContext& aRenderingContext, } #endif //0 break; - case SELECTION_SPELLCHECK:{ + case nsISelectionController::SELECTION_SPELLCHECK:{ aTextStyle.mNormalFont->GetUnderline(offset, size); aRenderingContext.SetColor(NS_RGB(255,0,0)); aRenderingContext.FillRect(aX + startOffset, aY + baseline - offset, textWidth, size); }break; - case SELECTION_IME_SELECTEDRAWTEXT:{ + case nsISelectionController::SELECTION_IME_SELECTEDRAWTEXT:{ #ifdef USE_INVERT_FOR_SELECTION aRenderingContext.SetColor(NS_RGB(255,255,255)); aRenderingContext.InvertRect(aX + startOffset, aY, textWidth, rect.height); @@ -1629,12 +1629,12 @@ nsTextFrame::PaintTextDecorations(nsIRenderingContext& aRenderingContext, aRenderingContext.SetColor(IME_RAW_COLOR); aRenderingContext.FillRect(aX + startOffset+size, aY + baseline - offset, textWidth-2*size, size); }break; - case SELECTION_IME_RAWINPUT:{ + case nsISelectionController::SELECTION_IME_RAWINPUT:{ aTextStyle.mNormalFont->GetUnderline(offset, size); aRenderingContext.SetColor(IME_RAW_COLOR); aRenderingContext.FillRect(aX + startOffset+size, aY + baseline - offset, textWidth-2*size, size); }break; - case SELECTION_IME_SELECTEDCONVERTEDTEXT:{ + case nsISelectionController::SELECTION_IME_SELECTEDCONVERTEDTEXT:{ #ifdef USE_INVERT_FOR_SELECTION aRenderingContext.SetColor(NS_RGB(255,255,255)); aRenderingContext.InvertRect(aX + startOffset, aY, textWidth, rect.height); @@ -1646,7 +1646,7 @@ nsTextFrame::PaintTextDecorations(nsIRenderingContext& aRenderingContext, aRenderingContext.SetColor(IME_CONVERTED_COLOR); aRenderingContext.FillRect(aX + startOffset+size, aY + baseline - offset, textWidth-2*size, size); }break; - case SELECTION_IME_CONVERTEDTEXT:{ + case nsISelectionController::SELECTION_IME_CONVERTEDTEXT:{ aTextStyle.mNormalFont->GetUnderline(offset, size); aRenderingContext.SetColor(IME_CONVERTED_COLOR); aRenderingContext.FillRect(aX + startOffset+size, aY + baseline - offset, textWidth-2*size, size); @@ -3345,9 +3345,10 @@ nsTextFrame::HandleMultiplePress(nsIPresContext* aPresContext, nsMouseEvent *me = (nsMouseEvent *)aEvent; nsCOMPtr shell; - nsresult rv = aPresContext->GetShell(getter_AddRefs(shell)); - + nsCOMPtr selCon = do_QueryInterface(shell); + if (NS_FAILED(rv) || !shell || !selCon) + return rv ?rv:NS_ERROR_FAILURE; if (me->clickCount > 2)//triple clicking { nsCOMPtr mPrefs; @@ -3414,7 +3415,7 @@ nsTextFrame::HandleMultiplePress(nsIPresContext* aPresContext, return rv; nsCOMPtr selection; - if (NS_SUCCEEDED(shell->GetSelection(SELECTION_NORMAL, getter_AddRefs(selection)))){ + if (NS_SUCCEEDED(selCon->GetSelection(nsISelectionController::SELECTION_NORMAL, getter_AddRefs(selection)))){ rv = selection->Collapse(startNode, startOffset); if (NS_FAILED(rv)) return rv; @@ -3474,7 +3475,7 @@ nsTextFrame::HandleMultiplePress(nsIPresContext* aPresContext, return rv; nsCOMPtr selection; - if (NS_SUCCEEDED(shell->GetSelection(SELECTION_NORMAL, getter_AddRefs(selection)))){ + if (NS_SUCCEEDED(selCon->GetSelection(nsISelectionController::SELECTION_NORMAL, getter_AddRefs(selection)))){ rv = selection->Collapse(startNode,startpos.mContentOffset); if (NS_FAILED(rv)) return rv; diff --git a/mozilla/layout/html/base/src/nsFrame.cpp b/mozilla/layout/html/base/src/nsFrame.cpp index 33292094a2f..cca6bf5d4e5 100644 --- a/mozilla/layout/html/base/src/nsFrame.cpp +++ b/mozilla/layout/html/base/src/nsFrame.cpp @@ -981,9 +981,9 @@ nsFrame::HandleMultiplePress(nsIPresContext* aPresContext, return NS_OK; nsCOMPtr shell; nsresult rv = aPresContext->GetShell(getter_AddRefs(shell)); - + nsCOMPtr selcon = do_QueryInterface(shell); - if (NS_SUCCEEDED(rv) && shell) { + if (NS_SUCCEEDED(rv) && shell && selcon) { nsCOMPtr acx; nsCOMPtr tracker; tracker = do_QueryInterface(shell, &rv); @@ -1038,7 +1038,7 @@ nsFrame::HandleMultiplePress(nsIPresContext* aPresContext, return rv; nsCOMPtr selection; - if (NS_SUCCEEDED(shell->GetSelection(SELECTION_NORMAL, getter_AddRefs(selection)))){ + if (NS_SUCCEEDED(selcon->GetSelection(nsISelectionController::SELECTION_NORMAL, getter_AddRefs(selection)))){ rv = selection->Collapse(startNode,startpos.mContentOffset); if (NS_FAILED(rv)) return rv; diff --git a/mozilla/layout/html/base/src/nsPresShell.cpp b/mozilla/layout/html/base/src/nsPresShell.cpp index d7fafc58c51..069247272ac 100644 --- a/mozilla/layout/html/base/src/nsPresShell.cpp +++ b/mozilla/layout/html/base/src/nsPresShell.cpp @@ -19,7 +19,7 @@ * * Contributor(s): */ - + #define PL_ARENA_CONST_ALIGN_MASK 3 #include "nsIPresShell.h" #include "nsISpaceManager.h" @@ -551,6 +551,7 @@ public: NS_IMETHOD GetActiveAlternateStyleSheet(nsString& aSheetTitle); NS_IMETHOD SelectAlternateStyleSheet(const nsString& aSheetTitle); NS_IMETHOD ListAlternateStyleSheets(nsStringArray& aTitleList); + NS_IMETHOD GetSelection(SelectionType aType, nsIDOMSelection** aSelection); NS_IMETHOD ScrollSelectionIntoView(SelectionType aType, SelectionRegion aRegion); NS_IMETHOD RepaintSelection(SelectionType aType); @@ -1378,7 +1379,7 @@ PresShell::EndObservingDocument() if (mSelection){ nsCOMPtr domselection; nsresult result; - result = mSelection->GetSelection(SELECTION_NORMAL, getter_AddRefs(domselection)); + result = mSelection->GetSelection(nsISelectionController::SELECTION_NORMAL, getter_AddRefs(domselection)); if (NS_FAILED(result)) return result; if (!domselection) @@ -2471,7 +2472,7 @@ PresShell::DoCopy() nsresult rv; nsIDOMSelection* sel; - GetSelection(SELECTION_NORMAL, &sel); + GetSelection(nsISelectionController::SELECTION_NORMAL, &sel); if (sel != nsnull) doc->CreateXIF(buffer,sel); @@ -4251,10 +4252,14 @@ PresShellViewEventListener::HideCaret() if (mPresShell && 0 == mCallCount) { - result = mPresShell->GetCaretEnabled(&mWasVisible); + nsCOMPtr selCon = do_QueryInterface(mPresShell); + if (selCon) + { + result = selCon->GetCaretEnabled(&mWasVisible); - if (NS_SUCCEEDED(result) && mWasVisible) - result = mPresShell->SetCaretEnabled(PR_FALSE); + if (NS_SUCCEEDED(result) && mWasVisible) + result = selCon->SetCaretEnabled(PR_FALSE); + } } ++mCallCount; @@ -4270,7 +4275,11 @@ PresShellViewEventListener::RestoreCaretVisibility() --mCallCount; if (mPresShell && 0 == mCallCount && mWasVisible) - result = mPresShell->SetCaretEnabled(PR_TRUE); + { + nsCOMPtr selCon = do_QueryInterface(mPresShell); + if (selCon) + result = selCon->SetCaretEnabled(PR_TRUE); + } return result; } diff --git a/mozilla/layout/html/base/src/nsTextFrame.cpp b/mozilla/layout/html/base/src/nsTextFrame.cpp index 089309f90f5..8e79726652b 100644 --- a/mozilla/layout/html/base/src/nsTextFrame.cpp +++ b/mozilla/layout/html/base/src/nsTextFrame.cpp @@ -781,7 +781,7 @@ inline nscolor EnsureDifferentColors(nscolor colorA, nscolor colorB) class DrawSelectionIterator { enum {DISABLED_COLOR = NS_RGB(176,176,176)}; - enum {SELECTION_TYPES_WE_CARE_ABOUT=SELECTION_NONE+SELECTION_NORMAL}; + enum {SELECTION_TYPES_WE_CARE_ABOUT=nsISelectionController::SELECTION_NONE+nsISelectionController::SELECTION_NORMAL}; public: DrawSelectionIterator(const SelectionDetails *aSelDetails, PRUnichar *aText, PRUint32 aTextLength, nsTextFrame::TextStyle &aTextStyle, @@ -1002,7 +1002,7 @@ DrawSelectionIterator::CurrentForeGroundColor() colorSet = PR_TRUE; } } - else if (mTypes[mCurrentIdx] | SELECTION_NORMAL)//Find color based on mTypes[mCurrentIdx]; + else if (mTypes[mCurrentIdx] | nsISelectionController::SELECTION_NORMAL)//Find color based on mTypes[mCurrentIdx]; { foreColor = mOldStyle.mSelectionTextColor; colorSet = PR_TRUE; @@ -1026,7 +1026,7 @@ DrawSelectionIterator::CurrentBackGroundColor(nscolor &aColor) return PR_TRUE; } } - else if (mTypes[mCurrentIdx] | SELECTION_NORMAL) + else if (mTypes[mCurrentIdx] | nsISelectionController::SELECTION_NORMAL) { aColor = (mSelectionStatus==nsIDocument::SELECTION_ON)?mOldStyle.mSelectionBGColor:mDisabledColor; return PR_TRUE; @@ -1591,7 +1591,7 @@ nsTextFrame::PaintTextDecorations(nsIRenderingContext& aRenderingContext, } switch (aDetails->mType) { - case SELECTION_NORMAL: + case nsISelectionController::SELECTION_NORMAL: #if 0 { //using new selectionpainting now @@ -1612,12 +1612,12 @@ nsTextFrame::PaintTextDecorations(nsIRenderingContext& aRenderingContext, } #endif //0 break; - case SELECTION_SPELLCHECK:{ + case nsISelectionController::SELECTION_SPELLCHECK:{ aTextStyle.mNormalFont->GetUnderline(offset, size); aRenderingContext.SetColor(NS_RGB(255,0,0)); aRenderingContext.FillRect(aX + startOffset, aY + baseline - offset, textWidth, size); }break; - case SELECTION_IME_SELECTEDRAWTEXT:{ + case nsISelectionController::SELECTION_IME_SELECTEDRAWTEXT:{ #ifdef USE_INVERT_FOR_SELECTION aRenderingContext.SetColor(NS_RGB(255,255,255)); aRenderingContext.InvertRect(aX + startOffset, aY, textWidth, rect.height); @@ -1629,12 +1629,12 @@ nsTextFrame::PaintTextDecorations(nsIRenderingContext& aRenderingContext, aRenderingContext.SetColor(IME_RAW_COLOR); aRenderingContext.FillRect(aX + startOffset+size, aY + baseline - offset, textWidth-2*size, size); }break; - case SELECTION_IME_RAWINPUT:{ + case nsISelectionController::SELECTION_IME_RAWINPUT:{ aTextStyle.mNormalFont->GetUnderline(offset, size); aRenderingContext.SetColor(IME_RAW_COLOR); aRenderingContext.FillRect(aX + startOffset+size, aY + baseline - offset, textWidth-2*size, size); }break; - case SELECTION_IME_SELECTEDCONVERTEDTEXT:{ + case nsISelectionController::SELECTION_IME_SELECTEDCONVERTEDTEXT:{ #ifdef USE_INVERT_FOR_SELECTION aRenderingContext.SetColor(NS_RGB(255,255,255)); aRenderingContext.InvertRect(aX + startOffset, aY, textWidth, rect.height); @@ -1646,7 +1646,7 @@ nsTextFrame::PaintTextDecorations(nsIRenderingContext& aRenderingContext, aRenderingContext.SetColor(IME_CONVERTED_COLOR); aRenderingContext.FillRect(aX + startOffset+size, aY + baseline - offset, textWidth-2*size, size); }break; - case SELECTION_IME_CONVERTEDTEXT:{ + case nsISelectionController::SELECTION_IME_CONVERTEDTEXT:{ aTextStyle.mNormalFont->GetUnderline(offset, size); aRenderingContext.SetColor(IME_CONVERTED_COLOR); aRenderingContext.FillRect(aX + startOffset+size, aY + baseline - offset, textWidth-2*size, size); @@ -3345,9 +3345,10 @@ nsTextFrame::HandleMultiplePress(nsIPresContext* aPresContext, nsMouseEvent *me = (nsMouseEvent *)aEvent; nsCOMPtr shell; - nsresult rv = aPresContext->GetShell(getter_AddRefs(shell)); - + nsCOMPtr selCon = do_QueryInterface(shell); + if (NS_FAILED(rv) || !shell || !selCon) + return rv ?rv:NS_ERROR_FAILURE; if (me->clickCount > 2)//triple clicking { nsCOMPtr mPrefs; @@ -3414,7 +3415,7 @@ nsTextFrame::HandleMultiplePress(nsIPresContext* aPresContext, return rv; nsCOMPtr selection; - if (NS_SUCCEEDED(shell->GetSelection(SELECTION_NORMAL, getter_AddRefs(selection)))){ + if (NS_SUCCEEDED(selCon->GetSelection(nsISelectionController::SELECTION_NORMAL, getter_AddRefs(selection)))){ rv = selection->Collapse(startNode, startOffset); if (NS_FAILED(rv)) return rv; @@ -3474,7 +3475,7 @@ nsTextFrame::HandleMultiplePress(nsIPresContext* aPresContext, return rv; nsCOMPtr selection; - if (NS_SUCCEEDED(shell->GetSelection(SELECTION_NORMAL, getter_AddRefs(selection)))){ + if (NS_SUCCEEDED(selCon->GetSelection(nsISelectionController::SELECTION_NORMAL, getter_AddRefs(selection)))){ rv = selection->Collapse(startNode,startpos.mContentOffset); if (NS_FAILED(rv)) return rv; diff --git a/mozilla/layout/html/forms/src/nsGfxTextControlFrame.cpp b/mozilla/layout/html/forms/src/nsGfxTextControlFrame.cpp index fcf7e1b1709..4c24a9767ff 100644 --- a/mozilla/layout/html/forms/src/nsGfxTextControlFrame.cpp +++ b/mozilla/layout/html/forms/src/nsGfxTextControlFrame.cpp @@ -1191,34 +1191,38 @@ nsGfxTextControlFrame::AttributeChanged(nsIPresContext* aPresContext, } else if (mEditor && nsHTMLAtoms::readonly == aAttribute) { - nsCOMPtr presShell; - aPresContext->GetShell(getter_AddRefs(presShell)); + nsCOMPtr selCon; + mEditor->GetSelectionController(getter_AddRefs(selCon)); + nsresult rv = DoesAttributeExist(nsHTMLAtoms::readonly); PRUint32 flags; mEditor->GetFlags(&flags); if (NS_CONTENT_ATTR_NOT_THERE != rv) { // set readonly flags |= nsIHTMLEditor::eEditorReadonlyMask; - presShell->SetCaretEnabled(PR_FALSE); + selCon->SetCaretEnabled(PR_FALSE); } else { // unset readonly flags &= ~(nsIHTMLEditor::eEditorReadonlyMask); - presShell->SetCaretEnabled(PR_TRUE); + selCon->SetCaretEnabled(PR_TRUE); } mEditor->SetFlags(flags); } else if (mEditor && nsHTMLAtoms::disabled == aAttribute) { + nsCOMPtr selCon; + mEditor->GetSelectionController(getter_AddRefs(selCon)); nsCOMPtr presShell; - aPresContext->GetShell(getter_AddRefs(presShell)); + presShell = do_QueryInterface(selCon); + nsresult rv = DoesAttributeExist(nsHTMLAtoms::disabled); PRUint32 flags; mEditor->GetFlags(&flags); if (NS_CONTENT_ATTR_NOT_THERE != rv) { // set readonly flags |= nsIHTMLEditor::eEditorDisabledMask; - presShell->SetCaretEnabled(PR_FALSE); + selCon->SetCaretEnabled(PR_FALSE); nsCOMPtr doc; presShell->GetDocument(getter_AddRefs(doc)); NS_ASSERTION(doc, "null document"); @@ -1228,7 +1232,7 @@ nsGfxTextControlFrame::AttributeChanged(nsIPresContext* aPresContext, else { // unset readonly flags &= ~(nsIHTMLEditor::eEditorDisabledMask); - presShell->SetCaretEnabled(PR_TRUE); + selCon->SetCaretEnabled(PR_TRUE); nsCOMPtr doc; presShell->GetDocument(getter_AddRefs(doc)); NS_ASSERTION(doc, "null document"); @@ -3206,6 +3210,9 @@ nsGfxTextControlFrame::InitializeTextControl(nsIPresShell *aPresShell, nsIDOMDoc nsCOMPtr htmlEditor = do_QueryInterface(mEditor); if (!htmlEditor) { return NS_ERROR_NO_INTERFACE; } + + nsCOMPtr selCon; + selCon = do_QueryInterface(aPresShell); nsCOMPtrpresContext; aPresShell->GetPresContext(getter_AddRefs(presContext)); @@ -3409,13 +3416,15 @@ nsGfxTextControlFrame::InitializeTextControl(nsIPresShell *aPresShell, nsIDOMDoc result = content->GetAttribute(nameSpaceID, nsHTMLAtoms::readonly, resultValue); if (NS_CONTENT_ATTR_NOT_THERE != result) { flags |= nsIHTMLEditor::eEditorReadonlyMask; - aPresShell->SetCaretEnabled(PR_FALSE); + if (selCon) + selCon->SetCaretEnabled(PR_FALSE); } result = content->GetAttribute(nameSpaceID, nsHTMLAtoms::disabled, resultValue); if (NS_CONTENT_ATTR_NOT_THERE != result) { flags |= nsIHTMLEditor::eEditorDisabledMask; - aPresShell->SetCaretEnabled(PR_FALSE); + if (selCon) + selCon->SetCaretEnabled(PR_FALSE); nsCOMPtrdoc = do_QueryInterface(aDoc); if (doc) { doc->SetDisplaySelection(nsIDocument::SELECTION_OFF); diff --git a/mozilla/webshell/src/nsWebShell.cpp b/mozilla/webshell/src/nsWebShell.cpp index 2bfe718c658..e7400b1e255 100644 --- a/mozilla/webshell/src/nsWebShell.cpp +++ b/mozilla/webshell/src/nsWebShell.cpp @@ -1497,9 +1497,12 @@ nsWebShell::SelectAll(void) nsCOMPtr presShell; rv = docViewer->GetPresShell(*getter_AddRefs(presShell)); if (NS_FAILED(rv) || !presShell) return rv; + + nsCOMPtr selCon = do_QueryInterface(presShell); + if (NS_FAILED(rv) || !selCon) return rv; nsCOMPtr selection; - rv = presShell->GetSelection(SELECTION_NORMAL, getter_AddRefs(selection)); + rv = selCon->GetSelection(nsISelectionController::SELECTION_NORMAL, getter_AddRefs(selection)); if (NS_FAILED(rv) || !selection) return rv; // Get the document object