Bug 847983 - Skip script text nodes for content events; r=masayuki
authorJim Chen <nchen@mozilla.com>
Thu, 04 Apr 2013 12:29:59 -0400
changeset 127680 5d817fa463cbb7a75c4314cdbacd296fde8759a4
parent 127679 6c18d264e0b5035d0baa58e123050f56473e5b1b
child 127681 2606c534949383ed25f1549ddcaf0a87d88f0d1a
push id1
push userroot
push dateMon, 20 Oct 2014 17:29:22 +0000
reviewersmasayuki
bugs847983
milestone23.0a1
Bug 847983 - Skip script text nodes for content events; r=masayuki
content/events/src/nsContentEventHandler.cpp
--- 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))