Bug 753517 part 4. Set up auto-generation of CSS2Properties.webidl from nsCSSPropList.h and enable Paris bindings for CSSStyleDeclaration and CSS2Properties. r=khuey,peterv,dbaron

This commit is contained in:
Boris Zbarsky 2012-08-23 21:08:09 -07:00
parent 8b4fc28fc2
commit 31276eb444
12 changed files with 156 additions and 25 deletions

View File

@ -82,6 +82,16 @@ DOMInterfaces = {
}
}],
'CSS2Properties': {
'nativeType': 'nsDOMCSSDeclaration',
'prefable': True,
},
'CSSStyleDeclaration': {
'nativeType': 'nsICSSDeclaration',
'prefable': True
},
'Document': [
{
'nativeType': 'nsIDocument',
@ -373,6 +383,8 @@ addExternalHTMLElement('HTMLImageElement')
addExternalHTMLElement('HTMLVideoElement')
addExternalIface('CanvasGradient', headerFile='nsIDOMCanvasRenderingContext2D.h')
addExternalIface('CanvasPattern', headerFile='nsIDOMCanvasRenderingContext2D.h')
addExternalIface('CSSRule')
addExternalIface('CSSValue')
addExternalIface('HitRegionOptions', nativeType='nsISupports')
addExternalIface('ImageData', nativeType='mozilla::dom::ImageData')
addExternalIface('TextMetrics', headerFile='nsIDOMCanvasRenderingContext2D.h')

View File

@ -0,0 +1,22 @@
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this file,
# You can obtain one at http://mozilla.org/MPL/2.0/.
import sys
import string
propList = eval(sys.stdin.read())
props = ""
for [prop, pref] in propList:
pref = '[Pref=%s] ' % pref if pref is not "" else ""
if not prop.startswith("Moz"):
prop = prop[0].lower() + prop[1:]
# Unfortunately, even some of the getters here are fallible
# (e.g. on nsComputedDOMStyle).
props += " %sattribute DOMString %s;\n" % (pref, prop)
idlFile = open(sys.argv[1], "r");
idlTemplate = idlFile.read();
idlFile.close();
print string.Template(idlTemplate).substitute({ "props": props })

View File

@ -22,7 +22,7 @@ include $(topsrcdir)/dom/dom-config.mk
include $(topsrcdir)/dom/webidl/WebIDL.mk
binding_include_path := mozilla/dom
all_webidl_files = $(webidl_files)
all_webidl_files = $(webidl_files) $(generated_webidl_files)
# Set exported_binding_headers before adding the test IDL to the mix
exported_binding_headers := $(subst .webidl,Binding.h,$(all_webidl_files))
# Set linked_binding_cpp_files before adding the test IDL to the mix
@ -88,6 +88,16 @@ bindinggen_dependencies := \
$(GLOBAL_DEPS) \
$(NULL)
CSS2Properties.webidl: $(topsrcdir)/layout/style/nsCSSPropList.h \
$(topsrcdir)/layout/style/nsCSSPropAliasList.h \
$(webidl_base)/CSS2Properties.webidl.in \
$(webidl_base)/CSS2PropertiesProps.h \
$(srcdir)/GenerateCSS2PropertiesWebIDL.py \
$(GLOBAL_DEPS)
$(CPP) -I$(topsrcdir)/layout/style $(webidl_base)/CSS2PropertiesProps.h | \
PYTHONDONTWRITEBYTECODE=1 $(PYTHON) \
$(srcdir)/GenerateCSS2PropertiesWebIDL.py $(webidl_base)/CSS2Properties.webidl.in > CSS2Properties.webidl
$(webidl_files): %: $(webidl_base)/%
$(INSTALL) $(IFLAGS1) $(webidl_base)/$* .

View File

@ -101,15 +101,10 @@ function testMediaList() {
function testCSSStyleDeclaration() {
var s = document.createElement("span");
try {
is(s.style[-1], "", "Wrong value for out of bounds access (CSSStyleDeclaration)");
todo(true, "Didn't throw");
} catch (e) {
todo(false, "Shouldn't throw");
}
is(s.style[0], "", "Wrong value for out of bounds access (CSSStyleDeclaration)");
is(s.style[1], "", "Wrong value for out of bounds access (CSSStyleDeclaration)");
is(s.style[2], "", "Wrong value for out of bounds access (CSSStyleDeclaration)");
is(s.style[-1], undefined, "Wrong value for out of bounds access (CSSStyleDeclaration)");
is(s.style[0], undefined, "Wrong value for out of bounds access (CSSStyleDeclaration)");
is(s.style[1], undefined, "Wrong value for out of bounds access (CSSStyleDeclaration)");
is(s.style[2], undefined, "Wrong value for out of bounds access (CSSStyleDeclaration)");
is(s.style.item(-1), "", "Wrong value for out of bounds access (CSSStyleDeclaration)");
is(s.style.item(0), "", "Wrong value for out of bounds access (CSSStyleDeclaration)");
is(s.style.item(1), "", "Wrong value for out of bounds access (CSSStyleDeclaration)");
@ -117,15 +112,10 @@ function testCSSStyleDeclaration() {
s.setAttribute("style", "color: blue; z-index: 42;");
try {
is(s.style[-1], "", "Wrong value for out of bounds access (CSSStyleDeclaration)");
todo(true, "Didn't throw");
} catch (e) {
todo(false, "Shouldn't throw");
}
is(s.style[-1], undefined, "Wrong value for out of bounds access (CSSStyleDeclaration)");
is(s.style[0], "color", "Wrong value for in bounds access (CSSStyleDeclaration)");
is(s.style[1], "z-index", "Wrong value for in bounds access (CSSStyleDeclaration)");
is(s.style[2], "", "Wrong value for out of bounds access (CSSStyleDeclaration)");
is(s.style[2], undefined, "Wrong value for out of bounds access (CSSStyleDeclaration)");
is(s.style.item(-1), "", "Wrong value for out of bounds access (CSSStyleDeclaration)");
is(s.style.item(0), "color", "Wrong value for in bounds access (CSSStyleDeclaration)");
is(s.style.item(1), "z-index", "Wrong value for in bounds access (CSSStyleDeclaration)");

View File

@ -0,0 +1,3 @@
interface CSS2Properties : CSSStyleDeclaration {
${props}
};

View File

@ -0,0 +1,34 @@
/* A file meant as input to the preprocessor only */
/* DO_PROP serves as an extra level of indirection to allow expansion
of CSS_PROP_DOMPROP_PREFIXED */
[
#define DO_PROP(method, pref) \
[ #method, pref ],
#define CSS_PROP(name, id, method, flags, pref, parsevariant, kwtable, \
stylestruct, stylestructofset, animtype) \
DO_PROP(method, pref)
#define CSS_PROP_SHORTHAND(name, id, method, flags, pref) \
DO_PROP(method, pref)
#define CSS_PROP_DOMPROP_PREFIXED(val) Moz##val
#define CSS_PROP_LIST_EXCLUDE_INTERNAL
#include "nsCSSPropList.h"
#undef CSS_PROP_LIST_EXCLUDE_INTERNAL
#undef CSS_PROP_DOMPROP_PREFIXED
#undef CSS_PROP_SHORTHAND
#undef CSS_PROP
#define CSS_PROP_ALIAS(name, id, method, pref) \
DO_PROP(method, pref)
#include "nsCSSPropAliasList.h"
#undef CSS_PROP_ALIAS
#undef DO_PROP
]

View File

@ -0,0 +1,34 @@
/* -*- Mode: IDL; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
* You can obtain one at http://mozilla.org/MPL/2.0/.
*
* The origin of this IDL file is
* http://dev.w3.org/csswg/cssom/
*/
interface CSSRule;
interface CSSValue;
interface CSSStyleDeclaration {
[GetterInfallible]
attribute DOMString cssText;
[Infallible]
readonly attribute unsigned long length;
[Infallible]
getter DOMString item(unsigned long index);
DOMString getPropertyValue(DOMString property);
// Mozilla extension, sort of
CSSValue getPropertyCSSValue(DOMString property);
[Infallible]
DOMString getPropertyPriority(DOMString property);
// This would be nicer if it used a string default value of "".
// See bug 759622.
void setProperty(DOMString property, DOMString value, [TreatNullAs=EmptyString] optional DOMString priority);
DOMString removeProperty(DOMString property);
[Infallible]
readonly attribute CSSRule parentRule;
};

View File

@ -4,8 +4,13 @@
webidl_base = $(topsrcdir)/dom/webidl
generated_webidl_files = \
CSS2Properties.webidl \
$(NULL)
webidl_files = \
CanvasRenderingContext2D.webidl \
CSSStyleDeclaration.webidl \
Function.webidl \
EventListener.webidl \
EventTarget.webidl \

View File

@ -220,14 +220,6 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=668855
let dummy_test_map = new WeakMap;
let div_fail = false;
try {
dummy_test_map.set(document.createElement("div").style, 1);
} catch (e) {
div_fail = true;
}
ok(div_fail, "Using elem.style as a weak map key should produce an exception because it can't be wrapper preserved.");
let navi_fail = false;
try {
dummy_test_map.set(window.navigator, 1);

View File

@ -35,6 +35,7 @@
#include "nsCSSParser.h"
#include "nsPrintfCString.h"
#include "nsDOMClassInfoID.h"
#include "mozilla/dom/CSSStyleDeclarationBinding.h"
namespace css = mozilla::css;
@ -1619,6 +1620,14 @@ nsCSSFontFaceStyleDecl::GetParentObject()
return ContainingRule()->GetDocument();
}
JSObject*
nsCSSFontFaceStyleDecl::WrapObject(JSContext *cx, JSObject *scope,
bool *triedToWrap)
{
return mozilla::dom::CSSStyleDeclarationBinding::Wrap(cx, scope, this,
triedToWrap);
}
// -------------------------------------------
// nsCSSFontFaceRule
//

View File

@ -164,12 +164,20 @@ public:
NS_DECL_NSIDOMCSSSTYLEDECLARATION
NS_DECL_NSICSSDECLARATION
nsCSSFontFaceStyleDecl()
{
SetIsDOMBinding();
}
virtual nsINode *GetParentObject();
virtual void IndexedGetter(uint32_t aIndex, bool& aFound, nsAString& aPropName);
nsresult GetPropertyValue(nsCSSFontDesc aFontDescID,
nsAString & aResult) const;
virtual JSObject* WrapObject(JSContext *cx, JSObject *scope,
bool *triedToWrap);
protected:
friend class nsCSSFontFaceRule;
#define CSS_FONT_DESC(name_, method_) nsCSSValue m##method_;

View File

@ -11,6 +11,7 @@
#include "nsICSSDeclaration.h"
#include "nsIDOMCSS2Properties.h"
#include "nsCOMPtr.h"
#include "mozilla/dom/CSS2PropertiesBinding.h"
class nsCSSParser;
class nsIURI;
@ -96,6 +97,13 @@ public:
virtual void IndexedGetter(uint32_t aIndex, bool& aFound, nsAString& aPropName);
virtual JSObject* WrapObject(JSContext *cx, JSObject *scope,
bool *triedToWrap)
{
return mozilla::dom::CSS2PropertiesBinding::Wrap(cx, scope, this,
triedToWrap);
}
protected:
// This method can return null regardless of the value of aAllocate;
// however, a null return should only be considered a failure
@ -141,6 +149,10 @@ protected:
protected:
virtual ~nsDOMCSSDeclaration();
nsDOMCSSDeclaration()
{
SetIsDOMBinding();
}
};
#endif // nsDOMCSSDeclaration_h___