Bug 847983 - Skip script text nodes for content events; r=masayuki
--- a/content/events/src/nsContentEventHandler.cpp
+++ b/content/events/src/nsContentEventHandler.cpp
@@ -225,16 +225,20 @@ static uint32_t CountNewlinesInNativeLen
return newlines;
}
#endif
/* static */ uint32_t
nsContentEventHandler::GetNativeTextLength(nsIContent* aContent, uint32_t aMaxLength)
{
if (aContent->IsNodeOfType(nsINode::eTEXT)) {
+ // Skip text nodes without frames, e.g. inside script elements
+ if (!aContent->GetPrimaryFrame()) {
+ return 0;
+ }
uint32_t textLengthDifference =
#if defined(XP_MACOSX)
// On Mac, the length of a native newline ("\r") is equal to the length of
// the XP newline ("\n"), so the native length is the same as the XP length.
0;
#elif defined(XP_WIN)
// On Windows, the length of a native newline ("\r\n") is twice the length of
// the XP newline ("\n"), so XP length is equal to the length of the native
@@ -304,16 +308,20 @@ static nsresult GenerateFlatTextContent(
nsINode* node = iter->GetCurrentNode();
if (!node)
break;
if (!node->IsNodeOfType(nsINode::eCONTENT))
continue;
nsIContent* content = static_cast<nsIContent*>(node);
if (content->IsNodeOfType(nsINode::eTEXT)) {
+ // Skip text nodes without frames, e.g. inside script elements
+ if (!content->GetPrimaryFrame()) {
+ continue;
+ }
if (content == startNode)
AppendSubString(aString, content, aRange->StartOffset(),
content->TextLength() - aRange->StartOffset());
else if (content == endNode)
AppendSubString(aString, content, 0, aRange->EndOffset());
else
AppendString(aString, content);
} else if (IsContentBR(content))