Bug 814677 - Replace XP_IS_SPACE with dom::IsSpaceCharacter and add form-feed to match DOM spec. r=bz

This commit is contained in:
Mats Palmgren 2012-11-30 17:04:11 +01:00
parent c298a0ce6f
commit 0bae59cdf1
12 changed files with 95 additions and 26 deletions

View File

@ -49,6 +49,18 @@ class nsXPCClassInfo;
namespace mozilla {
namespace dom {
/**
* @return true if aChar is what the DOM spec defines as 'space character'.
* http://dom.spec.whatwg.org/#space-character
*/
inline bool IsSpaceCharacter(PRUnichar aChar) {
return aChar == ' ' || aChar == '\t' || aChar == '\n' || aChar == '\r' ||
aChar == '\f';
}
inline bool IsSpaceCharacter(char aChar) {
return aChar == ' ' || aChar == '\t' || aChar == '\n' || aChar == '\r' ||
aChar == '\f';
}
class Element;
class EventHandlerNonNull;
class OnErrorEventHandlerNonNull;

View File

@ -844,6 +844,7 @@ nsGenericDOMDataNode::AppendText(const PRUnichar* aBuffer,
bool
nsGenericDOMDataNode::TextIsOnlyWhitespace()
{
// FIXME: should this method take content language into account?
if (mText.Is2b()) {
// The fragment contains non-8bit characters and such characters
// are never considered whitespace.
@ -856,7 +857,7 @@ nsGenericDOMDataNode::TextIsOnlyWhitespace()
while (cp < end) {
char ch = *cp;
if (!XP_IS_SPACE(ch)) {
if (!dom::IsSpaceCharacter(ch)) {
return false;
}

View File

@ -24,22 +24,6 @@ class nsCString;
// XXX nsTextFragmentPool?
// XXX these need I18N spankage
#define XP_IS_SPACE(_ch) \
(((_ch) == ' ') || ((_ch) == '\t') || ((_ch) == '\n') || ((_ch) == '\r'))
#define XP_IS_UPPERCASE(_ch) \
(((_ch) >= 'A') && ((_ch) <= 'Z'))
#define XP_IS_LOWERCASE(_ch) \
(((_ch) >= 'a') && ((_ch) <= 'z'))
#define XP_TO_LOWER(_ch) ((_ch) | 32)
#define XP_TO_UPPER(_ch) ((_ch) & ~32)
#define XP_IS_SPACE_W XP_IS_SPACE
/**
* A fragment of text. If mIs2b is 1 then the m2b pointer is valid
* otherwise the m1b pointer is valid. If m1b is used then each byte

View File

@ -150,7 +150,7 @@ nsXBLContentSink::FlushText(bool aReleaseTextNode)
const PRUnichar* end = mText + mTextLength;
while (cp < end) {
PRUnichar ch = *cp++;
if (!XP_IS_SPACE(ch)) {
if (!dom::IsSpaceCharacter(ch)) {
isWS = false;
break;
}

View File

@ -10337,7 +10337,8 @@ FirstLetterCount(const nsTextFragment* aFragment)
int32_t i, n = aFragment->GetLength();
for (i = 0; i < n; i++) {
PRUnichar ch = aFragment->CharAt(i);
if (XP_IS_SPACE(ch)) {
// FIXME: take content language into account when deciding whitespace.
if (dom::IsSpaceCharacter(ch)) {
if (firstLetterLength) {
break;
}

View File

@ -937,7 +937,7 @@ nsImageFrame::MeasureString(const PRUnichar* aString,
uint32_t len = aLength;
bool trailingSpace = false;
for (int32_t i = 0; i < aLength; i++) {
if (XP_IS_SPACE(aString[i]) && (i > 0)) {
if (dom::IsSpaceCharacter(aString[i]) && (i > 0)) {
len = i; // don't include the space when measuring
trailingSpace = true;
break;

View File

@ -638,7 +638,7 @@ int32_t nsTextFrame::GetInFlowContentLength() {
return endFlow - mContentOffset;
}
// Smarter versions of XP_IS_SPACE.
// Smarter versions of dom::IsSpaceCharacter.
// Unicode is really annoying; sometimes a space character isn't whitespace ---
// when it combines with another character
// So we have several versions of IsSpace for use in different contexts.

View File

@ -0,0 +1,35 @@
<!DOCTYPE HTML>
<html><head>
<meta charset="utf-8">
<title>Testcase for bug 814677</title>
<style type="text/css">
html,body {
color:black; background-color:white; font-size:16px; padding:0; margin:0;
}
span { display: table-cell; }
.t { display:table; }
</style>
</head>
<body>
<div><span>A</span><span>B</span></div>
<div><span>A</span><span>B</span></div>
<div class="t"><span>A</span></div>&#x0B;<div class="t"><span>B</span></div>
<div><span>A</span><span>B</span></div>
<div><span>A</span><span>B</span></div>
<div class="t"><span>A</span></div>&nbsp;<div class="t"><span>B</span></div>
<div><span>A</span><span>B</span></div>
<div><span>A</span><span>B</span></div>
<div><span>A</span><span>B</span></div>
<div class="t"><span>A</span></div>&#x0B;<div class="t"><span>B</span></div>
<div><span>A</span><span>B</span></div>
<div><span>A</span><span>B</span></div>
<div class="t"><span>A</span></div>&nbsp;<div class="t"><span>B</span></div>
<div><span>A</span><span>B</span></div>
</body>
</html>

View File

@ -0,0 +1,34 @@
<!DOCTYPE HTML>
<html><head>
<meta charset="utf-8">
<title>Testcase for bug 814677</title>
<style type="text/css">
html,body {
color:black; background-color:white; font-size:16px; padding:0; margin:0;
}
span { display: table-cell; }
.pre { white-space:pre; }
</style>
</head>
<body>
<div><span>A</span>&#x09;<span>B</span></div>
<div><span>A</span>&#x0A;<span>B</span></div>
<div><span>A</span>&#x0B;<span>B</span></div>
<div><span>A</span>&#x0C;<span>B</span></div>
<div><span>A</span>&#x0D;<span>B</span></div>
<div><span>A</span>&nbsp;<span>B</span></div>
<div><span>A</span> <span>B</span></div>
<div class="pre"><span>A</span>&#x09;<span>B</span></div>
<div class="pre"><span>A</span>&#x0A;<span>B</span></div>
<div class="pre"><span>A</span>&#x0B;<span>B</span></div>
<div class="pre"><span>A</span>&#x0C;<span>B</span></div>
<div class="pre"><span>A</span>&#x0D;<span>B</span></div>
<div class="pre"><span>A</span>&nbsp;<span>B</span></div>
<div class="pre"><span>A</span> <span>B</span></div>
</body>
</html>

View File

@ -1732,4 +1732,5 @@ fuzzy(40,800) == 797797-2.html 797797-2-ref.html # 'opacity:N' and rgba(,,,N) te
== 804323-1.html 804323-1-ref.html
== 811301-1.html 811301-1-ref.html
== 812824-1.html 812824-1-ref.html
== 814677.html 814677-ref.html
== 815593-1.html 815593-1-ref.html

View File

@ -1169,11 +1169,11 @@ CompressIndex(int index, const nsTextFragment*fragment)
if (fragment->Is2b()) {
const PRUnichar *data=fragment->Get2b();
while(*data && index) {
if (XP_IS_SPACE_W(*data)){
if (dom::IsSpaceCharacter(*data)){
do {
++data;
--index;
}while(XP_IS_SPACE_W(*data) && index);
}while(dom::IsSpaceCharacter(*data) && index);
}
else {
++data;
@ -1185,11 +1185,11 @@ CompressIndex(int index, const nsTextFragment*fragment)
else {
const char *data=fragment->Get1b();
while(*data && index) {
if (XP_IS_SPACE_W(*data)){
if (dom::IsSpaceCharacter(*data)){
do {
++data;
--index;
}while(XP_IS_SPACE_W(*data) && index);
}while(dom::IsSpaceCharacter(*data) && index);
}
else {
++data;

View File

@ -803,7 +803,8 @@ nsTypeAheadFind::RangeStartsInsideLink(nsIDOMRange *aRange,
if (textFrag) {
// look for non whitespace character before start offset
for (int32_t index = 0; index < startOffset; index++) {
if (!XP_IS_SPACE(textFrag->CharAt(index))) {
// FIXME: take content language into account when deciding whitespace.
if (!mozilla::dom::IsSpaceCharacter(textFrag->CharAt(index))) {
*aIsStartingLink = false; // not at start of a node
break;