Bug 753517 part 3. Expose the API needed for Paris bindings on nsDOMCSSDeclaration and nsICSSDeclaration. r=dbaron,peterv

This commit is contained in:
Boris Zbarsky 2012-08-23 21:08:08 -07:00
Родитель 5aa143112a
Коммит 688a8b41eb
11 изменённых файлов: 172 добавлений и 37 удалений

Просмотреть файл

@ -12,6 +12,7 @@
#define mozilla_ErrorResult_h
#include "nscore.h"
#include "mozilla/Assertions.h"
namespace mozilla {

Просмотреть файл

@ -987,7 +987,7 @@ Declaration::List(FILE* out, int32_t aIndent) const
}
#endif
void
bool
Declaration::GetNthProperty(uint32_t aIndex, nsAString& aReturn) const
{
aReturn.Truncate();
@ -995,8 +995,10 @@ Declaration::GetNthProperty(uint32_t aIndex, nsAString& aReturn) const
nsCSSProperty property = OrderValueAt(aIndex);
if (0 <= property) {
AppendASCIItoUTF16(nsCSSProps::GetStringValue(property), aReturn);
return true;
}
}
return false;
}
void

Просмотреть файл

@ -70,7 +70,9 @@ public:
uint32_t Count() const {
return mOrder.Length();
}
void GetNthProperty(uint32_t aIndex, nsAString& aReturn) const;
// Returns whether we actually had a property at aIndex
bool GetNthProperty(uint32_t aIndex, nsAString& aReturn) const;
void ToString(nsAString& aString) const;

Просмотреть файл

@ -1558,8 +1558,19 @@ nsCSSFontFaceStyleDecl::GetLength(uint32_t *aLength)
// DOMString item (in unsigned long index);
NS_IMETHODIMP
nsCSSFontFaceStyleDecl::Item(uint32_t index, nsAString & aResult)
{
nsCSSFontFaceStyleDecl::Item(uint32_t aIndex, nsAString& aReturn)
{
bool found;
IndexedGetter(aIndex, found, aReturn);
if (!found) {
aReturn.Truncate();
}
return NS_OK;
}
void
nsCSSFontFaceStyleDecl::IndexedGetter(uint32_t index, bool& aFound, nsAString & aResult)
{
int32_t nset = -1;
for (nsCSSFontDesc id = nsCSSFontDesc(eCSSFontDesc_UNKNOWN + 1);
id < eCSSFontDesc_COUNT;
@ -1568,13 +1579,13 @@ nsCSSFontFaceStyleDecl::Item(uint32_t index, nsAString & aResult)
!= eCSSUnit_Null) {
nset++;
if (nset == int32_t(index)) {
aFound = true;
aResult.AssignASCII(nsCSSProps::GetStringValue(id).get());
return NS_OK;
return;
}
}
}
aResult.Truncate();
return NS_OK;
aFound = false;
}
// readonly attribute nsIDOMCSSRule parentRule;

Просмотреть файл

@ -165,6 +165,7 @@ public:
NS_DECL_NSICSSDECLARATION
virtual nsINode *GetParentObject();
virtual void IndexedGetter(uint32_t aIndex, bool& aFound, nsAString& aPropName);
nsresult GetPropertyValue(nsCSSFontDesc aFontDescID,
nsAString & aResult) const;

Просмотреть файл

@ -545,18 +545,21 @@ nsComputedDOMStyle::SetProperty(const nsAString& aPropertyName,
NS_IMETHODIMP
nsComputedDOMStyle::Item(uint32_t aIndex, nsAString& aReturn)
{
aReturn.Truncate();
uint32_t length = 0;
const ComputedStyleMapEntry* propMap = GetQueryablePropertyMap(&length);
if (aIndex < length) {
CopyASCIItoUTF16(nsCSSProps::GetStringValue(propMap[aIndex].mProperty),
aReturn);
}
return NS_OK;
return nsDOMCSSDeclaration::Item(aIndex, aReturn);
}
void
nsComputedDOMStyle::IndexedGetter(uint32_t aIndex, bool& aFound,
nsAString& aPropName)
{
uint32_t length = 0;
const ComputedStyleMapEntry* propMap = GetQueryablePropertyMap(&length);
aFound = aIndex < length;
if (aFound) {
CopyASCIItoUTF16(nsCSSProps::GetStringValue(propMap[aIndex].mProperty),
aPropName);
}
}
// Property getters...

Просмотреть файл

@ -25,7 +25,7 @@
class nsIFrame;
class nsIPresShell;
class nsComputedDOMStyle : public nsDOMCSSDeclaration
class nsComputedDOMStyle MOZ_FINAL : public nsDOMCSSDeclaration
{
public:
NS_DECL_CYCLE_COLLECTING_ISUPPORTS
@ -35,6 +35,7 @@ public:
NS_DECL_NSICSSDECLARATION
NS_DECL_NSIDOMCSSSTYLEDECLARATION
virtual void IndexedGetter(uint32_t aIndex, bool& aFound, nsAString& aPropName);
nsComputedDOMStyle(mozilla::dom::Element* aElement,
const nsAString& aPseudoElt,

Просмотреть файл

@ -23,7 +23,7 @@ class Element;
}
}
class nsDOMCSSAttributeDeclaration : public nsDOMCSSDeclaration
class nsDOMCSSAttributeDeclaration MOZ_FINAL : public nsDOMCSSDeclaration
{
public:
typedef mozilla::dom::Element Element;

Просмотреть файл

@ -144,17 +144,11 @@ nsDOMCSSDeclaration::GetPropertyCSSValue(const nsAString& aPropertyName,
return NS_OK;
}
NS_IMETHODIMP
nsDOMCSSDeclaration::Item(uint32_t aIndex, nsAString& aReturn)
void
nsDOMCSSDeclaration::IndexedGetter(uint32_t aIndex, bool& aFound, nsAString& aPropName)
{
css::Declaration* decl = GetCSSDeclaration(false);
aReturn.SetLength(0);
if (decl) {
decl->GetNthProperty(aIndex, aReturn);
}
return NS_OK;
aFound = decl && decl->GetNthProperty(aIndex, aPropName);
}
NS_IMETHODIMP

Просмотреть файл

@ -33,7 +33,14 @@ public:
// of implementing AddRef/Release.
NS_IMETHOD QueryInterface(REFNSIID aIID, void** aInstancePtr);
// Declare addref and release so they can be called on us, but don't
// implement them. Our subclasses must handle their own
// refcounting.
NS_IMETHOD_(nsrefcnt) AddRef() = 0;
NS_IMETHOD_(nsrefcnt) Release() = 0;
NS_DECL_NSICSSDECLARATION
using nsICSSDeclaration::GetLength;
// Require subclasses to implement |GetParentRule|.
//NS_DECL_NSIDOMCSSSTYLEDECLARATION
@ -50,13 +57,45 @@ public:
NS_IMETHOD SetProperty(const nsAString & propertyName,
const nsAString & value, const nsAString & priority);
NS_IMETHOD GetLength(uint32_t *aLength);
NS_IMETHOD Item(uint32_t index, nsAString & _retval);
NS_IMETHOD GetParentRule(nsIDOMCSSRule * *aParentRule) = 0;
// We implement this as a shim which forwards to GetPropertyValue
// and SetPropertyValue; subclasses need not.
NS_DECL_NSIDOMCSS2PROPERTIES
// WebIDL interface for CSS2Properties
#define CSS_PROP_DOMPROP_PREFIXED(prop_) Moz ## prop_
#define CSS_PROP(name_, id_, method_, flags_, pref_, parsevariant_, \
kwtable_, stylestruct_, stylestructoffset_, animtype_) \
void \
Get##method_(nsAString& aValue, mozilla::ErrorResult& rv) \
{ \
rv = GetPropertyValue(eCSSProperty_##id_, aValue); \
} \
\
void \
Set##method_(const nsAString& aValue, mozilla::ErrorResult& rv) \
{ \
rv = SetPropertyValue(eCSSProperty_##id_, aValue); \
}
#define CSS_PROP_LIST_EXCLUDE_INTERNAL
#define CSS_PROP_SHORTHAND(name_, id_, method_, flags_, pref_) \
CSS_PROP(name_, id_, method_, flags_, pref_, X, X, X, X, X)
#include "nsCSSPropList.h"
#define CSS_PROP_ALIAS(aliasname_, propid_, aliasmethod_, pref_) \
CSS_PROP(X, propid_, aliasmethod_, X, pref_, X, X, X, X, X)
#include "nsCSSPropAliasList.h"
#undef CSS_PROP_ALIAS
#undef CSS_PROP_SHORTHAND
#undef CSS_PROP_LIST_EXCLUDE_INTERNAL
#undef CSS_PROP
#undef CSS_PROP_DOMPROP_PREFIXED
virtual void IndexedGetter(uint32_t aIndex, bool& aFound, nsAString& aPropName);
protected:
// This method can return null regardless of the value of aAllocate;
// however, a null return should only be considered a failure

Просмотреть файл

@ -22,11 +22,16 @@
#include "nsIDOMCSSStyleDeclaration.h"
#include "nsCSSProperty.h"
#include "nsWrapperCache.h"
#include "mozilla/dom/BindingUtils.h"
#include "nsString.h"
#include "nsIDOMCSSRule.h"
#include "nsIDOMCSSValue.h"
#include "mozilla/ErrorResult.h"
// 57eb81d1-a607-4429-926b-802519d43aad
// dbeabbfa-6cb3-4f5c-aec2-dd558d9d681f
#define NS_ICSSDECLARATION_IID \
{ 0x57eb81d1, 0xa607, 0x4429, \
{0x92, 0x6b, 0x80, 0x25, 0x19, 0xd4, 0x3a, 0xad } }
{ 0xdbeabbfa, 0x6cb3, 0x4f5c, \
{ 0xae, 0xc2, 0xdd, 0x55, 0x8d, 0x9d, 0x68, 0x1f } }
class nsINode;
@ -43,11 +48,6 @@ public:
NS_IMETHOD GetPropertyValue(const nsCSSProperty aPropID,
nsAString& aValue) = 0;
// Also have to declare the nsIDOMCSSStyleDeclaration method, so we
// don't hide it... very sad, but it stole the good method name
NS_IMETHOD GetPropertyValue(const nsAString& aPropName,
nsAString& aValue) = 0;
/**
* Method analogous to nsIDOMCSSStyleDeclaration::SetProperty. This
* method does NOT allow setting a priority (the priority will
@ -57,6 +57,87 @@ public:
const nsAString& aValue) = 0;
virtual nsINode *GetParentObject() = 0;
// Also have to declare all the nsIDOMCSSStyleDeclaration methods,
// since we want to be able to call them from the WebIDL versions.
NS_IMETHOD GetCssText(nsAString& aCssText) = 0;
NS_IMETHOD SetCssText(const nsAString& aCssText) = 0;
NS_IMETHOD GetPropertyValue(const nsAString& aPropName,
nsAString& aValue) = 0;
NS_IMETHOD GetPropertyCSSValue(const nsAString& aPropertyName,
nsIDOMCSSValue** aReturn) = 0;
NS_IMETHOD RemoveProperty(const nsAString& aPropertyName,
nsAString& aReturn) = 0;
NS_IMETHOD GetPropertyPriority(const nsAString& aPropertyName,
nsAString& aReturn) = 0;
NS_IMETHOD SetProperty(const nsAString& aPropertyName,
const nsAString& aValue,
const nsAString& aPriority) = 0;
NS_IMETHOD GetLength(uint32_t* aLength) = 0;
NS_IMETHOD Item(uint32_t aIndex, nsAString& aReturn)
{
bool found;
IndexedGetter(aIndex, found, aReturn);
if (!found) {
aReturn.Truncate();
}
return NS_OK;
}
NS_IMETHOD GetParentRule(nsIDOMCSSRule * *aParentRule) = 0;
// WebIDL interface for CSSStyleDeclaration
void SetCssText(const nsAString& aString, mozilla::ErrorResult& rv) {
rv = SetCssText(aString);
}
void GetCssText(nsString& aString) {
// Cast to nsAString& so we end up calling our virtual
// |GetCssText(nsAString& aCssText)| overload, which does the real work.
GetCssText(static_cast<nsAString&>(aString));
}
uint32_t GetLength() {
uint32_t length;
GetLength(&length);
return length;
}
void Item(uint32_t aIndex, nsString& aPropName) {
Item(aIndex, static_cast<nsAString&>(aPropName));
}
// The actual implementation of the Item method and the WebIDL indexed getter
virtual void IndexedGetter(uint32_t aIndex, bool& aFound, nsAString& aPropName) = 0;
void GetPropertyValue(const nsAString& aPropName, nsString& aValue,
mozilla::ErrorResult& rv) {
rv = GetPropertyValue(aPropName, aValue);
}
already_AddRefed<nsIDOMCSSValue>
GetPropertyCSSValue(const nsAString& aPropName, mozilla::ErrorResult& rv) {
nsCOMPtr<nsIDOMCSSValue> val;
rv = GetPropertyCSSValue(aPropName, getter_AddRefs(val));
return val.forget();
}
void GetPropertyPriority(const nsAString& aPropName, nsString& aPriority) {
GetPropertyPriority(aPropName, static_cast<nsAString&>(aPriority));
}
// XXXbz we should nix the Optional thing once bug 759622 is fixed.
void SetProperty(const nsAString& aPropName, const nsAString& aValue,
const mozilla::dom::Optional<nsAString>& aPriority,
mozilla::ErrorResult& rv) {
if (aPriority.WasPassed()) {
rv = SetProperty(aPropName, aValue, aPriority.Value());
} else {
rv = SetProperty(aPropName, aValue, EmptyString());
}
}
void RemoveProperty(const nsAString& aPropName, nsString& aRetval,
mozilla::ErrorResult& rv) {
rv = RemoveProperty(aPropName, aRetval);
}
already_AddRefed<nsIDOMCSSRule> GetParentRule() {
nsCOMPtr<nsIDOMCSSRule> rule;
GetParentRule(getter_AddRefs(rule));
return rule.forget();
}
};
NS_DEFINE_STATIC_IID_ACCESSOR(nsICSSDeclaration, NS_ICSSDECLARATION_IID)