Bug 1346623 - Part 2: Add an API to get computed style values through an AnonymousContent object. r=bholley

MozReview-Commit-ID: Dbvuk16CjFT

--HG--
extra : rebase_source : 2c40e4cd9ce08d6f2a5feb13293cc151de6deb80
This commit is contained in:
Cameron McCormack 2017-03-16 22:46:43 +08:00
parent 2a59bf895d
commit 0c4867b06c
3 changed files with 38 additions and 0 deletions

View File

@ -7,6 +7,7 @@
#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"
@ -208,5 +209,29 @@ AnonymousContent::WrapObject(JSContext* aCx,
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

View File

@ -68,6 +68,11 @@ public:
const Sequence<OwningNonNull<DOMRect>>& aRects,
ErrorResult& aError);
void GetComputedStylePropertyValue(const nsAString& aElementId,
const nsAString& aPropertyName,
DOMString& aResult,
ErrorResult& aRv);
private:
~AnonymousContent();
nsCOMPtr<Element> mContentNode;

View File

@ -77,4 +77,12 @@ interface AnonymousContent {
[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);
};