Bug 1571650: Add an API to change the style of AnonymousContent from devtools. r=smaug
☠☠ backed out by 00d7377efae9 ☠ ☠
authorDaisuke Akatsuka <dakatsuka@mozilla.com>
Wed, 14 Aug 2019 09:39:54 +0000
changeset 487893 eaef1d403d31e1db6fb78dd377704f601525c74a
parent 487892 f4aa9fbabdcb23241759d769590fe28aa2aed616
child 487894 48438a9d64f1d5a309e59b11d794c7760ccc2444
push id36433
push userbtara@mozilla.com
push dateWed, 14 Aug 2019 21:57:52 +0000
treeherdermozilla-central@7d9a2196d313 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerssmaug
bugs1571650
milestone70.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 1571650: Add an API to change the style of AnonymousContent from devtools. r=smaug DevTools is using AnonymousContent to highlight the element inspecting. And now, the z-order of highlighting became to be importance. In case of normal element, we can change the z-order by z-index or order of DOM. However, AnonymousContent does not have the such the way to change the z-order from DevTools side. This patch introduces an API to change the style, and makes the z-order changeable by the z-index. Differential Revision: https://phabricator.services.mozilla.com/D41927
dom/base/AnonymousContent.cpp
dom/base/AnonymousContent.h
dom/webidl/AnonymousContent.webidl
--- a/dom/base/AnonymousContent.cpp
+++ b/dom/base/AnonymousContent.cpp
@@ -202,10 +202,22 @@ void AnonymousContent::GetTargetIdForEve
   if (el && el->IsInNativeAnonymousSubtree() && mContentNode->Contains(el)) {
     aResult.SetKnownLiveAtom(el->GetID(), DOMString::eTreatNullAsNull);
     return;
   }
 
   aResult.SetNull();
 }
 
+void AnonymousContent::SetStyle(const nsAString& aProperty,
+                                const nsAString& aValue, ErrorResult& aRv) {
+  if (!mContentNode->IsHTMLElement()) {
+    aRv.Throw(NS_ERROR_NOT_AVAILABLE);
+    return;
+  }
+
+  nsGenericHTMLElement* element = nsGenericHTMLElement::FromNode(mContentNode);
+  nsCOMPtr<nsICSSDeclaration> declaration = element->Style();
+  declaration->SetProperty(aProperty, aValue, EmptyString());
+}
+
 }  // namespace dom
 }  // namespace mozilla
--- a/dom/base/AnonymousContent.h
+++ b/dom/base/AnonymousContent.h
@@ -66,16 +66,19 @@ class AnonymousContent final {
                                 ErrorResult& aError);
 
   void GetComputedStylePropertyValue(const nsAString& aElementId,
                                      const nsAString& aPropertyName,
                                      DOMString& aResult, ErrorResult& aRv);
 
   void GetTargetIdForEvent(Event& aEvent, DOMString& aResult);
 
+  void SetStyle(const nsAString& aProperty, const nsAString& aValue,
+                ErrorResult& aRv);
+
  private:
   ~AnonymousContent();
   RefPtr<Element> mContentNode;
 };
 
 }  // namespace dom
 }  // namespace mozilla
 
--- a/dom/webidl/AnonymousContent.webidl
+++ b/dom/webidl/AnonymousContent.webidl
@@ -86,9 +86,15 @@ interface AnonymousContent {
   DOMString? getComputedStylePropertyValue(DOMString elementId,
                                            DOMString propertyName);
 
   /**
    * If event's original target is in the anonymous content, this returns the id
    * attribute value of the target.
    */
   DOMString? getTargetIdForEvent(Event event);
+
+  /**
+   * Set given style to this AnonymousContent.
+   */
+  [Throws]
+  void setStyle(DOMString property, DOMString value);
 };