Bug 229526 Don't trim whitespace in <label> <description> or non-XUL r/sr=hyatt

This commit is contained in:
neil%parkwaycc.co.uk 2004-01-10 23:40:54 +00:00
Родитель e2ab7cfb74
Коммит 2181ff5286
2 изменённых файлов: 40 добавлений и 21 удалений

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

@ -170,24 +170,31 @@ nsXBLContentSink::FlushText(PRBool aCreateTextNode,
return NS_OK;
}
PRBool isWS = PR_TRUE;
if (mTextLength > 0) {
const PRUnichar* cp = mText;
const PRUnichar* end = mText + mTextLength;
while (cp < end) {
PRUnichar ch = *cp++;
if (!XP_IS_SPACE(ch)) {
isWS = PR_FALSE;
break;
nsIContent* content = GetCurrentContent();
if (content && (content->GetNodeInfo()->NamespaceEquals(kNameSpaceID_XBL) || (
content->IsContentOfType(nsIContent::eXUL) &&
content->Tag() != nsXULAtoms::label &&
content->Tag() != nsXULAtoms::description))) {
PRBool isWS = PR_TRUE;
if (mTextLength > 0) {
const PRUnichar* cp = mText;
const PRUnichar* end = mText + mTextLength;
while (cp < end) {
PRUnichar ch = *cp++;
if (!XP_IS_SPACE(ch)) {
isWS = PR_FALSE;
break;
}
}
}
}
if (isWS && mTextLength > 0) {
mTextLength = 0;
if (aDidFlush)
*aDidFlush = PR_TRUE;
return NS_OK;
if (isWS && mTextLength > 0) {
mTextLength = 0;
if (aDidFlush)
*aDidFlush = PR_TRUE;
return NS_OK;
}
}
return nsXMLContentSink::FlushText(aCreateTextNode, aDidFlush);

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

@ -649,23 +649,35 @@ XULContentSinkImpl::FlushText(PRBool aCreateTextNode)
if (! aCreateTextNode)
break;
nsXULPrototypeNode* node;
rv = mContextStack.GetTopNode(&node);
if (NS_FAILED(rv)) return rv;
PRBool stripWhitespace = PR_FALSE;
if (node->mType == nsXULPrototypeNode::eType_Element) {
nsINodeInfo *nodeInfo =
NS_STATIC_CAST(nsXULPrototypeElement*, node)->mNodeInfo;
if (nodeInfo->NamespaceEquals(kNameSpaceID_XUL))
stripWhitespace = !nodeInfo->Equals(nsXULAtoms::label) &&
!nodeInfo->Equals(nsXULAtoms::description);
}
// Don't bother if there's nothing but whitespace.
// XXX This could cause problems...
if (! IsDataInBuffer(mText, mTextLength))
if (stripWhitespace && ! IsDataInBuffer(mText, mTextLength))
break;
// Don't bother if we're not in XUL document body
if (mState != eInDocumentElement || mContextStack.Depth() == 0)
break;
// Trim the leading and trailing whitespace
nsXULPrototypeText* text = new nsXULPrototypeText();
if (! text)
return NS_ERROR_OUT_OF_MEMORY;
text->mValue.SetCapacity(mTextLength + 1);
text->mValue.Append(mText, mTextLength);
text->mValue.Trim(" \t\n\r");
text->mValue.Assign(mText, mTextLength);
if (stripWhitespace)
text->mValue.Trim(" \t\n\r");
// hook it up
nsVoidArray* children;