Bug 1346623 - Part 2: Add an API to get computed style values through an AnonymousContent object. r=bholley
☠☠ backed out by 2f9cdacc5359 ☠ ☠
authorCameron McCormack <cam@mcc.id.au>
Thu, 16 Mar 2017 22:46:43 +0800
changeset 348174 39ee9556d4a065ba77c11980dc6d814fe79865dc
parent 348173 9e40bc33e62091e96d33b4a8264e962b3653a8a5
child 348175 1f9a6ce59a5636364d3a07a03a8640eb16bfa12c
push id88164
push usercbook@mozilla.com
push dateFri, 17 Mar 2017 13:55:35 +0000
treeherdermozilla-inbound@e46c08babe02 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbholley
bugs1346623
milestone55.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 1346623 - Part 2: Add an API to get computed style values through an AnonymousContent object. r=bholley MozReview-Commit-ID: Dbvuk16CjFT
dom/base/AnonymousContent.cpp
dom/base/AnonymousContent.h
dom/webidl/AnonymousContent.webidl
--- a/dom/base/AnonymousContent.cpp
+++ b/dom/base/AnonymousContent.cpp
@@ -2,16 +2,17 @@
 /* vim: set ts=8 sts=2 et sw=2 tw=80: */
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #include "AnonymousContent.h"
 #include "mozilla/dom/Element.h"
 #include "mozilla/dom/AnonymousContentBinding.h"
+#include "nsComputedDOMStyle.h"
 #include "nsCycleCollectionParticipant.h"
 #include "nsIDocument.h"
 #include "nsIDOMHTMLCollection.h"
 #include "nsIFrame.h"
 #include "nsStyledElement.h"
 #include "HTMLCanvasElement.h"
 
 namespace mozilla {
@@ -203,10 +204,34 @@ AnonymousContent::GetElementById(const n
 bool
 AnonymousContent::WrapObject(JSContext* aCx,
                              JS::Handle<JSObject*> aGivenProto,
                              JS::MutableHandle<JSObject*> aReflector)
 {
   return AnonymousContentBinding::Wrap(aCx, this, aGivenProto, aReflector);
 }
 
+void
+AnonymousContent::GetComputedStylePropertyValue(const nsAString& aElementId,
+                                                const nsAString& aPropertyName,
+                                                DOMString& aResult,
+                                                ErrorResult& aRv)
+{
+  Element* element = GetElementById(aElementId);
+  if (!element) {
+    aRv.Throw(NS_ERROR_NOT_AVAILABLE);
+    return;
+  }
+
+  nsIPresShell* shell = element->OwnerDoc()->GetShell();
+  if (!shell) {
+    aRv.Throw(NS_ERROR_NOT_AVAILABLE);
+    return;
+  }
+
+  RefPtr<nsComputedDOMStyle> cs =
+    new nsComputedDOMStyle(element, NS_LITERAL_STRING(""), shell,
+                           nsComputedDOMStyle::eAll);
+  aRv = cs->GetPropertyValue(aPropertyName, aResult);
+}
+
 } // namespace dom
 } // namespace mozilla
--- a/dom/base/AnonymousContent.h
+++ b/dom/base/AnonymousContent.h
@@ -63,16 +63,21 @@ public:
                                                      JS::Handle<JSObject*> aKeyframes,
                                                      const UnrestrictedDoubleOrKeyframeAnimationOptions& aOptions,
                                                      ErrorResult& aError);
 
   void SetCutoutRectsForElement(const nsAString& aElementId,
                                 const Sequence<OwningNonNull<DOMRect>>& aRects,
                                 ErrorResult& aError);
 
+  void GetComputedStylePropertyValue(const nsAString& aElementId,
+                                     const nsAString& aPropertyName,
+                                     DOMString& aResult,
+                                     ErrorResult& aRv);
+
 private:
   ~AnonymousContent();
   nsCOMPtr<Element> mContentNode;
 };
 
 } // namespace dom
 } // namespace mozilla
 
--- a/dom/webidl/AnonymousContent.webidl
+++ b/dom/webidl/AnonymousContent.webidl
@@ -72,9 +72,17 @@ interface AnonymousContent {
    * Accepts a list of (possibly overlapping) DOMRects which describe a shape
    * in CSS pixels relative to the element's border box. This shape will be
    * excluded from the element's background color rendering. The element will
    * not render any background images once this method has been called.
    */
   [Throws]
   void setCutoutRectsForElement(DOMString elementId,
                                 sequence<DOMRect> rects);
+
+  /**
+   * Get the computed value of a property on an element inside this custom
+   * anonymous content.
+   */
+  [Throws]
+  DOMString? getComputedStylePropertyValue(DOMString elementId,
+                                           DOMString propertyName);
 };