(cross posting to b2g as this might be an interesting api for on-device
tools).
I have just landed the patches for bug 1020244 [1].
These patches introduce a new (chrome-only) API at document level that
can be used to insert custom DOM elements into the root container of the
page (the canvas frame), fixed positioned, above everything else on the
page.
The discussion [2] that led to the bug was about finding a solution to
display the devtools highlighter (the box-model overlay you see when
inspecting a page with the devtools) in a way that would work on
anything that runs gecko (indeed, prior to this bug, the devtools
highlighter markup would be appended to one of the page's parent XUL
node, which didn't work on B2G or Fennec, or with e10s enabled).
[1] https://bugzilla.mozilla.org/show_bug.cgi?id=1020244
[2]
https://groups.google.com/forum/#!topic/mozilla.dev.tech.layout/fiWpoAGnc8Q
Technical details:
- the API will clone the inserted elements, to avoid giving away to JS
consumers references to DOM nodes in native anonymous content,
- inserting content goes like this: let content =
document.insertAnonymousContent(aNode);
- the returned object provides a set of methods to manipulate the
inserted node
- relevant WebIDLs below:
partial interface Document {
/**
* Deep-clones the provided element and inserts it into the CanvasFrame.
* Returns an AnonymousContent instance that can be used to
manipulate the
* inserted element.
*/
[ChromeOnly, NewObject, Throws]
AnonymousContent insertAnonymousContent(Element aElement);
/**
* Removes the element inserted into the CanvasFrame given an
AnonymousContent
* instance.
*/
[ChromeOnly, Throws]
void removeAnonymousContent(AnonymousContent aContent);
};
[ChromeOnly]
interface AnonymousContent {
/**
* Get the text content of an element inside this custom anonymous
content.
*/
[Throws]
DOMString getTextContentForElement(DOMString elementId);
/**
* Set the text content of an element inside this custom anonymous
content.
*/
[Throws]
void setTextContentForElement(DOMString elementId, DOMString text);
/**
* Get the value of an attribute of an element inside this custom
anonymous
* content.
*/
[Throws]
DOMString? getAttributeForElement(DOMString elementId,
DOMString attributeName);
/**
* Set the value of an attribute of an element inside this custom
anonymous
* content.
*/
[Throws]
void setAttributeForElement(DOMString elementId,
DOMString attributeName,
DOMString value);
/**
* Remove an attribute from an element inside this custom anonymous
content.
*/
[Throws]
void removeAttributeForElement(DOMString elementId,
DOMString attributeName);
};
___
dev-platform mailing list
dev-platform@lists.mozilla.org
https://lists.mozilla.org/listinfo/dev-platform