diff --git a/mozilla/layout/forms/nsTextControlFrame.cpp b/mozilla/layout/forms/nsTextControlFrame.cpp index da157144440..c193d07b50e 100644 --- a/mozilla/layout/forms/nsTextControlFrame.cpp +++ b/mozilla/layout/forms/nsTextControlFrame.cpp @@ -316,3 +316,23 @@ nsTextControlFrame::SetSuggestedSize(nscoord aWidth, nscoord aHeight) return NS_OK; } + +NS_IMETHODIMP +nsTextControlFrame::GetWrapProperty(nsString &aOutValue) +{ + aOutValue = ""; + nsresult result = NS_CONTENT_ATTR_NOT_THERE; + nsIHTMLContent* content = nsnull; + mContent->QueryInterface(kIHTMLContentIID, (void**) &content); + if (nsnull != content) + { + nsHTMLValue value; + result = content->GetHTMLAttribute(nsHTMLAtoms::wrap, value); + if (eHTMLUnit_String == value.GetUnit()) + { + value.GetStringValue(aOutValue); + } + NS_RELEASE(content); + } + return result; +} diff --git a/mozilla/layout/forms/nsTextControlFrame.h b/mozilla/layout/forms/nsTextControlFrame.h index e09c85efb8e..89a01f3b96e 100644 --- a/mozilla/layout/forms/nsTextControlFrame.h +++ b/mozilla/layout/forms/nsTextControlFrame.h @@ -49,6 +49,11 @@ public: NS_IMETHOD GetCursor(nsIPresContext& aPresContext, nsPoint& aPoint, PRInt32& aCursor); NS_IMETHOD SetSuggestedSize(nscoord aWidth, nscoord aHeight); + /** returns the value of the "wrap" property in aOutValue + * returns NS_CONTENT_ATTR_NOT_THERE if the property does not exist for this + */ + NS_IMETHOD GetWrapProperty(nsString &aOutValue); + protected: virtual void GetDesiredSize(nsIPresContext* aPresContext, diff --git a/mozilla/layout/html/forms/src/nsGfxTextControlFrame.cpp b/mozilla/layout/html/forms/src/nsGfxTextControlFrame.cpp index 0ba67b0e70e..a806b6cada7 100644 --- a/mozilla/layout/html/forms/src/nsGfxTextControlFrame.cpp +++ b/mozilla/layout/html/forms/src/nsGfxTextControlFrame.cpp @@ -56,6 +56,7 @@ #include "nsWidgetsCID.h" #include "nsIHTMLEditor.h" +#include "nsIEditorMailSupport.h" #include "nsEditorCID.h" #include "nsIDOMNode.h" #include "nsIDOMElement.h" @@ -106,6 +107,9 @@ static NS_DEFINE_IID(kIDOMFocusListenerIID, NS_IDOMFOCUSLISTENER_IID); //#define NOISY const nscoord kSuggestedNotSet = -1; +nsAutoString kTextControl_Wrap_Soft = "SOFT"; +nsAutoString kTextControl_Wrap_Off = "OFF"; + /************************************** MODULE NOTES *********************************** 7/28/99 buster @@ -256,6 +260,40 @@ nsGfxTextControlFrame::~nsGfxTextControlFrame() // this will be a leak -- NS_IF_RELEASE(mDummyFrame); } +NS_METHOD nsGfxTextControlFrame::HandleEvent(nsIPresContext& aPresContext, + nsGUIEvent* aEvent, + nsEventStatus& aEventStatus) +{ + if (nsEventStatus_eConsumeNoDefault == aEventStatus) { + return NS_OK; + } + + aEventStatus = nsEventStatus_eConsumeDoDefault; // this is the default + + switch (aEvent->message) { + case NS_MOUSE_LEFT_CLICK: + MouseClicked(&aPresContext); + break; + + case NS_KEY_PRESS: + if (NS_KEY_EVENT == aEvent->eventStructType) { + nsKeyEvent* keyEvent = (nsKeyEvent*)aEvent; + if (NS_VK_RETURN == keyEvent->keyCode) + { + EnterPressed(aPresContext); + aEventStatus = nsEventStatus_eConsumeNoDefault; + } + else if (NS_VK_SPACE == keyEvent->keyCode) + { + MouseClicked(&aPresContext); + } + } + break; + } + return NS_OK; +} + + void nsGfxTextControlFrame::EnterPressed(nsIPresContext& aPresContext) { @@ -562,13 +600,31 @@ nsGfxTextControlFrame::PaintTextControl(nsIPresContext& aPresContext, } } +//XXX: this needs to be fixed for HTML output void nsGfxTextControlFrame::GetTextControlFrameState(nsString& aValue) { aValue = ""; // initialize out param - if (PR_TRUE==IsInitialized()) { + if (PR_TRUE==IsInitialized()) + { nsString format ("text/plain"); - mEditor->OutputToString(aValue, format, nsIEditor::EditorOutputNoDoctype); + PRUint32 flags = 0; + + if (PR_TRUE==IsPlainTextControl()) { + flags |= nsIEditor::EditorOutputNoDoctype; + } + + nsString wrap; + nsresult result = GetWrapProperty(wrap); + if (NS_CONTENT_ATTR_NOT_THERE != result) + { + if (kTextControl_Wrap_Soft.EqualsIgnoreCase(wrap)) + { + flags |= nsIEditor::EditorOutputFormatted; + } + } + + mEditor->OutputToString(aValue, format, flags); } } @@ -1113,16 +1169,20 @@ nsGfxTextControlFrame::InstallEditor() if (IsPasswordTextControl()) editorFlags |= nsIHTMLEditor::eEditorPasswordMask; + // initialize the editor result = mEditor->Init(mDoc, presShell, editorFlags); - if (NS_SUCCEEDED(result)) { - mEditor->PostCreate(); - } + // set data from the text control into the editor if (NS_SUCCEEDED(result)) { result = InitializeTextControl(presShell, mDoc); } + // install our own event handlers before the editor's event handlers if (NS_SUCCEEDED(result)) { result = InstallEventListeners(); } + // finish editor initialization, including event handler installation + if (NS_SUCCEEDED(result)) { + mEditor->PostCreate(); + } } return result; } @@ -1211,9 +1271,9 @@ nsGfxTextControlFrame::InitializeTextControl(nsIPresShell *aPresShell, nsIDOMDoc if (!presContext) { return NS_ERROR_NULL_POINTER; } /* set all style that propogates from the text control to its content - * into the presContext for the webshell. + * into the presContext for the webshell. * what I would prefer to do is hand the webshell my own - * pres context at creation, rather than having it create its own. + * pres context at creation, rather than having it create its own. */ nsFont font(presContext->GetDefaultFixedFontDeprecated()); @@ -1233,7 +1293,7 @@ nsGfxTextControlFrame::InitializeTextControl(nsIPresShell *aPresShell, nsIDOMDoc presContext->SetDefaultBackgroundImage(controlColor->mBackgroundImage); /* HACK: - * since I don't yet have a hook for setting info on the pres context before style is + * since I don't yet have a hook for setting info on the pres context before style is * resolved, I need to call remap style on the root frame's style context. * The above code for setting presContext data should happen on a presContext that * I create and pass into the webshell, rather than having the webshell create its own @@ -1243,7 +1303,7 @@ nsGfxTextControlFrame::InitializeTextControl(nsIPresShell *aPresShell, nsIDOMDoc if (NS_FAILED(result)) { return result; } if (nsnull==sc) { return NS_ERROR_NULL_POINTER; } sc->RemapStyle(presContext); - // end HACK + // end HACK // now that the style context is initialized, initialize the content nsAutoString value; @@ -1256,6 +1316,20 @@ nsGfxTextControlFrame::InitializeTextControl(nsIPresShell *aPresShell, nsIDOMDoc htmlEditor->SetMaxTextLength(maxLength); } + nsCOMPtr mailEditor = do_QueryInterface(mEditor); + if (mailEditor) + { + nsString wrap; + result = GetWrapProperty(wrap); + if (NS_CONTENT_ATTR_NOT_THERE != result) + { + if (kTextControl_Wrap_Off.EqualsIgnoreCase(wrap)) + { + mailEditor->SetBodyWrapWidth(-1); + } + } + } + nsCOMPtreditor = do_QueryInterface(mEditor); NS_ASSERTION(editor, "bad QI to nsIEditor from mEditor"); if (editor) diff --git a/mozilla/layout/html/forms/src/nsGfxTextControlFrame.h b/mozilla/layout/html/forms/src/nsGfxTextControlFrame.h index ad66d86b4a2..f445b430ad0 100644 --- a/mozilla/layout/html/forms/src/nsGfxTextControlFrame.h +++ b/mozilla/layout/html/forms/src/nsGfxTextControlFrame.h @@ -411,6 +411,14 @@ public: NS_IMETHOD GetText(nsString* aValue, PRBool aInitialValue); + /** + * Respond to a gui event + * @see nsNativeFormControlFrame::HandleEvent + */ + NS_IMETHOD HandleEvent(nsIPresContext& aPresContext, + nsGUIEvent* aEvent, + nsEventStatus& aEventStatus); + virtual void EnterPressed(nsIPresContext& aPresContext) ; virtual PRBool GetNamesValues(PRInt32 aMaxNumValues, PRInt32& aNumValues, diff --git a/mozilla/layout/html/forms/src/nsTextControlFrame.cpp b/mozilla/layout/html/forms/src/nsTextControlFrame.cpp index da157144440..c193d07b50e 100644 --- a/mozilla/layout/html/forms/src/nsTextControlFrame.cpp +++ b/mozilla/layout/html/forms/src/nsTextControlFrame.cpp @@ -316,3 +316,23 @@ nsTextControlFrame::SetSuggestedSize(nscoord aWidth, nscoord aHeight) return NS_OK; } + +NS_IMETHODIMP +nsTextControlFrame::GetWrapProperty(nsString &aOutValue) +{ + aOutValue = ""; + nsresult result = NS_CONTENT_ATTR_NOT_THERE; + nsIHTMLContent* content = nsnull; + mContent->QueryInterface(kIHTMLContentIID, (void**) &content); + if (nsnull != content) + { + nsHTMLValue value; + result = content->GetHTMLAttribute(nsHTMLAtoms::wrap, value); + if (eHTMLUnit_String == value.GetUnit()) + { + value.GetStringValue(aOutValue); + } + NS_RELEASE(content); + } + return result; +} diff --git a/mozilla/layout/html/forms/src/nsTextControlFrame.h b/mozilla/layout/html/forms/src/nsTextControlFrame.h index e09c85efb8e..89a01f3b96e 100644 --- a/mozilla/layout/html/forms/src/nsTextControlFrame.h +++ b/mozilla/layout/html/forms/src/nsTextControlFrame.h @@ -49,6 +49,11 @@ public: NS_IMETHOD GetCursor(nsIPresContext& aPresContext, nsPoint& aPoint, PRInt32& aCursor); NS_IMETHOD SetSuggestedSize(nscoord aWidth, nscoord aHeight); + /** returns the value of the "wrap" property in aOutValue + * returns NS_CONTENT_ATTR_NOT_THERE if the property does not exist for this + */ + NS_IMETHOD GetWrapProperty(nsString &aOutValue); + protected: virtual void GetDesiredSize(nsIPresContext* aPresContext,