Bug 796839 - Part 2 - Don't set inline properties on empty text nodes; r=roc
authorEhsan Akhgari <ehsan@mozilla.com>
Thu, 04 Oct 2012 20:37:45 -0400
changeset 115613 d97ca37eaa2d37073c9465d31c4e50a85ab05ced
parent 115612 d5abea9273a98c97b56ed0177292d59d5e34a298
child 115614 7297e7f7b7481785eb2645178718648aa856b5da
push id1708
push userakeybl@mozilla.com
push dateMon, 19 Nov 2012 21:10:21 +0000
treeherdermozilla-beta@27b14fe50103 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersroc
bugs796839
milestone18.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 796839 - Part 2 - Don't set inline properties on empty text nodes; r=roc This part, similar to the previous one, ensures that we skip empty text nodes when setting inline properties. Previously we were implicitly getting this behavior becasue we were calling IsEditable, but we need to be explicit about this.
editor/libeditor/html/nsHTMLEditorStyle.cpp
--- a/editor/libeditor/html/nsHTMLEditorStyle.cpp
+++ b/editor/libeditor/html/nsHTMLEditorStyle.cpp
@@ -49,16 +49,25 @@
 #include "nsTextEditUtils.h"
 #include "nsUnicharUtils.h"
 #include "nscore.h"
 
 class nsISupports;
 
 using namespace mozilla;
 
+static bool
+IsEmptyTextNode(nsHTMLEditor* aThis, nsINode* aNode)
+{
+  bool isEmptyTextNode = false;
+  return nsEditor::IsTextNode(aNode) &&
+         NS_SUCCEEDED(aThis->IsEmptyNode(aNode, &isEmptyTextNode)) &&
+         isEmptyTextNode;
+}
+
 NS_IMETHODIMP nsHTMLEditor::AddDefaultProperty(nsIAtom *aProperty, 
                                             const nsAString & aAttribute, 
                                             const nsAString & aValue)
 {
   nsString outValue;
   int32_t index;
   nsString attr(aAttribute);
   if (TypeInState::FindPropInList(aProperty, attr, &outValue, mDefaultStyles, index))
@@ -419,17 +428,17 @@ nsHTMLEditor::SetInlinePropertyOnNodeImp
   if (!TagCanContain(nsGkAtoms::span, aNode->AsDOMNode())) {
     if (aNode->HasChildren()) {
       nsCOMArray<nsIContent> arrayOfNodes;
 
       // Populate the list.
       for (nsIContent* child = aNode->GetFirstChild();
            child;
            child = child->GetNextSibling()) {
-        if (IsEditable(child)) {
+        if (IsEditable(child) && !IsEmptyTextNode(this, child)) {
           arrayOfNodes.AppendObject(child);
         }
       }
 
       // Then loop through the list, set the property on each node.
       int32_t listCount = arrayOfNodes.Count();
       for (int32_t j = 0; j < listCount; ++j) {
         nsresult rv = SetInlinePropertyOnNode(arrayOfNodes[j], aProperty,