Bug 1427419 - Part 17: Move inIDOMUtils.isIgnorableWhitespace to InspectorUtils. r?bz draft
authorCameron McCormack <cam@mcc.id.au>
Sat, 06 Jan 2018 15:08:15 +0800
changeset 716762 33edc022a0add1b722ec60650c5bd63604c08ed6
parent 716761 c485735c338e1c372090f8180da33234122bcd4b
child 716763 e05fc71f5ec4a1a2dbfdb87c9227d496ab7991ca
push id94496
push userbmo:cam@mcc.id.au
push dateSat, 06 Jan 2018 07:08:40 +0000
reviewersbz
bugs1427419
milestone59.0a1
Bug 1427419 - Part 17: Move inIDOMUtils.isIgnorableWhitespace to InspectorUtils. r?bz This is still being used by the old DOM Inspector in comm-central. MozReview-Commit-ID: A94BJQ2mqat
dom/webidl/InspectorUtils.webidl
layout/inspector/InspectorUtils.h
layout/inspector/inDOMUtils.cpp
layout/inspector/inDOMView.cpp
layout/inspector/inIDOMUtils.idl
layout/inspector/tests/test_bug462787.html
layout/inspector/tests/test_bug462789.html
--- a/dom/webidl/InspectorUtils.webidl
+++ b/dom/webidl/InspectorUtils.webidl
@@ -46,16 +46,18 @@ namespace InspectorUtils {
   const unsigned long TYPE_ANGLE = 4;
   const unsigned long TYPE_FREQUENCY = 5;
   const unsigned long TYPE_TIME = 6;
   const unsigned long TYPE_GRADIENT = 7;
   const unsigned long TYPE_TIMING_FUNCTION = 8;
   const unsigned long TYPE_IMAGE_RECT = 9;
   const unsigned long TYPE_NUMBER = 10;
   [Throws] boolean cssPropertySupportsType(DOMString property, unsigned long type);
+
+  boolean isIgnorableWhitespace(CharacterData dataNode);
 };
 
 dictionary PropertyNamesOptions {
   boolean includeAliases = false;
 };
 
 dictionary InspectorRGBATuple {
   /*
--- a/layout/inspector/InspectorUtils.h
+++ b/layout/inspector/InspectorUtils.h
@@ -6,16 +6,17 @@
  */
 
 #ifndef mozilla_dom_InspectorUtils_h
 #define mozilla_dom_InspectorUtils_h
 
 #include "mozilla/dom/BindingDeclarations.h"
 
 class nsAtom;
+class nsGenericDOMDataNode;
 class nsIDocument;
 class nsStyleContext;
 
 namespace mozilla {
 class StyleSheet;
 namespace css {
 class Rule;
 } // namespace css
@@ -154,16 +155,23 @@ public:
   // For shorthands, checks whether there's a corresponding longhand property
   // that accepts values of this type.  Throws on unsupported properties or
   // unknown types.
   static bool CssPropertySupportsType(GlobalObject& aGlobal,
                                       const nsAString& aProperty,
                                       uint32_t aType,
                                       ErrorResult& aRv);
 
+  static bool IsIgnorableWhitespace(GlobalObject& aGlobalObject,
+                                    nsGenericDOMDataNode& aDataNode)
+  {
+    return IsIgnorableWhitespace(aDataNode);
+  }
+  static bool IsIgnorableWhitespace(nsGenericDOMDataNode& aDataNode);
+
 private:
   static already_AddRefed<nsStyleContext>
     GetCleanStyleContextForElement(Element* aElement, nsAtom* aPseudo);
 };
 
 } // namespace dom
 } // namespace mozilla
 
--- a/layout/inspector/inDOMUtils.cpp
+++ b/layout/inspector/inDOMUtils.cpp
@@ -7,16 +7,17 @@
 #include "mozilla/ArrayUtils.h"
 #include "mozilla/EventStates.h"
 
 #include "inDOMUtils.h"
 #include "inLayoutUtils.h"
 
 #include "nsArray.h"
 #include "nsAutoPtr.h"
+#include "nsGenericDOMDataNode.h"
 #include "nsIServiceManager.h"
 #include "nsString.h"
 #include "nsIStyleSheetLinkingElement.h"
 #include "nsIContentInlines.h"
 #include "nsIDOMElement.h"
 #include "nsIDocument.h"
 #include "nsIPresShell.h"
 #include "nsIDOMDocument.h"
@@ -113,51 +114,36 @@ InspectorUtils::GetAllStyleSheets(Global
   }
 
   // Get the document sheets.
   for (size_t i = 0; i < aDocument.SheetCount(); i++) {
     aResult.AppendElement(aDocument.SheetAt(i));
   }
 }
 
-} // namespace dom
-} // namespace mozilla
-
-NS_IMETHODIMP
-inDOMUtils::IsIgnorableWhitespace(nsIDOMCharacterData *aDataNode,
-                                  bool *aReturn)
+bool
+InspectorUtils::IsIgnorableWhitespace(nsGenericDOMDataNode& aDataNode)
 {
-  NS_PRECONDITION(aReturn, "Must have an out parameter");
-
-  NS_ENSURE_ARG_POINTER(aDataNode);
-
-  *aReturn = false;
-
-  nsCOMPtr<nsIContent> content = do_QueryInterface(aDataNode);
-  NS_ASSERTION(content, "Does not implement nsIContent!");
-
-  if (!content->TextIsOnlyWhitespace()) {
-    return NS_OK;
+  if (!aDataNode.TextIsOnlyWhitespace()) {
+    return false;
   }
 
   // Okay.  We have only white space.  Let's check the white-space
   // property now and make sure that this isn't preformatted text...
-  nsIFrame* frame = content->GetPrimaryFrame();
-  if (frame) {
-    const nsStyleText* text = frame->StyleText();
-    *aReturn = !text->WhiteSpaceIsSignificant();
-  }
-  else {
-    // empty inter-tag text node without frame, e.g., in between <table>\n<tr>
-    *aReturn = true;
+  if (nsIFrame* frame = aDataNode.GetPrimaryFrame()) {
+    return !frame->StyleText()->WhiteSpaceIsSignificant();
   }
 
-  return NS_OK;
+  // empty inter-tag text node without frame, e.g., in between <table>\n<tr>
+  return true;
 }
 
+} // namespace dom
+} // namespace mozilla
+
 NS_IMETHODIMP
 inDOMUtils::GetParentForNode(nsIDOMNode* aNode,
                              bool aShowingAnonymousContent,
                              nsIDOMNode** aParent)
 {
   NS_ENSURE_ARG_POINTER(aNode);
 
   // First do the special cases -- document nodes and anonymous content
--- a/layout/inspector/inDOMView.cpp
+++ b/layout/inspector/inDOMView.cpp
@@ -1223,21 +1223,16 @@ nsresult
 inDOMView::AppendKidsToArray(nsIDOMNodeList* aKids,
                              nsCOMArray<nsIDOMNode>& aArray)
 {
   uint32_t l = 0;
   aKids->GetLength(&l);
   nsCOMPtr<nsIDOMNode> kid;
   uint16_t nodeType = 0;
 
-  // Try and get DOM Utils in case we don't have one yet.
-  if (!mShowWhitespaceNodes && !mDOMUtils) {
-    mDOMUtils = services::GetInDOMUtils();
-  }
-
   for (uint32_t i = 0; i < l; ++i) {
     aKids->Item(i, getter_AddRefs(kid));
     kid->GetNodeType(&nodeType);
 
     NS_ASSERTION(nodeType && nodeType <= nsIDOMNode::NOTATION_NODE,
                  "Unknown node type. "
                  "Were new types added to the spec?");
     // As of DOM Level 2 Core and Traversal, each NodeFilter constant
@@ -1245,22 +1240,21 @@ inDOMView::AppendKidsToArray(nsIDOMNodeL
     // where n is the numeric constant of the nodeType it represents.
     // If this invariant ever changes, we will need to update the
     // following line.
     uint32_t filterForNodeType = 1 << (nodeType - 1);
 
     if (mWhatToShow & filterForNodeType) {
       if ((nodeType == nsIDOMNode::TEXT_NODE ||
            nodeType == nsIDOMNode::COMMENT_NODE) &&
-          !mShowWhitespaceNodes && mDOMUtils) {
-        nsCOMPtr<nsIDOMCharacterData> data = do_QueryInterface(kid);
+          !mShowWhitespaceNodes) {
+        nsCOMPtr<nsIContent> content = do_QueryInterface(kid);
+        auto data = static_cast<nsGenericDOMDataNode*>(content.get());
         NS_ASSERTION(data, "Does not implement nsIDOMCharacterData!");
-        bool ignore;
-        mDOMUtils->IsIgnorableWhitespace(data, &ignore);
-        if (ignore) {
+        if (InspectorUtils::IsIgnorableWhitespace(*data)) {
           continue;
         }
       }
 
       aArray.AppendElement(kid.forget());
     }
   }
 
--- a/layout/inspector/inIDOMUtils.idl
+++ b/layout/inspector/inIDOMUtils.idl
@@ -15,18 +15,16 @@ interface nsIDOMNode;
 interface nsIDOMNodeList;
 interface nsIDOMFontFaceList;
 interface nsIDOMRange;
 interface nsIDOMCSSStyleSheet;
 
 [scriptable, uuid(362e98c3-82c2-4ad8-8dcb-00e8e4eab497)]
 interface inIDOMUtils : nsISupports
 {
-  // DOM Node utilities
-  boolean isIgnorableWhitespace(in nsIDOMCharacterData aDataNode);
   // Returns the "parent" of a node.  The parent of a document node is the
   // frame/iframe containing that document.  aShowingAnonymousContent says
   // whether we are showing anonymous content.
   nsIDOMNode getParentForNode(in nsIDOMNode aNode,
                               in boolean aShowingAnonymousContent);
   nsIDOMNodeList getChildrenForNode(in nsIDOMNode aNode,
                                     in boolean aShowingAnonymousContent);
 
--- a/layout/inspector/tests/test_bug462787.html
+++ b/layout/inspector/tests/test_bug462787.html
@@ -38,22 +38,21 @@ function do_test() {
     InspectorUtils.getRuleLine(null);
     ok(false, "expected an exception"); 
   }
   catch(e) {
     is(e.name, "TypeError", "got the expected exception");
   }
 
   try {
-    utils.isIgnorableWhitespace(null);
+    InspectorUtils.isIgnorableWhitespace(null);
     ok(false, "expected an exception");
   }
   catch(e) {
-    e = SpecialPowers.wrap(e);
-    is(e.result, INVALID_POINTER, "got the expected exception");
+    is(e.name, "TypeError", "got the expected exception");
   }
 
   try {
     utils.getParentForNode(null, true); 
     ok(false, "expected an exception");
   }
   catch(e) {
     e = SpecialPowers.wrap(e);
--- a/layout/inspector/tests/test_bug462789.html
+++ b/layout/inspector/tests/test_bug462789.html
@@ -44,17 +44,17 @@ function do_test() {
 
   try {
     var res = InspectorUtils.getRuleLine(rule);
     is(res, 1, "getRuleLine");
   }
   catch(e) { ok(false, "got an unexpected exception:" + e); }
 
   try {
-    var res = utils.isIgnorableWhitespace(text);
+    var res = InspectorUtils.isIgnorableWhitespace(text);
     is(res, false, "isIgnorableWhitespace");
   }
   catch(e) { ok(false, "got an unexpected exception:" + e); }
 
   try {
     var res = utils.getParentForNode(docElement, true);
     is(res.nodeType, DOCUMENT_NODE_TYPE, "getParentForNode(docElement, true)");
     res = utils.getParentForNode(text, true);