diff --git a/content/base/public/nsINode.h b/content/base/public/nsINode.h index db6ea81d6aa..acf4566cb5b 100644 --- a/content/base/public/nsINode.h +++ b/content/base/public/nsINode.h @@ -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; diff --git a/content/base/src/nsGenericDOMDataNode.cpp b/content/base/src/nsGenericDOMDataNode.cpp index 34e5b285201..163700ad889 100644 --- a/content/base/src/nsGenericDOMDataNode.cpp +++ b/content/base/src/nsGenericDOMDataNode.cpp @@ -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; } diff --git a/content/base/src/nsTextFragment.h b/content/base/src/nsTextFragment.h index 46d06156a99..1a9d74429bd 100644 --- a/content/base/src/nsTextFragment.h +++ b/content/base/src/nsTextFragment.h @@ -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 diff --git a/content/xbl/src/nsXBLContentSink.cpp b/content/xbl/src/nsXBLContentSink.cpp index b4f5d73fa4c..9cb22a5a23f 100644 --- a/content/xbl/src/nsXBLContentSink.cpp +++ b/content/xbl/src/nsXBLContentSink.cpp @@ -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; } diff --git a/layout/base/nsCSSFrameConstructor.cpp b/layout/base/nsCSSFrameConstructor.cpp index 77a49c3cb0c..ac5d4fd3245 100644 --- a/layout/base/nsCSSFrameConstructor.cpp +++ b/layout/base/nsCSSFrameConstructor.cpp @@ -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; } diff --git a/layout/generic/nsImageFrame.cpp b/layout/generic/nsImageFrame.cpp index e4d7586d428..a716e45e1d2 100644 --- a/layout/generic/nsImageFrame.cpp +++ b/layout/generic/nsImageFrame.cpp @@ -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; diff --git a/layout/generic/nsTextFrameThebes.cpp b/layout/generic/nsTextFrameThebes.cpp index 5d43adec78e..215a0286cc8 100644 --- a/layout/generic/nsTextFrameThebes.cpp +++ b/layout/generic/nsTextFrameThebes.cpp @@ -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. diff --git a/layout/reftests/bugs/814677-ref.html b/layout/reftests/bugs/814677-ref.html new file mode 100644 index 00000000000..2a9ab492f51 --- /dev/null +++ b/layout/reftests/bugs/814677-ref.html @@ -0,0 +1,35 @@ + + + + Testcase for bug 814677 + + + + +
AB
+
AB
+
A
B
+
AB
+
AB
+
A
 
B
+
AB
+ +
AB
+
AB
+
A
B
+
AB
+
AB
+
A
 
B
+
AB
+ + + + diff --git a/layout/reftests/bugs/814677.html b/layout/reftests/bugs/814677.html new file mode 100644 index 00000000000..d8a13130c60 --- /dev/null +++ b/layout/reftests/bugs/814677.html @@ -0,0 +1,34 @@ + + + + Testcase for bug 814677 + + + + +
A B
+
A B
+
A B
+
A B
+
A B
+
A B
+
A B
+ +
A B
+
A B
+
A B
+
A B
+
A B
+
A B
+
A B
+ + + diff --git a/layout/reftests/bugs/reftest.list b/layout/reftests/bugs/reftest.list index 6cd1b0b2e11..dbcdc2f34ae 100644 --- a/layout/reftests/bugs/reftest.list +++ b/layout/reftests/bugs/reftest.list @@ -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 diff --git a/layout/svg/nsSVGGlyphFrame.cpp b/layout/svg/nsSVGGlyphFrame.cpp index 9923384f787..0ba57783d4b 100644 --- a/layout/svg/nsSVGGlyphFrame.cpp +++ b/layout/svg/nsSVGGlyphFrame.cpp @@ -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; diff --git a/toolkit/components/typeaheadfind/nsTypeAheadFind.cpp b/toolkit/components/typeaheadfind/nsTypeAheadFind.cpp index 264a48104a3..df9da1cae4b 100644 --- a/toolkit/components/typeaheadfind/nsTypeAheadFind.cpp +++ b/toolkit/components/typeaheadfind/nsTypeAheadFind.cpp @@ -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;