Part of fix for bug 16813 -- line termination problems with forms. r=pollman, rickg.

This commit is contained in:
sfraser%netscape.com 1999-12-01 23:05:58 +00:00
Родитель 53edb43c8a
Коммит 3cbb52af45
4 изменённых файлов: 74 добавлений и 8 удалений

Просмотреть файл

@ -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;
}

Просмотреть файл

@ -42,6 +42,7 @@
#include "nsViewSourceHTML.h"
#include "nsParserNode.h"
#include "nsHTMLEntities.h"
#include "nsLinebreakConverter.h"
#ifdef XP_PC
#include <direct.h> //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;aIndex<aMax;aIndex++){
CHTMLToken* theNextToken=(CHTMLToken*)mSkippedContent.PopFront();
@ -1931,6 +1936,10 @@ nsresult CNavDTD::CollectSkippedContent(nsCParserNode& aNode,PRInt32 &aCount) {
if(eToken_attribute!=theTokenType) {
if((eHTMLTag_textarea==theNodeTag) && (eToken_entity==theTokenType)) {
((CEntityToken*)theNextToken)->TranslateToUnicodeStr(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;

Просмотреть файл

@ -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;
}

Просмотреть файл

@ -42,6 +42,7 @@
#include "nsViewSourceHTML.h"
#include "nsParserNode.h"
#include "nsHTMLEntities.h"
#include "nsLinebreakConverter.h"
#ifdef XP_PC
#include <direct.h> //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;aIndex<aMax;aIndex++){
CHTMLToken* theNextToken=(CHTMLToken*)mSkippedContent.PopFront();
@ -1931,6 +1936,10 @@ nsresult CNavDTD::CollectSkippedContent(nsCParserNode& aNode,PRInt32 &aCount) {
if(eToken_attribute!=theTokenType) {
if((eHTMLTag_textarea==theNodeTag) && (eToken_entity==theTokenType)) {
((CEntityToken*)theNextToken)->TranslateToUnicodeStr(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;