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

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Daisuke Akatsuka 2019-08-16 07:38:39 +00:00
parent fbd2729e3f
commit c6a47f400c
3 changed files with 21 additions and 0 deletions

View File

@ -207,5 +207,17 @@ void AnonymousContent::GetTargetIdForEvent(Event& aEvent, DOMString& aResult) {
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

View File

@ -71,6 +71,9 @@ class AnonymousContent final {
void GetTargetIdForEvent(Event& aEvent, DOMString& aResult);
void SetStyle(const nsAString& aProperty, const nsAString& aValue,
ErrorResult& aRv);
private:
~AnonymousContent();
RefPtr<Element> mContentNode;

View File

@ -91,4 +91,10 @@ interface AnonymousContent {
* attribute value of the target.
*/
DOMString? getTargetIdForEvent(Event event);
/**
* Set given style to this AnonymousContent.
*/
[Throws]
void setStyle(DOMString property, DOMString value);
};