Bug 1443923 - part6: Expose isCustomElementName to DevTools via InspectorUtils;r=emilio draft
authorJulian Descottes <jdescottes@mozilla.com>
Thu, 19 Jul 2018 13:59:05 +0200
changeset 821034 02019b77fdbdbc4994c625357411872dfa4211fe
parent 820423 e2ba05cb6d9b3cf204fee0756b1c3eef5f291913
child 821035 1f2ad05c0721891ed813bccd1698807ff37f770b
push id116997
push userjdescottes@mozilla.com
push dateFri, 20 Jul 2018 19:56:29 +0000
reviewersemilio
bugs1443923
milestone63.0a1
Bug 1443923 - part6: Expose isCustomElementName to DevTools via InspectorUtils;r=emilio MozReview-Commit-ID: GaHP1gOCwoB
dom/chrome-webidl/InspectorUtils.webidl
layout/inspector/InspectorUtils.cpp
layout/inspector/InspectorUtils.h
--- a/dom/chrome-webidl/InspectorUtils.webidl
+++ b/dom/chrome-webidl/InspectorUtils.webidl
@@ -72,16 +72,18 @@ namespace InspectorUtils {
   void addPseudoClassLock(Element element,
                           DOMString pseudoClass,
                           optional boolean enabled = true);
   void removePseudoClassLock(Element element, DOMString pseudoClass);
   boolean hasPseudoClassLock(Element element, DOMString pseudoClass);
   void clearPseudoClassLocks(Element element);
   [Throws] void parseStyleSheet(CSSStyleSheet sheet, DOMString input);
   void scrollElementIntoView(Element element);
+  boolean isCustomElementName([TreatNullAs=EmptyString] DOMString name,
+                              optional boolean isXULNameSpace = false);
 };
 
 dictionary PropertyNamesOptions {
   boolean includeAliases = false;
   boolean includeShorthands = true;
   boolean includeExperimentals = false;
 };
 
--- a/layout/inspector/InspectorUtils.cpp
+++ b/layout/inspector/InspectorUtils.cpp
@@ -727,10 +727,26 @@ InspectorUtils::ScrollElementIntoView(Gl
   }
 
   presShell->ScrollContentIntoView(&aElement,
                                    nsIPresShell::ScrollAxis(),
                                    nsIPresShell::ScrollAxis(),
                                    nsIPresShell::SCROLL_OVERFLOW_HIDDEN);
 }
 
+
+bool
+InspectorUtils::IsCustomElementName(GlobalObject& aGlobalObject,
+                                    const nsAString& aName,
+                                    bool aIsXULNameSpace)
+{
+  if (aName.IsEmpty()) {
+    return false;
+  }
+
+  RefPtr<nsAtom> nameElt = NS_Atomize(aName);
+  return nsContentUtils::IsCustomElementName(
+    nameElt,
+    aIsXULNameSpace ? kNameSpaceID_XUL : kNameSpaceID_XHTML);
+}
+
 } // namespace dom
 } // namespace mozilla
--- a/layout/inspector/InspectorUtils.h
+++ b/layout/inspector/InspectorUtils.h
@@ -269,16 +269,26 @@ public:
                               ErrorResult& aRv);
 
   /**
    * Scroll an element completely into view, if possible.
    * This is similar to ensureElementIsVisible but for all ancestors.
    */
   static void ScrollElementIntoView(GlobalObject& aGlobal, Element& aElement);
 
+  /**
+   * Check if the provided name can be custom element name.
+   *
+   * @param DOMString aName
+   * @param boolean aIsXULNameSpace
+   */
+  static bool IsCustomElementName(GlobalObject& aGlobal,
+                                  const nsAString& aName,
+                                  bool aIsXULNameSpace);
+
 private:
   static already_AddRefed<ComputedStyle>
     GetCleanComputedStyleForElement(Element* aElement, nsAtom* aPseudo);
 };
 
 } // namespace dom
 } // namespace mozilla