diff --git a/mozilla/content/base/public/nsISelectionController.idl b/mozilla/content/base/public/nsISelectionController.idl index 367d35cae93..0d02393dcf0 100644 --- a/mozilla/content/base/public/nsISelectionController.idl +++ b/mozilla/content/base/public/nsISelectionController.idl @@ -52,8 +52,9 @@ interface nsISelectionController : nsISupports const short NUM_SELECTION_REGIONS = 2; const short SELECTION_OFF = 0; - const short SELECTION_ON = 1; - const short SELECTION_DISABLED = 2; + const short SELECTION_HIDDEN =1;//>HIDDEN displays selection + const short SELECTION_ON = 2; + const short SELECTION_DISABLED = 3; /** * SetDisplaySelection will set the display mode for the selection. OFF,ON,DISABLED @@ -98,6 +99,14 @@ interface nsISelectionController : nsISupports */ void setCaretEnabled(in boolean enabled); + /** + * Set the caret readonly or not. An readonly caret will + * draw but not blink when made visible. + * @param aReadOnly PR_TRUE to enable caret. PR_FALSE to disable. + * @return always NS_OK + */ + void setCaretReadOnly(in boolean readOnly); + /** * Gets the current state of the caret. * @param aEnabled [OUT] set to the current caret state, as set by SetCaretEnabled @@ -113,7 +122,7 @@ interface nsISelectionController : nsISupports * @param aForward forward or backward if PR_FALSE * @param aExtend should it collapse the selection of extend it? */ - void characterMove(in boolean aForward, in boolean aExtend); + void characterMove(in boolean forward, in boolean extend); /** WordMove will move the selection one word forward/backward in the document. * this will also have the effect of collapsing the selection if the aExtend = PR_FALSE @@ -123,7 +132,7 @@ interface nsISelectionController : nsISupports * @param aExtend should it collapse the selection of extend it? */ - void wordMove(in boolean aForward, in boolean aExtend); + void wordMove(in boolean forward, in boolean extend); /** LineMove will move the selection one line forward/backward in the document. * this will also have the effect of collapsing the selection if the aExtend = PR_FALSE @@ -132,7 +141,7 @@ interface nsISelectionController : nsISupports * @param aForward forward or backward if PR_FALSE * @param aExtend should it collapse the selection of extend it? */ - void lineMove(in boolean aForward, in boolean aExtend); + void lineMove(in boolean forward, in boolean extend); /** IntraLineMove will move the selection to the front of the line or end of the line * in the document. @@ -142,7 +151,7 @@ interface nsISelectionController : nsISupports * @param aForward forward or backward if PR_FALSE * @param aExtend should it collapse the selection of extend it? */ - void intraLineMove(in boolean aForward, in boolean aExtend); + void intraLineMove(in boolean forward, in boolean extend); /** PageMove will move the selection one page forward/backward in the document. * this will also have the effect of collapsing the selection if the aExtend = PR_FALSE @@ -151,12 +160,12 @@ interface nsISelectionController : nsISupports * @param aForward forward or backward if PR_FALSE * @param aExtend should it collapse the selection of extend it? */ - void pageMove(in boolean aForward, in boolean aExtend); + void pageMove(in boolean forward, in boolean extend); /** CompleteScroll will move page view to the top or bottom of the document * @param aForward forward or backward if PR_FALSE */ - void completeScroll(in boolean aForward); + void completeScroll(in boolean forward); /** CompleteMove will move page view to the top or bottom of the document * this will also have the effect of collapsing the selection if the aExtend = PR_FALSE @@ -165,23 +174,23 @@ interface nsISelectionController : nsISupports * @param aForward forward or backward if PR_FALSE * @param aExtend should it collapse the selection of extend it? */ - void completeMove(in boolean aForward, in boolean aExtend); + void completeMove(in boolean forward, in boolean extend); /** ScrollPage will scroll the page without affecting the selection. * @param aForward scroll forward or backwards in selection */ - void scrollPage(in boolean aForward); + void scrollPage(in boolean forward); /** ScrolLine will scroll line up or down dependent on the boolean * @param aForward scroll forward or backwards in selection */ - void scrollLine(in boolean aForward); + void scrollLine(in boolean forward); /** ScrolHorizontal will scroll left or right dependent on the boolean * @param aLeft if true will scroll left. if not will scroll right. */ - void scrollHorizontal(in boolean aLeft); + void scrollHorizontal(in boolean left); /** SelectAll will select the whole page */ void selectAll(); diff --git a/mozilla/content/base/src/nsDocumentViewer.cpp b/mozilla/content/base/src/nsDocumentViewer.cpp index 8860bfc5eb7..3d39492ad28 100644 --- a/mozilla/content/base/src/nsDocumentViewer.cpp +++ b/mozilla/content/base/src/nsDocumentViewer.cpp @@ -1831,7 +1831,7 @@ nsDocViewerFocusListener::Focus(nsIDOMEvent* aEvent) selCon->GetDisplaySelection( &selectionStatus); //if selection was nsISelectionController::SELECTION_OFF, do nothing - //otherwise re-enable it. + //otherwise re-enable it. if(selectionStatus == nsISelectionController::SELECTION_DISABLED) { selCon->SetDisplaySelection(nsISelectionController::SELECTION_ON); @@ -1839,12 +1839,12 @@ nsDocViewerFocusListener::Focus(nsIDOMEvent* aEvent) } return result; } - + nsresult nsDocViewerFocusListener::Blur(nsIDOMEvent* aEvent) { nsCOMPtr shell; - if(!mDocViewer) + if(!mDocViewer) return NS_ERROR_FAILURE; nsresult result = mDocViewer->GetPresShell(*getter_AddRefs(shell));//deref once cause it take a ptr ref diff --git a/mozilla/content/base/src/nsSelection.cpp b/mozilla/content/base/src/nsSelection.cpp index 3ba42a56132..10c49850732 100644 --- a/mozilla/content/base/src/nsSelection.cpp +++ b/mozilla/content/base/src/nsSelection.cpp @@ -111,6 +111,7 @@ class nsAutoScrollTimer; class nsDOMSelection : public nsIDOMSelection , public nsIScriptObjectOwner, public nsSupportsWeakReference { public: + nsDOMSelection(); nsDOMSelection(nsSelection *aList); virtual ~nsDOMSelection(); @@ -523,15 +524,21 @@ nsresult NS_NewSelection(nsIFrameSelection **aFrameSelection) if (!rlist) return NS_ERROR_OUT_OF_MEMORY; *aFrameSelection = (nsIFrameSelection *)rlist; - nsresult result = rlist->AddRef(); - if (!NS_SUCCEEDED(result)) - { - delete rlist; - } - return result; + rlist->AddRef(); + return NS_OK; } +nsresult NS_NewDomSelection(nsIDOMSelection **aDomSelection); +nsresult NS_NewDomSelection(nsIDOMSelection **aDomSelection) +{ + nsDOMSelection *rlist = new nsDOMSelection; + if (!rlist) + return NS_ERROR_OUT_OF_MEMORY; + *aDomSelection = (nsIDOMSelection *)rlist; + rlist->AddRef(); + return NS_OK; +} //Horrible statics but no choice nsIAtom *nsSelection::sTableAtom = 0; @@ -781,12 +788,12 @@ nsSelection::nsSelection() if (mDomSelections[index]) autoCopyService->Listen(mDomSelections[index]); } - mDisplaySelection = nsISelectionController::SELECTION_ON; + mDisplaySelection = nsISelectionController::SELECTION_OFF; } -nsSelection::~nsSelection() +nsSelection::~nsSelection() { if (sInstanceCount <= 1) { @@ -1608,10 +1615,8 @@ nsSelection::TakeFocus(nsIContent *aNewFocus, PRUint32 aContentOffset, nsCOMPtr parent2; if (NS_FAILED(aNewFocus->GetParent(*getter_AddRefs(parent))) || !parent) return NS_ERROR_FAILURE; - //if (NS_FAILED(parent->GetParent(*getter_AddRefs(parent2))) || !parent2) - //return NS_ERROR_FAILURE; - //END HACKHACKHACK /checking for root frames/content + PRInt8 index = GetIndexFromSelectionType(nsISelectionController::SELECTION_NORMAL); domNode = do_QueryInterface(aNewFocus); //traverse through document and unselect crap here @@ -1688,7 +1693,7 @@ nsSelection::SetMouseDownState(PRBool aState) mSelectingTableCells = PR_FALSE; mStartSelectedCell = nsnull; mEndSelectedCell = nsnull; - NotifySelectionListeners(nsISelectionController::SELECTION_NORMAL); + //NotifySelectionListeners(nsISelectionController::SELECTION_NORMAL); } return NS_OK; } @@ -2625,6 +2630,18 @@ nsDOMSelection::nsDOMSelection(nsSelection *aList) } +nsDOMSelection::nsDOMSelection() +{ + mFixupState = PR_FALSE; + mDirection = eDirNext; + NS_NewISupportsArray(getter_AddRefs(mRangeArray)); + mScriptObject = nsnull; + mAutoScrollTimer = nsnull; + NS_NewISupportsArray(getter_AddRefs(mSelectionListeners)); + NS_INIT_REFCNT(); +} + + nsDOMSelection::~nsDOMSelection() { @@ -2986,7 +3003,7 @@ nsDOMSelection::GetPrimaryFrameForAnchorNode(nsIFrame **aReturnFrame) PRInt32 frameOffset = 0; *aReturnFrame = 0; nsCOMPtr content = do_QueryInterface(FetchAnchorNode()); - if (content) + if (content && mFrameSelection) return mFrameSelection->GetFrameForNodeOffset(content, FetchAnchorOffset(),aReturnFrame, &frameOffset); return NS_ERROR_FAILURE; } @@ -3001,7 +3018,7 @@ nsDOMSelection::GetPrimaryFrameForFocusNode(nsIFrame **aReturnFrame) *aReturnFrame = 0; nsCOMPtr content = do_QueryInterface(FetchFocusNode()); - if (content) + if (content && mFrameSelection) return mFrameSelection->GetFrameForNodeOffset(content, FetchFocusOffset(),aReturnFrame, &frameOffset); return NS_ERROR_FAILURE; } @@ -3017,6 +3034,8 @@ nsDOMSelection::selectFrames(nsIPresContext* aPresContext, nsIPresShell *aPresShell, PRBool aFlags) { + if (!mFrameSelection) + return NS_OK;//nothing to do nsresult result; nsCOMPtr genericiter = do_QueryInterface(aInnerIter); if (genericiter && aPresShell) @@ -3065,6 +3084,8 @@ nsDOMSelection::selectFrames(nsIPresContext* aPresContext, NS_IMETHODIMP nsDOMSelection::selectFrames(nsIPresContext* aPresContext, nsIDOMRange *aRange, PRBool aFlags) { + if (!mFrameSelection) + return NS_OK;//nothing to do if (!aRange || !aPresContext) return NS_ERROR_NULL_POINTER; nsCOMPtr iter; @@ -3314,6 +3335,8 @@ nsresult nsDOMSelection::StartAutoScrollTimer(nsIPresContext *aPresContext, nsIFrame *aFrame, nsPoint& aPoint, PRUint32 aDelay) { nsresult result; + if (!mFrameSelection) + return NS_OK;//nothing to do if (!mAutoScrollTimer) { @@ -3572,6 +3595,8 @@ nsDOMSelection::GetEnumerator(nsIEnumerator **aIterator) NS_IMETHODIMP nsDOMSelection::ClearSelection() { + if (!mFrameSelection) + return NS_OK;//nothing to do nsCOMPtr presContext; GetPresContext(getter_AddRefs(presContext)); @@ -3608,7 +3633,8 @@ nsDOMSelection::AddRange(nsIDOMRange* aRange) GetPresContext(getter_AddRefs(presContext)); selectFrames(presContext, aRange, PR_TRUE); //ScrollIntoView(); this should not happen automatically - + if (!mFrameSelection) + return NS_OK;//nothing to do return mFrameSelection->NotifySelectionListeners(GetType()); } @@ -3632,6 +3658,8 @@ nsDOMSelection::RemoveRange(nsIDOMRange* aRange) ScrollIntoView(); } } + if (!mFrameSelection) + return NS_OK;//nothing to do return mFrameSelection->NotifySelectionListeners(GetType()); } @@ -3695,7 +3723,8 @@ nsDOMSelection::Collapse(nsIDOMNode* aParentNode, PRInt32 aOffset) selectFrames(presContext, range,PR_TRUE); if (NS_FAILED(result)) return result; - + if (!mFrameSelection) + return NS_OK;//nothing to do return mFrameSelection->NotifySelectionListeners(GetType()); } @@ -4503,6 +4532,8 @@ nsDOMSelection::Extend(nsIDOMNode* aParentNode, PRInt32 aOffset) printf ("Sel. Extend set to null parent.\n"); } #endif + if (!mFrameSelection) + return NS_OK;//nothing to do return mFrameSelection->NotifySelectionListeners(GetType()); } @@ -4572,6 +4603,8 @@ nsDOMSelection::ContainsNode(nsIDOMNode* aNode, PRBool aRecursive, PRBool* aYes) nsresult nsDOMSelection::GetPresContext(nsIPresContext **aPresContext) { + if (!mFrameSelection) + return NS_ERROR_FAILURE;//nothing to do nsIFocusTracker *tracker = mFrameSelection->GetTracker(); if (!tracker) @@ -4584,6 +4617,8 @@ nsresult nsDOMSelection::GetPresShell(nsIPresShell **aPresShell) { nsresult rv = NS_OK; + if (!mFrameSelection) + return NS_ERROR_FAILURE;//nothing to do nsIFocusTracker *tracker = mFrameSelection->GetTracker(); @@ -4614,6 +4649,8 @@ nsDOMSelection::GetRootScrollableView(nsIScrollableView **aScrollableView) // NOTE: This method returns a NON-AddRef'd pointer // to the scrollable view! // + if (!mFrameSelection) + return NS_ERROR_FAILURE;//nothing to do nsresult rv = NS_OK; @@ -4648,6 +4685,8 @@ nsresult nsDOMSelection::GetFrameToRootViewOffset(nsIFrame *aFrame, nscoord *aX, nscoord *aY) { nsresult rv = NS_OK; + if (!mFrameSelection) + return NS_ERROR_FAILURE;//nothing to do if (!aFrame || !aX || !aY) { return NS_ERROR_NULL_POINTER; @@ -4705,6 +4744,8 @@ nsresult nsDOMSelection::GetPointFromOffset(nsIFrame *aFrame, PRInt32 aContentOffset, nsPoint *aPoint) { nsresult rv = NS_OK; + if (!mFrameSelection) + return NS_ERROR_FAILURE;//nothing to do if (!aFrame || !aPoint) return NS_ERROR_NULL_POINTER; @@ -4800,6 +4841,8 @@ nsresult nsDOMSelection::GetSelectionRegionRect(SelectionRegion aRegion, nsRect *aRect) { nsresult result = NS_OK; + if (!mFrameSelection) + return NS_ERROR_FAILURE;//nothing to do if (!aRect) return NS_ERROR_NULL_POINTER; @@ -4976,6 +5019,8 @@ nsDOMSelection::ScrollRectIntoView(nsRect& aRect, PRIntn aHPercent) { nsresult rv = NS_OK; + if (!mFrameSelection) + return NS_OK;//nothing to do nsIScrollableView *scrollingView = 0; @@ -5052,6 +5097,8 @@ NS_IMETHODIMP nsDOMSelection::ScrollIntoView(SelectionRegion aRegion) { nsresult result; + if (!mFrameSelection) + return NS_OK;//nothing to do if (mFrameSelection->GetBatching()) return NS_OK; @@ -5119,6 +5166,8 @@ nsDOMSelection::NotifySelectionListeners() { if (!mSelectionListeners) return NS_ERROR_FAILURE; + if (!mFrameSelection) + return NS_OK;//nothing to do if (mFrameSelection->GetBatching()){ mFrameSelection->SetDirty(); @@ -5152,6 +5201,8 @@ nsDOMSelection::NotifySelectionListeners() NS_IMETHODIMP nsDOMSelection::StartBatchChanges() { + if (!mFrameSelection) + return NS_OK;//nothing to do return mFrameSelection->StartBatchChanges(); } @@ -5160,6 +5211,8 @@ nsDOMSelection::StartBatchChanges() NS_IMETHODIMP nsDOMSelection::EndBatchChanges() { + if (!mFrameSelection) + return NS_OK;//nothing to do return mFrameSelection->EndBatchChanges(); } @@ -5168,6 +5221,8 @@ nsDOMSelection::EndBatchChanges() NS_IMETHODIMP nsDOMSelection::DeleteFromDocument() { + if (!mFrameSelection) + return NS_OK;//nothing to do return mFrameSelection->DeleteFromDocument(); } diff --git a/mozilla/content/events/src/nsEventStateManager.cpp b/mozilla/content/events/src/nsEventStateManager.cpp index 1d88d717cb3..596f766f83f 100644 --- a/mozilla/content/events/src/nsEventStateManager.cpp +++ b/mozilla/content/events/src/nsEventStateManager.cpp @@ -737,7 +737,9 @@ nsEventStateManager::PostHandleEvent(nsIPresContext* aPresContext, if ((ui->mUserFocus != NS_STYLE_USER_FOCUS_IGNORE) && (ui->mUserFocus != NS_STYLE_USER_FOCUS_NONE)) { currFrame->GetContent(getter_AddRefs(newFocus)); - break; + nsCOMPtr domElement(do_QueryInterface(newFocus)); + if (domElement) + break; } currFrame->GetParent(&currFrame); } diff --git a/mozilla/content/html/content/src/nsHTMLInputElement.cpp b/mozilla/content/html/content/src/nsHTMLInputElement.cpp index 33a669927d1..26bf774fff6 100644 --- a/mozilla/content/html/content/src/nsHTMLInputElement.cpp +++ b/mozilla/content/html/content/src/nsHTMLInputElement.cpp @@ -1132,7 +1132,7 @@ nsHTMLInputElement::GetTextLength(PRInt32* aTextLength) nsresult rv = nsGenericHTMLElement::GetPrimaryFrame(this, formControlFrame); if (NS_SUCCEEDED(rv) && formControlFrame) { - nsCOMPtr textControlFrame(do_QueryInterface(formControlFrame)); + nsCOMPtr textControlFrame(do_QueryInterface(formControlFrame)); if (textControlFrame) textControlFrame->GetTextLength(aTextLength); @@ -1148,7 +1148,7 @@ nsHTMLInputElement::SetSelectionRange(PRInt32 aSelectionStart, PRInt32 aSelectio nsresult rv = nsGenericHTMLElement::GetPrimaryFrame(this, formControlFrame); if (NS_SUCCEEDED(rv) && formControlFrame) { - nsCOMPtr textControlFrame(do_QueryInterface(formControlFrame)); + nsCOMPtr textControlFrame(do_QueryInterface(formControlFrame)); if (textControlFrame) textControlFrame->SetSelectionRange(aSelectionStart, aSelectionEnd); @@ -1173,7 +1173,7 @@ nsHTMLInputElement::SetSelectionStart(PRInt32 aSelectionStart) nsresult rv = nsGenericHTMLElement::GetPrimaryFrame(this, formControlFrame); if (NS_SUCCEEDED(rv) && formControlFrame) { - nsCOMPtr textControlFrame(do_QueryInterface(formControlFrame)); + nsCOMPtr textControlFrame(do_QueryInterface(formControlFrame)); if (textControlFrame) textControlFrame->SetSelectionStart(aSelectionStart); @@ -1199,7 +1199,7 @@ nsHTMLInputElement::SetSelectionEnd(PRInt32 aSelectionEnd) nsresult rv = nsGenericHTMLElement::GetPrimaryFrame(this, formControlFrame); if (NS_SUCCEEDED(rv) && formControlFrame) { - nsCOMPtr textControlFrame(do_QueryInterface(formControlFrame)); + nsCOMPtr textControlFrame(do_QueryInterface(formControlFrame)); if (textControlFrame) textControlFrame->SetSelectionEnd(aSelectionEnd); @@ -1215,7 +1215,7 @@ nsHTMLInputElement::GetSelectionRange(PRInt32* aSelectionStart, PRInt32* aSelect nsresult rv = nsGenericHTMLElement::GetPrimaryFrame(this, formControlFrame); if (NS_SUCCEEDED(rv) && formControlFrame) { - nsCOMPtr textControlFrame(do_QueryInterface(formControlFrame)); + nsCOMPtr textControlFrame(do_QueryInterface(formControlFrame)); if (textControlFrame) textControlFrame->GetSelectionRange(aSelectionStart, aSelectionEnd); diff --git a/mozilla/layout/base/nsCaret.cpp b/mozilla/layout/base/nsCaret.cpp index 0672319a01c..3da4377aca2 100644 --- a/mozilla/layout/base/nsCaret.cpp +++ b/mozilla/layout/base/nsCaret.cpp @@ -161,8 +161,9 @@ NS_IMETHODIMP nsCaret::QueryInterface(const nsIID& aIID, //----------------------------------------------------------------------------- -NS_IMETHODIMP nsCaret::SetCaretVisible(PRBool inMakeVisible) +NS_IMETHODIMP nsCaret::SetCaretVisible(PRBool inMakeVisible, nsIDOMSelection *aDOMSel) { + mDomSelectionWeak = getter_AddRefs( NS_GetWeakReference(aDOMSel) ); // weak reference to pres shell mVisible = inMakeVisible; nsresult err = NS_OK; if (mVisible) @@ -175,8 +176,10 @@ NS_IMETHODIMP nsCaret::SetCaretVisible(PRBool inMakeVisible) //----------------------------------------------------------------------------- -NS_IMETHODIMP nsCaret::SetCaretReadOnly(PRBool inMakeReadonly) +NS_IMETHODIMP nsCaret::SetCaretReadOnly(PRBool inMakeReadonly, nsIDOMSelection *aDOMSel) { + mDomSelectionWeak = getter_AddRefs( NS_GetWeakReference(aDOMSel) ); // weak reference to pres shell + mReadOnly = inMakeReadonly; return NS_OK; } @@ -187,6 +190,8 @@ NS_IMETHODIMP nsCaret::GetWindowRelativeCoordinates(nsRect& outCoordinates, PRBo { if (!mPresShell) return NS_ERROR_NOT_INITIALIZED; + + mDomSelectionWeak = getter_AddRefs( NS_GetWeakReference(aDOMSel) ); // weak reference to pres shell nsCOMPtr domSelection = aDOMSel; nsresult err; @@ -501,8 +506,6 @@ void nsCaret::GetViewForRendering(nsIFrame *caretFrame, EViewCoordinates coordTy do { theView->GetPosition(&x, &y); - viewOffset.x += x; - viewOffset.y += y; if (!returnView) { @@ -516,6 +519,8 @@ void nsCaret::GetViewForRendering(nsIFrame *caretFrame, EViewCoordinates coordTy if (coordType == eViewCoordinates) break; } + viewOffset.x += x; + viewOffset.y += y; } theView->GetParent(theView); diff --git a/mozilla/layout/base/nsCaret.h b/mozilla/layout/base/nsCaret.h index b8c2f1ce89f..0b8a4db09be 100644 --- a/mozilla/layout/base/nsCaret.h +++ b/mozilla/layout/base/nsCaret.h @@ -53,8 +53,8 @@ class nsCaret : public nsICaret, // nsICaret interface NS_IMETHOD Init(nsIPresShell *inPresShell); - NS_IMETHOD SetCaretVisible(PRBool inMakeVisible); - NS_IMETHOD SetCaretReadOnly(PRBool inMakeReadonly); + NS_IMETHOD SetCaretVisible(PRBool inMakeVisible, nsIDOMSelection *aSel); + NS_IMETHOD SetCaretReadOnly(PRBool inMakeReadonly, nsIDOMSelection *aSel); NS_IMETHOD GetWindowRelativeCoordinates(nsRect& outCoordinates, PRBool& outIsCollapsed, nsIDOMSelection *aDOMSel); NS_IMETHOD ClearFrameRefs(nsIFrame* aFrame); diff --git a/mozilla/layout/base/nsDocumentViewer.cpp b/mozilla/layout/base/nsDocumentViewer.cpp index 8860bfc5eb7..3d39492ad28 100644 --- a/mozilla/layout/base/nsDocumentViewer.cpp +++ b/mozilla/layout/base/nsDocumentViewer.cpp @@ -1831,7 +1831,7 @@ nsDocViewerFocusListener::Focus(nsIDOMEvent* aEvent) selCon->GetDisplaySelection( &selectionStatus); //if selection was nsISelectionController::SELECTION_OFF, do nothing - //otherwise re-enable it. + //otherwise re-enable it. if(selectionStatus == nsISelectionController::SELECTION_DISABLED) { selCon->SetDisplaySelection(nsISelectionController::SELECTION_ON); @@ -1839,12 +1839,12 @@ nsDocViewerFocusListener::Focus(nsIDOMEvent* aEvent) } return result; } - + nsresult nsDocViewerFocusListener::Blur(nsIDOMEvent* aEvent) { nsCOMPtr shell; - if(!mDocViewer) + if(!mDocViewer) return NS_ERROR_FAILURE; nsresult result = mDocViewer->GetPresShell(*getter_AddRefs(shell));//deref once cause it take a ptr ref diff --git a/mozilla/layout/base/nsICaret.h b/mozilla/layout/base/nsICaret.h index 88c13f7fa6c..a9654f49662 100644 --- a/mozilla/layout/base/nsICaret.h +++ b/mozilla/layout/base/nsICaret.h @@ -47,13 +47,13 @@ public: /** SetCaretVisible will set the visibility of the caret * @param inMakeVisible PR_TRUE to show the caret, PR_FALSE to hide it */ - NS_IMETHOD SetCaretVisible(PRBool inMakeVisible) = 0; + NS_IMETHOD SetCaretVisible(PRBool inMakeVisible, nsIDOMSelection *aDOMSel) = 0; /** SetCaretReadOnly set the appearance of the caret * @param inMakeReadonly PR_TRUE to show the caret in a 'read only' state, * PR_FALSE to show the caret in normal, editing state */ - NS_IMETHOD SetCaretReadOnly(PRBool inMakeReadonly) = 0; + NS_IMETHOD SetCaretReadOnly(PRBool inMakeReadonly, nsIDOMSelection *aDOMSel) = 0; /** GetWindowRelativeCoordinates * Get the position of the caret in (top-level) window coordinates. diff --git a/mozilla/layout/base/nsPresShell.cpp b/mozilla/layout/base/nsPresShell.cpp index 206444018ee..b7285af7554 100644 --- a/mozilla/layout/base/nsPresShell.cpp +++ b/mozilla/layout/base/nsPresShell.cpp @@ -651,10 +651,11 @@ public: NS_IMETHOD ScrollFrameIntoView(nsIFrame *aFrame); // caret handling NS_IMETHOD GetCaret(nsICaret **aOutCaret); - NS_IMETHOD SetCaretEnabled(PRBool aaInEnable); + NS_IMETHOD SetCaretEnabled(PRBool aInEnable); + NS_IMETHOD SetCaretReadOnly(PRBool aReadOnly); NS_IMETHOD GetCaretEnabled(PRBool *aOutEnabled); - NS_IMETHOD SetDisplayNonTextSelection(PRBool aaInEnable); + NS_IMETHOD SetDisplayNonTextSelection(PRBool aInEnable); NS_IMETHOD GetDisplayNonTextSelection(PRBool *aOutEnable); // nsISelectionController @@ -1772,17 +1773,30 @@ NS_IMETHODIMP PresShell::SetCaretEnabled(PRBool aInEnable) if (mCaret && (mCaretEnabled != oldEnabled)) { // Update the document's content and frame models. - if (mDocument) mDocument->FlushPendingNotifications(); + if (mDocument) + mDocument->FlushPendingNotifications(); - if (mCaretEnabled) - result = mCaret->SetCaretVisible(PR_TRUE); - else - result = mCaret->SetCaretVisible(PR_FALSE); + nsCOMPtr sel; + if (NS_SUCCEEDED(GetSelection(nsISelectionController::SELECTION_NORMAL, getter_AddRefs(sel))) && sel) + { + result = mCaret->SetCaretVisible(mCaretEnabled, sel); + } } return result; } + +NS_IMETHODIMP PresShell::SetCaretReadOnly(PRBool aReadOnly) +{ + nsCOMPtr domSel; + if (NS_SUCCEEDED(GetSelection(nsISelectionController::SELECTION_NORMAL, getter_AddRefs(domSel))) && domSel) + { + return mCaret->SetCaretReadOnly(aReadOnly, domSel); + } + return NS_ERROR_FAILURE; +} + NS_IMETHODIMP PresShell::GetCaretEnabled(PRBool *aOutEnabled) { if (!aOutEnabled) { return NS_ERROR_INVALID_ARG; } diff --git a/mozilla/layout/base/public/nsICaret.h b/mozilla/layout/base/public/nsICaret.h index 88c13f7fa6c..a9654f49662 100644 --- a/mozilla/layout/base/public/nsICaret.h +++ b/mozilla/layout/base/public/nsICaret.h @@ -47,13 +47,13 @@ public: /** SetCaretVisible will set the visibility of the caret * @param inMakeVisible PR_TRUE to show the caret, PR_FALSE to hide it */ - NS_IMETHOD SetCaretVisible(PRBool inMakeVisible) = 0; + NS_IMETHOD SetCaretVisible(PRBool inMakeVisible, nsIDOMSelection *aDOMSel) = 0; /** SetCaretReadOnly set the appearance of the caret * @param inMakeReadonly PR_TRUE to show the caret in a 'read only' state, * PR_FALSE to show the caret in normal, editing state */ - NS_IMETHOD SetCaretReadOnly(PRBool inMakeReadonly) = 0; + NS_IMETHOD SetCaretReadOnly(PRBool inMakeReadonly, nsIDOMSelection *aDOMSel) = 0; /** GetWindowRelativeCoordinates * Get the position of the caret in (top-level) window coordinates. diff --git a/mozilla/layout/base/public/nsISelectionController.idl b/mozilla/layout/base/public/nsISelectionController.idl index 367d35cae93..0d02393dcf0 100644 --- a/mozilla/layout/base/public/nsISelectionController.idl +++ b/mozilla/layout/base/public/nsISelectionController.idl @@ -52,8 +52,9 @@ interface nsISelectionController : nsISupports const short NUM_SELECTION_REGIONS = 2; const short SELECTION_OFF = 0; - const short SELECTION_ON = 1; - const short SELECTION_DISABLED = 2; + const short SELECTION_HIDDEN =1;//>HIDDEN displays selection + const short SELECTION_ON = 2; + const short SELECTION_DISABLED = 3; /** * SetDisplaySelection will set the display mode for the selection. OFF,ON,DISABLED @@ -98,6 +99,14 @@ interface nsISelectionController : nsISupports */ void setCaretEnabled(in boolean enabled); + /** + * Set the caret readonly or not. An readonly caret will + * draw but not blink when made visible. + * @param aReadOnly PR_TRUE to enable caret. PR_FALSE to disable. + * @return always NS_OK + */ + void setCaretReadOnly(in boolean readOnly); + /** * Gets the current state of the caret. * @param aEnabled [OUT] set to the current caret state, as set by SetCaretEnabled @@ -113,7 +122,7 @@ interface nsISelectionController : nsISupports * @param aForward forward or backward if PR_FALSE * @param aExtend should it collapse the selection of extend it? */ - void characterMove(in boolean aForward, in boolean aExtend); + void characterMove(in boolean forward, in boolean extend); /** WordMove will move the selection one word forward/backward in the document. * this will also have the effect of collapsing the selection if the aExtend = PR_FALSE @@ -123,7 +132,7 @@ interface nsISelectionController : nsISupports * @param aExtend should it collapse the selection of extend it? */ - void wordMove(in boolean aForward, in boolean aExtend); + void wordMove(in boolean forward, in boolean extend); /** LineMove will move the selection one line forward/backward in the document. * this will also have the effect of collapsing the selection if the aExtend = PR_FALSE @@ -132,7 +141,7 @@ interface nsISelectionController : nsISupports * @param aForward forward or backward if PR_FALSE * @param aExtend should it collapse the selection of extend it? */ - void lineMove(in boolean aForward, in boolean aExtend); + void lineMove(in boolean forward, in boolean extend); /** IntraLineMove will move the selection to the front of the line or end of the line * in the document. @@ -142,7 +151,7 @@ interface nsISelectionController : nsISupports * @param aForward forward or backward if PR_FALSE * @param aExtend should it collapse the selection of extend it? */ - void intraLineMove(in boolean aForward, in boolean aExtend); + void intraLineMove(in boolean forward, in boolean extend); /** PageMove will move the selection one page forward/backward in the document. * this will also have the effect of collapsing the selection if the aExtend = PR_FALSE @@ -151,12 +160,12 @@ interface nsISelectionController : nsISupports * @param aForward forward or backward if PR_FALSE * @param aExtend should it collapse the selection of extend it? */ - void pageMove(in boolean aForward, in boolean aExtend); + void pageMove(in boolean forward, in boolean extend); /** CompleteScroll will move page view to the top or bottom of the document * @param aForward forward or backward if PR_FALSE */ - void completeScroll(in boolean aForward); + void completeScroll(in boolean forward); /** CompleteMove will move page view to the top or bottom of the document * this will also have the effect of collapsing the selection if the aExtend = PR_FALSE @@ -165,23 +174,23 @@ interface nsISelectionController : nsISupports * @param aForward forward or backward if PR_FALSE * @param aExtend should it collapse the selection of extend it? */ - void completeMove(in boolean aForward, in boolean aExtend); + void completeMove(in boolean forward, in boolean extend); /** ScrollPage will scroll the page without affecting the selection. * @param aForward scroll forward or backwards in selection */ - void scrollPage(in boolean aForward); + void scrollPage(in boolean forward); /** ScrolLine will scroll line up or down dependent on the boolean * @param aForward scroll forward or backwards in selection */ - void scrollLine(in boolean aForward); + void scrollLine(in boolean forward); /** ScrolHorizontal will scroll left or right dependent on the boolean * @param aLeft if true will scroll left. if not will scroll right. */ - void scrollHorizontal(in boolean aLeft); + void scrollHorizontal(in boolean left); /** SelectAll will select the whole page */ void selectAll(); diff --git a/mozilla/layout/base/src/nsCaret.cpp b/mozilla/layout/base/src/nsCaret.cpp index 0672319a01c..3da4377aca2 100644 --- a/mozilla/layout/base/src/nsCaret.cpp +++ b/mozilla/layout/base/src/nsCaret.cpp @@ -161,8 +161,9 @@ NS_IMETHODIMP nsCaret::QueryInterface(const nsIID& aIID, //----------------------------------------------------------------------------- -NS_IMETHODIMP nsCaret::SetCaretVisible(PRBool inMakeVisible) +NS_IMETHODIMP nsCaret::SetCaretVisible(PRBool inMakeVisible, nsIDOMSelection *aDOMSel) { + mDomSelectionWeak = getter_AddRefs( NS_GetWeakReference(aDOMSel) ); // weak reference to pres shell mVisible = inMakeVisible; nsresult err = NS_OK; if (mVisible) @@ -175,8 +176,10 @@ NS_IMETHODIMP nsCaret::SetCaretVisible(PRBool inMakeVisible) //----------------------------------------------------------------------------- -NS_IMETHODIMP nsCaret::SetCaretReadOnly(PRBool inMakeReadonly) +NS_IMETHODIMP nsCaret::SetCaretReadOnly(PRBool inMakeReadonly, nsIDOMSelection *aDOMSel) { + mDomSelectionWeak = getter_AddRefs( NS_GetWeakReference(aDOMSel) ); // weak reference to pres shell + mReadOnly = inMakeReadonly; return NS_OK; } @@ -187,6 +190,8 @@ NS_IMETHODIMP nsCaret::GetWindowRelativeCoordinates(nsRect& outCoordinates, PRBo { if (!mPresShell) return NS_ERROR_NOT_INITIALIZED; + + mDomSelectionWeak = getter_AddRefs( NS_GetWeakReference(aDOMSel) ); // weak reference to pres shell nsCOMPtr domSelection = aDOMSel; nsresult err; @@ -501,8 +506,6 @@ void nsCaret::GetViewForRendering(nsIFrame *caretFrame, EViewCoordinates coordTy do { theView->GetPosition(&x, &y); - viewOffset.x += x; - viewOffset.y += y; if (!returnView) { @@ -516,6 +519,8 @@ void nsCaret::GetViewForRendering(nsIFrame *caretFrame, EViewCoordinates coordTy if (coordType == eViewCoordinates) break; } + viewOffset.x += x; + viewOffset.y += y; } theView->GetParent(theView); diff --git a/mozilla/layout/base/src/nsCaret.h b/mozilla/layout/base/src/nsCaret.h index b8c2f1ce89f..0b8a4db09be 100644 --- a/mozilla/layout/base/src/nsCaret.h +++ b/mozilla/layout/base/src/nsCaret.h @@ -53,8 +53,8 @@ class nsCaret : public nsICaret, // nsICaret interface NS_IMETHOD Init(nsIPresShell *inPresShell); - NS_IMETHOD SetCaretVisible(PRBool inMakeVisible); - NS_IMETHOD SetCaretReadOnly(PRBool inMakeReadonly); + NS_IMETHOD SetCaretVisible(PRBool inMakeVisible, nsIDOMSelection *aSel); + NS_IMETHOD SetCaretReadOnly(PRBool inMakeReadonly, nsIDOMSelection *aSel); NS_IMETHOD GetWindowRelativeCoordinates(nsRect& outCoordinates, PRBool& outIsCollapsed, nsIDOMSelection *aDOMSel); NS_IMETHOD ClearFrameRefs(nsIFrame* aFrame); diff --git a/mozilla/layout/base/src/nsDocumentViewer.cpp b/mozilla/layout/base/src/nsDocumentViewer.cpp index 8860bfc5eb7..3d39492ad28 100644 --- a/mozilla/layout/base/src/nsDocumentViewer.cpp +++ b/mozilla/layout/base/src/nsDocumentViewer.cpp @@ -1831,7 +1831,7 @@ nsDocViewerFocusListener::Focus(nsIDOMEvent* aEvent) selCon->GetDisplaySelection( &selectionStatus); //if selection was nsISelectionController::SELECTION_OFF, do nothing - //otherwise re-enable it. + //otherwise re-enable it. if(selectionStatus == nsISelectionController::SELECTION_DISABLED) { selCon->SetDisplaySelection(nsISelectionController::SELECTION_ON); @@ -1839,12 +1839,12 @@ nsDocViewerFocusListener::Focus(nsIDOMEvent* aEvent) } return result; } - + nsresult nsDocViewerFocusListener::Blur(nsIDOMEvent* aEvent) { nsCOMPtr shell; - if(!mDocViewer) + if(!mDocViewer) return NS_ERROR_FAILURE; nsresult result = mDocViewer->GetPresShell(*getter_AddRefs(shell));//deref once cause it take a ptr ref diff --git a/mozilla/layout/base/src/nsSelection.cpp b/mozilla/layout/base/src/nsSelection.cpp index 3ba42a56132..10c49850732 100644 --- a/mozilla/layout/base/src/nsSelection.cpp +++ b/mozilla/layout/base/src/nsSelection.cpp @@ -111,6 +111,7 @@ class nsAutoScrollTimer; class nsDOMSelection : public nsIDOMSelection , public nsIScriptObjectOwner, public nsSupportsWeakReference { public: + nsDOMSelection(); nsDOMSelection(nsSelection *aList); virtual ~nsDOMSelection(); @@ -523,15 +524,21 @@ nsresult NS_NewSelection(nsIFrameSelection **aFrameSelection) if (!rlist) return NS_ERROR_OUT_OF_MEMORY; *aFrameSelection = (nsIFrameSelection *)rlist; - nsresult result = rlist->AddRef(); - if (!NS_SUCCEEDED(result)) - { - delete rlist; - } - return result; + rlist->AddRef(); + return NS_OK; } +nsresult NS_NewDomSelection(nsIDOMSelection **aDomSelection); +nsresult NS_NewDomSelection(nsIDOMSelection **aDomSelection) +{ + nsDOMSelection *rlist = new nsDOMSelection; + if (!rlist) + return NS_ERROR_OUT_OF_MEMORY; + *aDomSelection = (nsIDOMSelection *)rlist; + rlist->AddRef(); + return NS_OK; +} //Horrible statics but no choice nsIAtom *nsSelection::sTableAtom = 0; @@ -781,12 +788,12 @@ nsSelection::nsSelection() if (mDomSelections[index]) autoCopyService->Listen(mDomSelections[index]); } - mDisplaySelection = nsISelectionController::SELECTION_ON; + mDisplaySelection = nsISelectionController::SELECTION_OFF; } -nsSelection::~nsSelection() +nsSelection::~nsSelection() { if (sInstanceCount <= 1) { @@ -1608,10 +1615,8 @@ nsSelection::TakeFocus(nsIContent *aNewFocus, PRUint32 aContentOffset, nsCOMPtr parent2; if (NS_FAILED(aNewFocus->GetParent(*getter_AddRefs(parent))) || !parent) return NS_ERROR_FAILURE; - //if (NS_FAILED(parent->GetParent(*getter_AddRefs(parent2))) || !parent2) - //return NS_ERROR_FAILURE; - //END HACKHACKHACK /checking for root frames/content + PRInt8 index = GetIndexFromSelectionType(nsISelectionController::SELECTION_NORMAL); domNode = do_QueryInterface(aNewFocus); //traverse through document and unselect crap here @@ -1688,7 +1693,7 @@ nsSelection::SetMouseDownState(PRBool aState) mSelectingTableCells = PR_FALSE; mStartSelectedCell = nsnull; mEndSelectedCell = nsnull; - NotifySelectionListeners(nsISelectionController::SELECTION_NORMAL); + //NotifySelectionListeners(nsISelectionController::SELECTION_NORMAL); } return NS_OK; } @@ -2625,6 +2630,18 @@ nsDOMSelection::nsDOMSelection(nsSelection *aList) } +nsDOMSelection::nsDOMSelection() +{ + mFixupState = PR_FALSE; + mDirection = eDirNext; + NS_NewISupportsArray(getter_AddRefs(mRangeArray)); + mScriptObject = nsnull; + mAutoScrollTimer = nsnull; + NS_NewISupportsArray(getter_AddRefs(mSelectionListeners)); + NS_INIT_REFCNT(); +} + + nsDOMSelection::~nsDOMSelection() { @@ -2986,7 +3003,7 @@ nsDOMSelection::GetPrimaryFrameForAnchorNode(nsIFrame **aReturnFrame) PRInt32 frameOffset = 0; *aReturnFrame = 0; nsCOMPtr content = do_QueryInterface(FetchAnchorNode()); - if (content) + if (content && mFrameSelection) return mFrameSelection->GetFrameForNodeOffset(content, FetchAnchorOffset(),aReturnFrame, &frameOffset); return NS_ERROR_FAILURE; } @@ -3001,7 +3018,7 @@ nsDOMSelection::GetPrimaryFrameForFocusNode(nsIFrame **aReturnFrame) *aReturnFrame = 0; nsCOMPtr content = do_QueryInterface(FetchFocusNode()); - if (content) + if (content && mFrameSelection) return mFrameSelection->GetFrameForNodeOffset(content, FetchFocusOffset(),aReturnFrame, &frameOffset); return NS_ERROR_FAILURE; } @@ -3017,6 +3034,8 @@ nsDOMSelection::selectFrames(nsIPresContext* aPresContext, nsIPresShell *aPresShell, PRBool aFlags) { + if (!mFrameSelection) + return NS_OK;//nothing to do nsresult result; nsCOMPtr genericiter = do_QueryInterface(aInnerIter); if (genericiter && aPresShell) @@ -3065,6 +3084,8 @@ nsDOMSelection::selectFrames(nsIPresContext* aPresContext, NS_IMETHODIMP nsDOMSelection::selectFrames(nsIPresContext* aPresContext, nsIDOMRange *aRange, PRBool aFlags) { + if (!mFrameSelection) + return NS_OK;//nothing to do if (!aRange || !aPresContext) return NS_ERROR_NULL_POINTER; nsCOMPtr iter; @@ -3314,6 +3335,8 @@ nsresult nsDOMSelection::StartAutoScrollTimer(nsIPresContext *aPresContext, nsIFrame *aFrame, nsPoint& aPoint, PRUint32 aDelay) { nsresult result; + if (!mFrameSelection) + return NS_OK;//nothing to do if (!mAutoScrollTimer) { @@ -3572,6 +3595,8 @@ nsDOMSelection::GetEnumerator(nsIEnumerator **aIterator) NS_IMETHODIMP nsDOMSelection::ClearSelection() { + if (!mFrameSelection) + return NS_OK;//nothing to do nsCOMPtr presContext; GetPresContext(getter_AddRefs(presContext)); @@ -3608,7 +3633,8 @@ nsDOMSelection::AddRange(nsIDOMRange* aRange) GetPresContext(getter_AddRefs(presContext)); selectFrames(presContext, aRange, PR_TRUE); //ScrollIntoView(); this should not happen automatically - + if (!mFrameSelection) + return NS_OK;//nothing to do return mFrameSelection->NotifySelectionListeners(GetType()); } @@ -3632,6 +3658,8 @@ nsDOMSelection::RemoveRange(nsIDOMRange* aRange) ScrollIntoView(); } } + if (!mFrameSelection) + return NS_OK;//nothing to do return mFrameSelection->NotifySelectionListeners(GetType()); } @@ -3695,7 +3723,8 @@ nsDOMSelection::Collapse(nsIDOMNode* aParentNode, PRInt32 aOffset) selectFrames(presContext, range,PR_TRUE); if (NS_FAILED(result)) return result; - + if (!mFrameSelection) + return NS_OK;//nothing to do return mFrameSelection->NotifySelectionListeners(GetType()); } @@ -4503,6 +4532,8 @@ nsDOMSelection::Extend(nsIDOMNode* aParentNode, PRInt32 aOffset) printf ("Sel. Extend set to null parent.\n"); } #endif + if (!mFrameSelection) + return NS_OK;//nothing to do return mFrameSelection->NotifySelectionListeners(GetType()); } @@ -4572,6 +4603,8 @@ nsDOMSelection::ContainsNode(nsIDOMNode* aNode, PRBool aRecursive, PRBool* aYes) nsresult nsDOMSelection::GetPresContext(nsIPresContext **aPresContext) { + if (!mFrameSelection) + return NS_ERROR_FAILURE;//nothing to do nsIFocusTracker *tracker = mFrameSelection->GetTracker(); if (!tracker) @@ -4584,6 +4617,8 @@ nsresult nsDOMSelection::GetPresShell(nsIPresShell **aPresShell) { nsresult rv = NS_OK; + if (!mFrameSelection) + return NS_ERROR_FAILURE;//nothing to do nsIFocusTracker *tracker = mFrameSelection->GetTracker(); @@ -4614,6 +4649,8 @@ nsDOMSelection::GetRootScrollableView(nsIScrollableView **aScrollableView) // NOTE: This method returns a NON-AddRef'd pointer // to the scrollable view! // + if (!mFrameSelection) + return NS_ERROR_FAILURE;//nothing to do nsresult rv = NS_OK; @@ -4648,6 +4685,8 @@ nsresult nsDOMSelection::GetFrameToRootViewOffset(nsIFrame *aFrame, nscoord *aX, nscoord *aY) { nsresult rv = NS_OK; + if (!mFrameSelection) + return NS_ERROR_FAILURE;//nothing to do if (!aFrame || !aX || !aY) { return NS_ERROR_NULL_POINTER; @@ -4705,6 +4744,8 @@ nsresult nsDOMSelection::GetPointFromOffset(nsIFrame *aFrame, PRInt32 aContentOffset, nsPoint *aPoint) { nsresult rv = NS_OK; + if (!mFrameSelection) + return NS_ERROR_FAILURE;//nothing to do if (!aFrame || !aPoint) return NS_ERROR_NULL_POINTER; @@ -4800,6 +4841,8 @@ nsresult nsDOMSelection::GetSelectionRegionRect(SelectionRegion aRegion, nsRect *aRect) { nsresult result = NS_OK; + if (!mFrameSelection) + return NS_ERROR_FAILURE;//nothing to do if (!aRect) return NS_ERROR_NULL_POINTER; @@ -4976,6 +5019,8 @@ nsDOMSelection::ScrollRectIntoView(nsRect& aRect, PRIntn aHPercent) { nsresult rv = NS_OK; + if (!mFrameSelection) + return NS_OK;//nothing to do nsIScrollableView *scrollingView = 0; @@ -5052,6 +5097,8 @@ NS_IMETHODIMP nsDOMSelection::ScrollIntoView(SelectionRegion aRegion) { nsresult result; + if (!mFrameSelection) + return NS_OK;//nothing to do if (mFrameSelection->GetBatching()) return NS_OK; @@ -5119,6 +5166,8 @@ nsDOMSelection::NotifySelectionListeners() { if (!mSelectionListeners) return NS_ERROR_FAILURE; + if (!mFrameSelection) + return NS_OK;//nothing to do if (mFrameSelection->GetBatching()){ mFrameSelection->SetDirty(); @@ -5152,6 +5201,8 @@ nsDOMSelection::NotifySelectionListeners() NS_IMETHODIMP nsDOMSelection::StartBatchChanges() { + if (!mFrameSelection) + return NS_OK;//nothing to do return mFrameSelection->StartBatchChanges(); } @@ -5160,6 +5211,8 @@ nsDOMSelection::StartBatchChanges() NS_IMETHODIMP nsDOMSelection::EndBatchChanges() { + if (!mFrameSelection) + return NS_OK;//nothing to do return mFrameSelection->EndBatchChanges(); } @@ -5168,6 +5221,8 @@ nsDOMSelection::EndBatchChanges() NS_IMETHODIMP nsDOMSelection::DeleteFromDocument() { + if (!mFrameSelection) + return NS_OK;//nothing to do return mFrameSelection->DeleteFromDocument(); } diff --git a/mozilla/layout/build/nsLayoutCID.h b/mozilla/layout/build/nsLayoutCID.h index 710fc0e266f..cc7526f9c59 100644 --- a/mozilla/layout/build/nsLayoutCID.h +++ b/mozilla/layout/build/nsLayoutCID.h @@ -115,6 +115,10 @@ {/* {905F80F1-8A7B-11d2-918C-0080C8E44DB5}*/ \ 0x905f80f1, 0x8a7b, 0x11d2, { 0x91, 0x8c, 0x0, 0x80, 0xc8, 0xe4, 0x4d, 0xb5 } } +#define NS_DOMSELECTION_CID \ +{/* {C87A37FC-8109-4ce2-A322-8CDEC925379F}*/ \ + 0xc87a37fc, 0x8109, 0x4ce2, { 0xa3, 0x22, 0x8c, 0xde, 0xc9, 0x25, 0x37, 0x9f } } + #define NS_RANGE_CID \ {/* {56AD2981-8A87-11d2-918C-0080C8E44DB5}*/ \ 0x56ad2981, 0x8a87, 0x11d2, { 0x91, 0x8c, 0x0, 0x80, 0xc8, 0xe4, 0x4d, 0xb5 } } diff --git a/mozilla/layout/build/nsLayoutFactory.cpp b/mozilla/layout/build/nsLayoutFactory.cpp index 632ce49ecaa..ec3f9829208 100644 --- a/mozilla/layout/build/nsLayoutFactory.cpp +++ b/mozilla/layout/build/nsLayoutFactory.cpp @@ -79,6 +79,8 @@ static NS_DEFINE_IID(kHTMLOptionElementCID, NS_HTMLOPTIONELEMENT_CID); static NS_DEFINE_CID(kSelectionCID, NS_SELECTION_CID); static NS_DEFINE_IID(kFrameSelectionCID, NS_FRAMESELECTION_CID); +static NS_DEFINE_IID(kDOMSelectionCID, NS_DOMSELECTION_CID); + static NS_DEFINE_IID(kRangeCID, NS_RANGE_CID); static NS_DEFINE_IID(kContentIteratorCID, NS_CONTENTITERATOR_CID); static NS_DEFINE_IID(kGeneratedContentIteratorCID, NS_GENERATEDCONTENTITERATOR_CID); @@ -106,6 +108,7 @@ static NS_DEFINE_CID(kAutoCopyServiceCID, NS_AUTOCOPYSERVICE_CID); extern nsresult NS_NewSelection(nsIFrameSelection** aResult); +extern nsresult NS_NewDomSelection(nsIDOMSelection** aResult); extern nsresult NS_NewRange(nsIDOMRange** aResult); extern nsresult NS_NewContentIterator(nsIContentIterator** aResult); extern nsresult NS_NewGenRegularIterator(nsIContentIterator** aResult); @@ -238,6 +241,13 @@ nsLayoutFactory::CreateInstance(nsISupports *aOuter, return res; } } + else if (mClassID.Equals(kDOMSelectionCID)) { + res = NS_NewDomSelection((nsIDOMSelection**)&inst); + if (NS_FAILED(res)) { + LOG_NEW_FAILURE("NS_NewDomSelection", res); + return res; + } + } else if (mClassID.Equals(kRangeCID)) { res = NS_NewRange((nsIDOMRange **)&inst); if (NS_FAILED(res)) { diff --git a/mozilla/layout/events/src/nsEventStateManager.cpp b/mozilla/layout/events/src/nsEventStateManager.cpp index 1d88d717cb3..596f766f83f 100644 --- a/mozilla/layout/events/src/nsEventStateManager.cpp +++ b/mozilla/layout/events/src/nsEventStateManager.cpp @@ -737,7 +737,9 @@ nsEventStateManager::PostHandleEvent(nsIPresContext* aPresContext, if ((ui->mUserFocus != NS_STYLE_USER_FOCUS_IGNORE) && (ui->mUserFocus != NS_STYLE_USER_FOCUS_NONE)) { currFrame->GetContent(getter_AddRefs(newFocus)); - break; + nsCOMPtr domElement(do_QueryInterface(newFocus)); + if (domElement) + break; } currFrame->GetParent(&currFrame); } diff --git a/mozilla/layout/forms/nsFileControlFrame.cpp b/mozilla/layout/forms/nsFileControlFrame.cpp index 8e6d314187c..98f226ad6e1 100644 --- a/mozilla/layout/forms/nsFileControlFrame.cpp +++ b/mozilla/layout/forms/nsFileControlFrame.cpp @@ -23,8 +23,8 @@ #include "nsFileControlFrame.h" #include "nsFormFrame.h" -#ifdef DEBUG_MJUDGE -#define DEBUG_NEWFRAME 1 +#ifdef DEBUG_mjudge +#define DEBUG_NEWFRAME 1 #endif diff --git a/mozilla/layout/forms/nsITextControlFrame.h b/mozilla/layout/forms/nsITextControlFrame.h index 96e00307a8d..2075c125ad6 100644 --- a/mozilla/layout/forms/nsITextControlFrame.h +++ b/mozilla/layout/forms/nsITextControlFrame.h @@ -24,6 +24,8 @@ class nsIEditor; class nsIDocShell; +class nsISelectionController; + #define NS_IGFXTEXTCONTROLFRAME_IID \ {/* d3ea33ea-9e00-11d3-bccc-0060b0fc76bd*/ \ @@ -46,5 +48,28 @@ public: NS_IMETHOD SetSelectionRange(PRInt32 aSelectionStart, PRInt32 aSelectionEnd) = 0; NS_IMETHOD GetSelectionRange(PRInt32* aSelectionStart, PRInt32* aSelectionEnd) = 0; - + +}; + +#define NS_IGFXTEXTCONTROLFRAME2_IID \ +{/* A744CFC9-2DA8-416d-A058-ADB1D4B3B534*/ \ +0xa744cfc9, 0x2da8, 0x416d, \ +{ 0xa0, 0x58, 0xad, 0xb1, 0xd4, 0xb3, 0xb5, 0x34 } } + +class nsIGfxTextControlFrame2 : public nsISupports +{ +public: + static const nsIID& GetIID() { static nsIID iid = NS_IGFXTEXTCONTROLFRAME2_IID; return iid; } + + NS_IMETHOD GetEditor(nsIEditor **aEditor) = 0; + + NS_IMETHOD GetTextLength(PRInt32* aTextLength) = 0; + + NS_IMETHOD SetSelectionStart(PRInt32 aSelectionStart) = 0; + NS_IMETHOD SetSelectionEnd(PRInt32 aSelectionEnd) = 0; + + NS_IMETHOD SetSelectionRange(PRInt32 aSelectionStart, PRInt32 aSelectionEnd) = 0; + NS_IMETHOD GetSelectionRange(PRInt32* aSelectionStart, PRInt32* aSelectionEnd) = 0; + + NS_IMETHOD GetSelectionController(nsISelectionController **aSelCon) = 0; }; diff --git a/mozilla/layout/generic/nsBlockFrame.cpp b/mozilla/layout/generic/nsBlockFrame.cpp index 715bec5166e..02810662a8b 100644 --- a/mozilla/layout/generic/nsBlockFrame.cpp +++ b/mozilla/layout/generic/nsBlockFrame.cpp @@ -6307,17 +6307,17 @@ nsBlockFrame::HandleEvent(nsIPresContext* aPresContext, nsGUIEvent* aEvent, nsEventStatus* aEventStatus) { + + nsresult result; if (aEvent->message == NS_MOUSE_MOVE) { - nsCOMPtr shell; - nsresult rv = aPresContext->GetShell(getter_AddRefs(shell)); - if (NS_SUCCEEDED(rv)){ - nsCOMPtr frameselection; - if (NS_SUCCEEDED(shell->GetFrameSelection(getter_AddRefs(frameselection))) && frameselection){ - PRBool mouseDown = PR_FALSE; - if (NS_FAILED(frameselection->GetMouseDownState(&mouseDown)) || !mouseDown) - return NS_OK;//do not handle - } - } + nsCOMPtr selCon; + result = GetSelectionController(aPresContext, getter_AddRefs(selCon)); + if (NS_FAILED(result) || !selCon) + return result?result:NS_ERROR_FAILURE; + nsCOMPtr frameSelection = do_QueryInterface(selCon); + PRBool mouseDown = PR_FALSE; + if (!frameSelection || NS_FAILED(frameSelection->GetMouseDownState(&mouseDown)) || !mouseDown) + return NS_OK;//do not handle } if (aEvent->message == NS_MOUSE_LEFT_BUTTON_DOWN || aEvent->message == NS_MOUSE_MOVE || @@ -6330,7 +6330,6 @@ nsBlockFrame::HandleEvent(nsIPresContext* aPresContext, CaptureMouse(aPresContext, PR_TRUE); } - nsresult result; nsIFrame *resultFrame = nsnull;//this will be passed the handle event when we //can tell who to pass it to nsCOMPtr it; diff --git a/mozilla/layout/generic/nsBlockReflowState.cpp b/mozilla/layout/generic/nsBlockReflowState.cpp index 715bec5166e..02810662a8b 100644 --- a/mozilla/layout/generic/nsBlockReflowState.cpp +++ b/mozilla/layout/generic/nsBlockReflowState.cpp @@ -6307,17 +6307,17 @@ nsBlockFrame::HandleEvent(nsIPresContext* aPresContext, nsGUIEvent* aEvent, nsEventStatus* aEventStatus) { + + nsresult result; if (aEvent->message == NS_MOUSE_MOVE) { - nsCOMPtr shell; - nsresult rv = aPresContext->GetShell(getter_AddRefs(shell)); - if (NS_SUCCEEDED(rv)){ - nsCOMPtr frameselection; - if (NS_SUCCEEDED(shell->GetFrameSelection(getter_AddRefs(frameselection))) && frameselection){ - PRBool mouseDown = PR_FALSE; - if (NS_FAILED(frameselection->GetMouseDownState(&mouseDown)) || !mouseDown) - return NS_OK;//do not handle - } - } + nsCOMPtr selCon; + result = GetSelectionController(aPresContext, getter_AddRefs(selCon)); + if (NS_FAILED(result) || !selCon) + return result?result:NS_ERROR_FAILURE; + nsCOMPtr frameSelection = do_QueryInterface(selCon); + PRBool mouseDown = PR_FALSE; + if (!frameSelection || NS_FAILED(frameSelection->GetMouseDownState(&mouseDown)) || !mouseDown) + return NS_OK;//do not handle } if (aEvent->message == NS_MOUSE_LEFT_BUTTON_DOWN || aEvent->message == NS_MOUSE_MOVE || @@ -6330,7 +6330,6 @@ nsBlockFrame::HandleEvent(nsIPresContext* aPresContext, CaptureMouse(aPresContext, PR_TRUE); } - nsresult result; nsIFrame *resultFrame = nsnull;//this will be passed the handle event when we //can tell who to pass it to nsCOMPtr it; diff --git a/mozilla/layout/generic/nsBlockReflowState.h b/mozilla/layout/generic/nsBlockReflowState.h index 715bec5166e..02810662a8b 100644 --- a/mozilla/layout/generic/nsBlockReflowState.h +++ b/mozilla/layout/generic/nsBlockReflowState.h @@ -6307,17 +6307,17 @@ nsBlockFrame::HandleEvent(nsIPresContext* aPresContext, nsGUIEvent* aEvent, nsEventStatus* aEventStatus) { + + nsresult result; if (aEvent->message == NS_MOUSE_MOVE) { - nsCOMPtr shell; - nsresult rv = aPresContext->GetShell(getter_AddRefs(shell)); - if (NS_SUCCEEDED(rv)){ - nsCOMPtr frameselection; - if (NS_SUCCEEDED(shell->GetFrameSelection(getter_AddRefs(frameselection))) && frameselection){ - PRBool mouseDown = PR_FALSE; - if (NS_FAILED(frameselection->GetMouseDownState(&mouseDown)) || !mouseDown) - return NS_OK;//do not handle - } - } + nsCOMPtr selCon; + result = GetSelectionController(aPresContext, getter_AddRefs(selCon)); + if (NS_FAILED(result) || !selCon) + return result?result:NS_ERROR_FAILURE; + nsCOMPtr frameSelection = do_QueryInterface(selCon); + PRBool mouseDown = PR_FALSE; + if (!frameSelection || NS_FAILED(frameSelection->GetMouseDownState(&mouseDown)) || !mouseDown) + return NS_OK;//do not handle } if (aEvent->message == NS_MOUSE_LEFT_BUTTON_DOWN || aEvent->message == NS_MOUSE_MOVE || @@ -6330,7 +6330,6 @@ nsBlockFrame::HandleEvent(nsIPresContext* aPresContext, CaptureMouse(aPresContext, PR_TRUE); } - nsresult result; nsIFrame *resultFrame = nsnull;//this will be passed the handle event when we //can tell who to pass it to nsCOMPtr it; diff --git a/mozilla/layout/generic/nsFrame.cpp b/mozilla/layout/generic/nsFrame.cpp index e200e031dcd..41049871c8f 100644 --- a/mozilla/layout/generic/nsFrame.cpp +++ b/mozilla/layout/generic/nsFrame.cpp @@ -60,6 +60,8 @@ #include "nsIDOMRange.h" #include "nsITableLayout.h" //selection neccesity #include "nsITableCellLayout.h"// " +#include "nsIGfxTextControlFrame.h" + // Some Misc #defines @@ -654,76 +656,71 @@ nsFrame::Paint(nsIPresContext* aPresContext, const nsRect& aDirtyRect, nsFramePaintLayer aWhichLayer) { - //if (NS_FRAME_PAINT_LAYER_FOREGROUND == aWhichLayer) { -/** GetDocument -*/ - nsCOMPtr doc; - nsresult result; - nsCOMPtr shell; - result = aPresContext->GetShell(getter_AddRefs(shell)); - if (NS_FAILED(result)) - return result; + nsCOMPtr doc; + nsresult result; + nsCOMPtr shell; + result = aPresContext->GetShell(getter_AddRefs(shell)); + if (NS_FAILED(result)) + return result; - PRBool displyNonTextSelection = PR_TRUE; - result = shell->GetDisplayNonTextSelection(&displyNonTextSelection); - if (NS_FAILED(result)) + PRBool displaySelection = PR_TRUE; + result = shell->GetDisplayNonTextSelection(&displaySelection); + if (NS_FAILED(result)) + return result; + if (!displaySelection) + return NS_OK; + if (mContent) { + result = mContent->GetDocument(*getter_AddRefs(doc)); + } + +//check frame selection state + PRBool isSelected; + nsFrameState frameState; + GetFrameState(&frameState); + isSelected = (frameState & NS_FRAME_SELECTED_CONTENT) == NS_FRAME_SELECTED_CONTENT; +//if not selected then return + if (!isSelected) + return NS_OK; //nothing to do + +//get the selection controller + nsCOMPtr selCon; + result = GetSelectionController(aPresContext, getter_AddRefs(selCon)); + PRInt16 selectionValue; + selCon->GetDisplaySelection(&selectionValue); + displaySelection = selectionValue > nsISelectionController::SELECTION_HIDDEN; +//check display selection state. + if (!displaySelection) + return NS_OK; //if frame does not allow selection. do nothing + + + nsCOMPtr newContent; + result = mContent->GetParent(*getter_AddRefs(newContent)); + +//check to see if we are anonymouse content + PRInt32 offset; + if (NS_SUCCEEDED(result) && newContent){ + result = newContent->IndexOf(mContent, offset); + if (NS_FAILED(result)) + { return result; - PRInt16 displaySelection = displyNonTextSelection; - if (!displaySelection) - return NS_OK; - if (mContent) { - result = mContent->GetDocument(*getter_AddRefs(doc)); } + } - nsCOMPtr selCon; - result = GetSelectionController(aPresContext, getter_AddRefs(selCon)); - if (NS_FAILED(result) || !selCon) - return result? result:NS_ERROR_FAILURE; + SelectionDetails *details; + if (NS_SUCCEEDED(result) && shell){ - selCon->GetDisplaySelection(&displaySelection); - nsFrameState frameState; - PRBool isSelected; - GetFrameState(&frameState); - isSelected = (frameState & NS_FRAME_SELECTED_CONTENT) == NS_FRAME_SELECTED_CONTENT; -// PRInt32 selectionStartOffset = 0;//frame coordinates -// PRInt32 selectionEndOffset = 0;//frame coordinates - - if (!displaySelection || !isSelected) - return NS_OK; - - nsCOMPtr selection; nsCOMPtr frameSelection; - - nsCOMPtr newContent; - result = mContent->GetParent(*getter_AddRefs(newContent)); - - SelectionDetails *details; - PRInt32 offset; - if (NS_SUCCEEDED(result) && newContent){ - result = newContent->IndexOf(mContent, offset); - if (NS_FAILED(result)) - { - return result; - } + if (NS_SUCCEEDED(result) && selCon) + { + frameSelection = do_QueryInterface(selCon); //this MAY implement } - - if (NS_SUCCEEDED(result) && shell){ - - nsCOMPtr selCon; - result = GetSelectionController(aPresContext, getter_AddRefs(selCon)); - nsCOMPtr frameselection; - if (NS_SUCCEEDED(result) && selCon) - { - frameSelection = do_QueryInterface(selCon); //this MAY implement - } - if (!frameSelection) - result = shell->GetFrameSelection(getter_AddRefs(frameSelection)); - if (NS_SUCCEEDED(result) && frameSelection){ - result = frameSelection->LookUpSelection(newContent, offset, - 1, &details, PR_FALSE); - } + if (!frameSelection) + result = shell->GetFrameSelection(getter_AddRefs(frameSelection)); + if (NS_SUCCEEDED(result) && frameSelection){ + result = frameSelection->LookUpSelection(newContent, offset, + 1, &details, PR_FALSE);//look up to see what selection(s) are on this frame } - //} + } if (details) { nsRect rect; @@ -741,8 +738,6 @@ nsFrame::Paint(nsIPresContext* aPresContext, details = deletingDetails; } delete details; - //aRenderingContext.DrawLine(rect.x, rect.y, rect.XMost(), rect.YMost()); - //aRenderingContext.DrawLine(rect.x, rect.YMost(), rect.XMost(), rect.y); } return NS_OK; } @@ -972,10 +967,18 @@ nsFrame::HandlePress(nsIPresContext* aPresContext, { if (!IsMouseCaptured(aPresContext)) CaptureMouse(aPresContext, PR_TRUE); - if (DisplaySelection(aPresContext) == nsISelectionController::SELECTION_OFF) { - return NS_OK; + + PRInt16 displayresult = nsISelectionController::SELECTION_OFF; + nsresult rv; + nsCOMPtr selCon; + rv = GetSelectionController(aPresContext, getter_AddRefs(selCon)); + if (NS_SUCCEEDED(rv) && selCon) { + selCon->GetDisplaySelection(&displayresult); + if (displayresult == nsISelectionController::SELECTION_OFF) + return NS_OK;//nothing to do we cannot affect selection from here } + nsMouseEvent *me = (nsMouseEvent *)aEvent; if (me->clickCount >1 ) return HandleMultiplePress(aPresContext,aEvent,aEventStatus); @@ -986,7 +989,7 @@ nsFrame::HandlePress(nsIPresContext* aPresContext, if (!IsSelectable(this)) return NS_OK; nsCOMPtr shell; - nsresult rv = aPresContext->GetShell(getter_AddRefs(shell)); + rv = aPresContext->GetShell(getter_AddRefs(shell)); if (NS_SUCCEEDED(rv) && shell) { PRInt32 startPos = 0; // PRUint32 contentOffset = 0; @@ -1992,23 +1995,19 @@ nsFrame::GetSelectionController(nsIPresContext *aPresContext, nsISelectionContro nsIFrame *tmp = this; while ( NS_SUCCEEDED(tmp->GetParent(&tmp)) && tmp) { - tmp->GetFrameState(&state); - if (! (state & NS_FRAME_INDEPENDENT_SELECTION)) //we have found the nsGfx* + nsIGfxTextControlFrame2 *tcf; + if (NS_SUCCEEDED(tmp->QueryInterface(nsIGfxTextControlFrame2::GetIID(),(void**)&tcf))) { - nsFrame* castParent = NS_STATIC_CAST(nsFrame *,tmp); - return castParent->GetSelectionController(aPresContext, aSelCon); + return tcf->GetSelectionController(aSelCon); } } } - else + nsCOMPtr shell; + if (NS_SUCCEEDED(aPresContext->GetShell(getter_AddRefs(shell))) && shell) { - nsCOMPtr shell; - if (NS_SUCCEEDED(aPresContext->GetShell(getter_AddRefs(shell))) && shell) - { - nsCOMPtr selCon = do_QueryInterface(shell); - NS_IF_ADDREF(*aSelCon = selCon); - return NS_OK; - } + nsCOMPtr selCon = do_QueryInterface(shell); + NS_IF_ADDREF(*aSelCon = selCon); + return NS_OK; } return NS_OK; } diff --git a/mozilla/layout/generic/nsSelection.cpp b/mozilla/layout/generic/nsSelection.cpp index 3ba42a56132..10c49850732 100644 --- a/mozilla/layout/generic/nsSelection.cpp +++ b/mozilla/layout/generic/nsSelection.cpp @@ -111,6 +111,7 @@ class nsAutoScrollTimer; class nsDOMSelection : public nsIDOMSelection , public nsIScriptObjectOwner, public nsSupportsWeakReference { public: + nsDOMSelection(); nsDOMSelection(nsSelection *aList); virtual ~nsDOMSelection(); @@ -523,15 +524,21 @@ nsresult NS_NewSelection(nsIFrameSelection **aFrameSelection) if (!rlist) return NS_ERROR_OUT_OF_MEMORY; *aFrameSelection = (nsIFrameSelection *)rlist; - nsresult result = rlist->AddRef(); - if (!NS_SUCCEEDED(result)) - { - delete rlist; - } - return result; + rlist->AddRef(); + return NS_OK; } +nsresult NS_NewDomSelection(nsIDOMSelection **aDomSelection); +nsresult NS_NewDomSelection(nsIDOMSelection **aDomSelection) +{ + nsDOMSelection *rlist = new nsDOMSelection; + if (!rlist) + return NS_ERROR_OUT_OF_MEMORY; + *aDomSelection = (nsIDOMSelection *)rlist; + rlist->AddRef(); + return NS_OK; +} //Horrible statics but no choice nsIAtom *nsSelection::sTableAtom = 0; @@ -781,12 +788,12 @@ nsSelection::nsSelection() if (mDomSelections[index]) autoCopyService->Listen(mDomSelections[index]); } - mDisplaySelection = nsISelectionController::SELECTION_ON; + mDisplaySelection = nsISelectionController::SELECTION_OFF; } -nsSelection::~nsSelection() +nsSelection::~nsSelection() { if (sInstanceCount <= 1) { @@ -1608,10 +1615,8 @@ nsSelection::TakeFocus(nsIContent *aNewFocus, PRUint32 aContentOffset, nsCOMPtr parent2; if (NS_FAILED(aNewFocus->GetParent(*getter_AddRefs(parent))) || !parent) return NS_ERROR_FAILURE; - //if (NS_FAILED(parent->GetParent(*getter_AddRefs(parent2))) || !parent2) - //return NS_ERROR_FAILURE; - //END HACKHACKHACK /checking for root frames/content + PRInt8 index = GetIndexFromSelectionType(nsISelectionController::SELECTION_NORMAL); domNode = do_QueryInterface(aNewFocus); //traverse through document and unselect crap here @@ -1688,7 +1693,7 @@ nsSelection::SetMouseDownState(PRBool aState) mSelectingTableCells = PR_FALSE; mStartSelectedCell = nsnull; mEndSelectedCell = nsnull; - NotifySelectionListeners(nsISelectionController::SELECTION_NORMAL); + //NotifySelectionListeners(nsISelectionController::SELECTION_NORMAL); } return NS_OK; } @@ -2625,6 +2630,18 @@ nsDOMSelection::nsDOMSelection(nsSelection *aList) } +nsDOMSelection::nsDOMSelection() +{ + mFixupState = PR_FALSE; + mDirection = eDirNext; + NS_NewISupportsArray(getter_AddRefs(mRangeArray)); + mScriptObject = nsnull; + mAutoScrollTimer = nsnull; + NS_NewISupportsArray(getter_AddRefs(mSelectionListeners)); + NS_INIT_REFCNT(); +} + + nsDOMSelection::~nsDOMSelection() { @@ -2986,7 +3003,7 @@ nsDOMSelection::GetPrimaryFrameForAnchorNode(nsIFrame **aReturnFrame) PRInt32 frameOffset = 0; *aReturnFrame = 0; nsCOMPtr content = do_QueryInterface(FetchAnchorNode()); - if (content) + if (content && mFrameSelection) return mFrameSelection->GetFrameForNodeOffset(content, FetchAnchorOffset(),aReturnFrame, &frameOffset); return NS_ERROR_FAILURE; } @@ -3001,7 +3018,7 @@ nsDOMSelection::GetPrimaryFrameForFocusNode(nsIFrame **aReturnFrame) *aReturnFrame = 0; nsCOMPtr content = do_QueryInterface(FetchFocusNode()); - if (content) + if (content && mFrameSelection) return mFrameSelection->GetFrameForNodeOffset(content, FetchFocusOffset(),aReturnFrame, &frameOffset); return NS_ERROR_FAILURE; } @@ -3017,6 +3034,8 @@ nsDOMSelection::selectFrames(nsIPresContext* aPresContext, nsIPresShell *aPresShell, PRBool aFlags) { + if (!mFrameSelection) + return NS_OK;//nothing to do nsresult result; nsCOMPtr genericiter = do_QueryInterface(aInnerIter); if (genericiter && aPresShell) @@ -3065,6 +3084,8 @@ nsDOMSelection::selectFrames(nsIPresContext* aPresContext, NS_IMETHODIMP nsDOMSelection::selectFrames(nsIPresContext* aPresContext, nsIDOMRange *aRange, PRBool aFlags) { + if (!mFrameSelection) + return NS_OK;//nothing to do if (!aRange || !aPresContext) return NS_ERROR_NULL_POINTER; nsCOMPtr iter; @@ -3314,6 +3335,8 @@ nsresult nsDOMSelection::StartAutoScrollTimer(nsIPresContext *aPresContext, nsIFrame *aFrame, nsPoint& aPoint, PRUint32 aDelay) { nsresult result; + if (!mFrameSelection) + return NS_OK;//nothing to do if (!mAutoScrollTimer) { @@ -3572,6 +3595,8 @@ nsDOMSelection::GetEnumerator(nsIEnumerator **aIterator) NS_IMETHODIMP nsDOMSelection::ClearSelection() { + if (!mFrameSelection) + return NS_OK;//nothing to do nsCOMPtr presContext; GetPresContext(getter_AddRefs(presContext)); @@ -3608,7 +3633,8 @@ nsDOMSelection::AddRange(nsIDOMRange* aRange) GetPresContext(getter_AddRefs(presContext)); selectFrames(presContext, aRange, PR_TRUE); //ScrollIntoView(); this should not happen automatically - + if (!mFrameSelection) + return NS_OK;//nothing to do return mFrameSelection->NotifySelectionListeners(GetType()); } @@ -3632,6 +3658,8 @@ nsDOMSelection::RemoveRange(nsIDOMRange* aRange) ScrollIntoView(); } } + if (!mFrameSelection) + return NS_OK;//nothing to do return mFrameSelection->NotifySelectionListeners(GetType()); } @@ -3695,7 +3723,8 @@ nsDOMSelection::Collapse(nsIDOMNode* aParentNode, PRInt32 aOffset) selectFrames(presContext, range,PR_TRUE); if (NS_FAILED(result)) return result; - + if (!mFrameSelection) + return NS_OK;//nothing to do return mFrameSelection->NotifySelectionListeners(GetType()); } @@ -4503,6 +4532,8 @@ nsDOMSelection::Extend(nsIDOMNode* aParentNode, PRInt32 aOffset) printf ("Sel. Extend set to null parent.\n"); } #endif + if (!mFrameSelection) + return NS_OK;//nothing to do return mFrameSelection->NotifySelectionListeners(GetType()); } @@ -4572,6 +4603,8 @@ nsDOMSelection::ContainsNode(nsIDOMNode* aNode, PRBool aRecursive, PRBool* aYes) nsresult nsDOMSelection::GetPresContext(nsIPresContext **aPresContext) { + if (!mFrameSelection) + return NS_ERROR_FAILURE;//nothing to do nsIFocusTracker *tracker = mFrameSelection->GetTracker(); if (!tracker) @@ -4584,6 +4617,8 @@ nsresult nsDOMSelection::GetPresShell(nsIPresShell **aPresShell) { nsresult rv = NS_OK; + if (!mFrameSelection) + return NS_ERROR_FAILURE;//nothing to do nsIFocusTracker *tracker = mFrameSelection->GetTracker(); @@ -4614,6 +4649,8 @@ nsDOMSelection::GetRootScrollableView(nsIScrollableView **aScrollableView) // NOTE: This method returns a NON-AddRef'd pointer // to the scrollable view! // + if (!mFrameSelection) + return NS_ERROR_FAILURE;//nothing to do nsresult rv = NS_OK; @@ -4648,6 +4685,8 @@ nsresult nsDOMSelection::GetFrameToRootViewOffset(nsIFrame *aFrame, nscoord *aX, nscoord *aY) { nsresult rv = NS_OK; + if (!mFrameSelection) + return NS_ERROR_FAILURE;//nothing to do if (!aFrame || !aX || !aY) { return NS_ERROR_NULL_POINTER; @@ -4705,6 +4744,8 @@ nsresult nsDOMSelection::GetPointFromOffset(nsIFrame *aFrame, PRInt32 aContentOffset, nsPoint *aPoint) { nsresult rv = NS_OK; + if (!mFrameSelection) + return NS_ERROR_FAILURE;//nothing to do if (!aFrame || !aPoint) return NS_ERROR_NULL_POINTER; @@ -4800,6 +4841,8 @@ nsresult nsDOMSelection::GetSelectionRegionRect(SelectionRegion aRegion, nsRect *aRect) { nsresult result = NS_OK; + if (!mFrameSelection) + return NS_ERROR_FAILURE;//nothing to do if (!aRect) return NS_ERROR_NULL_POINTER; @@ -4976,6 +5019,8 @@ nsDOMSelection::ScrollRectIntoView(nsRect& aRect, PRIntn aHPercent) { nsresult rv = NS_OK; + if (!mFrameSelection) + return NS_OK;//nothing to do nsIScrollableView *scrollingView = 0; @@ -5052,6 +5097,8 @@ NS_IMETHODIMP nsDOMSelection::ScrollIntoView(SelectionRegion aRegion) { nsresult result; + if (!mFrameSelection) + return NS_OK;//nothing to do if (mFrameSelection->GetBatching()) return NS_OK; @@ -5119,6 +5166,8 @@ nsDOMSelection::NotifySelectionListeners() { if (!mSelectionListeners) return NS_ERROR_FAILURE; + if (!mFrameSelection) + return NS_OK;//nothing to do if (mFrameSelection->GetBatching()){ mFrameSelection->SetDirty(); @@ -5152,6 +5201,8 @@ nsDOMSelection::NotifySelectionListeners() NS_IMETHODIMP nsDOMSelection::StartBatchChanges() { + if (!mFrameSelection) + return NS_OK;//nothing to do return mFrameSelection->StartBatchChanges(); } @@ -5160,6 +5211,8 @@ nsDOMSelection::StartBatchChanges() NS_IMETHODIMP nsDOMSelection::EndBatchChanges() { + if (!mFrameSelection) + return NS_OK;//nothing to do return mFrameSelection->EndBatchChanges(); } @@ -5168,6 +5221,8 @@ nsDOMSelection::EndBatchChanges() NS_IMETHODIMP nsDOMSelection::DeleteFromDocument() { + if (!mFrameSelection) + return NS_OK;//nothing to do return mFrameSelection->DeleteFromDocument(); } diff --git a/mozilla/layout/generic/nsTextFrame.cpp b/mozilla/layout/generic/nsTextFrame.cpp index 8d0cd2fbb04..58ba05e5893 100644 --- a/mozilla/layout/generic/nsTextFrame.cpp +++ b/mozilla/layout/generic/nsTextFrame.cpp @@ -1027,7 +1027,7 @@ DrawSelectionIterator::CurrentForeGroundColor() PRBool DrawSelectionIterator::CurrentBackGroundColor(nscolor &aColor) -{ +{ //Find color based on mTypes[mCurrentIdx]; if (!mTypes) { @@ -1750,12 +1750,13 @@ nsTextFrame::PaintUnicodeText(nsIPresContext* aPresContext, if (NS_FAILED(rv) || !shell) return; nsCOMPtr selCon; - selCon = do_QueryInterface(shell, &rv); + rv = GetSelectionController(aPresContext, getter_AddRefs(selCon)); if (NS_FAILED(rv) || !selCon) return; - PRInt16 displaySelection; - selCon->GetDisplaySelection(&displaySelection); + PRInt16 selectionValue; + selCon->GetDisplaySelection(&selectionValue); + PRBool displaySelection = selectionValue > nsISelectionController::SELECTION_HIDDEN; // Make enough space to transform nsAutoTextBuffer paintBuffer; @@ -1838,7 +1839,7 @@ nsTextFrame::PaintUnicodeText(nsIPresContext* aPresContext, } //while we have substrings... PRBool drawn = PR_FALSE; - DrawSelectionIterator iter(details,text,(PRUint32)textLength,aTextStyle, displaySelection); + DrawSelectionIterator iter(details,text,(PRUint32)textLength,aTextStyle, selectionValue); if (!iter.IsDone() && iter.First()) { nscoord currentX = dx; @@ -2275,12 +2276,13 @@ nsTextFrame::PaintTextSlowly(nsIPresContext* aPresContext, if (NS_FAILED(rv) || !shell) return; nsCOMPtr selCon; - selCon = do_QueryInterface(shell, &rv); + rv = GetSelectionController(aPresContext, getter_AddRefs(selCon)); if (NS_FAILED(rv) || !selCon) return; - PRInt16 displaySelection; - selCon->GetDisplaySelection(&displaySelection); + PRInt16 selectionValue; + selCon->GetDisplaySelection(&selectionValue); + PRBool displaySelection = selectionValue > nsISelectionController::SELECTION_HIDDEN; // Make enough space to transform @@ -2356,7 +2358,7 @@ nsTextFrame::PaintTextSlowly(nsIPresContext* aPresContext, sdptr = sdptr->mNext; } - DrawSelectionIterator iter(details,text,(PRUint32)textLength,aTextStyle, displaySelection); + DrawSelectionIterator iter(details,text,(PRUint32)textLength,aTextStyle, selectionValue); if (!iter.IsDone() && iter.First()) { nscoord currentX = dx; @@ -2421,13 +2423,14 @@ nsTextFrame::PaintAsciiText(nsIPresContext* aPresContext, if (NS_FAILED(rv) || !shell) return; nsCOMPtr selCon; - selCon = do_QueryInterface(shell, &rv); + rv = GetSelectionController(aPresContext, getter_AddRefs(selCon)); if (NS_FAILED(rv) || !selCon) return; - PRInt16 displaySelection; + PRInt16 selectionValue; PRBool isSelected; - selCon->GetDisplaySelection(&displaySelection); + selCon->GetDisplaySelection(&selectionValue); + PRBool displaySelection = selectionValue > nsISelectionController::SELECTION_HIDDEN; isSelected = (mState & NS_FRAME_SELECTED_CONTENT) == NS_FRAME_SELECTED_CONTENT; @@ -2562,7 +2565,7 @@ nsTextFrame::PaintAsciiText(nsIPresContext* aPresContext, sdptr->mEnd = ip[sdptr->mEnd] - mContentOffset; sdptr = sdptr->mNext; } - DrawSelectionIterator iter(details,(PRUnichar *)text,(PRUint32)textLength,aTextStyle, displaySelection);//ITS OK TO CAST HERE THE RESULT WE USE WILLNOT DO BAD CONVERSION + DrawSelectionIterator iter(details,(PRUnichar *)text,(PRUint32)textLength,aTextStyle, selectionValue);//ITS OK TO CAST HERE THE RESULT WE USE WILLNOT DO BAD CONVERSION if (!iter.IsDone() && iter.First()) { nscoord currentX = dx; @@ -3420,9 +3423,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; + nsCOMPtr selCon; + rv = GetSelectionController(aPresContext, getter_AddRefs(selCon)); + if (NS_FAILED(rv) || !selCon) + return rv?rv:NS_ERROR_FAILURE; if (me->clickCount > 2)//triple clicking { nsCOMPtr mPrefs; diff --git a/mozilla/layout/html/base/src/nsBlockFrame.cpp b/mozilla/layout/html/base/src/nsBlockFrame.cpp index 715bec5166e..02810662a8b 100644 --- a/mozilla/layout/html/base/src/nsBlockFrame.cpp +++ b/mozilla/layout/html/base/src/nsBlockFrame.cpp @@ -6307,17 +6307,17 @@ nsBlockFrame::HandleEvent(nsIPresContext* aPresContext, nsGUIEvent* aEvent, nsEventStatus* aEventStatus) { + + nsresult result; if (aEvent->message == NS_MOUSE_MOVE) { - nsCOMPtr shell; - nsresult rv = aPresContext->GetShell(getter_AddRefs(shell)); - if (NS_SUCCEEDED(rv)){ - nsCOMPtr frameselection; - if (NS_SUCCEEDED(shell->GetFrameSelection(getter_AddRefs(frameselection))) && frameselection){ - PRBool mouseDown = PR_FALSE; - if (NS_FAILED(frameselection->GetMouseDownState(&mouseDown)) || !mouseDown) - return NS_OK;//do not handle - } - } + nsCOMPtr selCon; + result = GetSelectionController(aPresContext, getter_AddRefs(selCon)); + if (NS_FAILED(result) || !selCon) + return result?result:NS_ERROR_FAILURE; + nsCOMPtr frameSelection = do_QueryInterface(selCon); + PRBool mouseDown = PR_FALSE; + if (!frameSelection || NS_FAILED(frameSelection->GetMouseDownState(&mouseDown)) || !mouseDown) + return NS_OK;//do not handle } if (aEvent->message == NS_MOUSE_LEFT_BUTTON_DOWN || aEvent->message == NS_MOUSE_MOVE || @@ -6330,7 +6330,6 @@ nsBlockFrame::HandleEvent(nsIPresContext* aPresContext, CaptureMouse(aPresContext, PR_TRUE); } - nsresult result; nsIFrame *resultFrame = nsnull;//this will be passed the handle event when we //can tell who to pass it to nsCOMPtr it; diff --git a/mozilla/layout/html/base/src/nsBlockReflowState.cpp b/mozilla/layout/html/base/src/nsBlockReflowState.cpp index 715bec5166e..02810662a8b 100644 --- a/mozilla/layout/html/base/src/nsBlockReflowState.cpp +++ b/mozilla/layout/html/base/src/nsBlockReflowState.cpp @@ -6307,17 +6307,17 @@ nsBlockFrame::HandleEvent(nsIPresContext* aPresContext, nsGUIEvent* aEvent, nsEventStatus* aEventStatus) { + + nsresult result; if (aEvent->message == NS_MOUSE_MOVE) { - nsCOMPtr shell; - nsresult rv = aPresContext->GetShell(getter_AddRefs(shell)); - if (NS_SUCCEEDED(rv)){ - nsCOMPtr frameselection; - if (NS_SUCCEEDED(shell->GetFrameSelection(getter_AddRefs(frameselection))) && frameselection){ - PRBool mouseDown = PR_FALSE; - if (NS_FAILED(frameselection->GetMouseDownState(&mouseDown)) || !mouseDown) - return NS_OK;//do not handle - } - } + nsCOMPtr selCon; + result = GetSelectionController(aPresContext, getter_AddRefs(selCon)); + if (NS_FAILED(result) || !selCon) + return result?result:NS_ERROR_FAILURE; + nsCOMPtr frameSelection = do_QueryInterface(selCon); + PRBool mouseDown = PR_FALSE; + if (!frameSelection || NS_FAILED(frameSelection->GetMouseDownState(&mouseDown)) || !mouseDown) + return NS_OK;//do not handle } if (aEvent->message == NS_MOUSE_LEFT_BUTTON_DOWN || aEvent->message == NS_MOUSE_MOVE || @@ -6330,7 +6330,6 @@ nsBlockFrame::HandleEvent(nsIPresContext* aPresContext, CaptureMouse(aPresContext, PR_TRUE); } - nsresult result; nsIFrame *resultFrame = nsnull;//this will be passed the handle event when we //can tell who to pass it to nsCOMPtr it; diff --git a/mozilla/layout/html/base/src/nsBlockReflowState.h b/mozilla/layout/html/base/src/nsBlockReflowState.h index 715bec5166e..02810662a8b 100644 --- a/mozilla/layout/html/base/src/nsBlockReflowState.h +++ b/mozilla/layout/html/base/src/nsBlockReflowState.h @@ -6307,17 +6307,17 @@ nsBlockFrame::HandleEvent(nsIPresContext* aPresContext, nsGUIEvent* aEvent, nsEventStatus* aEventStatus) { + + nsresult result; if (aEvent->message == NS_MOUSE_MOVE) { - nsCOMPtr shell; - nsresult rv = aPresContext->GetShell(getter_AddRefs(shell)); - if (NS_SUCCEEDED(rv)){ - nsCOMPtr frameselection; - if (NS_SUCCEEDED(shell->GetFrameSelection(getter_AddRefs(frameselection))) && frameselection){ - PRBool mouseDown = PR_FALSE; - if (NS_FAILED(frameselection->GetMouseDownState(&mouseDown)) || !mouseDown) - return NS_OK;//do not handle - } - } + nsCOMPtr selCon; + result = GetSelectionController(aPresContext, getter_AddRefs(selCon)); + if (NS_FAILED(result) || !selCon) + return result?result:NS_ERROR_FAILURE; + nsCOMPtr frameSelection = do_QueryInterface(selCon); + PRBool mouseDown = PR_FALSE; + if (!frameSelection || NS_FAILED(frameSelection->GetMouseDownState(&mouseDown)) || !mouseDown) + return NS_OK;//do not handle } if (aEvent->message == NS_MOUSE_LEFT_BUTTON_DOWN || aEvent->message == NS_MOUSE_MOVE || @@ -6330,7 +6330,6 @@ nsBlockFrame::HandleEvent(nsIPresContext* aPresContext, CaptureMouse(aPresContext, PR_TRUE); } - nsresult result; nsIFrame *resultFrame = nsnull;//this will be passed the handle event when we //can tell who to pass it to nsCOMPtr it; diff --git a/mozilla/layout/html/base/src/nsFrame.cpp b/mozilla/layout/html/base/src/nsFrame.cpp index e200e031dcd..41049871c8f 100644 --- a/mozilla/layout/html/base/src/nsFrame.cpp +++ b/mozilla/layout/html/base/src/nsFrame.cpp @@ -60,6 +60,8 @@ #include "nsIDOMRange.h" #include "nsITableLayout.h" //selection neccesity #include "nsITableCellLayout.h"// " +#include "nsIGfxTextControlFrame.h" + // Some Misc #defines @@ -654,76 +656,71 @@ nsFrame::Paint(nsIPresContext* aPresContext, const nsRect& aDirtyRect, nsFramePaintLayer aWhichLayer) { - //if (NS_FRAME_PAINT_LAYER_FOREGROUND == aWhichLayer) { -/** GetDocument -*/ - nsCOMPtr doc; - nsresult result; - nsCOMPtr shell; - result = aPresContext->GetShell(getter_AddRefs(shell)); - if (NS_FAILED(result)) - return result; + nsCOMPtr doc; + nsresult result; + nsCOMPtr shell; + result = aPresContext->GetShell(getter_AddRefs(shell)); + if (NS_FAILED(result)) + return result; - PRBool displyNonTextSelection = PR_TRUE; - result = shell->GetDisplayNonTextSelection(&displyNonTextSelection); - if (NS_FAILED(result)) + PRBool displaySelection = PR_TRUE; + result = shell->GetDisplayNonTextSelection(&displaySelection); + if (NS_FAILED(result)) + return result; + if (!displaySelection) + return NS_OK; + if (mContent) { + result = mContent->GetDocument(*getter_AddRefs(doc)); + } + +//check frame selection state + PRBool isSelected; + nsFrameState frameState; + GetFrameState(&frameState); + isSelected = (frameState & NS_FRAME_SELECTED_CONTENT) == NS_FRAME_SELECTED_CONTENT; +//if not selected then return + if (!isSelected) + return NS_OK; //nothing to do + +//get the selection controller + nsCOMPtr selCon; + result = GetSelectionController(aPresContext, getter_AddRefs(selCon)); + PRInt16 selectionValue; + selCon->GetDisplaySelection(&selectionValue); + displaySelection = selectionValue > nsISelectionController::SELECTION_HIDDEN; +//check display selection state. + if (!displaySelection) + return NS_OK; //if frame does not allow selection. do nothing + + + nsCOMPtr newContent; + result = mContent->GetParent(*getter_AddRefs(newContent)); + +//check to see if we are anonymouse content + PRInt32 offset; + if (NS_SUCCEEDED(result) && newContent){ + result = newContent->IndexOf(mContent, offset); + if (NS_FAILED(result)) + { return result; - PRInt16 displaySelection = displyNonTextSelection; - if (!displaySelection) - return NS_OK; - if (mContent) { - result = mContent->GetDocument(*getter_AddRefs(doc)); } + } - nsCOMPtr selCon; - result = GetSelectionController(aPresContext, getter_AddRefs(selCon)); - if (NS_FAILED(result) || !selCon) - return result? result:NS_ERROR_FAILURE; + SelectionDetails *details; + if (NS_SUCCEEDED(result) && shell){ - selCon->GetDisplaySelection(&displaySelection); - nsFrameState frameState; - PRBool isSelected; - GetFrameState(&frameState); - isSelected = (frameState & NS_FRAME_SELECTED_CONTENT) == NS_FRAME_SELECTED_CONTENT; -// PRInt32 selectionStartOffset = 0;//frame coordinates -// PRInt32 selectionEndOffset = 0;//frame coordinates - - if (!displaySelection || !isSelected) - return NS_OK; - - nsCOMPtr selection; nsCOMPtr frameSelection; - - nsCOMPtr newContent; - result = mContent->GetParent(*getter_AddRefs(newContent)); - - SelectionDetails *details; - PRInt32 offset; - if (NS_SUCCEEDED(result) && newContent){ - result = newContent->IndexOf(mContent, offset); - if (NS_FAILED(result)) - { - return result; - } + if (NS_SUCCEEDED(result) && selCon) + { + frameSelection = do_QueryInterface(selCon); //this MAY implement } - - if (NS_SUCCEEDED(result) && shell){ - - nsCOMPtr selCon; - result = GetSelectionController(aPresContext, getter_AddRefs(selCon)); - nsCOMPtr frameselection; - if (NS_SUCCEEDED(result) && selCon) - { - frameSelection = do_QueryInterface(selCon); //this MAY implement - } - if (!frameSelection) - result = shell->GetFrameSelection(getter_AddRefs(frameSelection)); - if (NS_SUCCEEDED(result) && frameSelection){ - result = frameSelection->LookUpSelection(newContent, offset, - 1, &details, PR_FALSE); - } + if (!frameSelection) + result = shell->GetFrameSelection(getter_AddRefs(frameSelection)); + if (NS_SUCCEEDED(result) && frameSelection){ + result = frameSelection->LookUpSelection(newContent, offset, + 1, &details, PR_FALSE);//look up to see what selection(s) are on this frame } - //} + } if (details) { nsRect rect; @@ -741,8 +738,6 @@ nsFrame::Paint(nsIPresContext* aPresContext, details = deletingDetails; } delete details; - //aRenderingContext.DrawLine(rect.x, rect.y, rect.XMost(), rect.YMost()); - //aRenderingContext.DrawLine(rect.x, rect.YMost(), rect.XMost(), rect.y); } return NS_OK; } @@ -972,10 +967,18 @@ nsFrame::HandlePress(nsIPresContext* aPresContext, { if (!IsMouseCaptured(aPresContext)) CaptureMouse(aPresContext, PR_TRUE); - if (DisplaySelection(aPresContext) == nsISelectionController::SELECTION_OFF) { - return NS_OK; + + PRInt16 displayresult = nsISelectionController::SELECTION_OFF; + nsresult rv; + nsCOMPtr selCon; + rv = GetSelectionController(aPresContext, getter_AddRefs(selCon)); + if (NS_SUCCEEDED(rv) && selCon) { + selCon->GetDisplaySelection(&displayresult); + if (displayresult == nsISelectionController::SELECTION_OFF) + return NS_OK;//nothing to do we cannot affect selection from here } + nsMouseEvent *me = (nsMouseEvent *)aEvent; if (me->clickCount >1 ) return HandleMultiplePress(aPresContext,aEvent,aEventStatus); @@ -986,7 +989,7 @@ nsFrame::HandlePress(nsIPresContext* aPresContext, if (!IsSelectable(this)) return NS_OK; nsCOMPtr shell; - nsresult rv = aPresContext->GetShell(getter_AddRefs(shell)); + rv = aPresContext->GetShell(getter_AddRefs(shell)); if (NS_SUCCEEDED(rv) && shell) { PRInt32 startPos = 0; // PRUint32 contentOffset = 0; @@ -1992,23 +1995,19 @@ nsFrame::GetSelectionController(nsIPresContext *aPresContext, nsISelectionContro nsIFrame *tmp = this; while ( NS_SUCCEEDED(tmp->GetParent(&tmp)) && tmp) { - tmp->GetFrameState(&state); - if (! (state & NS_FRAME_INDEPENDENT_SELECTION)) //we have found the nsGfx* + nsIGfxTextControlFrame2 *tcf; + if (NS_SUCCEEDED(tmp->QueryInterface(nsIGfxTextControlFrame2::GetIID(),(void**)&tcf))) { - nsFrame* castParent = NS_STATIC_CAST(nsFrame *,tmp); - return castParent->GetSelectionController(aPresContext, aSelCon); + return tcf->GetSelectionController(aSelCon); } } } - else + nsCOMPtr shell; + if (NS_SUCCEEDED(aPresContext->GetShell(getter_AddRefs(shell))) && shell) { - nsCOMPtr shell; - if (NS_SUCCEEDED(aPresContext->GetShell(getter_AddRefs(shell))) && shell) - { - nsCOMPtr selCon = do_QueryInterface(shell); - NS_IF_ADDREF(*aSelCon = selCon); - return NS_OK; - } + nsCOMPtr selCon = do_QueryInterface(shell); + NS_IF_ADDREF(*aSelCon = selCon); + return NS_OK; } return NS_OK; } diff --git a/mozilla/layout/html/base/src/nsPresShell.cpp b/mozilla/layout/html/base/src/nsPresShell.cpp index 206444018ee..b7285af7554 100644 --- a/mozilla/layout/html/base/src/nsPresShell.cpp +++ b/mozilla/layout/html/base/src/nsPresShell.cpp @@ -651,10 +651,11 @@ public: NS_IMETHOD ScrollFrameIntoView(nsIFrame *aFrame); // caret handling NS_IMETHOD GetCaret(nsICaret **aOutCaret); - NS_IMETHOD SetCaretEnabled(PRBool aaInEnable); + NS_IMETHOD SetCaretEnabled(PRBool aInEnable); + NS_IMETHOD SetCaretReadOnly(PRBool aReadOnly); NS_IMETHOD GetCaretEnabled(PRBool *aOutEnabled); - NS_IMETHOD SetDisplayNonTextSelection(PRBool aaInEnable); + NS_IMETHOD SetDisplayNonTextSelection(PRBool aInEnable); NS_IMETHOD GetDisplayNonTextSelection(PRBool *aOutEnable); // nsISelectionController @@ -1772,17 +1773,30 @@ NS_IMETHODIMP PresShell::SetCaretEnabled(PRBool aInEnable) if (mCaret && (mCaretEnabled != oldEnabled)) { // Update the document's content and frame models. - if (mDocument) mDocument->FlushPendingNotifications(); + if (mDocument) + mDocument->FlushPendingNotifications(); - if (mCaretEnabled) - result = mCaret->SetCaretVisible(PR_TRUE); - else - result = mCaret->SetCaretVisible(PR_FALSE); + nsCOMPtr sel; + if (NS_SUCCEEDED(GetSelection(nsISelectionController::SELECTION_NORMAL, getter_AddRefs(sel))) && sel) + { + result = mCaret->SetCaretVisible(mCaretEnabled, sel); + } } return result; } + +NS_IMETHODIMP PresShell::SetCaretReadOnly(PRBool aReadOnly) +{ + nsCOMPtr domSel; + if (NS_SUCCEEDED(GetSelection(nsISelectionController::SELECTION_NORMAL, getter_AddRefs(domSel))) && domSel) + { + return mCaret->SetCaretReadOnly(aReadOnly, domSel); + } + return NS_ERROR_FAILURE; +} + NS_IMETHODIMP PresShell::GetCaretEnabled(PRBool *aOutEnabled) { if (!aOutEnabled) { return NS_ERROR_INVALID_ARG; } diff --git a/mozilla/layout/html/base/src/nsTextFrame.cpp b/mozilla/layout/html/base/src/nsTextFrame.cpp index 8d0cd2fbb04..58ba05e5893 100644 --- a/mozilla/layout/html/base/src/nsTextFrame.cpp +++ b/mozilla/layout/html/base/src/nsTextFrame.cpp @@ -1027,7 +1027,7 @@ DrawSelectionIterator::CurrentForeGroundColor() PRBool DrawSelectionIterator::CurrentBackGroundColor(nscolor &aColor) -{ +{ //Find color based on mTypes[mCurrentIdx]; if (!mTypes) { @@ -1750,12 +1750,13 @@ nsTextFrame::PaintUnicodeText(nsIPresContext* aPresContext, if (NS_FAILED(rv) || !shell) return; nsCOMPtr selCon; - selCon = do_QueryInterface(shell, &rv); + rv = GetSelectionController(aPresContext, getter_AddRefs(selCon)); if (NS_FAILED(rv) || !selCon) return; - PRInt16 displaySelection; - selCon->GetDisplaySelection(&displaySelection); + PRInt16 selectionValue; + selCon->GetDisplaySelection(&selectionValue); + PRBool displaySelection = selectionValue > nsISelectionController::SELECTION_HIDDEN; // Make enough space to transform nsAutoTextBuffer paintBuffer; @@ -1838,7 +1839,7 @@ nsTextFrame::PaintUnicodeText(nsIPresContext* aPresContext, } //while we have substrings... PRBool drawn = PR_FALSE; - DrawSelectionIterator iter(details,text,(PRUint32)textLength,aTextStyle, displaySelection); + DrawSelectionIterator iter(details,text,(PRUint32)textLength,aTextStyle, selectionValue); if (!iter.IsDone() && iter.First()) { nscoord currentX = dx; @@ -2275,12 +2276,13 @@ nsTextFrame::PaintTextSlowly(nsIPresContext* aPresContext, if (NS_FAILED(rv) || !shell) return; nsCOMPtr selCon; - selCon = do_QueryInterface(shell, &rv); + rv = GetSelectionController(aPresContext, getter_AddRefs(selCon)); if (NS_FAILED(rv) || !selCon) return; - PRInt16 displaySelection; - selCon->GetDisplaySelection(&displaySelection); + PRInt16 selectionValue; + selCon->GetDisplaySelection(&selectionValue); + PRBool displaySelection = selectionValue > nsISelectionController::SELECTION_HIDDEN; // Make enough space to transform @@ -2356,7 +2358,7 @@ nsTextFrame::PaintTextSlowly(nsIPresContext* aPresContext, sdptr = sdptr->mNext; } - DrawSelectionIterator iter(details,text,(PRUint32)textLength,aTextStyle, displaySelection); + DrawSelectionIterator iter(details,text,(PRUint32)textLength,aTextStyle, selectionValue); if (!iter.IsDone() && iter.First()) { nscoord currentX = dx; @@ -2421,13 +2423,14 @@ nsTextFrame::PaintAsciiText(nsIPresContext* aPresContext, if (NS_FAILED(rv) || !shell) return; nsCOMPtr selCon; - selCon = do_QueryInterface(shell, &rv); + rv = GetSelectionController(aPresContext, getter_AddRefs(selCon)); if (NS_FAILED(rv) || !selCon) return; - PRInt16 displaySelection; + PRInt16 selectionValue; PRBool isSelected; - selCon->GetDisplaySelection(&displaySelection); + selCon->GetDisplaySelection(&selectionValue); + PRBool displaySelection = selectionValue > nsISelectionController::SELECTION_HIDDEN; isSelected = (mState & NS_FRAME_SELECTED_CONTENT) == NS_FRAME_SELECTED_CONTENT; @@ -2562,7 +2565,7 @@ nsTextFrame::PaintAsciiText(nsIPresContext* aPresContext, sdptr->mEnd = ip[sdptr->mEnd] - mContentOffset; sdptr = sdptr->mNext; } - DrawSelectionIterator iter(details,(PRUnichar *)text,(PRUint32)textLength,aTextStyle, displaySelection);//ITS OK TO CAST HERE THE RESULT WE USE WILLNOT DO BAD CONVERSION + DrawSelectionIterator iter(details,(PRUnichar *)text,(PRUint32)textLength,aTextStyle, selectionValue);//ITS OK TO CAST HERE THE RESULT WE USE WILLNOT DO BAD CONVERSION if (!iter.IsDone() && iter.First()) { nscoord currentX = dx; @@ -3420,9 +3423,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; + nsCOMPtr selCon; + rv = GetSelectionController(aPresContext, getter_AddRefs(selCon)); + if (NS_FAILED(rv) || !selCon) + return rv?rv:NS_ERROR_FAILURE; if (me->clickCount > 2)//triple clicking { nsCOMPtr mPrefs; diff --git a/mozilla/layout/html/content/src/nsHTMLInputElement.cpp b/mozilla/layout/html/content/src/nsHTMLInputElement.cpp index 33a669927d1..26bf774fff6 100644 --- a/mozilla/layout/html/content/src/nsHTMLInputElement.cpp +++ b/mozilla/layout/html/content/src/nsHTMLInputElement.cpp @@ -1132,7 +1132,7 @@ nsHTMLInputElement::GetTextLength(PRInt32* aTextLength) nsresult rv = nsGenericHTMLElement::GetPrimaryFrame(this, formControlFrame); if (NS_SUCCEEDED(rv) && formControlFrame) { - nsCOMPtr textControlFrame(do_QueryInterface(formControlFrame)); + nsCOMPtr textControlFrame(do_QueryInterface(formControlFrame)); if (textControlFrame) textControlFrame->GetTextLength(aTextLength); @@ -1148,7 +1148,7 @@ nsHTMLInputElement::SetSelectionRange(PRInt32 aSelectionStart, PRInt32 aSelectio nsresult rv = nsGenericHTMLElement::GetPrimaryFrame(this, formControlFrame); if (NS_SUCCEEDED(rv) && formControlFrame) { - nsCOMPtr textControlFrame(do_QueryInterface(formControlFrame)); + nsCOMPtr textControlFrame(do_QueryInterface(formControlFrame)); if (textControlFrame) textControlFrame->SetSelectionRange(aSelectionStart, aSelectionEnd); @@ -1173,7 +1173,7 @@ nsHTMLInputElement::SetSelectionStart(PRInt32 aSelectionStart) nsresult rv = nsGenericHTMLElement::GetPrimaryFrame(this, formControlFrame); if (NS_SUCCEEDED(rv) && formControlFrame) { - nsCOMPtr textControlFrame(do_QueryInterface(formControlFrame)); + nsCOMPtr textControlFrame(do_QueryInterface(formControlFrame)); if (textControlFrame) textControlFrame->SetSelectionStart(aSelectionStart); @@ -1199,7 +1199,7 @@ nsHTMLInputElement::SetSelectionEnd(PRInt32 aSelectionEnd) nsresult rv = nsGenericHTMLElement::GetPrimaryFrame(this, formControlFrame); if (NS_SUCCEEDED(rv) && formControlFrame) { - nsCOMPtr textControlFrame(do_QueryInterface(formControlFrame)); + nsCOMPtr textControlFrame(do_QueryInterface(formControlFrame)); if (textControlFrame) textControlFrame->SetSelectionEnd(aSelectionEnd); @@ -1215,7 +1215,7 @@ nsHTMLInputElement::GetSelectionRange(PRInt32* aSelectionStart, PRInt32* aSelect nsresult rv = nsGenericHTMLElement::GetPrimaryFrame(this, formControlFrame); if (NS_SUCCEEDED(rv) && formControlFrame) { - nsCOMPtr textControlFrame(do_QueryInterface(formControlFrame)); + nsCOMPtr textControlFrame(do_QueryInterface(formControlFrame)); if (textControlFrame) textControlFrame->GetSelectionRange(aSelectionStart, aSelectionEnd); diff --git a/mozilla/layout/html/forms/public/nsIGfxTextControlFrame.h b/mozilla/layout/html/forms/public/nsIGfxTextControlFrame.h index 96e00307a8d..2075c125ad6 100644 --- a/mozilla/layout/html/forms/public/nsIGfxTextControlFrame.h +++ b/mozilla/layout/html/forms/public/nsIGfxTextControlFrame.h @@ -24,6 +24,8 @@ class nsIEditor; class nsIDocShell; +class nsISelectionController; + #define NS_IGFXTEXTCONTROLFRAME_IID \ {/* d3ea33ea-9e00-11d3-bccc-0060b0fc76bd*/ \ @@ -46,5 +48,28 @@ public: NS_IMETHOD SetSelectionRange(PRInt32 aSelectionStart, PRInt32 aSelectionEnd) = 0; NS_IMETHOD GetSelectionRange(PRInt32* aSelectionStart, PRInt32* aSelectionEnd) = 0; - + +}; + +#define NS_IGFXTEXTCONTROLFRAME2_IID \ +{/* A744CFC9-2DA8-416d-A058-ADB1D4B3B534*/ \ +0xa744cfc9, 0x2da8, 0x416d, \ +{ 0xa0, 0x58, 0xad, 0xb1, 0xd4, 0xb3, 0xb5, 0x34 } } + +class nsIGfxTextControlFrame2 : public nsISupports +{ +public: + static const nsIID& GetIID() { static nsIID iid = NS_IGFXTEXTCONTROLFRAME2_IID; return iid; } + + NS_IMETHOD GetEditor(nsIEditor **aEditor) = 0; + + NS_IMETHOD GetTextLength(PRInt32* aTextLength) = 0; + + NS_IMETHOD SetSelectionStart(PRInt32 aSelectionStart) = 0; + NS_IMETHOD SetSelectionEnd(PRInt32 aSelectionEnd) = 0; + + NS_IMETHOD SetSelectionRange(PRInt32 aSelectionStart, PRInt32 aSelectionEnd) = 0; + NS_IMETHOD GetSelectionRange(PRInt32* aSelectionStart, PRInt32* aSelectionEnd) = 0; + + NS_IMETHOD GetSelectionController(nsISelectionController **aSelCon) = 0; }; diff --git a/mozilla/layout/html/forms/public/nsITextControlFrame.h b/mozilla/layout/html/forms/public/nsITextControlFrame.h index 96e00307a8d..2075c125ad6 100644 --- a/mozilla/layout/html/forms/public/nsITextControlFrame.h +++ b/mozilla/layout/html/forms/public/nsITextControlFrame.h @@ -24,6 +24,8 @@ class nsIEditor; class nsIDocShell; +class nsISelectionController; + #define NS_IGFXTEXTCONTROLFRAME_IID \ {/* d3ea33ea-9e00-11d3-bccc-0060b0fc76bd*/ \ @@ -46,5 +48,28 @@ public: NS_IMETHOD SetSelectionRange(PRInt32 aSelectionStart, PRInt32 aSelectionEnd) = 0; NS_IMETHOD GetSelectionRange(PRInt32* aSelectionStart, PRInt32* aSelectionEnd) = 0; - + +}; + +#define NS_IGFXTEXTCONTROLFRAME2_IID \ +{/* A744CFC9-2DA8-416d-A058-ADB1D4B3B534*/ \ +0xa744cfc9, 0x2da8, 0x416d, \ +{ 0xa0, 0x58, 0xad, 0xb1, 0xd4, 0xb3, 0xb5, 0x34 } } + +class nsIGfxTextControlFrame2 : public nsISupports +{ +public: + static const nsIID& GetIID() { static nsIID iid = NS_IGFXTEXTCONTROLFRAME2_IID; return iid; } + + NS_IMETHOD GetEditor(nsIEditor **aEditor) = 0; + + NS_IMETHOD GetTextLength(PRInt32* aTextLength) = 0; + + NS_IMETHOD SetSelectionStart(PRInt32 aSelectionStart) = 0; + NS_IMETHOD SetSelectionEnd(PRInt32 aSelectionEnd) = 0; + + NS_IMETHOD SetSelectionRange(PRInt32 aSelectionStart, PRInt32 aSelectionEnd) = 0; + NS_IMETHOD GetSelectionRange(PRInt32* aSelectionStart, PRInt32* aSelectionEnd) = 0; + + NS_IMETHOD GetSelectionController(nsISelectionController **aSelCon) = 0; }; diff --git a/mozilla/layout/html/forms/src/nsFileControlFrame.cpp b/mozilla/layout/html/forms/src/nsFileControlFrame.cpp index 8e6d314187c..98f226ad6e1 100644 --- a/mozilla/layout/html/forms/src/nsFileControlFrame.cpp +++ b/mozilla/layout/html/forms/src/nsFileControlFrame.cpp @@ -23,8 +23,8 @@ #include "nsFileControlFrame.h" #include "nsFormFrame.h" -#ifdef DEBUG_MJUDGE -#define DEBUG_NEWFRAME 1 +#ifdef DEBUG_mjudge +#define DEBUG_NEWFRAME 1 #endif diff --git a/mozilla/layout/html/forms/src/nsGfxTextControlFrame2.cpp b/mozilla/layout/html/forms/src/nsGfxTextControlFrame2.cpp index f9de6253bf0..ca70d93fa3d 100644 --- a/mozilla/layout/html/forms/src/nsGfxTextControlFrame2.cpp +++ b/mozilla/layout/html/forms/src/nsGfxTextControlFrame2.cpp @@ -45,6 +45,11 @@ #include "nsIElementFactory.h" #include "nsIHTMLContent.h" #include "nsFormFrame.h" +#include "nsIEditorIMESupport.h" +#include "nsIDOMHTMLTextAreaElement.h" +#include "nsINameSpaceManager.h" +#include "nsINodeInfo.h" + #include "nsIContent.h" @@ -96,6 +101,7 @@ public: NS_IMETHOD RepaintSelection(PRInt16 type); NS_IMETHOD RepaintSelection(nsIPresContext* aPresContext, SelectionType aSelectionType); NS_IMETHOD SetCaretEnabled(PRBool enabled); + NS_IMETHOD SetCaretReadOnly(PRBool aReadOnly); NS_IMETHOD GetCaretEnabled(PRBool *_retval); NS_IMETHOD CharacterMove(PRBool aForward, PRBool aExtend); NS_IMETHOD WordMove(PRBool aForward, PRBool aExtend); @@ -213,14 +219,45 @@ NS_IMETHODIMP nsTextAreaSelectionImpl::SetCaretEnabled(PRBool enabled) { if (!mPresShellWeak) return NS_ERROR_NOT_INITIALIZED; - nsCOMPtr selCon = do_QueryReferent(mPresShellWeak); - if (selCon) + nsresult result; + nsCOMPtr shell = do_QueryReferent(mPresShellWeak, &result); + if (shell) { - return selCon->SetCaretEnabled(enabled);//we can use presshells because there is only 1 caret + nsCOMPtr caret; + if (NS_SUCCEEDED(result = shell->GetCaret(getter_AddRefs(caret)))) + { + nsCOMPtr domSel; + if (NS_SUCCEEDED(result = mFrameSelection->GetSelection(nsISelectionController::SELECTION_NORMAL, getter_AddRefs(domSel)))) + { + return caret->SetCaretVisible(enabled, domSel); + } + } + } return NS_ERROR_FAILURE; } +NS_IMETHODIMP +nsTextAreaSelectionImpl::SetCaretReadOnly(PRBool aReadOnly) +{ + if (!mPresShellWeak) return NS_ERROR_NOT_INITIALIZED; + nsresult result; + nsCOMPtr shell = do_QueryReferent(mPresShellWeak, &result); + if (shell) + { + nsCOMPtr caret; + if (NS_SUCCEEDED(result = shell->GetCaret(getter_AddRefs(caret)))) + { + nsCOMPtr domSel; + if (NS_SUCCEEDED(result = mFrameSelection->GetSelection(nsISelectionController::SELECTION_NORMAL, getter_AddRefs(domSel)))) + { + return caret->SetCaretReadOnly(aReadOnly, domSel); + } + } + + } + return NS_ERROR_FAILURE; +} NS_IMETHODIMP nsTextAreaSelectionImpl::GetCaretEnabled(PRBool *_retval) @@ -436,6 +473,10 @@ nsGfxTextControlFrame2::QueryInterface(const nsIID& aIID, void** aInstancePtr) *aInstancePtr = (void*)(nsIAnonymousContentCreator*) this; return NS_OK; } + if (aIID.Equals(NS_GET_IID(nsIGfxTextControlFrame2))) { + *aInstancePtr = (void*)(nsIGfxTextControlFrame2*) this; + return NS_OK; + } return nsHTMLContainerFrame::QueryInterface(aIID, aInstancePtr); } @@ -443,6 +484,7 @@ nsGfxTextControlFrame2::nsGfxTextControlFrame2() { mIsProcessing=PR_FALSE; mFormFrame = nsnull; + mCachedState = nsnull; } nsGfxTextControlFrame2::~nsGfxTextControlFrame2() @@ -493,7 +535,7 @@ nsGfxTextControlFrame2::CreateFrameFor(nsIPresContext* aPresContext, return NS_ERROR_FAILURE; } - +#define DIV_STRING "user-focus: none; overflow:scroll; border: 0px !important; padding: 0px; margin:0px" NS_IMETHODIMP nsGfxTextControlFrame2::CreateAnonymousContent(nsIPresContext* aPresContext, @@ -502,18 +544,34 @@ nsGfxTextControlFrame2::CreateAnonymousContent(nsIPresContext* aPresContext, //create editor //create selection //init editor with div. +//==== - nsCAutoString progID = NS_ELEMENT_FACTORY_PROGID_PREFIX; - progID += "http://www.w3.org/TR/REC-html40"; - nsresult rv; - NS_WITH_SERVICE(nsIElementFactory, elementFactory, progID, &rv); - if (!elementFactory) - return NS_ERROR_FAILURE; +//get the presshell + mState |= NS_FRAME_INDEPENDENT_SELECTION; + nsCOMPtr shell; + nsresult rv = aPresContext->GetShell(getter_AddRefs(shell)); + if (NS_FAILED(rv) || !shell) + return rv?rv:NS_ERROR_FAILURE; + +//get the document + nsCOMPtr doc; + rv = shell->GetDocument(getter_AddRefs(doc)); + if (NS_FAILED(rv) || !doc) + return rv?rv:NS_ERROR_FAILURE; + nsCOMPtr domdoc = do_QueryInterface(doc, &rv); + if (NS_FAILED(rv) || !domdoc) + return rv?rv:NS_ERROR_FAILURE; + nsCOMPtr content; - elementFactory->CreateInstanceByTag(NS_ConvertToString("div"), getter_AddRefs(content)); + nsCOMPtr domElement; + + + if (NS_FAILED(domdoc->CreateElement(NS_ConvertToString("div"),getter_AddRefs(domElement))) && domElement) + content = do_QueryInterface(domElement); if (content) { + content->SetAttribute(kNameSpaceID_None,nsHTMLAtoms::style, NS_ConvertToString(DIV_STRING), PR_FALSE); aChildList.AppendElement(content); //make the editor @@ -525,11 +583,6 @@ nsGfxTextControlFrame2::CreateAnonymousContent(nsIPresContext* aPresContext, if (!mEditor) return NS_ERROR_OUT_OF_MEMORY; -//get the presshell - nsCOMPtr shell; - rv = aPresContext->GetShell(getter_AddRefs(shell)); - if (NS_FAILED(rv) || !shell) - return rv?rv:NS_ERROR_FAILURE; //create selection nsCOMPtr frameSel; rv = nsComponentManager::CreateInstance(kFrameSelectionCID, nsnull, @@ -539,15 +592,7 @@ nsGfxTextControlFrame2::CreateAnonymousContent(nsIPresContext* aPresContext, nsTextAreaSelectionImpl * textSelImpl = new nsTextAreaSelectionImpl(frameSel,shell,content); mSelCon = do_QueryInterface((nsISupports *)(nsISelectionController *)textSelImpl);//this will addref it once mSelCon->SetDisplaySelection(nsISelectionController::SELECTION_ON); -//get the document - nsCOMPtr doc; - rv = shell->GetDocument(getter_AddRefs(doc)); - if (NS_FAILED(rv) || !doc) - return rv?rv:NS_ERROR_FAILURE; - nsCOMPtr domdoc = do_QueryInterface(doc, &rv); - if (NS_FAILED(rv) || !domdoc) - return rv?rv:NS_ERROR_FAILURE; -//get the flags +//get the flags PRUint32 editorFlags = 0; if (IsPlainTextControl()) editorFlags |= nsIHTMLEditor::eEditorPlaintextMask; @@ -687,6 +732,8 @@ NS_IMETHODIMP nsGfxTextControlFrame2::Reflow(nsIPresContext* aPresConte const nsHTMLReflowState& aReflowState, nsReflowStatus& aStatus) { + mState |= NS_FRAME_HAS_DIRTY_CHILDREN; + // assuming 1 child nsIFrame* child = mFrames.FirstChild(); //mFrames.FirstChild(aPresContext,nsnull,&child); @@ -700,17 +747,11 @@ NS_IMETHODIMP nsGfxTextControlFrame2::Reflow(nsIPresContext* aPresConte if (kidReflowState.mComputedWidth != NS_INTRINSICSIZE) - kidReflowState.mComputedWidth -= kidReflowState.mComputedBorderPadding.left + kidReflowState.mComputedBorderPadding.right; + kidReflowState.mComputedWidth -= (kidReflowState.mComputedBorderPadding.left + kidReflowState.mComputedBorderPadding.right); if (kidReflowState.mComputedHeight != NS_INTRINSICSIZE) - kidReflowState.mComputedHeight -= kidReflowState.mComputedBorderPadding.top + kidReflowState.mComputedBorderPadding.bottom; + kidReflowState.mComputedHeight -= (kidReflowState.mComputedBorderPadding.top + kidReflowState.mComputedBorderPadding.bottom); - if (aReflowState.reason == eReflowReason_Initial) - { - aDesiredSize.height = 10; - return nsHTMLContainerFrame::Reflow(aPresContext,aDesiredSize,aReflowState,aStatus); - } - else if (aReflowState.reason == eReflowReason_Incremental) { if (aReflowState.reflowCommand) { @@ -747,6 +788,8 @@ NS_IMETHODIMP nsGfxTextControlFrame2::Reflow(nsIPresContext* aPresConte FinishReflowChild(child, aPresContext, aDesiredSize, aReflowState.mComputedBorderPadding.left, aReflowState.mComputedBorderPadding.top, 0); + aStatus = NS_FRAME_COMPLETE; + return rv; } //#endif @@ -761,14 +804,14 @@ nsGfxTextControlFrame2::GetSkipSides() const NS_IMETHODIMP nsGfxTextControlFrame2::GetName(nsString* aResult) { - nsresult result = NS_FORM_NOTOK; + nsresult rv = NS_FORM_NOTOK; if (mContent) { nsIHTMLContent* formControl = nsnull; - result = mContent->QueryInterface(NS_GET_IID(nsIHTMLContent),(void**)&formControl); - if (NS_SUCCEEDED(result) && formControl) { + rv = mContent->QueryInterface(NS_GET_IID(nsIHTMLContent),(void**)&formControl); + if (NS_SUCCEEDED(rv) && formControl) { nsHTMLValue value; - result = formControl->GetHTMLAttribute(nsHTMLAtoms::name, value); - if (NS_CONTENT_ATTR_HAS_VALUE == result) { + rv = formControl->GetHTMLAttribute(nsHTMLAtoms::name, value); + if (NS_CONTENT_ATTR_HAS_VALUE == rv) { if (eHTMLUnit_String == value.GetUnit()) { value.GetStringValue(*aResult); } @@ -776,22 +819,22 @@ nsGfxTextControlFrame2::GetName(nsString* aResult) NS_RELEASE(formControl); } } - return result; + return rv; } NS_IMETHODIMP nsGfxTextControlFrame2::GetType(PRInt32* aType) const { - nsresult result = NS_FORM_NOTOK; + nsresult rv = NS_FORM_NOTOK; if (mContent) { nsIFormControl* formControl = nsnull; - result = mContent->QueryInterface(NS_GET_IID(nsIFormControl), (void**)&formControl); - if ((NS_OK == result) && formControl) { - result = formControl->GetType(aType); + rv = mContent->QueryInterface(NS_GET_IID(nsIFormControl), (void**)&formControl); + if ((NS_OK == rv) && formControl) { + rv = formControl->GetType(aType); NS_RELEASE(formControl); } } - return result; + return rv; } @@ -912,6 +955,282 @@ NS_IMETHODIMP nsGfxTextControlFrame2::GetProperty(nsIAtom* aName, nsString& aVal } + +NS_IMETHODIMP +nsGfxTextControlFrame2::GetEditor(nsIEditor **aEditor) +{ + NS_ENSURE_ARG_POINTER(aEditor); + *aEditor = mEditor; + NS_IF_ADDREF(*aEditor); + return NS_OK; +} + + + +NS_IMETHODIMP +nsGfxTextControlFrame2::GetTextLength(PRInt32* aTextLength) +{ + NS_ENSURE_ARG_POINTER(aTextLength); + nsString *str = GetCachedString(); + if (str) + { + *aTextLength = str->Length(); + return NS_OK; + } + return NS_ERROR_FAILURE; +} + + + +NS_IMETHODIMP +nsGfxTextControlFrame2::SetSelectionStart(PRInt32 aSelectionStart) +{ + return NS_ERROR_NOT_IMPLEMENTED; +} + + + +NS_IMETHODIMP +nsGfxTextControlFrame2::SetSelectionEnd(PRInt32 aSelectionEnd) +{ + return NS_ERROR_NOT_IMPLEMENTED; +} + +NS_IMETHODIMP +nsGfxTextControlFrame2::SetSelectionRange(PRInt32 aSelectionStart, PRInt32 aSelectionEnd) +{ + return NS_ERROR_NOT_IMPLEMENTED; +} + +NS_IMETHODIMP +nsGfxTextControlFrame2::GetSelectionRange(PRInt32* aSelectionStart, PRInt32* aSelectionEnd) +{ + return NS_ERROR_NOT_IMPLEMENTED; +} + + +NS_IMETHODIMP +nsGfxTextControlFrame2::GetSelectionController(nsISelectionController **aSelCon) +{ + NS_ENSURE_ARG_POINTER(aSelCon); + NS_IF_ADDREF(*aSelCon = mSelCon); + return NS_OK; +} + + +/////END INTERFACE IMPLEMENTATIONS + +////NSIFRAME +NS_IMETHODIMP +nsGfxTextControlFrame2::AttributeChanged(nsIPresContext* aPresContext, + nsIContent* aChild, + PRInt32 aNameSpaceID, + nsIAtom* aAttribute, + PRInt32 aHint) +{ + if (!mEditor || !mSelCon) {return NS_ERROR_NOT_INITIALIZED;} + nsresult rv = NS_OK; + + if (nsHTMLAtoms::value == aAttribute) + { + if (mEditor) + { + nsString value; + GetText(&value, PR_TRUE); // get the initial value from the content attribute + mEditor->EnableUndo(PR_FALSE); // wipe out undo info + SetTextControlFrameState(value); // set new text value + mEditor->EnableUndo(PR_TRUE); // fire up a new txn stack + } + if (aHint != NS_STYLE_HINT_REFLOW) + nsFormFrame::StyleChangeReflow(aPresContext, this); + } + else if (nsHTMLAtoms::maxlength == aAttribute) + { + PRInt32 maxLength; + nsresult rv = GetMaxLength(&maxLength); + + nsCOMPtr htmlEditor = do_QueryInterface(mEditor); + if (htmlEditor) + { + if (NS_CONTENT_ATTR_NOT_THERE != rv) + { // set the maxLength attribute + htmlEditor->SetMaxTextLength(maxLength); + // if maxLength>docLength, we need to truncate the doc content + } + else { // unset the maxLength attribute + htmlEditor->SetMaxTextLength(-1); + } + } + } + else if (mEditor && nsHTMLAtoms::readonly == aAttribute) + { + nsresult rv = DoesAttributeExist(nsHTMLAtoms::readonly); + PRUint32 flags; + mEditor->GetFlags(&flags); + if (NS_CONTENT_ATTR_NOT_THERE != rv) + { // set readonly + flags |= nsIHTMLEditor::eEditorReadonlyMask; + if (mSelCon) + mSelCon->SetCaretEnabled(PR_FALSE); + } + else + { // unset readonly + flags &= ~(nsIHTMLEditor::eEditorReadonlyMask); + if (mSelCon) + mSelCon->SetCaretEnabled(PR_TRUE); + } + mEditor->SetFlags(flags); + } + else if (mEditor && nsHTMLAtoms::disabled == aAttribute) + { + nsCOMPtr shell; + rv = aPresContext->GetShell(getter_AddRefs(shell)); + if (NS_FAILED(rv) || !shell) + return rv?rv:NS_ERROR_FAILURE; + + rv = DoesAttributeExist(nsHTMLAtoms::disabled); + PRUint32 flags; + mEditor->GetFlags(&flags); + if (NS_CONTENT_ATTR_NOT_THERE != rv) + { // set readonly + flags |= nsIHTMLEditor::eEditorDisabledMask; + mSelCon->SetCaretEnabled(PR_FALSE); + mSelCon->SetDisplaySelection(nsISelectionController::SELECTION_OFF); + } + else + { // unset readonly + flags &= ~(nsIHTMLEditor::eEditorDisabledMask); + mSelCon->SetCaretEnabled(PR_TRUE); + mSelCon->SetDisplaySelection(nsISelectionController::SELECTION_ON); + } + mEditor->SetFlags(flags); + } + else if ((nsHTMLAtoms::size == aAttribute || + nsHTMLAtoms::rows == aAttribute) && aHint != NS_STYLE_HINT_REFLOW) { + nsFormFrame::StyleChangeReflow(aPresContext, this); + } + // Allow the base class to handle common attributes supported + // by all form elements... + else { + rv = nsHTMLContainerFrame::AttributeChanged(aPresContext, aChild, aNameSpaceID, aAttribute, aHint); + } + + return rv; +} + + +NS_IMETHODIMP +nsGfxTextControlFrame2::GetText(nsString* aText, PRBool aInitialValue) +{ + nsresult rv = NS_CONTENT_ATTR_NOT_THERE; + PRInt32 type; + GetType(&type); + if ((NS_FORM_INPUT_TEXT == type) || (NS_FORM_INPUT_PASSWORD == type)) + { + if (PR_TRUE==aInitialValue) + { + rv = nsFormControlHelper::GetInputElementValue(mContent, aText, aInitialValue); + } + else + { + if (mEditor) + { + nsCOMPtr imeSupport = do_QueryInterface(mEditor); + if(imeSupport) + imeSupport->ForceCompositionEnd(); + nsString format; format.AssignWithConversion("text/plain"); + mEditor->OutputToString(*aText, format, 0); + } + // we've never built our editor, so the content attribute is the value + else + { + rv = nsFormControlHelper::GetInputElementValue(mContent, aText, aInitialValue); + } + } + RemoveNewlines(*aText); + } + else + { + nsIDOMHTMLTextAreaElement* textArea = nsnull; + rv = mContent->QueryInterface(NS_GET_IID(nsIDOMHTMLTextAreaElement), (void**)&textArea); + if ((NS_OK == rv) && textArea) { + if (PR_TRUE == aInitialValue) { + rv = textArea->GetDefaultValue(*aText); + } + else { + if(mEditor) { + nsCOMPtr imeSupport = do_QueryInterface(mEditor); + if(imeSupport) + imeSupport->ForceCompositionEnd(); + } + rv = textArea->GetValue(*aText); + } + NS_RELEASE(textArea); + } + } + return rv; +} + + + +///END NSIFRAME OVERLOADS +/////BEGIN PROTECTED METHODS + +void nsGfxTextControlFrame2::RemoveNewlines(nsString &aString) +{ + // strip CR/LF and null + static const char badChars[] = {10, 13, 0}; + aString.StripChars(badChars); +} + + +NS_IMETHODIMP +nsGfxTextControlFrame2::GetMaxLength(PRInt32* aSize) +{ + *aSize = -1; + nsresult rv = NS_CONTENT_ATTR_NOT_THERE; + nsIHTMLContent* content = nsnull; + mContent->QueryInterface(kIHTMLContentIID, (void**) &content); + if (nsnull != content) { + nsHTMLValue value; + rv = content->GetHTMLAttribute(nsHTMLAtoms::maxlength, value); + if (eHTMLUnit_Integer == value.GetUnit()) { + *aSize = value.GetIntValue(); + } + NS_RELEASE(content); + } + return rv; +} + +NS_IMETHODIMP +nsGfxTextControlFrame2::DoesAttributeExist(nsIAtom *aAtt) +{ + nsresult rv = NS_CONTENT_ATTR_NOT_THERE; + nsIHTMLContent* content = nsnull; + mContent->QueryInterface(kIHTMLContentIID, (void**) &content); + if (nsnull != content) + { + nsHTMLValue value; + rv = content->GetHTMLAttribute(aAtt, value); + NS_RELEASE(content); + } + return rv; +} + + +nsString * +nsGfxTextControlFrame2::GetCachedString() +{ + if (!mCachedState && mEditor) + { + mCachedState = new nsString; + if (!mCachedState) + return nsnull; + GetTextControlFrameState(*mCachedState); + } + return mCachedState; +} + void nsGfxTextControlFrame2::GetTextControlFrameState(nsString& aValue) { aValue.SetLength(0); // initialize out param @@ -926,8 +1245,8 @@ void nsGfxTextControlFrame2::GetTextControlFrameState(nsString& aValue) } nsFormControlHelper::nsHTMLTextWrap wrapProp; - nsresult result = nsFormControlHelper::GetWrapPropertyEnum(mContent, wrapProp); - if (NS_CONTENT_ATTR_NOT_THERE != result) + nsresult rv = nsFormControlHelper::GetWrapPropertyEnum(mContent, wrapProp); + if (NS_CONTENT_ATTR_NOT_THERE != rv) { if (wrapProp == nsFormControlHelper::eHTMLTextWrap_Hard) { @@ -949,7 +1268,7 @@ nsGfxTextControlFrame2::SetTextControlFrameState(const nsString& aValue) { nsAutoString currentValue; nsAutoString format; format.AssignWithConversion("text/plain"); - nsresult result = mEditor->OutputToString(currentValue, format, 0); + nsresult rv = mEditor->OutputToString(currentValue, format, 0); if (PR_TRUE==IsSingleLineTextControl()) { RemoveNewlines(currentValue); } @@ -963,11 +1282,11 @@ nsGfxTextControlFrame2::SetTextControlFrameState(const nsString& aValue) nsFormControlHelper::PlatformToDOMLineBreaks(currentValue); nsCOMPtrdomDoc; - result = mEditor->GetDocument(getter_AddRefs(domDoc)); - if (NS_FAILED(result)) return; + rv = mEditor->GetDocument(getter_AddRefs(domDoc)); + if (NS_FAILED(rv)) return; if (!domDoc) return; - result = mEditor->SelectAll(); + rv = mEditor->SelectAll(); nsCOMPtr htmlEditor = do_QueryInterface(mEditor); if (!htmlEditor) return; @@ -992,7 +1311,7 @@ nsGfxTextControlFrame2::SetInitialChildList(nsIPresContext* aPresContext, nsIAtom* aListName, nsIFrame* aChildList) { - nsIFrame *list = aChildList; + /*nsIFrame *list = aChildList; nsFrameState frameState; while (list) { @@ -1001,58 +1320,11 @@ nsGfxTextControlFrame2::SetInitialChildList(nsIPresContext* aPresContext, list->SetFrameState(frameState); list->GetNextSibling(&list); } - nsresult result = nsHTMLContainerFrame::SetInitialChildList(aPresContext, aListName, aChildList); + */ + nsresult rv = nsHTMLContainerFrame::SetInitialChildList(aPresContext, aListName, aChildList); if (mEditor) mEditor->PostCreate(); - return result; -} - - -NS_IMETHODIMP -nsGfxTextControlFrame2::GetSelectionController(nsIPresContext *aPresContext, nsISelectionController **aSelCon) -{ - if (!aSelCon) - return NS_ERROR_INVALID_ARG; - NS_IF_ADDREF(*aSelCon = mSelCon); - return NS_OK; -} - - -nsresult -nsGfxTextControlFrame2::GetColRowSizeAttr(nsIFormControlFrame* aFrame, - nsIAtom * aColSizeAttr, - nsHTMLValue & aColSize, - nsresult & aColStatus, - nsIAtom * aRowSizeAttr, - nsHTMLValue & aRowSize, - nsresult & aRowStatus) -{ - nsIContent* iContent = nsnull; - aFrame->GetFormContent((nsIContent*&) iContent); - if (!iContent) { - return NS_ERROR_FAILURE; - } - nsIHTMLContent* hContent = nsnull; - nsresult result = iContent->QueryInterface(kIHTMLContentIID, (void**)&hContent); - if ((NS_OK != result) || !hContent) { - NS_RELEASE(iContent); - return NS_ERROR_FAILURE; - } - - aColStatus = NS_CONTENT_ATTR_NOT_THERE; - if (nsnull != aColSizeAttr) { - aColStatus = hContent->GetHTMLAttribute(aColSizeAttr, aColSize); - } - - aRowStatus= NS_CONTENT_ATTR_NOT_THERE; - if (nsnull != aRowSizeAttr) { - aRowStatus = hContent->GetHTMLAttribute(aRowSizeAttr, aRowSize); - } - - NS_RELEASE(hContent); - NS_RELEASE(iContent); - - return NS_OK; + return rv; } @@ -1061,12 +1333,12 @@ nsGfxTextControlFrame2::GetWidthInCharacters() const { // see if there's a COL attribute, if so it wins nsCOMPtr content; - nsresult result = mContent->QueryInterface(NS_GET_IID(nsIHTMLContent), getter_AddRefs(content)); - if (NS_SUCCEEDED(result) && content) + nsresult rv = mContent->QueryInterface(NS_GET_IID(nsIHTMLContent), getter_AddRefs(content)); + if (NS_SUCCEEDED(rv) && content) { nsHTMLValue resultValue; - result = content->GetHTMLAttribute(nsHTMLAtoms::cols, resultValue); - if (NS_CONTENT_ATTR_NOT_THERE != result) + rv = content->GetHTMLAttribute(nsHTMLAtoms::cols, resultValue); + if (NS_CONTENT_ATTR_NOT_THERE != rv) { if (resultValue.GetUnit() == eHTMLUnit_Integer) { diff --git a/mozilla/layout/html/forms/src/nsGfxTextControlFrame2.h b/mozilla/layout/html/forms/src/nsGfxTextControlFrame2.h index e21da09074d..bc903e1e257 100644 --- a/mozilla/layout/html/forms/src/nsGfxTextControlFrame2.h +++ b/mozilla/layout/html/forms/src/nsGfxTextControlFrame2.h @@ -29,7 +29,7 @@ #include "nsIAnonymousContentCreator.h" #include "nsIStatefulFrame.h" #include "nsIEditor.h" -#include "nsHTMLValue.h" +#include "nsIGfxTextControlFrame.h" class nsIPresState; @@ -45,7 +45,8 @@ class nsISelectionController; class nsGfxTextControlFrame2 : public nsHTMLContainerFrame, - public nsIAnonymousContentCreator, public nsIFormControlFrame + public nsIAnonymousContentCreator, public nsIFormControlFrame, + public nsIGfxTextControlFrame2 { public: nsGfxTextControlFrame2(); @@ -74,10 +75,6 @@ public: NS_IMETHOD SetInitialChildList(nsIPresContext* aPresContext, nsIAtom* aListName, nsIFrame* aChildList); - NS_IMETHOD GetSelectionController(nsIPresContext *aPresContext, nsISelectionController **aSelCon); - - - //==== BEGIN NSIFORMCONTROLFRAME NS_IMETHOD GetType(PRInt32* aType) const; //* @@ -108,9 +105,35 @@ public: //==== END NSIFORMCONTROLFRAME + +//==== NSIGFXTEXTCONTROLFRAME2 + + NS_IMETHOD GetEditor(nsIEditor **aEditor); + NS_IMETHOD GetTextLength(PRInt32* aTextLength); + NS_IMETHOD SetSelectionStart(PRInt32 aSelectionStart); + NS_IMETHOD SetSelectionEnd(PRInt32 aSelectionEnd); + NS_IMETHOD SetSelectionRange(PRInt32 aSelectionStart, PRInt32 aSelectionEnd); + NS_IMETHOD GetSelectionRange(PRInt32* aSelectionStart, PRInt32* aSelectionEnd); + NS_IMETHOD GetSelectionController(nsISelectionController **aSelCon); + +//==== END NSIGFXTEXTCONTROLFRAME2 +//==== OVERLOAD of nsIFrame + /** handler for attribute changes to mContent */ + NS_IMETHOD AttributeChanged(nsIPresContext* aPresContext, + nsIContent* aChild, + PRInt32 aNameSpaceID, + nsIAtom* aAttribute, + PRInt32 aHint); + + NS_IMETHOD GetText(nsString* aText, PRBool aInitialValue); + NS_DECL_ISUPPORTS_INHERITED protected: + nsString *GetCachedString(); virtual PRIntn GetSkipSides() const; + void RemoveNewlines(nsString &aString); + NS_IMETHOD GetMaxLength(PRInt32* aSize); + NS_IMETHOD DoesAttributeExist(nsIAtom *aAtt); //helper methods virtual PRBool IsSingleLineTextControl() const; @@ -121,30 +144,12 @@ protected: nsIContent * aContent, nsIFrame** aFrame); - nsresult GetColRowSizeAttr(nsIFormControlFrame* aFrame, - nsIAtom * aColSizeAttr, - nsHTMLValue & aColSize, - nsresult & aColStatus, - nsIAtom * aRowSizeAttr, - nsHTMLValue & aRowSize, - nsresult & aRowStatus); - NS_IMETHOD GetType(PRInt32* aType) const; - - nsresult GetColRowSizeAttr(nsIFormControlFrame* aFrame, - nsIAtom * aColSizeAttr, - nsHTMLValue & aColSize, - nsresult & aColStatus, - nsIAtom * aRowSizeAttr, - nsHTMLValue & aRowSize, - nsresult & aRowStatus); - PRInt32 GetWidthInCharacters() const; ->>>>>>> 1.6 private: nsCOMPtr mEditor; nsCOMPtr mSelCon; - nsString mCachedState; + nsString *mCachedState; PRBool mIsProcessing; nsFormFrame *mFormFrame; };