diff --git a/content/html/content/src/nsHTMLTextAreaElement.cpp b/content/html/content/src/nsHTMLTextAreaElement.cpp index 7c977b41da4a..45b56eeb41f2 100644 --- a/content/html/content/src/nsHTMLTextAreaElement.cpp +++ b/content/html/content/src/nsHTMLTextAreaElement.cpp @@ -44,6 +44,7 @@ #include "nsIFocusableContent.h" #include "nsIEventStateManager.h" #include "nsISizeOfHandler.h" +#include "nsLinebreakConverter.h" static NS_DEFINE_IID(kIDOMHTMLTextAreaElementIID, NS_IDOMHTMLTEXTAREAELEMENT_IID); static NS_DEFINE_IID(kIDOMHTMLFormElementIID, NS_IDOMHTMLFORMELEMENT_IID); @@ -373,11 +374,17 @@ nsHTMLTextAreaElement::GetDefaultValue(nsString& aDefaultValue) NS_IMETHODIMP nsHTMLTextAreaElement::SetDefaultValue(const nsString& aDefaultValue) { - // trim leading whitespace + // trim leading whitespace. -- why? static char whitespace[] = " \r\n\t"; - nsString value(aDefaultValue); - value.Trim(whitespace, PR_TRUE, PR_FALSE); - mInner.SetAttribute(kNameSpaceID_HTML, nsHTMLAtoms::value, value, PR_TRUE); + nsString defaultValue(aDefaultValue); + defaultValue.Trim(whitespace, PR_TRUE, PR_FALSE); + + // normalize line breaks. Need this e.g. when the value is + // coming from a URL, which used platform line breaks. + nsLinebreakConverter::ConvertStringLineBreaks(defaultValue, + nsLinebreakConverter::eLinebreakAny, nsLinebreakConverter::eLinebreakContent); + + mInner.SetAttribute(kNameSpaceID_HTML, nsHTMLAtoms::value, defaultValue, PR_TRUE); return NS_OK; } diff --git a/htmlparser/src/CNavDTD.cpp b/htmlparser/src/CNavDTD.cpp index 7b3ab94e2d8f..c6edcd316b4a 100644 --- a/htmlparser/src/CNavDTD.cpp +++ b/htmlparser/src/CNavDTD.cpp @@ -42,6 +42,7 @@ #include "nsViewSourceHTML.h" #include "nsParserNode.h" #include "nsHTMLEntities.h" +#include "nsLinebreakConverter.h" #ifdef XP_PC #include //this is here for debug reasons... @@ -1919,6 +1920,10 @@ nsresult CNavDTD::CollectSkippedContent(nsCParserNode& aNode,PRInt32 &aCount) { int aIndex=0; int aMax=mSkippedContent.GetSize(); + // XXX rickg This linefeed conversion stuff should be moved out of + // the parser and into the form element code + PRBool aMustConvertLinebreaks = PR_FALSE; + for(aIndex=0;aIndexTranslateToUnicodeStr(mScratch); + // since this is an entity, we know that it's only one character. + // check to see if it's a CR, in which case we'll need to do line + // termination conversion at the end. + aMustConvertLinebreaks |= (mScratch[0] == kCR); } else theNextToken->GetSource(mScratch); @@ -1938,6 +1947,23 @@ nsresult CNavDTD::CollectSkippedContent(nsCParserNode& aNode,PRInt32 &aCount) { } mTokenRecycler->RecycleToken(theNextToken); } + + // if the string contained CRs (hence is either CR, or CRLF terminated) + // we need to convert line breaks + if (aMustConvertLinebreaks) + { + /* + PRInt32 offset; + while ((offset = aNode.mSkippedContent.Find("\r\n")) != kNotFound) + aNode.mSkippedContent.Cut(offset, 1); // remove the CR + + // now replace remaining CRs with LFs + aNode.mSkippedContent.ReplaceChar("\r", kNewLine); + */ + nsLinebreakConverter::ConvertStringLineBreaks(aNode.mSkippedContent, + nsLinebreakConverter::eLinebreakAny, nsLinebreakConverter::eLinebreakContent); + } + // Let's hope that this does not hamper the PERFORMANCE!! mLineNumber += aNode.mSkippedContent.CountChar(kNewLine); return NS_OK; diff --git a/layout/html/content/src/nsHTMLTextAreaElement.cpp b/layout/html/content/src/nsHTMLTextAreaElement.cpp index 7c977b41da4a..45b56eeb41f2 100644 --- a/layout/html/content/src/nsHTMLTextAreaElement.cpp +++ b/layout/html/content/src/nsHTMLTextAreaElement.cpp @@ -44,6 +44,7 @@ #include "nsIFocusableContent.h" #include "nsIEventStateManager.h" #include "nsISizeOfHandler.h" +#include "nsLinebreakConverter.h" static NS_DEFINE_IID(kIDOMHTMLTextAreaElementIID, NS_IDOMHTMLTEXTAREAELEMENT_IID); static NS_DEFINE_IID(kIDOMHTMLFormElementIID, NS_IDOMHTMLFORMELEMENT_IID); @@ -373,11 +374,17 @@ nsHTMLTextAreaElement::GetDefaultValue(nsString& aDefaultValue) NS_IMETHODIMP nsHTMLTextAreaElement::SetDefaultValue(const nsString& aDefaultValue) { - // trim leading whitespace + // trim leading whitespace. -- why? static char whitespace[] = " \r\n\t"; - nsString value(aDefaultValue); - value.Trim(whitespace, PR_TRUE, PR_FALSE); - mInner.SetAttribute(kNameSpaceID_HTML, nsHTMLAtoms::value, value, PR_TRUE); + nsString defaultValue(aDefaultValue); + defaultValue.Trim(whitespace, PR_TRUE, PR_FALSE); + + // normalize line breaks. Need this e.g. when the value is + // coming from a URL, which used platform line breaks. + nsLinebreakConverter::ConvertStringLineBreaks(defaultValue, + nsLinebreakConverter::eLinebreakAny, nsLinebreakConverter::eLinebreakContent); + + mInner.SetAttribute(kNameSpaceID_HTML, nsHTMLAtoms::value, defaultValue, PR_TRUE); return NS_OK; } diff --git a/parser/htmlparser/src/CNavDTD.cpp b/parser/htmlparser/src/CNavDTD.cpp index 7b3ab94e2d8f..c6edcd316b4a 100644 --- a/parser/htmlparser/src/CNavDTD.cpp +++ b/parser/htmlparser/src/CNavDTD.cpp @@ -42,6 +42,7 @@ #include "nsViewSourceHTML.h" #include "nsParserNode.h" #include "nsHTMLEntities.h" +#include "nsLinebreakConverter.h" #ifdef XP_PC #include //this is here for debug reasons... @@ -1919,6 +1920,10 @@ nsresult CNavDTD::CollectSkippedContent(nsCParserNode& aNode,PRInt32 &aCount) { int aIndex=0; int aMax=mSkippedContent.GetSize(); + // XXX rickg This linefeed conversion stuff should be moved out of + // the parser and into the form element code + PRBool aMustConvertLinebreaks = PR_FALSE; + for(aIndex=0;aIndexTranslateToUnicodeStr(mScratch); + // since this is an entity, we know that it's only one character. + // check to see if it's a CR, in which case we'll need to do line + // termination conversion at the end. + aMustConvertLinebreaks |= (mScratch[0] == kCR); } else theNextToken->GetSource(mScratch); @@ -1938,6 +1947,23 @@ nsresult CNavDTD::CollectSkippedContent(nsCParserNode& aNode,PRInt32 &aCount) { } mTokenRecycler->RecycleToken(theNextToken); } + + // if the string contained CRs (hence is either CR, or CRLF terminated) + // we need to convert line breaks + if (aMustConvertLinebreaks) + { + /* + PRInt32 offset; + while ((offset = aNode.mSkippedContent.Find("\r\n")) != kNotFound) + aNode.mSkippedContent.Cut(offset, 1); // remove the CR + + // now replace remaining CRs with LFs + aNode.mSkippedContent.ReplaceChar("\r", kNewLine); + */ + nsLinebreakConverter::ConvertStringLineBreaks(aNode.mSkippedContent, + nsLinebreakConverter::eLinebreakAny, nsLinebreakConverter::eLinebreakContent); + } + // Let's hope that this does not hamper the PERFORMANCE!! mLineNumber += aNode.mSkippedContent.CountChar(kNewLine); return NS_OK;