From 1cc1a29d139d715f69e66e138d6d019c7ea1ca18 Mon Sep 17 00:00:00 2001 From: "mjudge%netscape.com" Date: Fri, 28 Apr 2000 06:21:31 +0000 Subject: [PATCH] change to move selection interfaces to nsISelectionController and away from nsIPresShell or nsIDocument git-svn-id: svn://10.0.0.236/trunk@67486 18797224-902f-48f8-a5cc-f745e15eee43 --- mozilla/content/base/public/nsIDocument.h | 4 -- .../base/public/nsISelectionController.idl | 16 ++++- mozilla/content/base/src/nsDocument.cpp | 9 --- mozilla/content/base/src/nsDocument.h | 2 - mozilla/content/base/src/nsDocumentViewer.cpp | 62 +++++++----------- mozilla/content/base/src/nsSelection.cpp | 22 ++++++- mozilla/layout/base/nsDocumentViewer.cpp | 62 +++++++----------- mozilla/layout/base/nsIFrameSelection.h | 6 ++ mozilla/layout/base/nsPresShell.cpp | 16 ++++- mozilla/layout/base/public/nsIDocument.h | 4 -- .../layout/base/public/nsIFrameSelection.h | 6 ++ .../base/public/nsISelectionController.idl | 16 ++++- mozilla/layout/base/src/nsDocument.cpp | 9 --- mozilla/layout/base/src/nsDocument.h | 2 - mozilla/layout/base/src/nsDocumentViewer.cpp | 62 +++++++----------- mozilla/layout/base/src/nsSelection.cpp | 22 ++++++- mozilla/layout/generic/nsFrame.cpp | 29 ++++----- mozilla/layout/generic/nsSelection.cpp | 22 ++++++- mozilla/layout/generic/nsTextFrame.cpp | 63 ++++++++++++++----- mozilla/layout/html/base/src/nsFrame.cpp | 29 ++++----- mozilla/layout/html/base/src/nsPresShell.cpp | 16 ++++- mozilla/layout/html/base/src/nsTextFrame.cpp | 63 ++++++++++++++----- .../html/forms/src/nsGfxTextControlFrame.cpp | 27 ++++---- 23 files changed, 340 insertions(+), 229 deletions(-) diff --git a/mozilla/content/base/public/nsIDocument.h b/mozilla/content/base/public/nsIDocument.h index 9a3af5e0148..b0720f16373 100644 --- a/mozilla/content/base/public/nsIDocument.h +++ b/mozilla/content/base/public/nsIDocument.h @@ -315,10 +315,6 @@ public: virtual nsIContent* GetPrevContent(const nsIContent *aContent) const = 0; virtual nsIContent* GetNextContent(const nsIContent *aContent) const = 0; - enum{SELECTION_OFF = 0, SELECTION_ON = 1, SELECTION_DISABLED = 2 }; - virtual void SetDisplaySelection(PRInt8 aToggle) = 0; - virtual PRInt8 GetDisplaySelection() const = 0; - NS_IMETHOD HandleDOMEvent(nsIPresContext* aPresContext, nsEvent* aEvent, nsIDOMEvent** aDOMEvent, diff --git a/mozilla/content/base/public/nsISelectionController.idl b/mozilla/content/base/public/nsISelectionController.idl index be4b3415341..39a72676eaa 100644 --- a/mozilla/content/base/public/nsISelectionController.idl +++ b/mozilla/content/base/public/nsISelectionController.idl @@ -51,7 +51,21 @@ interface nsISelectionController : nsISupports const short SELECTION_FOCUS_REGION = 1; const short NUM_SELECTION_REGIONS = 2; - /** + const short SELECTION_OFF = 0; + const short SELECTION_ON = 1; + const short SELECTION_DISABLED = 2; + + /** + * SetDisplaySelection will set the display mode for the selection. OFF,ON,DISABLED + */ + void setDisplaySelection(in short toggle); + + /** + * GetDisplaySelection will get the display mode for the selection. OFF,ON,DISABLED + */ + short getDisplaySelection(); + + /** * GetSelection will return the selection that the presentation * shell may implement. * diff --git a/mozilla/content/base/src/nsDocument.cpp b/mozilla/content/base/src/nsDocument.cpp index dd5b17b5ced..36b7f96fc8a 100644 --- a/mozilla/content/base/src/nsDocument.cpp +++ b/mozilla/content/base/src/nsDocument.cpp @@ -3396,13 +3396,4 @@ nsIContent* nsDocument::GetNextContent(const nsIContent *aContent) const return result; } -void nsDocument::SetDisplaySelection(PRInt8 aToggle) -{ - mDisplaySelection = aToggle; -} - -PRInt8 nsDocument::GetDisplaySelection() const -{ - return mDisplaySelection; -} diff --git a/mozilla/content/base/src/nsDocument.h b/mozilla/content/base/src/nsDocument.h index d19c0ed3246..5f9487d6e56 100644 --- a/mozilla/content/base/src/nsDocument.h +++ b/mozilla/content/base/src/nsDocument.h @@ -402,8 +402,6 @@ public: virtual PRBool IsInSelection(nsIDOMSelection* aSelection, const nsIContent *aContent) const; virtual nsIContent* GetPrevContent(const nsIContent *aContent) const; virtual nsIContent* GetNextContent(const nsIContent *aContent) const; - virtual void SetDisplaySelection(PRInt8 aToggle); - virtual PRInt8 GetDisplaySelection() const; // nsIJSScriptObject interface virtual PRBool AddProperty(JSContext *aContext, JSObject *aObj, diff --git a/mozilla/content/base/src/nsDocumentViewer.cpp b/mozilla/content/base/src/nsDocumentViewer.cpp index 95babda7424..780485490ac 100644 --- a/mozilla/content/base/src/nsDocumentViewer.cpp +++ b/mozilla/content/base/src/nsDocumentViewer.cpp @@ -1796,33 +1796,24 @@ nsDocViewerFocusListener::HandleEvent(nsIDOMEvent* aEvent) nsresult nsDocViewerFocusListener::Focus(nsIDOMEvent* aEvent) { - nsCOMPtr doc; + nsCOMPtr shell; if(!mDocViewer) return NS_ERROR_FAILURE; - nsresult result = mDocViewer->GetDocument(*getter_AddRefs(doc));//deref once cause it take a ptr ref - if(NS_FAILED(result) || !doc) + nsresult result = mDocViewer->GetPresShell(*getter_AddRefs(shell));//deref once cause it take a ptr ref + if(NS_FAILED(result) || !shell) return result?result:NS_ERROR_FAILURE; + nsCOMPtr selCon; + selCon = do_QueryInterface(shell); + PRInt16 selectionStatus; + selCon->GetDisplaySelection( &selectionStatus); - PRInt8 selectionStatus; - selectionStatus = doc->GetDisplaySelection(); - - //if selection was nsIDocument::SELECTION_OFF, do nothing + //if selection was nsISelectionController::SELECTION_OFF, do nothing //otherwise re-enable it. - if(selectionStatus == nsIDocument::SELECTION_DISABLED) + if(selectionStatus == nsISelectionController::SELECTION_DISABLED) { - doc->SetDisplaySelection(nsIDocument::SELECTION_ON); - - nsCOMPtr ps; - result = mDocViewer->GetPresShell(*getter_AddRefs(ps)); - if(NS_FAILED(result) || !ps) - return result?result:NS_ERROR_FAILURE; - - nsCOMPtr selcon; - selcon = do_QueryInterface(ps,&result); - if(NS_FAILED(result) || !selcon) - return result?result:NS_ERROR_FAILURE; - selcon->RepaintSelection(nsISelectionController::SELECTION_NORMAL); + selCon->SetDisplaySelection(nsISelectionController::SELECTION_ON); + selCon->RepaintSelection(nsISelectionController::SELECTION_NORMAL); } return result; } @@ -1830,33 +1821,24 @@ nsDocViewerFocusListener::Focus(nsIDOMEvent* aEvent) nsresult nsDocViewerFocusListener::Blur(nsIDOMEvent* aEvent) { - nsCOMPtr doc; + nsCOMPtr shell; if(!mDocViewer) return NS_ERROR_FAILURE; - nsresult result = mDocViewer->GetDocument(*getter_AddRefs(doc));//deref once cause it take a ptr ref - if(NS_FAILED(result) || !doc) + nsresult result = mDocViewer->GetPresShell(*getter_AddRefs(shell));//deref once cause it take a ptr ref + if(NS_FAILED(result) || !shell) return result?result:NS_ERROR_FAILURE; - - PRInt8 selectionStatus; - selectionStatus = doc->GetDisplaySelection(); + nsCOMPtr selCon; + selCon = do_QueryInterface(shell); + PRInt16 selectionStatus; + selCon->GetDisplaySelection(&selectionStatus); - //if selection was nsIDocument::SELECTION_OFF, do nothing + //if selection was nsISelectionController::SELECTION_OFF, do nothing //otherwise re-enable it. - if(selectionStatus == nsIDocument::SELECTION_ON) + if(selectionStatus == nsISelectionController::SELECTION_ON) { - doc->SetDisplaySelection(nsIDocument::SELECTION_DISABLED); - - 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; - - nsCOMPtr selcon; - selcon = do_QueryInterface(ps,&result); - if(NS_FAILED(result) || !selcon) - return result?result:NS_ERROR_FAILURE; - selcon->RepaintSelection(nsISelectionController::SELECTION_NORMAL); + selCon->SetDisplaySelection(nsISelectionController::SELECTION_DISABLED); + selCon->RepaintSelection(nsISelectionController::SELECTION_NORMAL); } return result; } diff --git a/mozilla/content/base/src/nsSelection.cpp b/mozilla/content/base/src/nsSelection.cpp index b0727318d52..3bca1929c52 100644 --- a/mozilla/content/base/src/nsSelection.cpp +++ b/mozilla/content/base/src/nsSelection.cpp @@ -141,6 +141,7 @@ public: NS_IMETHOD ToString(nsString& aReturn); NS_IMETHOD SetHint(PRBool aHintRight); NS_IMETHOD GetHint(PRBool *aHintRight); + /*END nsIDOMSelection interface implementations*/ /*BEGIN nsIScriptObjectOwner interface implementations*/ @@ -277,6 +278,8 @@ public: NS_IMETHOD LineMove(PRBool aForward, PRBool aExtend); NS_IMETHOD IntraLineMove(PRBool aForward, PRBool aExtend); NS_IMETHOD SelectAll(); + NS_IMETHOD SetDisplaySelection(PRInt16 aState); + NS_IMETHOD GetDisplaySelection(PRInt16 *aState); /*END nsIFrameSelection interfacse*/ @@ -290,6 +293,7 @@ public: NS_IMETHOD StartBatchChanges(); NS_IMETHOD EndBatchChanges(); NS_IMETHOD DeleteFromDocument(); + nsIFocusTracker *GetTracker(){return mTracker;} private: NS_IMETHOD TakeFocus(nsIContent *aNewFocus, PRUint32 aContentOffset, PRUint32 aContentEndOffset, @@ -350,6 +354,7 @@ private: nsIFocusTracker *mTracker; PRBool mMouseDownState; //for drag purposes + PRInt8 mDisplaySelection; //for visual display purposes. PRInt32 mDesiredX; PRBool mDesiredXSet; enum HINT {HINTLEFT=0,HINTRIGHT=1}mHint;//end of this line or beginning of next @@ -1508,7 +1513,6 @@ nsDOMSelection::GetHint(PRBool *aHintRight) } - NS_IMETHODIMP nsSelection::HandleClick(nsIContent *aNewFocus, PRUint32 aContentOffset, PRUint32 aContentEndOffset, PRBool aContinueSelection, @@ -2624,6 +2628,22 @@ nsSelection::DeleteFromDocument() } +NS_IMETHODIMP +nsSelection::SetDisplaySelection(PRInt16 aToggle) +{ + mDisplaySelection = aToggle; + return NS_OK; +} + +NS_IMETHODIMP +nsSelection::GetDisplaySelection(PRInt16 *aToggle) +{ + if (!aToggle) + return NS_ERROR_INVALID_ARG; + *aToggle = mDisplaySelection; + return NS_OK; +} + //END nsIDOMSelection interface implementations #ifdef XP_MAC diff --git a/mozilla/layout/base/nsDocumentViewer.cpp b/mozilla/layout/base/nsDocumentViewer.cpp index 95babda7424..780485490ac 100644 --- a/mozilla/layout/base/nsDocumentViewer.cpp +++ b/mozilla/layout/base/nsDocumentViewer.cpp @@ -1796,33 +1796,24 @@ nsDocViewerFocusListener::HandleEvent(nsIDOMEvent* aEvent) nsresult nsDocViewerFocusListener::Focus(nsIDOMEvent* aEvent) { - nsCOMPtr doc; + nsCOMPtr shell; if(!mDocViewer) return NS_ERROR_FAILURE; - nsresult result = mDocViewer->GetDocument(*getter_AddRefs(doc));//deref once cause it take a ptr ref - if(NS_FAILED(result) || !doc) + nsresult result = mDocViewer->GetPresShell(*getter_AddRefs(shell));//deref once cause it take a ptr ref + if(NS_FAILED(result) || !shell) return result?result:NS_ERROR_FAILURE; + nsCOMPtr selCon; + selCon = do_QueryInterface(shell); + PRInt16 selectionStatus; + selCon->GetDisplaySelection( &selectionStatus); - PRInt8 selectionStatus; - selectionStatus = doc->GetDisplaySelection(); - - //if selection was nsIDocument::SELECTION_OFF, do nothing + //if selection was nsISelectionController::SELECTION_OFF, do nothing //otherwise re-enable it. - if(selectionStatus == nsIDocument::SELECTION_DISABLED) + if(selectionStatus == nsISelectionController::SELECTION_DISABLED) { - doc->SetDisplaySelection(nsIDocument::SELECTION_ON); - - nsCOMPtr ps; - result = mDocViewer->GetPresShell(*getter_AddRefs(ps)); - if(NS_FAILED(result) || !ps) - return result?result:NS_ERROR_FAILURE; - - nsCOMPtr selcon; - selcon = do_QueryInterface(ps,&result); - if(NS_FAILED(result) || !selcon) - return result?result:NS_ERROR_FAILURE; - selcon->RepaintSelection(nsISelectionController::SELECTION_NORMAL); + selCon->SetDisplaySelection(nsISelectionController::SELECTION_ON); + selCon->RepaintSelection(nsISelectionController::SELECTION_NORMAL); } return result; } @@ -1830,33 +1821,24 @@ nsDocViewerFocusListener::Focus(nsIDOMEvent* aEvent) nsresult nsDocViewerFocusListener::Blur(nsIDOMEvent* aEvent) { - nsCOMPtr doc; + nsCOMPtr shell; if(!mDocViewer) return NS_ERROR_FAILURE; - nsresult result = mDocViewer->GetDocument(*getter_AddRefs(doc));//deref once cause it take a ptr ref - if(NS_FAILED(result) || !doc) + nsresult result = mDocViewer->GetPresShell(*getter_AddRefs(shell));//deref once cause it take a ptr ref + if(NS_FAILED(result) || !shell) return result?result:NS_ERROR_FAILURE; - - PRInt8 selectionStatus; - selectionStatus = doc->GetDisplaySelection(); + nsCOMPtr selCon; + selCon = do_QueryInterface(shell); + PRInt16 selectionStatus; + selCon->GetDisplaySelection(&selectionStatus); - //if selection was nsIDocument::SELECTION_OFF, do nothing + //if selection was nsISelectionController::SELECTION_OFF, do nothing //otherwise re-enable it. - if(selectionStatus == nsIDocument::SELECTION_ON) + if(selectionStatus == nsISelectionController::SELECTION_ON) { - doc->SetDisplaySelection(nsIDocument::SELECTION_DISABLED); - - 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; - - nsCOMPtr selcon; - selcon = do_QueryInterface(ps,&result); - if(NS_FAILED(result) || !selcon) - return result?result:NS_ERROR_FAILURE; - selcon->RepaintSelection(nsISelectionController::SELECTION_NORMAL); + selCon->SetDisplaySelection(nsISelectionController::SELECTION_DISABLED); + selCon->RepaintSelection(nsISelectionController::SELECTION_NORMAL); } return result; } diff --git a/mozilla/layout/base/nsIFrameSelection.h b/mozilla/layout/base/nsIFrameSelection.h index 0194e705ad8..00b2dca99c0 100644 --- a/mozilla/layout/base/nsIFrameSelection.h +++ b/mozilla/layout/base/nsIFrameSelection.h @@ -294,6 +294,12 @@ public: * it will select the whole doc */ NS_IMETHOD SelectAll()=0; + + /** Sets/Gets The display selection enum. + */ + NS_IMETHOD SetDisplaySelection(PRInt16 aState)=0; + NS_IMETHOD GetDisplaySelection(PRInt16 *aState)=0; + }; diff --git a/mozilla/layout/base/nsPresShell.cpp b/mozilla/layout/base/nsPresShell.cpp index 069247272ac..7ae7db1f7e4 100644 --- a/mozilla/layout/base/nsPresShell.cpp +++ b/mozilla/layout/base/nsPresShell.cpp @@ -552,6 +552,8 @@ public: NS_IMETHOD SelectAlternateStyleSheet(const nsString& aSheetTitle); NS_IMETHOD ListAlternateStyleSheets(nsStringArray& aTitleList); + NS_IMETHOD SetDisplaySelection(PRInt16 aToggle); + NS_IMETHOD GetDisplaySelection(PRInt16 *aToggle); NS_IMETHOD GetSelection(SelectionType aType, nsIDOMSelection** aSelection); NS_IMETHOD ScrollSelectionIntoView(SelectionType aType, SelectionRegion aRegion); NS_IMETHOD RepaintSelection(SelectionType aType); @@ -1110,7 +1112,7 @@ PresShell::Init(nsIDocument* aDocument, result = docShell->GetItemType(&docShellType); if (NS_SUCCEEDED(result)){ if (nsIDocShellTreeItem::typeContent == docShellType){ - mDocument->SetDisplaySelection(nsIDocument::SELECTION_ON); + SetDisplaySelection(nsISelectionController::SELECTION_ON); } } } @@ -1322,6 +1324,18 @@ PresShell::ListAlternateStyleSheets(nsStringArray& aTitleList) return NS_OK; } +NS_IMETHODIMP +PresShell::SetDisplaySelection(PRInt16 aToggle) +{ + return mSelection->SetDisplaySelection(aToggle); +} + +NS_IMETHODIMP +PresShell::GetDisplaySelection(PRInt16 *aToggle) +{ + return mSelection->GetDisplaySelection(aToggle); +} + NS_IMETHODIMP PresShell::GetSelection(SelectionType aType, nsIDOMSelection **aSelection) { diff --git a/mozilla/layout/base/public/nsIDocument.h b/mozilla/layout/base/public/nsIDocument.h index 9a3af5e0148..b0720f16373 100644 --- a/mozilla/layout/base/public/nsIDocument.h +++ b/mozilla/layout/base/public/nsIDocument.h @@ -315,10 +315,6 @@ public: virtual nsIContent* GetPrevContent(const nsIContent *aContent) const = 0; virtual nsIContent* GetNextContent(const nsIContent *aContent) const = 0; - enum{SELECTION_OFF = 0, SELECTION_ON = 1, SELECTION_DISABLED = 2 }; - virtual void SetDisplaySelection(PRInt8 aToggle) = 0; - virtual PRInt8 GetDisplaySelection() const = 0; - NS_IMETHOD HandleDOMEvent(nsIPresContext* aPresContext, nsEvent* aEvent, nsIDOMEvent** aDOMEvent, diff --git a/mozilla/layout/base/public/nsIFrameSelection.h b/mozilla/layout/base/public/nsIFrameSelection.h index 0194e705ad8..00b2dca99c0 100644 --- a/mozilla/layout/base/public/nsIFrameSelection.h +++ b/mozilla/layout/base/public/nsIFrameSelection.h @@ -294,6 +294,12 @@ public: * it will select the whole doc */ NS_IMETHOD SelectAll()=0; + + /** Sets/Gets The display selection enum. + */ + NS_IMETHOD SetDisplaySelection(PRInt16 aState)=0; + NS_IMETHOD GetDisplaySelection(PRInt16 *aState)=0; + }; diff --git a/mozilla/layout/base/public/nsISelectionController.idl b/mozilla/layout/base/public/nsISelectionController.idl index be4b3415341..39a72676eaa 100644 --- a/mozilla/layout/base/public/nsISelectionController.idl +++ b/mozilla/layout/base/public/nsISelectionController.idl @@ -51,7 +51,21 @@ interface nsISelectionController : nsISupports const short SELECTION_FOCUS_REGION = 1; const short NUM_SELECTION_REGIONS = 2; - /** + const short SELECTION_OFF = 0; + const short SELECTION_ON = 1; + const short SELECTION_DISABLED = 2; + + /** + * SetDisplaySelection will set the display mode for the selection. OFF,ON,DISABLED + */ + void setDisplaySelection(in short toggle); + + /** + * GetDisplaySelection will get the display mode for the selection. OFF,ON,DISABLED + */ + short getDisplaySelection(); + + /** * GetSelection will return the selection that the presentation * shell may implement. * diff --git a/mozilla/layout/base/src/nsDocument.cpp b/mozilla/layout/base/src/nsDocument.cpp index dd5b17b5ced..36b7f96fc8a 100644 --- a/mozilla/layout/base/src/nsDocument.cpp +++ b/mozilla/layout/base/src/nsDocument.cpp @@ -3396,13 +3396,4 @@ nsIContent* nsDocument::GetNextContent(const nsIContent *aContent) const return result; } -void nsDocument::SetDisplaySelection(PRInt8 aToggle) -{ - mDisplaySelection = aToggle; -} - -PRInt8 nsDocument::GetDisplaySelection() const -{ - return mDisplaySelection; -} diff --git a/mozilla/layout/base/src/nsDocument.h b/mozilla/layout/base/src/nsDocument.h index d19c0ed3246..5f9487d6e56 100644 --- a/mozilla/layout/base/src/nsDocument.h +++ b/mozilla/layout/base/src/nsDocument.h @@ -402,8 +402,6 @@ public: virtual PRBool IsInSelection(nsIDOMSelection* aSelection, const nsIContent *aContent) const; virtual nsIContent* GetPrevContent(const nsIContent *aContent) const; virtual nsIContent* GetNextContent(const nsIContent *aContent) const; - virtual void SetDisplaySelection(PRInt8 aToggle); - virtual PRInt8 GetDisplaySelection() const; // nsIJSScriptObject interface virtual PRBool AddProperty(JSContext *aContext, JSObject *aObj, diff --git a/mozilla/layout/base/src/nsDocumentViewer.cpp b/mozilla/layout/base/src/nsDocumentViewer.cpp index 95babda7424..780485490ac 100644 --- a/mozilla/layout/base/src/nsDocumentViewer.cpp +++ b/mozilla/layout/base/src/nsDocumentViewer.cpp @@ -1796,33 +1796,24 @@ nsDocViewerFocusListener::HandleEvent(nsIDOMEvent* aEvent) nsresult nsDocViewerFocusListener::Focus(nsIDOMEvent* aEvent) { - nsCOMPtr doc; + nsCOMPtr shell; if(!mDocViewer) return NS_ERROR_FAILURE; - nsresult result = mDocViewer->GetDocument(*getter_AddRefs(doc));//deref once cause it take a ptr ref - if(NS_FAILED(result) || !doc) + nsresult result = mDocViewer->GetPresShell(*getter_AddRefs(shell));//deref once cause it take a ptr ref + if(NS_FAILED(result) || !shell) return result?result:NS_ERROR_FAILURE; + nsCOMPtr selCon; + selCon = do_QueryInterface(shell); + PRInt16 selectionStatus; + selCon->GetDisplaySelection( &selectionStatus); - PRInt8 selectionStatus; - selectionStatus = doc->GetDisplaySelection(); - - //if selection was nsIDocument::SELECTION_OFF, do nothing + //if selection was nsISelectionController::SELECTION_OFF, do nothing //otherwise re-enable it. - if(selectionStatus == nsIDocument::SELECTION_DISABLED) + if(selectionStatus == nsISelectionController::SELECTION_DISABLED) { - doc->SetDisplaySelection(nsIDocument::SELECTION_ON); - - nsCOMPtr ps; - result = mDocViewer->GetPresShell(*getter_AddRefs(ps)); - if(NS_FAILED(result) || !ps) - return result?result:NS_ERROR_FAILURE; - - nsCOMPtr selcon; - selcon = do_QueryInterface(ps,&result); - if(NS_FAILED(result) || !selcon) - return result?result:NS_ERROR_FAILURE; - selcon->RepaintSelection(nsISelectionController::SELECTION_NORMAL); + selCon->SetDisplaySelection(nsISelectionController::SELECTION_ON); + selCon->RepaintSelection(nsISelectionController::SELECTION_NORMAL); } return result; } @@ -1830,33 +1821,24 @@ nsDocViewerFocusListener::Focus(nsIDOMEvent* aEvent) nsresult nsDocViewerFocusListener::Blur(nsIDOMEvent* aEvent) { - nsCOMPtr doc; + nsCOMPtr shell; if(!mDocViewer) return NS_ERROR_FAILURE; - nsresult result = mDocViewer->GetDocument(*getter_AddRefs(doc));//deref once cause it take a ptr ref - if(NS_FAILED(result) || !doc) + nsresult result = mDocViewer->GetPresShell(*getter_AddRefs(shell));//deref once cause it take a ptr ref + if(NS_FAILED(result) || !shell) return result?result:NS_ERROR_FAILURE; - - PRInt8 selectionStatus; - selectionStatus = doc->GetDisplaySelection(); + nsCOMPtr selCon; + selCon = do_QueryInterface(shell); + PRInt16 selectionStatus; + selCon->GetDisplaySelection(&selectionStatus); - //if selection was nsIDocument::SELECTION_OFF, do nothing + //if selection was nsISelectionController::SELECTION_OFF, do nothing //otherwise re-enable it. - if(selectionStatus == nsIDocument::SELECTION_ON) + if(selectionStatus == nsISelectionController::SELECTION_ON) { - doc->SetDisplaySelection(nsIDocument::SELECTION_DISABLED); - - 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; - - nsCOMPtr selcon; - selcon = do_QueryInterface(ps,&result); - if(NS_FAILED(result) || !selcon) - return result?result:NS_ERROR_FAILURE; - selcon->RepaintSelection(nsISelectionController::SELECTION_NORMAL); + selCon->SetDisplaySelection(nsISelectionController::SELECTION_DISABLED); + selCon->RepaintSelection(nsISelectionController::SELECTION_NORMAL); } return result; } diff --git a/mozilla/layout/base/src/nsSelection.cpp b/mozilla/layout/base/src/nsSelection.cpp index b0727318d52..3bca1929c52 100644 --- a/mozilla/layout/base/src/nsSelection.cpp +++ b/mozilla/layout/base/src/nsSelection.cpp @@ -141,6 +141,7 @@ public: NS_IMETHOD ToString(nsString& aReturn); NS_IMETHOD SetHint(PRBool aHintRight); NS_IMETHOD GetHint(PRBool *aHintRight); + /*END nsIDOMSelection interface implementations*/ /*BEGIN nsIScriptObjectOwner interface implementations*/ @@ -277,6 +278,8 @@ public: NS_IMETHOD LineMove(PRBool aForward, PRBool aExtend); NS_IMETHOD IntraLineMove(PRBool aForward, PRBool aExtend); NS_IMETHOD SelectAll(); + NS_IMETHOD SetDisplaySelection(PRInt16 aState); + NS_IMETHOD GetDisplaySelection(PRInt16 *aState); /*END nsIFrameSelection interfacse*/ @@ -290,6 +293,7 @@ public: NS_IMETHOD StartBatchChanges(); NS_IMETHOD EndBatchChanges(); NS_IMETHOD DeleteFromDocument(); + nsIFocusTracker *GetTracker(){return mTracker;} private: NS_IMETHOD TakeFocus(nsIContent *aNewFocus, PRUint32 aContentOffset, PRUint32 aContentEndOffset, @@ -350,6 +354,7 @@ private: nsIFocusTracker *mTracker; PRBool mMouseDownState; //for drag purposes + PRInt8 mDisplaySelection; //for visual display purposes. PRInt32 mDesiredX; PRBool mDesiredXSet; enum HINT {HINTLEFT=0,HINTRIGHT=1}mHint;//end of this line or beginning of next @@ -1508,7 +1513,6 @@ nsDOMSelection::GetHint(PRBool *aHintRight) } - NS_IMETHODIMP nsSelection::HandleClick(nsIContent *aNewFocus, PRUint32 aContentOffset, PRUint32 aContentEndOffset, PRBool aContinueSelection, @@ -2624,6 +2628,22 @@ nsSelection::DeleteFromDocument() } +NS_IMETHODIMP +nsSelection::SetDisplaySelection(PRInt16 aToggle) +{ + mDisplaySelection = aToggle; + return NS_OK; +} + +NS_IMETHODIMP +nsSelection::GetDisplaySelection(PRInt16 *aToggle) +{ + if (!aToggle) + return NS_ERROR_INVALID_ARG; + *aToggle = mDisplaySelection; + return NS_OK; +} + //END nsIDOMSelection interface implementations #ifdef XP_MAC diff --git a/mozilla/layout/generic/nsFrame.cpp b/mozilla/layout/generic/nsFrame.cpp index cca6bf5d4e5..84e8b23010f 100644 --- a/mozilla/layout/generic/nsFrame.cpp +++ b/mozilla/layout/generic/nsFrame.cpp @@ -579,15 +579,15 @@ NS_IMETHODIMP nsFrame::FirstChild(nsIPresContext* aPresContext, PRBool nsFrame::DisplaySelection(nsIPresContext* aPresContext, PRBool isOkToTurnOn) { - PRBool result = PR_FALSE; + PRInt16 result = PR_FALSE; nsCOMPtr shell; nsresult rv = aPresContext->GetShell(getter_AddRefs(shell)); if (NS_SUCCEEDED(rv) && shell) { - nsCOMPtr doc; - rv = shell->GetDocument(getter_AddRefs(doc)); - if (NS_SUCCEEDED(rv) && doc) { - result = doc->GetDisplaySelection(); + nsCOMPtr selCon; + selCon = do_QueryInterface(shell, &rv); + if (NS_SUCCEEDED(rv) && selCon) { + selCon->GetDisplaySelection(&result); if (result) { // check whether style allows selection const nsStyleUserInterface* userinterface; @@ -606,7 +606,7 @@ nsFrame::DisplaySelection(nsIPresContext* aPresContext, PRBool isOkToTurnOn) } } if (isOkToTurnOn && !result) { - doc->SetDisplaySelection(nsIDocument::SELECTION_ON); + selCon->SetDisplaySelection(nsISelectionController::SELECTION_ON); result = PR_TRUE; } } @@ -658,22 +658,23 @@ nsFrame::Paint(nsIPresContext* aPresContext, if (NS_FAILED(result)) return result; - PRBool displaySelection = PR_TRUE; - result = shell->GetDisplayNonTextSelection(&displaySelection); + PRBool displyNonTextSelection = PR_TRUE; + result = shell->GetDisplayNonTextSelection(&displyNonTextSelection); if (NS_FAILED(result)) return result; + PRInt16 displaySelection = displyNonTextSelection; if (!displaySelection) return NS_OK; if (mContent) { result = mContent->GetDocument(*getter_AddRefs(doc)); } - if (!doc || NS_FAILED(result)) { - if (NS_SUCCEEDED(result) && shell) { - result = shell->GetDocument(getter_AddRefs(doc)); - } - } - displaySelection = doc->GetDisplaySelection(); + nsCOMPtr selCon; + selCon = do_QueryInterface(shell, &result); + if (NS_FAILED(result) || !selCon) + return result? result:NS_ERROR_FAILURE; + + selCon->GetDisplaySelection(&displaySelection); nsFrameState frameState; PRBool isSelected; GetFrameState(&frameState); diff --git a/mozilla/layout/generic/nsSelection.cpp b/mozilla/layout/generic/nsSelection.cpp index b0727318d52..3bca1929c52 100644 --- a/mozilla/layout/generic/nsSelection.cpp +++ b/mozilla/layout/generic/nsSelection.cpp @@ -141,6 +141,7 @@ public: NS_IMETHOD ToString(nsString& aReturn); NS_IMETHOD SetHint(PRBool aHintRight); NS_IMETHOD GetHint(PRBool *aHintRight); + /*END nsIDOMSelection interface implementations*/ /*BEGIN nsIScriptObjectOwner interface implementations*/ @@ -277,6 +278,8 @@ public: NS_IMETHOD LineMove(PRBool aForward, PRBool aExtend); NS_IMETHOD IntraLineMove(PRBool aForward, PRBool aExtend); NS_IMETHOD SelectAll(); + NS_IMETHOD SetDisplaySelection(PRInt16 aState); + NS_IMETHOD GetDisplaySelection(PRInt16 *aState); /*END nsIFrameSelection interfacse*/ @@ -290,6 +293,7 @@ public: NS_IMETHOD StartBatchChanges(); NS_IMETHOD EndBatchChanges(); NS_IMETHOD DeleteFromDocument(); + nsIFocusTracker *GetTracker(){return mTracker;} private: NS_IMETHOD TakeFocus(nsIContent *aNewFocus, PRUint32 aContentOffset, PRUint32 aContentEndOffset, @@ -350,6 +354,7 @@ private: nsIFocusTracker *mTracker; PRBool mMouseDownState; //for drag purposes + PRInt8 mDisplaySelection; //for visual display purposes. PRInt32 mDesiredX; PRBool mDesiredXSet; enum HINT {HINTLEFT=0,HINTRIGHT=1}mHint;//end of this line or beginning of next @@ -1508,7 +1513,6 @@ nsDOMSelection::GetHint(PRBool *aHintRight) } - NS_IMETHODIMP nsSelection::HandleClick(nsIContent *aNewFocus, PRUint32 aContentOffset, PRUint32 aContentEndOffset, PRBool aContinueSelection, @@ -2624,6 +2628,22 @@ nsSelection::DeleteFromDocument() } +NS_IMETHODIMP +nsSelection::SetDisplaySelection(PRInt16 aToggle) +{ + mDisplaySelection = aToggle; + return NS_OK; +} + +NS_IMETHODIMP +nsSelection::GetDisplaySelection(PRInt16 *aToggle) +{ + if (!aToggle) + return NS_ERROR_INVALID_ARG; + *aToggle = mDisplaySelection; + return NS_OK; +} + //END nsIDOMSelection interface implementations #ifdef XP_MAC diff --git a/mozilla/layout/generic/nsTextFrame.cpp b/mozilla/layout/generic/nsTextFrame.cpp index 8e79726652b..c276fc658cb 100644 --- a/mozilla/layout/generic/nsTextFrame.cpp +++ b/mozilla/layout/generic/nsTextFrame.cpp @@ -785,7 +785,7 @@ class DrawSelectionIterator public: DrawSelectionIterator(const SelectionDetails *aSelDetails, PRUnichar *aText, PRUint32 aTextLength, nsTextFrame::TextStyle &aTextStyle, - PRInt8 aSelectionStatus); + PRInt16 aSelectionStatus); ~DrawSelectionIterator(); PRBool First(); PRBool Next(); @@ -810,14 +810,14 @@ private: PRBool mDone; PRUint8 * mTypes; PRBool mInit; - PRInt8 mSelectionStatus;//see nsIDocument.h SetDisplaySelection() + PRInt16 mSelectionStatus;//see nsIDocument.h SetDisplaySelection() nscolor mDisabledColor; //private methods void FillCurrentData(); }; DrawSelectionIterator::DrawSelectionIterator(const SelectionDetails *aSelDetails, PRUnichar *aText, - PRUint32 aTextLength, nsTextFrame::TextStyle &aTextStyle, PRInt8 aSelectionStatus) + PRUint32 aTextLength, nsTextFrame::TextStyle &aTextStyle, PRInt16 aSelectionStatus) :mOldStyle(aTextStyle) { mDetails = aSelDetails; @@ -1022,13 +1022,13 @@ DrawSelectionIterator::CurrentBackGroundColor(nscolor &aColor) { if (mCurrentIdx == (PRUint32)mDetails->mStart) { - aColor = (mSelectionStatus==nsIDocument::SELECTION_ON)?mOldStyle.mSelectionBGColor:mDisabledColor; + aColor = (mSelectionStatus==nsISelectionController::SELECTION_ON)?mOldStyle.mSelectionBGColor:mDisabledColor; return PR_TRUE; } } else if (mTypes[mCurrentIdx] | nsISelectionController::SELECTION_NORMAL) { - aColor = (mSelectionStatus==nsIDocument::SELECTION_ON)?mOldStyle.mSelectionBGColor:mDisabledColor; + aColor = (mSelectionStatus==nsISelectionController::SELECTION_ON)?mOldStyle.mSelectionBGColor:mDisabledColor; return PR_TRUE; } return PR_FALSE; @@ -1734,10 +1734,17 @@ nsTextFrame::PaintUnicodeText(nsIPresContext* aPresContext, TextStyle& aTextStyle, nscoord dx, nscoord dy) { - nsCOMPtr doc(getter_AddRefs(GetDocument(aPresContext))); + nsCOMPtr shell; + nsresult rv = aPresContext->GetShell(getter_AddRefs(shell)); + if (NS_FAILED(rv) || !shell) + return; + nsCOMPtr selCon; + selCon = do_QueryInterface(shell, &rv); + if (NS_FAILED(rv) || !selCon) + return; - PRInt8 displaySelection; - displaySelection = doc->GetDisplaySelection(); + PRInt16 displaySelection; + selCon->GetDisplaySelection(&displaySelection); // Make enough space to transform nsAutoTextBuffer paintBuffer; @@ -1754,6 +1761,10 @@ nsTextFrame::PaintUnicodeText(nsIPresContext* aPresContext, // transformed when we formatted it, then there's no need to do all // this and we should just render the text fragment directly. See // PaintAsciiText()... + nsCOMPtr doc; + shell->GetDocument(getter_AddRefs(doc)); + if (!doc) + return; nsCOMPtr lb; doc->GetLineBreaker(getter_AddRefs(lb)); nsTextTransformer tx(lb, nsnull); @@ -2241,10 +2252,18 @@ nsTextFrame::PaintTextSlowly(nsIPresContext* aPresContext, TextStyle& aTextStyle, nscoord dx, nscoord dy) { - nsCOMPtr doc(getter_AddRefs(GetDocument(aPresContext))); + nsCOMPtr shell; + nsresult rv = aPresContext->GetShell(getter_AddRefs(shell)); + if (NS_FAILED(rv) || !shell) + return; + nsCOMPtr selCon; + selCon = do_QueryInterface(shell, &rv); + if (NS_FAILED(rv) || !selCon) + return; + + PRInt16 displaySelection; + selCon->GetDisplaySelection(&displaySelection); - PRBool displaySelection; - displaySelection = doc->GetDisplaySelection(); // Make enough space to transform nsAutoTextBuffer paintBuffer; @@ -2256,6 +2275,10 @@ nsTextFrame::PaintTextSlowly(nsIPresContext* aPresContext, PRInt32 textLength; // Transform text from content into renderable form + nsCOMPtr doc; + shell->GetDocument(getter_AddRefs(doc)); + if (!doc) + return; nsCOMPtr lb; doc->GetLineBreaker(getter_AddRefs(lb)); nsTextTransformer tx(lb, nsnull); @@ -2368,11 +2391,19 @@ nsTextFrame::PaintAsciiText(nsIPresContext* aPresContext, nscoord dx, nscoord dy) { NS_PRECONDITION(0 == (TEXT_HAS_MULTIBYTE & mState), "text is multi-byte"); - nsCOMPtr doc(getter_AddRefs(GetDocument(aPresContext))); + nsCOMPtr shell; + nsresult rv = aPresContext->GetShell(getter_AddRefs(shell)); + if (NS_FAILED(rv) || !shell) + return; + nsCOMPtr selCon; + selCon = do_QueryInterface(shell, &rv); + if (NS_FAILED(rv) || !selCon) + return; - PRBool displaySelection; + PRInt16 displaySelection; PRBool isSelected; - displaySelection = doc->GetDisplaySelection(); + selCon->GetDisplaySelection(&displaySelection); + isSelected = (mState & NS_FRAME_SELECTED_CONTENT) == NS_FRAME_SELECTED_CONTENT; // Get the text fragment @@ -2395,6 +2426,10 @@ nsTextFrame::PaintAsciiText(nsIPresContext* aPresContext, } // Construct a text transformer + nsCOMPtr doc; + shell->GetDocument(getter_AddRefs(doc)); + if (!doc) + return; nsCOMPtr lb; doc->GetLineBreaker(getter_AddRefs(lb)); nsTextTransformer tx(lb, nsnull); diff --git a/mozilla/layout/html/base/src/nsFrame.cpp b/mozilla/layout/html/base/src/nsFrame.cpp index cca6bf5d4e5..84e8b23010f 100644 --- a/mozilla/layout/html/base/src/nsFrame.cpp +++ b/mozilla/layout/html/base/src/nsFrame.cpp @@ -579,15 +579,15 @@ NS_IMETHODIMP nsFrame::FirstChild(nsIPresContext* aPresContext, PRBool nsFrame::DisplaySelection(nsIPresContext* aPresContext, PRBool isOkToTurnOn) { - PRBool result = PR_FALSE; + PRInt16 result = PR_FALSE; nsCOMPtr shell; nsresult rv = aPresContext->GetShell(getter_AddRefs(shell)); if (NS_SUCCEEDED(rv) && shell) { - nsCOMPtr doc; - rv = shell->GetDocument(getter_AddRefs(doc)); - if (NS_SUCCEEDED(rv) && doc) { - result = doc->GetDisplaySelection(); + nsCOMPtr selCon; + selCon = do_QueryInterface(shell, &rv); + if (NS_SUCCEEDED(rv) && selCon) { + selCon->GetDisplaySelection(&result); if (result) { // check whether style allows selection const nsStyleUserInterface* userinterface; @@ -606,7 +606,7 @@ nsFrame::DisplaySelection(nsIPresContext* aPresContext, PRBool isOkToTurnOn) } } if (isOkToTurnOn && !result) { - doc->SetDisplaySelection(nsIDocument::SELECTION_ON); + selCon->SetDisplaySelection(nsISelectionController::SELECTION_ON); result = PR_TRUE; } } @@ -658,22 +658,23 @@ nsFrame::Paint(nsIPresContext* aPresContext, if (NS_FAILED(result)) return result; - PRBool displaySelection = PR_TRUE; - result = shell->GetDisplayNonTextSelection(&displaySelection); + PRBool displyNonTextSelection = PR_TRUE; + result = shell->GetDisplayNonTextSelection(&displyNonTextSelection); if (NS_FAILED(result)) return result; + PRInt16 displaySelection = displyNonTextSelection; if (!displaySelection) return NS_OK; if (mContent) { result = mContent->GetDocument(*getter_AddRefs(doc)); } - if (!doc || NS_FAILED(result)) { - if (NS_SUCCEEDED(result) && shell) { - result = shell->GetDocument(getter_AddRefs(doc)); - } - } - displaySelection = doc->GetDisplaySelection(); + nsCOMPtr selCon; + selCon = do_QueryInterface(shell, &result); + if (NS_FAILED(result) || !selCon) + return result? result:NS_ERROR_FAILURE; + + selCon->GetDisplaySelection(&displaySelection); nsFrameState frameState; PRBool isSelected; GetFrameState(&frameState); diff --git a/mozilla/layout/html/base/src/nsPresShell.cpp b/mozilla/layout/html/base/src/nsPresShell.cpp index 069247272ac..7ae7db1f7e4 100644 --- a/mozilla/layout/html/base/src/nsPresShell.cpp +++ b/mozilla/layout/html/base/src/nsPresShell.cpp @@ -552,6 +552,8 @@ public: NS_IMETHOD SelectAlternateStyleSheet(const nsString& aSheetTitle); NS_IMETHOD ListAlternateStyleSheets(nsStringArray& aTitleList); + NS_IMETHOD SetDisplaySelection(PRInt16 aToggle); + NS_IMETHOD GetDisplaySelection(PRInt16 *aToggle); NS_IMETHOD GetSelection(SelectionType aType, nsIDOMSelection** aSelection); NS_IMETHOD ScrollSelectionIntoView(SelectionType aType, SelectionRegion aRegion); NS_IMETHOD RepaintSelection(SelectionType aType); @@ -1110,7 +1112,7 @@ PresShell::Init(nsIDocument* aDocument, result = docShell->GetItemType(&docShellType); if (NS_SUCCEEDED(result)){ if (nsIDocShellTreeItem::typeContent == docShellType){ - mDocument->SetDisplaySelection(nsIDocument::SELECTION_ON); + SetDisplaySelection(nsISelectionController::SELECTION_ON); } } } @@ -1322,6 +1324,18 @@ PresShell::ListAlternateStyleSheets(nsStringArray& aTitleList) return NS_OK; } +NS_IMETHODIMP +PresShell::SetDisplaySelection(PRInt16 aToggle) +{ + return mSelection->SetDisplaySelection(aToggle); +} + +NS_IMETHODIMP +PresShell::GetDisplaySelection(PRInt16 *aToggle) +{ + return mSelection->GetDisplaySelection(aToggle); +} + NS_IMETHODIMP PresShell::GetSelection(SelectionType aType, nsIDOMSelection **aSelection) { diff --git a/mozilla/layout/html/base/src/nsTextFrame.cpp b/mozilla/layout/html/base/src/nsTextFrame.cpp index 8e79726652b..c276fc658cb 100644 --- a/mozilla/layout/html/base/src/nsTextFrame.cpp +++ b/mozilla/layout/html/base/src/nsTextFrame.cpp @@ -785,7 +785,7 @@ class DrawSelectionIterator public: DrawSelectionIterator(const SelectionDetails *aSelDetails, PRUnichar *aText, PRUint32 aTextLength, nsTextFrame::TextStyle &aTextStyle, - PRInt8 aSelectionStatus); + PRInt16 aSelectionStatus); ~DrawSelectionIterator(); PRBool First(); PRBool Next(); @@ -810,14 +810,14 @@ private: PRBool mDone; PRUint8 * mTypes; PRBool mInit; - PRInt8 mSelectionStatus;//see nsIDocument.h SetDisplaySelection() + PRInt16 mSelectionStatus;//see nsIDocument.h SetDisplaySelection() nscolor mDisabledColor; //private methods void FillCurrentData(); }; DrawSelectionIterator::DrawSelectionIterator(const SelectionDetails *aSelDetails, PRUnichar *aText, - PRUint32 aTextLength, nsTextFrame::TextStyle &aTextStyle, PRInt8 aSelectionStatus) + PRUint32 aTextLength, nsTextFrame::TextStyle &aTextStyle, PRInt16 aSelectionStatus) :mOldStyle(aTextStyle) { mDetails = aSelDetails; @@ -1022,13 +1022,13 @@ DrawSelectionIterator::CurrentBackGroundColor(nscolor &aColor) { if (mCurrentIdx == (PRUint32)mDetails->mStart) { - aColor = (mSelectionStatus==nsIDocument::SELECTION_ON)?mOldStyle.mSelectionBGColor:mDisabledColor; + aColor = (mSelectionStatus==nsISelectionController::SELECTION_ON)?mOldStyle.mSelectionBGColor:mDisabledColor; return PR_TRUE; } } else if (mTypes[mCurrentIdx] | nsISelectionController::SELECTION_NORMAL) { - aColor = (mSelectionStatus==nsIDocument::SELECTION_ON)?mOldStyle.mSelectionBGColor:mDisabledColor; + aColor = (mSelectionStatus==nsISelectionController::SELECTION_ON)?mOldStyle.mSelectionBGColor:mDisabledColor; return PR_TRUE; } return PR_FALSE; @@ -1734,10 +1734,17 @@ nsTextFrame::PaintUnicodeText(nsIPresContext* aPresContext, TextStyle& aTextStyle, nscoord dx, nscoord dy) { - nsCOMPtr doc(getter_AddRefs(GetDocument(aPresContext))); + nsCOMPtr shell; + nsresult rv = aPresContext->GetShell(getter_AddRefs(shell)); + if (NS_FAILED(rv) || !shell) + return; + nsCOMPtr selCon; + selCon = do_QueryInterface(shell, &rv); + if (NS_FAILED(rv) || !selCon) + return; - PRInt8 displaySelection; - displaySelection = doc->GetDisplaySelection(); + PRInt16 displaySelection; + selCon->GetDisplaySelection(&displaySelection); // Make enough space to transform nsAutoTextBuffer paintBuffer; @@ -1754,6 +1761,10 @@ nsTextFrame::PaintUnicodeText(nsIPresContext* aPresContext, // transformed when we formatted it, then there's no need to do all // this and we should just render the text fragment directly. See // PaintAsciiText()... + nsCOMPtr doc; + shell->GetDocument(getter_AddRefs(doc)); + if (!doc) + return; nsCOMPtr lb; doc->GetLineBreaker(getter_AddRefs(lb)); nsTextTransformer tx(lb, nsnull); @@ -2241,10 +2252,18 @@ nsTextFrame::PaintTextSlowly(nsIPresContext* aPresContext, TextStyle& aTextStyle, nscoord dx, nscoord dy) { - nsCOMPtr doc(getter_AddRefs(GetDocument(aPresContext))); + nsCOMPtr shell; + nsresult rv = aPresContext->GetShell(getter_AddRefs(shell)); + if (NS_FAILED(rv) || !shell) + return; + nsCOMPtr selCon; + selCon = do_QueryInterface(shell, &rv); + if (NS_FAILED(rv) || !selCon) + return; + + PRInt16 displaySelection; + selCon->GetDisplaySelection(&displaySelection); - PRBool displaySelection; - displaySelection = doc->GetDisplaySelection(); // Make enough space to transform nsAutoTextBuffer paintBuffer; @@ -2256,6 +2275,10 @@ nsTextFrame::PaintTextSlowly(nsIPresContext* aPresContext, PRInt32 textLength; // Transform text from content into renderable form + nsCOMPtr doc; + shell->GetDocument(getter_AddRefs(doc)); + if (!doc) + return; nsCOMPtr lb; doc->GetLineBreaker(getter_AddRefs(lb)); nsTextTransformer tx(lb, nsnull); @@ -2368,11 +2391,19 @@ nsTextFrame::PaintAsciiText(nsIPresContext* aPresContext, nscoord dx, nscoord dy) { NS_PRECONDITION(0 == (TEXT_HAS_MULTIBYTE & mState), "text is multi-byte"); - nsCOMPtr doc(getter_AddRefs(GetDocument(aPresContext))); + nsCOMPtr shell; + nsresult rv = aPresContext->GetShell(getter_AddRefs(shell)); + if (NS_FAILED(rv) || !shell) + return; + nsCOMPtr selCon; + selCon = do_QueryInterface(shell, &rv); + if (NS_FAILED(rv) || !selCon) + return; - PRBool displaySelection; + PRInt16 displaySelection; PRBool isSelected; - displaySelection = doc->GetDisplaySelection(); + selCon->GetDisplaySelection(&displaySelection); + isSelected = (mState & NS_FRAME_SELECTED_CONTENT) == NS_FRAME_SELECTED_CONTENT; // Get the text fragment @@ -2395,6 +2426,10 @@ nsTextFrame::PaintAsciiText(nsIPresContext* aPresContext, } // Construct a text transformer + nsCOMPtr doc; + shell->GetDocument(getter_AddRefs(doc)); + if (!doc) + return; nsCOMPtr lb; doc->GetLineBreaker(getter_AddRefs(lb)); nsTextTransformer tx(lb, nsnull); diff --git a/mozilla/layout/html/forms/src/nsGfxTextControlFrame.cpp b/mozilla/layout/html/forms/src/nsGfxTextControlFrame.cpp index 4c24a9767ff..fbed2faee04 100644 --- a/mozilla/layout/html/forms/src/nsGfxTextControlFrame.cpp +++ b/mozilla/layout/html/forms/src/nsGfxTextControlFrame.cpp @@ -1200,12 +1200,14 @@ nsGfxTextControlFrame::AttributeChanged(nsIPresContext* aPresContext, if (NS_CONTENT_ATTR_NOT_THERE != rv) { // set readonly flags |= nsIHTMLEditor::eEditorReadonlyMask; - selCon->SetCaretEnabled(PR_FALSE); + if (selCon) + selCon->SetCaretEnabled(PR_FALSE); } else { // unset readonly flags &= ~(nsIHTMLEditor::eEditorReadonlyMask); - selCon->SetCaretEnabled(PR_TRUE); + if (selCon) + selCon->SetCaretEnabled(PR_TRUE); } mEditor->SetFlags(flags); } @@ -1223,21 +1225,13 @@ nsGfxTextControlFrame::AttributeChanged(nsIPresContext* aPresContext, { // set readonly flags |= nsIHTMLEditor::eEditorDisabledMask; selCon->SetCaretEnabled(PR_FALSE); - nsCOMPtr doc; - presShell->GetDocument(getter_AddRefs(doc)); - NS_ASSERTION(doc, "null document"); - if (!doc) { return NS_ERROR_NULL_POINTER; } - doc->SetDisplaySelection(nsIDocument::SELECTION_OFF); + selCon->SetDisplaySelection(nsISelectionController::SELECTION_OFF); } else { // unset readonly flags &= ~(nsIHTMLEditor::eEditorDisabledMask); selCon->SetCaretEnabled(PR_TRUE); - nsCOMPtr doc; - presShell->GetDocument(getter_AddRefs(doc)); - NS_ASSERTION(doc, "null document"); - if (!doc) { return NS_ERROR_NULL_POINTER; } - doc->SetDisplaySelection(nsIDocument::SELECTION_ON); + selCon->SetDisplaySelection(nsISelectionController::SELECTION_ON); } mEditor->SetFlags(flags); } @@ -3004,7 +2998,9 @@ nsGfxTextControlFrame::InstallEditor() editorFlags |= nsIHTMLEditor::eEditorPasswordMask; // initialize the editor - result = mEditor->Init(mDoc, presShell, editorFlags); + nsCOMPtr selCon; + selCon = do_QueryInterface(presShell); + result = mEditor->Init(mDoc, presShell,selCon, editorFlags); if (NS_FAILED(result)) { return result; } nsCOMPtr framePresShell; @@ -3424,10 +3420,9 @@ nsGfxTextControlFrame::InitializeTextControl(nsIPresShell *aPresShell, nsIDOMDoc { flags |= nsIHTMLEditor::eEditorDisabledMask; if (selCon) + { selCon->SetCaretEnabled(PR_FALSE); - nsCOMPtrdoc = do_QueryInterface(aDoc); - if (doc) { - doc->SetDisplaySelection(nsIDocument::SELECTION_OFF); + selCon->SetDisplaySelection(nsISelectionController::SELECTION_OFF); } } }