Bug 1455559: Make FromNode work for references. r=bz,Nika
authorEmilio Cobos Álvarez <emilio@crisal.io>
Fri, 20 Apr 2018 11:10:12 +0200
changeset 469112 ad5095a897e5ef6cf6d4d448635917b1806d98b7
parent 469111 2df9e20ea6c0aee71514c217c8efb95c2f90de5d
child 469113 8645b620dad4d104616775593b1a368d16c76721
push id9165
push userasasaki@mozilla.com
push dateThu, 26 Apr 2018 21:04:54 +0000
treeherdermozilla-beta@064c3804de2e [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbz, Nika
bugs1455559
milestone61.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 1455559: Make FromNode work for references. r=bz,Nika MozReview-Commit-ID: 1ldU1aKeMzs
dom/base/nsINode.h
editor/libeditor/HTMLAnonymousNodeEditor.cpp
--- a/dom/base/nsINode.h
+++ b/dom/base/nsINode.h
@@ -2145,43 +2145,55 @@ ToSupports(nsINode* aPointer)
 inline nsISupports*
 ToCanonicalSupports(nsINode* aPointer)
 {
   return aPointer;
 }
 
 // Some checks are faster to do on nsIContent or Element than on
 // nsINode, so spit out FromNode versions taking those types too.
-#define NS_IMPL_FROMNODE_HELPER(_class, _check)                         \
-  template<typename ArgType>                                            \
-  static _class* FromNode(ArgType&& aNode)                              \
-  {                                                                     \
-    /* We need the double-cast in case aNode is a smartptr.  Those */   \
-    /* can cast to superclasses of the type they're templated on, */    \
-    /* but not directly to subclasses.  */                              \
-    return aNode->_check ?                                              \
-      static_cast<_class*>(static_cast<nsINode*>(aNode)) : nullptr;     \
-  }                                                                     \
-  template<typename ArgType>                                            \
-  static _class* FromNodeOrNull(ArgType&& aNode)                        \
-  {                                                                     \
-    return aNode ? FromNode(aNode) : nullptr;                           \
-  }                                                                     \
-  template<typename ArgType>                                            \
-  static const _class* FromNode(const ArgType* aNode)                   \
-  {                                                                     \
-    return aNode->_check ? static_cast<const _class*>(aNode) : nullptr; \
-  }                                                                     \
-  template<typename ArgType>                                            \
-  static const _class* FromNodeOrNull(const ArgType* aNode)             \
-  {                                                                     \
-    return aNode ? FromNode(aNode) : nullptr;                           \
+#define NS_IMPL_FROMNODE_GENERIC(_class, _check, _const)                 \
+  template<typename T>                                                   \
+  static auto FromNode(_const T& aNode)                                  \
+    -> decltype(static_cast<_const _class*>(&aNode))                     \
+  {                                                                      \
+    return aNode._check ? static_cast<_const _class*>(&aNode) : nullptr; \
+  }                                                                      \
+  template<typename T>                                                   \
+  static _const _class* FromNode(_const T* aNode)                        \
+  {                                                                      \
+    return FromNode(*aNode);                                             \
+  }                                                                      \
+  template<typename T>                                                   \
+  static _const _class* FromNodeOrNull(_const T* aNode)                  \
+  {                                                                      \
+    return aNode ? FromNode(*aNode) : nullptr;                           \
   }
 
-#define NS_IMPL_FROMNODE(_class, _nsid)                                     \
+#define NS_IMPL_FROMNODE_HELPER(_class, _check)                          \
+  NS_IMPL_FROMNODE_GENERIC(_class, _check, )                             \
+  NS_IMPL_FROMNODE_GENERIC(_class, _check, const)                        \
+                                                                         \
+  template<typename T>                                                   \
+  static _class* FromNode(T&& aNode)                                     \
+  {                                                                      \
+    /* We need the double-cast in case aNode is a smartptr.  Those */    \
+    /* can cast to superclasses of the type they're templated on, */     \
+    /* but not directly to subclasses.  */                               \
+    return aNode->_check                                                 \
+      ? static_cast<_class*>(static_cast<nsINode*>(aNode))               \
+      : nullptr;                                                         \
+  }                                                                      \
+  template<typename T>                                                   \
+  static _class* FromNodeOrNull(T&& aNode)                               \
+  {                                                                      \
+    return aNode ? FromNode(aNode) : nullptr;                            \
+  }
+
+#define NS_IMPL_FROMNODE(_class, _nsid)                                 \
   NS_IMPL_FROMNODE_HELPER(_class, IsInNamespace(_nsid))
 
 #define NS_IMPL_FROMNODE_WITH_TAG(_class, _nsid, _tag)                      \
   NS_IMPL_FROMNODE_HELPER(_class, NodeInfo()->Equals(nsGkAtoms::_tag, _nsid))
 
 #define NS_IMPL_FROMNODE_HTML_WITH_TAG(_class, _tag)                        \
   NS_IMPL_FROMNODE_WITH_TAG(_class, kNameSpaceID_XHTML, _tag)
 
--- a/editor/libeditor/HTMLAnonymousNodeEditor.cpp
+++ b/editor/libeditor/HTMLAnonymousNodeEditor.cpp
@@ -485,17 +485,17 @@ HTMLEditor::GetPositionAndDimensions(Ele
          aMarginLeft + aBorderLeft;
     aY = GetCSSFloatValue(cssDecl, NS_LITERAL_STRING("top")) +
          aMarginTop + aBorderTop;
     aW = GetCSSFloatValue(cssDecl, NS_LITERAL_STRING("width"));
     aH = GetCSSFloatValue(cssDecl, NS_LITERAL_STRING("height"));
   } else {
     mResizedObjectIsAbsolutelyPositioned = false;
     RefPtr<nsGenericHTMLElement> htmlElement =
-      nsGenericHTMLElement::FromNode(&aElement);
+      nsGenericHTMLElement::FromNode(aElement);
     if (!htmlElement) {
       return NS_ERROR_NULL_POINTER;
     }
     GetElementOrigin(aElement, aX, aY);
 
     aW = htmlElement->OffsetWidth();
     aH = htmlElement->OffsetHeight();